CCCPaste

0001-libc-gpu-ftell-uses-LIBC_FTELL.patch

[libc][GPU] ftell: use the LIBC_FTELL opcode instead of LIBC_FSEEK

The GPU ftell() opened the RPC port with LIBC_FSEEK and only filled data[0].
The host server then called fseek(stream, data[1], data[2]) with whatever was
left in the buffer from a previous message. glibc just returns EINVAL, so the
bug is silent on Linux; the MSVC CRT treats an invalid 'origin' as an invalid
parameter and terminates the process (0xC0000409, FAST_FAIL_INVALID_ARG).
Still present in llvm-project main as of 2026-10.

--- a/libc/src/stdio/gpu/ftell.cpp
+++ b/libc/src/stdio/gpu/ftell.cpp
@@ -16,7 +16,7 @@

LLVM_LIBC_FUNCTION(long, ftell, (::FILE * stream)) {
long ret;
- rpc::Client::Port port = rpc::client.open<LIBC_FSEEK>();
+ rpc::Client::Port port = rpc::client.open<LIBC_FTELL>();
port.send_and_recv(
[=](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = file::from_stream(stream);