SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

Diff markup

Differences between /sos/syscall.c (Article 8) and /sos/syscall.c (Article 9)


001 /* Copyright (C) 2005  David Decotigny            001 /* Copyright (C) 2005  David Decotigny
002                                                   002 
003    This program is free software; you can redi    003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU Genera    004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundatio    005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any lat    006    of the License, or (at your option) any later version.
007                                                   007    
008    This program is distributed in the hope tha    008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the     009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR    010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details    011    GNU General Public License for more details.
012                                                   012    
013    You should have received a copy of the GNU     013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to t    014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 3    015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA.                                           016    USA. 
017 */                                                017 */
018 #include <sos/thread.h>                           018 #include <sos/thread.h>
019 #include <sos/kmalloc.h>                          019 #include <sos/kmalloc.h>
020 #include <sos/klibc.h>                            020 #include <sos/klibc.h>
021 #include <drivers/bochs.h>                        021 #include <drivers/bochs.h>
022 #include <hwcore/paging.h>                        022 #include <hwcore/paging.h>
023 #include <sos/physmem.h>                          023 #include <sos/physmem.h>
024 #include <sos/umem_vmm.h>                         024 #include <sos/umem_vmm.h>
025 #include <drivers/zero.h>                         025 #include <drivers/zero.h>
026 #include <drivers/mem.h>                          026 #include <drivers/mem.h>
027 #include <sos/binfmt_elf32.h>                     027 #include <sos/binfmt_elf32.h>
028                                                   028 
029 #include <hwcore/cpu_context.h>                   029 #include <hwcore/cpu_context.h>
030 #include <sos/uaccess.h>                          030 #include <sos/uaccess.h>
031 #include "syscall.h"                              031 #include "syscall.h"
032                                                   032 
033                                                << 
034 /**                                               033 /**
035  * THE syscall entry point                        034  * THE syscall entry point
036  */                                               035  */
037 sos_ret_t sos_do_syscall(int syscall_id,          036 sos_ret_t sos_do_syscall(int syscall_id,
038                          const struct sos_cpu_    037                          const struct sos_cpu_state *user_ctxt)
039 {                                                 038 {
040   sos_ret_t retval;                               039   sos_ret_t retval;
041                                                   040 
042   switch(syscall_id)                              041   switch(syscall_id)
043     {                                             042     {
044     case SOS_SYSCALL_ID_EXIT:                     043     case SOS_SYSCALL_ID_EXIT:
045       {                                           044       {
046         unsigned int status;                      045         unsigned int status;
047                                                   046 
048         retval = sos_syscall_get1arg(user_ctxt    047         retval = sos_syscall_get1arg(user_ctxt, & status);
049         if (SOS_OK != retval)                     048         if (SOS_OK != retval)
050           break;                                  049           break;
051         sos_thread_exit();                        050         sos_thread_exit();
052         retval = -SOS_EFATAL; /* Not reached *    051         retval = -SOS_EFATAL; /* Not reached */
053       }                                           052       }
054       break;                                      053       break;
055                                                   054 
056     case SOS_SYSCALL_ID_FORK:                     055     case SOS_SYSCALL_ID_FORK:
057       {                                           056       {
058         struct sos_thread *cur_thr, *new_thr;     057         struct sos_thread *cur_thr, *new_thr;
059         struct sos_process *new_proc;             058         struct sos_process *new_proc;
060                                                   059 
061         cur_thr = sos_thread_get_current();       060         cur_thr = sos_thread_get_current();
062                                                   061 
063         /* Duplicate the current process (and     062         /* Duplicate the current process (and its address space) */
064         new_proc = sos_process_create(NULL, TR    063         new_proc = sos_process_create(NULL, TRUE);
065         if (! new_proc)                           064         if (! new_proc)
066           {                                       065           {
067             retval = -SOS_ENOMEM;                 066             retval = -SOS_ENOMEM;
068             break;                                067             break;
069           }                                       068           }
070                                                   069         
071         /* Create *the* thread in this new pro    070         /* Create *the* thread in this new processs, copy of the
072            current user thread (same registers    071            current user thread (same registers, EXCEPT eax which is
073            set to 0) */                           072            set to 0) */
074         new_thr =                                 073         new_thr =
075           sos_duplicate_user_thread(NULL, new_    074           sos_duplicate_user_thread(NULL, new_proc,
076                                     cur_thr,      075                                     cur_thr,
077                                     user_ctxt,    076                                     user_ctxt,
078                                     0);           077                                     0);
079         if (! new_thr)                            078         if (! new_thr)
080           {                                       079           {
081             sos_process_unref(new_proc);          080             sos_process_unref(new_proc);
082             retval = -SOS_ENOMEM;                 081             retval = -SOS_ENOMEM;
083             break;                                082             break;
084           }                                       083           }
085                                                   084 
086         sos_process_unref(new_proc);              085         sos_process_unref(new_proc);
087                                                   086 
088         /* Return to the "parent" thread with     087         /* Return to the "parent" thread with a value different from
089            0. Unix says it should be the "PID"    088            0. Unix says it should be the "PID" of the child. We don't
090            have such a "PID" notion for now */    089            have such a "PID" notion for now */
091         retval = (sos_ui32_t)new_proc;            090         retval = (sos_ui32_t)new_proc;
092       }                                           091       }
093       break;                                      092       break;
094                                                   093 
095     case SOS_SYSCALL_ID_EXEC:                     094     case SOS_SYSCALL_ID_EXEC:
096       {                                           095       {
097         struct sos_thread *cur_thr, *new_thr;     096         struct sos_thread *cur_thr, *new_thr;
098         struct sos_process * proc;                097         struct sos_process * proc;
099         struct sos_umem_vmm_as *new_as;           098         struct sos_umem_vmm_as *new_as;
100         sos_uaddr_t user_str, ustack, start_ua    099         sos_uaddr_t user_str, ustack, start_uaddr;
101         sos_size_t len;                           100         sos_size_t len;
102         char * str;                               101         char * str;
103                                                   102 
104         cur_thr = sos_thread_get_current();       103         cur_thr = sos_thread_get_current();
105         proc    = cur_thr->process;               104         proc    = cur_thr->process;
106                                                   105 
107         /* Make sure the process has exactly 1    106         /* Make sure the process has exactly 1 thread in it */
108         if (sos_process_get_nb_threads(proc) !    107         if (sos_process_get_nb_threads(proc) != 1)
109           {                                       108           {
110             retval = -SOS_EBUSY;                  109             retval = -SOS_EBUSY;
111             break;                                110             break;
112           }                                       111           }
113                                                   112 
114         /* Get the user arguments */              113         /* Get the user arguments */
115         retval = sos_syscall_get2args(user_ctx    114         retval = sos_syscall_get2args(user_ctxt, & user_str, & len);
116         if (SOS_OK != retval)                     115         if (SOS_OK != retval)
117           break;                                  116           break;
118                                                   117 
119         /* Copy the program name into kernel s    118         /* Copy the program name into kernel sppace */
120         retval = sos_strndup_from_user(& str,     119         retval = sos_strndup_from_user(& str, user_str, len + 1, 0);
121         if (SOS_OK != retval)                     120         if (SOS_OK != retval)
122           {                                       121           {
123             break;                                122             break;
124           }                                       123           }
125                                                   124 
126         /* Create a new empty address space to    125         /* Create a new empty address space to map the program */
127         new_as = sos_umem_vmm_create_empty_as(    126         new_as = sos_umem_vmm_create_empty_as(proc);
128         if (! new_as)                             127         if (! new_as)
129           {                                       128           {
130             sos_kfree((sos_vaddr_t)str);          129             sos_kfree((sos_vaddr_t)str);
131             retval = -SOS_ENOMEM;                 130             retval = -SOS_ENOMEM;
132             break;                                131             break;
133           }                                       132           }
134                                                   133 
135         /* Map the program in it */               134         /* Map the program in it */
136         start_uaddr = sos_binfmt_elf32_map(new    135         start_uaddr = sos_binfmt_elf32_map(new_as, str);
137         if (start_uaddr == (sos_uaddr_t)NULL)     136         if (start_uaddr == (sos_uaddr_t)NULL)
138           {                                       137           {
139             sos_umem_vmm_delete_as(new_as);       138             sos_umem_vmm_delete_as(new_as);
140             sos_kfree((sos_vaddr_t)str);          139             sos_kfree((sos_vaddr_t)str);
141             retval = -SOS_ENOENT;                 140             retval = -SOS_ENOENT;
142             break;                                141             break;
143           }                                       142           }
144                                                   143 
145         /* Allocate space for the user stack (    144         /* Allocate space for the user stack (8MB) */
146 #define SOS_DEFAULT_USER_STACK_SIZE (8 << 20)     145 #define SOS_DEFAULT_USER_STACK_SIZE (8 << 20)
147         ustack = (SOS_PAGING_TOP_USER_ADDRESS     146         ustack = (SOS_PAGING_TOP_USER_ADDRESS - SOS_DEFAULT_USER_STACK_SIZE)
148                     + 1;                          147                     + 1;
149         retval = sos_dev_zero_map(new_as, &ust    148         retval = sos_dev_zero_map(new_as, &ustack, SOS_DEFAULT_USER_STACK_SIZE,
150                                   SOS_VM_MAP_P    149                                   SOS_VM_MAP_PROT_READ | SOS_VM_MAP_PROT_WRITE,
151                                   /* PRIVATE *    150                                   /* PRIVATE */ 0);
152         if (SOS_OK != retval)                     151         if (SOS_OK != retval)
153           {                                       152           {
154             sos_umem_vmm_delete_as(new_as);       153             sos_umem_vmm_delete_as(new_as);
155             sos_kfree((sos_vaddr_t)str);          154             sos_kfree((sos_vaddr_t)str);
156             break;                                155             break;
157           }                                       156           }
158                                                   157 
159         /* Now create the user thread */          158         /* Now create the user thread */
160         new_thr = sos_create_user_thread(NULL,    159         new_thr = sos_create_user_thread(NULL,
161                                          proc,    160                                          proc,
162                                          start    161                                          start_uaddr,
163                                          0, 0,    162                                          0, 0,
164                                          ustac    163                                          ustack + SOS_DEFAULT_USER_STACK_SIZE
165                                            - 4    164                                            - 4,
166                                          SOS_S    165                                          SOS_SCHED_PRIO_TS_LOWEST);
167         if (! new_thr)                            166         if (! new_thr)
168           {                                       167           {
169             sos_umem_vmm_delete_as(new_as);       168             sos_umem_vmm_delete_as(new_as);
170             sos_kfree((sos_vaddr_t)str);          169             sos_kfree((sos_vaddr_t)str);
171             retval = -SOS_ENOMEM;                 170             retval = -SOS_ENOMEM;
172             break;                                171             break;          
173           }                                       172           }
174                                                   173 
175         sos_process_set_name(proc, str);          174         sos_process_set_name(proc, str);
176                                                   175 
177         /* Switch to this address space */        176         /* Switch to this address space */
178         retval = sos_process_set_address_space    177         retval = sos_process_set_address_space(proc,
179                                                   178                                                new_as);
180         if (SOS_OK != retval)                     179         if (SOS_OK != retval)
181           {                                       180           {
182             sos_umem_vmm_delete_as(new_as);       181             sos_umem_vmm_delete_as(new_as);
183             sos_kfree((sos_vaddr_t)str);          182             sos_kfree((sos_vaddr_t)str);
184             break;                                183             break;          
185           }                                       184           }
186                                                   185 
187         /* The current thread must exit now */    186         /* The current thread must exit now */
188         sos_kfree((sos_vaddr_t)str);              187         sos_kfree((sos_vaddr_t)str);
189         sos_thread_exit();                        188         sos_thread_exit();
190         retval = -SOS_EFATAL;                     189         retval = -SOS_EFATAL;
191       }                                           190       }
192       break;                                      191       break;
193                                                   192 
194     case SOS_SYSCALL_ID_FAKEMMAP:              << 
195       {                                        << 
196         sos_uaddr_t ptr_hint_uaddr;            << 
197         sos_uaddr_t hint_uaddr;                << 
198         sos_size_t  length;                    << 
199         sos_ui32_t  prot;                      << 
200         sos_ui32_t  flags;                     << 
201         sos_uaddr_t name_user;                 << 
202         sos_ui32_t  offs64_hi;                 << 
203         sos_ui32_t  offs64_lo;                 << 
204         sos_luoffset_t offset_in_resource;     << 
205         char        name[256];                 << 
206         struct sos_umem_vmm_as * my_as;        << 
207                                                << 
208         retval = sos_syscall_get7args(user_ctx << 
209                                       (unsigne << 
210                                       (unsigne << 
211                                       (unsigne << 
212                                       (unsigne << 
213                                       (unsigne << 
214                                       (unsigne << 
215                                       (unsigne << 
216         if (SOS_OK != retval)                  << 
217           break;                               << 
218                                                << 
219         /* Compute 64 bits offset value */     << 
220         offset_in_resource   = offs64_hi;      << 
221         offset_in_resource <<= 32;             << 
222         offset_in_resource  |= offs64_lo;      << 
223                                                << 
224         retval = sos_memcpy_from_user((sos_vad << 
225                                       ptr_hint << 
226                                       sizeof(h << 
227         if (sizeof(hint_uaddr) != retval)      << 
228           {                                    << 
229             retval = -SOS_EFAULT;              << 
230             break;                             << 
231           }                                    << 
232                                                << 
233         retval = sos_strzcpy_from_user(name, n << 
234         if (SOS_OK != retval)                  << 
235           break;                               << 
236                                                << 
237         my_as                                  << 
238           = sos_process_get_address_space(sos_ << 
239         if ( (0 == strncmp(name, "/dev/zero",  << 
240              || (0 == strncmp(name, "/dev/null << 
241           retval = sos_dev_zero_map(my_as, & h << 
242         else if (0 == strncmp(name, "/dev/mem" << 
243           retval = sos_dev_physmem_map(my_as,  << 
244                                        offset_ << 
245         else if (0 == strncmp(name, "/dev/kmem << 
246           retval = sos_dev_kmem_map(my_as, & h << 
247                                     offset_in_ << 
248         else                                   << 
249           retval = -SOS_ENOENT;                << 
250                                                << 
251         if (SOS_OK == retval)                  << 
252           {                                    << 
253             if (sizeof(hint_uaddr)             << 
254                 != sos_memcpy_to_user(ptr_hint << 
255                                       (sos_vad << 
256                                       sizeof(h << 
257               {                                << 
258                 sos_umem_vmm_unmap(my_as, hint << 
259                 retval = -SOS_EFAULT;          << 
260               }                                << 
261           }                                    << 
262                                                << 
263       }                                        << 
264       break;                                   << 
265                                                << 
266     case SOS_SYSCALL_ID_MUNMAP:                   193     case SOS_SYSCALL_ID_MUNMAP:
267       {                                           194       {
268         sos_uaddr_t start_uaddr;                  195         sos_uaddr_t start_uaddr;
269         sos_size_t  size;                         196         sos_size_t  size;
270         struct sos_umem_vmm_as * my_as;           197         struct sos_umem_vmm_as * my_as;
271                                                   198 
272         my_as                                     199         my_as
273           = sos_process_get_address_space(sos_    200           = sos_process_get_address_space(sos_thread_get_current()->process);
274                                                   201 
275         retval = sos_syscall_get2args(user_ctx    202         retval = sos_syscall_get2args(user_ctxt,
276                                       (unsigne    203                                       (unsigned int*)& start_uaddr,
277                                       (unsigne    204                                       (unsigned int*)& size);
278         if (SOS_OK != retval)                     205         if (SOS_OK != retval)
279           break;                                  206           break;
280                                                   207 
281         retval = sos_umem_vmm_unmap(my_as, sta    208         retval = sos_umem_vmm_unmap(my_as, start_uaddr, size);
282       }                                           209       }
283       break;                                      210       break;
284                                                   211 
285     case SOS_SYSCALL_ID_MPROTECT:                 212     case SOS_SYSCALL_ID_MPROTECT:
286       {                                           213       {
287         sos_uaddr_t start_uaddr;                  214         sos_uaddr_t start_uaddr;
288         sos_size_t  size;                         215         sos_size_t  size;
289         sos_ui32_t  new_access_rights;            216         sos_ui32_t  new_access_rights;
290         struct sos_umem_vmm_as * my_as;           217         struct sos_umem_vmm_as * my_as;
291                                                   218 
292         my_as                                     219         my_as
293           = sos_process_get_address_space(sos_    220           = sos_process_get_address_space(sos_thread_get_current()->process);
294                                                   221 
295         retval = sos_syscall_get3args(user_ctx    222         retval = sos_syscall_get3args(user_ctxt,
296                                       (unsigne    223                                       (unsigned int*)& start_uaddr,
297                                       (unsigne    224                                       (unsigned int*)& size,
298                                       (unsigne    225                                       (unsigned int*)& new_access_rights);
299         if (SOS_OK != retval)                     226         if (SOS_OK != retval)
300           break;                                  227           break;
301                                                   228 
302         retval = sos_thread_prepare_user_space    229         retval = sos_thread_prepare_user_space_access(NULL, (sos_vaddr_t)NULL);
303         if (SOS_OK != retval)                     230         if (SOS_OK != retval)
304           break;                                  231           break;
305                                                   232 
306         retval = sos_umem_vmm_chprot(my_as, st    233         retval = sos_umem_vmm_chprot(my_as, start_uaddr, size,
307                                      new_acces    234                                      new_access_rights);
308                                                   235 
309         sos_thread_end_user_space_access();       236         sos_thread_end_user_space_access();
310       }                                           237       }
311       break;                                      238       break;
312                                                   239 
313     case SOS_SYSCALL_ID_MRESIZE:                  240     case SOS_SYSCALL_ID_MRESIZE:
314       {                                           241       {
315         sos_uaddr_t old_uaddr;                    242         sos_uaddr_t old_uaddr;
316         sos_size_t  old_size;                     243         sos_size_t  old_size;
317         sos_uaddr_t *uptr_new_uaddr;              244         sos_uaddr_t *uptr_new_uaddr;
318         sos_uaddr_t new_uaddr;                    245         sos_uaddr_t new_uaddr;
319         sos_size_t  new_size;                     246         sos_size_t  new_size;
320         sos_ui32_t  flags;                        247         sos_ui32_t  flags;
321         struct sos_umem_vmm_as * my_as;           248         struct sos_umem_vmm_as * my_as;
322                                                   249 
323         my_as                                     250         my_as
324           = sos_process_get_address_space(sos_    251           = sos_process_get_address_space(sos_thread_get_current()->process);
325                                                   252 
326         retval = sos_syscall_get5args(user_ctx    253         retval = sos_syscall_get5args(user_ctxt,
327                                       (unsigne    254                                       (unsigned int*)& old_uaddr,
328                                       (unsigne    255                                       (unsigned int*)& old_size,
329                                       (unsigne    256                                       (unsigned int*)& uptr_new_uaddr,
330                                       (unsigne    257                                       (unsigned int*)& new_size,
331                                       (unsigne    258                                       (unsigned int*)& flags);
332         if (SOS_OK != retval)                     259         if (SOS_OK != retval)
333           break;                                  260           break;
334                                                   261 
335         if (sizeof(new_uaddr) != sos_memcpy_fr    262         if (sizeof(new_uaddr) != sos_memcpy_from_user((sos_vaddr_t)& new_uaddr,
336                                                   263                                                       (sos_uaddr_t)
337                                                   264                                                         uptr_new_uaddr,
338                                                   265                                                       sizeof(new_uaddr)))
339           {                                       266           {
340             retval = -SOS_EFAULT;                 267             retval = -SOS_EFAULT;
341             break;                                268             break;
342           }                                       269           }
343                                                   270 
344         retval = sos_thread_prepare_user_space    271         retval = sos_thread_prepare_user_space_access(NULL, (sos_vaddr_t)NULL);
345         if (SOS_OK != retval)                     272         if (SOS_OK != retval)
346           break;                                  273           break;
347                                                   274 
348         retval = sos_umem_vmm_resize(my_as, ol    275         retval = sos_umem_vmm_resize(my_as, old_uaddr, old_size,
349                                      & new_uad    276                                      & new_uaddr, new_size, flags);
350         sos_thread_end_user_space_access();       277         sos_thread_end_user_space_access();
351         if (SOS_OK != retval)                     278         if (SOS_OK != retval)
352           break;                                  279           break;
353                                                   280 
354         if (sizeof(new_uaddr)                     281         if (sizeof(new_uaddr)
355             == sos_memcpy_to_user((sos_uaddr_t    282             == sos_memcpy_to_user((sos_uaddr_t)uptr_new_uaddr,
356                                   (sos_vaddr_t    283                                   (sos_vaddr_t)&new_uaddr,
357                                   sizeof(new_u    284                                   sizeof(new_uaddr)))
358           {                                       285           {
359             retval = -SOS_EFAULT;                 286             retval = -SOS_EFAULT;
360             break;                                287             break;
361           }                                       288           }
362       }                                           289       }
363       break;                                      290       break;
364                                                   291 
365     case SOS_SYSCALL_ID_NEW_THREAD:               292     case SOS_SYSCALL_ID_NEW_THREAD:
366       {                                           293       {
367         sos_uaddr_t start_func;                   294         sos_uaddr_t start_func;
368         sos_ui32_t  start_arg1, start_arg2;       295         sos_ui32_t  start_arg1, start_arg2;
369         sos_size_t  stack_size;                   296         sos_size_t  stack_size;
370         sos_uaddr_t stack_uaddr;                  297         sos_uaddr_t stack_uaddr;
371                                                   298 
372         struct sos_thread * new_thr;              299         struct sos_thread * new_thr;
373         struct sos_umem_vmm_as * my_as;           300         struct sos_umem_vmm_as * my_as;
374                                                   301 
375         my_as                                     302         my_as
376           = sos_process_get_address_space(sos_    303           = sos_process_get_address_space(sos_thread_get_current()->process);
377                                                   304 
378         retval = sos_syscall_get4args(user_ctx    305         retval = sos_syscall_get4args(user_ctxt,
379                                       (unsigne    306                                       (unsigned int*)& start_func,
380                                       (unsigne    307                                       (unsigned int*)& start_arg1,
381                                       (unsigne    308                                       (unsigned int*)& start_arg2,
382                                       (unsigne    309                                       (unsigned int*)& stack_size);
383         if (SOS_OK != retval)                     310         if (SOS_OK != retval)
384           break;                                  311           break;
385                                                   312 
386         if (stack_size <= 0)                      313         if (stack_size <= 0)
387           {                                       314           {
388             retval = -SOS_EINVAL;                 315             retval = -SOS_EINVAL;
389             break;                                316             break;
390           }                                       317           }
391                                                   318 
392         /* Allocate the stack */                  319         /* Allocate the stack */
393         stack_uaddr = 0;                          320         stack_uaddr = 0;
394         stack_size = SOS_PAGE_ALIGN_SUP(stack_    321         stack_size = SOS_PAGE_ALIGN_SUP(stack_size);
395         retval = sos_dev_zero_map(my_as, & sta    322         retval = sos_dev_zero_map(my_as, & stack_uaddr, stack_size,
396                                   SOS_VM_MAP_P    323                                   SOS_VM_MAP_PROT_READ | SOS_VM_MAP_PROT_WRITE,
397                                   /* PRIVATE *    324                                   /* PRIVATE */ 0);
398         if (SOS_OK != retval)                     325         if (SOS_OK != retval)
399           break;                                  326           break;
400                                                   327 
401         /* Now create the user thread */          328         /* Now create the user thread */
402         new_thr = sos_create_user_thread(NULL,    329         new_thr = sos_create_user_thread(NULL,
403                                          sos_t    330                                          sos_thread_get_current()->process,
404                                          start    331                                          start_func,
405                                          start    332                                          start_arg1,
406                                          start    333                                          start_arg2,
407                                          stack    334                                          stack_uaddr + stack_size - 4,
408                                          SOS_S    335                                          SOS_SCHED_PRIO_TS_LOWEST);
409                                                   336 
410         if (! new_thr)                            337         if (! new_thr)
411           {                                       338           {
412             sos_umem_vmm_unmap(my_as, stack_ua    339             sos_umem_vmm_unmap(my_as, stack_uaddr, stack_size);
413             retval = -SOS_ENOMEM;                 340             retval = -SOS_ENOMEM;
414             break;                                341             break;          
415           }                                       342           }
416                                                   343 
417       }                                           344       }
418       break;                                      345       break;
419                                                   346 
420     case SOS_SYSCALL_ID_NANOSLEEP:                347     case SOS_SYSCALL_ID_NANOSLEEP:
421       {                                           348       {
422         struct sos_time delay;                    349         struct sos_time delay;
423                                                   350 
424         retval = sos_syscall_get2args(user_ctx    351         retval = sos_syscall_get2args(user_ctxt,
425                                       (unsigne    352                                       (unsigned int*)& delay.sec,
426                                       (unsigne    353                                       (unsigned int*)& delay.nanosec);
427         if (SOS_OK != retval)                     354         if (SOS_OK != retval)
428           break;                                  355           break;
429                                                   356 
430         retval = sos_thread_sleep(& delay);       357         retval = sos_thread_sleep(& delay);
431       }                                           358       }
432       break;                                      359       break;
433                                                   360 
434     case SOS_SYSCALL_ID_BRK:                      361     case SOS_SYSCALL_ID_BRK:
435       {                                           362       {
436         sos_uaddr_t new_top_heap;                 363         sos_uaddr_t new_top_heap;
437         struct sos_umem_vmm_as * my_as;           364         struct sos_umem_vmm_as * my_as;
438                                                   365 
439         my_as                                     366         my_as
440           = sos_process_get_address_space(sos_    367           = sos_process_get_address_space(sos_thread_get_current()->process);
441                                                   368 
442         retval = sos_syscall_get1arg(user_ctxt    369         retval = sos_syscall_get1arg(user_ctxt,
443                                      (unsigned    370                                      (unsigned int*)& new_top_heap);
444         if (SOS_OK != retval)                     371         if (SOS_OK != retval)
445           break;                                  372           break;
446                                                   373 
447         retval = sos_thread_prepare_user_space    374         retval = sos_thread_prepare_user_space_access(NULL, (sos_vaddr_t)NULL);
448         if (SOS_OK != retval)                     375         if (SOS_OK != retval)
449           break;                                  376           break;
450                                                   377 
451         retval = sos_umem_vmm_brk(my_as, new_t    378         retval = sos_umem_vmm_brk(my_as, new_top_heap);
452         sos_thread_end_user_space_access();       379         sos_thread_end_user_space_access();
453       }                                           380       }
454       break;                                      381       break;
455                                                   382 
456                                                   383       
457       /**                                         384       /**
458        * File system interface                    385        * File system interface
459        */                                         386        */
460     case SOS_SYSCALL_ID_MOUNT:                    387     case SOS_SYSCALL_ID_MOUNT:
461       {                                           388       {
462         sos_uaddr_t user_src;                     389         sos_uaddr_t user_src;
463         sos_size_t srclen;                        390         sos_size_t srclen;
464         const char * kernel_src = NULL;        !! 391         char * kernel_src = NULL;
465         sos_uaddr_t user_dst;                     392         sos_uaddr_t user_dst;
466         sos_size_t dstlen;                        393         sos_size_t dstlen;
467         const char * kernel_dst;               !! 394         char * kernel_dst;
468         sos_ui32_t mountflags;                    395         sos_ui32_t mountflags;
469         sos_uaddr_t user_fstype;                  396         sos_uaddr_t user_fstype;
470         char * kernel_fstype;                     397         char * kernel_fstype;
471         sos_uaddr_t user_args;                    398         sos_uaddr_t user_args;
472         char * kernel_args = NULL;                399         char * kernel_args = NULL;
473         struct sos_process * proc;                400         struct sos_process * proc;
474                                                   401 
475         proc = sos_thread_get_current()->proce    402         proc = sos_thread_get_current()->process;
476         retval = sos_syscall_get7args(user_ctx    403         retval = sos_syscall_get7args(user_ctxt,
477                                       (unsigne    404                                       (unsigned int*)& user_src,
478                                       (unsigne    405                                       (unsigned int*)& srclen,
479                                       (unsigne    406                                       (unsigned int*)& user_dst,
480                                       (unsigne    407                                       (unsigned int*)& dstlen,
481                                       (unsigne    408                                       (unsigned int*)& user_fstype,
482                                       (unsigne    409                                       (unsigned int*)& mountflags,
483                                       (unsigne    410                                       (unsigned int*)& user_args);
484         if (SOS_OK != retval)                     411         if (SOS_OK != retval)
485           break;                                  412           break;
486                                                   413 
487         if (user_src != (sos_uaddr_t)NULL)        414         if (user_src != (sos_uaddr_t)NULL)
488           {                                       415           {
489             retval = sos_memdup_from_user((sos !! 416             retval = sos_strndup_from_user(&kernel_src, user_src, srclen, 0);
490             if (SOS_OK != retval)                 417             if (SOS_OK != retval)
491               break;                              418               break;
492           }                                       419           }
493                                                   420 
494         retval = sos_memdup_from_user((sos_vad !! 421         retval = sos_strndup_from_user(&kernel_dst, user_dst, dstlen, 0);
495         if (SOS_OK != retval)                     422         if (SOS_OK != retval)
496           {                                       423           {
497             if (kernel_src)                       424             if (kernel_src)
498               sos_kfree((sos_vaddr_t)kernel_sr    425               sos_kfree((sos_vaddr_t)kernel_src);
499             break;                                426             break;
500           }                                       427           }
501                                                   428 
502         retval = sos_strndup_from_user(& kerne    429         retval = sos_strndup_from_user(& kernel_fstype, user_fstype, 256, 0);
503         if (SOS_OK != retval)                     430         if (SOS_OK != retval)
504           {                                       431           {
505             if (kernel_src)                       432             if (kernel_src)
506               sos_kfree((sos_vaddr_t)kernel_sr    433               sos_kfree((sos_vaddr_t)kernel_src);
507             sos_kfree((sos_vaddr_t)kernel_dst)    434             sos_kfree((sos_vaddr_t)kernel_dst);
508             break;                                435             break;
509           }                                       436           }
510                                                   437 
511         if (user_args != (sos_uaddr_t)NULL)       438         if (user_args != (sos_uaddr_t)NULL)
512           {                                       439           {
513             retval = sos_strndup_from_user(& k    440             retval = sos_strndup_from_user(& kernel_args, user_args, 1024, 0);
514             if (SOS_OK != retval)                 441             if (SOS_OK != retval)
515               {                                   442               {
516                 if (kernel_src)                   443                 if (kernel_src)
517                   sos_kfree((sos_vaddr_t)kerne    444                   sos_kfree((sos_vaddr_t)kernel_src);
518                 sos_kfree((sos_vaddr_t)kernel_    445                 sos_kfree((sos_vaddr_t)kernel_dst);
519                 sos_kfree((sos_vaddr_t)kernel_    446                 sos_kfree((sos_vaddr_t)kernel_fstype);
520                 break;                            447                 break;
521               }                                   448               }
522           }                                       449           }
523                                                   450 
524         retval = sos_fs_mount(proc, kernel_src    451         retval = sos_fs_mount(proc, kernel_src, srclen,
525                               kernel_dst, dstl    452                               kernel_dst, dstlen,
526                               kernel_fstype,      453                               kernel_fstype,
527                               mountflags,         454                               mountflags,
528                               kernel_args,        455                               kernel_args,
529                               NULL);              456                               NULL);
530         if (kernel_src)                           457         if (kernel_src)
531           sos_kfree((sos_vaddr_t)kernel_src);     458           sos_kfree((sos_vaddr_t)kernel_src);
532         sos_kfree((sos_vaddr_t)kernel_dst);       459         sos_kfree((sos_vaddr_t)kernel_dst);
533         sos_kfree((sos_vaddr_t)kernel_fstype);    460         sos_kfree((sos_vaddr_t)kernel_fstype);
534         if (kernel_args)                          461         if (kernel_args)
535           sos_kfree((sos_vaddr_t)kernel_args);    462           sos_kfree((sos_vaddr_t)kernel_args);
536       }                                           463       }
537       break;                                      464       break;
538                                                   465 
539     case SOS_SYSCALL_ID_UMOUNT:                   466     case SOS_SYSCALL_ID_UMOUNT:
540       {                                           467       {
541         sos_uaddr_t user_str;                     468         sos_uaddr_t user_str;
542         sos_size_t  len;                          469         sos_size_t  len;
543         char * path;                              470         char * path;
544         struct sos_process * proc;                471         struct sos_process * proc;
545                                                   472         
546         proc = sos_thread_get_current()->proce    473         proc = sos_thread_get_current()->process;
547         retval = sos_syscall_get2args(user_ctx    474         retval = sos_syscall_get2args(user_ctxt,
548                                       (unsigne    475                                       (unsigned int*)& user_str,
549                                       (unsigne    476                                       (unsigned int*)& len);
550         if (SOS_OK != retval)                     477         if (SOS_OK != retval)
551           break;                                  478           break;
552                                                   479         
553         retval = sos_memdup_from_user((sos_vad !! 480         retval = sos_strndup_from_user(&path, user_str, len, 0);
554         if (SOS_OK != retval)                     481         if (SOS_OK != retval)
555           break;                                  482           break;
556                                                   483         
557         retval = sos_fs_umount(proc,              484         retval = sos_fs_umount(proc,
558                                path, len);        485                                path, len);
559         sos_kfree((sos_vaddr_t)path);             486         sos_kfree((sos_vaddr_t)path);
560       }                                           487       }
561       break;                                      488       break;
562                                                   489 
563     case SOS_SYSCALL_ID_SYNC:                     490     case SOS_SYSCALL_ID_SYNC:
564       {                                           491       {
565         sos_fs_sync_all_fs();                     492         sos_fs_sync_all_fs();
566         retval = SOS_OK;                          493         retval = SOS_OK;
567       }                                           494       }
568       break;                                      495       break;
569                                                   496 
570     case SOS_SYSCALL_ID_VFSTAT64:                 497     case SOS_SYSCALL_ID_VFSTAT64:
571       {                                           498       {
572         sos_uaddr_t user_str;                     499         sos_uaddr_t user_str;
573         sos_size_t  len;                          500         sos_size_t  len;
574         sos_uaddr_t user_vfstat_struct;           501         sos_uaddr_t user_vfstat_struct;
575         struct sos_fs_statfs kernel_vfstat_str    502         struct sos_fs_statfs kernel_vfstat_struct;
576         char * path;                              503         char * path;
577         struct sos_process * proc;                504         struct sos_process * proc;
578                                                   505 
579         proc = sos_thread_get_current()->proce    506         proc = sos_thread_get_current()->process;
580         retval = sos_syscall_get3args(user_ctx    507         retval = sos_syscall_get3args(user_ctxt,
581                                       (unsigne    508                                       (unsigned int*)& user_str,
582                                       (unsigne    509                                       (unsigned int*)& len,
583                                       (unsigne    510                                       (unsigned int*)& user_vfstat_struct);
584         if (SOS_OK != retval)                     511         if (SOS_OK != retval)
585           break;                                  512           break;
586                                                   513 
587         retval = sos_memdup_from_user((sos_vad !! 514         retval = sos_strndup_from_user(&path, user_str, len, 0);
588         if (SOS_OK != retval)                     515         if (SOS_OK != retval)
589           break;                                  516           break;
590                                                   517 
591         retval = sos_fs_vfstat(proc, path, len    518         retval = sos_fs_vfstat(proc, path, len, & kernel_vfstat_struct);
592         sos_kfree((sos_vaddr_t)path);             519         sos_kfree((sos_vaddr_t)path);
593         if (SOS_OK != retval)                     520         if (SOS_OK != retval)
594           break;                                  521           break;
595                                                   522 
596         if (sizeof(kernel_vfstat_struct)          523         if (sizeof(kernel_vfstat_struct)
597             != sos_memcpy_to_user(user_vfstat_    524             != sos_memcpy_to_user(user_vfstat_struct,
598                                   (sos_vaddr_t    525                                   (sos_vaddr_t) & kernel_vfstat_struct,
599                                   sizeof(kerne    526                                   sizeof(kernel_vfstat_struct)))
600           retval = -SOS_EFAULT;                   527           retval = -SOS_EFAULT;
601       }                                           528       }
602       break;                                      529       break;
603                                                   530 
604     case SOS_SYSCALL_ID_OPEN:                     531     case SOS_SYSCALL_ID_OPEN:
605       {                                           532       {
606         sos_uaddr_t user_str;                     533         sos_uaddr_t user_str;
607         sos_size_t  len;                          534         sos_size_t  len;
608         sos_ui32_t  open_flags;                   535         sos_ui32_t  open_flags;
609         sos_ui32_t  access_rights;                536         sos_ui32_t  access_rights;
610         char * path;                              537         char * path;
611         struct sos_fs_opened_file * of;           538         struct sos_fs_opened_file * of;
612         struct sos_process * proc;                539         struct sos_process * proc;
613                                                   540 
614         proc = sos_thread_get_current()->proce    541         proc = sos_thread_get_current()->process;
615         retval = sos_syscall_get4args(user_ctx    542         retval = sos_syscall_get4args(user_ctxt,
616                                       (unsigne    543                                       (unsigned int*)& user_str,
617                                       (unsigne    544                                       (unsigned int*)& len,
618                                       (unsigne    545                                       (unsigned int*)& open_flags,
619                                       (unsigne    546                                       (unsigned int*)& access_rights);
620         if (SOS_OK != retval)                     547         if (SOS_OK != retval)
621           break;                                  548           break;
622                                                   549 
623         retval = sos_memdup_from_user((sos_vad !! 550         retval = sos_strndup_from_user(&path, user_str, len, 0);
624         if (SOS_OK != retval)                     551         if (SOS_OK != retval)
625           break;                                  552           break;
626                                                   553 
627         retval = sos_fs_open(proc,                554         retval = sos_fs_open(proc,
628                              path, len,           555                              path, len,
629                              open_flags,          556                              open_flags,
630                              access_rights,       557                              access_rights,
631                              & of);               558                              & of);
632         sos_kfree((sos_vaddr_t)path);             559         sos_kfree((sos_vaddr_t)path);
633         if (SOS_OK != retval)                     560         if (SOS_OK != retval)
634           break;                                  561           break;
635                                                   562 
636         retval = sos_process_register_opened_f    563         retval = sos_process_register_opened_file(proc, of);
637         if (retval < 0)                           564         if (retval < 0)
638           {                                       565           {
639             sos_fs_close(of);                     566             sos_fs_close(of);
640             break;                                567             break;
641           }                                       568           }
642       }                                           569       }
643       break;                                      570       break;
644                                                   571 
645     case SOS_SYSCALL_ID_CLOSE:                    572     case SOS_SYSCALL_ID_CLOSE:
646       {                                           573       {
647         struct sos_fs_opened_file * of;           574         struct sos_fs_opened_file * of;
648         struct sos_process * proc;                575         struct sos_process * proc;
649         int fd;                                   576         int fd;
650                                                   577 
651         proc = sos_thread_get_current()->proce    578         proc = sos_thread_get_current()->process;
652         retval = sos_syscall_get1arg(user_ctxt    579         retval = sos_syscall_get1arg(user_ctxt,
653                                      (unsigned    580                                      (unsigned int*)& fd);
654         if (SOS_OK != retval)                     581         if (SOS_OK != retval)
655           break;                                  582           break;
656                                                   583 
657         of = sos_process_get_opened_file(proc,    584         of = sos_process_get_opened_file(proc, fd);
658         if (NULL == of)                           585         if (NULL == of)
659           {                                       586           {
660             retval = -SOS_EBADF;                  587             retval = -SOS_EBADF;
661             break;                                588             break;
662           }                                       589           }
663                                                   590 
664         retval = sos_process_unregister_opened    591         retval = sos_process_unregister_opened_file(proc, fd);
665         if (SOS_OK != retval)                     592         if (SOS_OK != retval)
666           break;                                  593           break;
667                                                   594 
668         retval = sos_fs_close(of);                595         retval = sos_fs_close(of);
669       }                                           596       }
670       break;                                      597       break;
671                                                   598 
672     case SOS_SYSCALL_ID_READ:                     599     case SOS_SYSCALL_ID_READ:
673       {                                           600       {
674         struct sos_fs_opened_file * of;           601         struct sos_fs_opened_file * of;
675         struct sos_process * proc;                602         struct sos_process * proc;
676         sos_uaddr_t uaddr_buf;                    603         sos_uaddr_t uaddr_buf;
677         sos_uaddr_t uaddr_buflen;                 604         sos_uaddr_t uaddr_buflen;
678         sos_size_t kernel_buflen;                 605         sos_size_t kernel_buflen;
679         int fd;                                   606         int fd;
680                                                   607 
681         proc = sos_thread_get_current()->proce    608         proc = sos_thread_get_current()->process;
682         retval = sos_syscall_get3args(user_ctx    609         retval = sos_syscall_get3args(user_ctxt,
683                                       (unsigne    610                                       (unsigned int*)& fd,
684                                       (unsigne    611                                       (unsigned int*)& uaddr_buf,
685                                       (unsigne    612                                       (unsigned int*)& uaddr_buflen);
686         if (SOS_OK != retval)                     613         if (SOS_OK != retval)
687           break;                                  614           break;
688                                                   615 
689         /* Retrieve the value for "buflen" */     616         /* Retrieve the value for "buflen" */
690         retval = sos_memcpy_from_user((sos_vad    617         retval = sos_memcpy_from_user((sos_vaddr_t)& kernel_buflen,
691                                       uaddr_bu    618                                       uaddr_buflen,
692                                       sizeof(k    619                                       sizeof(kernel_buflen));
693         if (sizeof(kernel_buflen) != retval)      620         if (sizeof(kernel_buflen) != retval)
694           {                                       621           {
695             retval = -SOS_EFAULT;                 622             retval = -SOS_EFAULT;
696             break;                                623             break;
697           }                                       624           }
698                                                   625 
699         of = sos_process_get_opened_file(proc,    626         of = sos_process_get_opened_file(proc, fd);
700         if (NULL == of)                           627         if (NULL == of)
701           {                                       628           {
702             retval = -SOS_EBADF;                  629             retval = -SOS_EBADF;
703             break;                                630             break;
704           }                                       631           }
705                                                   632 
706         /* Do the actual reading */               633         /* Do the actual reading */
707         retval = sos_fs_read(of, uaddr_buf, &     634         retval = sos_fs_read(of, uaddr_buf, & kernel_buflen);
708                                                   635         
709         /* Send successful number of bytes rea    636         /* Send successful number of bytes read to user */
710         sos_memcpy_to_user(uaddr_buflen,          637         sos_memcpy_to_user(uaddr_buflen,
711                            (sos_vaddr_t)& kern    638                            (sos_vaddr_t)& kernel_buflen,
712                            sizeof(kernel_bufle    639                            sizeof(kernel_buflen));
713       }                                           640       }
714       break;                                      641       break;
715                                                   642 
716     case SOS_SYSCALL_ID_READDIR:                  643     case SOS_SYSCALL_ID_READDIR:
717       {                                           644       {
718         struct sos_fs_opened_file * of;           645         struct sos_fs_opened_file * of;
719         struct sos_process * proc;                646         struct sos_process * proc;
720         sos_uaddr_t uaddr_direntry;               647         sos_uaddr_t uaddr_direntry;
721         struct sos_fs_dirent direntry;            648         struct sos_fs_dirent direntry;
722         int fd;                                   649         int fd;
723                                                   650 
724         proc = sos_thread_get_current()->proce    651         proc = sos_thread_get_current()->process;
725         retval = sos_syscall_get2args(user_ctx    652         retval = sos_syscall_get2args(user_ctxt,
726                                       (unsigne    653                                       (unsigned int*)& fd,
727                                       (unsigne    654                                       (unsigned int*)& uaddr_direntry);
728         if (SOS_OK != retval)                     655         if (SOS_OK != retval)
729           break;                                  656           break;
730                                                   657 
731         of = sos_process_get_opened_file(proc,    658         of = sos_process_get_opened_file(proc, fd);
732         if (NULL == of)                           659         if (NULL == of)
733           {                                       660           {
734             retval = -SOS_EBADF;                  661             retval = -SOS_EBADF;
735             break;                                662             break;
736           }                                       663           }
737                                                   664 
738         /* Do the actual readdir */               665         /* Do the actual readdir */
739         retval = sos_fs_readdir(of, & direntry    666         retval = sos_fs_readdir(of, & direntry);
740         if (SOS_OK != retval)                     667         if (SOS_OK != retval)
741           break;                                  668           break;
742                                                   669         
743         /* Send direntry structure to user */     670         /* Send direntry structure to user */
744         if (sizeof(direntry) != sos_memcpy_to_    671         if (sizeof(direntry) != sos_memcpy_to_user(uaddr_direntry,
745                                                   672                                                    (sos_vaddr_t)& direntry,
746                                                   673                                                    sizeof(direntry)))
747           retval = -SOS_EFAULT;                   674           retval = -SOS_EFAULT;
748       }                                           675       }
749       break;                                      676       break;
750                                                   677 
751     case SOS_SYSCALL_ID_WRITE:                    678     case SOS_SYSCALL_ID_WRITE:
752       {                                           679       {
753         struct sos_fs_opened_file * of;           680         struct sos_fs_opened_file * of;
754         struct sos_process * proc;                681         struct sos_process * proc;
755         sos_uaddr_t uaddr_buf;                    682         sos_uaddr_t uaddr_buf;
756         sos_uaddr_t uaddr_buflen;                 683         sos_uaddr_t uaddr_buflen;
757         sos_size_t kernel_buflen;                 684         sos_size_t kernel_buflen;
758         int fd;                                   685         int fd;
759                                                   686 
760         proc = sos_thread_get_current()->proce    687         proc = sos_thread_get_current()->process;
761         retval = sos_syscall_get3args(user_ctx    688         retval = sos_syscall_get3args(user_ctxt,
762                                       (unsigne    689                                       (unsigned int*)& fd,
763                                       (unsigne    690                                       (unsigned int*)& uaddr_buf,
764                                       (unsigne    691                                       (unsigned int*)& uaddr_buflen);
765         if (SOS_OK != retval)                     692         if (SOS_OK != retval)
766           break;                                  693           break;
767                                                   694 
768         /* Retrieve the value for "buflen" */     695         /* Retrieve the value for "buflen" */
769         retval = sos_memcpy_from_user((sos_vad    696         retval = sos_memcpy_from_user((sos_vaddr_t)& kernel_buflen,
770                                       uaddr_bu    697                                       uaddr_buflen,
771                                       sizeof(k    698                                       sizeof(kernel_buflen));
772         if (sizeof(kernel_buflen) != retval)      699         if (sizeof(kernel_buflen) != retval)
773           {                                       700           {
774             retval = -SOS_EFAULT;                 701             retval = -SOS_EFAULT;
775             break;                                702             break;
776           }                                       703           }
777                                                   704 
778         of = sos_process_get_opened_file(proc,    705         of = sos_process_get_opened_file(proc, fd);
779         if (NULL == of)                           706         if (NULL == of)
780           {                                       707           {
781             retval = -SOS_EBADF;                  708             retval = -SOS_EBADF;
782             break;                                709             break;
783           }                                       710           }
784                                                   711 
785         /* Do the actual writing */               712         /* Do the actual writing */
786         retval = sos_fs_write(of, uaddr_buf, &    713         retval = sos_fs_write(of, uaddr_buf, & kernel_buflen);
787                                                   714         
788         /* Send successful number of bytes wri    715         /* Send successful number of bytes written to user */
789         sos_memcpy_to_user(uaddr_buflen,          716         sos_memcpy_to_user(uaddr_buflen,
790                            (sos_vaddr_t)& kern    717                            (sos_vaddr_t)& kernel_buflen,
791                            sizeof(kernel_bufle    718                            sizeof(kernel_buflen));
792       }                                           719       }
793       break;                                      720       break;
794                                                   721 
795     case SOS_SYSCALL_ID_SEEK64:                   722     case SOS_SYSCALL_ID_SEEK64:
796       {                                           723       {
797         struct sos_fs_opened_file * of;           724         struct sos_fs_opened_file * of;
798         struct sos_process * proc;                725         struct sos_process * proc;
799         sos_uaddr_t uaddr_offset;                 726         sos_uaddr_t uaddr_offset;
800         sos_seek_whence_t whence;                 727         sos_seek_whence_t whence;
801         sos_lsoffset_t kernel_offset, result_p    728         sos_lsoffset_t kernel_offset, result_position;
802         int fd;                                   729         int fd;
803                                                   730 
804         proc = sos_thread_get_current()->proce    731         proc = sos_thread_get_current()->process;
805         retval = sos_syscall_get3args(user_ctx    732         retval = sos_syscall_get3args(user_ctxt,
806                                       (unsigne    733                                       (unsigned int*)& fd,
807                                       (unsigne    734                                       (unsigned int*)& uaddr_offset,
808                                       (unsigne    735                                       (unsigned int*)& whence);
809         if (SOS_OK != retval)                     736         if (SOS_OK != retval)
810           break;                                  737           break;
811                                                   738 
812         /* Retrieve the value for "buflen" */     739         /* Retrieve the value for "buflen" */
813         retval = sos_memcpy_from_user((sos_vad    740         retval = sos_memcpy_from_user((sos_vaddr_t)& kernel_offset,
814                                       uaddr_of    741                                       uaddr_offset,
815                                       sizeof(k    742                                       sizeof(kernel_offset));
816         if (sizeof(kernel_offset) != retval)      743         if (sizeof(kernel_offset) != retval)
817           {                                       744           {
818             retval = -SOS_EFAULT;                 745             retval = -SOS_EFAULT;
819             break;                                746             break;
820           }                                       747           }
821                                                   748 
822         of = sos_process_get_opened_file(proc,    749         of = sos_process_get_opened_file(proc, fd);
823         if (NULL == of)                           750         if (NULL == of)
824           {                                       751           {
825             retval = -SOS_EBADF;                  752             retval = -SOS_EBADF;
826             break;                                753             break;
827           }                                       754           }
828                                                   755 
829         /* Do the actual seek */                  756         /* Do the actual seek */
830         retval = sos_fs_seek(of, kernel_offset    757         retval = sos_fs_seek(of, kernel_offset, whence, & result_position);
831                                                   758         
832         /* Send successful number of bytes wri    759         /* Send successful number of bytes written to user */
833         sos_memcpy_to_user(uaddr_offset,          760         sos_memcpy_to_user(uaddr_offset,
834                            (sos_vaddr_t)& resu    761                            (sos_vaddr_t)& result_position,
835                            sizeof(kernel_offse    762                            sizeof(kernel_offset));
836       }                                           763       }
837       break;                                      764       break;
838                                                   765 
839     case SOS_SYSCALL_ID_FTRUNCATE64:              766     case SOS_SYSCALL_ID_FTRUNCATE64:
840       {                                           767       {
841         struct sos_fs_opened_file * of;           768         struct sos_fs_opened_file * of;
842         struct sos_process * proc;                769         struct sos_process * proc;
843         sos_lsoffset_t length;                    770         sos_lsoffset_t length;
844         int fd;                                   771         int fd;
845                                                   772 
846         proc = sos_thread_get_current()->proce    773         proc = sos_thread_get_current()->process;
847         retval = sos_syscall_get2args(user_ctx    774         retval = sos_syscall_get2args(user_ctxt,
848                                       (unsigne    775                                       (unsigned int*)& fd,
849                                       (unsigne    776                                       (unsigned int*)& length);
850         if (SOS_OK != retval)                     777         if (SOS_OK != retval)
851           break;                                  778           break;
852                                                   779 
853         of = sos_process_get_opened_file(proc,    780         of = sos_process_get_opened_file(proc, fd);
854         if (NULL == of)                           781         if (NULL == of)
855           {                                       782           {
856             retval = -SOS_EBADF;                  783             retval = -SOS_EBADF;
857             break;                                784             break;
858           }                                       785           }
859                                                   786 
860         /* Do the actual trunc */                 787         /* Do the actual trunc */
861         retval = sos_fs_ftruncate(of, length);    788         retval = sos_fs_ftruncate(of, length);
862       }                                           789       }
863       break;                                      790       break;
864                                                   791 
865     case SOS_SYSCALL_ID_FSMMAP:                   792     case SOS_SYSCALL_ID_FSMMAP:
866       {                                           793       {
867         sos_uaddr_t ptr_hint_uaddr;               794         sos_uaddr_t ptr_hint_uaddr;
868         sos_uaddr_t hint_uaddr;                   795         sos_uaddr_t hint_uaddr;
869         sos_size_t  length;                       796         sos_size_t  length;
870         sos_ui32_t  prot;                         797         sos_ui32_t  prot;
871         sos_ui32_t  flags;                        798         sos_ui32_t  flags;
872         int         fd;                           799         int         fd;
873         sos_ui32_t  offs64_hi;                    800         sos_ui32_t  offs64_hi;
874         sos_ui32_t  offs64_lo;                    801         sos_ui32_t  offs64_lo;
875         sos_luoffset_t offset_in_resource;        802         sos_luoffset_t offset_in_resource;
876         struct sos_fs_opened_file * of;           803         struct sos_fs_opened_file * of;
877         struct sos_process * proc;                804         struct sos_process * proc;
878                                                   805         
879         proc = sos_thread_get_current()->proce    806         proc = sos_thread_get_current()->process;
880         retval = sos_syscall_get7args(user_ctx    807         retval = sos_syscall_get7args(user_ctxt,
881                                       (unsigne    808                                       (unsigned int*)& ptr_hint_uaddr,
882                                       (unsigne    809                                       (unsigned int*)& length,
883                                       (unsigne    810                                       (unsigned int*)& prot,
884                                       (unsigne    811                                       (unsigned int*)& flags,
885                                       (unsigne    812                                       (unsigned int*)& fd,
886                                       (unsigne    813                                       (unsigned int*)& offs64_hi,
887                                       (unsigne    814                                       (unsigned int*)& offs64_lo);
888         if (SOS_OK != retval)                     815         if (SOS_OK != retval)
889           break;                                  816           break;
890                                                   817 
891         of = sos_process_get_opened_file(proc,    818         of = sos_process_get_opened_file(proc, fd);
892         if (NULL == of)                           819         if (NULL == of)
893           {                                       820           {
894             retval = -SOS_EBADF;                  821             retval = -SOS_EBADF;
895             break;                                822             break;
896           }                                       823           }
897                                                   824 
898         /* Compute 64 bits offset value */        825         /* Compute 64 bits offset value */
899         offset_in_resource   = offs64_hi;         826         offset_in_resource   = offs64_hi;
900         offset_in_resource <<= 32;                827         offset_in_resource <<= 32;
901         offset_in_resource  |= offs64_lo;         828         offset_in_resource  |= offs64_lo;
902                                                   829 
903         retval = sos_memcpy_from_user((sos_vad    830         retval = sos_memcpy_from_user((sos_vaddr_t)& hint_uaddr,
904                                       ptr_hint    831                                       ptr_hint_uaddr,
905                                       sizeof(h    832                                       sizeof(hint_uaddr));
906         if (sizeof(hint_uaddr) != retval)         833         if (sizeof(hint_uaddr) != retval)
907           {                                       834           {
908             retval = -SOS_EFAULT;                 835             retval = -SOS_EFAULT;
909             break;                                836             break;
910           }                                       837           }
911                                                   838 
912         retval = sos_fs_mmap(of, & hint_uaddr,    839         retval = sos_fs_mmap(of, & hint_uaddr, length, prot, flags,
913                              offset_in_resourc    840                              offset_in_resource);
914         if (SOS_OK == retval)                     841         if (SOS_OK == retval)
915           {                                       842           {
916             if (sizeof(hint_uaddr)                843             if (sizeof(hint_uaddr)
917                 != sos_memcpy_to_user(ptr_hint    844                 != sos_memcpy_to_user(ptr_hint_uaddr,
918                                       (sos_vad    845                                       (sos_vaddr_t)& hint_uaddr,
919                                       sizeof(h    846                                       sizeof(hint_uaddr)))
920               {                                   847               {
921                 sos_umem_vmm_unmap(sos_process    848                 sos_umem_vmm_unmap(sos_process_get_address_space(proc),
922                                    hint_uaddr,    849                                    hint_uaddr, length);
923                 retval = -SOS_EFAULT;             850                 retval = -SOS_EFAULT;
924               }                                   851               }
925           }                                       852           }
926                                                   853 
927       }                                           854       }
928       break;                                      855       break;
929                                                   856 
930     case SOS_SYSCALL_ID_FSYNC:                    857     case SOS_SYSCALL_ID_FSYNC:
931       {                                           858       {
932         struct sos_fs_opened_file * of;           859         struct sos_fs_opened_file * of;
933         struct sos_process * proc;                860         struct sos_process * proc;
934         int fd;                                   861         int fd;
935                                                   862 
936         proc = sos_thread_get_current()->proce    863         proc = sos_thread_get_current()->process;
937         retval = sos_syscall_get1arg(user_ctxt    864         retval = sos_syscall_get1arg(user_ctxt,
938                                      (unsigned    865                                      (unsigned int*)& fd);
939         if (SOS_OK != retval)                     866         if (SOS_OK != retval)
940           break;                                  867           break;
941                                                   868 
942         of = sos_process_get_opened_file(proc,    869         of = sos_process_get_opened_file(proc, fd);
943         if (NULL == of)                           870         if (NULL == of)
944           {                                       871           {
945             retval = -SOS_EBADF;                  872             retval = -SOS_EBADF;
946             break;                                873             break;
947           }                                       874           }
948                                                   875 
949         /* Do the actual sync */                  876         /* Do the actual sync */
950         retval = sos_fs_fsync(of);                877         retval = sos_fs_fsync(of);
951       }                                           878       }
952       break;                                      879       break;
953                                                   880 
954     case SOS_SYSCALL_ID_FCNTL:                    881     case SOS_SYSCALL_ID_FCNTL:
955       {                                           882       {
956         struct sos_fs_opened_file * of;           883         struct sos_fs_opened_file * of;
957         struct sos_process * proc;                884         struct sos_process * proc;
958         sos_ui32_t cmd, arg;                      885         sos_ui32_t cmd, arg;
959         int fd;                                   886         int fd;
960                                                   887 
961         proc = sos_thread_get_current()->proce    888         proc = sos_thread_get_current()->process;
962         retval = sos_syscall_get3args(user_ctx    889         retval = sos_syscall_get3args(user_ctxt,
963                                       (unsigne    890                                       (unsigned int*)& fd,
964                                       (unsigne    891                                       (unsigned int*)& cmd,
965                                       (unsigne    892                                       (unsigned int*)& arg);
966         if (SOS_OK != retval)                     893         if (SOS_OK != retval)
967           break;                                  894           break;
968                                                   895 
969         of = sos_process_get_opened_file(proc,    896         of = sos_process_get_opened_file(proc, fd);
970         if (NULL == of)                           897         if (NULL == of)
971           {                                       898           {
972             retval = -SOS_EBADF;                  899             retval = -SOS_EBADF;
973             break;                                900             break;
974           }                                       901           }
975                                                   902 
976         /* Do the actual fcntl */                 903         /* Do the actual fcntl */
977         retval = sos_fs_fcntl(of, cmd, arg);      904         retval = sos_fs_fcntl(of, cmd, arg);
978       }                                           905       }
979       break;                                      906       break;
980                                                   907 
                                                   >> 908     case SOS_SYSCALL_ID_IOCTL:
                                                   >> 909       {
                                                   >> 910         struct sos_fs_opened_file * of;
                                                   >> 911         struct sos_process * proc;
                                                   >> 912         sos_ui32_t cmd, arg;
                                                   >> 913         int fd;
                                                   >> 914 
                                                   >> 915         proc = sos_thread_get_current()->process;
                                                   >> 916         retval = sos_syscall_get3args(user_ctxt,
                                                   >> 917                                       (unsigned int*)& fd,
                                                   >> 918                                       (unsigned int*)& cmd,
                                                   >> 919                                       (unsigned int*)& arg);
                                                   >> 920         if (SOS_OK != retval)
                                                   >> 921           break;
                                                   >> 922 
                                                   >> 923         of = sos_process_get_opened_file(proc, fd);
                                                   >> 924         if (NULL == of)
                                                   >> 925           {
                                                   >> 926             retval = -SOS_EBADF;
                                                   >> 927             break;
                                                   >> 928           }
                                                   >> 929 
                                                   >> 930         /* Do the actual ioctl */
                                                   >> 931         retval = sos_fs_ioctl(of, cmd, arg);
                                                   >> 932       }
                                                   >> 933       break;
                                                   >> 934 
981     case SOS_SYSCALL_ID_CREAT:                    935     case SOS_SYSCALL_ID_CREAT:
982       {                                           936       {
983         sos_uaddr_t user_str;                     937         sos_uaddr_t user_str;
984         sos_size_t  len;                          938         sos_size_t  len;
985         sos_ui32_t  access_rights;                939         sos_ui32_t  access_rights;
986         char * path;                              940         char * path;
987         struct sos_process * proc;                941         struct sos_process * proc;
988                                                   942 
989         proc = sos_thread_get_current()->proce    943         proc = sos_thread_get_current()->process;
990         retval = sos_syscall_get3args(user_ctx    944         retval = sos_syscall_get3args(user_ctxt,
991                                       (unsigne    945                                       (unsigned int*)& user_str,
992                                       (unsigne    946                                       (unsigned int*)& len,
993                                       (unsigne    947                                       (unsigned int*)& access_rights);
994         if (SOS_OK != retval)                     948         if (SOS_OK != retval)
995           break;                                  949           break;
996                                                   950 
997         retval = sos_memdup_from_user((sos_vad !! 951         retval = sos_strndup_from_user(&path, user_str, len, 0);
998         if (SOS_OK != retval)                     952         if (SOS_OK != retval)
999           break;                                  953           break;
1000                                                  954 
1001         retval = sos_fs_creat(proc,              955         retval = sos_fs_creat(proc,
1002                               path, len,         956                               path, len,
1003                               access_rights);    957                               access_rights);
1004         sos_kfree((sos_vaddr_t)path);            958         sos_kfree((sos_vaddr_t)path);
1005       }                                          959       }
1006       break;                                     960       break;
1007                                                  961 
1008     case SOS_SYSCALL_ID_LINK:                    962     case SOS_SYSCALL_ID_LINK:
1009     case SOS_SYSCALL_ID_RENAME:                  963     case SOS_SYSCALL_ID_RENAME:
1010       {                                          964       {
1011         sos_uaddr_t user_oldpath, user_newpat    965         sos_uaddr_t user_oldpath, user_newpath;
1012         sos_size_t  oldpathlen, newpathlen;      966         sos_size_t  oldpathlen, newpathlen;
1013         char * kernel_oldpath, * kernel_newpa    967         char * kernel_oldpath, * kernel_newpath;
1014         struct sos_process * proc;               968         struct sos_process * proc;
1015                                                  969 
1016         proc = sos_thread_get_current()->proc    970         proc = sos_thread_get_current()->process;
1017         retval = sos_syscall_get4args(user_ct    971         retval = sos_syscall_get4args(user_ctxt,
1018                                       (unsign    972                                       (unsigned int*)& user_oldpath,
1019                                       (unsign    973                                       (unsigned int*)& oldpathlen,
1020                                       (unsign    974                                       (unsigned int*)& user_newpath,
1021                                       (unsign    975                                       (unsigned int*)& newpathlen);
1022         if (SOS_OK != retval)                    976         if (SOS_OK != retval)
1023           break;                                 977           break;
1024                                                  978 
1025         retval = sos_memdup_from_user((sos_va !! 979         retval = sos_strndup_from_user(&kernel_oldpath,
1026                                       user_ol !! 980                                        user_oldpath,
1027                                       oldpath !! 981                                        oldpathlen, 0);
1028         if (SOS_OK != retval)                    982         if (SOS_OK != retval)
1029           break;                                 983           break;
1030                                                  984 
1031         retval = sos_memdup_from_user((sos_va !! 985         retval = sos_strndup_from_user(&kernel_newpath,
1032                                       user_ne !! 986                                        user_newpath,
1033                                       newpath !! 987                                        newpathlen, 0);
1034         if (SOS_OK != retval)                    988         if (SOS_OK != retval)
1035           {                                      989           {
1036             sos_kfree((sos_vaddr_t) kernel_ol    990             sos_kfree((sos_vaddr_t) kernel_oldpath);
1037             break;                               991             break;
1038           }                                      992           }
1039                                                  993 
1040         if (syscall_id == SOS_SYSCALL_ID_LINK    994         if (syscall_id == SOS_SYSCALL_ID_LINK)
1041           retval = sos_fs_link(proc,             995           retval = sos_fs_link(proc,
1042                                kernel_oldpath    996                                kernel_oldpath, oldpathlen,
1043                                kernel_newpath    997                                kernel_newpath, newpathlen);
1044         else                                     998         else
1045           retval = sos_fs_rename(proc,           999           retval = sos_fs_rename(proc,
1046                                  kernel_oldpa    1000                                  kernel_oldpath, oldpathlen,
1047                                  kernel_newpa    1001                                  kernel_newpath, newpathlen);
1048         sos_kfree((sos_vaddr_t)kernel_oldpath    1002         sos_kfree((sos_vaddr_t)kernel_oldpath);
1049         sos_kfree((sos_vaddr_t)kernel_newpath    1003         sos_kfree((sos_vaddr_t)kernel_newpath);
1050       }                                          1004       }
1051       break;                                     1005       break;
1052                                                  1006 
1053     case SOS_SYSCALL_ID_UNLINK:                  1007     case SOS_SYSCALL_ID_UNLINK:
1054       {                                          1008       {
1055         sos_uaddr_t user_str;                    1009         sos_uaddr_t user_str;
1056         sos_size_t  len;                         1010         sos_size_t  len;
1057         char * path;                             1011         char * path;
1058         struct sos_process * proc;               1012         struct sos_process * proc;
1059                                                  1013 
1060         proc = sos_thread_get_current()->proc    1014         proc = sos_thread_get_current()->process;
1061         retval = sos_syscall_get2args(user_ct    1015         retval = sos_syscall_get2args(user_ctxt,
1062                                       (unsign    1016                                       (unsigned int*)& user_str,
1063                                       (unsign    1017                                       (unsigned int*)& len);
1064         if (SOS_OK != retval)                    1018         if (SOS_OK != retval)
1065           break;                                 1019           break;
1066                                                  1020 
1067         retval = sos_memdup_from_user((sos_va !! 1021         retval = sos_strndup_from_user(&path, user_str, len, 0);
1068         if (SOS_OK != retval)                    1022         if (SOS_OK != retval)
1069           break;                                 1023           break;
1070                                                  1024 
1071         retval = sos_fs_unlink(proc,             1025         retval = sos_fs_unlink(proc,
1072                                path, len);       1026                                path, len);
1073         sos_kfree((sos_vaddr_t)path);            1027         sos_kfree((sos_vaddr_t)path);
1074       }                                          1028       }
1075       break;                                     1029       break;
1076                                                  1030 
1077     case SOS_SYSCALL_ID_SYMLINK:                 1031     case SOS_SYSCALL_ID_SYMLINK:
1078       {                                          1032       {
1079         sos_uaddr_t user_path, user_targetpat    1033         sos_uaddr_t user_path, user_targetpath;
1080         sos_size_t  pathlen, targetpathlen;      1034         sos_size_t  pathlen, targetpathlen;
1081         char * kernel_path;                      1035         char * kernel_path;
1082         struct sos_process * proc;               1036         struct sos_process * proc;
1083                                                  1037 
1084         proc = sos_thread_get_current()->proc    1038         proc = sos_thread_get_current()->process;
1085         retval = sos_syscall_get4args(user_ct    1039         retval = sos_syscall_get4args(user_ctxt,
1086                                       (unsign    1040                                       (unsigned int*)& user_path,
1087                                       (unsign    1041                                       (unsigned int*)& pathlen,
1088                                       (unsign    1042                                       (unsigned int*)& user_targetpath,
1089                                       (unsign    1043                                       (unsigned int*)& targetpathlen);
1090         if (SOS_OK != retval)                    1044         if (SOS_OK != retval)
1091           break;                                 1045           break;
1092                                                  1046 
1093         retval = sos_memdup_from_user((sos_va !! 1047         retval = sos_strndup_from_user(&kernel_path,
1094                                       user_pa !! 1048                                        user_path,
1095                                       pathlen !! 1049                                        pathlen, 0);
1096         if (SOS_OK != retval)                    1050         if (SOS_OK != retval)
1097           break;                                 1051           break;
1098                                                  1052 
1099         retval = sos_fs_symlink(proc,            1053         retval = sos_fs_symlink(proc,
1100                                 kernel_path,     1054                                 kernel_path, pathlen,
1101                                 user_targetpa    1055                                 user_targetpath, targetpathlen);
1102         sos_kfree((sos_vaddr_t)kernel_path);     1056         sos_kfree((sos_vaddr_t)kernel_path);
1103       }                                          1057       }
1104       break;                                     1058       break;
1105                                                  1059 
                                                   >> 1060     case SOS_SYSCALL_ID_MKNOD:
                                                   >> 1061       {
                                                   >> 1062         sos_uaddr_t user_str;
                                                   >> 1063         sos_size_t  len;
                                                   >> 1064         sos_ui32_t  access_rights;
                                                   >> 1065         int type;
                                                   >> 1066         char * path;
                                                   >> 1067         struct sos_fs_dev_id_t dev_id;
                                                   >> 1068         struct sos_process * proc;
                                                   >> 1069 
                                                   >> 1070         proc = sos_thread_get_current()->process;
                                                   >> 1071         retval = sos_syscall_get6args(user_ctxt,
                                                   >> 1072                                       (unsigned int*)& user_str,
                                                   >> 1073                                       (unsigned int*)& len,
                                                   >> 1074                                       (unsigned int*)& type,
                                                   >> 1075                                       (unsigned int*)& access_rights,
                                                   >> 1076                                       (unsigned int*)& dev_id.device_class,
                                                   >> 1077                                       (unsigned int*)& dev_id.device_instance);
                                                   >> 1078         if (SOS_OK != retval)
                                                   >> 1079           break;
                                                   >> 1080 
                                                   >> 1081         retval = sos_strndup_from_user(&path, user_str, len, 0);
                                                   >> 1082         if (SOS_OK != retval)
                                                   >> 1083           break;
                                                   >> 1084 
                                                   >> 1085         switch (type)
                                                   >> 1086           {
                                                   >> 1087           case SOS_FS_NODE_REGULAR_FILE:
                                                   >> 1088             retval = sos_fs_creat(proc, path, len, access_rights);
                                                   >> 1089             break;
                                                   >> 1090 
                                                   >> 1091           case SOS_FS_NODE_DIRECTORY:
                                                   >> 1092             retval = sos_fs_mkdir(proc, path, len, access_rights);
                                                   >> 1093             break;
                                                   >> 1094 
                                                   >> 1095           case SOS_FS_NODE_SYMLINK:
                                                   >> 1096             retval = -SOS_ENOSUP;
                                                   >> 1097             break;
                                                   >> 1098 
                                                   >> 1099           case SOS_FS_NODE_DEVICE_CHAR:
                                                   >> 1100             retval = sos_fs_mknod(proc,
                                                   >> 1101                                   path, len, type, access_rights, &dev_id);
                                                   >> 1102             break;
                                                   >> 1103 
                                                   >> 1104           default:
                                                   >> 1105             retval = -SOS_EINVAL;
                                                   >> 1106             break;
                                                   >> 1107           }
                                                   >> 1108 
                                                   >> 1109         sos_kfree((sos_vaddr_t)path);
                                                   >> 1110       }
                                                   >> 1111       break;
                                                   >> 1112 
1106     case SOS_SYSCALL_ID_MKDIR:                   1113     case SOS_SYSCALL_ID_MKDIR:
1107       {                                          1114       {
1108         sos_uaddr_t user_str;                    1115         sos_uaddr_t user_str;
1109         sos_size_t  len;                         1116         sos_size_t  len;
1110         sos_ui32_t  access_rights;               1117         sos_ui32_t  access_rights;
1111         char * path;                             1118         char * path;
1112         struct sos_process * proc;               1119         struct sos_process * proc;
1113                                                  1120 
1114         proc = sos_thread_get_current()->proc    1121         proc = sos_thread_get_current()->process;
1115         retval = sos_syscall_get3args(user_ct    1122         retval = sos_syscall_get3args(user_ctxt,
1116                                       (unsign    1123                                       (unsigned int*)& user_str,
1117                                       (unsign    1124                                       (unsigned int*)& len,
1118                                       (unsign    1125                                       (unsigned int*)& access_rights);
1119         if (SOS_OK != retval)                    1126         if (SOS_OK != retval)
1120           break;                                 1127           break;
1121                                                  1128 
1122         retval = sos_memdup_from_user((sos_va !! 1129         retval = sos_strndup_from_user(&path, user_str, len, 0);
1123         if (SOS_OK != retval)                    1130         if (SOS_OK != retval)
1124           break;                                 1131           break;
1125                                                  1132 
1126         retval = sos_fs_mkdir(proc,              1133         retval = sos_fs_mkdir(proc,
1127                               path, len, acce    1134                               path, len, access_rights);
1128         sos_kfree((sos_vaddr_t)path);            1135         sos_kfree((sos_vaddr_t)path);
1129       }                                          1136       }
1130       break;                                     1137       break;
1131                                                  1138 
1132     case SOS_SYSCALL_ID_RMDIR:                   1139     case SOS_SYSCALL_ID_RMDIR:
1133       {                                          1140       {
1134         sos_uaddr_t user_str;                    1141         sos_uaddr_t user_str;
1135         sos_size_t  len;                         1142         sos_size_t  len;
1136         char * path;                             1143         char * path;
1137         struct sos_process * proc;               1144         struct sos_process * proc;
1138                                                  1145 
1139         proc = sos_thread_get_current()->proc    1146         proc = sos_thread_get_current()->process;
1140         retval = sos_syscall_get2args(user_ct    1147         retval = sos_syscall_get2args(user_ctxt,
1141                                       (unsign    1148                                       (unsigned int*)& user_str,
1142                                       (unsign    1149                                       (unsigned int*)& len);
1143         if (SOS_OK != retval)                    1150         if (SOS_OK != retval)
1144           break;                                 1151           break;
1145                                                  1152 
1146         retval = sos_memdup_from_user((sos_va !! 1153         retval = sos_strndup_from_user(&path, user_str, len, 0);
1147         if (SOS_OK != retval)                    1154         if (SOS_OK != retval)
1148           break;                                 1155           break;
1149                                                  1156 
1150         retval = sos_fs_rmdir(proc, path, len    1157         retval = sos_fs_rmdir(proc, path, len);
1151         sos_kfree((sos_vaddr_t)path);            1158         sos_kfree((sos_vaddr_t)path);
1152       }                                          1159       }
1153       break;                                     1160       break;
1154                                                  1161 
1155     case SOS_SYSCALL_ID_CHMOD:                   1162     case SOS_SYSCALL_ID_CHMOD:
1156       {                                          1163       {
1157         sos_uaddr_t user_str;                    1164         sos_uaddr_t user_str;
1158         sos_size_t  len;                         1165         sos_size_t  len;
1159         sos_ui32_t  access_rights;               1166         sos_ui32_t  access_rights;
1160         char * path;                             1167         char * path;
1161         struct sos_process * proc;               1168         struct sos_process * proc;
1162                                                  1169 
1163         proc = sos_thread_get_current()->proc    1170         proc = sos_thread_get_current()->process;
1164         retval = sos_syscall_get3args(user_ct    1171         retval = sos_syscall_get3args(user_ctxt,
1165                                       (unsign    1172                                       (unsigned int*)& user_str,
1166                                       (unsign    1173                                       (unsigned int*)& len,
1167                                       (unsign    1174                                       (unsigned int*)& access_rights);
1168         if (SOS_OK != retval)                    1175         if (SOS_OK != retval)
1169           break;                                 1176           break;
1170                                                  1177 
1171         retval = sos_memdup_from_user((sos_va !! 1178         retval = sos_strndup_from_user(&path, user_str, len, 0);
1172         if (SOS_OK != retval)                    1179         if (SOS_OK != retval)
1173           break;                                 1180           break;
1174                                                  1181 
1175         retval = sos_fs_chmod(proc, path, len    1182         retval = sos_fs_chmod(proc, path, len, access_rights);
1176         sos_kfree((sos_vaddr_t)path);            1183         sos_kfree((sos_vaddr_t)path);
1177       }                                          1184       }
1178       break;                                     1185       break;
1179                                                  1186 
1180     case SOS_SYSCALL_ID_STAT64:                  1187     case SOS_SYSCALL_ID_STAT64:
1181       {                                          1188       {
1182         sos_uaddr_t user_str;                    1189         sos_uaddr_t user_str;
1183         sos_size_t  len;                         1190         sos_size_t  len;
1184         sos_uaddr_t user_stat_struct;            1191         sos_uaddr_t user_stat_struct;
1185         struct sos_fs_stat kernel_stat_struct    1192         struct sos_fs_stat kernel_stat_struct;
1186         int nofollow;                            1193         int nofollow;
1187         char * path;                             1194         char * path;
1188         struct sos_process * proc;               1195         struct sos_process * proc;
1189                                                  1196 
1190         proc = sos_thread_get_current()->proc    1197         proc = sos_thread_get_current()->process;
1191         retval = sos_syscall_get4args(user_ct    1198         retval = sos_syscall_get4args(user_ctxt,
1192                                       (unsign    1199                                       (unsigned int*)& user_str,
1193                                       (unsign    1200                                       (unsigned int*)& len,
1194                                       (unsign    1201                                       (unsigned int*)& nofollow,
1195                                       (unsign    1202                                       (unsigned int*)& user_stat_struct);
1196         if (SOS_OK != retval)                    1203         if (SOS_OK != retval)
1197           break;                                 1204           break;
1198                                                  1205 
1199         retval = sos_memdup_from_user((sos_va !! 1206         retval = sos_strndup_from_user(&path, user_str, len, 0);
1200         if (SOS_OK != retval)                    1207         if (SOS_OK != retval)
1201           break;                                 1208           break;
1202                                                  1209 
1203         retval = sos_fs_stat(proc, path, len,    1210         retval = sos_fs_stat(proc, path, len, nofollow, & kernel_stat_struct);
1204         sos_kfree((sos_vaddr_t)path);            1211         sos_kfree((sos_vaddr_t)path);
1205         if (SOS_OK != retval)                    1212         if (SOS_OK != retval)
1206           break;                                 1213           break;
1207                                                  1214 
1208         if (sizeof(kernel_stat_struct)           1215         if (sizeof(kernel_stat_struct)
1209             != sos_memcpy_to_user(user_stat_s    1216             != sos_memcpy_to_user(user_stat_struct,
1210                                   (sos_vaddr_    1217                                   (sos_vaddr_t) & kernel_stat_struct,
1211                                   sizeof(kern    1218                                   sizeof(kernel_stat_struct)))
1212           retval = -SOS_EFAULT;                  1219           retval = -SOS_EFAULT;
1213       }                                          1220       }
1214       break;                                     1221       break;
1215                                                  1222 
1216     case SOS_SYSCALL_ID_CHROOT:                  1223     case SOS_SYSCALL_ID_CHROOT:
1217     case SOS_SYSCALL_ID_CHDIR:                   1224     case SOS_SYSCALL_ID_CHDIR:
1218       {                                          1225       {
1219         sos_uaddr_t user_str;                    1226         sos_uaddr_t user_str;
1220         sos_size_t  len;                         1227         sos_size_t  len;
1221         char * path;                             1228         char * path;
1222         struct sos_fs_opened_file * of, * old    1229         struct sos_fs_opened_file * of, * old_of;
1223         struct sos_process * proc;               1230         struct sos_process * proc;
1224                                                  1231 
1225         proc = sos_thread_get_current()->proc    1232         proc = sos_thread_get_current()->process;
1226         retval = sos_syscall_get2args(user_ct    1233         retval = sos_syscall_get2args(user_ctxt,
1227                                       (unsign    1234                                       (unsigned int*)& user_str,
1228                                       (unsign    1235                                       (unsigned int*)& len);
1229         if (SOS_OK != retval)                    1236         if (SOS_OK != retval)
1230           break;                                 1237           break;
1231                                                  1238 
1232         retval = sos_memdup_from_user((sos_va !! 1239         retval = sos_strndup_from_user(&path, user_str, len, 0);
1233         if (SOS_OK != retval)                    1240         if (SOS_OK != retval)
1234           break;                                 1241           break;
1235                                                  1242 
1236         retval = sos_fs_open(proc,               1243         retval = sos_fs_open(proc,
1237                              path, len,          1244                              path, len,
1238                              SOS_FS_OPEN_DIRE    1245                              SOS_FS_OPEN_DIRECTORY,
1239                              SOS_FS_OPEN_READ    1246                              SOS_FS_OPEN_READ,
1240                              & of);              1247                              & of);
1241         sos_kfree((sos_vaddr_t)path);            1248         sos_kfree((sos_vaddr_t)path);
1242         if (SOS_OK != retval)                    1249         if (SOS_OK != retval)
1243           break;                                 1250           break;
1244                                                  1251 
1245         if (syscall_id == SOS_SYSCALL_ID_CHRO    1252         if (syscall_id == SOS_SYSCALL_ID_CHROOT)
1246           retval = sos_process_chroot(proc, o    1253           retval = sos_process_chroot(proc, of, & old_of);
1247         else                                     1254         else
1248           retval = sos_process_chdir(proc, of    1255           retval = sos_process_chdir(proc, of, & old_of);
1249                                                  1256 
1250         if (retval < 0)                          1257         if (retval < 0)
1251           {                                      1258           {
1252             sos_fs_close(of);                    1259             sos_fs_close(of);
1253             break;                               1260             break;
1254           }                                      1261           }
1255                                                  1262 
1256         sos_fs_close(old_of);                    1263         sos_fs_close(old_of);
1257       }                                          1264       }
1258       break;                                     1265       break;      
1259                                                  1266 
1260     case SOS_SYSCALL_ID_FCHDIR:                  1267     case SOS_SYSCALL_ID_FCHDIR:
1261       {                                          1268       {
1262         struct sos_fs_opened_file * of, * new    1269         struct sos_fs_opened_file * of, * new_of, * old_of;
1263         struct sos_process * proc;               1270         struct sos_process * proc;
1264         int fd;                                  1271         int fd;
1265                                                  1272 
1266         proc = sos_thread_get_current()->proc    1273         proc = sos_thread_get_current()->process;
1267         retval = sos_syscall_get1arg(user_ctx    1274         retval = sos_syscall_get1arg(user_ctxt,
1268                                      (unsigne    1275                                      (unsigned int*)& fd);
1269         if (SOS_OK != retval)                    1276         if (SOS_OK != retval)
1270           break;                                 1277           break;
1271                                                  1278 
1272         of = sos_process_get_opened_file(proc    1279         of = sos_process_get_opened_file(proc, fd);
1273         if (NULL == of)                          1280         if (NULL == of)
1274           {                                      1281           {
1275             retval = -SOS_EBADF;                 1282             retval = -SOS_EBADF;
1276             break;                               1283             break;
1277           }                                      1284           }
1278                                                  1285 
1279         /* Duplicate this FD */                  1286         /* Duplicate this FD */
1280         retval = sos_fs_duplicate_opened_file    1287         retval = sos_fs_duplicate_opened_file(of, proc, & new_of);
1281         if (SOS_OK != retval)                    1288         if (SOS_OK != retval)
1282           break;                                 1289           break;
1283                                                  1290 
1284         /* Do the actual chdir */                1291         /* Do the actual chdir */
1285         retval = sos_process_chdir(proc, new_    1292         retval = sos_process_chdir(proc, new_of, & old_of);
1286         if (retval < 0)                          1293         if (retval < 0)
1287           {                                      1294           {
1288             sos_fs_close(new_of);                1295             sos_fs_close(new_of);
1289             break;                               1296             break;
1290           }                                      1297           }
1291                                                  1298 
1292         sos_fs_close(old_of);                    1299         sos_fs_close(old_of);
1293       }                                          1300       }
1294       break;                                     1301       break;
1295                                                  1302 
1296     case SOS_SYSCALL_ID_BOCHS_WRITE:             1303     case SOS_SYSCALL_ID_BOCHS_WRITE:
1297       {                                          1304       {
1298         sos_uaddr_t user_str;                    1305         sos_uaddr_t user_str;
1299         sos_size_t len;                          1306         sos_size_t len;
1300         char * str;                              1307         char * str;
1301         retval = sos_syscall_get2args(user_ct    1308         retval = sos_syscall_get2args(user_ctxt, & user_str, & len);
1302         if (SOS_OK != retval)                    1309         if (SOS_OK != retval)
1303           break;                                 1310           break;
1304                                                  1311 
1305         retval = sos_strndup_from_user(& str,    1312         retval = sos_strndup_from_user(& str, user_str, len + 1, 0);
1306         if (SOS_OK == retval)                    1313         if (SOS_OK == retval)
1307           {                                      1314           {
1308             sos_bochs_printf("THR 0x%x: ",       1315             sos_bochs_printf("THR 0x%x: ",
1309                              (unsigned)sos_th    1316                              (unsigned)sos_thread_get_current());
1310             retval = sos_bochs_putstring(str)    1317             retval = sos_bochs_putstring(str);
1311             retval = len;                        1318             retval = len;
1312             sos_kfree((sos_vaddr_t)str);         1319             sos_kfree((sos_vaddr_t)str);
1313           }                                      1320           }
1314       }                                          1321       }
1315       break;                                     1322       break;
1316                                                  1323 
1317                                                  1324 
1318       /* ************************************    1325       /* ***********************************************
1319        * Debug syscalls (will be removed in t    1326        * Debug syscalls (will be removed in the future)
1320        */                                        1327        */
1321                                                  1328 
1322                                                  1329 
1323       /**                                        1330       /**
1324        * Syscall 4012: hexdump of a user-spac    1331        * Syscall 4012: hexdump of a user-space memory region
1325        * args: addr_start size, retval=ignore    1332        * args: addr_start size, retval=ignored
1326        */                                        1333        */
1327     case 4012:                                   1334     case 4012:
1328       {                                          1335       {
1329         sos_uaddr_t user_str;                    1336         sos_uaddr_t user_str;
1330         unsigned int len;                        1337         unsigned int len;
1331         unsigned char * str;                     1338         unsigned char * str;
1332                                                  1339 
1333         retval = sos_syscall_get2args(user_ct    1340         retval = sos_syscall_get2args(user_ctxt, & user_str, & len);
1334         if (SOS_OK != retval)                    1341         if (SOS_OK != retval)
1335           break;                                 1342           break;
1336                                                  1343 
1337         str = (char*)sos_kmalloc(len, 0);     !! 1344         str = (unsigned char*)sos_kmalloc(len, 0);
1338         if (str)                                 1345         if (str)
1339           {                                      1346           {
1340             int i;                               1347             int i;
1341             sos_bochs_printf("Hexdump(0x%x, %    1348             sos_bochs_printf("Hexdump(0x%x, %d):\n", user_str, len);
1342             retval = sos_memcpy_from_user((so    1349             retval = sos_memcpy_from_user((sos_vaddr_t) str, user_str, len);
1343             sos_bochs_printf("  (Successfully    1350             sos_bochs_printf("  (Successfully copied %d out of %d)\n",
1344                              retval, len);       1351                              retval, len);
1345                                                  1352 
1346             for (i = 0 ; i < retval ; i++)       1353             for (i = 0 ; i < retval ; i++)
1347               {                                  1354               {
1348                 if ((i % 32) == 0)               1355                 if ((i % 32) == 0)
1349                   sos_bochs_printf("%x:", i);    1356                   sos_bochs_printf("%x:", i);
1350                 sos_bochs_printf(" %x", str[i    1357                 sos_bochs_printf(" %x", str[i]);
1351                 if (((i+1) % 32) == 0)           1358                 if (((i+1) % 32) == 0)
1352                   sos_bochs_printf("\n");        1359                   sos_bochs_printf("\n");
1353               }                                  1360               }
1354             if (i % 32)                          1361             if (i % 32)
1355               sos_bochs_printf("\n");            1362               sos_bochs_printf("\n");
1356                                                  1363 
1357             sos_kfree((sos_vaddr_t)str);         1364             sos_kfree((sos_vaddr_t)str);
1358           }                                      1365           }
1359         else                                     1366         else
1360           retval = -SOS_ENOMEM;                  1367           retval = -SOS_ENOMEM;
1361       }                                          1368       }
1362       break;                                     1369       break;
1363                                                  1370 
1364                                                  1371       
1365       /**                                        1372       /**
1366        * Syscall 4004: lists the VR of the cu    1373        * Syscall 4004: lists the VR of the current thread's address space
1367        * args: debug_string, retval=ignored      1374        * args: debug_string, retval=ignored
1368        */                                        1375        */
1369     case 4004:                                   1376     case 4004:
1370       {                                          1377       {
1371         sos_uaddr_t ustr;                        1378         sos_uaddr_t ustr;
1372         char * kstr;                             1379         char * kstr;
1373         struct sos_umem_vmm_as * my_as;          1380         struct sos_umem_vmm_as * my_as;
1374                                                  1381 
1375         retval = sos_syscall_get1arg(user_ctx    1382         retval = sos_syscall_get1arg(user_ctxt, & ustr);
1376         if (SOS_OK != retval)                    1383         if (SOS_OK != retval)
1377           break;                                 1384           break;
1378                                                  1385 
1379         retval = sos_strndup_from_user(& kstr    1386         retval = sos_strndup_from_user(& kstr, ustr, 256, 0);
1380         if (SOS_OK != retval)                    1387         if (SOS_OK != retval)
1381           break;                                 1388           break;
1382                                                  1389 
1383         extern void sos_dump_as(const struct     1390         extern void sos_dump_as(const struct sos_umem_vmm_as *, const char *);
1384         my_as                                    1391         my_as
1385           = sos_process_get_address_space(sos    1392           = sos_process_get_address_space(sos_thread_get_current()->process);
1386         sos_dump_as(my_as, kstr);                1393         sos_dump_as(my_as, kstr);
1387         sos_kfree((sos_vaddr_t)kstr);            1394         sos_kfree((sos_vaddr_t)kstr);
1388       }                                          1395       }
1389       break;                                     1396       break;
1390                                                  1397 
1391                                                  1398 
1392       /**                                        1399       /**
1393        * Syscall 4008: dump the list of proce    1400        * Syscall 4008: dump the list of processes in the system
1394        * args: none, retval=ignored              1401        * args: none, retval=ignored
1395        */                                        1402        */
1396     case 4008:                                   1403     case 4008:
1397       {                                          1404       {
1398         extern void sos_process_dumplist(void    1405         extern void sos_process_dumplist(void);
1399         sos_process_dumplist();                  1406         sos_process_dumplist();
1400         retval = SOS_OK;                         1407         retval = SOS_OK;
1401       }                                          1408       }
1402       break;                                     1409       break;
1403                                                  1410 
1404     default:                                     1411     default:
1405       sos_bochs_printf("Syscall: UNKNOWN[%d]\    1412       sos_bochs_printf("Syscall: UNKNOWN[%d]\n", syscall_id);
1406       retval = -SOS_ENOSUP;                      1413       retval = -SOS_ENOSUP;
1407     }                                            1414     }
1408                                                  1415   
1409   return retval;                                 1416   return retval;
1410 }                                                1417 }
                                                      

source navigation ] diff markup ] identifier search ] general search ]