lwp: Rewrite signal wait code for portability and safety

LWP's use of sigset_t is problematic.

To iterate over a sigset_t, it uses NSIG, which is not portable: BSD
and System V provide it, but it's not POSIX.

To record signals caught, it updates a sigset_t variable from a signal
handler.  The variable isn't volatile, because we'd have to cast away
volatile for sigaddset().

Replace sigset_t by an array of signal numbers terminated with 0.

Since lwpInitSigWait() needs to store the signal set for
lwpCatchAwaitedSig() anyway, there is no need to pass it to
lwpSigWait().  Drop its parameter.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2020-12-27 09:36:54 +01:00
parent 460cc9e2ee
commit 2e4793408c
5 changed files with 68 additions and 60 deletions

View file

@ -28,7 +28,7 @@
* lwp.h -- prototypes and structures for lightweight processes
*
* Known contributors to this file:
* Markus Armbruster, 2004-2013
* Markus Armbruster, 2004-2020
* Ron Koenderink, 2007-2009
*/
@ -41,7 +41,6 @@
#ifndef LWP_H
#define LWP_H
#include <signal.h>
#include <sys/time.h>
#define LWP_STACKCHECK 0x1
@ -55,7 +54,7 @@ struct lwp_rwlock;
#define LWP_MAX_PRIO 8
struct lwpProc *lwpInitSystem(int prio, void **ctxp, int flags, sigset_t *);
struct lwpProc *lwpInitSystem(int prio, void **ctxp, int flags, int[]);
struct lwpProc *lwpCreate(int prio, void (*)(void *), int size,
int flags, char *name,
int argc, char **argv, void *ud);
@ -65,7 +64,7 @@ void lwpYield(void);
int lwpSleepFd(int fd, int flags, struct timeval *timeout);
int lwpSleepUntil(time_t until);
void lwpWakeup(struct lwpProc *);
int lwpSigWait(sigset_t *set, int *sig);
int lwpSigWait(int *sig);
void *lwpGetUD(struct lwpProc *);
void lwpSetUD(struct lwpProc *, char *ud);
int lwpSetPriority(int prio);