diff --git a/libc/include/signal.h b/libc/include/signal.h index 0159bf21c..c01b33a45 100644 --- a/libc/include/signal.h +++ b/libc/include/signal.h @@ -51,14 +51,15 @@ __BEGIN_DECLS typedef int sig_atomic_t; -/* TODO: 64-bit: we should probably #undef the uapi NSIG and add a unit test that NSIG == _NSIG && NSIG >= 64. */ -#ifndef _NSIG -# define _NSIG 64 -#endif -#ifndef NSIG -# define NSIG _NSIG +/* The arm and x86 kernel header files don't define _NSIG. */ +#ifndef _KERNEL__NSIG +#define _KERNEL__NSIG 64 #endif +/* Userspace's NSIG is the kernel's _NSIG + 1. */ +#define _NSIG (_KERNEL__NSIG + 1) +#define NSIG _NSIG + extern const char* const sys_siglist[]; extern const char* const sys_signame[]; diff --git a/libc/kernel/tools/cpp.py b/libc/kernel/tools/cpp.py index 04e42567c..2c40d7c60 100644 --- a/libc/kernel/tools/cpp.py +++ b/libc/kernel/tools/cpp.py @@ -1521,7 +1521,7 @@ class BlockList: """replace tokens according to the given dict """ for b in self.blocks: - if not b.isDirective(): + if (not b.isDirective()) or b.isDefine(): for tok in b.tokens: if tok.id == tokIDENT: if tok.value in replacements: diff --git a/libc/kernel/tools/defaults.py b/libc/kernel/tools/defaults.py index f2358033c..09556c9e6 100644 --- a/libc/kernel/tools/defaults.py +++ b/libc/kernel/tools/defaults.py @@ -57,10 +57,15 @@ kernel_arch_token_replacements = { "mips": {"off_t":"__kernel_off_t"}, "x86": {}, } + # Replace tokens in the output according to this mapping kernel_token_replacements = { "asm": "__asm__", - "__unused": "__linux_unused", # The kernel usage of __unused conflicts with the macro defined in sys/cdefs.h + # The kernel usage of __unused for unused struct fields conflicts with the macro defined in . + "__unused": "__linux_unused", + # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside. + "_NSIG": "_KERNEL__NSIG", + "NSIG": "_KERNEL_NSIG", } # this is the set of known static inline functions that we want to keep diff --git a/libc/kernel/uapi/asm-arm/asm/signal.h b/libc/kernel/uapi/asm-arm/asm/signal.h index 9297a7003..512e22a25 100644 --- a/libc/kernel/uapi/asm-arm/asm/signal.h +++ b/libc/kernel/uapi/asm-arm/asm/signal.h @@ -21,7 +21,7 @@ #include struct siginfo; /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ -#define NSIG 32 +#define _KERNEL_NSIG 32 typedef unsigned long sigset_t; #define SIGHUP 1 #define SIGINT 2 @@ -67,7 +67,7 @@ typedef unsigned long sigset_t; #define SIGUNUSED 31 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #define SIGRTMIN 32 -#define SIGRTMAX _NSIG +#define SIGRTMAX _KERNEL__NSIG #define SIGSWI 32 #define SA_NOCLDSTOP 0x00000001 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ diff --git a/libc/kernel/uapi/asm-generic/signal.h b/libc/kernel/uapi/asm-generic/signal.h index c4c7e00e4..fe7d9a097 100644 --- a/libc/kernel/uapi/asm-generic/signal.h +++ b/libc/kernel/uapi/asm-generic/signal.h @@ -19,10 +19,10 @@ #ifndef _UAPI__ASM_GENERIC_SIGNAL_H #define _UAPI__ASM_GENERIC_SIGNAL_H #include -#define _NSIG 64 +#define _KERNEL__NSIG 64 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #define _NSIG_BPW __BITS_PER_LONG -#define _NSIG_WORDS (_NSIG / _NSIG_BPW) +#define _NSIG_WORDS (_KERNEL__NSIG / _NSIG_BPW) #define SIGHUP 1 #define SIGINT 2 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ @@ -68,7 +68,7 @@ /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #define SIGRTMIN 32 #ifndef SIGRTMAX -#define SIGRTMAX _NSIG +#define SIGRTMAX _KERNEL__NSIG #endif /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #define SA_NOCLDSTOP 0x00000001 diff --git a/libc/kernel/uapi/asm-mips/asm/signal.h b/libc/kernel/uapi/asm-mips/asm/signal.h index 771e31a6e..53f501513 100644 --- a/libc/kernel/uapi/asm-mips/asm/signal.h +++ b/libc/kernel/uapi/asm-mips/asm/signal.h @@ -19,10 +19,10 @@ #ifndef _UAPI_ASM_SIGNAL_H #define _UAPI_ASM_SIGNAL_H #include -#define _NSIG 128 +#define _KERNEL__NSIG 128 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #define _NSIG_BPW (sizeof(unsigned long) * 8) -#define _NSIG_WORDS (_NSIG / _NSIG_BPW) +#define _NSIG_WORDS (_KERNEL__NSIG / _NSIG_BPW) typedef struct { unsigned long sig[_NSIG_WORDS]; /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ @@ -72,7 +72,7 @@ typedef unsigned long old_sigset_t; #define SIGXFSZ 31 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #define SIGRTMIN 32 -#define SIGRTMAX _NSIG +#define SIGRTMAX _KERNEL__NSIG #define SA_ONSTACK 0x08000000 #define SA_RESETHAND 0x80000000 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ diff --git a/libc/kernel/uapi/asm-x86/asm/signal.h b/libc/kernel/uapi/asm-x86/asm/signal.h index bba6bc768..6f5b4354d 100644 --- a/libc/kernel/uapi/asm-x86/asm/signal.h +++ b/libc/kernel/uapi/asm-x86/asm/signal.h @@ -24,7 +24,7 @@ #include #include struct siginfo; -#define NSIG 32 +#define _KERNEL_NSIG 32 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ typedef unsigned long sigset_t; #endif @@ -72,7 +72,7 @@ typedef unsigned long sigset_t; #define SIGUNUSED 31 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #define SIGRTMIN 32 -#define SIGRTMAX _NSIG +#define SIGRTMAX _KERNEL__NSIG #define SA_NOCLDSTOP 0x00000001u #define SA_NOCLDWAIT 0x00000002u /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ diff --git a/libc/kernel/uapi/asm-x86/asm/stat.h b/libc/kernel/uapi/asm-x86/asm/stat.h index 09981062b..04c556909 100644 --- a/libc/kernel/uapi/asm-x86/asm/stat.h +++ b/libc/kernel/uapi/asm-x86/asm/stat.h @@ -102,7 +102,7 @@ struct stat { long __linux_unused[3]; /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ }; -#define INIT_STRUCT_STAT_PADDING(st) do { st.__pad0 = 0; st.__unused[0] = 0; st.__unused[1] = 0; st.__unused[2] = 0; } while (0) +#define INIT_STRUCT_STAT_PADDING(st) do { st.__pad0 = 0; st.__linux_unused[0] = 0; st.__linux_unused[1] = 0; st.__linux_unused[2] = 0; } while (0) #endif struct __old_kernel_stat { /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */