Commit Graph

54 Commits

Author SHA1 Message Date
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
René Hickersberger
ad560cff0f LibC: Implement vdprintf and dprintf
These functions work just like `vfprintf` and `fprintf`, except that
they take a file descriptor as their first argument instead of a FILE*.
2023-09-03 06:21:40 +02:00
Timothy Flynn
05fbd31727 Revert "LibC: Remove duplicate log statement"
This reverts commit 58c91f0a99.
2023-07-22 12:19:53 -04:00
Sam Atkins
58c91f0a99 LibC: Remove duplicate log statement
Now that warnln() also outputs to the debug console, this would print
the error twice.
2023-07-16 00:59:13 +02:00
Ben Wiederhake
3281050359 Everywhere: Remove "LibC/" includes, add lint-rule against it 2023-01-07 10:01:37 -07:00
sin-ack
d5fbdf1866 Kernel+LibC+LibCore: Implement renameat(2)
Now with the ability to specify different bases for the old and new
paths.
2022-12-11 19:55:37 -07:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Linus Groh
d26aabff04 Everywhere: Run clang-format 2022-12-03 23:52:23 +00:00
Liav A
74a080fb68 LibC: Use proper casting in fgetc and fgetc_unlocked functions
In the fgetc function, a fix was already in place but was clunky. A real
proper solution is to use an unsigned char instead of a char when
returning the value, so an implicit cast is happening based on the
assumption that the value is unsigned, so if the variable contained 0xff
it won't be treated as -1, but as unsigned 0xff, so the result int will
be 0xff and not -1.

The same solution is applied to the fgetc_unlocked function as well.
2022-10-18 13:21:38 +02:00
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