Merge pull request #16429 from amer760/feat/nkwebkit-concurrent-ptr-hash-set

feat(libSceNKWebKit): implement WTF::ConcurrentPtrHashSet
This commit is contained in:
Dean authored and GitHub committed 2026-11-10 07:52:37 +13:00
commit 3cd86e6ea7
7 files changed
+580 -43

No files matched your search

-28
View File
@@ -16015,34 +16015,6 @@ int APS5_VABI _ZN3WTF19numGraphemeClustersENS_10StringViewE() {
NotImplemented_nid_no_patch(__func__);
}
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSet15deleteOldTablesEv() {
NotImplemented_nid_no_patch(__func__);
}
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSet5clearEv() {
NotImplemented_nid_no_patch(__func__);
}
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSet7addSlowEPNS0_5TableEjjjPv() {
NotImplemented_nid_no_patch(__func__);
}
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSetC1Ev() {
NotImplemented_nid_no_patch(__func__);
}
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSetC2Ev() {
NotImplemented_nid_no_patch(__func__);
}
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSetD1Ev() {
NotImplemented_nid_no_patch(__func__);
}
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSetD2Ev() {
NotImplemented_nid_no_patch(__func__);
}
int APS5_VABI _ZN3WTF20ParallelHelperClient13doSomeHelpingEv() {
NotImplemented_nid_no_patch(__func__);
}
@@ -1546,13 +1546,6 @@ int APS5_VABI _ZN3WTF19ParallelEnvironmentC1EPFvPvEmi();
int APS5_VABI _ZN3WTF19ParallelEnvironmentC2EPFvPvEmi();
int APS5_VABI _ZN3WTF19isCompilationThreadEv();
int APS5_VABI _ZN3WTF19numGraphemeClustersENS_10StringViewE();
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSet15deleteOldTablesEv();
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSet5clearEv();
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSet7addSlowEPNS0_5TableEjjjPv();
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSetC1Ev();
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSetC2Ev();
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSetD1Ev();
int APS5_VABI _ZN3WTF20ConcurrentPtrHashSetD2Ev();
int APS5_VABI _ZN3WTF20ParallelHelperClient13doSomeHelpingEv();
int APS5_VABI _ZN3WTF20ParallelHelperClient6finishEv();
int APS5_VABI _ZN3WTF20ParallelHelperClientD1Ev();
@@ -0,0 +1,58 @@
#pragma once
#include "prx/libc/include/general/VabiMacros.hpp"
#include <cstddef>
#include <cstdint>
#include <type_traits>
namespace WTF {
struct ConcurrentPtrHashSetTable {
std::uint32_t size;
std::uint32_t mask;
std::uint32_t load;
void* array[1];
};
struct ConcurrentPtrHashSet {
ConcurrentPtrHashSetTable** tablesBuffer;
std::uint32_t tablesCapacity;
std::uint32_t tablesSize;
ConcurrentPtrHashSetTable* tablesInline[4];
ConcurrentPtrHashSetTable* table;
ConcurrentPtrHashSetTable stubTable;
std::uint8_t lock;
};
static_assert(std::is_standard_layout_v<ConcurrentPtrHashSetTable>);
static_assert(sizeof(ConcurrentPtrHashSetTable) == 24);
static_assert(offsetof(ConcurrentPtrHashSetTable, size) == 0);
static_assert(offsetof(ConcurrentPtrHashSetTable, mask) == 4);
static_assert(offsetof(ConcurrentPtrHashSetTable, load) == 8);
static_assert(offsetof(ConcurrentPtrHashSetTable, array) == 16);
static_assert(std::is_standard_layout_v<ConcurrentPtrHashSet>);
static_assert(sizeof(ConcurrentPtrHashSet) == 88);
static_assert(alignof(ConcurrentPtrHashSet) == 8);
static_assert(offsetof(ConcurrentPtrHashSet, tablesBuffer) == 0);
static_assert(offsetof(ConcurrentPtrHashSet, tablesCapacity) == 8);
static_assert(offsetof(ConcurrentPtrHashSet, tablesSize) == 12);
static_assert(offsetof(ConcurrentPtrHashSet, tablesInline) == 16);
static_assert(offsetof(ConcurrentPtrHashSet, table) == 48);
static_assert(offsetof(ConcurrentPtrHashSet, stubTable) == 56);
static_assert(offsetof(ConcurrentPtrHashSet, lock) == 80);
}
extern "C" {
void APS5_VABI _ZN3WTF20ConcurrentPtrHashSetC1Ev(WTF::ConcurrentPtrHashSet* self);
void APS5_VABI _ZN3WTF20ConcurrentPtrHashSetC2Ev(WTF::ConcurrentPtrHashSet* self);
void APS5_VABI _ZN3WTF20ConcurrentPtrHashSetD1Ev(WTF::ConcurrentPtrHashSet* self);
void APS5_VABI _ZN3WTF20ConcurrentPtrHashSetD2Ev(WTF::ConcurrentPtrHashSet* self);
void APS5_VABI _ZN3WTF20ConcurrentPtrHashSet15deleteOldTablesEv(WTF::ConcurrentPtrHashSet* self);
void APS5_VABI _ZN3WTF20ConcurrentPtrHashSet5clearEv(WTF::ConcurrentPtrHashSet* self);
bool APS5_VABI _ZN3WTF20ConcurrentPtrHashSet7addSlowEPNS0_5TableEjjjPv(WTF::ConcurrentPtrHashSet* self,
WTF::ConcurrentPtrHashSetTable* table, std::uint32_t mask, std::uint32_t startIndex, std::uint32_t index, void* ptr);
}
@@ -21,6 +21,7 @@
#include "prx/libSceNKWebKit/include/WtfBitVector.hpp"
#include "prx/libSceNKWebKit/include/WtfExports.hpp"
#include "prx/libSceNKWebKit/include/WtfFastBitVector.hpp"
#include "prx/libSceNKWebKit/include/WtfConcurrentPtrHashSet.hpp"
#include "prx/libSceNKWebKit/src/Preferences.hpp"
#include "prx/libSceNKWebKit/include/DiagnosticLoggingKeysExports.hpp"
#include "prx/libSceNKWebKit/include/MediaExports.hpp"
@@ -0,0 +1,284 @@
// Derived from Sony PS5 WebKit 11.x revision 80f77e94c6, Source/WTF/wtf/ConcurrentPtrHashSet.cpp
/*
* Copyright (C) 2017-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "prx/libSceNKWebKit/include/WtfConcurrentPtrHashSet.hpp"
#include "prx/libSceNKWebKit/include/WtfExports.hpp"
#include <algorithm>
#include <atomic>
#include <cstring>
#include <limits>
#include <stdexcept>
#include <thread>
namespace {
using Set = WTF::ConcurrentPtrHashSet;
using Table = WTF::ConcurrentPtrHashSetTable;
constexpr std::uint32_t kInitialSize = 32;
constexpr std::uint32_t kStubDefaultLoad = 10;
constexpr std::uint32_t kInlineTables = 4;
constexpr std::size_t kMinTablesCapacity = 16;
constexpr std::uint8_t kLockHeldBit = 1;
class SetLocker {
public:
explicit SetLocker(Set* set)
: m_byte(set->lock) {
std::uint8_t expected = 0;
while (!m_byte.compare_exchange_weak(expected, kLockHeldBit, std::memory_order_acquire)) {
if (expected & ~kLockHeldBit)
throw std::runtime_error("ConcurrentPtrHashSet: lock has parked threads");
expected = 0;
std::this_thread::yield();
}
}
~SetLocker() {
m_byte.store(0, std::memory_order_release);
}
SetLocker(const SetLocker&) = delete;
SetLocker& operator=(const SetLocker&) = delete;
private:
std::atomic_ref<std::uint8_t> m_byte;
};
Set* CheckedSet(Set* set) {
if (!set) throw std::invalid_argument("ConcurrentPtrHashSet: null set");
return set;
}
unsigned PtrHash(void* ptr) {
auto key = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(ptr));
key += ~(key << 32);
key ^= (key >> 22);
key += ~(key << 13);
key ^= (key >> 8);
key += (key << 3);
key ^= (key >> 15);
key += ~(key << 27);
key ^= (key >> 31);
return static_cast<unsigned>(key);
}
std::atomic_ref<void*> Slot(Table* table, std::uint32_t index) {
auto* array = reinterpret_cast<void**>(reinterpret_cast<std::byte*>(table) + offsetof(Table, array));
return std::atomic_ref<void*>(array[index]);
}
std::atomic_ref<std::uint32_t> Load(Table* table) {
return std::atomic_ref<std::uint32_t>(table->load);
}
std::atomic_ref<Table*> Current(Set* set) {
return std::atomic_ref<Table*>(set->table);
}
Table* CreateTable(std::uint32_t size) {
auto* table = static_cast<Table*>(_ZN3WTF10fastMallocEm(offsetof(Table, array) + sizeof(void*) * std::size_t{size}));
table->size = size;
table->mask = size - 1;
Load(table).store(0, std::memory_order_relaxed);
for (std::uint32_t i = 0; i < size; ++i) Slot(table, i).store(nullptr, std::memory_order_relaxed);
return table;
}
void InitializeStub(Table& stub) {
stub.size = 0;
stub.mask = 0;
Load(&stub).store(kStubDefaultLoad, std::memory_order_relaxed);
Slot(&stub, 0).store(nullptr, std::memory_order_relaxed);
}
void InitializeTables(Set* set) {
set->tablesBuffer = set->tablesInline;
set->tablesCapacity = kInlineTables;
set->tablesSize = 0;
}
void AppendTable(Set* set, Table* table) {
if (set->tablesSize == set->tablesCapacity) {
const std::size_t capacity = set->tablesCapacity;
const auto newCapacity = std::max<std::size_t>(capacity + 1, std::max(kMinTablesCapacity, capacity + capacity / 4 + 1));
if (newCapacity > std::numeric_limits<std::uint32_t>::max() / sizeof(Table*))
throw std::length_error("ConcurrentPtrHashSet: table list capacity overflow");
auto* buffer = static_cast<Table**>(_ZN3WTF10fastMallocEm(newCapacity * sizeof(Table*)));
std::memcpy(buffer, set->tablesBuffer, set->tablesSize * sizeof(Table*));
if (set->tablesBuffer != set->tablesInline) _ZN3WTF8fastFreeEPv(set->tablesBuffer);
set->tablesBuffer = buffer;
set->tablesCapacity = static_cast<std::uint32_t>(newCapacity);
}
set->tablesBuffer[set->tablesSize++] = table;
}
void DestroyTables(Set* set) {
if (set->tablesSize && !set->tablesBuffer) throw std::invalid_argument("ConcurrentPtrHashSet: null table list");
for (std::uint32_t i = 0; i < set->tablesSize; ++i) _ZN3WTF8fastFreeEPv(set->tablesBuffer[i]);
set->tablesSize = 0;
if (set->tablesBuffer != set->tablesInline) _ZN3WTF8fastFreeEPv(set->tablesBuffer);
InitializeTables(set);
}
void Initialize(Set* set) {
auto* table = CreateTable(kInitialSize);
Current(set).store(table, std::memory_order_relaxed);
AppendTable(set, table);
InitializeStub(set->stubTable);
}
void Construct(Set* set) {
InitializeTables(CheckedSet(set));
set->lock = 0;
Initialize(set);
}
void Destroy(Set* set) {
DestroyTables(CheckedSet(set));
}
void ResizeIfNecessary(Set* set) {
SetLocker locker(set);
auto* table = Current(set).load(std::memory_order_relaxed);
if (table == &set->stubTable) throw std::runtime_error("ConcurrentPtrHashSet: stub table installed outside a resize");
if (Load(table).load(std::memory_order_relaxed) < table->size / 2) return;
if (table->size > std::numeric_limits<std::uint32_t>::max() / 2)
throw std::length_error("ConcurrentPtrHashSet: table size overflow");
Current(set).store(&set->stubTable);
auto* newTable = CreateTable(table->size * 2);
const auto mask = newTable->mask;
std::uint32_t load = 0;
for (std::uint32_t i = 0; i < table->size; ++i) {
auto* ptr = Slot(table, i).load(std::memory_order_relaxed);
if (!ptr) continue;
const auto startIndex = PtrHash(ptr) & mask;
auto index = startIndex;
for (;;) {
auto entry = Slot(newTable, index);
auto* value = entry.load(std::memory_order_relaxed);
if (!value) {
entry.store(ptr, std::memory_order_relaxed);
break;
}
if (value == ptr) throw std::runtime_error("ConcurrentPtrHashSet: duplicate entry during resize");
index = (index + 1) & mask;
if (index == startIndex) throw std::runtime_error("ConcurrentPtrHashSet: resized table is full");
}
++load;
}
Load(newTable).store(load, std::memory_order_relaxed);
Current(set).store(newTable);
Load(&set->stubTable).store(kStubDefaultLoad);
AppendTable(set, newTable);
}
bool AddSlow(Set* set, Table* table, std::uint32_t mask, std::uint32_t startIndex, std::uint32_t index, void* ptr);
bool Add(Set* set, void* ptr) {
auto* table = Current(set).load(std::memory_order_relaxed);
const auto mask = table->mask;
const auto startIndex = PtrHash(ptr) & mask;
auto index = startIndex;
for (;;) {
auto* entry = Slot(table, index).load(std::memory_order_relaxed);
if (!entry) return AddSlow(set, table, mask, startIndex, index, ptr);
if (entry == ptr) return false;
index = (index + 1) & mask;
if (index == startIndex) throw std::runtime_error("ConcurrentPtrHashSet: table is full");
}
}
bool AddSlow(Set* set, Table* table, std::uint32_t mask, std::uint32_t startIndex, std::uint32_t index, void* ptr) {
if (Load(table).fetch_add(1) >= table->size / 2) {
ResizeIfNecessary(set);
return Add(set, ptr);
}
for (;;) {
void* oldEntry = nullptr;
Slot(table, index).compare_exchange_strong(oldEntry, ptr);
if (!oldEntry) {
if (Current(set).load() != table) return Add(set, ptr);
return true;
}
if (oldEntry == ptr) return false;
index = (index + 1) & mask;
if (index == startIndex) throw std::runtime_error("ConcurrentPtrHashSet: table is full");
}
}
}
extern "C" void APS5_VABI _ZN3WTF20ConcurrentPtrHashSetC1Ev(WTF::ConcurrentPtrHashSet* self) {
Construct(self);
}
extern "C" void APS5_VABI _ZN3WTF20ConcurrentPtrHashSetC2Ev(WTF::ConcurrentPtrHashSet* self) {
Construct(self);
}
extern "C" void APS5_VABI _ZN3WTF20ConcurrentPtrHashSetD1Ev(WTF::ConcurrentPtrHashSet* self) {
Destroy(self);
}
extern "C" void APS5_VABI _ZN3WTF20ConcurrentPtrHashSetD2Ev(WTF::ConcurrentPtrHashSet* self) {
Destroy(self);
}
extern "C" void APS5_VABI _ZN3WTF20ConcurrentPtrHashSet15deleteOldTablesEv(WTF::ConcurrentPtrHashSet* self) {
SetLocker locker(CheckedSet(self));
auto* current = Current(self).load(std::memory_order_relaxed);
if (current == &self->stubTable) throw std::runtime_error("ConcurrentPtrHashSet::deleteOldTables: stub table installed");
std::uint32_t kept = 0;
for (std::uint32_t i = 0; i < self->tablesSize; ++i) {
auto* table = self->tablesBuffer[i];
if (table == current)
self->tablesBuffer[kept++] = table;
else
_ZN3WTF8fastFreeEPv(table);
}
self->tablesSize = kept;
}
extern "C" void APS5_VABI _ZN3WTF20ConcurrentPtrHashSet5clearEv(WTF::ConcurrentPtrHashSet* self) {
SetLocker locker(CheckedSet(self));
DestroyTables(self);
Initialize(self);
}
extern "C" bool APS5_VABI _ZN3WTF20ConcurrentPtrHashSet7addSlowEPNS0_5TableEjjjPv(WTF::ConcurrentPtrHashSet* self,
WTF::ConcurrentPtrHashSetTable* table, std::uint32_t mask, std::uint32_t startIndex, std::uint32_t index, void* ptr) {
CheckedSet(self);
if (!table) throw std::invalid_argument("ConcurrentPtrHashSet::addSlow: null table");
if (!ptr) throw std::invalid_argument("ConcurrentPtrHashSet::addSlow: null pointer");
if (mask != table->mask || startIndex > mask || index > mask)
throw std::invalid_argument("ConcurrentPtrHashSet::addSlow: index outside the table");
return AddSlow(self, table, mask, startIndex, index, ptr);
}
@@ -0,0 +1,234 @@
#include "prx/libSceNKWebKit/libSceNKWebKit.hpp"
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <source_location>
#include <stdexcept>
#include <thread>
#include <type_traits>
#include <vector>
namespace {
void Require(bool condition, std::source_location location = std::source_location::current()) {
if (!condition) {
std::fprintf(stderr, "ConcurrentPtrHashSet check failed at line %u\n", location.line());
std::abort();
}
}
template<class Function>
void RequireThrows(Function function) {
bool threw = false;
try {
function();
} catch (const std::exception&) {
threw = true;
}
Require(threw);
}
using Set = WTF::ConcurrentPtrHashSet;
using Table = WTF::ConcurrentPtrHashSetTable;
using Lifetime = void (APS5_VABI *)(Set*);
using AddSlow = bool (APS5_VABI *)(Set*, Table*, std::uint32_t, std::uint32_t, std::uint32_t, void*);
static_assert(std::is_same_v<decltype(&_ZN3WTF20ConcurrentPtrHashSetC1Ev), Lifetime>);
static_assert(std::is_same_v<decltype(&_ZN3WTF20ConcurrentPtrHashSetC2Ev), Lifetime>);
static_assert(std::is_same_v<decltype(&_ZN3WTF20ConcurrentPtrHashSetD1Ev), Lifetime>);
static_assert(std::is_same_v<decltype(&_ZN3WTF20ConcurrentPtrHashSetD2Ev), Lifetime>);
static_assert(std::is_same_v<decltype(&_ZN3WTF20ConcurrentPtrHashSet15deleteOldTablesEv), Lifetime>);
static_assert(std::is_same_v<decltype(&_ZN3WTF20ConcurrentPtrHashSet5clearEv), Lifetime>);
static_assert(std::is_same_v<decltype(&_ZN3WTF20ConcurrentPtrHashSet7addSlowEPNS0_5TableEjjjPv), AddSlow>);
unsigned PtrHash(void* ptr) {
auto key = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(ptr));
key += ~(key << 32);
key ^= (key >> 22);
key += ~(key << 13);
key ^= (key >> 8);
key += (key << 3);
key ^= (key >> 15);
key += ~(key << 27);
key ^= (key >> 31);
return static_cast<unsigned>(key);
}
void* Entry(Table* table, std::uint32_t index) {
auto* array = reinterpret_cast<void**>(reinterpret_cast<std::byte*>(table) + offsetof(Table, array));
return std::atomic_ref<void*>(array[index]).load(std::memory_order_relaxed);
}
Table* CurrentTable(Set* set) {
return std::atomic_ref<Table*>(set->table).load(std::memory_order_relaxed);
}
bool InlineAdd(Set* set, void* ptr) {
auto* table = CurrentTable(set);
const auto mask = table->mask;
const auto startIndex = PtrHash(ptr) & mask;
auto index = startIndex;
for (;;) {
auto* entry = Entry(table, index);
if (!entry) return _ZN3WTF20ConcurrentPtrHashSet7addSlowEPNS0_5TableEjjjPv(set, table, mask, startIndex, index, ptr);
if (entry == ptr) return false;
index = (index + 1) & mask;
Require(index != startIndex);
}
}
bool InlineContains(Set* set, void* ptr) {
auto* table = CurrentTable(set);
Require(table != &set->stubTable);
const auto mask = table->mask;
const auto startIndex = PtrHash(ptr) & mask;
auto index = startIndex;
for (;;) {
auto* entry = Entry(table, index);
if (!entry) return false;
if (entry == ptr) return true;
index = (index + 1) & mask;
Require(index != startIndex);
}
}
void* Key(std::uintptr_t value) {
return reinterpret_cast<void*>((value + 1) * 16);
}
struct GuardedSet {
std::uint64_t before = 0x0123456789ABCDEF;
Set set;
std::uint64_t after = 0xFEDCBA9876543210;
void CheckGuards() const {
Require(before == 0x0123456789ABCDEF && after == 0xFEDCBA9876543210);
}
};
void RequireFreshState(Set& set) {
Require(set.tablesBuffer == set.tablesInline && set.tablesCapacity == 4 && set.tablesSize == 1);
auto* table = set.tablesBuffer[0];
Require(CurrentTable(&set) == table);
Require(table->size == 32 && table->mask == 31 && table->load == 0);
Require(_ZN3WTF14fastMallocSizeEPKv(table) == offsetof(Table, array) + 32 * sizeof(void*));
for (std::uint32_t i = 0; i < 32; ++i) Require(Entry(table, i) == nullptr);
Require(set.stubTable.size == 0 && set.stubTable.mask == 0 && set.stubTable.load == 10);
Require(set.stubTable.array[0] == nullptr && set.lock == 0);
}
void TestConstructionAndClear() {
for (auto construct : {&_ZN3WTF20ConcurrentPtrHashSetC1Ev, &_ZN3WTF20ConcurrentPtrHashSetC2Ev}) {
GuardedSet value;
std::memset(&value.set, 0xCD, sizeof(value.set));
construct(&value.set);
value.CheckGuards();
RequireFreshState(value.set);
_ZN3WTF20ConcurrentPtrHashSetD1Ev(&value.set);
value.CheckGuards();
}
GuardedSet value;
_ZN3WTF20ConcurrentPtrHashSetC1Ev(&value.set);
for (std::uintptr_t i = 0; i < 1000; ++i) Require(InlineAdd(&value.set, Key(i)));
Require(value.set.tablesBuffer != value.set.tablesInline);
Require(value.set.tablesCapacity == 16 && value.set.tablesSize == 7);
for (std::uint32_t i = 0; i < 7; ++i) Require(value.set.tablesBuffer[i]->size == (32u << i));
_ZN3WTF20ConcurrentPtrHashSet5clearEv(&value.set);
value.CheckGuards();
RequireFreshState(value.set);
Require(!InlineContains(&value.set, Key(0)));
Require(InlineAdd(&value.set, Key(0)));
Require(InlineContains(&value.set, Key(0)));
_ZN3WTF20ConcurrentPtrHashSetD2Ev(&value.set);
value.CheckGuards();
std::printf("ConcurrentPtrHashSet: construction, clear and destruction passed\n");
}
void TestAddAndResize() {
GuardedSet value;
_ZN3WTF20ConcurrentPtrHashSetC1Ev(&value.set);
constexpr std::uintptr_t count = 5000;
for (std::uintptr_t i = 0; i < count; ++i) {
Require(InlineAdd(&value.set, Key(i)));
Require(!InlineAdd(&value.set, Key(i)));
}
auto* table = CurrentTable(&value.set);
Require(table->size == 16384 && table->mask == 16383);
Require(table->load == count);
Require(value.set.stubTable.load == 10 && value.set.lock == 0);
for (std::uintptr_t i = 0; i < count; ++i) Require(InlineContains(&value.set, Key(i)));
for (std::uintptr_t i = count; i < count * 2; ++i) Require(!InlineContains(&value.set, Key(i)));
std::size_t stored = 0;
for (std::uint32_t i = 0; i < table->size; ++i) stored += Entry(table, i) != nullptr;
Require(stored == count);
Require(value.set.tablesSize == 10 && value.set.tablesCapacity == 16);
_ZN3WTF20ConcurrentPtrHashSet15deleteOldTablesEv(&value.set);
Require(value.set.tablesSize == 1 && value.set.tablesBuffer[0] == table);
Require(value.set.tablesBuffer != value.set.tablesInline && value.set.tablesCapacity == 16);
for (std::uintptr_t i = 0; i < count; ++i) Require(InlineContains(&value.set, Key(i)));
_ZN3WTF20ConcurrentPtrHashSet15deleteOldTablesEv(&value.set);
Require(value.set.tablesSize == 1 && value.set.tablesBuffer[0] == table);
Require(InlineAdd(&value.set, Key(count)));
_ZN3WTF20ConcurrentPtrHashSetD1Ev(&value.set);
value.CheckGuards();
std::printf("ConcurrentPtrHashSet: %zu adds, resizes and deleteOldTables passed\n", static_cast<std::size_t>(count));
}
void TestConcurrentAdds() {
Set set;
_ZN3WTF20ConcurrentPtrHashSetC1Ev(&set);
constexpr unsigned threads = 4;
constexpr std::uintptr_t keys = 4000;
std::atomic<std::size_t> added{0};
std::vector<std::thread> workers;
for (unsigned t = 0; t < threads; ++t) {
workers.emplace_back([&, t] {
std::size_t local = 0;
for (std::uintptr_t i = 0; i < keys; ++i) local += InlineAdd(&set, Key((i * 7919 + t * 1013) % keys));
added += local;
});
}
for (auto& worker : workers) worker.join();
Require(added <= keys);
for (std::uintptr_t i = 0; i < keys; ++i) Require(InlineContains(&set, Key(i)));
Require(CurrentTable(&set) != &set.stubTable && set.lock == 0);
_ZN3WTF20ConcurrentPtrHashSetD1Ev(&set);
std::printf("ConcurrentPtrHashSet: %u threads stored all %zu keys, at most one add reported each\n", threads, static_cast<std::size_t>(keys));
}
void TestInvalidArguments() {
RequireThrows([] { _ZN3WTF20ConcurrentPtrHashSetC1Ev(nullptr); });
RequireThrows([] { _ZN3WTF20ConcurrentPtrHashSetD1Ev(nullptr); });
RequireThrows([] { _ZN3WTF20ConcurrentPtrHashSet5clearEv(nullptr); });
RequireThrows([] { _ZN3WTF20ConcurrentPtrHashSet15deleteOldTablesEv(nullptr); });
Set set;
_ZN3WTF20ConcurrentPtrHashSetC1Ev(&set);
auto* table = CurrentTable(&set);
auto add = &_ZN3WTF20ConcurrentPtrHashSet7addSlowEPNS0_5TableEjjjPv;
RequireThrows([&] { add(nullptr, table, 31, 0, 0, Key(1)); });
RequireThrows([&] { add(&set, nullptr, 31, 0, 0, Key(1)); });
RequireThrows([&] { add(&set, table, 31, 0, 0, nullptr); });
RequireThrows([&] { add(&set, table, 15, 0, 0, Key(1)); });
RequireThrows([&] { add(&set, table, 31, 32, 0, Key(1)); });
RequireThrows([&] { add(&set, table, 31, 0, 32, Key(1)); });
Require(table->load == 0 && set.lock == 0);
Require(add(&set, &set.stubTable, 0, 0, 0, Key(1)));
Require(InlineContains(&set, Key(1)) && set.tablesSize == 1 && set.stubTable.load == 11);
_ZN3WTF20ConcurrentPtrHashSetD1Ev(&set);
std::printf("ConcurrentPtrHashSet: invalid arguments throw\n");
}
}
int main() {
TestConstructionAndClear();
TestAddAndResize();
TestConcurrentAdds();
TestInvalidArguments();
}
+3 -8
View File
@@ -18,6 +18,8 @@ Inventory prose retains historical counts; use the [generated progress report](h
- [FastBitVector exports](../../../core/libs/prx/libSceNKWebKit/src/WtfFastBitVector.cpp) have no console ABI or behavior verification. The 16-byte owner (word pointer at 0, 64-bit bit count at 8), range clearing, growth and copying follow the paired header and [PS5 11.x WebKit source](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/FastBitVector.cpp). `resizeSlow` preserves the stored bit count and unused bits of existing words; new words are zeroed. Allocation uses the module's `fastMalloc` and `fastFree`. Invalid ranges, null accessed storage, shrinking the word count and overflowing the upstream round-up throw instead of reproducing assertion failures or invalid memory access. Closes when: compared with a console module.
- [ConcurrentPtrHashSet exports](../../../core/libs/prx/libSceNKWebKit/src/WtfConcurrentPtrHashSet.cpp) have no console ABI or behavior verification. The 88-byte layout (a `Vector<std::unique_ptr<Table>, 4>` at 0, the current table at 48, the 24-byte stub table at 56, the one-byte `Lock` at 80), the `PtrHash` probe sequence, resizing at half load and the table list growth follow the [PS5 11.x WebKit source](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/ConcurrentPtrHashSet.cpp) and its `Vector.h`. The lock spins with `std::this_thread::yield` instead of parking, and throws if it finds the parked bit set. A null set, table or pointer, an index or mask that does not fit the table, a full table and a table size that overflows on doubling throw instead of reproducing `RELEASE_ASSERT` crashes or invalid memory access. Closes when: compared with a console module.
- [PAL::SessionID exports](../../../core/libs/prx/libSceNKWebKit/src/PalSessionID.cpp) have no console ABI or behavior verification. They follow the [PS5 11.x WebKit source](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/PAL/pal/SessionID.cpp). The generators throw after `enableGenerationProtection` instead of reproducing the `RELEASE_ASSERT` crash. Closes when: compared with a console module.
- [bmalloc::FreeList exports](../../../core/libs/prx/libSceNKWebKit/src/BmallocFreeList.cpp) have no console ABI or behavior verification. The 32-byte layout and field writes follow the [PS5 11.x WebKit source](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/bmalloc/bmalloc/FreeList.cpp), which compiles only without libpas; that the console build has libpas off is inferred from the PlayStation build options and the exported symbols. A null `self` throws instead of reproducing invalid memory access. Closes when: compared with a console module.
@@ -105,7 +107,7 @@ Inventory prose retains historical counts; use the [generated progress report](h
- The [revision-pinned identity inventory](https://gist.github.com/kyon-eth/d44995f181e1818977bd38f0e6fc0f34/8afcb14b0707a09b6274ff7f7bcf33ef46cfe2e7) records the module, library, symbol type and NIDs for the declarations in [Export.cpp](../../../core/libs/prx/libSceNKWebKit/Export.cpp); it is a metadata summary rather than independent verification. For the 255 absent from the public catalogue, [per-image ELF records](https://gist.github.com/kyon-eth/147be8dd556e9cced2577ccbed548972/1a659ecfe819e724675991a574a1aebb5fbb48e5) include the raw qualified names, module and library identities, symbol type, values and sizes; the record file SHA-256 is `44bdc4d6073192a8f41b7be359b75364b3d41dbbd11ce649924b8cebdd4ffe51`. Image labels are not authenticated.
- [WebCore text dumps](../../../core/libs/prx/libSceNKWebKit/src/WebCoreDump.cpp) (libSceNKWebKit) - the `operator<<(TextStream&, ...)` overloads for geometry, transforms, `ScrollAlignment` and scrolling and graphics enums follow the pinned [`FloatPoint.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/graphics/FloatPoint.cpp), [`GraphicsTypes.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/graphics/GraphicsTypes.cpp) and [`ScrollTypes.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/ScrollTypes.cpp); expectations are hand-derived and not checked against console binaries. They rely on the `TextStream` exports and layout of the WTF text change. `XYZ_D65` prints `XYZ-D50`, as in that source; a `CompositeOperator` or `BlendMode` outside its name table throws.
- [Additional callable exports](../../../core/libs/prx/libSceNKWebKit/Export.cpp) - 6282 of the 8703 inventory declarations listed below throw through `NotImplemented_nid_no_patch`; signatures and behavior are unverified. The later 13.60-labelled image contains all 8703; 8448 match the public 3.20 catalogue, while 255 are absent and their presence in retail 3.20 is unverified. Per-image records show the latter in a separate 3.20-labelled image, but neither image label is authenticated. Identified names match NIDs in the [public symbol database](https://github.com/zecoxao/sce_symbols/blob/2883963a0a514ba6e77407a08ef4730a65e88254/aerolib.csv) or [supplemental catalog](https://github.com/claimore22/ps5rs/blob/2304be5131221bae0dac24b9767cabffda33f747/data/nids.csv). Data exports need separate analysis.
- [Additional callable exports](../../../core/libs/prx/libSceNKWebKit/Export.cpp) - 6275 of the 8703 inventory declarations listed below throw through `NotImplemented_nid_no_patch`; signatures and behavior are unverified. The later 13.60-labelled image contains all 8703; 8448 match the public 3.20 catalogue, while 255 are absent and their presence in retail 3.20 is unverified. Per-image records show the latter in a separate 3.20-labelled image, but neither image label is authenticated. Identified names match NIDs in the [public symbol database](https://github.com/zecoxao/sce_symbols/blob/2883963a0a514ba6e77407a08ef4730a65e88254/aerolib.csv) or [supplemental catalog](https://github.com/claimore22/ps5rs/blob/2304be5131221bae0dac24b9767cabffda33f747/data/nids.csv). Data exports need separate analysis.
| Name | NID |
| --- | --- |
@@ -1550,13 +1552,6 @@ Inventory prose retains historical counts; use the [generated progress report](h
| `_ZN3WTF19ParallelEnvironmentC2EPFvPvEmi` | `ciXM3j2URKk` |
| `_ZN3WTF19isCompilationThreadEv` | `qoO6VaMuvG0` |
| `_ZN3WTF19numGraphemeClustersENS_10StringViewE` | `K7qAbz7P3rs` |
| `_ZN3WTF20ConcurrentPtrHashSet15deleteOldTablesEv` | `K59xDVxbCyM` |
| `_ZN3WTF20ConcurrentPtrHashSet5clearEv` | `sDuWnr1d9ko` |
| `_ZN3WTF20ConcurrentPtrHashSet7addSlowEPNS0_5TableEjjjPv` | `V-fPa0Bhh0w` |
| `_ZN3WTF20ConcurrentPtrHashSetC1Ev` | `CQtwXOnCU1M` |
| `_ZN3WTF20ConcurrentPtrHashSetC2Ev` | `ZVyMTXVUQN0` |
| `_ZN3WTF20ConcurrentPtrHashSetD1Ev` | `NWIItqDdYTQ` |
| `_ZN3WTF20ConcurrentPtrHashSetD2Ev` | `VZF7dCw7zNo` |
| `_ZN3WTF20ParallelHelperClient13doSomeHelpingEv` | `jLYyt8tfmkE` |
| `_ZN3WTF20ParallelHelperClient6finishEv` | `X+GUHRxWSq4` |
| `_ZN3WTF20ParallelHelperClientD1Ev` | `pCPHOY0VhUY` |