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 /userland/crt.c (Article 9.5) and /userland/crt.c (Article 9)


001 /* Copyright (C) 2005 David Decotigny             001 /* Copyright (C) 2005 David Decotigny
002    Copyright (C) 2003 Thomas Petazzoni            002    Copyright (C) 2003 Thomas Petazzoni
003                                                   003 
004    This program is free software; you can redi    004    This program is free software; you can redistribute it and/or
005    modify it under the terms of the GNU Genera    005    modify it under the terms of the GNU General Public License
006    as published by the Free Software Foundatio    006    as published by the Free Software Foundation; either version 2
007    of the License, or (at your option) any lat    007    of the License, or (at your option) any later version.
008                                                   008    
009    This program is distributed in the hope tha    009    This program is distributed in the hope that it will be useful,
010    but WITHOUT ANY WARRANTY; without even the     010    but WITHOUT ANY WARRANTY; without even the implied warranty of
011    MERCHANTABILITY or FITNESS FOR A PARTICULAR    011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012    GNU General Public License for more details    012    GNU General Public License for more details.
013                                                   013    
014    You should have received a copy of the GNU     014    You should have received a copy of the GNU General Public License
015    along with this program; if not, write to t    015    along with this program; if not, write to the Free Software
016    Foundation, Inc., 59 Temple Place - Suite 3    016    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
017    USA.                                           017    USA. 
018 */                                                018 */
019                                                   019 
020                                                   020 
021 /**                                               021 /**
022  * @file crt.c                                    022  * @file crt.c
023  *                                                023  *
024  * The C RunTime environment for the basic sup    024  * The C RunTime environment for the basic support of SOS C user
025  * programs                                       025  * programs
026  */                                               026  */
027                                                   027 
028 #include <hwcore/swintr.h>                        028 #include <hwcore/swintr.h>
029 #include <string.h>                               029 #include <string.h>
030 #include "crt.h"                                  030 #include "crt.h"
031                                                   031 
032 /**                                               032 /**
033  * Starter function !                             033  * Starter function !
034  */                                               034  */
035 void _start(void) __attribute__((noreturn));   !! 035 void _start() __attribute__((noreturn));
036 void _start(void)                              !! 036 void _start()
037 {                                                 037 {
038   /* This starter function expects a main() fu    038   /* This starter function expects a main() function somewhere */
039   extern int main(void);                       !! 039   extern int main();
040                                                   040 
041   /* Reset the bss section */                     041   /* Reset the bss section */
042   extern char _bbss, _ebss;                       042   extern char _bbss, _ebss;
043   memset(& _bbss, 0x0, (& _ebss) - (& _bbss));    043   memset(& _bbss, 0x0, (& _ebss) - (& _bbss));
044                                                   044 
045   _sos_exit(main());                              045   _sos_exit(main());
046 }                                                 046 }
047                                                   047 
048                                                   048 
049 /*                                                049 /*
050  * By convention, the USER SOS programs always    050  * By convention, the USER SOS programs always pass 4 arguments to the
051  * kernel syscall handler: in eax/../edx. For     051  * kernel syscall handler: in eax/../edx. For less arguments, the
052  * unused registers are filled with 0s. For mo    052  * unused registers are filled with 0s. For more arguments, the 4th
053  * syscall parameter gives the address of the     053  * syscall parameter gives the address of the array containing the
054  * remaining arguments. In any case, eax corre    054  * remaining arguments. In any case, eax corresponds to the syscall
055  * IDentifier.                                    055  * IDentifier.
056  */                                               056  */
057                                                   057 
058                                                   058 
059 inline                                            059 inline
060 int _sos_syscall3(int id,                         060 int _sos_syscall3(int id,
061                   unsigned int arg1,              061                   unsigned int arg1,
062                   unsigned int arg2,              062                   unsigned int arg2,
063                   unsigned int arg3)              063                   unsigned int arg3)
064 {                                                 064 {
065   int ret;                                        065   int ret;
066                                                   066   
067   asm volatile("movl %1,%%eax \n"                 067   asm volatile("movl %1,%%eax \n"
068                "movl %2,%%ebx \n"                 068                "movl %2,%%ebx \n"
069                "movl %3,%%ecx \n"                 069                "movl %3,%%ecx \n"
070                "movl %4,%%edx \n"                 070                "movl %4,%%edx \n"
071                "int  %5\n"                        071                "int  %5\n"
072                "movl %%eax, %0"                   072                "movl %%eax, %0"
073                :"=g"(ret)                         073                :"=g"(ret)
074                :"g"(id),"g"(arg1),"g"(arg2),"g    074                :"g"(id),"g"(arg1),"g"(arg2),"g"(arg3)
075                 ,"i"(SOS_SWINTR_SOS_SYSCALL)      075                 ,"i"(SOS_SWINTR_SOS_SYSCALL)
076                :"eax","ebx","ecx","edx","memor    076                :"eax","ebx","ecx","edx","memory");
077                                                   077 
078   return ret;                                     078   return ret;
079 }                                                 079 }
080                                                   080 
081                                                   081 
082 int _sos_syscall0(int id)                         082 int _sos_syscall0(int id)
083 {                                                 083 {
084   return _sos_syscall3(id, 0, 0, 0);              084   return _sos_syscall3(id, 0, 0, 0);
085 }                                                 085 }
086                                                   086 
087                                                   087 
088 int _sos_syscall1(int id,                         088 int _sos_syscall1(int id,
089              unsigned int arg1)                   089              unsigned int arg1)
090 {                                                 090 {
091   return _sos_syscall3(id, arg1, 0, 0);           091   return _sos_syscall3(id, arg1, 0, 0);
092 }                                                 092 }
093                                                   093 
094                                                   094 
095 int _sos_syscall2(int id,                         095 int _sos_syscall2(int id,
096                   unsigned int arg1,              096                   unsigned int arg1,
097                   unsigned int arg2)              097                   unsigned int arg2)
098 {                                                 098 {
099   return _sos_syscall3(id, arg1, arg2, 0);        099   return _sos_syscall3(id, arg1, arg2, 0);
100 }                                                 100 }
101                                                   101 
102                                                   102 
103 int _sos_syscall4(int id,                         103 int _sos_syscall4(int id,
104                   unsigned int arg1,              104                   unsigned int arg1,
105                   unsigned int arg2,              105                   unsigned int arg2,
106                   unsigned int arg3,              106                   unsigned int arg3,
107                   unsigned int arg4)              107                   unsigned int arg4)
108 {                                                 108 {
109   unsigned int args[] = { arg3, arg4 };           109   unsigned int args[] = { arg3, arg4 };
110   return _sos_syscall3(id, arg1, arg2, (unsign    110   return _sos_syscall3(id, arg1, arg2, (unsigned)args);
111 }                                                 111 }
112                                                   112 
113                                                   113 
114 int _sos_syscall5(int id,                         114 int _sos_syscall5(int id,
115                   unsigned int arg1,              115                   unsigned int arg1,
116                   unsigned int arg2,              116                   unsigned int arg2,
117                   unsigned int arg3,              117                   unsigned int arg3,
118                   unsigned int arg4,              118                   unsigned int arg4,
119                   unsigned int arg5)              119                   unsigned int arg5)
120 {                                                 120 {
121   unsigned int args[] = { arg3, arg4, arg5 };     121   unsigned int args[] = { arg3, arg4, arg5 };
122   return _sos_syscall3(id, arg1, arg2, (unsign    122   return _sos_syscall3(id, arg1, arg2, (unsigned)args);
123 }                                                 123 }
124                                                   124 
125                                                   125 
126 int _sos_syscall6(int id,                         126 int _sos_syscall6(int id,
127                   unsigned int arg1,              127                   unsigned int arg1,
128                   unsigned int arg2,              128                   unsigned int arg2,
129                   unsigned int arg3,              129                   unsigned int arg3,
130                   unsigned int arg4,              130                   unsigned int arg4,
131                   unsigned int arg5,              131                   unsigned int arg5,
132                   unsigned int arg6)              132                   unsigned int arg6)
133 {                                                 133 {
134   unsigned int args[] = { arg3, arg4, arg5, ar    134   unsigned int args[] = { arg3, arg4, arg5, arg6 };
135   return _sos_syscall3(id, arg1, arg2, (unsign    135   return _sos_syscall3(id, arg1, arg2, (unsigned)args);
136 }                                                 136 }
137                                                   137 
138                                                   138 
139 int _sos_syscall7(int id,                         139 int _sos_syscall7(int id,
140                   unsigned int arg1,              140                   unsigned int arg1,
141                   unsigned int arg2,              141                   unsigned int arg2,
142                   unsigned int arg3,              142                   unsigned int arg3,
143                   unsigned int arg4,              143                   unsigned int arg4,
144                   unsigned int arg5,              144                   unsigned int arg5,
145                   unsigned int arg6,              145                   unsigned int arg6,
146                   unsigned int arg7)              146                   unsigned int arg7)
147 {                                                 147 {
148   unsigned int args[] = { arg3, arg4, arg5, ar    148   unsigned int args[] = { arg3, arg4, arg5, arg6, arg7 };
149   return _sos_syscall3(id, arg1, arg2, (unsign    149   return _sos_syscall3(id, arg1, arg2, (unsigned)args);
150 }                                                 150 }
151                                                   151 
152                                                   152 
153 int _sos_syscall8(int id,                         153 int _sos_syscall8(int id,
154                   unsigned int arg1,              154                   unsigned int arg1,
155                   unsigned int arg2,              155                   unsigned int arg2,
156                   unsigned int arg3,              156                   unsigned int arg3,
157                   unsigned int arg4,              157                   unsigned int arg4,
158                   unsigned int arg5,              158                   unsigned int arg5,
159                   unsigned int arg6,              159                   unsigned int arg6,
160                   unsigned int arg7,              160                   unsigned int arg7,
161                   unsigned int arg8)              161                   unsigned int arg8)
162 {                                                 162 {
163   unsigned int args[] = { arg3, arg4, arg5, ar    163   unsigned int args[] = { arg3, arg4, arg5, arg6, arg7, arg8 };
164   return _sos_syscall3(id, arg1, arg2, (unsign    164   return _sos_syscall3(id, arg1, arg2, (unsigned)args);
165 }                                                 165 }
166                                                   166 
167                                                   167 
168 void _sos_exit(int status)                        168 void _sos_exit(int status)
169 {                                                 169 {
170   _sos_syscall1(SOS_SYSCALL_ID_EXIT, (unsigned    170   _sos_syscall1(SOS_SYSCALL_ID_EXIT, (unsigned)status);
171                                                   171   
172   /* Never reached ! */                           172   /* Never reached ! */
173   for ( ; ; )                                     173   for ( ; ; )
174     ;                                             174     ;
175 }                                                 175 }
176                                                   176 
177                                                   177 
178 int _sos_bochs_write(const char * str, unsigne    178 int _sos_bochs_write(const char * str, unsigned length)
179 {                                                 179 {
180   return _sos_syscall2(SOS_SYSCALL_ID_BOCHS_WR    180   return _sos_syscall2(SOS_SYSCALL_ID_BOCHS_WRITE,
181                        (unsigned)str,             181                        (unsigned)str,
182                        length);                   182                        length);
183 }                                                 183 }
184                                                   184 
185                                                   185 
186 int _sos_fork()                                   186 int _sos_fork()
187 {                                                 187 {
188   return _sos_syscall0(SOS_SYSCALL_ID_FORK);      188   return _sos_syscall0(SOS_SYSCALL_ID_FORK);
189 }                                                 189 }
190                                                   190 
191                                                   191 
192 int _sos_exec(const char * prog)                  192 int _sos_exec(const char * prog)
193 {                                                 193 {
194   return _sos_syscall2(SOS_SYSCALL_ID_EXEC, (u    194   return _sos_syscall2(SOS_SYSCALL_ID_EXEC, (unsigned int)prog,
195                        (unsigned int)strlen(pr    195                        (unsigned int)strlen(prog));
196 }                                                 196 }
197                                                   197 
198                                                   198 
199 int _sos_munmap(void * start, size_t length)      199 int _sos_munmap(void * start, size_t length)
200 {                                                 200 {
201   return _sos_syscall2(SOS_SYSCALL_ID_MUNMAP,     201   return _sos_syscall2(SOS_SYSCALL_ID_MUNMAP,
202                        (unsigned int)start,       202                        (unsigned int)start,
203                        length);                   203                        length);
204 }                                                 204 }
205                                                   205 
206                                                   206 
207 int _sos_mprotect(const void *addr, size_t len    207 int _sos_mprotect(const void *addr, size_t len, int prot)
208 {                                                 208 {
209   return _sos_syscall3(SOS_SYSCALL_ID_MPROTECT    209   return _sos_syscall3(SOS_SYSCALL_ID_MPROTECT,
210                        (unsigned int)addr,        210                        (unsigned int)addr,
211                        len,                       211                        len,
212                        (unsigned int)prot);       212                        (unsigned int)prot);
213 }                                                 213 }
214                                                   214 
215                                                   215 
216 int _sos_mresize(void * old_addr, size_t old_l    216 int _sos_mresize(void * old_addr, size_t old_len,
217                  void * *new_addr, size_t new_    217                  void * *new_addr, size_t new_len,
218                  unsigned long flags)             218                  unsigned long flags)
219 {                                                 219 {
220   return _sos_syscall5(SOS_SYSCALL_ID_MRESIZE,    220   return _sos_syscall5(SOS_SYSCALL_ID_MRESIZE,
221                        (unsigned int)old_addr,    221                        (unsigned int)old_addr,
222                        old_len,                   222                        old_len,
223                        (unsigned int)new_addr,    223                        (unsigned int)new_addr,
224                        new_len,                   224                        new_len,
225                        flags);                    225                        flags);
226 }                                                 226 }
227                                                   227 
228                                                   228 
229 int _sos_msync(void *start, size_t length, int << 
230 {                                              << 
231   return _sos_syscall3(SOS_SYSCALL_ID_MSYNC,   << 
232                        (unsigned int)start,    << 
233                        length,                 << 
234                        flags);                 << 
235 }                                              << 
236                                                << 
237                                                << 
238 /**                                               229 /**
239  * Helper function that represents the start r    230  * Helper function that represents the start routine of a new user
240  * thread created from user space (syscall new    231  * thread created from user space (syscall new_thread). It takes 2
241  * arguments that are passsed in the eax/ebx r    232  * arguments that are passsed in the eax/ebx registers (@see
242  * cpu_ustate_init() in hwcore/cpu_context.c):    233  * cpu_ustate_init() in hwcore/cpu_context.c): the start function of
243  * the new thread (eax), the argument passed t    234  * the new thread (eax), the argument passed to it (ebx).
244  */                                               235  */
245 static void thread_routine(void)               !! 236 static void thread_routine()
246 {                                                 237 {
247   /* NOTE: variables as named registers is a g    238   /* NOTE: variables as named registers is a gcc extension */
248   register unsigned long int reg_arg1 asm("%ea    239   register unsigned long int reg_arg1 asm("%eax");
249   register unsigned long int reg_arg2 asm("%eb    240   register unsigned long int reg_arg2 asm("%ebx");
250                                                   241 
251   sos_thread_func_t * func = (sos_thread_func_    242   sos_thread_func_t * func = (sos_thread_func_t*)reg_arg1;
252   unsigned long int arg = reg_arg2;               243   unsigned long int arg = reg_arg2;
253                                                   244 
254   func(arg);                                      245   func(arg);
255   _sos_exit(0);                                   246   _sos_exit(0);
256 }                                                 247 }
257                                                   248 
258                                                   249 
259 int _sos_new_thread(sos_thread_func_t *func,      250 int _sos_new_thread(sos_thread_func_t *func,
260                     void* arg,                    251                     void* arg,
261                     size_t stack_size)            252                     size_t stack_size)
262 {                                                 253 {
263   return _sos_syscall4(SOS_SYSCALL_ID_NEW_THRE    254   return _sos_syscall4(SOS_SYSCALL_ID_NEW_THREAD,
264                        (unsigned)thread_routin    255                        (unsigned)thread_routine,
265                        (unsigned)func, (unsign    256                        (unsigned)func, (unsigned)arg,
266                        stack_size);               257                        stack_size);
267 }                                                 258 }
268                                                   259 
269                                                   260 
270 int _sos_nanosleep(unsigned long int sec,         261 int _sos_nanosleep(unsigned long int sec,
271                    unsigned long int nanosec)     262                    unsigned long int nanosec)
272 {                                                 263 {
273   return _sos_syscall2(SOS_SYSCALL_ID_NANOSLEE    264   return _sos_syscall2(SOS_SYSCALL_ID_NANOSLEEP,
274                        sec, nanosec);             265                        sec, nanosec);
275 }                                                 266 }
276                                                   267 
277                                                   268 
278 void * _sos_brk(void * new_top_address)           269 void * _sos_brk(void * new_top_address)
279 {                                                 270 {
280   return (void*)_sos_syscall1(SOS_SYSCALL_ID_B    271   return (void*)_sos_syscall1(SOS_SYSCALL_ID_BRK,
281                               (unsigned)new_to    272                               (unsigned)new_top_address);
282 }                                                 273 }
283                                                   274 
284                                                   275 
285 int _sos_mount(const char *source, const char     276 int _sos_mount(const char *source, const char *target,
286                const char *filesystemtype, uns    277                const char *filesystemtype, unsigned long mountflags,
287                const char *args)                  278                const char *args)
288 {                                                 279 {
289   if (!target || !filesystemtype)                 280   if (!target || !filesystemtype)
290     return -1;                                    281     return -1;
291                                                   282 
292   return _sos_syscall7(SOS_SYSCALL_ID_MOUNT,      283   return _sos_syscall7(SOS_SYSCALL_ID_MOUNT,
293                        (unsigned int)source, s    284                        (unsigned int)source, source?strlen(source):0,
294                        (unsigned int)target, s    285                        (unsigned int)target, strlen(target),
295                        (unsigned int)filesyste    286                        (unsigned int)filesystemtype,
296                        mountflags,                287                        mountflags,
297                        (unsigned int)args);       288                        (unsigned int)args);
298 }                                                 289 }
299                                                   290 
300                                                   291 
301 int _sos_umount(const char *target)               292 int _sos_umount(const char *target)
302 {                                                 293 {
303   if (!target)                                    294   if (!target)
304     return -1;                                    295     return -1;
305                                                   296 
306   return _sos_syscall2(SOS_SYSCALL_ID_UMOUNT,     297   return _sos_syscall2(SOS_SYSCALL_ID_UMOUNT,
307                        (unsigned int)target,      298                        (unsigned int)target,
308                        strlen(target));           299                        strlen(target));
309 }                                                 300 }
310                                                   301 
311                                                   302 
312 void _sos_sync(void)                              303 void _sos_sync(void)
313 {                                                 304 {
314   _sos_syscall0(SOS_SYSCALL_ID_SYNC);             305   _sos_syscall0(SOS_SYSCALL_ID_SYNC);
315 }                                                 306 }
316                                                   307 
317                                                   308 
318 int _sos_statvfs(const char *path, struct stat    309 int _sos_statvfs(const char *path, struct statvfs *buf)
319 {                                                 310 {
320   if (! path)                                     311   if (! path)
321     return -1;                                    312     return -1;
322                                                   313     
323   return _sos_syscall3(SOS_SYSCALL_ID_VFSTAT64    314   return _sos_syscall3(SOS_SYSCALL_ID_VFSTAT64,
324                        (unsigned)path,            315                        (unsigned)path,
325                        strlen(path),              316                        strlen(path),
326                        (unsigned)buf);            317                        (unsigned)buf);
327 }                                                 318 }
328                                                   319 
329                                                   320 
330 int _sos_open(const char * pathname, int flags    321 int _sos_open(const char * pathname, int flags, int mode)
331 {                                                 322 {
332   if (! pathname)                                 323   if (! pathname)
333     return -1;                                    324     return -1;
334                                                   325 
335   return _sos_syscall4(SOS_SYSCALL_ID_OPEN,       326   return _sos_syscall4(SOS_SYSCALL_ID_OPEN,
336                        (unsigned)pathname,        327                        (unsigned)pathname,
337                        strlen(pathname),          328                        strlen(pathname),
338                        flags,                     329                        flags,
339                        mode);                     330                        mode);
340 }                                                 331 }
341                                                   332 
342                                                   333 
343 int _sos_close(int fd)                            334 int _sos_close(int fd)
344 {                                                 335 {
345   return _sos_syscall1(SOS_SYSCALL_ID_CLOSE, f    336   return _sos_syscall1(SOS_SYSCALL_ID_CLOSE, fd);
346 }                                                 337 }
347                                                   338 
348                                                   339 
349 int _sos_read(int fd, char * buf, size_t * len    340 int _sos_read(int fd, char * buf, size_t * len)
350 {                                                 341 {
351   return _sos_syscall3(SOS_SYSCALL_ID_READ, fd    342   return _sos_syscall3(SOS_SYSCALL_ID_READ, fd,
352                        (unsigned int) buf,        343                        (unsigned int) buf,
353                        (unsigned int) len);       344                        (unsigned int) len);
354 }                                                 345 }
355                                                   346 
356                                                   347 
357 int _sos_write(int fd, const char * buf, size_    348 int _sos_write(int fd, const char * buf, size_t * len)
358 {                                                 349 {
359   return _sos_syscall3(SOS_SYSCALL_ID_WRITE, f    350   return _sos_syscall3(SOS_SYSCALL_ID_WRITE, fd,
360                        (unsigned int) buf,        351                        (unsigned int) buf,
361                        (unsigned int) len);       352                        (unsigned int) len);
362 }                                                 353 }
363                                                   354 
364                                                   355 
365 int _sos_seek64(int fd, loff_t * offset, int w    356 int _sos_seek64(int fd, loff_t * offset, int whence)
366 {                                                 357 {
367   return _sos_syscall3(SOS_SYSCALL_ID_SEEK64,     358   return _sos_syscall3(SOS_SYSCALL_ID_SEEK64, fd,
368                        (unsigned int)offset,      359                        (unsigned int)offset,
369                        (unsigned int)whence);     360                        (unsigned int)whence);
370 }                                                 361 }
371                                                   362 
372                                                   363 
373 int _sos_fmmap(void ** ptr_hint_addr, size_t l    364 int _sos_fmmap(void ** ptr_hint_addr, size_t len, int prot, int flags,
374                int fd, loff_t offset)             365                int fd, loff_t offset)
375 {                                                 366 {
376   return _sos_syscall7(SOS_SYSCALL_ID_FSMMAP,     367   return _sos_syscall7(SOS_SYSCALL_ID_FSMMAP,
377                        (unsigned int)ptr_hint_    368                        (unsigned int)ptr_hint_addr, len, prot, flags,
378                        (unsigned int)fd,          369                        (unsigned int)fd,
379                        /* offs64_hi */(offset     370                        /* offs64_hi */(offset >> 32),
380                        /* offs64_lo */(offset     371                        /* offs64_lo */(offset & 0xffffffff));
381 }                                                 372 }
382                                                   373 
383                                                   374 
384 int _sos_ftruncate64(int fd, loff_t length)       375 int _sos_ftruncate64(int fd, loff_t length)
385 {                                                 376 {
386   return _sos_syscall2(SOS_SYSCALL_ID_FTRUNCAT    377   return _sos_syscall2(SOS_SYSCALL_ID_FTRUNCATE64, fd,
387                        (unsigned int)length);     378                        (unsigned int)length);  
388 }                                                 379 }
389                                                   380 
390                                                   381 
391 int _sos_fcntl(int fd, int cmd, int arg)          382 int _sos_fcntl(int fd, int cmd, int arg)
392 {                                                 383 {
393   return _sos_syscall3(SOS_SYSCALL_ID_FCNTL, f    384   return _sos_syscall3(SOS_SYSCALL_ID_FCNTL, fd,
394                        (unsigned int)cmd,         385                        (unsigned int)cmd,
395                        (unsigned int)arg);        386                        (unsigned int)arg);
396 }                                                 387 }
397                                                   388 
398                                                   389 
399 int _sos_ioctl(int fd, int cmd, int arg)          390 int _sos_ioctl(int fd, int cmd, int arg)
400 {                                                 391 {
401   return _sos_syscall3(SOS_SYSCALL_ID_IOCTL, f    392   return _sos_syscall3(SOS_SYSCALL_ID_IOCTL, fd,
402                        (unsigned int)cmd,         393                        (unsigned int)cmd,
403                        (unsigned int)arg);        394                        (unsigned int)arg);
404 }                                                 395 }
405                                                   396 
406                                                   397 
407 int _sos_creat(const char *pathname, int mode)    398 int _sos_creat(const char *pathname, int mode)
408 {                                                 399 {
409   if (! pathname)                                 400   if (! pathname)
410     return -1;                                    401     return -1;
411                                                   402 
412   return _sos_syscall3(SOS_SYSCALL_ID_CREAT,      403   return _sos_syscall3(SOS_SYSCALL_ID_CREAT,
413                        (unsigned int)pathname,    404                        (unsigned int)pathname,
414                        strlen(pathname),          405                        strlen(pathname),
415                        mode);                     406                        mode);
416 }                                                 407 }
417                                                   408 
418                                                   409 
419 int _sos_link (const char *oldpath, const char    410 int _sos_link (const char *oldpath, const char *newpath)
420 {                                                 411 {
421   if (!oldpath || !newpath)                       412   if (!oldpath || !newpath)
422     return -1;                                    413     return -1;
423                                                   414 
424   return _sos_syscall4(SOS_SYSCALL_ID_LINK,       415   return _sos_syscall4(SOS_SYSCALL_ID_LINK,
425                        (unsigned int)oldpath,     416                        (unsigned int)oldpath,
426                        strlen(oldpath),           417                        strlen(oldpath),
427                        (unsigned int)newpath,     418                        (unsigned int)newpath,
428                        strlen(newpath));          419                        strlen(newpath));
429 }                                                 420 }
430                                                   421 
431                                                   422 
432 int _sos_unlink(const char *pathname)             423 int _sos_unlink(const char *pathname)
433 {                                                 424 {
434   if (! pathname)                                 425   if (! pathname)
435     return -1;                                    426     return -1;
436                                                   427 
437   return _sos_syscall2(SOS_SYSCALL_ID_UNLINK,     428   return _sos_syscall2(SOS_SYSCALL_ID_UNLINK,
438                        (unsigned int)pathname,    429                        (unsigned int)pathname,
439                        strlen(pathname));         430                        strlen(pathname));
440 }                                                 431 }
441                                                   432 
442                                                   433 
443 int _sos_rename (const char *oldpath, const ch    434 int _sos_rename (const char *oldpath, const char *newpath)
444 {                                                 435 {
445   if (!oldpath || !newpath)                       436   if (!oldpath || !newpath)
446     return -1;                                    437     return -1;
447                                                   438 
448   return _sos_syscall4(SOS_SYSCALL_ID_RENAME,     439   return _sos_syscall4(SOS_SYSCALL_ID_RENAME,
449                        (unsigned int)oldpath,     440                        (unsigned int)oldpath,
450                        strlen(oldpath),           441                        strlen(oldpath),
451                        (unsigned int)newpath,     442                        (unsigned int)newpath,
452                        strlen(newpath));          443                        strlen(newpath));
453 }                                                 444 }
454                                                   445 
455                                                   446 
456 int _sos_symlink(const char *target, const cha    447 int _sos_symlink(const char *target, const char *path)
457 {                                                 448 {
458   if (!path || !target)                           449   if (!path || !target)
459     return -1;                                    450     return -1;
460                                                   451 
461   return _sos_syscall4(SOS_SYSCALL_ID_SYMLINK,    452   return _sos_syscall4(SOS_SYSCALL_ID_SYMLINK,
462                        (unsigned int)path,        453                        (unsigned int)path,
463                        strlen(path),              454                        strlen(path),
464                        (unsigned int)target,      455                        (unsigned int)target,
465                        strlen(target));           456                        strlen(target));
466 }                                                 457 }
467                                                   458 
468                                                   459 
469 int _sos_mknod(const char *pathname, mode_t mo    460 int _sos_mknod(const char *pathname, mode_t mode,
470                int type,                          461                int type,
471                unsigned int major, unsigned mi    462                unsigned int major, unsigned minor)
472 {                                                 463 {
473   if (!pathname)                                  464   if (!pathname)
474     return -1;                                    465     return -1;
475                                                   466 
476   return _sos_syscall6(SOS_SYSCALL_ID_MKNOD,      467   return _sos_syscall6(SOS_SYSCALL_ID_MKNOD,
477                        (unsigned int)pathname,    468                        (unsigned int)pathname,
478                        strlen(pathname),          469                        strlen(pathname),
479                        type, mode, major, mino    470                        type, mode, major, minor);
480 }                                                 471 }
481                                                   472 
482                                                   473 
483 struct dirent; /* Forward declaration */          474 struct dirent; /* Forward declaration */
484 int _sos_readdir(int fd, struct dirent * diren    475 int _sos_readdir(int fd, struct dirent * dirent)
485 {                                                 476 {
486   return _sos_syscall2(SOS_SYSCALL_ID_READDIR,    477   return _sos_syscall2(SOS_SYSCALL_ID_READDIR,
487                        fd,                        478                        fd,
488                        (unsigned int)dirent);     479                        (unsigned int)dirent);
489 }                                                 480 }
490                                                   481 
491                                                   482 
492 int _sos_mkdir(const char *pathname, mode_t mo    483 int _sos_mkdir(const char *pathname, mode_t mode)
493 {                                                 484 {
494   if (!pathname)                                  485   if (!pathname)
495     return -1;                                    486     return -1;
496                                                   487 
497   return _sos_syscall3(SOS_SYSCALL_ID_MKDIR,      488   return _sos_syscall3(SOS_SYSCALL_ID_MKDIR,
498                        (unsigned int)pathname,    489                        (unsigned int)pathname,
499                        strlen(pathname),          490                        strlen(pathname),
500                        mode);                     491                        mode);
501 }                                                 492 }
502                                                   493 
503                                                   494 
504 int _sos_rmdir(const char *pathname)              495 int _sos_rmdir(const char *pathname)
505 {                                                 496 {
506   if (!pathname)                                  497   if (!pathname)
507     return -1;                                    498     return -1;
508                                                   499 
509   return _sos_syscall2(SOS_SYSCALL_ID_RMDIR,      500   return _sos_syscall2(SOS_SYSCALL_ID_RMDIR,
510                        (unsigned int)pathname,    501                        (unsigned int)pathname,
511                        strlen(pathname));         502                        strlen(pathname));
512 }                                                 503 }
513                                                   504 
514                                                   505 
515 int _sos_chmod(const char *pathname, mode_t mo    506 int _sos_chmod(const char *pathname, mode_t mode)
516 {                                                 507 {
517   if (!pathname)                                  508   if (!pathname)
518     return -1;                                    509     return -1;
519                                                   510 
520   return _sos_syscall3(SOS_SYSCALL_ID_CHMOD,      511   return _sos_syscall3(SOS_SYSCALL_ID_CHMOD,
521                        (unsigned int)pathname,    512                        (unsigned int)pathname,
522                        strlen(pathname),          513                        strlen(pathname),
523                        mode);                     514                        mode);
524 }                                                 515 }
525                                                   516 
526                                                   517 
527 int _sos_stat(const char *pathname, int nofoll    518 int _sos_stat(const char *pathname, int nofollow, struct stat * st)
528 {                                                 519 {
529   if (!pathname || !st)                           520   if (!pathname || !st)
530     return -1;                                    521     return -1;
531                                                   522 
532   return _sos_syscall4(SOS_SYSCALL_ID_STAT64,     523   return _sos_syscall4(SOS_SYSCALL_ID_STAT64,
533                        (unsigned int)pathname,    524                        (unsigned int)pathname,
534                        strlen(pathname),          525                        strlen(pathname),
535                        nofollow,                  526                        nofollow,
536                        (unsigned int)st);         527                        (unsigned int)st);
537 }                                                 528 }
538                                                   529 
539                                                   530 
540 int _sos_chroot(const char *dirname)              531 int _sos_chroot(const char *dirname)
541 {                                                 532 {
542   if (!dirname)                                   533   if (!dirname)
543     return -1;                                    534     return -1;
544                                                   535 
545   return _sos_syscall2(SOS_SYSCALL_ID_CHROOT,     536   return _sos_syscall2(SOS_SYSCALL_ID_CHROOT,
546                        (unsigned int)dirname,     537                        (unsigned int)dirname,
547                        strlen(dirname));          538                        strlen(dirname));
548 }                                                 539 }
549                                                   540 
550                                                   541 
551 int _sos_chdir(const char *dirname)               542 int _sos_chdir(const char *dirname)
552 {                                                 543 {
553   if (!dirname)                                   544   if (!dirname)
554     return -1;                                    545     return -1;
555                                                   546 
556   return _sos_syscall2(SOS_SYSCALL_ID_CHDIR,      547   return _sos_syscall2(SOS_SYSCALL_ID_CHDIR,
557                        (unsigned int)dirname,     548                        (unsigned int)dirname,
558                        strlen(dirname));          549                        strlen(dirname));
559 }                                                 550 }
560                                                   551 
561                                                   552 
562 int _sos_fchdir(int fd)                           553 int _sos_fchdir(int fd)
563 {                                                 554 {
564   return _sos_syscall1(SOS_SYSCALL_ID_FCHDIR,     555   return _sos_syscall1(SOS_SYSCALL_ID_FCHDIR,
565                        (unsigned int)fd);         556                        (unsigned int)fd);
566 }                                                 557 }
                                                      

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