|
17 | 17 | #include <sys/time.h> |
18 | 18 | #include <sys/times.h> |
19 | 19 | #include <sys/types.h> |
| 20 | +#include <sys/signal.h> |
20 | 21 |
|
21 | 22 | char **environ; /* pointer to array of char * strings that define the current |
22 | 23 | environment variables */ |
@@ -85,6 +86,24 @@ char **environ; /* pointer to array of char * strings that define the current |
85 | 86 | return ret; \ |
86 | 87 | } |
87 | 88 |
|
| 89 | +#define DEFINE_SYSCALL_4_default(_ret_type, _syscall, _nr, _type1, _type2, \ |
| 90 | + _type3, _type4, ...) \ |
| 91 | + _ret_type _##_syscall(_type1 arg1, _type2 arg2, _type3 arg3, _type4 arg4, \ |
| 92 | + ##__VA_ARGS__) \ |
| 93 | + { \ |
| 94 | + _ret_type ret; \ |
| 95 | + __asm__ volatile("int $0x80" \ |
| 96 | + : "=a"(ret) \ |
| 97 | + : "a"(_nr), "b"(arg1), "c"(arg2), "d"(arg3), \ |
| 98 | + "S"(arg4) \ |
| 99 | + : "memory"); \ |
| 100 | + if (ret < 0) { \ |
| 101 | + errno = (int)ret; \ |
| 102 | + ret = (_ret_type) - 1; \ |
| 103 | + } \ |
| 104 | + return ret; \ |
| 105 | + } |
| 106 | + |
88 | 107 | /* |
89 | 108 | * Noreturn syscalls (exit) |
90 | 109 | */ |
@@ -113,6 +132,24 @@ pid_t _wait(int *status) |
113 | 132 | return _waitpid(-1, status, 0); |
114 | 133 | } |
115 | 134 |
|
| 135 | +/* |
| 136 | + * signal() should not be used for anything else than setting the handler |
| 137 | + * to SIGDFL or SIGIGN. For other values follow the BSD semantics: the signal |
| 138 | + * is masked until delivered and handler (also the same as glibc). |
| 139 | + */ |
| 140 | +int _signal(int signo, sig_sa_handler_t handler) |
| 141 | +{ |
| 142 | + struct sigaction sigaction = { |
| 143 | + .sa_handler = handler, |
| 144 | + .sa_flags = 0, |
| 145 | + }; |
| 146 | + |
| 147 | + sigemptyset(&sigaction.sa_mask); |
| 148 | + sigaddset(&sigaction.sa_mask, signo); |
| 149 | + |
| 150 | + return _sigaction(signo, &sigaction, NULL); |
| 151 | +} |
| 152 | + |
116 | 153 | /* |
117 | 154 | * Unimplemented syscalls |
118 | 155 | */ |
|
0 commit comments