1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 22:25:08 +00:00
Commit graph

535 commits

Author SHA1 Message Date
Nico Weber
323e727a4c Kernel+LibC: Add adjtime(2)
Most systems (Linux, OpenBSD) adjust 0.5 ms per second, or 0.5 us per
1 ms tick. That is, the clock is sped up or slowed down by at most
0.05%.  This means adjusting the clock by 1 s takes 2000 s, and the
clock an be adjusted by at most 1.8 s per hour.

FreeBSD adjusts 5 ms per second if the remaining time adjustment is
>= 1 s (0.5%) , else it adjusts by 0.5 ms as well. This allows adjusting
by (almost) 18 s per hour.

Since Serenity OS can lose more than 22 s per hour (#3429), this
picks an adjustment rate up to 1% for now. This allows us to
adjust up to 36s per hour, which should be sufficient to adjust
the clock fast enough to keep up with how much time the clock
currently loses. Once we have a fancier NTP implementation that can
adjust tick rate in addition to offset, we can think about reducing
this.

adjtime is a bit old-school and most current POSIX-y OSs instead
implement adjtimex/ntp_adjtime, but a) we have to start somewhere
b) ntp_adjtime() is a fairly gnarly API. OpenBSD's adjfreq looks
like it might provide similar functionality with a nicer API. But
before worrying about all this, it's probably a good idea to get
to a place where the kernel APIs are (barely) good enough so that
we can write an ntp service, and once we have that we should write
a way to automatically evaluate how well it keeps the time adjusted,
and only then should we add improvements ot the adjustment mechanism.
2020-11-10 19:03:08 +01:00
Brendan Coles
9b79ea78d3 LibC: Add POSIX1 minimum limits to limits.h 2020-11-10 14:39:38 +01:00
Andreas Kling
c4dd77a170 UserspaceEmulator+LibC: Have UE notice realloc() and update accounting
When a mallocation is shrunk/grown without moving, UE needs to update
its precise metadata about the mallocation, since it tracks *exactly*
how many bytes were allocated, not just the malloc chunk size.
2020-11-08 10:43:15 +01:00
Andreas Kling
79b45f96ee LibC: Add two little assertions in malloc() and malloc_size() 2020-11-08 01:15:02 +01:00
Andreas Kling
a28f29c82c Kernel+LibC: Don't allow a directory to become a subdirectory of itself
If you try to do this (e.g "mv directory directory"), sys$rename() will
now fail with EDIRINTOSELF.

Dr. POSIX says we should return EINVAL for this, but a custom error
code allows us to print a much more helpful error message when this
problem occurs. :^)
2020-11-01 19:21:19 +01:00
Andreas Kling
34014fa838 LibC: Use dbgln() in setlocale() 2020-10-30 17:03:28 +01:00
Andreas Kling
77e9eadd9d Userland+LibC: Add "kill -l" to show all known signal names/numbers 2020-10-29 23:32:18 +01:00
Andreas Kling
662959b173 LibC: Use NSIG instead of hard-coding 32 as the signal count 2020-10-29 23:32:18 +01:00
asynts
607931268e CMake: Use CONFIGURE_DEPENDS in existing globs. 2020-10-29 11:52:47 +01:00
Andreas Kling
ad0295d033 LibC: Move getsignalbyname() helper from Userland/kill into LibC 2020-10-29 11:49:24 +01:00
Andreas Kling
e590c53a1d LibC: Add NAME_MAX (255) 2020-10-22 18:58:53 +02:00
Andreas Kling
c8c7db8c33 LibC: Fix a warning when building LibC with -O2 2020-10-20 18:10:22 +02:00
Stephen Gregoratto
5245277369 LibC: Make difftime a function
The previous define led to issues when compiling some ports, namely zsh
5.8.
2020-10-15 13:45:00 +02:00
Andreas Kling
1208f3fd75 LibC: We still need to use NULL (not nullptr) in C headers
Thanks to @alimpfard for noticing this.
2020-10-14 13:57:51 +02:00
Matthew L. Curry
5d5c32cec1 Style: Remove uses of NULL, substituting nullptr 2020-10-13 13:52:52 +02:00
Andreas Kling
65cdac1a5b Kernel+LibC: Use uintptr_t as the main type in the syscall interface 2020-10-12 19:53:25 +02:00
asynts
59e7ffa86d AK: Make the return type of dbgputstr consistent. 2020-10-04 19:18:32 +02:00
Emanuele Torre
4e86c34ef0 LibC: Remove unnecessary fallthrough comments.
A "fallthrough comment" or `[[fallthrough]]` is only required after
non-empty `case`s.
2020-10-03 12:35:40 +02:00
Nico Weber
ef1b21004f Everywhere: Fix typos
Mostly in comments, but sprintf() now prints "August" instead of
"Auguest" so that's something.
2020-10-02 16:03:17 +02:00
Benoit Lormeau
f158cb27ea LibC: Remove an unneeded string.h include in ctype.h/cpp
And include string.h in the files that actually needed it
2020-09-27 21:15:25 +02:00
Luke
bf809226de LibC: Add SCM_RIGHTS to sockets.h and caddr_t to types.h 2020-09-27 01:02:11 +02:00
Luke
1ec59f28ce LibC: Make isalum/isalpha/etc. functions instead of macros
These are supposed to be both functions and macros. I'm not sure
how to provide the functions at the same time as the macros,
as they collide with each other and cause compile errors.

However, some ports fully expect them to be functions.
For example, OpenSSH stores them into structures as function
pointers.
2020-09-27 01:02:11 +02:00
Luke
9266006349 LibC: Add ss_family to sockaddr_storage
I'm not exactly sure if this is in the right spot in the structure,
especially since I read that this is supposed to be cast into other
structures.
2020-09-27 01:02:11 +02:00
Luke
9d8f1032b7 LibC: Add missing utmp backwards compatibility hacks and user/dead process macros
The user/dead process macros are not used anywhere in Serenity right now,
but are required for OpenSSH.
2020-09-27 01:02:11 +02:00
Luke
721788943d Kernel: Implement _SC_OPEN_MAX 2020-09-27 01:02:11 +02:00
Luke
db31452bc2 LibC: Made mbtowc return int instead of size_t 2020-09-27 01:02:11 +02:00
Luke
5fbb8f9c6a LibC: Add FIXME for vsscanf 2020-09-27 01:02:11 +02:00
Luke
7a558d16b0 LibC: Add some missing netinet macros required by OpenSSH
Not used anywhere in Serenity right now, but required for OpenSSH.
2020-09-27 01:02:11 +02:00
Luke
f2cc565670 LibC: Add SSIZE_MAX limit 2020-09-27 01:02:11 +02:00
Luke
83849f0ef3 LibC: Include cdefs.h in getopt.h
Required for __BEGIN_DECLS
2020-09-27 01:02:11 +02:00
Luke
7334f21ef7 LibC: Add EPFNOSUPPORT error number
Not used anywhere in Serenity currently, but required for OpenSSH.
2020-09-27 01:02:11 +02:00
Luke
93b9929391 LibC: Add paths.h with some default mail directory for now 2020-09-27 01:02:11 +02:00
Ben Wiederhake
ede5dbd7b3 Meta+LibC through LibHTTP: Make clang-format-10 clean
Why break at LibHTTP? Because "Meta+Libraries" would be insanely large,
and breaking between LibHTTP and LibJS makes the commits roughly evenly large.
2020-09-25 21:18:17 +02:00
Nico Weber
47b3e98af8 Kernel+LibC+UserspaceEmulator: Add SO_TIMESTAMP, and cmsg definitions
When SO_TIMESTAMP is set as an option on a SOCK_DGRAM socket, then
recvmsg() will return a SCM_TIMESTAMP control message that
contains a struct timeval with the system time that was current
when the socket was received.
2020-09-17 17:23:01 +02:00
Nico Weber
ae5ba4074d LibC: Convert SO_ constants to enum
I want to add another entry to this list and don't want to
have to think of a number for it.
2020-09-17 17:23:01 +02:00
Nico Weber
b36a2d6686 Kernel+LibC+UserspaceEmulator: Mostly add recvmsg(), sendmsg()
The implementation only supports a single iovec for now.
Some might say having more than one iovec is the main point of
recvmsg() and sendmsg(), but I'm interested in the control message
bits.
2020-09-17 17:23:01 +02:00
Tom
c8d9f1b9c9 Kernel: Make copy_to/from_user safe and remove unnecessary checks
Since the CPU already does almost all necessary validation steps
for us, we don't really need to attempt to do this. Doing it
ourselves doesn't really work very reliably, because we'd have to
account for other processors modifying virtual memory, and we'd
have to account for e.g. pages not being able to be allocated
due to insufficient resources.

So change the copy_to/from_user (and associated helper functions)
to use the new safe_memcpy, which will return whether it succeeded
or not. The only manual validation step needed (which the CPU
can't perform for us) is making sure the pointers provided by user
mode aren't pointing to kernel mappings.

To make it easier to read/write from/to either kernel or user mode
data add the UserOrKernelBuffer helper class, which will internally
either use copy_from/to_user or directly memcpy, or pass the data
through directly using a temporary buffer on the stack.

Last but not least we need to keep syscall params trivial as we
need to copy them from/to user mode using copy_from/to_user.
2020-09-13 21:19:15 +02:00
Ben Wiederhake
8280dcfb89 LibC: Avoid write-back of unused value
This might make sleep() faster by up to pi nanoseconds, or less.
It's more about avoiding a senseless write than about optimization.
2020-09-12 13:46:15 +02:00
Ben Wiederhake
be1e4f28cc LibC: Don't advertise wrong functions
str{,n}casecmp is supposed to be *only* declared by strings.h, note the
trailing 's' in the filename.

We don't have any implementation for strlcat; using any strcat variants is
a bad idea anyway, given our implementation of AK::String.

TODO: Find a way to lint for declared-but-nowhere-defined functions.
2020-09-12 13:46:15 +02:00
Andreas Kling
f8e59addf7 Kernel+LibC+UE: Introduce SIGINFO (generated with ^T)
This signal is ignored by default, but can be caught to implement state
reporting a la BSD. :^)
2020-09-09 21:10:23 +02:00
Nico Weber
0fff4e11a6 LibC: Add settimeofday 2020-09-06 21:50:55 +02:00
Itamar
542f665b27 LibC: Avoid generating calls to__cxa_guard_* functions in netdb.cpp
g++ seems to generate calls to __cxa_guard_* functions when we use
non-trivial initialization of local statics.
Requiring these symbols breaks some ports since these symbols are
defined in libcstdc++ which we do not link against when building ports.

This commit turns some local statics into global statics in netdb.cpp so
libc wouldn't need these symbols.
2020-09-06 21:36:36 +02:00
Itamar
c5b0e0b96b LibC: Don't include things required for getopt_long in unistd.h
Previously, we were including the whole of <getopt.h> in <unistd.h>.
However according to the posix <unistd.h> doesn't have to contain
everything we had in <getopt.h>.

This fixes some symbol collisions that broke the git port.
2020-09-06 21:36:36 +02:00
Andreas Kling
386c7201d8 LibC: Move the static String in getlogin() out of the function
For some reason, this stops it from adding __cxa_guard_acquire/release
calls around its initialization. This unbreaks building ports.
2020-09-01 16:17:17 +02:00
Erlend Fagerheim
22265f1445 LibC: add getopt.h to unistd.h 2020-09-01 15:45:35 +02:00
Andreas Kling
e002cbb06b Build: Add some -Wno-unknown-warning-option flags to CXXFLAGS
Patch from Anonymous.
2020-09-01 12:00:53 +02:00
AnotherTest
9adbbff4dd LibC: Partially implement 'freopen' 2020-08-31 09:14:11 +02:00
Sergey Bugaev
f808810d00 LibC: Deprecate strcpy(), strncpy(), strcat() and strncat() :^)
And also mark strlcpy() and strlcat() with __attribute__((warn_unused_result)).

Since our code is warning-free, this ensures we never misuse those functions.
(Or are very sure about doing it when turning off the warning for a particular
piece of code.)
2020-08-30 17:35:27 +02:00
Sergey Bugaev
1cdd798ac7 LibC: Replace some strncpy() calls with memcpy()
In case we know exactly how many bytes we're copying (and not copying a string
while limiting its length to that of a buffer), memcpy() is a more appropriate
function to call.

Also, fix null-terminating the %c pointer.
2020-08-30 17:35:27 +02:00
Sergey Bugaev
34353e18cf LibC: Misc fixes and improvements in netdb 2020-08-30 17:35:27 +02:00