From a3254ced93e2db103d7395c4d5a727260ae69894 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 24 Aug 2017 16:45:49 +0200 Subject: libdiskfs: Use control class for the singleton 'bootinfo'. * libdiskfs/boot-start.c (bootinfo): New variable. (diskfs_start_bootstrap): Create 'bootinfo' as an instance of 'diskfs_control_class'. (diskfs_S_fsys_getpriv): Only allow operation on 'bootinfo'. (diskfs_S_fsys_init): Allow operation on any control object, but only once. * libdiskfs/diskfs.h (diskfs_initboot_class): Drop declaration. * libdiskfs/init-init.c (diskfs_initboot_class): Drop variable. (diskfs_init_diskfs): Adapt. --- libdiskfs/boot-start.c | 15 ++++++++------- libdiskfs/diskfs.h | 1 - libdiskfs/init-init.c | 2 -- 3 files changed, 8 insertions(+), 10 deletions(-) (limited to 'libdiskfs') diff --git a/libdiskfs/boot-start.c b/libdiskfs/boot-start.c index d0044478..1b76ebde 100644 --- a/libdiskfs/boot-start.c +++ b/libdiskfs/boot-start.c @@ -38,6 +38,10 @@ #include "fsys_S.h" #include "fsys_reply_U.h" +/* We use this port to communicate with startup. It is the only + object that fsys_getpriv and fsys_init may be invoked upon. */ +static struct port_info *bootinfo; + static mach_port_t diskfs_exec_ctl; extern task_t diskfs_exec_server_task; extern task_t diskfs_kernel_task; @@ -104,7 +108,6 @@ diskfs_start_bootstrap () char *exec_argv, *exec_env; const char *initname; size_t exec_argvlen, exec_envlen; - struct port_info *bootinfo; struct protid *rootpi; struct peropen *rootpo; mach_port_t diskfs_exec; @@ -282,11 +285,10 @@ diskfs_start_bootstrap () assert_backtrace (retry == FS_RETRY_NORMAL); assert_backtrace (pathbuf[0] == '\0'); - err = ports_create_port (diskfs_initboot_class, diskfs_port_bucket, + err = ports_create_port (diskfs_control_class, diskfs_port_bucket, sizeof (struct port_info), &bootinfo); assert_perror_backtrace (err); bootpt = ports_get_send_right (bootinfo); - ports_port_deref (bootinfo); portarray[INIT_PORT_CRDIR] = root_pt; portarray[INIT_PORT_CWDIR] = root_pt; @@ -461,7 +463,7 @@ diskfs_S_fsys_getpriv (struct diskfs_control *init_bootstrap_port, error_t err; if (!init_bootstrap_port - || init_bootstrap_port->pi.class != diskfs_initboot_class) + || init_bootstrap_port != bootinfo) return EOPNOTSUPP; err = get_privileged_ports (host_priv, dev_master); @@ -490,10 +492,9 @@ diskfs_S_fsys_init (struct diskfs_control *pt, struct protid *rootpi; struct peropen *rootpo; - if (!pt - || pt->pi.class != diskfs_initboot_class) + if (!pt) return EOPNOTSUPP; - + if (initdone) return EOPNOTSUPP; initdone = 1; diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h index ea79a1d2..402b65e5 100644 --- a/libdiskfs/diskfs.h +++ b/libdiskfs/diskfs.h @@ -216,7 +216,6 @@ struct pager; extern struct port_class *diskfs_protid_class; extern struct port_class *diskfs_control_class; extern struct port_class *diskfs_execboot_class; -extern struct port_class *diskfs_initboot_class; extern struct port_class *diskfs_shutdown_notification_class; extern struct port_bucket *diskfs_port_bucket; diff --git a/libdiskfs/init-init.c b/libdiskfs/init-init.c index e642c2e5..b9a714fe 100644 --- a/libdiskfs/init-init.c +++ b/libdiskfs/init-init.c @@ -46,7 +46,6 @@ int _diskfs_ncontrol_ports; struct port_class *diskfs_protid_class; struct port_class *diskfs_control_class; -struct port_class *diskfs_initboot_class; struct port_class *diskfs_execboot_class; struct port_class *diskfs_shutdown_notification_class; @@ -91,7 +90,6 @@ diskfs_init_diskfs (void) diskfs_protid_class = ports_create_class (diskfs_protid_rele, 0); diskfs_control_class = ports_create_class (_diskfs_control_clean, 0); - diskfs_initboot_class = ports_create_class (0, 0); diskfs_execboot_class = ports_create_class (0, 0); diskfs_shutdown_notification_class = ports_create_class (0, 0); -- cgit v1.2.3