mirror of
https://github.com/jart/cosmopolitan.git
synced 2026-11-07 17:22:16 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f2bf3895e | ||
|
|
dbb8d66f22 | ||
|
|
cba15bc77a | ||
|
|
8d24a18c62 | ||
|
|
1f6f9e6701 | ||
|
|
a88290e595 | ||
|
|
5250feb7ad | ||
|
|
c91de6a356 | ||
|
|
ea607781f8 | ||
|
|
bb3ebedfce | ||
|
|
290a49952e | ||
|
|
64aca4dc4f | ||
|
|
4e81d3277c | ||
|
|
12a33858c9 | ||
|
|
6cb9553706 | ||
|
|
ca990ef091 | ||
|
|
f312f706f4 | ||
|
|
5f57fc1f59 | ||
|
|
5a455eaa0b | ||
|
|
59766efd3e | ||
|
|
86d9323a43 | ||
|
|
a0237a017c | ||
|
|
4c093155a3 | ||
|
|
d04430f4ef | ||
|
|
ae0ee59614 | ||
|
|
e5e3cdf447 | ||
|
|
7e46645193 | ||
|
|
036b9a0002 | ||
|
|
aef9a69a60 | ||
|
|
135080fd3e | ||
|
|
2b73e72d59 | ||
|
|
ca2860947f | ||
|
|
08ff26c817 | ||
|
|
8303e23b3a | ||
|
|
57cc257f58 | ||
|
|
a493b64233 | ||
|
|
b008950d90 | ||
|
|
12438cce16 | ||
|
|
fc82f77a46 | ||
|
|
3dac9f8999 | ||
|
|
d9e27203d4 | ||
|
|
b31ba86ace | ||
|
|
bf6459e324 | ||
|
|
1c2da3a55a | ||
|
|
420f889ac3 | ||
|
|
e8b43903b2 | ||
|
|
f42089d5c6 | ||
|
|
fec139f423 | ||
|
|
7c9ef924bf | ||
|
|
b7bf052a4b | ||
|
|
369f9740de | ||
|
|
497d4fa6d1 | ||
|
|
614229e3f4 | ||
|
|
1a839ba41d | ||
|
|
4a6be2154d | ||
|
|
3e702e8f65 | ||
|
|
a8ff220654 | ||
|
|
d484e1dbd4 | ||
|
|
d5b8b644c2 | ||
|
|
f7bccf5513 | ||
|
|
6758c3f400 | ||
|
|
9a5d69c842 | ||
|
|
12e07798df | ||
|
|
9c6d78c26d | ||
|
|
221adfa606 | ||
|
|
4ad4c2625d | ||
|
|
e3eb55cc8f | ||
|
|
36f52ea687 | ||
|
|
669b4c5f19 | ||
|
|
ba42248575 | ||
|
|
999481ace0 | ||
|
|
7f925e6be9 | ||
|
|
2f4335e081 | ||
|
|
0adefbf152 | ||
|
|
a412ca7a77 | ||
|
|
426d441994 | ||
|
|
4f39139fe0 | ||
|
|
0d084d01b9 | ||
|
|
390aee960a | ||
|
|
792b1c84c0 | ||
|
|
2d6ea2fbc9 | ||
|
|
58b2f9bd6b | ||
|
|
893703a07b | ||
|
|
775f456d4c | ||
|
|
e2f429b742 | ||
|
|
ba180e754d | ||
|
|
713d4424c6 | ||
|
|
e16b969829 | ||
|
|
2112fb1736 | ||
|
|
2aa044cb0c | ||
|
|
c8a9d3458e | ||
|
|
c5de653b98 | ||
|
|
22fcab131c | ||
|
|
da7c8c7b54 | ||
|
|
f5520209f5 | ||
|
|
ae365928c5 | ||
|
|
5923d483a4 | ||
|
|
0312898979 | ||
|
|
db16f0129a | ||
|
|
c395d16230 | ||
|
|
1011db793f | ||
|
|
ca88fc34c3 | ||
|
|
ad97d7b9db | ||
|
|
18a24935cc | ||
|
|
8b69acc1cc | ||
|
|
0468ca02fe | ||
|
|
7355499a6a | ||
|
|
1208ac9f10 | ||
|
|
298ba74a45 | ||
|
|
b15f9eb58f | ||
|
|
60eb34509b | ||
|
|
a808b3e738 | ||
|
|
0f1ead8943 | ||
|
|
dfabcd84c1 | ||
|
|
71d955be1d | ||
|
|
e4ee1da652 | ||
|
|
ff9c15f48a | ||
|
|
b275e664ec | ||
|
|
e323527ffa | ||
|
|
08fef9b277 | ||
|
|
94dcf81954 | ||
|
|
2b6261a52d | ||
|
|
0eb621f75e | ||
|
|
9634227181 | ||
|
|
9fce2751c8 | ||
|
|
49c1dea03b |
No files matched your search
@@ -8,6 +8,7 @@ AlwaysBreakBeforeMultilineStrings: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
IncludeBlocks: Merge
|
||||
---
|
||||
Language: Cpp
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# -*- conf -*-
|
||||
*.gz binary
|
||||
/build/bootstrap/*.com binary
|
||||
/build/bootstrap/*.com binary
|
||||
/usr/share/zoneinfo/* binary
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- conf -*-
|
||||
|
||||
/o
|
||||
/.prompt.jtlp
|
||||
|
||||
# TODO: Find some way to have Python write to o/
|
||||
__pycache__
|
||||
|
||||
@@ -117,10 +117,11 @@ 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 # │
|
||||
include third_party/zlib/zlib.mk # │
|
||||
include third_party/double-conversion/dc.mk # │
|
||||
include libc/elf/elf.mk # │
|
||||
@@ -131,18 +132,21 @@ 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 #─┐
|
||||
include libc/zipos/zipos.mk # ├──DYNAMIC RUNTIME
|
||||
include third_party/gdtoa/gdtoa.mk # │ You can now use stdio
|
||||
include libc/time/time.mk # │ You can finally call malloc()
|
||||
include third_party/nsync/mem/mem.mk # │
|
||||
include libc/thread/thread.mk # │
|
||||
include third_party/gdtoa/gdtoa.mk # ├──DYNAMIC RUNTIME
|
||||
include third_party/nsync/mem/mem.mk # │ You can now use stdio
|
||||
include libc/thread/thread.mk # │ You can finally call malloc()
|
||||
include libc/zipos/zipos.mk # │
|
||||
include libc/time/time.mk # │
|
||||
include libc/stdio/stdio.mk # │
|
||||
include third_party/libcxx/libcxx.mk # │
|
||||
include net/net.mk # │
|
||||
include third_party/vqsort/vqsort.mk # │
|
||||
include libc/log/log.mk # │
|
||||
include third_party/ggml/ggml.mk # │
|
||||
include third_party/bzip2/bzip2.mk # │
|
||||
include dsp/core/core.mk # │
|
||||
include libc/x/x.mk # │
|
||||
@@ -152,6 +156,8 @@ include dsp/mpeg/mpeg.mk # │
|
||||
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
|
||||
@@ -195,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
|
||||
@@ -281,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 $@
|
||||
|
||||
@@ -309,7 +316,6 @@ COSMOPOLITAN_OBJECTS = \
|
||||
LIBC_LOG \
|
||||
LIBC_TIME \
|
||||
LIBC_ZIPOS \
|
||||
THIRD_PARTY_ZLIB \
|
||||
THIRD_PARTY_MUSL \
|
||||
LIBC_STDIO \
|
||||
THIRD_PARTY_GDTOA \
|
||||
@@ -335,6 +341,7 @@ COSMOPOLITAN_OBJECTS = \
|
||||
LIBC_NT_ADVAPI32 \
|
||||
LIBC_NT_SYNCHRONIZATION \
|
||||
LIBC_FMT \
|
||||
THIRD_PARTY_PUFF \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
LIBC_TINYMATH \
|
||||
THIRD_PARTY_XED \
|
||||
@@ -413,7 +420,8 @@ toolchain: o/cosmopolitan.h \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/ape/ape-copy-self.o \
|
||||
o/$(MODE)/ape/ape-no-modify-self.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
o/$(MODE)/cosmopolitan.a \
|
||||
o/$(MODE)/third_party/libcxx/libcxx.a
|
||||
|
||||
# UNSPECIFIED PREREQUISITES TUTORIAL
|
||||
#
|
||||
|
||||
@@ -243,6 +243,11 @@ You normally run the `.com.dbg` file under gdb. If you need to debug the
|
||||
gdb foo.com -ex 'add-symbol-file foo.com.dbg 0x401000'
|
||||
```
|
||||
|
||||
## Discord Chatroom
|
||||
|
||||
The Cosmopolitan development team collaborates on the Redbean Discord
|
||||
server. You're welcome to join us! <https://discord.gg/FwAVVu7eJ4>
|
||||
|
||||
## Support Vector
|
||||
|
||||
| Platform | Min Version | Circa |
|
||||
|
||||
@@ -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
-160
@@ -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,159 +620,7 @@ 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);
|
||||
|
||||
HIDDEN(blink_arm_b0 = RVA(blink_arm) % 10 + 48);
|
||||
HIDDEN(blink_arm_b1 = RVA(blink_arm) < 10 ? 32 : RVA(blink_arm) / 10 % 10 + 48);
|
||||
HIDDEN(blink_arm_b2 = RVA(blink_arm) < 100 ? 32 : RVA(blink_arm) / 100 % 10 + 48);
|
||||
HIDDEN(blink_arm_b3 = RVA(blink_arm) < 1000 ? 32 : RVA(blink_arm) / 1000 % 10 + 48);
|
||||
HIDDEN(blink_arm_b4 = RVA(blink_arm) < 10000 ? 32 : RVA(blink_arm) / 10000 % 10 + 48);
|
||||
HIDDEN(blink_arm_b5 = RVA(blink_arm) < 100000 ? 32 : RVA(blink_arm) / 100000 % 10 + 48);
|
||||
HIDDEN(blink_arm_b6 = RVA(blink_arm) < 1000000 ? 32 : RVA(blink_arm) / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_arm_b7 = RVA(blink_arm) < 10000000 ? 32 : RVA(blink_arm) / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_arm_b8 = RVA(blink_arm) < 100000000 ? 32 : RVA(blink_arm) / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_arm_b9 = RVA(blink_arm) < 1000000000 ? 32 : RVA(blink_arm) / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_arm_size_b0 = blink_arm_size % 10 + 48);
|
||||
HIDDEN(blink_arm_size_b1 = blink_arm_size < 10 ? 32 : blink_arm_size / 10 % 10 + 48);
|
||||
HIDDEN(blink_arm_size_b2 = blink_arm_size < 100 ? 32 : blink_arm_size / 100 % 10 + 48);
|
||||
HIDDEN(blink_arm_size_b3 = blink_arm_size < 1000 ? 32 : blink_arm_size / 1000 % 10 + 48);
|
||||
HIDDEN(blink_arm_size_b4 = blink_arm_size < 10000 ? 32 : blink_arm_size / 10000 % 10 + 48);
|
||||
HIDDEN(blink_arm_size_b5 = blink_arm_size < 100000 ? 32 : blink_arm_size / 100000 % 10 + 48);
|
||||
HIDDEN(blink_arm_size_b6 = blink_arm_size < 1000000 ? 32 : blink_arm_size / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_arm_size_b7 = blink_arm_size < 10000000 ? 32 : blink_arm_size / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_arm_size_b8 = blink_arm_size < 100000000 ? 32 : blink_arm_size / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_arm_size_b9 = blink_arm_size < 1000000000 ? 32 : blink_arm_size / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_i486_b0 = RVA(blink_i486) % 10 + 48);
|
||||
HIDDEN(blink_i486_b1 = RVA(blink_i486) < 10 ? 32 : RVA(blink_i486) / 10 % 10 + 48);
|
||||
HIDDEN(blink_i486_b2 = RVA(blink_i486) < 100 ? 32 : RVA(blink_i486) / 100 % 10 + 48);
|
||||
HIDDEN(blink_i486_b3 = RVA(blink_i486) < 1000 ? 32 : RVA(blink_i486) / 1000 % 10 + 48);
|
||||
HIDDEN(blink_i486_b4 = RVA(blink_i486) < 10000 ? 32 : RVA(blink_i486) / 10000 % 10 + 48);
|
||||
HIDDEN(blink_i486_b5 = RVA(blink_i486) < 100000 ? 32 : RVA(blink_i486) / 100000 % 10 + 48);
|
||||
HIDDEN(blink_i486_b6 = RVA(blink_i486) < 1000000 ? 32 : RVA(blink_i486) / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_i486_b7 = RVA(blink_i486) < 10000000 ? 32 : RVA(blink_i486) / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_i486_b8 = RVA(blink_i486) < 100000000 ? 32 : RVA(blink_i486) / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_i486_b9 = RVA(blink_i486) < 1000000000 ? 32 : RVA(blink_i486) / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_i486_size_b0 = blink_i486_size % 10 + 48);
|
||||
HIDDEN(blink_i486_size_b1 = blink_i486_size < 10 ? 32 : blink_i486_size / 10 % 10 + 48);
|
||||
HIDDEN(blink_i486_size_b2 = blink_i486_size < 100 ? 32 : blink_i486_size / 100 % 10 + 48);
|
||||
HIDDEN(blink_i486_size_b3 = blink_i486_size < 1000 ? 32 : blink_i486_size / 1000 % 10 + 48);
|
||||
HIDDEN(blink_i486_size_b4 = blink_i486_size < 10000 ? 32 : blink_i486_size / 10000 % 10 + 48);
|
||||
HIDDEN(blink_i486_size_b5 = blink_i486_size < 100000 ? 32 : blink_i486_size / 100000 % 10 + 48);
|
||||
HIDDEN(blink_i486_size_b6 = blink_i486_size < 1000000 ? 32 : blink_i486_size / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_i486_size_b7 = blink_i486_size < 10000000 ? 32 : blink_i486_size / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_i486_size_b8 = blink_i486_size < 100000000 ? 32 : blink_i486_size / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_i486_size_b9 = blink_i486_size < 1000000000 ? 32 : blink_i486_size / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_riscv64_b0 = RVA(blink_riscv64) % 10 + 48);
|
||||
HIDDEN(blink_riscv64_b1 = RVA(blink_riscv64) < 10 ? 32 : RVA(blink_riscv64) / 10 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_b2 = RVA(blink_riscv64) < 100 ? 32 : RVA(blink_riscv64) / 100 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_b3 = RVA(blink_riscv64) < 1000 ? 32 : RVA(blink_riscv64) / 1000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_b4 = RVA(blink_riscv64) < 10000 ? 32 : RVA(blink_riscv64) / 10000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_b5 = RVA(blink_riscv64) < 100000 ? 32 : RVA(blink_riscv64) / 100000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_b6 = RVA(blink_riscv64) < 1000000 ? 32 : RVA(blink_riscv64) / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_b7 = RVA(blink_riscv64) < 10000000 ? 32 : RVA(blink_riscv64) / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_b8 = RVA(blink_riscv64) < 100000000 ? 32 : RVA(blink_riscv64) / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_b9 = RVA(blink_riscv64) < 1000000000 ? 32 : RVA(blink_riscv64) / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_riscv64_size_b0 = blink_riscv64_size % 10 + 48);
|
||||
HIDDEN(blink_riscv64_size_b1 = blink_riscv64_size < 10 ? 32 : blink_riscv64_size / 10 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_size_b2 = blink_riscv64_size < 100 ? 32 : blink_riscv64_size / 100 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_size_b3 = blink_riscv64_size < 1000 ? 32 : blink_riscv64_size / 1000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_size_b4 = blink_riscv64_size < 10000 ? 32 : blink_riscv64_size / 10000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_size_b5 = blink_riscv64_size < 100000 ? 32 : blink_riscv64_size / 100000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_size_b6 = blink_riscv64_size < 1000000 ? 32 : blink_riscv64_size / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_size_b7 = blink_riscv64_size < 10000000 ? 32 : blink_riscv64_size / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_size_b8 = blink_riscv64_size < 100000000 ? 32 : blink_riscv64_size / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_riscv64_size_b9 = blink_riscv64_size < 1000000000 ? 32 : blink_riscv64_size / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_mipsel_b0 = RVA(blink_mipsel) % 10 + 48);
|
||||
HIDDEN(blink_mipsel_b1 = RVA(blink_mipsel) < 10 ? 32 : RVA(blink_mipsel) / 10 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_b2 = RVA(blink_mipsel) < 100 ? 32 : RVA(blink_mipsel) / 100 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_b3 = RVA(blink_mipsel) < 1000 ? 32 : RVA(blink_mipsel) / 1000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_b4 = RVA(blink_mipsel) < 10000 ? 32 : RVA(blink_mipsel) / 10000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_b5 = RVA(blink_mipsel) < 100000 ? 32 : RVA(blink_mipsel) / 100000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_b6 = RVA(blink_mipsel) < 1000000 ? 32 : RVA(blink_mipsel) / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_b7 = RVA(blink_mipsel) < 10000000 ? 32 : RVA(blink_mipsel) / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_b8 = RVA(blink_mipsel) < 100000000 ? 32 : RVA(blink_mipsel) / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_b9 = RVA(blink_mipsel) < 1000000000 ? 32 : RVA(blink_mipsel) / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_mipsel_size_b0 = blink_mipsel_size % 10 + 48);
|
||||
HIDDEN(blink_mipsel_size_b1 = blink_mipsel_size < 10 ? 32 : blink_mipsel_size / 10 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_size_b2 = blink_mipsel_size < 100 ? 32 : blink_mipsel_size / 100 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_size_b3 = blink_mipsel_size < 1000 ? 32 : blink_mipsel_size / 1000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_size_b4 = blink_mipsel_size < 10000 ? 32 : blink_mipsel_size / 10000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_size_b5 = blink_mipsel_size < 100000 ? 32 : blink_mipsel_size / 100000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_size_b6 = blink_mipsel_size < 1000000 ? 32 : blink_mipsel_size / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_size_b7 = blink_mipsel_size < 10000000 ? 32 : blink_mipsel_size / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_size_b8 = blink_mipsel_size < 100000000 ? 32 : blink_mipsel_size / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_mipsel_size_b9 = blink_mipsel_size < 1000000000 ? 32 : blink_mipsel_size / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_powerpc64le_b0 = RVA(blink_powerpc64le) % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_b1 = RVA(blink_powerpc64le) < 10 ? 32 : RVA(blink_powerpc64le) / 10 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_b2 = RVA(blink_powerpc64le) < 100 ? 32 : RVA(blink_powerpc64le) / 100 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_b3 = RVA(blink_powerpc64le) < 1000 ? 32 : RVA(blink_powerpc64le) / 1000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_b4 = RVA(blink_powerpc64le) < 10000 ? 32 : RVA(blink_powerpc64le) / 10000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_b5 = RVA(blink_powerpc64le) < 100000 ? 32 : RVA(blink_powerpc64le) / 100000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_b6 = RVA(blink_powerpc64le) < 1000000 ? 32 : RVA(blink_powerpc64le) / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_b7 = RVA(blink_powerpc64le) < 10000000 ? 32 : RVA(blink_powerpc64le) / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_b8 = RVA(blink_powerpc64le) < 100000000 ? 32 : RVA(blink_powerpc64le) / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_b9 = RVA(blink_powerpc64le) < 1000000000 ? 32 : RVA(blink_powerpc64le) / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_powerpc64le_size_b0 = blink_powerpc64le_size % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_size_b1 = blink_powerpc64le_size < 10 ? 32 : blink_powerpc64le_size / 10 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_size_b2 = blink_powerpc64le_size < 100 ? 32 : blink_powerpc64le_size / 100 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_size_b3 = blink_powerpc64le_size < 1000 ? 32 : blink_powerpc64le_size / 1000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_size_b4 = blink_powerpc64le_size < 10000 ? 32 : blink_powerpc64le_size / 10000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_size_b5 = blink_powerpc64le_size < 100000 ? 32 : blink_powerpc64le_size / 100000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_size_b6 = blink_powerpc64le_size < 1000000 ? 32 : blink_powerpc64le_size / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_size_b7 = blink_powerpc64le_size < 10000000 ? 32 : blink_powerpc64le_size / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_size_b8 = blink_powerpc64le_size < 100000000 ? 32 : blink_powerpc64le_size / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc64le_size_b9 = blink_powerpc64le_size < 1000000000 ? 32 : blink_powerpc64le_size / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_powerpc_b0 = RVA(blink_powerpc) % 10 + 48);
|
||||
HIDDEN(blink_powerpc_b1 = RVA(blink_powerpc) < 10 ? 32 : RVA(blink_powerpc) / 10 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_b2 = RVA(blink_powerpc) < 100 ? 32 : RVA(blink_powerpc) / 100 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_b3 = RVA(blink_powerpc) < 1000 ? 32 : RVA(blink_powerpc) / 1000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_b4 = RVA(blink_powerpc) < 10000 ? 32 : RVA(blink_powerpc) / 10000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_b5 = RVA(blink_powerpc) < 100000 ? 32 : RVA(blink_powerpc) / 100000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_b6 = RVA(blink_powerpc) < 1000000 ? 32 : RVA(blink_powerpc) / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_b7 = RVA(blink_powerpc) < 10000000 ? 32 : RVA(blink_powerpc) / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_b8 = RVA(blink_powerpc) < 100000000 ? 32 : RVA(blink_powerpc) / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_b9 = RVA(blink_powerpc) < 1000000000 ? 32 : RVA(blink_powerpc) / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_powerpc_size_b0 = blink_powerpc_size % 10 + 48);
|
||||
HIDDEN(blink_powerpc_size_b1 = blink_powerpc_size < 10 ? 32 : blink_powerpc_size / 10 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_size_b2 = blink_powerpc_size < 100 ? 32 : blink_powerpc_size / 100 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_size_b3 = blink_powerpc_size < 1000 ? 32 : blink_powerpc_size / 1000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_size_b4 = blink_powerpc_size < 10000 ? 32 : blink_powerpc_size / 10000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_size_b5 = blink_powerpc_size < 100000 ? 32 : blink_powerpc_size / 100000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_size_b6 = blink_powerpc_size < 1000000 ? 32 : blink_powerpc_size / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_size_b7 = blink_powerpc_size < 10000000 ? 32 : blink_powerpc_size / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_size_b8 = blink_powerpc_size < 100000000 ? 32 : blink_powerpc_size / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_powerpc_size_b9 = blink_powerpc_size < 1000000000 ? 32 : blink_powerpc_size / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_s390x_b0 = RVA(blink_s390x) % 10 + 48);
|
||||
HIDDEN(blink_s390x_b1 = RVA(blink_s390x) < 10 ? 32 : RVA(blink_s390x) / 10 % 10 + 48);
|
||||
HIDDEN(blink_s390x_b2 = RVA(blink_s390x) < 100 ? 32 : RVA(blink_s390x) / 100 % 10 + 48);
|
||||
HIDDEN(blink_s390x_b3 = RVA(blink_s390x) < 1000 ? 32 : RVA(blink_s390x) / 1000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_b4 = RVA(blink_s390x) < 10000 ? 32 : RVA(blink_s390x) / 10000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_b5 = RVA(blink_s390x) < 100000 ? 32 : RVA(blink_s390x) / 100000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_b6 = RVA(blink_s390x) < 1000000 ? 32 : RVA(blink_s390x) / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_b7 = RVA(blink_s390x) < 10000000 ? 32 : RVA(blink_s390x) / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_b8 = RVA(blink_s390x) < 100000000 ? 32 : RVA(blink_s390x) / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_b9 = RVA(blink_s390x) < 1000000000 ? 32 : RVA(blink_s390x) / 1000000000 % 10 + 48);
|
||||
|
||||
HIDDEN(blink_s390x_size_b0 = blink_s390x_size % 10 + 48);
|
||||
HIDDEN(blink_s390x_size_b1 = blink_s390x_size < 10 ? 32 : blink_s390x_size / 10 % 10 + 48);
|
||||
HIDDEN(blink_s390x_size_b2 = blink_s390x_size < 100 ? 32 : blink_s390x_size / 100 % 10 + 48);
|
||||
HIDDEN(blink_s390x_size_b3 = blink_s390x_size < 1000 ? 32 : blink_s390x_size / 1000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_size_b4 = blink_s390x_size < 10000 ? 32 : blink_s390x_size / 10000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_size_b5 = blink_s390x_size < 100000 ? 32 : blink_s390x_size / 100000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_size_b6 = blink_s390x_size < 1000000 ? 32 : blink_s390x_size / 1000000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_size_b7 = blink_s390x_size < 10000000 ? 32 : blink_s390x_size / 10000000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_size_b8 = blink_s390x_size < 100000000 ? 32 : blink_s390x_size / 100000000 % 10 + 48);
|
||||
HIDDEN(blink_s390x_size_b9 = blink_s390x_size < 1000000000 ? 32 : blink_s390x_size / 1000000000 % 10 + 48);
|
||||
#endif /* APE_IS_SHELL_SCRIPT */
|
||||
|
||||
#if SupportsMetal()
|
||||
HIDDEN(v_ape_realsectors =
|
||||
@@ -772,7 +629,7 @@ HIDDEN(v_ape_realbytes = v_ape_realsectors * 512);
|
||||
HIDDEN(v_ape_realdwords = v_ape_realsectors * (512 / 4));
|
||||
HIDDEN(v_ape_allsectors = ROUNDUP(RVA(_ezip), 512) / 512);
|
||||
HIDDEN(v_ape_allbytes = v_ape_allsectors * 512);
|
||||
HIDDEN(v_ape_highsectors = v_ape_allsectors - v_ape_realsectors);
|
||||
HIDDEN(v_ape_highsectors = MIN(0xffff, v_ape_allsectors - v_ape_realsectors));
|
||||
TSSDESCSTUB2(_tss, _tss, _tss_end ? _tss_end - _tss - 1 : 0);
|
||||
#endif
|
||||
|
||||
|
||||
+54
-52
@@ -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,22 +94,12 @@ o/ape/idata.inc: \
|
||||
ape/idata.internal.h \
|
||||
ape/relocations.h
|
||||
|
||||
o/$(MODE)/ape/ape.o: \
|
||||
ape/blink-aarch64.gz \
|
||||
ape/blink-arm.gz \
|
||||
ape/blink-darwin-arm64.gz \
|
||||
ape/blink-i486.gz \
|
||||
ape/blink-mipsel.gz \
|
||||
ape/blink-powerpc.gz \
|
||||
ape/blink-powerpc64le.gz \
|
||||
ape/blink-riscv64.gz \
|
||||
ape/blink-s390x.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 \
|
||||
@@ -127,14 +115,7 @@ o/$(MODE)/ape/ape-no-modify-self.o: \
|
||||
libc/runtime/symbolic.h \
|
||||
libc/sysv/consts/prot.h \
|
||||
ape/blink-aarch64.gz \
|
||||
ape/blink-arm.gz \
|
||||
ape/blink-darwin-arm64.gz \
|
||||
ape/blink-i486.gz \
|
||||
ape/blink-mipsel.gz \
|
||||
ape/blink-powerpc.gz \
|
||||
ape/blink-powerpc64le.gz \
|
||||
ape/blink-riscv64.gz \
|
||||
ape/blink-s390x.gz \
|
||||
o/$(MODE)/ape/ape.elf
|
||||
@$(COMPILE) \
|
||||
-AOBJECTIFY.S \
|
||||
@@ -148,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 \
|
||||
@@ -163,14 +145,7 @@ o/$(MODE)/ape/ape-copy-self.o: \
|
||||
libc/runtime/symbolic.h \
|
||||
libc/sysv/consts/prot.h \
|
||||
ape/blink-aarch64.gz \
|
||||
ape/blink-arm.gz \
|
||||
ape/blink-darwin-arm64.gz \
|
||||
ape/blink-i486.gz \
|
||||
ape/blink-mipsel.gz \
|
||||
ape/blink-powerpc.gz \
|
||||
ape/blink-powerpc64le.gz \
|
||||
ape/blink-riscv64.gz \
|
||||
ape/blink-s390x.gz
|
||||
ape/blink-darwin-arm64.gz
|
||||
@$(COMPILE) \
|
||||
-AOBJECTIFY.S \
|
||||
$(OBJECTIFY.S) \
|
||||
@@ -215,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
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+15
-7
@@ -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
@@ -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
@@ -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.
Binary file not shown.
+31
-1
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
|
||||
@@ -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
@@ -17,7 +17,7 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.align 16
|
||||
.balign 16
|
||||
|
||||
// Mixes audio.
|
||||
//
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
@@ -26,7 +26,7 @@ static void ttyidentfree(struct TtyIdent *ti) {
|
||||
if (ti) {
|
||||
assert(ti != ti->next);
|
||||
ttyidentfree(ti->next);
|
||||
free_s(&ti);
|
||||
free(ti);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -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 "libc/intrin/xmmintrin.internal.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);
|
||||
|
||||
@@ -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
@@ -3,7 +3,6 @@
|
||||
#include "dsp/tty/ttyrgb.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/xmmintrin.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/str.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
@@ -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
@@ -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) {
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/intrin/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]);
|
||||
}
|
||||
@@ -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
@@ -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
@@ -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;
|
||||
}
|
||||
@@ -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
@@ -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);
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -89,6 +89,7 @@ EXAMPLES_DIRECTDEPS = \
|
||||
THIRD_PARTY_SED \
|
||||
THIRD_PARTY_STB \
|
||||
THIRD_PARTY_TR \
|
||||
THIRD_PARTY_VQSORT \
|
||||
THIRD_PARTY_XED \
|
||||
THIRD_PARTY_ZLIB \
|
||||
TOOL_BUILD_LIB \
|
||||
@@ -183,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 <$< >$@
|
||||
|
||||
################################################################################
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#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/stdio/stdio.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char buf[256];
|
||||
if (!getdomainname(buf, sizeof(buf))) {
|
||||
printf("%s\n", buf);
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -27,13 +27,13 @@ dontinline void ShowIt(const char *path) {
|
||||
"optimal transfer block size");
|
||||
sizefmt(ibuf, sf.f_frsize, 1024);
|
||||
printf("f_frsize = %,zu (%sb %s)\n", sf.f_frsize, ibuf, "fragment size");
|
||||
sizefmt(ibuf, sf.f_blocks * sf.f_bsize, 1024);
|
||||
sizefmt(ibuf, sf.f_blocks * sf.f_frsize, 1024);
|
||||
printf("f_blocks = %,zu (%sb %s)\n", sf.f_blocks, ibuf,
|
||||
"total data blocks in filesystem");
|
||||
sizefmt(ibuf, sf.f_bfree * sf.f_bsize, 1024);
|
||||
sizefmt(ibuf, sf.f_bfree * sf.f_frsize, 1024);
|
||||
printf("f_bfree = %,zu (%sb %s)\n", sf.f_bfree, ibuf,
|
||||
"free blocks in filesystem");
|
||||
sizefmt(ibuf, sf.f_bavail * sf.f_bsize, 1024);
|
||||
sizefmt(ibuf, sf.f_bavail * sf.f_frsize, 1024);
|
||||
printf("f_bavail = %,zu (%sb %s)\n", sf.f_bavail, ibuf,
|
||||
"free blocks available to use");
|
||||
printf("f_files = %,zu (%s)\n", sf.f_files,
|
||||
|
||||
+16
-16
@@ -46,31 +46,31 @@ int main(int argc, char *argv[]) {
|
||||
1. / 65536 * si.loads[1], //
|
||||
1. / 65536 * si.loads[2]); //
|
||||
|
||||
sizefmt(ibuf, si.totalram, 1024);
|
||||
printf("%-16s %s\n", "totalram", ibuf);
|
||||
sizefmt(ibuf, si.totalram * si.mem_unit, 1024);
|
||||
printf("%-16s %ld (%s)\n", "totalram", si.totalram, ibuf);
|
||||
|
||||
sizefmt(ibuf, si.freeram, 1024);
|
||||
printf("%-16s %s\n", "freeram", ibuf);
|
||||
sizefmt(ibuf, si.freeram * si.mem_unit, 1024);
|
||||
printf("%-16s %ld (%s)\n", "freeram", si.freeram, ibuf);
|
||||
|
||||
sizefmt(ibuf, si.sharedram, 1024);
|
||||
printf("%-16s %s\n", "sharedram", ibuf);
|
||||
sizefmt(ibuf, si.sharedram * si.mem_unit, 1024);
|
||||
printf("%-16s %ld (%s)\n", "sharedram", si.sharedram, ibuf);
|
||||
|
||||
sizefmt(ibuf, si.bufferram, 1024);
|
||||
printf("%-16s %s\n", "bufferram", ibuf);
|
||||
sizefmt(ibuf, si.bufferram * si.mem_unit, 1024);
|
||||
printf("%-16s %ld (%s)\n", "bufferram", si.bufferram, ibuf);
|
||||
|
||||
sizefmt(ibuf, si.totalswap, 1024);
|
||||
printf("%-16s %s\n", "totalswap", ibuf);
|
||||
sizefmt(ibuf, si.totalswap * si.mem_unit, 1024);
|
||||
printf("%-16s %ld (%s)\n", "totalswap", si.totalswap, ibuf);
|
||||
|
||||
sizefmt(ibuf, si.freeswap, 1024);
|
||||
printf("%-16s %s\n", "freeswap", ibuf);
|
||||
sizefmt(ibuf, si.freeswap * si.mem_unit, 1024);
|
||||
printf("%-16s %ld (%s)\n", "freeswap", si.freeswap, ibuf);
|
||||
|
||||
printf("%-16s %lu\n", "processes", si.procs);
|
||||
|
||||
sizefmt(ibuf, si.totalhigh, 1024);
|
||||
printf("%-16s %s\n", "totalhigh", ibuf);
|
||||
sizefmt(ibuf, si.totalhigh * si.mem_unit, 1024);
|
||||
printf("%-16s %ld (%s)\n", "totalhigh", si.totalhigh, ibuf);
|
||||
|
||||
sizefmt(ibuf, si.freehigh, 1024);
|
||||
printf("%-16s %s\n", "freehigh", ibuf);
|
||||
sizefmt(ibuf, si.freehigh * si.mem_unit, 1024);
|
||||
printf("%-16s %ld (%s)\n", "freehigh", si.freehigh, ibuf);
|
||||
|
||||
sizefmt(ibuf, si.mem_unit, 1024);
|
||||
printf("%-16s %s\n", "mem_unit", ibuf);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#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 "third_party/vqsort/vqsort.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "third_party/vqsort/vqsort.h"
|
||||
|
||||
// how to sort one gigabyte of 64-bit integers per second
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int64_t A[] = {9, 3, -3, 5, 23, 7};
|
||||
vqsort_int64(A, ARRAYLEN(A));
|
||||
for (int i = 0; i < ARRAYLEN(A); ++i) {
|
||||
if (i) printf(" ");
|
||||
printf("%ld", A[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
@@ -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
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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) {
|
||||
|
||||
@@ -5,6 +5,26 @@
|
||||
#define _POSIX2_VERSION _POSIX_VERSION
|
||||
#define _XOPEN_VERSION 700
|
||||
|
||||
#define _POSIX_MAPPED_FILES _POSIX_VERSION
|
||||
#define _POSIX_FSYNC _POSIX_VERSION
|
||||
#define _POSIX_IPV6 _POSIX_VERSION
|
||||
#define _POSIX_THREADS _POSIX_VERSION
|
||||
#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION
|
||||
#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION
|
||||
#define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION
|
||||
#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION
|
||||
#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
|
||||
#define _POSIX_THREAD_CPUTIME _POSIX_VERSION
|
||||
#define _POSIX_TIMEOUTS _POSIX_VERSION
|
||||
#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION
|
||||
#define _POSIX_CPUTIME _POSIX_VERSION
|
||||
#define _POSIX_BARRIERS _POSIX_VERSION
|
||||
#define _POSIX_SPIN_LOCKS _POSIX_VERSION
|
||||
#define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION
|
||||
#define _POSIX_SEMAPHORES _POSIX_VERSION
|
||||
#define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION
|
||||
#define _POSIX_MEMLOCK_RANGE _POSIX_VERSION
|
||||
|
||||
#define EOF -1 /* end of file */
|
||||
#define WEOF -1u /* end of file (multibyte) */
|
||||
#define _IOFBF 0 /* fully buffered */
|
||||
|
||||
+2
-1
@@ -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))))
|
||||
|
||||
+1
-1
@@ -16,11 +16,11 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/consts/rusage.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -212,7 +212,7 @@ static bool ShouldUseSpinNanosleep(int clock, int flags,
|
||||
* while (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &abs, 0));
|
||||
*
|
||||
* will accurately spin on `EINTR` errors. That way you're not impeding
|
||||
* signal delivery and you're not losing precision on your wait timeout.
|
||||
* signal delivery and you're not loosing precision on the wait timeout.
|
||||
* This function has first-class support on Linux, FreeBSD, and NetBSD;
|
||||
* on OpenBSD it's good; on XNU it's bad; and on Windows it's ugly.
|
||||
*
|
||||
|
||||
+18
-4
@@ -16,16 +16,18 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/ok.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
static bool IsExePath(const char *s, size_t n) {
|
||||
@@ -48,6 +50,9 @@ static bool AccessCommand(const char *name, char *path, size_t pathsz,
|
||||
size_t pathlen) {
|
||||
size_t suffixlen;
|
||||
suffixlen = strlen(suffix);
|
||||
if (IsWindows() && suffixlen == 0 && !IsExePath(name, namelen) &&
|
||||
!IsComPath(name, namelen))
|
||||
return false;
|
||||
if (pathlen + 1 + namelen + suffixlen + 1 > pathsz) return false;
|
||||
if (pathlen && (path[pathlen - 1] != '/' && path[pathlen - 1] != '\\')) {
|
||||
path[pathlen] = !IsWindows() ? '/'
|
||||
@@ -57,7 +62,16 @@ static bool AccessCommand(const char *name, char *path, size_t pathsz,
|
||||
}
|
||||
memcpy(path + pathlen, name, namelen);
|
||||
memcpy(path + pathlen + namelen, suffix, suffixlen + 1);
|
||||
if (!access(path, X_OK)) return true;
|
||||
if (!access(path, X_OK)) {
|
||||
struct stat st;
|
||||
if (!stat(path, &st)) {
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
return true;
|
||||
} else {
|
||||
errno = EACCES;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (errno == EACCES || *err != EACCES) *err = errno;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/copyfile.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/syscall_support-nt.internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "libc/calls/blockcancel.internal.h"
|
||||
#include "libc/calls/blocksigs.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/execve-sysv.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
@@ -37,6 +38,11 @@ static bool CanExecute(const char *path) {
|
||||
return !sys_faccessat(AT_FDCWD, path, X_OK, 0);
|
||||
}
|
||||
|
||||
bool IsAPEMagic(char buf[8]) {
|
||||
return READ64LE(buf) == READ64LE("MZqFpD='") ||
|
||||
READ64LE(buf) == READ64LE("JTqFpD='");
|
||||
}
|
||||
|
||||
static bool IsApeBinary(const char *path) {
|
||||
int fd;
|
||||
char buf[8];
|
||||
@@ -44,11 +50,7 @@ static bool IsApeBinary(const char *path) {
|
||||
// TODO(jart): Should we block signals too?
|
||||
BLOCK_CANCELLATIONS;
|
||||
if ((fd = sys_open(path, O_RDONLY, 0)) != -1) {
|
||||
if (sys_read(fd, buf, 8) == 8 && //
|
||||
(READ64LE(buf) == READ64LE("MZqFpD='") ||
|
||||
READ64LE(buf) == READ64LE("JTqFpD='"))) {
|
||||
res = true;
|
||||
}
|
||||
res = sys_read(fd, buf, 8) == 8 && IsAPEMagic(buf);
|
||||
sys_close(fd);
|
||||
}
|
||||
ALLOW_CANCELLATIONS;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_CALLS_EXECVE_SYSV_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_EXECVE_SYSV_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
bool IsAPEMagic(char[8]) _Hide;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_EXECVE_SYSV_H_ */
|
||||
+20
-8
@@ -32,6 +32,7 @@
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/zipos/zipos.internal.h"
|
||||
|
||||
/**
|
||||
* Replaces current process with program.
|
||||
@@ -51,6 +52,7 @@
|
||||
* @vforksafe
|
||||
*/
|
||||
int execve(const char *prog, char *const argv[], char *const envp[]) {
|
||||
struct ZiposUri uri;
|
||||
int rc;
|
||||
size_t i;
|
||||
if (!prog || !argv || !envp ||
|
||||
@@ -61,16 +63,26 @@ int execve(const char *prog, char *const argv[], char *const envp[]) {
|
||||
} else {
|
||||
STRACE("execve(%#s, %s, %s) → ...", prog, DescribeStringList(argv),
|
||||
DescribeStringList(envp));
|
||||
if (!IsWindows()) {
|
||||
rc = 0;
|
||||
if (IsLinux() && __execpromises && _weaken(sys_pledge_linux)) {
|
||||
rc = _weaken(sys_pledge_linux)(__execpromises, __pledge_mode);
|
||||
}
|
||||
if (!rc) {
|
||||
rc = 0;
|
||||
if (IsLinux() && __execpromises && _weaken(sys_pledge_linux)) {
|
||||
rc = _weaken(sys_pledge_linux)(__execpromises, __pledge_mode);
|
||||
}
|
||||
if (!rc) {
|
||||
if (_weaken(__zipos_parseuri) &&
|
||||
(_weaken(__zipos_parseuri)(prog, &uri) != -1)) {
|
||||
rc = _weaken(__zipos_open)(&uri, O_RDONLY | O_CLOEXEC, 0);
|
||||
if (rc != -1) {
|
||||
const int zipFD = rc;
|
||||
strace_enabled(-1);
|
||||
rc = fexecve(zipFD, argv, envp);
|
||||
close(zipFD);
|
||||
strace_enabled(+1);
|
||||
}
|
||||
} else if (!IsWindows()) {
|
||||
rc = sys_execve(prog, argv, envp);
|
||||
} else {
|
||||
rc = sys_execve_nt(prog, argv, envp);
|
||||
}
|
||||
} else {
|
||||
rc = sys_execve_nt(prog, argv, envp);
|
||||
}
|
||||
}
|
||||
STRACE("execve(%#s) failed %d% m", prog, rc);
|
||||
|
||||
+1
-1
@@ -17,8 +17,8 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
|
||||
/**
|
||||
|
||||
+209
-12
@@ -16,21 +16,167 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/blockcancel.internal.h"
|
||||
#include "libc/calls/blocksigs.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/cp.internal.h"
|
||||
#include "libc/calls/execve-sysv.internal.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/stat.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/fd.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/mfd.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/sysv/consts/shm.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
static bool IsAPEFd(const int fd) {
|
||||
char buf[8];
|
||||
bool res;
|
||||
return (sys_pread(fd, buf, 8, 0, 0) == 8) && IsAPEMagic(buf);
|
||||
}
|
||||
|
||||
static int fexecve_impl(const int fd, char *const argv[], char *const envp[]) {
|
||||
int rc;
|
||||
if (IsLinux()) {
|
||||
char path[14 + 12];
|
||||
FormatInt32(stpcpy(path, "/proc/self/fd/"), fd);
|
||||
rc = __sys_execve(path, argv, envp);
|
||||
} else if (IsFreebsd()) {
|
||||
rc = sys_fexecve(fd, argv, envp);
|
||||
} else {
|
||||
rc = enosys();
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
PTF_NUM = 1 << 0,
|
||||
PTF_NUM2 = 1 << 1,
|
||||
PTF_NUM3 = 1 << 2,
|
||||
PTF_ANY = 1 << 3
|
||||
} PTF_PARSE;
|
||||
|
||||
static bool ape_to_elf(void *ape, const size_t apesize) {
|
||||
static const char printftok[] = "printf '";
|
||||
static const size_t printftoklen = sizeof(printftok) - 1;
|
||||
const char *tok = memmem(ape, apesize, printftok, printftoklen);
|
||||
if (tok) {
|
||||
tok += printftoklen;
|
||||
uint8_t *dest = ape;
|
||||
PTF_PARSE state = PTF_ANY;
|
||||
uint8_t value = 0;
|
||||
for (; tok < (const char *)(dest + apesize); tok++) {
|
||||
if ((state & (PTF_NUM | PTF_NUM2 | PTF_NUM3)) &&
|
||||
(*tok >= '0' && *tok <= '7')) {
|
||||
value = (value << 3) | (*tok - '0');
|
||||
state <<= 1;
|
||||
if (state & PTF_ANY) {
|
||||
*dest++ = value;
|
||||
}
|
||||
} else if (state & PTF_NUM) {
|
||||
break;
|
||||
} else {
|
||||
if (state & (PTF_NUM2 | PTF_NUM3)) {
|
||||
*dest++ = value;
|
||||
}
|
||||
if (*tok == '\\') {
|
||||
state = PTF_NUM;
|
||||
value = 0;
|
||||
} else if (*tok == '\'') {
|
||||
return true;
|
||||
} else {
|
||||
*dest++ = *tok;
|
||||
state = PTF_ANY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
errno = ENOEXEC;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a memfd and copies fd to it.
|
||||
*
|
||||
* This does an inplace conversion of APE to ELF when detected!!!!
|
||||
*/
|
||||
static int fd_to_mem_fd(const int infd, char *path) {
|
||||
if (!IsLinux() && !IsFreebsd() || !_weaken(mmap) || !_weaken(munmap)) {
|
||||
return enosys();
|
||||
}
|
||||
|
||||
struct stat st;
|
||||
if (fstat(infd, &st) == -1) {
|
||||
return -1;
|
||||
}
|
||||
int fd;
|
||||
if (IsLinux()) {
|
||||
fd = sys_memfd_create(__func__, MFD_CLOEXEC);
|
||||
} else if (IsFreebsd()) {
|
||||
fd = sys_shm_open(SHM_ANON, O_CREAT | O_RDWR, 0);
|
||||
} else {
|
||||
return enosys();
|
||||
}
|
||||
if (fd == -1) {
|
||||
return -1;
|
||||
}
|
||||
void *space;
|
||||
if ((sys_ftruncate(fd, st.st_size, st.st_size) != -1) &&
|
||||
((space = _weaken(mmap)(0, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||
fd, 0)) != MAP_FAILED)) {
|
||||
ssize_t readRc;
|
||||
readRc = pread(infd, space, st.st_size, 0);
|
||||
bool success = readRc != -1;
|
||||
if (success && (st.st_size > 8) && IsAPEMagic(space)) {
|
||||
int flags = fcntl(fd, F_GETFD);
|
||||
if (success = (flags != -1) &&
|
||||
(fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) &&
|
||||
ape_to_elf(space, st.st_size)) {
|
||||
const int newfd = fcntl(fd, F_DUPFD, 9001);
|
||||
if (newfd != -1) {
|
||||
close(fd);
|
||||
fd = newfd;
|
||||
}
|
||||
}
|
||||
}
|
||||
const int e = errno;
|
||||
if ((_weaken(munmap)(space, st.st_size) != -1) && success) {
|
||||
if (path) {
|
||||
FormatInt32(stpcpy(path, "COSMOPOLITAN_INIT_ZIPOS="), fd);
|
||||
}
|
||||
_unassert(readRc == st.st_size);
|
||||
return fd;
|
||||
} else if (!success) {
|
||||
errno = e;
|
||||
}
|
||||
}
|
||||
const int e = errno;
|
||||
close(fd);
|
||||
errno = e;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes binary executable at file descriptor.
|
||||
*
|
||||
* This is only supported on Linux and FreeBSD. APE binaries currently
|
||||
* aren't supported.
|
||||
* This is only supported on Linux and FreeBSD. APE binaries are
|
||||
* supported. Zipos is supported. Zipos fds or FD_CLOEXEC APE fds or
|
||||
* fds that fail fexecve with ENOEXEC are copied to a new memfd (with
|
||||
* in-memory APE to ELF conversion) and fexecve is (re)attempted.
|
||||
*
|
||||
* @param fd is opened executable and current file position is ignored
|
||||
* @return doesn't return on success, otherwise -1 w/ errno
|
||||
@@ -38,8 +184,7 @@
|
||||
* @raise ENOSYS on Windows, XNU, OpenBSD, NetBSD, and Metal
|
||||
*/
|
||||
int fexecve(int fd, char *const argv[], char *const envp[]) {
|
||||
int rc;
|
||||
size_t i;
|
||||
int rc = 0;
|
||||
if (!argv || !envp ||
|
||||
(IsAsan() &&
|
||||
(!__asan_is_valid_strlist(argv) || !__asan_is_valid_strlist(envp)))) {
|
||||
@@ -47,15 +192,67 @@ int fexecve(int fd, char *const argv[], char *const envp[]) {
|
||||
} else {
|
||||
STRACE("fexecve(%d, %s, %s) → ...", fd, DescribeStringList(argv),
|
||||
DescribeStringList(envp));
|
||||
if (IsLinux()) {
|
||||
char path[14 + 12];
|
||||
FormatInt32(stpcpy(path, "/proc/self/fd/"), fd);
|
||||
rc = __sys_execve(path, argv, envp);
|
||||
} else if (IsFreebsd()) {
|
||||
rc = sys_fexecve(fd, argv, envp);
|
||||
} else {
|
||||
rc = enosys();
|
||||
int savedErr = 0;
|
||||
do {
|
||||
if (!IsLinux() && !IsFreebsd()) {
|
||||
rc = enosys();
|
||||
break;
|
||||
}
|
||||
if (!__isfdkind(fd, kFdZip)) {
|
||||
bool memfdReq;
|
||||
BEGIN_CANCELLATION_POINT;
|
||||
BLOCK_SIGNALS;
|
||||
strace_enabled(-1);
|
||||
memfdReq = ((rc = fcntl(fd, F_GETFD)) != -1) && (rc & FD_CLOEXEC) &&
|
||||
IsAPEFd(fd);
|
||||
strace_enabled(+1);
|
||||
ALLOW_SIGNALS;
|
||||
END_CANCELLATION_POINT;
|
||||
if (rc == -1) {
|
||||
break;
|
||||
} else if (!memfdReq) {
|
||||
fexecve_impl(fd, argv, envp);
|
||||
if (errno != ENOEXEC) {
|
||||
break;
|
||||
}
|
||||
savedErr = ENOEXEC;
|
||||
}
|
||||
}
|
||||
int newfd;
|
||||
char *path = alloca(PATH_MAX);
|
||||
BEGIN_CANCELLATION_POINT;
|
||||
BLOCK_SIGNALS;
|
||||
strace_enabled(-1);
|
||||
newfd = fd_to_mem_fd(fd, path);
|
||||
strace_enabled(+1);
|
||||
ALLOW_SIGNALS;
|
||||
END_CANCELLATION_POINT;
|
||||
if (newfd == -1) {
|
||||
break;
|
||||
}
|
||||
size_t numenvs;
|
||||
for (numenvs = 0; envp[numenvs];) ++numenvs;
|
||||
const size_t desenvs = min(500, max(numenvs + 1, 2));
|
||||
static _Thread_local char *envs[500];
|
||||
memcpy(envs, envp, numenvs * sizeof(char *));
|
||||
envs[numenvs] = path;
|
||||
envs[numenvs + 1] = NULL;
|
||||
fexecve_impl(newfd, argv, envs);
|
||||
if (!savedErr) {
|
||||
savedErr = errno;
|
||||
}
|
||||
BEGIN_CANCELLATION_POINT;
|
||||
BLOCK_SIGNALS;
|
||||
strace_enabled(-1);
|
||||
close(newfd);
|
||||
strace_enabled(+1);
|
||||
ALLOW_SIGNALS;
|
||||
END_CANCELLATION_POINT;
|
||||
} while (0);
|
||||
if (savedErr) {
|
||||
errno = savedErr;
|
||||
}
|
||||
rc = -1;
|
||||
}
|
||||
STRACE("fexecve(%d) failed %d% m", fd, rc);
|
||||
return rc;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ int fsync(int fd) {
|
||||
rc = sys_fdatasync_nt(fd);
|
||||
}
|
||||
END_CANCELLATION_POINT;
|
||||
STRACE("fysnc(%d) → %d% m", fd, rc);
|
||||
STRACE("fsync(%d) → %d% m", fd, rc);
|
||||
} else {
|
||||
rc = fstat(fd, &st);
|
||||
STRACE("fsync_fake(%d) → %d% m", fd, rc);
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_CALLS_GETCONSOLECTRLEVENT_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_GETCONSOLECTRLEVENT_H_
|
||||
#include "libc/nt/enum/ctrlevent.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
static inline int GetConsoleCtrlEvent(int sig) {
|
||||
switch (sig) {
|
||||
case SIGINT:
|
||||
return kNtCtrlCEvent;
|
||||
case SIGQUIT:
|
||||
return kNtCtrlBreakEvent;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_GETCONSOLECTRLEVENT_H_ */
|
||||
@@ -17,10 +17,10 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/enum/computernameformat.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/nt/enum/computernameformat.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/struct/itimerval.h"
|
||||
#include "libc/calls/struct/itimerval.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
||||
/**
|
||||
* Returns process group id.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -17,9 +17,9 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
||||
/**
|
||||
* Gets real, effective, and "saved" group ids.
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
||||
/**
|
||||
* Gets real, effective, and "saved" user ids.
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/struct/rlimit.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/consts/rlimit.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/calls/struct/rusage.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -17,8 +17,8 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
||||
/**
|
||||
* Creates session and sets the process group id.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/ioctl.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/struct/metatermios.internal.h"
|
||||
#include "libc/calls/termios.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/nt/console.h"
|
||||
#include "libc/nt/enum/consolemodeflags.h"
|
||||
#include "libc/nt/enum/version.h"
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/ioctl.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/struct/winsize.h"
|
||||
#include "libc/calls/struct/winsize.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
||||
+1
-1
@@ -18,12 +18,12 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/struct/winsize.h"
|
||||
#include "libc/calls/syscall-nt.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -16,11 +16,11 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/_getauxval.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/_getauxval.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/consts/auxv.h"
|
||||
|
||||
/**
|
||||
|
||||
+19
-4
@@ -17,7 +17,6 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/getconsolectrlevent.internal.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.internal.h"
|
||||
@@ -29,8 +28,20 @@
|
||||
#include "libc/nt/process.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/struct/processentry32.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
static inline int GetConsoleCtrlEvent(int sig) {
|
||||
switch (sig) {
|
||||
case SIGINT:
|
||||
return kNtCtrlCEvent;
|
||||
case SIGQUIT:
|
||||
return kNtCtrlBreakEvent;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
textwindows int sys_kill_nt(int pid, int sig) {
|
||||
bool32 ok;
|
||||
int64_t h;
|
||||
@@ -46,6 +57,7 @@ textwindows int sys_kill_nt(int pid, int sig) {
|
||||
|
||||
// If we're targeting current process group then just call raise().
|
||||
if (!pid || pid == getpid()) {
|
||||
if (!sig) return 0; // ability check passes
|
||||
return raise(sig);
|
||||
}
|
||||
|
||||
@@ -72,6 +84,7 @@ textwindows int sys_kill_nt(int pid, int sig) {
|
||||
|
||||
// is this a cosmo pid that was returned by fork?
|
||||
if (__isfdkind(pid, kFdProcess)) {
|
||||
if (!sig) return 0; // ability check passes
|
||||
// since windows can't execve we need to kill the grandchildren
|
||||
// TODO(jart): should we just kill the whole tree too? there's
|
||||
// no obvious way to tell if it's the execve shell
|
||||
@@ -96,9 +109,11 @@ textwindows int sys_kill_nt(int pid, int sig) {
|
||||
|
||||
// XXX: Is this a raw new technology pid? Because that's messy.
|
||||
if ((h = OpenProcess(kNtProcessTerminate, false, pid))) {
|
||||
ok = TerminateProcess(h, 128 + sig);
|
||||
if (!ok && GetLastError() == kNtErrorAccessDenied) {
|
||||
ok = true; // cargo culting other codebases here
|
||||
if (sig) {
|
||||
ok = TerminateProcess(h, 128 + sig);
|
||||
if (!ok && GetLastError() == kNtErrorAccessDenied) {
|
||||
ok = true; // cargo culting other codebases here
|
||||
}
|
||||
}
|
||||
CloseHandle(h);
|
||||
return 0;
|
||||
|
||||
@@ -26,6 +26,16 @@
|
||||
*/
|
||||
#define LANDLOCK_ACCESS_FS_REFER 0x2000ul
|
||||
|
||||
/**
|
||||
* Control file truncation.
|
||||
*
|
||||
* @see
|
||||
* https://lore.kernel.org/all/[email protected]/
|
||||
* @see https://docs.kernel.org/userspace-api/landlock.html
|
||||
* @note ABI 3+
|
||||
*/
|
||||
#define LANDLOCK_ACCESS_FS_TRUNCATE 0x4000ul
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall-nt.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
||||
/**
|
||||
* Creates anonymous 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__ */
|
||||
@@ -17,8 +17,8 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
||||
/**
|
||||
* Tells you which pages are resident in memory.
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Loaded 100 of 17681 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user