summaryrefslogtreecommitdiff
path: root/Libraries/LibC
AgeCommit message (Collapse)Author
2020-05-20Revert "AK+LibC: Move non-placement new/delete into LibC"Andreas Kling
This reverts commit 2c823473930121aecbacf0422c8372a0912e581b.
2020-05-20Revert "LibC: Implement Itanium C++ ABI for static variable guards"Andreas Kling
This reverts commit cdbbe14062ea49f9a9d9b0e5627aba9efd07659a.
2020-05-20Revert "Build: Include headers from LibC, LibM, and LibPthread with -isystem"Andreas Kling
This reverts commit c1eb744ff0a82cf6c8e3470ac10e2f417c7d9de2.
2020-05-20LibC: Claim some copyright for stdioSergey Bugaev
I've written a large part of the new stdio, so I'm (partly) to blame for it now.
2020-05-20LibC: Handle fgets(size = 0)Sergey Bugaev
I accidentally broke this in the recent rewrite. This reinstantiates the behavior implemented in https://github.com/SerenityOS/serenity/commit/65714685259d1ea4ba9d32bc41aee6fc8c56a645.
2020-05-20Build: Include headers from LibC, LibM, and LibPthread with -isystemAndrew Kaster
Make sure that userspace is always referencing "system" headers in a way that would build on target :). This means removing the explicit include_directories of Libraries/LibC in favor of having it export its headers as SYSTEM. Also remove a redundant include_directories of Libraries in the 'serenity build' part of the build script. It's already set at the top. This causes issues for the Kernel, and for crt0.o. These special cases are handled individually.
2020-05-20LibC: Implement Itanium C++ ABI for static variable guardsAndrew Kaster
This is __cxa_guard_acquire, __cxa_guard_release, and __cxa_guard_abort. We put these symbols in a 'fake' libstdc++ to trick gcc into thinking it has libstdc++. These symbols are necessary for C++ programs and not C programs, so, seems file. There's no way to tell gcc that, for example, the standard lib it should use is libc++ or libc. So, this is what we have for now. When threaded code enters a block that is trying to call the constructor for a block-scope static, the compiler will emit calls to these methods to handle the "call_once" nature of block-scope statics. The compiler creates a 64-bit guard variable, which it checks the first byte of to determine if the variable should be intialized or not. If the compiler-generated code reads that byte as a 0, it will call __cxa_guard_acquire to try and be the thread to call the constructor for the static variable. If the first byte is 1, it will assume that the variable's constructor was called, and go on to access it. __cxa_guard_acquire uses one of the 7 implementation defined bytes of the guard variable as an atomic 8 bit variable. To control a state machine that lets each entering thread know if they gained 'initialization rights', someone is working on the varaible, someone is working on the varaible and there's at least one thread waiting for it to be intialized, or if the variable was initialized and it's time to access it. We only store a 1 to the byte the compiler looks at in __cxa_guard_release, and use a futex to handle waiting.
2020-05-20AK+LibC: Move non-placement new/delete into LibCAndrew Kaster
This allows operator new and operator delete to be available to anyone that links -lc (everyone) rather than just people that include kmalloc.h (almost no one).
2020-05-20LibC: Rewrite stdioSergey Bugaev
The new version uses buffering much more prominently, and hopefully performs better. It also uses something resembling C++ rather than plain C.
2020-05-20Kernel+LibC: Switch isatty() to use a fcntl()Sergey Bugaev
We would want it to work with only stdio pledged.
2020-05-17LibC: Don't let ctype isfoo() helpers access array out of boundsAndreas Kling
2020-05-17Kernel + LibC: Handle running processes in do_waitid()AnotherTest
2020-05-16Kernel: Absorb LibBareMetal back into the kernelAndreas Kling
This was supposed to be the foundation for some kind of pre-kernel environment, but nobody is working on it right now, so let's move everything back into the kernel and remove all the confusion.
2020-05-16Kernel: Remove now-unused KernelInfoPage.hAndreas Kling
2020-05-16Kernel: Remove sys$getdtablesize()Andreas Kling
I'm not sure why this was a syscall. If we need this we can add it in LibC as a wrapper around sysconf(_SC_OPEN_MAX).
2020-05-16Kernel: Remove the "kernel info page" used for fast gettimeofday()Andreas Kling
We stopped using gettimeofday() in Core::EventLoop a while back, in favor of clock_gettime() for monotonic time. Maintaining an optimization for a syscall we're not using doesn't make a lot of sense, so let's go back to the old-style sys$gettimeofday().
2020-05-15LibC: Fix execvp() errnoSergey Bugaev
Of course, using dbg() in the middle will change errno (most likely, reset it to zero).
2020-05-14Build: Switch to CMake :^)Sergey Bugaev
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-05-12LibC: Always assign the offset pointer to endptr in strto{u,}ll()AnotherTest
This patch makes strto{u,}l{l,}() behave more to-spec about endptr. "If endptr is not NULL, strtoull stores the address of the first invalid character in *endptr."
2020-05-11LibC: Implement strtoull correctlyBen Wiederhake
This fixes the behavior for several inputs: - '-0' (shouldn't work but was accepted) - '+3' (shouldn't work but was accepted) - '13835058055282163712' (should work but returned 9223372036854775807 with errno=ERANGE)
2020-05-11LibC: Use more flexible digit parsing code, deduplicateBen Wiederhake
2020-05-11LibC: Implement new strtod, accurate up to 8 epsBen Wiederhake
This strtod implementation is not perfectly accurate, as evidenced by the test (accuracy_strtod.cpp), but it is sufficiently close (up to 8 eps). The main sources of inaccuracy are: - Highly repeated division/multiplication by 'base' (Each operation brings a multiplicative error of 1+2^-53.) - Loss during the initial conversion from long long to double (most prominently, 69294956446009195 should first be rounded to 69294956446009200 and then converted to 69294956446009200.0 and then divided by ten, yielding 6929495644600920.0. Currently, it converts first to double, can't represent 69294956446009195.0, and instead represents 69294956446009190, which eventually yields 6929495644600919.0. Close, but technically wrong.) I believe that these issues can be fixed by rewriting the part at and after double value = digits.number(); and that the loss before that is acceptable. Specifically, losing the exact exponent on overflow is obviously fine. The only other loss occurs when the significant digits overflow a 'long long'. But these store 64(-7ish) bits, and the mantissa of a double only stores 52 bits. With a bit more thinking, one could probably get the error down to 1 or 2 eps. (But not better.) Fixes #1979.
2020-05-11LibC: Add minimal <netinet/ip.h>Yonatan Goldschmidt
It's based on <netinet/in.h> and more definitions might be required here (e.g, IP header).
2020-05-11LibC: Add missing <sys/time.h> include in <utmp.h>Yonatan Goldschmidt
This file uses 'struct timeval' without including relevant header.
2020-05-11LibC: Add inet_aton, based on inet_ptonYonatan Goldschmidt
2020-05-11Kernel+LibC: Add AF_MAXYonatan Goldschmidt
Will be updated as we add more protocols (e.g AF_INET6)
2020-05-11LibC: Return nullptr in fgets for size=0Yonatan Goldschmidt
I had this assert trigger, I believe in a legitimate case. This is the behavior glic and musl follow.
2020-05-10LibC: Fix get{sock,peer}name to match their kernel-side prototypesYonatan Goldschmidt
In f4302b58fb0, the kernel-side syscalls (e.g Process::sys$getsockname) were updated to use SC_get{sock,peer}name_params, but the libc functions were not updated.
2020-05-09Meta: Add script to enforce license headers & run it on TravisLinus Groh
2020-05-07LibC: Log calls to getrusageItamar
2020-05-05LibC: Remove ASSERT_NOT_REACHED in getrusageItamar
The gcc port was hitting that assertion for some reason. This patch fixes it.
2020-05-02LibC: added F_SETLK and SO_TYPE defsEd Rochenski
2020-04-30AK: Add ALWAYS_INLINE, NEVER_INLINE and FLATTEN macrosAndreas Kling
It's tedious to write (and look at) [[gnu::always_inline]] etc. :^)
2020-04-30LibC: Hint the compiler that assertions rarely failSergey Bugaev
Also, rewrite the macro to expand to an if statement instead of a weird ternary operator with a (void)0 banch.
2020-04-29Kernel: Fix integer overflow in framebuffer resolution handlingAndreas Kling
This made it possible to map the E1000 MMIO range into userspace and mess with the registers. Thanks to @grigoritchy for finding this! Fixes #2015.
2020-04-26AK: Add a simple and inefficient Base64 decoderAndreas Kling
2020-04-26Kernel: Added the ability to set the hostname via new syscallLuke Payne
Userland/hostname: Now takes parameter to set the hostname LibC/unistd: Added sethostname function
2020-04-18LibC: getprotoent() family of functionsRead H
This commit implements the getprotoent() family of functions, including getprotoent() getprotobyname() getprotobynumber() setprotoent() endprotoent() This implementation is very similar to the getservent family of functions, which is what led to the discovery of a bug in the process of reading the aliases. The ByteBuffer for the alias strings didn't include a null terminating character, this was fixed for both the protoent and servent family of functions by appending a null character to the end of them before adding them to the alias lists.
2020-04-16LibC netdb: Requested ChangesRead H
fix all requested changes including: - remove explicit vector initialization - change keep_service_file_open to boolean - closing service file on seek error - change C level char allocation to use ByteBuffer instead - simplified getservby* loops to a single loop - change fill_getserv_buffers return to early-return style
2020-04-16LibC: Service entry APIRead H
This commit implements the getservent family of functions: getservent() setservent() endservent() getservbyname() getservbyport() for accessing the /etc/services file. This commit has addressed the issues identified by utilizing more C++ structures, addressing unchecked error possibilities, strncpy bounds checking, and other issues found in the initial pull request
2020-04-13LibC: Fix truncated strncpy() in getlogin()Andreas Kling
2020-04-13LibC: Fix truncated strncpy() in /etc/group parsingAndreas Kling
2020-04-13LibC: Fix strncpy() overflow in /etc/passwd parsingAndreas Kling
2020-04-13LibC: Fix strncpy() overflow in gethostbyname()Andreas Kling
2020-04-13LibC: Simplify ASSERT() to reduce code sizeAndreas Kling
Instead of pushing the message, file name, line# and function name separately, we now mash the message, file name and line# into a string constant and pass that. This means that the failure path only has to push a single address onto the stack, reducing the code size and causing the compiler to inline many more functions containing an assertions (e.g RefPtr::operator*()) Obviously if you wanted minimal size, you could turn assertions off entirely, but I really like running with assertions, so let's make a little effort to reduce their impact. :^)
2020-04-13LibC: Simplify the gettid() cache by just clearing the cache in fork()Andreas Kling
It's hilarious how much better this is. Thanks to Sergey for suggesting it! :^)
2020-04-13ptrace: Report error in PT_PEEK via errnoItamar
The syscall wrapper for ptrace needs to return the peeked value when using PT_PEEK. Because of this, the user has to check errno to detect an error in PT_PEEK. This commit changes the actual syscall's interface (only for PT_PEEK) to allow the syscall wrapper to detect an error and change errno.
2020-04-13ptrace: Add PT_SETREGSItamar
PT_SETTREGS sets the regsiters of the traced thread. It can only be used when the tracee is stopped. Also, refactor ptrace. The implementation was getting long and cluttered the alraedy large Process.cpp file. This commit moves the bulk of the implementation to Kernel/Ptrace.cpp, and factors out peek & poke to separate methods of the Process class.
2020-04-13ptrace: Add PT_POKEItamar
PT_POKE writes a single word to the tracee's address space. Some caveats: - If the user requests to write to an address in a read-only region, we temporarily change the page's protections to allow it. - If the user requests to write to a region that's backed by a SharedInodeVMObject, we replace the vmobject with a PrivateIndoeVMObject.
2020-04-13ptrace: Add PT_PEEKItamar
PT_PEEK reads a single word from the tracee's address space and returns it to the tracer.