Files
Steam-Link-PS5/tooling/native/app_cpp_runtime.cpp
T
jmelovich ae52676cfc M0: boilerplate skeleton builds with the system clang and launches as PPSA99350
Imported ps5-native-app-boilerplate (Makefile, tools, tooling, clean-room runtime
builder, CPU demo renderer). The compiler wrapper and build.sh fall back to the
host clang when clang-18 is absent (Arch ships clang 22; verified), ccache is
optional, and the large home-screen DDS/AT9 assets stay out of git. Identity:
PPSA99350 "Steam Remote Play". Submodules pinned: ihslib master 1881b9a,
protobuf-c v1.5.2, mbedtls v3.6.4, opus v1.5.2 (the mbedtls/opus revisions
ProsperoLight proved on the console). ProsperoLight's sceNet socket adapter,
entropy source, mbedtls config and VideoDec2/VideoOut/AGC link stubs are staged
under platform/ps5 and vendor/ps5 for M1/M2.

Tested: make, make deploy, shsrv launch; the demo screen renders on the TV.
2026-10-08 17:12:01 -07:00

153 lines
3.4 KiB
C++

/*
* ps5-native-app-boilerplate - Minimal target C++ allocation runtime.
* Copyright (C) 2026 BlackBearReloaded
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Bridges standard C++ allocation operators to the clean-room libc module
* without introducing exceptions, RTTI, or the complete libc++ runtime.
*/
#include <cstddef>
#include <new>
extern "C"
{
void *malloc(std::size_t size);
void free(void *address);
int posix_memalign(void **address, std::size_t alignment, std::size_t size);
}
namespace
{
[[nodiscard]] void *allocate(std::size_t size) noexcept
{
return malloc(size == 0 ? 1 : size);
}
[[nodiscard]] void *allocate_aligned(std::size_t size, std::size_t alignment) noexcept
{
void *address = nullptr;
if (alignment < sizeof(void *))
alignment = sizeof(void *);
if ((alignment & (alignment - 1)) != 0)
return nullptr;
return posix_memalign(&address, alignment, size == 0 ? 1 : size) == 0 ? address : nullptr;
}
[[noreturn]] void allocation_failure() noexcept
{
__builtin_trap();
}
} // namespace
extern "C" __attribute__((noinline, visibility("hidden"))) bool
ps5ObserveOwnedAllocation(const void *address) noexcept
{
__asm__ volatile("" : : "r"(address) : "memory");
return address != nullptr;
}
void *operator new(std::size_t size)
{
if (void *address = allocate(size))
return address;
allocation_failure();
}
void *operator new[](std::size_t size)
{
return ::operator new(size);
}
void *operator new(std::size_t size, const std::nothrow_t &) noexcept
{
return allocate(size);
}
void *operator new[](std::size_t size, const std::nothrow_t &) noexcept
{
return allocate(size);
}
void *operator new(std::size_t size, std::align_val_t alignment)
{
if (void *address = allocate_aligned(size, static_cast<std::size_t>(alignment)))
return address;
allocation_failure();
}
void *operator new[](std::size_t size, std::align_val_t alignment)
{
return ::operator new(size, alignment);
}
void *operator new(std::size_t size, std::align_val_t alignment, const std::nothrow_t &) noexcept
{
return allocate_aligned(size, static_cast<std::size_t>(alignment));
}
void *operator new[](std::size_t size, std::align_val_t alignment, const std::nothrow_t &) noexcept
{
return allocate_aligned(size, static_cast<std::size_t>(alignment));
}
void operator delete(void *address) noexcept
{
free(address);
}
void operator delete[](void *address) noexcept
{
free(address);
}
void operator delete(void *address, std::size_t) noexcept
{
free(address);
}
void operator delete[](void *address, std::size_t) noexcept
{
free(address);
}
void operator delete(void *address, std::align_val_t) noexcept
{
free(address);
}
void operator delete[](void *address, std::align_val_t) noexcept
{
free(address);
}
void operator delete(void *address, std::size_t, std::align_val_t) noexcept
{
free(address);
}
void operator delete[](void *address, std::size_t, std::align_val_t) noexcept
{
free(address);
}
void operator delete(void *address, const std::nothrow_t &) noexcept
{
free(address);
}
void operator delete[](void *address, const std::nothrow_t &) noexcept
{
free(address);
}
void operator delete(void *address, std::align_val_t, const std::nothrow_t &) noexcept
{
free(address);
}
void operator delete[](void *address, std::align_val_t, const std::nothrow_t &) noexcept
{
free(address);
}