KCall methods do not depend on m_source and m_type fields

- substituted the use of the m_source message field by
  caller->p_endpoint in kernel calls. It is the same information, just
  passed more intuitively.
  
- the last dependency on m_type field is removed.
  
- do_unused() is substituted by a check for NULL.

- this pretty much removes the depency of kernel calls on the general
  message format. In the future this may be used to pass the kcall
  arguments in a different structure or registers (x86-64, ARM?) The
  kcall number may be passed in a register already.
This commit is contained in:
Tomas Hruby 2010-06-01 08:54:31 +00:00
parent ebbd319ac0
commit 40f440b8cd
12 changed files with 56 additions and 74 deletions

View file

@ -109,7 +109,13 @@ PRIVATE int kernel_call_dispatch(struct proc * caller, message *msg)
result = ECALLDENIED; /* illegal message type */ result = ECALLDENIED; /* illegal message type */
} else { } else {
/* handle the system call */ /* handle the system call */
result = (*call_vec[call_nr])(caller, msg); if (call_vec[call_nr])
result = (*call_vec[call_nr])(caller, msg);
else {
printf("Unused kernel call %d from %d\n",
call_nr, caller->p_endpoint);
result = EBADREQUEST;
}
} }
return result; return result;
@ -170,7 +176,7 @@ PUBLIC void system_init(void)
* if an illegal call number is used. The ordering is not important here. * if an illegal call number is used. The ordering is not important here.
*/ */
for (i=0; i<NR_SYS_CALLS; i++) { for (i=0; i<NR_SYS_CALLS; i++) {
call_vec[i] = do_unused; call_vec[i] = NULL;
callnames[i] = "unused"; callnames[i] = "unused";
} }

View file

@ -1,5 +1,5 @@
/* Function prototypes for the system library. The prototypes in this file /* Function prototypes for the system library. The prototypes in this file
* are undefined to do_unused if the kernel call is not enabled in config.h. * are undefined to NULL if the kernel call is not enabled in config.h.
* The implementation is contained in src/kernel/system/. * The implementation is contained in src/kernel/system/.
* *
* The system library allows to access system services by doing a kernel call. * The system library allows to access system services by doing a kernel call.
@ -36,147 +36,144 @@
#include "proto.h" #include "proto.h"
#include "proc.h" #include "proc.h"
/* Default handler for unused kernel calls. */
_PROTOTYPE( int do_unused, (struct proc * caller, message *m_ptr) );
_PROTOTYPE( int do_exec, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_exec, (struct proc * caller, message *m_ptr) );
#if ! USE_EXEC #if ! USE_EXEC
#define do_exec do_unused #define do_exec NULL
#endif #endif
_PROTOTYPE( int do_fork, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_fork, (struct proc * caller, message *m_ptr) );
#if ! USE_FORK #if ! USE_FORK
#define do_fork do_unused #define do_fork NULL
#endif #endif
_PROTOTYPE( int do_newmap, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_newmap, (struct proc * caller, message *m_ptr) );
#if ! USE_NEWMAP #if ! USE_NEWMAP
#define do_newmap do_unused #define do_newmap NULL
#endif #endif
_PROTOTYPE( int do_clear, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_clear, (struct proc * caller, message *m_ptr) );
#if ! USE_CLEAR #if ! USE_CLEAR
#define do_clear do_unused #define do_clear NULL
#endif #endif
_PROTOTYPE( int do_trace, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_trace, (struct proc * caller, message *m_ptr) );
#if ! USE_TRACE #if ! USE_TRACE
#define do_trace do_unused #define do_trace NULL
#endif #endif
_PROTOTYPE( int do_runctl, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_runctl, (struct proc * caller, message *m_ptr) );
#if ! USE_RUNCTL #if ! USE_RUNCTL
#define do_runctl do_unused #define do_runctl NULL
#endif #endif
_PROTOTYPE( int do_update, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_update, (struct proc * caller, message *m_ptr) );
#if ! USE_UPDATE #if ! USE_UPDATE
#define do_update do_unused #define do_update NULL
#endif #endif
_PROTOTYPE( int do_exit, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_exit, (struct proc * caller, message *m_ptr) );
#if ! USE_EXIT #if ! USE_EXIT
#define do_exit do_unused #define do_exit NULL
#endif #endif
_PROTOTYPE( int do_copy, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_copy, (struct proc * caller, message *m_ptr) );
#define do_vircopy do_copy #define do_vircopy do_copy
#if ! (USE_VIRCOPY || USE_PHYSCOPY) #if ! (USE_VIRCOPY || USE_PHYSCOPY)
#define do_copy do_unused #define do_copy NULL
#endif #endif
_PROTOTYPE( int do_umap, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_umap, (struct proc * caller, message *m_ptr) );
#if ! USE_UMAP #if ! USE_UMAP
#define do_umap do_unused #define do_umap NULL
#endif #endif
_PROTOTYPE( int do_memset, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_memset, (struct proc * caller, message *m_ptr) );
#if ! USE_MEMSET #if ! USE_MEMSET
#define do_memset do_unused #define do_memset NULL
#endif #endif
_PROTOTYPE( int do_abort, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_abort, (struct proc * caller, message *m_ptr) );
#if ! USE_ABORT #if ! USE_ABORT
#define do_abort do_unused #define do_abort NULL
#endif #endif
_PROTOTYPE( int do_getinfo, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_getinfo, (struct proc * caller, message *m_ptr) );
#if ! USE_GETINFO #if ! USE_GETINFO
#define do_getinfo do_unused #define do_getinfo NULL
#endif #endif
_PROTOTYPE( int do_privctl, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_privctl, (struct proc * caller, message *m_ptr) );
#if ! USE_PRIVCTL #if ! USE_PRIVCTL
#define do_privctl do_unused #define do_privctl NULL
#endif #endif
_PROTOTYPE( int do_segctl, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_segctl, (struct proc * caller, message *m_ptr) );
#if ! USE_SEGCTL #if ! USE_SEGCTL
#define do_segctl do_unused #define do_segctl NULL
#endif #endif
_PROTOTYPE( int do_irqctl, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_irqctl, (struct proc * caller, message *m_ptr) );
#if ! USE_IRQCTL #if ! USE_IRQCTL
#define do_irqctl do_unused #define do_irqctl NULL
#endif #endif
_PROTOTYPE( int do_devio, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_devio, (struct proc * caller, message *m_ptr) );
#if ! USE_DEVIO #if ! USE_DEVIO
#define do_devio do_unused #define do_devio NULL
#endif #endif
_PROTOTYPE( int do_vdevio, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_vdevio, (struct proc * caller, message *m_ptr) );
#if ! USE_VDEVIO #if ! USE_VDEVIO
#define do_vdevio do_unused #define do_vdevio NULL
#endif #endif
_PROTOTYPE( int do_int86, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_int86, (struct proc * caller, message *m_ptr) );
_PROTOTYPE( int do_sdevio, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_sdevio, (struct proc * caller, message *m_ptr) );
#if ! USE_SDEVIO #if ! USE_SDEVIO
#define do_sdevio do_unused #define do_sdevio NULL
#endif #endif
_PROTOTYPE( int do_kill, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_kill, (struct proc * caller, message *m_ptr) );
#if ! USE_KILL #if ! USE_KILL
#define do_kill do_unused #define do_kill NULL
#endif #endif
_PROTOTYPE( int do_getksig, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_getksig, (struct proc * caller, message *m_ptr) );
#if ! USE_GETKSIG #if ! USE_GETKSIG
#define do_getksig do_unused #define do_getksig NULL
#endif #endif
_PROTOTYPE( int do_endksig, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_endksig, (struct proc * caller, message *m_ptr) );
#if ! USE_ENDKSIG #if ! USE_ENDKSIG
#define do_endksig do_unused #define do_endksig NULL
#endif #endif
_PROTOTYPE( int do_sigsend, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_sigsend, (struct proc * caller, message *m_ptr) );
#if ! USE_SIGSEND #if ! USE_SIGSEND
#define do_sigsend do_unused #define do_sigsend NULL
#endif #endif
_PROTOTYPE( int do_sigreturn, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_sigreturn, (struct proc * caller, message *m_ptr) );
#if ! USE_SIGRETURN #if ! USE_SIGRETURN
#define do_sigreturn do_unused #define do_sigreturn NULL
#endif #endif
_PROTOTYPE( int do_times, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_times, (struct proc * caller, message *m_ptr) );
#if ! USE_TIMES #if ! USE_TIMES
#define do_times do_unused #define do_times NULL
#endif #endif
_PROTOTYPE( int do_setalarm, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_setalarm, (struct proc * caller, message *m_ptr) );
#if ! USE_SETALARM #if ! USE_SETALARM
#define do_setalarm do_unused #define do_setalarm NULL
#endif #endif
_PROTOTYPE( int do_stime, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_stime, (struct proc * caller, message *m_ptr) );
_PROTOTYPE( int do_vtimer, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_vtimer, (struct proc * caller, message *m_ptr) );
#if ! USE_VTIMER #if ! USE_VTIMER
#define do_vtimer do_unused #define do_vtimer NULL
#endif #endif
_PROTOTYPE( int do_safecopy_to, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_safecopy_to, (struct proc * caller, message *m_ptr) );
@ -193,7 +190,7 @@ _PROTOTYPE( int do_safeunmap, (struct proc * caller, message *m_ptr) );
_PROTOTYPE( int do_sprofile, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_sprofile, (struct proc * caller, message *m_ptr) );
#if ! SPROFILE #if ! SPROFILE
#define do_sprofile do_unused #define do_sprofile NULL
#endif #endif
_PROTOTYPE( int do_cprofile, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_cprofile, (struct proc * caller, message *m_ptr) );
@ -202,8 +199,8 @@ _PROTOTYPE( int do_profbuf, (struct proc * caller, message *m_ptr) );
_PROTOTYPE( int do_getmcontext, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_getmcontext, (struct proc * caller, message *m_ptr) );
_PROTOTYPE( int do_setmcontext, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_setmcontext, (struct proc * caller, message *m_ptr) );
#if ! USE_MCONTEXT #if ! USE_MCONTEXT
#define do_getmcontext do_unused #define do_getmcontext NULL
#define do_setmcontext do_unused #define do_setmcontext NULL
#endif #endif
_PROTOTYPE( int do_schedule, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_schedule, (struct proc * caller, message *m_ptr) );
@ -211,7 +208,7 @@ _PROTOTYPE( int do_schedctl, (struct proc * caller, message *m_ptr) );
_PROTOTYPE( int do_statectl, (struct proc * caller, message *m_ptr) ); _PROTOTYPE( int do_statectl, (struct proc * caller, message *m_ptr) );
#if ! USE_STATECTL #if ! USE_STATECTL
#define do_statectl do_unused #define do_statectl NULL
#endif #endif
#endif /* SYSTEM_H */ #endif /* SYSTEM_H */

View file

@ -3,7 +3,6 @@
.PATH: ${.CURDIR}/system .PATH: ${.CURDIR}/system
SRCS+= \ SRCS+= \
do_unused.c \
do_fork.c \ do_fork.c \
do_exec.c \ do_exec.c \
do_newmap.c \ do_newmap.c \

View file

@ -30,9 +30,9 @@ PUBLIC int do_copy(struct proc * caller, message * m_ptr)
int i; int i;
#if 0 #if 0
if (m_ptr->m_source != PM_PROC_NR && m_ptr->m_source != VFS_PROC_NR && if (caller->p_endpoint != PM_PROC_NR && caller->p_endpoint != VFS_PROC_NR &&
m_ptr->m_source != RS_PROC_NR && m_ptr->m_source != MEM_PROC_NR && caller->p_endpoint != RS_PROC_NR && caller->p_endpoint != MEM_PROC_NR &&
m_ptr->m_source != VM_PROC_NR) caller->p_endpoint != VM_PROC_NR)
{ {
static int first=1; static int first=1;
if (first) if (first)
@ -40,7 +40,7 @@ PUBLIC int do_copy(struct proc * caller, message * m_ptr)
first= 0; first= 0;
printf( printf(
"do_copy: got request from %d (source %d, seg %d, destination %d, seg %d)\n", "do_copy: got request from %d (source %d, seg %d, destination %d, seg %d)\n",
m_ptr->m_source, caller->p_endpoint,
m_ptr->CP_SRC_ENDPT, m_ptr->CP_SRC_ENDPT,
m_ptr->CP_SRC_SPACE, m_ptr->CP_SRC_SPACE,
m_ptr->CP_DST_ENDPT, m_ptr->CP_DST_ENDPT,
@ -65,7 +65,7 @@ PUBLIC int do_copy(struct proc * caller, message * m_ptr)
int p; int p;
/* Check if process number was given implictly with SELF and is valid. */ /* Check if process number was given implictly with SELF and is valid. */
if (vir_addr[i].proc_nr_e == SELF) if (vir_addr[i].proc_nr_e == SELF)
vir_addr[i].proc_nr_e = m_ptr->m_source; vir_addr[i].proc_nr_e = caller->p_endpoint;
if (vir_addr[i].segment != PHYS_SEG) { if (vir_addr[i].segment != PHYS_SEG) {
if(! isokendpt(vir_addr[i].proc_nr_e, &p)) { if(! isokendpt(vir_addr[i].proc_nr_e, &p)) {
printf("do_copy: %d: seg 0x%x, %d not ok endpoint\n", printf("do_copy: %d: seg 0x%x, %d not ok endpoint\n",
@ -73,10 +73,6 @@ PUBLIC int do_copy(struct proc * caller, message * m_ptr)
return(EINVAL); return(EINVAL);
} }
} }
/* Check if physical addressing is used without SYS_PHYSCOPY. */
if ((vir_addr[i].segment & PHYS_SEG) &&
m_ptr->m_type != SYS_PHYSCOPY) return(EPERM);
} }
/* Check for overflow. This would happen for 64K segments and 16-bit /* Check for overflow. This would happen for 64K segments and 16-bit

View file

@ -43,7 +43,7 @@ PUBLIC int do_irqctl(struct proc * caller, message * m_ptr)
case IRQ_DISABLE: case IRQ_DISABLE:
if (irq_hook_id >= NR_IRQ_HOOKS || irq_hook_id < 0 || if (irq_hook_id >= NR_IRQ_HOOKS || irq_hook_id < 0 ||
irq_hooks[irq_hook_id].proc_nr_e == NONE) return(EINVAL); irq_hooks[irq_hook_id].proc_nr_e == NONE) return(EINVAL);
if (irq_hooks[irq_hook_id].proc_nr_e != m_ptr->m_source) return(EPERM); if (irq_hooks[irq_hook_id].proc_nr_e != caller->p_endpoint) return(EPERM);
if (m_ptr->IRQ_REQUEST == IRQ_ENABLE) { if (m_ptr->IRQ_REQUEST == IRQ_ENABLE) {
enable_irq(&irq_hooks[irq_hook_id]); enable_irq(&irq_hooks[irq_hook_id]);
} }
@ -76,7 +76,7 @@ PUBLIC int do_irqctl(struct proc * caller, message * m_ptr)
{ {
printf( printf(
"do_irqctl: IRQ check failed for proc %d, IRQ %d\n", "do_irqctl: IRQ check failed for proc %d, IRQ %d\n",
m_ptr->m_source, irq_vec); caller->p_endpoint, irq_vec);
return EPERM; return EPERM;
} }
} }
@ -90,7 +90,7 @@ PUBLIC int do_irqctl(struct proc * caller, message * m_ptr)
/* Try to find an existing mapping to override. */ /* Try to find an existing mapping to override. */
hook_ptr = NULL; hook_ptr = NULL;
for (i=0; !hook_ptr && i<NR_IRQ_HOOKS; i++) { for (i=0; !hook_ptr && i<NR_IRQ_HOOKS; i++) {
if (irq_hooks[i].proc_nr_e == m_ptr->m_source if (irq_hooks[i].proc_nr_e == caller->p_endpoint
&& irq_hooks[i].notify_id == notify_id) { && irq_hooks[i].notify_id == notify_id) {
irq_hook_id = i; irq_hook_id = i;
hook_ptr = &irq_hooks[irq_hook_id]; /* existing hook */ hook_ptr = &irq_hooks[irq_hook_id]; /* existing hook */
@ -108,7 +108,7 @@ PUBLIC int do_irqctl(struct proc * caller, message * m_ptr)
if (hook_ptr == NULL) return(ENOSPC); if (hook_ptr == NULL) return(ENOSPC);
/* Install the handler. */ /* Install the handler. */
hook_ptr->proc_nr_e = m_ptr->m_source; /* process to notify */ hook_ptr->proc_nr_e = caller->p_endpoint; /* process to notify */
hook_ptr->notify_id = notify_id; /* identifier to pass */ hook_ptr->notify_id = notify_id; /* identifier to pass */
hook_ptr->policy = m_ptr->IRQ_POLICY; /* policy for interrupts */ hook_ptr->policy = m_ptr->IRQ_POLICY; /* policy for interrupts */
put_irq_handler(hook_ptr, irq_vec, generic_handler); put_irq_handler(hook_ptr, irq_vec, generic_handler);
@ -121,7 +121,7 @@ PUBLIC int do_irqctl(struct proc * caller, message * m_ptr)
if (irq_hook_id < 0 || irq_hook_id >= NR_IRQ_HOOKS || if (irq_hook_id < 0 || irq_hook_id >= NR_IRQ_HOOKS ||
irq_hooks[irq_hook_id].proc_nr_e == NONE) { irq_hooks[irq_hook_id].proc_nr_e == NONE) {
return(EINVAL); return(EINVAL);
} else if (m_ptr->m_source != irq_hooks[irq_hook_id].proc_nr_e) { } else if (caller->p_endpoint != irq_hooks[irq_hook_id].proc_nr_e) {
return(EPERM); return(EPERM);
} }
/* Remove the handler and return. */ /* Remove the handler and return. */

View file

@ -26,7 +26,7 @@ PUBLIC int do_profbuf(struct proc * caller, message * m_ptr)
struct proc *rp; struct proc *rp;
/* Store process name, control struct, table locations. */ /* Store process name, control struct, table locations. */
if(!isokendpt(m_ptr->m_source, &proc_nr)) if(!isokendpt(caller->p_endpoint, &proc_nr))
return EDEADSRCDST; return EDEADSRCDST;
if(cprof_procs_no >= NR_SYS_PROCS) if(cprof_procs_no >= NR_SYS_PROCS)

View file

@ -34,7 +34,7 @@ PUBLIC int do_setalarm(struct proc * caller, message * m_ptr)
/* Get the timer structure and set the parameters for this alarm. */ /* Get the timer structure and set the parameters for this alarm. */
tp = &(priv(caller)->s_alarm_timer); tp = &(priv(caller)->s_alarm_timer);
tmr_arg(tp)->ta_int = m_ptr->m_source; tmr_arg(tp)->ta_int = caller->p_endpoint;
tp->tmr_func = cause_alarm; tp->tmr_func = cause_alarm;
/* Return the ticks left on the previous alarm. */ /* Return the ticks left on the previous alarm. */

View file

@ -28,7 +28,7 @@ PUBLIC int do_times(struct proc * caller, message * m_ptr)
* The clock's interrupt handler may run to update the user or system time * The clock's interrupt handler may run to update the user or system time
* while in this code, but that cannot do any harm. * while in this code, but that cannot do any harm.
*/ */
e_proc_nr = (m_ptr->T_ENDPT == SELF) ? m_ptr->m_source : m_ptr->T_ENDPT; e_proc_nr = (m_ptr->T_ENDPT == SELF) ? caller->p_endpoint : m_ptr->T_ENDPT;
if(e_proc_nr != NONE && isokendpt(e_proc_nr, &proc_nr)) { if(e_proc_nr != NONE && isokendpt(e_proc_nr, &proc_nr)) {
rp = proc_addr(proc_nr); rp = proc_addr(proc_nr);
m_ptr->T_USER_TIME = rp->p_user_time; m_ptr->T_USER_TIME = rp->p_user_time;

View file

@ -1,16 +0,0 @@
/* This file provides a catch-all handler for unused kernel calls. A kernel
* call may be unused when it is not defined or when it is disabled in the
* kernel's configuration.
*/
#include "kernel/system.h"
/*===========================================================================*
* do_unused *
*===========================================================================*/
PUBLIC int do_unused(struct proc * caller, message * m_ptr)
{
printf("SYSTEM: got unused request %d from %d\n",
m_ptr->m_type, m_ptr->m_source);
return(EBADREQUEST); /* illegal message type */
}

View file

@ -94,7 +94,7 @@ PUBLIC int do_vdevio(struct proc * caller, message * m_ptr)
{ {
printf( printf(
"do_vdevio: I/O port check failed for proc %d, port 0x%x\n", "do_vdevio: I/O port check failed for proc %d, port 0x%x\n",
m_ptr->m_source, port); caller->p_endpoint, port);
return EPERM; return EPERM;
} }
} }

View file

@ -22,7 +22,7 @@ PUBLIC int do_vmctl(struct proc * caller, message * m_ptr)
endpoint_t ep = m_ptr->SVMCTL_WHO; endpoint_t ep = m_ptr->SVMCTL_WHO;
struct proc *p, *rp, *target; struct proc *p, *rp, *target;
if(ep == SELF) { ep = m_ptr->m_source; } if(ep == SELF) { ep = caller->p_endpoint; }
if(!isokendpt(ep, &proc_nr)) { if(!isokendpt(ep, &proc_nr)) {
printf("do_vmctl: unexpected endpoint %d from VM\n", ep); printf("do_vmctl: unexpected endpoint %d from VM\n", ep);

View file

@ -34,7 +34,7 @@ PUBLIC int do_vtimer(struct proc * caller, message * m_ptr)
return(EINVAL); return(EINVAL);
/* The target process must be valid. */ /* The target process must be valid. */
proc_nr_e = (m_ptr->VT_ENDPT == SELF) ? m_ptr->m_source : m_ptr->VT_ENDPT; proc_nr_e = (m_ptr->VT_ENDPT == SELF) ? caller->p_endpoint : m_ptr->VT_ENDPT;
if (!isokendpt(proc_nr_e, &proc_nr)) return(EINVAL); if (!isokendpt(proc_nr_e, &proc_nr)) return(EINVAL);
rp = proc_addr(proc_nr); rp = proc_addr(proc_nr);