[lxc-devel] [lxc/master] compiler: add __returns_twice attribute

brauner on Github lxc-bot at linuxcontainers.org
Sat May 4 11:39:32 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 816 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190504/8de326da/attachment.bin>
-------------- next part --------------
From 633cb8bee31b0ce075adbe8a143f88f533605552 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 4 May 2019 13:35:51 +0200
Subject: [PATCH] compiler: add __returns_twice attribute

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 at ubuntu.com>
---
 src/lxc/compiler.h     | 4 ++++
 src/lxc/raw_syscalls.c | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/lxc/compiler.h b/src/lxc/compiler.h
index 65457cb31b..9b0de394a5 100644
--- a/src/lxc/compiler.h
+++ b/src/lxc/compiler.h
@@ -59,6 +59,10 @@
 #	define __hot __attribute__((hot))
 #endif
 
+#ifndef __returns_twice
+#define __returns_twice __attribute__((returns_twice))
+#endif
+
 #define __cgfsng_ops
 
 #endif /* __LXC_COMPILER_H */
diff --git a/src/lxc/raw_syscalls.c b/src/lxc/raw_syscalls.c
index a4db306919..2e15575870 100644
--- a/src/lxc/raw_syscalls.c
+++ b/src/lxc/raw_syscalls.c
@@ -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


More information about the lxc-devel mailing list