mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
4778cd4d27
This change fixes an issue with the tcflow() magic numbers that was causing bash to freeze up on Linux. While auditing termios polyfills, several other issues were identified with XNU/BSD compatibility. Out of an abundance of caution this change undefines as much surface area from libc/calls/struct/termios.h as possible, so that autoconf scripts are less likely to detect non-POSIX teletypewriter APIs that haven't been polyfilled by Cosmopolitan. This is a *breaking change* for your static archives in /opt/cosmos if you use the cosmocc toolchain. That's because this change disables the ioctl() undiamonding trick for code outside the monorepo, specifically because it'll lead to brittle ABI breakages like this. If you're using the cosmocc toolchain, you'll need to rebuild libraries like ncurses, readline, etc. Yes diamonds cause bloat. To work around that, consider using tcgetwinsize() instead of ioctl(TIOCGWINSZ) since it'll help you avoid pulling every single ioctl-related polyfill into the linkage. The cosmocc script was specifying -DNDEBUG for some reason. It's fixed.
59 lines
2.6 KiB
C
59 lines
2.6 KiB
C
#ifndef COSMOPOLITAN_LIBC_BITS_PUSHPOP_H_
|
|
#define COSMOPOLITAN_LIBC_BITS_PUSHPOP_H_
|
|
#include "libc/macros.internal.h"
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
#ifdef COSMO
|
|
|
|
#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__) || \
|
|
!defined(__MNO_RED_ZONE__)
|
|
#define pushpop(x) (x)
|
|
#else
|
|
/**
|
|
* PushPop
|
|
* An elegant weapon for a more civilized age.
|
|
*/
|
|
#define pushpop(x) \
|
|
({ \
|
|
typeof(x) Popped; \
|
|
if (__builtin_constant_p(x) && \
|
|
(TYPE_SIGNED(typeof(x)) ? (intptr_t)(x) + 128 < 256 \
|
|
: (intptr_t)(x) < 128)) { \
|
|
if (x) { \
|
|
asm("push\t%1\n\t" \
|
|
"pop\t%q0" \
|
|
: "=r"(Popped) \
|
|
: "ir"(x)); \
|
|
} else { \
|
|
asm("xor\t%k0,%k0" : "=r"(Popped)); \
|
|
} \
|
|
} else { \
|
|
asm("" : "=r"(Popped) : "0"(x)); \
|
|
} \
|
|
Popped; \
|
|
})
|
|
#endif
|
|
|
|
#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__) || \
|
|
!defined(__MNO_RED_ZONE__)
|
|
#define pushmov(d, x) (*(d) = (x))
|
|
#else
|
|
#define pushmov(d, x) \
|
|
({ \
|
|
typeof(*(d)) Popped = (x); \
|
|
if (__builtin_constant_p(x) && \
|
|
(TYPE_SIGNED(typeof(x)) ? (intptr_t)(x) + 128 < 256 \
|
|
: (intptr_t)(x) < 128)) { \
|
|
asm("pushq\t%1\n\t" \
|
|
"popq\t%0" \
|
|
: "=m"(*(d)) \
|
|
: "ir"(Popped)); \
|
|
} else { \
|
|
*(d) = Popped; \
|
|
} \
|
|
Popped; \
|
|
})
|
|
#endif
|
|
|
|
#endif /* COSMO */
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_BITS_PUSHPOP_H_ */
|