5 #include "sys/syscall.h"
10 void abort (void) __attribute__((__noreturn__
));
12 extern int __trap34 (int function
, ...);
14 /* This is used by _sbrk. */
15 register char *stack_ptr
asm ("r15");
17 extern int main (int, char**);
24 return __trap34 (SYS_read
, file
, ptr
, len
);
32 return __trap34 (SYS_lseek
, file
, ptr
, dir
);
40 return __trap34 (SYS_write
, file
, ptr
, len
);
46 return __trap34 (SYS_close
, file
, 0, 0);
50 _link (char *old
, char *new)
58 extern char end
; /* Defined by the linker */
59 static char *heap_end
;
66 prev_heap_end
= heap_end
;
67 if (heap_end
+ incr
> stack_ptr
)
69 _write (1, "Heap and stack collision\n", 25);
73 return (caddr_t
) prev_heap_end
;
80 st
->st_mode
= S_IFCHR
;
85 _open (const char *path
,
88 return __trap34 (SYS_open
, path
, flags
, 0);
92 _creat (const char *path
,
95 return __trap34 (SYS_creat
, path
, mode
, 0);
116 _ATTRIBUTE ((__noreturn__
)) void
119 __trap34 (SYS_exit
, n
, 0, 0);
126 return __trap34 (SYS_exit
, 0xdead, 0, 0);
141 _stat (const char *path
, struct stat
*st
)
144 return __trap34 (SYS_stat
, path
, st
, 0);
148 _chmod (const char *path
, short mode
)
150 return __trap34 (SYS_chmod
, path
, mode
);
154 _chown (const char *path
, short owner
, short group
)
156 return __trap34 (SYS_chown
, path
, owner
, group
);
160 _utime (const char *path
,
163 return __trap34 (SYS_utime
, path
, times
);
169 return __trap34 (SYS_fork
);
175 return __trap34 (SYS_wait
);
179 _execve (const char *path
, char *const argv
[], char *const envp
[])
181 return __trap34 (SYS_execve
, path
, argv
, envp
);
185 _execv (const char *path
, char *const argv
[])
187 return __trap34 (SYS_execv
, path
, argv
);
193 return __trap34 (SYS_pipe
, fd
);
196 /* This is only provided because _gettimeofday_r and _times_r are
197 defined in the same module, so we avoid a link error. */
199 _times (struct tms
*tp
)
205 _gettimeofday (struct timeval
*tv
, void *tz
)
208 tv
->tv_sec
= __trap34 (SYS_time
);
213 __setup_argv_for_main (int argc
)
218 argv
= __builtin_alloca ((1 + argc
) * sizeof (*argv
));
222 argv
[i
] = __builtin_alloca (1 + __trap34 (SYS_argnlen
, i
));
223 __trap34 (SYS_argn
, i
, argv
[i
]);
226 return main (argc
, argv
);
230 __setup_argv_and_call_main ()
232 int argc
= __trap34 (SYS_argc
);
235 return main (argc
, NULL
);
237 return __setup_argv_for_main (argc
);