]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
compiler: add __returns_twice attribute 2975/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 4 May 2019 11:35:51 +0000 (13:35 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 4 May 2019 11:35:51 +0000 (13:35 +0200)
The returns_twice attribute tells the compiler that a function may return more
than one time. The compiler will ensure that all registers are dead before
calling such a function and will emit a warning about the variables that may be
clobbered after the second return from the function. Examples of such functions
are setjmp and vfork. The longjmp-like counterpart of such function, if any,
might need to be marked with the noreturn attribute.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/compiler.h
src/lxc/raw_syscalls.c

index 65457cb31b6633c96b2088d3063bf9af3882a1ed..9b0de394a576ab38f884329ac4a38ebcb382b2ad 100644 (file)
 #      define __hot __attribute__((hot))
 #endif
 
+#ifndef __returns_twice
+#define __returns_twice __attribute__((returns_twice))
+#endif
+
 #define __cgfsng_ops
 
 #endif /* __LXC_COMPILER_H */
index a4db3069196c193397cd0ed2d46b5526190426c5..2e15575870727697aeccd7aaff91b1402efa6407 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/syscall.h>
 #include <unistd.h>
 
+#include "compiler.h"
 #include "config.h"
 #include "macro.h"
 #include "raw_syscalls.h"
@@ -32,7 +33,7 @@ int lxc_raw_execveat(int dirfd, const char *pathname, char *const argv[],
  * The nice thing about this is that we get fork() behavior. That is
  * lxc_raw_clone() returns 0 in the child and the child pid in the parent.
  */
-pid_t lxc_raw_clone(unsigned long flags)
+__returns_twice pid_t lxc_raw_clone(unsigned long flags)
 {
        /*
         * These flags don't interest at all so we don't jump through any hoops