summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC
AgeCommit message (Collapse)Author
2022-07-10Kernel+LibC+LibCore: Pass fcntl extra argument as pointer-sized variablegggggg-gggggg
The extra argument to fcntl is a pointer in the case of F_GETLK/F_SETLK and we were pulling out a u32, leading to pointer truncation on x86_64. Among other things, this fixes Assistant on x86_64 :^)
2022-07-08LibC: Move stack canary initialization before the global constructorsTim Schumacher
Once again, QEMU creates threads while running its constructors, which is a recipe for disaster if we switch out the stack guard while that is already running in the background. To solve that, move initialization to our LibC initialization stage, which is before any actual external initialization code runs.
2022-07-08Kernel: Implement `sigsuspend` using a SignalBlockerTim Schumacher
`sigsuspend` was previously implemented using a poll on an empty set of file descriptors. However, this broke quite a few assumptions in `SelectBlocker`, as it verifies at least one file descriptor to be ready after waking up and as it relies on being notified by the file descriptor. A bare-bones `sigsuspend` may also be implemented by relying on any of the `sigwait` functions, but as `sigsuspend` features several (currently unimplemented) restrictions on how returns work, it is a syscall on its own.
2022-07-08LibC: Add stubs for glob and globfreeTim Schumacher
2022-07-06AK: Use an enum instead of a bool for String::replace(all_occurences)DexesTTP
This commit has no behavior changes. In particular, this does not fix any of the wrong uses of the previous default parameter (which used to be 'false', meaning "only replace the first occurence in the string"). It simply replaces the default uses by String::replace(..., ReplaceMode::FirstOnly), leaving them incorrect.
2022-07-06LibC: Stop leaking FILE in `getpwuid` and `getpwnam`Tim Schumacher
2022-07-06LibC: Don't clear static storage during `endpwent`Tim Schumacher
2022-07-06LibC: Don't clear static storage during `endgrent`Tim Schumacher
The POSIX documentation for `endgrent` only mentions that it "closes the group database", not that it clears the backing storage for return values. This means that applications might make use of the returned values even after closing the group database itself. This includes our own implementations for `getgrnam` and `getgrgid`. The specification also states that "the storage areas might be overwritten by a subsequent call to `getgrgid`, `getgrnam`, or `getgrent`". This implies that `getgrgid` and `getgrnam` aren't meant to have their own static storage and instead rely on the storage of `getgrent`.
2022-06-30LibC: Align _ctype_ to newlib's implementationAndrew Kaster
newlib has an extra character slot at the beginning to enable some macro tricks that cause a warning when someone passes a type that's not "int" into a ctype function. Our deviation from this causes issues for LLVM.
2022-06-30LibC: Implement `wcswidth`Tim Schumacher
2022-06-30LibC: Stub out `brk` and `sbrk`Tim Schumacher
2022-06-25LibC: Implement the getsubopt functionLiav A
This is a LibC function that POSIX defines to help userspace programs to get suboptions. An example of a suboption is the token "pixclk" from a Shell command running "edid-decode --gtf w=1024,h=768,pixclk=48". The function should be run in a while loop to acquire all suboptions until the last one.
2022-06-23LibC: Implement `wcsftime` using a makeshift solutionTim Schumacher
2022-06-21LibC: Make `scanf` read an `unsigned long` when using `%lu`Tim Schumacher
2022-06-21LibC: Don't change the stack canary across function boundariesTim Schumacher
2022-06-19LibC: Stop leaking FILE* from use of getgrnam and getgrgidAndrew Kaster
2022-06-18LibC: Add `ctermid`SeekingBlues
We simply return "/dev/tty", since it always refers to the controlling terminal of the calling process.
2022-06-17LibC: Add printf and scanf format macros for "fast" and "least" typeskleines Filmröllchen
As usual, we just define these based on the given integer size itself.
2022-06-17LibC: Allow parsing numbers right on the cutoffTim Schumacher
2022-06-17LibC: Add POSIX spec links to `wait`, `waitpid` and `waitid`SeekingBlues
2022-06-17LibC: Make `waitpid`'s return value more POSIX-compliantSeekingBlues
* Always return 0 if `WNOHANG` is specified and no waitable child is found, even if `wstatus` is null. * Do not return 0 if the child is continued. Treat it the same way as all the other states. Refer to the RETURN VALUE section of the POSIX spec: https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html
2022-06-17LibC: Add `WIFCONTINUED` macroSeekingBlues
Like other systems, we can encode the continued state with 0xffff in the status value. This is needed for some ports.
2022-06-12LibC: Force default visibility for the _ctype_ symbolAndrew Kaster
When ports compile with -fvisibility=hidden, they can end up with unresolved references to _ctype_ without passing -Wl,--allow-shlib-undefined
2022-06-12LibC: Add public and independent ucontext.h headerAndrew Kaster
2022-06-04LibC: Make asctime_r() in time.h POSIX compliantMay
Previously, when the asctime_r() buffer overflowed, we would fail an assertion. This patch modifies asctime_r() to instead set errno and return null.
2022-05-23LibC: Add barebones <complex.h>Peter Elliott
2022-05-21Kernel+LibC: Implement futimens(3)Ariel Don
Implement futimes() in terms of utimensat(). Now, utimensat() strays from POSIX compliance because it also accepts a combination of a file descriptor of a regular file and an empty path. utimensat() then uses this file descriptor instead of the path to update the last access and/or modification time of a file. That being said, its prior behavior remains intact. With the new behavior of utimensat(), `path` must point to a valid string; given a null pointer instead of an empty string, utimensat() sets `errno` to `EFAULT` and returns a failure.
2022-05-21Kernel+LibC+VFS: Implement utimensat(3)Ariel Don
Create POSIX utimensat() library call and corresponding system call to update file access and modification times.
2022-05-21LibC: Add a stub for nice()Simon Danner
2022-05-20LibC: Implement posix_memalign(3) and aligned_alloc(3)Peter Elliott
Some ports linked against posix_memalign, but didn't use it, and others used it if it was Available. So I decided to implement posix_memalign. My implementation adds almost no overhead to regular mallocs. However, if an alignment is specified, it will use the smallest ChunkedBlock, for which aligned chunks exist, and simply use one of the chunks that is aligned. If it cannot use a ChunkedBlock, for size or alignment reasons, it will use a BigAllocationBlock, and return a pointer to the first aligned address past the start of the block. This implementation supports alignments up to 32768, due to the limitations of the BigAllocationBlock technique.
2022-05-12LibC: Add herror() and hstrerror()Michał Lach
2022-05-12LibC: Make h_errno thread-localMichał Lach
2022-05-12LibC+Kernel: Prevent string functions from calling themselvesDaniel Bertalan
Most of the string.h and wchar.h functions are implemented quite naively at the moment, and GCC's pattern recognition pass might realize what we are trying to do, and transform them into libcalls. This is usually a useful optimization, but not when we're implementing the functions themselves :^) Relevant discussion from the GCC Bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102725 This prevents the infamous recursive `strlen`. A more proper fix would be writing these functions in assembly. That would likely give a small performance boost as well ;)
2022-05-08LibC: Add missing macro definitions for errno codescircl
2022-05-05Everywhere: Purge all support and usage of framebuffer devicesLiav A
Long live the DisplayConnector object!
2022-05-05Everywhere: Rename FB prefix structure names => GraphicsLiav A
2022-05-05Everywhere: Rename FB prefix name ioctls => GRAPHICSLiav A
2022-05-05DisplaySettings+WindowServer: Add support for display connector devicesLiav A
2022-05-05Kernel/Graphics: Introduce the DisplayConnector classLiav A
The DisplayConnector class is meant to replace the FramebufferDevice class. The advantage of this class over the FramebufferDevice class is: 1. It removes the mmap interface entirely. This interface is unsafe, as multiple processes could try to use it, and when switching to and from text console mode, there's no "good" way to revoke a memory mapping from this interface, let alone when there are multiple processes that call this interface. Therefore, in the DisplayConnector class there's no implementation for this method at all. 2. The class uses a new real-world structure called ModeSetting, which takes into account the fact that real hardware requires more than width, height and pitch settings to mode-set the display resolution. 3. The class assumes all instances should supply some sort of EDID, so it facilitates such mechanism to do so. Even if a given driver does not know what is the actual EDID, it will ask to create default-generic EDID blob. 3. This class shifts the responsibilies of switching between console mode and graphical mode from a GraphicsAdapter to the DisplayConnector class, so when doing the switch, the GraphicsManagement code actually asks each DisplayConnector object to do the switch and doesn't rely on the GraphicsAdapter objects at all.
2022-05-05LibC: Add IN6_IS_ADDR_MULTICASTTim Schumacher
2022-05-03LibC: Hide `posix_memalign` by defaultTim Schumacher
This should keep ports from preferring `posix_memalign` over other implementations of aligned memory.
2022-05-02Meta+Userland: Add ENABLE_USERSPACE_COVERAGE_COLLECTION CMake optionAndrew Kaster
This option sets -fprofile-instr-generate -fcoverage-mapping for Clang builds only on almost all of Userland. Loader and LibTimeZone are exempt. This can be used for generating code coverage reports, or even PGO in the future.
2022-05-01LibC: Implement a faster memset routine for x86-64 in assemblyDaniel Bertalan
This commit addresses the following shortcomings of our current, simple and elegant memset function: - REP STOSB/STOSQ has considerable startup overhead, it's impractical to use for smaller sizes. - Up until very recently, AMD CPUs didn't have support for "Enhanced REP MOVSB/STOSB", so it performed pretty poorly on them. With this commit applied, I could measure a ~5% decrease in `test-js`'s runtime when I used qemu's TCG backend. The implementation is based on the following article from Microsoft: https://msrc-blog.microsoft.com/2021/01/11/building-faster-amd64-memset-routines Two versions of the routine are implemented: one that uses the ERMS extension mentioned above, and one that performs plain SSE stores. The version appropriate for the CPU is selected at load time using an IFUNC.
2022-05-01LibELF: Add support for IFUNCsDaniel Bertalan
IFUNC is a GNU extension to the ELF standard that allows a function to have multiple implementations. A resolver function has to be called at load time to choose the right one to use. The PLT will contain the entry to the resolved function, so branching and more indirect jumps can be avoided at run-time. This mechanism is usually used when a routine can be made faster using CPU features that are available in only some models, and a fallback implementation has to exist for others. We will use this feature to have two separate memset implementations for CPUs with and without ERMS (Enhanced REP MOVSB/STOSB) support.
2022-04-30LibC: Add all the `POSIX_FADV_*` constantsTim Schumacher
2022-04-29LibC: Implement posix_fadvise() (as a harmless no-op)Andreas Kling
2022-04-29LibC: Add more _POSIX_FOO constants to unistd.hAndreas Kling
Let's advertise more of our POSIX capabilities. :^)
2022-04-29LibC: Add MIN, MAX and howmany macros to sys/param.hAndreas Kling
2022-04-29LibC: Actually set the FPU environment instead of its pointerTim Schumacher
2022-04-29Kernel: Support userspace TTY graphics modesettingPeter Elliott
This is a copy of linux's KDSETMODE/KDGETMODE console ioctl(2) interface.