mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 15:03:34 +00:00
In order to improve our chances of success building other open source projects we shouldn't define APIs that'll lead any ./configure script astray. For example: - brk() and sbrk() can break mac/windows support - syscall() is a superb way to break portability - arch_prctl() is the greatest of all horror shows
26 lines
887 B
C
26 lines
887 B
C
#ifndef COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
|
|
#define COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
|
#ifdef COSMO
|
|
|
|
/**
|
|
* Reads scalar from memory, offset by segment.
|
|
*
|
|
* @return *(MEM) relative to segment
|
|
* @see pushpop()
|
|
*/
|
|
#define fs(MEM) __peek("fs", MEM)
|
|
#define gs(MEM) __peek("gs", MEM)
|
|
|
|
#define __peek(SEGMENT, ADDRESS) \
|
|
({ \
|
|
typeof(*(ADDRESS)) Pk; \
|
|
asm("mov\t%%" SEGMENT ":%1,%0" : "=r"(Pk) : "m"(*(ADDRESS))); \
|
|
Pk; \
|
|
})
|
|
|
|
#endif /* COSMO */
|
|
#endif /* __GNUC__ && !__STRICT_ANSI__ */
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_ */
|