Hello!

Some time ago, we added code to make GNU Mach's build system install a
file containing information to enable rpctrace to translate between the
rpc stub numbers to their names, `/share/msgids/gnumach.msgids'.

However, it may happen (and happened to me today, so...) that this file
and the actual rpc stubs that are provided are not in sync.  So, I came
up with the following patch that adds a `msgids.tar.gz' device to GNU
Mach which in turn can be used as follows:

#v+
[EMAIL PROTECTED]:/var/tmp $ rpctrace /bin/true 2>&1 | head -n 5
task411-> 2030 () = 0 {4096 47650 5238 6923 3737 47695 0 8978 2878 307452 24670 
21985 20884}
task411-> 2029 (134217728) = 0 134512640 12288 5 7 1 0   49 0
task411-> 3206 (pn{  3}) = 0 
task411-> 2029 (134524928) = 0 134524928 4096 3 7 1 0   51 0
task411-> 3206 (pn{  3}) = 0 
#v-

That's what we already know.  Numbers, but no names.

Now.  Introducing the new device, named `msgids.tar.gz'.

#v+
[EMAIL PROTECTED]:/var/tmp $ sudo devprobe msgids.tar.gz
msgids.tar.gz
#v-

Make it available.

#v+
[EMAIL PROTECTED]:/var/tmp $ sudo settrans -ca msgids.tar.gz /hurd/storeio 
--readonly msgids.tar.gz
#v-

Publish its content.

#v+
[EMAIL PROTECTED]:/var/tmp $ settrans -ca msgids `pwd`/tarfs/tarfs --gzip 
--readonly `pwd`/msgids.tar.gz
[EMAIL PROTECTED]:/var/tmp $ ls msgids/
device.server.msgids        mach.server.msgids        mach_host.server.msgids  
memory_object_default.user.msgids
device_pager.server.msgids  mach4.server.msgids       mach_i386.server.msgids  
memory_object_reply.user.msgids
device_reply.user.msgids    mach_debug.server.msgids  mach_port.server.msgids  
memory_object_user.user.msgids
#v-

And finally use its content.

#v+
[EMAIL PROTECTED]:/var/tmp $ rpctrace -I msgids/ /bin/true 2>&1 | head -n 5
task414->vm_statistics () = 0 {4096 47636 5244 6931 3737 51980 0 8984 2884 
333549 24846 22070 20968}
task414->vm_region (134217728) = 0 134512640 12288 5 7 1 0   49 0
task414->mach_port_deallocate (pn{  3}) = 0 
task414->vm_region (134524928) = 0 134524928 4096 3 7 1 0   51 0
task414->mach_port_deallocate (pn{  3}) = 0 
#v-


I could imagine that the `storeio' translator would be installed onto
`/dev/gnumach.msgids.tar.gz', the `tarfs' one onto `/dev/gnumach.msgids/'
and `rpctrace' would look into `/dev/gnumach.msgids/' and
`/share/msgids/' (for the Hurd server's information) by default.


Richard Braun didn't really like this approach, saying that this data
doesn't belong into the microkernel, but I like the tight coupling
between the kernel-provided call ids and their translation to names.
What do others think?


#v+
2007-03-24  Thomas Schwinge  <[EMAIL PROTECTED]>

        * Makerules.am (%.incbin.h %.incbin.s): New rule.
        * Makefrag.am (libkernel_a_SOURCES): Add `device/msgids.c'.
        (gnumach.msgids): Remove rule.
        (exec_msgidsdir, exec_msgids_DATA): Don't define.
        (gnumach.msgids.tar, mostlyclean-local-gnumach-msgids): New rules.
        (nodist_libkernel_a_SOURCES): Add `gnumach.msgids.tar.gz.incbin.h' and
        `gnumach.msgids.tar.gz.incbin.s'.
        * device/msgids.c: New file.
        * i386/i386at/conf.c (dev_name_list): Add the `msgids.tar.gz' device.

Index: Makerules.am
===================================================================
RCS file: /cvsroot/hurd/gnumach/Attic/Makerules.am,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 Makerules.am
--- Makerules.am        23 Mar 2007 10:21:45 -0000      1.1.2.7
+++ Makerules.am        24 Mar 2007 00:03:30 -0000
@@ -30,6 +30,21 @@ EXTRA_DIST += \
          -e 's/mAgIc[^-0-9]*//'
 
 #
+# Transform arbitrary binary files into object files.
+#
+
+%.incbin.h %.incbin.s: %
+       echo 'extern char _NAME_start, _NAME_end;' > $*.incbin.tmp
+       sed 's/NAME/$(subst .,_,$*)/g' < $*.incbin.tmp > $*.incbin.h
+       ( echo '        .section _NAME, "a"';                   \
+         echo '        .global _NAME_start, _NAME_end';        \
+         echo '_NAME_start:';                                  \
+         echo '        .incbin "$*"';                          \
+         echo '_NAME_end:' ) > $*.incbin.tmp
+       sed 's/NAME/$(subst .,_,$*)/g' < $*.incbin.tmp > $*.incbin.s
+       rm $*.incbin.tmp
+
+#
 # Building RPC stubs.
 #
 
Index: Makefrag.am
===================================================================
RCS file: /cvsroot/hurd/gnumach/Attic/Makefrag.am,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 Makefrag.am
--- Makefrag.am 23 Mar 2007 23:51:29 -0000      1.1.2.10
+++ Makefrag.am 24 Mar 2007 00:03:30 -0000
@@ -291,6 +291,12 @@ libkernel_a_SOURCES += \
        device/kmsg.h
 endif
 
+#
+# `gnumach.tar.gz' device.
+#
+
+libkernel_a_SOURCES += \
+       device/msgids.c
 
 #
 # Version number.
@@ -493,15 +499,21 @@ nodist_libkernel_a_SOURCES += \
 #      kern/mach_host.server.defs
 
 # rpctrace can make use of that.
-MOSTLYCLEANFILES += \
-       gnumach.msgids
-gnumach.msgids: $(filter %.msgids,$(nodist_libkernel_a_SOURCES))
-       cat $^ > [EMAIL PROTECTED]
+mostlyclean-local: mostlyclean-local-gnumach-msgids
+mostlyclean-local-gnumach-msgids:
+       rm -f gnumach.msgids*
+gnumach.msgids.tar: $(filter %.msgids,$(nodist_libkernel_a_SOURCES))
+       rm -rf $@
+       mkdir $@
+       cp $^ $@/
+# Is it correct to use $(AMTAR) like this?
+       ( cd $@/ && \
+         $(AMTAR) -c * ) > [EMAIL PROTECTED]
+       rm -rf $@
        mv [EMAIL PROTECTED] $@
-# `exec_' prefix, so that we don't try to build that file during when running
-# `make install-data', as it may fail there, but isn't needed there either.
-exec_msgidsdir = $(datadir)/msgids
-exec_msgids_DATA = gnumach.msgids
+nodist_libkernel_a_SOURCES += \
+       gnumach.msgids.tar.gz.incbin.h \
+       gnumach.msgids.tar.gz.incbin.s
 
 #
 # Specific code.
Index: device/msgids.c
===================================================================
RCS file: device/msgids.c
diff -N device/msgids.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ device/msgids.c     24 Mar 2007 00:03:31 -0000
@@ -0,0 +1,87 @@
+/* A device called `msgids.tar.gz'.
+ *
+ * Copyright (C) 2007 Free Software Foundation, Inc.
+ * 
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * 
+ * Written by Thomas Schwinge.
+ */
+
+#include <string.h>
+#include <sys/types.h>
+
+#include <device/device_types.h>
+#include <device/ds_routines.h>
+#include <device/io_req.h>
+
+#include <kern/printf.h>
+
+#include <gnumach.msgids.tar.gz.incbin.h>
+
+io_return_t
+msgids_get_status (dev_t dev, int flavor, int *data, unsigned int *count)
+{
+  switch (flavor)
+    {
+    case DEV_GET_SIZE:
+      data[DEV_GET_SIZE_DEVICE_SIZE] =
+       &_gnumach_msgids_tar_gz_end - &_gnumach_msgids_tar_gz_start;
+      data[DEV_GET_SIZE_RECORD_SIZE] = 1;
+      *count = DEV_GET_SIZE_COUNT;
+      break;
+
+    default:
+      return D_INVALID_OPERATION;
+    }
+
+  return D_SUCCESS;
+}
+
+io_return_t
+msgids_read (dev_t dev, io_req_t ior)
+{
+  kern_return_t err;
+  vm_size_t len;
+
+  len = &_gnumach_msgids_tar_gz_end - &_gnumach_msgids_tar_gz_start;
+
+/*   printf ("%s: %x to %x (%u)\n", __PRETTY_FUNCTION__, */
+/*       &_gnumach_msgids_tar_gz_start, &_gnumach_msgids_tar_gz_end, len); */
+
+/*   printf ("%s: ior->io_count = %lu\tior->io_recnum = %u\n", 
__PRETTY_FUNCTION__, */
+/*       ior->io_count, ior->io_recnum); */
+
+  if (ior->io_recnum > len)
+    return D_INVALID_RECNUM;
+
+  if (ior->io_recnum + ior->io_count > len)
+    return D_INVALID_SIZE;
+
+  len = ior->io_count > len ? len : ior->io_count;
+/*   printf ("%s: len = %u\n", __PRETTY_FUNCTION__, */
+/*       len); */
+
+  err = device_read_alloc (ior, len);
+  if (err != KERN_SUCCESS)
+    return err;
+/*   printf ("%s: ior->io_alloc_size = %lu\n", __PRETTY_FUNCTION__, */
+/*       ior->io_alloc_size); */
+
+  memcpy (ior->io_data, &_gnumach_msgids_tar_gz_start + ior->io_recnum, len);
+
+  ior->io_residual = ior->io_count - len;
+
+  return D_SUCCESS;
+}
Index: i386/i386at/conf.c
===================================================================
RCS file: /cvsroot/hurd/gnumach/i386/i386at/Attic/conf.c,v
retrieving revision 1.4.2.14
diff -u -p -r1.4.2.14 conf.c
--- i386/i386at/conf.c  24 Mar 2007 00:01:35 -0000      1.4.2.14
+++ i386/i386at/conf.c  24 Mar 2007 00:03:31 -0000
@@ -65,6 +65,9 @@ extern vm_offset_t ioplmmap();
 extern int     kmsgopen(), kmsgclose(), kmsgread(), kmsggetstat();
 #define kmsgname               "kmsg"
 
+extern int     msgids_read(), msgids_get_status();
+#define msgidsname             "msgids.tar.gz"
+
 /*
  * List of devices - console must be at slot 0
  */
@@ -129,6 +132,11 @@ struct dev_ops     dev_name_list[] =
           nodev },
 #endif
 
+        { msgidsname,   nulldev,        nulldev,         msgids_read,
+          nodev,        msgids_get_status, nodev,        nomap,
+          nodev,        nulldev,        nulldev,         0,
+          nodev },
+
 };
 int    dev_name_count = sizeof(dev_name_list)/sizeof(dev_name_list[0]);
 
#v-


Regards,
 Thomas

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Bug-hurd mailing list
Bug-hurd@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-hurd

Reply via email to