syscall.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005 Martin Decky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00038 #include <syscall/syscall.h>
00039 #include <proc/thread.h>
00040 #include <proc/task.h>
00041 #include <mm/as.h>
00042 #include <print.h>
00043 #include <putchar.h>
00044 #include <errno.h>
00045 #include <arch.h>
00046 #include <debug.h>
00047 #include <ipc/sysipc.h>
00048 #include <synch/futex.h>
00049 #include <ddi/ddi.h>
00050 #include <security/cap.h>
00051 #include <syscall/copy.h>
00052 #include <sysinfo/sysinfo.h>
00053 #include <console/console.h>
00054 #include <console/klog.h>
00055 
00061 static __native sys_io(int fd, const void * buf, size_t count) 
00062 {
00063         size_t i;
00064         char *data;
00065         int rc;
00066 
00067         if (count > PAGE_SIZE)
00068                 return ELIMIT;
00069 
00070         data = malloc(count, 0);
00071         if (!data)
00072                 return ENOMEM;
00073         
00074         rc = copy_from_uspace(data, buf, count);
00075         if (rc) {
00076                 free(data);
00077                 return rc;
00078         }
00079 
00080         for (i = 0; i < count; i++)
00081                 putchar(data[i]);
00082         free(data);
00083         
00084         return count;
00085 }
00086 
00088 static __native sys_debug_enable_console(void)
00089 {
00090         arch_grab_console();
00091         return 0;
00092 }
00093 
00095 __native syscall_handler(__native a1, __native a2, __native a3,
00096                          __native a4, __native id)
00097 {
00098         __native rc;
00099 
00100         if (id < SYSCALL_END)
00101                 rc = syscall_table[id](a1,a2,a3,a4);
00102         else {
00103                 klog_printf("TASK %lld: Unknown syscall id %d",TASK->taskid,id);
00104                 task_kill(TASK->taskid);
00105                 thread_exit();
00106         }
00107                 
00108         if (THREAD->interrupted)
00109                 thread_exit();
00110         
00111         return rc;
00112 }
00113 
00114 syshandler_t syscall_table[SYSCALL_END] = {
00115         sys_io,
00116         sys_tls_set,
00117         
00118         /* Thread and task related syscalls. */
00119         sys_thread_create,
00120         sys_thread_exit,
00121         sys_task_get_id,
00122         
00123         /* Synchronization related syscalls. */
00124         sys_futex_sleep_timeout,
00125         sys_futex_wakeup,
00126         
00127         /* Address space related syscalls. */
00128         sys_as_area_create,
00129         sys_as_area_resize,
00130         sys_as_area_destroy,
00131 
00132         /* IPC related syscalls. */
00133         sys_ipc_call_sync_fast,
00134         sys_ipc_call_sync,
00135         sys_ipc_call_async_fast,
00136         sys_ipc_call_async,
00137         sys_ipc_answer_fast,
00138         sys_ipc_answer,
00139         sys_ipc_forward_fast,
00140         sys_ipc_wait_for_call,
00141         sys_ipc_hangup,
00142         sys_ipc_register_irq,
00143         sys_ipc_unregister_irq,
00144 
00145         /* Capabilities related syscalls. */
00146         sys_cap_grant,
00147         sys_cap_revoke,
00148 
00149         /* DDI related syscalls. */
00150         sys_physmem_map,
00151         sys_iospace_enable,
00152         sys_preempt_control,
00153         
00154         /* Sysinfo syscalls */
00155         sys_sysinfo_valid,
00156         sys_sysinfo_value,
00157         
00158         /* Debug calls */
00159         sys_debug_enable_console
00160 };
00161 

Generated on Sun Jun 18 17:01:58 2006 for HelenOS Kernel (mips32) by  doxygen 1.4.6