mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 10:18:31 +00:00
Add SSL to redbean
Your redbean can now interoperate with clients that require TLS crypto. This is accomplished using a protocol polyglot that lets us distinguish between HTTP and HTTPS regardless of the port number. Certificates will be generated automatically, if none are supplied by the user. Footprint increases by only a few hundred kb so redbean in MODY=tiny is now 1.0mb - Add lseek() polyfills for ZIP executable - Automatically polyfill /tmp/FOO paths on NT - Fix readdir() / ftw() / nftw() bugs on Windows - Introduce -B flag for slower SSL that's stronger - Remove mbedtls features Cosmopolitan doesn't need - Have base64 decoder support the uri-safe alternative - Remove Truncated HMAC because it's forbidden by the IETF - Add all the mbedtls test suites and make them go 3x faster - Support opendir() / readdir() / closedir() on ZIP executable - Use Everest for ECDHE-ECDSA because it's so good it's so good - Add tinier implementation of sha1 since it's not worth the rom - Add chi-square monte-carlo mean correlation tests for getrandom() - Source entropy on Windows from the proper interface everyone uses We're continuing to outperform NGINX and other servers on raw message throughput. Using SSL means that instead of 1,000,000 qps you can get around 300,000 qps. However redbean isn't as fast as NGINX yet at SSL handshakes, since redbean can do 2,627 per second and NGINX does 4.3k Right now, the SSL UX story works best if you give your redbean a key signing key since that can be easily generated by openssl using a one liner then redbean will do all the things that are impossibly hard to do like signing ecdsa and rsa certificates that'll work in chrome. We should integrate the let's encrypt acme protocol in the future. Live Demo: https://redbean.justine.lol/ Root Cert: https://redbean.justine.lol/redbean1.crt
This commit is contained in:
parent
1beeb7a829
commit
cc1920749e
1032 changed files with 152673 additions and 69310 deletions
|
@ -98,5 +98,4 @@ M(1, f, "fpclassify", Fpclassify, fpclassify(x),
|
|||
"nan=0,inf=1,zero=2,subnorm=3,normal=4")
|
||||
|
||||
M(0, i, "rand", Rand, rand(), "deterministic random number")
|
||||
M(0, i, "rand32", Rand32, rand32(), "32-bit random number")
|
||||
M(0, i, "rand64", Rand64, rand64(), "64-bit random number")
|
||||
|
|
|
@ -62,16 +62,27 @@ void AppendWide(struct Buffer *b, wint_t wc) {
|
|||
}
|
||||
|
||||
int AppendFmt(struct Buffer *b, const char *fmt, ...) {
|
||||
int bytes;
|
||||
char *tmp;
|
||||
va_list va;
|
||||
tmp = NULL;
|
||||
int n;
|
||||
char *p;
|
||||
va_list va, vb;
|
||||
va_start(va, fmt);
|
||||
bytes = vasprintf(&tmp, fmt, va);
|
||||
va_copy(vb, va);
|
||||
n = vsnprintf(b->p + b->i, b->n - b->i, fmt, va);
|
||||
if (n >= b->n - b->i) {
|
||||
do {
|
||||
if (b->n) {
|
||||
b->n += b->n >> 1; /* the proper way to grow w/ amortization */
|
||||
} else {
|
||||
b->n = 16;
|
||||
}
|
||||
} while (b->i + n > b->n);
|
||||
b->p = realloc(b->p, b->n);
|
||||
vsnprintf(b->p + b->i, b->n - b->i, fmt, vb);
|
||||
}
|
||||
va_end(vb);
|
||||
va_end(va);
|
||||
if (bytes != -1) AppendData(b, tmp, bytes);
|
||||
free(tmp);
|
||||
return bytes;
|
||||
b->i += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,6 +96,8 @@
|
|||
* - 1 byte exit status
|
||||
*/
|
||||
|
||||
#define DEATH_CLOCK_SECONDS 5
|
||||
|
||||
#define kLogFile "o/runitd.log"
|
||||
#define kLogMaxBytes (2 * 1000 * 1000)
|
||||
|
||||
|
@ -321,7 +323,7 @@ void HandleClient(void) {
|
|||
|
||||
/* run program, tee'ing stderr to both log and client */
|
||||
DEBUGF("spawning %s", exename);
|
||||
SetDeadline(1, 0);
|
||||
SetDeadline(DEATH_CLOCK_SECONDS, 0);
|
||||
ignore.sa_flags = 0;
|
||||
ignore.sa_handler = SIG_IGN;
|
||||
LOGIFNEG1(sigemptyset(&ignore.sa_mask));
|
||||
|
@ -342,24 +344,29 @@ void HandleClient(void) {
|
|||
}
|
||||
LOGIFNEG1(close(pipefds[1]));
|
||||
DEBUGF("communicating %s[%d]", exename, child);
|
||||
for (;;) {
|
||||
CHECK_NE(-1, (got = read(pipefds[0], g_buf, sizeof(g_buf))));
|
||||
if (!got) {
|
||||
close(pipefds[0]);
|
||||
break;
|
||||
}
|
||||
fwrite(g_buf, got, 1, stderr);
|
||||
SendOutputFragmentMessage(g_clifd, kRunitStderr, g_buf, got);
|
||||
}
|
||||
while (waitpid(child, &wstatus, 0) == -1) {
|
||||
if (errno == EINTR) {
|
||||
if (g_alarmed) {
|
||||
WARNF("killing %s which timed out");
|
||||
LOGIFNEG1(kill(child, SIGKILL));
|
||||
while (!g_alarmed) {
|
||||
if ((got = read(pipefds[0], g_buf, sizeof(g_buf))) != -1) {
|
||||
if (!got) {
|
||||
close(pipefds[0]);
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
fwrite(g_buf, got, 1, stderr);
|
||||
SendOutputFragmentMessage(g_clifd, kRunitStderr, g_buf, got);
|
||||
} else {
|
||||
CHECK_EQ(EINTR, errno);
|
||||
}
|
||||
}
|
||||
for (;;) {
|
||||
if (g_alarmed) {
|
||||
WARNF("killing %s which timed out");
|
||||
LOGIFNEG1(kill(child, SIGKILL));
|
||||
g_alarmed = false;
|
||||
}
|
||||
if (waitpid(child, &wstatus, 0) != -1) {
|
||||
break;
|
||||
} else {
|
||||
CHECK_EQ(EINTR, errno);
|
||||
}
|
||||
FATALF("waitpid failed");
|
||||
}
|
||||
if (WIFEXITED(wstatus)) {
|
||||
DEBUGF("%s exited with %d", exename, WEXITSTATUS(wstatus));
|
||||
|
|
|
@ -108,7 +108,6 @@ Keywords={
|
|||
"optimizespeed",
|
||||
"alignof",
|
||||
"relegated",
|
||||
"antiquity",
|
||||
"memcpyesque",
|
||||
"libcesque",
|
||||
"artificial",
|
||||
|
|
|
@ -1279,7 +1279,8 @@
|
|||
"COSMOPOLITAN_C_START_"
|
||||
"COSMOPOLITAN_C_END_"
|
||||
"MACHINE_CODE_ANALYSIS_BEGIN_"
|
||||
"MACHINE_CODE_ANALYSIS_END_"))
|
||||
"MACHINE_CODE_ANALYSIS_END_"
|
||||
"__VSCODE_INTELLISENSE__"))
|
||||
|
||||
(cosmopolitan-builtin-functions
|
||||
'("DebugBreak"
|
||||
|
|
|
@ -165,6 +165,8 @@
|
|||
(cosmo
|
||||
'("int_least128_t"
|
||||
"int_fast128_t"
|
||||
"mbedtls_mpi_sint"
|
||||
"mbedtls_mpi_uint"
|
||||
"bool32"
|
||||
"int128_t"
|
||||
"uint128_t"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
"__GNUC_PATCHLEVEL__"
|
||||
"__GNUC__"
|
||||
"__APPLE__"
|
||||
"__MACH__"
|
||||
"__GNUG__"
|
||||
"__INCLUDE_LEVEL__"
|
||||
"__INTMAX_MAX__"
|
||||
|
|
|
@ -204,6 +204,24 @@
|
|||
,(concat "make -j8 -O $f MODE=$m V=1")
|
||||
"./$f"))
|
||||
mode name))
|
||||
((eq kind 'run-win7)
|
||||
(format
|
||||
(cosmo-join
|
||||
" && "
|
||||
`("m=%s; f=o/$m/%s.com"
|
||||
,(concat "make -j8 -O $f MODE=$m V=1")
|
||||
"scp $f $f.dbg win7:"
|
||||
"ssh win7 ./%s.com"))
|
||||
mode name (file-name-nondirectory name)))
|
||||
((eq kind 'run-win10)
|
||||
(format
|
||||
(cosmo-join
|
||||
" && "
|
||||
`("m=%s; f=o/$m/%s.com"
|
||||
,(concat "make -j8 -O $f MODE=$m V=1")
|
||||
"scp $f $f.dbg win10:"
|
||||
"ssh win10 ./%s.com"))
|
||||
mode name (file-name-nondirectory name)))
|
||||
((and (file-regular-p this)
|
||||
(file-executable-p this))
|
||||
(format "./%s" file))
|
||||
|
@ -580,12 +598,46 @@
|
|||
('t
|
||||
(error "cosmo-run: unknown major mode")))))))
|
||||
|
||||
(defun cosmo-run-win7 (arg)
|
||||
(interactive "P")
|
||||
(let* ((this (or (buffer-file-name) dired-directory))
|
||||
(proj (locate-dominating-file this "Makefile"))
|
||||
(root (or proj default-directory))
|
||||
(file (file-relative-name this root)))
|
||||
(when root
|
||||
(let ((default-directory root))
|
||||
(save-buffer)
|
||||
(cond ((memq major-mode '(c-mode c++-mode asm-mode fortran-mode))
|
||||
(let* ((mode (cosmo--make-mode arg))
|
||||
(compile-command (cosmo--compile-command this root 'run-win7 mode "" "")))
|
||||
(compile compile-command)))
|
||||
('t
|
||||
(error "cosmo-run: unknown major mode")))))))
|
||||
|
||||
(defun cosmo-run-win10 (arg)
|
||||
(interactive "P")
|
||||
(let* ((this (or (buffer-file-name) dired-directory))
|
||||
(proj (locate-dominating-file this "Makefile"))
|
||||
(root (or proj default-directory))
|
||||
(file (file-relative-name this root)))
|
||||
(when root
|
||||
(let ((default-directory root))
|
||||
(save-buffer)
|
||||
(cond ((memq major-mode '(c-mode c++-mode asm-mode fortran-mode))
|
||||
(let* ((mode (cosmo--make-mode arg))
|
||||
(compile-command (cosmo--compile-command this root 'run-win10 mode "" "")))
|
||||
(compile compile-command)))
|
||||
('t
|
||||
(error "cosmo-run: unknown major mode")))))))
|
||||
|
||||
(progn
|
||||
(define-key asm-mode-map (kbd "C-c C-r") 'cosmo-run)
|
||||
(define-key c-mode-base-map (kbd "C-c C-r") 'cosmo-run)
|
||||
(define-key fortran-mode-map (kbd "C-c C-r") 'cosmo-run)
|
||||
(define-key sh-mode-map (kbd "C-c C-r") 'cosmo-run)
|
||||
(define-key python-mode-map (kbd "C-c C-r") 'cosmo-run))
|
||||
(define-key python-mode-map (kbd "C-c C-r") 'cosmo-run)
|
||||
(define-key c-mode-map (kbd "C-c C-s") 'cosmo-run-win7)
|
||||
(define-key c-mode-map (kbd "C-c C-_") 'cosmo-run-win10))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
|
@ -88,7 +88,6 @@
|
|||
"ceil"
|
||||
"floor"
|
||||
"rand"
|
||||
"rand32"
|
||||
"rand64"))
|
||||
|
||||
(defun ctest--make-regex (words)
|
||||
|
|
|
@ -6,28 +6,50 @@ DESCRIPTION
|
|||
|
||||
redbean - single-file distributable web server
|
||||
|
||||
OVERVIEW
|
||||
|
||||
redbean makes it possible to share web applications that run offline
|
||||
as a single-file Actually Portable Executable PKZIP archive which
|
||||
contains your assets. All you need to do is download the redbean.com
|
||||
program below, change the filename to .zip, add your content in a zip
|
||||
editing tool, and then change the extension back to .com.
|
||||
|
||||
redbean can serve 1 million+ gzip encoded responses per second on a
|
||||
cheap personal computer. That performance is thanks to zip and gzip
|
||||
using the same compression format, which enables kernelspace copies.
|
||||
Another reason redbean goes fast is that it's a tiny static binary,
|
||||
which makes fork memory paging nearly free.
|
||||
|
||||
redbean is also easy to modify to suit your own needs. The program
|
||||
itself is written as a single .c file. It embeds the Lua programming
|
||||
language and SQLite which let you write dynamic pages.
|
||||
|
||||
FLAGS
|
||||
|
||||
-h help
|
||||
-s increase silence [repeat]
|
||||
-v increase verbosity [repeat]
|
||||
-d daemonize
|
||||
-u uniprocess
|
||||
-z print port
|
||||
-m log messages
|
||||
-b log message body
|
||||
-b log message bodies
|
||||
-a log resource usage
|
||||
-g log handler latency
|
||||
-f log worker function calls
|
||||
-H K:V sets http header globally [repeat]
|
||||
-D DIR serve assets from local directory [repeat]
|
||||
-t MS tunes read and write timeouts [default 30000]
|
||||
-M INT tunes max message payload size [default 65536]
|
||||
-c SEC configures static asset cache-control headers
|
||||
-r /X=/Y redirect X to Y [repeat]
|
||||
-R /X=/Y rewrites X to Y [repeat]
|
||||
-l ADDR listen ip [default 0.0.0.0]
|
||||
-p PORT listen port [default 8080]
|
||||
-B use stronger cryptography
|
||||
-s increase silence [repeatable]
|
||||
-v increase verbosity [repeatable]
|
||||
-V increase ssl verbosity [repeatable]
|
||||
-H K:V sets http header globally [repeatable]
|
||||
-D DIR overlay assets in local directory [repeatable]
|
||||
-r /X=/Y redirect X to Y [repeatable]
|
||||
-R /X=/Y rewrites X to Y [repeatable]
|
||||
-K PATH tls private key path [repeatable]
|
||||
-C PATH tls certificate(s) path [repeatable]
|
||||
-t MS tunes read and write timeouts [def. 60000]
|
||||
-M INT tunes max message payload size [def. 65536]
|
||||
-p PORT listen port [def. 8080; repeatable]
|
||||
-l ADDR listen addr [def. 0.0.0.0; repeatable]
|
||||
-c SEC configures static cache-control
|
||||
-L PATH log file location
|
||||
-P PATH pid file location
|
||||
-U INT daemon set user id
|
||||
|
@ -36,14 +58,13 @@ FLAGS
|
|||
FEATURES
|
||||
|
||||
- Lua v5.4
|
||||
- HTTP v0.9
|
||||
- HTTP v1.0
|
||||
- HTTP v1.1
|
||||
- Pipelining
|
||||
- Accounting
|
||||
- Content-Encoding
|
||||
- Range / Content-Range
|
||||
- Last-Modified / If-Modified-Since
|
||||
- SQLite 3.35.5
|
||||
- TLS v1.2 / v1.1 / v1.0
|
||||
- HTTP v1.1 / v1.0 / v0.9
|
||||
- Chromium-Zlib Compression
|
||||
- Statusz Monitoring Statistics
|
||||
- Self-Modifying PKZIP Object Store
|
||||
- Linux + Windows + Mac + FreeBSD + OpenBSD + NetBSD
|
||||
|
||||
USAGE
|
||||
|
||||
|
@ -122,7 +143,7 @@ USAGE
|
|||
|
||||
You can have redbean run as a daemon by doing the following:
|
||||
|
||||
redbean.com -vv -d -L redbean.log -P redbean.pid
|
||||
sudo ./redbean.com -vvdp80 -p443 -L redbean.log -P redbean.pid
|
||||
kill -TERM $(cat redbean.pid) # 1x: graceful shutdown
|
||||
kill -TERM $(cat redbean.pid) # 2x: forceful shutdown
|
||||
|
||||
|
@ -152,6 +173,32 @@ USAGE
|
|||
inside the binary. redbean also respects your privacy and won't
|
||||
phone home because your computer is its home.
|
||||
|
||||
SECURITY
|
||||
|
||||
redbean uses a protocol polyglot for serving HTTP and HTTPS on
|
||||
the same port numbers. For example, both of these are valid:
|
||||
|
||||
http://127.0.0.1:8080/
|
||||
https://127.0.0.1:8080/
|
||||
|
||||
The easiest way to use a self-signed certificate is to provide
|
||||
redbean with a key-signing key:
|
||||
|
||||
openssl req -x509 -newkey rsa:2048 \
|
||||
-keyout .ca.key -out .ca.crt -days 6570 -nodes \
|
||||
-subj '/C=US/ST=CA/O=Jane Doe/CN=My Root CA 1' \
|
||||
-addext 'keyUsage = critical,cRLSign,keyCertSign'
|
||||
sudo ./redbean.com -C ca.crt -K .ca.key -p 80 -p 443
|
||||
|
||||
SSL verbosity is controlled as follows for troubleshooting:
|
||||
|
||||
-V log ssl errors
|
||||
-VV log ssl state changes too
|
||||
-VVV log ssl informational messages too
|
||||
-VVVV log ssl verbose details too
|
||||
|
||||
That's in addition to existing flags like -vvvm.
|
||||
|
||||
SEE ALSO
|
||||
|
||||
https://justine.lol/redbean/index.html
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
-- special script called by main redbean process at startup
|
||||
HidePath('/usr/share/zoneinfo/')
|
||||
HidePath('/usr/share/ssl/')
|
||||
|
|
|
@ -27,6 +27,7 @@ C(forbiddens)
|
|||
C(forkerrors)
|
||||
C(frags)
|
||||
C(fumbles)
|
||||
C(handshakeinterrupts)
|
||||
C(http09)
|
||||
C(http10)
|
||||
C(http11)
|
||||
|
@ -65,6 +66,7 @@ C(openfails)
|
|||
C(partialresponses)
|
||||
C(payloaddisconnects)
|
||||
C(pipelinedrequests)
|
||||
C(pollinterrupts)
|
||||
C(precompressedresponses)
|
||||
C(readerrors)
|
||||
C(readinterrupts)
|
||||
|
@ -78,6 +80,15 @@ C(serveroptions)
|
|||
C(shutdowns)
|
||||
C(slowloris)
|
||||
C(slurps)
|
||||
C(sslcantciphers)
|
||||
C(sslhandshakefails)
|
||||
C(sslhandshakes)
|
||||
C(sslnociphers)
|
||||
C(sslshakemacs)
|
||||
C(ssltimeouts)
|
||||
C(sslunknownca)
|
||||
C(sslunknowncert)
|
||||
C(sslupgrades)
|
||||
C(statfails)
|
||||
C(staticrequests)
|
||||
C(stats)
|
||||
|
|
|
@ -3,6 +3,7 @@ sqlite3 = require "lsqlite3"
|
|||
|
||||
-- /.init.lua is loaded at startup in redbean's main process
|
||||
HidePath('/usr/share/zoneinfo/')
|
||||
HidePath('/usr/share/ssl/')
|
||||
|
||||
-- open a browser tab using explorer/open/xdg-open
|
||||
-- LaunchBrowser('/tool/net/demo/index.html')
|
||||
|
|
112
tool/net/net.mk
112
tool/net/net.mk
|
@ -10,13 +10,18 @@ TOOL_NET_HDRS = $(filter %.h,$(TOOL_NET_FILES))
|
|||
TOOL_NET_OBJS = \
|
||||
$(TOOL_NET_SRCS:%.c=o/$(MODE)/%.o)
|
||||
|
||||
TOOL_NET_COMS = \
|
||||
$(TOOL_NET_SRCS:%.c=o/$(MODE)/%.com)
|
||||
|
||||
TOOL_NET_BINS = \
|
||||
$(TOOL_NET_COMS) \
|
||||
$(TOOL_NET_COMS:%=%.dbg)
|
||||
|
||||
TOOL_NET_COMS = \
|
||||
o/$(MODE)/tool/net/redbean.com \
|
||||
o/$(MODE)/tool/net/redbean-demo.com \
|
||||
o/$(MODE)/tool/net/redbean-static.com \
|
||||
o/$(MODE)/tool/net/redbean-unsecure.com \
|
||||
o/$(MODE)/tool/net/redbean-original.com \
|
||||
o/$(MODE)/tool/net/echoserver.com
|
||||
|
||||
TOOL_NET_DIRECTDEPS = \
|
||||
LIBC_ALG \
|
||||
LIBC_BITS \
|
||||
|
@ -27,6 +32,8 @@ TOOL_NET_DIRECTDEPS = \
|
|||
LIBC_LOG \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_NT_IPHLPAPI \
|
||||
LIBC_NT_KERNEL32 \
|
||||
LIBC_RAND \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_SOCK \
|
||||
|
@ -39,11 +46,14 @@ TOOL_NET_DIRECTDEPS = \
|
|||
LIBC_TINYMATH \
|
||||
LIBC_UNICODE \
|
||||
LIBC_X \
|
||||
LIBC_ZIPOS \
|
||||
NET_HTTP \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
THIRD_PARTY_LUA \
|
||||
THIRD_PARTY_SQLITE3 \
|
||||
THIRD_PARTY_MBEDTLS \
|
||||
THIRD_PARTY_REGEX \
|
||||
THIRD_PARTY_SQLITE3 \
|
||||
THIRD_PARTY_ZLIB \
|
||||
TOOL_DECODE_LIB
|
||||
|
||||
|
@ -62,6 +72,10 @@ o/$(MODE)/tool/net/%.com.dbg: \
|
|||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
# REDBEAN.COM
|
||||
#
|
||||
# The little web server that could!
|
||||
|
||||
o/$(MODE)/tool/net/redbean.com.dbg: \
|
||||
$(TOOL_NET_DEPS) \
|
||||
o/$(MODE)/tool/net/redbean.o \
|
||||
|
@ -82,12 +96,19 @@ o/$(MODE)/tool/net/redbean.com: \
|
|||
@$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.ape bs=64 count=11 conv=notrunc 2>/dev/null
|
||||
@$(COMPILE) -AZIP -T$@ zip -qj $@ o/$(MODE)/tool/net/.ape tool/net/.help.txt tool/net/.init.lua tool/net/favicon.ico tool/net/redbean.png
|
||||
|
||||
# REDBEAN-DEMO.COM
|
||||
#
|
||||
# This redbean-demo.com program is the same as redbean.com except it
|
||||
# bundles a bunch of example code and there's a live of it available
|
||||
# online at http://redbean.justine.lol/
|
||||
|
||||
o/$(MODE)/tool/net/redbean-demo.com.dbg: \
|
||||
o/$(MODE)/tool/net/redbean.com.dbg
|
||||
@$(COMPILE) -ACP -T$@ cp $< $@
|
||||
|
||||
o/$(MODE)/tool/net/redbean-demo.com: \
|
||||
o/$(MODE)/tool/net/redbean-demo.com.dbg \
|
||||
o/$(MODE)/host/third_party/infozip/zip.com \
|
||||
tool/net/net.mk \
|
||||
tool/net/favicon.ico \
|
||||
tool/net/redbean.png \
|
||||
|
@ -114,22 +135,27 @@ o/$(MODE)/tool/net/redbean-demo.com: \
|
|||
@$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@
|
||||
@$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/.redbean-demo
|
||||
@$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.redbean-demo/.ape bs=64 count=11 conv=notrunc 2>/dev/null
|
||||
@$(COMPILE) -AZIP -T$@ zip -qj $@ o/$(MODE)/tool/net/.redbean-demo/.ape tool/net/.help.txt tool/net/demo/.init.lua tool/net/demo/.reload.lua
|
||||
@$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-demo/.ape tool/net/.help.txt tool/net/demo/.init.lua tool/net/demo/.reload.lua
|
||||
@$(COMPILE) -ARM -T$@ rm -rf o/$(MODE)/tool/net/.lua
|
||||
@$(COMPILE) -ACP -T$@ cp -R tool/net/demo/.lua o/$(MODE)/tool/net/
|
||||
@(cd o/$(MODE)/tool/net && zip -qr redbean-demo.com .lua)
|
||||
@$(COMPILE) -AZIP -T$@ zip -qj $@ tool/net/demo/hello.lua tool/net/demo/sql.lua
|
||||
@echo "<-- check out this lua server page" | $(COMPILE) -AZIP -T$@ zip -cqj $@ tool/net/demo/redbean.lua
|
||||
@$(COMPILE) -AZIP -T$@ zip -qj $@ tool/net/demo/404.html tool/net/favicon.ico tool/net/redbean.png tool/net/demo/redbean-form.lua tool/net/demo/redbean-xhr.lua
|
||||
@echo Uncompressed for HTTP Range requests | $(COMPILE) -AZIP -T$@ zip -cqj0 $@ tool/net/demo/seekable.txt
|
||||
@$(COMPILE) -AZIP -T$@ zip -q $@ tool/net/ tool/net/demo/ tool/net/demo/index.html tool/net/demo/redbean.css tool/net/redbean.c net/http/parsehttprequest.c net/http/parseurl.c net/http/encodeurl.c test/net/http/parsehttprequest_test.c test/net/http/parseurl_test.c
|
||||
@printf "<p>This is a live instance of <a href=https://justine.lol/redbean/>redbean</a>: a tiny multiplatform webserver that <a href=https://news.ycombinator.com/item?id=26271117>went viral</a> on hacker news a few months ago.\r\nSince then, we've added Lua dynamic serving, which also goes as fast as 1,000,000 requests per second on a core i9 (rather than a cheap virtual machine like this). the text you're reading now is a PKZIP End Of Central Directory comment.\r\n<p>redbean aims to be production worthy across six operating systems, using a single executable file (this demo is hosted on FreeBSD 13). redbean has been enhanced to restore the APE header after startup.\r\nIt automatically generates this listing page based on your ZIP contents. If you use redbean as an application server / web development environment,\r\nthen you'll find other new and useful features like function call logging so you can get that sweet sweet microsecond scale latency." | $(COMPILE) -AZIP -T$@ zip -z $@
|
||||
@(cd o/$(MODE)/tool/net && ../../host/third_party/infozip/zip.com -qr redbean-demo.com .lua)
|
||||
@$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ tool/net/demo/hello.lua tool/net/demo/sql.lua
|
||||
@echo "<-- check out this lua server page" | $(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -cqj $@ tool/net/demo/redbean.lua
|
||||
@$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ tool/net/demo/404.html tool/net/favicon.ico tool/net/redbean.png tool/net/demo/redbean-form.lua tool/net/demo/redbean-xhr.lua
|
||||
@echo Uncompressed for HTTP Range requests | $(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -cqj0 $@ tool/net/demo/seekable.txt
|
||||
@$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -q $@ tool/net/ tool/net/demo/ tool/net/demo/index.html tool/net/demo/redbean.css tool/net/redbean.c net/http/parsehttprequest.c net/http/parseurl.c net/http/encodeurl.c test/net/http/parsehttprequest_test.c test/net/http/parseurl_test.c
|
||||
@printf "<p>This is a live instance of <a href=https://justine.lol/redbean/>redbean</a>: a tiny multiplatform webserver that <a href=https://news.ycombinator.com/item?id=26271117>went viral</a> on hacker news a few months ago.\r\nSince then, we've added Lua dynamic serving, which also goes as fast as 1,000,000 requests per second on a core i9 (rather than a cheap virtual machine like this). the text you're reading now is a PKZIP End Of Central Directory comment.\r\n<p>redbean aims to be production worthy across six operating systems, using a single executable file (this demo is hosted on FreeBSD 13). redbean has been enhanced to restore the APE header after startup.\r\nIt automatically generates this listing page based on your O/$(MODE)/THIRD_PARTY/INFOZIP/ZIP.COM contents. If you use redbean as an application server / web development environment,\r\nthen you'll find other new and useful features like function call logging so you can get that sweet sweet microsecond scale latency." | $(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -z $@
|
||||
@$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/virtualbean.justine.lol/
|
||||
@$(COMPILE) -ACP -T$@ cp tool/net/redbean.png o/$(MODE)/tool/net/virtualbean.justine.lol/redbean.png
|
||||
@$(COMPILE) -ACP -T$@ cp tool/net/demo/virtualbean.html o/$(MODE)/tool/net/virtualbean.justine.lol/index.html
|
||||
@(cd o/$(MODE)/tool/net && zip -q redbean-demo.com virtualbean.justine.lol/)
|
||||
@(cd o/$(MODE)/tool/net && echo 'Go to <a href=http://virtualbean.justine.lol>http://virtualbean.justine.lol</a>' | zip -cq redbean-demo.com virtualbean.justine.lol/index.html)
|
||||
@(cd o/$(MODE)/tool/net && zip -q redbean-demo.com virtualbean.justine.lol/redbean.png)
|
||||
@(cd o/$(MODE)/tool/net && ../../host/third_party/infozip/zip.com -q redbean-demo.com virtualbean.justine.lol/)
|
||||
@(cd o/$(MODE)/tool/net && echo 'Go to <a href=http://virtualbean.justine.lol>http://virtualbean.justine.lol</a>' | ../../host/third_party/infozip/zip.com -cq redbean-demo.com virtualbean.justine.lol/index.html)
|
||||
@(cd o/$(MODE)/tool/net && ../../host/third_party/infozip/zip.com -q redbean-demo.com virtualbean.justine.lol/redbean.png)
|
||||
|
||||
# REDBEAN-STATIC.COM
|
||||
#
|
||||
# Passing the -DSTATIC causes Lua and SQLite to be removed. This reduces
|
||||
# the binary size from roughly 1500 kb to 500 kb. It still supports SSL.
|
||||
|
||||
o/$(MODE)/tool/net/redbean-static.com: \
|
||||
o/$(MODE)/tool/net/redbean-static.com.dbg \
|
||||
|
@ -149,7 +175,61 @@ o/$(MODE)/tool/net/redbean-static.com.dbg: \
|
|||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/tool/net/redbean-static.o: tool/net/redbean.c
|
||||
@$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -DSTATIC $(OUTPUT_OPTION) $<
|
||||
@$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -DSTATIC -DREDBEAN=\"redbean-static\" $(OUTPUT_OPTION) $<
|
||||
|
||||
# REDBEAN-UNSECURE.COM
|
||||
#
|
||||
# Passing the -DUNSECURE will cause the TLS security code to be removed.
|
||||
# That doesn't mean redbean becomes insecure. It just reduces complexity
|
||||
# in situations where you'd rather have SSL be handled in an edge proxy.
|
||||
|
||||
o/$(MODE)/tool/net/redbean-unsecure.com: \
|
||||
o/$(MODE)/tool/net/redbean-unsecure.com.dbg \
|
||||
tool/net/favicon.ico \
|
||||
tool/net/redbean.png
|
||||
@$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@
|
||||
@$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/.redbean-unsecure
|
||||
@$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.redbean-unsecure/.ape bs=64 count=11 conv=notrunc 2>/dev/null
|
||||
@$(COMPILE) -AZIP -T$@ zip -qj $@ o/$(MODE)/tool/net/.redbean-unsecure/.ape tool/net/favicon.ico tool/net/redbean.png
|
||||
|
||||
o/$(MODE)/tool/net/redbean-unsecure.com.dbg: \
|
||||
$(TOOL_NET_DEPS) \
|
||||
o/$(MODE)/tool/net/redbean-unsecure.o \
|
||||
o/$(MODE)/tool/net/lsqlite3.o \
|
||||
o/$(MODE)/tool/net/net.pkg \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/tool/net/redbean-unsecure.o: tool/net/redbean.c
|
||||
@$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -DUNSECURE -DREDBEAN=\"redbean-unsecure\" $(OUTPUT_OPTION) $<
|
||||
|
||||
# REDBEAN-ORIGINAL.COM
|
||||
#
|
||||
# Passing the -DSTATIC and -DUNSECURE flags together w/ MODE=tiny will
|
||||
# produce 200kb binary that's very similar to redbean as it existed on
|
||||
# Hacker News the day it went viral.
|
||||
|
||||
o/$(MODE)/tool/net/redbean-original.com: \
|
||||
o/$(MODE)/tool/net/redbean-original.com.dbg \
|
||||
tool/net/favicon.ico \
|
||||
tool/net/redbean.png
|
||||
@$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@
|
||||
@$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/.redbean-original
|
||||
@$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.redbean-original/.ape bs=64 count=11 conv=notrunc 2>/dev/null
|
||||
@$(COMPILE) -AZIP -T$@ zip -qj $@ o/$(MODE)/tool/net/.redbean-original/.ape tool/net/favicon.ico tool/net/redbean.png
|
||||
|
||||
o/$(MODE)/tool/net/redbean-original.com.dbg: \
|
||||
$(TOOL_NET_DEPS) \
|
||||
o/$(MODE)/tool/net/redbean-original.o \
|
||||
o/$(MODE)/tool/net/lsqlite3.o \
|
||||
o/$(MODE)/tool/net/net.pkg \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/tool/net/redbean-original.o: tool/net/redbean.c
|
||||
@$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -DSTATIC -DUNSECURE -DREDBEAN=\"redbean-original\" $(OUTPUT_OPTION) $<
|
||||
|
||||
.PHONY: o/$(MODE)/tool/net
|
||||
o/$(MODE)/tool/net: \
|
||||
|
|
1306
tool/net/redbean.c
1306
tool/net/redbean.c
File diff suppressed because it is too large
Load diff
|
@ -76,9 +76,9 @@ void showcachesizes(void) {
|
|||
printf("%-19s%s%s %u-way %,7u byte cache w/%s %,5u sets of %u byte lines "
|
||||
"shared across %u threads\n",
|
||||
gc(xasprintf("Level %u%s", CPUID4_CACHE_LEVEL,
|
||||
CPUID4_CACHE_TYPE == 1
|
||||
? " data"
|
||||
: CPUID4_CACHE_TYPE == 2 ? " code" : "")),
|
||||
CPUID4_CACHE_TYPE == 1 ? " data"
|
||||
: CPUID4_CACHE_TYPE == 2 ? " code"
|
||||
: "")),
|
||||
CPUID4_IS_FULLY_ASSOCIATIVE ? " fully-associative" : "",
|
||||
CPUID4_COMPLEX_INDEXING ? " complexly-indexed" : "",
|
||||
CPUID4_WAYS_OF_ASSOCIATIVITY, CPUID4_CACHE_SIZE_IN_BYTES,
|
||||
|
@ -110,12 +110,15 @@ int main(int argc, char *argv[]) {
|
|||
printf("Running inside %.4s%.4s%.4s (eax=%#x)\n", &ebx, &ecx, &edx, eax);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
SHOW(kX86CpuFamily);
|
||||
SHOW(kX86CpuModel);
|
||||
printf("\n");
|
||||
SHOW(kX86CpuStepping);
|
||||
SHOW(kX86CpuModelid);
|
||||
SHOW(kX86CpuFamilyid);
|
||||
SHOW(kX86CpuType);
|
||||
SHOW(kX86CpuModelid);
|
||||
SHOW(kX86CpuExtmodelid);
|
||||
SHOW(kX86CpuFamilyid);
|
||||
SHOW(kX86CpuExtfamilyid);
|
||||
|
||||
printf("\n");
|
||||
|
|
29
tool/viz/fliphex.c
Normal file
29
tool/viz/fliphex.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*-*- 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 2021 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/fmt/conv.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i, x;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
x = strtoul(argv[i], 0, 0);
|
||||
printf("%#x\n", -x);
|
||||
}
|
||||
return 0;
|
||||
}
|
82
tool/viz/ntmaster.c
Normal file
82
tool/viz/ntmaster.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*-*- 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 2021 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/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
#define DLL "iphlpapi"
|
||||
|
||||
/**
|
||||
* @fileoverview Tool for adding rnew libraries to libc/nt/master.sh
|
||||
*
|
||||
* If provided with a /tmp/syms.txt file containing one symbol name per
|
||||
* line, this tool will output the correctly tab indented shell code.
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *f;
|
||||
int i, n, t;
|
||||
char *sym, tabs[64];
|
||||
showcrashreports();
|
||||
f = fopen("/tmp/syms.txt", "r");
|
||||
memset(tabs, '\t', 64);
|
||||
while ((sym = chomp(xgetline(f)))) {
|
||||
if (strlen(sym)) {
|
||||
printf("imp\t");
|
||||
|
||||
/* what we call the symbol */
|
||||
i = printf("'%s'", sym);
|
||||
t = 0;
|
||||
n = 56;
|
||||
if (i % 8) ++t, i = ROUNDUP(i, 8);
|
||||
t += (n - i) / 8;
|
||||
printf("%.*s", t, tabs);
|
||||
|
||||
/* what the kernel dll calls the symbol */
|
||||
i = printf("%s", sym);
|
||||
t = 0;
|
||||
n = 56;
|
||||
if (i % 8) ++t, i = ROUNDUP(i, 8);
|
||||
t += (n - i) / 8;
|
||||
printf("%.*s", t, tabs);
|
||||
|
||||
/* dll short name */
|
||||
i = printf("%s", DLL);
|
||||
t = 0;
|
||||
n = 16;
|
||||
if (i % 8) ++t, i = ROUNDUP(i, 8);
|
||||
t += (n - i) / 8;
|
||||
printf("%.*s", t, tabs);
|
||||
|
||||
/* hint */
|
||||
i = printf("0");
|
||||
t = 0;
|
||||
n = 8;
|
||||
if (i % 8) ++t, i = ROUNDUP(i, 8);
|
||||
t += (n - i) / 8;
|
||||
printf("%.*s", t, tabs);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
free(sym);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue