Compare commits

..
37 Commits
Author SHA1 Message Date
Justine Tunney 7f2bf3895e Moar sorting 2023-05-11 09:09:46 -07:00
Justine Tunney dbb8d66f22 Use yield on aarch in spin locks 2023-05-11 02:55:41 -07:00
Justine Tunney cba15bc77a Fix regression in DNS client
Calling FreeResolvConf() would crash, due to a recent change from
yesterday where free_s() was removed.
2023-05-10 23:27:10 -07:00
Justine Tunney 8d24a18c62 Tune magic division for size
This helps it avoid generating a branch instruction.
2023-05-10 21:32:04 -07:00
Justine Tunney 1f6f9e6701 Remove division from matrix multiplication
This change reduces llama.com CPU cycles systemically by 2.5% according
to the Linux Kernel `perf stat -Bddd` utility.
2023-05-10 21:19:54 -07:00
Justine Tunney a88290e595 Make sure llama.com terminal cleanup happens 2023-05-10 15:56:01 -07:00
Justine Tunney 5250feb7ad There must only be one strerror() 2023-05-10 15:34:13 -07:00
Justine Tunney c91de6a356 Avoid running clang-format on ggml.c 2023-05-10 14:59:33 -07:00
Justine Tunney ea607781f8 Fix the build 2023-05-10 10:14:15 -07:00
Justine Tunney bb3ebedfce Fix load time measurement 2023-05-10 07:54:21 -07:00
Justine Tunney 290a49952e Fix some more issues with aarch64 and llama.cpp 2023-05-10 07:34:26 -07:00
Justine Tunney 64aca4dc4f Fix weird behavior issue w/ kprintf() on aarch64 2023-05-10 06:17:33 -07:00
Justine Tunney 4e81d3277c Do some basic housekeeping in LIBC_STR 2023-05-10 06:17:20 -07:00
Justine Tunney 12a33858c9 There must be only one clock() 2023-05-10 06:16:01 -07:00
Justine Tunney 6cb9553706 Fix alignment bug in llama.com 2023-05-10 06:15:32 -07:00
Justine Tunney ca990ef091 Make llama.com -h print to stdout 2023-05-10 04:55:59 -07:00
Justine Tunney f312f706f4 Bring MODE=tiny binary sizes down to 20kb minimum
aarch64 binaries start at 4kb.
2023-05-10 04:20:48 -07:00
Justine Tunney 5f57fc1f59 Upgrade llama.cpp to e6a46b0ed1884c77267dc70693183e3b7164e0e0 2023-05-10 04:20:48 -07:00
Justine Tunney 5a455eaa0b Work on magic numbers for aarch64 2023-05-10 04:20:48 -07:00
Justine Tunney 59766efd3e Do some more aarch64 fixups 2023-05-10 04:20:47 -07:00
Justine Tunney 86d9323a43 Remove sys_getrandom() on NetBSD
This fixes an apparent regression caused by
3f0bcdc3ef where getrandom() on NetBSD 9.2
doesn't appear to work; ktrace oddly reports:

    1446      1 .ape     CALL  #91 (unimplemented getdopt)
    1446      1 .ape     RET   #91 (unimplemented getdopt) -1 errno 78
    Function not implemented
    1446      1 .ape     PSIG  SIGSYS SIG_DFL: code=SI_NOINFO
2023-05-10 04:20:47 -07:00
Justine Tunney a0237a017c Get llama.com working on aarch64 2023-05-10 04:20:47 -07:00
Justine Tunney 4c093155a3 Get llama.com building as an aarch64 native binary 2023-05-10 04:20:47 -07:00
Justine Tunney d04430f4ef Get LIBC_MEM and LIBC_STDIO building with aarch64 2023-05-10 04:20:47 -07:00
Justine Tunney ae0ee59614 Get aarch64 hello world working
$ m=aarch64-tiny
    $ make -j8 m=$m o/$m/tool/hello/hello.com o/third_party/qemu/qemu-aarch64
    $ o/third_party/qemu/qemu-aarch64 o/$m/tool/hello/hello.com
    hello world
    $ ls -hal o/$m/tool/hello/hello.com
    -rwxr-xr-x 1 jart jart 4.0K May  9 05:04 o/aarch64-tiny/tool/hello/hello.com
2023-05-10 04:20:47 -07:00
Justine Tunney e5e3cdf447 Get LIBC_RUNTIME and LIBC_CALLS building on aarch64 2023-05-10 04:20:47 -07:00
Justine Tunney 7e46645193 Get LIBC_FMT to build for aarch64 2023-05-10 04:20:47 -07:00
Justine Tunney 036b9a0002 Make further progress on non-x86 support 2023-05-10 04:20:47 -07:00
Justine Tunney aef9a69a60 Make more progress on aarch64 2023-05-10 04:20:47 -07:00
Justine Tunney 135080fd3e Get libc/tinymath/ compiling on aarch64 2023-05-10 04:20:46 -07:00
Justine Tunney 2b73e72d59 Make more code aarch64 friendly 2023-05-10 04:20:46 -07:00
Justine Tunney ca2860947f Make progress towards aarch64 build 2023-05-10 04:20:46 -07:00
Justine Tunney 08ff26c817 Add qemu-aarch64 2023-05-10 04:20:46 -07:00
Justine Tunney 8303e23b3a Do some basic build tuning 2023-05-10 04:20:46 -07:00
Justine Tunney 57cc257f58 Vendor musl-cross-make gcc 9.2.0 aarch64 2023-05-10 04:20:46 -07:00
Paul Kulchenko a493b64233 Merge pull request #807 from jart/evalarg
Fix the behavior of `redbean -i -e CODE`
2023-05-02 07:48:43 -07:00
Justine Tunney 497d4fa6d1 Fix the behavior of redbean -i -e CODE
When redbean is functioning as a Lua interpreter, the `-e` flag should
behave the same way as other open source language interpreters. Namely
it should exit after evaluating the code rather than showing the REPL.
2023-04-25 01:52:13 -07:00
17207 changed files with 79494 additions and 36875 deletions

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
# -*- conf -*-
*.gz binary
/build/bootstrap/*.com binary
/build/bootstrap/*.com binary
/usr/share/zoneinfo/* binary
+7 -4
View File
@@ -117,8 +117,8 @@ include libc/sysv/sysv.mk # ├──SYSTEM SUPPORT
include libc/nt/nt.mk # │ You can do math
include libc/intrin/intrin.mk # │ You can use the stack
include libc/linux/linux.mk # │ You can manipulate arrays
include libc/tinymath/tinymath.mk # │ You can issue raw system calls
include third_party/compiler_rt/compiler_rt.mk # │
include third_party/compiler_rt/compiler_rt.mk # │ You can issue raw system calls
include libc/tinymath/tinymath.mk # │
include libc/str/str.mk # │
include third_party/xed/xed.mk # │
include third_party/puff/puff.mk # │
@@ -132,6 +132,7 @@ include libc/calls/calls.mk #─┐
include third_party/getopt/getopt.mk # │
include libc/runtime/runtime.mk # ├──SYSTEMS RUNTIME
include libc/crt/crt.mk # │ You can issue system calls
include tool/hello/hello.mk # │
include third_party/nsync/nsync.mk # │
include third_party/dlmalloc/dlmalloc.mk #─┘
include libc/mem/mem.mk #─┐
@@ -156,6 +157,7 @@ include dsp/dsp.mk # │
include third_party/zlib/gz/gz.mk # │
include third_party/musl/musl.mk # │
include third_party/intel/intel.mk # │
include third_party/aarch64/aarch64.mk # │
include libc/libc.mk #─┘
include libc/sock/sock.mk #─┐
include dsp/tty/tty.mk # ├──ONLINE RUNTIME
@@ -199,6 +201,7 @@ include tool/build/emucrt/emucrt.mk
include tool/build/emubin/emubin.mk
include tool/build/build.mk
include tool/curl/curl.mk
include third_party/qemu/qemu.mk
include examples/examples.mk
include examples/pyapp/pyapp.mk
include examples/pylife/pylife.mk
@@ -285,12 +288,12 @@ o/$(MODE)/hdrs-old.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(HDRS
$(file >$@) $(foreach x,$(HDRS) $(INCS),$(file >>$@,$(x)))
TAGS: private .UNSANDBOXED = 1
TAGS: o/$(MODE)/srcs-old.txt $(SRCS) o/$(MODE)/third_party/ctags/ctags.com
TAGS: o/$(MODE)/srcs-old.txt $(SRCS) #o/$(MODE)/third_party/ctags/ctags.com
@$(RM) $@
@o/$(MODE)/third_party/ctags/ctags.com $(TAGSFLAGS) -L $< -o $@
HTAGS: private .UNSANDBOXED = 1
HTAGS: o/$(MODE)/hdrs-old.txt $(HDRS) o/$(MODE)/third_party/ctags/ctags.com
HTAGS: o/$(MODE)/hdrs-old.txt $(HDRS) #o/$(MODE)/third_party/ctags/ctags.com
@$(RM) $@
@build/htags o/$(MODE)/third_party/ctags/ctags.com -L $< -o $@
+404 -380
View File
File diff suppressed because it is too large. Load diff
+9
View File
@@ -0,0 +1,9 @@
#ifndef COSMOPOLITAN_APE_APE_INTERNAL_H_
#define COSMOPOLITAN_APE_APE_INTERNAL_H_
#include "libc/dce.h"
#if SupportsWindows() || SupportsMetal() || SupportsXnu()
#define APE_IS_SHELL_SCRIPT
#endif
#endif /* COSMOPOLITAN_APE_APE_INTERNAL_H_ */
+17 -6
View File
@@ -181,8 +181,15 @@
#include "libc/elf/pf2prot.internal.h"
#include "libc/nt/pedef.internal.h"
#include "libc/thread/tls.h"
#include "ape/ape.internal.h"
#include "libc/zip.h"
#ifdef __x86__
#define CODE_GRANULE 1
#else
#define CODE_GRANULE 4
#endif
ENTRY(_start)
PHDRS {
@@ -250,10 +257,11 @@ SECTIONS {
KEEP(*(SORT_BY_NAME(.sort.text.real.*)))
/* Code we want earlier in the binary w/o modifications */
KEEP(*(.ape.loader))
. = ALIGN(CODE_GRANULE);
HIDDEN(_ereal = .);
/*END: realmode addressability guarantee */
/*BEGIN: morphable code */
. += 1;
. += CODE_GRANULE;
/* Normal Code */
*(.start)
@@ -291,13 +299,12 @@ SECTIONS {
/* Privileged code invulnerable to magic */
KEEP(*(.ape.pad.privileged));
. += . > 0 ? 1 : 0;
. = ALIGN(__privileged_end > __privileged_start ? PAGESIZE : 1);
/*END: morphable code */
HIDDEN(__privileged_start = .);
. += . > 0 ? 1 : 0;
*(.privileged)
HIDDEN(__privileged_end = .);
. += . > 0 ? 1 : 0;
. += . > 0 ? CODE_GRANULE : 0;
/*BEGIN: Read Only Data */
@@ -383,7 +390,7 @@ SECTIONS {
KEEP(*(.dataprologue))
*(.data .data.*)
KEEP(*(SORT_BY_NAME(.sort.data.*)))
. += . > 0 ? 1 : 0;
. += . > 0 ? CODE_GRANULE : 0;
KEEP(*(.gotprologue))
*(.got)
@@ -420,7 +427,7 @@ SECTIONS {
*(.piro.bss)
KEEP(*(SORT_BY_NAME(.piro.bss.sort.*)))
HIDDEN(__piro_end = .);
. += . > 0 ? 1 : 0;
. += . > 0 ? CODE_GRANULE : 0;
/*END: Post-Initialization Read-Only */
/* Statically Allocated Empty Space */
@@ -567,6 +574,8 @@ SHSTUB2(ape_loader_dd_count,
? ROUNDUP(ape_loader_end - ape_loader, PAGESIZE) / 64
: 0);
#if defined(APE_IS_SHELL_SCRIPT) && !IsTiny()
HIDDEN(blink_aarch64_b0 = RVA(blink_aarch64) % 10 + 48);
HIDDEN(blink_aarch64_b1 = RVA(blink_aarch64) < 10 ? 32 : RVA(blink_aarch64) / 10 % 10 + 48);
HIDDEN(blink_aarch64_b2 = RVA(blink_aarch64) < 100 ? 32 : RVA(blink_aarch64) / 100 % 10 + 48);
@@ -611,6 +620,8 @@ HIDDEN(blink_darwin_arm64_size_b7 = blink_darwin_arm64_size < 10000000 ? 32 : bl
HIDDEN(blink_darwin_arm64_size_b8 = blink_darwin_arm64_size < 100000000 ? 32 : blink_darwin_arm64_size / 100000000 % 10 + 48);
HIDDEN(blink_darwin_arm64_size_b9 = blink_darwin_arm64_size < 1000000000 ? 32 : blink_darwin_arm64_size / 1000000000 % 10 + 48);
#endif /* APE_IS_SHELL_SCRIPT */
#if SupportsMetal()
HIDDEN(v_ape_realsectors =
MIN(0x70000 - IMAGE_BASE_REAL, ROUNDUP(RVA(_ezip), 512)) / 512);
+53 -30
View File
@@ -15,9 +15,32 @@
PKGS += APE
APE_FILES := $(wildcard ape/*.*)
APE_HDRS = $(filter %.h,$(APE_FILES))
APE_INCS = $(filter %.inc,$(APE_FILES))
APE = o/$(MODE)/ape/ape.o \
o/$(MODE)/ape/ape.lds
APELINK = \
$(COMPILE) \
-ALINK.ape \
$(LINK) \
$(LINKARGS) \
$(OUTPUT_OPTION)
ifeq ($(ARCH), aarch64)
APE_SRCS = ape/ape.S
APE_OBJS = o/$(MODE)/ape/ape.o
APE_NO_MODIFY_SELF = $(APE)
APE_COPY_SELF = $(APE)
.PHONY: o/$(MODE)/ape
o/$(MODE)/ape: $(APE)
else
APE_NO_MODIFY_SELF = \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/ape/ape-no-modify-self.o
@@ -26,13 +49,6 @@ APE_COPY_SELF = \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/ape/ape-copy-self.o
APELINK = \
$(COMPILE) \
-ALINK.ape \
$(LINK) \
$(LINKARGS) \
$(OUTPUT_OPTION)
APE_LOADER_FLAGS = \
-DNDEBUG \
-iquote. \
@@ -49,35 +65,17 @@ APE_LOADER_FLAGS = \
$(OUTPUT_OPTION) \
$<
APE_FILES := $(wildcard ape/*.*)
APE_HDRS = $(filter %.h,$(APE_FILES))
APE_INCS = $(filter %.inc,$(APE_FILES))
APE_SRCS_C = ape/loader.c
APE_SRCS_S = $(filter %.S,$(APE_FILES))
APE_SRCS = $(APE_SRCS_C) $(APE_SRCS_S)
APE_OBJS = $(APE_SRCS_S:%.S=o/$(MODE)/%.o)
APE_CHECKS = $(APE_HDRS:%=o/%.ok)
o/$(MODE)/ape/ape.lds: \
ape/ape.lds \
ape/macros.internal.h \
ape/relocations.h \
libc/intrin/bits.h \
libc/thread/tls.h \
libc/calls/struct/timespec.h \
libc/thread/thread.h \
libc/dce.h \
libc/elf/def.h \
libc/elf/pf2prot.internal.h \
libc/macros.internal.h \
libc/nt/pedef.internal.h \
libc/str/str.h \
libc/zip.h
o/$(MODE)/ape/public/ape.lds: OVERRIDE_CPPFLAGS += -UCOSMO
o/$(MODE)/ape/public/ape.lds: \
ape/public/ape.lds \
ape/ape.lds \
ape/ape.internal.h \
ape/macros.internal.h \
ape/relocations.h \
libc/intrin/bits.h \
@@ -96,15 +94,12 @@ o/ape/idata.inc: \
ape/idata.internal.h \
ape/relocations.h
o/$(MODE)/ape/ape.o: \
ape/blink-aarch64.gz \
ape/blink-darwin-arm64.gz
o/$(MODE)/ape/ape-no-modify-self.o: \
ape/ape.S \
ape/macros.internal.h \
ape/notice.inc \
ape/relocations.h \
ape/ape.internal.h \
libc/dce.h \
libc/elf/def.h \
libc/intrin/asancodes.h \
@@ -134,6 +129,7 @@ o/$(MODE)/ape/ape-copy-self.o: \
ape/macros.internal.h \
ape/notice.inc \
ape/relocations.h \
ape/ape.internal.h \
libc/dce.h \
libc/elf/def.h \
libc/intrin/asancodes.h \
@@ -194,3 +190,30 @@ o/$(MODE)/ape: $(APE_CHECKS) \
o/$(MODE)/ape/ape.macho \
o/$(MODE)/ape/ape-copy-self.o \
o/$(MODE)/ape/ape-no-modify-self.o
endif
# these assembly files are safe to build on aarch64
o/$(MODE)/ape/ape.o: ape/ape.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/ape/ape.o: \
ape/blink-aarch64.gz \
ape/blink-darwin-arm64.gz
o/$(MODE)/ape/ape.lds: \
ape/ape.lds \
ape/macros.internal.h \
ape/relocations.h \
ape/ape.internal.h \
libc/intrin/bits.h \
libc/thread/tls.h \
libc/calls/struct/timespec.h \
libc/thread/thread.h \
libc/dce.h \
libc/elf/def.h \
libc/elf/pf2prot.internal.h \
libc/macros.internal.h \
libc/nt/pedef.internal.h \
libc/str/str.h \
libc/zip.h
+15 -7
View File
@@ -32,6 +32,7 @@
// @see ape/ape.lds
// @see winimp
.macro .imp dll:req fn:req actual:req hint
#ifdef __x86_64__
.dll "\dll"
.section ".piro.data.sort.iat.2.\dll\().2.\actual","aw",@progbits
.type \fn,@object
@@ -49,18 +50,25 @@
.previous
.section ".idata.ro.hnt.\dll\().2.\actual","a",@progbits
"\dll\().\actual":
.ifnb \hint # hint i.e. guess function ordinal
.ifnb \hint // hint i.e. guess function ordinal
.short \hint
.else
.short 0
.endif
.asciz "\actual"
.align 2 # documented requirement
.align 2 // documented requirement
.globl "\dll\().\actual"
.hidden "\dll\().\actual"
.type "\dll\().\actual",@object
.size "\dll\().\actual",.-"\dll\().\actual"
.previous
#else
.section ".data.nt.\actual","aw",@progbits
.globl "\fn"
.balign 8
.weak "\actual"
"\fn": .quad "\actual"
#endif
.endm
// Defines DLL import.
@@ -68,11 +76,11 @@
.macro .dll name:req
.section ".idata.ro.idt.2.\name","aG",@progbits,"\name",comdat
.equ ".Lidata.idt.\name",.
.long RVA("idata.ilt.\name") # ImportLookupTable
.long 0 # TimeDateStamp
.long 0 # ForwarderChain
.long RVA(".Lidata.str.\name") # DllNameRva
.long RVA("idata.iat.\name") # ImportAddressTable
.long RVA("idata.ilt.\name") // ImportLookupTable
.long 0 // TimeDateStamp
.long 0 // ForwarderChain
.long RVA(".Lidata.str.\name") // DllNameRva
.long RVA("idata.iat.\name") // ImportAddressTable
.type ".Lidata.idt.\name",@object
.size ".Lidata.idt.\name",.-".Lidata.idt.\name"
.previous
+6 -6
View File
@@ -25,7 +25,7 @@
// APE Loader Executable Structure
// Linux, FreeBSD, NetBSD, OpenBSD
.align 8
.balign 8
ehdr: .ascii "\177ELF"
.byte ELFCLASS64
.byte ELFDATA2LSB
@@ -47,7 +47,7 @@ ehdr: .ascii "\177ELF"
.word 0 # e_shstrndx
.endobj ehdr,globl
.align 8
.balign 8
phdrs: .long PT_LOAD # p_type
.long PF_R|PF_X # p_flags
.quad 0 # p_offset
@@ -89,18 +89,18 @@ note: .long 2f-1f
.long 4f-3f
.long 1
1: .asciz "OpenBSD"
2: .align 4
2: .balign 4
3: .long 0
4: .long 2f-1f
.long 4f-3f
.long 1
1: .asciz "NetBSD"
2: .align 4
2: .balign 4
3: .long 901000000
4: .endobj note
notesize = . - note
.align 64,0 # for ape.S dd
.balign 64,0 # for ape.S dd
.org 0x180 # for ape.S dd
// APE Loader XNU Header
@@ -197,7 +197,7 @@ macho: .long 0xFEEDFACE+1
60:
.endobj macho
.align 64,0 # for ape.S dd
.balign 64,0 # for ape.S dd
.org 0x400 # for ape.S dd
// Ape Loader Entrpoint
+2 -2
View File
@@ -23,7 +23,7 @@
// APE Loader Executable Structure for XNU
.align 4096
.balign 4096
macho: .long 0xFEEDFACE+1
.long MAC_CPU_NEXGEN32E
.long MAC_CPU_NEXGEN32E_ALL
@@ -112,7 +112,7 @@ macho: .long 0xFEEDFACE+1
60:
.endobj macho,globl
.align 64
.balign 64
_start:
// Hack for detecting M1 Rosetta environment.
Binary file not shown.
Binary file not shown.
+31 -1
View File
@@ -17,6 +17,11 @@ CONFIG_CPPFLAGS += -DSYSDEBUG
TARGET_ARCH ?= -msse3
endif
ifeq ($(MODE), aarch64)
CONFIG_CCFLAGS += -O2 $(BACKTRACES) #$(FTRACE)
CONFIG_CPPFLAGS += -DSYSDEBUG
endif
# Fast Build Mode
#
# - `make MODE=fastbuild`
@@ -27,7 +32,7 @@ endif
# - Limited Backtraces
# - Compiles 28% faster
#
ifeq ($(MODE),fastbuild)
ifeq ($(MODE), fastbuild)
CONFIG_CCFLAGS += $(BACKTRACES) $(FTRACE) -O
CONFIG_CPPFLAGS += -DSYSDEBUG -DDWARFLESS
CONFIG_OFLAGS += -g0
@@ -180,6 +185,31 @@ PYFLAGS += \
-B
endif
ifeq ($(MODE), aarch64-tiny)
CONFIG_CPPFLAGS += \
-DTINY \
-DNDEBUG \
-DTRUSTWORTHY
CONFIG_CCFLAGS += \
-Os \
-fno-align-functions \
-fno-align-jumps \
-fno-align-labels \
-fno-align-loops \
-fschedule-insns2 \
-fomit-frame-pointer \
-momit-leaf-frame-pointer \
-foptimize-sibling-calls \
-DDWARFLESS
CONFIG_OFLAGS += \
-g0
CONFIG_LDFLAGS += \
-S
PYFLAGS += \
-O2 \
-B
endif
# Linux-Only Tiny Mode
#
# - `make MODE=tinylinux`
+29 -9
View File
@@ -56,6 +56,7 @@ TMPDIR = o/tmp
AR = build/bootstrap/ar.com
CP = build/bootstrap/cp.com
RM = build/bootstrap/rm.com -f
GZIP = build/bootstrap/gzip.com
ECHO = build/bootstrap/echo.com
TOUCH = build/bootstrap/touch.com
PKG = build/bootstrap/package.com
@@ -72,12 +73,22 @@ IMAGE_BASE_VIRTUAL ?= 0x400000
IGNORE := $(shell $(ECHO) -2 ♥cosmo)
IGNORE := $(shell $(MKDIR) o/tmp)
ifneq ($(findstring aarch64,$(MODE)),)
ARCH = aarch64
VM = o/third_party/qemu/qemu-aarch64
else
ARCH = x86_64
endif
ifneq ("$(wildcard o/third_party/gcc/bin/x86_64-pc-linux-gnu-*)","")
PREFIX = o/third_party/gcc/bin/x86_64-pc-linux-gnu-
else
IGNORE := $(shell build/bootstrap/unbundle.com)
PREFIX = o/third_party/gcc/bin/x86_64-linux-musl-
endif
ifeq ($(ARCH), aarch64)
PREFIX = o/third_party/gcc/bin/aarch64-linux-musl-
endif
AS = $(PREFIX)as
CC = $(PREFIX)gcc
@@ -104,20 +115,27 @@ else
TMPSAFE = $(TMPDIR)/
endif
ifneq ($(ARCH), aarch64)
MNO_FENTRY = -mno-fentry
endif
FTRACE = \
-pg
BACKTRACES = \
-fno-schedule-insns2 \
-fno-omit-frame-pointer \
-fno-optimize-sibling-calls \
-mno-omit-leaf-frame-pointer
ifneq ($(ARCH), aarch64)
BACKTRACES += -fno-schedule-insns2
endif
SANITIZER = \
-fsanitize=address
NO_MAGIC = \
-mno-fentry \
$(MNO_FENTRY) \
-fno-stack-protector \
-fwrapv \
-fno-sanitize=all
@@ -143,17 +161,20 @@ DEFAULT_OFLAGS = \
-gdescribe-dies
DEFAULT_COPTS = \
-mno-red-zone \
-fno-math-errno \
-fno-trapping-math \
-fno-fp-int-builtin-inexact \
-fno-ident \
-fno-common \
-fno-gnu-unique \
-fstrict-aliasing \
-fstrict-overflow \
-fno-semantic-interposition \
-fno-semantic-interposition
ifneq ($(ARCH), aarch64)
DEFAULT_COPTS += \
-mno-red-zone \
-mno-tls-direct-seg-refs
endif
MATHEMATICAL = \
-O3 \
@@ -187,7 +208,6 @@ DEFAULT_ASFLAGS = \
DEFAULT_LDFLAGS = \
-static \
-nostdlib \
-melf_x86_64 \
--gc-sections \
--build-id=none \
--no-dynamic-linker \
@@ -324,7 +344,7 @@ OBJECTIFY.greg.c = \
-fno-optimize-sibling-calls \
-fno-sanitize=all \
-ffreestanding \
-mno-fentry \
$(MNO_FENTRY) \
-fwrapv \
-c
@@ -364,7 +384,7 @@ OBJECTIFY.ncabi.c = \
$(OBJECTIFY.c.flags) \
-mno-sse \
-mfpmath=387 \
-mno-fentry \
$(MNO_FENTRY) \
-fno-stack-protector \
-fno-instrument-functions \
-fno-optimize-sibling-calls \
@@ -383,7 +403,7 @@ OBJECTIFY.ncabi.c = \
OBJECTIFY.initabi.c = \
$(GCC) \
$(OBJECTIFY.c.flags) \
-mno-fentry \
$(MNO_FENTRY) \
-fno-stack-protector \
-fno-instrument-functions \
-fno-optimize-sibling-calls \
Executable
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
for last; do true; done
if printf '%s\n' "$last" | grep aarch64 >/dev/null 2>&1; then
exec o/third_party/gcc/bin/aarch64-linux-musl-objdump "$@"
else
exec o/third_party/gcc/bin/x86_64-linux-musl-objdump "$@"
fi
+26 -13
View File
@@ -16,25 +16,14 @@
MAKEFLAGS += --no-builtin-rules
o/%.o: %.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/%.o: o/%.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/%.s: %.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
o/%.s: o/%.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
o/%.o: %.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
o/%.o: o/%.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
o/%.lds: %.lds ; @$(COMPILE) -APREPROCESS $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
o/%.inc: %.h ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) -D__ASSEMBLER__ -P $<
o/%.greg.o: %.greg.c ; @$(COMPILE) -AOBJECTIFY.greg $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%: o/$(MODE)/%.dbg ; @$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@
o/$(MODE)/%.o: %.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: o/$(MODE)/%.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: %.f ; @$(COMPILE) -AOBJECTIFY.f $(OBJECTIFY.f) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: %.F ; @$(COMPILE) -AOBJECTIFY.F $(OBJECTIFY.F) $(OUTPUT_OPTION) $<
o/$(MODE)/%.h: %.c ; @$(COMPILE) -AAMALGAMATE $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
o/$(MODE)/%.h: o/$(MODE)/%.c ; @$(COMPILE) -AAMALGAMATE $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
o/$(MODE)/%.o: %.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: o/$(MODE)/%.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: %.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
o/$(MODE)/%.lds: %.lds ; @$(COMPILE) -APREPROCESS $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: %.greg.c ; @$(COMPILE) -AOBJECTIFY.greg $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
@@ -43,6 +32,30 @@ o/$(MODE)/%.initabi.o: %.initabi.c ; @$(COMPILE) -AOBJECTIFY.init $(OBJECTIFY.in
o/$(MODE)/%.ncabi.o: %.ncabi.c ; @$(COMPILE) -AOBJECTIFY.nc $(OBJECTIFY.ncabi.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.real.o: %.c ; @$(COMPILE) -AOBJECTIFY.real $(OBJECTIFY.real.c) $(OUTPUT_OPTION) $<
ifneq ($(ARCH), aarch64)
o/%.o: %.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/%.o: o/%.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/%.s: %.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
o/%.s: o/%.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
o/%.o: %.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
o/%.o: o/%.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: %.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: o/$(MODE)/%.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: %.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: o/$(MODE)/%.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
else
o/%.o: %.s libc/empty.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) libc/empty.s
o/%.o: o/%.s libc/empty.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) libc/empty.s
o/%.s: %.S libc/empty.s ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) libc/empty.s
o/%.s: o/%.S libc/empty.s ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) libc/empty.s
o/%.o: %.S libc/empty.s ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.s) $(OUTPUT_OPTION) libc/empty.s
o/%.o: o/%.S libc/empty.s ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.s) $(OUTPUT_OPTION) libc/empty.s
o/$(MODE)/%.o: %.s libc/empty.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) libc/empty.s
o/$(MODE)/%.o: o/$(MODE)/%.s libc/empty.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) libc/empty.s
o/$(MODE)/%.o: %.S libc/empty.s ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.s) $(OUTPUT_OPTION) libc/empty.s
o/$(MODE)/%.o: o/$(MODE)/%.S libc/empty.s ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.s) $(OUTPUT_OPTION) libc/empty.s
endif
o/%.o: %.cc
@$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
@$(COMPILE) -AFIXUPOBJ -wT$@ $(FIXUPOBJ) $@
@@ -129,8 +142,8 @@ o/$(MODE)/%: o/$(MODE)/%.com o/$(MODE)/tool/build/cp.com o/$(MODE)/tool/build/as
# then the stdout/stderr output, which would normally be suppressed,
# will actually be displayed.
o/$(MODE)/%.runs: o/$(MODE)/%
@$(COMPILE) -ACHECK -wtT$@ $< $(TESTARGS)
o/$(MODE)/%.runs: o/$(MODE)/% $(VM)
@$(COMPILE) -ACHECK -wtT$@ $(VM) $< $(TESTARGS)
################################################################################
# ELF ZIP FILES
Executable
+10
View File
@@ -0,0 +1,10 @@
#!/bin/sh
for last; do true; done
if printf '%s\n' "$last" | grep aarch64 >/dev/null 2>&1; then
if [ ! -f o/third_party/qemu/qemu-aarch64 ]; then
make -j8 o/third_party/qemu/qemu-aarch64
fi
exec o/third_party/qemu/qemu-aarch64 "$@"
else
exec "$@"
fi
+1 -1
View File
@@ -17,7 +17,7 @@
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/macros.internal.h"
.align 16
.balign 16
// Mixes audio.
//
-1
View File
@@ -32,7 +32,6 @@
#include "dsp/mpeg/idct.h"
#include "dsp/mpeg/mpeg.h"
#include "dsp/mpeg/video.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/fmt/conv.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
+2 -1
View File
@@ -90,7 +90,8 @@ int ttyident(struct TtyIdent *ti, int ttyinfd, int ttyoutfd) {
: _weaken(malloc)(sizeof(struct TtyIdent))))) {
memcpy(ti->next, &outer, sizeof(outer));
} else {
free_s(&ti->next);
free(ti->next);
ti->next = 0;
}
}
ttyrestore(ttyinfd, &old);
+1 -1
View File
@@ -26,7 +26,7 @@ static void ttyidentfree(struct TtyIdent *ti) {
if (ti) {
assert(ti != ti->next);
ttyidentfree(ti->next);
free_s(&ti);
free(ti);
}
}
+6 -5
View File
@@ -1,21 +1,22 @@
#ifndef COSMOPOLITAN_DSP_TTY_INTERNAL_H_
#define COSMOPOLITAN_DSP_TTY_INTERNAL_H_
#include "dsp/tty/quant.h"
#include "dsp/tty/ttyrgb.h"
#include "third_party/intel/xmmintrin.internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct TtyRgb rgb2tty24f_(__m128);
struct TtyRgb rgb2ttyf2i_(__m128);
struct TtyRgb rgb2tty24f_(ttyrgb_m128);
struct TtyRgb rgb2ttyf2i_(ttyrgb_m128);
struct TtyRgb rgb2ttyi2f_(int, int, int);
struct TtyRgb rgb2ansi_(int, int, int);
struct TtyRgb rgb2ansihash_(int, int, int);
struct TtyRgb rgb2xterm24_(int, int, int);
struct TtyRgb rgb2xterm256gray_(__m128);
struct TtyRgb rgb2xterm256gray_(ttyrgb_m128);
struct TtyRgb tty2rgb_(struct TtyRgb);
struct TtyRgb tty2rgb24_(struct TtyRgb);
__m128 tty2rgbf_(struct TtyRgb);
__m128 tty2rgbf24_(struct TtyRgb);
ttyrgb_m128 tty2rgbf_(struct TtyRgb);
ttyrgb_m128 tty2rgbf24_(struct TtyRgb);
char *setbg16_(char *, struct TtyRgb);
char *setfg16_(char *, struct TtyRgb);
-1
View File
@@ -18,7 +18,6 @@
╚─────────────────────────────────────────────────────────────────────────────*/
#include "dsp/tty/itoa8.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/str/str.h"
struct Itoa8 kItoa8;
+4 -3
View File
@@ -5,7 +5,6 @@
#include "libc/intrin/bits.h"
#include "libc/limits.h"
#include "libc/str/str.h"
#include "third_party/intel/xmmintrin.internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@@ -14,12 +13,14 @@ COSMOPOLITAN_C_START_
#define BL 2
#define BR 3
typedef __m128 (*tty2rgbf_f)(struct TtyRgb);
typedef float ttyrgb_m128 __attribute__((__vector_size__(16), __may_alias__));
typedef ttyrgb_m128 (*tty2rgbf_f)(struct TtyRgb);
typedef char *(*setbg_f)(char *, struct TtyRgb);
typedef char *(*setbgfg_f)(char *, struct TtyRgb, struct TtyRgb);
typedef char *(*setfg_f)(char *, struct TtyRgb);
typedef struct TtyRgb (*rgb2tty_f)(int, int, int);
typedef struct TtyRgb (*rgb2ttyf_f)(__m128);
typedef struct TtyRgb (*rgb2ttyf_f)(ttyrgb_m128);
typedef struct TtyRgb (*tty2rgb_f)(struct TtyRgb);
typedef struct TtyRgb ttypalette_t[2][8];
+2 -3
View File
@@ -19,7 +19,6 @@
#include "dsp/core/core.h"
#include "dsp/tty/quant.h"
#include "libc/assert.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/limits.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
@@ -40,9 +39,9 @@ struct TtyRgb tty2rgb_(struct TtyRgb rgbxt) {
return g_ansi2rgb_[rgbxt.xt];
}
__m128 tty2rgbf_(struct TtyRgb rgbxt) {
ttyrgb_m128 tty2rgbf_(struct TtyRgb rgbxt) {
rgbxt = g_ansi2rgb_[rgbxt.xt];
return (__m128){(int)rgbxt.r, (int)rgbxt.g, (int)rgbxt.b} / 255;
return (ttyrgb_m128){(int)rgbxt.r, (int)rgbxt.g, (int)rgbxt.b} / 255;
}
static int rgb2xterm256_(int r, int g, int b) {
+5 -6
View File
@@ -17,12 +17,11 @@
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "dsp/tty/quant.h"
#include "third_party/intel/xmmintrin.internal.h"
struct TtyRgb rgb2ttyf2i_(__m128 rgb) {
__v4si i4;
typedef int ttyrgb_i4 __attribute__((__vector_size__(16)));
struct TtyRgb rgb2ttyf2i_(ttyrgb_m128 rgb) {
rgb *= 255;
/* i4 = __builtin_ia32_cvtps2dq(rgb); */
asm("cvttps2dq\t%0,%1" : "+%x"(rgb), "=x"(i4));
return rgb2tty(i4[0], i4[1], i4[2]);
ttyrgb_i4 rgbi = {rgb[0], rgb[1], rgb[2], rgb[3]};
return rgb2tty(rgbi[0], rgbi[1], rgbi[2]);
}
+1 -1
View File
@@ -21,5 +21,5 @@
#include "libc/macros.internal.h"
struct TtyRgb rgb2ttyi2f_(int r, int g, int b) {
return rgb2ttyf((__m128){r, g, b} / 255);
return rgb2ttyf((ttyrgb_m128){r, g, b} / 255);
}
+14 -15
View File
@@ -17,25 +17,24 @@
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "dsp/tty/quant.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "third_party/intel/xmmintrin.internal.h"
/*
struct TtyRgb rgb2tty24f_(__m128 rgb) {
const __v4si kMax = {255, 255, 255, 255};
const __v4si kMin = {0, 0, 0, 0};
struct TtyRgb res;
__v4si rgb255;
rgb255 = _mm_min_ps(_mm_max_ps(_mm_cvtps_epi32(rgb * 255), kMin), kMax);
res = (struct TtyRgb){rgb255[0], rgb255[1], rgb255[2], rgb255[3]};
return res;
}
*/
struct TtyRgb rgb2tty24f_(__m128 rgb) {
const __m128 kMax = {1, 1, 1, 1};
const __m128 kMin = {0, 0, 0, 0};
struct TtyRgb rgb2tty24f_(ttyrgb_m128 rgb) {
#ifdef __x86_64__
const ttyrgb_m128 kMax = {1, 1, 1, 1};
const ttyrgb_m128 kMin = {0, 0, 0, 0};
struct TtyRgb res;
rgb = _mm_min_ps(_mm_max_ps(rgb, kMin), kMax) * 255;
res = (struct TtyRgb){rgb[0], rgb[1], rgb[2], rgb[3]};
return res;
#else
return (struct TtyRgb){
MAX(0, MIN(1, rgb[0])) * 255,
MAX(0, MIN(1, rgb[1])) * 255,
MAX(0, MIN(1, rgb[2])) * 255,
MAX(0, MIN(1, rgb[3])) * 255,
};
#endif
}
+7 -3
View File
@@ -30,13 +30,17 @@
* @param ti comes from ttyident() and null means no-op
*/
int ttysendtitle(int ttyfd, const char *title, const struct TtyIdent *ti) {
int res;
if (ti) {
char *p;
if (ti->id == kTtyIdScreen) {
return ttysend(ttyfd, gc(xstrcat("\eP\e]0;", title, "\a\e\\")));
res = ttysend(ttyfd, (p = xstrcat("\eP\e]0;", title, "\a\e\\")));
} else {
return ttysend(ttyfd, gc(xstrcat("\e]0;", title, "\a")));
res = ttysend(ttyfd, (p = xstrcat("\e]0;", title, "\a")));
}
free(p);
} else {
return 0;
res = 0;
}
return res;
}
+2 -2
View File
@@ -18,6 +18,6 @@
╚─────────────────────────────────────────────────────────────────────────────*/
#include "dsp/tty/quant.h"
__m128 tty2rgbf24_(struct TtyRgb rgbxt) {
return (__m128){(int)rgbxt.r, (int)rgbxt.g, (int)rgbxt.b} / 255;
ttyrgb_m128 tty2rgbf24_(struct TtyRgb rgbxt) {
return (ttyrgb_m128){(int)rgbxt.r, (int)rgbxt.g, (int)rgbxt.b} / 255;
}
+3 -1
View File
@@ -45,6 +45,8 @@ void ttyhisto(uint32_t histogram[hasatleast 256],
histogram[xtcolors[i * 8]]++;
}
}
imapxlatab(dominant);
for (i = 0; i < 256; ++i) {
dominant[i] = i;
}
qsort_r(dominant, 256, 1, (void *)histcmp, histogram);
}
-1
View File
@@ -18,7 +18,6 @@
╚─────────────────────────────────────────────────────────────────────────────*/
#include "dsp/tty/internal.h"
#include "dsp/tty/quant.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/dce.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
+3 -4
View File
@@ -184,11 +184,10 @@ o/$(MODE)/usr/share/dict/words.zip.o: private ZIPOBJ_FLAGS += -C2
$(EXAMPLES_OBJS): examples/examples.mk
o/$(MODE)/usr/share/dict/words: \
usr/share/dict/words.gz \
o/$(MODE)/tool/build/gzip.com
o/$(MODE)/usr/share/dict/words: \
usr/share/dict/words.gz
@$(MKDIR) $(@D)
@o/$(MODE)/tool/build/gzip.com $(ZFLAGS) -cd <$< >$@
@$(GZIP) $(ZFLAGS) -cd <$< >$@
################################################################################
-62
View File
@@ -1,62 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
│ To the extent possible under law, Justine Tunney has waived │
│ all copyright and related or neighboring rights to this file, │
│ as it is written in the following disclaimers: │
│ • http://unlicense.org/ │
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
╚─────────────────────────────────────────────────────────────────*/
#endif
#include "libc/calls/calls.h"
#include "libc/macros.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/sig.h"
#include "libc/testlib/ezbench.h"
/**
* @fileoverview Fast Division Using Multiplication Tutorial
*
* Expected program output:
*
* 23 / 3 = 7
* 0x5555555555555556 1 1
* division l: 16𝑐 5𝑛𝑠
* fast div l: 5𝑐 2𝑛𝑠
* precomps l: 70𝑐 23𝑛𝑠
*/
struct Divisor {
uint64_t m;
uint8_t s;
uint8_t t;
};
struct Divisor GetDivisor(uint64_t d) {
int b;
uint128_t x;
if (!d) raise(SIGFPE);
b = __builtin_clzll(d) ^ 63;
x = -d & (((1ull << b) - 1) | (1ull << b));
return (struct Divisor){(x << 64) / d + 1, MIN(1, b + 1), MAX(0, b)};
}
uint64_t Divide(uint64_t x, struct Divisor d) {
uint128_t t;
uint64_t l, h;
t = d.m;
t *= x;
l = t;
h = t >> 64;
l = (x - h) >> d.s;
return (h + l) >> d.t;
}
int main(int argc, char *argv[]) {
printf("23 / 3 = %ld\n", Divide(23, GetDivisor(3)));
volatile struct Divisor v = GetDivisor(3);
volatile uint64_t x = 23, y = 3, z;
EZBENCH2("division", donothing, z = x / y);
EZBENCH2("fast div", donothing, z = Divide(x, v));
EZBENCH2("precomp ", donothing, v = GetDivisor(y));
return 0;
}
-152
View File
@@ -1,152 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
│ To the extent possible under law, Justine Tunney has waived │
│ all copyright and related or neighboring rights to this file, │
│ as it is written in the following disclaimers: │
│ • http://unlicense.org/ │
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
╚─────────────────────────────────────────────────────────────────*/
#endif
#include "dsp/core/core.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/itimerval.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/fmt/nf32.h"
#include "libc/intrin/bits.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/append.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/itimer.h"
#include "libc/sysv/consts/sig.h"
#include "libc/time/time.h"
/**
* @fileoverview experimental way to play audio in terminals
*
* This is an stdio application that prints audio samples. The terminal
* on the other end, needs to be able to understand the Nf sequences we
* use here, which should be invisible to the terminal sort of like out
* of band signalling.
*
* To play audio with a supporting terminal:
*
* make -j8 o//examples/ttyaudio.com
* wget https://justine.lol/numbers.s16
* o//examples/ttyaudio.com numbers.s16
*
* To reveal the inband ansi audio transmission:
*
* o//examples/ttyaudio.com numbers.s16 2>/dev/null |
* o//tool/viz/bing.com |
* o//tool/viz/fold.com
*
*/
#define CSI "s"
#define SGR1 "?80"
#define SGR2 "?81"
struct Ring {
int i; // read index
int j; // write index
int n; // total samples
short* p; // samples
};
struct Speaker {
int rate; // in hertz, e.g. 8000
int codec; // 0 = s16, 2 = µ-Law
int channels; // 1 = mono, 2 = stereo
struct Ring buf; // audio playback buffer
};
const int maxar = 31;
const int ptime = 20;
struct Speaker s;
void OnAlrm(int sig) {
}
void LoadAudioFile(struct Speaker* s, const char* path) {
int rc;
FILE* f;
short buf[1024];
if (!(f = fopen(path, "rb"))) {
fprintf(stderr, "failed to open file\n");
exit(1);
}
for (;;) {
rc = fread(buf, sizeof(short), sizeof(buf) / sizeof(short), f);
if (rc) {
s->buf.p = (short*)realloc(s->buf.p, (s->buf.n + rc) * sizeof(short));
memcpy(s->buf.p + s->buf.n, buf, rc * sizeof(short));
s->buf.n += rc;
} else if (ferror(f)) {
fprintf(stderr, "read error: %s\n", strerror(ferror(f)));
exit(2);
} else {
break;
}
}
fclose(f);
}
int main(int argc, char* argv[]) {
if (argc < 2) return 1;
if (!isatty(0)) exit(1);
s.rate = 8000;
s.channels = 1;
s.codec = 0;
LoadAudioFile(&s, argv[1]);
char nf[21];
char* obuf = 0;
appendw(&obuf, READ16LE("\e%"));
appendd(&obuf, nf, EncodeNf32(nf, s.rate) - nf);
appendw(&obuf, '/');
appendd(&obuf, nf, EncodeNf32(nf, s.channels) - nf);
appendw(&obuf, '/');
appendd(&obuf, nf, EncodeNf32(nf, s.codec) - nf);
appendw(&obuf, '0');
write(1, obuf, appendz(obuf).i);
free(obuf);
struct sigaction sa = {.sa_handler = OnAlrm};
struct itimerval it = {{0, ptime * 1000}, {0, ptime * 1000}};
CHECK_NE(-1, sigaction(SIGALRM, &sa, 0));
CHECK_NE(-1, setitimer(ITIMER_REAL, &it, 0));
for (;;) {
char* p;
int count;
char nf[22];
int i, j, x;
char* obuf = 0;
int samps = s.rate / (1000 / ptime);
appendw(&obuf, READ16LE("\e "));
for (i = 0; i < samps; ++i) {
if (s.codec == 1) {
x = mulaw(s.buf.p[s.buf.i++]);
} else {
x = s.buf.p[s.buf.i++] & 0xffff;
}
*(p = EncodeNf32(nf, x)) = '/';
appendd(&obuf, nf, p + 1 - nf);
if (s.buf.i == s.buf.n) break;
}
appendw(&obuf, '0');
write(1, obuf, appendz(obuf).i);
free(obuf);
fprintf(stderr, "\r\e[K%d / %d", s.buf.i, s.buf.n);
fflush(stderr);
pause();
}
return 1;
}
-30
View File
@@ -1,30 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2022 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/macros.internal.h"
.initbss 301,_init___clock_gettime
__clock_gettime:
.quad 0
.endobj __clock_gettime,globl,hidden
.previous
.init.start 301,_init___clock_gettime
ezlea __clock_gettime_init,ax
stosq
.init.end 301,_init___clock_gettime
+21
View File
@@ -0,0 +1,21 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2023 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/clock_gettime.internal.h"
clock_gettime_f *__clock_gettime = __clock_gettime_init;
-30
View File
@@ -1,30 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2022 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/macros.internal.h"
.initbss 301,_init___gettimeofday
__gettimeofday:
.quad 0
.endobj __gettimeofday,globl,hidden
.previous
.init.start 301,_init___gettimeofday
ezlea __gettimeofday_init,ax
stosq
.init.end 301,_init___gettimeofday
+4
View File
@@ -34,6 +34,8 @@
#include "libc/sysv/errfuns.h"
#include "libc/thread/tls.h"
#ifdef __x86_64__
/**
* Allocates piece of memory for storing pending signal.
* @assume lock is held
@@ -304,3 +306,5 @@ textwindows void __sig_check_ignore(const int sig, const unsigned rva) {
__sig_unlock();
}
}
#endif /* __x86_64__ */
+4
View File
@@ -23,6 +23,8 @@
#include "libc/sysv/errfuns.h"
#include "libc/thread/tls.h"
#ifdef __x86_64__
#define GetSigBit(x) (1ull << (((x)-1) & 63))
textwindows int __sig_mask(int how, const sigset_t *neu, sigset_t *old) {
@@ -58,3 +60,5 @@ textwindows int __sig_mask(int how, const sigset_t *neu, sigset_t *old) {
return einval();
}
}
#endif /* __x86_64__ */
+4
View File
@@ -21,6 +21,8 @@
#include "libc/calls/state.internal.h"
#include "libc/calls/struct/sigset.h"
#ifdef __x86_64__
/**
* Determines the pending signals on New Technology.
*
@@ -41,3 +43,5 @@ textwindows void __sig_pending(sigset_t *pending) {
__sig_unlock();
}
}
#endif /* __x86_64__ */
+5
View File
@@ -2,17 +2,22 @@
#define COSMOPOLITAN_LIBC_CALLS_ASAN_INTERNAL_H_
#include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timeval.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/asmflag.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
forceinline bool __asan_is_valid_timespec(const struct timespec *ts) {
#ifdef __x86_64__
bool zf;
asm(ZFLAG_ASM("cmpw\t$0,0x7fff8000(%1)")
: ZFLAG_CONSTRAINT(zf)
: "r"((intptr_t)ts >> 3)
: "memory");
return zf;
#else
return __asan_is_valid(ts, sizeof(*ts));
#endif
}
forceinline bool __asan_is_valid_timeval(const struct timeval *tv) {
+2 -1
View File
@@ -51,7 +51,8 @@ LIBC_CALLS_A_DIRECTDEPS = \
LIBC_STR \
LIBC_STUBS \
LIBC_SYSV_CALLS \
LIBC_SYSV
LIBC_SYSV \
THIRD_PARTY_COMPILER_RT
LIBC_CALLS_A_DEPS := \
$(call uniq,$(foreach x,$(LIBC_CALLS_A_DIRECTDEPS),$($(x))))
+7 -1
View File
@@ -95,13 +95,19 @@ int clock_gettime(int clock, struct timespec *ts) {
return rc;
}
#ifdef __aarch64__
#define CGT_VDSO __vdsosym("LINUX_2.6.39", "__kernel_clock_gettime")
#else
#define CGT_VDSO __vdsosym("LINUX_2.6", "__vdso_clock_gettime")
#endif
/**
* Returns pointer to fastest clock_gettime().
*/
clock_gettime_f *__clock_gettime_get(bool *opt_out_isfast) {
bool isfast;
clock_gettime_f *res;
if (IsLinux() && (res = __vdsosym("LINUX_2.6", "__vdso_clock_gettime"))) {
if (IsLinux() && (res = CGT_VDSO)) {
isfast = true;
} else if (IsXnu()) {
isfast = false;
+1 -2
View File
@@ -17,7 +17,6 @@
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/calls.h"
#include "libc/intrin/lockxadd.h"
#include "libc/nt/process.h"
static textwindows char16_t *UintToChar16Array(char16_t p[21], uint64_t x) {
@@ -44,7 +43,7 @@ textwindows char16_t *CreatePipeName(char16_t *a) {
while (*q) *p++ = *q++;
p = UintToChar16Array(p, GetCurrentProcessId());
*p++ = '-';
p = UintToChar16Array(p, _lockxadd(&x, 1));
p = UintToChar16Array(p, (x += 1));
*p = 0;
return a;
}
+1 -5
View File
@@ -30,11 +30,7 @@
int32_t sys_fstat(int32_t fd, struct stat *st) {
void *p;
union metastat ms;
if (IsLinux()) {
_Static_assert(sizeof(*st) == sizeof(ms.linux), "assumption broken");
if (IsAsan() && !__asan_is_valid(st, sizeof(*st))) return efault();
p = st;
} else if (st) {
if (st) {
p = &ms;
} else {
p = 0;
+1 -5
View File
@@ -32,11 +32,7 @@ int32_t sys_fstatat(int32_t dirfd, const char *path, struct stat *st,
void *p;
union metastat ms;
if (IsAsan() && !__asan_is_valid_str(path)) return efault();
if (IsLinux()) {
_Static_assert(sizeof(*st) == sizeof(ms.linux), "assumption broken");
if (IsAsan() && (st && !__asan_is_valid(st, sizeof(*st)))) return efault();
p = st;
} else if (st) {
if (st) {
p = &ms;
} else {
p = 0;
+8
View File
@@ -18,6 +18,7 @@
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/calls.h"
#include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asmflag.h"
@@ -49,6 +50,7 @@
*/
privileged int getpriority(int which, unsigned who) {
int rc;
#ifdef __x86_64__
char cf;
if (IsLinux()) {
asm volatile("syscall"
@@ -73,6 +75,12 @@ privileged int getpriority(int which, unsigned who) {
} else {
rc = sys_getpriority_nt(which, who);
}
#else
rc = sys_getpriority(which, who);
if (rc != -1) {
rc = NZERO - rc;
}
#endif
STRACE("getpriority(%s, %u) → %d% m", DescribeWhichPrio(which), who, rc);
return rc;
}
+6 -4
View File
@@ -31,8 +31,8 @@
#include "libc/time/struct/timezone.h"
typedef axdx_t gettimeofday_f(struct timeval *, struct timezone *, void *);
extern gettimeofday_f *__gettimeofday;
static gettimeofday_f __gettimeofday_init;
static gettimeofday_f *__gettimeofday = __gettimeofday_init;
/**
* Returns system wall time in microseconds, e.g.
@@ -97,8 +97,10 @@ gettimeofday_f *__gettimeofday_get(bool *opt_out_isfast) {
return res;
}
_Hide int __gettimeofday_init(struct timeval *tv, struct timezone *tz) {
static axdx_t __gettimeofday_init(struct timeval *tv, //
struct timezone *tz, //
void *arg) {
gettimeofday_f *gettime;
__gettimeofday = gettime = __gettimeofday_get(0);
return gettime(tv, tz, 0).ax;
return gettime(tv, tz, 0);
}
-1
View File
@@ -26,7 +26,6 @@
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/lockcmpxchgp.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/sysv/errfuns.h"
+4
View File
@@ -22,6 +22,7 @@
#include "libc/sysv/consts/pr.h"
privileged bool __is_linux_2_6_23(void) {
#ifdef __x86_64__
int rc;
if (!IsLinux()) return false;
if (IsGenuineBlink()) return true;
@@ -30,4 +31,7 @@ privileged bool __is_linux_2_6_23(void) {
: "0"(157), "D"(PR_GET_SECCOMP)
: "rcx", "r11", "memory");
return rc != -EINVAL;
#else
return true;
#endif
}
+4
View File
@@ -41,6 +41,8 @@
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/errfuns.h"
#ifdef __x86_64__
#define MAP_ANONYMOUS_linux 0x00000020
#define MAP_FIXED_linux 0x00000010
#define MAP_SHARED_linux 0x00000001
@@ -73,3 +75,5 @@ textstartup noasan void InitializeMetalFile(void) {
__ape_com_size = size;
}
}
#endif /* __x86_64__ */
-1
View File
@@ -26,7 +26,6 @@
#include "libc/str/oldutf16.internal.h"
#include "libc/str/str.h"
#include "libc/str/thompike.h"
#include "libc/str/tpdecode.internal.h"
#include "libc/str/utf16.h"
#include "libc/sysv/errfuns.h"
+18 -10
View File
@@ -17,6 +17,7 @@
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asmflag.h"
@@ -34,34 +35,41 @@
* features like ASAN memory safety and kprintf() won't work as well.
*/
privileged void *sys_mremap(void *p, size_t n, size_t m, int f, void *q) {
#ifdef __x86_64__
bool cf;
uintptr_t rax, rdi, rsi, rdx;
uintptr_t res, rdi, rsi, rdx;
register uintptr_t r8 asm("r8");
register uintptr_t r10 asm("r10");
if (IsLinux()) {
r10 = f;
r8 = (uintptr_t)q;
asm("syscall"
: "=a"(rax)
: "=a"(res)
: "0"(0x019), "D"(p), "S"(n), "d"(m), "r"(r10), "r"(r8)
: "rcx", "r11", "memory", "cc");
if (rax > -4096ul) errno = -rax, rax = -1;
if (res > -4096ul) errno = -res, res = -1;
} else if (IsNetbsd()) {
if (f & MREMAP_MAYMOVE) {
rax = 0x19B;
res = 0x19B;
r10 = m;
r8 = (f & MREMAP_FIXED) ? MAP_FIXED : 0;
asm(CFLAG_ASM("syscall")
: CFLAG_CONSTRAINT(cf), "+a"(rax), "=d"(rdx)
: CFLAG_CONSTRAINT(cf), "+a"(res), "=d"(rdx)
: "D"(p), "S"(n), "2"(q), "r"(r10), "r"(r8)
: "rcx", "r9", "r11", "memory", "cc");
if (cf) errno = rax, rax = -1;
if (cf) errno = res, res = -1;
} else {
rax = einval();
res = einval();
}
} else {
rax = enosys();
res = enosys();
}
KERNTRACE("sys_mremap(%p, %'zu, %'zu, %#b, %p) → %p% m", p, n, m, f, q, rax);
return (void *)rax;
#elif defined(__aarch64__)
void *res;
res = __sys_mremap(p, n, m, f, q);
#else
#error "arch unsupported"
#endif
KERNTRACE("sys_mremap(%p, %'zu, %'zu, %#b, %p) → %p% m", p, n, m, f, q, res);
return (void *)res;
}
+3
View File
@@ -18,6 +18,7 @@
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/intrin/directmap.internal.h"
#include "libc/runtime/pc.internal.h"
#ifdef __x86_64__
noasan int sys_munmap_metal(void *addr, size_t size) {
size_t i;
@@ -36,3 +37,5 @@ noasan int sys_munmap_metal(void *addr, size_t size) {
}
return 0;
}
#endif
+2 -1
View File
@@ -23,7 +23,6 @@
#include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h"
@@ -113,3 +112,5 @@ long double nowl_setup(void) {
}
return nowl();
}
long double (*nowl)(void) = nowl_setup;
-29
View File
@@ -1,29 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2022 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/macros.internal.h"
.initbss 201,_init_nowl
nowl: .quad 0
.endobj nowl,globl
.previous
.init.start 201,_init_nowl
ezlea nowl_setup,ax
stosq
.init.end 201,_init_nowl
+4
View File
@@ -21,6 +21,8 @@
#include "libc/nt/struct/context.h"
#include "libc/str/str.h"
#ifdef __x86_64__
// TODO(jart): uc_sigmask support
privileged void _ntcontext2linux(ucontext_t *ctx, const struct NtContext *cr) {
@@ -75,3 +77,5 @@ privileged void _ntlinux2context(struct NtContext *cr, const ucontext_t *ctx) {
cr->SegFs = ctx->uc_mcontext.fs;
__repmovsb(&cr->FltSave, &ctx->__fpustate, sizeof(ctx->__fpustate));
}
#endif /* __x86_64__ */
-1
View File
@@ -21,7 +21,6 @@
#include "libc/calls/struct/timespec.h"
#include "libc/dce.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/initializer.internal.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h"
+4
View File
@@ -28,6 +28,8 @@
#include "libc/thread/tls.h"
#include "libc/thread/tls2.h"
#ifdef __x86_64__
textwindows bool32 __onntconsoleevent(uint32_t dwCtrlType) {
struct CosmoTib tib;
struct StackFrame *fr;
@@ -60,3 +62,5 @@ textwindows bool32 __onntconsoleevent(uint32_t dwCtrlType) {
return false;
}
}
#endif /* __x86_64__ */
+4
View File
@@ -35,6 +35,8 @@
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#ifdef __x86_64__
int sys_openat_metal(int dirfd, const char *file, int flags, unsigned mode) {
int fd;
struct MetalFile *state;
@@ -61,3 +63,5 @@ int sys_openat_metal(int dirfd, const char *file, int flags, unsigned mode) {
g_fds.p[fd].handle = (intptr_t)state;
return fd;
}
#endif /* __x86_64__ */
+4
View File
@@ -20,6 +20,8 @@
#include "libc/macros.internal.h"
#include "libc/str/str.h"
#ifdef __x86_64__
static int FindPromise(const char *name) {
int i;
for (i = 0; i < ARRAYLEN(kPledge); ++i) {
@@ -64,3 +66,5 @@ int ParsePromises(const char *promises, unsigned long *out) {
}
return rc;
}
#endif /* __x86_64__ */
+5 -3
View File
@@ -35,6 +35,7 @@
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/pr.h"
#include "libc/sysv/consts/prot.h"
#ifdef __x86_64__
/**
* @fileoverview OpenBSD pledge() Polyfill Payload for GNU/Systemd
@@ -239,7 +240,7 @@ static const struct thatispacked SyscallName {
{__NR_linux_capget, "capget"}, //
{__NR_linux_capset, "capset"}, //
{__NR_linux_sigtimedwait, "sigtimedwait"}, //
{__NR_linux_rt_sigqueueinfo, "rt_sigqueueinfo"}, //
{__NR_linux_sigqueueinfo, "sigqueueinfo"}, //
{__NR_linux_personality, "personality"}, //
{__NR_linux_ustat, "ustat"}, //
{__NR_linux_sysfs, "sysfs"}, //
@@ -358,7 +359,7 @@ static const struct thatispacked SyscallName {
{__NR_linux_epoll_create1, "epoll_create1"}, //
{__NR_linux_perf_event_open, "perf_event_open"}, //
{__NR_linux_inotify_init1, "inotify_init1"}, //
{__NR_linux_rt_tgsigqueueinfo, "rt_tgsigqueueinfo"}, //
{__NR_linux_tgsigqueueinfo, "tgsigqueueinfo"}, //
{__NR_linux_signalfd, "signalfd"}, //
{__NR_linux_signalfd4, "signalfd4"}, //
{__NR_linux_eventfd, "eventfd"}, //
@@ -1360,7 +1361,6 @@ static privileged void AllowMmapExec(struct Filter *f) {
// The flags parameter must not have:
//
// - MAP_LOCKED (0x02000)
// - MAP_POPULATE (0x08000)
// - MAP_NONBLOCK (0x10000)
// - MAP_HUGETLB (0x40000)
//
@@ -2060,3 +2060,5 @@ privileged int sys_pledge_linux(unsigned long ipromises, int mode) {
return rc;
}
#endif
+4
View File
@@ -28,6 +28,8 @@
#include "libc/runtime/runtime.h"
#include "libc/sysv/errfuns.h"
#ifdef __x86_64__
/**
* Permits system operations, e.g.
*
@@ -276,3 +278,5 @@ int pledge(const char *promises, const char *execpromises) {
STRACE("pledge(%#s, %#s) → %d% m", promises, execpromises, rc);
return rc;
}
#endif /* __x86_64__ */
+3
View File
@@ -24,6 +24,7 @@
#include "libc/sock/internal.h"
#include "libc/sock/struct/pollfd.h"
#include "libc/sysv/consts/poll.h"
#ifdef __x86_64__
int sys_poll_metal(struct pollfd *fds, size_t nfds, unsigned timeout_ms) {
int rc;
@@ -80,3 +81,5 @@ int sys_poll_metal(struct pollfd *fds, size_t nfds, unsigned timeout_ms) {
}
return rc;
}
#endif
+4
View File
@@ -41,6 +41,8 @@
#include "libc/sysv/consts/sig.h"
#include "libc/sysv/errfuns.h"
#ifdef __x86_64__
/*
* Polls on the New Technology.
*
@@ -218,3 +220,5 @@ ReturnPath:
}
return rc;
}
#endif /* __x86_64__ */
+18
View File
@@ -17,6 +17,7 @@
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/describeflags.internal.h"
@@ -41,6 +42,7 @@ privileged int prctl(int operation, ...) {
d = va_arg(va, intptr_t);
va_end(va);
#ifdef __x86_64__
if (IsLinux()) {
asm volatile("mov\t%5,%%r10\n\t"
"mov\t%6,%%r8\n\t"
@@ -52,6 +54,22 @@ privileged int prctl(int operation, ...) {
} else {
rc = enosys();
}
#elif defined(__aarch64__)
register long r0 asm("x0") = (long)operation;
register long r1 asm("x1") = (long)a;
register long r2 asm("x2") = (long)b;
register long r3 asm("x3") = (long)c;
register long r4 asm("x4") = (long)d;
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n\t"
"svc\t0"
: "=r"(res_x0)
: "i"(167), "r"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4)
: "x8", "memory");
rc = _sysret(res_x0);
#else
#error "arch unsupported"
#endif
#ifdef SYSDEBUG
if (operation == PR_CAPBSET_READ || operation == PR_CAPBSET_DROP) {
@@ -1,50 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/macros.internal.h"
.initbss 400,_init_program_invocation_short_name
// Supplies basename(argv[0]) The GNU Way.
//
// If argv[0] isn't supplied, this value will be null.
//
// @see GetProgramExecutableName()
// @see program_invocation_name
program_invocation_short_name:
.quad 0
.endobj program_invocation_short_name,globl
.previous
.init.start 400,_init_program_invocation_short_name
push %rsi
xor %eax,%eax
test %r12d,%r12d # argc
jz 2f
mov (%r13),%rsi # argv[0]
mov %rsi,%rcx
1: lodsb
cmp $'/',%al
cmoveq %rsi,%rcx
cmp $'\\',%al
cmoveq %rsi,%rcx
test %al,%al
jnz 1b
xchg %rcx,%rax
pop %rsi
2: stosq
.init.end 400,_init_program_invocation_short_name
@@ -0,0 +1,34 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2023 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
char *program_invocation_short_name;
__attribute__((__constructor__)) static void //
program_invocation_short_name_init(void) {
char *p, *r;
if (!__argc) return;
if ((p = strrchr(__argv[0], '/'))) {
r = p + 1;
} else {
r = __argv[0];
}
program_invocation_short_name = r;
}
+4
View File
@@ -26,6 +26,8 @@
#include "libc/sysv/errfuns.h"
#include "libc/vga/vga.internal.h"
#ifdef __x86_64__
ssize_t sys_readv_metal(struct Fd *fd, const struct iovec *iov, int iovlen) {
int i;
size_t got, toto;
@@ -56,3 +58,5 @@ ssize_t sys_readv_metal(struct Fd *fd, const struct iovec *iov, int iovlen) {
return ebadf();
}
}
#endif /* __x86_64__ */
+3
View File
@@ -20,6 +20,7 @@
#include "libc/calls/struct/iovec.internal.h"
#include "libc/nexgen32e/uart.internal.h"
#include "libc/runtime/pc.internal.h"
#ifdef __x86_64__
static bool IsDataAvailable(struct Fd *fd) {
return inb(fd->handle + UART_LSR) & UART_TTYDA;
@@ -47,3 +48,5 @@ ssize_t sys_readv_serial(struct Fd *fd, const struct iovec *iov, int iovlen) {
return 0;
}
}
#endif
+16
View File
@@ -18,6 +18,7 @@
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/struct/seccomp.h"
#include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/describeflags.internal.h"
@@ -36,6 +37,7 @@
*/
privileged int seccomp(unsigned operation, unsigned flags, void *args) {
int rc;
#ifdef __x86_64__
if (IsLinux()) {
asm volatile("syscall"
: "=a"(rc)
@@ -62,6 +64,20 @@ privileged int seccomp(unsigned operation, unsigned flags, void *args) {
} else {
rc = enosys();
}
#elif defined(__aarch64__)
register long r0 asm("x0") = (long)operation;
register long r1 asm("x1") = (long)flags;
register long r2 asm("x2") = (long)args;
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n\t"
"svc\t0"
: "=r"(res_x0)
: "i"(211), "r"(r0), "r"(r1), "r"(r2)
: "x8", "memory");
rc = _sysret(res_x0);
#else
#error "arch unsupported"
#endif
STRACE("seccomp(%s, %#x, %p) → %d% m", DescribeSeccompOperation(operation),
flags, args, rc);
return rc;
+4
View File
@@ -41,6 +41,8 @@
#include "libc/sysv/errfuns.h"
#include "libc/time/time.h"
#ifdef __x86_64__
/**
* @fileoverview Heartbreaking polyfill for SIGALRM on NT.
*
@@ -130,3 +132,5 @@ textwindows int sys_setitimer_nt(int which, const struct itimerval *newvalue,
return 0;
}
#endif /* __x86_64__ */
+3 -1
View File
@@ -255,7 +255,9 @@ static int __sigaction(int sig, const struct sigaction *act,
if (act) {
__sighandrvas[sig] = rva;
__sighandflags[sig] = act->sa_flags;
__sig_check_ignore(sig, rva);
if (IsWindows()) {
__sig_check_ignore(sig, rva);
}
}
}
return rc;
+4
View File
@@ -32,6 +32,8 @@
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/sig.h"
#ifdef __x86_64__
/**
* Checks to see if SIGCHLD should be raised on Windows.
* @return true if a signal was raised
@@ -67,3 +69,5 @@ void _check_sigchld(void) {
__fds_unlock();
__sig_add(0, SIGCHLD, CLD_EXITED);
}
#endif /* __x86_64__ */
+4
View File
@@ -32,6 +32,8 @@
#include "libc/str/str.h"
#include "libc/sysv/consts/sa.h"
#ifdef __x86_64__
privileged void __sigenter_freebsd(int sig, struct siginfo_freebsd *freebsdinfo,
struct ucontext_freebsd *ctx) {
int rva, flags;
@@ -114,3 +116,5 @@ privileged void __sigenter_freebsd(int sig, struct siginfo_freebsd *freebsdinfo,
* function, and 2) calls sys_sigreturn() once this returns.
*/
}
#endif /* __x86_64__ */
+4
View File
@@ -28,6 +28,8 @@
#include "libc/str/str.h"
#include "libc/sysv/consts/sa.h"
#ifdef __x86_64__
privileged void __sigenter_wsl(int sig, struct siginfo *info, ucontext_t *ctx) {
int i, rva, flags;
rva = __sighandrvas[sig & (NSIG - 1)];
@@ -45,3 +47,5 @@ privileged void __sigenter_wsl(int sig, struct siginfo *info, ucontext_t *ctx) {
((sigaction_f)(_base + rva))(sig, info, ctx);
}
}
#endif /* __x86_64__ */
+4
View File
@@ -32,6 +32,8 @@
#include "libc/str/str.h"
#include "libc/sysv/consts/sa.h"
#ifdef __x86_64__
privileged void __sigenter_netbsd(int sig, struct siginfo_netbsd *si,
struct ucontext_netbsd *ctx) {
int rva, flags;
@@ -109,3 +111,5 @@ privileged void __sigenter_netbsd(int sig, struct siginfo_netbsd *si,
* function, and 2) calls sys_sigreturn() once this returns.
*/
}
#endif /* __x86_64__ */
+4
View File
@@ -32,6 +32,8 @@
#include "libc/str/str.h"
#include "libc/sysv/consts/sa.h"
#ifdef __x86_64__
privileged void __sigenter_openbsd(int sig, struct siginfo_openbsd *openbsdinfo,
struct ucontext_openbsd *ctx) {
int rva, flags;
@@ -108,3 +110,5 @@ privileged void __sigenter_openbsd(int sig, struct siginfo_openbsd *openbsdinfo,
* function, and 2) calls sys_sigreturn() once this returns.
*/
}
#endif /* __x86_64__ */
+3
View File
@@ -31,6 +31,7 @@
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/sa.h"
#ifdef __x86_64__
/**
* @fileoverview XNU kernel callback normalization.
@@ -527,3 +528,5 @@ privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
: "rcx", "r11", "memory", "cc");
notpossible;
}
#endif
+4
View File
@@ -32,6 +32,8 @@
#include "libc/sysv/consts/sig.h"
#include "libc/thread/tls.h"
#ifdef __x86_64__
static struct winsize __ws;
textwindows void _check_sigwinch(struct Fd *fd) {
@@ -58,3 +60,5 @@ textwindows void _check_sigwinch(struct Fd *fd) {
}
errno = e;
}
#endif /* __x86_64__ */
+14
View File
@@ -22,6 +22,20 @@
void __stat2cosmo(struct stat *restrict st, const union metastat *ms) {
if (st) {
if (IsLinux()) {
st->st_dev = ms->linux.st_dev;
st->st_ino = ms->linux.st_ino;
st->st_nlink = ms->linux.st_nlink;
st->st_mode = ms->linux.st_mode;
st->st_uid = ms->linux.st_uid;
st->st_gid = ms->linux.st_gid;
st->st_flags = 0;
st->st_rdev = ms->linux.st_rdev;
st->st_size = ms->linux.st_size;
st->st_blksize = ms->linux.st_blksize;
st->st_blocks = ms->linux.st_blocks;
st->st_atim = ms->linux.st_atim;
st->st_mtim = ms->linux.st_mtim;
st->st_ctim = ms->linux.st_ctim;
st->st_birthtim = st->st_ctim;
if (st->st_atim.tv_sec < st->st_ctim.tv_sec)
st->st_birthtim = st->st_atim;
+18
View File
@@ -16,6 +16,7 @@ COSMOPOLITAN_C_START_
struct stat_linux {
uint64_t st_dev;
uint64_t st_ino;
#ifdef __x86_64__
uint64_t st_nlink;
uint32_t st_mode;
uint32_t st_uid;
@@ -29,6 +30,23 @@ struct stat_linux {
struct timespec st_mtim;
struct timespec st_ctim;
int64_t __unused[3];
#elif defined(__aarch64__)
uint32_t st_mode;
uint32_t st_nlink;
uint32_t st_uid;
uint32_t st_gid;
uint64_t st_rdev;
uint64_t __pad1;
int64_t st_size;
int32_t st_blksize;
int32_t __pad2;
int64_t st_blocks;
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
uint32_t __unused4;
uint32_t __unused5;
#endif
};
struct stat_xnu {
@@ -5,6 +5,8 @@
COSMOPOLITAN_C_START_
// clang-format off
#ifdef __x86_64__
#define __UCONTEXT_SIZE 784
#define _UC_SIGMASK 0x01
#define _UC_STACK 0x02
@@ -78,6 +80,8 @@ struct ucontext_netbsd {
};
};
#endif /* __x86_64__ */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_NETBSD_INTERNAL_H_ */
+2
View File
@@ -137,7 +137,9 @@ u32 sys_geteuid(void) _Hide;
u32 sys_getgid(void) _Hide;
u32 sys_getuid(void) _Hide;
u32 sys_umask(u32) _Hide;
unsigned long _sysret(unsigned long) _Hide;
void *__sys_mmap(void *, u64, u32, u32, i64, i64, i64) _Hide;
void *__sys_mremap(void *, u64, u64, i32, void *) _Hide;
void *sys_mremap(void *, u64, u64, i32, void *) _Hide;
void sys_exit(i32) _Hide;
+22 -3
View File
@@ -5,6 +5,8 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#ifdef __x86_64__
struct XmmRegister {
uint64_t u64[2];
};
@@ -33,7 +35,10 @@ typedef uint64_t greg_t;
typedef greg_t gregset_t[23];
typedef struct FpuState *fpregset_t;
struct MachineContext {
#endif /* __x86_64__ */
struct sigcontext {
#ifdef __x86_64__
union {
struct {
uint64_t r8;
@@ -67,18 +72,32 @@ struct MachineContext {
};
struct FpuState *fpregs; /* zero when no fpu context */
uint64_t __pad1[8];
#elif defined(__aarch64__)
uint64_t fault_address;
uint64_t regs[31];
uint64_t sp;
uint64_t pc;
uint64_t pstate;
uint8_t __reserved[4096] __attribute__((__aligned__(16)));
#endif /* __x86_64__ */
};
typedef struct MachineContext mcontext_t;
typedef struct sigcontext mcontext_t;
struct ucontext {
uint64_t uc_flags; /* don't use this */
struct ucontext *uc_link;
stack_t uc_stack;
mcontext_t uc_mcontext; /* use this */
#ifdef __x86_64__
struct sigcontext uc_mcontext;
sigset_t uc_sigmask;
uint64_t __pad;
struct FpuState __fpustate; /* for cosmo on non-linux */
#elif defined(__aarch64__)
sigset_t uc_sigmask;
uint8_t __unused[1024 / 8 - sizeof(sigset_t)];
struct sigcontext uc_mcontext;
#endif
};
typedef struct ucontext ucontext_t;
+5 -3
View File
@@ -17,7 +17,8 @@
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/calls.h"
#include "libc/intrin/lockxchg.h"
// TODO(jart): DELETE
/**
* Deletes file.
@@ -29,6 +30,7 @@
* @asyncsignalsafe
*/
int unlink_s(const char **namep) {
const char *name = NULL;
return unlink(lockxchg(namep, &name));
const char *name = *namep;
*namep = 0;
return unlink(name);
}
+4
View File
@@ -48,6 +48,8 @@
#include "libc/sysv/errfuns.h"
#include "libc/thread/tls.h"
#ifdef __x86_64__
#define OFF(f) offsetof(struct seccomp_data, f)
#define UNVEIL_READ \
@@ -400,3 +402,5 @@ int unveil(const char *path, const char *permissions) {
STRACE("unveil(%#s, %#s) → %d% m", path, permissions, rc);
return rc;
}
#endif /* __x86_64__ */
+24
View File
@@ -0,0 +1,24 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2023 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/runtime/runtime.h"
#ifndef __x86_64__
size_t __virtualmax = -1;
#endif /* __x86_64__ */
+4
View File
@@ -45,6 +45,8 @@
#include "libc/sysv/consts/w.h"
#include "libc/sysv/errfuns.h"
#ifdef __x86_64__
static textwindows int sys_wait4_nt_impl(int pid, int *opt_out_wstatus,
int options,
struct rusage *opt_out_rusage) {
@@ -156,3 +158,5 @@ textwindows int sys_wait4_nt(int pid, int *opt_out_wstatus, int options,
__sig_mask(SIG_SETMASK, &oldmask, 0);
return rc;
}
#endif /* __x86_64__ */
+8 -2
View File
@@ -7,7 +7,6 @@
*/
#define blkcnt_t int64_t
#define blksize_t int64_t /* int32_t on xnu */
#define cc_t uint8_t
#define clock_t int64_t /* uint64_t on xnu */
#define dev_t uint64_t /* int32_t on xnu */
@@ -38,7 +37,14 @@
#define uid_t uint32_t
#define rlim_t uint64_t /* int64_t on bsd */
#define clockid_t int32_t
#define nlink_t uint64_t
#ifdef __x86_64__
#define blksize_t int64_t /* int32_t on xnu */
#define nlink_t uint64_t
#elif defined(__aarch64__)
#define blksize_t int32_t
#define nlink_t uint32_t
#endif
#define TIME_T_MAX __INT64_MAX__
#define TIME_T_MIN (-TIME_T_MAX - 1)
+4
View File
@@ -34,6 +34,8 @@
#include "libc/thread/tls.h"
#include "libc/thread/tls2.h"
#ifdef __x86_64__
privileged unsigned __wincrash(struct NtExceptionPointers *ep) {
int64_t rip;
int sig, code;
@@ -147,3 +149,5 @@ privileged unsigned __wincrash(struct NtExceptionPointers *ep) {
return kNtExceptionContinueExecution;
}
#endif /* __x86_64__ */
+1 -3
View File
@@ -72,9 +72,7 @@ ssize_t write(int fd, const void *buf, size_t size) {
if ((!buf && size) || (IsAsan() && !__asan_is_valid(buf, size))) {
rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = _weaken(__zipos_write)(
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle,
&(struct iovec){buf, size}, 1, -1);
rc = enotsup();
} else if (!IsWindows() && !IsMetal()) {
rc = sys_write(fd, buf, size);
} else if (fd >= g_fds.n) {
+4
View File
@@ -23,6 +23,8 @@
#include "libc/sysv/errfuns.h"
#include "libc/vga/vga.internal.h"
#ifdef __x86_64__
ssize_t sys_writev_metal(struct Fd *fd, const struct iovec *iov, int iovlen) {
switch (fd->kind) {
case kFdConsole:
@@ -34,3 +36,5 @@ ssize_t sys_writev_metal(struct Fd *fd, const struct iovec *iov, int iovlen) {
return ebadf();
}
}
#endif /* __x86_64__ */
+3
View File
@@ -21,6 +21,7 @@
#include "libc/calls/struct/iovec.internal.h"
#include "libc/nexgen32e/uart.internal.h"
#include "libc/runtime/pc.internal.h"
#ifdef __x86_64__
ssize_t sys_writev_serial(struct Fd *fd, const struct iovec *iov, int iovlen) {
size_t i, j, wrote = 0;
@@ -35,3 +36,5 @@ ssize_t sys_writev_serial(struct Fd *fd, const struct iovec *iov, int iovlen) {
}
return wrote;
}
#endif
+23 -8
View File
@@ -30,6 +30,7 @@
// @note ape.S and ape-loader both set RCX to XNU on Darwin
// @noreturn
_start:
#ifdef __x86_64__
#if SupportsXnu()
// Hack for detecting M1 Rosetta environment.
@@ -63,9 +64,9 @@ _start:
mov %edx,4(%rbx)
// translates arguments from old stack abi
mov (%rsp),%ebx # argc
lea 8(%rsp),%rsi # argv
lea 16(%rsp,%rbx,8),%rdx # envp
mov (%rsp),%ebx // argc
lea 8(%rsp),%rsi // argv
lea 16(%rsp,%rbx,8),%rdx // envp
mov %rsp,__oldstack(%rip)
and $-16,%rsp
xor %ebp,%ebp
@@ -87,19 +88,33 @@ _start:
or $-1,%ecx
mov %rdx,%rdi
repnz scasq
mov %rdi,%rcx # auxv
mov %rdi,%rcx // auxv
#if SupportsXnu()
// xnu doesn't have auxiliary values
testb IsXnu()
jz 1f # polyfill xnu auxv
push $0 # auxv[1][1]=0
push $0 # auxv[1][0]=0
mov %rsp,%rcx # auxv
jz 1f // polyfill xnu auxv
push $0 // auxv[1][1]=0
push $0 // auxv[1][0]=0
mov %rsp,%rcx // auxv
#endif
// enter cosmopolitan runtime
1: mov %ebx,%edi
call cosmo
9: .unreachable
////////////////////////////////////////////////////////////////////////////////
#elif defined(__aarch64__)
mov x29,#0
mov x30,#0
mov x0,sp
and sp,x0,#-16
b cosmo
////////////////////////////////////////////////////////////////////////////////
#else
#error "architecture unsupported"
#endif /* __x86_64__ */
.endfn _start,weak,hidden
+4
View File
@@ -26,5 +26,9 @@ CRT_SRCS = libc/crt/crt.S
CRT_OBJS = o/$(MODE)/libc/crt/crt.o
$(CRT_OBJS): $(BUILD_FILES) libc/crt/crt.mk
# these assembly files are safe to build on aarch64
o/$(MODE)/libc/crt/crt.o: libc/crt/crt.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
.PHONY: o/$(MODE)/libc/crt
o/$(MODE)/libc/crt: $(CRT)
+9 -1
View File
@@ -5,11 +5,15 @@
╚─────────────────────────────────────────────────────────────────────────────*/
#ifndef SUPPORT_VECTOR
#ifdef __x86_64__
/**
* Supported Platforms Tuning Knob (Runtime & Compile-Time)
* Tuning this bitmask will remove platform polyfills at compile-time.
*/
#define SUPPORT_VECTOR 255
#else
#define SUPPORT_VECTOR _HOSTLINUX
#endif
#endif
#define _HOSTLINUX 1
@@ -106,9 +110,13 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#ifdef __x86_64__
extern const int __hostos;
bool IsWsl1(void);
#else
#define __hostos _HOSTLINUX
#define IsWsl1() false
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
-31
View File
@@ -1,31 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/dns/hoststxt.h"
#include "libc/runtime/runtime.h"
/**
* Frees HOSTS.TXT data structure populated by ParseHostsTxt().
*/
void FreeHostsTxt(struct HostsTxt **ht) {
if (*ht) {
free_s(&(*ht)->entries.p);
free_s(&(*ht)->strings.p);
free_s(ht);
}
}
-30
View File
@@ -1,30 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/dns/resolvconf.h"
#include "libc/runtime/runtime.h"
/**
* Frees resolv.conf data structure populated by ParseResolvConf().
*/
void FreeResolvConf(struct ResolvConf **rvp) {
if (*rvp) {
free_s(&(*rvp)->nameservers.p);
free_s(rvp);
}
}
+19
View File
@@ -24,6 +24,7 @@
#include "libc/intrin/pushpop.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nt/systeminfo.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
@@ -85,3 +86,21 @@ const struct HostsTxt *GetHostsTxt(void) {
pthread_mutex_unlock(&init->lock);
return g_hoststxt;
}
/**
* Frees HOSTS.TXT data structure populated by ParseHostsTxt().
*/
void FreeHostsTxt(struct HostsTxt **ht) {
if (*ht) {
if ((*ht)->entries.p != g_hoststxt_init.entries) {
free((*ht)->entries.p);
}
if ((*ht)->strings.p != g_hoststxt_init.strings) {
free((*ht)->strings.p);
}
if (*ht != &g_hoststxt_init.ht) {
free(*ht);
}
*ht = 0;
}
}
Loaded 100 of 17207 files, more files were not shown because too many files have changed in this diff. Show more