diff options
62 files changed, 468 insertions, 513 deletions
diff --git a/include/rpc/clnt.h b/include/rpc/clnt.h index 72801e382..0dcadcb5a 100644 --- a/include/rpc/clnt.h +++ b/include/rpc/clnt.h @@ -132,6 +132,10 @@ struct rpc_err { typedef struct CLIENT CLIENT; struct CLIENT { AUTH *cl_auth; /* authenticator */ + /* not sure whether non-const-ness is a part of the spec... if it is, + * enclose "const" in #ifdef UCLIBC_INTERNAL / #endif + * to make it effective only for libc compile */ + const struct clnt_ops { enum clnt_stat (*cl_call) (CLIENT *, u_long, xdrproc_t, caddr_t, xdrproc_t, caddr_t, struct timeval); diff --git a/include/stdlib.h b/include/stdlib.h index 9112a95c4..87b284639 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -347,9 +347,10 @@ struct random_data int32_t *fptr; /* Front pointer. */ int32_t *rptr; /* Rear pointer. */ int32_t *state; /* Array of state values. */ - int rand_type; /* Type of random number generator. */ - int rand_deg; /* Degree of random number generator. */ - int rand_sep; /* Distance between front and rear. */ + /* random_r.c, TYPE_x, DEG_x, SEP_x - small enough for int8_t */ + int8_t rand_type; /* Type of random number generator. */ + int8_t rand_deg; /* Degree of random number generator. */ + int8_t rand_sep; /* Distance between front and rear. */ int32_t *end_ptr; /* Pointer behind state table. */ }; diff --git a/libc/inet/rpc/clnt_raw.c b/libc/inet/rpc/clnt_raw.c index 91340d85a..792796a5f 100644 --- a/libc/inet/rpc/clnt_raw.c +++ b/libc/inet/rpc/clnt_raw.c @@ -84,7 +84,7 @@ static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t); static bool_t clntraw_control (CLIENT *, int, char *); static void clntraw_destroy (CLIENT *); -static struct clnt_ops client_ops = +static const struct clnt_ops client_ops = { clntraw_call, clntraw_abort, diff --git a/libc/inet/rpc/clnt_tcp.c b/libc/inet/rpc/clnt_tcp.c index 622d44552..42bef0793 100644 --- a/libc/inet/rpc/clnt_tcp.c +++ b/libc/inet/rpc/clnt_tcp.c @@ -117,7 +117,7 @@ static bool_t clnttcp_freeres (CLIENT *, xdrproc_t, caddr_t); static bool_t clnttcp_control (CLIENT *, int, char *); static void clnttcp_destroy (CLIENT *); -static struct clnt_ops tcp_ops = +static const struct clnt_ops tcp_ops = { clnttcp_call, clnttcp_abort, diff --git a/libc/inet/rpc/clnt_udp.c b/libc/inet/rpc/clnt_udp.c index 84eb5ed10..e7e816c39 100644 --- a/libc/inet/rpc/clnt_udp.c +++ b/libc/inet/rpc/clnt_udp.c @@ -98,7 +98,7 @@ static bool_t clntudp_freeres (CLIENT *, xdrproc_t, caddr_t); static bool_t clntudp_control (CLIENT *, int, char *); static void clntudp_destroy (CLIENT *); -static struct clnt_ops udp_ops = +static const struct clnt_ops udp_ops = { clntudp_call, clntudp_abort, diff --git a/libc/inet/rpc/clnt_unix.c b/libc/inet/rpc/clnt_unix.c index b412ccb7d..3a1e13c05 100644 --- a/libc/inet/rpc/clnt_unix.c +++ b/libc/inet/rpc/clnt_unix.c @@ -116,7 +116,7 @@ static bool_t clntunix_freeres (CLIENT *, xdrproc_t, caddr_t); static bool_t clntunix_control (CLIENT *, int, char *); static void clntunix_destroy (CLIENT *); -static struct clnt_ops unix_ops = +static const struct clnt_ops unix_ops = { clntunix_call, clntunix_abort, @@ -474,7 +474,7 @@ __msgread (int sock, void *data, size_t cnt) struct iovec iov; struct msghdr msg; #ifdef SCM_CREDENTIALS - static char cm[CMSG_SPACE(sizeof (struct ucred))]; + /*static -why??*/ char cm[CMSG_SPACE(sizeof (struct ucred))]; #endif int len; diff --git a/libc/inet/rpc/create_xid.c b/libc/inet/rpc/create_xid.c index be24d660c..0f045b9c1 100644 --- a/libc/inet/rpc/create_xid.c +++ b/libc/inet/rpc/create_xid.c @@ -34,14 +34,13 @@ #include <bits/uClibc_mutex.h> __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER); - static smallint is_initialized; static struct drand48_data __rpc_lrand48_data; u_long _create_xid (void) attribute_hidden; u_long _create_xid (void) { - unsigned long res; + long res; __UCLIBC_MUTEX_LOCK(mylock); diff --git a/libc/inet/rpc/xdr.c b/libc/inet/rpc/xdr.c index 11e52136d..f76cc6a88 100644 --- a/libc/inet/rpc/xdr.c +++ b/libc/inet/rpc/xdr.c @@ -104,7 +104,6 @@ libc_hidden_def(xdr_void) bool_t xdr_long (XDR *xdrs, long *lp) { - if (xdrs->x_op == XDR_ENCODE && (sizeof (int32_t) == sizeof (long) || (int32_t) *lp == *lp)) @@ -237,10 +236,10 @@ xdr_u_int (XDR *xdrs, u_int *up) { case XDR_ENCODE: l = (u_long) * up; - return XDR_PUTLONG (xdrs, &l); + return XDR_PUTLONG (xdrs, (long *) &l); case XDR_DECODE: - if (!XDR_GETLONG (xdrs, &l)) + if (!XDR_GETLONG (xdrs, (long *) &l)) { return FALSE; } @@ -268,19 +267,20 @@ bool_t xdr_hyper (XDR *xdrs, quad_t *llp) { long t1; - unsigned long int t2; + unsigned long t2; if (xdrs->x_op == XDR_ENCODE) { t1 = (long) ((*llp) >> 32); t2 = (long) (*llp); - return (XDR_PUTLONG(xdrs, &t1) && XDR_PUTLONG(xdrs, &t2)); + return (XDR_PUTLONG(xdrs, &t1) && XDR_PUTLONG(xdrs, (long *) &t2)); } if (xdrs->x_op == XDR_DECODE) { - if (!XDR_GETLONG(xdrs, &t1) || !XDR_GETLONG(xdrs, &t2)) + if (!XDR_GETLONG(xdrs, &t1) || !XDR_GETLONG(xdrs, (long *) &t2)) return FALSE; + /* t2 must be unsigned for this to work */ *llp = ((quad_t) t1) << 32; *llp |= t2; return TRUE; @@ -309,12 +309,12 @@ xdr_u_hyper (XDR *xdrs, u_quad_t *ullp) { t1 = (unsigned long) ((*ullp) >> 32); t2 = (unsigned long) (*ullp); - return (XDR_PUTLONG(xdrs, &t1) && XDR_PUTLONG(xdrs, &t2)); + return (XDR_PUTLONG(xdrs, (long *) &t1) && XDR_PUTLONG(xdrs, (long *) &t2)); } if (xdrs->x_op == XDR_DECODE) { - if (!XDR_GETLONG(xdrs, &t1) || !XDR_GETLONG(xdrs, &t2)) + if (!XDR_GETLONG(xdrs, (long *) &t1) || !XDR_GETLONG(xdrs, (long *) &t2)) return FALSE; *ullp = ((u_quad_t) t1) << 32; *ullp |= t2; @@ -353,10 +353,10 @@ xdr_u_short (XDR *xdrs, u_short *usp) { case XDR_ENCODE: l = (u_long) * usp; - return XDR_PUTLONG (xdrs, &l); + return XDR_PUTLONG (xdrs, (long *) &l); case XDR_DECODE: - if (!XDR_GETLONG (xdrs, &l)) + if (!XDR_GETLONG (xdrs, (long *) &l)) { return FALSE; } diff --git a/libc/inet/rpc/xdr_intXX_t.c b/libc/inet/rpc/xdr_intXX_t.c index d36d1623b..ff2177584 100644 --- a/libc/inet/rpc/xdr_intXX_t.c +++ b/libc/inet/rpc/xdr_intXX_t.c @@ -34,9 +34,9 @@ xdr_int64_t (XDR *xdrs, int64_t *ip) case XDR_ENCODE: t1 = (int32_t) ((*ip) >> 32); t2 = (int32_t) (*ip); - return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, &t2)); + return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, (int32_t *) &t2)); case XDR_DECODE: - if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, &t2)) + if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, (int32_t *) &t2)) return FALSE; *ip = ((int64_t) t1) << 32; *ip |= t2; diff --git a/libc/inet/rpc/xdr_rec.c b/libc/inet/rpc/xdr_rec.c index af5eb5217..b010ab446 100644 --- a/libc/inet/rpc/xdr_rec.c +++ b/libc/inet/rpc/xdr_rec.c @@ -64,20 +64,27 @@ /* libc_hidden_proto(fputs) */ /* libc_hidden_proto(lseek) */ -static bool_t xdrrec_getlong (XDR *, long *); -static bool_t xdrrec_putlong (XDR *, const long *); static bool_t xdrrec_getbytes (XDR *, caddr_t, u_int); static bool_t xdrrec_putbytes (XDR *, const char *, u_int); +static bool_t xdrrec_getint32 (XDR *, int32_t *); +static bool_t xdrrec_putint32 (XDR *, const int32_t *); +#if ULONG_MAX != 0xffffffff +static bool_t xdrrec_getlong (XDR *, long *); +static bool_t xdrrec_putlong (XDR *, const long *); +#endif static u_int xdrrec_getpos (const XDR *); static bool_t xdrrec_setpos (XDR *, u_int); static int32_t *xdrrec_inline (XDR *, u_int); static void xdrrec_destroy (XDR *); -static bool_t xdrrec_getint32 (XDR *, int32_t *); -static bool_t xdrrec_putint32 (XDR *, const int32_t *); static const struct xdr_ops xdrrec_ops = { +#if ULONG_MAX == 0xffffffff + (bool_t (*)(XDR *, long *)) xdrrec_getint32, + (bool_t (*)(XDR *, const long *)) xdrrec_putint32, +#else xdrrec_getlong, xdrrec_putlong, +#endif xdrrec_getbytes, xdrrec_putbytes, xdrrec_getpos, @@ -218,35 +225,46 @@ libc_hidden_def(xdrrec_create) */ static bool_t -xdrrec_getlong (XDR *xdrs, long *lp) +xdrrec_getint32 (XDR *xdrs, int32_t *ip) { RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private; - int32_t *buflp = (int32_t *) rstrm->in_finger; + int32_t *bufip = (int32_t *) rstrm->in_finger; int32_t mylong; /* first try the inline, fast case */ if (rstrm->fbtbc >= BYTES_PER_XDR_UNIT && - rstrm->in_boundry - (char *) buflp >= BYTES_PER_XDR_UNIT) + rstrm->in_boundry - (char *) bufip >= BYTES_PER_XDR_UNIT) { - *lp = (int32_t) ntohl (*buflp); + *ip = ntohl (*bufip); rstrm->fbtbc -= BYTES_PER_XDR_UNIT; rstrm->in_finger += BYTES_PER_XDR_UNIT; } else { - if (!xdrrec_getbytes (xdrs, (caddr_t) & mylong, + if (!xdrrec_getbytes (xdrs, (caddr_t) &mylong, BYTES_PER_XDR_UNIT)) return FALSE; - *lp = (int32_t) ntohl (mylong); + *ip = ntohl (mylong); } return TRUE; } +#if ULONG_MAX != 0xffffffff static bool_t -xdrrec_putlong (XDR *xdrs, const long *lp) +xdrrec_getlong (XDR *xdrs, long *lp) +{ + int32_t v; + bool_t r = xdrrec_getint32 (xdrs, &v); + *lp = v; + return r; +} +#endif + +static bool_t +xdrrec_putint32 (XDR *xdrs, const int32_t *ip) { RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private; - int32_t *dest_lp = (int32_t *) rstrm->out_finger; + int32_t *dest_ip = (int32_t *) rstrm->out_finger; if ((rstrm->out_finger += BYTES_PER_XDR_UNIT) > rstrm->out_boundry) { @@ -258,13 +276,22 @@ xdrrec_putlong (XDR *xdrs, const long *lp) rstrm->frag_sent = TRUE; if (!flush_out (rstrm, FALSE)) return FALSE; - dest_lp = (int32_t *) rstrm->out_finger; + dest_ip = (int32_t *) rstrm->out_finger; rstrm->out_finger += BYTES_PER_XDR_UNIT; } - *dest_lp = htonl (*lp); + *dest_ip = htonl (*ip); return TRUE; } +#if ULONG_MAX != 0xffffffff +static bool_t +xdrrec_putlong (XDR *xdrs, const long *lp) +{ + int32_t v = *lp; + return xdrrec_putint32 (xdrs, &v); +} +#endif + static bool_t /* must manage buffers, fragments, and records */ xdrrec_getbytes (XDR *xdrs, caddr_t addr, u_int len) { @@ -425,54 +452,6 @@ xdrrec_destroy (XDR *xdrs) mem_free ((caddr_t) rstrm, sizeof (RECSTREAM)); } -static bool_t -xdrrec_getint32 (XDR *xdrs, int32_t *ip) -{ - RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private; - int32_t *bufip = (int32_t *) rstrm->in_finger; - int32_t mylong; - - /* first try the inline, fast case */ - if (rstrm->fbtbc >= BYTES_PER_XDR_UNIT && - rstrm->in_boundry - (char *) bufip >= BYTES_PER_XDR_UNIT) - { - *ip = ntohl (*bufip); - rstrm->fbtbc -= BYTES_PER_XDR_UNIT; - rstrm->in_finger += BYTES_PER_XDR_UNIT; - } - else - { - if (!xdrrec_getbytes (xdrs, (caddr_t) &mylong, - BYTES_PER_XDR_UNIT)) - return FALSE; - *ip = ntohl (mylong); - } - return TRUE; -} - -static bool_t -xdrrec_putint32 (XDR *xdrs, const int32_t *ip) -{ - RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private; - int32_t *dest_ip = (int32_t *) rstrm->out_finger; - - if ((rstrm->out_finger += BYTES_PER_XDR_UNIT) > rstrm->out_boundry) - { - /* - * this case should almost never happen so the code is - * inefficient - */ - rstrm->out_finger -= BYTES_PER_XDR_UNIT; - rstrm->frag_sent = TRUE; - if (!flush_out (rstrm, FALSE)) - return FALSE; - dest_ip = (int32_t *) rstrm->out_finger; - rstrm->out_finger += BYTES_PER_XDR_UNIT; - } - *dest_ip = htonl (*ip); - return TRUE; -} - /* * Exported routines to manage xdr records */ diff --git a/libc/misc/ctype/ctype.c b/libc/misc/ctype/ctype.c index 43f95429a..8c99d004c 100644 --- a/libc/misc/ctype/ctype.c +++ b/libc/misc/ctype/ctype.c @@ -875,11 +875,7 @@ libc_hidden_data_def(__ctype_b) /**********************************************************************/ #ifdef L___C_ctype_tolower -//vda:TODO: make static - -extern const __ctype_touplow_t __C_ctype_tolower_data[]; -libc_hidden_proto(__C_ctype_tolower_data) -const __ctype_touplow_t __C_ctype_tolower_data[] = { +static const __ctype_touplow_t __C_ctype_tolower_data[] = { #ifdef __UCLIBC_HAS_CTYPE_SIGNED__ -128, -127, -126, -125, -124, -123, -122, -121, @@ -979,7 +975,6 @@ const __ctype_touplow_t __C_ctype_tolower_data[] = { 248, 249, 250, 251, 252, 253, 254, 255 }; -libc_hidden_data_def(__C_ctype_tolower_data) /* libc_hidden_proto(__C_ctype_tolower) */ const __ctype_touplow_t *__C_ctype_tolower = @@ -999,11 +994,7 @@ libc_hidden_data_def(__ctype_tolower) /**********************************************************************/ #ifdef L___C_ctype_toupper -//vda:TODO: make static - -extern const __ctype_touplow_t __C_ctype_toupper_data[]; -libc_hidden_proto(__C_ctype_toupper_data) -const __ctype_touplow_t __C_ctype_toupper_data[] = { +static const __ctype_touplow_t __C_ctype_toupper_data[] = { #ifdef __UCLIBC_HAS_CTYPE_SIGNED__ -128, -127, -126, -125, -124, -123, -122, -121, @@ -1103,7 +1094,6 @@ const __ctype_touplow_t __C_ctype_toupper_data[] = { 248, 249, 250, 251, 252, 253, 254, 255 }; -libc_hidden_data_def(__C_ctype_toupper_data) /* libc_hidden_proto(__C_ctype_toupper) */ const __ctype_touplow_t *__C_ctype_toupper = diff --git a/libc/misc/syslog/syslog.c b/libc/misc/syslog/syslog.c index ccc71ddec..da60874b3 100644 --- a/libc/misc/syslog/syslog.c +++ b/libc/misc/syslog/syslog.c @@ -207,11 +207,7 @@ vsyslog(int pri, const char *fmt, va_list ap) memset(&action, 0, sizeof(action)); action.sa_handler = closelog_intern; - sigemptyset(&action.sa_mask); /* TODO: memset already zeroed it out! */ - /* Only two errors are possible for sigaction: - * EFAULT (bad address of &oldaction) and EINVAL (invalid signo) - * none of which can happen here. */ - /*int sigpipe =*/ sigaction(SIGPIPE, &action, &oldaction); + sigaction(SIGPIPE, &action, &oldaction); saved_errno = errno; @@ -317,8 +313,7 @@ vsyslog(int pri, const char *fmt, va_list ap) getout: __UCLIBC_MUTEX_UNLOCK(mylock); - /*if (sigpipe == 0)*/ - sigaction(SIGPIPE, &oldaction, (struct sigaction *) NULL); + sigaction(SIGPIPE, &oldaction, NULL); } libc_hidden_def(vsyslog) diff --git a/libc/misc/sysvipc/msgq.c b/libc/misc/sysvipc/msgq.c index 8271ffbef..d67645a4d 100644 --- a/libc/misc/sysvipc/msgq.c +++ b/libc/misc/sysvipc/msgq.c @@ -12,7 +12,7 @@ #ifdef __NR_msgctl #define __NR___libc_msgctl __NR_msgctl -static __inline__ _syscall3(int, __libc_msgctl, int, msqid, int, cmd, struct msqid_ds *, buf) +static __inline__ _syscall3(int, __libc_msgctl, int, msqid, int, cmd, struct msqid_ds *, buf); #endif /* Message queue control operation. */ int msgctl(int msqid, int cmd, struct msqid_ds *buf) diff --git a/libc/misc/sysvipc/sem.c b/libc/misc/sysvipc/sem.c index 96d6a6ee5..e340216e9 100644 --- a/libc/misc/sysvipc/sem.c +++ b/libc/misc/sysvipc/sem.c @@ -99,7 +99,7 @@ _syscall4(int, semtimedop, int, semid, struct sembuf *, sops, size_t, nsops, con int semtimedop(int semid, struct sembuf *sops, size_t nsops, const struct timespec *timeout) { - return __syscall_ipc(IPCOP_semtimedop, semid, nsops, 0, sops, timeout); + return __syscall_ipc(IPCOP_semtimedop, semid, nsops, 0, sops, (void *) timeout); } #endif #endif diff --git a/libc/pwd_grp/lckpwdf.c b/libc/pwd_grp/lckpwdf.c index a9601d45d..c0c8f0d90 100644 --- a/libc/pwd_grp/lckpwdf.c +++ b/libc/pwd_grp/lckpwdf.c @@ -39,11 +39,9 @@ /* libc_hidden_proto(sigemptyset) */ /* libc_hidden_proto(alarm) */ -/* How long to wait for getting the lock before returning with an - error. */ +/* How long to wait for getting the lock before returning with an error. */ #define TIMEOUT 15 /* sec */ - /* File descriptor for lock file. */ static int lock_fd = -1; @@ -51,7 +49,6 @@ static int lock_fd = -1; #include <bits/uClibc_mutex.h> __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER); - /* Prototypes for local functions. */ static void noop_handler (int __sig); @@ -82,71 +79,47 @@ lckpwdf (void) } /* Make sure file gets correctly closed when process finished. */ - flags = fcntl (lock_fd, F_GETFD, 0); - if (flags == -1) { - /* Cannot get file flags. */ - close(lock_fd); - lock_fd = -1; - goto DONE; - } - flags |= FD_CLOEXEC; /* Close on exit. */ - if (fcntl (lock_fd, F_SETFD, flags) < 0) { - /* Cannot set new flags. */ - close(lock_fd); - lock_fd = -1; - goto DONE; - } - + flags = fcntl (lock_fd, F_GETFD); + flags |= FD_CLOEXEC; + fcntl (lock_fd, F_SETFD, flags); /* Now we have to get exclusive write access. Since multiple process could try this we won't stop when it first fails. Instead we set a timeout for the system call. Once the timer expires it is likely that there are some problems which cannot be - resolved by waiting. + resolved by waiting. (sa_flags have no SA_RESTART. Thus SIGALRM + will EINTR fcntl(F_SETLKW) It is important that we don't change the signal state. We must restore the old signal behaviour. */ memset (&new_act, '\0', sizeof (struct sigaction)); new_act.sa_handler = noop_handler; - sigfillset (&new_act.sa_mask); - new_act.sa_flags = 0ul; + __sigfillset (&new_act.sa_mask); - /* Install new action handler for alarm and save old. */ - if (sigaction (SIGALRM, &new_act, &saved_act) < 0) { - /* Cannot install signal handler. */ - close(lock_fd); - lock_fd = -1; - goto DONE; - } + /* Install new action handler for alarm and save old. + * This never fails in Linux. */ + sigaction (SIGALRM, &new_act, &saved_act); /* Now make sure the alarm signal is not blocked. */ - sigemptyset (&new_set); - sigaddset (&new_set, SIGALRM); - if (sigprocmask (SIG_UNBLOCK, &new_set, &saved_set) < 0) { - sigaction (SIGALRM, &saved_act, NULL); - close(lock_fd); - lock_fd = -1; - goto DONE; - } + __sigemptyset (&new_set); + __sigaddset (&new_set, SIGALRM); + sigprocmask (SIG_UNBLOCK, &new_set, &saved_set); /* Start timer. If we cannot get the lock in the specified time we get a signal. */ alarm (TIMEOUT); /* Try to get the lock. */ - memset (&fl, '\0', sizeof (struct flock)); - fl.l_type = F_WRLCK; - fl.l_whence = SEEK_SET; + memset (&fl, '\0', sizeof (fl)); + if (F_WRLCK) + fl.l_type = F_WRLCK; + if (SEEK_SET) + fl.l_whence = SEEK_SET; result = fcntl (lock_fd, F_SETLKW, &fl); /* Clear alarm. */ alarm (0); - /* Restore old set of handled signals. We don't need to know - about the current one.*/ sigprocmask (SIG_SETMASK, &saved_set, NULL); - - /* Restore old action handler for alarm. We don't need to know - about the current one. */ sigaction (SIGALRM, &saved_act, NULL); if (result < 0) { diff --git a/libc/signal/sigaction.c b/libc/signal/sigaction.c index 221951eeb..f430070e6 100644 --- a/libc/signal/sigaction.c +++ b/libc/signal/sigaction.c @@ -43,25 +43,32 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) { int result; struct kernel_sigaction kact, koact; + enum { + /* We try hard to actually have them equal, + * but just for paranoid reasons, be safe */ + SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask) + ? sizeof(kact.sa_mask) : sizeof(act->sa_mask) + }; if (act) { kact.k_sa_handler = act->sa_handler; - memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t)); + memcpy (&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE); kact.sa_flags = act->sa_flags; # ifdef HAVE_SA_RESTORER kact.sa_restorer = act->sa_restorer; # endif } - /* XXX The size argument hopefully will have to be changed to the - real size of the user-level sigset_t. */ + /* NB: kernel (as of 2.6.25) will return EINVAL + * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */ result = __syscall_rt_sigaction(sig, - act ? __ptrvalue (&kact) : NULL, - oact ? __ptrvalue (&koact) : NULL, _NSIG / 8); + act ? __ptrvalue (&kact) : NULL, + oact ? __ptrvalue (&koact) : NULL, + sizeof(kact.sa_mask)); if (oact && result >= 0) { oact->sa_handler = koact.k_sa_handler; - memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t)); + memcpy (&oact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE); oact->sa_flags = koact.sa_flags; # ifdef HAVE_SA_RESTORER oact->sa_restorer = koact.sa_restorer; diff --git a/libc/signal/sigblock.c b/libc/signal/sigblock.c index 7051a94ce..5a16f336b 100644 --- a/libc/signal/sigblock.c +++ b/libc/signal/sigblock.c @@ -19,6 +19,7 @@ #define __UCLIBC_HIDE_DEPRECATED__ #include <errno.h> #include <signal.h> +#include <string.h> /* libc_hidden_proto(sigprocmask) */ @@ -30,12 +31,8 @@ int sigblock (int mask) { sigset_t set, oset; - if (sigset_set_old_mask (&set, mask) < 0) - return -1; - - if (sigprocmask (SIG_BLOCK, &set, &oset) < 0) - return -1; - + sigset_set_old_mask (&set, mask); + sigprocmask (SIG_BLOCK, &set, &oset); /* can't fail */ return sigset_get_old_mask (&oset); } libc_hidden_def(sigblock) diff --git a/libc/signal/sigempty.c b/libc/signal/sigempty.c index 96260fb92..56b62bc65 100644 --- a/libc/signal/sigempty.c +++ b/libc/signal/sigempty.c @@ -26,13 +26,15 @@ /* libc_hidden_proto(sigemptyset) */ int sigemptyset (sigset_t *set) { +#if 0 /* is it really required by standards?! */ if (set == NULL) { __set_errno (EINVAL); return -1; } +#endif - memset (set, 0, sizeof (sigset_t)); + __sigemptyset (set); return 0; } diff --git a/libc/signal/sigfillset.c b/libc/signal/sigfillset.c index 2f8fb8138..b0b093032 100644 --- a/libc/signal/sigfillset.c +++ b/libc/signal/sigfillset.c @@ -27,13 +27,15 @@ int sigfillset (sigset_t *set) { +#if 0 /* is it really required by standards?! */ if (set == NULL) { __set_errno (EINVAL); return -1; } +#endif - memset (set, 0xff, sizeof (sigset_t)); + __sigfillset (set); /* If the implementation uses a cancellation signal don't set the bit. */ #ifdef SIGCANCEL diff --git a/libc/signal/sighold.c b/libc/signal/sighold.c index f8003d60f..fde0a0c2a 100644 --- a/libc/signal/sighold.c +++ b/libc/signal/sighold.c @@ -30,10 +30,9 @@ int sighold (int sig) sigset_t set; /* Retrieve current signal set. */ - if (sigprocmask (SIG_SETMASK, NULL, &set) < 0) - return -1; + sigprocmask (SIG_SETMASK, NULL, &set); /* can't fail */ - /* Add the specified signal. */ + /* Bound-check sig, add it to the set. */ if (sigaddset (&set, sig) < 0) return -1; diff --git a/libc/signal/sigignore.c b/libc/signal/sigignore.c index 58d1c9bfd..f484e29fc 100644 --- a/libc/signal/sigignore.c +++ b/libc/signal/sigignore.c @@ -30,10 +30,8 @@ int sigignore (int sig) { struct sigaction act; + memset(&act, 0, sizeof(act)); act.sa_handler = SIG_IGN; - if (__sigemptyset (&act.sa_mask) < 0) - return -1; - act.sa_flags = 0; return sigaction (sig, &act, NULL); } diff --git a/libc/signal/sigintr.c b/libc/signal/sigintr.c index 351c82b75..1a8d60eb2 100644 --- a/libc/signal/sigintr.c +++ b/libc/signal/sigintr.c @@ -34,7 +34,8 @@ int siginterrupt (int sig, int interrupt) #ifdef SA_RESTART struct sigaction action; - if (sigaction (sig, (struct sigaction *) NULL, &action) < 0) + /* Fails if sig is bad. */ + if (sigaction (sig, NULL, &action) < 0) return -1; if (interrupt) @@ -48,10 +49,7 @@ int siginterrupt (int sig, int interrupt) action.sa_flags |= SA_RESTART; } - if (sigaction (sig, &action, (struct sigaction *) NULL) < 0) - return -1; - - return 0; + return sigaction (sig, &action, NULL); #else __set_errno (ENOSYS); return -1; diff --git a/libc/signal/sigjmp.c b/libc/signal/sigjmp.c index d83b49a0b..646949935 100644 --- a/libc/signal/sigjmp.c +++ b/libc/signal/sigjmp.c @@ -31,7 +31,7 @@ int __sigjmp_save (sigjmp_buf env, int savemask) attribute_hidden; int __sigjmp_save (sigjmp_buf env, int savemask) { env[0].__mask_was_saved = (savemask && - sigprocmask (SIG_BLOCK, (sigset_t *) NULL, &env[0].__saved_mask) == 0); + sigprocmask (SIG_BLOCK, NULL, &env[0].__saved_mask) == 0); return 0; } diff --git a/libc/signal/signal.c b/libc/signal/signal.c index 4d379606f..f3dfa33fc 100644 --- a/libc/signal/signal.c +++ b/libc/signal/signal.c @@ -42,10 +42,10 @@ __bsd_signal (int sig, __sighandler_t handler) } act.sa_handler = handler; - if (__sigemptyset (&act.sa_mask) < 0 - || __sigaddset (&act.sa_mask, sig) < 0) - return SIG_ERR; + __sigemptyset (&act.sa_mask); + __sigaddset (&act.sa_mask, sig); act.sa_flags = __sigismember (&_sigintr, sig) ? 0 : SA_RESTART; + /* In Linux (as of 2.6.25), fails only if sig is SIGKILL or SIGSTOP */ if (sigaction (sig, &act, &oact) < 0) return SIG_ERR; diff --git a/libc/signal/sigpause.c b/libc/signal/sigpause.c index 8cf28ac6e..3275b7ab4 100644 --- a/libc/signal/sigpause.c +++ b/libc/signal/sigpause.c @@ -40,16 +40,16 @@ int __sigpause (int sig_or_mask, int is_sig) { sigset_t set; - if (is_sig != 0) + if (is_sig) { /* The modern X/Open implementation is requested. */ - if (sigprocmask (0, NULL, &set) < 0 - /* Yes, we call `sigdelset' and not `__sigdelset'. */ - || sigdelset (&set, sig_or_mask) < 0) + sigprocmask (SIG_BLOCK, NULL, &set); + /* Bound-check sig_or_mask, remove it from the set. */ + if (sigdelset (&set, sig_or_mask) < 0) return -1; } - else if (sigset_set_old_mask (&set, sig_or_mask) < 0) - return -1; + else + sigset_set_old_mask (&set, sig_or_mask); /* Note the sigpause() is a cancellation point. But since we call sigsuspend() which itself is a cancellation point we do not have diff --git a/libc/signal/sigrelse.c b/libc/signal/sigrelse.c index f5ee6fedc..1a7141ac5 100644 --- a/libc/signal/sigrelse.c +++ b/libc/signal/sigrelse.c @@ -30,10 +30,9 @@ int sigrelse (int sig) sigset_t set; /* Retrieve current signal set. */ - if (sigprocmask (SIG_SETMASK, NULL, &set) < 0) - return -1; + sigprocmask (SIG_SETMASK, NULL, &set); /* can't fail */ - /* Remove the specified signal. */ + /* Bound-check sig, remove it from the set. */ if (sigdelset (&set, sig) < 0) return -1; diff --git a/libc/signal/sigset-cvt-mask.h b/libc/signal/sigset-cvt-mask.h index 7b2f4cdce..76dd01c7e 100644 --- a/libc/signal/sigset-cvt-mask.h +++ b/libc/signal/sigset-cvt-mask.h @@ -19,22 +19,14 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -static __inline__ int __attribute__ ((unused)) +static __inline__ void __attribute__ ((unused)) sigset_set_old_mask (sigset_t *set, int mask) { - unsigned long int *ptr; - int cnt; - - ptr = &set->__val[0]; - - *ptr++ = (unsigned int) mask; - - cnt = _SIGSET_NWORDS - 2; - do - *ptr++ = 0ul; - while (--cnt >= 0); - - return 0; + if (_SIGSET_NWORDS == 2) /* typical */ + set->__val[1] = 0; + if (_SIGSET_NWORDS > 2) + memset(set, 0, sizeof(*set)); + set->__val[0] = (unsigned int) mask; } static __inline__ int __attribute__ ((unused)) diff --git a/libc/signal/sigset.c b/libc/signal/sigset.c index f4c04dc3e..03f3dc869 100644 --- a/libc/signal/sigset.c +++ b/libc/signal/sigset.c @@ -31,51 +31,39 @@ __sighandler_t sigset (int sig, __sighandler_t disp) struct sigaction act, oact; sigset_t set; + /* Check signal extents to protect __sigismember. */ + if (disp == SIG_ERR || sig < 1 || sig >= NSIG) + { + __set_errno (EINVAL); + return SIG_ERR; + } + #ifdef SIG_HOLD /* Handle SIG_HOLD first. */ if (disp == SIG_HOLD) { - /* Create an empty signal set. */ - if (__sigemptyset (&set) < 0) - return SIG_ERR; - - /* Add the specified signal. */ - if (__sigaddset (&set, sig) < 0) - return SIG_ERR; + __sigemptyset (&set); + __sigaddset (&set, sig); /* Add the signal set to the current signal mask. */ - if (sigprocmask (SIG_BLOCK, &set, NULL) < 0) - return SIG_ERR; + sigprocmask (SIG_BLOCK, &set, NULL); /* can't fail */ return SIG_HOLD; } #endif /* SIG_HOLD */ - /* Check signal extents to protect __sigismember. */ - if (disp == SIG_ERR || sig < 1 || sig >= NSIG) - { - __set_errno (EINVAL); - return SIG_ERR; - } - + memset(&act, 0, sizeof(act)); act.sa_handler = disp; - if (__sigemptyset (&act.sa_mask) < 0) - return SIG_ERR; - act.sa_flags = 0; + /* In Linux (as of 2.6.25), fails only if sig is SIGKILL or SIGSTOP */ if (sigaction (sig, &act, &oact) < 0) return SIG_ERR; - /* Create an empty signal set. */ - if (__sigemptyset (&set) < 0) - return SIG_ERR; - - /* Add the specified signal. */ - if (__sigaddset (&set, sig) < 0) - return SIG_ERR; + /* Create an empty signal set. Add the specified signal. */ + __sigemptyset (&set); + __sigaddset (&set, sig); /* Remove the signal set from the current signal mask. */ - if (sigprocmask (SIG_UNBLOCK, &set, NULL) < 0) - return SIG_ERR; + sigprocmask (SIG_UNBLOCK, &set, NULL); /* can't fail */ return oact.sa_handler; } diff --git a/libc/signal/sigsetmask.c b/libc/signal/sigsetmask.c index 5de4b59e4..f8784e288 100644 --- a/libc/signal/sigsetmask.c +++ b/libc/signal/sigsetmask.c @@ -19,6 +19,7 @@ #define __UCLIBC_HIDE_DEPRECATED__ #include <errno.h> #include <signal.h> +#include <string.h> /* libc_hidden_proto(sigprocmask) */ @@ -31,13 +32,8 @@ sigsetmask (int mask) { sigset_t set, oset; - if (sigset_set_old_mask (&set, mask) < 0) - return -1; - - if (sigprocmask (SIG_SETMASK, &set, &oset) < 0) - return -1; - - + sigset_set_old_mask (&set, mask); + sigprocmask (SIG_SETMASK, &set, &oset); /* can't fail */ return sigset_get_old_mask (&oset); } libc_hidden_def(sigsetmask) diff --git a/libc/signal/sysv_signal.c b/libc/signal/sysv_signal.c index c0cd19a95..118094b27 100644 --- a/libc/signal/sysv_signal.c +++ b/libc/signal/sysv_signal.c @@ -47,10 +47,9 @@ __sighandler_t __sysv_signal (int sig, __sighandler_t handler) } act.sa_handler = handler; - if (__sigemptyset (&act.sa_mask) < 0) - return SIG_ERR; - act.sa_flags = SA_ONESHOT | SA_NOMASK | SA_INTERRUPT; - act.sa_flags &= ~SA_RESTART; + __sigemptyset (&act.sa_mask); + act.sa_flags = (SA_ONESHOT | SA_NOMASK | SA_INTERRUPT) & ~SA_RESTART; + /* In Linux (as of 2.6.25), fails only if sig is SIGKILL or SIGSTOP */ if (sigaction (sig, &act, &oact) < 0) return SIG_ERR; diff --git a/libc/stdio/fgetc.c b/libc/stdio/fgetc.c index 89c8fe35a..dfe57a6cd 100644 --- a/libc/stdio/fgetc.c +++ b/libc/stdio/fgetc.c @@ -79,7 +79,7 @@ libc_hidden_def(__fgetc_unlocked) strong_alias(__fgetc_unlocked,fgetc_unlocked) libc_hidden_def(fgetc_unlocked) -//libc_hidden_proto(__getc_unlocked) +///* libc_hidden_proto(__getc_unlocked) */ //strong_alias(__fgetc_unlocked,__getc_unlocked) //libc_hidden_def(__getc_unlocked) diff --git a/libc/stdio/fputc.c b/libc/stdio/fputc.c index 09d8ee138..f426161d2 100644 --- a/libc/stdio/fputc.c +++ b/libc/stdio/fputc.c @@ -72,11 +72,9 @@ int __fputc_unlocked(int c, register FILE *stream) } libc_hidden_def(__fputc_unlocked) -/* exposing these would be fundamentally *wrong*! fix you, instead! */ /* libc_hidden_proto(fputc_unlocked) */ strong_alias(__fputc_unlocked,fputc_unlocked) -/* exposing these would be fundamentally *wrong*! fix you, instead! */ -/* libc_hidden_def(fputc_unlocked) */ +libc_hidden_def(fputc_unlocked) /* libc_hidden_proto(putc_unlocked) */ strong_alias(__fputc_unlocked,putc_unlocked) diff --git a/libc/stdio/fwprintf.c b/libc/stdio/fwprintf.c index a5f09cd2d..6bae0c7a4 100644 --- a/libc/stdio/fwprintf.c +++ b/libc/stdio/fwprintf.c @@ -22,3 +22,4 @@ int fwprintf(FILE * __restrict stream, const wchar_t * __restrict format, ...) return rv; } +libc_hidden_def(fwprintf) diff --git a/libc/stdlib/abort.c b/libc/stdlib/abort.c index 7291d0ea4..fcf90187c 100644 --- a/libc/stdlib/abort.c +++ b/libc/stdlib/abort.c @@ -60,9 +60,9 @@ void abort(void) __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(mylock); /* Unmask SIGABRT to be sure we can get it */ - if (__sigemptyset(&sigs) == 0 && __sigaddset(&sigs, SIGABRT) == 0) { - sigprocmask(SIG_UNBLOCK, &sigs, (sigset_t *) NULL); - } + __sigemptyset(&sigs); + __sigaddset(&sigs, SIGABRT); + sigprocmask(SIG_UNBLOCK, &sigs, NULL); while (1) { /* Try to suicide with a SIGABRT */ @@ -91,9 +91,9 @@ abort_it: been_there_done_that++; memset(&act, '\0', sizeof(struct sigaction)); - act.sa_handler = SIG_DFL; + if (SIG_DFL) /* if it's constant zero, already done */ + act.sa_handler = SIG_DFL; __sigfillset(&act.sa_mask); - act.sa_flags = 0; sigaction(SIGABRT, &act, NULL); goto abort_it; diff --git a/libc/stdlib/l64a.c b/libc/stdlib/l64a.c index a8b2d551e..5a1dc13a6 100644 --- a/libc/stdlib/l64a.c +++ b/libc/stdlib/l64a.c @@ -36,21 +36,21 @@ char * l64a (long int n) { unsigned long int m = (unsigned long int) n; static char result[7]; - int cnt; + char *p; /* The standard says that only 32 bits are used. */ - m &= 0xffffffff; + if (sizeof(m) != 4) + m &= 0xffffffff; - if (m == 0ul) - /* The value for N == 0 is defined to be the empty string. */ - return (char *) ""; - - for (cnt = 0; m > 0ul; ++cnt) + /* The value for N == 0 is defined to be the empty string, + * this code provides that as well. */ + p = result; + while (m) { - result[cnt] = conv_table[m & 0x3f]; + *p++ = conv_table[m & 0x3f]; m >>= 6; } - result[cnt] = '\0'; + *p = '\0'; - return result; + return p; } diff --git a/libc/stdlib/rand.c b/libc/stdlib/rand.c index 61aaa9105..93fc01483 100644 --- a/libc/stdlib/rand.c +++ b/libc/stdlib/rand.c @@ -9,8 +9,7 @@ /* libc_hidden_proto(random) */ -int rand (void) +int rand(void) { - return((int)random()); + return (int)random(); } - diff --git a/libc/stdlib/random.c b/libc/stdlib/random.c index 6d5d06e09..967a1e52a 100644 --- a/libc/stdlib/random.c +++ b/libc/stdlib/random.c @@ -74,11 +74,7 @@ __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); -/* For each of the currently supported random number generators, we have a - break value on the amount of state information (you need at least this many - bytes of state info to support this random number generator), a degree for - the polynomial (actually a trinomial) that the R.N.G. is based on, and - separation between the two lower order coefficients of the trinomial. */ +/* Keep constants in sync with random_r.c */ /* Linear congruential. */ #define TYPE_0 0 @@ -110,13 +106,8 @@ __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); #define DEG_4 63 #define SEP_4 1 - -/* Array versions of the above information to make code run faster. - Relies on fact that TYPE_i == i. */ - #define MAX_TYPES 5 /* Max number of types above. */ - /* Initially, everything is set up as if from: initstate(1, randtbl, 128); Note that this initialization takes advantage of the fact that srandom diff --git a/libc/stdlib/random_r.c b/libc/stdlib/random_r.c index b6ff6afd2..cb70b7dc4 100644 --- a/libc/stdlib/random_r.c +++ b/libc/stdlib/random_r.c @@ -27,8 +27,7 @@ #include <limits.h> #include <stddef.h> #include <stdlib.h> - - +#include <unistd.h> /* An improved random number generation package. In addition to the standard rand()/srand() like interface, this package also has a special state info @@ -109,8 +108,8 @@ struct random_poly_info { - int seps[MAX_TYPES]; - int degrees[MAX_TYPES]; + smallint seps[MAX_TYPES]; + smallint degrees[MAX_TYPES]; }; static const struct random_poly_info random_poly_info = @@ -121,7 +120,6 @@ static const struct random_poly_info random_poly_info = - /* If we are using the trivial TYPE_0 R.N.G., just do the old linear congruential bit. Otherwise, we do our fancy trinomial stuff, which is the same in all the other cases due to all the global variables that have been diff --git a/libc/sysdeps/linux/alpha/sigprocmask.c b/libc/sysdeps/linux/alpha/sigprocmask.c index f5e3c8d91..832684cef 100644 --- a/libc/sysdeps/linux/alpha/sigprocmask.c +++ b/libc/sysdeps/linux/alpha/sigprocmask.c @@ -44,17 +44,18 @@ sigprocmask (int how, const sigset_t *set, sigset_t *oset) result = osf_sigprocmask(how, setval); if (result == -1) - /* If there are ever more than 63 signals, we need to recode this + /* If there are ever more than 64 signals, we need to recode this in assembler since we wouldn't be able to distinguish a mask of all 1s from -1, but for now, we're doing just fine... */ return result; if (oset) { + if (_SIGSET_NWORDS == 2) /* typical */ + oset->__val[1] = 0; + if (_SIGSET_NWORDS > 2) + memset(oset, 0, sizeof(*oset)); oset->__val[0] = result; - result = _SIGSET_NWORDS; - while (--result > 0) - oset->__val[result] = 0; } return 0; } diff --git a/libc/sysdeps/linux/avr32/sigaction.c b/libc/sysdeps/linux/avr32/sigaction.c index 05caec7ee..45d0abb5a 100644 --- a/libc/sysdeps/linux/avr32/sigaction.c +++ b/libc/sysdeps/linux/avr32/sigaction.c @@ -27,10 +27,14 @@ int __libc_sigaction(int signum, const struct sigaction *act, { struct kernel_sigaction kact, koact; int result; + enum { + SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask) + ? sizeof(kact.sa_mask) : sizeof(act->sa_mask) + }; if (act) { kact.k_sa_handler = act->sa_handler; - memcpy(&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask)); + memcpy(&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE); kact.sa_flags = act->sa_flags; if (kact.sa_flags & SA_RESTORER) kact.sa_restorer = act->sa_restorer; @@ -39,14 +43,16 @@ int __libc_sigaction(int signum, const struct sigaction *act, kact.sa_flags |= SA_RESTORER; } - result = __syscall_rt_sigaction(signum, act ? __ptrvalue(&kact) : NULL, - oldact ? __ptrvalue(&koact) : NULL, - _NSIG / 8); + /* NB: kernel (as of 2.6.25) will return EINVAL + * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */ + result = __syscall_rt_sigaction(signum, + act ? __ptrvalue(&kact) : NULL, + oldact ? __ptrvalue(&koact) : NULL, + sizeof(kact.sa_mask)); if (oldact && result >= 0) { oldact->sa_handler = koact.k_sa_handler; - memcpy(&oldact->sa_mask, &koact.sa_mask, - sizeof(oldact->sa_mask)); + memcpy(&oldact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE); oldact->sa_flags = koact.sa_flags; oldact->sa_restorer = koact.sa_restorer; } diff --git a/libc/sysdeps/linux/common/bits/sigset.h b/libc/sysdeps/linux/common/bits/sigset.h index 9a16e5cb9..7ec87eb1d 100644 --- a/libc/sysdeps/linux/common/bits/sigset.h +++ b/libc/sysdeps/linux/common/bits/sigset.h @@ -22,13 +22,26 @@ typedef int __sig_atomic_t; -/* A `sigset_t' has a bit for each signal. */ - -# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int))) -typedef struct - { - unsigned long int __val[_SIGSET_NWORDS]; - } __sigset_t; +/* A 'sigset_t' has a bit for each signal. + * glibc has space for 1024 signals (!), but most arches supported + * by Linux have 64 signals, and only MIPS has 128. + * There seems to be some historical baggage in sparc[64] + * where they might have (or had in the past) 32 signals only, + * I hope it's irrelevant now. + * Signal 0 does not exist, so we have signals 1..64, not 0..63. + * Note that struct sigaction has embedded sigset_t, + * and this necessitates translation in sigaction() + * to convert it to struct kernel_sigaction. + * See libc/.../sigaction.c, libc/.../kernel_sigaction.h + */ +#if defined(__mips__) +# define _SIGSET_NWORDS (128 / (8 * sizeof (unsigned long))) +#else +# define _SIGSET_NWORDS (64 / (8 * sizeof (unsigned long))) +#endif +typedef struct { + unsigned long __val[_SIGSET_NWORDS]; +} __sigset_t; #endif @@ -47,53 +60,98 @@ typedef struct # endif /* Return a mask that includes the bit for SIG only. */ +/* Unsigned cast ensures shift/mask insns are used. */ # define __sigmask(sig) \ - (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int)))) + (((unsigned long) 1) << ((unsigned)((sig) - 1) % (8 * sizeof (unsigned long)))) /* Return the word index for SIG. */ -# define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int))) +# define __sigword(sig) ((unsigned)((sig) - 1) / (8 * sizeof (unsigned long))) + +/* gcc 4.3.1 is not clever enough to optimize for _SIGSET_NWORDS == 1 and 2, + * which are about the only values which can be there */ # if defined __GNUC__ && __GNUC__ >= 2 # define __sigemptyset(set) \ - (__extension__ ({ int __cnt = _SIGSET_NWORDS; \ - sigset_t *__set = (set); \ - while (--__cnt >= 0) __set->__val[__cnt] = 0; \ - 0; })) +(__extension__ ({ \ + sigset_t *__set = (set); \ + if (_SIGSET_NWORDS <= 2) { \ + __set->__val[0] = 0; \ + if (_SIGSET_NWORDS == 2) \ + __set->__val[1] = 0; \ + } else { \ + int __cnt = _SIGSET_NWORDS; \ + while (--__cnt >= 0) __set->__val[__cnt] = 0; \ + } \ + 0; \ +})) # define __sigfillset(set) \ - (__extension__ ({ int __cnt = _SIGSET_NWORDS; \ - sigset_t *__set = (set); \ - while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \ - 0; })) +(__extension__ ({ \ + sigset_t *__set = (set); \ + if (_SIGSET_NWORDS <= 2) { \ + __set->__val[0] = ~0UL; \ + if (_SIGSET_NWORDS == 2) \ + __set->__val[1] = ~0UL; \ + } else { \ + int __cnt = _SIGSET_NWORDS; \ + while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \ + } \ + 0; \ +})) # ifdef __USE_GNU /* The POSIX does not specify for handling the whole signal set in one command. This is often wanted and so we define three more functions here. */ # define __sigisemptyset(set) \ - (__extension__ ({ int __cnt = _SIGSET_NWORDS; \ - const sigset_t *__set = (set); \ - int __ret = __set->__val[--__cnt]; \ - while (!__ret && --__cnt >= 0) \ - __ret = __set->__val[__cnt]; \ - __ret == 0; })) +(__extension__ ({ \ + long __ret; \ + const sigset_t *__set = (set); \ + if (_SIGSET_NWORDS == 1) { \ + __ret = __set->__val[0]; \ + } else if (_SIGSET_NWORDS == 2) { \ + __ret = __set->__val[0] | __set->__val[1]; \ + } else { \ + int __cnt = _SIGSET_NWORDS; \ + __ret = __set->__val[--__cnt]; \ + while (!__ret && --__cnt >= 0) \ + __ret = __set->__val[__cnt]; \ + } \ + __ret == 0; \ +})) # define __sigandset(dest, left, right) \ - (__extension__ ({ int __cnt = _SIGSET_NWORDS; \ - sigset_t *__dest = (dest); \ - const sigset_t *__left = (left); \ - const sigset_t *__right = (right); \ - while (--__cnt >= 0) \ - __dest->__val[__cnt] = (__left->__val[__cnt] \ - & __right->__val[__cnt]); \ - 0; })) +(__extension__ ({ \ + sigset_t *__dest = (dest); \ + const sigset_t *__left = (left); \ + const sigset_t *__right = (right); \ + if (_SIGSET_NWORDS <= 2) { \ + __dest->__val[0] = __left->__val[0] & __right->__val[0];\ + if (_SIGSET_NWORDS == 2) \ + __dest->__val[1] = __left->__val[1] & __right->__val[1];\ + } else { \ + int __cnt = _SIGSET_NWORDS; \ + while (--__cnt >= 0) \ + __dest->__val[__cnt] = (__left->__val[__cnt] \ + & __right->__val[__cnt]); \ + } \ + 0; \ +})) # define __sigorset(dest, left, right) \ - (__extension__ ({ int __cnt = _SIGSET_NWORDS; \ - sigset_t *__dest = (dest); \ - const sigset_t *__left = (left); \ - const sigset_t *__right = (right); \ - while (--__cnt >= 0) \ - __dest->__val[__cnt] = (__left->__val[__cnt] \ - | __right->__val[__cnt]); \ - 0; })) +(__extension__ ({ \ + sigset_t *__dest = (dest); \ + const sigset_t *__left = (left); \ + const sigset_t *__right = (right); \ + if (_SIGSET_NWORDS <= 2) { \ + __dest->__val[0] = __left->__val[0] | __right->__val[0];\ + if (_SIGSET_NWORDS == 2) \ + __dest->__val[1] = __left->__val[1] | __right->__val[1];\ + } else { \ + int __cnt = _SIGSET_NWORDS; \ + while (--__cnt >= 0) \ + __dest->__val[__cnt] = (__left->__val[__cnt] \ + | __right->__val[__cnt]); \ + } \ + 0; \ +})) # endif # endif @@ -108,14 +166,14 @@ extern int __sigdelset (__sigset_t *, int); libc_hidden_proto(__sigdelset) # ifdef __USE_EXTERN_INLINES -# define __SIGSETFN(NAME, BODY, CONST) \ - _EXTERN_INLINE int \ - NAME (CONST __sigset_t *__set, int __sig) \ - { \ - unsigned long int __mask = __sigmask (__sig); \ - unsigned long int __word = __sigword (__sig); \ - return BODY; \ - } +# define __SIGSETFN(NAME, BODY, CONST) \ +_EXTERN_INLINE int \ +NAME (CONST __sigset_t *__set, int __sig) \ +{ \ + unsigned long __mask = __sigmask (__sig); \ + unsigned long __word = __sigword (__sig); \ + return BODY; \ +} __SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const) __SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), ) diff --git a/libc/sysdeps/linux/common/longjmp.c b/libc/sysdeps/linux/common/longjmp.c index 672754a73..e600c7f13 100644 --- a/libc/sysdeps/linux/common/longjmp.c +++ b/libc/sysdeps/linux/common/longjmp.c @@ -38,8 +38,7 @@ void __libc_longjmp (sigjmp_buf env, int val) if (env[0].__mask_was_saved) /* Restore the saved signal mask. */ - (void) sigprocmask (SIG_SETMASK, &env[0].__saved_mask, - (sigset_t *) NULL); + (void) sigprocmask (SIG_SETMASK, &env[0].__saved_mask, NULL); /* Call the machine-dependent function to restore machine state. */ __longjmp (env[0].__jmpbuf, val ?: 1); diff --git a/libc/sysdeps/linux/common/mknod.c b/libc/sysdeps/linux/common/mknod.c index 75aff70c8..5c7f9a5fd 100644 --- a/libc/sysdeps/linux/common/mknod.c +++ b/libc/sysdeps/linux/common/mknod.c @@ -11,18 +11,14 @@ #include <sys/stat.h> #include <sys/sysmacros.h> -libc_hidden_proto(mknod) +/* libc_hidden_proto(mknod) */ #define __NR___syscall_mknod __NR_mknod static __inline__ _syscall3(int, __syscall_mknod, const char *, path, - __kernel_mode_t, mode, __kernel_dev_t, dev); + __kernel_mode_t, mode, __kernel_dev_t, dev) int mknod(const char *path, mode_t mode, dev_t dev) { - /* We must convert the dev_t value to a __kernel_dev_t */ - __kernel_dev_t k_dev; - - k_dev = ((major(dev) & 0xff) << 8) | (minor(dev) & 0xff); - return __syscall_mknod(path, mode, k_dev); + return __syscall_mknod(path, mode, (__kernel_dev_t)dev); } libc_hidden_def(mknod) diff --git a/libc/sysdeps/linux/common/pause.c b/libc/sysdeps/linux/common/pause.c index b68ec4a51..7baba1a93 100644 --- a/libc/sysdeps/linux/common/pause.c +++ b/libc/sysdeps/linux/common/pause.c @@ -12,6 +12,8 @@ #include <unistd.h> #include <sysdep-cancel.h> #include <signal.h> +/* libc_hidden_proto(__sigpause) */ +/* libc_hidden_proto(sigblock) */ /* Suspend the process until a signal arrives. This always returns -1 and sets errno to EINTR. */ diff --git a/libc/sysdeps/linux/common/ssp.c b/libc/sysdeps/linux/common/ssp.c index 73d7113b8..8a84e4893 100644 --- a/libc/sysdeps/linux/common/ssp.c +++ b/libc/sysdeps/linux/common/ssp.c @@ -51,16 +51,15 @@ static void block_signals(void) struct sigaction sa; sigset_t mask; - sigfillset(&mask); - - sigdelset(&mask, SSP_SIGTYPE); /* Block all signal handlers */ + __sigfillset(&mask); + __sigdelset(&mask, SSP_SIGTYPE); /* Block all signal handlers */ sigprocmask(SIG_BLOCK, &mask, NULL); /* except SSP_SIGTYPE */ /* Make the default handler associated with the signal handler */ - memset(&sa, 0, sizeof(struct sigaction)); - sigfillset(&sa.sa_mask); /* Block all signals */ - sa.sa_flags = 0; - sa.sa_handler = SIG_DFL; + memset(&sa, 0, sizeof(sa)); + __sigfillset(&sa.sa_mask); /* Block all signals */ + if (SIG_DFL) /* if it's constant zero, it's already done */ + sa.sa_handler = SIG_DFL; sigaction(SSP_SIGTYPE, &sa, NULL); } diff --git a/libc/sysdeps/linux/common/wait4.c b/libc/sysdeps/linux/common/wait4.c index 5c51116fa..4fd866996 100644 --- a/libc/sysdeps/linux/common/wait4.c +++ b/libc/sysdeps/linux/common/wait4.c @@ -12,11 +12,11 @@ #include <sys/wait.h> #include <sys/resource.h> -libc_hidden_proto(wait4) +/* libc_hidden_proto(wait4) */ #define __NR___syscall_wait4 __NR_wait4 static __inline__ _syscall4(int, __syscall_wait4, __kernel_pid_t, pid, - int *, status, int, opts, struct rusage *, rusage); + int *, status, int, opts, struct rusage *, rusage) pid_t wait4(pid_t pid, int *status, int opts, struct rusage *rusage) { diff --git a/libc/sysdeps/linux/i386/sigaction.c b/libc/sysdeps/linux/i386/sigaction.c index 32c8f64bc..e323d0938 100644 --- a/libc/sysdeps/linux/i386/sigaction.c +++ b/libc/sysdeps/linux/i386/sigaction.c @@ -39,38 +39,44 @@ extern void restore (void) __asm__ ("__restore") attribute_hidden; If OACT is not NULL, put the old action for SIG in *OACT. */ int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) { - int result; - struct kernel_sigaction kact, koact; + int result; + struct kernel_sigaction kact, koact; + enum { + SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask) + ? sizeof(kact.sa_mask) : sizeof(act->sa_mask) + }; #ifdef SIGCANCEL - if (sig == SIGCANCEL) { - __set_errno (EINVAL); - return -1; - } + if (sig == SIGCANCEL) { + __set_errno (EINVAL); + return -1; + } #endif - if (act) { - kact.k_sa_handler = act->sa_handler; - memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask)); - kact.sa_flags = act->sa_flags; - - kact.sa_flags = act->sa_flags | SA_RESTORER; - kact.sa_restorer = ((act->sa_flags & SA_SIGINFO) - ? &restore_rt : &restore); - } - - /* XXX The size argument hopefully will have to be changed to the - real size of the user-level sigset_t. */ - result = __syscall_rt_sigaction(sig, act ? __ptrvalue (&kact) : NULL, - oact ? __ptrvalue (&koact) : NULL, _NSIG / 8); - - if (oact && result >= 0) { - oact->sa_handler = koact.k_sa_handler; - memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (oact->sa_mask)); - oact->sa_flags = koact.sa_flags; - oact->sa_restorer = koact.sa_restorer; - } - return result; + if (act) { + kact.k_sa_handler = act->sa_handler; + memcpy (&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE); + kact.sa_flags = act->sa_flags; + + kact.sa_flags = act->sa_flags | SA_RESTORER; + kact.sa_restorer = ((act->sa_flags & SA_SIGINFO) + ? &restore_rt : &restore); + } + + /* NB: kernel (as of 2.6.25) will return EINVAL + * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */ + result = __syscall_rt_sigaction(sig, + act ? __ptrvalue (&kact) : NULL, + oact ? __ptrvalue (&koact) : NULL, + sizeof(kact.sa_mask)); + + if (oact && result >= 0) { + oact->sa_handler = koact.k_sa_handler; + memcpy (&oact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE); + oact->sa_flags = koact.sa_flags; + oact->sa_restorer = koact.sa_restorer; + } + return result; } diff --git a/libc/sysdeps/linux/mips/bits/signum.h b/libc/sysdeps/linux/mips/bits/signum.h index a9b684834..6176b90b9 100644 --- a/libc/sysdeps/linux/mips/bits/signum.h +++ b/libc/sysdeps/linux/mips/bits/signum.h @@ -65,7 +65,7 @@ #define SIGXFSZ 31 /* File size limit exceeded (4.2 BSD). */ -#define _NSIG 128 /* Biggest signal number + 1 +#define _NSIG 129 /* Biggest signal number + 1 (including real-time signals). */ #define SIGRTMIN (__libc_current_sigrtmin ()) diff --git a/libc/sysdeps/linux/mips/bits/socket.h b/libc/sysdeps/linux/mips/bits/socket.h index 0860b4d38..39fadc676 100644 --- a/libc/sysdeps/linux/mips/bits/socket.h +++ b/libc/sysdeps/linux/mips/bits/socket.h @@ -270,6 +270,7 @@ struct cmsghdr extern struct cmsghdr * __NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg)) __THROW; +libc_hidden_proto(__cmsg_nxthdr) #ifdef __USE_EXTERN_INLINES # ifndef _EXTERN_INLINE # define _EXTERN_INLINE extern __inline diff --git a/libc/sysdeps/linux/mips/sigaction.c b/libc/sysdeps/linux/mips/sigaction.c index edd265438..ca39740af 100644 --- a/libc/sysdeps/linux/mips/sigaction.c +++ b/libc/sysdeps/linux/mips/sigaction.c @@ -47,36 +47,42 @@ static void restore (void) __asm__ ("__restore"); If OACT is not NULL, put the old action for SIG in *OACT. */ int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) { - int result; - struct kernel_sigaction kact, koact; - - if (act) { - kact.k_sa_handler = act->sa_handler; - memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask)); - kact.sa_flags = act->sa_flags; + int result; + struct kernel_sigaction kact, koact; + enum { + SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask) + ? sizeof(kact.sa_mask) : sizeof(act->sa_mask) + }; + + if (act) { + kact.k_sa_handler = act->sa_handler; + memcpy (&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE); + kact.sa_flags = act->sa_flags; # ifdef HAVE_SA_RESTORER # if _MIPS_SIM == _ABIO32 - kact.sa_restorer = act->sa_restorer; + kact.sa_restorer = act->sa_restorer; # else - kact.sa_restorer = &restore_rt; + kact.sa_restorer = &restore_rt; # endif # endif - } - - /* XXX The size argument hopefully will have to be changed to the - real size of the user-level sigset_t. */ - result = __syscall_rt_sigaction(sig, act ? __ptrvalue (&kact) : NULL, - oact ? __ptrvalue (&koact) : NULL, _NSIG / 8); - - if (oact && result >= 0) { - oact->sa_handler = koact.k_sa_handler; - memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (oact->sa_mask)); - oact->sa_flags = koact.sa_flags; + } + + /* NB: kernel (as of 2.6.25) will return EINVAL + * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */ + result = __syscall_rt_sigaction(sig, + act ? __ptrvalue (&kact) : NULL, + oact ? __ptrvalue (&koact) : NULL, + sizeof(kact.sa_mask)); + + if (oact && result >= 0) { + oact->sa_handler = koact.k_sa_handler; + memcpy (&oact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE); + oact->sa_flags = koact.sa_flags; # ifdef HAVE_SA_RESTORER - oact->sa_restorer = koact.sa_restorer; + oact->sa_restorer = koact.sa_restorer; # endif - } - return result; + } + return result; } diff --git a/libc/sysdeps/linux/mips/syscall.S b/libc/sysdeps/linux/mips/syscall.S index ff6f3d1b4..acb91011d 100644 --- a/libc/sysdeps/linux/mips/syscall.S +++ b/libc/sysdeps/linux/mips/syscall.S @@ -32,7 +32,6 @@ syscall: #ifdef __PIC__ SETUP_GP #endif - .set noreorder move v0, a0 /* Load system call number from first arg. */ move a0, a1 /* Move the next three args up a register. */ move a1, a2 @@ -59,12 +58,12 @@ syscall: lw v0,7*4(sp) /* for system call restarts */ #endif syscall /* Do the system call. */ - bnez a3, 1f #ifdef __mips64 daddiu sp,sp,16 #else addiu sp,sp,32 #endif + bnez a3, 1f j ra /* Return to caller. */ 1: move a0,v0 /* Pass return val to C function. */ diff --git a/libc/sysdeps/linux/x86_64/sigaction.c b/libc/sysdeps/linux/x86_64/sigaction.c index 3d9e4ea29..e53e30442 100644 --- a/libc/sysdeps/linux/x86_64/sigaction.c +++ b/libc/sysdeps/linux/x86_64/sigaction.c @@ -50,23 +50,29 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) { int result; struct kernel_sigaction kact, koact; + enum { + SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask) + ? sizeof(kact.sa_mask) : sizeof(act->sa_mask) + }; if (act) { kact.k_sa_handler = act->sa_handler; - memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t)); + memcpy (&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE); kact.sa_flags = act->sa_flags | SA_RESTORER; kact.sa_restorer = &restore_rt; } - /* XXX The size argument hopefully will have to be changed to the - real size of the user-level sigset_t. */ - result = INLINE_SYSCALL (rt_sigaction, 4, - sig, act ? __ptrvalue (&kact) : NULL, - oact ? __ptrvalue (&koact) : NULL, _NSIG / 8); + /* NB: kernel (as of 2.6.25) will return EINVAL + * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */ + result = INLINE_SYSCALL (rt_sigaction, 4, sig, + act ? __ptrvalue (&kact) : NULL, + oact ? __ptrvalue (&koact) : NULL, + sizeof(kact.sa_mask)); + if (oact && result >= 0) { oact->sa_handler = koact.k_sa_handler; - memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t)); + memcpy (&oact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE); oact->sa_flags = koact.sa_flags; oact->sa_restorer = koact.sa_restorer; } diff --git a/libc/sysdeps/linux/xtensa/sigaction.c b/libc/sysdeps/linux/xtensa/sigaction.c index 790a8f21f..c6c24fc36 100644 --- a/libc/sysdeps/linux/xtensa/sigaction.c +++ b/libc/sysdeps/linux/xtensa/sigaction.c @@ -20,14 +20,18 @@ extern void __default_sa_restorer (void); /* Experimentally off - libc_hidden_proto(memcpy) */ int __libc_sigaction (int signum, const struct sigaction *act, - struct sigaction *oldact) + struct sigaction *oact) { - struct kernel_sigaction kact, koldact; + struct kernel_sigaction kact, koact; int result; + enum { + SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask) + ? sizeof(kact.sa_mask) : sizeof(act->sa_mask) + }; if (act) { kact.k_sa_handler = act->sa_handler; - memcpy(&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask)); + memcpy(&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE); kact.sa_flags = act->sa_flags; if (kact.sa_flags & SA_RESTORER) { @@ -38,15 +42,18 @@ int __libc_sigaction (int signum, const struct sigaction *act, } } - result = __syscall_rt_sigaction(signum, act ? __ptrvalue (&kact) : NULL, - oldact ? __ptrvalue (&koldact) : NULL, - _NSIG / 8); + /* NB: kernel (as of 2.6.25) will return EINVAL + * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */ + result = __syscall_rt_sigaction(signum, + act ? __ptrvalue (&kact) : NULL, + oact ? __ptrvalue (&koact) : NULL, + sizeof(kact.sa_mask)); - if (oldact && result >= 0) { - oldact->sa_handler = koldact.k_sa_handler; - memcpy(&oldact->sa_mask, &koldact.sa_mask, sizeof(oldact->sa_mask)); - oldact->sa_flags = koldact.sa_flags; - oldact->sa_restorer = koldact.sa_restorer; + if (oact && result >= 0) { + oact->sa_handler = koact.k_sa_handler; + memcpy(&oact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE); + oact->sa_flags = koact.sa_flags; + oact->sa_restorer = koact.sa_restorer; } return result; diff --git a/libc/unistd/sleep.c b/libc/unistd/sleep.c index e7152c46b..4d55d843d 100644 --- a/libc/unistd/sleep.c +++ b/libc/unistd/sleep.c @@ -66,10 +66,9 @@ unsigned int sleep (unsigned int seconds) /* Linux will wake up the system call, nanosleep, when SIGCHLD arrives even if SIGCHLD is ignored. We have to deal with it in libc. We block SIGCHLD first. */ - if (__sigemptyset (&set) < 0 - || __sigaddset (&set, SIGCHLD) < 0 - || sigprocmask (SIG_BLOCK, &set, &oset)) - return -1; + __sigemptyset (&set); + __sigaddset (&set, SIGCHLD); + sigprocmask (SIG_BLOCK, &set, &oset); /* can't fail */ /* If SIGCHLD is already blocked, we don't have to do anything. */ if (!__sigismember (&oset, SIGCHLD)) @@ -77,18 +76,10 @@ unsigned int sleep (unsigned int seconds) int saved_errno; struct sigaction oact; - if (__sigemptyset (&set) < 0 || __sigaddset (&set, SIGCHLD) < 0) - return -1; + __sigemptyset (&set); + __sigaddset (&set, SIGCHLD); - /* We get the signal handler for SIGCHLD. */ - if (sigaction (SIGCHLD, (struct sigaction *) NULL, &oact) < 0) - { - saved_errno = errno; - /* Restore the original signal mask. */ - (void) sigprocmask (SIG_SETMASK, &oset, (sigset_t *) NULL); - __set_errno (saved_errno); - return -1; - } + sigaction (SIGCHLD, NULL, &oact); /* never fails */ if (oact.sa_handler == SIG_IGN) { @@ -97,13 +88,13 @@ unsigned int sleep (unsigned int seconds) saved_errno = errno; /* Restore the original signal mask. */ - (void) sigprocmask (SIG_SETMASK, &oset, (sigset_t *) NULL); + sigprocmask (SIG_SETMASK, &oset, NULL); __set_errno (saved_errno); } else { /* We should unblock SIGCHLD. Restore the original signal mask. */ - (void) sigprocmask (SIG_SETMASK, &oset, (sigset_t *) NULL); + sigprocmask (SIG_SETMASK, &oset, NULL); result = nanosleep (&ts, &ts); } } @@ -136,29 +127,27 @@ unsigned int sleep (unsigned int seconds) return 0; /* block SIGALRM */ - if (__sigemptyset (&set) < 0 - || __sigaddset (&set, SIGALRM) < 0 - || sigprocmask (SIG_BLOCK, &set, &oset)) - return seconds; + __sigemptyset (&set); + __sigaddset (&set, SIGALRM); + sigprocmask (SIG_BLOCK, &set, &oset); /* can't fail */ act.sa_handler = sleep_alarm_handler; act.sa_flags = 0; act.sa_mask = oset; - if (sigaction(SIGALRM, &act, &oact) < 0) - return seconds; + sigaction(SIGALRM, &act, &oact); /* never fails */ before = time(NULL); remaining = alarm(seconds); if (remaining && remaining > seconds) { /* restore user's alarm */ - (void) sigaction(SIGALRM, &oact, (struct sigaction *) NULL); + sigaction(SIGALRM, &oact, NULL); alarm(remaining); /* restore old alarm */ sigsuspend(&oset); after = time(NULL); } else { sigsuspend (&oset); after = time(NULL); - (void) sigaction (SIGALRM, &oact, NULL); + sigaction (SIGALRM, &oact, NULL); } result = after - before; alarm(remaining > result ? remaining - result : 0); diff --git a/libcrypt/des.c b/libcrypt/des.c index eb1e13fec..6af65b615 100644 --- a/libcrypt/des.c +++ b/libcrypt/des.c @@ -454,33 +454,26 @@ des_setkey(const char *key) static int do_des( u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, int count) { - /* - * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. - */ + /* l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. */ u_int32_t l, r, *kl, *kr, *kl1, *kr1; u_int32_t f, r48l, r48r; int round; if (count == 0) { - return(1); - } else if (count > 0) { - /* - * Encrypting - */ + return 1; + } + if (count > 0) { + /* Encrypting */ kl1 = en_keysl; kr1 = en_keysr; } else { - /* - * Decrypting - */ + /* Decrypting */ count = -count; kl1 = de_keysl; kr1 = de_keysr; } - /* - * Do initial permutation (IP). - */ + /* Do initial permutation (IP). */ l = ip_maskl[0][l_in >> 24] | ip_maskl[1][(l_in >> 16) & 0xff] | ip_maskl[2][(l_in >> 8) & 0xff] @@ -499,22 +492,17 @@ do_des( u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, int | ip_maskr[7][r_in & 0xff]; while (count--) { - /* - * Do each round. - */ + /* Do each round. */ kl = kl1; kr = kr1; round = 16; - while (round--) { - /* - * Expand R to 48 bits (simulate the E-box). - */ + do { + /* Expand R to 48 bits (simulate the E-box). */ r48l = ((r & 0x00000001) << 23) | ((r & 0xf8000000) >> 9) | ((r & 0x1f800000) >> 11) | ((r & 0x01f80000) >> 13) | ((r & 0x001f8000) >> 15); - r48r = ((r & 0x0001f800) << 7) | ((r & 0x00001f80) << 5) | ((r & 0x000001f8) << 3) @@ -535,19 +523,15 @@ do_des( u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, int | psbox[1][m_sbox[1][r48l & 0xfff]] | psbox[2][m_sbox[2][r48r >> 12]] | psbox[3][m_sbox[3][r48r & 0xfff]]; - /* - * Now that we've permuted things, complete f(). - */ + /* Now that we've permuted things, complete f(). */ f ^= l; l = r; r = f; - } + } while (--round); r = l; l = f; } - /* - * Do final permutation (inverse of IP). - */ + /* Do final permutation (inverse of IP). */ *l_out = fp_maskl[0][l >> 24] | fp_maskl[1][(l >> 16) & 0xff] | fp_maskl[2][(l >> 8) & 0xff] diff --git a/libpthread/linuxthreads.old/manager.c b/libpthread/linuxthreads.old/manager.c index ef9046de1..2be474c53 100644 --- a/libpthread/linuxthreads.old/manager.c +++ b/libpthread/linuxthreads.old/manager.c @@ -137,7 +137,7 @@ int attribute_noreturn __pthread_manager(void *arg) #endif /* __UCLIBC_HAS_XLOCALE__ */ /* Block all signals except __pthread_sig_cancel and SIGTRAP */ - sigfillset(&manager_mask); + __sigfillset(&manager_mask); sigdelset(&manager_mask, __pthread_sig_cancel); /* for thread termination */ sigdelset(&manager_mask, SIGTRAP); /* for debugging purposes */ if (__pthread_threads_debug && __pthread_sig_debug > 0) diff --git a/libpthread/linuxthreads.old/pthread.c b/libpthread/linuxthreads.old/pthread.c index e96f3ab6a..562aa433c 100644 --- a/libpthread/linuxthreads.old/pthread.c +++ b/libpthread/linuxthreads.old/pthread.c @@ -471,22 +471,19 @@ static void pthread_initialize(void) /* Setup signal handlers for the initial thread. Since signal handlers are shared between threads, these settings will be inherited by all other threads. */ + memset(&sa, 0, sizeof(sa)); sa.sa_handler = pthread_handle_sigrestart; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; __libc_sigaction(__pthread_sig_restart, &sa, NULL); sa.sa_handler = pthread_handle_sigcancel; sigaddset(&sa.sa_mask, __pthread_sig_restart); - /* sa.sa_flags = 0; */ __libc_sigaction(__pthread_sig_cancel, &sa, NULL); if (__pthread_sig_debug > 0) { sa.sa_handler = pthread_handle_sigdebug; - sigemptyset(&sa.sa_mask); - /* sa.sa_flags = 0; */ + __sigemptyset(&sa.sa_mask); __libc_sigaction(__pthread_sig_debug, &sa, NULL); } /* Initially, block __pthread_sig_restart. Will be unblocked on demand. */ - sigemptyset(&mask); + __sigemptyset(&mask); sigaddset(&mask, __pthread_sig_restart); sigprocmask(SIG_BLOCK, &mask, NULL); /* And unblock __pthread_sig_cancel if it has been blocked. */ @@ -653,8 +650,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, request.req_args.create.attr = attr; request.req_args.create.fn = start_routine; request.req_args.create.arg = arg; - sigprocmask(SIG_SETMASK, (const sigset_t *) NULL, - &request.req_args.create.mask); + sigprocmask(SIG_SETMASK, NULL, &request.req_args.create.mask); PDEBUG("write REQ_CREATE to manager thread\n"); TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request, (char *) &request, sizeof(request))); @@ -928,9 +924,9 @@ void __pthread_kill_other_threads_np(void) /* Reset the signal handlers behaviour for the signals the implementation uses since this would be passed to the new process. */ - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sa.sa_handler = SIG_DFL; + memset(&sa, 0, sizeof(sa)); + if (SIG_DFL) /* if it's constant zero, it's already done */ + sa.sa_handler = SIG_DFL; __libc_sigaction(__pthread_sig_restart, &sa, NULL); __libc_sigaction(__pthread_sig_cancel, &sa, NULL); if (__pthread_sig_debug > 0) @@ -1007,7 +1003,7 @@ __pthread_timedsuspend_old(pthread_descr self, const struct timespec *abstime) THREAD_SETMEM(self, p_signal_jmp, &jmpbuf); THREAD_SETMEM(self, p_signal, 0); /* Unblock the restart signal */ - sigemptyset(&unblock); + __sigemptyset(&unblock); sigaddset(&unblock, __pthread_sig_restart); sigprocmask(SIG_UNBLOCK, &unblock, &initial_mask); @@ -1092,7 +1088,7 @@ int __pthread_timedsuspend_new(pthread_descr self, const struct timespec *abstim THREAD_SETMEM(self, p_signal_jmp, &jmpbuf); THREAD_SETMEM(self, p_signal, 0); /* Unblock the restart signal */ - sigemptyset(&unblock); + __sigemptyset(&unblock); sigaddset(&unblock, __pthread_sig_restart); sigprocmask(SIG_UNBLOCK, &unblock, &initial_mask); diff --git a/libpthread/linuxthreads.old/signals.c b/libpthread/linuxthreads.old/signals.c index 23ba9778f..2a451f3d2 100644 --- a/libpthread/linuxthreads.old/signals.c +++ b/libpthread/linuxthreads.old/signals.c @@ -196,7 +196,7 @@ int sigwait(const sigset_t * set, int * sig) and if not, install our dummy handler. This is conformant to POSIX: "The effect of sigwait() on the signal actions for the signals in set is unspecified." */ - sigfillset(&mask); + __sigfillset(&mask); sigdelset(&mask, __pthread_sig_cancel); for (s = 1; s <= NSIG; s++) { if (sigismember(set, s) && @@ -207,9 +207,8 @@ int sigwait(const sigset_t * set, int * sig) if (sighandler[s].old == NULL || sighandler[s].old == (arch_sighandler_t) SIG_DFL || sighandler[s].old == (arch_sighandler_t) SIG_IGN) { + memset(&sa, 0, sizeof(sa)); sa.sa_handler = pthread_null_sighandler; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; sigaction(s, &sa, NULL); } } diff --git a/libpthread/linuxthreads/manager.c b/libpthread/linuxthreads/manager.c index b0a2a3712..be1e8d2be 100644 --- a/libpthread/linuxthreads/manager.c +++ b/libpthread/linuxthreads/manager.c @@ -132,7 +132,7 @@ __pthread_manager(void *arg) self->p_h_errnop = &self->p_h_errno; #endif /* Block all signals except __pthread_sig_cancel and SIGTRAP */ - sigfillset(&manager_mask); + __sigfillset(&manager_mask); sigdelset(&manager_mask, __pthread_sig_cancel); /* for thread termination */ sigdelset(&manager_mask, SIGTRAP); /* for debugging purposes */ if (__pthread_threads_debug && __pthread_sig_debug > 0) diff --git a/libpthread/linuxthreads/pthread.c b/libpthread/linuxthreads/pthread.c index 36961a1c9..2d0f49ee9 100644 --- a/libpthread/linuxthreads/pthread.c +++ b/libpthread/linuxthreads/pthread.c @@ -561,22 +561,19 @@ static void pthread_initialize(void) /* Setup signal handlers for the initial thread. Since signal handlers are shared between threads, these settings will be inherited by all other threads. */ + memset(&sa, 0, sizeof(sa)); sa.sa_handler = pthread_handle_sigrestart; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; __libc_sigaction(__pthread_sig_restart, &sa, NULL); sa.sa_handler = pthread_handle_sigcancel; sigaddset(&sa.sa_mask, __pthread_sig_restart); - /* sa.sa_flags = 0; */ __libc_sigaction(__pthread_sig_cancel, &sa, NULL); if (__pthread_sig_debug > 0) { sa.sa_handler = pthread_handle_sigdebug; - sigemptyset(&sa.sa_mask); - /* sa.sa_flags = 0; */ + __sigemptyset(&sa.sa_mask); __libc_sigaction(__pthread_sig_debug, &sa, NULL); } /* Initially, block __pthread_sig_restart. Will be unblocked on demand. */ - sigemptyset(&mask); + __sigemptyset(&mask); sigaddset(&mask, __pthread_sig_restart); sigprocmask(SIG_BLOCK, &mask, NULL); /* And unblock __pthread_sig_cancel if it has been blocked. */ @@ -834,8 +831,7 @@ int __pthread_create(pthread_t *thread, const pthread_attr_t *attr, request.req_args.create.attr = attr; request.req_args.create.fn = start_routine; request.req_args.create.arg = arg; - sigprocmask(SIG_SETMASK, (const sigset_t *) NULL, - &request.req_args.create.mask); + sigprocmask(SIG_SETMASK, NULL, &request.req_args.create.mask); TEMP_FAILURE_RETRY(write_not_cancel(__pthread_manager_request, (char *) &request, sizeof(request))); suspend(self); @@ -1151,9 +1147,9 @@ void __pthread_kill_other_threads_np(void) /* Reset the signal handlers behaviour for the signals the implementation uses since this would be passed to the new process. */ - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sa.sa_handler = SIG_DFL; + memset(&sa, 0, sizeof(sa)); + if (SIG_DFL) /* if it's constant zero, it's already done */ + sa.sa_handler = SIG_DFL; __libc_sigaction(__pthread_sig_restart, &sa, NULL); __libc_sigaction(__pthread_sig_cancel, &sa, NULL); if (__pthread_sig_debug > 0) @@ -1230,7 +1226,7 @@ __pthread_timedsuspend_old(pthread_descr self, const struct timespec *abstime) THREAD_SETMEM(self, p_signal_jmp, &jmpbuf); THREAD_SETMEM(self, p_signal, 0); /* Unblock the restart signal */ - sigemptyset(&unblock); + __sigemptyset(&unblock); sigaddset(&unblock, __pthread_sig_restart); sigprocmask(SIG_UNBLOCK, &unblock, &initial_mask); @@ -1317,7 +1313,7 @@ __pthread_timedsuspend_new(pthread_descr self, const struct timespec *abstime) THREAD_SETMEM(self, p_signal_jmp, &jmpbuf); THREAD_SETMEM(self, p_signal, 0); /* Unblock the restart signal */ - sigemptyset(&unblock); + __sigemptyset(&unblock); sigaddset(&unblock, __pthread_sig_restart); sigprocmask(SIG_UNBLOCK, &unblock, &initial_mask); diff --git a/libpthread/linuxthreads/signals.c b/libpthread/linuxthreads/signals.c index 62e83211a..02bf1c64b 100644 --- a/libpthread/linuxthreads/signals.c +++ b/libpthread/linuxthreads/signals.c @@ -153,7 +153,7 @@ int __pthread_sigwait(const sigset_t * set, int * sig) and if not, install our dummy handler. This is conformant to POSIX: "The effect of sigwait() on the signal actions for the signals in set is unspecified." */ - sigfillset(&mask); + __sigfillset(&mask); sigdelset(&mask, __pthread_sig_cancel); for (s = 1; s < NSIG; s++) { if (sigismember(set, s) && @@ -165,7 +165,7 @@ int __pthread_sigwait(const sigset_t * set, int * sig) __sighandler[s].old == (arch_sighandler_t) SIG_DFL || __sighandler[s].old == (arch_sighandler_t) SIG_IGN) { sa.sa_handler = __pthread_null_sighandler; - sigfillset(&sa.sa_mask); + __sigfillset(&sa.sa_mask); sa.sa_flags = 0; sigaction(s, &sa, NULL); } diff --git a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mq_notify.c b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mq_notify.c index 6cd0f09c1..31d614b40 100644 --- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mq_notify.c +++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mq_notify.c @@ -76,7 +76,7 @@ __attribute__ ((noinline)) change_sigmask (int how, sigset_t *oss) { sigset_t ss; - sigfillset (&ss); + __sigfillset (&ss); return pthread_sigmask (how, &ss, oss); } |