Skip to content

Commit 14afb82

Browse files
committed
Revert musl commit 722a1ae3351a03ab25010dbebd492eced664853b
1 parent 1c3fe00 commit 14afb82

File tree

2 files changed

+14
-33
lines changed

2 files changed

+14
-33
lines changed

system/lib/libc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Some changes have been made to the version that was taken from upstream, includi
1515
* Handling trailing % in `strftime` and `wcsftime` format strings.
1616
* Revert musl commit [5850546e9669f793aab61dfc7c4f2c1ff35c4b29](https://git.musl-libc.org/cgit/musl/commit/?id=5850546e9669f793aab61dfc7c4f2c1ff35c4b29).
1717
* Revert musl commit [22276671d031639f1bd55d7dbf817290c321c7bf](https://git.musl-libc.org/cgit/musl/commit/?id=22276671d031639f1bd55d7dbf817290c321c7bf).
18+
* Revert musl commit [722a1ae3351a03ab25010dbebd492eced664853b](https://git.musl-libc.org/cgit/musl/commit/?id=722a1ae3351a03ab25010dbebd492eced664853b).
1819

1920
Copy log.c and log2.c from earlier version of musl which result in smaller
2021
binary size since they do not rely data tables in log_data.c and log2_data.c.

system/lib/libc/musl/src/select/select.c

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,22 @@
44
#include <errno.h>
55
#include "syscall.h"
66

7-
#define IS32BIT(x) !((x)+0x80000000ULL>>32)
8-
#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
9-
107
int select(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict efds, struct timeval *restrict tv)
118
{
12-
time_t s = tv ? tv->tv_sec : 0;
13-
suseconds_t us = tv ? tv->tv_usec : 0;
14-
long ns;
15-
const time_t max_time = (1ULL<<8*sizeof(time_t)-1)-1;
16-
17-
if (s<0 || us<0) return __syscall_ret(-EINVAL);
18-
if (us/1000000 > max_time - s) {
19-
s = max_time;
20-
us = 999999;
21-
ns = 999999999;
22-
} else {
23-
s += us/1000000;
24-
us %= 1000000;
25-
ns = us*1000;
26-
}
27-
28-
#ifdef SYS_pselect6_time64
29-
int r = -ENOSYS;
30-
if (SYS_pselect6 == SYS_pselect6_time64 || !IS32BIT(s))
31-
r = __syscall_cp(SYS_pselect6_time64, n, rfds, wfds, efds,
32-
tv ? ((long long[]){s, ns}) : 0,
33-
((syscall_arg_t[]){ 0, _NSIG/8 }));
34-
if (SYS_pselect6 == SYS_pselect6_time64 || r!=-ENOSYS)
35-
return __syscall_ret(r);
36-
s = CLAMP(s);
37-
#endif
389
#ifdef SYS_select
39-
return syscall_cp(SYS_select, n, rfds, wfds, efds,
40-
tv ? ((long[]){s, us}) : 0);
10+
return syscall_cp(SYS_select, n, rfds, wfds, efds, tv);
4111
#else
42-
return syscall_cp(SYS_pselect6, n, rfds, wfds, efds,
43-
tv ? ((long[]){s, ns}) : 0, ((syscall_arg_t[]){ 0, _NSIG/8 }));
12+
syscall_arg_t data[2] = { 0, _NSIG/8 };
13+
struct timespec ts;
14+
if (tv) {
15+
if (tv->tv_sec < 0 || tv->tv_usec < 0)
16+
return __syscall_ret(-EINVAL);
17+
time_t extra_secs = tv->tv_usec / 1000000;
18+
ts.tv_nsec = tv->tv_usec % 1000000 * 1000;
19+
const time_t max_time = (1ULL<<8*sizeof(time_t)-1)-1;
20+
ts.tv_sec = extra_secs > max_time - tv->tv_sec ?
21+
max_time : tv->tv_sec + extra_secs;
22+
}
23+
return syscall_cp(SYS_pselect6, n, rfds, wfds, efds, tv ? &ts : 0, data);
4424
#endif
4525
}

0 commit comments

Comments
 (0)