mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Introduce #include <cosmo.h>
to toolchain users
This change improves the way internal APIs are being hidden behind the `COSMO` define. The cosmo.h header will take care of defining that, so that a separate define statement isn't needed. This change also does a lot more to define which APIs are standard, and which belong to Cosmo.
This commit is contained in:
parent
9b55dbe417
commit
4a59210008
115 changed files with 699 additions and 422 deletions
|
@ -2,7 +2,7 @@
|
||||||
│vi: set et sts=2 tw=2 fenc=utf-8 :vi│
|
│vi: set et sts=2 tw=2 fenc=utf-8 :vi│
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/thread/tls.h"
|
#include "libc/thread/tls.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
ENTRY(_start)
|
ENTRY(_start)
|
||||||
OUTPUT_ARCH(aarch64)
|
OUTPUT_ARCH(aarch64)
|
||||||
|
@ -12,8 +12,9 @@ OUTPUT_FORMAT("elf64-littleaarch64",
|
||||||
|
|
||||||
SECTIONS {
|
SECTIONS {
|
||||||
|
|
||||||
__executable_start = SEGMENT_START("text-segment", IMAGE_BASE_VIRTUAL);
|
. = SEGMENT_START("text-segment", IMAGE_BASE_VIRTUAL);
|
||||||
. = SEGMENT_START("text-segment", IMAGE_BASE_VIRTUAL) + SIZEOF_HEADERS;
|
__executable_start = .;
|
||||||
|
. += SIZEOF_HEADERS;
|
||||||
|
|
||||||
.interp : { *(.interp) }
|
.interp : { *(.interp) }
|
||||||
.note.gnu.build-id : { *(.note.gnu.build-id) }
|
.note.gnu.build-id : { *(.note.gnu.build-id) }
|
||||||
|
@ -271,7 +272,7 @@ SECTIONS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ape_stack_memsz = DEFINED(ape_stack_memsz) ? ape_stack_memsz : STACKSIZE;
|
ape_stack_memsz = DEFINED(ape_stack_memsz) ? ape_stack_memsz : APE_STACKSIZE;
|
||||||
_tls_size = _tbss_end - _tdata_start;
|
_tls_size = _tbss_end - _tdata_start;
|
||||||
_tdata_size = _tdata_end - _tdata_start;
|
_tdata_size = _tdata_end - _tdata_start;
|
||||||
_tbss_size = _tbss_end - _tbss_start;
|
_tbss_size = _tbss_end - _tbss_start;
|
||||||
|
|
30
ape/ape.lds
30
ape/ape.lds
|
@ -182,7 +182,7 @@
|
||||||
#include "libc/nt/pedef.internal.h"
|
#include "libc/nt/pedef.internal.h"
|
||||||
#include "libc/thread/tls.h"
|
#include "libc/thread/tls.h"
|
||||||
#include "ape/ape.internal.h"
|
#include "ape/ape.internal.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/* uncomment if .com.dbg won't execute on your kernel (will break .com file) */
|
/* uncomment if .com.dbg won't execute on your kernel (will break .com file) */
|
||||||
/* #define APE_FIX_COM_DBG */
|
/* #define APE_FIX_COM_DBG */
|
||||||
|
@ -257,7 +257,7 @@ SECTIONS {
|
||||||
HIDDEN(ape_macho_end = .);
|
HIDDEN(ape_macho_end = .);
|
||||||
|
|
||||||
KEEP(*(.ape.pad.head))
|
KEEP(*(.ape.pad.head))
|
||||||
. = ALIGN(SupportsWindows() || SupportsMetal() ? PAGESIZE : 16);
|
. = ALIGN(SupportsWindows() || SupportsMetal() ? 4096 : 16);
|
||||||
HIDDEN(_ehead = .);
|
HIDDEN(_ehead = .);
|
||||||
} :Head
|
} :Head
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ SECTIONS {
|
||||||
|
|
||||||
/* Privileged code invulnerable to magic */
|
/* Privileged code invulnerable to magic */
|
||||||
KEEP(*(.ape.pad.privileged));
|
KEEP(*(.ape.pad.privileged));
|
||||||
. = ALIGN(__privileged_end > __privileged_start ? PAGESIZE : 1);
|
. = ALIGN(__privileged_end > __privileged_start ? 4096 : 1);
|
||||||
/*END: morphable code */
|
/*END: morphable code */
|
||||||
__privileged_start = .;
|
__privileged_start = .;
|
||||||
*(.privileged)
|
*(.privileged)
|
||||||
|
@ -367,7 +367,7 @@ SECTIONS {
|
||||||
KEEP(*(SORT_BY_NAME(.sort.rodata.*)))
|
KEEP(*(SORT_BY_NAME(.sort.rodata.*)))
|
||||||
|
|
||||||
KEEP(*(.ape.pad.text))
|
KEEP(*(.ape.pad.text))
|
||||||
. = ALIGN(PAGESIZE);
|
. = ALIGN(4096);
|
||||||
HIDDEN(_etext = .);
|
HIDDEN(_etext = .);
|
||||||
PROVIDE_HIDDEN(etext = .);
|
PROVIDE_HIDDEN(etext = .);
|
||||||
/*END: Read Only Data (only needed for initialization) */
|
/*END: Read Only Data (only needed for initialization) */
|
||||||
|
@ -380,7 +380,7 @@ SECTIONS {
|
||||||
*(SORT_BY_ALIGNMENT(.tdata))
|
*(SORT_BY_ALIGNMENT(.tdata))
|
||||||
*(SORT_BY_ALIGNMENT(.tdata.*))
|
*(SORT_BY_ALIGNMENT(.tdata.*))
|
||||||
_tdata_end = .;
|
_tdata_end = .;
|
||||||
. = ALIGN(PAGESIZE);
|
. = ALIGN(4096);
|
||||||
} :Tls :Rom
|
} :Tls :Rom
|
||||||
/*END: Read Only Data */
|
/*END: Read Only Data */
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ SECTIONS {
|
||||||
_tbss_end = .;
|
_tbss_end = .;
|
||||||
} :Tls
|
} :Tls
|
||||||
|
|
||||||
.data ALIGN(PAGESIZE) : {
|
.data ALIGN(4096) : {
|
||||||
/*BEGIN: Read/Write Data */
|
/*BEGIN: Read/Write Data */
|
||||||
KEEP(*(SORT_BY_NAME(.piro.data.sort.iat.*)))
|
KEEP(*(SORT_BY_NAME(.piro.data.sort.iat.*)))
|
||||||
/*BEGIN: NT FORK COPYING */
|
/*BEGIN: NT FORK COPYING */
|
||||||
|
@ -426,7 +426,7 @@ SECTIONS {
|
||||||
PROVIDE_HIDDEN(edata = .);
|
PROVIDE_HIDDEN(edata = .);
|
||||||
KEEP(*(SORT_BY_NAME(.zip.*)))
|
KEEP(*(SORT_BY_NAME(.zip.*)))
|
||||||
HIDDEN(_ezip = .);
|
HIDDEN(_ezip = .);
|
||||||
. = ALIGN(PAGESIZE);
|
. = ALIGN(4096);
|
||||||
} :Ram
|
} :Ram
|
||||||
|
|
||||||
/*END: file content that's loaded by o/s */
|
/*END: file content that's loaded by o/s */
|
||||||
|
@ -452,7 +452,7 @@ SECTIONS {
|
||||||
|
|
||||||
KEEP(*(.bssepilogue))
|
KEEP(*(.bssepilogue))
|
||||||
/*END: NT FORK COPYING */
|
/*END: NT FORK COPYING */
|
||||||
. = ALIGN(PAGESIZE);
|
. = ALIGN(4096);
|
||||||
HIDDEN(_end = .);
|
HIDDEN(_end = .);
|
||||||
PROVIDE_HIDDEN(end = .);
|
PROVIDE_HIDDEN(end = .);
|
||||||
} :Bss
|
} :Bss
|
||||||
|
@ -525,7 +525,7 @@ HIDDEN(ape_rom_vaddr = ADDR(.head));
|
||||||
HIDDEN(ape_rom_paddr = LOADADDR(.head));
|
HIDDEN(ape_rom_paddr = LOADADDR(.head));
|
||||||
HIDDEN(ape_rom_filesz = LOADADDR(.data) - ape_rom_paddr);
|
HIDDEN(ape_rom_filesz = LOADADDR(.data) - ape_rom_paddr);
|
||||||
HIDDEN(ape_rom_memsz = ADDR(.data) - ADDR(.head));
|
HIDDEN(ape_rom_memsz = ADDR(.data) - ADDR(.head));
|
||||||
HIDDEN(ape_rom_align = PAGESIZE);
|
HIDDEN(ape_rom_align = 4096);
|
||||||
HIDDEN(ape_rom_rva = RVA(ape_rom_vaddr));
|
HIDDEN(ape_rom_rva = RVA(ape_rom_vaddr));
|
||||||
|
|
||||||
HIDDEN(ape_ram_offset = ape_rom_offset + ape_rom_filesz);
|
HIDDEN(ape_ram_offset = ape_rom_offset + ape_rom_filesz);
|
||||||
|
@ -533,7 +533,7 @@ HIDDEN(ape_ram_vaddr = ADDR(.data));
|
||||||
HIDDEN(ape_ram_paddr = LOADADDR(.data));
|
HIDDEN(ape_ram_paddr = LOADADDR(.data));
|
||||||
HIDDEN(ape_ram_filesz = SIZEOF(.data));
|
HIDDEN(ape_ram_filesz = SIZEOF(.data));
|
||||||
HIDDEN(ape_ram_memsz = ADDR(.bss) + SIZEOF(.bss) - ape_ram_vaddr);
|
HIDDEN(ape_ram_memsz = ADDR(.bss) + SIZEOF(.bss) - ape_ram_vaddr);
|
||||||
HIDDEN(ape_ram_align = PAGESIZE);
|
HIDDEN(ape_ram_align = 4096);
|
||||||
HIDDEN(ape_ram_rva = RVA(ape_ram_vaddr));
|
HIDDEN(ape_ram_rva = RVA(ape_ram_vaddr));
|
||||||
|
|
||||||
HIDDEN(ape_stack_pf = DEFINED(ape_stack_pf) ? ape_stack_pf : PF_R | PF_W);
|
HIDDEN(ape_stack_pf = DEFINED(ape_stack_pf) ? ape_stack_pf : PF_R | PF_W);
|
||||||
|
@ -542,7 +542,7 @@ HIDDEN(ape_stack_offset = ape_ram_offset + ape_ram_filesz);
|
||||||
HIDDEN(ape_stack_vaddr = DEFINED(ape_stack_vaddr) ? ape_stack_vaddr : 0x700000000000);
|
HIDDEN(ape_stack_vaddr = DEFINED(ape_stack_vaddr) ? ape_stack_vaddr : 0x700000000000);
|
||||||
HIDDEN(ape_stack_paddr = ape_ram_paddr + ape_ram_filesz);
|
HIDDEN(ape_stack_paddr = ape_ram_paddr + ape_ram_filesz);
|
||||||
HIDDEN(ape_stack_filesz = 0);
|
HIDDEN(ape_stack_filesz = 0);
|
||||||
HIDDEN(ape_stack_memsz = DEFINED(ape_stack_memsz) ? ape_stack_memsz : STACKSIZE);
|
HIDDEN(ape_stack_memsz = DEFINED(ape_stack_memsz) ? ape_stack_memsz : APE_STACKSIZE);
|
||||||
HIDDEN(ape_stack_align = 16);
|
HIDDEN(ape_stack_align = 16);
|
||||||
|
|
||||||
HIDDEN(ape_note_offset = ape_rom_offset + (ape_note - ape_rom_vaddr));
|
HIDDEN(ape_note_offset = ape_rom_offset + (ape_note - ape_rom_vaddr));
|
||||||
|
@ -557,7 +557,7 @@ HIDDEN(ape_text_paddr = LOADADDR(.text));
|
||||||
HIDDEN(ape_text_vaddr = ADDR(.text));
|
HIDDEN(ape_text_vaddr = ADDR(.text));
|
||||||
HIDDEN(ape_text_filesz = SIZEOF(.text) + SIZEOF(.tdata));
|
HIDDEN(ape_text_filesz = SIZEOF(.text) + SIZEOF(.tdata));
|
||||||
HIDDEN(ape_text_memsz = SIZEOF(.text) + SIZEOF(.tdata));
|
HIDDEN(ape_text_memsz = SIZEOF(.text) + SIZEOF(.tdata));
|
||||||
HIDDEN(ape_text_align = PAGESIZE);
|
HIDDEN(ape_text_align = 4096);
|
||||||
HIDDEN(ape_text_rva = RVA(ape_text_vaddr));
|
HIDDEN(ape_text_rva = RVA(ape_text_vaddr));
|
||||||
|
|
||||||
HIDDEN(ape_data_offset = ape_ram_offset + LOADADDR(.data) - ape_ram_paddr);
|
HIDDEN(ape_data_offset = ape_ram_offset + LOADADDR(.data) - ape_ram_paddr);
|
||||||
|
@ -565,7 +565,7 @@ HIDDEN(ape_data_paddr = LOADADDR(.data));
|
||||||
HIDDEN(ape_data_vaddr = ADDR(.data));
|
HIDDEN(ape_data_vaddr = ADDR(.data));
|
||||||
HIDDEN(ape_data_filesz = SIZEOF(.data));
|
HIDDEN(ape_data_filesz = SIZEOF(.data));
|
||||||
HIDDEN(ape_data_memsz = SIZEOF(.data));
|
HIDDEN(ape_data_memsz = SIZEOF(.data));
|
||||||
HIDDEN(ape_data_align = PAGESIZE);
|
HIDDEN(ape_data_align = 4096);
|
||||||
HIDDEN(ape_data_rva = RVA(ape_data_vaddr));
|
HIDDEN(ape_data_rva = RVA(ape_data_vaddr));
|
||||||
|
|
||||||
HIDDEN(ape_bss_offset = ape_ram_offset + LOADADDR(.bss) - ape_ram_paddr);
|
HIDDEN(ape_bss_offset = ape_ram_offset + LOADADDR(.bss) - ape_ram_paddr);
|
||||||
|
@ -573,7 +573,7 @@ HIDDEN(ape_bss_paddr = LOADADDR(.bss));
|
||||||
HIDDEN(ape_bss_vaddr = ADDR(.bss));
|
HIDDEN(ape_bss_vaddr = ADDR(.bss));
|
||||||
HIDDEN(ape_bss_filesz = 0);
|
HIDDEN(ape_bss_filesz = 0);
|
||||||
HIDDEN(ape_bss_memsz = SIZEOF(.bss));
|
HIDDEN(ape_bss_memsz = SIZEOF(.bss));
|
||||||
HIDDEN(ape_bss_align = PAGESIZE);
|
HIDDEN(ape_bss_align = 4096);
|
||||||
|
|
||||||
/* we roundup here because xnu wants the file load segments page-aligned */
|
/* we roundup here because xnu wants the file load segments page-aligned */
|
||||||
/* but we don't want to add the nop padding to the ape program, so we'll */
|
/* but we don't want to add the nop padding to the ape program, so we'll */
|
||||||
|
@ -581,7 +581,7 @@ HIDDEN(ape_bss_align = PAGESIZE);
|
||||||
SHSTUB2(ape_loader_dd_skip, DEFINED(ape_loader) ? RVA(ape_loader) / 64 : 0);
|
SHSTUB2(ape_loader_dd_skip, DEFINED(ape_loader) ? RVA(ape_loader) / 64 : 0);
|
||||||
SHSTUB2(ape_loader_dd_count,
|
SHSTUB2(ape_loader_dd_count,
|
||||||
DEFINED(ape_loader_end)
|
DEFINED(ape_loader_end)
|
||||||
? ROUNDUP(ape_loader_end - ape_loader, PAGESIZE) / 64
|
? ROUNDUP(ape_loader_end - ape_loader, 4096) / 64
|
||||||
: 0);
|
: 0);
|
||||||
|
|
||||||
#if defined(APE_IS_SHELL_SCRIPT) && !IsTiny()
|
#if defined(APE_IS_SHELL_SCRIPT) && !IsTiny()
|
||||||
|
|
10
ape/config.h
10
ape/config.h
|
@ -1,10 +0,0 @@
|
||||||
#ifndef COSMOPOLITAN_APE_CONFIG_H_
|
|
||||||
#define COSMOPOLITAN_APE_CONFIG_H_
|
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
||||||
|
|
||||||
#define STATIC_SYMBOL(NAME, VALUE) \
|
|
||||||
asm(".equ\t" NAME "," VALUE "\n\t" \
|
|
||||||
".globl\t" NAME)
|
|
||||||
|
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
||||||
#endif /* COSMOPOLITAN_APE_CONFIG_H_ */
|
|
232
ape/loader-elf.S
232
ape/loader-elf.S
|
@ -32,57 +32,57 @@ ehdr: .ascii "\177ELF"
|
||||||
.byte 1
|
.byte 1
|
||||||
.byte ELFOSABI_FREEBSD
|
.byte ELFOSABI_FREEBSD
|
||||||
.quad 0
|
.quad 0
|
||||||
.word ET_EXEC # e_type
|
.word ET_EXEC // e_type
|
||||||
.word EM_NEXGEN32E # e_machine
|
.word EM_NEXGEN32E // e_machine
|
||||||
.long 1 # e_version
|
.long 1 // e_version
|
||||||
.quad _start # e_entry
|
.quad _start // e_entry
|
||||||
.quad phdrs - ehdr # e_phoff
|
.quad phdrs - ehdr // e_phoff
|
||||||
.quad 0 # e_shoff
|
.quad 0 // e_shoff
|
||||||
.long 0 # e_flags
|
.long 0 // e_flags
|
||||||
.word 64 # e_ehsize
|
.word 64 // e_ehsize
|
||||||
.word 56 # e_phentsize
|
.word 56 // e_phentsize
|
||||||
.word 4 # e_phnum
|
.word 4 // e_phnum
|
||||||
.word 0 # e_shentsize
|
.word 0 // e_shentsize
|
||||||
.word 0 # e_shnum
|
.word 0 // e_shnum
|
||||||
.word 0 # e_shstrndx
|
.word 0 // e_shstrndx
|
||||||
.endobj ehdr,globl
|
.endobj ehdr,globl
|
||||||
|
|
||||||
.balign 8
|
.balign 8
|
||||||
phdrs: .long PT_LOAD # p_type
|
phdrs: .long PT_LOAD // p_type
|
||||||
.long PF_R|PF_X # p_flags
|
.long PF_R|PF_X // p_flags
|
||||||
.quad 0 # p_offset
|
.quad 0 // p_offset
|
||||||
.quad ehdr # p_vaddr
|
.quad ehdr // p_vaddr
|
||||||
.quad ehdr # p_paddr
|
.quad ehdr // p_paddr
|
||||||
.quad filesz # p_filesz
|
.quad filesz // p_filesz
|
||||||
.quad filesz # p_memsz
|
.quad filesz // p_memsz
|
||||||
.quad PAGESIZE # p_align
|
.quad 4096 // p_align
|
||||||
|
|
||||||
.long PT_LOAD # p_type
|
.long PT_LOAD // p_type
|
||||||
.long PF_R|PF_W # p_flags
|
.long PF_R|PF_W // p_flags
|
||||||
.quad 0 # p_offset
|
.quad 0 // p_offset
|
||||||
.quad bss # p_vaddr
|
.quad bss // p_vaddr
|
||||||
.quad bss # p_paddr
|
.quad bss // p_paddr
|
||||||
.quad 0 # p_filesz
|
.quad 0 // p_filesz
|
||||||
.quad bsssize # p_memsz
|
.quad bsssize // p_memsz
|
||||||
.quad PAGESIZE # p_align
|
.quad 4096 // p_align
|
||||||
|
|
||||||
.long PT_GNU_STACK # p_type
|
.long PT_GNU_STACK // p_type
|
||||||
.long PF_R|PF_W # p_flags
|
.long PF_R|PF_W // p_flags
|
||||||
.quad 0 # p_offset
|
.quad 0 // p_offset
|
||||||
.quad 0 # p_vaddr
|
.quad 0 // p_vaddr
|
||||||
.quad 0 # p_paddr
|
.quad 0 // p_paddr
|
||||||
.quad 0 # p_filesz
|
.quad 0 // p_filesz
|
||||||
.quad 0 # p_memsz
|
.quad 0 // p_memsz
|
||||||
.quad 16 # p_align
|
.quad 16 // p_align
|
||||||
|
|
||||||
.long PT_NOTE # p_type
|
.long PT_NOTE // p_type
|
||||||
.long PF_R # p_flags
|
.long PF_R // p_flags
|
||||||
.quad note - ehdr # p_offset
|
.quad note - ehdr // p_offset
|
||||||
.quad note # p_vaddr
|
.quad note // p_vaddr
|
||||||
.quad note # p_paddr
|
.quad note // p_paddr
|
||||||
.quad notesize # p_filesz
|
.quad notesize // p_filesz
|
||||||
.quad notesize # p_memsz
|
.quad notesize // p_memsz
|
||||||
.quad 8 # p_align
|
.quad 8 // p_align
|
||||||
.endobj phdrs
|
.endobj phdrs
|
||||||
|
|
||||||
note: .long 2f-1f
|
note: .long 2f-1f
|
||||||
|
@ -100,8 +100,8 @@ note: .long 2f-1f
|
||||||
4: .endobj note
|
4: .endobj note
|
||||||
notesize = . - note
|
notesize = . - note
|
||||||
|
|
||||||
.balign 64,0 # for ape.S dd
|
.balign 64,0 // for ape.S dd
|
||||||
.org 0x180 # for ape.S dd
|
.org 0x180 // for ape.S dd
|
||||||
|
|
||||||
// APE Loader XNU Header
|
// APE Loader XNU Header
|
||||||
//
|
//
|
||||||
|
@ -113,92 +113,92 @@ macho: .long 0xFEEDFACE+1
|
||||||
.long MAC_CPU_NEXGEN32E
|
.long MAC_CPU_NEXGEN32E
|
||||||
.long MAC_CPU_NEXGEN32E_ALL
|
.long MAC_CPU_NEXGEN32E_ALL
|
||||||
.long MAC_EXECUTE
|
.long MAC_EXECUTE
|
||||||
.long 5 # number of load commands
|
.long 5 // number of load commands
|
||||||
.long 60f-10f # size of all load commands
|
.long 60f-10f // size of all load commands
|
||||||
.long MAC_NOUNDEFS # flags
|
.long MAC_NOUNDEFS // flags
|
||||||
.long 0 # reserved
|
.long 0 // reserved
|
||||||
10: .long MAC_LC_SEGMENT_64
|
10: .long MAC_LC_SEGMENT_64
|
||||||
.long 20f-10b # unmaps first page dir
|
.long 20f-10b // unmaps first page dir
|
||||||
.ascin "__PAGEZERO",16 # consistent with linux
|
.ascin "__PAGEZERO",16 // consistent with linux
|
||||||
.quad 0,0x200000,0,0 # which forbids mem <2m
|
.quad 0,0x200000,0,0 // which forbids mem <2m
|
||||||
.long 0,0,0,0
|
.long 0,0,0,0
|
||||||
20: .long MAC_LC_SEGMENT_64
|
20: .long MAC_LC_SEGMENT_64
|
||||||
.long 30f-20b
|
.long 30f-20b
|
||||||
.ascin "__TEXT",16
|
.ascin "__TEXT",16
|
||||||
.quad ehdr # vaddr
|
.quad ehdr // vaddr
|
||||||
.quad 4096 # memsz
|
.quad 4096 // memsz
|
||||||
.quad 0 # file offset
|
.quad 0 // file offset
|
||||||
.quad filesz # file size
|
.quad filesz // file size
|
||||||
.long PROT_EXEC|PROT_READ|PROT_WRITE # maxprot
|
.long PROT_EXEC|PROT_READ|PROT_WRITE // maxprot
|
||||||
.long PROT_EXEC|PROT_READ # initprot
|
.long PROT_EXEC|PROT_READ // initprot
|
||||||
.long 1 # segment section count
|
.long 1 // segment section count
|
||||||
.long 0 # flags
|
.long 0 // flags
|
||||||
210: .ascin "__text",16 # section name (.text)
|
210: .ascin "__text",16 // section name (.text)
|
||||||
.ascin "__TEXT",16
|
.ascin "__TEXT",16
|
||||||
.quad _start # vaddr
|
.quad _start // vaddr
|
||||||
.quad textsz # memsz
|
.quad textsz // memsz
|
||||||
.long textoff # offset
|
.long textoff // offset
|
||||||
.long 6 # align 2**6 = 64
|
.long 6 // align 2**6 = 64
|
||||||
.long 0 # reloc table offset
|
.long 0 // reloc table offset
|
||||||
.long 0 # relocation count
|
.long 0 // relocation count
|
||||||
.long MAC_S_ATTR_SOME_INSTRUCTIONS # section type & attributes
|
.long MAC_S_ATTR_SOME_INSTRUCTIONS // section type & attributes
|
||||||
.long 0,0,0 # reserved
|
.long 0,0,0 // reserved
|
||||||
30: .long MAC_LC_SEGMENT_64
|
30: .long MAC_LC_SEGMENT_64
|
||||||
.long 40f-30b
|
.long 40f-30b
|
||||||
.ascin "__DATA",16
|
.ascin "__DATA",16
|
||||||
.quad bss # vaddr
|
.quad bss // vaddr
|
||||||
.quad bsssize # memsz
|
.quad bsssize // memsz
|
||||||
.quad 0 # offset
|
.quad 0 // offset
|
||||||
.quad 0 # file size
|
.quad 0 // file size
|
||||||
.long PROT_EXEC|PROT_READ|PROT_WRITE # maxprot
|
.long PROT_EXEC|PROT_READ|PROT_WRITE // maxprot
|
||||||
.long PROT_READ|PROT_WRITE # initprot
|
.long PROT_READ|PROT_WRITE // initprot
|
||||||
.long 1 # segment section count
|
.long 1 // segment section count
|
||||||
.long 0 # flags
|
.long 0 // flags
|
||||||
310: .ascin "__bss",16 # section name (.bss)
|
310: .ascin "__bss",16 // section name (.bss)
|
||||||
.ascin "__DATA",16
|
.ascin "__DATA",16
|
||||||
.quad bss # vaddr
|
.quad bss // vaddr
|
||||||
.quad bsssize # memsz
|
.quad bsssize // memsz
|
||||||
.long 0 # offset
|
.long 0 // offset
|
||||||
.long 12 # align 2**12 = 4096
|
.long 12 // align 2**12 = 4096
|
||||||
.long 0 # reloc table offset
|
.long 0 // reloc table offset
|
||||||
.long 0 # relocation count
|
.long 0 // relocation count
|
||||||
.long MAC_S_ZEROFILL # section type & attributes
|
.long MAC_S_ZEROFILL // section type & attributes
|
||||||
.long 0,0,0 # reserved
|
.long 0,0,0 // reserved
|
||||||
40: .long MAC_LC_UUID
|
40: .long MAC_LC_UUID
|
||||||
.long 50f-40b
|
.long 50f-40b
|
||||||
.quad 0x3fb29ee4ac6c87aa # uuid1
|
.quad 0x3fb29ee4ac6c87aa // uuid1
|
||||||
.quad 0xdd2c9bb866d9eef8 # uuid2
|
.quad 0xdd2c9bb866d9eef8 // uuid2
|
||||||
50: .long MAC_LC_UNIXTHREAD
|
50: .long MAC_LC_UNIXTHREAD
|
||||||
.long 60f-50b # cmdsize
|
.long 60f-50b // cmdsize
|
||||||
.long MAC_THREAD_NEXGEN32E # flavaflav
|
.long MAC_THREAD_NEXGEN32E // flavaflav
|
||||||
.long (520f-510f)/4 # count
|
.long (520f-510f)/4 // count
|
||||||
510: .quad 0 # rax
|
510: .quad 0 // rax
|
||||||
.quad 0 # rbx
|
.quad 0 // rbx
|
||||||
.quad 0 # rcx
|
.quad 0 // rcx
|
||||||
.quad _HOSTXNU # rdx
|
.quad _HOSTXNU // rdx
|
||||||
.quad 0 # rdi
|
.quad 0 // rdi
|
||||||
.quad 0 # rsi
|
.quad 0 // rsi
|
||||||
.quad 0 # rbp
|
.quad 0 // rbp
|
||||||
.quad 0 # rsp
|
.quad 0 // rsp
|
||||||
.quad 0 # r8
|
.quad 0 // r8
|
||||||
.quad 0 # r9
|
.quad 0 // r9
|
||||||
.quad 0 # r10
|
.quad 0 // r10
|
||||||
.quad 0 # r11
|
.quad 0 // r11
|
||||||
.quad 0 # r12
|
.quad 0 // r12
|
||||||
.quad 0 # r13
|
.quad 0 // r13
|
||||||
.quad 0 # r14
|
.quad 0 // r14
|
||||||
.quad 0 # r15
|
.quad 0 // r15
|
||||||
.quad _start # rip
|
.quad _start // rip
|
||||||
.quad 0 # rflags
|
.quad 0 // rflags
|
||||||
.quad 0 # cs
|
.quad 0 // cs
|
||||||
.quad 0 # fs
|
.quad 0 // fs
|
||||||
.quad 0 # gs
|
.quad 0 // gs
|
||||||
520:
|
520:
|
||||||
60:
|
60:
|
||||||
.endobj macho
|
.endobj macho
|
||||||
|
|
||||||
.balign 64,0 # for ape.S dd
|
.balign 64,0 // for ape.S dd
|
||||||
.org 0x400 # for ape.S dd
|
.org 0x400 // for ape.S dd
|
||||||
|
|
||||||
// Ape Loader Entrpoint
|
// Ape Loader Entrpoint
|
||||||
//
|
//
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#define APE_LOADER_BASE 0x200000
|
#define APE_LOADER_BASE 0x200000
|
||||||
#define APE_LOADER_SIZE 0x200000
|
#define APE_LOADER_SIZE 0x200000
|
||||||
#define APE_LOADER_ENTRY 0x200400
|
#define APE_LOADER_ENTRY 0x200400
|
||||||
#define APE_LOADER_BSS (PAGESIZE * 2)
|
#define APE_LOADER_BSS (4096 * 2)
|
||||||
#define APE_LOADER_STACK 0x7f0000000000
|
#define APE_LOADER_STACK 0x7f0000000000
|
||||||
#define APE_BLOCK_BASE 0x7e0000000000
|
#define APE_BLOCK_BASE 0x7e0000000000
|
||||||
#define APE_BLOCK_SIZE 0x000200000000
|
#define APE_BLOCK_SIZE 0x000200000000
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||||
╚─────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────*/
|
||||||
#endif
|
#endif
|
||||||
#include "libc/log/log.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatically launches GDB Debugger TUI during crash.
|
* Automatically launches GDB Debugger TUI during crash.
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────*/
|
||||||
#endif
|
#endif
|
||||||
#include "libc/calls/struct/timespec.h"
|
#include "libc/calls/struct/timespec.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
#include "libc/time/time.h"
|
#include "libc/time/time.h"
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
╚─────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────*/
|
||||||
#endif
|
#endif
|
||||||
#include "libc/intrin/kprintf.h"
|
#include "libc/intrin/kprintf.h"
|
||||||
#include "libc/log/log.h"
|
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/runtime/symbols.internal.h"
|
#include "libc/runtime/symbols.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/struct/sigset.h"
|
#include "libc/calls/struct/sigset.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include "libc/time/time.h"
|
#include "libc/time/time.h"
|
||||||
#include "libc/x/xasprintf.h"
|
#include "libc/x/xasprintf.h"
|
||||||
#include "libc/x/xsigaction.h"
|
#include "libc/x/xsigaction.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
#include "third_party/getopt/getopt.h"
|
#include "third_party/getopt/getopt.h"
|
||||||
#include "third_party/libcxx/vector"
|
#include "third_party/libcxx/vector"
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/log/check.h"
|
#include "libc/log/check.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/runtime/stack.h"
|
#include "libc/runtime/stack.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
#include "libc/sysv/consts/prot.h"
|
#include "libc/sysv/consts/prot.h"
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────*/
|
||||||
#endif
|
#endif
|
||||||
#include "libc/intrin/kprintf.h"
|
#include "libc/intrin/kprintf.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview example of how to embed symbol table in .com file
|
* @fileoverview example of how to embed symbol table in .com file
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/asan.internal.h"
|
#include "libc/intrin/asan.internal.h"
|
||||||
#include "libc/intrin/kprintf.h"
|
#include "libc/intrin/kprintf.h"
|
||||||
#include "libc/log/rop.h"
|
#include "libc/log/rop.internal.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/consts/at.h"
|
#include "libc/sysv/consts/at.h"
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/pledge.internal.h"
|
#include "libc/calls/pledge.internal.h"
|
||||||
#include "libc/calls/prctl.internal.h"
|
#include "libc/calls/prctl.internal.h"
|
||||||
#include "libc/calls/struct/bpf.h"
|
#include "libc/calls/struct/bpf.internal.h"
|
||||||
#include "libc/calls/struct/filter.h"
|
#include "libc/calls/struct/filter.internal.h"
|
||||||
#include "libc/calls/struct/seccomp.h"
|
#include "libc/calls/struct/seccomp.internal.h"
|
||||||
#include "libc/calls/struct/sigaction.h"
|
#include "libc/calls/struct/sigaction.h"
|
||||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||||
#include "libc/intrin/bsr.h"
|
#include "libc/intrin/bsr.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/struct/seccomp.h"
|
#include "libc/calls/struct/seccomp.internal.h"
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/syscall-sysv.internal.h"
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
|
|
|
@ -25,7 +25,7 @@ struct sigaction { /* cosmo abi */
|
||||||
sighandler_t signal(int, sighandler_t);
|
sighandler_t signal(int, sighandler_t);
|
||||||
int sigaction(int, const struct sigaction *, struct sigaction *);
|
int sigaction(int, const struct sigaction *, struct sigaction *);
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(COSMO)
|
||||||
|
|
||||||
void _init_onntconsoleevent(void);
|
void _init_onntconsoleevent(void);
|
||||||
void _init_wincrash(void);
|
void _init_wincrash(void);
|
||||||
|
|
|
@ -1,24 +1,5 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
|
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
|
||||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
|
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
|
||||||
|
|
||||||
#ifdef COSMO
|
|
||||||
#define timespec_get __timespec_get
|
|
||||||
#define timespec_getres __timespec_getres
|
|
||||||
#define timespec_cmp __timespec_cmp
|
|
||||||
#define timespec_tomicros __timespec_tomicros
|
|
||||||
#define timespec_tomillis __timespec_tomillis
|
|
||||||
#define timespec_tonanos __timespec_tonanos
|
|
||||||
#define timespec_add __timespec_add
|
|
||||||
#define timespec_fromnanos __timespec_fromnanos
|
|
||||||
#define timespec_frommicros __timespec_frommicros
|
|
||||||
#define timespec_frommillis __timespec_frommillis
|
|
||||||
#define timespec_real __timespec_real
|
|
||||||
#define timespec_mono __timespec_mono
|
|
||||||
#define timespec_sleep __timespec_sleep
|
|
||||||
#define timespec_sleep_until __timespec_sleep_until
|
|
||||||
#define timespec_sub __timespec_sub
|
|
||||||
#endif /* COSMO */
|
|
||||||
|
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
|
@ -32,7 +13,6 @@ int clock_gettime(int, struct timespec *);
|
||||||
int clock_nanosleep(int, int, const struct timespec *, struct timespec *);
|
int clock_nanosleep(int, int, const struct timespec *, struct timespec *);
|
||||||
int futimens(int, const struct timespec[2]);
|
int futimens(int, const struct timespec[2]);
|
||||||
int nanosleep(const struct timespec *, struct timespec *);
|
int nanosleep(const struct timespec *, struct timespec *);
|
||||||
int sys_futex(int *, int, int, const struct timespec *, int *);
|
|
||||||
int utimensat(int, const char *, const struct timespec[2], int);
|
int utimensat(int, const char *, const struct timespec[2], int);
|
||||||
|
|
||||||
#ifdef COSMO
|
#ifdef COSMO
|
||||||
|
@ -55,6 +35,7 @@ struct timespec timespec_mono(void);
|
||||||
struct timespec timespec_sleep(struct timespec);
|
struct timespec timespec_sleep(struct timespec);
|
||||||
int timespec_sleep_until(struct timespec);
|
int timespec_sleep_until(struct timespec);
|
||||||
struct timespec timespec_sub(struct timespec, struct timespec) pureconst;
|
struct timespec timespec_sub(struct timespec, struct timespec) pureconst;
|
||||||
|
int sys_futex(int *, int, int, const struct timespec *, int *);
|
||||||
#endif /* COSMO */
|
#endif /* COSMO */
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
|
|
|
@ -2,17 +2,6 @@
|
||||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_
|
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_
|
||||||
#include "libc/calls/struct/timespec.h"
|
#include "libc/calls/struct/timespec.h"
|
||||||
#include "libc/time/struct/timezone.h"
|
#include "libc/time/struct/timezone.h"
|
||||||
|
|
||||||
#ifdef COSMO
|
|
||||||
#define timeval_cmp __timeval_cmp
|
|
||||||
#define timeval_frommicros __timeval_frommicros
|
|
||||||
#define timeval_frommillis __timeval_frommillis
|
|
||||||
#define timeval_add __timeval_add
|
|
||||||
#define timeval_sub __timeval_sub
|
|
||||||
#define timespec_totimeval __timespec_totimeval
|
|
||||||
#define timeval_totimespec __timeval_totimespec
|
|
||||||
#endif /* COSMO */
|
|
||||||
|
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
#include "libc/calls/blockcancel.internal.h"
|
#include "libc/calls/blockcancel.internal.h"
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/landlock.h"
|
#include "libc/calls/landlock.h"
|
||||||
#include "libc/calls/struct/bpf.h"
|
#include "libc/calls/struct/bpf.internal.h"
|
||||||
#include "libc/calls/struct/filter.h"
|
#include "libc/calls/struct/filter.internal.h"
|
||||||
#include "libc/calls/struct/seccomp.h"
|
#include "libc/calls/struct/seccomp.internal.h"
|
||||||
#include "libc/calls/struct/stat.h"
|
#include "libc/calls/struct/stat.h"
|
||||||
#include "libc/calls/struct/stat.internal.h"
|
#include "libc/calls/struct/stat.internal.h"
|
||||||
#include "libc/calls/syscall-sysv.internal.h"
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
|
|
|
@ -152,8 +152,9 @@ typedef struct {
|
||||||
#define libcesque dontthrow nocallback
|
#define libcesque dontthrow nocallback
|
||||||
#define memcpyesque libcesque
|
#define memcpyesque libcesque
|
||||||
#define strlenesque libcesque nosideeffect paramsnonnull()
|
#define strlenesque libcesque nosideeffect paramsnonnull()
|
||||||
#define vallocesque \
|
#define vallocesque \
|
||||||
libcesque dontdiscard returnsaligned((GUARDSIZE)) returnspointerwithnoaliases
|
libcesque dontdiscard returnsaligned((APE_PAGESIZE)) \
|
||||||
|
returnspointerwithnoaliases
|
||||||
#define reallocesque libcesque returnsaligned((16))
|
#define reallocesque libcesque returnsaligned((16))
|
||||||
#define mallocesque reallocesque returnspointerwithnoaliases
|
#define mallocesque reallocesque returnspointerwithnoaliases
|
||||||
#define interruptfn nocallersavedregisters forcealignargpointer
|
#define interruptfn nocallersavedregisters forcealignargpointer
|
||||||
|
|
|
@ -66,27 +66,26 @@
|
||||||
#define __BIGGEST_ALIGNMENT__ 16
|
#define __BIGGEST_ALIGNMENT__ 16
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TODO(jart): Remove this in favor of GetStackSize() */
|
|
||||||
#ifdef COSMO
|
#ifdef COSMO
|
||||||
#define STACKSIZE 262144 /* 256kb stack */
|
/* Programs should call GetStackSize() */
|
||||||
|
#define APE_STACKSIZE 262144 /* default 256kb stack */
|
||||||
|
#define FRAMESIZE 0x10000
|
||||||
|
#define PAGESIZE 0x1000 /* i386+ */
|
||||||
#else
|
#else
|
||||||
#define STACKSIZE 8388608 /* 8mb stack */
|
#define APE_STACKSIZE 8388608 /* default 8mb stack */
|
||||||
#endif
|
#endif
|
||||||
|
#define APE_PAGESIZE 0x10000 /* i386+ */
|
||||||
|
#define APE_GUARDSIZE 0x4000 /* b/c apple m1 */
|
||||||
|
|
||||||
#define BIGPAGESIZE 0x200000
|
#define BUFSIZ 0x1000 /* best stdio default */
|
||||||
#define FRAMESIZE 0x10000 /* 8086 */
|
#define CHAR_BIT 8 /* b/c von neumann */
|
||||||
#define GUARDSIZE 0x4000 /* b/c apple m1 */
|
#define ARG_MAX 0xfffe /* for argv and envp; see CreateProcess (32767*2) */
|
||||||
#define PAGESIZE 0x1000 /* i386+ */
|
#define PATH_MAX 1024 /* b/c _XOPEN_PATH_MAX */
|
||||||
#define BUFSIZ 0x1000 /* best stdio default */
|
#define NAME_MAX 255 /* 511 on netbsd */
|
||||||
#define CACHELINE 0x40 /* nexgen32e */
|
#define CHILD_MAX 16 /* only if malloc isn't linked */
|
||||||
#define CHAR_BIT 8 /* b/c von neumann */
|
#define OPEN_MAX 16 /* only if malloc isn't linked */
|
||||||
#define ARG_MAX 0xfffe /* for argv and envp; see CreateProcess (32767*2) */
|
#define ATEXIT_MAX 32 /* only if malloc isn't linked */
|
||||||
#define PATH_MAX 1024 /* b/c _XOPEN_PATH_MAX */
|
#define NSIG 128 /* b/c freebsd */
|
||||||
#define NAME_MAX 255 /* 511 on netbsd */
|
|
||||||
#define CHILD_MAX 16 /* only if malloc isn't linked */
|
|
||||||
#define OPEN_MAX 16 /* only if malloc isn't linked */
|
|
||||||
#define ATEXIT_MAX 32 /* only if malloc isn't linked */
|
|
||||||
#define NSIG 128 /* b/c freebsd */
|
|
||||||
|
|
||||||
#if defined(__LP64__) && !defined(__INT64_TYPE__)
|
#if defined(__LP64__) && !defined(__INT64_TYPE__)
|
||||||
#include "libc/integral/lp64.inc"
|
#include "libc/integral/lp64.inc"
|
||||||
|
|
|
@ -1465,7 +1465,7 @@ static textstartup void __asan_shadow_mapping(struct MemoryIntervals *m,
|
||||||
static textstartup void __asan_shadow_existing_mappings(void) {
|
static textstartup void __asan_shadow_existing_mappings(void) {
|
||||||
__asan_shadow_mapping(&_mmi, 0);
|
__asan_shadow_mapping(&_mmi, 0);
|
||||||
__asan_map_shadow(GetStackAddr(), GetStackSize());
|
__asan_map_shadow(GetStackAddr(), GetStackSize());
|
||||||
__asan_poison((void *)GetStackAddr(), GUARDSIZE, kAsanStackOverflow);
|
__asan_poison((void *)GetStackAddr(), APE_GUARDSIZE, kAsanStackOverflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline ssize_t __write_str(const char *s) {
|
forceinline ssize_t __write_str(const char *s) {
|
||||||
|
@ -1492,7 +1492,7 @@ void __asan_init(int argc, char **argv, char **envp, intptr_t *auxv) {
|
||||||
__asan_shadow_existing_mappings();
|
__asan_shadow_existing_mappings();
|
||||||
__asan_map_shadow((uintptr_t)__executable_start, _end - __executable_start);
|
__asan_map_shadow((uintptr_t)__executable_start, _end - __executable_start);
|
||||||
__asan_map_shadow(0, 4096);
|
__asan_map_shadow(0, 4096);
|
||||||
__asan_poison(0, GUARDSIZE, kAsanNullPage);
|
__asan_poison(0, APE_GUARDSIZE, kAsanNullPage);
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
sys_mprotect((void *)0x7fff8000, 0x10000, PROT_READ);
|
sys_mprotect((void *)0x7fff8000, 0x10000, PROT_READ);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/struct/seccomp.h"
|
#include "libc/calls/struct/seccomp.internal.h"
|
||||||
#include "libc/intrin/describeflags.internal.h"
|
#include "libc/intrin/describeflags.internal.h"
|
||||||
|
|
||||||
const char *DescribeSeccompOperation(int x) {
|
const char *DescribeSeccompOperation(int x) {
|
||||||
|
|
|
@ -184,7 +184,7 @@ privileged bool kisdangerous(const void *p) {
|
||||||
if (IsStackFrame(frame)) return false;
|
if (IsStackFrame(frame)) return false;
|
||||||
if (kismapped(frame)) return false;
|
if (kismapped(frame)) return false;
|
||||||
}
|
}
|
||||||
if (GetStackAddr() + GUARDSIZE <= (uintptr_t)p &&
|
if (GetStackAddr() + APE_GUARDSIZE <= (uintptr_t)p &&
|
||||||
(uintptr_t)p < GetStackAddr() + GetStackSize()) {
|
(uintptr_t)p < GetStackAddr() + GetStackSize()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
67
libc/isystem/cosmo.h
Normal file
67
libc/isystem/cosmo.h
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_COSMO_H_
|
||||||
|
#define COSMOPOLITAN_LIBC_ISYSTEM_COSMO_H_
|
||||||
|
|
||||||
|
#ifdef COSMO
|
||||||
|
#define COSMO_ALREADY_DEFINED
|
||||||
|
#else
|
||||||
|
#define COSMO
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fileoverview Curated Cosmopolitan non-POSIX C Libraries
|
||||||
|
*
|
||||||
|
* Users of the `cosmocc` toolchain can say, for example:
|
||||||
|
*
|
||||||
|
* #include <cosmo.h>
|
||||||
|
*
|
||||||
|
* int main(int argc, char *argv[]) {
|
||||||
|
* ShowCrashReports();
|
||||||
|
* kprintf("hello world\n");
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* Which will define the best stuff from Cosmopolitan Libc, which
|
||||||
|
* includes core runtime services, third party libraries we've curated,
|
||||||
|
* as well as internal libraries we made that are good enough to share.
|
||||||
|
*
|
||||||
|
* @see tool/script/cosmocc
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/calls/struct/timespec.h"
|
||||||
|
#include "libc/calls/struct/timeval.h"
|
||||||
|
#include "libc/dce.h"
|
||||||
|
#include "libc/fmt/itoa.h"
|
||||||
|
#include "libc/fmt/leb128.h"
|
||||||
|
#include "libc/intrin/bsf.h"
|
||||||
|
#include "libc/intrin/bsr.h"
|
||||||
|
#include "libc/intrin/kprintf.h"
|
||||||
|
#include "libc/intrin/likely.h"
|
||||||
|
#include "libc/intrin/tpenc.h"
|
||||||
|
#include "libc/intrin/weaken.h"
|
||||||
|
#include "libc/mem/critbit0.h"
|
||||||
|
#include "libc/mem/gc.h"
|
||||||
|
#include "libc/mem/hook.internal.h"
|
||||||
|
#include "libc/nexgen32e/rdtsc.h"
|
||||||
|
#include "libc/nexgen32e/stackframe.h"
|
||||||
|
#include "libc/nexgen32e/x86feature.h"
|
||||||
|
#include "libc/runtime/morph.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/runtime/stack.h"
|
||||||
|
#include "libc/runtime/symbols.internal.h"
|
||||||
|
#include "libc/stdio/append.h"
|
||||||
|
#include "libc/stdio/rand.h"
|
||||||
|
#include "libc/str/blake2.h"
|
||||||
|
#include "libc/str/highwayhash64.h"
|
||||||
|
#include "libc/str/slice.h"
|
||||||
|
#include "libc/str/thompike.h"
|
||||||
|
#include "libc/str/unicode.h"
|
||||||
|
#include "libc/str/utf16.h"
|
||||||
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
|
#ifdef COSMO_ALREADY_DEFINED
|
||||||
|
#undef COSMO_ALREADY_DEFINED
|
||||||
|
#else
|
||||||
|
#undef COSMO
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_COSMO_H_ */
|
|
@ -43,8 +43,6 @@ const char *commandvenv(const char *, const char *);
|
||||||
int LogKprintfToFile(const char *);
|
int LogKprintfToFile(const char *);
|
||||||
const char *GetAddr2linePath(void);
|
const char *GetAddr2linePath(void);
|
||||||
const char *GetGdbPath(void);
|
const char *GetGdbPath(void);
|
||||||
void ShowCrashReports(void);
|
|
||||||
int MakeProcessNice(void);
|
|
||||||
bool32 IsDebuggerPresent(bool);
|
bool32 IsDebuggerPresent(bool);
|
||||||
bool IsRunningUnderMake(void);
|
bool IsRunningUnderMake(void);
|
||||||
const char *GetSiCodeName(int, int);
|
const char *GetSiCodeName(int, int);
|
||||||
|
|
|
@ -226,7 +226,7 @@ relegated void ShowCrashReport(int err, int sig, struct siginfo *si,
|
||||||
" %s %s %s %s\n",
|
" %s %s %s %s\n",
|
||||||
!__nocolor ? "\e[30;101m" : "", !__nocolor ? "\e[0m" : "", sig,
|
!__nocolor ? "\e[30;101m" : "", !__nocolor ? "\e[0m" : "", sig,
|
||||||
(ctx && (ctx->uc_mcontext.rsp >= GetStaticStackAddr(0) &&
|
(ctx && (ctx->uc_mcontext.rsp >= GetStaticStackAddr(0) &&
|
||||||
ctx->uc_mcontext.rsp <= GetStaticStackAddr(0) + GUARDSIZE))
|
ctx->uc_mcontext.rsp <= GetStaticStackAddr(0) + APE_GUARDSIZE))
|
||||||
? "Stack Overflow"
|
? "Stack Overflow"
|
||||||
: GetSiCodeName(sig, si->si_code),
|
: GetSiCodeName(sig, si->si_code),
|
||||||
host, getpid(), gettid(), program_invocation_name, names.sysname,
|
host, getpid(), gettid(), program_invocation_name, names.sysname,
|
||||||
|
|
|
@ -184,7 +184,7 @@ relegated void __oncrash_arm64(int sig, struct siginfo *si, void *arg) {
|
||||||
gethostname(host, sizeof(host));
|
gethostname(host, sizeof(host));
|
||||||
reset = !__nocolor ? RESET : "";
|
reset = !__nocolor ? RESET : "";
|
||||||
strong = !__nocolor ? STRONG : "";
|
strong = !__nocolor ? STRONG : "";
|
||||||
if (ctx && (ctx->uc_mcontext.sp & (GetStackSize() - 1)) <= GUARDSIZE) {
|
if (ctx && (ctx->uc_mcontext.sp & (GetStackSize() - 1)) <= APE_GUARDSIZE) {
|
||||||
kind = "Stack Overflow";
|
kind = "Stack Overflow";
|
||||||
} else {
|
} else {
|
||||||
kind = GetSiCodeName(sig, si->si_code);
|
kind = GetSiCodeName(sig, si->si_code);
|
||||||
|
|
|
@ -21,9 +21,6 @@
|
||||||
|
|
||||||
/* TODO(jart): delete */
|
/* TODO(jart): delete */
|
||||||
|
|
||||||
#define kGuard GUARDSIZE
|
|
||||||
#define kGrain FRAMESIZE
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates page-guarded buffer.
|
* Allocates page-guarded buffer.
|
||||||
*
|
*
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
|
||||||
|
|
||||||
// Loads XMM registers from buffer.
|
// Loads XMM registers from buffer.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,14 +17,16 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
|
||||||
|
|
||||||
// Loads previously saved processor state.
|
// Loads previously saved processor state.
|
||||||
//
|
//
|
||||||
// @param rdi points to the jmp_buf
|
// @param rdi points to the jmp_buf
|
||||||
// @param rsi is returned by setlongerjmp() invocation
|
// @param rsi is returned by setlongerjmp() invocation
|
||||||
// @noreturn
|
// @noreturn
|
||||||
|
.ftrace1
|
||||||
longerjmp:
|
longerjmp:
|
||||||
|
.ftrace2
|
||||||
|
#ifdef __x86_64__
|
||||||
mov $1,%eax
|
mov $1,%eax
|
||||||
mov %rsi,%rdx
|
mov %rsi,%rdx
|
||||||
mov (%rdi),%rsp
|
mov (%rdi),%rsp
|
||||||
|
@ -35,4 +37,22 @@ longerjmp:
|
||||||
mov 40(%rdi),%r14
|
mov 40(%rdi),%r14
|
||||||
mov 48(%rdi),%r15
|
mov 48(%rdi),%r15
|
||||||
jmp *56(%rdi)
|
jmp *56(%rdi)
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
ldp x19,x20,[x0,#0]
|
||||||
|
ldp x21,x22,[x0,#16]
|
||||||
|
ldp x23,x24,[x0,#32]
|
||||||
|
ldp x25,x26,[x0,#48]
|
||||||
|
ldp x27,x28,[x0,#64]
|
||||||
|
ldp x29,x30,[x0,#80]
|
||||||
|
ldr x2,[x0,#104]
|
||||||
|
mov sp,x2
|
||||||
|
ldp d8 ,d9,[x0,#112]
|
||||||
|
ldp d10,d11,[x0,#128]
|
||||||
|
ldp d12,d13,[x0,#144]
|
||||||
|
ldp d14,d15,[x0,#160]
|
||||||
|
mov x0,x1
|
||||||
|
br x30
|
||||||
|
#else
|
||||||
|
#error "unsupported architecture"
|
||||||
|
#endif
|
||||||
.endfn longerjmp,globl
|
.endfn longerjmp,globl
|
||||||
|
|
|
@ -57,6 +57,8 @@ longjmp:
|
||||||
cmp w1,0
|
cmp w1,0
|
||||||
csinc w0,w1,wzr,ne
|
csinc w0,w1,wzr,ne
|
||||||
br x30
|
br x30
|
||||||
|
#else
|
||||||
|
#error "unsupported architecture"
|
||||||
#endif
|
#endif
|
||||||
.endfn longjmp,globl
|
.endfn longjmp,globl
|
||||||
.alias longjmp,_longjmp
|
.alias longjmp,_longjmp
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
|
||||||
|
|
||||||
// Stores XMM registers to buffer.
|
// Stores XMM registers to buffer.
|
||||||
//
|
//
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
// @note code built w/ microsoft abi compiler can't call this
|
// @note code built w/ microsoft abi compiler can't call this
|
||||||
// @see longjmp(), _gclongjmp()
|
// @see longjmp(), _gclongjmp()
|
||||||
.ftrace1
|
.ftrace1
|
||||||
setjmp: .ftrace2
|
setjmp:
|
||||||
|
.ftrace2
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
lea 8(%rsp),%rax
|
lea 8(%rsp),%rax
|
||||||
mov %rax,(%rdi)
|
mov %rax,(%rdi)
|
||||||
|
@ -40,6 +41,7 @@ setjmp: .ftrace2
|
||||||
mov (%rsp),%rax
|
mov (%rsp),%rax
|
||||||
mov %rax,56(%rdi)
|
mov %rax,56(%rdi)
|
||||||
xor %eax,%eax
|
xor %eax,%eax
|
||||||
|
ret
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
stp x19,x20,[x0,#0]
|
stp x19,x20,[x0,#0]
|
||||||
stp x21,x22,[x0,#16]
|
stp x21,x22,[x0,#16]
|
||||||
|
@ -54,7 +56,9 @@ setjmp: .ftrace2
|
||||||
stp d12,d13,[x0,#144]
|
stp d12,d13,[x0,#144]
|
||||||
stp d14,d15,[x0,#160]
|
stp d14,d15,[x0,#160]
|
||||||
mov x0,#0
|
mov x0,#0
|
||||||
#endif
|
|
||||||
ret
|
ret
|
||||||
|
#else
|
||||||
|
#error "unsupported architecture"
|
||||||
|
#endif
|
||||||
.endfn setjmp,globl
|
.endfn setjmp,globl
|
||||||
.alias setjmp,_setjmp
|
.alias setjmp,_setjmp
|
||||||
|
|
|
@ -24,7 +24,10 @@
|
||||||
// @return eax contains 0 when set, and 1 if jumped
|
// @return eax contains 0 when set, and 1 if jumped
|
||||||
// @return rdx contains value passed to longerjmp()
|
// @return rdx contains value passed to longerjmp()
|
||||||
// @returnstwice
|
// @returnstwice
|
||||||
|
.ftrace1
|
||||||
setlongerjmp:
|
setlongerjmp:
|
||||||
|
.ftrace2
|
||||||
|
#ifdef __x86_64__
|
||||||
lea 8(%rsp),%rax
|
lea 8(%rsp),%rax
|
||||||
mov %rax,(%rdi)
|
mov %rax,(%rdi)
|
||||||
mov %rbx,8(%rdi)
|
mov %rbx,8(%rdi)
|
||||||
|
@ -38,4 +41,23 @@ setlongerjmp:
|
||||||
xor %eax,%eax
|
xor %eax,%eax
|
||||||
xor %edx,%edx
|
xor %edx,%edx
|
||||||
ret
|
ret
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
stp x19,x20,[x0,#0]
|
||||||
|
stp x21,x22,[x0,#16]
|
||||||
|
stp x23,x24,[x0,#32]
|
||||||
|
stp x25,x26,[x0,#48]
|
||||||
|
stp x27,x28,[x0,#64]
|
||||||
|
stp x29,x30,[x0,#80]
|
||||||
|
mov x2,sp
|
||||||
|
str x2,[x0,#104]
|
||||||
|
stp d8,d9,[x0,#112]
|
||||||
|
stp d10,d11,[x0,#128]
|
||||||
|
stp d12,d13,[x0,#144]
|
||||||
|
stp d14,d15,[x0,#160]
|
||||||
|
mov x0,#0
|
||||||
|
mov x1,#0
|
||||||
|
ret
|
||||||
|
#else
|
||||||
|
#error "unsupported architecture"
|
||||||
|
#endif
|
||||||
.endfn setlongerjmp,globl
|
.endfn setlongerjmp,globl
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
#include "ape/relocations.h"
|
#include "ape/relocations.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
// ZIP Central Directory.
|
// ZIP Central Directory.
|
||||||
.section .zip.3,"",@progbits
|
.section .zip.3,"",@progbits
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/thread/thread.h"
|
#include "libc/thread/thread.h"
|
||||||
#include "libc/x/x.h"
|
#include "libc/x/x.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
#include "third_party/puff/puff.h"
|
#include "third_party/puff/puff.h"
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "libc/intrin/nopl.internal.h"
|
#include "libc/intrin/nopl.internal.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
#include "libc/nt/version.h"
|
#include "libc/nt/version.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/runtime/stack.h"
|
#include "libc/runtime/stack.h"
|
||||||
#include "libc/sysv/consts/ss.h"
|
#include "libc/sysv/consts/ss.h"
|
||||||
#include "libc/thread/tls.h"
|
#include "libc/thread/tls.h"
|
||||||
|
|
|
@ -367,10 +367,10 @@ noasan inline void *_Mmap(void *addr, size_t size, int prot, int flags, int fd,
|
||||||
// however this 1mb behavior oddly enough is smart enough to not
|
// however this 1mb behavior oddly enough is smart enough to not
|
||||||
// apply if the mapping is a manually-created guard page.
|
// apply if the mapping is a manually-created guard page.
|
||||||
int e = errno;
|
int e = errno;
|
||||||
if ((dm = sys_mmap(p + size - GUARDSIZE, GUARDSIZE, prot,
|
if ((dm = sys_mmap(p + size - APE_GUARDSIZE, APE_GUARDSIZE, prot,
|
||||||
f | MAP_GROWSDOWN_linux, fd, off))
|
f | MAP_GROWSDOWN_linux, fd, off))
|
||||||
.addr != MAP_FAILED) {
|
.addr != MAP_FAILED) {
|
||||||
_npassert(sys_mmap(p, GUARDSIZE, PROT_NONE,
|
_npassert(sys_mmap(p, APE_GUARDSIZE, PROT_NONE,
|
||||||
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)
|
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)
|
||||||
.addr == p);
|
.addr == p);
|
||||||
dm.addr = p;
|
dm.addr = p;
|
||||||
|
@ -398,11 +398,11 @@ noasan inline void *_Mmap(void *addr, size_t size, int prot, int flags, int fd,
|
||||||
if (needguard) {
|
if (needguard) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
// make windows fork() code simpler
|
// make windows fork() code simpler
|
||||||
mprotect(p, GUARDSIZE, PROT_NONE);
|
mprotect(p, APE_GUARDSIZE, PROT_NONE);
|
||||||
}
|
}
|
||||||
if (IsAsan()) {
|
if (IsAsan()) {
|
||||||
__repstosb((void *)(((intptr_t)p >> 3) + 0x7fff8000),
|
__repstosb((void *)(((intptr_t)p >> 3) + 0x7fff8000),
|
||||||
kAsanStackOverflow, GUARDSIZE / 8);
|
kAsanStackOverflow, APE_GUARDSIZE / 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,19 +41,10 @@ extern bool __isworker;
|
||||||
|
|
||||||
void mcount(void);
|
void mcount(void);
|
||||||
int daemon(int, int);
|
int daemon(int, int);
|
||||||
int _freestack(void *);
|
|
||||||
void _bt(const char *, ...);
|
|
||||||
int _cocmd(int, char **, char **);
|
|
||||||
unsigned long getauxval(unsigned long);
|
unsigned long getauxval(unsigned long);
|
||||||
void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
|
|
||||||
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
|
|
||||||
void *_mapstack(void) returnsaligned((FRAMESIZE)) mallocesque;
|
|
||||||
int setjmp(jmp_buf)
|
int setjmp(jmp_buf)
|
||||||
libcesque returnstwice paramsnonnull();
|
libcesque returnstwice paramsnonnull();
|
||||||
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
||||||
axdx_t setlongerjmp(jmp_buf)
|
|
||||||
libcesque returnstwice paramsnonnull();
|
|
||||||
void longerjmp(jmp_buf, intptr_t) libcesque wontreturn paramsnonnull();
|
|
||||||
int _setjmp(jmp_buf)
|
int _setjmp(jmp_buf)
|
||||||
libcesque returnstwice paramsnonnull();
|
libcesque returnstwice paramsnonnull();
|
||||||
int sigsetjmp(sigjmp_buf, int) libcesque returnstwice paramsnonnull();
|
int sigsetjmp(sigjmp_buf, int) libcesque returnstwice paramsnonnull();
|
||||||
|
@ -62,8 +53,6 @@ void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
||||||
void exit(int) wontreturn;
|
void exit(int) wontreturn;
|
||||||
void _exit(int) libcesque wontreturn;
|
void _exit(int) libcesque wontreturn;
|
||||||
void _Exit(int) libcesque wontreturn;
|
void _Exit(int) libcesque wontreturn;
|
||||||
void _Exitr(int) libcesque wontreturn;
|
|
||||||
void _Exit1(int) libcesque wontreturn;
|
|
||||||
void quick_exit(int) wontreturn;
|
void quick_exit(int) wontreturn;
|
||||||
void abort(void) wontreturn;
|
void abort(void) wontreturn;
|
||||||
int __cxa_atexit(void *, void *, void *) libcesque;
|
int __cxa_atexit(void *, void *, void *) libcesque;
|
||||||
|
@ -92,38 +81,61 @@ int vhangup(void);
|
||||||
int getdtablesize(void);
|
int getdtablesize(void);
|
||||||
int sethostname(const char *, size_t);
|
int sethostname(const char *, size_t);
|
||||||
int acct(const char *);
|
int acct(const char *);
|
||||||
|
|
||||||
|
#ifdef COSMO
|
||||||
|
/* utilities */
|
||||||
void _intsort(int *, size_t);
|
void _intsort(int *, size_t);
|
||||||
void _longsort(long *, size_t);
|
void _longsort(long *, size_t);
|
||||||
bool _isheap(void *);
|
/* diagnostics */
|
||||||
int NtGetVersion(void) pureconst;
|
void ShowCrashReports(void);
|
||||||
|
void __printargs(const char *);
|
||||||
int _getcpucount(void) pureconst;
|
int _getcpucount(void) pureconst;
|
||||||
long _missingno();
|
|
||||||
void __oom_hook(size_t);
|
|
||||||
void _loadxmm(void *);
|
|
||||||
void _peekall(void);
|
|
||||||
void _savexmm(void *);
|
|
||||||
void _weakfree(void *);
|
|
||||||
int _OpenExecutable(void);
|
|
||||||
int ftrace_install(void);
|
int ftrace_install(void);
|
||||||
int ftrace_enabled(int);
|
int ftrace_enabled(int);
|
||||||
int strace_enabled(int);
|
int strace_enabled(int);
|
||||||
long _GetResourceLimit(int);
|
void _bt(const char *, ...);
|
||||||
|
void __print_maps(void);
|
||||||
long _GetMaxFd(void);
|
long _GetMaxFd(void);
|
||||||
|
/* builtin shell language */
|
||||||
|
int _cocmd(int, char **, char **);
|
||||||
|
/* executable program */
|
||||||
char *GetProgramExecutableName(void);
|
char *GetProgramExecutableName(void);
|
||||||
char *GetInterpreterExecutableName(char *, size_t);
|
char *GetInterpreterExecutableName(char *, size_t);
|
||||||
void __printargs(const char *);
|
int _OpenExecutable(void);
|
||||||
void __paginate(int, const char *);
|
|
||||||
int __arg_max(void);
|
|
||||||
void __print_maps(void);
|
|
||||||
void __warn_if_powersave(void);
|
|
||||||
const char *__describe_os(void);
|
|
||||||
bool _IsDynamicExecutable(const char *);
|
bool _IsDynamicExecutable(const char *);
|
||||||
|
/* execution control */
|
||||||
|
int MakeProcessNice(void);
|
||||||
|
axdx_t setlongerjmp(jmp_buf)
|
||||||
|
libcesque returnstwice paramsnonnull();
|
||||||
|
void longerjmp(jmp_buf, intptr_t) libcesque wontreturn paramsnonnull();
|
||||||
|
void __warn_if_powersave(void);
|
||||||
|
void _Exitr(int) libcesque wontreturn;
|
||||||
|
void _Exit1(int) libcesque wontreturn;
|
||||||
void _restorewintty(void);
|
void _restorewintty(void);
|
||||||
|
void __paginate(int, const char *);
|
||||||
|
void _loadxmm(void *);
|
||||||
|
void _savexmm(void *);
|
||||||
|
long _missingno();
|
||||||
|
/* memory management */
|
||||||
|
void _weakfree(void *);
|
||||||
|
void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
|
||||||
|
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
|
||||||
|
void *_mapstack(void) returnsaligned((FRAMESIZE)) mallocesque;
|
||||||
|
int _freestack(void *);
|
||||||
|
void __oom_hook(size_t);
|
||||||
|
void _peekall(void);
|
||||||
|
bool _isheap(void *);
|
||||||
|
/* portability */
|
||||||
|
int NtGetVersion(void) pureconst;
|
||||||
|
bool IsGenuineBlink(void);
|
||||||
|
bool IsCygwin(void);
|
||||||
const char *GetCpuidOs(void);
|
const char *GetCpuidOs(void);
|
||||||
const char *GetCpuidEmulator(void);
|
const char *GetCpuidEmulator(void);
|
||||||
void GetCpuidBrand(char[13], uint32_t);
|
void GetCpuidBrand(char[13], uint32_t);
|
||||||
bool IsGenuineBlink(void);
|
long _GetResourceLimit(int);
|
||||||
bool IsCygwin(void);
|
const char *__describe_os(void);
|
||||||
|
int __arg_max(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
|
#ifndef COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
|
||||||
#define COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
|
#define COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
|
||||||
#include "ape/config.h"
|
|
||||||
#include "libc/dce.h"
|
|
||||||
#include "libc/nt/version.h"
|
|
||||||
#include "libc/runtime/runtime.h"
|
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
|
#ifdef COSMO
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tunes APE stack maximum size.
|
* Tunes APE stack maximum size.
|
||||||
*
|
*
|
||||||
* This defaults to `STACKSIZE`. The bottom-most page will be protected
|
* The bottom-most page will be protected to ensure your stack does not
|
||||||
* to ensure your stack does not magically grow beyond this value. It's
|
* magically grow beyond this value. It's possible to detect stack
|
||||||
* possible to detect stack overflows, by calling `ShowCrashReports()`.
|
* overflows, by calling `ShowCrashReports()`. Your stack size must be a
|
||||||
* Your stack size must be a power of two; the linker will check this.
|
* power of two; the linker will check this.
|
||||||
*
|
*
|
||||||
* If you want to know how much stack your programs needs, then
|
* If you want to know how much stack your programs needs, then
|
||||||
*
|
*
|
||||||
|
@ -24,7 +21,7 @@
|
||||||
* @see ape/ape.lds
|
* @see ape/ape.lds
|
||||||
*/
|
*/
|
||||||
#define STATIC_STACK_SIZE(BYTES) \
|
#define STATIC_STACK_SIZE(BYTES) \
|
||||||
STATIC_SYMBOL("ape_stack_memsz", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)
|
_STACK_SYMBOL("ape_stack_memsz", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tunes APE stack virtual address.
|
* Tunes APE stack virtual address.
|
||||||
|
@ -46,7 +43,7 @@
|
||||||
* @see ape/ape.lds
|
* @see ape/ape.lds
|
||||||
*/
|
*/
|
||||||
#define STATIC_STACK_ADDR(ADDR) \
|
#define STATIC_STACK_ADDR(ADDR) \
|
||||||
STATIC_SYMBOL("ape_stack_vaddr", _STACK_STRINGIFY(ADDR))
|
_STACK_SYMBOL("ape_stack_vaddr", _STACK_STRINGIFY(ADDR))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes program stack executable if declared, e.g.
|
* Makes program stack executable if declared, e.g.
|
||||||
|
@ -63,11 +60,14 @@
|
||||||
* printf("result %d should be 7\n", func());
|
* printf("result %d should be 7\n", func());
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
#define STATIC_EXEC_STACK() STATIC_SYMBOL("ape_stack_pf", "7")
|
#define STATIC_EXEC_STACK() _STACK_SYMBOL("ape_stack_pf", "7")
|
||||||
|
|
||||||
#define _STACK_STRINGIFY(ADDR) #ADDR
|
#define _STACK_STRINGIFY(ADDR) #ADDR
|
||||||
|
#define _STACK_SYMBOL(NAME, VALUE) \
|
||||||
|
asm(".equ\t" NAME "," VALUE "\n\t" \
|
||||||
|
".globl\t" NAME)
|
||||||
|
|
||||||
#if IsAsan()
|
#ifdef __SANITIZE_ADDRESS__
|
||||||
#define _STACK_EXTRA "*2"
|
#define _STACK_EXTRA "*2"
|
||||||
#else
|
#else
|
||||||
#define _STACK_EXTRA ""
|
#define _STACK_EXTRA ""
|
||||||
|
@ -125,7 +125,7 @@ extern char ape_stack_align[] __attribute__((__weak__));
|
||||||
* Returns true if at least `n` bytes of stack are available.
|
* Returns true if at least `n` bytes of stack are available.
|
||||||
*/
|
*/
|
||||||
#define HaveStackMemory(n) \
|
#define HaveStackMemory(n) \
|
||||||
((intptr_t)__builtin_frame_address(0) >= GetStackAddr() + GUARDSIZE + (n))
|
((intptr_t)__builtin_frame_address(0) >= GetStackAddr() + APE_GUARDSIZE + (n))
|
||||||
|
|
||||||
forceinline void CheckLargeStackAllocation(void *p, ssize_t n) {
|
forceinline void CheckLargeStackAllocation(void *p, ssize_t n) {
|
||||||
for (; n > 0; n -= 4096) {
|
for (; n > 0; n -= 4096) {
|
||||||
|
@ -133,6 +133,7 @@ forceinline void CheckLargeStackAllocation(void *p, ssize_t n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* COSMO */
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* GNU ELF */
|
#endif /* GNU ELF */
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_SYMBOLS_H_
|
#ifndef COSMOPOLITAN_LIBC_SYMBOLS_H_
|
||||||
#define COSMOPOLITAN_LIBC_SYMBOLS_H_
|
#define COSMOPOLITAN_LIBC_SYMBOLS_H_
|
||||||
#include "libc/intrin/bits.h"
|
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
#define SYMBOLS_MAGIC READ32LE("SYMT")
|
#define SYMBOLS_MAGIC 0x544d5953 /* SYMT */
|
||||||
#define SYMBOLS_ABI 1
|
#define SYMBOLS_ABI 1
|
||||||
|
|
||||||
struct Symbol {
|
struct Symbol {
|
||||||
|
|
|
@ -18,9 +18,9 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/struct/bpf.h"
|
#include "libc/calls/struct/bpf.internal.h"
|
||||||
#include "libc/calls/struct/filter.h"
|
#include "libc/calls/struct/filter.internal.h"
|
||||||
#include "libc/calls/struct/seccomp.h"
|
#include "libc/calls/struct/seccomp.internal.h"
|
||||||
#include "libc/calls/struct/sigaction.h"
|
#include "libc/calls/struct/sigaction.h"
|
||||||
#include "libc/calls/struct/sigset.h"
|
#include "libc/calls/struct/sigset.h"
|
||||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_STDIO_APPEND_H_
|
#ifndef COSMOPOLITAN_LIBC_STDIO_APPEND_H_
|
||||||
#define COSMOPOLITAN_LIBC_STDIO_APPEND_H_
|
#define COSMOPOLITAN_LIBC_STDIO_APPEND_H_
|
||||||
#include "libc/fmt/pflink.h"
|
|
||||||
#ifdef COSMO
|
#ifdef COSMO
|
||||||
|
|
||||||
#define APPEND_COOKIE 21578
|
#define APPEND_COOKIE 21578
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "libc/sysv/consts/s.h"
|
#include "libc/sysv/consts/s.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/thread/thread.h"
|
#include "libc/thread/thread.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns comment of zip central directory.
|
* Returns comment of zip central directory.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns comment of zip central directory.
|
* Returns comment of zip central directory.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns offset of zip central directory.
|
* Returns offset of zip central directory.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns number of records in zip central directory.
|
* Returns number of records in zip central directory.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns size of zip central directory.
|
* Returns size of zip central directory.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns compressed size in bytes from zip central directory header.
|
* Returns compressed size in bytes from zip central directory header.
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/nt/enum/fileflagandattributes.h"
|
#include "libc/nt/enum/fileflagandattributes.h"
|
||||||
#include "libc/sysv/consts/s.h"
|
#include "libc/sysv/consts/s.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
static int ConvertWindowsToUnixMode(int x) {
|
static int ConvertWindowsToUnixMode(int x) {
|
||||||
int m;
|
int m;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns offset of local file header.
|
* Returns offset of local file header.
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/fmt/conv.h"
|
#include "libc/fmt/conv.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
static inline int pop(int x) {
|
static inline int pop(int x) {
|
||||||
return !!(x & 1) + !!(x & 2) + !!(x & 4);
|
return !!(x & 1) + !!(x & 2) + !!(x & 4);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns uncompressed size in bytes from zip central directory header.
|
* Returns uncompressed size in bytes from zip central directory header.
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/intrin/bits.h"
|
#include "libc/intrin/bits.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
typedef char v16qi __attribute__((__vector_size__(16)));
|
typedef char v16qi __attribute__((__vector_size__(16)));
|
||||||
typedef short v8hi __attribute__((__vector_size__(16)));
|
typedef short v8hi __attribute__((__vector_size__(16)));
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns compressed size in bytes from zip local file header.
|
* Returns compressed size in bytes from zip local file header.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns uncompressed size in bytes from zip local file header.
|
* Returns uncompressed size in bytes from zip local file header.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if ZIP EOCD record seems legit.
|
* Determines if ZIP EOCD record seems legit.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns kZipOk if zip64 end of central directory header seems legit.
|
* Returns kZipOk if zip64 end of central directory header seems legit.
|
||||||
|
|
|
@ -415,7 +415,7 @@ _init_systemfive_pid:
|
||||||
mov (%rdi),%eax
|
mov (%rdi),%eax
|
||||||
testb $_HOSTWINDOWS|_HOSTMETAL,(%rcx)
|
testb $_HOSTWINDOWS|_HOSTMETAL,(%rcx)
|
||||||
jnz 1f
|
jnz 1f
|
||||||
mov __NR_getpid,%eax
|
mov __NR_getpid(%rip),%eax
|
||||||
syscall
|
syscall
|
||||||
1: stosq
|
1: stosq
|
||||||
.endfn _init_systemfive_pid
|
.endfn _init_systemfive_pid
|
||||||
|
@ -433,7 +433,7 @@ _init_systemfive_sigsys:
|
||||||
push %rax
|
push %rax
|
||||||
push %rax
|
push %rax
|
||||||
push $SIG_IGN // sigaction_meta size 48
|
push $SIG_IGN // sigaction_meta size 48
|
||||||
mov __NR_sigaction,%eax // mag
|
mov __NR_sigaction(%rip),%eax // mag
|
||||||
mov SIGSYS,%edi // sig
|
mov SIGSYS,%edi // sig
|
||||||
mov %rsp,%rsi // new
|
mov %rsp,%rsi // new
|
||||||
xor %edx,%edx // old
|
xor %edx,%edx // old
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
errno_t pthread_attr_init(pthread_attr_t *attr) {
|
errno_t pthread_attr_init(pthread_attr_t *attr) {
|
||||||
*attr = (pthread_attr_t){
|
*attr = (pthread_attr_t){
|
||||||
.__stacksize = GetStackSize(),
|
.__stacksize = GetStackSize(),
|
||||||
.__guardsize = GUARDSIZE,
|
.__guardsize = APE_GUARDSIZE,
|
||||||
};
|
};
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,12 +174,12 @@ static errno_t pthread_create_impl(pthread_t *thread,
|
||||||
pt->flags = PT_OWNSTACK;
|
pt->flags = PT_OWNSTACK;
|
||||||
pt->attr.__stacksize = MAX(pt->attr.__stacksize, GetStackSize());
|
pt->attr.__stacksize = MAX(pt->attr.__stacksize, GetStackSize());
|
||||||
pt->attr.__stacksize = _roundup2pow(pt->attr.__stacksize);
|
pt->attr.__stacksize = _roundup2pow(pt->attr.__stacksize);
|
||||||
pt->attr.__guardsize = ROUNDUP(pt->attr.__guardsize, GUARDSIZE);
|
pt->attr.__guardsize = ROUNDUP(pt->attr.__guardsize, APE_GUARDSIZE);
|
||||||
if (pt->attr.__guardsize + GUARDSIZE >= pt->attr.__stacksize) {
|
if (pt->attr.__guardsize + APE_GUARDSIZE >= pt->attr.__stacksize) {
|
||||||
_pthread_free(pt);
|
_pthread_free(pt);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
if (pt->attr.__guardsize == GUARDSIZE) {
|
if (pt->attr.__guardsize == APE_GUARDSIZE) {
|
||||||
// user is wisely using smaller stacks with default guard size
|
// user is wisely using smaller stacks with default guard size
|
||||||
pt->attr.__stackaddr =
|
pt->attr.__stackaddr =
|
||||||
mmap(0, pt->attr.__stacksize, PROT_READ | PROT_WRITE,
|
mmap(0, pt->attr.__stacksize, PROT_READ | PROT_WRITE,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define COSMOPOLITAN_LIBC_THREAD_THREAD_H_
|
#define COSMOPOLITAN_LIBC_THREAD_THREAD_H_
|
||||||
|
|
||||||
#define PTHREAD_KEYS_MAX 128
|
#define PTHREAD_KEYS_MAX 128
|
||||||
#define PTHREAD_STACK_MIN FRAMESIZE
|
#define PTHREAD_STACK_MIN 65536
|
||||||
#define PTHREAD_DESTRUCTOR_ITERATIONS 4
|
#define PTHREAD_DESTRUCTOR_ITERATIONS 4
|
||||||
|
|
||||||
#define PTHREAD_BARRIER_SERIAL_THREAD 31337
|
#define PTHREAD_BARRIER_SERIAL_THREAD 31337
|
||||||
|
|
221
libc/zip.internal.h
Normal file
221
libc/zip.internal.h
Normal file
|
@ -0,0 +1,221 @@
|
||||||
|
#ifndef COSMOPOLITAN_LIBC_ZIP_H_
|
||||||
|
#define COSMOPOLITAN_LIBC_ZIP_H_
|
||||||
|
#include "libc/calls/struct/timespec.h"
|
||||||
|
#include "libc/intrin/bits.h"
|
||||||
|
#include "libc/macros.internal.h"
|
||||||
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fileoverview PKZIP Data Structures.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define kZipOk 0
|
||||||
|
#define kZipErrorEocdNotFound -1
|
||||||
|
#define kZipErrorEocdOffsetOverflow -2
|
||||||
|
#define kZipErrorEocdMagicNotFound -3
|
||||||
|
#define kZipErrorEocdSizeOverflow -4
|
||||||
|
#define kZipErrorEocdDiskMismatch -5
|
||||||
|
#define kZipErrorCdirRecordsMismatch -6
|
||||||
|
#define kZipErrorCdirRecordsOverflow -7
|
||||||
|
#define kZipErrorCdirOffsetPastEocd -8
|
||||||
|
#define kZipErrorCdirLocatorMagic -9
|
||||||
|
#define kZipErrorCdirLocatorOffset -10
|
||||||
|
#define kZipErrorRaceCondition -11
|
||||||
|
#define kZipErrorMapFailed -12
|
||||||
|
#define kZipErrorOpenFailed -13
|
||||||
|
|
||||||
|
#define kZipAlign 2
|
||||||
|
|
||||||
|
#define kZipCosmopolitanVersion kZipEra2001
|
||||||
|
|
||||||
|
#define kZipOsDos 0
|
||||||
|
#define kZipOsAmiga 1
|
||||||
|
#define kZipOsOpenvms 2
|
||||||
|
#define kZipOsUnix 3
|
||||||
|
#define kZipOsVmcms 4
|
||||||
|
#define kZipOsAtarist 5
|
||||||
|
#define kZipOsOs2hpfs 6
|
||||||
|
#define kZipOsMacintosh 7
|
||||||
|
#define kZipOsZsystem 8
|
||||||
|
#define kZipOsCpm 9
|
||||||
|
#define kZipOsWindowsntfs 10
|
||||||
|
#define kZipOsMvsos390zos 11
|
||||||
|
#define kZipOsVse 12
|
||||||
|
#define kZipOsAcornrisc 13
|
||||||
|
#define kZipOsVfat 14
|
||||||
|
#define kZipOsAltmvs 15
|
||||||
|
#define kZipOsBeos 16
|
||||||
|
#define kZipOsTandem 17
|
||||||
|
#define kZipOsOs400 18
|
||||||
|
#define kZipOsOsxdarwin 19
|
||||||
|
|
||||||
|
#define kZipEra1989 10 /* PKZIP 1.0 */
|
||||||
|
#define kZipEra1993 20 /* PKZIP 2.0: deflate/subdir/etc. support */
|
||||||
|
#define kZipEra2001 45 /* PKZIP 4.5: kZipExtraZip64 support */
|
||||||
|
|
||||||
|
#define kZipIattrBinary 0 /* first bit not set */
|
||||||
|
#define kZipIattrText 1 /* first bit set */
|
||||||
|
|
||||||
|
#define kZipCompressionNone 0
|
||||||
|
#define kZipCompressionDeflate 8
|
||||||
|
|
||||||
|
#define kZipCdirHdrMagic 0x06054b50 /* PK♣♠ "PK\5\6" */
|
||||||
|
#define kZipCdirHdrMinSize 22
|
||||||
|
#define kZipCdirAlign kZipAlign
|
||||||
|
#define kZipCdirHdrLinkableSize 294
|
||||||
|
|
||||||
|
#define kZipCdir64HdrMagic 0x06064b50 /* PK♣♠ "PK\6\6" */
|
||||||
|
#define kZipCdir64HdrMinSize 56
|
||||||
|
#define kZipCdir64LocatorMagic 0x07064b50 /* PK♠• "PK\6\7" */
|
||||||
|
#define kZipCdir64LocatorSize 20
|
||||||
|
|
||||||
|
#define kZipCfileHdrMagic 0x02014b50 /* PK☺☻ "PK\1\2" */
|
||||||
|
#define kZipCfileHdrMinSize 46
|
||||||
|
#define kZipCfileOffsetGeneralflag 8
|
||||||
|
#define kZipCfileOffsetCompressionmethod 10
|
||||||
|
#define kZipCfileOffsetLastmodifiedtime 12
|
||||||
|
#define kZipCfileOffsetLastmodifieddate 14
|
||||||
|
#define kZipCfileOffsetCrc32 16
|
||||||
|
#define kZipCfileOffsetCompressedsize 20
|
||||||
|
#define kZipCfileOffsetUncompressedsize 24
|
||||||
|
#define kZipCfileOffsetExternalattributes 38
|
||||||
|
#define kZipCfileOffsetOffset 42
|
||||||
|
|
||||||
|
#define kZipLfileHdrMagic 0x04034b50 /* PK♥♦ "PK\3\4" */
|
||||||
|
#define kZipLfileHdrMinSize 30
|
||||||
|
#define kZipLfileOffsetGeneralflag 6
|
||||||
|
#define kZipLfileOffsetCompressionmethod 8
|
||||||
|
#define kZipLfileOffsetLastmodifiedtime 10
|
||||||
|
#define kZipLfileOffsetLastmodifieddate 12
|
||||||
|
#define kZipLfileOffsetCrc32 14
|
||||||
|
#define kZipLfileOffsetCompressedsize 18
|
||||||
|
#define kZipLfileOffsetUncompressedsize 22
|
||||||
|
|
||||||
|
#define kZipGflagUtf8 0x800
|
||||||
|
|
||||||
|
#define kZipExtraHdrSize 4
|
||||||
|
#define kZipExtraZip64 0x0001
|
||||||
|
#define kZipExtraNtfs 0x000a
|
||||||
|
#define kZipExtraUnix 0x000d
|
||||||
|
#define kZipExtraExtendedTimestamp 0x5455
|
||||||
|
#define kZipExtraInfoZipNewUnixExtra 0x7875
|
||||||
|
|
||||||
|
#define kZipCfileMagic "PK\001\002"
|
||||||
|
|
||||||
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
|
|
||||||
|
/* end of central directory record */
|
||||||
|
#define ZIP_CDIR_MAGIC(P) READ32LE(P)
|
||||||
|
#define ZIP_CDIR_DISK(P) READ16LE((P) + 4)
|
||||||
|
#define ZIP_CDIR_STARTINGDISK(P) READ16LE((P) + 6)
|
||||||
|
#define ZIP_CDIR_RECORDSONDISK(P) READ16LE((P) + 8)
|
||||||
|
#define ZIP_CDIR_RECORDS(P) READ16LE((P) + 10)
|
||||||
|
#define ZIP_CDIR_SIZE(P) READ32LE((P) + 12)
|
||||||
|
#define ZIP_CDIR_OFFSET(P) READ32LE((P) + 16)
|
||||||
|
#define ZIP_CDIR_COMMENTSIZE(P) READ16LE((P) + 20)
|
||||||
|
#define ZIP_CDIR_COMMENT(P) ((P) + 22) /* recommend stopping at nul */
|
||||||
|
#define ZIP_CDIR_HDRSIZE(P) (ZIP_CDIR_COMMENTSIZE(P) + kZipCdirHdrMinSize)
|
||||||
|
|
||||||
|
/* zip64 end of central directory record */
|
||||||
|
#define ZIP_CDIR64_MAGIC(P) READ32LE(P)
|
||||||
|
#define ZIP_CDIR64_HDRSIZE(P) (READ64LE((P) + 4) + 12)
|
||||||
|
#define ZIP_CDIR64_VERSIONMADE(P) READ16LE((P) + 12)
|
||||||
|
#define ZIP_CDIR64_VERSIONNEED(P) READ16LE((P) + 14)
|
||||||
|
#define ZIP_CDIR64_DISK(P) READ32LE((P) + 16)
|
||||||
|
#define ZIP_CDIR64_STARTINGDISK(P) READ32LE((P) + 20)
|
||||||
|
#define ZIP_CDIR64_RECORDSONDISK(P) READ64LE((P) + 24)
|
||||||
|
#define ZIP_CDIR64_RECORDS(P) READ64LE((P) + 32)
|
||||||
|
#define ZIP_CDIR64_SIZE(P) READ64LE((P) + 40)
|
||||||
|
#define ZIP_CDIR64_OFFSET(P) READ64LE((P) + 48)
|
||||||
|
#define ZIP_CDIR64_COMMENTSIZE(P) \
|
||||||
|
(ZIP_CDIR64_HDRSIZE(P) >= 56 ? ZIP_CDIR64_HDRSIZE(P) - 56 : 0)
|
||||||
|
#define ZIP_CDIR64_COMMENT(P) ((P) + 56) /* recommend stopping at nul */
|
||||||
|
#define ZIP_LOCATE64_MAGIC(P) READ32LE(P)
|
||||||
|
#define ZIP_LOCATE64_STARTINGDISK(P) READ32LE((P) + 4)
|
||||||
|
#define ZIP_LOCATE64_OFFSET(P) READ64LE((P) + 8)
|
||||||
|
#define ZIP_LOCATE64_TOTALDISKS(P) READ32LE((P) + 12)
|
||||||
|
|
||||||
|
/* central directory file header */
|
||||||
|
#define ZIP_CFILE_MAGIC(P) READ32LE(P)
|
||||||
|
#define ZIP_CFILE_VERSIONMADE(P) (255 & (P)[4])
|
||||||
|
#define ZIP_CFILE_FILEATTRCOMPAT(P) (255 & (P)[5])
|
||||||
|
#define ZIP_CFILE_VERSIONNEED(P) (255 & (P)[6])
|
||||||
|
#define ZIP_CFILE_OSNEED(P) (255 & (P)[7])
|
||||||
|
#define ZIP_CFILE_GENERALFLAG(P) READ16LE((P) + kZipCfileOffsetGeneralflag)
|
||||||
|
#define ZIP_CFILE_COMPRESSIONMETHOD(P) \
|
||||||
|
READ16LE((P) + kZipCfileOffsetCompressionmethod)
|
||||||
|
#define ZIP_CFILE_LASTMODIFIEDTIME(P) \
|
||||||
|
READ16LE((P) + kZipCfileOffsetLastmodifiedtime) /* @see DOS_TIME() */
|
||||||
|
#define ZIP_CFILE_LASTMODIFIEDDATE(P) \
|
||||||
|
READ16LE((P) + kZipCfileOffsetLastmodifieddate) /* @see DOS_DATE() */
|
||||||
|
#define ZIP_CFILE_CRC32(P) READ32LE((P) + kZipCfileOffsetCrc32)
|
||||||
|
#define ZIP_CFILE_COMPRESSEDSIZE(P) READ32LE(P + kZipCfileOffsetCompressedsize)
|
||||||
|
#define ZIP_CFILE_UNCOMPRESSEDSIZE(P) \
|
||||||
|
READ32LE((P) + kZipCfileOffsetUncompressedsize)
|
||||||
|
#define ZIP_CFILE_NAMESIZE(P) READ16LE((P) + 28)
|
||||||
|
#define ZIP_CFILE_EXTRASIZE(P) READ16LE((P) + 30)
|
||||||
|
#define ZIP_CFILE_COMMENTSIZE(P) READ16LE((P) + 32)
|
||||||
|
#define ZIP_CFILE_DISK(P) READ16LE((P) + 34)
|
||||||
|
#define ZIP_CFILE_INTERNALATTRIBUTES(P) READ16LE((P) + 36)
|
||||||
|
#define ZIP_CFILE_EXTERNALATTRIBUTES(P) \
|
||||||
|
READ32LE((P) + kZipCfileOffsetExternalattributes)
|
||||||
|
#define ZIP_CFILE_OFFSET(P) READ32LE((P) + kZipCfileOffsetOffset)
|
||||||
|
#define ZIP_CFILE_NAME(P) ((const char *)((P) + 46)) /* not nul-terminated */
|
||||||
|
#define ZIP_CFILE_EXTRA(P) ((P) + 46 + ZIP_CFILE_NAMESIZE(P))
|
||||||
|
#define ZIP_CFILE_COMMENT(P) \
|
||||||
|
((const char *)((P) + 46 + ZIP_CFILE_NAMESIZE(P) + \
|
||||||
|
ZIP_CFILE_EXTRASIZE(P))) /* recommend stopping at nul */
|
||||||
|
#define ZIP_CFILE_HDRSIZE(P) \
|
||||||
|
(ZIP_CFILE_NAMESIZE(P) + ZIP_CFILE_EXTRASIZE(P) + ZIP_CFILE_COMMENTSIZE(P) + \
|
||||||
|
kZipCfileHdrMinSize)
|
||||||
|
|
||||||
|
/* local file header */
|
||||||
|
#define ZIP_LFILE_MAGIC(P) READ32LE(P)
|
||||||
|
#define ZIP_LFILE_VERSIONNEED(P) (255 & (P)[4])
|
||||||
|
#define ZIP_LFILE_OSNEED(P) (255 & (P)[5])
|
||||||
|
#define ZIP_LFILE_GENERALFLAG(P) READ16LE((P) + kZipLfileOffsetGeneralflag)
|
||||||
|
#define ZIP_LFILE_COMPRESSIONMETHOD(P) \
|
||||||
|
READ16LE((P) + kZipLfileOffsetCompressionmethod)
|
||||||
|
#define ZIP_LFILE_LASTMODIFIEDTIME(P) \
|
||||||
|
READ16LE((P) + kZipLfileOffsetLastmodifiedtime) /* @see DOS_TIME() */
|
||||||
|
#define ZIP_LFILE_LASTMODIFIEDDATE(P) \
|
||||||
|
READ16LE((P) + kZipLfileOffsetLastmodifieddate) /* @see DOS_DATE() */
|
||||||
|
#define ZIP_LFILE_CRC32(P) READ32LE((P) + kZipLfileOffsetCrc32)
|
||||||
|
#define ZIP_LFILE_COMPRESSEDSIZE(P) \
|
||||||
|
READ32LE((P) + kZipLfileOffsetCompressedsize)
|
||||||
|
#define ZIP_LFILE_UNCOMPRESSEDSIZE(P) \
|
||||||
|
READ32LE((P) + kZipLfileOffsetUncompressedsize)
|
||||||
|
#define ZIP_LFILE_NAMESIZE(P) READ16LE((P) + 26)
|
||||||
|
#define ZIP_LFILE_EXTRASIZE(P) READ16LE((P) + 28)
|
||||||
|
#define ZIP_LFILE_NAME(P) ((const char *)((P) + 30))
|
||||||
|
#define ZIP_LFILE_EXTRA(P) ((P) + 30 + ZIP_LFILE_NAMESIZE(P))
|
||||||
|
#define ZIP_LFILE_HDRSIZE(P) \
|
||||||
|
(ZIP_LFILE_NAMESIZE(P) + ZIP_LFILE_EXTRASIZE(P) + kZipLfileHdrMinSize)
|
||||||
|
#define ZIP_LFILE_CONTENT(P) ((P) + ZIP_LFILE_HDRSIZE(P))
|
||||||
|
#define ZIP_LFILE_SIZE(P) (ZIP_LFILE_HDRSIZE(P) + ZIP_LFILE_COMPRESSEDSIZE(P))
|
||||||
|
|
||||||
|
#define ZIP_EXTRA_HEADERID(P) READ16LE(P)
|
||||||
|
#define ZIP_EXTRA_CONTENTSIZE(P) READ16LE((P) + 2)
|
||||||
|
#define ZIP_EXTRA_CONTENT(P) ((P) + 4)
|
||||||
|
#define ZIP_EXTRA_SIZE(P) (ZIP_EXTRA_CONTENTSIZE(P) + kZipExtraHdrSize)
|
||||||
|
|
||||||
|
void *GetZipEocd(const uint8_t *, size_t, int *);
|
||||||
|
uint8_t *FindEmbeddedApe(const uint8_t *, size_t);
|
||||||
|
int IsZipEocd32(const uint8_t *, size_t, size_t);
|
||||||
|
int IsZipEocd64(const uint8_t *, size_t, size_t);
|
||||||
|
int GetZipCfileMode(const uint8_t *);
|
||||||
|
uint64_t GetZipCdirOffset(const uint8_t *);
|
||||||
|
uint64_t GetZipCdirRecords(const uint8_t *);
|
||||||
|
void *GetZipCdirComment(const uint8_t *);
|
||||||
|
uint64_t GetZipCdirSize(const uint8_t *);
|
||||||
|
uint64_t GetZipCdirCommentSize(const uint8_t *);
|
||||||
|
uint64_t GetZipCfileUncompressedSize(const uint8_t *);
|
||||||
|
uint64_t GetZipCfileCompressedSize(const uint8_t *);
|
||||||
|
uint64_t GetZipCfileOffset(const uint8_t *);
|
||||||
|
uint64_t GetZipLfileUncompressedSize(const uint8_t *);
|
||||||
|
uint64_t GetZipLfileCompressedSize(const uint8_t *);
|
||||||
|
void GetZipCfileTimestamps(const uint8_t *, struct timespec *,
|
||||||
|
struct timespec *, struct timespec *, int);
|
||||||
|
|
||||||
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
|
#endif /* COSMOPOLITAN_LIBC_ZIP_H_ */
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/calls/struct/stat.h"
|
#include "libc/calls/struct/stat.h"
|
||||||
#include "libc/sysv/consts/ok.h"
|
#include "libc/sysv/consts/ok.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
|
|
||||||
// TODO: this should check parent directory components
|
// TODO: this should check parent directory components
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/sysv/consts/fd.h"
|
#include "libc/sysv/consts/fd.h"
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
|
|
||||||
#define ZIPOS __zipos_get()
|
#define ZIPOS __zipos_get()
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
|
|
||||||
// TODO(jart): improve time complexity here
|
// TODO(jart): improve time complexity here
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
#include "libc/sysv/consts/prot.h"
|
#include "libc/sysv/consts/prot.h"
|
||||||
#include "libc/thread/thread.h"
|
#include "libc/thread/thread.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/thread/thread.h"
|
#include "libc/thread/thread.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include "libc/sysv/consts/sig.h"
|
#include "libc/sysv/consts/sig.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/thread/thread.h"
|
#include "libc/thread/thread.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
|
|
||||||
static char *mapend;
|
static char *mapend;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/intrin/safemacros.internal.h"
|
#include "libc/intrin/safemacros.internal.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/thread/thread.h"
|
#include "libc/thread/thread.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
|
|
||||||
static size_t GetIovSize(const struct iovec *iov, size_t iovlen) {
|
static size_t GetIovSize(const struct iovec *iov, size_t iovlen) {
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/consts/s.h"
|
#include "libc/sysv/consts/s.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
|
|
||||||
int __zipos_stat_impl(struct Zipos *zipos, size_t cf, struct stat *st) {
|
int __zipos_stat_impl(struct Zipos *zipos, size_t cf, struct stat *st) {
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
#include "libc/time/struct/tm.h"
|
#include "libc/time/struct/tm.h"
|
||||||
#include "libc/x/x.h"
|
#include "libc/x/x.h"
|
||||||
#include "libc/x/xasprintf.h"
|
#include "libc/x/xasprintf.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "net/http/escape.h"
|
#include "net/http/escape.h"
|
||||||
#include "net/http/http.h"
|
#include "net/http/http.h"
|
||||||
#include "net/http/ip.h"
|
#include "net/http/ip.h"
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/pledge.internal.h"
|
#include "libc/calls/pledge.internal.h"
|
||||||
#include "libc/calls/struct/seccomp.h"
|
#include "libc/calls/struct/seccomp.internal.h"
|
||||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/ioctl.h"
|
#include "libc/calls/ioctl.h"
|
||||||
#include "libc/calls/pledge.internal.h"
|
#include "libc/calls/pledge.internal.h"
|
||||||
#include "libc/calls/struct/bpf.h"
|
#include "libc/calls/struct/bpf.internal.h"
|
||||||
#include "libc/calls/struct/filter.h"
|
#include "libc/calls/struct/filter.internal.h"
|
||||||
#include "libc/calls/struct/flock.h"
|
#include "libc/calls/struct/flock.h"
|
||||||
#include "libc/calls/struct/seccomp.h"
|
#include "libc/calls/struct/seccomp.internal.h"
|
||||||
#include "libc/calls/struct/sigaction.h"
|
#include "libc/calls/struct/sigaction.h"
|
||||||
#include "libc/calls/struct/sigset.h"
|
#include "libc/calls/struct/sigset.h"
|
||||||
#include "libc/calls/struct/stat.h"
|
#include "libc/calls/struct/stat.h"
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/struct/bpf.h"
|
#include "libc/calls/struct/bpf.internal.h"
|
||||||
#include "libc/calls/struct/filter.h"
|
#include "libc/calls/struct/filter.internal.h"
|
||||||
#include "libc/calls/struct/iovec.h"
|
#include "libc/calls/struct/iovec.h"
|
||||||
#include "libc/calls/struct/seccomp.h"
|
#include "libc/calls/struct/seccomp.internal.h"
|
||||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
|
@ -128,8 +128,8 @@ TEST(setrlimit, testMemoryLimit) {
|
||||||
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
||||||
if (wstatus == -2) {
|
if (wstatus == -2) {
|
||||||
ASSERT_EQ(0, SetKernelEnforcedMemoryLimit(MEM));
|
ASSERT_EQ(0, SetKernelEnforcedMemoryLimit(MEM));
|
||||||
for (gotsome = i = 0; i < (MEM * 2) / GUARDSIZE; ++i) {
|
for (gotsome = i = 0; i < (MEM * 2) / APE_GUARDSIZE; ++i) {
|
||||||
p = mmap(0, GUARDSIZE, PROT_READ | PROT_WRITE,
|
p = mmap(0, APE_GUARDSIZE, PROT_READ | PROT_WRITE,
|
||||||
MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE, -1, 0);
|
MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE, -1, 0);
|
||||||
if (p != MAP_FAILED) {
|
if (p != MAP_FAILED) {
|
||||||
gotsome = true;
|
gotsome = true;
|
||||||
|
@ -141,7 +141,7 @@ TEST(setrlimit, testMemoryLimit) {
|
||||||
ASSERT_EQ(ENOMEM, errno);
|
ASSERT_EQ(ENOMEM, errno);
|
||||||
_Exit(0);
|
_Exit(0);
|
||||||
}
|
}
|
||||||
rngset(p, GUARDSIZE, _rand64, -1);
|
rngset(p, APE_GUARDSIZE, _rand64, -1);
|
||||||
}
|
}
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
}
|
}
|
||||||
|
@ -161,15 +161,15 @@ TEST(setrlimit, testVirtualMemoryLimit) {
|
||||||
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
||||||
if (wstatus == -2) {
|
if (wstatus == -2) {
|
||||||
ASSERT_EQ(0, setrlimit(RLIMIT_AS, &(struct rlimit){MEM, MEM}));
|
ASSERT_EQ(0, setrlimit(RLIMIT_AS, &(struct rlimit){MEM, MEM}));
|
||||||
for (i = 0; i < (MEM * 2) / GUARDSIZE; ++i) {
|
for (i = 0; i < (MEM * 2) / APE_GUARDSIZE; ++i) {
|
||||||
p = sys_mmap(0, GUARDSIZE, PROT_READ | PROT_WRITE,
|
p = sys_mmap(0, APE_GUARDSIZE, PROT_READ | PROT_WRITE,
|
||||||
MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE, -1, 0)
|
MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE, -1, 0)
|
||||||
.addr;
|
.addr;
|
||||||
if (p == MAP_FAILED) {
|
if (p == MAP_FAILED) {
|
||||||
ASSERT_EQ(ENOMEM, errno);
|
ASSERT_EQ(ENOMEM, errno);
|
||||||
_Exit(0);
|
_Exit(0);
|
||||||
}
|
}
|
||||||
rngset(p, GUARDSIZE, _rand64, -1);
|
rngset(p, APE_GUARDSIZE, _rand64, -1);
|
||||||
}
|
}
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
}
|
}
|
||||||
|
@ -191,15 +191,15 @@ TEST(setrlimit, testDataMemoryLimit) {
|
||||||
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
||||||
if (wstatus == -2) {
|
if (wstatus == -2) {
|
||||||
ASSERT_EQ(0, setrlimit(RLIMIT_DATA, &(struct rlimit){MEM, MEM}));
|
ASSERT_EQ(0, setrlimit(RLIMIT_DATA, &(struct rlimit){MEM, MEM}));
|
||||||
for (i = 0; i < (MEM * 2) / GUARDSIZE; ++i) {
|
for (i = 0; i < (MEM * 2) / APE_GUARDSIZE; ++i) {
|
||||||
p = sys_mmap(0, GUARDSIZE, PROT_READ | PROT_WRITE,
|
p = sys_mmap(0, APE_GUARDSIZE, PROT_READ | PROT_WRITE,
|
||||||
MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE, -1, 0)
|
MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE, -1, 0)
|
||||||
.addr;
|
.addr;
|
||||||
if (p == MAP_FAILED) {
|
if (p == MAP_FAILED) {
|
||||||
ASSERT_EQ(ENOMEM, errno);
|
ASSERT_EQ(ENOMEM, errno);
|
||||||
_Exit(0);
|
_Exit(0);
|
||||||
}
|
}
|
||||||
rngset(p, GUARDSIZE, _rand64, -1);
|
rngset(p, APE_GUARDSIZE, _rand64, -1);
|
||||||
}
|
}
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/runtime/memtrack.internal.h"
|
#include "libc/runtime/memtrack.internal.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/runtime/stack.h"
|
||||||
#include "libc/stdio/rand.h"
|
#include "libc/stdio/rand.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
@ -150,17 +151,18 @@ TEST(mmap, testMapFixed_destroysEverythingInItsPath) {
|
||||||
TEST(mmap, customStackMemory_isAuthorized) {
|
TEST(mmap, customStackMemory_isAuthorized) {
|
||||||
char *stack;
|
char *stack;
|
||||||
uintptr_t w, r;
|
uintptr_t w, r;
|
||||||
ASSERT_NE(MAP_FAILED, (stack = mmap(NULL, STACKSIZE, PROT_READ | PROT_WRITE,
|
ASSERT_NE(MAP_FAILED,
|
||||||
MAP_ANONYMOUS | MAP_STACK, -1, 0)));
|
(stack = mmap(NULL, GetStackSize(), PROT_READ | PROT_WRITE,
|
||||||
|
MAP_ANONYMOUS | MAP_STACK, -1, 0)));
|
||||||
asm("mov\t%%rsp,%0\n\t"
|
asm("mov\t%%rsp,%0\n\t"
|
||||||
"mov\t%2,%%rsp\n\t"
|
"mov\t%2,%%rsp\n\t"
|
||||||
"push\t%3\n\t"
|
"push\t%3\n\t"
|
||||||
"pop\t%1\n\t"
|
"pop\t%1\n\t"
|
||||||
"mov\t%0,%%rsp"
|
"mov\t%0,%%rsp"
|
||||||
: "=&r"(w), "=&r"(r)
|
: "=&r"(w), "=&r"(r)
|
||||||
: "rm"(stack + STACKSIZE - 8), "i"(123));
|
: "rm"(stack + GetStackSize() - 8), "i"(123));
|
||||||
ASSERT_EQ(123, r);
|
ASSERT_EQ(123, r);
|
||||||
EXPECT_SYS(0, 0, munmap(stack, STACKSIZE));
|
EXPECT_SYS(0, 0, munmap(stack, GetStackSize()));
|
||||||
}
|
}
|
||||||
#endif /* __x86_64__ */
|
#endif /* __x86_64__ */
|
||||||
|
|
||||||
|
|
|
@ -114,9 +114,9 @@ void TearDown(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(mprotect, testOkMemory) {
|
TEST(mprotect, testOkMemory) {
|
||||||
char *p = gc(memalign(GUARDSIZE, GUARDSIZE));
|
char *p = gc(memalign(APE_GUARDSIZE, APE_GUARDSIZE));
|
||||||
p[0] = 0;
|
p[0] = 0;
|
||||||
ASSERT_NE(-1, mprotect(p, GUARDSIZE, PROT_READ | PROT_WRITE));
|
ASSERT_NE(-1, mprotect(p, APE_GUARDSIZE, PROT_READ | PROT_WRITE));
|
||||||
p[0] = 1;
|
p[0] = 1;
|
||||||
EXPECT_EQ(1, p[0]);
|
EXPECT_EQ(1, p[0]);
|
||||||
EXPECT_FALSE(gotsegv);
|
EXPECT_FALSE(gotsegv);
|
||||||
|
@ -125,19 +125,19 @@ TEST(mprotect, testOkMemory) {
|
||||||
|
|
||||||
TEST(mprotect, testSegfault_writeToReadOnlyAnonymous) {
|
TEST(mprotect, testSegfault_writeToReadOnlyAnonymous) {
|
||||||
volatile char *p;
|
volatile char *p;
|
||||||
p = gc(memalign(GUARDSIZE, GUARDSIZE));
|
p = gc(memalign(APE_GUARDSIZE, APE_GUARDSIZE));
|
||||||
EXPECT_FALSE(gotsegv);
|
EXPECT_FALSE(gotsegv);
|
||||||
p[0] = 1;
|
p[0] = 1;
|
||||||
EXPECT_FALSE(gotsegv);
|
EXPECT_FALSE(gotsegv);
|
||||||
EXPECT_FALSE(gotbusted);
|
EXPECT_FALSE(gotbusted);
|
||||||
EXPECT_NE(-1, mprotect(p, GUARDSIZE, PROT_READ));
|
EXPECT_NE(-1, mprotect(p, APE_GUARDSIZE, PROT_READ));
|
||||||
_missingno(p[0]);
|
_missingno(p[0]);
|
||||||
EXPECT_FALSE(gotsegv);
|
EXPECT_FALSE(gotsegv);
|
||||||
EXPECT_FALSE(gotbusted);
|
EXPECT_FALSE(gotbusted);
|
||||||
p[0] = 2;
|
p[0] = 2;
|
||||||
EXPECT_TRUE(gotsegv | gotbusted);
|
EXPECT_TRUE(gotsegv | gotbusted);
|
||||||
EXPECT_EQ(1, p[0]);
|
EXPECT_EQ(1, p[0]);
|
||||||
EXPECT_NE(-1, mprotect(p, GUARDSIZE, PROT_READ | PROT_WRITE));
|
EXPECT_NE(-1, mprotect(p, APE_GUARDSIZE, PROT_READ | PROT_WRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(mprotect, testExecOnly_canExecute) {
|
TEST(mprotect, testExecOnly_canExecute) {
|
||||||
|
@ -157,33 +157,33 @@ TEST(mprotect, testExecOnly_canExecute) {
|
||||||
|
|
||||||
TEST(mprotect, testProtNone_cantEvenRead) {
|
TEST(mprotect, testProtNone_cantEvenRead) {
|
||||||
volatile char *p;
|
volatile char *p;
|
||||||
p = gc(memalign(GUARDSIZE, GUARDSIZE));
|
p = gc(memalign(APE_GUARDSIZE, APE_GUARDSIZE));
|
||||||
EXPECT_NE(-1, mprotect(p, GUARDSIZE, PROT_NONE));
|
EXPECT_NE(-1, mprotect(p, APE_GUARDSIZE, PROT_NONE));
|
||||||
_missingno(p[0]);
|
_missingno(p[0]);
|
||||||
EXPECT_TRUE(gotsegv | gotbusted);
|
EXPECT_TRUE(gotsegv | gotbusted);
|
||||||
EXPECT_NE(-1, mprotect(p, GUARDSIZE, PROT_READ | PROT_WRITE));
|
EXPECT_NE(-1, mprotect(p, APE_GUARDSIZE, PROT_READ | PROT_WRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(mprotect, testExecJit_actuallyWorks) {
|
TEST(mprotect, testExecJit_actuallyWorks) {
|
||||||
int (*p)(void) = gc(memalign(GUARDSIZE, GUARDSIZE));
|
int (*p)(void) = gc(memalign(APE_GUARDSIZE, APE_GUARDSIZE));
|
||||||
memcpy(p, kRet31337, sizeof(kRet31337));
|
memcpy(p, kRet31337, sizeof(kRet31337));
|
||||||
EXPECT_NE(-1, mprotect(p, GUARDSIZE, PROT_EXEC));
|
EXPECT_NE(-1, mprotect(p, APE_GUARDSIZE, PROT_EXEC));
|
||||||
EXPECT_EQ(31337, p());
|
EXPECT_EQ(31337, p());
|
||||||
EXPECT_FALSE(gotsegv);
|
EXPECT_FALSE(gotsegv);
|
||||||
EXPECT_FALSE(gotbusted);
|
EXPECT_FALSE(gotbusted);
|
||||||
EXPECT_NE(-1, mprotect(p, GUARDSIZE, PROT_READ | PROT_WRITE));
|
EXPECT_NE(-1, mprotect(p, APE_GUARDSIZE, PROT_READ | PROT_WRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(mprotect, testRwxMap_vonNeumannRules) {
|
TEST(mprotect, testRwxMap_vonNeumannRules) {
|
||||||
if (IsOpenbsd()) return; // boo
|
if (IsOpenbsd()) return; // boo
|
||||||
if (IsXnuSilicon()) return; // boo
|
if (IsXnuSilicon()) return; // boo
|
||||||
int (*p)(void) = gc(memalign(GUARDSIZE, GUARDSIZE));
|
int (*p)(void) = gc(memalign(APE_GUARDSIZE, APE_GUARDSIZE));
|
||||||
memcpy(p, kRet31337, sizeof(kRet31337));
|
memcpy(p, kRet31337, sizeof(kRet31337));
|
||||||
EXPECT_NE(-1, mprotect(p, GUARDSIZE, PROT_READ | PROT_WRITE | PROT_EXEC));
|
EXPECT_NE(-1, mprotect(p, APE_GUARDSIZE, PROT_READ | PROT_WRITE | PROT_EXEC));
|
||||||
EXPECT_EQ(31337, p());
|
EXPECT_EQ(31337, p());
|
||||||
EXPECT_FALSE(gotsegv);
|
EXPECT_FALSE(gotsegv);
|
||||||
EXPECT_FALSE(gotbusted);
|
EXPECT_FALSE(gotbusted);
|
||||||
EXPECT_NE(-1, mprotect(p, GUARDSIZE, PROT_READ | PROT_WRITE));
|
EXPECT_NE(-1, mprotect(p, APE_GUARDSIZE, PROT_READ | PROT_WRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(mprotect, testExecuteFlatFileMapOpenedAsReadonly) {
|
TEST(mprotect, testExecuteFlatFileMapOpenedAsReadonly) {
|
||||||
|
@ -218,13 +218,13 @@ TEST(mprotect, testFileMap_canChangeToExecWhileOpenInRdwrMode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(mprotect, testBadProt_failsEinval) {
|
TEST(mprotect, testBadProt_failsEinval) {
|
||||||
volatile char *p = gc(memalign(GUARDSIZE, GUARDSIZE));
|
volatile char *p = gc(memalign(APE_GUARDSIZE, APE_GUARDSIZE));
|
||||||
EXPECT_EQ(-1, mprotect(p, 9999, -1));
|
EXPECT_EQ(-1, mprotect(p, 9999, -1));
|
||||||
EXPECT_EQ(EINVAL, errno);
|
EXPECT_EQ(EINVAL, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(mprotect, testZeroSize_doesNothing) {
|
TEST(mprotect, testZeroSize_doesNothing) {
|
||||||
volatile char *p = gc(memalign(GUARDSIZE, GUARDSIZE));
|
volatile char *p = gc(memalign(APE_GUARDSIZE, APE_GUARDSIZE));
|
||||||
EXPECT_NE(-1, mprotect(p, 0, PROT_READ));
|
EXPECT_NE(-1, mprotect(p, 0, PROT_READ));
|
||||||
p[0] = 1;
|
p[0] = 1;
|
||||||
EXPECT_FALSE(gotsegv);
|
EXPECT_FALSE(gotsegv);
|
||||||
|
|
6
third_party/getopt/getopt.h
vendored
6
third_party/getopt/getopt.h
vendored
|
@ -1,6 +1,5 @@
|
||||||
#ifndef COSMOPOLITAN_THIRD_PARTY_GETOPT_GETOPT_H_
|
#ifndef COSMOPOLITAN_THIRD_PARTY_GETOPT_GETOPT_H_
|
||||||
#define COSMOPOLITAN_THIRD_PARTY_GETOPT_GETOPT_H_
|
#define COSMOPOLITAN_THIRD_PARTY_GETOPT_GETOPT_H_
|
||||||
#ifdef COSMO
|
|
||||||
|
|
||||||
#define no_argument 0
|
#define no_argument 0
|
||||||
#define required_argument 1
|
#define required_argument 1
|
||||||
|
@ -12,8 +11,8 @@ COSMOPOLITAN_C_START_
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
extern int optind, opterr, optopt, optreset;
|
extern int optind, opterr, optopt, optreset;
|
||||||
|
|
||||||
int getopt(int, char *const[], const char *);
|
int getopt(int, char *const[], const char *) paramsnonnull();
|
||||||
int getsubopt(char **, char *const *, char **);
|
int getsubopt(char **, char *const *, char **) paramsnonnull();
|
||||||
|
|
||||||
struct option {
|
struct option {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -28,5 +27,4 @@ int getopt_long_only(int, char *const *, const char *, const struct option *,
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
#endif /* COSMO */
|
|
||||||
#endif /* COSMOPOLITAN_THIRD_PARTY_GETOPT_GETOPT_H_ */
|
#endif /* COSMOPOLITAN_THIRD_PARTY_GETOPT_GETOPT_H_ */
|
||||||
|
|
3
third_party/getopt/getsubopt.c
vendored
3
third_party/getopt/getsubopt.c
vendored
|
@ -48,9 +48,6 @@ getsubopt(char **optionp, char * const *tokens, char **valuep)
|
||||||
|
|
||||||
suboptarg = *valuep = NULL;
|
suboptarg = *valuep = NULL;
|
||||||
|
|
||||||
if (!optionp || !*optionp)
|
|
||||||
return(-1);
|
|
||||||
|
|
||||||
/* skip leading white-space, commas */
|
/* skip leading white-space, commas */
|
||||||
for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
|
for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
|
||||||
|
|
||||||
|
|
4
third_party/lua/luaencodejsondata.c
vendored
4
third_party/lua/luaencodejsondata.c
vendored
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/intrin/bits.h"
|
#include "libc/intrin/bits.h"
|
||||||
#include "libc/intrin/likely.h"
|
#include "libc/intrin/likely.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/log/rop.h"
|
#include "libc/log/rop.internal.h"
|
||||||
#include "libc/mem/gc.internal.h"
|
#include "libc/mem/gc.internal.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/runtime/stack.h"
|
#include "libc/runtime/stack.h"
|
||||||
|
@ -169,7 +169,7 @@ static int SerializeTable(lua_State *L, char **buf, int idx,
|
||||||
bool multi;
|
bool multi;
|
||||||
bool isarray;
|
bool isarray;
|
||||||
lua_Unsigned n;
|
lua_Unsigned n;
|
||||||
if (UNLIKELY(!HaveStackMemory(GUARDSIZE))) {
|
if (UNLIKELY(!HaveStackMemory(APE_GUARDSIZE))) {
|
||||||
z->reason = "out of stack";
|
z->reason = "out of stack";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
4
third_party/lua/luaencodeluadata.c
vendored
4
third_party/lua/luaencodeluadata.c
vendored
|
@ -19,7 +19,7 @@
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
#include "libc/fmt/itoa.h"
|
#include "libc/fmt/itoa.h"
|
||||||
#include "libc/intrin/bits.h"
|
#include "libc/intrin/bits.h"
|
||||||
#include "libc/log/rop.h"
|
#include "libc/log/rop.internal.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/runtime/stack.h"
|
#include "libc/runtime/stack.h"
|
||||||
|
@ -353,7 +353,7 @@ static int SerializeTable(lua_State *L, char **buf, int idx,
|
||||||
int rc;
|
int rc;
|
||||||
bool multi;
|
bool multi;
|
||||||
intptr_t rsp, bot;
|
intptr_t rsp, bot;
|
||||||
if (UNLIKELY(!HaveStackMemory(GUARDSIZE))) {
|
if (UNLIKELY(!HaveStackMemory(APE_GUARDSIZE))) {
|
||||||
z->reason = "out of stack";
|
z->reason = "out of stack";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
2
third_party/lua/lunix.c
vendored
2
third_party/lua/lunix.c
vendored
|
@ -24,7 +24,7 @@
|
||||||
#include "libc/calls/ioctl.h"
|
#include "libc/calls/ioctl.h"
|
||||||
#include "libc/calls/makedev.h"
|
#include "libc/calls/makedev.h"
|
||||||
#include "libc/calls/pledge.h"
|
#include "libc/calls/pledge.h"
|
||||||
#include "libc/calls/struct/bpf.h"
|
#include "libc/calls/struct/bpf.internal.h"
|
||||||
#include "libc/calls/struct/dirent.h"
|
#include "libc/calls/struct/dirent.h"
|
||||||
#include "libc/calls/struct/flock.h"
|
#include "libc/calls/struct/flock.h"
|
||||||
#include "libc/calls/struct/itimerval.h"
|
#include "libc/calls/struct/itimerval.h"
|
||||||
|
|
2
third_party/lua/serialize.c
vendored
2
third_party/lua/serialize.c
vendored
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/log/rop.h"
|
#include "libc/log/rop.internal.h"
|
||||||
#include "libc/stdio/append.h"
|
#include "libc/stdio/append.h"
|
||||||
#include "third_party/lua/cosmo.h"
|
#include "third_party/lua/cosmo.h"
|
||||||
#include "third_party/lua/lua.h"
|
#include "third_party/lua/lua.h"
|
||||||
|
|
2
third_party/make/function.c
vendored
2
third_party/make/function.c
vendored
|
@ -24,7 +24,7 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
#include "third_party/make/os.h"
|
#include "third_party/make/os.h"
|
||||||
#include "third_party/make/commands.h"
|
#include "third_party/make/commands.h"
|
||||||
#include "libc/mem/critbit0.h"
|
#include "libc/mem/critbit0.h"
|
||||||
#include "libc/log/rop.h"
|
#include "libc/log/rop.internal.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "third_party/make/debug.h"
|
#include "third_party/make/debug.h"
|
||||||
|
|
||||||
|
|
8
third_party/make/job.c
vendored
8
third_party/make/job.c
vendored
|
@ -24,9 +24,9 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/pledge.h"
|
#include "libc/calls/pledge.h"
|
||||||
#include "libc/calls/pledge.internal.h"
|
#include "libc/calls/pledge.internal.h"
|
||||||
#include "libc/calls/struct/bpf.h"
|
#include "libc/calls/struct/bpf.internal.h"
|
||||||
#include "libc/calls/struct/filter.h"
|
#include "libc/calls/struct/filter.internal.h"
|
||||||
#include "libc/calls/struct/seccomp.h"
|
#include "libc/calls/struct/seccomp.internal.h"
|
||||||
#include "libc/calls/struct/sysinfo.h"
|
#include "libc/calls/struct/sysinfo.h"
|
||||||
#include "libc/calls/struct/timeval.h"
|
#include "libc/calls/struct/timeval.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
|
@ -42,7 +42,7 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
#include "libc/intrin/safemacros.internal.h"
|
#include "libc/intrin/safemacros.internal.h"
|
||||||
#include "libc/log/backtrace.internal.h"
|
#include "libc/log/backtrace.internal.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/log/rop.h"
|
#include "libc/log/rop.internal.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
#include "libc/nexgen32e/kcpuids.h"
|
#include "libc/nexgen32e/kcpuids.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
6
third_party/make/main.c
vendored
6
third_party/make/main.c
vendored
|
@ -28,9 +28,9 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
#include "third_party/make/rule.h"
|
#include "third_party/make/rule.h"
|
||||||
/**/
|
/**/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/struct/bpf.h"
|
#include "libc/calls/struct/bpf.internal.h"
|
||||||
#include "libc/calls/struct/filter.h"
|
#include "libc/calls/struct/filter.internal.h"
|
||||||
#include "libc/calls/struct/seccomp.h"
|
#include "libc/calls/struct/seccomp.internal.h"
|
||||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
|
|
1
third_party/python/Modules/mmapmodule.c
vendored
1
third_party/python/Modules/mmapmodule.c
vendored
|
@ -8,6 +8,7 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/weirdtypes.h"
|
#include "libc/calls/weirdtypes.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/runtime/sysconf.h"
|
#include "libc/runtime/sysconf.h"
|
||||||
#include "libc/sysv/consts/map.h"
|
#include "libc/sysv/consts/map.h"
|
||||||
#include "libc/sysv/consts/msync.h"
|
#include "libc/sysv/consts/msync.h"
|
||||||
|
|
2
third_party/python/pyobj.c
vendored
2
third_party/python/pyobj.c
vendored
|
@ -35,7 +35,7 @@
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
#include "libc/time/time.h"
|
#include "libc/time/time.h"
|
||||||
#include "libc/x/x.h"
|
#include "libc/x/x.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "third_party/getopt/getopt.h"
|
#include "third_party/getopt/getopt.h"
|
||||||
#include "third_party/python/Include/abstract.h"
|
#include "third_party/python/Include/abstract.h"
|
||||||
#include "third_party/python/Include/bytesobject.h"
|
#include "third_party/python/Include/bytesobject.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/dos.h"
|
#include "libc/dos.internal.h"
|
||||||
#include "libc/fmt/conv.h"
|
#include "libc/fmt/conv.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/log/check.h"
|
#include "libc/log/check.h"
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
#include "libc/time/struct/tm.h"
|
#include "libc/time/struct/tm.h"
|
||||||
#include "libc/x/x.h"
|
#include "libc/x/x.h"
|
||||||
#include "libc/x/xasprintf.h"
|
#include "libc/x/xasprintf.h"
|
||||||
#include "libc/zip.h"
|
#include "libc/zip.internal.h"
|
||||||
#include "net/http/http.h"
|
#include "net/http/http.h"
|
||||||
#include "third_party/zlib/zlib.h"
|
#include "third_party/zlib/zlib.h"
|
||||||
#include "tool/build/lib/elfwriter.h"
|
#include "tool/build/lib/elfwriter.h"
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "tool/build/lib/loader.h"
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/struct/stat.h"
|
#include "libc/calls/struct/stat.h"
|
||||||
#include "libc/elf/elf.h"
|
#include "libc/elf/elf.h"
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include "third_party/xed/x86.h"
|
#include "third_party/xed/x86.h"
|
||||||
#include "tool/build/lib/argv.h"
|
#include "tool/build/lib/argv.h"
|
||||||
#include "tool/build/lib/endian.h"
|
#include "tool/build/lib/endian.h"
|
||||||
#include "tool/build/lib/loader.h"
|
|
||||||
#include "tool/build/lib/machine.h"
|
#include "tool/build/lib/machine.h"
|
||||||
#include "tool/build/lib/memory.h"
|
#include "tool/build/lib/memory.h"
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ static void LoadBin(struct Machine *m, intptr_t base, const char *prog,
|
||||||
.p_vaddr = base,
|
.p_vaddr = base,
|
||||||
.p_paddr = base,
|
.p_paddr = base,
|
||||||
.p_filesz = codesize,
|
.p_filesz = codesize,
|
||||||
.p_memsz = ROUNDUP(codesize + FRAMESIZE, BIGPAGESIZE),
|
.p_memsz = ROUNDUP(codesize + FRAMESIZE, 0x200000),
|
||||||
.p_align = PAGESIZE,
|
.p_align = PAGESIZE,
|
||||||
};
|
};
|
||||||
LoadElfLoadSegment(m, code, codesize, &phdr);
|
LoadElfLoadSegment(m, code, codesize, &phdr);
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue