Subversion Repositories HelenOS

Rev

Rev 3149 | Rev 3153 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3149 Rev 3150
1
/*
1
/*
2
 * Copyright (c) 2005 Martin Decky
2
 * Copyright (c) 2005 Martin Decky
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup generic
29
/** @addtogroup generic
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 <mm/as.h>
41
#include <mm/as.h>
42
#include <print.h>
42
#include <print.h>
43
#include <putchar.h>
43
#include <putchar.h>
44
#include <errno.h>
44
#include <errno.h>
45
#include <arch.h>
45
#include <arch.h>
46
#include <debug.h>
46
#include <debug.h>
47
#include <ipc/sysipc.h>
47
#include <ipc/sysipc.h>
48
#include <synch/futex.h>
48
#include <synch/futex.h>
49
#include <ddi/ddi.h>
49
#include <ddi/ddi.h>
50
#include <security/cap.h>
50
#include <security/cap.h>
51
#include <syscall/copy.h>
51
#include <syscall/copy.h>
52
#include <sysinfo/sysinfo.h>
52
#include <sysinfo/sysinfo.h>
53
#include <console/console.h>
53
#include <console/console.h>
54
 
54
 
55
/** Print using kernel facility
55
/** Print using kernel facility
56
 *
56
 *
57
 * Print to kernel log.
57
 * Print to kernel log.
58
 *
58
 *
59
 */
59
 */
60
static unative_t sys_io(int fd, const void * buf, size_t count)
60
static unative_t sys_io(int fd, const void * buf, size_t count)
61
{
61
{
62
    size_t i;
62
    size_t i;
63
    char *data;
63
    char *data;
64
    int rc;
64
    int rc;
65
 
65
 
66
    if (count > PAGE_SIZE)
66
    if (count > PAGE_SIZE)
67
        return ELIMIT;
67
        return ELIMIT;
68
 
68
 
69
    data = (char *) malloc(count, 0);
69
    data = (char *) malloc(count, 0);
70
    if (!data)
70
    if (!data)
71
        return ENOMEM;
71
        return ENOMEM;
72
   
72
   
73
    rc = copy_from_uspace(data, buf, count);
73
    rc = copy_from_uspace(data, buf, count);
74
    if (rc) {
74
    if (rc) {
75
        free(data);
75
        free(data);
76
        return rc;
76
        return rc;
77
    }
77
    }
78
 
78
 
79
    for (i = 0; i < count; i++)
79
    for (i = 0; i < count; i++)
80
        putchar(data[i]);
80
        putchar(data[i]);
81
    free(data);
81
    free(data);
82
   
82
   
83
    return count;
83
    return count;
84
}
84
}
85
 
85
 
86
/** Tell kernel to get keyboard/console access again */
86
/** Tell kernel to get keyboard/console access again */
87
static unative_t sys_debug_enable_console(void)
87
static unative_t sys_debug_enable_console(void)
88
{
88
{
89
    arch_grab_console();
89
    arch_grab_console();
90
    return 0;
90
    return 0;
91
}
91
}
92
 
92
 
93
/** Print a hex integer into klog */
93
/** Print a hex integer into klog */
94
static unative_t sys_debug_putint(unative_t i)
94
static unative_t sys_debug_putint(unative_t i)
95
{
95
{
96
    klog_printf("[task:0x%x]", i);
96
    printf("[task:0x%x]", i);
97
    return 0;
97
    return 0;
98
}
98
}
99
 
99
 
100
/** Dispatch system call */
100
/** Dispatch system call */
101
unative_t syscall_handler(unative_t a1, unative_t a2, unative_t a3,
101
unative_t syscall_handler(unative_t a1, unative_t a2, unative_t a3,
102
    unative_t a4, unative_t a5, unative_t a6, unative_t id)
102
    unative_t a4, unative_t a5, unative_t a6, unative_t id)
103
{
103
{
104
    unative_t rc;
104
    unative_t rc;
105
 
105
 
106
    if (id < SYSCALL_END)
106
    if (id < SYSCALL_END)
107
        rc = syscall_table[id](a1, a2, a3, a4, a5, a6);
107
        rc = syscall_table[id](a1, a2, a3, a4, a5, a6);
108
    else {
108
    else {
109
        printf("Task %" PRIu64": Unknown syscall %#" PRIxn, TASK->taskid, id);
109
        printf("Task %" PRIu64": Unknown syscall %#" PRIxn, TASK->taskid, id);
110
        task_kill(TASK->taskid);
110
        task_kill(TASK->taskid);
111
        thread_exit();
111
        thread_exit();
112
    }
112
    }
113
       
113
       
114
    if (THREAD->interrupted)
114
    if (THREAD->interrupted)
115
        thread_exit();
115
        thread_exit();
116
   
116
   
117
    return rc;
117
    return rc;
118
}
118
}
119
 
119
 
120
syshandler_t syscall_table[SYSCALL_END] = {
120
syshandler_t syscall_table[SYSCALL_END] = {
121
    (syshandler_t) sys_io,
121
    (syshandler_t) sys_io,
122
    (syshandler_t) sys_tls_set,
122
    (syshandler_t) sys_tls_set,
123
   
123
   
124
    /* Thread and task related syscalls. */
124
    /* Thread and task related syscalls. */
125
    (syshandler_t) sys_thread_create,
125
    (syshandler_t) sys_thread_create,
126
    (syshandler_t) sys_thread_exit,
126
    (syshandler_t) sys_thread_exit,
127
    (syshandler_t) sys_thread_get_id,
127
    (syshandler_t) sys_thread_get_id,
128
   
128
   
129
    (syshandler_t) sys_task_get_id,
129
    (syshandler_t) sys_task_get_id,
130
    (syshandler_t) sys_task_spawn,
130
    (syshandler_t) sys_task_spawn,
131
    (syshandler_t) sys_task_spawn_loader,
131
    (syshandler_t) sys_task_spawn_loader,
132
   
132
   
133
    /* Synchronization related syscalls. */
133
    /* Synchronization related syscalls. */
134
    (syshandler_t) sys_futex_sleep_timeout,
134
    (syshandler_t) sys_futex_sleep_timeout,
135
    (syshandler_t) sys_futex_wakeup,
135
    (syshandler_t) sys_futex_wakeup,
136
   
136
   
137
    /* Address space related syscalls. */
137
    /* Address space related syscalls. */
138
    (syshandler_t) sys_as_area_create,
138
    (syshandler_t) sys_as_area_create,
139
    (syshandler_t) sys_as_area_resize,
139
    (syshandler_t) sys_as_area_resize,
140
    (syshandler_t) sys_as_area_change_flags,
140
    (syshandler_t) sys_as_area_change_flags,
141
    (syshandler_t) sys_as_area_destroy,
141
    (syshandler_t) sys_as_area_destroy,
142
   
142
   
143
    /* IPC related syscalls. */
143
    /* IPC related syscalls. */
144
    (syshandler_t) sys_ipc_call_sync_fast,
144
    (syshandler_t) sys_ipc_call_sync_fast,
145
    (syshandler_t) sys_ipc_call_sync_slow,
145
    (syshandler_t) sys_ipc_call_sync_slow,
146
    (syshandler_t) sys_ipc_call_async_fast,
146
    (syshandler_t) sys_ipc_call_async_fast,
147
    (syshandler_t) sys_ipc_call_async_slow,
147
    (syshandler_t) sys_ipc_call_async_slow,
148
    (syshandler_t) sys_ipc_answer_fast,
148
    (syshandler_t) sys_ipc_answer_fast,
149
    (syshandler_t) sys_ipc_answer_slow,
149
    (syshandler_t) sys_ipc_answer_slow,
150
    (syshandler_t) sys_ipc_forward_fast,
150
    (syshandler_t) sys_ipc_forward_fast,
151
    (syshandler_t) sys_ipc_wait_for_call,
151
    (syshandler_t) sys_ipc_wait_for_call,
152
    (syshandler_t) sys_ipc_hangup,
152
    (syshandler_t) sys_ipc_hangup,
153
    (syshandler_t) sys_ipc_register_irq,
153
    (syshandler_t) sys_ipc_register_irq,
154
    (syshandler_t) sys_ipc_unregister_irq,
154
    (syshandler_t) sys_ipc_unregister_irq,
155
   
155
   
156
    /* Capabilities related syscalls. */
156
    /* Capabilities related syscalls. */
157
    (syshandler_t) sys_cap_grant,
157
    (syshandler_t) sys_cap_grant,
158
    (syshandler_t) sys_cap_revoke,
158
    (syshandler_t) sys_cap_revoke,
159
   
159
   
160
    /* DDI related syscalls. */
160
    /* DDI related syscalls. */
161
    (syshandler_t) sys_physmem_map,
161
    (syshandler_t) sys_physmem_map,
162
    (syshandler_t) sys_iospace_enable,
162
    (syshandler_t) sys_iospace_enable,
163
    (syshandler_t) sys_preempt_control,
163
    (syshandler_t) sys_preempt_control,
164
   
164
   
165
    /* Sysinfo syscalls */
165
    /* Sysinfo syscalls */
166
    (syshandler_t) sys_sysinfo_valid,
166
    (syshandler_t) sys_sysinfo_valid,
167
    (syshandler_t) sys_sysinfo_value,
167
    (syshandler_t) sys_sysinfo_value,
168
   
168
   
169
    /* Debug calls */
169
    /* Debug calls */
170
    (syshandler_t) sys_debug_putint,
170
    (syshandler_t) sys_debug_putint,
171
    (syshandler_t) sys_debug_enable_console
171
    (syshandler_t) sys_debug_enable_console
172
};
172
};
173
 
173
 
174
/** @}
174
/** @}
175
 */
175
 */
176
 
176