Byrgenwerthnotes of Paleblood, rebuilding Bloodborne one verified function at a time

Last updated: November 17, 2026

Kernel

The engine's core library: thin wrappers around the PS4 kernel for threads, mutexes, read-write locks and condition variables, which report every unexpected result through one fatal error function.

At a glance

Scope
Dantelion2's kernel layer ("ClassLibrary/Core/Kernel" in its source paths), and the kernel and libc calls the executable imports.
Verified
kernel_condition_wait (0x02483e80), the condition-variable wait the frame-rate patches edit, and since 15 November most of the engine's mutex, light mutex and read-write lock wrappers and its memory pool free. A few members without recordings stay edge-verified (the function table gives each one's status).
Open
Which objects the condition waits made each frame belong to; the error paths of the lock wrappers are covered only by constructed cases.

Summary

What the kernel layer is

Dantelion2 is the engine's core library. Its kernel classes wrap the PS4 kernel's threads, mutexes and condition variables. Each wrapper checks the result of the call it makes, and any unexpected result goes to the engine's fatal error function (0x024b55b0), which takes a file, a line and a message.

The current thread

kernel_thread_self (0x0111a8a0) stores the calling thread's handle from scePthreadSelf through its pointer argument and returns 0. It is reached only through a function pointer. By @evill33t in #105, merged in #203: its 7 constructed edge cases pass against the original on current main, and an independent review approved it.

Reading files

Four small wrappers handle the engine's file access (#283, by @evill33t): kernel_file_open (0x0111a620) opens a file read-only and reports its size (from the system's file-status record) and its descriptor; kernel_file_close, kernel_file_read_count and kernel_file_seek_absolute (0x0111a6b0, 0x0111a6e0, 0x0111a720) close, read and seek. Each was checked on constructed edge cases against the original and approved by an independent review.

FMOD's semaphores and recursive mutexes

FMOD (the sound engine; see Audio) wraps the kernel's semaphores and mutexes in small functions of its own, and these are the first of them mapped:

  • Semaphores (#271): create (0x0111ad10) makes an empty first-in-first-out semaphore with room for 0xffff units and stores its handle only if the kernel succeeds; destroy (0x0111ad80), wait (0x0111ada0, one unit, no time limit) and signal (0x0111adc0, one unit) pass the handle on.
  • Recursive mutexes (#275): create (0x0111abb0) allocates the mutex from FMOD's memory pool (or uses one shared static slot), sets it up as recursive and hands it back only after every step succeeded; destroy, lock and unlock (0x0111ac80, 0x0111acd0, 0x0111acf0) pass it on, and lock and unlock do nothing for a null mutex.

All of them turn any kernel error into 0x21 (a failed allocation gives 0x2b). By @evill33t in #111 and #108: each was brought up to date with main, its constructed edge cases pass against the original on current main, and an independent review approved it.

The engine's light mutex

DLLightMutex wraps one system mutex (at +0x08) with an "initialized" flag (at +0x10). Eight of its members (0x0247ecb0–0x0247f070: constructor, destructors, initialize, finalize, lock, try lock, unlock) were replaced by contributor @FFwLo (#748). Every member asks whether the mutex is initialized through the object's third virtual function (0x0247ee80), which is only four bytes long, too short to hook, so it stays original. A destructor leaves the flag set when the system says the mutex is busy (EBUSY), and reports any other failure through the engine's error report. Seven of the eight are now verified on recordings from the game (#1119); the deleting destructor, which has no recordings, stays edge-verified.

The engine's own mutex and read-write lock

Below the light mutex sit the engine's plain mutex wrappers (its PthreadMutex.cpp) and its read-write lock, DLReadWriteLock. Both were replaced by @FFwLo, and they follow the same pattern: a few expected results come back as small numbers, and anything else goes to the engine's error report.

  • The mutex (#740): initialize, destroy, lock, try lock and unlock (0x02483fe0–0x02484290). The mutex is recursive. Lock waits forever when the timeout is -1 and otherwise makes a timed wait; a time-out gives -3, a busy mutex -2, and running out of memory or mutexes at initialization -1. Unlock accepts quietly a mutex the thread does not own (EPERM). For some errors the original reports a chain of messages that falls through from one to the next, and the replacement keeps that chain.
  • The read-write lock (#745): eleven members (0x0247f180–0x0247f710). Like the light mutex it holds the system lock at +0x08 and an "initialized" flag at +0x10, and asks for the flag through a four-byte virtual function that stays original. Read and write locks wait forever or with a time limit, a try write lock gives -2 when busy, and the unlock (the same code three times in the executable) gives -4 for a lock the thread does not hold. A lock that is not initialized is reported and then used anyway, as in the original. The resource loader (see Loading) takes these locks.
  • The memory pool free (#889): 0x011ab3a0, the release the kernel layer's mutex destroy uses. It creates the pool's own lock on first use, takes the block's size off the pool's counters (from a header in front of the block, the block's first word, or the backing heap), then hands the block to the pool's free callback, releases its pages, or frees it on the backing heap.

Most of these are verified on recordings from the game, approved by an independent review (#1119). The recordings exercise only the success paths; the error paths are covered by constructed edge cases. The members without recordings (the mutex's destroy and try lock, the lock's deleting destructor and try write lock) stay edge-verified. Every edge-verified function also carries a current recorded edge result (#912).

How a condition wait works

kernel_condition_wait (0x02483e80) waits on a condition variable. It has two paths:

  1. Timeout of -1: it waits forever (an untimed wait).
  2. Any other timeout: it makes a timed wait, and returns -3 if the time runs out.

It is called about 40 times a frame in gameplay. Every wait recorded in gameplay is untimed, which matters for the frame-rate patches (see Patch points).

Imports are not implementations

The executable and its bundled libc import POSIX-like calls such as getpagesize, getpid, clock_gettime and gettimeofday. An import only says the game can call something; it does not mean Paleblood implements it. For implementation status and evidence limits, see the runtime system-call notes.

Two clock details are established so far:

  • The frame limiter passes null as gettimeofday's timezone argument.
  • Numeric clock ID 4 is confirmed for sceKernelClockGettime, not for the imported clock_gettime wrapper.
getpagesize: why it stops by name

In the current runtime, both getpagesize entries are registered as fail-loud unresolved diagnostics because the PS4 page-size value is not established, as recorded in merged Paleblood PR #66.

Runtime thread-call implementations

These are Paleblood runtime services, not newly decompiled game functions: the runtime answers some thread and timing calls itself. Two rules run through them:

  • A call is implemented only when its guest-visible contract is known. Where the PS4's exact behaviour is not established, the call stays a fail-loud diagnostic that stops by name.
  • The SCE names and the POSIX names of the same call differ in their errors: the POSIX names return the FreeBSD error number, where the SCE names return 0x80020000 plus it.

The former boot stop, scePthreadAttrGetaffinity, is no longer reached: since Paleblood #207 the bundled C library's probe that called it returns at once. The boots recorded on merged main since then pass through these thread calls, and since #408 no system call stops the boot at all. Later thread work includes ending a thread early with scePthreadExit (#389) and semaphores that wake their waiters by thread priority (#426); the runtime system-call notes explain them.

What each runtime change implements (PRs #62, #72, #81, #94, #95, #97)

Merged PR #62 implements scePthreadEqual by comparing the object pointers used as guest thread handles. Its synthetic registry tests cover one handle compared with itself, distinct handles in both argument orders, and null; the public FreeBSD pthread_equal(3) contract supports zero for unequal and nonzero for equal, but the PS4's exact nonzero value is unknown.

Merged PR #72 implements imported sched_yield by yielding the host thread and returning zero, following POSIX and FreeBSD's documented contract. Unit tests check the result but cannot show that another host thread actually ran.

Later runtime merges extend the same thread and timing group:

  • PR #81 adds the detach-state setters for thread attributes under both the SCE and POSIX names. Reading a detach state that the system itself supplies still stops by name, because the PS4 default is not established.
  • PR #95 registers the POSIX names pthread_self, pthread_attr_init and pthread_attr_destroy. They return the FreeBSD error number where the SCE names return 0x80020000 plus it.
  • PR #94 sleeps the host thread for sceKernelUsleep, the call the verified frame limiter and swap-chain present functions make, and for usleep below one second.
  • PR #97 ends the program by name on __stack_chk_fail.

These are runtime services checked by synthetic registry tests, not decompiled game functions.

scePthreadYield answers zero

The similarly named scePthreadYield yields the same way and answers zero (Paleblood #308). Its PS4 signature is unpublished: FreeBSD's pthread_yield returns void, Linux's analogue returns int. Zero is right under either, and all 26 direct call sites in the executable ignore the result.

Key functions

Address Size Name Status Notes
0x0111a620 129 kernel_file_open edge-verified Open read-only and query FreeBSD amd64 stat; publish low32 file size before int64 descriptor; compiler stack guard omitted
0x0111a6b0 23 kernel_file_close edge-verified Forward the full opaque descriptor; translate nonzero low32 close status to 19; synthetic wire edge cases only
0x0111a6e0 60 kernel_file_read_count edge-verified Publish uint32 transferred bytes after kernel buffer writes; full64 received count controls errors and short reads
0x0111a720 22 kernel_file_seek_absolute edge-verified Forward the full opaque descriptor and zero-extended unsigned32 absolute offset; full64 seek result sign maps to 0 or 19; synthetic wire edge cases only
0x0111a8a0 26 kernel_thread_self verified Copy the complete opaque current-thread handle to the output and return zero
0x0111abb0 207 kernel_mutex_create verified Create a recursive mutex in static or allocated storage; low-byte ownership flag; publish storage only after all kernel stages succeed; no error cleanup
0x0111ac80 78 kernel_mutex_destroy verified Destroy the mutex and release storage only after kernel success with a zero low-byte static flag; errors map to 0x21; ignore release result
0x0111acd0 30 kernel_mutex_lock verified Accept a null mutex without a call; preserve the full kernel pointer and API writes; map any nonzero low32 result to 0x21
0x0111acf0 30 kernel_mutex_unlock verified Accept a null mutex without a call; forward its full pointer to unlock; preserve API writes and translate nonzero low32 results to 0x21
0x0111ad10 103 kernel_semaphore_create verified Create the fixed empty FIFO semaphore; preserve all six API arguments and full opaque handle; publish only after low32 kernel success; errors map to 0x21
0x0111ad80 23 kernel_semaphore_destroy edge-verified Forward the full opaque handle including null to kernel deletion; preserve kernel writes and translate any nonzero low32 result to 0x21
0x0111ada0 30 kernel_semaphore_wait verified Wait for one unit using the full opaque handle including null and a null timeout pointer; preserve kernel writes; nonzero low32 results map to 0x21
0x0111adc0 28 kernel_semaphore_signal verified Signal one unit using the full opaque handle including null; preserve kernel writes and translate every nonzero low32 result to 0x21
0x011ab3a0 260 kernel_memory_pool_free_011ab3a0 verified Memory pool free: lazy static lock; header/page/heap size off the counters; callback, page release or heap free; page pools repeat on the context pool
0x0247ecb0 15 kernel_light_mutex_construct verified DLLightMutex constructor: its vtable and a cleared initialized flag; the system mutex handle is left as it was
0x0247ecc0 118 kernel_light_mutex_delete edge-verified DLLightMutex deleting destructor: destroys an initialized mutex (errors reported) without clearing the flag then frees the object
0x0247ed40 115 kernel_light_mutex_destruct verified DLLightMutex destructor: destroys an initialized mutex; EBUSY keeps the flag set; EINVAL and unknown errors reported
0x0247edc0 124 kernel_light_mutex_finalize verified DLLightMutex finalize: asks the vtable; EBUSY returns -2 and keeps the flag; otherwise the flag clears after any error reports
0x0247ee40 49 kernel_light_mutex_initialize verified DLLightMutex initialize: asks the vtable; the PthreadMutex initialize (0x02483fe0); a nonzero result is returned and the flag stays clear
0x0247ee90 226 kernel_light_mutex_lock verified DLLightMutex lock: the PthreadMutex lock inlined (forever); ETIMEDOUT returns -3; a mutex not initialized is reported then used
0x0247ef80 230 kernel_light_mutex_try_lock verified DLLightMutex try lock: the PthreadMutex try lock inlined; EBUSY returns -2; a mutex not initialized is reported then used
0x0247f070 124 kernel_light_mutex_unlock verified DLLightMutex unlock: the PthreadMutex unlock inlined; EPERM accepted; a mutex not initialized is reported then used
0x0247f180 15 kernel_read_write_lock_construct verified DLReadWriteLock constructor: its vtable and a cleared initialized flag; the system lock handle is left as it was
0x0247f190 81 kernel_read_write_lock_delete edge-verified DLReadWriteLock deleting destructor: destroys an initialized lock (EINVAL reported) without clearing the flag then frees the object
0x0247f1f0 85 kernel_read_write_lock_destruct verified DLReadWriteLock destructor: destroys an initialized lock; EBUSY keeps the flag set; EINVAL reported; otherwise the flag clears
0x0247f250 94 kernel_read_write_lock_finalize verified DLReadWriteLock finalize: asks the vtable; EBUSY returns -2 and keeps the flag; EINVAL reported; otherwise the flag clears
0x0247f2b0 244 kernel_read_write_lock_initialize verified DLReadWriteLock initialize: ENOMEM/EAGAIN return -1; any other result sets the flag after the EPERM/EBUSY/EINVAL/EFAULT report chain
0x0247f3d0 198 kernel_read_write_lock_write verified DLReadWriteLock write lock (untimed when timeout is -1): ETIMEDOUT returns -3; EINVAL/EDEADLK reports fall through to the unknown error
0x0247f4a0 146 kernel_read_write_lock_try_write edge-verified DLReadWriteLock try write lock: EBUSY returns -2; EINVAL then EDEADLK reported; anything else returns 0
0x0247f540 115 kernel_read_write_lock_unlock_0247f540 verified DLReadWriteLock unlock (one of three identical copies): EPERM returns -4; EINVAL reported
0x0247f5c0 115 kernel_read_write_lock_unlock_0247f5c0 verified DLReadWriteLock unlock (one of three identical copies): EPERM returns -4; EINVAL reported
0x0247f640 206 kernel_read_write_lock_read verified DLReadWriteLock read lock (untimed when timeout is -1): ETIMEDOUT returns -3; EINVAL/EAGAIN/EDEADLK reports fall through
0x0247f710 115 kernel_read_write_lock_unlock_0247f710 verified DLReadWriteLock unlock (one of three identical copies): EPERM returns -4; EINVAL reported
0x02483e80 204 kernel_condition_wait verified Dantelion2 PthreadCondition wait (untimed when timeout is -1); the FPS patches put a ret on the timed path
0x02483fe0 196 kernel_pthread_mutex_initialize verified Dantelion2 PthreadMutex init: recursive attribute then init; ENOMEM/EAGAIN return -1; EINVAL and unknown errors reported with the source line
0x024840b0 90 kernel_pthread_mutex_destroy edge-verified Dantelion2 PthreadMutex destroy: EBUSY returns -2; EINVAL then the unknown error reported with the source line
0x02484110 183 kernel_pthread_mutex_lock verified Dantelion2 PthreadMutex lock (untimed when timeout is -1); ETIMEDOUT returns -3; EDEADLK/EINVAL/EAGAIN reports fall through to the runtime error
0x024841d0 177 kernel_pthread_mutex_try_lock edge-verified Dantelion2 PthreadMutex try lock: EBUSY returns -2; EDEADLK/EINVAL/EAGAIN reports fall through to the runtime error
0x02484290 71 kernel_pthread_mutex_unlock verified Dantelion2 PthreadMutex unlock: 0 and EPERM accepted; EINVAL or any other result reported with the source line

Structs and globals

Not documented yet.

Patch points

  • 30 FPS++, 60 FPS++, 90 FPS++ and Uncap FPS++ write a return over the timed-wait call in 0x02483e80. If that path ever ran, the return would jump to a garbage address. Every wait recorded in gameplay is untimed, so it never does. Our replacement keeps the original behaviour.

Open questions

  • Which objects the ~40 condition waits per frame belong to (job queues, the render thread?).