Subversion Repositories HelenOS

Rev

Rev 3623 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3623 Rev 4377
Line 30... Line 30...
30
 * @{
30
 * @{
31
 */
31
 */
32
 
32
 
33
/**
33
/**
34
 * @file
34
 * @file
35
 * @brief   Syscall table and syscall wrappers.
35
 * @brief Syscall table and syscall wrappers.
36
 */
36
 */
37
 
37
 
38
#include <syscall/syscall.h>
38
#include <syscall/syscall.h>
39
#include <proc/thread.h>
39
#include <proc/thread.h>
40
#include <proc/task.h>
40
#include <proc/task.h>
41
#include <proc/program.h>
41
#include <proc/program.h>
42
#include <mm/as.h>
42
#include <mm/as.h>
43
#include <print.h>
43
#include <print.h>
44
#include <putchar.h>
-
 
45
#include <errno.h>
-
 
46
#include <arch.h>
44
#include <arch.h>
47
#include <debug.h>
45
#include <debug.h>
-
 
46
#include <ddi/device.h>
48
#include <ipc/sysipc.h>
47
#include <ipc/sysipc.h>
49
#include <synch/futex.h>
48
#include <synch/futex.h>
50
#include <synch/smc.h>
49
#include <synch/smc.h>
51
#include <ddi/ddi.h>
50
#include <ddi/ddi.h>
-
 
51
#include <ipc/event.h>
52
#include <security/cap.h>
52
#include <security/cap.h>
53
#include <syscall/copy.h>
-
 
54
#include <sysinfo/sysinfo.h>
53
#include <sysinfo/sysinfo.h>
55
#include <console/console.h>
54
#include <console/console.h>
56
#include <udebug/udebug.h>
55
#include <udebug/udebug.h>
57
 
56
 
58
/** Print using kernel facility
-
 
59
 *
-
 
60
 * Print to kernel log.
-
 
61
 *
-
 
62
 */
-
 
63
static unative_t sys_klog(int fd, const void * buf, size_t count)
-
 
64
{
-
 
65
    size_t i;
-
 
66
    char *data;
-
 
67
    int rc;
-
 
68
 
-
 
69
    if (count > PAGE_SIZE)
-
 
70
        return ELIMIT;
-
 
71
   
-
 
72
    if (count > 0) {
-
 
73
        data = (char *) malloc(count, 0);
-
 
74
        if (!data)
-
 
75
            return ENOMEM;
-
 
76
       
-
 
77
        rc = copy_from_uspace(data, buf, count);
-
 
78
        if (rc) {
-
 
79
            free(data);
-
 
80
            return rc;
-
 
81
        }
-
 
82
   
-
 
83
        for (i = 0; i < count; i++)
-
 
84
            putchar(data[i]);
-
 
85
        free(data);
-
 
86
    } else
-
 
87
        klog_update();
-
 
88
   
-
 
89
    return count;
-
 
90
}
-
 
91
 
-
 
92
/** Tell kernel to get keyboard/console access again */
-
 
93
static unative_t sys_debug_enable_console(void)
-
 
94
{
-
 
95
    arch_grab_console();
-
 
96
    return 0;
-
 
97
}
-
 
98
 
-
 
99
/** Dispatch system call */
57
/** Dispatch system call */
100
unative_t syscall_handler(unative_t a1, unative_t a2, unative_t a3,
58
unative_t syscall_handler(unative_t a1, unative_t a2, unative_t a3,
101
    unative_t a4, unative_t a5, unative_t a6, unative_t id)
59
    unative_t a4, unative_t a5, unative_t a6, unative_t id)
102
{
60
{
103
    unative_t rc;
61
    unative_t rc;
104
 
62
   
105
#ifdef CONFIG_UDEBUG
63
#ifdef CONFIG_UDEBUG
106
    THREAD->udebug.uspace_state = NULL;
64
    THREAD->udebug.uspace_state = NULL;
107
    udebug_syscall_event(a1, a2, a3, a4, a5, a6, id, 0, false);
65
    udebug_syscall_event(a1, a2, a3, a4, a5, a6, id, 0, false);
108
#endif
66
#endif
-
 
67
   
109
    if (id < SYSCALL_END) {
68
    if (id < SYSCALL_END) {
110
        rc = syscall_table[id](a1, a2, a3, a4, a5, a6);
69
        rc = syscall_table[id](a1, a2, a3, a4, a5, a6);
111
    } else {
70
    } else {
112
        printf("Task %" PRIu64": Unknown syscall %#" PRIxn, TASK->taskid, id);
71
        printf("Task %" PRIu64": Unknown syscall %#" PRIxn, TASK->taskid, id);
113
        task_kill(TASK->taskid);
72
        task_kill(TASK->taskid);
114
        thread_exit();
73
        thread_exit();
115
    }
74
    }
116
       
75
   
117
    if (THREAD->interrupted)
76
    if (THREAD->interrupted)
118
        thread_exit();
77
        thread_exit();
119
 
78
   
120
#ifdef CONFIG_UDEBUG
79
#ifdef CONFIG_UDEBUG
121
    udebug_syscall_event(a1, a2, a3, a4, a5, a6, id, rc, true);
80
    udebug_syscall_event(a1, a2, a3, a4, a5, a6, id, rc, true);
122
 
81
   
123
    /*
82
    /*
124
     * Stopping point needed for tasks that only invoke non-blocking
83
     * Stopping point needed for tasks that only invoke non-blocking
125
     * system calls.
84
     * system calls.
126
     */
85
     */
127
    udebug_stoppable_begin();
86
    udebug_stoppable_begin();
128
    udebug_stoppable_end();
87
    udebug_stoppable_end();
129
#endif  
88
#endif
-
 
89
   
130
    return rc;
90
    return rc;
131
}
91
}
132
 
92
 
133
syshandler_t syscall_table[SYSCALL_END] = {
93
syshandler_t syscall_table[SYSCALL_END] = {
134
    (syshandler_t) sys_klog,
94
    (syshandler_t) sys_klog,
Line 138... Line 98...
138
    (syshandler_t) sys_thread_create,
98
    (syshandler_t) sys_thread_create,
139
    (syshandler_t) sys_thread_exit,
99
    (syshandler_t) sys_thread_exit,
140
    (syshandler_t) sys_thread_get_id,
100
    (syshandler_t) sys_thread_get_id,
141
   
101
   
142
    (syshandler_t) sys_task_get_id,
102
    (syshandler_t) sys_task_get_id,
-
 
103
    (syshandler_t) sys_task_set_name,
143
    (syshandler_t) sys_program_spawn_loader,
104
    (syshandler_t) sys_program_spawn_loader,
144
   
105
   
145
    /* Synchronization related syscalls. */
106
    /* Synchronization related syscalls. */
146
    (syshandler_t) sys_futex_sleep_timeout,
107
    (syshandler_t) sys_futex_sleep_timeout,
147
    (syshandler_t) sys_futex_wakeup,
108
    (syshandler_t) sys_futex_wakeup,
Line 159... Line 120...
159
    (syshandler_t) sys_ipc_call_async_fast,
120
    (syshandler_t) sys_ipc_call_async_fast,
160
    (syshandler_t) sys_ipc_call_async_slow,
121
    (syshandler_t) sys_ipc_call_async_slow,
161
    (syshandler_t) sys_ipc_answer_fast,
122
    (syshandler_t) sys_ipc_answer_fast,
162
    (syshandler_t) sys_ipc_answer_slow,
123
    (syshandler_t) sys_ipc_answer_slow,
163
    (syshandler_t) sys_ipc_forward_fast,
124
    (syshandler_t) sys_ipc_forward_fast,
-
 
125
    (syshandler_t) sys_ipc_forward_slow,
164
    (syshandler_t) sys_ipc_wait_for_call,
126
    (syshandler_t) sys_ipc_wait_for_call,
165
    (syshandler_t) sys_ipc_hangup,
127
    (syshandler_t) sys_ipc_hangup,
166
    (syshandler_t) sys_ipc_register_irq,
128
    (syshandler_t) sys_ipc_register_irq,
167
    (syshandler_t) sys_ipc_unregister_irq,
129
    (syshandler_t) sys_ipc_unregister_irq,
-
 
130
 
-
 
131
    /* Event notification syscalls. */
-
 
132
    (syshandler_t) sys_event_subscribe,
168
   
133
   
169
    /* Capabilities related syscalls. */
134
    /* Capabilities related syscalls. */
170
    (syshandler_t) sys_cap_grant,
135
    (syshandler_t) sys_cap_grant,
171
    (syshandler_t) sys_cap_revoke,
136
    (syshandler_t) sys_cap_revoke,
172
   
137
   
173
    /* DDI related syscalls. */
138
    /* DDI related syscalls. */
-
 
139
    (syshandler_t) sys_device_assign_devno,
174
    (syshandler_t) sys_physmem_map,
140
    (syshandler_t) sys_physmem_map,
175
    (syshandler_t) sys_iospace_enable,
141
    (syshandler_t) sys_iospace_enable,
176
    (syshandler_t) sys_preempt_control,
142
    (syshandler_t) sys_preempt_control,
177
   
143
   
178
    /* Sysinfo syscalls */
144
    /* Sysinfo syscalls */
179
    (syshandler_t) sys_sysinfo_valid,
145
    (syshandler_t) sys_sysinfo_valid,
180
    (syshandler_t) sys_sysinfo_value,
146
    (syshandler_t) sys_sysinfo_value,
181
   
147
   
182
    /* Debug calls */
148
    /* Debug calls */
183
    (syshandler_t) sys_debug_enable_console,
149
    (syshandler_t) sys_debug_enable_console,
-
 
150
    (syshandler_t) sys_debug_disable_console,
184
 
151
   
185
    (syshandler_t) sys_ipc_connect_kbox
152
    (syshandler_t) sys_ipc_connect_kbox
186
};
153
};
187
 
154
 
188
/** @}
155
/** @}
189
 */
156
 */