Commit Graph

13 Commits

Author SHA1 Message Date
DotDebian 096bdb38c2 fix(libkernel): give CLOCK_VIRTUAL, CLOCK_PROF and CLOCK_SECOND their FreeBSD meaning
clock_gettime and clock_getres served three FreeBSD clock ids with the wrong
clock or not at all:

- CLOCK_VIRTUAL (1) was the monotonic clock on Windows and threw on Linux; it
  is the user CPU time of the process.
- CLOCK_PROF (2) threw on both hosts; it is the user plus system CPU time of
  the process.
- CLOCK_SECOND (13) returned the coarse realtime clock with nanoseconds and a
  sub-second resolution; it is the current second with tv_nsec 0 and a
  resolution of one second.

Behaviour follows FreeBSD 11 clock_gettime(2) and kern_clock_gettime /
kern_clock_getres in sys/kern/kern_time.c.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 10:24:22 +02:00
DotDebian d98bbcd5bb fix(libkernel): report invalid nanosleep requests through errno and the sce error codes
nanosleep and _nanosleep forwarded the result of sceKernelNanosleep, which
returned -1 for a rejected request: errno was never set, and the sce call
returned a value that is not an sce error. A request with negative seconds
was rejected as well, where FreeBSD's kern_nanosleep returns 0 without
sleeping.

nanosleep and _nanosleep now return -1 with errno set to EINVAL when tv_nsec
is outside [0, 1000000000) and to EFAULT for a null request;
sceKernelNanosleep returns the matching SCE_KERNEL_ERROR code. A request
with valid nanoseconds and negative seconds returns 0 at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 18:19:53 +02:00
DotDebian d6cca762f4 feat(libkernel): support the CPU-time clocks in clock_gettime and clock_getres on Windows
CLOCK_THREAD_CPUTIME_ID (14) and CLOCK_PROCESS_CPUTIME_ID (15) threw
"unsupported clock_id" on Windows while the Linux branch already maps
them to the native clocks. clock_gettime now returns the user + kernel
time from GetThreadTimes / GetProcessTimes, and clock_getres reports the
clock interrupt period from GetSystemTimeAdjustment, which is the step
those counters actually advance by.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 11:40:22 +02:00
asimplestray c6d098d487 feat(kernel): implement Sleep, sigprocmask and pthread finalize 2026-09-29 23:40:48 +00:00
Dean Galvin 9754937a5d feat(libkernel): hinted and no-overwrite mappings, virtual range names and usleep
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ButHENCbXXt8h4EZuWUabJ
2026-09-28 14:22:48 +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 7a925c68e5 fix(libkernel): handle clock_second 13 in clock_gettime and clock_getres 2026-09-27 11:43:39 +03:00
boykopovar 13c648bebb feat(libkernel): impl file, time, process, signal for posix 2026-09-27 11:43:38 +03:00
devilismyfriend af3c2024ed feat(runtime): timed waits, sync primitive fixes, heap and RTC fixes, unattended-run switches
libkernel: a TimedWait service for condition variables, semaphores, event flags, rwlocks and
equeues with the scheduler tick; mutex/cond/sem corner cases the title hits; job worker
affinity is opt-in (APS5_JOB_AFFINITY). libc: calloc/realloc heap slot swap, a default
terminate handler with a backtrace, CPU topology helper. libSceRtc export fixes with tests.
libSceVideoOut: APS5_NO_PAD_INPUT ignores host input for unattended measurements,
APS5_FLIP_QUEUE_WAIT keeps a stalled process alive for a debugger. ApplicationHeap and
GuestRtc tests wired into the test build.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0177gthrWEBBfBu5xJDXgBfo
2026-09-26 19:00:39 -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
boykopovar 5d715ee549 refactor(libkernel): move from Export.cpp to separated files 2026-09-13 16:41:04 +03:00
boykopovar f19a234f38 feat(libkernel): add gettime getres gettimeofday impl 2026-09-13 11:21:37 +03:00
boykopovar a7521f3a7e feat(libkernel): libkernel time functions impl 2026-09-12 16:33:29 +03:00