From 40f440b8cd282b04599203ed3b27a0d5daa96ce4 Mon Sep 17 00:00:00 2001 From: Tomas Hruby Date: Tue, 1 Jun 2010 08:54:31 +0000 Subject: [PATCH] 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. --- kernel/system.c | 10 ++++-- kernel/system.h | 67 ++++++++++++++++++------------------- kernel/system/Makefile.inc | 1 - kernel/system/do_copy.c | 14 +++----- kernel/system/do_irqctl.c | 10 +++--- kernel/system/do_profbuf.c | 2 +- kernel/system/do_setalarm.c | 2 +- kernel/system/do_times.c | 2 +- kernel/system/do_unused.c | 16 --------- kernel/system/do_vdevio.c | 2 +- kernel/system/do_vmctl.c | 2 +- kernel/system/do_vtimer.c | 2 +- 12 files changed, 56 insertions(+), 74 deletions(-) delete mode 100644 kernel/system/do_unused.c diff --git a/kernel/system.c b/kernel/system.c index ef405463f..4cb223852 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -109,7 +109,13 @@ PRIVATE int kernel_call_dispatch(struct proc * caller, message *msg) result = ECALLDENIED; /* illegal message type */ } else { /* 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; @@ -170,7 +176,7 @@ PUBLIC void system_init(void) * if an illegal call number is used. The ordering is not important here. */ for (i=0; im_source != PM_PROC_NR && m_ptr->m_source != VFS_PROC_NR && - m_ptr->m_source != RS_PROC_NR && m_ptr->m_source != MEM_PROC_NR && - m_ptr->m_source != VM_PROC_NR) + if (caller->p_endpoint != PM_PROC_NR && caller->p_endpoint != VFS_PROC_NR && + caller->p_endpoint != RS_PROC_NR && caller->p_endpoint != MEM_PROC_NR && + caller->p_endpoint != VM_PROC_NR) { static int first=1; if (first) @@ -40,7 +40,7 @@ PUBLIC int do_copy(struct proc * caller, message * m_ptr) first= 0; printf( "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_SPACE, m_ptr->CP_DST_ENDPT, @@ -65,7 +65,7 @@ PUBLIC int do_copy(struct proc * caller, message * m_ptr) int p; /* Check if process number was given implictly with SELF and is valid. */ 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(! isokendpt(vir_addr[i].proc_nr_e, &p)) { 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); } } - - /* 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 diff --git a/kernel/system/do_irqctl.c b/kernel/system/do_irqctl.c index 2e14eedb3..08e107634 100644 --- a/kernel/system/do_irqctl.c +++ b/kernel/system/do_irqctl.c @@ -43,7 +43,7 @@ PUBLIC int do_irqctl(struct proc * caller, message * m_ptr) case IRQ_DISABLE: if (irq_hook_id >= NR_IRQ_HOOKS || irq_hook_id < 0 || 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) { enable_irq(&irq_hooks[irq_hook_id]); } @@ -76,7 +76,7 @@ PUBLIC int do_irqctl(struct proc * caller, message * m_ptr) { printf( "do_irqctl: IRQ check failed for proc %d, IRQ %d\n", - m_ptr->m_source, irq_vec); + caller->p_endpoint, irq_vec); return EPERM; } } @@ -90,7 +90,7 @@ PUBLIC int do_irqctl(struct proc * caller, message * m_ptr) /* Try to find an existing mapping to override. */ hook_ptr = NULL; for (i=0; !hook_ptr && im_source + if (irq_hooks[i].proc_nr_e == caller->p_endpoint && irq_hooks[i].notify_id == notify_id) { irq_hook_id = i; 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); /* 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->policy = m_ptr->IRQ_POLICY; /* policy for interrupts */ 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 || irq_hooks[irq_hook_id].proc_nr_e == NONE) { 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); } /* Remove the handler and return. */ diff --git a/kernel/system/do_profbuf.c b/kernel/system/do_profbuf.c index 3600f26fc..7b87df016 100644 --- a/kernel/system/do_profbuf.c +++ b/kernel/system/do_profbuf.c @@ -26,7 +26,7 @@ PUBLIC int do_profbuf(struct proc * caller, message * m_ptr) struct proc *rp; /* Store process name, control struct, table locations. */ - if(!isokendpt(m_ptr->m_source, &proc_nr)) + if(!isokendpt(caller->p_endpoint, &proc_nr)) return EDEADSRCDST; if(cprof_procs_no >= NR_SYS_PROCS) diff --git a/kernel/system/do_setalarm.c b/kernel/system/do_setalarm.c index 0825a5a36..d28007a81 100644 --- a/kernel/system/do_setalarm.c +++ b/kernel/system/do_setalarm.c @@ -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. */ 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; /* Return the ticks left on the previous alarm. */ diff --git a/kernel/system/do_times.c b/kernel/system/do_times.c index dd6d7e4c4..0de86debf 100644 --- a/kernel/system/do_times.c +++ b/kernel/system/do_times.c @@ -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 * 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)) { rp = proc_addr(proc_nr); m_ptr->T_USER_TIME = rp->p_user_time; diff --git a/kernel/system/do_unused.c b/kernel/system/do_unused.c deleted file mode 100644 index 155968ba5..000000000 --- a/kernel/system/do_unused.c +++ /dev/null @@ -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 */ -} - diff --git a/kernel/system/do_vdevio.c b/kernel/system/do_vdevio.c index d3be18e67..88524357b 100644 --- a/kernel/system/do_vdevio.c +++ b/kernel/system/do_vdevio.c @@ -94,7 +94,7 @@ PUBLIC int do_vdevio(struct proc * caller, message * m_ptr) { printf( "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; } } diff --git a/kernel/system/do_vmctl.c b/kernel/system/do_vmctl.c index b18cbde6e..c5fdbd865 100644 --- a/kernel/system/do_vmctl.c +++ b/kernel/system/do_vmctl.c @@ -22,7 +22,7 @@ PUBLIC int do_vmctl(struct proc * caller, message * m_ptr) endpoint_t ep = m_ptr->SVMCTL_WHO; 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)) { printf("do_vmctl: unexpected endpoint %d from VM\n", ep); diff --git a/kernel/system/do_vtimer.c b/kernel/system/do_vtimer.c index a3fb88377..a0c6de045 100644 --- a/kernel/system/do_vtimer.c +++ b/kernel/system/do_vtimer.c @@ -34,7 +34,7 @@ PUBLIC int do_vtimer(struct proc * caller, message * m_ptr) return(EINVAL); /* 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); rp = proc_addr(proc_nr); -- 2.44.0