Commit Graph

52 Commits

Author SHA1 Message Date
Dean c963432db0
Merge pull request #1645 from XairRrR/fix/raise-open-file-limit
fix(libkernel): raise the open file soft limit on Linux
2026-10-10 14:44:55 +13:00
ArjenS-LA 705e49d407 fix(libkernel): preserve Windows file timestamp precision 2026-10-10 01:51:56 +02:00
Raihan Abdul Majid e768d97949 fix(kernel): keep the file offset in Windows AIO reads and writes
Each Windows AIO request is an overlapped ReadFile/WriteFile at the
request's offset, which on a synchronous handle also moves the
descriptor's file pointer; on the console AIO transfers leave it alone.
The requests now go through the positioned path sceKernelPread and
sceKernelPwrite use (NativePositioned in Stdio.cpp, exposed as
NativePositioned_nid_no_patch), which restores the pointer afterwards.
Negative offsets still fail with EINVAL before the transfer.

GuestAio sets the offset to 2 before a write batch and checks it is
still 2 after. TechnicalDebt records that a concurrent read or write on
the same descriptor can see the moved pointer in between, as for the
pread family.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UTjpbMX7BUFMZZaxJE98zV
2026-10-10 00:22:22 +02:00
Adrià 72cf6c3c5a
Merge pull request #1624 from babyhuey/feat/libkernel-lstat
feat(libkernel): implement lstat
2026-10-09 23:52:02 +02:00
Adrià 830130aa00
Merge pull request #1620 from babyhuey/feat/libkernel-fdatasync
feat(libkernel): implement fdatasync
2026-10-09 23:50:45 +02:00
Adrià 3d19932caf
Merge pull request #1738 from SleglJan/feat/libkernel-termios
feat(libkernel): implement tcgetattr and tcsetattr
2026-10-09 23:48:53 +02:00
Hannah Lyons 903f50a3b4 feat(libkernel): implement lstat 2026-10-09 17:30:43 -04:00
Hannah Lyons 6768210713 feat(libkernel): implement fdatasync 2026-10-09 17:30:24 -04:00
Jan Šlégl 14cc6497d2 feat(libkernel): implement tcgetattr and tcsetattr
A title's descriptors are taken as never being terminals: a file or
pipe gets ENOTTY with the termios untouched, a socket gets what its
protocol answers a termios ioctl on FreeBSD (EADDRNOTAVAIL for AF_INET,
EOPNOTSUPP otherwise), and a closed or invalid descriptor EBADF.
tcsetattr gives EINVAL for an action other than TCSANOW, TCSADRAIN or
TCSAFLUSH, with or without TCSASOFT, before anything else, and EFAULT
for a null termios before the descriptor is checked; with TCSASOFT a
null termios throws, where FreeBSD's libc faults copying it. What the
console gives a title as descriptors 0 to 2 is unknown, as recorded in
TechnicalDebt.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-09 23:17:12 +02:00
Hannah Lyons d6963f46d6 feat(libkernel): implement getdents and getdirentries 2026-10-09 13:30:45 -04:00
XairRrR df3aa1a9db fix(libkernel): raise the open file soft limit on Linux
Each direct memory backing keeps a memfd open, so a title such as
Dreaming Sarah (PPSA02929) holds about 1100 descriptors at startup.
With the systemd default soft limit of 1024, later opens fail with
EMFILE: memfd_create throws "create direct memory backing: Too many
open files", or the title's fopen returns NULL and it faults in fread.

libkernel now raises the RLIMIT_NOFILE soft limit to the hard limit
when it is loaded, before the title creates any descriptor, and throws
if the limit cannot be read or raised.
2026-10-08 17:38:48 +02:00
Adrià fe9beae001
Merge pull request #1452 from mrk1987/fix/posix-mkdir-errors
fix(libkernel): return POSIX errors from mkdir
2026-10-08 16:09:37 +02:00
kjhq bb1a4cbec4 fix(libkernel): flush only the paths the guest changed in sceKernelSync on Windows
Opening a volume needs administrator rights, so the volume flush skipped
every volume in a normal user session. The libc, libkernel, save data and
app content file functions now record each host file and directory they
change. On Windows sceKernelSync flushes the recorded paths that changed
since the previous call, plus their changed parent directories, through
handles a normal user can open. Linux still calls sync().
2026-10-08 08:27:22 +00:00
Raihan Abdul Majid 87f4444441 fix(kernel): transfer each iovec directly on Windows
Gathering every iovec into one host buffer threw for a total above
INT_MAX, which a console readv/writev accepts, and copied the whole
transfer twice. Each iovec is now read or written in place, in chunks
of at most INT_MAX bytes. A readv on a pipe returns after one read so
it does not block once the available bytes are consumed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UTjpbMX7BUFMZZaxJE98zV
2026-10-08 09:52:49 +02:00
Raihan Abdul Majid a38df0f020 feat(kernel): implement vectored file IO on Windows
sceKernelReadv, sceKernelWritev, sceKernelPreadv and sceKernelPwritev threw on Windows. They now gather or scatter through one host buffer and issue a single read or write, with the same argument checks and error codes as the Linux path. Positioned transfers restore the file offset afterwards, as pread and pwrite do on POSIX, and report ESPIPE for handles that are not disk files. guest_file_vector now runs on Windows as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UTjpbMX7BUFMZZaxJE98zV
2026-10-08 09:52:49 +02:00
mrk1987 a9d31f3cba fix(libkernel): return POSIX errors from mkdir 2026-10-08 09:20:04 +02:00
kjhq 295780ab20 feat(libkernel): report no write throttling in sceKernelWriteThrottlingStatus
The host has no SSD write budget, so the status reports the largest budget in its first qword and zeroes the rest.
2026-10-08 08:21:23 +02:00
Gjon Gojcevic ccc9e3c6da fix(libkernel): return EBADF from sceKernelClose for a descriptor that is not open 2026-10-07 14:10:53 -04:00
alfalfa-star e91fe0f063 feat(libs): declare the exports PPSA14632 imports that no library provides
LEGO Horizon Adventures imports 19 functions that no library exports
and no open pull request adds, so it fails eager binding. They are
declared as throwing stubs. The two libSceAjmWVorbis imports have no
known name and are exported by NID from libSceAjm.native.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 07:10:13 +02:00
Adrià Franch ab98cd7f4a feat(libkernel): sceKernelReadv, Writev, Preadv and Pwritev
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-06 07:33:51 +02:00
Nicolas Abosch 7789c0a57b feat(libs): implement homebrew libc and kernel runtime exports 2026-10-05 22:40:16 -03:00
Nahuel Genchi ec17b9811c feat(libkernel): implement futimes 2026-10-05 20:47:34 -03:00
Nahuel Genchi eded1e010f feat(libkernel): implement fchmod and sceKernelFchmod 2026-10-05 20:46:34 -03:00
Merijn 8f6328242d feat(libs): add exports imported by PPSA12544
Implement scePthreadGetschedparam and scePthreadSetschedparam on top of
the thread priority, POSIX utimes and fsync on top of sceKernelUtimes
and sceKernelFsync, and sceUserServiceGetAccessibilityZoomFollowFocus
like the other accessibility queries. Add the remaining imports of
PPSA12544 as unimplemented exports and record unknown NIDs and
signatures in the technical debt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 19:25:52 +02:00
Dean d0bec2e448
Merge pull request #378 from DotDebian/fix/posix-file-errno
fix(libkernel): return -1 and set errno from the POSIX open, stat, unlink and rmdir
2026-10-04 14:01:57 +13:00
boykopovar 5026351b3f
Merge pull request #274 from RomainROCH/codex/fix-directory-buffer-errors
fix(libkernel): report undersized Windows directory buffers
2026-10-02 22:39:37 +03:00
boykopovar d399b4e04c
Merge pull request #245 from RomainROCH/codex/fix-windows-directory-close
fix(libkernel): clear directory metadata on close
2026-10-02 22:21:30 +03:00
DotDebian 1817d83fec fix(libkernel): return -1 and set errno from the POSIX open, stat, unlink and rmdir
open, _open, stat, unlink and rmdir forwarded the result of their sceKernel
twin, so a failure returned 0x8002xxxx instead of -1 and errno was never set
to the guest error. They now return -1 with errno set to the code carried by
the sce error, and report a null pointer as EFAULT and an empty path as
ENOENT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 18:17:12 +02:00
RomainROCH 021eb65b51 fix(libkernel): report undersized Windows directory buffers 2026-10-01 23:24:41 +02:00
Michon 676bbea348 fix(libkernel): read, pread, AIO and APR write into guest memory as host writes
A file read into guest memory is a host write: before the I/O it pins the shared pages it
covers, which reopens any page armed for write tracking and keeps write tracking from arming
it again until the read ends, when the pages count as written. A destination the guest cannot
write fails with EFAULT before any I/O; read and pread throw as for any failed read, AIO
reports SCE_KERNEL_ERROR_EFAULT, and APR throws. APR also throws when a read ends before the
requested size.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-01 18:56:36 +02:00
RomainROCH 91dd508c85 fix(libkernel): clear directory metadata on close 2026-10-01 16:48:10 +02:00
asimplestray a4e755ccb1 feat(kernel): implement file metadata ops and address conversion 2026-09-30 16:51:37 +00:00
STL1te 6b36c050fe style: drop the branch's code comments per CONVENTIONS.md
Only the lines this branch added lose their comments; the commits before
keep them, with the reasoning behind each change, for whoever digs into
that code later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 21:25:29 +03:00
STL1te c206f7049a feat(kernel, libc): memory, files and threads for retail title boot
libkernel:
- direct memory keeps its contents per physical page across unmap and
  remap; a page mapped at two live addresses at once throws
- sceKernelDirectMemoryQuery answers from tracked allocations
- SCE protections read back as set, GPU and AMPR bits included
- APR prefix path resolve, file size and stat by id, positional reads,
  fsync/pread/pwrite; directories open as descriptors on Windows
- sceKernelCheckReachability, getpeername, shutdown
- Dinkumware C11 threads (_Mtx_*, _Cnd_*, _Thrd_*) in the title libc
  layout; any pthread stack size, rounded at thread creation

libc:
- unaddressed guest mappings go to the system-managed area from
  0x2_0000_0000, leaving the application area to fixed mappings
- the process starts in /app0
- guest sscanf on Windows; a null %s prints as (null) as on FreeBSD
- localeconv, _FNan, _FDtest, _FExp, __udivti3, wcsncpy_s, aligned
  operator new, _Throw_Cpp_error

Tests: direct memory following physical pages, guest formatting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 21:22:13 +03:00
Claude 2aced8e8d9
Merge fix/audit-2026-09 (with upstream main) into refactor/kernel-error-header
Bring in the resolved #25 branch, which already carries upstream main
including boykopovar/AnyPS5#10, and re-apply the KernelErrors.hpp
refactor onto the rewritten files:

- Equeue: drop the local EQUEUE_ERROR_* constants and use the shared
  SCE_KERNEL_ERROR_* names.
- Pthread Attr/Thread: drop local error constants and include
  KernelErrors.hpp.
- Pthread Cond/Mutex: take upstream; they no longer define local
  SCE_KERNEL_ERROR_* constants.
- Semaphore: drop KERNEL_SEMA_ERROR_* in favour of KernelErrors.hpp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018emyZ4Rk8yoSJvxTFBe4DL
2026-09-28 07:40:42 +00:00
Claude 210987745c
Merge upstream main into fix/audit-2026-09
Resolve conflicts with boykopovar/AnyPS5#10 (sce module loading) and
later upstream changes.

- Pthread Cond/Mutex: take upstream. It already releases mutex
  ownership across condition waits, returns ETIMEDOUT 0x8002003C, and
  rejects unlocks from non-owners for every mutex type.
- Pthread Thread: keep upstream's lifecycle, Windows adoption and job
  affinity; re-apply the POSIX fixes on top: reference-counted
  release on join/detach/exit, self-join rejection on both platforms,
  and scePthreadSelf adoption for threads not created by
  scePthreadCreate.
- Semaphore: keep upstream's TimedWait::Condition and wait tracing;
  re-apply sceKernelDeleteSema waking waiters with EACCES.
- Relinker: keep --windows-gui alongside upstream's --skip-sce-module,
  trampoline-aware Patch signature and new Python tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018emyZ4Rk8yoSJvxTFBe4DL
2026-09-28 07:34:25 +00:00
Dean Galvin f7e1bdf0b9 feat(libkernel): pread, pwrite, getdents and getdirentries on linux
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ButHENCbXXt8h4EZuWUabJ
2026-09-28 16:40:22 +13:00
devilismyfriend a503d0b617 Merge remote-tracking branch 'origin/main' into feat/demons-souls-boot
Brings in main up to 9958d26 (homebrew runtime, POSIX wrappers in
libkernel, sce_module guest modules and --skip-sce-module, the --to-intel
general pipeline, libSceRandom, libSceRtc, libScePosixForWebKit,
libRenoirCore, test wiring).

Resolutions where both sides implemented the same thing:
- libkernel pthread: main's structure (lazy static initialisation,
  destroyed markers, MutexOperations/CondOperations, mutex protocol and
  condattr clock) with this branch's TimedWait deadlines and condition
  (precise timed lock/wait on Windows), wait tracing, the adaptive mutex
  type 4, POSIX default ERRORCHECK mutexes, EDEADLK/EPERM results instead
  of throws, and condition clocks honoured for absolute timeouts.
- libc locale: the guest Dinkumware ABI (_Locimp, facet vtables, short
  ctype/case tables, locale ids, stream storage) is kept because guest code
  inlines those layouts; main's C character functions are kept on top.
- libc stdio/strings/math: main's stream functions (guest FILE status
  sync), strerror/perror, remove, formatting, string and math exports win
  over this branch's duplicates.
- libc paths: main's working directory with this branch's path aliases
  resolved on the normalised guest path.
- libkernel file: this branch's sceKernel* results as SCE errors, main's
  POSIX wrappers and both fstat helpers.
- relinker: this branch's stub lowering keeps its trampolines through the
  main executable path; guest modules refuse lowerings that need stubs.
- AGC driver: main's rendering wait is executed by this branch's workers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0177gthrWEBBfBu5xJDXgBfo
2026-09-27 10:52:21 -07:00
boykopovar f5ea673c10 feat(libkernel): impl posix stdio wrappers, reusing sceKernel file ops 2026-09-27 11:43:40 +03:00
boykopovar 13c648bebb feat(libkernel): impl file, time, process, signal for posix 2026-09-27 11:43:38 +03:00
boykopovar 40101471ee feat(libkernel): add new posix, pthread, semaphore, process funcs definitions 2026-09-27 11:43:31 +03:00
QDarkRex 2081071237 refactor(kernel): share SCE kernel error codes through KernelErrors.hpp
Kernel error codes were redeclared per file under three prefixes
(SCE_KERNEL_ERROR_, EQUEUE_ERROR_, KERNEL_SEMA_ERROR_), which let wrong
values go unnoticed. Define them once as 0x80020000 | errno for errno
1..94 and use the SCE_KERNEL_ERROR_ names everywhere. Values are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 13:32:28 +07:00
QDarkRex 15b749c2ba fix(kernel): return 64-bit offsets from sceKernelLseek
The SCE ABI returns off_t; offsets above INT_MAX threw instead of being returned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 12:38:59 +07:00
devilismyfriend f3ac61000d feat(runtime): guest arena, kernel thread/sync/file APIs, crash hooks
- libc: reserve guest memory in one arena below the PS5 map limit with
  MEM_WRITE_WATCH (GuestArena) and a caching guest heap; the allocation
  registry gains a generation counter, an invalidator callback for the
  driver's page cache and a pin waiter for leased ranges. This replaces
  the fault-based GuestMemoryTracking/GuestMemoryBacking layer, whose
  files are removed.
- libkernel: mmap/mprotect/munmap on the arena, flexible memory budget,
  real sceKernelVirtualQuery; POSIX pthread layer, rwlocks, timed locks,
  TSD, event flags; 0.5 ms scheduler tick and high-resolution sleeps;
  TSC/clock/time functions; file APIs return SCE errno codes; the APR
  file-streaming API.
- libc: vectored crash reporter with backtraces for fatal exceptions,
  SIGABRT, UCRT invalid parameters and process exit; SSE4a EXTRQ/INSERTQ
  emulation for Intel hosts; %ls/%lc/%S/%C with the guest's 16-bit
  wchar_t; hand-written setjmp/longjmp for the guest jmp_buf; a path
  alias table for short save-data mount points; more string, stdio and
  math exports.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0177gthrWEBBfBu5xJDXgBfo
2026-09-25 16:27:49 -07:00
SamG-Coder 9cbefb7e04 feat(kernel): implement tracked UDP sockets and ioctl 2026-09-25 06:23:44 +10:00
boykopovar 630d918b4a feat(agc): add timing logs for path after recompling 2026-09-23 22:11:41 +03:00
boykopovar 10e4d5e469 perf(shader): make -ools validation and optimization optional 2026-09-23 21:48:51 +03:00
boykopovar 5d715ee549 refactor(libkernel): move from Export.cpp to separated files 2026-09-13 16:41:04 +03:00
boykopovar 7c44d13b3a feat(libs): global shared path resolver in libc 2026-09-13 12:45:50 +03:00
boykopovar f66a8fc5c4 feat(libkernel): libkernel file functions impl 2026-09-13 12:07:47 +03:00