Commit graph

1420 commits

Author SHA1 Message Date
Gavin Hayes
a412ca7a77
clang-format: merge include blocks (#792) 2023-03-29 00:05:58 -07:00
Justine Tunney
426d441994
Fix quick regression due to header line 2023-03-28 23:35:09 -07:00
Justine Tunney
4f39139fe0
Support kill(pid, 0) behavior on Windows
It's specified by POSIX as a way to check if a pid can be signalled.
2023-03-28 22:28:09 -07:00
Justine Tunney
0d084d01b9
Discern MAP_ANONYMOUS the proper way on NT
We were checking for anonymous mappings earlier on Windows by seeing if
the file descriptor argument to mmap() was supplied as -1. This was not
correct. The proper thing to do is check `flags & MAP_ANONYMOUS`.
2023-03-28 22:16:26 -07:00
Justine Tunney
390aee960a
Use enum and typedef in stdatomic.h 2023-03-28 22:15:58 -07:00
Gabriel Ravier
792b1c84c0
Fix padding+minus flag on numbers for printf-family functions (#787)
The C standard states, for conversions using the d, i, b, B, o, u, x or X conversion specifiers:
> The precision specifies the minimum number of digits to appear; if
> the value being converted can be represented in fewer digits, it is
> expanded with leading zeros.
- C standard, 7.23.6.1. The fprintf function

However, cosmopolitan currently suppresses the addition of leading
zeros when the minus flag is set. This is not reflected by anything
within the C standard, meaning that behavior is incorrect.

This patch fixes this.
2023-03-25 14:39:25 -04:00
Gabriel Ravier
2d6ea2fbc9
Fix issue #771 by implementing S conversion specifier for printf-related functions (#786)
* Implement S conversion specifier for printf-related functions

POSIX specifies that a conversion specifier of S must be interpreted
the same way as %ls. This patch implements this.

* clang-format

---------

Co-authored-by: Gavin Hayes <gavin@computoid.com>
2023-03-25 14:38:21 -04:00
Paul Kulchenko
58b2f9bd6b
Fix missing detail in the error message in redbean (#768)
This only happens on calls that need to happen during active connection.
2023-03-20 11:10:32 -04:00
Ariel Núñez
893703a07b
Fix import asyncio (#763) 2023-03-11 23:29:03 -08:00
Alexandre Gomes Gaigalas
775f456d4c
Avoid matching directories when searching PATH (#717)
When searching for an executable, performs an additional check to
determine if the path is a file.
2023-03-06 11:15:32 -05:00
Paul Kulchenko
e2f429b742
Redbean documentation typo fixes. (#756)
* Redbean documentation typo fixes.

* Add brief description to some unix.* calls missing it
2023-03-06 00:15:09 -08:00
Justine Tunney
ba180e754d
Improve cosmocc toolchain
- Decouple zlib from libc
- Add some underscores to mostly internal names
2023-03-05 23:52:49 -08:00
Justine Tunney
713d4424c6
Don't add loopback address to generated SSL cert 2023-03-05 22:57:22 -08:00
Justine Tunney
e16b969829
Make intrin_test go faster 2023-03-05 22:57:07 -08:00
Justine Tunney
2112fb1736
Fix SHUFPD and SHUFPS and add fuzz tests
See: https://github.com/jart/blink/issues/72
See: https://github.com/jart/blink/issues/68
2023-03-05 16:12:28 -08:00
Justine Tunney
2aa044cb0c
Interalize msr.h 2023-03-05 16:12:11 -08:00
Justine Tunney
c8a9d3458e
Update commentary in ape.S 2023-03-05 16:11:03 -08:00
Gavin Hayes
c5de653b98
GetZipCdir: prevent integer underflow. posix_spawn_test.c: stop attempting to load zipos from /usr/bin/ape. (#758) 2023-03-05 14:29:38 -08:00
Paul Kulchenko
22fcab131c
Fix redbean SQLite to report results on failure to open db (#760) 2023-03-05 14:26:56 -08:00
imawaki
da7c8c7b54
Serve .mjs files as text/javascript (#761) 2023-03-05 14:26:18 -08:00
Gavin Hayes
f5520209f5
execve_test.com: fix run with landlock make. Cleanup execve/fexecve tests (#755) 2023-03-01 22:32:15 -08:00
tkchia
ae365928c5
[metal] Minor corrections to constants for paging structures (#751) 2023-02-24 11:49:08 -08:00
Gavin Hayes
5923d483a4
Add execve / fexecve support to ZIpOS (#727) 2023-02-24 11:48:24 -08:00
Paul Kulchenko
0312898979
Make redbean cache directive configurable (#750)
Thank you @johnmuhl for the proposal. Fixes #739
2023-02-23 22:24:40 -08:00
Paul Kulchenko
db16f0129a
Redbean sqlite fix multi close (#749)
* Update redbean SQLite config to handle more options

This requires moving sqlite3_initialize call to open, as configuration
should be allowed before initialization is done. This call is effective
only for the first time and then no-op after that.

* Fix redbean SQLite for closing db with already finalized statements

There is a loop in cleanupdb that finalizes all vms that are associated
with that db when it's being closed. Under some circumstances (detailed
below) that loop may contain references pointing to already collected
objects, thus leading to SIGSEGV when those references are used.

This may happen with the following sequence of events ("VM" is the name
used in lsqlite and describes the same thing as "statement"):
1. A finalized statement is created (for example, by preparing an empty
string or a string with no statement that is still grammatically valid).
2. This statement goes out of scope before the DB object it's associated
with does and is garbage collected.
3. When it's garbage collected, dbvm_gc method is called, which checks
for svm->vm being not NULL.
4. Since the VM is already finalized, cleanupvm method is not called,
so the VM reference is not removed from the table of VMs tracked for
that DB.
5. When the DB is finally closed or garbage collected, all the VMs
associated with it are accessed to be finalized, including the ones that
have been garbage collected and have invalid references (thus leading
to a memory access error).

Here is an example of a stacktrace from the resulting SIGSEGV:

70000003de20 5df71a getgeneric+26
70000003fac0 5dfc7f luaH_get+111
70000003faf0 5e06c8 luaH_set+40
70000003fb20 5c5bd7 aux_rawset+55
70000003fb50 5c70cb lua_rawset+27
70000003fb60 4fa8e7 cleanupvm+71
70000003fb80 4fa988 cleanupdb+88
70000003fbc0 4fe899 db_gc+41

One way to fix this is to use userdata references (which anchor their
targets) instead of lightuserdata references (which do not), but this
would prevent the targets (VMs) from being garbage collected until the
DB itself is garbage collected, so this needs to be combined with
weakening the keys in the DB table. The code in cleanupdb to remove the
VM references is no longer needed, as this is handled by having weak keys.

The patch also switches to using close_v2, as it is intended for use
with garbage collected languages where the order in which destructors
are called is arbitrary, as is the case here.

* Remove GC collection from redbean SQLite session

The behavior of sqlite3session_delete is undefined after the DB
connection is closed, so we need to avoid calling it from gc handler.
2023-02-23 20:10:03 -08:00
Justine Tunney
c395d16230
Upgrade embedded blink to 0.9.2 2023-02-23 12:25:01 -08:00
Justine Tunney
1011db793f
Bump embedded blink binary to 0.9.0
This is an official tagged version. The 1.1 version used earlier was
informal. Formal versions will always have major.minor.patch going
forward. See https://github.com/jart/blink/tags 1.0.0 coming soon.
2023-02-23 09:57:08 -08:00
Michael Ford
ca88fc34c3
doc: remove "everything everything" from ParseUrl doc (#704)
Closes: #702.
2023-02-23 09:34:48 -08:00
Justine Tunney
ad97d7b9db
Disable Python test_sys 2023-02-23 08:56:31 -08:00
Justine Tunney
18a24935cc
Fix Python stack overflow checking in MODE=dbg 2023-02-23 08:13:33 -08:00
Justine Tunney
8b69acc1cc
Make mkdeps more helpful when files are missing 2023-02-23 08:11:08 -08:00
Justine Tunney
0468ca02fe
Support building APE binaries greater than 30mb 2023-02-23 08:10:43 -08:00
Justine Tunney
7355499a6a
Remove a misplaced include 2023-02-23 08:10:38 -08:00
Justine Tunney
1208ac9f10
Add some POSIX feature definitions
This helps Python configure itself. We should focus more on vetting
these to make 100% sure they're accurate to define.
2023-02-23 08:09:34 -08:00
Justine Tunney
298ba74a45
Make POSIX semaphores always process shared
Python triggered the undefined behavior previously since it appears to
be posting to a semaphore owned by a different process that wasn't set
to process shared mode. The performance loss to process shared futexes
is so low and semaphores are generally used for this purpose, so it'll
be much simpler to simply not impose undefined behavior here.
2023-02-23 08:07:54 -08:00
Justine Tunney
b15f9eb58f
Improve Python's threading story
Python threads are now generally working, however some parts of Python's
regression tests for threads are flaky. This is possibly due to needing
more locking primitives in Cosmo's IO system call wrappers, e.g. close.

    make o//third_party/python/Lib/test/test_threading.py.runs

See #747
2023-02-23 06:55:54 -08:00
ahgamut
60eb34509b
quick addition of cosmo pthreads to python.com
- enable WITH_THREAD and _POSIX_THREADS
- add headers everywhere
- breaks only two tests (faulthandler and signal)
- disabled terminal completion because it causes segfaults for some
  reason (probably could not get the current thread)
2023-02-23 06:55:17 -08:00
Justine Tunney
a808b3e738
Serialize ZipOS handle IO across threads 2023-02-23 06:55:10 -08:00
Justine Tunney
0f1ead8943
Fix select() on Linux
This fixes a bug where the caller's timeval will be clobbered on Linux.
The Kernel ABI *always* modifies the timeout argument but POSIX says it
should be a const parameter. The wrapper now handles the difference and
sys_select() may be used if obtaining the remainder on Linux is needed.
2023-02-23 06:55:05 -08:00
Justine Tunney
dfabcd84c1
Fix sysinfo()
The system call wrapper was wrongfully reinterpreting kernel data. The
examples/sysinfo.c program is now updated to show how to correctly use
what's returned.
2023-02-23 06:54:58 -08:00
Justine Tunney
71d955be1d
Add blog link for access() impl inspiration 2023-02-23 06:54:53 -08:00
James Hulce
e4ee1da652
Fix filenames in help.txt (#722)
Many functions incorrectly direct users to see a .c file, when they should be .S
2023-02-22 19:00:49 -08:00
Gavin Hayes
ff9c15f48a
Add APE fexecve() support (#733) 2023-02-22 18:58:23 -08:00
Gavin Hayes
b275e664ec
Make ZipOS mmap safer (#735)
- It now runs entirely under __mmi_lock
- Hide implementation strace
2023-02-22 18:57:36 -08:00
Paul Kulchenko
e323527ffa
Remove slowloris handling from Redbean (#737)
It's been superseded by token bucket processing, does not take time
into considerations (only the number of fragments), and affects file
uploads that may require a large number of reads.
2023-02-22 18:56:02 -08:00
Joshua Wierenga
08fef9b277
Fix nt path format check (#744) 2023-02-22 18:42:13 -08:00
Gavin Hayes
94dcf81954
Add glob to cocmd (#740) 2023-02-21 10:31:04 -08:00
Justine Tunney
2b6261a52d
Make some system call fixes
- Fix minor ABI issue with SIOCGIFCONF
- Fix ABI translation issues with statfs() on BSDs
- Fix SQLite angled header line
2023-02-12 22:16:34 -08:00
Justine Tunney
0eb621f75e
Remove non-JIT'd blink builds for now 2023-02-12 22:14:16 -08:00
Justine Tunney
9634227181
Polyfill Linux unlink() EISDIR on POSIX platforms 2023-02-05 16:50:11 -08:00