Skip to content

Commit f7ff77d

Browse files
committed
Make fixes and improvements
- Invent iso8601us() for faster timestamps - Improve --strace descriptions of sigset_t - Rebuild the Landlock Make bootstrap binary - Introduce MODE=sysv for non-Windows builds - Permit OFD fcntl() locks under pledge(flock) - redbean can now protect your kernel from ddos - Have vfork() fallback to sys_fork() not fork() - Change kmalloc() to not die when out of memory - Improve documentation for some termios functions - Rewrite putenv() and friends to conform to POSIX - Fix linenoise + strace verbosity issue on Windows - Fix regressions in our ability to show backtraces - Change redbean SetHeader() to no-op if value is nil - Improve fcntl() so SQLite locks work in non-WAL mode - Remove some unnecessary work during fork() on Windows - Create redbean-based SSL reverse proxy for IPv4 TurfWar - Fix ape/apeinstall.sh warning when using non-bash shells - Add ProgramTrustedIp(), and IsTrustedIp() APIs to redbean - Support $PWD, $UID, $GID, and $EUID in command interpreter - Introduce experimental JTqFpD APE prefix for non-Windows builds - Invent blackhole daemon for firewalling IP addresses via UNIX named socket - Add ProgramTokenBucket(), AcquireToken(), and CountTokens() APIs to redbean
1 parent 648bf65 commit f7ff77d

File tree

209 files changed

+3810
-990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+3810
-990
lines changed

ape/ape.S

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,15 @@ cstr: .endobj cstr,globl,hidden # ←for gdb readability
112112
//
113113
// @param dl is drive number
114114
// @noreturn
115-
ape_mz: .asciz "MZqFpD='\n" # Mark 'Zibo' Joseph Zbikowski
115+
ape_mz:
116+
#if SupportsWindows() || SupportsMetal()
117+
.asciz "MZqFpD='\n" # Mark 'Zibo' Joseph Zbikowski
118+
#else
119+
// Avoid virus scanner reputation damage when targeting System Five.
120+
// WARNING: This prefix is experimental; it may be removed sometime.
121+
// TODO(jart): Find another prefix that will work with BIOS loading.
122+
.asciz "JTqFpD='\n" # Mark 'Zibo' Joseph Zbikowski
123+
#endif
116124
.short 0x1000 # MZ: lowers upper bound load / 16
117125
.short 0xf800 # MZ: roll greed on bss
118126
.short 0 # MZ: lower bound on stack segment

ape/apeinstall.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
if [ $UID -eq 0 ]; then
3+
if [ "$(id -u)" -eq 0 ]; then
44
SUDO=
55
else
66
SUDO=sudo
@@ -97,6 +97,8 @@ if [ x"$(uname -s)" = xLinux ]; then
9797
echo you may need to edit configs to persist across reboot >&2
9898
echo '$SUDO sh -c "echo '"'"':APE:M::MZqFpD::/usr/bin/ape:'"'"' >/proc/sys/fs/binfmt_misc/register"' >&2
9999
$SUDO sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" || exit
100+
echo '$SUDO sh -c "echo '"'"':APE-sysv:M::JTqFpD::/usr/bin/ape:'"'"' >/proc/sys/fs/binfmt_misc/register"' >&2
101+
$SUDO sh -c "echo ':APE-sysv:M::JTqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" || exit
100102
echo done >&2
101103

102104
if [ x"$(cat /proc/sys/fs/binfmt_misc/status)" = xdisabled ]; then

ape/apeuninstall.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fi
1111
echo "APE Uninstaller intends to run"
1212
echo
1313
echo " $SUDO sh -c 'echo -1 >/proc/sys/fs/binfmt_misc/APE'"
14+
echo " $SUDO sh -c 'echo -1 >/proc/sys/fs/binfmt_misc/APE-sysv'"
1415
echo " $SUDO rm -f /usr/bin/ape ~/.ape o/tmp/.ape /tmp/.ape"
1516
echo
1617
echo "You may then use ape/apeinstall.sh to reinstall it"
@@ -21,4 +22,7 @@ set -ex
2122
if [ -f /proc/sys/fs/binfmt_misc/APE ]; then
2223
$SUDO sh -c 'echo -1 >/proc/sys/fs/binfmt_misc/APE' || exit
2324
fi
25+
if [ -f /proc/sys/fs/binfmt_misc/APE-sysv ]; then
26+
$SUDO sh -c 'echo -1 >/proc/sys/fs/binfmt_misc/APE-sysv' || exit
27+
fi
2428
$SUDO rm -f /usr/bin/ape ~/.ape o/tmp/.ape o/tmp/ape /tmp/.ape /tmp/ape || exit

build/bootstrap/make.com

4.49 KB
Binary file not shown.

build/config.mk

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ endif
2929
#
3030
ifeq ($(MODE),fastbuild)
3131
CONFIG_CCFLAGS += $(BACKTRACES) $(FTRACE) -O
32-
CONFIG_CPPFLAGS += -DSYSDEBUG
32+
CONFIG_CPPFLAGS += -DSYSDEBUG -DDWARFLESS
3333
CONFIG_OFLAGS += -g0
3434
CONFIG_LDFLAGS += -S
3535
TARGET_ARCH ?= -msse3
@@ -125,6 +125,22 @@ TARGET_ARCH ?= -msse3
125125
OVERRIDE_CCFLAGS += -fno-pie
126126
endif
127127

128+
# System Five Mode
129+
#
130+
# - `make MODE=sysv`
131+
# - Optimized
132+
# - Backtraces
133+
# - Debuggable
134+
# - Syscall tracing
135+
# - Function tracing
136+
# - No Windows bloat!
137+
#
138+
ifeq ($(MODE), sysv)
139+
CONFIG_CCFLAGS += $(BACKTRACES) $(FTRACE) -O2
140+
CONFIG_CPPFLAGS += -DSYSDEBUG -DSUPPORT_VECTOR=121
141+
TARGET_ARCH ?= -msse3
142+
endif
143+
128144
# Tiny Mode
129145
#
130146
# - `make MODE=tiny`
@@ -151,7 +167,8 @@ CONFIG_CCFLAGS += \
151167
-fschedule-insns2 \
152168
-fomit-frame-pointer \
153169
-momit-leaf-frame-pointer \
154-
-foptimize-sibling-calls
170+
-foptimize-sibling-calls \
171+
-DDWARFLESS
155172
CONFIG_OFLAGS += \
156173
-g0
157174
CONFIG_LDFLAGS += \
@@ -181,7 +198,8 @@ CONFIG_CPPFLAGS += \
181198
-DTINY \
182199
-DNDEBUG \
183200
-DTRUSTWORTHY \
184-
-DSUPPORT_VECTOR=1
201+
-DSUPPORT_VECTOR=1 \
202+
-DDWARFLESS
185203
DEFAULT_COPTS += \
186204
-mred-zone
187205
CONFIG_OFLAGS += \
@@ -217,7 +235,8 @@ CONFIG_CPPFLAGS += \
217235
-DTINY \
218236
-DNDEBUG \
219237
-DTRUSTWORTHY \
220-
-DSUPPORT_VECTOR=113
238+
-DSUPPORT_VECTOR=113 \
239+
-DDWARFLESS
221240
DEFAULT_COPTS += \
222241
-mred-zone
223242
CONFIG_OFLAGS += \
@@ -252,7 +271,8 @@ CONFIG_CPPFLAGS += \
252271
-DTINY \
253272
-DNDEBUG \
254273
-DTRUSTWORTHY \
255-
-DSUPPORT_VECTOR=121
274+
-DSUPPORT_VECTOR=121 \
275+
-DDWARFLESS
256276
DEFAULT_COPTS += \
257277
-mred-zone
258278
CONFIG_CCFLAGS += \
@@ -287,7 +307,8 @@ CONFIG_CPPFLAGS += \
287307
-DTINY \
288308
-DNDEBUG \
289309
-DTRUSTWORTHY \
290-
-DSUPPORT_VECTOR=251
310+
-DSUPPORT_VECTOR=251 \
311+
-DDWARFLESS
291312
CONFIG_CCFLAGS += \
292313
-Os \
293314
-fno-align-functions \

examples/auto-memory-safety-crash2.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
88
╚─────────────────────────────────────────────────────────────────*/
99
#endif
10-
#include "libc/intrin/bits.h"
1110
#include "libc/dce.h"
11+
#include "libc/intrin/bits.h"
12+
#include "libc/intrin/kprintf.h"
1213
#include "libc/log/log.h"
1314
#include "libc/mem/mem.h"
1415
#include "libc/runtime/runtime.h"
15-
#include "libc/stdio/stdio.h"
1616
#include "libc/str/str.h"
1717

1818
/**
@@ -59,9 +59,15 @@
5959

6060
int main(int argc, char *argv[]) {
6161
if (!IsAsan()) {
62-
printf("this example is intended for MODE=asan or MODE=dbg\n");
62+
kprintf("this example is intended for MODE=asan or MODE=dbg\n");
6363
exit(1);
6464
}
65+
66+
kprintf("----------------\n");
67+
kprintf(" THIS IS A TEST \n");
68+
kprintf("SIMULATING CRASH\n");
69+
kprintf("----------------\n");
70+
6571
char *buffer;
6672
ShowCrashReports(); /* not needed but yoinks appropriate symbols */
6773
buffer = malloc(13);

examples/crashreport.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
88
╚─────────────────────────────────────────────────────────────────*/
99
#endif
10+
#include "libc/intrin/kprintf.h"
1011
#include "libc/log/log.h"
1112
#include "libc/runtime/symbols.internal.h"
1213

@@ -24,6 +25,12 @@
2425
*/
2526

2627
noubsan int main(int argc, char *argv[]) {
28+
29+
kprintf("----------------\n");
30+
kprintf(" THIS IS A TEST \n");
31+
kprintf("SIMULATING CRASH\n");
32+
kprintf("----------------\n");
33+
2734
volatile int64_t x;
2835
ShowCrashReports();
2936
return 1 / (x = 0);

examples/examples.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,25 @@ o/$(MODE)/examples/nesemu1.com.dbg: \
146146
$(EXAMPLES_BOOTLOADER)
147147
@$(APELINK)
148148

149+
# # force symtab.com to be a zip file, by pulling a zip asset into linkage
150+
# # we wouldn't need to do this if we depended on functions like localtime
151+
# o/$(MODE)/examples/symtab.com.dbg: \
152+
# $(EXAMPLES_DEPS) \
153+
# o/$(MODE)/examples/symtab.o \
154+
# o/$(MODE)/examples/symtab.c.zip.o \
155+
# o/$(MODE)/examples/examples.pkg \
156+
# $(EXAMPLES_BOOTLOADER)
157+
# @$(APELINK)
158+
159+
# modify .com so it can read the symbol table without needing the .com.dbg file
160+
o/$(MODE)/examples/symtab.com: \
161+
o/$(MODE)/examples/symtab.com.dbg \
162+
o/$(MODE)/third_party/zip/zip.com \
163+
o/$(MODE)/tool/build/symtab.com
164+
@$(MAKE_OBJCOPY)
165+
@$(MAKE_SYMTAB_CREATE)
166+
@$(MAKE_SYMTAB_ZIP)
167+
149168
o/$(MODE)/examples/picol.o: private \
150169
OVERRIDE_CPPFLAGS += \
151170
-DSTACK_FRAME_UNLIMITED

examples/nesemu1.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#include "third_party/libcxx/vector"
4848
#include "tool/viz/lib/knobs.h"
4949

50-
STATIC_YOINK("zip_uri_support");
50+
STATIC_YOINK("zipos");
5151

5252
#define USAGE \
5353
" [ROM] [FMV]\n\

examples/symtab.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#if 0
2+
/*─────────────────────────────────────────────────────────────────╗
3+
│ To the extent possible under law, Justine Tunney has waived │
4+
│ all copyright and related or neighboring rights to this file, │
5+
│ as it is written in the following disclaimers: │
6+
│ • http://unlicense.org/ │
7+
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
8+
╚─────────────────────────────────────────────────────────────────*/
9+
#endif
10+
#include "libc/intrin/kprintf.h"
11+
#include "libc/log/log.h"
12+
13+
/**
14+
* @fileoverview example of how to embed symbol table in .com file
15+
*
16+
* # build our binary
17+
* make -j16 o//examples/symtab.com
18+
*
19+
* # move binary somewhere else
20+
* # so it can't find the .com.dbg binary
21+
* cp o//examples/symtab.com /tmp
22+
*
23+
* # run program
24+
* # notice that it has a symbolic backtrace
25+
* /tmp/symtab.com
26+
*
27+
* @see examples/examples.mk
28+
*/
29+
30+
int main(int argc, char *argv[]) {
31+
32+
// this links all the debugging and zip functionality
33+
ShowCrashReports();
34+
35+
kprintf("----------------\n");
36+
kprintf(" THIS IS A TEST \n");
37+
kprintf("SIMULATING CRASH\n");
38+
kprintf("----------------\n");
39+
40+
volatile int64_t x;
41+
return 1 / (x = 0);
42+
}

0 commit comments

Comments
 (0)