Commit graph

1135 commits

Author SHA1 Message Date
Justine Tunney
155b378a39
Tidy up the threading implementation
The organization of the source files is now much more rational.
Old experiments that didn't work out are now deleted. Naming of
things like files is now more intuitive.
2022-09-10 02:56:25 -07:00
Justine Tunney
e9272f03fb
Make some minor touchups for nightlies 2022-09-09 19:12:40 -07:00
Justine Tunney
3265324e00
Don't relocate file descriptor memory
This change fixes #496 where ASAN spotted a race condition that could
happen in multithreaded programs, with more than OPEN_MAX descriptors
when using ZipOS or Windows NT, which require tracking open file info
and this change fixes that table so it never relocates, thus allowing
us to continue to enjoy the benefits of avoiding locks while reading.
2022-09-09 16:54:28 -07:00
Justine Tunney
c3208eb9d5
Add more POSIX threads APIs 2022-09-09 11:30:33 -07:00
Justine Tunney
1729a8259c
Introduce MODE=fastbuild for 28% speedup 2022-09-09 08:59:59 -07:00
Gautham
094ccbb4bd
Add more foo64 stubs for Rust (#607) 2022-09-09 06:50:45 -07:00
Justine Tunney
e97f1a99cf
Fix pthread stacks with larger guard size 2022-09-09 06:41:22 -07:00
tkchia
1db76c288e
Bare metal VGA: enable bright background colors, disable blinking (#603)
Co-authored-by: tkchia <tkchia-cosmo@gmx.com>
2022-09-09 04:35:16 -07:00
Paul Kulchenko
f68151c010
Add sigpending to redbean unix.* module (#605) 2022-09-09 04:20:13 -07:00
Justine Tunney
2d17ab016c
Perform more low-level code cleanup 2022-09-09 04:07:08 -07:00
Gautham
c32e2d4486
Set stackaddr if mmap is called in pthread_create (#606) 2022-09-08 21:07:53 -07:00
Paul Kulchenko
5140897c27
Update redbean to include params in slash redirect (#604) 2022-09-08 19:14:54 -07:00
Justine Tunney
9f963dc597
Clean up some of the threading code 2022-09-08 12:31:56 -07:00
Justine Tunney
0547eabcd6
Polyfill IPv6 on non-Linux 2022-09-08 06:06:22 -07:00
Justine Tunney
b73e35c6fa
Improve open source compatibility
This change tunes the default stack size for the outside world to 8mb
while at the same time, reducing Cosmopolitan's default stack size to
64kb. You can override the stack size using STATIC_STACK_SIZE(). Your
build scripts should point to o//ape/public/ape.lds

This change also fixes the definition of SOMAXCONN and removes AF_RDS
since it's not polyfilled and Python 3.11 complained.
2022-09-08 03:19:35 -07:00
Justine Tunney
0e2b1bfeed
Make garbage collection thread safe
- You can now use _gc(malloc()) in multithreaded programs
- This change fixes a bug where fork() on NT disabled TLS
- Fixed TLS code morphing on XNU/NT, for R8-R15 registers
2022-09-08 02:33:01 -07:00
Justine Tunney
571c2c3c69
Fix race condition in makedirs() 2022-09-07 23:12:44 -07:00
Gavin Hayes
b7c07d548c
Add FP_ILOGB constants (#599) 2022-09-07 21:37:53 -07:00
Justine Tunney
6c323383e5
Make some fixups to POSIX threads 2022-09-07 21:13:50 -07:00
Justine Tunney
de511bc71a
Add phtread_setname_np() and pthread_getname_np() 2022-09-07 19:04:05 -07:00
Justine Tunney
114176c304
Add more foo64() functions for Rust 2022-09-07 05:48:57 -07:00
Gavin Hayes
a849a63771
Implement sigpending for sysv and nt (#597) 2022-09-07 05:38:12 -07:00
Justine Tunney
4339d9f15e
Add pthread attributes and other libc functions 2022-09-07 05:28:32 -07:00
Justine Tunney
d5c9308a43
Don't sandbox documentation generator 2022-09-06 20:45:21 -07:00
Justine Tunney
8bd9ad8342
Simplify redbean serialization code 2022-09-06 20:07:29 -07:00
tkchia
3fdb1c14f1
Add VGA support on bare metal (#588)
If your main module has this declaration:

    STATIC_YOINK("vga_console");

Then a VGA driver will be linked into your executable which
displays your stdio characters on the PC display, whereas
before we could only use the serial port. Your display is an
ANSI terminal and it's still a work in progress.
2022-09-06 18:41:08 -07:00
Gavin Hayes
598640864a
Fix inability to add some signals to mask on NT (#596) 2022-09-06 18:35:26 -07:00
Justine Tunney
d861d2787b
Import OpenBSD sorting algorithms
OpenBSD's qsort() function is more secure than the ones used by
FreeBSD, NetBSD and MacOS. The best part is it goes faster too!
This change also imports the OpenBSD mergesort() and heapsort()
2022-09-06 17:52:26 -07:00
Justine Tunney
dbf12c30b0
Make more compatibility improvements 2022-09-06 12:36:34 -07:00
Justine Tunney
11ec60d5fc
Use a better sorting algorithm
This change changes qsort() to use the same code as NetBSD and MacOS
because it goes 6x faster than Musl's SmoothSort function. Smoothsort
can still be used if you need something that's provenly linearithmic.
This change also improves GNU Make performance on whole by 7 percent!

netbsd nearly   l:    70,196c    22,673ns   m:    68,428c    22,102ns
musl nearly     l:    53,844c    17,391ns   m:    58,726c    18,968ns
unixv6 nearly   l:    65,885c    21,280ns   m:    63,082c    20,375ns

netbsd reverse  l:   120,290c    38,853ns   m:   122,619c    39,605ns
musl reverse    l:   801,826c   258,985ns   m:   794,689c   256,680ns
unixv6 reverse  l:    58,977c    19,049ns   m:    59,764c    19,303ns

netbsd random   l:   146,745c    47,398ns   m:   145,782c    47,087ns
musl random     l:   855,804c   276,420ns   m:   850,912c   274,840ns
unixv6 random   l:   214,325c    69,226ns   m:   213,906c    69,090ns

netbsd 2n       l:    77,299c    24,967ns   m:    76,773c    24,797ns
musl 2n         l:   818,012c   264,213ns   m:   818,282c   264,301ns
unixv6 2n       l: 3,967,009c 1,281,322ns   m: 3,941,792c 1,273,177ns

https://justine.lol/dox/sort.pdf
2022-09-06 11:06:10 -07:00
Justine Tunney
55c6297e13
Make more compatibility improvements 2022-09-06 07:04:13 -07:00
Justine Tunney
12d9e1e128
Improve quality of our ANSI C clock() function
It now works most excellently across all supported operating
sytsems (earlier it didn't work on NT and XNU). Demo code is
available in examples/clock.c and this change also adds some
of the newer ANSI C time functions like timespec_get(), plus
timespec_getres() which hasn't even come out yet as it's C23
2022-09-05 23:03:49 -07:00
Justine Tunney
7ff0ea8c13
Make pthread mutexes more scalable
pthread_mutex_lock() now uses a better algorithm which goes much faster
in multithreaded environments that have lock contention. This comes at
the cost of adding some fixed-cost overhead to mutex invocations. That
doesn't matter for Cosmopolitan because our core libraries all encode
locking operations as NOP instructions when in single-threaded mode.
Overhead only applies starting the moment you first call clone().
2022-09-05 15:57:51 -07:00
Gavin Hayes
7de2f229a7
Discard ignored signals on New Technology (#592) 2022-09-05 09:17:56 -07:00
Gautham
4b4ea046c4
Ensure libcxx.a is built when providing folder (#591) 2022-09-05 09:17:16 -07:00
Justine Tunney
44c315d789
Disable pthread broadcast test temporarily
This fixes the GitHub Actions build.
2022-09-05 09:06:16 -07:00
Justine Tunney
8cd4248f7f
Make SIG_DFL / SIG_IGN C++ compatible 2022-09-05 08:49:26 -07:00
Justine Tunney
d721ff8938
Remove testonly keyword 2022-09-05 08:41:43 -07:00
Justine Tunney
9be364d40a
Implement POSIX threads API 2022-09-05 08:27:15 -07:00
Justine Tunney
af24f21556
Unsandbox assembly generation 2022-09-05 08:27:15 -07:00
Paul Kulchenko
b0287ef34c
Tune a log message priority in redbean (#589) 2022-09-04 07:43:06 -07:00
Justine Tunney
6a04bc3318
Release redbean 2.0.18 2022-09-04 06:57:59 -07:00
Justine Tunney
8dd4ec68d0
Add more missing C / C++ headers 2022-09-04 04:53:52 -07:00
Justine Tunney
b9dc74b672
Do some work on unbuffer command 2022-09-04 02:25:34 -07:00
Justine Tunney
e1590e1e38
Remove accidental comment 2022-09-04 00:41:09 -07:00
tkchia
8569704c1d
Stop APE bare metal loader from reading beyond program image end (#574)
This allows e.g. `qemu-system-x86_64 -s o/examples/hello.com
-serial stdio` to work without having to add extra padding to
the end of the `hello.com` "disk image".

(The sector count computation is divided among two instructions
in the assembly code.  This is done on purpose, to prevent an
ASCII 0x27 (single quote) byte from appearing in the bare
metal loader code, which will break the shell script loader.
There is probably a better way.)

Co-authored-by: tkchia <tkchia-cosmo@gmx.com>
2022-09-04 00:19:08 -07:00
Gavin Hayes
9c017c98d3
Add sysconf to unistd.h (#575) 2022-09-04 00:10:17 -07:00
Gavin Hayes
74879bf067
Add pollfd to poll.h (#576) 2022-09-04 00:09:50 -07:00
Paul Kulchenko
8a3d8497e3
Update README to add a note about binfmt-related errors (#587) 2022-09-04 00:09:24 -07:00
Justine Tunney
3c00d8c29c Fix TLS linker warning
Fixes #565
Closes #577
Co-authored-by: tkchia <tkchia-cosmo@gmx.com>
2022-09-04 00:05:30 -07:00