Commit Graph

161 Commits

Author SHA1 Message Date
Brian Gianforcaro
dc0fc16981 Everywhere: Use bgianf@serenityos.org for my copyright attribution 2021-04-22 21:15:54 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Brian Gianforcaro
14f6425b8f LibC: Add pwrite(..) implementation to match the existing pread(..)
Add a basic non-thread safe implementation of pwrite, following the
existing pread(..) design.

This is needed for https://fio.readthedocs.io
2021-04-21 13:13:23 +02:00
Brian Gianforcaro
56ba3e1cbd LibC: Add LOG_NOWAIT stub to syslog.h
Needed for porting https://fio.readthedocs.io
2021-04-21 13:13:23 +02:00
Brian Gianforcaro
2ebb3f3c0d LibC: Add a definition for INET6_ADDRSTRLEN
Although serenity doesn't implement IPv6 yet, applications
will often declare buffers to be of size `INET6_ADDRSTRLEN`
so it's guaranteed to work in both IPv4 / IPv6 environments.

This is needed specifically for a port of Flexible IO Tester
https://fio.readthedocs.io

This is standardized here:
https://pubs.opengroup.org/onlinepubs/009695399/basedefs/netinet/in.h.html
2021-04-21 08:04:52 +02:00
Brian Gianforcaro
a1720eed2a LibC: Setup a unit test harness for LibC, add ctime_r / asctime_r tests.
LibC is no different than any other code, it should be unit tested where
appropriate / possible.
2021-04-21 08:04:52 +02:00
Brian Gianforcaro
df808f0ed3 LibC: Fix missing '\n' at the end of ctime/ctime_r/asctime/asctime_r
@linusg noticed this bug in the original implementation during code review.
This makes all of these API's more spec conforming.
2021-04-21 08:04:52 +02:00
Brian Gianforcaro
440b81deba LibC: Add ctime_r() and asctime_r() implementations
Need this for a port of FIO (Flexible IO Tester)
https://fio.readthedocs.io/
2021-04-21 08:04:52 +02:00
Gunnar Beutner
88cebb05ad LibC+LibPthread: Implement function forwarding for libpthread
GCC will insert various calls to pthread functions when compiling
C++ code with static initializers, even when the user doesn't link
their program against libpthread explicitly.

This is used to make static initializers thread-safe, e.g. when
building a library that does not itself use thread functionality
and thus does not link against libpthread - but is intended to
be used with other code that does use libpthread explicitly.

This makes these symbols available in libc.
2021-04-20 21:08:17 +02:00
Gunnar Beutner
ddcd149224 LibC: Avoid division by zero in fread()/fwrite() 2021-04-19 22:13:52 +02:00
Gunnar Beutner
cd432860d8 LibC: Additional functionality for getaddrinfo()
When node is NULL and AI_PASSIVE is specified we are supposed to use
the "any" address, otherwise we should use the loopback address.
2021-04-19 21:00:23 +02:00
Brian Gianforcaro
3e87e43f9d LibC: Expose new profiling_free_buffer(..) syscall.
Expose the new `profiling_free_buffer` syscall to user space.
2021-04-19 18:30:37 +02:00
Panagiotis Vasilopoulos
9de58a2d89 LibC: Added sysexits.h 2021-04-19 18:27:55 +02:00
Gunnar Beutner
a5be8d8976 LibC: Improve error logging for execvp() 2021-04-19 18:27:09 +02:00
FalseHonesty
7a1396f509 LibDebug: Implement ability to set watchpoints
Now we can set hardware watchpoints for our variables! :^)
These watchpoints will be automatically removed when
they go out of scope.
2021-04-18 17:02:40 +02:00
FalseHonesty
3123ffb19d Kernel: Add ptrace commands for reading/writing the debug registers
This adds PT_PEEKDEBUG and PT_POKEDEBUG to allow for reading/writing
the debug registers, and updates the Kernel's debug handler to read the
new information from the debug status register.
2021-04-18 17:02:40 +02:00
Gunnar Beutner
81daca5dd7 LibC: Implement assignment suppression for vsscanf
The vsscanf library function lets the user skip assigning
parsed values to the arguments, e.g. with %*c - even though
a character is scanned it is not assigned to one of the
arguments.

The figlet port uses this. With this patch the port is actually
usable.
2021-04-18 16:35:00 +02:00
Hendiadyoin1
f682c9f100 LibC: Add netinet/in_systm.h 2021-04-18 15:52:07 +02:00
Gunnar Beutner
f033416893 Kernel+LibC: Clean up how assertions work in the kernel and LibC
This also brings LibC's abort() function closer to the spec.
2021-04-18 11:11:15 +02:00
Gunnar Beutner
6cb28ecee8 LibC+LibELF: Implement support for the dl_iterate_phdr helper
This helper is used by libgcc_s to figure out where the .eh_frame sections
are located for all loaded shared objects.
2021-04-18 10:55:25 +02:00
Gunnar Beutner
ebca6aabc0 LibC: Make atexit handlers thread-safe 2021-04-18 10:52:05 +02:00
Gunnar Beutner
4075b306f8 LibC+LibPthread: Make sure TLS keys are destroyed after everything else
This ensures that __thread variables can be used when global destructors
are being invoked.
2021-04-18 10:52:05 +02:00
Linus Groh
2b0c361d04 Everywhere: Fix a bunch of typos 2021-04-18 10:30:03 +02:00
Gunnar Beutner
c33592d28c Kernel+LibC: Update struct stat to use struct timespec instead of time_t
Some programs unconditionally expect struct stat to have nanosecond support.
2021-04-17 11:12:42 +02:00
sin-ack
091d352526 Kernel: Add some missing socket ioctls
This patch adds a few missing ioctls which were required by Wine.
SIOCGIFNETMASK, SIOCGIFBRDADDR and SIOCGIFMTU are fully implemented,
while SIOCGIFFLAGS and SIOCGIFCONF are stubs.
2021-04-16 18:57:35 +02:00
Gunnar Beutner
92749d9a76 LibC: Don't call initializers in crt0
The dynamic linker is already taking care of this for us. Now
that crt0 is statically linked into each executable and shared
library this breaks things because initializers are invoked twice.

Before this PR this didn't crash because crt0 and its _start()
function was contained in LibC and thus only LibC's initializers were
invoked several times which wasn't as much of a problem because
these initializers didn't have any side effects (such as malloc/free).

However, user programs are more likely to have constructors with side
effects, e.g.:

    std::string g_test("hello!");

This would allocate memory when the constructor is invoked. When it is
invoked again the original allocation would be leaked and another copy
of the string would get allocated. Worse still, when the destructors are
invoked twice the memory would get free'd twice which would likely
crash the program.
2021-04-16 17:56:12 +02:00
Gunnar Beutner
50e4cad4a0 Toolchain+LibC: Don't link LibC against crt0
Instead GCC should be used to automatically link against crt0
and crt0_shared depending on the type of object file that is being
built.

Unfortunately this requires a rebuild of the toolchain as well
as everything that has been built with the old GCC.
2021-04-16 17:56:12 +02:00
Gunnar Beutner
67516fa555 LibC: Shared libraries shouldn't have an entry point
The _start() function attempts to call main() which is a
problem when trying to build a shared library with --no-undefined:

  $ echo > t.c
  $ gcc -shared -Wl,--no-undefined -o t.so t.c
  /usr/local/lib/gcc/i686-pc-serenity/10.2.0/../../../../i686-pc-serenity/bin/ld:
  /usr/lib/crt0_shared.o: in function `_start':
  ./Build/i686/../../Userland/Libraries/LibC/crt0_shared.cpp:56: undefined reference to `main'
  collect2: error: ld returned 1 exit status

Also, unless explicitly requested by the user shared libraries
should not have an entry point (e.g. _start) at all.
2021-04-16 17:56:12 +02:00
Gunnar Beutner
1e1de4a542 LibC: Use __inline_isascii() in isascii() 2021-04-14 21:46:20 +02:00
Gunnar Beutner
3df7f868e8 LibC: Add support for isblank() 2021-04-14 21:46:20 +02:00
Gunnar Beutner
75d774ba29 LibC: Add missing macro for _SC_CLK_TCK 2021-04-14 21:46:20 +02:00
Gunnar Beutner
5a4206ef2e LibC: Turn regex_t and regmatch_t into typedefs
According to POSIX.1-2001 these should be anonymous structs with
a typedef.
2021-04-14 21:46:20 +02:00
Gunnar Beutner
546fa8cfb5 LibC: Change return type for sleep() to unsigned int
According to POSIX.1-2001 the return type should be unsigned int.
2021-04-14 21:46:20 +02:00
Gunnar Beutner
7d12c08bec LibC: Add definition for the NI_NAMEREQD macro 2021-04-14 13:13:06 +02:00
Gunnar Beutner
ea6d0aa1d4 LibPthread: Implement semaphore functions 2021-04-14 13:13:06 +02:00
Gunnar Beutner
dce57cd085 LibC: Add definitions for INTMAX_C and UINTMAX_C 2021-04-14 13:13:06 +02:00
Gunnar Beutner
1946a4bee6 LibC: Add missing include in <syslog.h>
The include is necessary for __BEGIN_DECLS and __END_DECLS.
2021-04-14 13:13:06 +02:00
Brendan Coles
ce010de74f LibC: getaddrinfo: Set addrinfo sin_port to 0 if service arg is NULL 2021-04-13 15:10:14 +02:00
Gunnar Beutner
30b038f8d9 LibC: Implement getaddrinfo(), freeaddrinfo(), gai_strerror() and getnameinfo() 2021-04-12 22:44:49 +02:00
Gunnar Beutner
8fcf91b030 LibC: The port numbers returned by getservby*() should be in network byte order 2021-04-12 22:44:49 +02:00
Gunnar Beutner
287a93a2a4 LibC: Validate the len argument for inet_ntop() 2021-04-12 22:44:49 +02:00
Gunnar Beutner
0497986572 LibC: Use dbgln() in strerror() and strsignal()
Printing error messages to stdout can have unintended side effects
depending on what the program is doing.
2021-04-12 22:34:07 +02:00
Gunnar Beutner
44486e8818 LibC: Turn CRASH() into a function and add noreturn attribute
This way CRASH() can be used in functions that are themselves
marked as noreturn.
2021-04-12 22:30:06 +02:00
Gunnar Beutner
64740a0214 LibC: getopt() and getopt_long() shouldn't modify argv 2021-04-11 09:51:20 +02:00
Gunnar Beutner
8ca5b8c065 LibC: Move S_* defines into <fcntl.h>
According to the Single UNIX Specification, Version 2 that's where
those macros should be defined. This fixes the libiconv port.

This also fixes some (but not all) build errors for the diffutils and nano ports.
2021-04-11 09:51:20 +02:00
Gunnar Beutner
be4b20c14d LibC: Make <limits.h> compatible with GCC so that it doesn't install a fixed header
GCC installs a fixed version of the <limits.h> header as per https://gcc.gnu.org/onlinedocs/gcc/Fixed-Headers.html.
The fixed header doesn't include the target's <limits.h> which in turn means that some definitions (such as PATH_MAX)
aren't available. This change requires rebuilding the toolchain (Toolchain/BuildIt.sh).

This fixes the flatbuffers port.

The commit also removes some non-standard defines (U*_MIN) which don't appear to be used
anywhere. By definition they're always 0 though so they're not strictly necessary.
2021-04-11 09:51:20 +02:00
Gunnar Beutner
03ffdeb43a LibC: Provide macros for the <ctype.h> functions
These are required for the 'tr' port.
2021-04-11 01:18:02 +02:00
Gunnar Beutner
fe8b1a732e LibC: Include additional headers in <arpa/inet.h>
According to the Single UNIX Specification, Version 2 the <arpa/inet.h>
header may optionally include <netinet/in.h> and <inttypes.h>. This
helps with porting software like c-ray that expects this to be the case.
2021-04-11 01:18:02 +02:00
AnotherTest
a6e4482080 AK+Everywhere: Make StdLibExtras templates less wrapper-y
This commit makes the user-facing StdLibExtras templates and utilities
arguably more nice-looking by removing the need to reach into the
wrapper structs generated by them to get the value/type needed.
The C++ standard library had to invent `_v` and `_t` variants (likely
because of backwards compat), but we don't need to cater to any codebase
except our own, so might as well have good things for free. :^)
2021-04-10 21:01:31 +02:00
Hendiadyoin1
e8ef10e2a6 Kernel/LibC: Make memset implementations the same
I dont know why we do a fast path in the Kernel, but not in Userspace

Also simplified the byte explosion in memset to "explode_byte"
it even seemed so, that we missed the highest byte when memseting something
2021-04-08 23:57:16 +02:00