cosmopolitan/examples
Justine Tunney ec480f5aa0
Make improvements
- Every unit test now passes on Apple Silicon. The final piece of this
  puzzle was porting our POSIX threads cancelation support, since that
  works differently on ARM64 XNU vs. AMD64. Our semaphore support on
  Apple Silicon is also superior now compared to AMD64, thanks to the
  grand central dispatch library which lets *NSYNC locks go faster.

- The Cosmopolitan runtime is now more stable, particularly on Windows.
  To do this, thread local storage is mandatory at all runtime levels,
  and the innermost packages of the C library is no longer being built
  using ASAN. TLS is being bootstrapped with a 128-byte TIB during the
  process startup phase, and then later on the runtime re-allocates it
  either statically or dynamically to support code using _Thread_local.
  fork() and execve() now do a better job cooperating with threads. We
  can now check how much stack memory is left in the process or thread
  when functions like kprintf() / execve() etc. call alloca(), so that
  ENOMEM can be raised, reduce a buffer size, or just print a warning.

- POSIX signal emulation is now implemented the same way kernels do it
  with pthread_kill() and raise(). Any thread can interrupt any other
  thread, regardless of what it's doing. If it's blocked on read/write
  then the killer thread will cancel its i/o operation so that EINTR can
  be returned in the mark thread immediately. If it's doing a tight CPU
  bound operation, then that's also interrupted by the signal delivery.
  Signal delivery works now by suspending a thread and pushing context
  data structures onto its stack, and redirecting its execution to a
  trampoline function, which calls SetThreadContext(GetCurrentThread())
  when it's done.

- We're now doing a better job managing locks and handles. On NetBSD we
  now close semaphore file descriptors in forked children. Semaphores on
  Windows can now be canceled immediately, which means mutexes/condition
  variables will now go faster. Apple Silicon semaphores can be canceled
  too. We're now using Apple's pthread_yield() funciton. Apple _nocancel
  syscalls are now used on XNU when appropriate to ensure pthread_cancel
  requests aren't lost. The MbedTLS library has been updated to support
  POSIX thread cancelations. See tool/build/runitd.c for an example of
  how it can be used for production multi-threaded tls servers. Handles
  on Windows now leak less often across processes. All i/o operations on
  Windows are now overlapped, which means file pointers can no longer be
  inherited across dup() and fork() for the time being.

- We now spawn a thread on Windows to deliver SIGCHLD and wakeup wait4()
  which means, for example, that posix_spawn() now goes 3x faster. POSIX
  spawn is also now more correct. Like Musl, it's now able to report the
  failure code of execve() via a pipe although our approach favors using
  shared memory to do that on systems that have a true vfork() function.

- We now spawn a thread to deliver SIGALRM to threads when setitimer()
  is used. This enables the most precise wakeups the OS makes possible.

- The Cosmopolitan runtime now uses less memory. On NetBSD for example,
  it turned out the kernel would actually commit the PT_GNU_STACK size
  which caused RSS to be 6mb for every process. Now it's down to ~4kb.
  On Apple Silicon, we reduce the mandatory upstream thread size to the
  smallest possible size to reduce the memory overhead of Cosmo threads.
  The examples directory has a program called greenbean which can spawn
  a web server on Linux with 10,000 worker threads and have the memory
  usage of the process be ~77mb. The 1024 byte overhead of POSIX-style
  thread-local storage is now optional; it won't be allocated until the
  pthread_setspecific/getspecific functions are called. On Windows, the
  threads that get spawned which are internal to the libc implementation
  use reserve rather than commit memory, which shaves a few hundred kb.

- sigaltstack() is now supported on Windows, however it's currently not
  able to be used to handle stack overflows, since crash signals are
  still generated by WIN32. However the crash handler will still switch
  to the alt stack, which is helpful in environments with tiny threads.

- Test binaries are now smaller. Many of the mandatory dependencies of
  the test runner have been removed. This ensures many programs can do a
  better job only linking the the thing they're testing. This caused the
  test binaries for LIBC_FMT for example, to decrease from 200kb to 50kb

- long double is no longer used in the implementation details of libc,
  except in the APIs that define it. The old code that used long double
  for time (instead of struct timespec) has now been thoroughly removed.

- ShowCrashReports() is now much tinier in MODE=tiny. Instead of doing
  backtraces itself, it'll just print a command you can run on the shell
  using our new `cosmoaddr2line` program to view the backtrace.

- Crash report signal handling now works in a much better way. Instead
  of terminating the process, it now relies on SA_RESETHAND so that the
  default SIG_IGN behavior can terminate the process if necessary.

- Our pledge() functionality has now been fully ported to AARCH64 Linux.
2023-09-18 21:04:47 -07:00
..
package Clean up more code 2023-06-18 01:00:05 -07:00
pyapp Fix V=0 make mode 2022-06-21 01:32:31 -07:00
pylife Cherry-pick bug fixes and Landlock Make 1.0.2 2022-08-10 12:56:45 -07:00
abort.c Make improvements 2023-09-18 21:04:47 -07:00
auto-launch-gdb-on-crash.c Introduce #include <cosmo.h> to toolchain users 2023-06-09 18:03:05 -07:00
auto-memory-safety-crash.c Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
auto-memory-safety-crash2.c Make fixes and improvements 2022-10-19 07:19:19 -07:00
auto-memory-safety-crash3.c Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
breakpoint.c Make considerably more progress on AARCH64 2023-05-12 22:42:57 -07:00
certapp.c Further improve fatcosmocc 2023-08-13 01:51:39 -07:00
check.c Mint APE Loader v1.5 2023-07-26 13:54:49 -07:00
clear.c Overhaul process spawning 2023-09-10 08:17:44 -07:00
clock.c Clean up more code 2023-06-18 01:00:05 -07:00
clock_getres.c Disable linker map generation and improve tinyness 2023-06-09 03:29:26 -07:00
compress.c Switch public headers to getopt_long() entirely 2023-07-02 19:57:43 -07:00
cplusplus-stl.cc Import C++ Standard Template Library 2022-03-22 06:41:54 -07:00
cplusplus.cc Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
crashreport.c Make improvements 2023-09-18 21:04:47 -07:00
crashreport2.c Fix warnings 2023-09-01 20:50:18 -07:00
ctrlc.c Make the Windows Console work better 2023-09-07 18:27:22 -07:00
datauri.c Fix warnings 2023-09-01 20:50:18 -07:00
date.c Make improvements to cosmocc toolchain 2023-06-10 15:50:01 -07:00
decompress.c Fix bugs in cosmocc toolchain 2023-06-08 23:44:03 -07:00
defer-statements.c Fix warnings 2023-09-01 20:50:18 -07:00
die.c Make improvements 2023-09-18 21:04:47 -07:00
dot.c Release Landlock Make v1.0.1 2022-08-10 12:17:06 -07:00
examples.mk Make improvements 2023-09-18 21:04:47 -07:00
exec.c Mint APE Loader v1.5 2023-07-26 13:54:49 -07:00
exit.c Make improvements 2022-05-12 06:45:36 -07:00
forkexec.c Fix warnings 2023-09-01 20:50:18 -07:00
forkexecwait.c Fix warnings 2023-09-01 20:50:18 -07:00
forkrand.c Rename rand64() to _rand64() 2022-10-10 04:12:06 -07:00
gc.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
generalized-automatic-datastructure-printing.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
getcpucount.c Fix small matters and improve sysconf() 2023-08-17 00:32:11 -07:00
getdomainname.c Improve cosmocc toolchain 2023-03-05 23:52:49 -08:00
getrandom.c Switch public headers to getopt_long() entirely 2023-07-02 19:57:43 -07:00
gettimeofday.c Fix warnings 2023-09-01 20:50:18 -07:00
greenbean.c Make improvements 2023-09-18 21:04:47 -07:00
gui.c Make examples folder somewhat more focused 2021-03-05 06:09:12 -08:00
hangman.c Fix warnings 2023-09-01 20:50:18 -07:00
hello.c Remove printf() linking hack 2023-06-17 10:13:50 -07:00
hello2.c Introduce new linker for fat ape binaries 2023-08-11 04:39:19 -07:00
hello3.c Remove printf() linking hack 2023-06-17 10:13:50 -07:00
hellolua.c Fix warnings 2023-09-01 20:50:18 -07:00
hellolua.lua Add Hello World example for LUA C API (#97) 2021-03-08 14:15:59 -08:00
hertz.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
hiredis.c Add a new example showing how to use hiredis. 2023-01-01 16:30:10 -08:00
hostname.c Improve quality of our ANSI C clock() function 2022-09-05 23:03:49 -07:00
img.c Fix warnings 2023-09-01 20:50:18 -07:00
kilo.c Fix warnings 2023-09-01 20:50:18 -07:00
life.c Always initialize thread local storage 2022-07-19 00:21:46 -07:00
linenoise.c Make improvements 2023-09-18 21:04:47 -07:00
loadavg.c Fix some win32 definitions 2022-03-22 19:54:36 -07:00
ls.c Replace COSMO define with _COSMO_SOURCE 2023-08-13 20:55:04 -07:00
lstime.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
mkhello.c Support Linux binfmt_misc and APE loading on Apple 2022-05-21 09:28:25 -07:00
nc.c Fix warnings 2023-09-01 20:50:18 -07:00
nesemu1.cc Make improvements 2023-09-18 21:04:47 -07:00
nomodifyself.c Introduce native support for MacOS ARM64 2023-05-20 04:17:03 -07:00
panels.c Fix warnings 2023-09-01 20:50:18 -07:00
picol.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
portscan.c Disable linker map generation and improve tinyness 2023-06-09 03:29:26 -07:00
printargs.c Make improvements 2022-04-24 10:06:05 -07:00
printprimes.c Do code cleanup use duff device linenoise i/o 2022-04-22 18:56:52 -07:00
reboot.c Improve cancellations, randomness, and time 2022-11-05 23:45:32 -07:00
rlimit.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
rusage.c Simplify the rusage.com command 2023-09-07 05:41:18 -07:00
script.c Fix warnings 2023-09-01 20:50:18 -07:00
script.txt Add script.com and whois.com courtesy of FreeBSD 2022-09-13 20:26:13 -07:00
seq.c Make improvements 2022-04-29 00:42:47 -07:00
setcontext.c Implement swapcontext() and makecontext() 2023-07-02 09:01:44 -07:00
setitimer.c Change sigaction_f to match sysv signature (#585) 2022-09-02 05:08:35 -07:00
shutdown.c Improve cancellations, randomness, and time 2022-11-05 23:45:32 -07:00
spawn_bench.c Make improvements 2023-09-18 21:04:47 -07:00
stackexplorer.c Mint APE Loader v1.7 2023-08-17 09:04:50 -07:00
stackoverflow.c Make improvements 2023-09-18 21:04:47 -07:00
stat.c Mint APE Loader v1.7 2023-08-17 09:04:50 -07:00
statfs.c Mint APE Loader v1.7 2023-08-17 09:04:50 -07:00
stringbuffer.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
sysconf.c Fix small matters and improve sysconf() 2023-08-17 00:32:11 -07:00
sysinfo.c Fix sysinfo() 2023-02-23 06:54:58 -08:00
system.c Mint APE Loader v1.5 2023-07-26 13:54:49 -07:00
thread.c Tidy up the threading implementation 2022-09-10 02:56:25 -07:00
tib.c Make improvements 2023-09-18 21:04:47 -07:00
tls.c Make improvements 2022-07-21 03:36:42 -07:00
ttyinfo.c Make improvements 2023-09-18 21:04:47 -07:00
ucontext-sigfpe-recovery.c Make considerably more progress on AARCH64 2023-05-12 22:42:57 -07:00
uname.c Improve quality of uname/gethostname/getdomainname 2022-09-03 20:20:40 -07:00
unbourne.c Simplify the rusage.com command 2023-09-07 05:41:18 -07:00
vga.c Mint APE Loader v1.5 2023-07-26 13:54:49 -07:00
vga2.c Mint APE Loader v1.5 2023-07-26 13:54:49 -07:00
vqsort.c Add more sorting algorithms 2023-04-27 05:44:44 -07:00
walk.c Make fixes and improvements 2023-07-09 05:21:11 -07:00
wall.c Fix warnings 2023-09-01 20:50:18 -07:00
whois.c Perform inconsequential code cleanup 2023-08-07 20:24:50 -07:00