Commit Graph

26 Commits

Author SHA1 Message Date
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Brian Gianforcaro
5a31ca06db LibPthread: Add non functional pthread_attr_[set|get]scope stubs
Standard: https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_attr_getscope.html

Needed for https://fio.readthedocs.io
2021-04-21 13:13:23 +02:00
Gunnar Beutner
2520ccfca4 LibPthread: Add stubs for pthread_spin_* functions
The stress-ng port depends on these now that it detects we have
thread support.
2021-04-20 21:08:17 +02:00
Gunnar Beutner
88cebb05ad LibC+LibPthread: Implement function forwarding for libpthread
GCC will insert various calls to pthread functions when compiling
C++ code with static initializers, even when the user doesn't link
their program against libpthread explicitly.

This is used to make static initializers thread-safe, e.g. when
building a library that does not itself use thread functionality
and thus does not link against libpthread - but is intended to
be used with other code that does use libpthread explicitly.

This makes these symbols available in libc.
2021-04-20 21:08:17 +02:00
Gunnar Beutner
bd08f9188a Pthread: Add stubs for pthread_cleanup_{push,pop}
The stubs are necessary to make the xz port properly detect pthread
support. The two functions are only used in the configure script and
nowhere else.
2021-04-19 17:55:35 +02:00
Gunnar Beutner
4075b306f8 LibC+LibPthread: Make sure TLS keys are destroyed after everything else
This ensures that __thread variables can be used when global destructors
are being invoked.
2021-04-18 10:52:05 +02:00
Gunnar Beutner
b3eb55ec9a LibPthread: Implement sem_getvalue() 2021-04-15 09:31:49 +02:00
Gunnar Beutner
a44ddc4793 LibPthread: Don't hold sem->mtx after sem_wait()/sem_trywait()
Semaphores with values greater than one didn't work because whoever
called sem_wait() first held the semaphore's mutex until a matching
sem_post() call.

Other callers then wouldn't be able to acquire the semaphore even
if the semaphore's value was still greater than zero at that point.
2021-04-15 09:31:49 +02:00
Gunnar Beutner
32794e00a1 LibPthread: Improve error handling for the semaphore functions
This patch makes sure we're propagating errors to the caller.
2021-04-15 09:31:49 +02:00
Gunnar Beutner
98403eccb0 LibPthread: Ensure we're not overflowing the semaphore's value 2021-04-15 09:31:49 +02:00
Gunnar Beutner
ea6d0aa1d4 LibPthread: Implement semaphore functions 2021-04-14 13:13:06 +02:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
25a69d2b18 LibPthread: Convert dbgprintf() => dbgln_if() 2021-02-17 15:46:21 +01:00
Ben Wiederhake
cf0d4994c2 LibC+LibPthread: Permit partial pthread_atfork
POSIX explicitly allows providing nullptr's, and our __pthread_*() implementation
stores and calls the provided functions as-is, without checking for nullptr.
2021-02-15 22:09:01 +01:00
AnotherTest
bb777459a0 LibC+LibPthread: Implement pthread_atfork()
This required a bit of rearchitecture, as pthread_atfork() required a
mutex, and duplicating a mutex impl for it was silly.
As such, this patch moves some standalone bits of pthread into LibC and
uses those to implement atfork().
It should be noted that for programs that don't use atfork(), this
mechanism only costs two atomic loads (as opposed to the normal mutex
lock+unlock) :^)
2021-02-15 17:32:56 +01:00
AnotherTest
8e074f8665 LibC+LibPthread: Implement pthread_rwlock_*
This implementation is pretty damn dumb, and probably has more bugs than
features.
But for the time being, it seems to work. however, we should definitely
replace it with a good implementation sometime very soon :^)
2021-02-15 17:32:56 +01:00
AnotherTest
2e50c232f7 LibPthread: Stub out pthread_atfork() 2021-02-15 17:32:56 +01:00
AnotherTest
26a8a84ded LibC+LibPthread: Stub out pthread_rwlock_* functions 2021-02-15 17:32:56 +01:00
Andreas Kling
e87eac9273 Userland: Add LibSystem and funnel all syscalls through it
This achieves two things:

- Programs can now intentionally perform arbitrary syscalls by calling
  syscall(). This allows us to work on things like syscall fuzzing.

- It restricts the ability of userspace to make syscalls to a single
  4KB page of code. In order to call the kernel directly, an attacker
  must now locate this page and call through it.
2021-02-05 12:23:39 +01:00
asynts
eea72b9b5c Everywhere: Hook up remaining debug macros to Debug.h. 2021-01-25 09:47:36 +01:00
asynts
acdcf59a33 Everywhere: Remove unnecessary debug comments.
It would be tempting to uncomment these statements, but that won't work
with the new changes.

This was done with the following commands:

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \;

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-25 09:47:36 +01:00
Tom
9943816e83 LibPthread: Fix asserting futex return value
FUTEX_WAIT returns the number of threads woken (if any).

Fixes #5032
2021-01-22 11:17:07 +01:00
Tom
1d621ab172 Kernel: Some futex improvements
This adds support for FUTEX_WAKE_OP, FUTEX_WAIT_BITSET, FUTEX_WAKE_BITSET,
FUTEX_REQUEUE, and FUTEX_CMP_REQUEUE, as well well as global and private
futex and absolute/relative timeouts against the appropriate clock. This
also changes the implementation so that kernel resources are only used when
a thread is blocked on a futex.

Global futexes are implemented as offsets in VMObjects, so that different
processes can share a futex against the same VMObject despite potentially
being mapped at different virtual addresses.
2021-01-17 20:30:31 +01:00
Andreas Kling
f2a6ee76c0 LibPthread: Add pthread_equal() 2021-01-12 13:42:45 +01:00
Andreas Kling
bee1145bdf LibPthread: Stub pthread_setcancelstate() and pthread_setcanceltype() 2021-01-12 13:40:48 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00