1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 14:35:07 +00:00
Commit graph

518 commits

Author SHA1 Message Date
Andreas Kling
1366557094 AK+LibC: Always use REP MOVSB/STOSB for memcpy()/memset()
There's no great advantage to using MMX instructions here on modern
processors, since REP MOVSB/STOSB are optimized in microcode anyway
and tend to run much faster than MMX/SSE/AVX variants.

This also makes it much easier to implement high-level emulation of
memcpy/memset in UserspaceEmulator once we get there. :^)
2020-07-27 15:54:39 +02:00
Brian Gianforcaro
bbc7e8429b LibC: Remove duplicate gs touch during gettid()/getpid() fast path
While profiling I noticed that gettid() was hitting gs register
twice, once for the initial fetch of s_cache_tid out of TLS for
the initialization check, and then again when we return the actual
value.

Optimize the implementation to cache the value so we avoid the
double fetch during the 99% case where it's already set. With
this change gettid() goes from being the 3rd most sampled function
in test-js, to pretty much disappearing into  ~20th place.

Additionally add the same optimization to getpid().
2020-07-23 12:28:11 +02:00
Andreas Kling
223b96c820 LibC: Make sure malloc chunks are 8-byte aligned
I noticed this while doing some instruction-level debugging. :^)
2020-07-21 22:48:17 +02:00
Andreas Kling
b820e4626c LibC: Add a cache for getpid()
This works the same as gettid(). No sense in making a syscall to the
kernel every time you ask for the PID since it won't change.
Just like gettid(), the cache is invalidated on fork().
2020-07-21 19:08:01 +02:00
Andreas Kling
30025dd576 LibC: Notify UserspaceEmulator about malloc *after* scrubbing
This makes sure that the emulator marks new malloc memory as
uninitialized (even after we've "initialized" it by scrubbing with
the scrub byte.)
2020-07-21 16:38:58 +02:00
Peter Elliott
82ba7d546a LibC: add mkfifo(3) 2020-07-19 11:46:37 +02:00
Andreas Kling
869a3e2cf3 LibC: Notify UserspaceEmulator about BigAllocationBlock mallocs
We were forgetting to inform UE about these, which caused it to believe
subsequent calls to free() were invalid.
2020-07-16 20:46:44 +02:00
Andreas Kling
4aa81a4fd9 LibC: Communicate malloc() and free() operations to UserspaceEmulator
Use the sneaky SALC secret mechanism of UserspaceEmulator to inform it
about malloc operations.
2020-07-15 23:25:20 +02:00
Nico Weber
4eb967b5eb LibC+Kernel: Start implementing sysconf
For now, only the non-standard _SC_NPROCESSORS_CONF and
_SC_NPROCESSORS_ONLN are implemented.

Use them to make ninja pick a better default -j value.
While here, make the ninja package script not fail if
no other port has been built yet.
2020-07-15 00:07:20 +02:00
Stefano Cristiano
a1e1aa96fb Toolchain: Allow building using CMake on macOS 2020-07-13 08:46:44 +02:00
Andreas Kling
9257657340 LibC: Some s/int/size_t/ in the malloc code 2020-07-11 23:57:14 +02:00
Peter Elliott
7a27fa3df8 LibC: Implement tcflush(3) 2020-07-11 11:33:33 +02:00
Nico Weber
0d851b1930 Add manpages for posix_spawn 2020-07-06 10:01:14 +02:00
Andreas Kling
11c4a28660 Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
AnotherTest
29e00b637e LibC: Implement cf{g,s}et{i,o}speed 2020-07-04 10:49:36 +02:00
Nico Weber
6d5bd8c76b LibC: Minor style fix for getresuid/getresgid 2020-07-03 19:37:28 +02:00
Sahan Fernando
0ba9651e6e LibC: Replace Berkley's qsort() with AK::dual_pivot_quick_sort() wrapper 2020-07-03 19:29:36 +02:00
Nico Weber
12cbc4ad0d Everywhere: Replace some uses of fork/exec with posix_spawn
It's less code, and it's potentially more efficient once
posix_spawn is a real syscall.
2020-06-29 12:04:27 +02:00
Andreas Kling
d4195672b7 Kernel+LibC: Add sys$recvfd() and sys$sendfd() for fd passing
These new syscalls allow you to send and receive file descriptors over
a local domain socket. This will enable various privilege separation
techniques and other good stuff. :^)
2020-06-24 23:08:09 +02:00
Nico Weber
d2684a8645 LibC+Kernel: Implement ppoll
ppoll() is similar() to poll(), but it takes its timeout
as timespec instead of as int, and it takes an additional
sigmask parameter.

Change the sys$poll parameters to match ppoll() and implement
poll() in terms of ppoll().
2020-06-23 14:12:20 +02:00
Nico Weber
d23e655c83 LibC: Implement pselect
pselect() is similar() to select(), but it takes its timeout
as timespec instead of as timeval, and it takes an additional
sigmask parameter.

Change the sys$select parameters to match pselect() and implement
select() in terms of pselect().
2020-06-22 16:00:20 +02:00
Nico Weber
29f509a2a0 LibC: Add timespec functions to sys/time.h
And rewrite the timeval functions as inline functions.

Also add the non-standard but fairly common and useful
TIMEVAL_TO_TIMESPEC / TIMESPEC_TO_TIMEVAL functions.
2020-06-22 16:00:20 +02:00
Nico Weber
ed0740d73c LibC: In posix_spawn(), use _exit instead of exit on child error
posix_spawn() tries to present semantics as if no fork() is happening
behind the scenes, so running arbitrary atexit handlers of the parent
in the child seems like the wrong thing to do.
2020-06-20 14:43:27 +02:00
Nico Weber
5208856688 LibC: Add addchdir() / addfchdir() to posix_spawn file actions
This isn't in posix yet, but it is implemented on some platforms
and it will be in a future version:
https://www.austingroupbugs.net/view.php?id=1208
2020-06-20 14:43:27 +02:00
Nico Weber
2ddca326be LibC: Add POSIX_SPAWN_SETSIGMASK
This isn't in posix yet, but it is implemented on some platforms
and it will be in a future version:
https://www.austingroupbugs.net/view.php?id=1044

It seems useful, so add it.
2020-06-20 14:43:27 +02:00
Nico Weber
39d1a43c45 LibC: Make sigprocmask error check more consistent with rest of this code 2020-06-20 14:43:27 +02:00
Nico Weber
7ffcc5a8b2 LibC: Implement file actions for posix_spawn 2020-06-19 22:11:38 +02:00
Nico Weber
68f281c864 LibC: Make spawn.h parse in C files 2020-06-19 22:11:38 +02:00
Nico Weber
e89a82a476 LibC: Add support for POSIX_SPAWN_RESETIDS
This is possible now that seteuid() / setegid() are implemented.
2020-06-19 20:34:59 +02:00
Nico Weber
dd53e070c5 Kernel+LibC: Remove setreuid() / setregid() again
It looks like they're considered a bad idea, so let's not add
them before we need them. I figured it's good to have them in
git history if we ever do need them though, hence the add/remove
dance.
2020-06-18 23:19:16 +02:00
Nico Weber
a38754d9f2 Kernel+LibC: Implement seteuid() and friends!
Add seteuid()/setegid() under _POSIX_SAVED_IDS semantics,
which also requires adding suid and sgid to Process, and
changing setuid()/setgid() to honor these semantics.

The exact semantics aren't specified by POSIX and differ
between different Unix implementations. This patch makes
serenity follow FreeBSD. The 2002 USENIX paper
"Setuid Demystified" explains the differences well.

In addition to seteuid() and setegid() this also adds
setreuid()/setregid() and setresuid()/setresgid(), and
the accessors getresuid()/getresgid().

Also reorder uid/euid functions so that they are the
same order everywhere (namely, the order that
geteuid()/getuid() already have).
2020-06-18 23:19:16 +02:00
Nico Weber
4720635aab LibC: Add posix_spawn()!
All the file actions stuff is still missing for now,
as is POSIX_SPAWN_SETSCHEDULER (not sure what that's
supposed to do) and POSIX_SPAWN_RESETIDS.

Implemented in userspace for now. Once there are users,
it'll likely make sense to make this a syscall for
performance reasons.

A simple test program of the form

    extern char **environ;
    int main(int argc, char* argv[])
    {
        pid_t pid;
        char* args[] = { "ls", NULL };
        posix_spawnp(&pid, "ls", nullptr, nullptr, args, environ);
    }

works fine.
2020-06-17 18:49:06 +02:00
Andreas Kling
723f4e5ee6 Meta: Scale back overly informal user-facing strings
We were getting a little overly memey in some places, so let's scale
things back to business-casual.

Informal language is fine in comments, commits and debug logs,
but let's keep the runtime nice and presentable. :^)
2020-06-17 18:35:49 +02:00
Nico Weber
9abafa2d1c LibC: Make setgid() definition protoype match declaration 2020-06-17 15:08:17 +02:00
Sergey Bugaev
47d83800e1 Kernel+LibC: Do not return -ENAMETOOLONG from sys$readlink()
That's not how readlink() is supposed to work: it should copy as many bytes
as fit into the buffer, and return the number of bytes copied. So do that,
but add a twist: make sys$readlink() actually return the whole size, not
the number of bytes copied. We fix up this return value in userspace, to make
LibC's readlink() behave as expected, but this will also allow other code
to allocate a buffer of just the right size.

Also, avoid an extra copy of the link target.
2020-06-17 15:02:03 +02:00
Nico Weber
d81ac80aba LibC: Declare pthread_sigmask() in signal.h.
That's where it's supposed to be declared.
2020-06-16 09:34:00 +02:00
Nico Weber
9825f7792b LibC: Add truncate().
Implemented in user space for now.
2020-06-15 17:34:52 +02:00
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Andreas Kling
a85506009f LibC: Don't assert on unknown mode character in fopen()
Just carry on with some debug log whining.
Gets rid of one dropbear patch. :^)
2020-06-08 21:57:13 +02:00
Andreas Kling
c88ea2f54a LibC: Add nanosleep() wrapper around clock_nanosleep(CLOCK_REALTIME)
Gets rid of one dropbear patch. :^)
2020-06-08 21:53:41 +02:00
Andreas Kling
57b6f51137 LibC: Add IPPORT_RESERVED and IPPORT_USERRESERVED
Gets rid of one dropbear patch. :^)
2020-06-08 21:50:45 +02:00
Andreas Kling
3ee1b3cbd4 LibC: Add ws_xpixel and ws_ypixel members to struct winsize
This matches what other systems have, although we don't use them.
Gets rid of one dropbear patch. :^)
2020-06-08 21:40:22 +02:00
Andreas Kling
a586a84450 LibC: Make sure that ioctl() requests are #defined as macros
This fixes terminal UI resizing in the vim port. The problem was that
vim had "#ifdef TIOCGWINSZ" around the code that figures out the size
of the terminal.

Since all of our ioctl() requests were enum values, this code was not
compiled into vim at all. This patch fixes that. :^)
2020-06-03 22:56:46 +02:00
Sergey Bugaev
2930fbcfcf LibC: Rewrite getopt()
Fixes https://github.com/SerenityOS/serenity/issues/91
2020-05-30 15:01:18 +02:00
Andreas Kling
1ef5d609d9 AK+LibC: Add TODO() as an alternative to ASSERT_NOT_REACHED()
I've been using this in the new HTML parser and it makes it much easier
to understand the state of unfinished code branches.

TODO() is for places where it's okay to end up but we need to implement
something there.

ASSERT_NOT_REACHED() is for places where it's not okay to end up, and
something has gone wrong.
2020-05-30 11:31:49 +02:00
Emanuele Torre
937d0be762 Meta: Add a script check the presence of "#pragma once" in header files
.. and make travis run it.

I renamed check-license-headers.sh to check-style.sh and expanded it so
that it now also checks for the presence of "#pragma once" in .h files.

It also checks the presence of a (single) blank line above and below the
"#pragma once" line.

I also added "#pragma once" to all the files that need it: even the ones
we are not check.
I also added/removed blank lines in order to make the script not fail.

I also ran clang-format on the files I modified.
2020-05-29 07:59:45 +02:00
Sergey Bugaev
3847d00727 Kernel+Userland: Support remounting filesystems :^)
This makes it possible to change flags of a mount after the fact, with the
caveats outlined in the man page.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
fdb71cdf8f Kernel: Support read-only filesystem mounts
This adds support for MS_RDONLY, a mount flag that tells the kernel to disallow
any attempts to write to the newly mounted filesystem. As this flag is
per-mount, and different mounts of the same filesystems (such as in case of bind
mounts) can have different mutability settings, you have to go though a custody
to find out if the filesystem is mounted read-only, instead of just asking the
filesystem itself whether it's inherently read-only.

This also adds a lot of checks we were previously missing; and moves some of
them to happen after more specific checks (such as regular permission checks).

One outstanding hole in this system is sys$mprotect(PROT_WRITE), as there's no
way we can know if the original file description this region has been mounted
from had been opened through a readonly mount point. Currently, we always allow
such sys$mprotect() calls to succeed, which effectively allows anyone to
circumvent the effect of MS_RDONLY. We should solve this one way or another.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
b905126365 Kernel+LibC: Move O_* and MS_* flags to UnixTypes.h
That's where the other similar definitions reside. Also, use bit shift
operations for MS_* values.
2020-05-29 07:53:30 +02:00
Emanuele Torre
cd507d0408 LibC: run clang-format on getopt.h to remove tab characters 2020-05-28 17:01:31 +02:00