thread_management.cpp: Various Mandatory Threading Fixes | Resolve #398 (#394)

* Handle empty mutex attribute

- scePthreadMutexInit did not return default when the mutex attributes were empty, now it does

* fix conditional unsafety

* Update thread_management.cpp

fix deref

* accurate heap api

- modified HeapAPI to a struct with preset function fields
- utilized the full array parameter passed to _sceKernelRtldSetApplicationHeapAPI

* fallback to std malloc

* clang format

* Declare all HeapAPI replacement functions

- calloc, realloc, memalign, reallocalign, malloc_stats, malloc_stats_fast, malloc_usable_size
- posix_memalign corrected parameters

* resolve suggestions

- `using` definition replacement for AppHeapAPI
- linux uses heap_malloc, windows uses std::malloc

---------

Co-authored-by: microsoftv <6063922+microsoftv@users.noreply.github.com>
This commit is contained in:
Lizardy 2024-08-13 02:08:03 -04:00 committed by GitHub
parent 18f1799280
commit 5eecd089ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 48 additions and 12 deletions

View file

@ -46,7 +46,21 @@ struct EntryParams {
const char* argv[3];
};
using HeapApiFunc = PS4_SYSV_ABI void* (*)(size_t);
struct HeapAPI {
PS4_SYSV_ABI void* (*heap_malloc)(size_t);
PS4_SYSV_ABI void (*heap_free)(void*);
PS4_SYSV_ABI void* (*heap_calloc)(size_t, size_t);
PS4_SYSV_ABI void* (*heap_realloc)(void*, size_t);
PS4_SYSV_ABI void* (*heap_memalign)(size_t, size_t);
PS4_SYSV_ABI int (*heap_posix_memalign)(void**, size_t, size_t);
// NOTE: Fields below may be inaccurate
PS4_SYSV_ABI int (*heap_reallocalign)(void);
PS4_SYSV_ABI void (*heap_malloc_stats)(void);
PS4_SYSV_ABI int (*heap_malloc_stats_fast)(void);
PS4_SYSV_ABI size_t (*heap_malloc_usable_size)(void*);
};
using AppHeapAPI = HeapAPI*;
class Linker {
public:
@ -75,8 +89,8 @@ public:
}
}
void SetHeapApiFunc(void* func) {
heap_api_func = *reinterpret_cast<HeapApiFunc*>(func);
void SetHeapAPI(void* func[]) {
heap_api = reinterpret_cast<AppHeapAPI>(func);
}
void AdvanceGenerationCounter() noexcept {
@ -104,7 +118,7 @@ private:
size_t static_tls_size{};
u32 max_tls_index{};
u32 num_static_modules{};
HeapApiFunc heap_api_func{};
AppHeapAPI heap_api{};
std::vector<std::unique_ptr<Module>> m_modules;
Loader::SymbolsResolver m_hle_symbols{};
};