UbixOS V2 2.0

syscall_posix.c
Go to the documentation of this file.
1 /*-
2 * Copyright (c) 2002-2018 The UbixOS Project.
3 * All rights reserved.
4 *
5 * This was developed by Christopher W. Olsen for the UbixOS Project.
6 *
7 * Redistribution and use in source and binary forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright notice, this list of
11 * conditions, the following disclaimer and the list of authors.
12 * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13 * conditions, the following disclaimer and the list of authors in the documentation and/or
14 * other materials provided with the distribution.
15 * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16 * endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <ubixos/syscalls.h>
30 #include <ubixos/syscall.h>
31 #include <ubixos/sched.h>
32 #include <ubixos/endtask.h>
33 #include <ubixos/spinlock.h>
34 #include <sys/trap.h>
35 #include <sys/elf.h>
36 #include <string.h>
37 #include <lib/kprintf.h>
38 #include <ubixos/kpanic.h>
39
40 struct spinLock Master = SPIN_LOCK_INITIALIZER;
41
42 void sys_call_posix(struct trapframe *frame) {
43 uint32_t code = 0x0;
44 caddr_t params;
45
46 /*
47 if (_current->id == 6)
48 kprintf("SYSCALL: 0x%X.", frame->tf_eip);
49 */
50
51 struct thread *td = &_current->td;
52
53 td->frame = frame;
54
55 int args[8];
56 int error = 0x0;
57
58 params = (caddr_t) frame->tf_esp + sizeof(int);
59
60 code = frame->tf_eax;
61
62 if (code == 198) {
63 memcpy(&code, params, sizeof(int));
64 params += sizeof(quad_t);
65 }
66
67 if (code > totalCalls_posix) {
68 kprintf("pCall [%i]\n", code);
69 die_if_kernel("Invalid System pCall", frame, frame->tf_eax);
70 kpanic("PID: %i", _current->id);
71 }
72 else if ((int) systemCalls_posix[code].sc_status == SYSCALL_INVALID) {
73 kprintf("Invalid Call: [%i][%s]\n", code, systemCalls_posix[code].sc_name);
74 frame->tf_eax = -1;
75 frame->tf_edx = 0x0;
76 frame->tf_eflags |= PSL_C;
77 }
78 else if ((int) systemCalls_posix[code].sc_status == SYSCALL_NOTIMP) {
79 kprintf("Not Implemented Call: [%i][%s]\n", code, systemCalls_posix[code].sc_name);
80 frame->tf_eax = 22;//-1;
81 frame->tf_edx = 0x0;
82 frame->tf_eflags |= PSL_C;
83 }
84 else {
85 td->td_retval[0] = 0;
86 td->td_retval[1] = frame->tf_edx;
87
88 if (systemCalls_posix[code].sc_status == SYSCALL_DUMMY)
89 kprintf("Syscall->abi: [%i], PID: [%i], Code: %i, Call: %s\n", td->abi, _current->id, frame->tf_eax, systemCalls[code].sc_name);
90
91 /*
92 if ( td->abi == ELFOSABI_UBIXOS )
93 error = (int) systemCalls[code].sc_entry( frame->tf_ebx, frame->tf_ecx, frame->tf_edx );
94 */
95
96 if (td->abi == ELFOSABI_FREEBSD)
97 error = (int) systemCalls_posix[code].sc_entry(td, params);
98 else
99 error = (int) systemCalls_posix[code].sc_entry(td, params);
100
101 if (systemCalls_posix[code].sc_status == SYSCALL_DUMMY) {
102 kprintf("RET(%i)1", code);
103 return;
104 }
105
106 switch (error) {
107 case 0:
108 frame->tf_eax = td->td_retval[0];
109 frame->tf_edx = td->td_retval[1];
110 frame->tf_eflags &= ~PSL_C;
111 if (systemCalls_posix[code].sc_status == SYSCALL_DUMMY)
112 kprintf("RET3");
113 break;
114 default:
115 frame->tf_eax = td->td_retval[0];
116 frame->tf_edx = td->td_retval[1];
117 frame->tf_eflags |= PSL_C;
118 kprintf("SC[%i][%s][%i][%i]\n", code, systemCalls_posix[code].sc_name, frame->tf_eax, frame->tf_edx);
119 break;
120 }
121 }
122 }
123
124 int invalidCall_posix() {
125 int sys_call;
126
127 asm(
128 "nop"
129 : "=a" (sys_call)
130 :
131 );
132
133 kprintf("Invalid System Call #[%i], PID: %i\n", sys_call, _current->id);
134 return (0);
135 }
syscalls.h
spinlock.h
invalidCall_posix
int invalidCall_posix()
Definition: syscall_posix.c:124
trap.h
string.h
sys_call
void sys_call(struct trapframe *frame)
Definition: syscall.c:43
thread
Definition: thread.h:40
PSL_C
#define PSL_C
Definition: cpu.h:37
endtask.h
syscall.h
SPIN_LOCK_INITIALIZER
#define SPIN_LOCK_INITIALIZER
Definition: spinlock.h:36
sched.h
kpanic
void kpanic(const char *fmt,...)
print panic message and halt system
Definition: kpanic.c:41
trapframe::tf_eflags
int tf_eflags
Definition: trap.h:52
quad_t
__int64_t quad_t
Definition: types.h:57
memcpy
void * memcpy(const void *dst, const void *src, size_t length)
systemCalls
struct syscall_entry systemCalls[]
Definition: syscalls.c:34
taskStruct::td
struct thread td
Definition: sched.h:78
kpanic.h
taskStruct::id
pidType id
Definition: sched.h:63
syscall_entry::sc_name
char * sc_name
Definition: syscalls.h:53
ELFOSABI_FREEBSD
#define ELFOSABI_FREEBSD
Definition: elf_common.h:164
thread::td_retval
int td_retval[2]
Definition: thread.h:41
trapframe::tf_eax
int tf_eax
Definition: trap.h:46
kprintf.h
SYSCALL_INVALID
#define SYSCALL_INVALID
Definition: syscalls.h:44
thread::abi
int abi
Definition: thread.h:48
uint32_t
__uint32_t uint32_t
Definition: types.h:46
trapframe
Definition: trap.h:34
SYSCALL_NOTIMP
#define SYSCALL_NOTIMP
Definition: syscalls.h:47
thread::frame
struct trapframe * frame
Definition: thread.h:47
SYSCALL_DUMMY
#define SYSCALL_DUMMY
Definition: syscalls.h:46
caddr_t
char * caddr_t
Definition: types.h:41
_current
kTask_t * _current
Definition: sched.c:50
Master
struct spinLock Master
Definition: syscall_posix.c:40
sys_call_posix
void sys_call_posix(struct trapframe *frame)
Definition: syscall_posix.c:42
spinLock
Definition: spinlock.h:41
die_if_kernel
void die_if_kernel(char *str, struct trapframe *regs, long err)
Definition: trap.c:59
trapframe::tf_esp
int tf_esp
Definition: trap.h:54
trapframe::tf_edx
int tf_edx
Definition: trap.h:44
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
elf.h
totalCalls_posix
int totalCalls_posix
Definition: syscalls_posix.c:2791
systemCalls_posix
struct syscall_entry systemCalls_posix[]
Definition: syscalls_posix.c:33