From: Ben Gras Date: Fri, 16 Jul 2010 15:36:29 +0000 (+0000) Subject: kernel - prettier output for ipc errors, call names instead of trap numbers X-Git-Tag: v3.1.8~209 X-Git-Url: http://zhaoyanbai.com/repos/%22../static/icons/man.3.ps?a=commitdiff_plain;h=b05c98929817e7065b8e27e557f4cd0eaa699520;p=minix.git kernel - prettier output for ipc errors, call names instead of trap numbers --- diff --git a/include/minix/ipcconst.h b/include/minix/ipcconst.h index c077b2c9e..acbd7ab12 100644 --- a/include/minix/ipcconst.h +++ b/include/minix/ipcconst.h @@ -8,6 +8,7 @@ #define NOTIFY 4 /* asynchronous notify */ #define SENDNB 5 /* nonblocking send */ #define SENDA 16 /* asynchronous send */ +#define IPCNO_HIGHEST SENDA /* Macros for IPC status code manipulation. */ #define IPC_STATUS_CALL_SHIFT 0 diff --git a/kernel/glo.h b/kernel/glo.h index ae8a58385..d7390fd49 100644 --- a/kernel/glo.h +++ b/kernel/glo.h @@ -12,6 +12,7 @@ #endif #include +#include #include #include "archconst.h" #include "config.h" @@ -29,7 +30,7 @@ EXTERN struct proc *proc_ptr; /* pointer to currently running process */ EXTERN struct proc *bill_ptr; /* process to bill for clock ticks */ EXTERN struct proc *vmrequest; /* first process on vmrequest queue */ EXTERN unsigned lost_ticks; /* clock ticks counted outside clock task */ - +EXTERN char *ipc_call_names[IPCNO_HIGHEST+1]; /* human-readable call names */ /* Interrupt related variables. */ EXTERN irq_hook_t irq_hooks[NR_IRQ_HOOKS]; /* hooks for general use */ diff --git a/kernel/main.c b/kernel/main.c index f0aab345b..049a1a0da 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -255,6 +255,19 @@ PUBLIC int main(void) cycles_accounting_init(); DEBUGEXTRA(("done\n")); +#define IPCNAME(n) { \ + assert((n) >= 0 && (n) <= IPCNO_HIGHEST); \ + assert(!ipc_call_names[n]); \ + ipc_call_names[n] = #n; \ +} + + IPCNAME(SEND); + IPCNAME(RECEIVE); + IPCNAME(SENDREC); + IPCNAME(NOTIFY); + IPCNAME(SENDNB); + IPCNAME(SENDA); + assert(runqueues_ok()); switch_to_user(); diff --git a/kernel/proc.c b/kernel/proc.c index 6d256e350..f5f71a4fa 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -254,6 +255,7 @@ PRIVATE int do_sync_ipc(struct proc * caller_ptr, /* who made the call */ { int result; /* the system call's result */ int src_dst_p; /* Process slot number */ + char *callname; /* Check destination. RECEIVE is the only call that accepts ANY (in addition * to a real endpoint). The other calls (SEND, SENDREC, and NOTIFY) require an @@ -262,13 +264,24 @@ PRIVATE int do_sync_ipc(struct proc * caller_ptr, /* who made the call */ */ assert(call_nr != SENDA); + /* Only allow non-negative call_nr values less than 32 */ + if (call_nr < 0 || call_nr > IPCNO_HIGHEST || call_nr >= 32 + || !(callname = ipc_call_names[call_nr])) { +#if DEBUG_ENABLE_IPC_WARNINGS + printf("sys_call: trap %d not allowed, caller %d, src_dst %d\n", + call_nr, proc_nr(caller_ptr), src_dst_p); +#endif + return(ETRAPDENIED); /* trap denied by mask or kernel */ + } + if (src_dst_e == ANY) { if (call_nr != RECEIVE) { #if 0 - printf("sys_call: trap %d by %d with bad endpoint %d\n", - call_nr, proc_nr(caller_ptr), src_dst_e); + printf("sys_call: %s by %d with bad endpoint %d\n", + callname, + proc_nr(caller_ptr), src_dst_e); #endif return EINVAL; } @@ -279,8 +292,9 @@ PRIVATE int do_sync_ipc(struct proc * caller_ptr, /* who made the call */ /* Require a valid source and/or destination process. */ if(!isokendpt(src_dst_e, &src_dst_p)) { #if 0 - printf("sys_call: trap %d by %d with bad endpoint %d\n", - call_nr, proc_nr(caller_ptr), src_dst_e); + printf("sys_call: %s by %d with bad endpoint %d\n", + callname, + proc_nr(caller_ptr), src_dst_e); #endif return EDEADSRCDST; } @@ -294,32 +308,23 @@ PRIVATE int do_sync_ipc(struct proc * caller_ptr, /* who made the call */ if (!may_send_to(caller_ptr, src_dst_p)) { #if DEBUG_ENABLE_IPC_WARNINGS printf( - "sys_call: ipc mask denied trap %d from %d to %d\n", - call_nr, caller_ptr->p_endpoint, src_dst_e); + "sys_call: ipc mask denied %s from %d to %d\n", + callname, + caller_ptr->p_endpoint, src_dst_e); #endif return(ECALLDENIED); /* call denied by ipc mask */ } } } - /* Only allow non-negative call_nr values less than 32 */ - if (call_nr < 0 || call_nr >= 32) - { -#if DEBUG_ENABLE_IPC_WARNINGS - printf("sys_call: trap %d not allowed, caller %d, src_dst %d\n", - call_nr, proc_nr(caller_ptr), src_dst_p); -#endif - return(ETRAPDENIED); /* trap denied by mask or kernel */ - } - /* Check if the process has privileges for the requested call. Calls to the * kernel may only be SENDREC, because tasks always reply and may not block * if the caller doesn't do receive(). */ if (!(priv(caller_ptr)->s_trap_mask & (1 << call_nr))) { #if DEBUG_ENABLE_IPC_WARNINGS - printf("sys_call: trap %d not allowed, caller %d, src_dst %d\n", - call_nr, proc_nr(caller_ptr), src_dst_p); + printf("sys_call: %s not allowed, caller %d, src_dst %d\n", + callname, proc_nr(caller_ptr), src_dst_p); #endif return(ETRAPDENIED); /* trap denied by mask or kernel */ } @@ -327,7 +332,7 @@ PRIVATE int do_sync_ipc(struct proc * caller_ptr, /* who made the call */ if (call_nr != SENDREC && call_nr != RECEIVE && iskerneln(src_dst_p)) { #if DEBUG_ENABLE_IPC_WARNINGS printf("sys_call: trap %d not allowed, caller %d, src_dst %d\n", - call_nr, proc_nr(caller_ptr), src_dst_e); + callname, proc_nr(caller_ptr), src_dst_e); #endif return(ETRAPDENIED); /* trap denied by mask or kernel */ }