00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
00119 sys_thread_create,
00120 sys_thread_exit,
00121 sys_task_get_id,
00122
00123
00124 sys_futex_sleep_timeout,
00125 sys_futex_wakeup,
00126
00127
00128 sys_as_area_create,
00129 sys_as_area_resize,
00130 sys_as_area_destroy,
00131
00132
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
00146 sys_cap_grant,
00147 sys_cap_revoke,
00148
00149
00150 sys_physmem_map,
00151 sys_iospace_enable,
00152 sys_preempt_control,
00153
00154
00155 sys_sysinfo_valid,
00156 sys_sysinfo_value,
00157
00158
00159 sys_debug_enable_console
00160 };
00161