Home | History | Annotate | Download | only in system_headers
      1 // Copyright 2015 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef SANDBOX_LINUX_SYSTEM_HEADERS_LINUX_SIGNAL_H_
      6 #define SANDBOX_LINUX_SYSTEM_HEADERS_LINUX_SIGNAL_H_
      7 
      8 #include <stdint.h>
      9 
     10 // NOTE: On some toolchains, signal related ABI is incompatible with Linux's
     11 // (not undefined, but defined different values and in different memory
     12 // layouts). So, fill the gap here.
     13 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || \
     14     defined(__aarch64__)
     15 
     16 #define LINUX_SIGHUP 1
     17 #define LINUX_SIGINT 2
     18 #define LINUX_SIGQUIT 3
     19 #define LINUX_SIGABRT 6
     20 #define LINUX_SIGBUS 7
     21 #define LINUX_SIGUSR1 10
     22 #define LINUX_SIGSEGV 11
     23 #define LINUX_SIGUSR2 12
     24 #define LINUX_SIGPIPE 13
     25 #define LINUX_SIGTERM 15
     26 #define LINUX_SIGCHLD 17
     27 #define LINUX_SIGSYS 31
     28 
     29 #define LINUX_SIG_BLOCK 0
     30 #define LINUX_SIG_UNBLOCK 1
     31 
     32 #define LINUX_SA_SIGINFO 4
     33 #define LINUX_SA_NODEFER 0x40000000
     34 #define LINUX_SA_RESTART 0x10000000
     35 
     36 #define LINUX_SIG_DFL 0
     37 
     38 #elif defined(__mips__)
     39 
     40 #define LINUX_SIGHUP 1
     41 #define LINUX_SIGINT 2
     42 #define LINUX_SIGQUIT 3
     43 #define LINUX_SIGABRT 6
     44 #define LINUX_SIGBUS 10
     45 #define LINUX_SIGSEGV 11
     46 #define LINUX_SIGSYS 12
     47 #define LINUX_SIGPIPE 13
     48 #define LINUX_SIGTERM 15
     49 #define LINUX_SIGUSR1 16
     50 #define LINUX_SIGUSR2 17
     51 #define LINUX_SIGCHLD 18
     52 
     53 #define LINUX_SIG_BLOCK 1
     54 #define LINUX_SIG_UNBLOCK 2
     55 
     56 #define LINUX_SA_SIGINFO 0x00000008
     57 #define LINUX_SA_NODEFER 0x40000000
     58 #define LINUX_SA_RESTART 0x10000000
     59 
     60 #define LINUX_SIG_DFL 0
     61 
     62 #else
     63 #error "Unsupported platform"
     64 #endif
     65 
     66 #if defined(__native_client_nonsfi__)
     67 #if !defined(__i386__) && !defined(__arm__)
     68 #error "Unsupported platform"
     69 #endif
     70 
     71 #include <signal.h>
     72 
     73 struct LinuxSigInfo {
     74   int si_signo;
     75   int si_errno;
     76   int si_code;
     77 
     78   // Extra data is followed by the |si_code|. The length depends on the
     79   // signal number.
     80   char _sifields[1];
     81 };
     82 
     83 #include "sandbox/linux/system_headers/linux_ucontext.h"
     84 
     85 #else  // !defined(__native_client_nonsfi__)
     86 
     87 #include <signal.h>
     88 
     89 static_assert(LINUX_SIGHUP == SIGHUP, "LINUX_SIGHUP == SIGHUP");
     90 static_assert(LINUX_SIGINT == SIGINT, "LINUX_SIGINT == SIGINT");
     91 static_assert(LINUX_SIGQUIT == SIGQUIT, "LINUX_SIGQUIT == SIGQUIT");
     92 static_assert(LINUX_SIGABRT == SIGABRT, "LINUX_SIGABRT == SIGABRT");
     93 static_assert(LINUX_SIGBUS == SIGBUS, "LINUX_SIGBUS == SIGBUS");
     94 static_assert(LINUX_SIGUSR1 == SIGUSR1, "LINUX_SIGUSR1 == SIGUSR1");
     95 static_assert(LINUX_SIGSEGV == SIGSEGV, "LINUX_SIGSEGV == SIGSEGV");
     96 static_assert(LINUX_SIGUSR2 == SIGUSR2, "LINUX_SIGUSR2 == SIGUSR2");
     97 static_assert(LINUX_SIGPIPE == SIGPIPE, "LINUX_SIGPIPE == SIGPIPE");
     98 static_assert(LINUX_SIGTERM == SIGTERM, "LINUX_SIGTERM == SIGTERM");
     99 static_assert(LINUX_SIGCHLD == SIGCHLD, "LINUX_SIGCHLD == SIGCHLD");
    100 static_assert(LINUX_SIGSYS == SIGSYS, "LINUX_SIGSYS == SIGSYS");
    101 static_assert(LINUX_SIG_BLOCK == SIG_BLOCK, "LINUX_SIG_BLOCK == SIG_BLOCK");
    102 static_assert(LINUX_SIG_UNBLOCK == SIG_UNBLOCK,
    103               "LINUX_SIG_UNBLOCK == SIG_UNBLOCK");
    104 static_assert(LINUX_SA_SIGINFO == SA_SIGINFO, "LINUX_SA_SIGINFO == SA_SIGINFO");
    105 static_assert(LINUX_SA_NODEFER == SA_NODEFER, "LINUX_SA_NODEFER == SA_NODEFER");
    106 static_assert(LINUX_SA_RESTART == SA_RESTART, "LINUX_SA_RESTART == SA_RESTART");
    107 static_assert(LINUX_SIG_DFL == SIG_DFL, "LINUX_SIG_DFL == SIG_DFL");
    108 
    109 typedef siginfo_t LinuxSigInfo;
    110 
    111 #if defined(__ANDROID__)
    112 // Android's signal.h doesn't define ucontext etc.
    113 #include "sandbox/linux/system_headers/linux_ucontext.h"
    114 #endif  // defined(__ANDROID__)
    115 
    116 #endif  // !defined(__native_client_nonsfi__)
    117 
    118 // struct sigset_t is different size in PNaCl from the Linux's.
    119 #if defined(__mips__)
    120 #if !defined(_NSIG_WORDS)
    121 #define _NSIG_WORDS 4
    122 #endif
    123 struct LinuxSigSet {
    124   unsigned long sig[_NSIG_WORDS];
    125 };
    126 #else
    127 typedef uint64_t LinuxSigSet;
    128 #endif
    129 
    130 // struct sigaction is different in PNaCl from the Linux's.
    131 #if defined(__mips__)
    132 struct LinuxSigAction {
    133   unsigned int sa_flags;
    134   void (*kernel_handler)(int);
    135   LinuxSigSet sa_mask;
    136 };
    137 #else
    138 struct LinuxSigAction {
    139   void (*kernel_handler)(int);
    140   uint32_t sa_flags;
    141   void (*sa_restorer)(void);
    142   LinuxSigSet sa_mask;
    143 };
    144 #endif
    145 
    146 #endif  // SANDBOX_LINUX_SYSTEM_HEADERS_LINUX_SIGNAL_H_
    147