From 2656f79608c8db735514bafe8026211c92d06aa1 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sun, 27 Sep 2015 17:07:18 +0200 Subject: trans/crash: convert to trivfs dynamic classes and buckets libtrivfs contains two ways of managing more than one port class and bucket. There is the old way of using a statically allocated array with explicit length, and the new way with dynamically allocated vectors. Converting all users to the new way of handling multiple classes and/or buckets, we can simplify the code in libtrivfs. In many cases, the code will be simpler and more expressive for the user. This also fixes a mild bug. The classes and buckets given to `trivfs_startup' end up in the dynamic vectors too, making the object lookup code use the more complicated code path. * trans/crash.c: Convert to dynamic classes and buckets. --- trans/crash.c | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'trans') diff --git a/trans/crash.c b/trans/crash.c index c424b163..23f2a2d6 100644 --- a/trans/crash.c +++ b/trans/crash.c @@ -44,6 +44,10 @@ process_t procserver; /* Our proc port, for easy access. */ /* Port bucket we service requests on. */ struct port_bucket *port_bucket; +/* Our port classes. */ +struct port_class *trivfs_control_class; +struct port_class *trivfs_protid_class; + /* Trivfs hooks. */ int trivfs_fstype = FSTYPE_MISC; int trivfs_fsid = 0; @@ -52,11 +56,6 @@ int trivfs_support_write = 0; int trivfs_support_exec = 0; int trivfs_allow_open = O_READ|O_WRITE|O_EXEC; -struct port_class *trivfs_protid_portclasses[1]; -struct port_class *trivfs_cntl_portclasses[1]; -int trivfs_protid_nportclasses = 1; -int trivfs_cntl_nportclasses = 1; - struct trivfs_control *fsys; enum crash_action @@ -156,7 +155,7 @@ S_crash_dump_task (mach_port_t port, mach_port_t user_proc = MACH_PORT_NULL; enum crash_action how; - cred = ports_lookup_port (port_bucket, port, trivfs_protid_portclasses[0]); + cred = ports_lookup_port (port_bucket, port, trivfs_protid_class); if (! cred) return EOPNOTSUPP; @@ -415,11 +414,11 @@ dead_crasher (void *ptr) /* The port data structures are cleaned up when we return. */ /* See if we are going away and this was the last thing keeping us up. */ - if (ports_count_class (trivfs_cntl_portclasses[0]) == 0) + if (ports_count_class (trivfs_control_class) == 0) { /* We have no fsys control port, so we are detached from the parent filesystem. Maybe we have no users left either. */ - if (ports_count_class (trivfs_protid_portclasses[0]) == 0) + if (ports_count_class (trivfs_protid_class) == 0) { /* We have no user ports left. Maybe we have no crashers still around either. */ @@ -428,9 +427,9 @@ dead_crasher (void *ptr) exit (0); ports_enable_class (crasher_portclass); } - ports_enable_class (trivfs_protid_portclasses[0]); + ports_enable_class (trivfs_protid_class); } - ports_enable_class (trivfs_cntl_portclasses[0]); + ports_enable_class (trivfs_control_class); } @@ -563,20 +562,27 @@ main (int argc, char **argv) /* Fetch our proc server port for easy use. */ procserver = getproc (); - port_bucket = ports_create_bucket (); - trivfs_cntl_portclasses[0] = ports_create_class (trivfs_clean_cntl, 0); - trivfs_protid_portclasses[0] = ports_create_class (trivfs_clean_protid, 0); crasher_portclass = ports_create_class (dead_crasher, 0); + err = trivfs_add_control_port_class (&trivfs_control_class); + if (err) + error (1, 0, "error creating control port class"); + + err = trivfs_add_protid_port_class (&trivfs_protid_class); + if (err) + error (1, 0, "error creating protid port class"); + /* Reply to our parent. */ err = trivfs_startup (bootstrap, 0, - trivfs_cntl_portclasses[0], port_bucket, - trivfs_protid_portclasses[0], port_bucket, - &fsys); + trivfs_control_class, NULL, + trivfs_protid_class, NULL, &fsys); + mach_port_deallocate (mach_task_self (), bootstrap); if (err) error (3, err, "Contacting parent"); + port_bucket = fsys->pi.bucket; + /* Launch. */ do ports_manage_port_operations_multithread (port_bucket, crash_demuxer, @@ -602,11 +608,11 @@ trivfs_goaway (struct trivfs_control *fsys, int flags) int count; /* Stop new requests. */ - ports_inhibit_class_rpcs (trivfs_cntl_portclasses[0]); - ports_inhibit_class_rpcs (trivfs_protid_portclasses[0]); + ports_inhibit_class_rpcs (trivfs_control_class); + ports_inhibit_class_rpcs (trivfs_protid_class); /* Are there any extant user ports for the /servers/crash file? */ - count = ports_count_class (trivfs_protid_portclasses[0]); + count = ports_count_class (trivfs_protid_class); if (count == 0 || (flags & FSYS_GOAWAY_FORCE)) { /* No users. Disconnect from the filesystem. */ @@ -629,9 +635,9 @@ trivfs_goaway (struct trivfs_control *fsys, int flags) else { /* We won't go away, so start things going again... */ - ports_enable_class (trivfs_protid_portclasses[0]); - ports_resume_class_rpcs (trivfs_cntl_portclasses[0]); - ports_resume_class_rpcs (trivfs_protid_portclasses[0]); + ports_enable_class (trivfs_protid_class); + ports_resume_class_rpcs (trivfs_control_class); + ports_resume_class_rpcs (trivfs_protid_class); return EBUSY; } -- cgit v1.2.3