Commit Graph

350 Commits

Author SHA1 Message Date
Timothy Flynn
d485cf29d7 LibRegex+LibUnicode: Begin implementing Unicode property escapes
This supports some binary property matching. It does not support any
properties not yet parsed by LibUnicode, nor does it support value
matching (such as Script_Extensions=Latin).
2021-07-30 21:26:31 +01:00
Luke
f5d4de8b66 LibC: Stub mlock in sys/mman
mlock is supposed to prevent memory from being paged out to swap, which
we don't have currently.

Required by OpenSSL.
2021-07-30 20:49:56 +02:00
Luke
e3b588a43d Kernel+LibC: Add linger to sys/sockets.h
Also adds SO_BROADCAST in UnixTypes.h to match sys/sockets.h.
Required by bash 5.1.8.
2021-07-29 19:35:03 +01:00
Gunnar Beutner
78c81854cc LibC: Don't include C++ headers in C system headers 2021-07-27 16:53:16 +02:00
Gunnar Beutner
daeb371180 DynamicLoader+LibELF: Move self-relocation code into a separate file 2021-07-27 13:15:16 +02:00
Brian Gianforcaro
46c9b1d81c Kernel+LibC: Use argument for TIOCGPGRP ioctl value
In preparation for modifying the Kernel IOCTL API to return KResult
instead of int, we need to fix this ioctl to an argument to receive
it's return value, instead of using the actual function return value.
2021-07-27 01:23:37 +04:30
Patrick Meyer
83f88df757 Kernel: Add option to build with coverage instrumentation and KCOV
GCC and Clang allow us to inject a call to a function named
__sanitizer_cov_trace_pc on every edge. This function has to be defined
by us. By noting down the caller in that function we can trace the code
we have encountered during execution. Such information is used by
coverage guided fuzzers like AFL and LibFuzzer to determine if a new
input resulted in a new code path. This makes fuzzing much more
effective.

Additionally this adds a basic KCOV implementation. KCOV is an API that
allows user space to request the kernel to start collecting coverage
information for a given user space thread. Furthermore KCOV then exposes
the collected program counters to user space via a BlockDevice which can
be mmaped from user space.

This work is required to add effective support for fuzzing SerenityOS to
the Syzkaller syscall fuzzer. :^) :^)
2021-07-26 17:40:28 +02:00
Kenneth Myhra
7a4f59f638 LibC: Declare wide character type functions in wctype.h
Declares all wide character handling functions in wctype.h. All calls
are forwarded to the corresponding character handling function in
ctype.h.

These functions are declared, but not implemented:
- iswctype
- wctype
- towctrans
- wctrans

This should also resolve a build issue with the 'sed' port getting
confused with iswprint being declared twice. Seems like it expected
more functions from wctype.h and then had a backup strategy of adding
its own wctype.h.
2021-07-26 11:36:21 +02:00
Andreas Kling
1fcb1ec367 LibC: Randomize malloc() block addresses on x86_64
We have a lot of address space here, let's use it. :^)
2021-07-25 18:01:24 +02:00
brapru
8313d35749 Kernel: Support ioctl SIOCSARP and SIOCDARP
Creates ioctl calls necessary to set/delete an entry from the ARP table
2021-07-25 17:57:08 +02:00
Andreas Kling
09bc4cee15 Kernel: Remove unused madvise(MADV_GET_VOLATILE)
This was used to query the volatile state of a memory region, however
nothing ever actually used it.
2021-07-25 17:28:06 +02:00
Andreas Kling
2d1a651e0a Kernel: Make purgeable memory a VMObject level concept (again)
This patch changes the semantics of purgeable memory.

- AnonymousVMObject now has a "purgeable" flag. It can only be set when
  constructing the object. (Previously, all anonymous memory was
  effectively purgeable.)

- AnonymousVMObject now has a "volatile" flag. It covers the entire
  range of physical pages. (Previously, we tracked ranges of volatile
  pages, effectively making it a page-level concept.)

- Non-volatile objects maintain a physical page reservation via the
  committed pages mechanism, to ensure full coverage for page faults.

- When an object is made volatile, it relinquishes any unused committed
  pages immediately. If later made non-volatile again, we then attempt
  to make a new committed pages reservation. If this fails, we return
  ENOMEM to userspace.

mmap() now creates purgeable objects if passed the MAP_PURGEABLE option
together with MAP_ANONYMOUS. anon_create() memory is always purgeable.
2021-07-25 17:28:05 +02:00
Andreas Kling
1610669519 LibC: Make calloc() actually fail on multiplication overflow 2021-07-22 09:17:02 +02:00
Gunnar Beutner
3904541938 LibC: Don't truncate arguments for ioctl() on x86_64
Among other things this makes "less" work on x86_64.
2021-07-22 04:18:39 +04:30
Andreas Kling
f0409081f5 LibC: Simplify assertion failure dbgln() a bit
There's no need to say USERSPACE(PID) since dbgln() will prefix lines
with that information anyway.
2021-07-21 17:45:24 +02:00
Peter Elliott
2ce8cca7b5 LibC: Implement flock(2) using fcntl's F_SETLK
While flock is not a posix interface, it exists on linux and all BSDs as
far as I am aware.
2021-07-20 17:44:30 +04:30
Peter Elliott
3fa2816642 Kernel+LibC: Implement fcntl(2) advisory locks
Advisory locks don't actually prevent other processes from writing to
the file, but they do prevent other processes looking to acquire and
advisory lock on the file.

This implementation currently only adds non-blocking locks, which are
all I need for now.
2021-07-20 17:44:30 +04:30
Kenneth Myhra
afb47d1741 LibC: Add stub for iswprint
Without the declaration of iswprint libarchive will not compile.
2021-07-19 16:24:15 +02:00
Peter Bindels
0a0089fc11 LibC strtod: Reduce incremental error to nearly nothing
Instead of scaling by 1/10th N times, scale 10^N and then divide by
that. Avoid doing this beyond double-infinity. This decreases the
progressive error for numbers outside of integer range immensely. Not
a full 100% fix; there is still a single ULP difference detected by a
Javascript test
2021-07-18 12:45:10 +01:00
Jean-Baptiste Boric
ad6c385c9e LibC: Fix grp.h includes
That header file uses FILE*, which is defined in bits/FILE.h.

Fixes #8827.
2021-07-17 13:00:33 +02:00
Peter Bindels
a5a62f99c5 LibC: Use 64-bit stack smash value for 64-bit mode
Otherwise it'll use the first 32 bits that happen to come after,
leading to very weird bugs. Fixes #8601
2021-07-17 01:45:20 +02:00
Peter Bindels
85c2ad94d5 LibC: Make scanf always copy its va_list
On x86_64 GCC implements va_list as an array. This makes the syntax
for taking a pointer to it break & crash. The workaround / solution is
to create a copy. Since va_list is a tiny struct referencing the
actual varargs, this is little overhead (especially compared to
va_args itself)
2021-07-17 00:43:34 +02:00
Gunnar Beutner
d83c672926 LibC: Don't include AK headers in system headers
AK/Platform.h might not be available when building the toolchain.
2021-07-15 23:51:59 +02:00
M4x1m3
927f6ea221 LibC: Add putgrent 2021-07-15 11:16:58 +02:00
Daniel Bertalan
a88f7c99fe LibC: Use our implementation of crti.o and crtn.o
We have had these for quite a while, but we didn't compile them, and
used GCC's version instead. Clang does not come with these, so we have
to provide our own implementation.

Our implementation follows what `musl` and `FreeBSD` do, so this should
work fine, even if documentation can hardly be found for them.
2021-07-14 13:12:25 +02:00
Gunnar Beutner
4cf24c6ba2 Userland: Prefer using ARCH() over __LP64__ 2021-07-13 23:19:33 +02:00
Linus Groh
552185066e LibC: Use C-style void cast in assert() 2021-07-13 19:02:20 +01:00
Gunnar Beutner
5f3773b715 LibC: Increase minimum alignment for malloc() to 16 bytes
This is required to make SSE instructions work when building with
Clang. Apparently Clang uses SSE instructions where GCC didn't so
we didn't previously run into this problem.
2021-07-13 17:31:22 +02:00
Ali Mohammad Pur
f9fed0b167 LibRegex+LibC: Make re_nsub available to the user
To comply with Dr.POSIX, this field has to be user-accessible.
2021-07-13 07:04:06 +02:00
Linus Groh
15d5c62915 LibC: Replace use of do/while in assert() with the ternary operator
It's a single expression, no do/while needed. This makes assert() work
with the comma operator (assert(foo), assert(bar), assert(baz)).
Found because exactly this is being used somewhere in the guts of LLVM.
2021-07-12 22:33:28 +01:00
Andrew Kaster
6ba87a6b5e LibC: Use correct macro to disable assert()
The C standard doesn't say anything about DEBUG, just NDEBUG :^)
2021-07-12 12:26:52 +02:00
Hendiadyoin1
a8d86cc533 DynamicLoader+LibC: Make _start a naked function 2021-07-11 17:07:20 +02:00
Gunnar Beutner
06883ed8a3 Kernel+Userland: Make the stack alignment comply with the System V ABI
The System V ABI for both x86 and x86_64 requires that the stack pointer
is 16-byte aligned on entry. Previously we did not align the stack
pointer properly.

As far as "main" was concerned the stack alignment was correct even
without this patch due to how the C++ _start function and the kernel
interacted, i.e. the kernel misaligned the stack as far as the ABI
was concerned but that misalignment (read: it was properly aligned for
a regular function call - but misaligned in terms of what the ABI
dictates) was actually expected by our _start function.
2021-07-10 01:41:57 +02:00
Gunnar Beutner
5662e72126 LibC: Make sure crt0 and crt0_shared are built before LibC
We need these two object files in order for ld to work.

Fixes #4538.
2021-07-09 21:56:21 +02:00
Ali Mohammad Pur
727403746f LibC: Make makedev()/minor()/major() static
As we've opted to make these inline functions and not macros, let's at
least make sure that the users don't *observe* multiple definitions of
these functions.
2021-07-09 15:36:50 +02:00
Andreas Kling
e5a1e535cc LibC: Re-run clang-format on malloc.cpp 2021-07-09 14:14:22 +02:00
Andreas Kling
19cb5ed97a LibC: Simplify locking in malloc
- Use a simple pthread_mutex_t instead of bringing in headers from
  LibThreading just to get a mutex.

- Use a normal mutex instead of a recursive one.

- Remove redundant locking in realloc().
2021-07-09 13:47:32 +02:00
Andreas Kling
b8a204c5b9 LibThreading: Rename Lock => Mutex 2021-07-09 11:15:50 +02:00
Daniel Bertalan
5208bc05ce LibC: Don't include fenv.h from float.h
This fixes a build issue where `compiler-rt` tried to declare its own
version of the `FE_*` macros, and included `float.h` in order to get the
constants. `compiler-rt` tried to declare these as an enum, and failed
with a syntax error when the constant's literal values were substituted.
2021-07-08 10:11:00 +02:00
Daniel Bertalan
98260c5862 LibC+Utilities: Add gnu::format attributes
Without these attributes present on these custom formatting functions,
Clang would warn use about nonliteral format strings. As an added bonus,
we now get type checking on these.
2021-07-08 10:11:00 +02:00
Sergey Bugaev
65b0642dd0 LibC+LibPthread: Use FUTEX_PRIVATE_FLAG in more places
Performance go brrrrr
2021-07-07 17:08:40 +02:00
Edwin Hoksberg
99328e1038 Kernel+KeyboardSettings: Remove numlock syscall and implement ioctl 2021-07-07 10:44:20 +02:00
Edwin Hoksberg
385e2ccb66 Kernel: Add keyboard ioctl to get num/caps lock state 2021-07-07 10:44:20 +02:00
Sergey Bugaev
30caa33f7e LibC: Only set owner on recursive mutexes
This lets us skip the gettid() calls on fast paths.

Also, verify that futex_wake() succeeds.
2021-07-06 17:25:34 +02:00
Andreas Kling
565796ae4e Kernel+LibC: Remove sys$donate()
This was an old SerenityOS-specific syscall for donating the remainder
of the calling thread's time-slice to another thread within the same
process.

Now that Threading::Lock uses a pthread_mutex_t internally, we no
longer need this syscall, which allows us to get rid of a surprising
amount of unnecessary scheduler logic. :^)
2021-07-05 23:30:15 +02:00
Andreas Kling
90e5fd5b53 LibC+LibPthread: Add PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
This is a common but non-standard way of initializing a pthread_mutex_t
in recursive mode.
2021-07-05 23:30:15 +02:00
Sergey Bugaev
00d8dbe739 LibPthread: Reimplement condition variables
This implementation features a fast path for pthread_cond_signal() and
pthread_cond_broadcast() for the case there's no thread waiting, and
does not exhibit the "thundering herd" issue in
pthread_cond_broadcast().

Fixes https://github.com/SerenityOS/serenity/issues/8432
2021-07-05 20:26:01 +02:00
Sergey Bugaev
5536f3c277 LibC: Add __pthread_mutex_lock_pessimistic_np()
This is a private function that locks the lock much like the regular
pthread_mutex_lock(), but causes the corresponding unlock operation to
always assume there may be other waiters. This is useful in case some
waiters are made to wait on the mutex's futex directly, without going
through pthread_mutex_lock(). This is going to be used by the condition
variable implementation in the next commit.
2021-07-05 20:26:01 +02:00
Sergey Bugaev
19bef90923 LibC: Rewrite pthread_mutex
pthread_mutex is now an actual "sleeping" mutex, and not just a
spinlock! It still has a fast path that only uses atomics and (in the
successful case) returns immediately without sleeping. In case of
contention, it calls futex_wait(), which lets the kernel scheduler put
this thread to sleep, *and* lets it know exactly when to consider
scheduling it again.
2021-07-05 20:26:01 +02:00
Sergey Bugaev
8fee93d868 LibC: Add futex_wait() and futex_wake() helpers
These are convinient wrappers over the most used futex operations.
futex_wait() also does some smarts for timeout and clock handling.

Use the new futex_wait() instead of a similar private helper in
LibPthread.
2021-07-05 20:26:01 +02:00