From 76bf77a21f01f3eb5a218cc711a04895ded2676d Mon Sep 17 00:00:00 2001 From: Cristiano Giuffrida Date: Sun, 2 Mar 2014 00:47:43 +0100 Subject: [PATCH] kernel: Extend the sys_whoami() interface. Add support for init flags. Change-Id: Ibb4d7eb9064d2bbee6d51112ad0c56b2750a5f8e --- minix/include/minix/ipc.h | 3 ++- minix/include/minix/priv.h | 6 ++++++ minix/include/minix/syslib.h | 2 +- minix/kernel/main.c | 3 +++ minix/kernel/priv.h | 1 + minix/kernel/system/do_getinfo.c | 2 ++ minix/kernel/system/do_privctl.c | 4 +++- minix/lib/libsys/panic.c | 3 ++- minix/lib/libsys/sef.c | 6 +++--- minix/lib/libsys/sys_getinfo.c | 3 ++- 10 files changed, 25 insertions(+), 8 deletions(-) diff --git a/minix/include/minix/ipc.h b/minix/include/minix/ipc.h index 0f056a61d..2515a5f55 100644 --- a/minix/include/minix/ipc.h +++ b/minix/include/minix/ipc.h @@ -289,7 +289,8 @@ _ASSERT_MSG_SIZE(mess_krn_lsys_sys_fork); typedef struct { endpoint_t endpt; int privflags; - char name[48]; + int initflags; + char name[44]; } mess_krn_lsys_sys_getwhoami; _ASSERT_MSG_SIZE(mess_krn_lsys_sys_getwhoami); diff --git a/minix/include/minix/priv.h b/minix/include/minix/priv.h index 03c0665c8..d798321e4 100644 --- a/minix/include/minix/priv.h +++ b/minix/include/minix/priv.h @@ -49,6 +49,12 @@ #define USR_F (BILLABLE | PREEMPTIBLE) /* user processes */ #define IMM_F (ROOT_SYS_PROC | VM_SYS_PROC | PREEMPTIBLE) /* immutable */ +/* init flags */ +#define TSK_I 0 /* all kernel tasks */ +#define SRV_I 0 /* system services */ +#define DSRV_I 0 /* dynamic system services */ +#define USR_I 0 /* user processes */ + /* allowed traps */ #define CSK_T (1 << RECEIVE) /* clock and system */ #define TSK_T 0 /* other kernel tasks */ diff --git a/minix/include/minix/syslib.h b/minix/include/minix/syslib.h index 3e4225833..9b783fe0b 100644 --- a/minix/include/minix/syslib.h +++ b/minix/include/minix/syslib.h @@ -194,7 +194,7 @@ int sys_diagctl(int ctl, char *arg1, int arg2); int sys_getinfo(int request, void *val_ptr, int val_len, void *val_ptr2, int val_len2); int sys_whoami(endpoint_t *ep, char *name, int namelen, int - *priv_flags); + *priv_flags, int* init_flags); /* Signal control. */ int sys_kill(endpoint_t proc_ep, int sig); diff --git a/minix/kernel/main.c b/minix/kernel/main.c index fcacd5f59..8786f48ec 100644 --- a/minix/kernel/main.c +++ b/minix/kernel/main.c @@ -211,6 +211,8 @@ void kmain(kinfo_t *local_cbi) else if(iskerneln(proc_nr)) { /* Privilege flags. */ priv(rp)->s_flags = (proc_nr == IDLE ? IDL_F : TSK_F); + /* Init flags. */ + priv(rp)->s_init_flags = TSK_I; /* Allowed traps. */ priv(rp)->s_trap_mask = (proc_nr == CLOCK || proc_nr == SYSTEM ? CSK_T : TSK_T); @@ -221,6 +223,7 @@ void kmain(kinfo_t *local_cbi) else { assert(isrootsysn(proc_nr)); priv(rp)->s_flags= RSYS_F; /* privilege flags */ + priv(rp)->s_init_flags = SRV_I; /* init flags */ priv(rp)->s_trap_mask= SRV_T; /* allowed traps */ ipc_to_m = SRV_M; /* allowed targets */ kcalls = SRV_KC; /* allowed kernel calls */ diff --git a/minix/kernel/priv.h b/minix/kernel/priv.h index d38101a6d..31cf215d6 100644 --- a/minix/kernel/priv.h +++ b/minix/kernel/priv.h @@ -22,6 +22,7 @@ struct priv { proc_nr_t s_proc_nr; /* number of associated process */ sys_id_t s_id; /* index of this system structure */ short s_flags; /* PREEMTIBLE, BILLABLE, etc. */ + int s_init_flags; /* initialization flags given to the process. */ /* Asynchronous sends */ vir_bytes s_asyntab; /* addr. of table in process' address space */ diff --git a/minix/kernel/system/do_getinfo.c b/minix/kernel/system/do_getinfo.c index 6d8530a16..e47b28c1e 100644 --- a/minix/kernel/system/do_getinfo.c +++ b/minix/kernel/system/do_getinfo.c @@ -11,6 +11,7 @@ * Upon return of the GETWHOAMI request the following parameters are used: * m_krn_lsys_sys_getwhoami.endpt (the caller endpoint) * m_krn_lsys_sys_getwhoami.privflags (the caller priviledes) + * m_krn_lsys_sys_getwhoami.initflags (the caller initflags) * m_krn_lsys_sys_getwhoami.name (the caller process name) * */ @@ -136,6 +137,7 @@ int do_getinfo(struct proc * caller, message * m_ptr) strncpy(m_ptr->m_krn_lsys_sys_getwhoami.name, caller->p_name, len); m_ptr->m_krn_lsys_sys_getwhoami.name[len] = '\0'; m_ptr->m_krn_lsys_sys_getwhoami.privflags = priv(caller)->s_flags; + m_ptr->m_krn_lsys_sys_getwhoami.initflags = priv(caller)->s_init_flags; return OK; } case GET_MONPARAMS: { diff --git a/minix/kernel/system/do_privctl.c b/minix/kernel/system/do_privctl.c index bcfd1d264..aa1ed57f5 100644 --- a/minix/kernel/system/do_privctl.c +++ b/minix/kernel/system/do_privctl.c @@ -125,6 +125,7 @@ int do_privctl(struct proc * caller, message * m_ptr) /* Set defaults for privilege bitmaps. */ priv(rp)->s_flags= DSRV_F; /* privilege flags */ + priv(rp)->s_init_flags= DSRV_I; /* initialization flags */ priv(rp)->s_trap_mask= DSRV_T; /* allowed traps */ memset(&map, 0, sizeof(map)); ipc_to_m = DSRV_M; /* allowed targets */ @@ -325,8 +326,9 @@ static int update_priv(struct proc *rp, struct priv *priv) int i; - /* Copy s_flags and signal managers. */ + /* Copy flags and signal managers. */ priv(rp)->s_flags = priv->s_flags; + priv(rp)->s_init_flags = priv->s_init_flags; priv(rp)->s_sig_mgr = priv->s_sig_mgr; priv(rp)->s_bak_sig_mgr = priv->s_bak_sig_mgr; diff --git a/minix/lib/libsys/panic.c b/minix/lib/libsys/panic.c index 630a17643..6b6bbf3e9 100644 --- a/minix/lib/libsys/panic.c +++ b/minix/lib/libsys/panic.c @@ -27,10 +27,11 @@ void panic(const char *fmt, ...) endpoint_t me = NONE; char name[20]; int priv_flags; + int init_flags; void (*suicide)(void); va_list args; - if(sys_whoami(&me, name, sizeof(name), &priv_flags) == OK && me != NONE) + if(sys_whoami(&me, name, sizeof(name), &priv_flags, &init_flags) == OK && me != NONE) printf("%s(%d): panic: ", name, me); else printf("(sys_whoami failed): panic: "); diff --git a/minix/lib/libsys/sef.c b/minix/lib/libsys/sef.c index c9bdd49d8..2033f1a89 100644 --- a/minix/lib/libsys/sef.c +++ b/minix/lib/libsys/sef.c @@ -58,13 +58,13 @@ void sef_startup() int r, status; endpoint_t old_endpoint; int priv_flags; + int init_flags; /* Get information about self. */ r = sys_whoami(&sef_self_endpoint, sef_self_name, SEF_SELF_NAME_MAXLEN, - &priv_flags); + &priv_flags, &init_flags); if ( r != OK) { - sef_self_endpoint = SELF; - strlcpy(sef_self_name, "Unknown", sizeof(sef_self_name)); + panic("sef_startup: sys_whoami failed: %d\n", r); } sef_self_priv_flags = priv_flags; old_endpoint = NONE; diff --git a/minix/lib/libsys/sys_getinfo.c b/minix/lib/libsys/sys_getinfo.c index 1b1076bdf..fad4da4f2 100644 --- a/minix/lib/libsys/sys_getinfo.c +++ b/minix/lib/libsys/sys_getinfo.c @@ -29,7 +29,7 @@ int len2; /* length or process nr */ * sys_whoami * *===========================================================================*/ int sys_whoami(endpoint_t *who_ep, char *who_name, int len, - int *priv_flags) + int *priv_flags, int *init_flags) { message m; int r; @@ -49,6 +49,7 @@ int sys_whoami(endpoint_t *who_ep, char *who_name, int len, who_name[lenmin] = '\0'; *who_ep = m.m_krn_lsys_sys_getwhoami.endpt; *priv_flags = m.m_krn_lsys_sys_getwhoami.privflags; + *init_flags = m.m_krn_lsys_sys_getwhoami.initflags; return OK; } -- 2.44.0