From 460378bf1371987e2ecc1bede7553a36d0220102 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 29 Apr 2012 11:04:31 +0000 Subject: [PATCH] Add a convenience macro for the returns_twice attribute, and apply it to the prototypes of the appropriate functions (getcontext, savectx, setjmp, sigsetjmp and vfork). MFC after: 2 weeks --- include/setjmp.h | 6 +++--- include/unistd.h | 2 +- sys/amd64/include/pcb.h | 2 +- sys/arm/include/pcb.h | 2 +- sys/i386/include/pcb.h | 2 +- sys/ia64/include/pcb.h | 4 ++-- sys/mips/include/pcb.h | 2 +- sys/powerpc/include/cpu.h | 2 +- sys/sparc64/include/pcb.h | 2 +- sys/sys/cdefs.h | 6 ++++++ sys/sys/systm.h | 2 +- sys/sys/ucontext.h | 2 +- 12 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/setjmp.h b/include/setjmp.h index 49d4ed5e8cef..bf03f6fbb43a 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -46,16 +46,16 @@ __BEGIN_DECLS #if __BSD_VISIBLE || __XSI_VISIBLE >= 600 void _longjmp(jmp_buf, int) __dead2; -int _setjmp(jmp_buf); +int _setjmp(jmp_buf) __returns_twice; #endif void longjmp(jmp_buf, int) __dead2; #if __BSD_VISIBLE void longjmperror(void); #endif -int setjmp(jmp_buf); +int setjmp(jmp_buf) __returns_twice; #if __BSD_VISIBLE || __POSIX_VISIBLE || __XSI_VISIBLE void siglongjmp(sigjmp_buf, int) __dead2; -int sigsetjmp(sigjmp_buf, int); +int sigsetjmp(sigjmp_buf, int) __returns_twice; #endif __END_DECLS diff --git a/include/unistd.h b/include/unistd.h index 90694ede7314..9b2f2ecb997c 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -479,7 +479,7 @@ char *getwd(char *); /* obsoleted by getcwd() */ useconds_t ualarm(useconds_t, useconds_t); int usleep(useconds_t); -pid_t vfork(void); +pid_t vfork(void) __returns_twice; #endif #if __BSD_VISIBLE diff --git a/sys/amd64/include/pcb.h b/sys/amd64/include/pcb.h index 61f651bb6247..70b2e6213396 100644 --- a/sys/amd64/include/pcb.h +++ b/sys/amd64/include/pcb.h @@ -130,7 +130,7 @@ clear_pcb_flags(struct pcb *pcb, const u_int flags) } void makectx(struct trapframe *, struct pcb *); -int savectx(struct pcb *); +int savectx(struct pcb *) __returns_twice; #endif diff --git a/sys/arm/include/pcb.h b/sys/arm/include/pcb.h index 4a5f330b8a53..ce9ab97e6bcf 100644 --- a/sys/arm/include/pcb.h +++ b/sys/arm/include/pcb.h @@ -94,7 +94,7 @@ void makectx(struct trapframe *tf, struct pcb *pcb); #ifdef _KERNEL -void savectx(struct pcb *); +void savectx(struct pcb *) __returns_twice; #endif /* _KERNEL */ #endif /* !_MACHINE_PCB_H_ */ diff --git a/sys/i386/include/pcb.h b/sys/i386/include/pcb.h index 1311ab1ed21e..4c227df06767 100644 --- a/sys/i386/include/pcb.h +++ b/sys/i386/include/pcb.h @@ -84,7 +84,7 @@ struct pcb { struct trapframe; void makectx(struct trapframe *, struct pcb *); -void savectx(struct pcb *); +void savectx(struct pcb *) __returns_twice; #endif #endif /* _I386_PCB_H_ */ diff --git a/sys/ia64/include/pcb.h b/sys/ia64/include/pcb.h index 59334bfa5d82..dac7169b3f42 100644 --- a/sys/ia64/include/pcb.h +++ b/sys/ia64/include/pcb.h @@ -65,10 +65,10 @@ struct trapframe; void makectx(struct trapframe *, struct pcb *); void restorectx(struct pcb *) __dead2; -int swapctx(struct pcb *old, struct pcb *new); +int swapctx(struct pcb *old, struct pcb *new) __returns_twice; void ia32_restorectx(struct pcb *); -void ia32_savectx(struct pcb *); +void ia32_savectx(struct pcb *) __returns_twice; #endif diff --git a/sys/mips/include/pcb.h b/sys/mips/include/pcb.h index 99113396277e..52589f54d402 100644 --- a/sys/mips/include/pcb.h +++ b/sys/mips/include/pcb.h @@ -78,7 +78,7 @@ struct pcb extern struct pcb *curpcb; /* the current running pcb */ void makectx(struct trapframe *, struct pcb *); -int savectx(struct pcb *); +int savectx(struct pcb *) __returns_twice; #endif #endif /* !_MACHINE_PCB_H_ */ diff --git a/sys/powerpc/include/cpu.h b/sys/powerpc/include/cpu.h index 73b1f5008573..66d21eb79ac2 100644 --- a/sys/powerpc/include/cpu.h +++ b/sys/powerpc/include/cpu.h @@ -99,6 +99,6 @@ void fork_trampoline(void); void swi_vm(void *); /* XXX the following should not be here. */ -void savectx(struct pcb *); +void savectx(struct pcb *) __returns_twice; #endif /* _MACHINE_CPU_H_ */ diff --git a/sys/sparc64/include/pcb.h b/sys/sparc64/include/pcb.h index f23c1f291c2f..25a41cccb115 100644 --- a/sys/sparc64/include/pcb.h +++ b/sys/sparc64/include/pcb.h @@ -55,7 +55,7 @@ struct pcb { #ifdef _KERNEL void makectx(struct trapframe *tf, struct pcb *pcb); -int savectx(struct pcb *pcb); +int savectx(struct pcb *pcb) __returns_twice; #endif #endif /* !LOCORE */ diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index 076842d8ebe2..80f7b8e2c683 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -293,6 +293,12 @@ #define __nonnull(x) #endif +#if __GNUC_PREREQ__(4, 1) +#define __returns_twice __attribute__((__returns_twice__)) +#else +#define __returns_twice +#endif + /* XXX: should use `#if __STDC_VERSION__ < 199901'. */ #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) #define __func__ NULL diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 5375ec4f8993..fec77d256d36 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -153,7 +153,7 @@ struct uio; struct _jmp_buf; struct trapframe; -int setjmp(struct _jmp_buf *); +int setjmp(struct _jmp_buf *) __returns_twice; void longjmp(struct _jmp_buf *, int) __dead2; int dumpstatus(vm_offset_t addr, off_t count); int nullop(void); diff --git a/sys/sys/ucontext.h b/sys/sys/ucontext.h index 609cdd38ccf4..1e504c9e4df9 100644 --- a/sys/sys/ucontext.h +++ b/sys/sys/ucontext.h @@ -71,7 +71,7 @@ struct ucontext4 { __BEGIN_DECLS -int getcontext(ucontext_t *); +int getcontext(ucontext_t *) __returns_twice; ucontext_t *getcontextx(void); int setcontext(const ucontext_t *); void makecontext(ucontext_t *, void (*)(void), int, ...);