1 | /** Linux system call interface. |
---|
2 | * Written by Shaun Jackman <sjackman@gmail.com>. |
---|
3 | * Copyright 2006 Pathway Connectivity |
---|
4 | * |
---|
5 | * Permission to use, copy, modify, and distribute this software |
---|
6 | * is freely granted, provided that this notice is preserved. |
---|
7 | */ |
---|
8 | |
---|
9 | #include <errno.h> |
---|
10 | #include <stdint.h> |
---|
11 | |
---|
12 | extern char _end[]; |
---|
13 | static void *curbrk = _end; |
---|
14 | |
---|
15 | extern void *_brk(void *addr); |
---|
16 | |
---|
17 | int brk(void *addr) |
---|
18 | { |
---|
19 | void *newbrk; |
---|
20 | if (curbrk == addr) |
---|
21 | return 0; |
---|
22 | newbrk = _brk(addr); |
---|
23 | curbrk = newbrk; |
---|
24 | if (newbrk < addr) { |
---|
25 | errno = ENOMEM; |
---|
26 | return -1; |
---|
27 | } |
---|
28 | return 0; |
---|
29 | } |
---|
30 | |
---|
31 | void *_sbrk(intptr_t incr) |
---|
32 | { |
---|
33 | void *oldbrk = curbrk; |
---|
34 | if (brk(oldbrk + incr) == -1) |
---|
35 | return (void *)-1; |
---|
36 | return oldbrk; |
---|
37 | } |
---|
38 | |
---|
39 | void *sbrk(intptr_t incr) __attribute__((alias("_sbrk"))); |
---|
40 | |
---|
41 | int _set_errno(int n) |
---|
42 | { |
---|
43 | if (n < 0) { |
---|
44 | errno = -n; |
---|
45 | return -1; |
---|
46 | } |
---|
47 | return n; |
---|
48 | } |
---|
49 | |
---|
50 | #include <sys/wait.h> |
---|
51 | |
---|
52 | struct rusage; |
---|
53 | |
---|
54 | pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage); |
---|
55 | |
---|
56 | pid_t _wait(int *status) |
---|
57 | { |
---|
58 | return wait4(-1, status, 0, NULL); |
---|
59 | } |
---|
60 | |
---|
61 | pid_t waitpid(pid_t pid, int *status, int options) |
---|
62 | { |
---|
63 | return wait4(pid, status, options, NULL); |
---|
64 | } |
---|
65 | |
---|
66 | extern int _reboot(int magic, int magic2, int flag, void *arg); |
---|
67 | |
---|
68 | int reboot(int flag) |
---|
69 | { |
---|
70 | return _reboot(0xfee1dead, 0x28121969, flag, NULL); |
---|
71 | } |
---|