1084 Commits

Author SHA1 Message Date
Sönke Holz
e6fe911bd7 LibC: Properly set termios flags in cfmakeraw()
OPOST is an c_oflag flag.
Similarly, ECHO, ECHONL etc. are c_lflag flags.
2026-04-07 14:51:25 +02:00
Sönke Holz
fb229083d7 LibC: Implement fegetenv() and fesetenv() on AArch64
These functions simply store/restore the floating-point control and
status flags.
2026-04-06 07:38:12 -04:00
Sönke Holz
24a7479c43 LibC: Implement fegetround() and fesetround() on AArch64
This is based on the RISC-V implementation.
2026-04-06 07:38:12 -04:00
Sönke Holz
e794250eee LibC: Add missing __{BEGIN,END}_DECLS to float.h
I noticed this while trying to compile a standalone lagom libm.so from
LibC's math.cpp for testing.
Before, this would fail with a "conflicting declaration" error since
the fegetround() declaration wasn't `extern "C"`.
2026-03-22 10:21:57 -04:00
Sönke Holz
835be1085d LibC: Reorder definitions in endian.h to match POSIX spec order
No behavior change. This makes it a bit easier to compare the header
with the POSIX spec.
2026-02-26 23:09:53 +01:00
Sönke Holz
e2a5a212e0 LibC: Use byte order definitions from the compiler
Instead of defining LITTLE_ENDIAN and BIG_ENDIAN ourselves, we should
use the definitions from the compiler.

Additionally, we don't have <bits/endian.h>, so it's never correct to
include that header.
2026-02-26 23:09:53 +01:00
Sönke Holz
051985c46b LibC: Add some POSIX spec comments to endian.h 2026-02-26 23:09:53 +01:00
Sönke Holz
e8133a43fa LibC: Remove PDP_ENDIAN
I don't expect SerenityOS to ever run on a PDP-11. This definition is
not required by POSIX either.
2026-02-26 23:09:53 +01:00
Sönke Holz
c3564fdb0f LibC: Remove __bswap{16,32,64}
These definitions are unused and not required by POSIX.
2026-02-26 23:09:53 +01:00
Sönke Holz
227ee20f3c LibC: Remove {le,be}toh{16,32,64}
These definitions appear to be unused and are not required by POSIX.
They appear to be specific to OpenBSD and do not seem to exist on any
other system.
2026-02-26 23:09:53 +01:00
Sönke Holz
a718987a01 LibC: Don't check for feature test macros in endian.h
We don't check for feature test macros in any other LibC header, and
especially not for _GNU_SOURCE or _BSD_SOURCE. With no feature test
macro defined, this header would previously essentially be empty.

POSIX doesn't seem to require any feature test macros for this header
either.
2026-02-26 23:09:53 +01:00
Sönke Holz
020b01a014 LibC: Remove __attribute__((weak)) from some symbols
These symbols don't need to be weak. They aren't overridden anywhere.
2026-02-24 13:52:50 +01:00
Sönke Holz
322e6575de LibC: Define CHAR_{MIN,MAX} correctly if char is unsigned 2026-02-08 15:51:33 +01:00
Sönke Holz
de5452add5 Meta+LibC: Stop building with -Wno-type-limits on AArch64
This only required one change in LibC. Wrapping that code in an
`if constexpr` block isn't enough to stop the compiler from complaining.
2026-02-08 15:51:33 +01:00
Lucas CHOLLET
e8dbbc3cd7 LibC: Support null argv and envp in execve
Either of these two parameters being null would previously invoke UB.

The Kernel still rejects null argv so this commit only makes calls with
a null `envp` actually work.
2025-12-09 17:38:58 +01:00
Linus Groh
ffa3524e33 LibC: Move a handful of functions into <sys/stat.h>
I'm not sure why they were defined elsewhere, POSIX tells us where they
belong.

This fixes the coreutils port, which currently fails with an 'undeclared
function' error.
2025-12-06 14:15:52 -05:00
Lucas CHOLLET
43541ba1aa LibC: Make NAN be a float
As per cpp reference:
> The macro NAN expands to a constant expression of type `float`
2025-11-21 01:13:36 +01:00
Lucas CHOLLET
e4c989e45f LibC: Remove two unused functions from serenity.{h,cpp} 2025-11-09 11:47:59 -05:00
Linus Groh
2a9154e77c Kernel+LibC+Profiler: Replace readv syscall with preadv
We already use pwritev to implement writev, so let's do the same for
readv. This resolves the awkward situation of having pwritev but not
preadv, which affects Zig for instance.
2025-10-31 21:59:30 -04:00
Nico Weber
0cd71f1d91 Everywhere: Use AK::mod() more, and add a test
The tests show that mod(a, b) takes on the sign of b while
a % b takes on the sign of a. As b is usually a positive constant,
mod() is useful when you want a guaranteed positive result.

mod() matches the semantics of % in Python.

Also, mod(a, b) == mod(a, abs(b)) modulo b, while
a % b != abs(a) % b modulo b. So mod() makes it easier to get a
guaranteed-positive result even if the sign of b is unknown.

No behavior change.
2025-10-15 07:56:51 -04:00
Sönke Holz
138057adb2 LibC: Use sys$posix_spawn for posix_spawnp if possible 2025-10-12 22:31:02 +02:00
Lucas CHOLLET
0ff1f39b8b Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-20 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")
2025-10-10 00:02:50 +02:00
Sönke Holz
eb978a5053 Everywhere: Use my fancy new serenityos.org email address :^) 2025-10-09 20:48:14 +02:00
Sönke Holz
1cfea3a620 LibC: Use the posix_spawn syscall if file_actions is non-null but empty
This results in the posix_spawn system call being used in more cases.
2025-09-27 16:54:28 -04:00
Tomás Porto da Rocha Simões
41c204542f LibC: Make posix_spawn() wrapper call sys$posix_spawn
Make posix_spawn() use the more efficient syscall if there are no file
actions or spawnattr.
2025-09-27 20:13:27 +02:00
Lucas CHOLLET
45232a0f16 Toolchain/GCC+LibC: Stop linking against crt0_shared
This makes GCC and Clang equal on that side and thus allows us to get
rid of most GCC-only branches in LibC/CMakeLists.txt.
2025-09-01 14:56:12 +02:00
Lucas CHOLLET
b140d3af2f Toolchain/GCC+LibC: Stop linking against crti and crtn
This doesn't seem to be used at all.
2025-09-01 14:56:12 +02:00
implicitfield
9c51b90a1b LibC: Make time_to_tm() use days_since_epoch_to_date() 2025-08-31 14:04:15 -04:00
implicitfield
a5bc3594f9 Tests+LibC: Add tests for sig2str() and str2sig()
Now we also assert that signal names fit within SIG2STR_MAX.
2025-08-08 19:07:23 -04:00
implicitfield
c19feacccf LibC: Implement fgetspent(3) 2025-08-07 21:34:32 -04:00
implicitfield
59911d8da3 LibC: Remove the non-standard internet_checksum()
This has been replaced by Crypto::Checksum::IPv4Header.
2025-08-07 21:34:32 -04:00
implicitfield
64de6f03e2 LibC: Remove getsignalbyname() and getsignalname()
These have been replaced by `sig2str()` and `str2sig()`.
2025-08-07 21:34:32 -04:00
implicitfield
9b8ec9646a LibC+Kernel: Implement sig2str(3) and str2sig(3) 2025-08-07 21:34:32 -04:00
Sönke Holz
5cdae14b18 LibC: Make {sigset,set,long}jmp symbols STT_FUNC 2025-07-24 13:29:56 +02:00
Jelle Raaijmakers
c5011889bd LibC: Pull in timespec in signal.h instead of including time.h
According to POSIX, we must define `timespec`, but we _may_ include
`time.h` in doing so. Compiling ScummVM 2.9.1 against LibC was failing
because compared to glibc, we were pulling in `time.h` too early which
caused conflicts in ScummVM's `common/forbidden.h`.
2025-07-03 00:14:23 +02:00
Sönke Holz
6c62fd2b0d LibC: Remove unnecessary include from arch/{riscv64,x86_64}/setjmp.S 2025-06-21 12:55:20 +02:00
Sönke Holz
631f3b2727 LibC: Use correct signal mask jmp_buf offsets for riscv64
I forgot to change these offsets in a203837b1f.
2025-06-21 12:55:20 +02:00
Sönke Holz
cc6d0fb858 LibC: Implement setjmp and longjmp for aarch64
This implementation is based on the riscv64 version.
2025-06-21 12:55:20 +02:00
Sönke Holz
a1f7857a7d Kernel/riscv64: Add an archctl option to get the extension bitmask 2025-06-03 14:09:21 +02:00
Linus Groh
a1bff1e1b6 LibC: Improve symbol visibility and naming consistency
This is largely inspired by https://github.com/ziglang/zig/issues/23879.
2025-05-29 20:15:22 -04:00
Sönke Holz
2f2a06d925 LibC: Correctly reset the getopt state on optind = 0
515f31339c incorrectly made getopt only reset its state when `optind`
is set to 1. However, the Linux man page says that setting it to 0 also
reinitializes its state and additionally checks for some GNU extensions.
stress-ng relies on this behavior.

The POSIX man page only says that setting it to 0 results in undefined
behavior.
2025-05-21 18:45:13 -04:00
Linus Groh
17840038f2 LibC: Break include cycle between signal.h and time.h
See: https://github.com/SerenityOS/serenity/pull/25925#issuecomment-2867972802
2025-05-10 14:09:05 +02:00
hiperbolt
b9e23f36cc LibC: Remove strtold impossible assert
Removed the impossible assertion of sizeof(double) == sizeof(long
double) in strtold. This fixes the crash but suffers from lack of
precision.
Our eisel-lemire implementation on FloatingPointStringConversions needs
a big overhaul to work properly with long doubles, especially with x87
80-bit extended precision format.

Fixes #25791
2025-05-07 06:18:18 -04:00
matyalatte
2c28cedf13 LibC: Add imaxabs 2025-04-28 17:41:43 -04:00
Bananymous
1c45ac5fc2 LibC: Don't allow pthread_spin_lock() to steal a lock 2025-04-28 14:10:33 +02:00
NoobZang
3ecadc4766 LibC: Implement guard page for pthread 2025-04-28 08:17:09 +02:00
Sönke Holz
5b78579a61 LibC: Add missing include in utime.h
<sys/types.h> declares the `utimbuf` struct used by this header.

Fixes #25899
2025-04-23 19:22:40 -04:00
Dan Klishch
fc0826cfa9 Meta+Toolchain: Symlink LibC headers into sysroot in Build{Clang,GNU}.sh
This avoids "[system_headers] install: X/Z and Y/Z are the same file"
error in these scripts when they are run against a prepopulated sysroot.

As a bonus, this slightly decreases toolchain build time as find +
install were taking a disproportionally long time before.
2025-04-22 08:40:37 -06:00
Dan Klishch
b004d172b5 LibC: Provide a more complete list of headers that are used by libc
While this is most likely still not a transitive closure of headers used
by libc itself, this list suffices for libc++ and libstdc++ to compile
if restricted to it.
2025-04-22 08:40:37 -06:00
matyalatte
da73013dd6 LibC: Replace llroundd with llroundl 2025-04-21 11:07:53 -04:00