|
Message-ID: <20120906191724.0be123b0@gmail.com> Date: Thu, 6 Sep 2012 19:17:24 +0200 From: philomath <philomath868@...il.com> To: musl@...ts.openwall.com Subject: [PATCH] Add _Noreturn specifier to other nonreturning functions As discussed. Note that this patch modifies my previous patch in setjmp.h, due to my shortsightedness. --- arch/arm/atomic.h | 3 +++ arch/i386/atomic.h | 3 +++ arch/mips/atomic.h | 3 +++ arch/x86_64/atomic.h | 3 +++ include/assert.h | 9 ++++++++- include/err.h | 15 +++++++++++---- include/pthread.h | 9 ++++++++- include/setjmp.h | 18 ++++++++---------- include/unistd.h | 9 ++++++++- src/exit/assert.c | 2 +- src/linux/err.c | 8 ++++---- src/signal/siglongjmp.c | 2 +- src/thread/pthread_create.c | 3 +++ src/unistd/_exit.c | 2 +- 14 files changed, 65 insertions(+), 24 deletions(-) diff --git a/arch/arm/atomic.h b/arch/arm/atomic.h index f434a0c..34ef6f9 100644 --- a/arch/arm/atomic.h +++ b/arch/arm/atomic.h @@ -78,6 +78,9 @@ static inline void a_spin() { } +#ifdef __GNUC__ +__attribute__((__noreturn__)) +#endif static inline void a_crash() { *(volatile char *)0=0; diff --git a/arch/i386/atomic.h b/arch/i386/atomic.h index 77b0b3b..400e642 100644 --- a/arch/i386/atomic.h +++ b/arch/i386/atomic.h @@ -119,6 +119,9 @@ static inline void a_spin() __asm__ __volatile__( "pause" : : : "memory" ); } +#ifdef __GNUC__ +__attribute__((__noreturn__)) +#endif static inline void a_crash() { __asm__ __volatile__( "hlt" : : : "memory" ); diff --git a/arch/mips/atomic.h b/arch/mips/atomic.h index f3478ef..99e6772 100644 --- a/arch/mips/atomic.h +++ b/arch/mips/atomic.h @@ -143,6 +143,9 @@ static inline void a_spin() { } +#ifdef __GNUC__ +__attribute__((__noreturn__)) +#endif static inline void a_crash() { *(volatile char *)0=0; diff --git a/arch/x86_64/atomic.h b/arch/x86_64/atomic.h index 0d3da6f..4aef1e7 100644 --- a/arch/x86_64/atomic.h +++ b/arch/x86_64/atomic.h @@ -118,6 +118,9 @@ static inline void a_spin() __asm__ __volatile__( "pause" : : : "memory" ); } +#ifdef __GNUC__ +__attribute__((__noreturn__)) +#endif static inline void a_crash() { __asm__ __volatile__( "hlt" : : : "memory" ); diff --git a/include/assert.h b/include/assert.h index bad2ccd..ad0a811 100644 --- a/include/assert.h +++ b/include/assert.h @@ -10,7 +10,14 @@ extern "C" { #endif -void __assert_fail (const char *, const char *, int, const char *); +#if __STDC_VERSION__ >= 201112L +#elif defined(__GNUC__) +#define _Noreturn __attribute__((__noreturn__)) +#else +#define _Noreturn +#endif + +_Noreturn void __assert_fail (const char *, const char *, int, const char *); #ifdef __cplusplus } diff --git a/include/err.h b/include/err.h index 5e33f9e..84494cf 100644 --- a/include/err.h +++ b/include/err.h @@ -12,10 +12,17 @@ void vwarn(const char *, va_list); void warnx(const char *, ...); void vwarnx(const char *, va_list); -void err(int, const char *, ...); -void verr(int, const char *, va_list); -void errx(int, const char *, ...); -void verrx(int, const char *, va_list); +#if __STDC_VERSION__ >= 201112L +#elif defined(__GNUC__) +#define _Noreturn __attribute__((__noreturn__)) +#else +#define _Noreturn +#endif + +_Noreturn void err(int, const char *, ...); +_Noreturn void verr(int, const char *, va_list); +_Noreturn void errx(int, const char *, ...); +_Noreturn void verrx(int, const char *, va_list); #ifdef __cplusplus } diff --git a/include/pthread.h b/include/pthread.h index d4ffb9a..1dfc85e 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -71,9 +71,16 @@ extern "C" { #define PTHREAD_BARRIER_SERIAL_THREAD (-1) +#if __STDC_VERSION__ >= 201112L +#elif defined(__GNUC__) +#define _Noreturn __attribute__((__noreturn__)) +#else +#define _Noreturn +#endif + int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *); int pthread_detach(pthread_t); -void pthread_exit(void *); +_Noreturn void pthread_exit(void *); int pthread_join(pthread_t, void **); #ifdef __GNUC__ diff --git a/include/setjmp.h b/include/setjmp.h index 321d859..cc06994 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -7,6 +7,12 @@ extern "C" { #include <bits/setjmp.h> +#if __STDC_VERSION__ >= 201112L +#elif defined(__GNUC__) +#define _Noreturn __attribute__((__noreturn__)) +#else +#define _Noreturn +#endif #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ @@ -17,22 +23,14 @@ typedef struct { unsigned long __ss[128/sizeof(long)]; } sigjmp_buf[1]; int sigsetjmp (sigjmp_buf, int); -void siglongjmp (sigjmp_buf, int); +_Noreturn void siglongjmp (sigjmp_buf, int); #endif #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ || defined(_BSD_SOURCE) int _setjmp (jmp_buf); -void _longjmp (jmp_buf, int); -#endif - - -#if __STDC_VERSION__ >= 201112L -#elif defined(__GNUC__) -#define _Noreturn __attribute__((__noreturn__)) -#else -#define _Noreturn +_Noreturn void _longjmp (jmp_buf, int); #endif int setjmp (jmp_buf); diff --git a/include/unistd.h b/include/unistd.h index 12d153b..a4410dc 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -76,6 +76,13 @@ unsigned alarm(unsigned); unsigned sleep(unsigned); int pause(void); +#if __STDC_VERSION__ >= 201112L +#elif defined(__GNUC__) +#define _Noreturn __attribute__((__noreturn__)) +#else +#define _Noreturn +#endif + pid_t fork(void); int execve(const char *, char *const [], char *const []); int execv(const char *, char *const []); @@ -84,7 +91,7 @@ int execl(const char *, const char *, ...); int execvp(const char *, char *const []); int execlp(const char *, const char *, ...); int fexecve(int, char *const [], char *const []); -void _exit(int); +_Noreturn void _exit(int); pid_t getpid(void); pid_t getppid(void); diff --git a/src/exit/assert.c b/src/exit/assert.c index e87442a..49b0dc3 100644 --- a/src/exit/assert.c +++ b/src/exit/assert.c @@ -1,7 +1,7 @@ #include <stdio.h> #include <stdlib.h> -void __assert_fail(const char *expr, const char *file, int line, const char *func) +_Noreturn void __assert_fail(const char *expr, const char *file, int line, const char *func) { fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line); fflush(NULL); diff --git a/src/linux/err.c b/src/linux/err.c index c291136..0f74853 100644 --- a/src/linux/err.c +++ b/src/linux/err.c @@ -15,13 +15,13 @@ void vwarnx(const char *fmt, va_list ap) putc('\n', stderr); } -void verr(int status, const char *fmt, va_list ap) +_Noreturn void verr(int status, const char *fmt, va_list ap) { vwarn(fmt, ap); exit(status); } -void verrx(int status, const char *fmt, va_list ap) +_Noreturn void verrx(int status, const char *fmt, va_list ap) { vwarnx(fmt, ap); exit(status); @@ -43,7 +43,7 @@ void warnx(const char *fmt, ...) va_end(ap); } -void err(int status, const char *fmt, ...) +_Noreturn void err(int status, const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -51,7 +51,7 @@ void err(int status, const char *fmt, ...) va_end(ap); } -void errx(int status, const char *fmt, ...) +_Noreturn void errx(int status, const char *fmt, ...) { va_list ap; va_start(ap, fmt); diff --git a/src/signal/siglongjmp.c b/src/signal/siglongjmp.c index e9a6131..d0e4f67 100644 --- a/src/signal/siglongjmp.c +++ b/src/signal/siglongjmp.c @@ -3,7 +3,7 @@ #include <stdlib.h> #include "syscall.h" -void siglongjmp(sigjmp_buf buf, int ret) +_Noreturn void siglongjmp(sigjmp_buf buf, int ret) { if (buf->__fl) __syscall(SYS_rt_sigprocmask, SIG_SETMASK, buf->__ss, 0, __SYSCALL_SSLEN); diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 52b48d6..cced182 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -8,6 +8,9 @@ weak_alias(dummy_0, __synccall_lock); weak_alias(dummy_0, __synccall_unlock); weak_alias(dummy_0, __pthread_tsd_run_dtors); +#ifdef __GNUC__ +__attribute__((__noreturn__)) +#endif void pthread_exit(void *result) { pthread_t self = pthread_self(); diff --git a/src/unistd/_exit.c b/src/unistd/_exit.c index d2e84c4..7699482 100644 --- a/src/unistd/_exit.c +++ b/src/unistd/_exit.c @@ -1,7 +1,7 @@ #include <unistd.h> #include <stdlib.h> -void _exit(int status) +_Noreturn void _exit(int status) { _Exit(status); } -- 1.7.12
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.