Skip to content

Commit fa0b08f

Browse files
committed
linux: fix epoll_pwait() sigmask size calculation
Revisit the fix from commit b705b53. The problem with using sigset_t and _NSIG is that the size of sigset_t and the value of _NSIG depend on what headers libuv picks up first, <signal.h> or <asm/signal.h>. With the former, sizeof(sigset_t) = 128; with the latter, it's 8. Simply sidestep the issue by calculating the signal mask as a 64 bits integer, without using sigset_t or _NSIG. This is a partial cherry-pick of commit 751ac48 from the v1.x branch. Original PR-URL: #83 PR-URL: #84 Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
1 parent 03444aa commit fa0b08f

3 files changed

Lines changed: 10 additions & 15 deletions

File tree

src/unix/linux-core.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <sys/prctl.h>
3434
#include <sys/sysinfo.h>
3535
#include <unistd.h>
36-
#include <signal.h>
3736
#include <fcntl.h>
3837
#include <time.h>
3938

@@ -131,8 +130,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
131130
struct uv__epoll_event e;
132131
ngx_queue_t* q;
133132
uv__io_t* w;
134-
sigset_t* pset;
135-
sigset_t set;
133+
uint64_t sigmask;
136134
uint64_t base;
137135
uint64_t diff;
138136
int nevents;
@@ -183,24 +181,21 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
183181
w->events = w->pevents;
184182
}
185183

186-
pset = NULL;
187-
if (loop->flags & UV_LOOP_BLOCK_SIGPROF) {
188-
pset = &set;
189-
sigemptyset(pset);
190-
sigaddset(pset, SIGPROF);
191-
}
184+
sigmask = 0;
185+
if (loop->flags & UV_LOOP_BLOCK_SIGPROF)
186+
sigmask |= 1 << (SIGPROF - 1);
192187

193188
assert(timeout >= -1);
194189
base = loop->time;
195190
count = 48; /* Benchmarks suggest this gives the best throughput. */
196191

197192
for (;;) {
198-
if (no_epoll_wait || pset != NULL) {
193+
if (no_epoll_wait || sigmask) {
199194
nfds = uv__epoll_pwait(loop->backend_fd,
200195
events,
201196
ARRAY_SIZE(events),
202197
timeout,
203-
pset);
198+
sigmask);
204199
} else {
205200
nfds = uv__epoll_wait(loop->backend_fd,
206201
events,

src/unix/linux-syscalls.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,15 @@ int uv__epoll_pwait(int epfd,
291291
struct uv__epoll_event* events,
292292
int nevents,
293293
int timeout,
294-
const sigset_t* sigmask) {
294+
uint64_t sigmask) {
295295
#if defined(__NR_epoll_pwait)
296296
return syscall(__NR_epoll_pwait,
297297
epfd,
298298
events,
299299
nevents,
300300
timeout,
301-
sigmask,
302-
_NSIG / 8);
301+
&sigmask,
302+
sizeof(sigmask));
303303
#else
304304
return errno = ENOSYS, -1;
305305
#endif

src/unix/linux-syscalls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int uv__epoll_pwait(int epfd,
130130
struct uv__epoll_event* events,
131131
int nevents,
132132
int timeout,
133-
const sigset_t* sigmask);
133+
uint64_t sigmask);
134134
int uv__eventfd2(unsigned int count, int flags);
135135
int uv__inotify_init(void);
136136
int uv__inotify_init1(int flags);

0 commit comments

Comments
 (0)