fix double-processing of DT_RELR relocations in ldso relocating itself
[musl] / src / signal / setitimer.c
1 #include <sys/time.h>
2 #include <errno.h>
3 #include "syscall.h"
4
5 #define IS32BIT(x) !((x)+0x80000000ULL>>32)
6
7 int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old)
8 {
9         if (sizeof(time_t) > sizeof(long)) {
10                 time_t is = new->it_interval.tv_sec, vs = new->it_value.tv_sec;
11                 long ius = new->it_interval.tv_usec, vus = new->it_value.tv_usec;
12                 if (!IS32BIT(is) || !IS32BIT(vs))
13                         return __syscall_ret(-ENOTSUP);
14                 long old32[4];
15                 int r = __syscall(SYS_setitimer, which,
16                         ((long[]){is, ius, vs, vus}), old32);
17                 if (!r && old) {
18                         old->it_interval.tv_sec = old32[0];
19                         old->it_interval.tv_usec = old32[1];
20                         old->it_value.tv_sec = old32[2];
21                         old->it_value.tv_usec = old32[3];
22                 }
23                 return __syscall_ret(r);
24         }
25         return syscall(SYS_setitimer, which, new, old);
26 }