kernel: Extend the sys_whoami() interface.

Add support for init flags.

Change-Id: Ibb4d7eb9064d2bbee6d51112ad0c56b2750a5f8e
This commit is contained in:
Cristiano Giuffrida 2014-03-02 00:47:43 +01:00 committed by David van Moolenbroek
parent 41022be182
commit 76bf77a21f
10 changed files with 25 additions and 8 deletions

View file

@ -289,7 +289,8 @@ _ASSERT_MSG_SIZE(mess_krn_lsys_sys_fork);
typedef struct { typedef struct {
endpoint_t endpt; endpoint_t endpt;
int privflags; int privflags;
char name[48]; int initflags;
char name[44];
} mess_krn_lsys_sys_getwhoami; } mess_krn_lsys_sys_getwhoami;
_ASSERT_MSG_SIZE(mess_krn_lsys_sys_getwhoami); _ASSERT_MSG_SIZE(mess_krn_lsys_sys_getwhoami);

View file

@ -49,6 +49,12 @@
#define USR_F (BILLABLE | PREEMPTIBLE) /* user processes */ #define USR_F (BILLABLE | PREEMPTIBLE) /* user processes */
#define IMM_F (ROOT_SYS_PROC | VM_SYS_PROC | PREEMPTIBLE) /* immutable */ #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 */ /* allowed traps */
#define CSK_T (1 << RECEIVE) /* clock and system */ #define CSK_T (1 << RECEIVE) /* clock and system */
#define TSK_T 0 /* other kernel tasks */ #define TSK_T 0 /* other kernel tasks */

View file

@ -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 sys_getinfo(int request, void *val_ptr, int val_len, void *val_ptr2,
int val_len2); int val_len2);
int sys_whoami(endpoint_t *ep, char *name, int namelen, int int sys_whoami(endpoint_t *ep, char *name, int namelen, int
*priv_flags); *priv_flags, int* init_flags);
/* Signal control. */ /* Signal control. */
int sys_kill(endpoint_t proc_ep, int sig); int sys_kill(endpoint_t proc_ep, int sig);

View file

@ -211,6 +211,8 @@ void kmain(kinfo_t *local_cbi)
else if(iskerneln(proc_nr)) { else if(iskerneln(proc_nr)) {
/* Privilege flags. */ /* Privilege flags. */
priv(rp)->s_flags = (proc_nr == IDLE ? IDL_F : TSK_F); priv(rp)->s_flags = (proc_nr == IDLE ? IDL_F : TSK_F);
/* Init flags. */
priv(rp)->s_init_flags = TSK_I;
/* Allowed traps. */ /* Allowed traps. */
priv(rp)->s_trap_mask = (proc_nr == CLOCK priv(rp)->s_trap_mask = (proc_nr == CLOCK
|| proc_nr == SYSTEM ? CSK_T : TSK_T); || proc_nr == SYSTEM ? CSK_T : TSK_T);
@ -221,6 +223,7 @@ void kmain(kinfo_t *local_cbi)
else { else {
assert(isrootsysn(proc_nr)); assert(isrootsysn(proc_nr));
priv(rp)->s_flags= RSYS_F; /* privilege flags */ 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 */ priv(rp)->s_trap_mask= SRV_T; /* allowed traps */
ipc_to_m = SRV_M; /* allowed targets */ ipc_to_m = SRV_M; /* allowed targets */
kcalls = SRV_KC; /* allowed kernel calls */ kcalls = SRV_KC; /* allowed kernel calls */

View file

@ -22,6 +22,7 @@ struct priv {
proc_nr_t s_proc_nr; /* number of associated process */ proc_nr_t s_proc_nr; /* number of associated process */
sys_id_t s_id; /* index of this system structure */ sys_id_t s_id; /* index of this system structure */
short s_flags; /* PREEMTIBLE, BILLABLE, etc. */ short s_flags; /* PREEMTIBLE, BILLABLE, etc. */
int s_init_flags; /* initialization flags given to the process. */
/* Asynchronous sends */ /* Asynchronous sends */
vir_bytes s_asyntab; /* addr. of table in process' address space */ vir_bytes s_asyntab; /* addr. of table in process' address space */

View file

@ -11,6 +11,7 @@
* Upon return of the GETWHOAMI request the following parameters are used: * 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.endpt (the caller endpoint)
* m_krn_lsys_sys_getwhoami.privflags (the caller priviledes) * 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) * 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); 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.name[len] = '\0';
m_ptr->m_krn_lsys_sys_getwhoami.privflags = priv(caller)->s_flags; 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; return OK;
} }
case GET_MONPARAMS: { case GET_MONPARAMS: {

View file

@ -125,6 +125,7 @@ int do_privctl(struct proc * caller, message * m_ptr)
/* Set defaults for privilege bitmaps. */ /* Set defaults for privilege bitmaps. */
priv(rp)->s_flags= DSRV_F; /* privilege flags */ 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 */ priv(rp)->s_trap_mask= DSRV_T; /* allowed traps */
memset(&map, 0, sizeof(map)); memset(&map, 0, sizeof(map));
ipc_to_m = DSRV_M; /* allowed targets */ ipc_to_m = DSRV_M; /* allowed targets */
@ -325,8 +326,9 @@ static int update_priv(struct proc *rp, struct priv *priv)
int i; int i;
/* Copy s_flags and signal managers. */ /* Copy flags and signal managers. */
priv(rp)->s_flags = priv->s_flags; 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_sig_mgr = priv->s_sig_mgr;
priv(rp)->s_bak_sig_mgr = priv->s_bak_sig_mgr; priv(rp)->s_bak_sig_mgr = priv->s_bak_sig_mgr;

View file

@ -27,10 +27,11 @@ void panic(const char *fmt, ...)
endpoint_t me = NONE; endpoint_t me = NONE;
char name[20]; char name[20];
int priv_flags; int priv_flags;
int init_flags;
void (*suicide)(void); void (*suicide)(void);
va_list args; 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); printf("%s(%d): panic: ", name, me);
else else
printf("(sys_whoami failed): panic: "); printf("(sys_whoami failed): panic: ");

View file

@ -58,13 +58,13 @@ void sef_startup()
int r, status; int r, status;
endpoint_t old_endpoint; endpoint_t old_endpoint;
int priv_flags; int priv_flags;
int init_flags;
/* Get information about self. */ /* Get information about self. */
r = sys_whoami(&sef_self_endpoint, sef_self_name, SEF_SELF_NAME_MAXLEN, r = sys_whoami(&sef_self_endpoint, sef_self_name, SEF_SELF_NAME_MAXLEN,
&priv_flags); &priv_flags, &init_flags);
if ( r != OK) { if ( r != OK) {
sef_self_endpoint = SELF; panic("sef_startup: sys_whoami failed: %d\n", r);
strlcpy(sef_self_name, "Unknown", sizeof(sef_self_name));
} }
sef_self_priv_flags = priv_flags; sef_self_priv_flags = priv_flags;
old_endpoint = NONE; old_endpoint = NONE;

View file

@ -29,7 +29,7 @@ int len2; /* length or process nr */
* sys_whoami * * sys_whoami *
*===========================================================================*/ *===========================================================================*/
int sys_whoami(endpoint_t *who_ep, char *who_name, int len, int sys_whoami(endpoint_t *who_ep, char *who_name, int len,
int *priv_flags) int *priv_flags, int *init_flags)
{ {
message m; message m;
int r; int r;
@ -49,6 +49,7 @@ int sys_whoami(endpoint_t *who_ep, char *who_name, int len,
who_name[lenmin] = '\0'; who_name[lenmin] = '\0';
*who_ep = m.m_krn_lsys_sys_getwhoami.endpt; *who_ep = m.m_krn_lsys_sys_getwhoami.endpt;
*priv_flags = m.m_krn_lsys_sys_getwhoami.privflags; *priv_flags = m.m_krn_lsys_sys_getwhoami.privflags;
*init_flags = m.m_krn_lsys_sys_getwhoami.initflags;
return OK; return OK;
} }