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


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() __attribute__((noreturn));          035 void _start() __attribute__((noreturn));
036 void _start()                                     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();                              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");         076                :"eax","ebx","ecx","edx");
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_mmap(void ** ptr_hint_addr, size_t le !! 199 int _sos_fakemmap(void ** ptr_hint_addr, size_t len, int prot, int flags,
200               const char *resource_path, loff_ !! 200                   const char *resource_path, loff_t offset)
201 {                                                 201 {
202   return _sos_syscall7(SOS_SYSCALL_ID_MMAP,    !! 202   return _sos_syscall7(SOS_SYSCALL_ID_FAKEMMAP,
203                        (unsigned int)ptr_hint_    203                        (unsigned int)ptr_hint_addr, len, prot, flags,
204                        (unsigned int)resource_    204                        (unsigned int)resource_path,
205                        /* offs64_hi */(offset     205                        /* offs64_hi */(offset >> 32),
206                        /* offs64_lo */(offset     206                        /* offs64_lo */(offset & 0xffffffff));
207 }                                                 207 }
208                                                   208 
209                                                   209 
210 int _sos_munmap(void * start, size_t length)      210 int _sos_munmap(void * start, size_t length)
211 {                                                 211 {
212   return _sos_syscall2(SOS_SYSCALL_ID_MUNMAP,     212   return _sos_syscall2(SOS_SYSCALL_ID_MUNMAP,
213                        (unsigned int)start,       213                        (unsigned int)start,
214                        length);                   214                        length);
215 }                                                 215 }
216                                                   216 
217                                                   217 
218 int _sos_mprotect(const void *addr, size_t len    218 int _sos_mprotect(const void *addr, size_t len, int prot)
219 {                                                 219 {
220   return _sos_syscall3(SOS_SYSCALL_ID_MPROTECT    220   return _sos_syscall3(SOS_SYSCALL_ID_MPROTECT,
221                        (unsigned int)addr,        221                        (unsigned int)addr,
222                        len,                       222                        len,
223                        (unsigned int)prot);       223                        (unsigned int)prot);
224 }                                                 224 }
225                                                   225 
226                                                   226 
227 int _sos_mresize(void * old_addr, size_t old_l    227 int _sos_mresize(void * old_addr, size_t old_len,
228                  void * *new_addr, size_t new_    228                  void * *new_addr, size_t new_len,
229                  unsigned long flags)             229                  unsigned long flags)
230 {                                                 230 {
231   return _sos_syscall5(SOS_SYSCALL_ID_MRESIZE,    231   return _sos_syscall5(SOS_SYSCALL_ID_MRESIZE,
232                        (unsigned int)old_addr,    232                        (unsigned int)old_addr,
233                        old_len,                   233                        old_len,
234                        (unsigned int)new_addr,    234                        (unsigned int)new_addr,
235                        new_len,                   235                        new_len,
236                        flags);                    236                        flags);
237 }                                                 237 }
238                                                   238 
239                                                   239 
240 /**                                               240 /**
241  * Helper function that represents the start r    241  * Helper function that represents the start routine of a new user
242  * thread created from user space (syscall new    242  * thread created from user space (syscall new_thread). It takes 2
243  * arguments that are passsed in the eax/ebx r    243  * arguments that are passsed in the eax/ebx registers (@see
244  * cpu_ustate_init() in hwcore/cpu_context.c):    244  * cpu_ustate_init() in hwcore/cpu_context.c): the start function of
245  * the new thread (eax), the argument passed t    245  * the new thread (eax), the argument passed to it (ebx).
246  */                                               246  */
247 static void thread_routine()                      247 static void thread_routine()
248 {                                                 248 {
249   /* NOTE: variables as named registers is a g    249   /* NOTE: variables as named registers is a gcc extension */
250   register unsigned long int reg_arg1 asm("%ea    250   register unsigned long int reg_arg1 asm("%eax");
251   register unsigned long int reg_arg2 asm("%eb    251   register unsigned long int reg_arg2 asm("%ebx");
252                                                   252 
253   sos_thread_func_t * func = (sos_thread_func_    253   sos_thread_func_t * func = (sos_thread_func_t*)reg_arg1;
254   unsigned long int arg = reg_arg2;               254   unsigned long int arg = reg_arg2;
255                                                   255 
256   func(arg);                                      256   func(arg);
257   _sos_exit(0);                                   257   _sos_exit(0);
258 }                                                 258 }
259                                                   259 
260                                                   260 
261 int _sos_new_thread(sos_thread_func_t *func,      261 int _sos_new_thread(sos_thread_func_t *func,
262                     void* arg,                    262                     void* arg,
263                     size_t stack_size)            263                     size_t stack_size)
264 {                                                 264 {
265   return _sos_syscall4(SOS_SYSCALL_ID_NEW_THRE    265   return _sos_syscall4(SOS_SYSCALL_ID_NEW_THREAD,
266                        (unsigned)thread_routin    266                        (unsigned)thread_routine,
267                        (unsigned)func, (unsign    267                        (unsigned)func, (unsigned)arg,
268                        stack_size);               268                        stack_size);
269 }                                                 269 }
270                                                   270 
271                                                   271 
272 int _sos_nanosleep(unsigned long int sec,         272 int _sos_nanosleep(unsigned long int sec,
273                    unsigned long int nanosec)     273                    unsigned long int nanosec)
274 {                                                 274 {
275   return _sos_syscall2(SOS_SYSCALL_ID_NANOSLEE    275   return _sos_syscall2(SOS_SYSCALL_ID_NANOSLEEP,
276                        sec, nanosec);             276                        sec, nanosec);
277 }                                                 277 }
278                                                   278 
279                                                   279 
280 void * _sos_brk(void * new_top_address)           280 void * _sos_brk(void * new_top_address)
281 {                                                 281 {
282   return (void*)_sos_syscall1(SOS_SYSCALL_ID_B    282   return (void*)_sos_syscall1(SOS_SYSCALL_ID_BRK,
283                               (unsigned)new_to    283                               (unsigned)new_top_address);
                                                   >> 284 }
                                                   >> 285 
                                                   >> 286 
                                                   >> 287 int _sos_mount(const char *source, const char *target,
                                                   >> 288                const char *filesystemtype, unsigned long mountflags,
                                                   >> 289                const char *args)
                                                   >> 290 {
                                                   >> 291   if (!target || !filesystemtype)
                                                   >> 292     return -1;
                                                   >> 293 
                                                   >> 294   return _sos_syscall7(SOS_SYSCALL_ID_MOUNT,
                                                   >> 295                        (unsigned int)source, source?strlen(source):0,
                                                   >> 296                        (unsigned int)target, strlen(target),
                                                   >> 297                        (unsigned int)filesystemtype,
                                                   >> 298                        mountflags,
                                                   >> 299                        (unsigned int)args);
                                                   >> 300 }
                                                   >> 301 
                                                   >> 302 
                                                   >> 303 int _sos_umount(const char *target)
                                                   >> 304 {
                                                   >> 305   if (!target)
                                                   >> 306     return -1;
                                                   >> 307 
                                                   >> 308   return _sos_syscall2(SOS_SYSCALL_ID_UMOUNT,
                                                   >> 309                        (unsigned int)target,
                                                   >> 310                        strlen(target));
                                                   >> 311 }
                                                   >> 312 
                                                   >> 313 
                                                   >> 314 void _sos_sync(void)
                                                   >> 315 {
                                                   >> 316   _sos_syscall0(SOS_SYSCALL_ID_SYNC);
                                                   >> 317 }
                                                   >> 318 
                                                   >> 319 
                                                   >> 320 int _sos_statvfs(const char *path, struct statvfs *buf)
                                                   >> 321 {
                                                   >> 322   if (! path)
                                                   >> 323     return -1;
                                                   >> 324     
                                                   >> 325   return _sos_syscall3(SOS_SYSCALL_ID_VFSTAT64,
                                                   >> 326                        (unsigned)path,
                                                   >> 327                        strlen(path),
                                                   >> 328                        (unsigned)buf);
                                                   >> 329 }
                                                   >> 330 
                                                   >> 331 
                                                   >> 332 int _sos_open(const char * pathname, int flags, int mode)
                                                   >> 333 {
                                                   >> 334   if (! pathname)
                                                   >> 335     return -1;
                                                   >> 336     
                                                   >> 337   return _sos_syscall4(SOS_SYSCALL_ID_OPEN,
                                                   >> 338                        (unsigned)pathname,
                                                   >> 339                        strlen(pathname),
                                                   >> 340                        flags,
                                                   >> 341                        mode);
                                                   >> 342 }
                                                   >> 343 
                                                   >> 344 
                                                   >> 345 int _sos_close(int fd)
                                                   >> 346 {
                                                   >> 347   return _sos_syscall1(SOS_SYSCALL_ID_CLOSE, fd);
                                                   >> 348 }
                                                   >> 349 
                                                   >> 350 
                                                   >> 351 int _sos_read(int fd, char * buf, size_t * len)
                                                   >> 352 {
                                                   >> 353   return _sos_syscall3(SOS_SYSCALL_ID_READ, fd,
                                                   >> 354                        (unsigned int) buf,
                                                   >> 355                        (unsigned int) len);
                                                   >> 356 }
                                                   >> 357 
                                                   >> 358 
                                                   >> 359 int _sos_write(int fd, const char * buf, size_t * len)
                                                   >> 360 {
                                                   >> 361   return _sos_syscall3(SOS_SYSCALL_ID_WRITE, fd,
                                                   >> 362                        (unsigned int) buf,
                                                   >> 363                        (unsigned int) len);
                                                   >> 364 }
                                                   >> 365 
                                                   >> 366 
                                                   >> 367 int _sos_seek64(int fd, loff_t * offset, int whence)
                                                   >> 368 {
                                                   >> 369   return _sos_syscall3(SOS_SYSCALL_ID_SEEK64, fd,
                                                   >> 370                        (unsigned int)offset,
                                                   >> 371                        (unsigned int)whence);
                                                   >> 372 }
                                                   >> 373 
                                                   >> 374 
                                                   >> 375 int _sos_fmmap(void ** ptr_hint_addr, size_t len, int prot, int flags,
                                                   >> 376                int fd, loff_t offset)
                                                   >> 377 {
                                                   >> 378   return _sos_syscall7(SOS_SYSCALL_ID_FSMMAP,
                                                   >> 379                        (unsigned int)ptr_hint_addr, len, prot, flags,
                                                   >> 380                        (unsigned int)fd,
                                                   >> 381                        /* offs64_hi */(offset >> 32),
                                                   >> 382                        /* offs64_lo */(offset & 0xffffffff));
                                                   >> 383 }
                                                   >> 384 
                                                   >> 385 
                                                   >> 386 int _sos_ftruncate64(int fd, loff_t length)
                                                   >> 387 {
                                                   >> 388   return _sos_syscall2(SOS_SYSCALL_ID_FTRUNCATE64, fd,
                                                   >> 389                        (unsigned int)length);  
                                                   >> 390 }
                                                   >> 391 
                                                   >> 392 
                                                   >> 393 int _sos_fcntl(int fd, int cmd, int arg)
                                                   >> 394 {
                                                   >> 395   return _sos_syscall3(SOS_SYSCALL_ID_FCNTL, fd,
                                                   >> 396                        (unsigned int)cmd,
                                                   >> 397                        (unsigned int)arg);
                                                   >> 398 }
                                                   >> 399 
                                                   >> 400 
                                                   >> 401 int _sos_creat(const char *pathname, int mode)
                                                   >> 402 {
                                                   >> 403   if (! pathname)
                                                   >> 404     return -1;
                                                   >> 405 
                                                   >> 406   return _sos_syscall3(SOS_SYSCALL_ID_CREAT,
                                                   >> 407                        (unsigned int)pathname,
                                                   >> 408                        strlen(pathname),
                                                   >> 409                        mode);
                                                   >> 410 }
                                                   >> 411 
                                                   >> 412 
                                                   >> 413 int _sos_link (const char *oldpath, const char *newpath)
                                                   >> 414 {
                                                   >> 415   if (!oldpath || !newpath)
                                                   >> 416     return -1;
                                                   >> 417 
                                                   >> 418   return _sos_syscall4(SOS_SYSCALL_ID_LINK,
                                                   >> 419                        (unsigned int)oldpath,
                                                   >> 420                        strlen(oldpath),
                                                   >> 421                        (unsigned int)newpath,
                                                   >> 422                        strlen(newpath));
                                                   >> 423 }
                                                   >> 424 
                                                   >> 425 
                                                   >> 426 int _sos_unlink(const char *pathname)
                                                   >> 427 {
                                                   >> 428   if (! pathname)
                                                   >> 429     return -1;
                                                   >> 430 
                                                   >> 431   return _sos_syscall2(SOS_SYSCALL_ID_UNLINK,
                                                   >> 432                        (unsigned int)pathname,
                                                   >> 433                        strlen(pathname));
                                                   >> 434 }
                                                   >> 435 
                                                   >> 436 
                                                   >> 437 int _sos_rename (const char *oldpath, const char *newpath)
                                                   >> 438 {
                                                   >> 439   if (!oldpath || !newpath)
                                                   >> 440     return -1;
                                                   >> 441 
                                                   >> 442   return _sos_syscall4(SOS_SYSCALL_ID_RENAME,
                                                   >> 443                        (unsigned int)oldpath,
                                                   >> 444                        strlen(oldpath),
                                                   >> 445                        (unsigned int)newpath,
                                                   >> 446                        strlen(newpath));
                                                   >> 447 }
                                                   >> 448 
                                                   >> 449 
                                                   >> 450 int _sos_symlink(const char *target, const char *path)
                                                   >> 451 {
                                                   >> 452   if (!path || !target)
                                                   >> 453     return -1;
                                                   >> 454 
                                                   >> 455   return _sos_syscall4(SOS_SYSCALL_ID_SYMLINK,
                                                   >> 456                        (unsigned int)path,
                                                   >> 457                        strlen(path),
                                                   >> 458                        (unsigned int)target,
                                                   >> 459                        strlen(target));
                                                   >> 460 }
                                                   >> 461 
                                                   >> 462 
                                                   >> 463 struct dirent; /* Forward declaration */
                                                   >> 464 int _sos_readdir(int fd, struct dirent * dirent)
                                                   >> 465 {
                                                   >> 466   return _sos_syscall2(SOS_SYSCALL_ID_READDIR,
                                                   >> 467                        fd,
                                                   >> 468                        (unsigned int)dirent);
                                                   >> 469 }
                                                   >> 470 
                                                   >> 471 
                                                   >> 472 int _sos_mkdir(const char *pathname, mode_t mode)
                                                   >> 473 {
                                                   >> 474   if (!pathname)
                                                   >> 475     return -1;
                                                   >> 476 
                                                   >> 477   return _sos_syscall3(SOS_SYSCALL_ID_MKDIR,
                                                   >> 478                        (unsigned int)pathname,
                                                   >> 479                        strlen(pathname),
                                                   >> 480                        mode);
                                                   >> 481 }
                                                   >> 482 
                                                   >> 483 
                                                   >> 484 int _sos_rmdir(const char *pathname)
                                                   >> 485 {
                                                   >> 486   if (!pathname)
                                                   >> 487     return -1;
                                                   >> 488 
                                                   >> 489   return _sos_syscall2(SOS_SYSCALL_ID_RMDIR,
                                                   >> 490                        (unsigned int)pathname,
                                                   >> 491                        strlen(pathname));
                                                   >> 492 }
                                                   >> 493 
                                                   >> 494 
                                                   >> 495 int _sos_chmod(const char *pathname, mode_t mode)
                                                   >> 496 {
                                                   >> 497   if (!pathname)
                                                   >> 498     return -1;
                                                   >> 499 
                                                   >> 500   return _sos_syscall3(SOS_SYSCALL_ID_CHMOD,
                                                   >> 501                        (unsigned int)pathname,
                                                   >> 502                        strlen(pathname),
                                                   >> 503                        mode);
                                                   >> 504 }
                                                   >> 505 
                                                   >> 506 
                                                   >> 507 int _sos_stat(const char *pathname, int nofollow, struct stat * st)
                                                   >> 508 {
                                                   >> 509   if (!pathname || !st)
                                                   >> 510     return -1;
                                                   >> 511 
                                                   >> 512   return _sos_syscall4(SOS_SYSCALL_ID_STAT64,
                                                   >> 513                        (unsigned int)pathname,
                                                   >> 514                        strlen(pathname),
                                                   >> 515                        nofollow,
                                                   >> 516                        (unsigned int)st);
                                                   >> 517 }
                                                   >> 518 
                                                   >> 519 
                                                   >> 520 int _sos_chroot(const char *dirname)
                                                   >> 521 {
                                                   >> 522   if (!dirname)
                                                   >> 523     return -1;
                                                   >> 524 
                                                   >> 525   return _sos_syscall2(SOS_SYSCALL_ID_CHROOT,
                                                   >> 526                        (unsigned int)dirname,
                                                   >> 527                        strlen(dirname));
                                                   >> 528 }
                                                   >> 529 
                                                   >> 530 
                                                   >> 531 int _sos_chdir(const char *dirname)
                                                   >> 532 {
                                                   >> 533   if (!dirname)
                                                   >> 534     return -1;
                                                   >> 535 
                                                   >> 536   return _sos_syscall2(SOS_SYSCALL_ID_CHDIR,
                                                   >> 537                        (unsigned int)dirname,
                                                   >> 538                        strlen(dirname));
                                                   >> 539 }
                                                   >> 540 
                                                   >> 541 
                                                   >> 542 int _sos_fchdir(int fd)
                                                   >> 543 {
                                                   >> 544   return _sos_syscall1(SOS_SYSCALL_ID_FCHDIR,
                                                   >> 545                        (unsigned int)fd);
284 }                                                 546 }
                                                      

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