Commit graph

44 commits

Author SHA1 Message Date
Liav A
db45e242c4 LibC: Do an explicit static_cast in the fgetc function
We assumed that by returning a char in the fgetc function that an
implicit cast is sufficient, but apparently if that char contains 0xff,
the result int will be -1 (0xFFFFFFFF). To ensure this does not happen,
let's do an explicit casting.
2022-10-17 01:08:22 +02:00
Tim Schumacher
224ac1a307 LibC: Remove a bunch of weak pthread_* symbols 2022-07-19 20:58:51 -07:00
SeekingBlues
f34e69a52b LibC: Add ctermid
We simply return "/dev/tty", since it always refers to the controlling
terminal of the calling process.
2022-06-18 15:10:13 +02:00
Tim Schumacher
3237efc661 LibC: Implement __fseterr 2022-04-03 19:15:14 +02:00
Tim Schumacher
4f706d819a LibC: Implement __freadptrinc 2022-04-03 19:15:14 +02:00
Tim Schumacher
89ed0649f7 LibC: Implement __freadahead 2022-04-03 19:15:14 +02:00
Tim Schumacher
9b543ddb16 LibC: Implement __freadptr 2022-04-03 19:15:14 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Tim Schumacher
4917a610ab LibC: Partially implement __fpending 2022-03-28 10:38:02 -07:00
Ali Mohammad Pur
18f68d1aea LibC: Stub out fmemopen() 2022-02-12 12:16:59 +01:00
Andrew Kaster
353e72ac9b LibC+Kernel: Remove global variable use from snprintf and fprintf
The global variable use in these functions is super thread-unsafe and
means that any concurrent calls to sprintf or fprintf in a process
could race with each other and end up writing unexpected results.
We can just replace the function + global variable with a lambda that
captures the relevant argument when calling printf_internal instead.
2022-02-09 06:22:33 +00:00
Daniel Bertalan
6a6dbf5b0b LibC: Implement fflush(nullptr)
This caused all open file streams to be flushed.

This commit also changes `FILE::create` to handle buffer allocation
failure gracefully.
2022-01-16 14:59:21 -08:00
Andrew Kaster
d809637023 Userland: Resolve tautological-constant-out-of-range-compare warnings
Stop comparing platform-specific sized integer types to max() values of
other interger types. Enable the warning everywhere.
2022-01-04 07:51:31 +00:00
Conor Byrne
8515d7d5ab LibC: Implement `flockfile and funlockfile`
To do this, we must set the type attribute when initializing a FILE to
``__PTHREAD_MUTEX_RECURSIVE``.
2022-01-01 09:50:32 +00:00
Brian Gianforcaro
140a544051 LibC: Add POSIX spec comments for stdio APIs 2021-12-21 18:16:48 -08:00
Ali Mohammad Pur
e717ca32d1 LibC: Implement ungetwc() 2021-12-21 21:24:36 +03:30
Ali Mohammad Pur
db7a6d6e74 LibC: Implement f{get,put}ws() 2021-12-21 21:24:36 +03:30
Ali Mohammad Pur
cb90856756 LibC: Implement {f,}putwc() 2021-12-21 21:24:36 +03:30
Ali Mohammad Pur
cf17677206 LibC: Implement {f,}getwc() 2021-12-21 21:24:36 +03:30
Ben Wiederhake
33079c8ab9 Kernel+UE+LibC: Remove unused dbgputch syscall
Everything uses the dbgputstr syscall anyway, so there is no need to
keep supporting it.
2021-11-24 22:56:39 +01:00
Andreas Kling
c93687c15e LibC: Make remove() propagate non-EISDIR unlink() errors
Regressed in 16105091ba.
2021-09-09 21:49:49 +02:00
Andreas Kling
16105091ba LibC: Remove a bunch of pointless rc temporaries in stdio.cpp 2021-09-09 21:25:10 +02:00
Daniel Bertalan
b9f30c6f2a Everywhere: Fix some alignment issues
When creating uninitialized storage for variables, we need to make sure
that the alignment is correct. Fixes a KUBSAN failure when running
kernels compiled with Clang.

In `Syscalls/socket.cpp`, we can simply use local variables, as
`sockaddr_un` is a POD type.

Along with moving the `alignas` specifier to the correct member,
`AK::Optional`'s internal buffer has been made non-zeroed by default.
GCC emitted bogus uninitialized memory access warnings, so we now use
`__builtin_launder` to tell the compiler that we know what we are doing.
This might disable some optimizations, but judging by how GCC failed to
notice that the memory's initialization is dependent on `m_has_value`,
I'm not sure that's a bad thing.
2021-07-03 01:56:31 +04:30
Tim Schumacher
ccef5fe234 LibC: Implement __fpurge 2021-05-30 14:56:50 +01:00
Tim Schumacher
a3b4e43dd8 LibC: Implement __freading and __fwriting
These functions are used by gnulib (and therefore many GNU utilities)
to provide access to internal details of the stdio FILE structure.
2021-05-30 14:56:50 +01:00
Gunnar Beutner
4c6a91d0c0 LibC: Implement vscanf
libstdc++v3 checks whether vscanf is available and only then makes C99
stdio functions available in the std namespace.
2021-05-09 15:35:01 +02:00
Gunnar Beutner
1dfa386d70 LibC: Add missing initialization for the FILE mutex 2021-04-30 08:21:08 +02:00
Gunnar Beutner
6adb0dbdba LibC: Implement fgetc_unlocked(), fread_unlocked() and getc_unlocked() 2021-04-29 23:12:05 +02:00
Gunnar Beutner
36ee8a8c25 LibC: Make rewind() ignore errors as it should
POSIX says that rewind() should ignore errors and reset the
stream's error indicator. So let's do that.
2021-04-29 23:12:05 +02:00
Gunnar Beutner
62ee003ef5 LibC: Make stdio thread-safe 2021-04-29 23:12:05 +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
Gunnar Beutner
ddcd149224 LibC: Avoid division by zero in fread()/fwrite() 2021-04-19 22:13:52 +02:00
Andreas Kling
bf1ad16078 LibC: Fix FILE::flush() passing bogus arguments to lseek()
This was a regression from the 64-bit off_t changes.

When dropping buffered data after a flush, we would subtract the
buffered amount from zero to get the seek offset. This didn't work
right since the subtraction was done with a 32-bit size_t and we
ended up with e.g (i64)0xfffffffc as the offset.

Fixes #6003.
2021-04-03 23:01:14 +02:00
Andreas Kling
fdd01a0a07 LibC: Implement asprintf() and vasprintf()
These simply use StringBuilder::appendvf() internally which is not
optimal in terms of heap allocations, but simple enough and I don't
think they are performance sensitive functions anyway.
2021-03-28 18:39:32 +02:00
Andreas Kling
ef1e5db1d0 Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)
Good-bye LogStream. Long live AK::Format!
2021-03-12 17:29:37 +01:00
Ben Wiederhake
bceb98e2df Userland: Remove superfluous headers
Userland has no reason to access 'kmalloc'.
2021-03-11 12:32:53 +01:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
8d98051551 AK+LibC: Remove dbgprintf() :^)
Everything has been moved to dbgln() or other AK::Format-based APIs.
We can finally get rid of this old thing.
2021-02-20 17:17:30 +01:00
Andreas Kling
dffab4e034 LibC: Convert dbgprintf() => dbgln() 2021-02-17 15:39:32 +01:00
Andreas Kling
e87eac9273 Userland: Add LibSystem and funnel all syscalls through it
This achieves two things:

- Programs can now intentionally perform arbitrary syscalls by calling
  syscall(). This allows us to work on things like syscall fuzzing.

- It restricts the ability of userspace to make syscalls to a single
  4KB page of code. In order to call the kernel directly, an attacker
  must now locate this page and call through it.
2021-02-05 12:23:39 +01:00
Mart G
86a9e26996 LibC: Prevent remove from calling rmdir when unlink succeeds. 2021-01-23 15:26:44 +01:00
Andreas Kling
b0f19c2af4 LibC: Templatize unique filename enumeration for mkstemp() et al
This allows us to implement mkstemp() with open() directly, instead of
first lstat()'ing, and then open()'ing the filename.

Also implement tmpfile() in terms of mkstemp() instead of mktemp().
2021-01-22 19:39:44 +01:00
Linus Groh
b42f0b9650 LibC: Change a couple of ASSERT_NOT_REACHED() to TODO()
Just for semantic correctness and better visibility of those
unimplemented stub functions.
2021-01-17 08:43:46 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Renamed from Libraries/LibC/stdio.cpp (Browse further)