Commit Graph
204 Commits
Author SHA1 Message Date
Sönke Holz 77f058c32e Everywhere: Remove iOS support
Now that ladybird was hard-forked from SerenityOS, there's no good
reason to keep supporting iOS.

Ladybird only still exists in the SerenityOS repo to make testing LibWeb
easier.
2026-04-06 15:44:56 +02:00
Liav A. 2a4a096e0f Kernel+runc: Make unshare syscalls more fd-oriented
Instead of creating a new resource that has its own ID number and work
with it directly, we can create a file that describes the unshared
resource, execute ioctl calls on it and only enter into it in the end,
essentially creating the resource only during the last call instead
of the previous method of creation of a resource when "attaching" to
that resource.

We can enter a resource for current program execution, after the exec
syscall, or both.
That change allows userspace to create a resource and attach to it only
in the new program, which makes it more comfortable to do cleanups or
track the new process, outside of the created container.

It should be noted that until this commit, we entered a resource without
detaching the old one, essentially leaking the attach counter of a
resource. While this bug didn't have severe effects, it was obvious that
a proper cleanup userspace code later on wouldn't work in that situation
anyway, so this commit changes the way we work, and the terminology of
entering a resource is actually to **replace** it.

These changes essentially open an opportunity to extend runc to be a
container manager rather being launcher of a containerized environment,
which makes it possible to do all sorts of nice cleanups and tracking of
containers' states.
2026-03-14 11:45:37 +01:00
Andreas Kling 64eff8f658 LibCore: Fix memory leak in anon_create() on BSD/macOS
The mmap() call here served no purpose - anon_create() is only meant to
create and return a file descriptor. The actual mapping is done later
by AnonymousBufferImpl::create().

This leaked an mmap of `size` bytes for every AnonymousBuffer created,
which includes backing stores, shareable bitmaps, and more.

(cherry picked from commit 07630f3b0c4e08771a75edcc68ab3fdbc8948b2f)
2026-01-22 19:55:50 -05:00
po-nuvai 71780ed7a7 LibCore: Retry read() and write() syscalls on EINTR
When a read or write syscall is interrupted by a signal, it returns -1
with errno set to EINTR. Following POSIX conventions, we should retry
the syscall in this case rather than propagating the error.

This matches the existing behavior in Core::File::close() which already
handles EINTR by retrying in a loop.

Fixes #26500
2025-12-29 07:59:38 -05:00
implicitfield d1648b01c0 LibCore: Remove the getspent(3) wrapper
This is a bit of a footgun, since this isn't implemented properly on
musl. It can now be removed entirely as nothing uses it anymore.
2025-08-07 21:34:32 -04:00
implicitfield 478b576b67 LibCore: Stop using getspent(3)
musl doesn't implement getspent(3) properly - as its implementation
looks like this:
```
struct spwd *getspent()
{
        return 0;
}
```
To get around this, this patch makes Core::getspnam() actually
use getspnam(3) (rather than looping over getspent(3)), and makes
Account::generate_shadow_file() use fgetspent(3).
2025-08-07 21:34:32 -04:00
Timothy Flynn b385e357cd LibCore: Always reset the polled revents field back to 0
One benefit of using `poll` over `select` is that we can re-use the poll
structure list. But there's no guarantee that the underlying system will
reset the `revents` field back to 0. So let's explicitly do so.

(cherry picked from commit f46b721c57b9ccde9ad3de3034f626e0a7607e92,
tweaked due to additional Userland/ prefix in path)
2025-08-07 14:04:06 +02:00
Andrew Kaster f97e5a7088 LibCore: Only include BeepInstruction in System.cpp on Serenity
(cherry picked from commit f98e28912a9c700e78f6e57eb497fd3eb3134661;
amended to not delete BeepInstruction.h, and to not insert a stray
newline after lstat)
2024-11-15 08:56:56 -05:00
Asutosh Variar 50cc1b5d63 Everywhere: Convert from_string_view -> from_string_literal where static
(cherry picked from commit 229b64a4b723a391c21f247d72d78cd575ace6ff;
minorly amended to fix conflict in image.cpp due to serenity in the
meantime adding webp writing support, and due to changes in Android and
Vulkan-related files that serenity doesn't have)
2024-11-15 08:56:39 -05:00
Jelle Raaijmakers 2ce1b1af9b LibCore: Add System::physical_memory_bytes()
(cherry picked from commit 9515290fde3c973226c9737cbd055ebd85df7101)
2024-11-12 22:26:21 -05:00
Jonne Ransijn 095c076941 LibCore: Respect system hard limit in set_resource_limits
This avoids an "Invalid argument (errno=22)" error
on systems with lower hard limits.

(cherry picked from commit c97af00355159b0dac9019b885af7c6016e75dc7)
2024-11-12 07:14:25 -05:00
Timothy Flynn 999f7c5eb5 LibCore: Ensure shared memory file names on macOS are unique
At least on my mac, clock_gettime only provides millisecond resolution.
So if many WebContent processes are opened at once, it is not unlikely
that they will all create their backing stores within the same ms. When
that happens, all but the first will fail (and crash).

To prevent this, generate the shared memory file name based on the PID
and a static counter.

(cherry picked from commit 5056bda043984953685bb4284fc698ab42418045)
2024-11-10 20:06:23 -05:00
Liav A. 952b681896 LibCore: Add a method to jail a program until calling the execve syscall
This will be used later on, within the Assistant program.
2024-10-03 12:39:45 +02:00
Liav A. b90a36d2a9 Kernel+Userland: Rename jailed => jailed_until_exit
In all instances, it should be clear that the jailing of a process is
ending when the process exits.

This is a preparation before introducing another option to set a process
as jailed until it calls the execve syscall.
2024-10-03 12:39:45 +02:00
Timothy Flynn 5d70ea62db LibCore: Use Error::from_syscall to report get/setrlimit errors
(cherry picked from commit 9e7e22dc74ff1bb99e0e8dff63128ef087623480)
2024-08-13 15:43:40 -04:00
Timothy Flynn f30192280f LibCore: Add system call wrappers around getrlimit and setrlimit
(cherry picked from commit 0d6115e8ae3b20371923dfdb22ad5b506582eaf1)
2024-07-29 01:01:11 -04:00
Liav A. aa01f52592 LibCore: Add System methods to handle the unshare syscall family
These 2 methods will be used later by the userspace implementation that
will handle creation of containers.
2024-07-21 11:44:23 +02:00
Liav A. 4370bbb3ad Kernel+Userland: Introduce the copy_mount syscall
This new syscall will be used by the upcoming runc (run-container)
utility.

In addition to that, this syscall allows userspace to neatly copy RAMFS
instances to other places, which was not possible in the past.
2024-07-21 11:44:23 +02:00
Liav A. dd59fe35c7 Kernel+Userland: Reduce jails to be a simple boolean flag
The whole concept of Jails was far more complicated than I actually want
it to be, so let's reduce the complexity of how it works from now on.
Please note that we always leaked the attach count of a Jail object in
the fork syscall if it failed midway.
Instead, we should have attach to the jail just before registering the
new Process, so we don't need to worry about unsuccessful Process
creation.

The reduction of complexity in regard to jails means that instead of
relying on jails to provide PID isolation, we could simplify the whole
idea of them to be a simple SetOnce, and let the ProcessList (now called
ScopedProcessList) to be responsible for this type of isolation.

Therefore, we apply the following changes to do so:
- We make the Jail concept no longer a class of its own. Instead, we
  simplify the idea of being jailed to a simple ProtectedValues boolean
  flag. This means that we no longer check of matching jail pointers
  anywhere in the Kernel code.
  To set a process as jailed, a new prctl option was added to set a
  Kernel SetOnce boolean flag (so it cannot change ever again).
- We provide Process & Thread methods to iterate over process lists.
  A process can either iterate on the global process list, or if it's
  attached to a scoped process list, then only over that list.
  This essentially replaces the need of checking the Jail pointer of a
  process when iterating over process lists.
2024-07-21 11:44:23 +02:00
Liav A. 91c87c5b77 Kernel+Userland: Prepare for considering VFSRootContext when mounting
Expose some initial interfaces in the mount-related syscalls to select
the desired VFSRootContext, by specifying the VFSRootContext index
number.

For now there's still no way to create a different VFSRootContext, so
the only valid IDs are -1 (for currently attached VFSRootContext) or 1
for the first userspace VFSRootContext.
2024-07-21 11:44:23 +02:00
Nico Weber bb2d80a2bb Everywhere: Gently remove the ladybird android port
With Ladybird now being its own repository, there's little reason
to keep the Ladybird Android port in the SerenityOS repository.

(The Qt port is useful to be able to test changes to LibWeb in lagom
so it'll stay around. Similar for the AppKit port, since getting
Qt on macOS is a bit annoying. But if the AppKit port is too much
pain to keep working, we should toss that too.

Eventually, the lagom browser ports should move out from Ladybird/
to Meta/Lagom/Contrib, but for now it might make sense to leave them
where they are to keep cherry-picks from ladybird easier.)
2024-06-11 19:40:08 -04:00
Romain Chardiny 892da127d0 LibCore: Add wrapper for fsync() 2024-05-31 13:49:34 +01:00
implicitfield 4574a8c334 Kernel+LibC+LibCore: Implement mknodat(2) 2024-05-14 22:30:39 +02:00
Shannon Booth 9c9a378455 LibCore: Implement Core::System::hardware_concurrency() 2024-04-06 07:20:22 +02:00
Timothy Flynn 40beebca71 LibCore: Apply the flags provided to System::pipe2 on all systems
We currently drop the flags on the floor for systems that do not have a
pipe2 syscall. Instead, use fcntl to set the flags.
2024-03-13 12:52:07 -04:00
Filiph Siitam Sandström fd694e8672 AK+Lagom: Make it possible to build for iOS
This commit makes it possible to build AK and most of Lagom for iOS,
based on the work for the Ladybird build demoed on discord:
https://discord.com/channels/830522505605283862/830525031720943627/1211987732646068314
2024-03-03 13:13:42 -07:00
Sam Atkins c2bc07ef7c LibCore: Use Core::Environment::raw_environ() instead of environment() 2024-02-27 08:33:48 +00:00
Sam Atkins 97cb9cf469 LibCore: Use Core::Environment instead of manually iterating environ 2024-02-27 08:33:48 +00:00
Sam Atkins 56b8e248a5 LibCore: Remove now-unused Core::System::*env() functions
These have been moved to Core::Environment.
2024-02-27 08:33:48 +00:00
Ali Mohammad Pur 5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Dan Klishch d317309d89 Everywhere: Unport Core::System::current_executable_path from new string
Storing paths in AK::String is never correct.
2023-12-07 10:13:21 -07:00
Timothy Flynn 6655de189f LibCore: Add a Core::System wrapper around unsetenv 2023-11-08 09:28:17 +01:00
Liav A 26f96d2a42 Kernel+Userland: Add option for duration of /dev/beep producing sound 2023-11-03 15:19:33 +01:00
Liav A 1b00618fd9 Kernel+Userland: Replace the beep syscall with the new /dev/beep device
There's no need to have separate syscall for this kind of functionality,
as we can just have a device node in /dev, called "beep", that allows
writing tone generation packets to emulate the same behavior.

In addition to that, we remove LibC sysbeep function, as this function
was never being used by any C program nor it was standardized in any
way.
Instead, we move the userspace implementation to LibCore.
2023-11-03 15:19:33 +01:00
Ali Mohammad Pur aeee98b3a1 AK+Everywhere: Remove the null state of DeprecatedString
This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
2023-10-13 18:33:21 +03:30
Sam Atkins 57497c6ab2 LibCore: Add a Core::System wrapper for memory allocation
Allocating raw memory isn't something we do often, but it does happen.
Let's make it comfier.
2023-10-10 14:36:25 +02:00
nipos 0dfd6994e3 LibCore: Use BSD implementation of anon_create() on Haiku 2023-09-17 13:38:12 -06:00
nipos 0fa00a1b1e LibCore: Don't implement adjtime on Haiku 2023-09-17 13:38:12 -06:00
nipos 1e25ab956c LibCore: Use void* instead of FlatPtr for ioctl() arg on Haiku 2023-09-17 13:38:12 -06:00
nipos a1572555c2 LibCore: Implement current_executable_path() on Haiku 2023-09-17 13:38:12 -06:00
nipos 0816bbe727 LibCore: Use accept instead of accept4 on Haiku 2023-09-17 13:38:12 -06:00
Liav A 41db527369 LibCore: Add helpers to create block and character device files 2023-09-07 11:50:50 -06:00
Sergey Bugaev 29da1d7c23 LibCore: Implement readlink() and current_executable_path() on GNU/Hurd
Without using PATH_MAX :^)

To read a symlink, we can just open its file with O_NOLINK and read its
contents. To get the executable path, we could read the /proc/self/exe
link like the Linux version does; but that relies on procfs being
mounted. Instead, we could do what procfs itself does to get the path:
ask the proc server about it.
2023-09-06 11:41:16 -06:00
Sergey Bugaev cee38cf1e5 LibCore: Use SHM_ANON for anon_create() when available
On FreeBSD and GNU/Hurd, SHM_ANON is a nice way to create anonymous
files using the usual shm_open() API. This is a lot like the fallback
shm_open() branch that follows, except we don't have to fool around
with choosing a unique name (with retrying) and unlinking the file
afterwards; it just does the right thing. Isn't this nice?
2023-09-06 11:41:16 -06:00
Niklas Poslovski ebc5b33b77 LibCore: Don't include sys/sysctl.h on Solaris 2023-08-24 22:07:28 +01:00
nipos abf7941bb9 LibCore: Change Errno to Error in FreeBSD and NetBSD-specific functions 2023-08-20 12:48:37 -06:00
Andrew Kaster bb831a27dd LibCore: Add Core::System::current_executable_path()
This is based on Jakt::File::current_executable_path() and all the other
sources I looked at to figure out the per-platform way to do this. My
goodness, every platform has its own bespoke way.
2023-08-03 09:55:20 +02:00
Shannon Booth cb920b23cc LibCore: Add System::environment
Move this from an internal function of Core::Process so that it can be
used elsewhere.
2023-07-18 14:48:45 +01:00
Timothy Flynn 996c020b0d Everywhere: Remove 'clang-format off' comments that are no longer needed 2023-07-08 10:32:56 +01:00
Liav A 23a7ccf607 Kernel+LibCore+LibC: Split the mount syscall into multiple syscalls
This is a preparation before we can create a usable mechanism to use
filesystem-specific mount flags.
To keep some compatibility with userland code, LibC and LibCore mount
functions are kept being usable, but now instead of doing an "atomic"
syscall, they do multiple syscalls to perform the complete procedure of
mounting a filesystem.

The FileBackedFileSystem IntrusiveList in the VFS code is now changed to
be protected by a Mutex, because when we mount a new filesystem, we need
to check if a filesystem is already created for a given source_fd so we
do a scan for that OpenFileDescription in that list. If we fail to find
an already-created filesystem we create a new one and register it in the
list if we successfully mounted it. We use a Mutex because we might need
to initiate disk access during the filesystem creation, which will take
other mutexes in other parts of the kernel, therefore making it not
possible to take a spinlock while doing this.
2023-07-02 01:04:51 +02:00