Commit graph

105 commits

Author SHA1 Message Date
Lenny Maiorani
f2336d0144 AK+Everywhere: Move custom deleter capability to OwnPtr
`OwnPtrWithCustomDeleter` was a decorator which provided the ability
to add a custom deleter to `OwnPtr` by wrapping and taking the deleter
as a run-time argument to the constructor. This solution means that no
additional space is needed for the `OwnPtr` because it doesn't need to
store a pointer to the deleter, but comes at the cost of having an
extra type that stores a pointer for every instance.

This logic is moved directly into `OwnPtr` by adding a template
argument that is defaulted to the default deleter for the type. This
means that the type itself stores the pointer to the deleter instead
of every instance and adds some type safety by encoding the deleter in
the type itself instead of taking a run-time argument.
2022-12-17 16:00:08 -05:00
Lucas CHOLLET
687ef7740a LibCore: Add a wrapper for getaddrinfo() 2022-12-15 13:38:13 +00:00
Timothy Flynn
d09266237d LibCore: Define and use a fallible, OS-independent getgrent(_r) wrapper
Rather than maintaining a list of #ifdef guards to check systems that do
not provide the reentrant version of getgrent, we can use C++ concepts
to let the compiler perform this check for us.

While we're at it, we can also provide this wrapper as fallible to let
the caller TRY calling it.
2022-12-14 07:25:36 -05:00
Timothy Flynn
1ee808fae6 LibCore: Define and use a fallible, OS-independent getpwent(_r) wrapper
Rather than maintaining a list of #ifdef guards to check systems that do
not provide the reentrant version of getpwent, we can use C++ concepts
to let the compiler perform this check for us.

While we're at it, we can also provide this wrapper as fallible to let
the caller TRY calling it.
2022-12-14 07:25:36 -05:00
Ali Mohammad Pur
f96a3c002a Everywhere: Stop shoving things into ::std and mentioning them as such
Note that this still keeps the old behaviour of putting things in std by
default on serenity so the tools can be happy, but if USING_AK_GLOBALLY
is unset, AK behaves like a good citizen and doesn't try to put things
in the ::std namespace.

std::nothrow_t and its friends get to stay because I'm being told that
compilers assume things about them and I can't yeet them into a
different namespace...for now.
2022-12-14 11:44:32 +01:00
Lucas CHOLLET
5532640b71 LibCore: Add a wrapper for poll() 2022-12-12 16:14:11 +00:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Andreas Kling
c8ff2184bd LibCore: Add Core::System::posix_fallocate() 2022-11-29 11:09:19 +01:00
Liav A
718ae68621 Kernel+LibCore+LibC: Implement support for forcing unveil on exec
To accomplish this, we add another VeilState which is called
LockedInherited. The idea is to apply exec unveil data, similar to
execpromises of the pledge syscall, on the current exec'ed program
during the execve sequence. When applying the forced unveil data, the
veil state is set to be locked but the special state of LockedInherited
ensures that if the new program tries to unveil paths, the request will
silently be ignored, so the program will continue running without
receiving an error, but is still can only use the paths that were
unveiled before the exec syscall. This in turn, allows us to use the
unveil syscall with a special utility to sandbox other userland programs
in terms of what is visible to them on the filesystem, and is usable on
both programs that use or don't use the unveil syscall in their code.
2022-11-26 12:42:15 -07:00
Liav A
8d8b0d0a34 Userland: Add support for jails
This happens in two ways:
1. LibCore now has two new methods for creating Jails and attaching
   processes to a Jail.
2. We introduce 3 new utilities - lsjails, jail-create and jails-attach,
   which list jails, create jails and attach processes to a Jail,
   respectively.
2022-11-05 18:00:58 -06:00
Liav A
0d1af1ad63 LibCore: Add System::exec_command method
This method was taken from the pls utility and its purpose is to execute
a given command with all the required requirements such as providing a
suitable exec environment.
2022-11-05 18:00:58 -06:00
Peter Elliott
415eb17490 LibCore: Add Core::System::readlink 2022-10-31 22:10:22 +00:00
Andrew Kaster
1d533acbc0 AK+Userland: Replace Linux, macOS, and *BSD macros with platform defines
We have such nice platform macros, let's clean up any remnants of manual
__my_platform__ macros in LibCore, LibCompress and AK.
2022-10-10 12:23:12 +02:00
Andrew Kaster
828441852f Everywhere: Replace uses of __serenity__ with AK_OS_SERENITY
Now that we have OS macros for essentially every supported OS, let's try
to use them everywhere.
2022-10-10 12:23:12 +02:00
Peter Elliott
71728f3ea6 LibCore: Add Core::System wrapper for getsid() 2022-10-03 11:11:29 +02:00
Lucas CHOLLET
08dcc40aa5 LibCore: Allow the setgroups wrapper to be used on Lagom
i.e. move Core::System::setgroups() outside the `__serenity__` define.
The base function is already used by LibCore::Account.
2022-09-27 21:29:44 +01:00
Tim Schumacher
5f99934dce Userland: Consolidate most PATH resolving into a single implementation
We previously had at least three different implementations for resolving
executables in the PATH, all of which had slightly different
characteristics.

Merge those into a single implementation to keep the behaviour
consistent, and maybe to make that implementation more configurable in
the future.
2022-08-23 19:00:04 +01:00
Tim Schumacher
c44b9acac3 LibCore: Add System::link() 2022-07-25 22:21:01 +01:00
Itamar
91a03bc6ae LibCore: Add function for searching a file in $PATH
This extracts the logic of searching for a file in $PATH from
System::exec to a separate function.
2022-07-21 16:40:11 +02:00
Andrew Kaster
d84fc60f96 LibCore: Add support for compiling for Android with API Version >= 30
Most changes are around user and group management, which are exposed in
the Android NDK differently than other Unices.

We require version 30 for memfd_create, version 28 for posix_spawn, and
so on. It's possible a shim for memfd_create could be used, but since
Google is mandating new apps use API level 30 as of Nov 2022, this seems
suitable.
2022-07-19 10:44:02 +01:00
sin-ack
828060e631 LibCore: Add convenience templates for System::{unveil,pledge}
These convenience templates allow the following to be written as before:

    TRY(Core::System::pledge("promises..."));
    TRY(Core::System::pledge("promises...", "execpromises..."));
    TRY(Core::System::unveil("path", "permissions"));
    TRY(Core::System::unveil(nullptr, nullptr));

Other uses must now append sv to any literal string passed to pledge and
unveil.
2022-07-12 23:11:35 +02:00
Andrew Kaster
30b626414d LibCore: Stub out pledge and unveil for non-serenity systems 2022-07-06 14:24:23 +02:00
Kenneth Myhra
fbe22af86e Everywhere: Use my fairly new and shiny serenityos.org email :^) 2022-06-30 15:59:42 +01:00
Lucas CHOLLET
d288c700c7 LibCore: Add a wrapper for endgrent() 2022-06-09 22:08:04 +02:00
MacDue
0295d79339 LibCore: Add posix_spawn() wrapper to Core::System 2022-05-25 23:14:22 +01:00
Sam Atkins
32ab09a930 LibCore: Add a wrapper for execvpe() and friends
This is a single function, which behaves like the various LibC exec()
functions depending on the passed parameters. No direct equivalent is
made for execl() - you have to wrap your arguments in a Span of some
kind.

On Serenity, this calls the syscall directly, whereas Lagom forwards to
the appropriate LibC function.
2022-04-11 21:09:42 +02:00
kleines Filmröllchen
ceba27c3fe LibCore: Add openat() syscall wrapper and improve open's implementation
We don't need va_args in open(), we can just use a default parameter.
2022-04-11 00:08:48 +02:00
Kenneth Myhra
0015040ebd LibCore: Add syscall wrapper for access() 2022-03-29 21:28:29 -07:00
Brian Gianforcaro
6eebd69b70 LibCore: Add Core::System::drop_privileges()
In a few places we intentionally drop privileges to reduce the potential
security surface area of networked program, with the pattern of:

```
if (setgid(getgid()) || setuid(getuid()) {
    return 1;
}
```

We can make this a bit nicer to use by creating a wrapper.
2022-03-22 11:39:20 +01:00
Lucas CHOLLET
5d29f64c99 LibCore: Add wrapper for posix_openpt(), grantpt() and unlockpt() 2022-03-02 18:08:05 +01:00
Lucas CHOLLET
ddf9987c39 LibCore+LibC: Add wrapper for setenv
I also added a common interface with StringView compatible parameters:

int serenity_setenv(const char*, ssize_t, const char*, ssize_t, int)

This function is called by both C and C++ API for setenv().
2022-03-02 18:08:05 +01:00
Lucas CHOLLET
b1af1b399e LibCore: Add tcsetpgrp(int, pid_t) wrapper 2022-03-02 18:08:05 +01:00
Lucas CHOLLET
19d5974e3a LibCore: Add killpg() wrapper 2022-03-02 18:08:05 +01:00
Lenny Maiorani
b455363ce7 LibCore: Add rmdir system call wrapper 2022-02-28 13:57:26 +01:00
Isak Holmstrom
4f716caa33 LibCore: Add FreeBSD as OpenBSD/Apple in System.cpp & System.h 2022-02-17 09:26:56 +00:00
sin-ack
37658e6fa6 LibCore: Implement System::fchown 2022-02-14 11:44:09 +01:00
rvictorr
73303f0dc1 LibCore: Add syscall wrapper for profiling_free_buffer() 2022-02-13 12:40:36 +01:00
rvictorr
014c0d68c0 LibCore: Add syscall wrapper for profiling_disable() 2022-02-13 12:40:36 +01:00
rvictorr
c6a743f22c LibCore: Add syscall wrapper for profiling_enable() 2022-02-13 12:40:36 +01:00
kleines Filmröllchen
cf1f58d51c LibCore/System: Add anon_create syscall wrapper
This wrapper is particularly helpful as we use a combination of similar
syscalls on Linux to simulate the behavior of the Serenity-exclusive
anon_create syscall. Users therefore won't have to worry about the
platform anymore :^)
2022-02-10 21:35:17 +01:00
Kenneth Myhra
c10abd6be2 LibCore: Add mkfifo() syscall wrapper 2022-01-24 14:01:58 +03:30
Kenneth Myhra
9fe1ebebdc LibCore: Add mknod() syscall wrapper 2022-01-24 14:01:58 +03:30
Federico Guerinoni
2291ef6c3c LibCore: Add syscall wrapper for umount() 2022-01-22 13:31:52 +02:00
Maciej
ccb8374434 LibCore: Add Core::System wrapper for disown() 2022-01-21 13:44:36 +01:00
mjz19910
a9fb34ca6f LibCore: Add ErrorOr wrapper for adjtime 2022-01-21 01:52:22 +01:00
sin-ack
301f4c469f LibCore: Implement Core::System::lseek 2022-01-20 10:40:51 +01:00
Lucas CHOLLET
b3b40ae1fa LibCore: Add wrapper for sethostname 2022-01-14 19:42:19 +02:00
Junior Rantila
0d328f3c86 LibCore+flock: Make Core::System::waitpid more ergonomic 2022-01-11 16:04:29 +01:00
Junior Rantila
7801e38af1 LibCore: Add beep wrapper 2022-01-09 11:16:00 +03:30
Lucas CHOLLET
3fa5be655d LibCore: Add a wrapper for setsid() 2022-01-09 03:22:10 +03:30