Fix ucontext_t alignment in strict ansi mode

Using `cosmocc -std=c11` was causing `ucontext_t` to become misaligned.
This change also adds the GNU constants on x86_64 for accessing general
registers, so you will not need `#ifdef`s to support both Cosmo and GNU
This commit is contained in:
Justine Tunney 2023-11-09 12:44:42 -08:00
parent b8d1377ae1
commit 15af5c2d7e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
2 changed files with 28 additions and 12 deletions

View file

@ -7,6 +7,32 @@ COSMOPOLITAN_C_START_
#ifdef __x86_64__
#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define REG_R8 0
#define REG_R9 1
#define REG_R10 2
#define REG_R11 3
#define REG_R12 4
#define REG_R13 5
#define REG_R14 6
#define REG_R15 7
#define REG_RDI 8
#define REG_RSI 9
#define REG_RBP 10
#define REG_RBX 11
#define REG_RDX 12
#define REG_RAX 13
#define REG_RCX 14
#define REG_RSP 15
#define REG_RIP 16
#define REG_EFL 17
#define REG_CSGSFS 18
#define REG_ERR 19
#define REG_TRAPNO 20
#define REG_OLDMASK 21
#define REG_CR2 22
#endif
struct XmmRegister {
uint64_t u64[2];
};
@ -31,7 +57,7 @@ struct thatispacked FpuState {
uint32_t __padding[24];
};
typedef uint64_t greg_t;
typedef long long greg_t;
typedef greg_t gregset_t[23];
typedef struct FpuState *fpregset_t;

View file

@ -174,18 +174,9 @@ typedef struct {
#endif
#ifndef forcealign
#ifndef __STRICT_ANSI__
#define forcealign(bytes) __attribute__((__aligned__(bytes)))
#else
#define forcealign(bytes)
#endif
#endif
#ifndef __STRICT_ANSI__
#define thatispacked __attribute__((__packed__))
#else
#define thatispacked
#endif
#ifndef __STRICT_ANSI__
#define printfesque(n) __attribute__((__format__(__gnu_printf__, n, n + 1)))
@ -727,8 +718,7 @@ void abort(void) wontreturn;
#define __static_yoink_source(PATH)
#endif
#define __weak_reference(sym, alias) \
__weak_reference_impl(sym, alias)
#define __weak_reference(sym, alias) __weak_reference_impl(sym, alias)
#define __weak_reference_impl(sym, alias) \
__asm__(".weak\t" #alias "\n\t" \
".equ\t" #alias ", " #sym "\n\t" \