temporary make std::print and std::format optional

This commit is contained in:
DH 2025-10-04 14:06:47 +03:00
parent d2b9b7c1f6
commit 5904079a87
26 changed files with 231 additions and 130 deletions

View file

@ -399,6 +399,7 @@ add_subdirectory(opencv EXCLUDE_FROM_ALL)
# FUSION # FUSION
add_subdirectory(fusion EXCLUDE_FROM_ALL) add_subdirectory(fusion EXCLUDE_FROM_ALL)
add_subdirectory(fmtlib)
# add nice ALIAS targets for ease of use # add nice ALIAS targets for ease of use
if(USE_SYSTEM_LIBUSB) if(USE_SYSTEM_LIBUSB)

View file

@ -30,7 +30,6 @@
#include "lv2/sys_spu.h" #include "lv2/sys_spu.h"
#include <cstddef> #include <cstddef>
#include <rx/format.hpp> #include <rx/format.hpp>
#include <format>
#ifdef LLVM_AVAILABLE #ifdef LLVM_AVAILABLE
#ifdef _MSC_VER #ifdef _MSC_VER

View file

@ -1,10 +1,10 @@
#include "AudioOut.hpp" #include "AudioOut.hpp"
#include "rx/format.hpp"
#include "rx/mem.hpp" #include "rx/mem.hpp"
#include "rx/watchdog.hpp" #include "rx/watchdog.hpp"
#include <atomic> #include <atomic>
#include <chrono> #include <chrono>
#include <fcntl.h> #include <fcntl.h>
#include <format>
#include <mutex> #include <mutex>
#include <orbis/evf.hpp> #include <orbis/evf.hpp>
#include <orbis/utils/Logs.hpp> #include <orbis/utils/Logs.hpp>
@ -41,10 +41,10 @@ void AudioOut::channelEntry(AudioOutChannelInfo info) {
std::format_to( std::format_to(
control_shm_name, "{}", control_shm_name, "{}",
rx::getShmGuestPath(std::format("shm_{}_C", info.idControl)).string()); rx::getShmGuestPath(rx::format("shm_{}_C", info.idControl)).string());
std::format_to( std::format_to(
audio_shm_name, "{}", audio_shm_name, "{}",
rx::getShmGuestPath(std::format("shm_{}_{}_A", info.channel, info.port)) rx::getShmGuestPath(rx::format("shm_{}_{}_A", info.channel, info.port))
.string()); .string());
int controlFd = ::open(control_shm_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); int controlFd = ::open(control_shm_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);

View file

@ -2,6 +2,8 @@
#include "gpu/DeviceCtl.hpp" #include "gpu/DeviceCtl.hpp"
#include "orbis/KernelContext.hpp" #include "orbis/KernelContext.hpp"
#include "rx/Config.hpp" #include "rx/Config.hpp"
#include "rx/format.hpp"
#include "rx/print.hpp"
#include <bit> #include <bit>
#include <chrono> #include <chrono>
#include <csignal> #include <csignal>
@ -10,8 +12,6 @@
#include <cstdlib> #include <cstdlib>
#include <fcntl.h> #include <fcntl.h>
#include <filesystem> #include <filesystem>
#include <format>
#include <print>
#include <string_view> #include <string_view>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -108,7 +108,7 @@ static void sendMessage(MessageId id, std::uint32_t data) {
const char *rx::getShmPath() { return g_shmPath; } const char *rx::getShmPath() { return g_shmPath; }
std::filesystem::path rx::getShmGuestPath(std::string_view path) { std::filesystem::path rx::getShmGuestPath(std::string_view path) {
return std::format("{}/guest/{}", getShmPath(), path); return rx::format("{}/guest/{}", getShmPath(), path);
} }
void rx::createGpuDevice() { void rx::createGpuDevice() {
@ -158,7 +158,7 @@ void rx::startWatchdog() {
std::exit(-1); std::exit(-1);
} }
if (!std::filesystem::create_directory(std::format("{}/guest", g_shmPath))) { if (!std::filesystem::create_directory(rx::format("{}/guest", g_shmPath))) {
perror("failed to create guest shared memory directory"); perror("failed to create guest shared memory directory");
std::exit(-1); std::exit(-1);
} }
@ -231,7 +231,7 @@ void rx::startWatchdog() {
} }
if (g_runGpuRequested) { if (g_runGpuRequested) {
std::println("watchdog: gpu start requested"); rx::println("watchdog: gpu start requested");
g_runGpuRequested = false; g_runGpuRequested = false;
runGPU(); runGPU();
} }

View file

@ -5,6 +5,7 @@
#include "rx/Config.hpp" #include "rx/Config.hpp"
#include "rx/hexdump.hpp" #include "rx/hexdump.hpp"
#include "rx/mem.hpp" #include "rx/mem.hpp"
#include "rx/print.hpp"
#include "shader/Evaluator.hpp" #include "shader/Evaluator.hpp"
#include "shader/GcnConverter.hpp" #include "shader/GcnConverter.hpp"
#include "shader/dialect.hpp" #include "shader/dialect.hpp"
@ -14,7 +15,6 @@
#include <cstddef> #include <cstddef>
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <print>
#include <rx/AddressRange.hpp> #include <rx/AddressRange.hpp>
#include <rx/MemoryTable.hpp> #include <rx/MemoryTable.hpp>
#include <rx/die.hpp> #include <rx/die.hpp>
@ -1354,7 +1354,7 @@ Cache::Shader Cache::Tag::getShader(const ShaderKey &key,
return {}; return {};
} }
std::print(stderr, "{}", shader::glsl::decompile(converted->spv)); rx::print(stderr, "{}", shader::glsl::decompile(converted->spv));
// if (auto opt = shader::spv::optimize(converted->spv)) { // if (auto opt = shader::spv::optimize(converted->spv)) {
// converted->spv = std::move(*opt); // converted->spv = std::move(*opt);
// std::fprintf(stderr, "opt: %s", // std::fprintf(stderr, "opt: %s",

View file

@ -10,7 +10,6 @@
#include <algorithm> #include <algorithm>
#include <map> #include <map>
#include <memory> #include <memory>
#include <print>
#include <rx/ConcurrentBitPool.hpp> #include <rx/ConcurrentBitPool.hpp>
#include <rx/MemoryTable.hpp> #include <rx/MemoryTable.hpp>
#include <shader/gcn.hpp> #include <shader/gcn.hpp>

View file

@ -11,7 +11,9 @@
#include "rx/Config.hpp" #include "rx/Config.hpp"
#include "rx/bits.hpp" #include "rx/bits.hpp"
#include "rx/die.hpp" #include "rx/die.hpp"
#include "rx/format.hpp"
#include "rx/mem.hpp" #include "rx/mem.hpp"
#include "rx/print.hpp"
#include "rx/watchdog.hpp" #include "rx/watchdog.hpp"
#include "shader/spv.hpp" #include "shader/spv.hpp"
#include "shaders/rdna-semantic-spirv.hpp" #include "shaders/rdna-semantic-spirv.hpp"
@ -20,8 +22,6 @@
#include <chrono> #include <chrono>
#include <cstdio> #include <cstdio>
#include <fcntl.h> #include <fcntl.h>
#include <format>
#include <print>
#include <stop_token> #include <stop_token>
#include <sys/mman.h> #include <sys/mman.h>
#include <thread> #include <thread>
@ -34,7 +34,7 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessageCallback(
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
void *pUserData) { void *pUserData) {
if (pCallbackData->pMessage) { if (pCallbackData->pMessage) {
std::println("{}", pCallbackData->pMessage); rx::println("{}", pCallbackData->pMessage);
} }
if (messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) { if (messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
@ -324,7 +324,7 @@ void Device::start() {
continue; continue;
} }
auto path = std::format("{}/dmem-{}", rx::getShmPath(), i); auto path = rx::format("{}/dmem-{}", rx::getShmPath(), i);
if (!std::filesystem::exists(path)) { if (!std::filesystem::exists(path)) {
std::println("Waiting for dmem {}", i); std::println("Waiting for dmem {}", i);
@ -382,7 +382,7 @@ void Device::start() {
if (gpIndex > GLFW_JOYSTICK_LAST) { if (gpIndex > GLFW_JOYSTICK_LAST) {
for (int i = 0; i <= GLFW_JOYSTICK_LAST; ++i) { for (int i = 0; i <= GLFW_JOYSTICK_LAST; ++i) {
if (glfwJoystickIsGamepad(i) == GLFW_TRUE) { if (glfwJoystickIsGamepad(i) == GLFW_TRUE) {
std::print("Gamepad \"{}\" activated", glfwGetGamepadName(i)); rx::print("Gamepad \"{}\" activated", glfwGetGamepadName(i));
gpIndex = i; gpIndex = i;
break; break;
} }
@ -571,7 +571,7 @@ void Device::mapProcess(std::uint32_t pid, int vmId) {
auto memory = amdgpu::RemoteMemory{vmId}; auto memory = amdgpu::RemoteMemory{vmId};
std::string pidVmName = std::format("{}/memory-{}", rx::getShmPath(), pid); std::string pidVmName = rx::format("{}/memory-{}", rx::getShmPath(), pid);
int memoryFd = ::open(pidVmName.c_str(), O_RDWR, S_IRUSR | S_IWUSR); int memoryFd = ::open(pidVmName.c_str(), O_RDWR, S_IRUSR | S_IWUSR);
process.vmFd = memoryFd; process.vmFd = memoryFd;

View file

@ -5,9 +5,8 @@
#include "rx/bits.hpp" #include "rx/bits.hpp"
#include "rx/die.hpp" #include "rx/die.hpp"
#include "rx/format.hpp" #include "rx/format.hpp"
#include "rx/print.hpp"
#include "shader/dialect.hpp" #include "shader/dialect.hpp"
#include <cstdio>
#include <print>
#include <vector> #include <vector>
using namespace amdgpu; using namespace amdgpu;
@ -40,7 +39,7 @@ void DeviceCtl::submitGfxCommand(int gfxPipe, int vmId,
if ((op != gnm::IT_INDIRECT_BUFFER && op != gnm::IT_INDIRECT_BUFFER_CNST && if ((op != gnm::IT_INDIRECT_BUFFER && op != gnm::IT_INDIRECT_BUFFER_CNST &&
op != gnm::IT_CONTEXT_CONTROL) || op != gnm::IT_CONTEXT_CONTROL) ||
type != 3 || command.size() != len) { type != 3 || command.size() != len) {
std::println(stderr, "unexpected gfx command for main ring: {}, {}, {}", rx::println(stderr, "unexpected gfx command for main ring: {}, {}, {}",
gnm::Pm4Opcode(op), type, len); gnm::Pm4Opcode(op), type, len);
rx::die(""); rx::die("");
} }

View file

@ -5,11 +5,11 @@
#include "gnm/mmio.hpp" #include "gnm/mmio.hpp"
#include "gnm/pm4.hpp" #include "gnm/pm4.hpp"
#include "orbis/KernelContext.hpp" #include "orbis/KernelContext.hpp"
#include "rx/print.hpp"
#include "vk.hpp" #include "vk.hpp"
#include <bit> #include <bit>
#include <cstdio> #include <cstdio>
#include <mutex> #include <mutex>
#include <print>
#include <rx/bits.hpp> #include <rx/bits.hpp>
#include <rx/die.hpp> #include <rx/die.hpp>
#include <rx/format.hpp> #include <rx/format.hpp>
@ -193,7 +193,7 @@ void ComputePipe::setIndirectRing(int queueId, int indirectLevel, Ring ring) {
} }
ring.indirectLevel = indirectLevel; ring.indirectLevel = indirectLevel;
std::println(stderr, "mapQueue: {}, {}, {}", (void *)ring.base, rx::println(stderr, "mapQueue: {}, {}, {}", (void *)ring.base,
(void *)ring.wptr, ring.size); (void *)ring.wptr, ring.size);
queues[1 - ring.indirectLevel][queueId] = ring; queues[1 - ring.indirectLevel][queueId] = ring;

View file

@ -1,11 +1,11 @@
#include "Renderer.hpp" #include "Renderer.hpp"
#include "Device.hpp" #include "Device.hpp"
#include "gnm/gnm.hpp" #include "gnm/gnm.hpp"
#include "rx/print.hpp"
#include <amdgpu/tiler.hpp> #include <amdgpu/tiler.hpp>
#include <gnm/constants.hpp> #include <gnm/constants.hpp>
#include <gnm/vulkan.hpp> #include <gnm/vulkan.hpp>
#include <print>
#include <rx/format.hpp> #include <rx/format.hpp>
#include <shader/Evaluator.hpp> #include <shader/Evaluator.hpp>
#include <shader/dialect.hpp> #include <shader/dialect.hpp>
@ -161,7 +161,7 @@ void amdgpu::draw(GraphicsPipe &pipe, int vmId, std::uint32_t firstVertex,
if (pipe.context.cbColorControl.mode != gnm::CbMode::Normal && if (pipe.context.cbColorControl.mode != gnm::CbMode::Normal &&
pipe.context.cbColorControl.mode != gnm::CbMode::EliminateFastClear) { pipe.context.cbColorControl.mode != gnm::CbMode::EliminateFastClear) {
std::println("unimplemented context.cbColorControl.mode = {}", rx::println("unimplemented context.cbColorControl.mode = {}",
static_cast<gnm::CbMode>(pipe.context.cbColorControl.mode)); static_cast<gnm::CbMode>(pipe.context.cbColorControl.mode));
return; return;
} }

View file

@ -7,9 +7,9 @@
#include "gcn.hpp" #include "gcn.hpp"
#include "ir.hpp" #include "ir.hpp"
#include "rx/die.hpp" #include "rx/die.hpp"
#include "rx/print.hpp"
#include <iostream> #include <iostream>
#include <limits> #include <limits>
#include <print>
using namespace shader; using namespace shader;
@ -1111,7 +1111,7 @@ static void expToSpv(GcnConverter &converter, gcn::Stage stage,
return result; return result;
}; };
std::println(stderr, "exp target {}.{}", targetToString(target), rx::println(stderr, "exp target {}.{}", targetToString(target),
swizzleToString(swizzle)); swizzleToString(swizzle));
std::abort(); std::abort();
} }
@ -1184,9 +1184,9 @@ static void instructionsToSpv(GcnConverter &converter, gcn::Import &importer,
if (inst.getKind() != ir::Kind::Spv && inst.getKind() != ir::Kind::AmdGpu && if (inst.getKind() != ir::Kind::Spv && inst.getKind() != ir::Kind::AmdGpu &&
semanticModuleInfo.findSemanticOf(inst.getInstId()) == nullptr) { semanticModuleInfo.findSemanticOf(inst.getInstId()) == nullptr) {
std::println(std::cerr, "unimplemented semantic: "); std::println(stderr, "unimplemented semantic: ");
inst.print(std::cerr, context.ns); inst.print(std::cerr, context.ns);
std::println(std::cerr, "\n"); std::println(stderr, "\n");
std::vector<ir::Instruction> workList; std::vector<ir::Instruction> workList;
std::set<ir::Instruction> removed; std::set<ir::Instruction> removed;
@ -1201,9 +1201,9 @@ static void instructionsToSpv(GcnConverter &converter, gcn::Import &importer,
continue; continue;
} }
std::println(std::cerr, "removing "); rx::println(stderr, "removing ");
inst.print(std::cerr, context.ns); inst.print(std::cerr, context.ns);
std::println(std::cerr, "\n"); std::println(stderr, "\n");
if (auto value = inst.cast<ir::Value>()) { if (auto value = inst.cast<ir::Value>()) {
for (auto &use : value.getUseList()) { for (auto &use : value.getUseList()) {

View file

@ -6,10 +6,10 @@
#include "analyze.hpp" #include "analyze.hpp"
#include "dialect.hpp" #include "dialect.hpp"
#include "ir.hpp" #include "ir.hpp"
#include "rx/print.hpp"
#include "spv.hpp" #include "spv.hpp"
#include "transform.hpp" #include "transform.hpp"
#include <print>
#include <rx/die.hpp> #include <rx/die.hpp>
#include <SPIRV/GlslangToSpv.h> #include <SPIRV/GlslangToSpv.h>
@ -22,7 +22,6 @@
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <optional> #include <optional>
#include <print>
#include <type_traits> #include <type_traits>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
@ -1933,7 +1932,7 @@ gcn::deserialize(gcn::Context &context, const gcn::Environment &environment,
exitLabel.replaceAllUsesWith(newLabel); exitLabel.replaceAllUsesWith(newLabel);
} }
std::print("\n\n{}\n\n", buildCFG(context.entryPoint).genTest()); rx::print("\n\n{}\n\n", buildCFG(context.entryPoint).genTest());
structurizeCfg(context, context.body); structurizeCfg(context, context.body);

View file

@ -9,6 +9,7 @@
#include "orbis/thread/Process.hpp" #include "orbis/thread/Process.hpp"
#include "orbis/thread/Thread.hpp" #include "orbis/thread/Thread.hpp"
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "rx/die.hpp"
#include "rx/mem.hpp" #include "rx/mem.hpp"
#include "rx/watchdog.hpp" #include "rx/watchdog.hpp"
#include "vm.hpp" #include "vm.hpp"
@ -16,7 +17,6 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <mutex> #include <mutex>
#include <print>
#include <sys/mman.h> #include <sys/mman.h>
static constexpr auto kDceControlMemoryOffset = 0; static constexpr auto kDceControlMemoryOffset = 0;
@ -229,8 +229,7 @@ int DceDevice::allocateVmId() {
int id = std::countr_zero(freeVmIds); int id = std::countr_zero(freeVmIds);
if (id >= kVmIdCount) { if (id >= kVmIdCount) {
std::println(stderr, "out of vm slots"); rx::die("out of vm slots");
std::abort();
} }
freeVmIds &= ~(1 << id); freeVmIds &= ~(1 << id);

View file

@ -8,11 +8,11 @@
#include "orbis/thread/Thread.hpp" #include "orbis/thread/Thread.hpp"
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "rx/align.hpp" #include "rx/align.hpp"
#include "rx/format.hpp"
#include "rx/watchdog.hpp" #include "rx/watchdog.hpp"
#include "vm.hpp" #include "vm.hpp"
#include <fcntl.h> #include <fcntl.h>
#include <filesystem> #include <filesystem>
#include <format>
#include <mutex> #include <mutex>
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
@ -36,7 +36,7 @@ DmemDevice::~DmemDevice() {
close(shmFd); close(shmFd);
} }
std::filesystem::remove(std::format("{}/dmem-{}", rx::getShmPath(), index)); std::filesystem::remove(rx::format("{}/dmem-{}", rx::getShmPath(), index));
} }
orbis::ErrorCode DmemDevice::mmap(void **address, std::uint64_t len, orbis::ErrorCode DmemDevice::mmap(void **address, std::uint64_t len,
@ -400,7 +400,7 @@ IoDevice *createDmemCharacterDevice(int index) {
newDevice->index = index; newDevice->index = index;
newDevice->dmemTotalSize = dmemSize; newDevice->dmemTotalSize = dmemSize;
auto path = std::format("{}/dmem-{}", rx::getShmPath(), index); auto path = rx::format("{}/dmem-{}", rx::getShmPath(), index);
auto shmFd = ::open(path.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); auto shmFd = ::open(path.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (ftruncate(shmFd, dmemSize) < 0) { if (ftruncate(shmFd, dmemSize) < 0) {

View file

@ -10,10 +10,10 @@
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "orbis/utils/SharedMutex.hpp" #include "orbis/utils/SharedMutex.hpp"
#include "rx/die.hpp" #include "rx/die.hpp"
#include "rx/print.hpp"
#include "vm.hpp" #include "vm.hpp"
#include <cstdio> #include <cstdio>
#include <mutex> #include <mutex>
#include <print>
#include <sys/mman.h> #include <sys/mman.h>
struct ComputeQueue { struct ComputeQueue {
@ -405,7 +405,7 @@ static orbis::ErrorCode gc_ioctl(orbis::File *file, std::uint64_t request,
case 0x802450c9: { case 0x802450c9: {
// used during Net initialization // used during Net initialization
std::println(stderr, "***WARNING*** Unknown gc ioctl_{:x}(0x{:x})", request, rx::println(stderr, "***WARNING*** Unknown gc ioctl_{:x}(0x{:x})", request,
(unsigned long)*(std::uint32_t *)argp); (unsigned long)*(std::uint32_t *)argp);
break; break;
} }

View file

@ -5,16 +5,16 @@
#include "orbis/KernelContext.hpp" #include "orbis/KernelContext.hpp"
#include "orbis/osem.hpp" #include "orbis/osem.hpp"
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "rx/format.hpp"
#include "rx/hexdump.hpp" #include "rx/hexdump.hpp"
#include "rx/mem.hpp" #include "rx/mem.hpp"
#include "rx/print.hpp"
#include "rx/watchdog.hpp" #include "rx/watchdog.hpp"
#include "vfs.hpp" #include "vfs.hpp"
#include "vm.hpp" #include "vm.hpp"
#include <cstdint> #include <cstdint>
#include <fcntl.h> #include <fcntl.h>
#include <filesystem> #include <filesystem>
#include <format>
#include <print>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -209,7 +209,7 @@ ipmi::IpmiServer::handle(orbis::IpmiSession *session,
result = handler(*session, response.errorCode, outData, inData); result = handler(*session, response.errorCode, outData, inData);
} else { } else {
std::println(stderr, "Unimplemented async method {}::{:x}(inBufCount={})", rx::println(stderr, "Unimplemented async method {}::{:x}(inBufCount={})",
session->server->name, unsigned(message->methodId), session->server->name, unsigned(message->methodId),
unsigned(message->numInData)); unsigned(message->numInData));
@ -562,9 +562,9 @@ void ipmi::createGnmCompositorObjects(orbis::Process *) {
void ipmi::createShellCoreObjects(orbis::Process *process) { void ipmi::createShellCoreObjects(orbis::Process *process) {
auto fmtHex = [](auto value, bool upperCase = false) { auto fmtHex = [](auto value, bool upperCase = false) {
if (upperCase) { if (upperCase) {
return std::format("{:08X}", value); return rx::format("{:08X}", value);
} }
return std::format("{:08x}", value); return rx::format("{:08x}", value);
}; };
createIpmiServer(process, "SceSystemLoggerService"); createIpmiServer(process, "SceSystemLoggerService");

View file

@ -12,6 +12,7 @@
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "rx/Config.hpp" #include "rx/Config.hpp"
#include "rx/mem.hpp" #include "rx/mem.hpp"
#include "rx/print.hpp"
#include "rx/watchdog.hpp" #include "rx/watchdog.hpp"
#include "thread.hpp" #include "thread.hpp"
#include "vfs.hpp" #include "vfs.hpp"
@ -19,7 +20,6 @@
#include "xbyak/xbyak.h" #include "xbyak/xbyak.h"
#include <optional> #include <optional>
#include <orbis/utils/Rc.hpp> #include <orbis/utils/Rc.hpp>
#include <print>
#include <rx/Version.hpp> #include <rx/Version.hpp>
#include <rx/align.hpp> #include <rx/align.hpp>
#include <rx/hexdump.hpp> #include <rx/hexdump.hpp>
@ -46,7 +46,6 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <filesystem> #include <filesystem>
#include <print>
static int g_gpuPid; static int g_gpuPid;
extern bool allowMonoDebug; extern bool allowMonoDebug;
@ -709,7 +708,7 @@ ExecEnv guestCreateExecEnv(orbis::Thread *mainThread,
mainThread); mainThread);
if (libkernel == nullptr) { if (libkernel == nullptr) {
std::println(stderr, "libkernel not found"); rx::println(stderr, "libkernel not found");
std::abort(); std::abort();
} }

View file

@ -4,14 +4,13 @@
#include "orbis/thread/Process.hpp" #include "orbis/thread/Process.hpp"
#include "orbis/thread/Thread.hpp" #include "orbis/thread/Thread.hpp"
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "rx/debug.hpp"
#include "rx/mem.hpp" #include "rx/mem.hpp"
#include "rx/print.hpp"
#include <asm/prctl.h> #include <asm/prctl.h>
#include <csignal> #include <csignal>
#include <immintrin.h> #include <immintrin.h>
#include <link.h> #include <link.h>
#include <linux/prctl.h> #include <linux/prctl.h>
#include <print>
#include <rx/align.hpp> #include <rx/align.hpp>
#include <sys/prctl.h> #include <sys/prctl.h>
#include <ucontext.h> #include <ucontext.h>
@ -363,7 +362,7 @@ void *rx::thread::setupSignalStack(void *address) {
void *rx::thread::setupSignalStack() { void *rx::thread::setupSignalStack() {
auto data = malloc(getSigAltStackSize()); auto data = malloc(getSigAltStackSize());
if (data == nullptr) { if (data == nullptr) {
std::println(stderr, "malloc produces null, {:x}", getSigAltStackSize()); rx::println(stderr, "malloc produces null, {:x}", getSigAltStackSize());
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
return setupSignalStack(data); return setupSignalStack(data);

View file

@ -8,15 +8,15 @@
#include "orbis/thread/Thread.hpp" #include "orbis/thread/Thread.hpp"
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "orbis/utils/Rc.hpp" #include "orbis/utils/Rc.hpp"
#include "rx/format.hpp"
#include "rx/print.hpp"
#include "rx/watchdog.hpp" #include "rx/watchdog.hpp"
#include <bit> #include <bit>
#include <cassert> #include <cassert>
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <fcntl.h> #include <fcntl.h>
#include <format>
#include <mutex> #include <mutex>
#include <print>
#include <rx/MemoryTable.hpp> #include <rx/MemoryTable.hpp>
#include <rx/align.hpp> #include <rx/align.hpp>
#include <rx/mem.hpp> #include <rx/mem.hpp>
@ -674,7 +674,7 @@ static void reserve(std::uint64_t startAddress, std::uint64_t endAddress) {
} }
void vm::fork(std::uint64_t pid) { void vm::fork(std::uint64_t pid) {
auto shmPath = std::format("{}/memory-{}", rx::getShmPath(), pid); auto shmPath = rx::format("{}/memory-{}", rx::getShmPath(), pid);
gMemoryShm = gMemoryShm =
::open(shmPath.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); ::open(shmPath.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
@ -682,7 +682,7 @@ void vm::fork(std::uint64_t pid) {
g_mtx.unlock(); // release mutex g_mtx.unlock(); // release mutex
if (gMemoryShm == -1) { if (gMemoryShm == -1) {
std::println(stderr, "Memory: failed to open {}", shmPath); rx::println(stderr, "Memory: failed to open {}", shmPath);
std::abort(); std::abort();
} }
@ -739,7 +739,7 @@ void vm::reset() {
void vm::initialize(std::uint64_t pid) { void vm::initialize(std::uint64_t pid) {
std::println("Memory: initialization"); std::println("Memory: initialization");
auto shmPath = std::format("{}/memory-{}", rx::getShmPath(), pid); auto shmPath = rx::format("{}/memory-{}", rx::getShmPath(), pid);
gMemoryShm = gMemoryShm =
::open(shmPath.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); ::open(shmPath.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
@ -1185,8 +1185,8 @@ bool vm::virtualQuery(const void *addr, std::int32_t flags,
} }
memoryType = dmemIt->memoryType; memoryType = dmemIt->memoryType;
blockFlags = kBlockFlagDirectMemory; blockFlags = kBlockFlagDirectMemory;
std::print(stderr, "virtual query {}", addr); rx::print(stderr, "virtual query {}", addr);
std::println(stderr, "memory type: {}", memoryType); rx::println(stderr, "memory type: {}", memoryType);
} }
// TODO // TODO
} }

View file

@ -2,7 +2,6 @@ project(rx)
find_package(Git) find_package(Git)
add_library(${PROJECT_NAME} OBJECT add_library(${PROJECT_NAME} OBJECT
src/debug.cpp src/debug.cpp
src/die.cpp src/die.cpp
@ -20,6 +19,8 @@ PRIVATE
include/${PROJECT_NAME} include/${PROJECT_NAME}
) )
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt)
if (Git_FOUND) if (Git_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} log --date=format:%Y%m%d --pretty=format:'%cd' -n 1 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE GIT_DATE) execute_process(COMMAND ${GIT_EXECUTABLE} log --date=format:%Y%m%d --pretty=format:'%cd' -n 1 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE GIT_DATE)

View file

@ -0,0 +1,59 @@
#pragma once
#ifndef __has_include
#define __has_include(x) 0
#endif
#if __has_include(<print>)
#include <format>
namespace rx {
using std::format;
using std::format_args;
using std::format_context;
using std::format_parse_context;
using std::format_string;
using std::format_to;
using std::format_to_n;
using std::formatter;
using std::make_format_args;
using std::vformat;
using std::vformat_to;
} // namespace rx
#else
#include <fmt/format.h>
#include <type_traits>
namespace rx {
using fmt::format;
using fmt::format_args;
using fmt::format_context;
using fmt::format_parse_context;
namespace detail {
template <typename... Args>
struct format_string_impl : fmt::format_string<Args...> {
using fmt::format_string<Args...>::format_string;
constexpr std::string_view get() const noexcept {
return std::string_view(this->str);
}
};
} // namespace detail
template <typename... Args>
using format_string = std::type_identity_t<detail::format_string_impl<Args...>>;
template <typename... Args>
auto make_format_args(const Args &...args)
-> decltype(fmt::make_format_args(const_cast<Args &>(args)...)) {
return fmt::make_format_args(const_cast<Args &>(args)...);
}
using fmt::format_to;
using fmt::format_to_n;
using fmt::formatter;
using fmt::vformat;
using fmt::vformat_to;
} // namespace rx
#endif

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "format-base.hpp"
#include "refl.hpp" #include "refl.hpp"
#include <array> #include <array>
#include <format> #include <source_location>
#include <optional>
#include <string_view> #include <string_view>
#include <type_traits> #include <type_traits>
#include <unordered_map> #include <unordered_map>
@ -14,8 +14,7 @@ struct StructFieldInfo {
std::size_t size = 0; std::size_t size = 0;
std::size_t align = 0; std::size_t align = 0;
std::size_t offset = 0; std::size_t offset = 0;
std::format_context::iterator (*format)(void *, format_context::iterator (*format)(void *, format_context &ctx) = nullptr;
std::format_context &ctx) = nullptr;
std::string_view name; std::string_view name;
}; };
@ -25,11 +24,10 @@ struct StructFieldQuery {
template <typename T> constexpr operator T() { template <typename T> constexpr operator T() {
info.size = sizeof(T); info.size = sizeof(T);
info.align = alignof(T); info.align = alignof(T);
if constexpr (std::is_default_constructible_v<std::formatter<T>>) { if constexpr (std::is_default_constructible_v<formatter<T>>) {
info.format = info.format = [](void *object,
[](void *object, format_context &ctx) -> format_context::iterator {
std::format_context &ctx) -> std::format_context::iterator { formatter<T> formatter;
std::formatter<T> formatter;
return formatter.format(*static_cast<T *>(object), ctx); return formatter.format(*static_cast<T *>(object), ctx);
}; };
} }
@ -132,51 +130,66 @@ template <auto &&Variable> void registerVariable() {
auto &storage = detail::getVariableStorage(); auto &storage = detail::getVariableStorage();
storage.infos[&Variable] = rx::getNameOf<Variable>(); storage.infos[&Variable] = rx::getNameOf<Variable>();
} }
namespace detail {
template <typename... Args>
struct format_string_with_location_impl : format_string<Args...> {
std::source_location location;
template <typename T>
constexpr format_string_with_location_impl(
T message,
std::source_location location = std::source_location::current())
: format_string<Args...>(message), location(location) {}
};
} // namespace detail
template <typename... Args>
using format_string_with_location =
std::type_identity_t<detail::format_string_with_location_impl<Args...>>;
} // namespace rx } // namespace rx
template <typename T> template <typename T>
requires(std::is_standard_layout_v<T> && std::is_class_v<T> && requires(std::is_standard_layout_v<T> && std::is_class_v<T> &&
rx::fieldCount<T> > 0) && rx::fieldCount<T> > 0) &&
(!requires(T value) { std::begin(value) != std::end(value); }) (!requires(T value) { std::begin(value) != std::end(value); })
struct std::formatter<T> { struct rx::formatter<T> {
constexpr std::format_parse_context::iterator constexpr rx::format_parse_context::iterator
parse(std::format_parse_context &ctx) { parse(rx::format_parse_context &ctx) {
return ctx.begin(); return ctx.begin();
} }
std::format_context::iterator format(T &s, std::format_context &ctx) const { format_context::iterator format(T &s, rx::format_context &ctx) const {
std::format_to(ctx.out(), "{}", rx::getNameOf<T>()); format_to(ctx.out(), "{}", rx::getNameOf<T>());
std::format_to(ctx.out(), "{{"); format_to(ctx.out(), "{{");
auto structInfo = rx::detail::getStructInfo<T>(); auto structInfo = rx::detail::getStructInfo<T>();
auto bytes = reinterpret_cast<std::byte *>(&s); auto bytes = reinterpret_cast<std::byte *>(&s);
for (std::size_t i = 0; i < rx::fieldCount<T>; ++i) { for (std::size_t i = 0; i < rx::fieldCount<T>; ++i) {
if (i != 0) { if (i != 0) {
std::format_to(ctx.out(), ", "); format_to(ctx.out(), ", ");
} }
if (!structInfo[i].name.empty()) { if (!structInfo[i].name.empty()) {
std::format_to(ctx.out(), ".{} = ", structInfo[i].name); format_to(ctx.out(), ".{} = ", structInfo[i].name);
} }
structInfo[i].format(bytes + structInfo[i].offset, ctx); structInfo[i].format(bytes + structInfo[i].offset, ctx);
} }
std::format_to(ctx.out(), "}}"); format_to(ctx.out(), "}}");
return ctx.out(); return ctx.out();
} }
}; };
template <typename T> template <typename T>
requires(std::is_enum_v<T> && rx::fieldCount<T> > 0) requires(std::is_enum_v<T> && rx::fieldCount<T> > 0)
struct std::formatter<T> { struct rx::formatter<T> {
constexpr std::format_parse_context::iterator constexpr rx::format_parse_context::iterator
parse(std::format_parse_context &ctx) { parse(rx::format_parse_context &ctx) {
return ctx.begin(); return ctx.begin();
} }
std::format_context::iterator format(T value, rx::format_context::iterator format(T value, format_context &ctx) const {
std::format_context &ctx) const {
auto getFieldName = auto getFieldName =
[]<std::size_t... I>(std::underlying_type_t<T> value, []<std::size_t... I>(std::underlying_type_t<T> value,
std::index_sequence<I...>) -> std::string { std::index_sequence<I...>) -> std::string {
@ -188,7 +201,7 @@ struct std::formatter<T> {
return std::string(result); return std::string(result);
} }
return std::format("{}", value); return rx::format("{}", value);
}; };
auto queryUnknownField = auto queryUnknownField =
@ -208,16 +221,19 @@ struct std::formatter<T> {
}; };
if (value < 0) { if (value < 0) {
(queryIndex(std::integral_constant<std::int64_t, -(I + Offset)>{}, value), ...); (queryIndex(std::integral_constant<std::int64_t, -(I + Offset)>{},
value),
...);
} else { } else {
(queryIndex(std::integral_constant<std::int64_t, I + Offset>{}, value), ...); (queryIndex(std::integral_constant<std::int64_t, I + Offset>{}, value),
...);
} }
if (!result.empty()) { if (!result.empty()) {
return std::string(result); return std::string(result);
} }
return std::format("{}", value); return rx::format("{}", value);
}; };
std::string fieldName; std::string fieldName;
@ -240,9 +256,9 @@ struct std::formatter<T> {
} }
if (fieldName[0] >= '0' && fieldName[0] <= '9') { if (fieldName[0] >= '0' && fieldName[0] <= '9') {
std::format_to(ctx.out(), "({}){}", rx::getNameOf<T>(), fieldName); rx::format_to(ctx.out(), "({}){}", rx::getNameOf<T>(), fieldName);
} else { } else {
std::format_to(ctx.out(), "{}::{}", rx::getNameOf<T>(), fieldName); rx::format_to(ctx.out(), "{}::{}", rx::getNameOf<T>(), fieldName);
} }
return ctx.out(); return ctx.out();
@ -251,26 +267,26 @@ struct std::formatter<T> {
template <typename T> template <typename T>
requires requires(T value) { std::begin(value) != std::end(value); } requires requires(T value) { std::begin(value) != std::end(value); }
struct std::formatter<T> { struct rx::formatter<T> {
constexpr std::format_parse_context::iterator constexpr rx::format_parse_context::iterator
parse(std::format_parse_context &ctx) { parse(rx::format_parse_context &ctx) {
return ctx.begin(); return ctx.begin();
} }
std::format_context::iterator format(T &s, std::format_context &ctx) const { rx::format_context::iterator format(T &s, rx::format_context &ctx) const {
std::format_to(ctx.out(), "["); rx::format_to(ctx.out(), "[");
for (bool first = true; auto &elem : s) { for (bool first = true; auto &elem : s) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
std::format_to(ctx.out(), ", "); rx::format_to(ctx.out(), ", ");
} }
std::format_to(ctx.out(), "{}", elem); rx::format_to(ctx.out(), "{}", elem);
} }
std::format_to(ctx.out(), "]"); rx::format_to(ctx.out(), "]");
return ctx.out(); return ctx.out();
} }
}; };
@ -281,25 +297,25 @@ template <typename T>
!std::is_same_v<std::remove_cv_t<T>, char8_t> && !std::is_same_v<std::remove_cv_t<T>, char8_t> &&
!std::is_same_v<std::remove_cv_t<T>, char16_t> && !std::is_same_v<std::remove_cv_t<T>, char16_t> &&
!std::is_same_v<std::remove_cv_t<T>, char32_t> && !std::is_same_v<std::remove_cv_t<T>, char32_t> &&
std::is_default_constructible_v<std::formatter<T>>) std::is_default_constructible_v<rx::formatter<T>>)
struct std::formatter<T *> { struct rx::formatter<T *> {
constexpr std::format_parse_context::iterator constexpr rx::format_parse_context::iterator
parse(std::format_parse_context &ctx) { parse(rx::format_parse_context &ctx) {
return ctx.begin(); return ctx.begin();
} }
std::format_context::iterator format(T *ptr, std::format_context &ctx) const { rx::format_context::iterator format(T *ptr, rx::format_context &ctx) const {
auto name = rx::detail::getVariableStorage().getVariableName(ptr); auto name = rx::detail::getVariableStorage().getVariableName(ptr);
if (!name.empty()) { if (!name.empty()) {
std::format_to(ctx.out(), "*{} = ", name); rx::format_to(ctx.out(), "*{} = ", name);
} else { } else {
std::format_to(ctx.out(), "*"); rx::format_to(ctx.out(), "*");
} }
if (ptr == nullptr) { if (ptr == nullptr) {
std::format_to(ctx.out(), "nullptr"); rx::format_to(ctx.out(), "nullptr");
} else { } else {
std::format_to(ctx.out(), "{}:{}", static_cast<void *>(ptr), *ptr); rx::format_to(ctx.out(), "{}:{}", static_cast<void *>(ptr), *ptr);
} }
return ctx.out(); return ctx.out();
} }

32
rx/include/rx/print.hpp Normal file
View file

@ -0,0 +1,32 @@
#pragma once
#ifndef __has_include
#define __has_include(x) 0
#endif
#if __has_include(<print>)
#include <print>
namespace rx {
using std::print;
using std::println;
using std::vprint_nonunicode;
using std::vprint_unicode;
} // namespace rx
#else
#include <fmt/format.h>
namespace rx {
using fmt::print;
using fmt::println;
inline void vprint_nonunicode(FILE *stream, std::string_view fmt,
fmt::format_args args) {
fmt::vprint(stream, fmt, args);
}
inline void vprint_unicode(FILE *stream, std::string_view fmt,
fmt::format_args args) {
fmt::vprint(stream, fmt, args);
}
} // namespace rx
#endif

View file

@ -1,7 +1,7 @@
#include "debug.hpp" #include "debug.hpp"
#include "print.hpp"
#include <fstream> #include <fstream>
#include <list> #include <list>
#include <print>
#include <thread> #include <thread>
#include <vector> #include <vector>
@ -73,13 +73,13 @@ void rx::waitForDebugger() {
return; return;
} }
std::println(stderr, "waiting for debugger, pid {}", ::getpid()); rx::println(stderr, "waiting for debugger, pid {}", ::getpid());
while (!isDebuggerPresent()) { while (!isDebuggerPresent()) {
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(1));
} }
std::println(stderr, "debugger was attached"); rx::println(stderr, "debugger was attached");
std::this_thread::sleep_for(std::chrono::seconds(3)); std::this_thread::sleep_for(std::chrono::seconds(3));
breakpoint(); breakpoint();
} }

View file

@ -1,8 +1,8 @@
#include "hexdump.hpp" #include "hexdump.hpp"
#include "FileLock.hpp" #include "FileLock.hpp"
#include "print.hpp"
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <print>
#include <string> #include <string>
void rx::hexdump(std::span<const std::byte> bytes) { void rx::hexdump(std::span<const std::byte> bytes) {
@ -18,13 +18,13 @@ void rx::hexdump(std::span<const std::byte> bytes) {
} }
rx::ScopedFileLock stderrLock(stderr); rx::ScopedFileLock stderrLock(stderr);
std::print(stderr, "{} ", std::string(sizeWidth, ' ')); rx::print(stderr, "{} ", std::string(sizeWidth, ' '));
for (unsigned i = 0; i < 16; ++i) { for (unsigned i = 0; i < 16; ++i) {
std::print(stderr, " {:02x}", i); rx::print(stderr, " {:02x}", i);
} }
std::print(stderr, "\n{} ", std::string(sizeWidth, ' ')); rx::print(stderr, "\n{} ", std::string(sizeWidth, ' '));
for (unsigned i = 0; i < 16; ++i) { for (unsigned i = 0; i < 16; ++i) {
std::print(stderr, " --"); rx::print(stderr, " --");
} }
std::byte zeros[16]{}; std::byte zeros[16]{};
@ -38,7 +38,7 @@ void rx::hexdump(std::span<const std::byte> bytes) {
if (std::memcmp(bytes.data() + i, zeros, 16) == 0) { if (std::memcmp(bytes.data() + i, zeros, 16) == 0) {
if (!dotsPrinted) { if (!dotsPrinted) {
dotsPrinted = true; dotsPrinted = true;
std::print(stderr, "\n..."); rx::print(stderr, "\n...");
} }
i += 15; i += 15;
continue; continue;
@ -46,22 +46,21 @@ void rx::hexdump(std::span<const std::byte> bytes) {
} }
if (!dotsPrinted) { if (!dotsPrinted) {
std::print(stderr, " | "); rx::print(stderr, " | ");
for (std::size_t j = i - 16; j < i; ++j) { for (std::size_t j = i - 16; j < i; ++j) {
auto c = unsigned(bytes[j]); auto c = unsigned(bytes[j]);
std::print(stderr, "{:c}", rx::print(stderr, "{:c}", (std::isprint(c) && c != '\n') ? c : '.');
(std::isprint(c) && c != '\n') ? c : '.');
} }
} }
} }
std::println(stderr, ""); rx::println(stderr, "");
std::print(stderr, "{:0{}x} ", i, sizeWidth); rx::print(stderr, "{:0{}x} ", i, sizeWidth);
wasAllZeros = true; wasAllZeros = true;
dotsPrinted = false; dotsPrinted = false;
} }
std::print(stderr, " {:02x}", unsigned(bytes[i])); rx::print(stderr, " {:02x}", unsigned(bytes[i]));
if (bytes[i] != std::byte{0}) { if (bytes[i] != std::byte{0}) {
wasAllZeros = false; wasAllZeros = false;
@ -70,17 +69,17 @@ void rx::hexdump(std::span<const std::byte> bytes) {
if (!bytes.empty()) { if (!bytes.empty()) {
for (std::size_t i = 0; i < (16 - (bytes.size() % 16)) % 16; ++i) { for (std::size_t i = 0; i < (16 - (bytes.size() % 16)) % 16; ++i) {
std::print(stderr, " "); rx::print(stderr, " ");
} }
std::print(stderr, " | "); rx::print(stderr, " | ");
for (std::size_t j = bytes.size() - for (std::size_t j = bytes.size() -
std::min(bytes.size(), std::min(bytes.size(),
(bytes.size() % 16 ? bytes.size() % 16 : 16)); (bytes.size() % 16 ? bytes.size() % 16 : 16));
j < bytes.size(); ++j) { j < bytes.size(); ++j) {
auto c = unsigned(bytes[j]); auto c = unsigned(bytes[j]);
std::print(stderr, "{:c}", (std::isprint(c) && c != '\n') ? c : '.'); rx::print(stderr, "{:c}", (std::isprint(c) && c != '\n') ? c : '.');
} }
} }
std::println(stderr, ""); rx::println(stderr, "");
} }

View file

@ -1,9 +1,9 @@
#include "mem.hpp" #include "mem.hpp"
#include "print.hpp"
#ifdef __linux__ #ifdef __linux__
#include <cstdio> #include <cstdio>
#include <print>
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
@ -41,7 +41,7 @@ void rx::mem::printStats() {
char *line = nullptr; char *line = nullptr;
std::size_t size = 0; std::size_t size = 0;
while (getline(&line, &size, maps) > 0) { while (getline(&line, &size, maps) > 0) {
std::print("{}", line); rx::print("{}", line);
} }
free(line); free(line);