Procházet zdrojové kódy

[LibOS] Use the C11 standard instead of GNU99

Chia-Che Tsai před 5 roky
rodič
revize
09ad502c3a

+ 18 - 18
LibOS/shim/include/shim_internal.h

@@ -33,7 +33,7 @@
 #define alias_str(name) #name
 
 #define extern_alias(name) \
-    extern __typeof(name) shim_##name __attribute ((alias (alias_str(name))))
+    extern __typeof__(name) shim_##name __attribute ((alias (alias_str(name))))
 
 #define static_always_inline static inline __attribute__((always_inline))
 
@@ -156,7 +156,7 @@ static inline void do_pause (void);
 #if USE_PAUSE == 1
 # define pause() do { do_pause(); } while (0)
 #else
-# define pause() do { asm volatile ("int $3"); } while (0)
+# define pause() do { __asm__ volatile ("int $3"); } while (0)
 #endif
 
 #define bug()                                                               \
@@ -758,28 +758,28 @@ extern const char ** initial_envp;
 
 #define ALIGNED(addr)   (!(((unsigned long) addr) & allocshift))
 #define ALIGN_UP(addr)      \
-    ((typeof(addr)) ((((unsigned long) addr) + allocshift) & allocmask))
+    ((__typeof__(addr)) ((((unsigned long) addr) + allocshift) & allocmask))
 #define ALIGN_DOWN(addr)    \
-    ((typeof(addr)) (((unsigned long) addr) & allocmask))
-
-#define switch_stack(stack_top)                                     \
-    ({                                                              \
-        void * _rsp, * _rbp;                                        \
-        void * _stack = (stack_top);                                \
-        asm volatile ("movq %%rsp, %0" : "=r"(_rsp) :: "memory");   \
-        asm volatile ("movq %%rbp, %0" : "=r"(_rbp) :: "memory");   \
-        _rsp = _stack - (_rbp - _rsp);                              \
-        _rbp = _stack;                                              \
-        asm volatile ("movq %0, %%rsp" :: "r"(_rsp) : "memory");    \
-        asm volatile ("movq %0, %%rbp" :: "r"(_rbp) : "memory");    \
-        asm volatile ("movq %%rbp, %0" : "=r"(_stack) :: "memory"); \
-        _stack;                                                     \
+    ((__typeof__(addr)) (((unsigned long) addr) & allocmask))
+
+#define switch_stack(stack_top)                                         \
+    ({                                                                  \
+        void * _rsp, * _rbp;                                            \
+        void * _stack = (stack_top);                                    \
+        __asm__ volatile ("movq %%rsp, %0" : "=r"(_rsp) :: "memory");   \
+        __asm__ volatile ("movq %%rbp, %0" : "=r"(_rbp) :: "memory");   \
+        _rsp = _stack - (_rbp - _rsp);                                  \
+        _rbp = _stack;                                                  \
+        __asm__ volatile ("movq %0, %%rsp" :: "r"(_rsp) : "memory");    \
+        __asm__ volatile ("movq %0, %%rbp" :: "r"(_rbp) : "memory");    \
+        __asm__ volatile ("movq %%rbp, %0" : "=r"(_stack) :: "memory"); \
+        _stack;                                                         \
     })
 
 static_always_inline void * current_stack(void)
 {
     void * _rsp;
-    asm volatile ("movq %%rsp, %0" : "=r"(_rsp) :: "memory");
+    __asm__ volatile ("movq %%rsp, %0" : "=r"(_rsp) :: "memory");
     return _rsp;
 }
 

+ 6 - 6
LibOS/shim/include/shim_thread.h

@@ -124,16 +124,16 @@ int init_thread (void);
 static inline struct shim_thread * shim_thread_self(void)
 {
     struct shim_thread * __self;
-    asm ("movq %%fs:%c1,%q0" : "=r" (__self)
-         : "i" (offsetof(__libc_tcb_t, shim_tcb.tp)));
+    __asm__ ("movq %%fs:%c1,%q0" : "=r" (__self)
+             : "i" (offsetof(__libc_tcb_t, shim_tcb.tp)));
     return __self;
 }
 
 static inline struct shim_thread * save_shim_thread_self(struct shim_thread * __self)
 {
-     asm ("movq %q0,%%fs:%c1" : : "r" (__self),
-          "i" (offsetof(__libc_tcb_t, shim_tcb.tp)));
-     return __self;
+    __asm__ ("movq %q0,%%fs:%c1" : : "r" (__self),
+             "i" (offsetof(__libc_tcb_t, shim_tcb.tp)));
+    return __self;
 }
 
 static inline bool is_internal(struct shim_thread *thread)
@@ -330,7 +330,7 @@ bool check_stack_size (struct shim_thread * cur_thread, int size)
         cur_thread = get_cur_thread();
 
     void * rsp;
-    asm volatile ("movq %%rsp, %0" : "=r"(rsp) :: "memory");
+    __asm__ volatile ("movq %%rsp, %0" : "=r"(rsp) :: "memory");
 
     if (rsp <= cur_thread->stack_top && rsp > cur_thread->stack)
         return size < rsp - cur_thread->stack;

+ 6 - 6
LibOS/shim/include/shim_tls.h

@@ -94,24 +94,24 @@ typedef struct
 static inline bool shim_tls_check_canary(void)
 {
     uint64_t __canary;
-    asm ("movq %%fs:%c1,%q0" : "=r" (__canary)
-         : "i" (offsetof(__libc_tcb_t, shim_tcb.canary)));
+    __asm__ ("movq %%fs:%c1,%q0" : "=r" (__canary)
+             : "i" (offsetof(__libc_tcb_t, shim_tcb.canary)));
     return __canary == SHIM_TLS_CANARY;
 }
 
 static inline shim_tcb_t * shim_get_tls(void)
 {
     shim_tcb_t *__self;
-    asm ("movq %%fs:%c1,%q0" : "=r" (__self)
-         : "i" (offsetof(__libc_tcb_t, shim_tcb.self)));
+    __asm__ ("movq %%fs:%c1,%q0" : "=r" (__self)
+             : "i" (offsetof(__libc_tcb_t, shim_tcb.self)));
     return __self;
 }
 
 static inline __libc_tcb_t * shim_libc_tcb(void)
 {
     __libc_tcb_t *__self;
-    asm ("movq %%fs:%c1,%q0" : "=r" (__self)
-         : "i" (offsetof(__libc_tcb_t, tcb)));
+    __asm__ ("movq %%fs:%c1,%q0" : "=r" (__self)
+             : "i" (offsetof(__libc_tcb_t, tcb)));
     return __self;
 }
 

+ 5 - 0
LibOS/shim/include/shim_types.h

@@ -37,8 +37,13 @@ typedef unsigned int        __u32;
 typedef unsigned long int   nfds_t;
 typedef unsigned long int   nlink_t;
 
+typedef uint32_t            socklen_t;
+typedef __kernel_uid_t      uid_t;
+typedef __kernel_gid_t      gid_t;
+typedef __kernel_pid_t      pid_t;
 typedef __kernel_caddr_t    caddr_t;
 typedef __kernel_mode_t     mode_t;
+typedef __kernel_off_t      off_t;
 typedef __kernel_loff_t     loff_t;
 typedef __kernel_time_t     time_t;
 typedef __kernel_old_dev_t  dev_t;

+ 1 - 1
LibOS/shim/src/Makefile

@@ -9,7 +9,7 @@ LD	= ld
 
 OMIT_FRAME_POINTER = no
 
-CFLAGS	= -Wall -fPIC -std=gnu99 -fgnu89-inline -Winline -Wwrite-strings \
+CFLAGS	= -Wall -fPIC -std=c11 -Winline -Wwrite-strings \
 	  -fmerge-all-constants -Wstrict-prototypes \
 	  -Werror=implicit-function-declaration \
 	  -fno-stack-protector -fno-builtin -Wno-inline \

+ 6 - 6
LibOS/shim/src/bookkeep/shim_thread.c

@@ -588,12 +588,12 @@ void switch_dummy_thread (struct shim_thread * thread)
 
     /* jump onto old stack
        we actually pop rbp as rsp, and later we will call 'ret' */
-    asm volatile("movq %0, %%rbp\r\n"
-                 "leaveq\r\n"
-                 "retq\r\n" :
-                 : "g"(real_thread->frameptr),
-                   "a"(child)
-                 : "memory");
+    __asm__ volatile("movq %0, %%rbp\r\n"
+                     "leaveq\r\n"
+                     "retq\r\n" :
+                     : "g"(real_thread->frameptr),
+                       "a"(child)
+                     : "memory");
 }
 
 BEGIN_CP_FUNC(thread)

+ 1 - 1
LibOS/shim/src/elf/rel.h

@@ -15,7 +15,7 @@
         ((ElfW(Addr)) (addr) >= (l)->l_map_start && (ElfW(Addr)) (addr) < (l)->l_map_end)
 
 #define RELOCATE(l, addr)   \
-        ((typeof(addr)) (IN_RANGE((l), (addr)) ? (ElfW(Addr)) (addr) :    \
+        ((__typeof__(addr)) (IN_RANGE((l), (addr)) ? (ElfW(Addr)) (addr) :    \
             (ElfW(Addr)) (addr) + (ElfW(Addr)) ((l)->l_addr)))
 
 #ifdef __x86_64__

+ 13 - 14
LibOS/shim/src/elf/shim_rtld.c

@@ -274,12 +274,12 @@ struct link_map * new_elf_object (const char * realname, int type)
 }
 
 #include <endian.h>
-#if BYTE_ORDER == BIG_ENDIAN
+#if __BYTE_ORDER == __BIG_ENDIAN
 # define byteorder ELFDATA2MSB
-#elif BYTE_ORDER == LITTLE_ENDIAN
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
 # define byteorder ELFDATA2LSB
 #else
-# error "Unknown BYTE_ORDER " BYTE_ORDER
+# error "Unknown __BYTE_ORDER " __BYTE_ORDER
 # define byteorder ELFDATANONE
 #endif
 
@@ -880,7 +880,7 @@ static int __check_elf_header (void * fbp, int len)
 
     /* Check whether the ELF header use the right endian */
     if (ehdr->e_ident[EI_DATA] != byteorder) {
-        if (BYTE_ORDER == BIG_ENDIAN) {
+        if (__BYTE_ORDER == __BIG_ENDIAN) {
             errstring = "ELF file data encoding not big-endian";
             goto verify_failed;
         } else {
@@ -1585,16 +1585,15 @@ int execute_elf_object (struct shim_handle * exec,
     __enable_preempt(tcb);
 
 #if defined(__x86_64__)
-    asm volatile (
-                    "pushq $0\r\n"
-                    "popfq\r\n"
-                    "movq %%rbx, %%rsp\r\n"
-                    "jmp *%%rax\r\n"
-                    :
-                    : "a"(entry),
-                      "b"(argcp),
-                      "d"(0)
-                    : "memory", "cc");
+    __asm__ volatile ("pushq $0\r\n"
+                      "popfq\r\n"
+                      "movq %%rbx, %%rsp\r\n"
+                      "jmp *%%rax\r\n"
+                      :
+                      : "a"(entry),
+                        "b"(argcp),
+                        "d"(0)
+                      : "memory", "cc");
 #else
 # error "architecture not supported"
 #endif

+ 19 - 19
LibOS/shim/src/shim_checkpoint.c

@@ -1274,23 +1274,23 @@ void restore_context (struct shim_context * context)
 
     memset(context, 0, sizeof(struct shim_context));
 
-    asm volatile("movq %0, %%rsp\r\n"
-                 "popq %%r15\r\n"
-                 "popq %%r14\r\n"
-                 "popq %%r13\r\n"
-                 "popq %%r12\r\n"
-                 "popq %%r11\r\n"
-                 "popq %%r10\r\n"
-                 "popq %%r9\r\n"
-                 "popq %%r8\r\n"
-                 "popq %%rcx\r\n"
-                 "popq %%rdx\r\n"
-                 "popq %%rsi\r\n"
-                 "popq %%rdi\r\n"
-                 "popq %%rbx\r\n"
-                 "popq %%rbp\r\n"
-                 "popq %%rsp\r\n"
-                 "movq $0, %%rax\r\n"
-                 "jmp *-128-8(%%rsp)\r\n"
-                 :: "g"(&regs) : "memory");
+    __asm__ volatile("movq %0, %%rsp\r\n"
+                     "popq %%r15\r\n"
+                     "popq %%r14\r\n"
+                     "popq %%r13\r\n"
+                     "popq %%r12\r\n"
+                     "popq %%r11\r\n"
+                     "popq %%r10\r\n"
+                     "popq %%r9\r\n"
+                     "popq %%r8\r\n"
+                     "popq %%rcx\r\n"
+                     "popq %%rdx\r\n"
+                     "popq %%rsi\r\n"
+                     "popq %%rdi\r\n"
+                     "popq %%rbx\r\n"
+                     "popq %%rbp\r\n"
+                     "popq %%rsp\r\n"
+                     "movq $0, %%rax\r\n"
+                     "jmp *-128-8(%%rsp)\r\n"
+                     :: "g"(&regs) : "memory");
 }

+ 1 - 1
LibOS/shim/src/shim_init.c

@@ -1055,7 +1055,7 @@ void check_stack_hook (void)
     struct shim_thread * cur_thread = get_cur_thread();
 
     void * rsp;
-    asm volatile ("movq %%rsp, %0" : "=r"(rsp) :: "memory");
+    __asm__ volatile ("movq %%rsp, %0" : "=r"(rsp) :: "memory");
 
     if (rsp <= cur_thread->stack_top && rsp > cur_thread->stack) {
         if (rsp - cur_thread->stack < PAL_CB(pagesize))

+ 2 - 2
LibOS/shim/src/sys/shim_vfork.c

@@ -58,8 +58,8 @@ int shim_do_vfork (void)
     struct shim_thread * new_thread = get_new_thread(0);
     /* put the new thread in a new process (thread group) */
 
-    asm volatile ("movq %%rbp, %0\r\n"
-                  : "=r"(new_thread->frameptr));
+    __asm__ volatile ("movq %%rbp, %0\r\n"
+                      : "=r"(new_thread->frameptr));
 
     size_t stack_size = 4096;