Commit Graph

460 Commits

Author SHA1 Message Date
Jelle Raaijmakers
380c42c405 LibC: Add getpriority() and setpriority() stubs
Expected behavior left as a FIXME is outlined here:
https://pubs.opengroup.org/onlinepubs/7908799/xsh/getpriority.html
2021-09-23 18:51:21 +02:00
Jelle Raaijmakers
a6539cc031 LibC: Add chroot() stub
Expected behavior left as a FIXME is described here:
https://pubs.opengroup.org/onlinepubs/7908799/xsh/chroot.html

It is marked as LEGACY but still used in projects such as PHP.
2021-09-23 18:51:21 +02:00
Itamar
a3360bcee8 LibC+DynamicLoader: Store the auxiliary vector address at startup
Previously, getauxval() got the address of the auxiliary vector by
traversing to the end of the `environ` pointer.

The assumption that the auxiliary vector comes after the environment
array is true at program startup, however the environment array may
be re-allocated and change its address during runtime which would cause
getauxval() to work with an incorrect auxiliary vector address.

To fix this, we now get the address of the auxiliary vector once in
__libc_init and store it in a libc-internal pointer which is then used
by getauxval().

Fixes #10087.
2021-09-20 18:32:09 +02:00
Kenneth Myhra
3b901e5b2b LibC: Spec compliant IN6_IS_ADDR_V4MAPPED
An IPv4 mapped IPv6 address consist of 80 "0" bits, followed by 16 "1"
bits, followed by the 32-bit IPv4 address.

Example of IPv4 mapped IPv6 address:
IPv4 address: 169.219.13.133
IPv6 address: 0000:0000:0000:0000:FFFF:A9DB:0D85
Simplified  : ::FFFF:A9DB:0D85
2021-09-20 15:26:46 +02:00
Andrew Kaster
da87497e61 AK+LibC: Remove SERENITY_LIBC_BUILD guard around <initializer_list>
This was required before commit 5f724b6ca1
when we were building LibC before libstdc++ headers were available in
the sysroot. However as noted in that commit, we never actually needed
to be building LibC before libstdc++, so we can go ahead and remove this
ancient hack.
2021-09-20 00:39:46 +00:00
Kenneth Myhra
c7422dcef7 LibC: Declare IN6_IS_ADDR_V4MAPPED correctly
When using the IN6_IS_ADDR_V4MAPPED macro in Serenity's LibC it would
fail when compiling with the error message:
'invalid type argument of '->''.

This patch corrects the macro so that e.g. GLib port can compile again.
2021-09-19 15:53:43 +02:00
Tim Schumacher
b9979e9a59 LibC: Implement most langinfo values mentioned in POSIX 2021-09-18 03:12:58 +00:00
Tim Schumacher
b8c756a53a LibC: Primitively implement wcscoll
At the moment, sorting like LC_COLLATE=C would do is better than
nothing.
2021-09-18 02:57:56 +00:00
Jean-Baptiste Boric
8043fcd466 LibC: Don't format strings when asserting with an unstable heap
If we hit an assertion while the heap isn't in a stable state, we can't
rely on dynamic memory allocation because the malloc mutex is already
held and the heap is most likely corrupted. Instead, we need to bail
out fast before we make the situation even worse.
2021-09-18 01:35:11 +00:00
Tim Schumacher
42031f026a LibC: Implement towctrans 2021-09-17 22:59:51 +00:00
Tim Schumacher
8c7b566629 LibC: Implement iswctype 2021-09-17 22:59:51 +00:00
Tim Schumacher
ff0ab8b9a9 LibC: Implement wctrans 2021-09-17 22:59:51 +00:00
Tim Schumacher
7b17230d7a LibC: Implement wctype 2021-09-17 22:59:51 +00:00
Tim Schumacher
ac406c8d0e LibC: Change wctrans_t to be a long instead of int*
The POSIX manpage just says that wctrans_t should be "a scalar type that
can hold values which represent locale-specific character mappings", and
doing switch statements with ints is much more pleasant than with
pointers.
2021-09-17 22:59:51 +00:00
Brian Gianforcaro
07b314e843 Kernel+LibC: Pack SC_stat_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
be15bd3c86 Kernel+LibC: Pack SC_mount_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
dcb327a83b Kernel+LibC: Pack SC_setsockopt_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
9956607283 Kernel+LibC: Pack SC_accept4_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
b45ca5d56e Kernel+LibC: Pack SC_inode_watcher_add_watch_params struct better
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Tim Schumacher
a1617faf44 LibC: Implement mbsinit and mbrtowc 2021-09-16 16:42:40 +02:00
Tim Schumacher
405f3d0aa3 LibC: Implement btowc() 2021-09-16 16:42:40 +02:00
Tim Schumacher
e4fa9c917e LibC: Stub out a bunch of wchar functions 2021-09-16 16:42:40 +02:00
Tim Schumacher
230df61aef LibC: Define ptrdiff_t limits 2021-09-16 16:42:40 +02:00
Tim Schumacher
328818af97 LibC: Provide a dummy mbstate_t in wchar.h
POSIX just says that mbstate_t should be an "object type other than an
array type" that can hold the conversion state for converting between
(multi-byte) characters and wide characters.

Since no other information regarding the contents is given, this
apparently means that we should add whatever we need once we start
implementing that conversion.
2021-09-16 16:42:40 +02:00
Tim Schumacher
8f9af4a582 LibC: Implement CODESET for langinfo 2021-09-16 16:42:40 +02:00
Andrew Kaster
b5c98ede08 Meta: Switch to a SuperBuild that splits host and target builds
Replace the old logic where we would start with a host build, and swap
all the CMake compiler and target variables underneath it to trick
CMake into building for Serenity after we configured and built the Lagom
code generators.

The SuperBuild creates two ExternalProjects, one for Lagom and one for
Serenity. The Serenity project depends on the install stage for the
Lagom build. The SuperBuild also generates a CMakeToolchain file for the
Serenity build to use that replaces the old toolchain file that was only
used for Ports.

To ensure that code generators are rebuilt when core libraries such as
AK and LibCore are modified, developers will need to direct their manual
`ninja` invocations to the SuperBuild's binary directory instead of the
Serenity binary directory.

This commit includes warning coalescing and option style cleanup for the
affected CMakeLists in the Kernel, top level, and runtime support
libraries. A large part of the cleanup is replacing USE_CLANG_TOOLCHAIN
with the proper CMAKE_CXX_COMPILER_ID variable, which will no longer be
confused by a host clang compiler.
2021-09-15 19:04:52 +04:30
Andreas Kling
5b19e9239a LibC: Upgrade memmove() to memcpy() when possible
We were missing out on opportunities to use memcpy() instead of
memmove() when the source and destination don't overlap.
2021-09-13 19:11:33 +02:00
Brian Gianforcaro
43f4292ca0 LibC: Implement explicit_bzero with AK::secure_zero 2021-09-13 00:02:42 +02:00
Liav A
8d0dbdeaac Kernel+Userland: Introduce a new way to reboot and poweroff the machine
This change removes the halt and reboot syscalls, and create a new
mechanism to change the power state of the machine.
Instead of how power state was changed until now, put a SysFS node as
writable only for the superuser, that with a defined value, can result
in either reboot or poweroff.
In the future, a power group can be assigned to this node (which will be
the GroupID responsible for power management).

This opens an opportunity to permit to shutdown/reboot without superuser
permissions, so in the future, a userspace daemon can take control of
this node to perform power management operations without superuser
permissions, if we enforce different UserID/GroupID on that node.
2021-09-12 11:52:16 +02:00
TheFightingCatfish
a81b21c1a7 Kernel+LibC: Implement fsync 2021-09-12 11:24:02 +02:00
Idan Horowitz
6704961c82 AK: Replace the mutable String::replace API with an immutable version
This removes the awkward String::replace API which was the only String
API which mutated the String and replaces it with a new immutable
version that returns a new String with the replacements applied. This
also fixes a couple of UAFs that were caused by the use of this API.

As an optimization an equivalent StringView::replace API was also added
to remove an unnecessary String allocations in the format of:
`String { view }.replace(...);`
2021-09-11 20:36:43 +03:00
Liav A
04ba31b8c5 Kernel+Userland: Remove loadable kernel moduless
These interfaces are broken for about 9 months, maybe longer than that.
At this point, this is just a dead code nobody tests or tries to use, so
let's remove it instead of keeping a stale code just for the sake of
keeping it and hoping someone will fix it.

To better justify this, I read that OpenBSD removed loadable kernel
modules in 5.7 release (2014), mainly for the same reason we do -
nobody used it so they had no good reason to maintain it.
Still, OpenBSD had LKMs being effectively working, which is not the
current state in our project for a long time.
An arguably better approach to minimize the Kernel image size is to
allow dropping drivers and features while compiling a new image.
2021-09-11 19:05:00 +02:00
Ali Mohammad Pur
5a0cdb15b0 AK+Everywhere: Reduce the number of template parameters of IntrusiveList
This makes the user-facing type only take the node member pointer, and
lets the compiler figure out the other needed types from that.
2021-09-10 18:05:46 +03:00
Rodrigo Tobar
2c22ff94b4 LibC: Define RLIM_NLIMITS constant
This is required by programs that want to either iterate over all
resources, or check that a resource identifier is valid before passing
it down.
2021-09-10 00:00:03 +02:00
Andreas Kling
c93687c15e LibC: Make remove() propagate non-EISDIR unlink() errors
Regressed in 16105091ba.
2021-09-09 21:49:49 +02:00
Andreas Kling
16105091ba LibC: Remove a bunch of pointless rc temporaries in stdio.cpp 2021-09-09 21:25:10 +02:00
Andreas Kling
6ad427993a Everywhere: Behaviour => Behavior 2021-09-07 13:53:14 +02:00
Andrew Kaster
fe701052ea LibC: Expand region for global destructors when it reaches capacity
In 553361d we started mprotecting the atexit handlers when they are not
being modified or executed. As part of that commit, we unintentionally
changed the max number of global destructors from 1024 to 256 (on x86,
only 128 on x86_64). This patch expands the initial size of the global
destructors page to 2 pages from 1, and allows the pool to be expanded
at runtime by mapping a new set of pages and copying the AtExitEntries
over.
2021-09-06 01:55:14 +02:00
Ali Mohammad Pur
3a9f00c59b Everywhere: Use OOM-safe ByteBuffer APIs where possible
If we can easily communicate failure, let's avoid asserting and report
failure instead.
2021-09-06 01:53:26 +02:00
Peter Elliott
33d7fdca28 Everywhere: Use my cool new @serenityos.org email address 2021-09-01 11:37:25 +04:30
Andreas Kling
af9d4281eb LibC: Run clang-format on setjmp.h 2021-08-31 01:37:30 +02:00
Dimenus
de0861581e Userland: Guard set_jmp.h static_assert check to cpp impls only 2021-08-31 00:47:18 +02:00
Nico Weber
bbad4758b2 CMake: Let Meta/serenity.sh run aarch64 make it past cmake
This adds just enough scaffolding to make cmake succeed.
The build falls over immediately.
2021-08-28 14:43:07 +01:00
Nico Weber
7052f403c8 Toolchain: Enough to make rebuild-toolchain aarch64 work
The gcc patch might not be completely correct, but at least the
toolchain completes building.
2021-08-28 14:43:07 +01:00
kleines Filmröllchen
d0ceaa24a6 Kernel: Implement ioctl for the SB16 to change sample rate
Two new ioctl requests are used to get and set the sample rate of the
sound card. The SB16 device keeps track of the sample rate separately,
because I don't want to figure out how to read the sample rate from the
device; it's easier that way.

The soundcard write doesn't set the sample rate to 44100 Hz every time
anymore, as we want to change it externally.
2021-08-27 23:35:27 +04:30
Jean-Baptiste Boric
0248e6ae27 LibC: Check for expected size of struct __jmp_buf
This structure is accessed through assembly code inside setjmp.S, make
some effort to ensure both header and assembly files are in sync.
2021-08-26 00:54:23 +02:00
Jean-Baptiste Boric
295e89af04 LibC: Fix sigsetjmp on x86_64
Registers were clobbered, offset values into __jmp_buf were wrong...
2021-08-26 00:54:23 +02:00
Jean-Baptiste Boric
c87aa6d908 LibC: Fix sigsetjmp on i686
Calling sigprocmask() through the PLT requires setting the ebx register
to the address of the global offset table, otherwise chaos ensues. Also
the value of the ecx register was assumed to be preserved across that
function call despite the fact that it is caller-saved in the x86
calling convention.
2021-08-26 00:54:23 +02:00
Maciej Zygmanowski
7237972022 LibC: Support getsignalbyname() with full signal name
This allows e.g. to use `kill` with names like -SIGKILL, not only -KILL.
2021-08-22 15:23:25 +02:00
Peter Elliott
ee0c6e1b6d LibC: Add <sys/poll.h> as an alias for <poll.h>
<poll.h> was originally <sys/poll.h> and some old software like X11
still uses the old path.
2021-08-22 10:29:06 +02:00