mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Improve dead code elimination
This commit is contained in:
parent
760db8c5ad
commit
0e36cb3ac4
6606 changed files with 9685 additions and 9854 deletions
76
ape/ape.S
76
ape/ape.S
|
@ -47,9 +47,6 @@
|
|||
|
||||
#define USE_SYMBOL_HACK 0
|
||||
|
||||
.source "NOTICE"
|
||||
.source "ape/ape.S"
|
||||
.source "ape/ape.lds"
|
||||
.section .text,"ax",@progbits
|
||||
.align __SIZEOF_POINTER__
|
||||
.previous
|
||||
|
@ -108,6 +105,8 @@ rlstr: .endobj rlstr,globl,hidden # ←for gdb readibility
|
|||
│ αcτµαlly pδrταblε εxεcµταblε § the old technology │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
|
||||
#if SupportsWindows() || SupportsXnu()
|
||||
|
||||
/ MZ Literally Executable Header
|
||||
/
|
||||
/ This is the beginning of the program file and it can serve as an
|
||||
|
@ -116,7 +115,7 @@ rlstr: .endobj rlstr,globl,hidden # ←for gdb readibility
|
|||
/ a machine, this header may need to morph itself to say the magic
|
||||
/ words, e.g. ⌂ELF, which also works fine as a generic entrypoint.
|
||||
/
|
||||
/ @see www.delorie.com/djgpp/doc/exe/
|
||||
/ @param dl is drive number
|
||||
/ @noreturn
|
||||
ape.mz: .ascii "MZ" # Mark 'Zibo' Joseph Zbikowski
|
||||
jno 2f # MZ: bytes on last page
|
||||
|
@ -136,10 +135,48 @@ ape.mz: .ascii "MZ" # Mark 'Zibo' Joseph Zbikowski
|
|||
.ascii "JT" # MZ: OEM identifier
|
||||
.short 0 # MZ: OEM information
|
||||
.org 0x40-4 # MZ: bytes reserved for you
|
||||
#if SupportsWindows()
|
||||
.long RVA(ape.pe) # PE: the new technology
|
||||
#else
|
||||
.long 0
|
||||
#endif
|
||||
.endfn ape.mz,globl,hidden
|
||||
|
||||
#else /* !(SupportsWindows() || SupportsXnu()) */
|
||||
|
||||
/ ELF Literally Executable Header
|
||||
/
|
||||
/ If we don't need to support Microsoft or Apple then we can
|
||||
/ produce a conventional executable without the shell script
|
||||
/
|
||||
/ @param dl is drive number
|
||||
/ @noreturn
|
||||
.ascii "\177ELF" # 0x0: ⌂ELF
|
||||
.byte ELFCLASS64 # 4: long mode
|
||||
.byte ELFDATA2LSB # 5: little endian
|
||||
.byte 1 # 6: elf v1.o
|
||||
.byte ELFOSABI_FREEBSD # 7: FreeBSD
|
||||
.byte 0 # 8: os/abi ver.
|
||||
.align 8,0 # 9: padding
|
||||
.short ET_EXEC # 10: εxεcµταblε
|
||||
.short EM_NEXGEN32E # 12: NexGen32e
|
||||
.long 1 # 14: elf v1.o
|
||||
.quad .Lape.elf.entry # 18: e_entry
|
||||
.quad .Lape.elf.phoff # 20: e_phoff
|
||||
.quad .Lape.elf.shoff # 28: e_shoff
|
||||
.long 0 # 30: e_flags
|
||||
.short 64 # 34: e_ehsize
|
||||
.short 56 # 36: e_phentsize
|
||||
.short .Lape.elf.phnum # 38: e_phnum
|
||||
.short 0 # 3a: e_shentsize
|
||||
.short .Lape.elf.shnum # 3c: e_shnum
|
||||
.short .Lape.elf.shstrndx # 3e: e_shstrndx
|
||||
|
||||
#endif /* SupportsWindows() || SupportsXnu() */
|
||||
|
||||
/ Disk Operating System Stub
|
||||
/
|
||||
/ @param dl is drive number
|
||||
/ @noreturn
|
||||
.org 0x40 # mz/elf header length
|
||||
stub: mov $0x40,%dl # *literally* dos
|
||||
|
@ -187,6 +224,7 @@ pc: cld
|
|||
xor %cx,%cx
|
||||
mov %cx,%es
|
||||
rlstack %di,%cx
|
||||
#if SupportsMetal()
|
||||
push %cs # memcpy() [relocate this page]
|
||||
pop %ds
|
||||
call 1f
|
||||
|
@ -391,6 +429,8 @@ ape_disk:
|
|||
.short BOOTSIG
|
||||
.endobj ape_disk
|
||||
|
||||
#endif /* SupportsMetal() */
|
||||
|
||||
/* ▄▄▄
|
||||
▄▄▄ ▀▓▓▒▄
|
||||
▄▓▒▒░ ▀▓▒▒▒▄
|
||||
|
@ -432,8 +472,10 @@ ape_disk:
|
|||
╚────────────────────────────────────────────────────────────────────────────│─╝
|
||||
the bourne executable & linkable format */
|
||||
|
||||
#if SupportsWindows() || SupportsXnu()
|
||||
apesh: .ascii "'\n#'\"\n" # sixth edition shebang
|
||||
.ascii "o=\"$(command -v \"$0\")\"\n"
|
||||
#if SupportsXnu()
|
||||
.ascii "if [ -d /Applications ]; then\n"
|
||||
.ascii "dd if=\"$o\""
|
||||
.ascii " of=\"$o\""
|
||||
|
@ -443,7 +485,9 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang
|
|||
.ascii "\" count=\""
|
||||
.shstub .Lape.macho.dd.count,2
|
||||
.ascii "\" conv=notrunc 2>/dev/null\n"
|
||||
.ascii "elif exec 7<> \"$o\"; then\n"
|
||||
.ascii "el"
|
||||
#endif
|
||||
.ascii "if exec 7<> \"$o\"; then\n"
|
||||
.ascii "printf '"
|
||||
.ascii "\\177ELF" # 0x0: ⌂ELF
|
||||
.ascii "\\2" # 4: long mode
|
||||
|
@ -483,6 +527,7 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang
|
|||
.ascii "fi\n"
|
||||
.ascii "exit $R\n"
|
||||
.endobj apesh
|
||||
#endif /* SupportsWindows() || SupportsXnu() */
|
||||
|
||||
.section .elf.phdrs,"a",@progbits
|
||||
.align __SIZEOF_POINTER__
|
||||
|
@ -506,6 +551,7 @@ ape.phdrs:
|
|||
.stub .Lape.ram.filesz,quad
|
||||
.stub .Lape.ram.memsz,quad
|
||||
.stub .Lape.ram.align,quad
|
||||
#if SupportsLinux()
|
||||
/ Linux ignores mprotect() and returns 0 without this lool
|
||||
/ It has nothing to do with the stack, which is still exec
|
||||
.align __SIZEOF_POINTER__
|
||||
|
@ -517,6 +563,8 @@ ape.phdrs:
|
|||
.quad 0 # p_filesz
|
||||
.quad 0 # p_memsz
|
||||
.quad 16 # p_align
|
||||
#endif
|
||||
#if SupportsOpenbsd() || SupportsNetbsd()
|
||||
.align __SIZEOF_POINTER__
|
||||
.long PT_NOTE # notes
|
||||
.long PF_R
|
||||
|
@ -526,8 +574,10 @@ ape.phdrs:
|
|||
.stub .Lape.note.filesz,quad
|
||||
.stub .Lape.note.memsz,quad
|
||||
.stub .Lape.note.align,quad
|
||||
#endif
|
||||
.previous
|
||||
|
||||
#if SupportsOpenbsd()
|
||||
.section .note.openbsd.ident,"a",@progbits
|
||||
.Lopenbsd.ident:
|
||||
.long 2f-1f
|
||||
|
@ -539,7 +589,9 @@ ape.phdrs:
|
|||
4: .size .Lopenbsd.ident,.-.Lopenbsd.ident
|
||||
.type .Lopenbsd.ident,@object
|
||||
.previous
|
||||
#endif /* SupportsOpenbsd() */
|
||||
|
||||
#if SupportsNetbsd()
|
||||
.section .note.netbsd.ident,"a",@progbits
|
||||
.Lnetbsd.ident:
|
||||
.long 2f-1f
|
||||
|
@ -551,6 +603,7 @@ ape.phdrs:
|
|||
4: .size .Lnetbsd.ident,.-.Lnetbsd.ident
|
||||
.type .Lnetbsd.ident,@object
|
||||
.previous
|
||||
#endif /* SupportsNetbsd() */
|
||||
|
||||
/* ▄▄███▄
|
||||
▄▄████████▄
|
||||
|
@ -583,6 +636,7 @@ ape.phdrs:
|
|||
@see System V Application Binary Interface NexGen32e Architecture
|
||||
Processor Supplement, Version 1.0, December 5th, 2018 */
|
||||
|
||||
#if SupportsXnu()
|
||||
.section .macho,"a",@progbits
|
||||
.align __SIZEOF_POINTER__
|
||||
|
||||
|
@ -654,8 +708,8 @@ ape.macho:
|
|||
.long 0,0,0 # reserved
|
||||
40: .long MAC_LC_UUID
|
||||
.long 50f-40b
|
||||
.stub uuid1_,quad
|
||||
.stub uuid2_,quad
|
||||
.stub .Lape.uuid1,quad
|
||||
.stub .Lape.uuid2,quad
|
||||
50: .long MAC_LC_UNIXTHREAD
|
||||
.long 60f-50b # cmdsize
|
||||
.long MAC_THREAD_NEXGEN32E # flavaflav
|
||||
|
@ -686,6 +740,7 @@ ape.macho:
|
|||
|
||||
.endobj ape.macho,globl,hidden
|
||||
.previous /* .macho */
|
||||
#endif /* SupportsXnu() */
|
||||
|
||||
/* ░░░░
|
||||
▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
|
||||
|
@ -763,6 +818,8 @@ ape.macho:
|
|||
.LPEDATA = 0b11000000000000000000000011000000
|
||||
.LPEIMPS = 0b11000000000000000000000001000000
|
||||
|
||||
#if SupportsWindows()
|
||||
|
||||
.section .pe.header,"a",@progbits
|
||||
.align __SIZEOF_POINTER__
|
||||
ape.pe: .ascin "PE",4
|
||||
|
@ -849,6 +906,8 @@ ape.pe: .ascin "PE",4
|
|||
.long .LPEDATA # Flags
|
||||
.previous
|
||||
|
||||
#endif /* SupportsWindows() */
|
||||
|
||||
.section .idata.ro.idt.1,"a",@progbits
|
||||
.type idata.idtend,@object
|
||||
.type idata.idt,@object
|
||||
|
@ -878,6 +937,7 @@ idata.iat:
|
|||
idata.iatend:
|
||||
.previous
|
||||
|
||||
#if SupportsMetal()
|
||||
/*─────────────────────────────────────────────────────────────────────────────╗
|
||||
│ αcτµαlly pδrταblε εxεcµταblε § early-stage read-only data │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
|
@ -1486,6 +1546,8 @@ metal:
|
|||
jmp _start
|
||||
.endfn metal
|
||||
|
||||
#endif /* SupportsMetal() */
|
||||
|
||||
/ Avoid linker script variables appearing as code in objdump.
|
||||
.macro .ldsvar name:req
|
||||
.type \name,@object
|
||||
|
|
119
ape/ape.lds
119
ape/ape.lds
|
@ -176,6 +176,7 @@
|
|||
#ifdef __LINKER__
|
||||
#include "ape/macros.internal.h"
|
||||
#include "ape/config.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nt/pedef.internal.h"
|
||||
#include "libc/zip.h"
|
||||
|
||||
|
@ -245,7 +246,7 @@ SECTIONS {
|
|||
. += 1;
|
||||
|
||||
KEEP(*(.ape.pad.head))
|
||||
. = ALIGN(4096); /* alignments only mandatory when impossible otherwise */
|
||||
. = ALIGN(SupportsWindows() ? PAGESIZE : 16);
|
||||
HIDDEN(_ehead = .);
|
||||
} AT>SmallCode :Head
|
||||
|
||||
|
@ -345,6 +346,22 @@ SECTIONS {
|
|||
KEEP(*(SORT_BY_NAME(.idata.ro.*)))
|
||||
. += 1;
|
||||
|
||||
. = ALIGN(__SIZEOF_POINTER__);
|
||||
PROVIDE_HIDDEN(__init_array_start = .);
|
||||
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)
|
||||
SORT_BY_INIT_PRIORITY(.ctors.*)))
|
||||
KEEP(*(SORT_NONE(.ctors)))
|
||||
KEEP(*(SORT_NONE(.init_array)))
|
||||
KEEP(*(SORT_NONE(.preinit_array)))
|
||||
PROVIDE_HIDDEN(__init_array_end = .);
|
||||
|
||||
. = ALIGN(__SIZEOF_POINTER__);
|
||||
PROVIDE_HIDDEN(__fini_array_start = .);
|
||||
KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*)
|
||||
SORT_BY_INIT_PRIORITY(.dtors.*)))
|
||||
KEEP(*(SORT_NONE(.dtors)))
|
||||
PROVIDE_HIDDEN(__fini_array_end = .);
|
||||
|
||||
/* Encoded Data Structures w/ Linear Initialization Order */
|
||||
KEEP(*(.initroprologue))
|
||||
KEEP(*(SORT_BY_NAME(.initro.*)))
|
||||
|
@ -379,24 +396,6 @@ SECTIONS {
|
|||
. = ALIGN(.Lape.piro.align);
|
||||
HIDDEN(__piro_start = .);
|
||||
|
||||
QUAD(IMAGE_BASE_VIRTUAL);
|
||||
|
||||
PROVIDE_HIDDEN(__init_array_start = .);
|
||||
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)
|
||||
SORT_BY_INIT_PRIORITY(.ctors.*)))
|
||||
KEEP(*(SORT_NONE(.ctors)))
|
||||
KEEP(*(SORT_NONE(.init_array)))
|
||||
KEEP(*(SORT_NONE(.preinit_array)))
|
||||
PROVIDE_HIDDEN(__init_array_end = .);
|
||||
|
||||
. += 1;
|
||||
. = ALIGN(__SIZEOF_POINTER__);
|
||||
PROVIDE_HIDDEN(__fini_array_start = .);
|
||||
KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*)
|
||||
SORT_BY_INIT_PRIORITY(.dtors.*)))
|
||||
KEEP(*(SORT_NONE(.dtors)))
|
||||
PROVIDE_HIDDEN(__fini_array_end = .);
|
||||
|
||||
KEEP(*(SORT_BY_NAME(.piro.relo.sort.*)))
|
||||
PROVIDE_HIDDEN(__relo_end = .);
|
||||
KEEP(*(SORT_BY_NAME(.piro.data.sort.*)))
|
||||
|
@ -481,25 +480,17 @@ PFSTUB8(.Lape.elf.shoff, 0);
|
|||
PFSTUB4(.Lape.elf.phnum, (.Lape.phdrs.end - ape.phdrs) / 56);
|
||||
PFSTUB4(.Lape.elf.shnum, 0);
|
||||
PFSTUB4(.Lape.elf.shstrndx, 0);
|
||||
SHSTUB2(.Lape.macho.dd.skip, RVA(ape.macho) / 8);
|
||||
SHSTUB2(.Lape.macho.dd.count, (.Lape.macho.end - ape.macho) / 8);
|
||||
PFSTUB4(.Lape.pe.offset, ape.pe - ape.mz);
|
||||
|
||||
HIDDEN(__privileged_addr = ROUNDDOWN(__privileged_start, PAGESIZE));
|
||||
HIDDEN(__privileged_size = (ROUNDUP(__privileged_end, PAGESIZE) -
|
||||
ROUNDDOWN(__privileged_start, PAGESIZE)));
|
||||
|
||||
HIDDEN(.Lape.pe.optsz = .Lape.pe.sections - (ape.pe + 24));
|
||||
HIDDEN(.Lape.pe.shnum = (.Lape.pe.sections_end - .Lape.pe.sections) / 40);
|
||||
HIDDEN(.Lidata.idtsize = idata.idtend - idata.idt);
|
||||
HIDDEN(.Lidata.iatsize = idata.iatend - idata.iat);
|
||||
|
||||
HIDDEN(.Lape.rom.offset = 0);
|
||||
HIDDEN(.Lape.rom.vaddr = ADDR(.head));
|
||||
HIDDEN(.Lape.rom.paddr = LOADADDR(.head));
|
||||
HIDDEN(.Lape.rom.filesz = LOADADDR(.data) - .Lape.rom.paddr);
|
||||
HIDDEN(.Lape.rom.memsz = ADDR(.data) - ADDR(.head));
|
||||
HIDDEN(.Lape.rom.align = 0x1000);
|
||||
HIDDEN(.Lape.rom.align = .Lape.data.align);
|
||||
HIDDEN(.Lape.rom.rva = RVA(.Lape.rom.vaddr));
|
||||
|
||||
HIDDEN(.Lape.ram.offset = .Lape.rom.offset + .Lape.rom.filesz);
|
||||
|
@ -507,7 +498,7 @@ HIDDEN(.Lape.ram.vaddr = ADDR(.data));
|
|||
HIDDEN(.Lape.ram.paddr = LOADADDR(.data));
|
||||
HIDDEN(.Lape.ram.filesz = LOADADDR(.bss) - LOADADDR(.data));
|
||||
HIDDEN(.Lape.ram.memsz = ADDR(.bss) + SIZEOF(.bss) - .Lape.ram.vaddr);
|
||||
HIDDEN(.Lape.ram.align = 0x1000);
|
||||
HIDDEN(.Lape.ram.align = .Lape.data.align);
|
||||
HIDDEN(.Lape.ram.rva = RVA(.Lape.ram.vaddr));
|
||||
|
||||
HIDDEN(.Lape.note.offset = .Lape.rom.offset + (.Lape.note - .Lape.rom.vaddr));
|
||||
|
@ -530,7 +521,7 @@ HIDDEN(.Lape.data.paddr = LOADADDR(.data));
|
|||
HIDDEN(.Lape.data.vaddr = ADDR(.data));
|
||||
HIDDEN(.Lape.data.filesz = SIZEOF(.data));
|
||||
HIDDEN(.Lape.data.memsz = SIZEOF(.data));
|
||||
HIDDEN(.Lape.data.align = 0x1000);
|
||||
HIDDEN(.Lape.data.align = .Lape.data.align);
|
||||
HIDDEN(.Lape.data.rva = RVA(.Lape.data.vaddr));
|
||||
|
||||
HIDDEN(.Lape.bss.offset = .Lape.ram.offset + LOADADDR(.bss) - .Lape.ram.paddr);
|
||||
|
@ -540,18 +531,30 @@ HIDDEN(.Lape.bss.filesz = 0);
|
|||
HIDDEN(.Lape.bss.memsz = SIZEOF(.bss));
|
||||
HIDDEN(.Lape.bss.align = .Lape.data.align);
|
||||
|
||||
/* Program Loader Auto-Tune */
|
||||
#if SupportsXnu()
|
||||
SHSTUB2(.Lape.macho.dd.skip, RVA(ape.macho) / 8);
|
||||
SHSTUB2(.Lape.macho.dd.count, (.Lape.macho.end - ape.macho) / 8);
|
||||
#endif
|
||||
|
||||
#if SupportsWindows()
|
||||
PFSTUB4(.Lape.pe.offset, ape.pe - ape.mz);
|
||||
HIDDEN(.Lape.pe.optsz = .Lape.pe.sections - (ape.pe + 24));
|
||||
HIDDEN(.Lape.pe.shnum = (.Lape.pe.sections_end - .Lape.pe.sections) / 40);
|
||||
HIDDEN(.Lidata.idtsize = idata.idtend - idata.idt);
|
||||
HIDDEN(.Lidata.iatsize = idata.iatend - idata.iat);
|
||||
HIDDEN(v_ntsubsystem = (DEFINED(GetMessage)
|
||||
? kNtImageSubsystemWindowsGui
|
||||
: kNtImageSubsystemWindowsCui));
|
||||
#endif
|
||||
|
||||
#if SupportsMetal()
|
||||
HIDDEN(v_ape_realsectors =
|
||||
MIN(REAL_SCRATCH_AREA - IMAGE_BASE_REAL,
|
||||
ROUNDUP(RVA(_edata), 4096)) / 512);
|
||||
HIDDEN(v_ape_realpages = v_ape_realsectors / (4096 / 512));
|
||||
HIDDEN(v_ape_highsectors =
|
||||
(ROUNDUP(RVA(_edata), 512) / 512) - v_ape_realsectors);
|
||||
|
||||
/* Windows NT Auto-Subsystem Embedding */
|
||||
HIDDEN(v_ntsubsystem = (DEFINED(GetMessage)
|
||||
? kNtImageSubsystemWindowsGui
|
||||
: kNtImageSubsystemWindowsCui));
|
||||
#endif
|
||||
|
||||
/* ZIP End of Central Directory header */
|
||||
#define ZIPCONST(NAME, VAL) HIDDEN(NAME = DEFINED(__zip_start) ? VAL : 0);
|
||||
|
@ -560,7 +563,8 @@ ZIPCONST(v_zip_cdirsize, __zip_end - __zip_start);
|
|||
ZIPCONST(v_zip_records, v_zip_cdirsize / kZipCdirHdrLinkableSize);
|
||||
ZIPCONST(v_zip_commentsize, _edata - __zip_end - kZipCdirHdrMinSize);
|
||||
|
||||
/* Generates deterministic ID for Mach-O. */
|
||||
#if SupportsXnu()
|
||||
/* Generates deterministic ID. */
|
||||
#define PHI 0x9e3779b9925d4c17
|
||||
#define XOR(X,Y) ((X | Y) - (X & Y))
|
||||
#define XORSHIFT(X,Y) \
|
||||
|
@ -573,14 +577,12 @@ ZIPCONST(v_zip_commentsize, _edata - __zip_end - kZipCdirHdrMinSize);
|
|||
X = (X + (Y >> 020) & 0xFF) * PHI; \
|
||||
X = (X + (Y >> 030) & 0xFF) * PHI
|
||||
#define CHURN(X) \
|
||||
XORSHIFT(uuid1_, X); \
|
||||
KMH(uuid1_, X); \
|
||||
XORSHIFT(uuid2_, X); \
|
||||
KMH(uuid2_, X)
|
||||
|
||||
HIDDEN(uuid1_ = 88172645463325252);
|
||||
HIDDEN(uuid2_ = 88172645463325252);
|
||||
|
||||
XORSHIFT(.Lape.uuid1, X); \
|
||||
KMH(.Lape.uuid1, X); \
|
||||
XORSHIFT(.Lape.uuid2, X); \
|
||||
KMH(.Lape.uuid2, X)
|
||||
HIDDEN(.Lape.uuid1 = 88172645463325252);
|
||||
HIDDEN(.Lape.uuid2 = 88172645463325252);
|
||||
CHURN(.Lape.bss.align);
|
||||
CHURN(.Lape.bss.filesz);
|
||||
CHURN(.Lape.bss.memsz);
|
||||
|
@ -608,12 +610,6 @@ CHURN(.Lape.note.memsz);
|
|||
CHURN(.Lape.note.offset);
|
||||
CHURN(.Lape.note.paddr);
|
||||
CHURN(.Lape.note.vaddr);
|
||||
CHURN(.Lape.pe.offset);
|
||||
CHURN(.Lape.pe.optsz);
|
||||
CHURN(.Lape.pe.sections);
|
||||
CHURN(.Lape.pe.sections_end);
|
||||
CHURN(.Lape.pe.shnum);
|
||||
CHURN(.Lape.phdrs.end);
|
||||
CHURN(.Lape.ram.align);
|
||||
CHURN(.Lape.ram.filesz);
|
||||
CHURN(.Lape.ram.memsz);
|
||||
|
@ -636,15 +632,28 @@ CHURN(.Lape.text.paddr);
|
|||
CHURN(.Lape.text.rva);
|
||||
CHURN(.Lape.text.vaddr);
|
||||
CHURN(ADDR(.bss));
|
||||
CHURN(WinMain);
|
||||
CHURN(_start);
|
||||
CHURN(ape.phdrs);
|
||||
#if SupportsMetal()
|
||||
CHURN(v_ape_realsectors);
|
||||
#endif
|
||||
#if SupportsXnu()
|
||||
CHURN(ape.macho);
|
||||
#endif
|
||||
#if SupportsWindows()
|
||||
CHURN(ape.mz);
|
||||
CHURN(ape.pe);
|
||||
CHURN(ape.phdrs);
|
||||
CHURN(v_ape_realsectors);
|
||||
CHURN(.Lape.pe.offset);
|
||||
CHURN(.Lape.pe.optsz);
|
||||
CHURN(.Lape.pe.sections);
|
||||
CHURN(.Lape.pe.sections_end);
|
||||
CHURN(.Lape.pe.shnum);
|
||||
CHURN(.Lape.phdrs.end);
|
||||
CHURN(WinMain);
|
||||
#endif /* SupportsWindows() */
|
||||
#endif /* SupportsXnu() */
|
||||
|
||||
ASSERT(ape.mz == IMAGE_BASE_VIRTUAL, "linker panic");
|
||||
ASSERT(DEFINED(ape.mz) ? ape.mz == IMAGE_BASE_VIRTUAL : 1, "linker panic");
|
||||
ASSERT((DEFINED(__init_bss_end) ? __init_bss_end : 0) % __SIZEOF_POINTER__ == 0,
|
||||
"__init_bss misalign");
|
||||
ASSERT(((DEFINED(__init_rodata_end) ? __init_rodata_end : 0) %
|
||||
|
|
|
@ -21,7 +21,7 @@ APE = $(APE_DEPS) \
|
|||
|
||||
APELINK = \
|
||||
ACTION=LINK.ape \
|
||||
$(MKDIR) $(@D) && \
|
||||
$(COMPILE) \
|
||||
$(LINK) \
|
||||
$(LINKARGS) \
|
||||
$(OUTPUT_OPTION) && \
|
||||
|
@ -39,6 +39,13 @@ APE_OBJS = $(APE_SRCS:%.S=o/$(MODE)/%.o)
|
|||
APE_DEPS = $(APE_LIB)
|
||||
APE_CHECKS = $(APE_HDRS:%=o/%.ok)
|
||||
|
||||
o/$(MODE)/ape/ape.lds: \
|
||||
ape/ape.lds \
|
||||
ape/config.h \
|
||||
ape/macros.internal.h \
|
||||
libc/dce.h \
|
||||
libc/zip.h
|
||||
|
||||
o/ape/idata.inc: \
|
||||
ape/idata.internal.h \
|
||||
ape/relocations.h
|
||||
|
|
116
build/config.mk
116
build/config.mk
|
@ -119,24 +119,132 @@ endif
|
|||
# - No backtraces
|
||||
# - No algorithmics
|
||||
# - YOLO
|
||||
|
||||
ifeq ($(MODE), tiny)
|
||||
|
||||
CONFIG_CPPFLAGS += \
|
||||
-DTINY \
|
||||
-DNDEBUG \
|
||||
-DTRUSTWORTHY
|
||||
|
||||
CONFIG_CCFLAGS += \
|
||||
-Os \
|
||||
-fno-align-functions \
|
||||
-fno-align-jumps \
|
||||
-fno-align-labels \
|
||||
-fno-align-loops
|
||||
|
||||
TARGET_ARCH ?= \
|
||||
-msse3
|
||||
endif
|
||||
|
||||
# Linux-Only Tiny Mode
|
||||
#
|
||||
# - `make MODE=tiny`
|
||||
# - No checks
|
||||
# - No asserts
|
||||
# - No canaries
|
||||
# - No paranoia
|
||||
# - No avx hooks
|
||||
# - No backtraces
|
||||
# - No portability
|
||||
# - No algorithmics
|
||||
# - YOLO
|
||||
ifeq ($(MODE), tinylinux)
|
||||
CONFIG_CPPFLAGS += \
|
||||
-DTINY \
|
||||
-DNDEBUG \
|
||||
-DTRUSTWORTHY \
|
||||
-DSUPPORT_VECTOR=1
|
||||
CONFIG_CCFLAGS += \
|
||||
-Os \
|
||||
-fno-align-functions \
|
||||
-fno-align-jumps \
|
||||
-fno-align-labels \
|
||||
-fno-align-loops
|
||||
TARGET_ARCH ?= \
|
||||
-msse3
|
||||
endif
|
||||
|
||||
# Linux+BSD Tiny Mode
|
||||
#
|
||||
# - `make MODE=tiny`
|
||||
# - No apple
|
||||
# - No checks
|
||||
# - No asserts
|
||||
# - No canaries
|
||||
# - No paranoia
|
||||
# - No microsoft
|
||||
# - No avx hooks
|
||||
# - No backtraces
|
||||
# - No algorithmics
|
||||
# - YOLO
|
||||
ifeq ($(MODE), tinylinuxbsd)
|
||||
CONFIG_CPPFLAGS += \
|
||||
-DTINY \
|
||||
-DNDEBUG \
|
||||
-DTRUSTWORTHY \
|
||||
-DSUPPORT_VECTOR=113
|
||||
CONFIG_CCFLAGS += \
|
||||
-Os \
|
||||
-fno-align-functions \
|
||||
-fno-align-jumps \
|
||||
-fno-align-labels \
|
||||
-fno-align-loops
|
||||
TARGET_ARCH ?= \
|
||||
-msse3
|
||||
endif
|
||||
|
||||
# Unix Tiny Mode
|
||||
#
|
||||
# - `make MODE=tiny`
|
||||
# - No checks
|
||||
# - No asserts
|
||||
# - No canaries
|
||||
# - No paranoia
|
||||
# - No microsoft
|
||||
# - No avx hooks
|
||||
# - No backtraces
|
||||
# - No algorithmics
|
||||
# - YOLO
|
||||
ifeq ($(MODE), tinysysv)
|
||||
CONFIG_CPPFLAGS += \
|
||||
-DTINY \
|
||||
-DNDEBUG \
|
||||
-DTRUSTWORTHY \
|
||||
-DSUPPORT_VECTOR=121
|
||||
CONFIG_CCFLAGS += \
|
||||
-Os \
|
||||
-fno-align-functions \
|
||||
-fno-align-jumps \
|
||||
-fno-align-labels \
|
||||
-fno-align-loops
|
||||
TARGET_ARCH ?= \
|
||||
-msse3
|
||||
endif
|
||||
|
||||
# Tiny Metallic Unix Mode
|
||||
#
|
||||
# - `make MODE=tiny`
|
||||
# - No checks
|
||||
# - No asserts
|
||||
# - No canaries
|
||||
# - No paranoia
|
||||
# - No microsoft
|
||||
# - No avx hooks
|
||||
# - No backtraces
|
||||
# - No algorithmics
|
||||
# - YOLO
|
||||
ifeq ($(MODE), tinynowin)
|
||||
CONFIG_CPPFLAGS += \
|
||||
-DTINY \
|
||||
-DNDEBUG \
|
||||
-DTRUSTWORTHY \
|
||||
-DSUPPORT_VECTOR=251
|
||||
CONFIG_CCFLAGS += \
|
||||
-Os \
|
||||
-fno-align-functions \
|
||||
-fno-align-jumps \
|
||||
-fno-align-labels \
|
||||
-fno-align-loops
|
||||
TARGET_ARCH ?= \
|
||||
-msse3
|
||||
endif
|
||||
|
||||
# ANSI Mode
|
||||
|
|
|
@ -89,6 +89,7 @@ BLAH2 := $(shell build/package 2>/dev/null)
|
|||
export ADDR2LINE
|
||||
export CCNAME
|
||||
export CCVERSION
|
||||
export COMPILE
|
||||
export CP
|
||||
export DD
|
||||
export GZ
|
||||
|
|
|
@ -28,11 +28,7 @@ EXAMPLES_COMS = \
|
|||
$(EXAMPLES_MAINS_C:%.c=o/$(MODE)/%.com) \
|
||||
$(EXAMPLES_MAINS_CC:%.cc=o/$(MODE)/%.com)
|
||||
|
||||
EXAMPLES_ELFS = \
|
||||
$(EXAMPLES_OBJS:%.o=%.elf)
|
||||
|
||||
EXAMPLES_BINS = \
|
||||
$(EXAMPLES_ELFS) \
|
||||
$(EXAMPLES_COMS) \
|
||||
$(EXAMPLES_COMS:%=%.dbg)
|
||||
|
||||
|
@ -98,21 +94,6 @@ o/$(MODE)/examples/%.com.dbg: \
|
|||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/examples/%.elf: \
|
||||
$(EXAMPLES_DEPS) \
|
||||
$(THIRD_PARTY_DUKTAPE) \
|
||||
o/$(MODE)/examples/%.o \
|
||||
$(CRT) \
|
||||
$(ELF)
|
||||
@$(ELFLINK)
|
||||
|
||||
o/$(MODE)/examples/tiny-raw-linux-tutorial.elf: \
|
||||
o/$(MODE)/examples/tiny-raw-linux-tutorial.o \
|
||||
$(ELF)
|
||||
@$(ELFLINK) -N -z max-page-size=0x10
|
||||
|
||||
$(EXAMPLES_OBJS): examples/examples.mk
|
||||
|
||||
o/$(MODE)/examples/hellojs.com.dbg: \
|
||||
$(EXAMPLES_DEPS) \
|
||||
$(THIRD_PARTY_DUKTAPE) \
|
||||
|
@ -144,6 +125,8 @@ o/$(MODE)/examples/nesemu1.com.dbg: \
|
|||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
$(EXAMPLES_OBJS): examples/examples.mk
|
||||
|
||||
usr/share/dict/words: usr/share/dict/words.gz
|
||||
@$(MKDIR) $(dir $@)
|
||||
@$(GZ) $(ZFLAGS) -d <$< >$@
|
||||
|
|
|
@ -1378,7 +1378,6 @@ void initEditor(void) {
|
|||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
showcrashreports();
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: kilo <filename>\n");
|
||||
exit(1);
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
@ -66,11 +65,10 @@ int main(int argc, char *argv[], char **envp) {
|
|||
for (i = 0; i < ARRAYLEN(kAuxiliaryValues); ++i) {
|
||||
key = *kAuxiliaryValues[i].id;
|
||||
val = getauxval(key);
|
||||
printf(PROGN(stpcpy(stpcpy(stpcpy(fmt, "%16s[%p] = "),
|
||||
kAuxiliaryValues[i].fmt),
|
||||
" # %s\n"),
|
||||
fmt),
|
||||
kAuxiliaryValues[i].name, key, val, kAuxiliaryValues[i].description);
|
||||
stpcpy(stpcpy(stpcpy(fmt, "%16s[%p] = "), kAuxiliaryValues[i].fmt),
|
||||
" # %s\n");
|
||||
printf(fmt, kAuxiliaryValues[i].name, key, val,
|
||||
kAuxiliaryValues[i].description);
|
||||
}
|
||||
printf("\nSpecial Directories:\n");
|
||||
printf(" ☼ kTmpPath = %`'s\n", kTmpPath);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_EMMINTRIN_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_EMMINTRIN_H_
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/bits/xmmintrin.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
|
@ -170,13 +169,25 @@ struct thatispacked mayalias __usi128ma {
|
|||
})
|
||||
|
||||
#define _mm_add_sd(M128D_0, M128D_1) \
|
||||
PROGN((M128D_0)[0] += (M128D_1)[0], (M128D_0))
|
||||
({ \
|
||||
(M128D_0)[0] += (M128D_1)[0]; \
|
||||
(M128D_0); \
|
||||
})
|
||||
#define _mm_sub_sd(M128D_0, M128D_1) \
|
||||
PROGN((M128D_0)[0] -= (M128D_1)[0], (M128D_0))
|
||||
({ \
|
||||
(M128D_0)[0] -= (M128D_1)[0]; \
|
||||
(M128D_0); \
|
||||
})
|
||||
#define _mm_mul_sd(M128D_0, M128D_1) \
|
||||
PROGN((M128D_0)[0] *= (M128D_1)[0], (M128D_0))
|
||||
({ \
|
||||
(M128D_0)[0] *= (M128D_1)[0]; \
|
||||
(M128D_0); \
|
||||
})
|
||||
#define _mm_div_sd(M128D_0, M128D_1) \
|
||||
PROGN((M128D_0)[0] /= (M128D_1)[0], (M128D_0))
|
||||
({ \
|
||||
(M128D_0)[0] /= (M128D_1)[0]; \
|
||||
(M128D_0); \
|
||||
})
|
||||
|
||||
#define _mm_min_sd(M128D_0, M128D_1) \
|
||||
__builtin_ia32_minsd((__v2df)(M128D_0), (__v2df)(M128D_1))
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_PROGN_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_PROGN_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
/**
|
||||
* Evaluates args, returning value of last one.
|
||||
*
|
||||
* This API comes from LISP.
|
||||
*/
|
||||
#define PROGN(...) ({ __VA_ARGS__; })
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_PROGN_H_ */
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_XMMINTRIN_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_XMMINTRIN_H_
|
||||
#include "libc/bits/emmintrin.internal.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
||||
#define _MM_EXCEPT_MASK 0x003f
|
||||
|
|
|
@ -39,21 +39,23 @@ int close(int fd) {
|
|||
if (fd < 0) return einval();
|
||||
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
|
||||
rc = weaken(__zipos_close)(fd);
|
||||
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdEpoll) {
|
||||
rc = weaken(sys_close_epoll)(fd);
|
||||
} else if (!IsWindows()) {
|
||||
rc = sys_close(fd);
|
||||
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdSocket) {
|
||||
rc = weaken(sys_closesocket_nt)(g_fds.p + fd);
|
||||
} else if (fd < g_fds.n &&
|
||||
(g_fds.p[fd].kind == kFdFile || g_fds.p[fd].kind == kFdConsole ||
|
||||
g_fds.p[fd].kind == kFdProcess)) {
|
||||
rc = sys_close_nt(g_fds.p + fd);
|
||||
} else {
|
||||
rc = ebadf();
|
||||
}
|
||||
if (!__vforked && fd < g_fds.n) {
|
||||
__releasefd(fd);
|
||||
if (!IsWindows()) {
|
||||
rc = sys_close(fd);
|
||||
} else {
|
||||
if (fd < g_fds.n && g_fds.p[fd].kind == kFdEpoll) {
|
||||
rc = weaken(sys_close_epoll_nt)(fd);
|
||||
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdSocket) {
|
||||
rc = weaken(sys_closesocket_nt)(g_fds.p + fd);
|
||||
} else if (fd < g_fds.n && (g_fds.p[fd].kind == kFdFile ||
|
||||
g_fds.p[fd].kind == kFdConsole ||
|
||||
g_fds.p[fd].kind == kFdProcess)) {
|
||||
rc = sys_close_nt(g_fds.p + fd);
|
||||
} else {
|
||||
rc = ebadf();
|
||||
}
|
||||
}
|
||||
}
|
||||
__releasefd(fd);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
@ -74,8 +73,14 @@ char *commandv(const char *name, char pathbuf[hasatleast PATH_MAX]) {
|
|||
char *p;
|
||||
size_t namelen;
|
||||
int rc, olderr;
|
||||
if (!(namelen = strlen(name))) return PROGN(enoent(), NULL);
|
||||
if (namelen + 1 > PATH_MAX) return PROGN(enametoolong(), NULL);
|
||||
if (!(namelen = strlen(name))) {
|
||||
enoent();
|
||||
return NULL;
|
||||
}
|
||||
if (namelen + 1 > PATH_MAX) {
|
||||
enametoolong();
|
||||
return NULL;
|
||||
}
|
||||
if (strchr(name, '/') || strchr(name, '\\')) {
|
||||
if (AccessCommand(strcpy(pathbuf, ""), name, namelen, 0)) {
|
||||
return pathbuf;
|
||||
|
|
|
@ -50,7 +50,7 @@ int fallocate(int fd, int32_t mode, int64_t offset, int64_t length) {
|
|||
return rc;
|
||||
} else if (!IsWindows()) {
|
||||
return sys_posix_fallocate(fd, offset, length);
|
||||
} else if (IsWindows()) {
|
||||
} else {
|
||||
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
||||
if (mode == FALLOC_FL_ZERO_RANGE) {
|
||||
if (DeviceIoControl(
|
||||
|
@ -70,7 +70,5 @@ int fallocate(int fd, int32_t mode, int64_t offset, int64_t length) {
|
|||
} else {
|
||||
return enosys();
|
||||
}
|
||||
} else {
|
||||
return enosys();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,12 +31,10 @@ int fstat(int fd, struct stat *st) {
|
|||
if (__isfdkind(fd, kFdZip)) {
|
||||
return weaken(__zipos_fstat)(
|
||||
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, st);
|
||||
} else if (!IsWindows()) {
|
||||
if (!IsMetal()) {
|
||||
return sys_fstat(fd, st);
|
||||
} else {
|
||||
return fstat_metal(fd, st);
|
||||
}
|
||||
} else if (!IsWindows() && !IsMetal()) {
|
||||
return sys_fstat(fd, st);
|
||||
} else if (IsMetal()) {
|
||||
return fstat_metal(fd, st);
|
||||
} else {
|
||||
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
||||
return sys_fstat_nt(g_fds.p[fd].handle, st);
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/bits/pushpop.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
|
@ -26,13 +25,21 @@ STATIC_YOINK("_init_g_fds");
|
|||
|
||||
hidden struct Fds g_fds;
|
||||
|
||||
hidden void InitializeFileDescriptors(void) {
|
||||
hidden textstartup void InitializeFileDescriptors(void) {
|
||||
struct Fds *fds;
|
||||
fds = VEIL("r", &g_fds);
|
||||
pushmov(&fds->f, 3ul);
|
||||
pushmov(&fds->n, ARRAYLEN(fds->__init_p));
|
||||
fds->p = fds->__init_p;
|
||||
if (!IsMetal()) {
|
||||
if (IsMetal()) {
|
||||
pushmov(&fds->f, 3ull);
|
||||
fds->__init_p[STDIN_FILENO].kind = pushpop(kFdSerial);
|
||||
fds->__init_p[STDOUT_FILENO].kind = pushpop(kFdSerial);
|
||||
fds->__init_p[STDERR_FILENO].kind = pushpop(kFdSerial);
|
||||
fds->__init_p[STDIN_FILENO].handle = VEIL("r", 0x3F8ull);
|
||||
fds->__init_p[STDOUT_FILENO].handle = VEIL("r", 0x3F8ull);
|
||||
fds->__init_p[STDERR_FILENO].handle = VEIL("r", 0x3F8ull);
|
||||
} else if (IsWindows()) {
|
||||
pushmov(&fds->f, 3ull);
|
||||
fds->__init_p[STDIN_FILENO].kind = pushpop(kFdFile);
|
||||
fds->__init_p[STDOUT_FILENO].kind = pushpop(kFdFile);
|
||||
fds->__init_p[STDERR_FILENO].kind = pushpop(kFdFile);
|
||||
|
@ -42,12 +49,5 @@ hidden void InitializeFileDescriptors(void) {
|
|||
GetStdHandle(pushpop(kNtStdOutputHandle));
|
||||
fds->__init_p[STDERR_FILENO].handle =
|
||||
GetStdHandle(pushpop(kNtStdErrorHandle));
|
||||
} else {
|
||||
fds->__init_p[STDIN_FILENO].kind = pushpop(kFdSerial);
|
||||
fds->__init_p[STDOUT_FILENO].kind = pushpop(kFdSerial);
|
||||
fds->__init_p[STDERR_FILENO].kind = pushpop(kFdSerial);
|
||||
fds->__init_p[STDIN_FILENO].handle = 0x3F8;
|
||||
fds->__init_p[STDOUT_FILENO].handle = 0x3F8;
|
||||
fds->__init_p[STDERR_FILENO].handle = 0x3F8;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/nt/startupinfo.h"
|
||||
#include "libc/nt/struct/startupinfo.h"
|
||||
|
||||
hidden struct NtStartupInfo __nt_startupinfo;
|
||||
|
||||
STATIC_YOINK("_init___nt_startupinfo");
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
.init.start 400,_init___nt_startupinfo
|
||||
ezlea __nt_startupinfo,cx
|
||||
mov %rsp,%rbp
|
||||
ntcall __imp_GetStartupInfoW
|
||||
.init.end 400,_init___nt_startupinfo,globl,hidden
|
|
@ -1,25 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/nt/struct/systeminfo.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
|
||||
hidden struct NtSystemInfo __nt_systeminfo;
|
||||
|
||||
STATIC_YOINK("_init___nt_systeminfo");
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
.init.start 400,_init___nt_systeminfo
|
||||
ezlea __nt_systeminfo,cx
|
||||
mov %rsp,%rbp
|
||||
ntcall __imp_GetSystemInfo
|
||||
.init.end 400,_init___nt_systeminfo,globl,hidden
|
|
@ -47,10 +47,10 @@ enum FdKind {
|
|||
};
|
||||
|
||||
struct Fd {
|
||||
enum FdKind kind;
|
||||
unsigned flags;
|
||||
int64_t handle;
|
||||
int64_t extra;
|
||||
int kind;
|
||||
unsigned flags;
|
||||
};
|
||||
|
||||
struct Fds {
|
||||
|
@ -66,8 +66,6 @@ hidden extern volatile bool __interrupted;
|
|||
hidden extern int __vforked;
|
||||
hidden extern unsigned __sighandrvas[NSIG];
|
||||
hidden extern struct Fds g_fds;
|
||||
hidden extern struct NtSystemInfo __nt_systeminfo;
|
||||
hidden extern struct NtStartupInfo __nt_startupinfo;
|
||||
hidden extern const struct NtSecurityAttributes kNtIsInheritable;
|
||||
|
||||
int __reservefd(void) hidden;
|
||||
|
@ -232,6 +230,7 @@ bool32 sys_isatty_nt(int) hidden;
|
|||
char *sys_getcwd_nt(char *, size_t) hidden;
|
||||
i64 sys_lseek_nt(int, i64, int) hidden;
|
||||
int sys_chdir_nt(const char *) hidden;
|
||||
int sys_close_epoll_nt(int) hidden;
|
||||
int sys_close_nt(struct Fd *) hidden;
|
||||
int sys_dup_nt(int, int, int) hidden;
|
||||
int sys_execve_nt(const char *, char *const[], char *const[]) hidden;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "libc/calls/struct/winsize.h"
|
||||
#include "libc/nt/console.h"
|
||||
#include "libc/nt/enum/startf.h"
|
||||
#include "libc/nt/startupinfo.h"
|
||||
#include "libc/nt/struct/consolescreenbufferinfoex.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
@ -29,8 +30,10 @@
|
|||
textwindows int ioctl_tiocgwinsz_nt(int fd, struct winsize *ws) {
|
||||
int i, fds[3];
|
||||
uint32_t mode;
|
||||
struct NtStartupInfo startinfo;
|
||||
struct NtConsoleScreenBufferInfoEx sbinfo;
|
||||
fds[0] = fd, fds[1] = 1, fds[2] = 0;
|
||||
GetStartupInfo(&startinfo);
|
||||
for (i = 0; i < ARRAYLEN(fds); ++i) {
|
||||
if (__isfdkind(fds[i], kFdFile) || __isfdkind(fds[i], kFdConsole)) {
|
||||
if (GetConsoleMode(g_fds.p[fds[i]].handle, &mode)) {
|
||||
|
@ -42,9 +45,9 @@ textwindows int ioctl_tiocgwinsz_nt(int fd, struct winsize *ws) {
|
|||
ws->ws_xpixel = 0;
|
||||
ws->ws_ypixel = 0;
|
||||
return 0;
|
||||
} else if (__nt_startupinfo.dwFlags & kNtStartfUsecountchars) {
|
||||
ws->ws_col = __nt_startupinfo.dwXCountChars;
|
||||
ws->ws_row = __nt_startupinfo.dwYCountChars;
|
||||
} else if (startinfo.dwFlags & kNtStartfUsecountchars) {
|
||||
ws->ws_col = startinfo.dwXCountChars;
|
||||
ws->ws_row = startinfo.dwYCountChars;
|
||||
ws->ws_xpixel = 0;
|
||||
ws->ws_ypixel = 0;
|
||||
return 0;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
|
@ -31,7 +32,11 @@ kNtSystemDirectory:
|
|||
.previous
|
||||
|
||||
.init.start 300,_init_kNtSystemDirectory
|
||||
#if SupportsWindows()
|
||||
pushpop BYTES,%rdx
|
||||
mov __imp_GetSystemDirectoryA(%rip),%rax
|
||||
call __getntsyspath
|
||||
#else
|
||||
add $BYTES,%rdi
|
||||
#endif
|
||||
.init.end 300,_init_kNtSystemDirectory
|
||||
|
|
|
@ -32,7 +32,11 @@ kNtWindowsDirectory:
|
|||
.previous
|
||||
|
||||
.init.start 300,_init_kNtWindowsDirectory
|
||||
#if SupportsWindows()
|
||||
pushpop BYTES,%rdx
|
||||
mov __imp_GetWindowsDirectoryA(%rip),%rax
|
||||
call __getntsyspath
|
||||
#else
|
||||
add $BYTES,%rdi
|
||||
#endif
|
||||
.init.end 300,_init_kNtWindowsDirectory
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
#define kTmpPathMax 80
|
||||
|
@ -34,8 +35,12 @@ kTmpPath:
|
|||
.init.start 300,_init_kTmpPath
|
||||
movl $'/|'t<<010|'m<<020|'p<<030,(%rdi)
|
||||
movw $'/,4(%rdi)
|
||||
#if SupportsWindows()
|
||||
pushpop kTmpPathMax,%rdx
|
||||
ezlea GetTempPathA_flunk,ax
|
||||
call __getntsyspath
|
||||
#else
|
||||
add $kTmpPathMax,%rdi
|
||||
#endif
|
||||
.init.end 300,_init_kTmpPath
|
||||
.source __FILE__
|
||||
|
|
|
@ -36,7 +36,7 @@ ssize_t readv(int fd, const struct iovec *iov, int iovlen) {
|
|||
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
|
||||
return weaken(__zipos_read)(
|
||||
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, iov, iovlen, -1);
|
||||
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdSerial) {
|
||||
} else if (SupportsMetal() && fd < g_fds.n && g_fds.p[fd].kind == kFdSerial) {
|
||||
return readv_serial(&g_fds.p[fd], iov, iovlen);
|
||||
} else if (!IsWindows()) {
|
||||
return sys_readv(fd, iov, iovlen);
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
|
||||
void __releasefd(int fd) {
|
||||
int x;
|
||||
g_fds.p[fd].kind = kFdEmpty;
|
||||
do {
|
||||
x = g_fds.f;
|
||||
if (fd >= x) break;
|
||||
} while (!cmpxchg(&g_fds.f, x, fd));
|
||||
if (!__vforked && 0 <= fd && fd < g_fds.n) {
|
||||
g_fds.p[fd].kind = kFdEmpty;
|
||||
do {
|
||||
x = g_fds.f;
|
||||
if (fd >= x) break;
|
||||
} while (!cmpxchg(&g_fds.f, x, fd));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,11 +25,13 @@
|
|||
|
||||
textwindows int sys_sysinfo_nt(struct sysinfo *info) {
|
||||
struct NtMemoryStatusEx memstat;
|
||||
struct NtSystemInfo sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
memstat.dwLength = sizeof(struct NtMemoryStatusEx);
|
||||
if (GlobalMemoryStatusEx(&memstat)) {
|
||||
info->totalram = memstat.ullTotalPhys;
|
||||
info->freeram = memstat.ullAvailPhys;
|
||||
info->procs = __nt_systeminfo.dwNumberOfProcessors;
|
||||
info->procs = sysinfo.dwNumberOfProcessors;
|
||||
info->mem_unit = 1;
|
||||
return 0;
|
||||
} else {
|
||||
|
|
|
@ -39,7 +39,7 @@ ssize_t writev(int fd, const struct iovec *iov, int iovlen) {
|
|||
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
|
||||
return weaken(__zipos_write)(
|
||||
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, iov, iovlen, -1);
|
||||
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdSerial) {
|
||||
} else if (SupportsMetal() && fd < g_fds.n && g_fds.p[fd].kind == kFdSerial) {
|
||||
return writev_serial(&g_fds.p[fd], iov, iovlen);
|
||||
} else if (!IsWindows()) {
|
||||
return sys_writev(fd, iov, iovlen);
|
||||
|
|
|
@ -21,19 +21,20 @@
|
|||
#include "libc/notice.inc"
|
||||
#include "libc/runtime/internal.h"
|
||||
.section .start,"ax",@progbits
|
||||
.source __FILE__
|
||||
|
||||
nop
|
||||
.align 16
|
||||
|
||||
/ System Five userspace program entrypoint.
|
||||
/
|
||||
/ @param rsp is [n,argv₀..argvₙ₋₁,0,envp₀..,0,auxv₀..,0,..]
|
||||
/ @note FreeBSD is special (see freebsd/lib/csu/amd64/...)
|
||||
/ @noreturn
|
||||
_start: test %rdi,%rdi
|
||||
_start:
|
||||
#if SupportsFreebsd()
|
||||
test %rdi,%rdi
|
||||
cmovnz %rdi,%rsp
|
||||
jz 0f
|
||||
movb $FREEBSD,__hostos(%rip)
|
||||
#endif
|
||||
0: mov (%rsp),%ebx # argc
|
||||
lea 8(%rsp),%rsi # argv
|
||||
lea 24(%rsp,%rbx,8),%rdx # envp
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* Supported Platforms Tuning Knob (Runtime & Compile-Time)
|
||||
* Tuning this bitmask will remove platform polyfills at compile-time.
|
||||
*/
|
||||
#define SUPPORT_VECTOR 0b11111111
|
||||
#define SUPPORT_VECTOR 255
|
||||
#endif
|
||||
|
||||
#define LINUX 1
|
||||
|
@ -78,7 +78,7 @@
|
|||
#define SupportsNetbsd() ((SUPPORT_VECTOR & NETBSD) == NETBSD)
|
||||
#define SupportsBsd() (!!(SUPPORT_VECTOR & (XNU | FREEBSD | OPENBSD | NETBSD)))
|
||||
#define SupportsSystemv() \
|
||||
((SUPPORT_VECTOR & (LINUX | METAL | XNU | OPENBSD | FREEBSD | NETBSD)) != 0)
|
||||
(!!(SUPPORT_VECTOR & (LINUX | XNU | OPENBSD | FREEBSD | NETBSD)))
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
#define IsLinux() (SupportsLinux() && (__hostos & LINUX))
|
||||
|
|
215
libc/elf/elf.lds
215
libc/elf/elf.lds
|
@ -1,215 +0,0 @@
|
|||
/*-*- mode: ld-script; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-│
|
||||
│vi: set et sts=2 tw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/relocations.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Cosmopolitan ELF-Normative Linker Script.
|
||||
*
|
||||
* This linker script is an alternative to αcτµαlly pδrταblε εxεcµταblε.
|
||||
* It's intended for host-only binaries that don't need to be able to run
|
||||
* without an operating system, and don't need to be distributed. These
|
||||
* are still static executables, and they start at roughly 1kb in size.
|
||||
*
|
||||
* @see ape/ape.lds
|
||||
*/
|
||||
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS {
|
||||
. = SEGMENT_START("text-segment", IMAGE_BASE_VIRTUAL) + SIZEOF_HEADERS;
|
||||
|
||||
.real : {
|
||||
HIDDEN(_base = .);
|
||||
*(.text.real)
|
||||
HIDDEN(_ereal = .);
|
||||
}
|
||||
|
||||
.start : {
|
||||
*(.start)
|
||||
KEEP(*(.initprologue))
|
||||
KEEP(*(SORT_BY_NAME(.init.*)))
|
||||
KEEP(*(SORT_NONE(.init)))
|
||||
KEEP(*(.initepilogue))
|
||||
*(.text.startup)
|
||||
}
|
||||
|
||||
.exit : {
|
||||
*(.text.exit)
|
||||
}
|
||||
|
||||
.cold : {
|
||||
*(.text.unlikely)
|
||||
}
|
||||
|
||||
.windows : {
|
||||
*(.textwindowsprologue)
|
||||
*(.text.windows) /* ← you can flip the windows bit in -DSUPPORT_VECTOR */
|
||||
*(.textwindowsepilogue)
|
||||
}
|
||||
|
||||
.text : {
|
||||
*(SORT_BY_ALIGNMENT(.text.hot))
|
||||
KEEP(*(.keep.text))
|
||||
*(.text .text.*)
|
||||
KEEP(*(SORT_BY_NAME(.sort.text.*)))
|
||||
}
|
||||
|
||||
.test : {
|
||||
HIDDEN(__test_start = .);
|
||||
*(.test.unlikely)
|
||||
*(.test .test.*)
|
||||
}
|
||||
|
||||
.privileged : {
|
||||
. = ALIGN(DEFINED(ftrace_init) ? PAGESIZE : 1);
|
||||
HIDDEN(__privileged_start = .);
|
||||
*(.privileged)
|
||||
HIDDEN(__privileged_end = .);
|
||||
}
|
||||
|
||||
.rodata : {
|
||||
HIDDEN(__ro = .); /* ←for gdb readibility */
|
||||
|
||||
/* Read-Only Data */
|
||||
*(.rodata .rodata.*)
|
||||
KEEP(*(SORT_BY_NAME(.sort.rodata.*)))
|
||||
|
||||
/* DSO stuff */
|
||||
PROVIDE_HIDDEN(__got_plt = .);
|
||||
*(.got.plt)
|
||||
|
||||
/* Windows DLL Import Directory */
|
||||
HIDDEN(idata.ro = .);
|
||||
KEEP(*(SORT_BY_NAME(.idata.ro.*)))
|
||||
}
|
||||
|
||||
.initro : {
|
||||
/* Encoded Data Structures */
|
||||
KEEP(*(.initroprologue))
|
||||
KEEP(*(SORT_BY_NAME(.initro.*)))
|
||||
KEEP(*(.initroepilogue))
|
||||
}
|
||||
|
||||
.ubsan : {
|
||||
/* Undefined Behavior Sanitizer Types */
|
||||
PROVIDE_HIDDEN(__ubsan_types_start = .);
|
||||
*(.ubsan.types)
|
||||
PROVIDE_HIDDEN(__ubsan_types_end = .);
|
||||
PROVIDE_HIDDEN(__ubsan_data_start = .);
|
||||
*(.ubsan.data)
|
||||
PROVIDE_HIDDEN(__ubsan_data_end = .);
|
||||
}
|
||||
|
||||
HIDDEN(_etext = .);
|
||||
PROVIDE_HIDDEN(etext = .);
|
||||
|
||||
. = DATA_SEGMENT_ALIGN(CONSTANT(MAXPAGESIZE), CONSTANT(COMMONPAGESIZE));
|
||||
|
||||
.data : {
|
||||
*(.data .data.*)
|
||||
KEEP(*(SORT_BY_NAME(.sort.data.*)))
|
||||
SORT(CONSTRUCTORS)
|
||||
KEEP(*(.edata))
|
||||
. = ALIGN(__SIZEOF_POINTER__);
|
||||
HIDDEN(__piro_start = .);
|
||||
QUAD(IMAGE_BASE_VIRTUAL);
|
||||
PROVIDE_HIDDEN(__init_array_start = .);
|
||||
KEEP(*(.preinit_array))
|
||||
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)
|
||||
SORT_BY_INIT_PRIORITY(.ctors.*)))
|
||||
KEEP(*(SORT_NONE(.init_array)))
|
||||
KEEP(*(SORT_NONE(.ctors)))
|
||||
PROVIDE_HIDDEN(__init_array_end = .);
|
||||
PROVIDE_HIDDEN(__fini_array_start = .);
|
||||
KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*)
|
||||
SORT_BY_INIT_PRIORITY(.dtors.*)))
|
||||
KEEP(*(SORT_NONE(.fini_array)))
|
||||
KEEP(*(SORT_NONE(.dtors)))
|
||||
PROVIDE_HIDDEN(__fini_array_end = .);
|
||||
KEEP(*(SORT_BY_NAME(.piro.relo.sort.*)))
|
||||
*(.data.rel.ro .data.rel.ro.*)
|
||||
PROVIDE_HIDDEN(__relo_end = .);
|
||||
KEEP(*(SORT_BY_NAME(.piro.data.sort.*)))
|
||||
}
|
||||
|
||||
HIDDEN(_edata = .);
|
||||
PROVIDE_HIDDEN(edata = .);
|
||||
|
||||
.bss : {
|
||||
KEEP(*(SORT_BY_NAME(.piro.bss.init.*)))
|
||||
*(.piro.bss)
|
||||
KEEP(*(SORT_BY_NAME(.piro.bss.sort.*)))
|
||||
HIDDEN(__piro_end = .);
|
||||
*(.bss .bss.*)
|
||||
*(COMMON)
|
||||
KEEP(*(SORT_BY_NAME(.sort.bss.*)))
|
||||
. = ALIGN(ABSOLUTE(.) - IMAGE_BASE_VIRTUAL > 0x80000000 ? 0x80000000 :
|
||||
ABSOLUTE(.) - IMAGE_BASE_VIRTUAL > 0x200000 ? 0x200000 : 0x1000);
|
||||
*(.xlm)
|
||||
. = ALIGN(ABSOLUTE(.) - IMAGE_BASE_VIRTUAL > 0x80000000 ? 0x80000000 :
|
||||
ABSOLUTE(.) - IMAGE_BASE_VIRTUAL > 0x200000 ? 0x200000 : 0x1000);
|
||||
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 1);
|
||||
}
|
||||
|
||||
HIDDEN(_end = .);
|
||||
PROVIDE_HIDDEN(end = .);
|
||||
|
||||
.gnu_debuglink 0 : { *(.gnu_debuglink) }
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
.stab.excl 0 : { *(.stab.excl) }
|
||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||
.stab.index 0 : { *(.stab.index) }
|
||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||
.debug 0 : { *(.debug) }
|
||||
.line 0 : { *(.line) }
|
||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||
.debug_aranges 0 : { *(.debug_aranges) }
|
||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
|
||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }
|
||||
.debug_frame 0 : { *(.debug_frame) }
|
||||
.debug_str 0 : { *(.debug_str) }
|
||||
.debug_loc 0 : { *(.debug_loc) }
|
||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||
.debug_weaknames 0 : { *(.debug_weaknames) }
|
||||
.debug_funcnames 0 : { *(.debug_funcnames) }
|
||||
.debug_typenames 0 : { *(.debug_typenames) }
|
||||
.debug_varnames 0 : { *(.debug_varnames) }
|
||||
.debug_pubtypes 0 : { *(.debug_pubtypes) }
|
||||
.debug_ranges 0 : { *(.debug_ranges) }
|
||||
.debug_macro 0 : { *(.debug_macro) }
|
||||
.debug_addr 0 : { *(.debug_addr) }
|
||||
.gnu.attributes 0 : { KEEP(*(.gnu.attributes)) }
|
||||
.GCC.command.line 0 : { *(.GCC.command.line) }
|
||||
|
||||
/DISCARD/ : {
|
||||
*(.comment)
|
||||
*(.discard)
|
||||
*(.yoink)
|
||||
*(.*)
|
||||
}
|
||||
}
|
||||
|
||||
HIDDEN(__privileged_addr = ROUNDDOWN(__privileged_start, PAGESIZE));
|
||||
HIDDEN(__privileged_size = (ROUNDUP(__privileged_end, PAGESIZE) -
|
||||
ROUNDDOWN(__privileged_start, PAGESIZE)));
|
|
@ -40,10 +40,6 @@ $(LIBC_ELF_A).pkg: \
|
|||
$(LIBC_ELF_A_OBJS) \
|
||||
$(foreach x,$(LIBC_ELF_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/libc/elf/elf.lds: \
|
||||
libc/elf/elf.lds \
|
||||
ape/relocations.h
|
||||
|
||||
LIBC_ELF_LIBS = $(foreach x,$(LIBC_ELF_ARTIFACTS),$($(x)))
|
||||
LIBC_ELF_SRCS = $(foreach x,$(LIBC_ELF_ARTIFACTS),$($(x)_SRCS))
|
||||
LIBC_ELF_HDRS = $(foreach x,$(LIBC_ELF_ARTIFACTS),$($(x)_HDRS))
|
||||
|
|
|
@ -294,7 +294,7 @@ XDEV\000\
|
|||
XFULL\000\
|
||||
\000";
|
||||
|
||||
const char *geterrname(long code) {
|
||||
static const char *geterrname(long code) {
|
||||
const long *e;
|
||||
size_t i, n;
|
||||
e = &E2BIG;
|
||||
|
@ -313,17 +313,16 @@ const char *geterrname(long code) {
|
|||
*/
|
||||
int strerror_r(int err, char *buf, size_t size) {
|
||||
const char *s;
|
||||
char16_t buf16[100];
|
||||
int winstate, sysvstate;
|
||||
if (err == -1 || IsTiny()) {
|
||||
s = "?";
|
||||
} else {
|
||||
s = firstnonnull(geterrname(err), "?");
|
||||
}
|
||||
if (!SupportsWindows()) {
|
||||
DebugBreak();
|
||||
snprintf(buf, size, "E%s[%d]", s, err);
|
||||
} else {
|
||||
char16_t buf16[100];
|
||||
int winstate, sysvstate;
|
||||
winstate = GetLastError();
|
||||
sysvstate = errno;
|
||||
if (FormatMessage(
|
||||
|
|
|
@ -28,17 +28,17 @@ COSMOPOLITAN_C_START_
|
|||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
#define LZ4_MAGIC(FRAME) READ32LE(FRAME)
|
||||
#define LZ4_FRAME_VERSION(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 6) & 0b11)
|
||||
#define LZ4_FRAME_VERSION(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 6) & 3)
|
||||
#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1)
|
||||
#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1)
|
||||
#define LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 3) & 1)
|
||||
#define LZ4_FRAME_BLOCKCONTENTCHECKSUMFLAG(FRAME) \
|
||||
((_LZ4_FRAME_FLG(FRAME) >> 2) & 1)
|
||||
#define LZ4_FRAME_DICTIONARYIDFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 0) & 1)
|
||||
#define LZ4_FRAME_BLOCKMAXSIZE(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 4) & 0b111)
|
||||
#define LZ4_FRAME_BLOCKMAXSIZE(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 4) & 7)
|
||||
#define LZ4_FRAME_RESERVED1(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 1) & 1)
|
||||
#define LZ4_FRAME_RESERVED2(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 7) & 1)
|
||||
#define LZ4_FRAME_RESERVED3(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 0) & 0b1111)
|
||||
#define LZ4_FRAME_RESERVED3(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 0) & 15)
|
||||
#define LZ4_FRAME_BLOCKCONTENTSIZE(FRAME) \
|
||||
(LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? READ64LE((FRAME) + 4 + 1 + 1) : 0)
|
||||
#define LZ4_FRAME_DICTIONARYID(FRAME) \
|
||||
|
|
|
@ -110,7 +110,12 @@ MemCpy: .leafprologue
|
|||
.L1: mov (%rsi),%cl
|
||||
mov %cl,(%rdi)
|
||||
jmp .L0
|
||||
.Lerms: cmp kHalfCache3(%rip),%rdx
|
||||
.Lerms:
|
||||
#ifdef TINY
|
||||
cmp $1024*1024,%rdx
|
||||
#else
|
||||
cmp kHalfCache3(%rip),%rdx
|
||||
#endif
|
||||
ja .Lnts
|
||||
push %rdi
|
||||
push %rsi
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
#define COSMOPOLITAN_LIBC_NEXGEN32E_X86INFO_H_
|
||||
#include "libc/nexgen32e/kcpuids.h"
|
||||
|
||||
#define kX86CpuStepping ((KCPUIDS(1H, EAX) >> 0) & 0b1111)
|
||||
#define kX86CpuModelid ((KCPUIDS(1H, EAX) >> 4) & 0b1111)
|
||||
#define kX86CpuFamilyid ((KCPUIDS(1H, EAX) >> 8) & 0b1111)
|
||||
#define kX86CpuType ((KCPUIDS(1H, EAX) >> 12) & 0b11)
|
||||
#define kX86CpuExtmodelid ((KCPUIDS(1H, EAX) >> 16) & 0b1111)
|
||||
#define kX86CpuExtfamilyid ((KCPUIDS(1H, EAX) >> 20) & 0b11111111)
|
||||
#define kX86CpuStepping ((KCPUIDS(1H, EAX) >> 0) & 15)
|
||||
#define kX86CpuModelid ((KCPUIDS(1H, EAX) >> 4) & 15)
|
||||
#define kX86CpuFamilyid ((KCPUIDS(1H, EAX) >> 8) & 15)
|
||||
#define kX86CpuType ((KCPUIDS(1H, EAX) >> 12) & 3)
|
||||
#define kX86CpuExtmodelid ((KCPUIDS(1H, EAX) >> 16) & 15)
|
||||
#define kX86CpuExtfamilyid ((KCPUIDS(1H, EAX) >> 20) & 255)
|
||||
|
||||
#define kX86CpuFamily \
|
||||
(kX86CpuFamilyid + (kX86CpuFamily == 15 ? kX86CpuExtfamilyid : 0))
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "libc/sysv/consts/nr.h"
|
||||
#include "libc/macros.h"
|
||||
.privileged
|
||||
.source __FILE__
|
||||
|
||||
/ Terminates program abnormally.
|
||||
/
|
||||
|
@ -38,8 +37,10 @@ abort: push %rbp
|
|||
mov %rsp,%rbp
|
||||
and $-16,%rsp
|
||||
sub $16,%rsp
|
||||
#if SupportsWindows()
|
||||
testb IsWindows()
|
||||
jnz 2f
|
||||
jnz sys_abort_nt
|
||||
#endif
|
||||
mov SIG_SETMASK,%edi
|
||||
mov %rsp,%rsi
|
||||
push $0xffffffffffffffdf # all bits blocked but SIGABRT
|
||||
|
@ -56,5 +57,5 @@ abort: push %rbp
|
|||
mov SIGABRT,%esi
|
||||
mov __NR_kill,%eax
|
||||
syscall # avoid hook and less bt noise
|
||||
2: call sys_abort_nt
|
||||
call _Exit
|
||||
.endfn abort,globl,protected
|
||||
|
|
|
@ -30,23 +30,6 @@
|
|||
_construct:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
ezlea __init_array_start,ax # static ctors in forward order
|
||||
.weak __init_array_start # could be called multiple times
|
||||
ezlea __init_array_end,cx # idempotency recommended
|
||||
.weak __init_array_end # @see ape/ape.lds
|
||||
1: cmp %rax,%rcx
|
||||
je 2f
|
||||
push %rax
|
||||
push %rcx
|
||||
mov %r12,%rdi
|
||||
mov %r13,%rsi
|
||||
mov %r14,%rdx
|
||||
mov %r15,%rcx
|
||||
call *(%rax)
|
||||
pop %rcx
|
||||
pop %rax
|
||||
add $8,%rax
|
||||
jmp 1b
|
||||
2: pop %rbp
|
||||
pop %rbp
|
||||
ret
|
||||
.endfn _construct,globl
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/dce.h"
|
||||
.text.startup
|
||||
.source __FILE__
|
||||
|
||||
/ Cosmopolitan runtime.
|
||||
/
|
||||
|
@ -34,30 +33,48 @@
|
|||
/ @noreturn
|
||||
cosmo: push %rbp
|
||||
mov %rsp,%rbp
|
||||
ezlea _base,bx
|
||||
mov %edi,%r12d
|
||||
mov %rsi,%r13
|
||||
mov %rdx,%r14
|
||||
mov %rcx,%r15
|
||||
#ifdef __FAST_MATH__
|
||||
call __fast_math
|
||||
push %rax
|
||||
stmxcsr (%rsp)
|
||||
orl $0x8040,(%rsp)
|
||||
ldmxcsr (%rsp)
|
||||
pop %rax
|
||||
#endif
|
||||
call _init
|
||||
call _construct
|
||||
ezlea __init_array_start,ax # static ctors in forward order
|
||||
.weak __init_array_start # could be called multiple times
|
||||
ezlea __init_array_end,cx # idempotency recommended
|
||||
.weak __init_array_end # @see ape/ape.lds
|
||||
1: cmp %rax,%rcx
|
||||
je 2f
|
||||
push %rax
|
||||
push %rcx
|
||||
call .Largs
|
||||
call *(%rax)
|
||||
pop %rcx
|
||||
pop %rax
|
||||
add $8,%rax
|
||||
jmp 1b
|
||||
2: nop
|
||||
#if !IsTrustworthy()
|
||||
mov $PROT_READ,%edi
|
||||
call _piro
|
||||
#endif
|
||||
mov %r12d,%edi
|
||||
mov %r13,%rsi
|
||||
mov %r14,%rdx
|
||||
mov %r15,%rcx
|
||||
call .Largs
|
||||
.weak main
|
||||
call main
|
||||
xchg %eax,%edi
|
||||
call exit
|
||||
.endfn cosmo,weak,hidden
|
||||
ud2
|
||||
.Largs: mov %r12d,%edi
|
||||
mov %r13,%rsi
|
||||
mov %r14,%rdx
|
||||
mov %r15,%rcx
|
||||
ret
|
||||
.endfn cosmo,weak
|
||||
|
||||
#ifdef __PG__
|
||||
.init.start 800,_init_ftrace
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/notice.inc"
|
||||
.text.startup
|
||||
.source __FILE__
|
||||
|
||||
/ Intel Manual V.1 §10.2.3 - MXCSR Control and Status Register
|
||||
#define MXCSR_DE (1 << 1) /* Denormal Flag */
|
||||
#define MXCSR_DAZ (1 << 6) /* Denormals Are Zeros */
|
||||
#define MXCSR_DM (1 << 8) /* Denormal Operation Mask */
|
||||
#define MXCSR_FTZ (1 << 15) /* Flush to Zero */
|
||||
|
||||
/ Initializes fast math.
|
||||
/
|
||||
/ “Seymour Cray didn't care that 81.0/3.0 did not give exactly
|
||||
/ 27.0 on the CDC 6000 class machines, and he was universally
|
||||
/ respected for making the fastest machines around.
|
||||
/ ──Linus Torvalds
|
||||
__fast_math:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
push %rax
|
||||
stmxcsr (%rsp)
|
||||
orl $MXCSR_FTZ+MXCSR_DAZ,(%rsp)
|
||||
ldmxcsr (%rsp)
|
||||
leave
|
||||
ret
|
||||
.endfn __fast_math,globl
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/interruptiblecall.h"
|
||||
|
@ -53,7 +52,8 @@ intptr_t interruptiblecall(struct InterruptibleCall *icall,
|
|||
icall->sa_new.sa_handler = interruptcall;
|
||||
icall->sa_new.sa_flags |= SA_RESTART | SA_RESETHAND;
|
||||
if ((rc = (sigaction)(icall->sig, &icall->sa_new, &icall->sa_old)) != -1) {
|
||||
g_interruptiblecall = PROGN((icall->prev = g_interruptiblecall), icall);
|
||||
icall->prev = g_interruptiblecall;
|
||||
g_interruptiblecall = icall;
|
||||
if (!setjmp(icall->jb)) {
|
||||
icall->returnval = rc = callback(p1, p2, p3, p4);
|
||||
} else {
|
||||
|
|
|
@ -69,7 +69,6 @@ int mprotect(void *, uint64_t, int) privileged;
|
|||
int msync(void *, size_t, int);
|
||||
void __print(const void *, size_t);
|
||||
void __print_string(const char *);
|
||||
void __fast_math(void);
|
||||
void *sbrk(intptr_t);
|
||||
int brk(void *);
|
||||
int NtGetVersion(void);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/runtime/memtrack.h"
|
||||
|
||||
|
@ -23,5 +24,9 @@ int UntrackMemoryIntervals(void *addr, size_t size) {
|
|||
int a, b;
|
||||
a = ROUNDDOWN((intptr_t)addr, FRAMESIZE) >> 16;
|
||||
b = ROUNDDOWN((intptr_t)addr + size - 1, FRAMESIZE) >> 16;
|
||||
return ReleaseMemoryIntervals(&_mmi, a, b, ReleaseMemoryNt);
|
||||
if (SupportsWindows()) {
|
||||
return ReleaseMemoryIntervals(&_mmi, a, b, ReleaseMemoryNt);
|
||||
} else {
|
||||
return ReleaseMemoryIntervals(&_mmi, a, b, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1399,7 +1399,7 @@ err:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static textwindows noinline int sys_close_epoll_nt(int fd) {
|
||||
textwindows int sys_close_epoll_nt(int fd) {
|
||||
struct PortState *port_state;
|
||||
struct TsTreeNode *tree_node;
|
||||
if (wepoll_init() < 0) return -1;
|
||||
|
@ -1417,14 +1417,6 @@ err:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int sys_close_epoll(int fd) {
|
||||
if (!IsWindows()) {
|
||||
return sys_close(fd);
|
||||
} else {
|
||||
return sys_close_epoll_nt(fd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new epoll instance.
|
||||
*
|
||||
|
@ -1448,7 +1440,7 @@ int epoll_create1(int flags) {
|
|||
int fd;
|
||||
if (flags & ~O_CLOEXEC) return einval();
|
||||
if (!IsWindows()) {
|
||||
return __ensurefds(__fixupnewfd(sys_epoll_create(1337), flags));
|
||||
return __fixupnewfd(sys_epoll_create(1337), flags);
|
||||
} else {
|
||||
return sys_epoll_create1_nt(flags);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/dirent.h"
|
||||
#include "libc/dce.h"
|
||||
|
@ -47,8 +46,8 @@
|
|||
* Directory stream object.
|
||||
*/
|
||||
struct dirstream {
|
||||
int64_t tell;
|
||||
int64_t fd;
|
||||
int64_t tell;
|
||||
struct dirent ent;
|
||||
union {
|
||||
struct {
|
||||
|
@ -98,24 +97,48 @@ struct dirent_netbsd {
|
|||
char d_name[512];
|
||||
};
|
||||
|
||||
static textwindows noinline DIR *opendir_nt(const char *name) {
|
||||
int len;
|
||||
static textwindows DIR *opendir_nt_impl(char16_t name[PATH_MAX], size_t len) {
|
||||
DIR *res;
|
||||
char16_t name16[PATH_MAX];
|
||||
if ((len = __mkntpath(name, name16)) == -1) return NULL;
|
||||
if (len + 2 + 1 > PATH_MAX) return PROGN(enametoolong(), NULL);
|
||||
while (name16[len - 1] == u'\\') name16[--len] = u'\0';
|
||||
name16[len++] = u'\\';
|
||||
name16[len++] = u'*';
|
||||
name16[len] = u'\0';
|
||||
if (!(res = calloc(1, sizeof(DIR)))) return NULL;
|
||||
if ((res->fd = FindFirstFile(name16, &res->windata)) != -1) {
|
||||
return res;
|
||||
if (len + 2 + 1 <= PATH_MAX) {
|
||||
if (name[len - 1] != u'\\') name[len++] = u'\\';
|
||||
name[len++] = u'*';
|
||||
name[len] = u'\0';
|
||||
if ((res = calloc(1, sizeof(DIR)))) {
|
||||
if ((res->fd = FindFirstFile(name, &res->windata)) != -1) {
|
||||
return res;
|
||||
} else {
|
||||
__winerr();
|
||||
}
|
||||
free(res);
|
||||
}
|
||||
} else {
|
||||
__winerr();
|
||||
free(res);
|
||||
return NULL;
|
||||
enametoolong();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static textwindows noinline DIR *opendir_nt(const char *path) {
|
||||
int len;
|
||||
char16_t name[PATH_MAX];
|
||||
if ((len = __mkntpath(path, name)) == -1) return NULL;
|
||||
return opendir_nt_impl(name, len);
|
||||
}
|
||||
|
||||
static textwindows noinline DIR *fdopendir_nt(int fd) {
|
||||
DIR *res;
|
||||
char16_t name[PATH_MAX];
|
||||
if (__isfdkind(fd, kFdFile)) {
|
||||
if ((res = opendir_nt_impl(
|
||||
name, GetFinalPathNameByHandle(
|
||||
g_fds.p[fd].handle, name, ARRAYLEN(name),
|
||||
kNtFileNameNormalized | kNtVolumeNameDos)))) {
|
||||
close(fd);
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
ebadf();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static textwindows noinline struct dirent *readdir_nt(DIR *dir) {
|
||||
|
@ -193,14 +216,12 @@ DIR *opendir(const char *name) {
|
|||
DIR *fdopendir(int fd) {
|
||||
DIR *dir;
|
||||
if (!IsWindows()) {
|
||||
if ((dir = calloc(1, sizeof(*dir)))) {
|
||||
dir->fd = fd;
|
||||
return dir;
|
||||
}
|
||||
if (!(dir = calloc(1, sizeof(*dir)))) return NULL;
|
||||
dir->fd = fd;
|
||||
return dir;
|
||||
} else {
|
||||
enosys(); /* TODO(jart): Implement me! */
|
||||
return fdopendir_nt(fd);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -221,7 +242,7 @@ struct dirent *readdir(DIR *dir) {
|
|||
struct dirent_openbsd *obsd;
|
||||
if (!IsWindows()) {
|
||||
if (dir->buf_pos >= dir->buf_end) {
|
||||
basep = dir->tell; /* <- what does xnu do */
|
||||
basep = dir->tell; /* TODO(jart): what does xnu do */
|
||||
rc = getdents(dir->fd, dir->buf, sizeof(dir->buf) - 256, &basep);
|
||||
if (!rc || rc == -1) return NULL;
|
||||
dir->buf_pos = 0;
|
||||
|
@ -295,5 +316,6 @@ long telldir(DIR *dir) {
|
|||
* Returns file descriptor associated with DIR object.
|
||||
*/
|
||||
int dirfd(DIR *dir) {
|
||||
if (IsWindows()) return eopnotsupp();
|
||||
return dir->fd;
|
||||
}
|
||||
|
|
2
libc/sysv/consts/ABDAY_1.S
Normal file
2
libc/sysv/consts/ABDAY_1.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ABDAY_1 0x020000 14 14 13 13 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ABDAY_1 0x020000 14 14 13 13 0
|
2
libc/sysv/consts/ABDAY_2.S
Normal file
2
libc/sysv/consts/ABDAY_2.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ABDAY_2 0x020001 15 15 14 14 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ABDAY_2 0x020001 15 15 14 14 0
|
2
libc/sysv/consts/ABDAY_3.S
Normal file
2
libc/sysv/consts/ABDAY_3.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ABDAY_3 0x020002 0x10 0x10 15 15 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ABDAY_3 0x020002 0x10 0x10 15 15 0
|
2
libc/sysv/consts/ABDAY_4.S
Normal file
2
libc/sysv/consts/ABDAY_4.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ABDAY_4 0x020003 17 17 0x10 0x10 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ABDAY_4 0x020003 17 17 0x10 0x10 0
|
2
libc/sysv/consts/ABDAY_5.S
Normal file
2
libc/sysv/consts/ABDAY_5.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ABDAY_5 0x020004 18 18 17 17 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ABDAY_5 0x020004 18 18 17 17 0
|
2
libc/sysv/consts/ABDAY_6.S
Normal file
2
libc/sysv/consts/ABDAY_6.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ABDAY_6 0x020005 19 19 18 18 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ABDAY_6 0x020005 19 19 18 18 0
|
2
libc/sysv/consts/ABDAY_7.S
Normal file
2
libc/sysv/consts/ABDAY_7.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ABDAY_7 0x020006 20 20 19 19 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ABDAY_7 0x020006 20 20 19 19 0
|
2
libc/sysv/consts/ABORTED_COMMAND.S
Normal file
2
libc/sysv/consts/ABORTED_COMMAND.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ABORTED_COMMAND 11 0 0 0 0 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ABORTED_COMMAND 11 0 0 0 0 0
|
2
libc/sysv/consts/ACCOUNTING.S
Normal file
2
libc/sysv/consts/ACCOUNTING.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ACCOUNTING 9 9 0 0 0 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ACCOUNTING 9 9 0 0 0 0
|
2
libc/sysv/consts/ACCT_BYTEORDER.S
Normal file
2
libc/sysv/consts/ACCT_BYTEORDER.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ACCT_BYTEORDER 0 0 0 0 0 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ACCT_BYTEORDER 0 0 0 0 0 0
|
2
libc/sysv/consts/ACCT_COMM.S
Normal file
2
libc/sysv/consts/ACCT_COMM.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ACCT_COMM 0x10 0 0 0 0 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ACCT_COMM 0x10 0 0 0 0 0
|
2
libc/sysv/consts/ACK.S
Normal file
2
libc/sysv/consts/ACK.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ACK 4 4 4 4 4 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ACK 4 4 4 4 4 0
|
2
libc/sysv/consts/ACORE.S
Normal file
2
libc/sysv/consts/ACORE.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc ACORE 0 8 8 8 8 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc ACORE 0 8 8 8 8 0
|
2
libc/sysv/consts/ADDR_COMPAT_LAYOUT.S
Normal file
2
libc/sysv/consts/ADDR_COMPAT_LAYOUT.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon prsnlty ADDR_COMPAT_LAYOUT 0x0200000 -1 -1 -1 -1 -1
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon prsnlty ADDR_COMPAT_LAYOUT 0x0200000 -1 -1 -1 -1 -1
|
2
libc/sysv/consts/ADDR_LIMIT_32BIT.S
Normal file
2
libc/sysv/consts/ADDR_LIMIT_32BIT.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon prsnlty ADDR_LIMIT_32BIT 0x0800000 -1 -1 -1 -1 -1
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon prsnlty ADDR_LIMIT_32BIT 0x0800000 -1 -1 -1 -1 -1
|
2
libc/sysv/consts/ADDR_LIMIT_3GB.S
Normal file
2
libc/sysv/consts/ADDR_LIMIT_3GB.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon prsnlty ADDR_LIMIT_3GB 0x8000000 -1 -1 -1 -1 -1
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon prsnlty ADDR_LIMIT_3GB 0x8000000 -1 -1 -1 -1 -1
|
2
libc/sysv/consts/ADDR_NO_RANDOMIZE.S
Normal file
2
libc/sysv/consts/ADDR_NO_RANDOMIZE.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon prsnlty ADDR_NO_RANDOMIZE 0x0040000 -1 -1 -1 -1 -1
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon prsnlty ADDR_NO_RANDOMIZE 0x0040000 -1 -1 -1 -1 -1
|
2
libc/sysv/consts/AFORK.S
Normal file
2
libc/sysv/consts/AFORK.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon misc AFORK 0 1 1 1 1 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon misc AFORK 0 1 1 1 1 0
|
2
libc/sysv/consts/AF_ALG.S
Normal file
2
libc/sysv/consts/AF_ALG.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af AF_ALG 38 0 0 0 0 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon af AF_ALG 38 0 0 0 0 0
|
2
libc/sysv/consts/AF_APPLETALK.S
Normal file
2
libc/sysv/consts/AF_APPLETALK.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af AF_APPLETALK 5 0x10 0x10 0x10 0x10 0x10
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon af AF_APPLETALK 5 0x10 0x10 0x10 0x10 0x10
|
2
libc/sysv/consts/AF_ASH.S
Normal file
2
libc/sysv/consts/AF_ASH.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af AF_ASH 18 0 0 0 0 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon af AF_ASH 18 0 0 0 0 0
|
2
libc/sysv/consts/AF_ATMPVC.S
Normal file
2
libc/sysv/consts/AF_ATMPVC.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af AF_ATMPVC 8 0 0 0 0 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon af AF_ATMPVC 8 0 0 0 0 0
|
2
libc/sysv/consts/AF_ATMSVC.S
Normal file
2
libc/sysv/consts/AF_ATMSVC.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af AF_ATMSVC 20 0 0 0 0 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon af AF_ATMSVC 20 0 0 0 0 0
|
2
libc/sysv/consts/AF_AX25.S
Normal file
2
libc/sysv/consts/AF_AX25.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af AF_AX25 3 0 0 0 0 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon af AF_AX25 3 0 0 0 0 0
|
2
libc/sysv/consts/AF_BLUETOOTH.S
Normal file
2
libc/sysv/consts/AF_BLUETOOTH.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af AF_BLUETOOTH 31 0 36 0x20 31 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon af AF_BLUETOOTH 31 0 36 0x20 31 0
|
2
libc/sysv/consts/AF_BRIDGE.S
Normal file
2
libc/sysv/consts/AF_BRIDGE.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af AF_BRIDGE 7 0 0 0 0 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon af AF_BRIDGE 7 0 0 0 0 0
|
2
libc/sysv/consts/AF_CAIF.S
Normal file
2
libc/sysv/consts/AF_CAIF.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af AF_CAIF 37 0 0 0 0 0
|
|
@ -1,2 +0,0 @@
|
|||
.include "libc/sysv/consts/syscon.inc"
|
||||
.syscon af AF_CAIF 37 0 0 0 0 0
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue