UbixOS  2.0
syscall.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/syscall.h>
30 #include <ubixos/syscalls.h>
31 #include <ubixos/sched.h>
32 #include <sys/types.h>
33 #include <ubixos/exec.h>
34 #include <sys/elf.h>
35 #include <ubixos/endtask.h>
36 #include <ubixos/time.h>
37 #include <sys/video.h>
38 #include <sys/trap.h>
39 #include <vfs/file.h>
40 #include <ubixfs/ubixfs.h>
41 #include <string.h>
42 #include <lib/kprintf.h>
43 #include <lib/kmalloc.h>
44 #include <ubixos/vitals.h>
45 /* #include <sde/sde.h> */
46 #include <mpi/mpi.h>
47 #include <vmm/vmm.h>
48 
49 //long fuword(const void *base);
50 
51 //void sdeTestThread();
52 
53 asm(
54  ".globl _sysCallNew \n"
55  "_sysCallNew: \n"
56  " pusha \n"
57  " push %ss \n"
58  " push %ds \n"
59  " push %es \n"
60  " push %fs \n"
61  " push %gs \n"
62  " cmpl totalCalls,%eax \n"
63  " jae invalidSysCallNew \n"
64  " mov %esp,%ebx \n"
65  " add $12,%ebx \n"
66  " push (%ebx) \n"
67  " call *systemCalls(,%eax,4) \n"
68  " add $4,%esp \n"
69  " jmp doneNew \n"
70  "invalidSysCallNew: \n"
71  " call InvalidSystemCall \n"
72  "doneNew: \n"
73  " pop %gs \n"
74  " pop %fs \n"
75  " pop %es \n"
76  " pop %ds \n"
77  " pop %ss \n"
78  " popa \n"
79  " iret \n"
80 );
81 
83  kprintf("attempt was made to an invalid system call\n");
84  return;
85 }
86 
87 typedef struct _UbixUser UbixUser;
88 struct _UbixUser {
89  char *username;
90  char *password;
91  int uid;
92  int gid;
93  char *home;
94  char *shell;
95 };
96 
98  kprintf("authenticating user %s\n", uu->username);
99 
100  /* MrOlsen 2016-01-01 uh?
101  if(uu->username == "root" && uu->password == "user")
102  {
103  uu->uid = 0;
104  uu->gid = 0;
105  }
106  */
107  uu->uid = -1;
108  uu->gid = -1;
109  return;
110 }
111 
112 void sysPasswd(char *passwd) {
113  kprintf("changing user password for user %d\n", _current->uid);
114  return;
115 }
116 
117 void sysAddModule() {
118  return;
119 }
120 
121 void sysRmModule() {
122  return;
123 }
124 
125 void sysGetpid(int *pid) {
126  if (pid)
127  *pid = _current->id;
128  return;
129 }
130 
131 void sysGetUid(int *uid) {
132  if (uid)
133  *uid = _current->uid;
134  return;
135 }
136 
137 void sysGetGid(int *gid) {
138  if (gid)
139  *gid = _current->gid;
140  return;
141 }
142 
143 void sysSetUid(int uid, int *status) {
144  if (_current->uid == 0x0) {
145  _current->uid = uid;
146  if (status)
147  *status = 0x0;
148  }
149  else {
150  if (status)
151  *status = 1;
152  }
153  return;
154 }
155 
156 void sysSetGid(int gid, int *status) {
157  if (_current->gid == 0x0) {
158  _current->gid = gid;
159  if (status)
160  *status = 0x0;
161  }
162  else {
163  if (status)
164  *status = 1;
165  }
166  return;
167 }
168 
169 void sysExit(int status) {
170  endTask(_current->id);
171 }
172 
173 void sysCheckPid(int pid, int *ptr) {
174  kTask_t *tmpTask = schedFindTask(pid);
175  if ((tmpTask != 0x0) && (ptr != 0x0))
176  *ptr = tmpTask->state;
177  else
178  *ptr = 0x0;
179  return;
180 }
181 
182 /************************************************************************
183 
184  Function: void sysGetFreePage();
185  Description: Allocs A Page To The Users VM Space
186  Notes:
187 
188  ************************************************************************/
189 void sysGetFreePage(long *ptr, int count, int type) {
190  if (ptr) {
191  if (type == 2)
192  *ptr = (long) vmmGetFreeVirtualPage(_current->id, count, VM_THRD);
193  else
194  *ptr = (long) vmmGetFreeVirtualPage(_current->id, count, VM_TASK);
195  }
196  return;
197 }
198 
199 void sysGetDrives(uInt32 *ptr) {
200  if (ptr)
201  *ptr = 0x0; //(uInt32)devices;
202  return;
203 }
204 
205 void sysGetUptime(uInt32 *ptr) {
206  if (ptr)
207  *ptr = systemVitals->sysTicks;
208  return;
209 }
210 
211 void sysGetTime(uInt32 *ptr) {
212  if (ptr)
214  return;
215 }
216 
217 void sysGetCwd(char *data, int len) {
218  if (data)
219  sprintf(data, "%s", _current->oInfo.cwd);
220  return;
221 }
222 
223 void sysSchedYield() {
224  sched_yield();
225 }
226 
227 void sysStartSDE() {
228  int i = 0x0;
229  for (i = 0; i < 1400; i++) {
230  asm("hlt");
231  }
232  //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0);
233  for (i = 0; i < 1400; i++) {
234  asm("hlt");
235  }
236  return;
237 }
238 
239 void invalidCall(int sys_call) {
240  kprintf("Invalid System Call #[%i]\n", sys_call);
241  return;
242 }
243 
244 /***
245  END
246  ***/
247 
sysSetUid
void sysSetUid(int uid, int *status)
Definition: syscall.c:143
taskStruct
Definition: sched.h:62
_UbixUser
Definition: syscall.c:88
syscalls.h
sysGetTime
void sysGetTime(uInt32 *ptr)
Definition: syscall.c:210
sysGetUptime
void sysGetUptime(uInt32 *ptr)
Definition: syscall.c:204
VM_THRD
#define VM_THRD
Definition: paging.h:51
uInt32
unsigned long int uInt32
Definition: objgfx30.h:49
file.h
trap.h
sysGetpid
void sysGetpid(int *pid)
Definition: syscall.c:125
uu
Definition: kprintf.c:40
string.h
video.h
sysSetGid
void sysSetGid(int gid, int *status)
Definition: syscall.c:156
vmm.h
_UbixUser::gid
int gid
Definition: syscall.c:92
endtask.h
syscall.h
exec.h
_UbixUser::password
char * password
Definition: syscall.c:90
sysRmModule
void sysRmModule()
Definition: syscall.c:121
sched.h
types.h
_UbixUser::username
char * username
Definition: syscall.c:89
sprintf
int sprintf(char *buf, const char *fmt,...)
Definition: kprintf.c:278
VM_TASK
#define VM_TASK
Definition: paging.h:52
sysGetGid
void sysGetGid(int *gid)
Definition: syscall.c:137
InvalidSystemCall
void InvalidSystemCall()
Definition: syscall.c:82
taskStruct::id
pidType id
Definition: sched.h:63
schedFindTask
kTask_t * schedFindTask(uInt32 id)
Definition: sched.c:207
vitalsStruct::timeStart
uint32_t timeStart
Definition: vitals.h:46
systemVitals
vitalsNode * systemVitals
Definition: vitals.c:35
invalidCall
void invalidCall(int sys_call)
Definition: syscall.c:238
kprintf.h
_UbixUser::home
char * home
Definition: syscall.c:93
mpi.h
time.h
vitals.h
vitalsStruct::sysTicks
uint32_t sysTicks
Definition: vitals.h:37
sysGetDrives
void sysGetDrives(uInt32 *ptr)
Definition: syscall.c:198
sys_call
void sys_call(struct trapframe *frame)
Definition: syscall.c:43
_UbixUser::shell
char * shell
Definition: syscall.c:94
endTask
void endTask(pidType)
Definition: endtask.c:44
_current
kTask_t * _current
Definition: sched.c:50
sysPasswd
void sysPasswd(char *passwd)
Definition: syscall.c:112
ubixfs.h
taskStruct::uid
uint32_t uid
Definition: sched.h:73
sysGetUid
void sysGetUid(int *uid)
Definition: syscall.c:131
taskStruct::state
tState state
Definition: sched.h:72
sysStartSDE
void sysStartSDE()
Definition: syscall.c:226
vitalsStruct::sysUptime
uint32_t sysUptime
Definition: vitals.h:38
sysCheckPid
void sysCheckPid(int pid, int *ptr)
Definition: syscall.c:173
sysGetFreePage
void sysGetFreePage(long *ptr, int count, int type)
Definition: syscall.c:188
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
elf.h
sysExit
void sysExit(int status)
Definition: syscall.c:169
kmalloc.h
taskStruct::oInfo
struct osInfo oInfo
Definition: sched.h:69
sysSchedYield
void sysSchedYield()
Definition: syscall.c:222
osInfo::cwd
char cwd[1024]
Definition: sched.h:58
sysAddModule
void sysAddModule()
Definition: syscall.c:117
sysGetCwd
void sysGetCwd(char *data, int len)
Definition: syscall.c:216
_UbixUser::uid
int uid
Definition: syscall.c:91
sysAuth
void sysAuth(UbixUser *uu)
Definition: syscall.c:97
sched_yield
void sched_yield()
Definition: sched.c:244
taskStruct::gid
uint32_t gid
Definition: sched.h:73