format all source code with clang-format

This commit is contained in:
DH 2025-04-05 22:50:45 +03:00
parent 6bbaf18e71
commit 42cb5d7977
1234 changed files with 90082 additions and 82954 deletions

View file

@ -65,8 +65,8 @@ struct ProcessOps {
uint64_t arg3);
SysResult (*dynlib_unload_prx)(Thread *thread, ModuleHandle handle);
SysResult (*thr_create)(Thread *thread, ptr<UContext> ctxt,
ptr<slong> arg, sint flags);
SysResult (*thr_create)(Thread *thread, ptr<UContext> ctxt, ptr<slong> arg,
sint flags);
SysResult (*thr_new)(Thread *thread, ptr<thr_param> param, sint param_size);
SysResult (*thr_exit)(Thread *thread, ptr<slong> state);
SysResult (*thr_kill)(Thread *thread, slong id, sint sig);

View file

@ -83,7 +83,6 @@ struct UContext {
static_assert(sizeof(UContext) == 0x500);
enum Signal {
kSigHup = 1,
kSigInt = 2,

View file

@ -1,7 +1,7 @@
#pragma once
#include "orbis-config.hpp"
#include "error/ErrorCode.hpp"
#include "orbis-config.hpp"
#include <cstddef>
#include <cstdint>
#include <cstring>
@ -49,8 +49,7 @@ struct Uio {
return {};
}
template<typename T>
ErrorCode write(const T &object) {
template <typename T> ErrorCode write(const T &object) {
return write(&object, sizeof(T));
}
};

View file

@ -54,7 +54,6 @@ inline constexpr auto kUmtxOpNwakePrivate = 21;
inline constexpr auto kUmtxOpMutexWake2 = 22;
inline constexpr auto kUmtxOpMutexWake3 = 23;
inline constexpr auto kSemNamed = 2;
struct umtx {

View file

@ -203,7 +203,8 @@ static orbis::SysResult doRelocation(orbis::Process *process,
auto &defModule = module->importedModules.at(symbol.moduleIndex);
if (!defModule) {
// std::printf("'%s' ('%s') uses undefined symbol '%llx' in unloaded module "
// std::printf("'%s' ('%s') uses undefined symbol '%llx' in unloaded
// module "
// "'%s', rel %u\n",
// module->moduleName, module->soName,
// (unsigned long long)symbol.id,
@ -295,7 +296,8 @@ static orbis::SysResult doRelocation(orbis::Process *process,
if (defObj == nullptr) {
return orbis::ErrorCode::INVAL;
}
*where32 = S ? reinterpret_cast<std::uintptr_t>(defObj->base) + S + A - P : 0;
*where32 =
S ? reinterpret_cast<std::uintptr_t>(defObj->base) + S + A - P : 0;
return {};
}
// case kRelCopy:

View file

@ -12,8 +12,8 @@ static orbis::ErrorCode pipe_read(orbis::File *file, orbis::Uio *uio,
while (true) {
if (pipe->data.empty()) {
// pipe->cv.wait(file->mtx);
// ORBIS_LOG_ERROR(__FUNCTION__, "wakeup", thread->name, thread->tid, file);
// continue;
// ORBIS_LOG_ERROR(__FUNCTION__, "wakeup", thread->name, thread->tid,
// file); continue;
return orbis::ErrorCode::WOULDBLOCK;
}
@ -32,7 +32,8 @@ static orbis::ErrorCode pipe_read(orbis::File *file, orbis::Uio *uio,
uio->offset += size;
std::memcpy(vec.base, pipe->data.data(), size);
ORBIS_LOG_ERROR(__FUNCTION__, thread->name, thread->tid, file, size, pipe->data.size(), uio->offset, file->nextOff);
ORBIS_LOG_ERROR(__FUNCTION__, thread->name, thread->tid, file, size,
pipe->data.size(), uio->offset, file->nextOff);
if (pipe->data.size() == size) {
pipe->data.clear();
@ -69,7 +70,8 @@ static orbis::ErrorCode pipe_write(orbis::File *file, orbis::Uio *uio,
uio->resid -= cnt;
uio->offset += cnt;
ORBIS_LOG_ERROR(__FUNCTION__, thread->name, thread->tid, file, uio->resid, uio->offset, file->nextOff, cnt);
ORBIS_LOG_ERROR(__FUNCTION__, thread->name, thread->tid, file, uio->resid,
uio->offset, file->nextOff, cnt);
thread->where();
return {};
}
@ -79,7 +81,8 @@ static orbis::FileOps pipe_ops = {
.write = pipe_write,
};
std::pair<orbis::Ref<orbis::Pipe>, orbis::Ref<orbis::Pipe>> orbis::createPipe() {
std::pair<orbis::Ref<orbis::Pipe>, orbis::Ref<orbis::Pipe>>
orbis::createPipe() {
auto a = knew<Pipe>();
auto b = knew<Pipe>();
a->event = knew<EventEmitter>();

View file

@ -1,15 +1,12 @@
#include "sys/sysproto.hpp"
orbis::SysResult orbis::sys_getcontext(Thread *thread,
ptr<UContext> ucp) {
return ErrorCode::NOSYS;
}
orbis::SysResult orbis::sys_setcontext(Thread *thread,
ptr<UContext> ucp) {
return ErrorCode::NOSYS;
}
orbis::SysResult orbis::sys_swapcontext(Thread *thread,
ptr<UContext> oucp,
orbis::SysResult orbis::sys_getcontext(Thread *thread, ptr<UContext> ucp) {
return ErrorCode::NOSYS;
}
orbis::SysResult orbis::sys_setcontext(Thread *thread, ptr<UContext> ucp) {
return ErrorCode::NOSYS;
}
orbis::SysResult orbis::sys_swapcontext(Thread *thread, ptr<UContext> oucp,
ptr<UContext> ucp) {
return ErrorCode::NOSYS;
}

View file

@ -148,7 +148,8 @@ orbis::SysResult orbis::sys_cpuset_setaffinity(Thread *thread, cpulevel_t level,
auto threadHandle = whichThread->getNativeHandle();
auto hostCpuSet = toHostCpuSet(whichThread->affinity);
ORBIS_LOG_ERROR(__FUNCTION__, threadHandle, thread->tid, id);
if (pthread_setaffinity_np(threadHandle, sizeof(hostCpuSet), &hostCpuSet)) {
if (pthread_setaffinity_np(threadHandle, sizeof(hostCpuSet),
&hostCpuSet)) {
ORBIS_LOG_ERROR(__FUNCTION__,
"failed to set affinity mask for host thread",
whichThread->hostTid, whichThread->affinity.bits);

View file

@ -2,8 +2,8 @@
#include "orbis/utils/Logs.hpp"
#include "stat.hpp"
#include "sys/sysproto.hpp"
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
#include "thread/Thread.hpp"
orbis::SysResult orbis::sys_getdtablesize(Thread *thread) {
return ErrorCode::NOSYS;

View file

@ -1,7 +1,7 @@
#include "sys/sysproto.hpp"
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
#include "thread/ProcessOps.hpp"
#include "thread/Thread.hpp"
orbis::SysResult orbis::sys_execve(Thread *thread, ptr<char> fname,
ptr<ptr<char>> argv, ptr<ptr<char>> envv) {

View file

@ -1,11 +1,11 @@
#include "KernelContext.hpp"
#include "sys/sysproto.hpp"
#include "thread/Process.hpp"
#include "thread/ProcessOps.hpp"
#include "utils/Logs.hpp"
#include <sys/resource.h>
#include <sys/wait.h>
#include <unistd.h>
#include "thread/Process.hpp"
orbis::SysResult orbis::sys_exit(Thread *thread, sint status) {
if (auto exit = thread->tproc->ops->exit) {

View file

@ -1,8 +1,8 @@
#include "file.hpp"
#include "orbis/utils/Logs.hpp"
#include "sys/sysproto.hpp"
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
#include "thread/Thread.hpp"
#include "uio.hpp"
#include <sstream>

View file

@ -1,6 +1,6 @@
#include "sys/sysproto.hpp"
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
#include "thread/Thread.hpp"
#include "utils/Logs.hpp"
#include <pipe.hpp>

View file

@ -59,11 +59,11 @@ orbis::SysResult orbis::sys_rtprio_thread(Thread *thread, sint function,
hostPolicy = SCHED_IDLE;
}
if (pthread_setschedparam(targetThread->getNativeHandle(),
hostPolicy, &hostParam)) {
ORBIS_LOG_ERROR(__FUNCTION__, "failed to set host priority",
hostPriority, targetThread->prio.prio,
targetThread->prio.type, errno,
if (pthread_setschedparam(targetThread->getNativeHandle(), hostPolicy,
&hostParam)) {
ORBIS_LOG_ERROR(
__FUNCTION__, "failed to set host priority", hostPriority,
targetThread->prio.prio, targetThread->prio.type, errno,
targetThread->getNativeHandle(), prioMin, prioMax, errno);
}
} else {

View file

@ -1165,8 +1165,7 @@ orbis::sys_dynlib_get_info_ex(Thread *thread, SceKernelModule handle,
result.ehFrame = module->ehFrame;
result.ehFrameHdrSize = module->ehFrameHdrSize;
result.ehFrameSize = module->ehFrameSize;
std::memcpy(result.segments, module->segments,
sizeof(ModuleSegment) * 2);
std::memcpy(result.segments, module->segments, sizeof(ModuleSegment) * 2);
result.segmentCount = 2;
result.refCount = 1;
ORBIS_LOG_WARNING(__FUNCTION__, result.id, result.name, result.tlsIndex,

View file

@ -140,10 +140,11 @@ orbis::SysResult orbis::sys_sigreturn(Thread *thread, ptr<UContext> sigcntxp) {
ORBIS_LOG_WARNING(__FUNCTION__, sigcntxp);
// auto sigRet = thread->sigReturns.front();
// thread->sigReturns.erase(thread->sigReturns.begin(), thread->sigReturns.begin() + 1);
// writeRegister(thread->context, RegisterId::rip, sigRet.rip);
// writeRegister(thread->context, RegisterId::rsp, sigRet.rsp);
// ORBIS_LOG_ERROR(__FUNCTION__, sigRet.rip, sigRet.rsp);
// thread->sigReturns.erase(thread->sigReturns.begin(),
// thread->sigReturns.begin() + 1); writeRegister(thread->context,
// RegisterId::rip, sigRet.rip); writeRegister(thread->context,
// RegisterId::rsp, sigRet.rsp); ORBIS_LOG_ERROR(__FUNCTION__, sigRet.rip,
// sigRet.rsp);
return {};
}

View file

@ -1,11 +1,10 @@
#include "sys/sysproto.hpp"
#include "thread/Process.hpp"
#include "thread/ProcessOps.hpp"
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
#include "ucontext.hpp"
orbis::SysResult orbis::sys_thr_create(Thread *thread,
ptr<UContext> ctxt,
orbis::SysResult orbis::sys_thr_create(Thread *thread, ptr<UContext> ctxt,
ptr<slong> arg, sint flags) {
if (auto thr_create = thread->tproc->ops->thr_create) {
return thr_create(thread, ctxt, arg, flags);

View file

@ -1,8 +1,8 @@
#include "file.hpp"
#include "sys/sysproto.hpp"
#include "thread/Process.hpp"
#include "thread/ProcessOps.hpp"
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
#include "uio.hpp"
#include "utils/Logs.hpp"
#include <sys/socket.h>
@ -128,7 +128,8 @@ orbis::SysResult orbis::sys_recvfrom(Thread *thread, sint s, caddr_t buf,
}
if (auto recvfrom = file->ops->recvfrom) {
return SysResult::notAnError(recvfrom(file.get(), buf, len, flags, from, fromlenaddr, thread));
return SysResult::notAnError(
recvfrom(file.get(), buf, len, flags, from, fromlenaddr, thread));
}
return ErrorCode::NOTSUP;

View file

@ -1,9 +1,9 @@
#include "file.hpp"
#include "orbis-config.hpp"
#include "sys/sysproto.hpp"
#include "thread/Process.hpp"
#include "thread/ProcessOps.hpp"
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
orbis::SysResult orbis::sys_shm_open(Thread *thread, ptr<const char> path,
sint flags, mode_t mode) {

View file

@ -1,8 +1,8 @@
#include "stat.hpp"
#include "sys/sysproto.hpp"
#include "thread/Process.hpp"
#include "thread/ProcessOps.hpp"
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
#include "utils/Logs.hpp"
#include <filesystem>
#include <span>
@ -71,8 +71,8 @@ orbis::SysResult orbis::sys_chroot(Thread *thread, ptr<char> path) {
}
// volatile bool debuggerPresent = false;
orbis::SysResult orbis::sys_open(Thread *thread, ptr<const char> path, sint flags,
sint mode) {
orbis::SysResult orbis::sys_open(Thread *thread, ptr<const char> path,
sint flags, sint mode) {
if (auto open = thread->tproc->ops->open) {
Ref<File> file;
auto result = open(thread, path, flags, mode, &file);
@ -82,7 +82,9 @@ orbis::SysResult orbis::sys_open(Thread *thread, ptr<const char> path, sint flag
auto fd = thread->tproc->fileDescriptors.insert(file);
thread->retval[0] = fd;
// if (path == std::string_view{"/app0/psm/Application/resource/Sce.Vsh.ShellUI.SystemMessage.rco"}) {
// if (path ==
// std::string_view{"/app0/psm/Application/resource/Sce.Vsh.ShellUI.SystemMessage.rco"})
// {
ORBIS_LOG_SUCCESS(__FUNCTION__, thread->tid, path, flags, mode, fd);
if (path == std::string_view{"/app0/wave/wave1.fbxd"}) {
thread->where();
@ -288,7 +290,8 @@ orbis::SysResult orbis::sys_readlink(Thread *thread, ptr<char> path,
}
Ref<File> file;
if (auto error = thread->tproc->ops->open(thread, path, 0, 0, &file); error.value()) {
if (auto error = thread->tproc->ops->open(thread, path, 0, 0, &file);
error.value()) {
return error;
}

View file

@ -1,6 +1,6 @@
#include "sys/sysproto.hpp"
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
#include "thread/Thread.hpp"
#include <mutex>
#include <string>

View file

@ -1,7 +1,7 @@
#include "sys/sysproto.hpp"
#include "thread/Process.hpp"
#include "thread/ProcessOps.hpp"
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
orbis::SysResult orbis::sys_mount(Thread *thread, ptr<char> type,
ptr<char> path, sint flags, caddr_t data) {

View file

@ -1,8 +1,8 @@
#include "error.hpp"
#include "sys/sysproto.hpp"
#include "thread/Process.hpp"
#include "thread/ProcessOps.hpp"
#include "thread/Thread.hpp"
#include "thread/Process.hpp"
orbis::SysResult orbis::sys_sbrk(Thread *, sint) {
return ErrorCode::OPNOTSUPP;

View file

@ -47,7 +47,8 @@ void shared_mutex::impl_lock_shared(unsigned val) {
if ((old % c_sig) + c_one >= c_sig)
std::abort(); // "shared_mutex overflow"
while (impl_wait() != std::errc{}) {}
while (impl_wait() != std::errc{}) {
}
lock_downgrade();
}
void shared_mutex::impl_unlock_shared(unsigned old) {
@ -120,7 +121,8 @@ void shared_mutex::impl_lock(unsigned val) {
if ((old % c_sig) + c_one >= c_sig)
std::abort(); // "shared_mutex overflow"
while (impl_wait() != std::errc{}) {}
while (impl_wait() != std::errc{}) {
}
}
void shared_mutex::impl_unlock(unsigned old) {
if (old - c_one >= c_err)
@ -152,7 +154,8 @@ void shared_mutex::impl_lock_upgrade() {
return;
}
while (impl_wait() != std::errc{}) {}
while (impl_wait() != std::errc{}) {
}
}
bool shared_mutex::lock_forced(int count) {
if (count == 0)

View file

@ -102,7 +102,7 @@ add_subdirectory(yaml-cpp)
# OpenGL
if (NOT ANDROID)
if (NOT ANDROID AND NOT WITHOUT_OPENGL)
find_package(OpenGL REQUIRED OPTIONAL_COMPONENTS EGL)
add_library(3rdparty_opengl INTERFACE)
@ -212,7 +212,7 @@ endif()
add_subdirectory(asmjit EXCLUDE_FROM_ALL)
# OpenAL
if (NOT ANDROID)
if (NOT ANDROID AND NOT WITHOUT_OPENAL)
add_subdirectory(OpenAL EXCLUDE_FROM_ALL)
else()
add_library(3rdparty_openal INTERFACE)
@ -303,7 +303,7 @@ endif()
# GLEW
add_library(3rdparty_glew INTERFACE)
if(NOT MSVC AND NOT ANDROID)
if(NOT MSVC AND NOT ANDROID AND NOT WITHOUT_OPENGLEW)
find_package(GLEW REQUIRED)
target_link_libraries(3rdparty_glew INTERFACE GLEW::GLEW)
endif()

View file

@ -2,6 +2,7 @@ option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" OFF)
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
option(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" ON)
option(ZSTD_BUILD_TESTS "BUILD TESTS" OFF)
option(ZSTD_USE_STATIC_RUNTIME "LINK TO STATIC RUN-TIME LIBRARIES" ON)
add_subdirectory(zstd/build/cmake EXLUDE_FROM_ALL)
add_library(3rdparty_zstd INTERFACE)

View file

@ -101,8 +101,8 @@ if(MSVC)
add_compile_options(/MP)
endif()
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message( FATAL_ERROR "RPCS3 can only be compiled on 64-bit platforms." )
if(CMAKE_SIZEOF_VOID_P AND NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message( FATAL_ERROR "RPCS3 can only be compiled on 64-bit platforms. ${CMAKE_SIZEOF_VOID_P}" )
endif()
find_program(CCACHE_FOUND ccache)

View file

@ -19,7 +19,8 @@ struct bf_base
using compact_type = std::conditional_t<can_be_packed, std::conditional_t<std::is_unsigned_v<vtype>, uint, int>, vtype>;
// Datatype bitsize
static constexpr uint bitmax = sizeof(T) * 8; static_assert(N - 1 < bitmax, "bf_base<> error: N out of bounds");
static constexpr uint bitmax = sizeof(T) * 8;
static_assert(N - 1 < bitmax, "bf_base<> error: N out of bounds");
// Field bitsize
static constexpr uint bitsize = N;
@ -44,7 +45,8 @@ struct bf_t : bf_base<T, N>
using compact_type = typename bf_t::compact_type;
// Field offset
static constexpr uint bitpos = I; static_assert(bitpos + N <= bf_t::bitmax, "bf_t<> error: I out of bounds");
static constexpr uint bitpos = I;
static_assert(bitpos + N <= bf_t::bitmax, "bf_t<> error: I out of bounds");
// Get bitmask of size N, at I pos
static constexpr utype data_mask()
@ -157,13 +159,19 @@ struct bf_t : bf_base<T, N>
};
template <typename T, uint I, uint N>
struct std::common_type<bf_t<T, I, N>, bf_t<T, I, N>> : std::common_type<T> {};
struct std::common_type<bf_t<T, I, N>, bf_t<T, I, N>> : std::common_type<T>
{
};
template <typename T, uint I, uint N, typename T2>
struct std::common_type<bf_t<T, I, N>, T2> : std::common_type<T2, std::common_type_t<T>> {};
struct std::common_type<bf_t<T, I, N>, T2> : std::common_type<T2, std::common_type_t<T>>
{
};
template <typename T, uint I, uint N, typename T2>
struct std::common_type<T2, bf_t<T, I, N>> : std::common_type<std::common_type_t<T>, T2> {};
struct std::common_type<T2, bf_t<T, I, N>> : std::common_type<std::common_type_t<T>, T2>
{
};
// Field pack (concatenated from left to right)
template <typename F = void, typename... Fields>

View file

@ -329,8 +329,7 @@ namespace CRCPP
@tparam CRCWidth Number of bits in the CRC
*/
template <typename CRCType, crcpp_uint16 CRCWidth>
inline CRC::Table<CRCType, CRCWidth>::Table(const Parameters<CRCType, CRCWidth> & parameters) :
parameters(parameters)
inline CRC::Table<CRCType, CRCWidth>::Table(const Parameters<CRCType, CRCWidth>& parameters) : parameters(parameters)
{
InitTable();
}
@ -343,8 +342,7 @@ namespace CRCPP
@tparam CRCWidth Number of bits in the CRC
*/
template <typename CRCType, crcpp_uint16 CRCWidth>
inline CRC::Table<CRCType, CRCWidth>::Table(Parameters<CRCType, CRCWidth> && parameters) :
parameters(::std::move(parameters))
inline CRC::Table<CRCType, CRCWidth>::Table(Parameters<CRCType, CRCWidth>&& parameters) : parameters(::std::move(parameters))
{
InitTable();
}
@ -611,7 +609,10 @@ namespace CRCPP
#else
// Catching this compile-time error is very important. Sadly, the compiler error will be very cryptic, but it's
// better than nothing.
enum { static_assert_failed_CRCType_is_too_small_to_contain_a_CRC_of_width_CRCWidth = 1 / (::std::numeric_limits<CRCType>::digits >= CRCWidth ? 1 : 0) };
enum
{
static_assert_failed_CRCType_is_too_small_to_contain_a_CRC_of_width_CRCWidth = 1 / (::std::numeric_limits<CRCType>::digits >= CRCWidth ? 1 : 0)
};
#endif
const unsigned char* current = reinterpret_cast<const unsigned char*>(data);

View file

@ -69,7 +69,7 @@ namespace cfg
// Incrementally load config entries from YAML::Node.
// The config value is preserved if the corresponding YAML node doesn't exist.
static void decode(const YAML::Node& data, class _base& rhs, bool dynamic = false);
}
} // namespace cfg
std::vector<std::string> cfg::make_int_range(s64 min, s64 max)
{
@ -80,7 +80,8 @@ bool try_to_int64(s64* out, std::string_view value, s64 min, s64 max)
{
if (value.empty())
{
if (out) cfg_log.error("cfg::try_to_int64(): called with an empty string");
if (out)
cfg_log.error("cfg::try_to_int64(): called with an empty string");
return false;
}
@ -107,7 +108,8 @@ bool try_to_int64(s64* out, std::string_view value, s64 min, s64 max)
if (ret.ec != std::errc() || ret.ptr != end || (start[0] == '-' && sign < 0))
{
if (out) cfg_log.error("cfg::try_to_int64('%s'): invalid integer", value);
if (out)
cfg_log.error("cfg::try_to_int64('%s'): invalid integer", value);
return false;
}
@ -115,11 +117,13 @@ bool try_to_int64(s64* out, std::string_view value, s64 min, s64 max)
if (result < min || result > max)
{
if (out) cfg_log.error("cfg::try_to_int64('%s'): out of bounds (val=%d, min=%d, max=%d)", value, result, min, max);
if (out)
cfg_log.error("cfg::try_to_int64('%s'): out of bounds (val=%d, min=%d, max=%d)", value, result, min, max);
return false;
}
if (out) *out = result;
if (out)
*out = result;
return true;
}
@ -132,7 +136,8 @@ bool try_to_uint64(u64* out, std::string_view value, u64 min, u64 max)
{
if (value.empty())
{
if (out) cfg_log.error("cfg::try_to_uint64(): called with an empty string");
if (out)
cfg_log.error("cfg::try_to_uint64(): called with an empty string");
return false;
}
@ -152,17 +157,20 @@ bool try_to_uint64(u64* out, std::string_view value, u64 min, u64 max)
if (ret.ec != std::errc() || ret.ptr != end)
{
if (out) cfg_log.error("cfg::try_to_uint64('%s'): invalid integer", value);
if (out)
cfg_log.error("cfg::try_to_uint64('%s'): invalid integer", value);
return false;
}
if (result < min || result > max)
{
if (out) cfg_log.error("cfg::try_to_uint64('%s'): out of bounds (val=%u, min=%u, max=%u)", value, result, min, max);
if (out)
cfg_log.error("cfg::try_to_uint64('%s'): out of bounds (val=%u, min=%u, max=%u)", value, result, min, max);
return false;
}
if (out) *out = result;
if (out)
*out = result;
return true;
}
@ -175,7 +183,8 @@ bool try_to_float(f64* out, std::string_view value, f64 min, f64 max)
{
if (value.empty())
{
if (out) cfg_log.error("cfg::try_to_float(): called with an empty string");
if (out)
cfg_log.error("cfg::try_to_float(): called with an empty string");
return false;
}
@ -188,36 +197,42 @@ bool try_to_float(f64* out, std::string_view value, f64 min, f64 max)
if (end_check != str.data() + str.size())
{
if (out) cfg_log.error("cfg::try_to_float('%s'): invalid float", value);
if (out)
cfg_log.error("cfg::try_to_float('%s'): invalid float", value);
return false;
}
if (result < min || result > max)
{
if (out) cfg_log.error("cfg::try_to_float('%s'): out of bounds (val=%f, min=%f, max=%f)", value, result, min, max);
if (out)
cfg_log.error("cfg::try_to_float('%s'): out of bounds (val=%f, min=%f, max=%f)", value, result, min, max);
return false;
}
if (out) *out = result;
if (out)
*out = result;
return true;
}
bool try_to_string(std::string* out, const f64& value)
{
#ifdef __APPLE__
if (out) *out = std::to_string(value);
if (out)
*out = std::to_string(value);
return true;
#else
std::array<char, 32> str{};
if (auto [ptr, ec] = std::to_chars(str.data(), str.data() + str.size(), value, std::chars_format::fixed); ec == std::errc())
{
if (out) *out = std::string(str.data(), ptr);
if (out)
*out = std::string(str.data(), ptr);
return true;
}
else
{
if (out) cfg_log.error("cfg::try_to_string(): could not convert value '%f' to string. error='%s'", value, std::make_error_code(ec).message());
if (out)
cfg_log.error("cfg::try_to_string(): could not convert value '%f' to string. error='%s'", value, std::make_error_code(ec).message());
return false;
}
#endif
@ -235,7 +250,8 @@ bool cfg::try_to_enum_value(u64* out, decltype(&fmt_class_string<int>::format) f
if (var == value)
{
if (out) *out = i;
if (out)
*out = i;
return true;
}
@ -271,17 +287,20 @@ bool cfg::try_to_enum_value(u64* out, decltype(&fmt_class_string<int>::format) f
if (ret.ec != std::errc() || ret.ptr != end)
{
if (out) cfg_log.error("cfg::try_to_enum_value('%s'): invalid enum or integer", value);
if (out)
cfg_log.error("cfg::try_to_enum_value('%s'): invalid enum or integer", value);
return false;
}
if (result > max)
{
if (out) cfg_log.error("cfg::try_to_enum_value('%s'): out of bounds(val=%u, min=0, max=%u)", value, result, max);
if (out)
cfg_log.error("cfg::try_to_enum_value('%s'): out of bounds(val=%u, min=0, max=%u)", value, result, max);
return false;
}
if (out) *out = result;
if (out)
*out = result;
return true;
}
@ -369,7 +388,8 @@ void cfg::encode(YAML::Emitter& out, const cfg::_base& rhs)
out << YAML::BeginMap;
for (const auto& np : static_cast<const log_entry&>(rhs).get_map())
{
if (np.second == logs::level::notice) continue;
if (np.second == logs::level::notice)
continue;
out << YAML::Key << np.first;
out << YAML::Value << fmt::format("%s", np.second);
}
@ -418,7 +438,8 @@ void cfg::decode(const YAML::Node& data, cfg::_base& rhs, bool dynamic)
for (const auto& pair : data)
{
if (!pair.first.IsScalar()) continue;
if (!pair.first.IsScalar())
continue;
// Find the key among existing nodes
for (const auto& node : static_cast<node&>(rhs).get_nodes())
@ -455,7 +476,8 @@ void cfg::decode(const YAML::Node& data, cfg::_base& rhs, bool dynamic)
for (const auto& pair : data)
{
if (!pair.first.IsScalar() || !pair.second.IsScalar()) continue;
if (!pair.first.IsScalar() || !pair.second.IsScalar())
continue;
values.emplace(pair.first.Scalar(), pair.second.Scalar());
}
@ -474,7 +496,8 @@ void cfg::decode(const YAML::Node& data, cfg::_base& rhs, bool dynamic)
for (const auto& pair : data)
{
if (!pair.first.IsScalar() || !pair.second.IsScalar()) continue;
if (!pair.first.IsScalar() || !pair.second.IsScalar())
continue;
u64 value;
if (cfg::try_to_enum_value(&value, &fmt_class_string<logs::level>::format, pair.second.Scalar()))
@ -497,13 +520,15 @@ void cfg::decode(const YAML::Node& data, cfg::_base& rhs, bool dynamic)
for (const auto& pair : data)
{
if (!pair.first.IsScalar() || !pair.second.IsMap()) continue;
if (!pair.first.IsScalar() || !pair.second.IsMap())
continue;
device_info info{};
for (const auto& key_value : pair.second)
{
if (!key_value.first.IsScalar() || !key_value.second.IsScalar()) continue;
if (!key_value.first.IsScalar() || !key_value.second.IsScalar())
continue;
if (key_value.first.Scalar() == "Path")
info.path = key_value.second.Scalar();
@ -578,7 +603,6 @@ bool cfg::node::from_json(const nlohmann::json &json, bool dynamic)
return nullptr;
};
for (auto& [key, value] : json.get<nlohmann::json::object_t>())
{
auto keyNode = find_node(key);

View file

@ -75,19 +75,34 @@ namespace cfg
virtual ~_base() = default;
// Get unique ID
u32 get_id() const { return m_id; }
u32 get_id() const
{
return m_id;
}
// Get parent
_base* get_parent() const { return m_parent; }
_base* get_parent() const
{
return m_parent;
}
// Get type
type get_type() const { return m_type; }
type get_type() const
{
return m_type;
}
// Get name
const std::string& get_name() const { return m_name; }
const std::string& get_name() const
{
return m_name;
}
// Get dynamic property for reloading configs during games
bool get_is_dynamic() const { return m_dynamic; }
bool get_is_dynamic() const
{
return m_dynamic;
}
// Reset defaults
virtual void from_default() = 0;
@ -168,9 +183,7 @@ namespace cfg
bool def;
_bool(node* owner, std::string name, bool def = false, bool dynamic = false)
: _base(type::_bool, owner, std::move(name), dynamic)
, m_value(def)
, def(def)
: _base(type::_bool, owner, std::move(name), dynamic), m_value(def), def(def)
{
}
@ -193,8 +206,7 @@ namespace cfg
nlohmann::ordered_json to_json() const override
{
return
{
return {
{"type", "bool"},
{"value", m_value.load()},
{"default", def},
@ -253,9 +265,7 @@ namespace cfg
const T def;
_enum(node* owner, const std::string& name, T value = {}, bool dynamic = false)
: _base(type::_enum, owner, name, dynamic)
, m_value(value)
, def(value)
: _base(type::_enum, owner, name, dynamic), m_value(value), def(value)
{
}
@ -293,8 +303,7 @@ namespace cfg
nlohmann::ordered_json to_json() const override
{
return
{
return {
{"type", "enum"},
{"value", to_string()},
{"default", def_to_string()},
@ -362,11 +371,7 @@ namespace cfg
_int(node* owner, const std::string& name, int_type def = std::min<int_type>(Max, std::max<int_type>(Min, 0)), bool dynamic = false,
std::function<s64()> min_fn = nullptr,
std::function<s64()> max_fn = nullptr)
: _base(type::_int, owner, name, dynamic)
, m_value(def)
, m_min_fn(std::move(min_fn))
, m_max_fn(std::move(max_fn))
, def(def)
: _base(type::_int, owner, name, dynamic), m_value(def), m_min_fn(std::move(min_fn)), m_max_fn(std::move(max_fn)), def(def)
{
}
@ -412,8 +417,7 @@ namespace cfg
nlohmann::ordered_json to_json() const override
{
return
{
return {
{"type", "int"},
{"value", to_string()},
{"default", def_to_string()},
@ -485,9 +489,7 @@ namespace cfg
static constexpr float_type min = Min;
_float(node* owner, const std::string& name, float_type def = std::min<float_type>(Max, std::max<float_type>(Min, 0)), bool dynamic = false)
: _base(type::_int, owner, name, dynamic)
, m_value(def)
, def(def)
: _base(type::_int, owner, name, dynamic), m_value(def), def(def)
{
}
@ -519,8 +521,7 @@ namespace cfg
nlohmann::ordered_json to_json() const override
{
return
{
return {
{"type", "float"},
{"value", to_string()},
{"default", def_to_string()},
@ -606,9 +607,7 @@ namespace cfg
static constexpr u64 min = Min;
uint(node* owner, const std::string& name, int_type def = std::max<int_type>(Min, 0), bool dynamic = false)
: _base(type::uint, owner, name, dynamic)
, m_value(def)
, def(def)
: _base(type::uint, owner, name, dynamic), m_value(def), def(def)
{
}
@ -634,8 +633,7 @@ namespace cfg
nlohmann::ordered_json to_json() const override
{
return
{
return {
{"type", "uint"},
{"value", to_string()},
{"default", def_to_string()},
@ -705,9 +703,7 @@ namespace cfg
std::string def;
string(node* owner, std::string name, std::string def = {}, bool dynamic = false)
: _base(type::string, owner, std::move(name), dynamic)
, m_value(def)
, def(std::move(def))
: _base(type::string, owner, std::move(name), dynamic), m_value(def), def(std::move(def))
{
}
@ -725,8 +721,7 @@ namespace cfg
nlohmann::ordered_json to_json() const override
{
return
{
return {
{"type", "string"},
{"value", to_string()},
{"default", def_to_string()},
@ -787,8 +782,7 @@ namespace cfg
nlohmann::ordered_json to_json() const override
{
return
{
return {
{"type", "set"},
{"value", to_list()},
};
@ -847,14 +841,12 @@ namespace cfg
nlohmann::ordered_json to_json() const override
{
return
{
return {
{"type", "map"},
{"value", m_map},
};
}
bool from_json(const nlohmann::json& json, bool) override
{
if (!json.is_object())
@ -915,8 +907,7 @@ namespace cfg
values[key] = level_string;
}
return
{
return {
{"type", "log_map"},
{"values", values},
{"levels", levels},
@ -1031,8 +1022,7 @@ namespace cfg
public:
device_entry(node* owner, const std::string& name, map_of_type<device_info> def = {})
: _base(type::device, owner, name, true)
, m_map(std::move(def))
: _base(type::device, owner, name, true), m_map(std::move(def))
{
m_default = m_map;
}
@ -1061,4 +1051,4 @@ namespace cfg
void from_default() override;
};
}
} // namespace cfg

View file

@ -25,7 +25,7 @@ std::string g_android_cache_dir;
#include "Utilities/StrUtil.h"
#include <cwchar>
#include <Windows.h>
#include <windows.h>
static std::unique_ptr<wchar_t[]> to_wchar(std::string_view source)
{
@ -402,8 +402,7 @@ namespace fs
public:
windows_file(HANDLE handle)
: m_handle(handle)
, m_pos(0)
: m_handle(handle), m_pos(0)
{
}
@ -577,7 +576,8 @@ namespace fs
const s64 new_pos =
whence == fs::seek_set ? offset :
whence == fs::seek_cur ? offset + m_pos :
whence == fs::seek_end ? offset + size() : -1;
whence == fs::seek_end ? offset + size() :
-1;
if (new_pos < 0)
{
@ -766,7 +766,8 @@ namespace fs
const int mode =
whence == seek_set ? SEEK_SET :
whence == seek_cur ? SEEK_CUR : SEEK_END;
whence == seek_cur ? SEEK_CUR :
SEEK_END;
const auto result = ::lseek(m_fd, offset, mode);
@ -833,7 +834,7 @@ namespace fs
}
};
#endif
}
} // namespace fs
shared_ptr<fs::device_base> fs::device_manager::get_device(const std::string& path, std::string_view* device_path)
{
@ -1019,7 +1020,10 @@ bool fs::get_stat(const std::string& path, stat_t& info)
struct close_t
{
HANDLE handle;
~close_t() { FindClose(handle); }
~close_t()
{
FindClose(handle);
}
};
for (close_t find_manage{handle}; attrs.cFileName != wpath_view.substr(wpath_view.find_last_of(wdelim) + 1);)
@ -1653,15 +1657,18 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
#ifdef _WIN32
DWORD access = 0;
if (mode & fs::read) access |= GENERIC_READ;
if (mode & fs::write) access |= DELETE | (mode & fs::append ? FILE_APPEND_DATA : GENERIC_WRITE);
if (mode & fs::read)
access |= GENERIC_READ;
if (mode & fs::write)
access |= DELETE | (mode & fs::append ? FILE_APPEND_DATA : GENERIC_WRITE);
DWORD disp = 0;
if (mode & fs::create)
{
disp =
mode & fs::excl ? CREATE_NEW :
mode & fs::trunc ? CREATE_ALWAYS : OPEN_ALWAYS;
mode & fs::trunc ? CREATE_ALWAYS :
OPEN_ALWAYS;
}
else
{
@ -1697,14 +1704,21 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
#else
int flags = O_CLOEXEC; // Ensures all files are closed on execl for auto updater
if (mode & fs::read && mode & fs::write) flags |= O_RDWR;
else if (mode & fs::read) flags |= O_RDONLY;
else if (mode & fs::write) flags |= O_WRONLY;
if (mode & fs::read && mode & fs::write)
flags |= O_RDWR;
else if (mode & fs::read)
flags |= O_RDONLY;
else if (mode & fs::write)
flags |= O_WRONLY;
if (mode & fs::append) flags |= O_APPEND;
if (mode & fs::create) flags |= O_CREAT;
if (mode & fs::trunc && !(mode & fs::lock)) flags |= O_TRUNC;
if (mode & fs::excl) flags |= O_EXCL;
if (mode & fs::append)
flags |= O_APPEND;
if (mode & fs::create)
flags |= O_CREAT;
if (mode & fs::trunc && !(mode & fs::lock))
flags |= O_TRUNC;
if (mode & fs::excl)
flags |= O_EXCL;
int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
@ -1753,8 +1767,6 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
#endif
}
fs::file fs::file::from_native_handle(native_handle handle)
{
fs::file result;
@ -1779,8 +1791,7 @@ fs::file::file(const void* ptr, usz size)
public:
memory_stream(const void* ptr, u64 size)
: m_ptr(static_cast<const char*>(ptr))
, m_size(size)
: m_ptr(static_cast<const char*>(ptr)), m_size(size)
{
}
@ -1834,7 +1845,8 @@ fs::file::file(const void* ptr, usz size)
const s64 new_pos =
whence == fs::seek_set ? offset :
whence == fs::seek_cur ? offset + m_pos :
whence == fs::seek_end ? offset + size() : -1;
whence == fs::seek_end ? offset + size() :
-1;
if (new_pos < 0)
{
@ -2518,7 +2530,8 @@ fs::file fs::make_gather(std::vector<fs::file> files)
const s64 new_pos =
whence == fs::seek_set ? offset :
whence == fs::seek_cur ? offset + pos :
whence == fs::seek_end ? offset + end : -1;
whence == fs::seek_end ? offset + end :
-1;
if (new_pos < 0)
{
@ -2581,8 +2594,7 @@ bool fs::pending_file::open(std::string_view path)
}
m_path.clear();
}
while (fs::g_tls_error == fs::error::exist); // Only retry if failed due to existing file
} while (fs::g_tls_error == fs::error::exist); // Only retry if failed due to existing file
return file.operator bool();
}
@ -2626,8 +2638,7 @@ bool fs::pending_file::commit(bool overwrite)
const auto ws1 = to_wchar(m_path);
const HANDLE file_handle = !overwrite ? INVALID_HANDLE_VALUE
: CreateFileW(ws1.get(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
const HANDLE file_handle = !overwrite ? INVALID_HANDLE_VALUE : CreateFileW(ws1.get(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
while (file_handle != INVALID_HANDLE_VALUE)
{
@ -2734,8 +2745,7 @@ bool fs::pending_file::commit(bool overwrite)
break;
}
}
while (fs::g_tls_error == fs::error::exist); // Only retry if failed due to existing file
} while (fs::g_tls_error == fs::error::exist); // Only retry if failed due to existing file
if (write_temp_path)
{

View file

@ -182,7 +182,9 @@ namespace fs
[[noreturn]] void xfail(std::source_location);
[[noreturn]] void xovfl();
constexpr struct pod_tag_t{} pod_tag;
constexpr struct pod_tag_t
{
} pod_tag;
// Get virtual device for specified path (nullptr for real path)
shared_ptr<device_base> get_virtual_device(const std::string& path, std::string_view* device_path);
@ -305,21 +307,24 @@ namespace fs
// Change file size (possibly appending zero bytes)
bool trunc(u64 length, std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
return m_file->trunc(length);
}
// Get file information
stat_t get_stat(std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
return m_file->get_stat();
}
// Sync file buffers
void sync(std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
return m_file->sync();
}
@ -329,80 +334,95 @@ namespace fs
// Read the data from the file and return the amount of data written in buffer
u64 read(void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
return m_file->read(buffer, count);
}
// Read the data from the file at specified offset in thread-safe manner
u64 read_at(u64 offset, void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
return m_file->read_at(offset, buffer, count);
}
// Write the data to the file and return the amount of data actually written
u64 write(const void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
return m_file->write(buffer, count);
}
u64 write_at(u64 offset, const void* buffer, u64 count, std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
return m_file->write_at(offset, buffer, count);
}
// Change current position, returns resulting position
u64 seek(s64 offset, seek_mode whence = seek_set, std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
return m_file->seek(offset, whence);
}
// Get file size
u64 size(std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
return m_file->size();
}
// Get current position
u64 pos(std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
return m_file->seek(0, seek_cur);
}
// Write std::basic_string unconditionally
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
template <typename T>
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
const file& write(const std::basic_string<T>& str, std::source_location src_loc = std::source_location::current()) const
{
if (write(str.data(), str.size() * sizeof(T), src_loc) != str.size() * sizeof(T)) xfail(src_loc);
if (write(str.data(), str.size() * sizeof(T), src_loc) != str.size() * sizeof(T))
xfail(src_loc);
return *this;
}
// Write POD unconditionally
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
template <typename T>
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
const file& write(const T& data, std::source_location src_loc = std::source_location::current()) const
{
if (write(std::addressof(data), sizeof(T), src_loc) != sizeof(T)) xfail(src_loc);
if (write(std::addressof(data), sizeof(T), src_loc) != sizeof(T))
xfail(src_loc);
return *this;
}
// Write POD std::vector unconditionally
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
template <typename T>
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
const file& write(const std::vector<T>& vec, std::source_location src_loc = std::source_location::current()) const
{
if (write(vec.data(), vec.size() * sizeof(T), src_loc) != vec.size() * sizeof(T)) xfail(src_loc);
if (write(vec.data(), vec.size() * sizeof(T), src_loc) != vec.size() * sizeof(T))
xfail(src_loc);
return *this;
}
// Read std::basic_string
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
template <typename T>
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
bool read(std::basic_string<T>& str, usz _size = umax, std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
if (_size != umax)
{
@ -419,7 +439,8 @@ namespace fs
}
// Read POD, sizeof(T) is used
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
template <typename T>
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
bool read(T& data,
pod_tag_t = pod_tag, std::source_location src_loc = std::source_location::current()) const
{
@ -427,10 +448,12 @@ namespace fs
}
// Read POD std::vector
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
template <typename T>
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
bool read(std::vector<T>& vec, usz _size = umax, bool use_offs = false, usz offset = umax, std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
if (_size != umax)
{
@ -452,11 +475,13 @@ namespace fs
}
// Read POD (experimental)
template <typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
template <typename T>
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
T read(pod_tag_t = pod_tag, std::source_location src_loc = std::source_location::current()) const
{
T result;
if (!read(result, pod_tag, src_loc)) xfail(src_loc);
if (!read(result, pod_tag, src_loc))
xfail(src_loc);
return result;
}
@ -467,17 +492,20 @@ namespace fs
std::basic_string<T> result;
result.resize(size() / sizeof(T));
seek(0);
if (!read(result, result.size(), src_loc)) xfail(src_loc);
if (!read(result, result.size(), src_loc))
xfail(src_loc);
return result;
}
// Read full file to std::vector
template<typename T> requires (std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
template <typename T>
requires(std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>)
std::vector<T> to_vector(std::source_location src_loc = std::source_location::current()) const
{
std::vector<T> result;
result.resize(size() / sizeof(T));
if (!read(result, result.size(), true, 0, src_loc)) xfail(src_loc);
if (!read(result, result.size(), true, 0, src_loc))
xfail(src_loc);
return result;
}
@ -490,7 +518,8 @@ namespace fs
// Gathered write
u64 write_gather(const iovec_clone* buffers, u64 buf_count, std::source_location src_loc = std::source_location::current()) const
{
if (!m_file) xnull(src_loc);
if (!m_file)
xnull(src_loc);
return m_file->write_gather(buffers, buf_count);
}
};
@ -536,14 +565,16 @@ namespace fs
// Get next directory entry
bool read(dir_entry& out, std::source_location src_loc = std::source_location::current()) const
{
if (!m_dir) xnull(src_loc);
if (!m_dir)
xnull(src_loc);
return m_dir->read(out);
}
// Reset to the beginning
void rewind(std::source_location src_loc = std::source_location::current()) const
{
if (!m_dir) xnull(src_loc);
if (!m_dir)
xnull(src_loc);
return m_dir->rewind();
}
@ -641,7 +672,10 @@ namespace fs
return false;
}
void rewind() override { m_offset = 0; }
void rewind() override
{
m_offset = 0;
}
};
// Get executable path
@ -730,9 +764,7 @@ namespace fs
u64 pos;
container_stream(T&& obj, const stat_t& init_stat = {})
: obj(std::forward<T>(obj))
, pos(0)
, m_stat(init_stat)
: obj(std::forward<T>(obj)), pos(0), m_stat(init_stat)
{
}
@ -812,7 +844,8 @@ namespace fs
obj.insert(obj.end(), src + overlap, src + size);
pos += size;
if (size) update_time(true);
if (size)
update_time(true);
return size;
}
@ -821,7 +854,8 @@ namespace fs
const s64 new_pos =
whence == fs::seek_set ? offset :
whence == fs::seek_cur ? offset + pos :
whence == fs::seek_end ? offset + size() : -1;
whence == fs::seek_end ? offset + size() :
-1;
if (new_pos < 0)
{
@ -899,4 +933,4 @@ namespace fs
file make_gather(std::vector<file>);
stx::generator<dir_entry&> list_dir_recursively(const std::string& path);
}
} // namespace fs

View file

@ -432,7 +432,7 @@ namespace asmjit
c.bind(next);
}
#endif
}
} // namespace asmjit
// Build runtime function with asmjit::X86Assembler
template <typename FT, typename Asm = native_asm, typename F>
@ -501,7 +501,7 @@ namespace llvm
class ExecutionEngine;
class Module;
class StringRef;
}
} // namespace llvm
enum class thread_state : u32;

View file

@ -389,8 +389,7 @@ jit_runtime_base& asmjit::get_global_runtime()
}
asmjit::inline_runtime::inline_runtime(uchar* data, usz size)
: m_data(data)
, m_size(size)
: m_data(data), m_size(size)
{
}

View file

@ -402,8 +402,7 @@ class ObjectCache final : public llvm::ObjectCache
public:
ObjectCache(const std::string& path, jit_compiler* compiler = nullptr)
: m_path(path)
, m_compiler(compiler)
: m_path(path), m_compiler(compiler)
{
}
@ -636,12 +635,12 @@ bool jit_compiler::add_sub_disk_space(ssz space)
}
return false;
}).second;
})
.second;
}
jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, const std::string& _cpu, u32 flags, std::function<u64(const std::string&)> symbols_cement) noexcept
: m_context(new llvm::LLVMContext)
, m_cpu(cpu(_cpu))
: m_context(new llvm::LLVMContext), m_cpu(cpu(_cpu))
{
[[maybe_unused]] static const bool s_install_llvm_error_handler = []()
{
@ -650,7 +649,8 @@ jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, co
{
const std::string_view out = msg ? msg : "";
fmt::throw_exception("LLVM Emergency Exit Invoked: '%s'", out);
}, nullptr);
},
nullptr);
return true;
}();

View file

@ -42,13 +42,22 @@ static bool IsSchemeValid( const std::string& SchemeName )
bool LUrlParser::clParseURL::GetPort(int* OutPort) const
{
if ( !IsValid() ) { return false; }
if (!IsValid())
{
return false;
}
const int Port = atoi(m_Port.c_str());
if ( Port <= 0 || Port > 65535 ) { return false; }
if (Port <= 0 || Port > 65535)
{
return false;
}
if ( OutPort ) { *OutPort = Port; }
if (OutPort)
{
*OutPort = Port;
}
return true;
}
@ -96,8 +105,10 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
*/
// skip "//"
if ( *CurrentString++ != '/' ) return clParseURL( LUrlParserError_NoDoubleSlash );
if ( *CurrentString++ != '/' ) return clParseURL( LUrlParserError_NoDoubleSlash );
if (*CurrentString++ != '/')
return clParseURL(LUrlParserError_NoDoubleSlash);
if (*CurrentString++ != '/')
return clParseURL(LUrlParserError_NoDoubleSlash);
// check if the user name and password are specified
bool bHasUserName = false;
@ -128,7 +139,8 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
if (bHasUserName)
{
// read user name
while ( *LocalString && *LocalString != ':' && *LocalString != '@' ) LocalString++;
while (*LocalString && *LocalString != ':' && *LocalString != '@')
LocalString++;
Result.m_UserName = std::string(CurrentString, LocalString - CurrentString);
@ -143,7 +155,8 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
// read password
LocalString = CurrentString;
while ( *LocalString && *LocalString != '@' ) LocalString++;
while (*LocalString && *LocalString != '@')
LocalString++;
Result.m_Password = std::string(CurrentString, LocalString - CurrentString);
@ -193,7 +206,8 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
// read port number
LocalString = CurrentString;
while ( *LocalString && *LocalString != '/' ) LocalString++;
while (*LocalString && *LocalString != '/')
LocalString++;
Result.m_Port = std::string(CurrentString, LocalString - CurrentString);
@ -219,7 +233,8 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
// parse the path
LocalString = CurrentString;
while ( *LocalString && *LocalString != '#' && *LocalString != '?' ) LocalString++;
while (*LocalString && *LocalString != '#' && *LocalString != '?')
LocalString++;
Result.m_Path = std::string(CurrentString, LocalString - CurrentString);
@ -234,7 +249,8 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
// read query
LocalString = CurrentString;
while ( *LocalString && *LocalString != '#' ) LocalString++;
while (*LocalString && *LocalString != '#')
LocalString++;
Result.m_Query = std::string(CurrentString, LocalString - CurrentString);
@ -250,7 +266,8 @@ LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL
// read fragment
LocalString = CurrentString;
while ( *LocalString ) LocalString++;
while (*LocalString)
LocalString++;
Result.m_Fragment = std::string(CurrentString, LocalString - CurrentString);

View file

@ -58,10 +58,14 @@ namespace LUrlParser
clParseURL()
: m_ErrorCode(LUrlParserError_Uninitialized)
{}
{
}
/// return 'true' if the parsing was successful
bool IsValid() const { return m_ErrorCode == LUrlParserError_Ok; }
bool IsValid() const
{
return m_ErrorCode == LUrlParserError_Ok;
}
/// helper to convert the port number to int, return 'true' if the port is valid (within the 0..65535 range)
bool GetPort(int* OutPort) const;
@ -72,7 +76,8 @@ namespace LUrlParser
private:
explicit clParseURL(LUrlParserError ErrorCode)
: m_ErrorCode(ErrorCode)
{}
{
}
};
} // namespace LUrlParser

View file

@ -8,10 +8,11 @@
#include <codecvt>
#include <algorithm>
#include <string_view>
#include <string>
#include "Thread.h"
#ifdef _WIN32
#include <Windows.h>
#include <windows.h>
#else
#include <errno.h>
#endif
@ -568,8 +569,7 @@ void fmt_class_string<std::source_location>::format(std::string& out, u64 arg)
if (std::string_view full_func{loc.function_name() ? loc.function_name() : ""}; !full_func.empty())
{
// Remove useless disambiguators
std::string func = fmt::replace_all(std::string(full_func), {
{"struct ", ""},
std::string func = fmt::replace_all(std::string(full_func), {{"struct ", ""},
{"class ", ""},
{"enum ", ""},
{"typename ", ""},
@ -670,7 +670,7 @@ namespace fmt
}
struct cfmt_src;
}
} // namespace fmt
// Temporary implementation
struct fmt::cfmt_src
@ -714,13 +714,15 @@ struct fmt::cfmt_src
{
// Hack: use known function pointers to determine type
#define TYPE(type) \
if (sup[extra].fmt_string == &fmt_class_string<type>::format) return sizeof(type);
if (sup[extra].fmt_string == &fmt_class_string<type>::format) \
return sizeof(type);
TYPE(int);
TYPE(llong);
TYPE(schar);
TYPE(short);
if constexpr (std::is_signed_v<char>) TYPE(char);
if constexpr (std::is_signed_v<char>)
TYPE(char);
TYPE(long);
TYPE(s128);
@ -806,7 +808,7 @@ std::vector<std::string> fmt::split(std::string_view source, std::initializer_li
continue;
}
result.emplace_back(std::string(piece));
result.emplace_back(piece);
}
if (result.empty() && !is_skip_empty)

View file

@ -20,7 +20,7 @@ namespace fmt
std::string win_error_to_string(unsigned long error, void* module_handle = nullptr);
std::string win_error_to_string(const win_error& error);
#endif
}
} // namespace fmt
template <typename T>
struct fmt_unveil
@ -250,11 +250,10 @@ struct fmt_class_string<wchar_t*> : fmt_class_string<const wchar_t*>
namespace fmt
{
template <typename T>
concept StringConvertible = requires (T & t)
{
concept StringConvertible = requires(T& t) {
{ t.to_string() } -> std::convertible_to<std::string>;
};
}
} // namespace fmt
template <fmt::StringConvertible T>
struct fmt_class_string<T>
@ -275,7 +274,7 @@ namespace fmt
// Both uchar and std::byte are allowed
template <typename T>
concept ByteArray = requires(T& t) { const_cast<std::conditional_t<std::is_same_v<decltype(std::as_const(t[0])), const std::byte&>, std::byte, uchar>&>(std::data(t)[0]); };
}
} // namespace fmt
template <fmt::ByteArray T>
struct fmt_class_string<T>
@ -301,8 +300,7 @@ struct fmt_type_info
template <typename T>
static constexpr fmt_type_info make()
{
return fmt_type_info
{
return fmt_type_info{
&fmt_class_string<T>::format,
};
}
@ -327,14 +325,12 @@ namespace fmt
template <typename T>
base57(const T& arg) noexcept
: data(reinterpret_cast<const uchar*>(std::addressof(arg)))
, size(sizeof(T))
: data(reinterpret_cast<const uchar*>(std::addressof(arg))), size(sizeof(T))
{
}
base57(const uchar* data, usz size) noexcept
: data(data)
, size(size)
: data(data), size(size)
{
}
};
@ -348,8 +344,7 @@ namespace fmt
base57_result& operator=(base57_result&&) = default;
explicit base57_result(usz size) noexcept
: base57(size ? new uchar[size] : nullptr, size)
, memory(const_cast<uchar*>(this->data))
: base57(size ? new uchar[size] : nullptr, size), memory(const_cast<uchar*>(this->data))
{
}
@ -385,7 +380,9 @@ namespace fmt
template <typename CharT, usz N, typename... Args>
struct throw_exception
{
struct args_break_t {};
struct args_break_t
{
};
[[noreturn]] FORCE_INLINE SAFE_BUFFERS() throw_exception(const CharT (&fmt)[N], const Args&... args,
args_break_t = args_break_t{}, std::source_location src_loc = std::source_location::current())
@ -412,8 +409,7 @@ namespace fmt
// Store only references, unveil op is postponed
tie(Arg&& arg, Args&&... args) noexcept
: arg(std::forward<Arg>(arg))
, next(std::forward<Args>(args)...)
: arg(std::forward<Arg>(arg)), next(std::forward<Args>(args)...)
{
}
@ -458,4 +454,4 @@ namespace fmt
raw_throw_exception(src_loc, reinterpret_cast<const char*>(fmt), type_info_v<std::remove_cvref_t<Args>...>, +data);
}
}
} // namespace fmt

View file

@ -96,8 +96,7 @@ namespace fmt
return src;
}
static inline
std::string replace_all(std::string src, const std::vector<std::pair<std::string, std::string>>& list)
static inline std::string replace_all(std::string src, const std::vector<std::pair<std::string, std::string>>& list)
{
for (usz pos = 0; pos < src.length(); ++pos)
{
@ -211,4 +210,4 @@ namespace fmt
return hash_type{}(str);
}
};
}
} // namespace fmt

View file

@ -16,7 +16,7 @@
#endif
#ifdef _WIN32
#include <Windows.h>
#include <windows.h>
#include <Psapi.h>
#include <process.h>
#include <sysinfoapi.h>
@ -109,7 +109,9 @@ extern thread_local std::string(*g_tls_log_prefix)();
// Report error and call std::abort(), defined in main.cpp
[[noreturn]] void report_fatal_error(std::string_view text, bool is_html = false, bool include_help_text = true);
enum cpu_threads_emulation_info_dump_t : u32 {};
enum cpu_threads_emulation_info_dump_t : u32
{
};
template <>
void fmt_class_string<thread_class>::format(std::string& out, u64 arg)
@ -773,7 +775,8 @@ void decode_x64_reg_op(const u8* code, x64_op_t& out_op, x64_reg_t& out_reg, usz
s_tls_reg3 = x64_reg_t{vreg};
if (vopm == 0x1) switch (vop1) // Implied leading byte 0x0F
if (vopm == 0x1)
switch (vop1) // Implied leading byte 0x0F
{
case 0x11:
case 0x29:
@ -802,7 +805,8 @@ void decode_x64_reg_op(const u8* code, x64_op_t& out_op, x64_reg_t& out_reg, usz
}
}
if (vopm == 0x2) switch (vop1) // Implied leading bytes 0x0F 0x38
if (vopm == 0x2)
switch (vop1) // Implied leading bytes 0x0F 0x38
{
case 0xf7:
{
@ -1005,8 +1009,7 @@ long* openbsd_x64reg(x64_context *context, int reg)
static const decltype(_REG_RAX) reg_table[] =
{
_REG_RAX, _REG_RCX, _REG_RDX, _REG_RBX, _REG_RSP, _REG_RBP, _REG_RSI, _REG_RDI,
_REG_R8, _REG_R9, _REG_R10, _REG_R11, _REG_R12, _REG_R13, _REG_R14, _REG_R15, _REG_RIP
};
_REG_R8, _REG_R9, _REG_R10, _REG_R11, _REG_R12, _REG_R13, _REG_R14, _REG_R15, _REG_RIP};
#define X64REG(context, reg) (&(context)->uc_mcontext.__gregs[reg_table[reg]])
#define XMM_sig(context, reg) (reinterpret_cast<v128*>(((struct fxsave64*)(context)->uc_mcontext.__fpregs)->fx_xmm[reg]))
@ -1017,8 +1020,7 @@ static const decltype(_REG_RAX) reg_table[] =
static const int reg_table[] =
{
REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI,
REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP
};
REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP};
#define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]])
#ifdef __sun
@ -1374,7 +1376,8 @@ bool handle_access_violation(u32 addr, bool is_writing, ucontext_t* context) noe
}
// check if address is RawSPU MMIO register
do if (addr - RAW_SPU_BASE_ADDR < (6 * RAW_SPU_OFFSET) && (addr % RAW_SPU_OFFSET) >= RAW_SPU_PROB_OFFSET)
do
if (addr - RAW_SPU_BASE_ADDR < (6 * RAW_SPU_OFFSET) && (addr % RAW_SPU_OFFSET) >= RAW_SPU_PROB_OFFSET)
{
auto thread = idm::get_unlocked<named_thread<spu_thread>>(spu_thread::find_raw_spu((addr - RAW_SPU_BASE_ADDR) / RAW_SPU_OFFSET));
@ -1505,7 +1508,8 @@ bool handle_access_violation(u32 addr, bool is_writing, ucontext_t* context) noe
RIP(context) += i_size;
g_tls_fault_spu++;
return true;
} while (0);
}
while (0);
#else
static_cast<void>(context);
#endif /* ARCH_ */
@ -1602,7 +1606,6 @@ bool handle_access_violation(u32 addr, bool is_writing, ucontext_t* context) noe
}
}
// Now, place the page fault event onto table so that other functions [sys_mmapper_free_address and pagefault recovery funcs etc]
// know that this thread is page faulted and where.
@ -1866,7 +1869,8 @@ static LONG exception_filter(PEXCEPTION_POINTERS pExp) noexcept
{
const auto cause =
pExp->ExceptionRecord->ExceptionInformation[0] == 8 ? "executing" :
pExp->ExceptionRecord->ExceptionInformation[0] == 1 ? "writing" : "reading";
pExp->ExceptionRecord->ExceptionInformation[0] == 1 ? "writing" :
"reading";
fmt::append(msg, "Segfault %s location %p at %p.\n", cause, pExp->ExceptionRecord->ExceptionInformation[1], pExp->ExceptionRecord->ExceptionAddress);
@ -2034,7 +2038,8 @@ static void signal_handler(int /*sig*/, siginfo_t* info, void* uct) noexcept
#endif
const u64 exec64 = (reinterpret_cast<u64>(info->si_addr) - reinterpret_cast<u64>(vm::g_exec_addr)) / 2;
const auto cause = is_executing ? "executing" : is_writing ? "writing" : "reading";
const auto cause = is_executing ? "executing" : is_writing ? "writing" :
"reading";
if (auto [addr, ok] = vm::try_get_addr(info->si_addr); ok && !is_executing)
{
@ -2241,7 +2246,8 @@ void thread_base::set_name(std::string name)
};
// Set thread name for VS debugger
if (IsDebuggerPresent()) [&]() NEVER_INLINE
if (IsDebuggerPresent())
[&]() NEVER_INLINE
{
THREADNAME_INFO info;
info.dwType = 0x1000;
@ -2361,7 +2367,10 @@ thread_base::native_entry thread_base::finalize(u64 _self) noexcept
g_tls_wait_fail = 0;
g_tls_access_violation_recovered = false;
g_tls_log_prefix = []() -> std::string { return {}; };
g_tls_log_prefix = []() -> std::string
{
return {};
};
if (_self == umax)
{
@ -2516,7 +2525,6 @@ void thread_ctrl::wait_for(u64 usec, [[maybe_unused]] bool alert /* true */)
list.wait(atomic_wait_timeout{usec <= 0xffff'ffff'ffff'ffff / 1000 ? usec * 1000 : 0xffff'ffff'ffff'ffff});
}
void thread_ctrl::wait_until(u64* wait_time, u64 add_time, u64 min_wait, bool update_to_current_time)
{
*wait_time = utils::add_saturate<u64>(*wait_time, add_time);
@ -2621,8 +2629,7 @@ std::string thread_ctrl::get_name_cached()
}
thread_base::thread_base(native_entry entry, std::string name) noexcept
: entry_point(entry)
, m_tname(make_single_value(std::move(name)))
: entry_point(entry), m_tname(make_single_value(std::move(name)))
{
}
@ -2851,7 +2858,8 @@ void thread_base::exec()
}
return false;
}).second)
})
.second)
{
utils::trap();
}
@ -2953,8 +2961,7 @@ u64 thread_ctrl::get_affinity_mask(thread_class group)
g_cfg.core.affinity.cpu4.get(),
g_cfg.core.affinity.cpu5.get(),
g_cfg.core.affinity.cpu6.get(),
g_cfg.core.affinity.cpu7.get()
};
g_cfg.core.affinity.cpu7.get()};
for (std::size_t i = 0; i < std::min<std::size_t>(std::thread::hardware_concurrency(), std::size(affinities)); ++i)
{

View file

@ -46,7 +46,8 @@ struct result_storage
using type = void;
};
template <typename Ctx, typename... Args> requires (!std::is_void_v<std::invoke_result_t<Ctx, Args&&...>>)
template <typename Ctx, typename... Args>
requires(!std::is_void_v<std::invoke_result_t<Ctx, Args && ...>>)
struct result_storage<Ctx, Args...>
{
using T = std::invoke_result_t<Ctx, Args&&...>;
@ -81,8 +82,7 @@ struct result_storage<Ctx, Args...>
};
template <typename T>
concept NamedThreadName = requires (const T&)
{
concept NamedThreadName = requires(const T&) {
std::string(T::thread_name);
};
@ -306,13 +306,20 @@ public:
template <typename T, typename U>
static inline void wait_on(T& wait, U old, u64 usec = -1)
{
wait_on_custom<1>([&](atomic_wait::list<3>& list) { list.template set<0>(wait, old); }, usec);
wait_on_custom<1>([&](atomic_wait::list<3>& list)
{
list.template set<0>(wait, old);
},
usec);
}
template <typename T>
static inline void wait_on(T& wait)
{
wait_on_custom<1>([&](atomic_wait::list<3>& list) { list.template set<0>(wait); });
wait_on_custom<1>([&](atomic_wait::list<3>& list)
{
list.template set<0>(wait);
});
}
// Exit.
@ -386,8 +393,7 @@ class thread_future_t : public thread_future, result_storage<Ctx, std::condition
public:
thread_future_t(Ctx&& func, Args&&... args) noexcept
: m_args(std::forward<Args>(args)...)
, m_func(std::forward<Ctx>(func))
: m_args(std::forward<Args>(args)...), m_func(std::forward<Ctx>(func))
{
thread_future::exec.raw() = +[](thread_base* tb, thread_future* tf)
{
@ -527,37 +533,37 @@ class named_thread final : public Context, result_storage<Context>, thread_base
public:
// Forwarding constructor with default name (also potentially the default constructor)
template <typename... Args> requires (std::is_constructible_v<Context, Args&&...>) && (!(std::is_same_v<std::remove_cvref_t<Args>, stx::launch_retainer> || ...)) && (NamedThreadName<Context>)
template <typename... Args>
requires(std::is_constructible_v<Context, Args && ...>) && (!(std::is_same_v<std::remove_cvref_t<Args>, stx::launch_retainer> || ...)) && (NamedThreadName<Context>)
named_thread(Args&&... args) noexcept
: Context(std::forward<Args>(args)...)
, thread(trampoline, std::string(Context::thread_name))
: Context(std::forward<Args>(args)...), thread(trampoline, std::string(Context::thread_name))
{
thread::start();
}
// Forwarding constructor with default name, does not automatically run the thread
template <typename... Args> requires (std::is_constructible_v<Context, Args&&...>) && (NamedThreadName<Context>)
template <typename... Args>
requires(std::is_constructible_v<Context, Args && ...>) && (NamedThreadName<Context>)
named_thread(const stx::launch_retainer&, Args&&... args) noexcept
: Context(std::forward<Args>(args)...)
, thread(trampoline, std::string(Context::thread_name))
: Context(std::forward<Args>(args)...), thread(trampoline, std::string(Context::thread_name))
{
// Create a stand-by thread context
m_sync |= static_cast<u32>(thread_state::finished);
}
// Normal forwarding constructor
template <typename... Args> requires (std::is_constructible_v<Context, Args&&...>) && (!NamedThreadName<Context>)
template <typename... Args>
requires(std::is_constructible_v<Context, Args && ...>) && (!NamedThreadName<Context>)
named_thread(std::string name, Args&&... args) noexcept
: Context(std::forward<Args>(args)...)
, thread(trampoline, std::move(name))
: Context(std::forward<Args>(args)...), thread(trampoline, std::move(name))
{
thread::start();
}
// Lambda constructor, also the implicit deduction guide candidate
named_thread(std::string_view name, Context&& f) noexcept requires (!NamedThreadName<Context>)
: Context(std::forward<Context>(f))
, thread(trampoline, std::string(name))
named_thread(std::string_view name, Context&& f) noexcept
requires(!NamedThreadName<Context>)
: Context(std::forward<Context>(f)), thread(trampoline, std::string(name))
{
thread::start();
}
@ -683,7 +689,11 @@ public:
// Try to abort by assigning thread_state::aborting/finished
// Join thread by thread_state::finished
if (s >= thread_state::aborting && thread::m_sync.fetch_op([](u32& v) { return !(v & 3) && (v |= 1); }).second)
if (s >= thread_state::aborting && thread::m_sync.fetch_op([](u32& v)
{
return !(v & 3) && (v |= 1);
})
.second)
{
notify_sync = true;
}
@ -747,8 +757,7 @@ class named_thread_group final
public:
// Lambda constructor, also the implicit deduction guide candidate
named_thread_group(std::string_view name, u32 count, Context&& f) noexcept
: m_count(count)
, m_threads(nullptr)
: m_count(count), m_threads(nullptr)
{
if (count == 0)
{
@ -771,8 +780,7 @@ public:
// Constructor with a function performed before adding more threads
template <typename CheckAndPrepare>
named_thread_group(std::string_view name, u32 count, Context&& f, CheckAndPrepare&& check) noexcept
: m_count(count)
, m_threads(nullptr)
: m_count(count), m_threads(nullptr)
{
if (count == 0)
{
@ -812,8 +820,7 @@ public:
// Default constructor
named_thread_group(std::string_view name, u32 count) noexcept
: m_count(count)
, m_threads(nullptr)
: m_count(count), m_threads(nullptr)
{
if (count == 0)
{

View file

@ -33,7 +33,6 @@ namespace utils
return (val & (get_page_size() - 1)) == 0;
}
/**
* Address Range utility class
*/
@ -174,8 +173,7 @@ namespace utils
{
return {
std::min(valid() ? start : umax, other.valid() ? other.start : umax),
std::max(valid() ? end : 0, other.valid() ? other.end : 0)
};
std::max(valid() ? end : 0, other.valid() ? other.end : 0)};
}
void set_min_max(const address_range& other)
@ -257,7 +255,6 @@ namespace utils
return address_range::start_end(page_start(addr), page_end(addr));
}
/**
* Address Range Vector utility class
*
@ -276,16 +273,46 @@ namespace utils
public:
// Wrapped functions
inline void reserve(usz nr) { data.reserve(nr); }
inline void clear() { data.clear(); }
inline size_type size() const { return data.size(); }
inline bool empty() const { return data.empty(); }
inline address_range& operator[](size_type n) { return data[n]; }
inline const address_range& operator[](size_type n) const { return data[n]; }
inline iterator begin() { return data.begin(); }
inline const_iterator begin() const { return data.begin(); }
inline iterator end() { return data.end(); }
inline const_iterator end() const { return data.end(); }
inline void reserve(usz nr)
{
data.reserve(nr);
}
inline void clear()
{
data.clear();
}
inline size_type size() const
{
return data.size();
}
inline bool empty() const
{
return data.empty();
}
inline address_range& operator[](size_type n)
{
return data[n];
}
inline const address_range& operator[](size_type n) const
{
return data[n];
}
inline iterator begin()
{
return data.begin();
}
inline const_iterator begin() const
{
return data.begin();
}
inline iterator end()
{
return data.end();
}
inline const_iterator end() const
{
return data.end();
}
// Search for ranges that touch new_range. If found, merge instead of adding new_range.
// When adding a new range, re-use invalid ranges whenever possible
@ -531,7 +558,6 @@ namespace utils
}
};
// These declarations must be done after address_range_vector has been defined
bool address_range::inside(const address_range_vector& vec) const
{
@ -545,7 +571,6 @@ namespace utils
} // namespace utils
namespace std
{
static_assert(sizeof(usz) >= 2 * sizeof(u32), "usz must be at least twice the size of u32");
@ -559,4 +584,4 @@ namespace std
return (usz{k.start} << 32) | usz{k.end};
}
};
}
} // namespace std

View file

@ -97,7 +97,10 @@ void patch_engine::patch_config_value::set_and_check_value(f64 new_value, std::s
case patch_configurable_type::double_enum:
case patch_configurable_type::long_enum:
{
if (std::none_of(allowed_values.begin(), allowed_values.end(), [&new_value](const patch_allowed_value& allowed_value){ return allowed_value.value == new_value; }))
if (std::none_of(allowed_values.begin(), allowed_values.end(), [&new_value](const patch_allowed_value& allowed_value)
{
return allowed_value.value == new_value;
}))
{
patch_log.error("Can't set configurable enumerated value '%s' to %f. Using default value %f", name, new_value, value);
return;
@ -329,7 +332,10 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st
is_valid = false;
continue;
}
else if (serial.size() != 9 || !std::all_of(serial.begin(), serial.end(), [](char c) { return std::isalnum(c); }))
else if (serial.size() != 9 || !std::all_of(serial.begin(), serial.end(), [](char c)
{
return std::isalnum(c);
}))
{
append_log_message(log_messages, fmt::format("Error: Serial '%s' invalid (patch: %s, key: %s, location: %s, file: %s)", serial, description, main_key, get_yaml_node_location(serial_node), path), &patch_log.error);
is_valid = false;
@ -558,7 +564,10 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st
new_allowed_value.label = allowed_value.first.Scalar();
new_allowed_value.value = get_and_check_config_value(allowed_value.second);
if (std::any_of(config_value.allowed_values.begin(), config_value.allowed_values.end(), [&new_allowed_value](const patch_allowed_value& other){ return new_allowed_value.value == other.value || new_allowed_value.label == other.label; }))
if (std::any_of(config_value.allowed_values.begin(), config_value.allowed_values.end(), [&new_allowed_value](const patch_allowed_value& other)
{
return new_allowed_value.value == other.value || new_allowed_value.label == other.label;
}))
{
append_log_message(log_messages, fmt::format("Error: Skipping configurable allowed value. Another entry with the same label or value already exists. (patch: %s, key: %s, location: %s, file: %s)", description, main_key, get_yaml_node_location(allowed_value), path), &patch_log.error);
is_valid = false;
@ -581,7 +590,10 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st
is_valid = false;
}
if (std::none_of(config_value.allowed_values.begin(), config_value.allowed_values.end(), [&config_value](const patch_allowed_value& other){ return other.value == config_value.value; }))
if (std::none_of(config_value.allowed_values.begin(), config_value.allowed_values.end(), [&config_value](const patch_allowed_value& other)
{
return other.value == config_value.value;
}))
{
append_log_message(log_messages, fmt::format("Error: Configurable value was not found in allowed values (key: %s, location: %s, file: %s)", main_key, get_yaml_node_location(config_value_allowed_values_node), path), &patch_log.error);
is_valid = false;
@ -954,7 +966,8 @@ static usz apply_modification(std::vector<u32>& applied, patch_engine::patch_inf
for (const patch_engine::patch_data& p : patch.data_list)
{
if (p.type != patch_type::alloc) continue;
if (p.type != patch_type::alloc)
continue;
// Do not allow null address or if resultant ptr is not a VM ptr
if (const u32 alloc_at = (p.offset & -4096); alloc_at >> 16)
@ -1572,8 +1585,7 @@ void patch_engine::apply(std::vector<u32>& applied_total, const std::string& nam
&patches_for_all_serials_and_all_versions,
&patches_for_all_serials_and_this_version,
&patches_for_this_serial_and_all_versions,
&patches_for_this_serial_and_this_version
};
&patches_for_this_serial_and_this_version};
// Filter by patch group (reverse so specific patches will be prioritized over globals)
for (auto it = std::rbegin(patch_super_list); it != std::rend(patch_super_list); it++)
@ -1790,11 +1802,16 @@ static void append_patches(patch_engine::patch_map& existing_patches, const patc
}
}
if (!new_info.patch_version.empty()) info.patch_version = new_info.patch_version;
if (!new_info.author.empty()) info.author = new_info.author;
if (!new_info.notes.empty()) info.notes = new_info.notes;
if (!new_info.data_list.empty()) info.data_list = new_info.data_list;
if (!new_info.source_path.empty()) info.source_path = new_info.source_path;
if (!new_info.patch_version.empty())
info.patch_version = new_info.patch_version;
if (!new_info.author.empty())
info.author = new_info.author;
if (!new_info.notes.empty())
info.notes = new_info.notes;
if (!new_info.data_list.empty())
info.data_list = new_info.data_list;
if (!new_info.source_path.empty())
info.source_path = new_info.source_path;
count++;
}
@ -1850,10 +1867,14 @@ bool patch_engine::save_patches(const patch_map& patches, const std::string& pat
out << YAML::EndMap;
if (!info.author.empty()) out << patch_key::author << info.author;
if (!info.patch_version.empty()) out << patch_key::patch_version << info.patch_version;
if (!info.patch_group.empty()) out << patch_key::group << info.patch_group;
if (!info.notes.empty()) out << patch_key::notes << info.notes;
if (!info.author.empty())
out << patch_key::author << info.author;
if (!info.patch_version.empty())
out << patch_key::patch_version << info.patch_version;
if (!info.patch_group.empty())
out << patch_key::group << info.patch_group;
if (!info.notes.empty())
out << patch_key::notes << info.notes;
if (!info.default_config_values.empty())
{

View file

@ -26,7 +26,7 @@ namespace patch_key
static const std::string min = "Min";
static const std::string max = "Max";
static const std::string allowed_values = "Allowed Values";
}
} // namespace patch_key
inline static const std::string patch_engine_version = "1.2";

View file

@ -26,8 +26,7 @@ Intersection (&) and symmetric difference (^) is also available.
#include "Utilities/StrFmt.h"
template <typename T>
concept BitSetEnum = std::is_enum_v<T> && requires(T x)
{
concept BitSetEnum = std::is_enum_v<T> && requires(T x) {
T::__bitset_enum_max;
};
@ -185,56 +184,64 @@ constexpr bs_t<T> operator +(T bit)
}
// Binary '+' operator: bitset union
template <BitSetEnum T, typename U> requires (std::is_constructible_v<bs_t<T>, U>)
template <BitSetEnum T, typename U>
requires(std::is_constructible_v<bs_t<T>, U>)
constexpr bs_t<T> operator+(T lhs, const U& rhs)
{
return bs_t<T>(lhs) + bs_t<T>(rhs);
}
// Binary '+' operator: bitset union
template <typename U, BitSetEnum T> requires (std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
template <typename U, BitSetEnum T>
requires(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
constexpr bs_t<T> operator+(const U& lhs, T rhs)
{
return bs_t<T>(lhs) + bs_t<T>(rhs);
}
// Binary '-' operator: bitset difference
template <BitSetEnum T, typename U> requires (std::is_constructible_v<bs_t<T>, U>)
template <BitSetEnum T, typename U>
requires(std::is_constructible_v<bs_t<T>, U>)
constexpr bs_t<T> operator-(T lhs, const U& rhs)
{
return bs_t<T>(lhs) - bs_t<T>(rhs);
}
// Binary '-' operator: bitset difference
template <typename U, BitSetEnum T> requires (std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
template <typename U, BitSetEnum T>
requires(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
constexpr bs_t<T> operator-(const U& lhs, T rhs)
{
return bs_t<T>(lhs) - bs_t<T>(rhs);
}
// Binary '&' operator: bitset intersection
template <BitSetEnum T, typename U> requires (std::is_constructible_v<bs_t<T>, U>)
template <BitSetEnum T, typename U>
requires(std::is_constructible_v<bs_t<T>, U>)
constexpr bs_t<T> operator&(T lhs, const U& rhs)
{
return bs_t<T>(lhs) & bs_t<T>(rhs);
}
// Binary '&' operator: bitset intersection
template <typename U, BitSetEnum T> requires (std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
template <typename U, BitSetEnum T>
requires(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
constexpr bs_t<T> operator&(const U& lhs, T rhs)
{
return bs_t<T>(lhs) & bs_t<T>(rhs);
}
// Binary '^' operator: bitset symmetric difference
template <BitSetEnum T, typename U> requires (std::is_constructible_v<bs_t<T>, U>)
template <BitSetEnum T, typename U>
requires(std::is_constructible_v<bs_t<T>, U>)
constexpr bs_t<T> operator^(T lhs, const U& rhs)
{
return bs_t<T>(lhs) ^ bs_t<T>(rhs);
}
// Binary '^' operator: bitset symmetric difference
template <typename U, BitSetEnum T> requires (std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
template <typename U, BitSetEnum T>
requires(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>)
constexpr bs_t<T> operator^(const U& lhs, T rhs)
{
return bs_t<T>(lhs) ^ bs_t<T>(rhs);

View file

@ -114,8 +114,7 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src)
out.push_back(value % 10 + '0');
value /= 10;
}
}
while (0 < --min_size || value);
} while (0 < --min_size || value);
// Revert written characters
for (usz i = start, j = out.size() - 1; i < j; i++, j--)
@ -125,7 +124,8 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src)
};
// Single pass over fmt string (null-terminated), TODO: check correct order
while (const Char ch = *fmt++) if (ctx.size == 0)
while (const Char ch = *fmt++)
if (ctx.size == 0)
{
if (ch == '%')
{
@ -145,7 +145,8 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src)
{
out.push_back(ch);
}
else switch (ctx.size++, ch)
else
switch (ctx.size++, ch)
{
case '-': ctx.left = true; break;
case '+': ctx.sign = true; break;

View file

@ -55,4 +55,4 @@ namespace date_time
strftime(str, sizeof(str), parse_buf.c_str(), &now);
return str;
}
}
} // namespace date_time

View file

@ -541,13 +541,19 @@ struct coord_base
union
{
position_base<T> position;
struct { T x, y; };
struct
{
T x, y;
};
};
union
{
size2_base<T> size;
struct { T width, height; };
struct
{
T width, height;
};
};
constexpr coord_base() : position{}, size{}
@ -623,12 +629,16 @@ struct area_base
void flip_vertical()
{
T _y = y1; y1 = y2; y2 = _y;
T _y = y1;
y1 = y2;
y2 = _y;
}
void flip_horizontal()
{
T _x = x1; x1 = x2; x2 = _x;
T _x = x1;
x1 = x2;
x2 = _x;
}
constexpr area_base flipped_vertical() const
@ -672,7 +682,8 @@ struct area_base
return {x1 / size.width, y1 / size.height, x2 / size.width, y2 / size.height};
}
template <typename U> requires (std::is_arithmetic_v<U>)
template <typename U>
requires(std::is_arithmetic_v<U>)
constexpr area_base operator/(const U& value) const
{
return area_base{static_cast<T>(x1 / value), static_cast<T>(y1 / value), static_cast<T>(x2 / value), static_cast<T>(y2 / value)};
@ -683,7 +694,8 @@ struct area_base
return {x1 * size.width, y1 * size.height, x2 * size.width, y2 * size.height};
}
template <typename U> requires (std::is_arithmetic_v<U>)
template <typename U>
requires(std::is_arithmetic_v<U>)
constexpr area_base operator*(const U& value) const
{
return area_base{static_cast<T>(x1 * value), static_cast<T>(y1 * value), static_cast<T>(x2 * value), static_cast<T>(y2 * value)};
@ -714,13 +726,19 @@ struct coord3_base
union
{
position3_base<T> position;
struct { T x, y, z; };
struct
{
T x, y, z;
};
};
union
{
size3_base<T> size;
struct { T width, height, depth; };
struct
{
T width, height, depth;
};
};
constexpr coord3_base() : position{}, size{}
@ -756,7 +774,6 @@ struct coord3_base
}
};
template <typename T>
struct color4_base
{
@ -777,26 +794,17 @@ struct color4_base
};
constexpr color4_base()
: x{ T{0} }
, y{ T{0} }
, z{ T{0} }
, w{ T(1) }
: x{T{0}}, y{T{0}}, z{T{0}}, w{T(1)}
{
}
constexpr color4_base(T x, T y, T z, T w)
: x(x)
, y(y)
, z(z)
, w(w)
: x(x), y(y), z(z), w(w)
{
}
constexpr color4_base(T value)
: x(value)
, y(value)
, z(value)
, w(value)
: x(value), y(value), z(value), w(value)
{
}
@ -863,9 +871,7 @@ struct color3_base
};
constexpr color3_base(T x = {}, T y = {}, T z = {})
: x(x)
, y(y)
, z(z)
: x(x), y(y), z(z)
{
}
@ -901,8 +907,7 @@ struct color2_base
};
constexpr color2_base(T x = {}, T y = {})
: x(x)
, y(y)
: x(x), y(y)
{
}

View file

@ -73,7 +73,8 @@ public:
return *result;
}
template <typename F> requires (std::is_invocable_v<F, T&>)
template <typename F>
requires(std::is_invocable_v<F, T&>)
auto for_each(F&& func, bool is_finite = true)
{
lf_array* _this = this;
@ -214,8 +215,7 @@ class lf_queue_item final
template <typename... Args>
constexpr lf_queue_item(lf_queue_item* link, Args&&... args)
: m_link(link)
, m_data(std::forward<Args>(args)...)
: m_link(link), m_data(std::forward<Args>(args)...)
{
}
@ -405,8 +405,7 @@ class lf_queue final
auto* pprev = prev->m_link;
prev->m_link = head;
head = std::exchange(prev, pprev);
}
while (prev);
} while (prev);
}
return head;
@ -573,8 +572,7 @@ public:
// Set to not check already checked items
_chk = _old;
}
while (!m_head.compare_exchange(_old, item));
} while (!m_head.compare_exchange(_old, item));
return &item->m_data;
}

View file

@ -50,7 +50,8 @@ protected:
}
return false;
}).second;
})
.second;
}
void post(u32 _max)

View file

@ -30,7 +30,8 @@ simple_ringbuf::simple_ringbuf(const simple_ringbuf& other)
simple_ringbuf& simple_ringbuf::operator=(const simple_ringbuf& other)
{
if (this == &other) return *this;
if (this == &other)
return *this;
ctr_state old = other.rw_ptr.load();
@ -61,7 +62,8 @@ simple_ringbuf::simple_ringbuf(simple_ringbuf&& other)
simple_ringbuf& simple_ringbuf::operator=(simple_ringbuf&& other)
{
if (this == &other) return *this;
if (this == &other)
return *this;
const ctr_state other_rw_ptr = other.rw_ptr.load();
buf = std::move(other.buf);
@ -119,7 +121,8 @@ void simple_ringbuf::writer_flush(u64 cnt)
rw_ptr.atomic_op([&](ctr_state& val)
{
const u64 used = get_used_size(val);
if (used == 0) return;
if (used == 0)
return;
val.write_ptr += buf.size() - std::min<u64>(used, cnt);
});

View file

@ -8,7 +8,6 @@
class simple_ringbuf
{
public:
simple_ringbuf(u64 size = 0);
virtual ~simple_ringbuf();
@ -34,7 +33,6 @@ public:
void reader_flush(u64 cnt = umax);
private:
struct ctr_state
{
alignas(sizeof(u64) * 2)

View file

@ -3,7 +3,7 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>
#define DBGHELP_TRANSLATE_TCHAR
#include <DbgHelp.h>
#include <codecvt>
@ -150,4 +150,4 @@ namespace utils
return result;
}
#endif
}
} // namespace utils

View file

@ -9,8 +9,7 @@ namespace utils
// Printing utilities
template <typename T>
concept Logger = requires (T& t, const std::string& msg)
{
concept Logger = requires(T& t, const std::string& msg) {
{ t.print(msg) };
};
@ -21,14 +20,15 @@ namespace utils
public:
print_to_log(logs::channel& chan)
: log(chan)
{}
{
}
void print(const std::string& s)
{
log.error("%s", s);
}
};
}
} // namespace stack_trace
std::vector<void*> get_backtrace(int max_depth = 255);
std::vector<std::string> get_backtrace_symbols(const std::vector<void*>& stack);
@ -43,4 +43,4 @@ namespace utils
logger.print(line);
}
}
}
} // namespace utils

View file

@ -9,7 +9,7 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
#include <windows.h>
#include <ctime>
#elif __linux__
#include <sys/syscall.h>
@ -20,12 +20,18 @@
#endif
#ifdef _WIN32
#if !defined(NTSTATUS)
typedef _Return_type_success_(return >= 0) LONG NTSTATUS;
#endif
#ifndef __GNUC__
DYNAMIC_IMPORT("ntdll.dll", NtWaitForKeyedEvent, NTSTATUS(HANDLE, PVOID Key, BOOLEAN Alertable, PLARGE_INTEGER Timeout));
DYNAMIC_IMPORT("ntdll.dll", NtReleaseKeyedEvent, NTSTATUS(HANDLE, PVOID Key, BOOLEAN Alertable, PLARGE_INTEGER Timeout));
DYNAMIC_IMPORT("ntdll.dll", NtWaitForSingleObject, NTSTATUS(HANDLE Handle, BOOLEAN Alertable, PLARGE_INTEGER Timeout));
DYNAMIC_IMPORT("ntdll.dll", NtDelayExecution, NTSTATUS(BOOLEAN Alertable, PLARGE_INTEGER DelayInterval));
DYNAMIC_IMPORT("ntdll.dll", NtWaitForAlertByThreadId, NTSTATUS(PVOID Address, PLARGE_INTEGER Timeout));
DYNAMIC_IMPORT("ntdll.dll", NtAlertThreadByThreadId, NTSTATUS(DWORD_PTR ThreadId));
#endif
constexpr NTSTATUS NTSTATUS_SUCCESS = 0;
constexpr NTSTATUS NTSTATUS_ALERTED = 0x101;

View file

@ -7,7 +7,6 @@
class universal_pool
{
public:
universal_pool(u32 gc_interval = 10000) : gc_interval(gc_interval)
{
}
@ -45,7 +44,6 @@ public:
}
private:
void delete_unused()
{
const u32 gc_int = gc_interval.observe();
@ -53,11 +51,12 @@ private:
if (u64 crnt_time = get_system_time(); gc_int == 0 || crnt_time > gc_last_time + gc_int)
{
gc_last_time = crnt_time;
storage.erase
(
std::remove_if(storage.begin(), storage.end(), [](auto& obj) { return obj.use_count() <= 1; }),
storage.end()
);
storage.erase(
std::remove_if(storage.begin(), storage.end(), [](auto& obj)
{
return obj.use_count() <= 1;
}),
storage.end());
}
}
@ -71,7 +70,6 @@ template<typename T>
class transactional_storage
{
public:
transactional_storage(std::shared_ptr<universal_pool> pool, std::shared_ptr<T> obj = std::make_shared<T>())
{
ensure(pool && obj);
@ -98,7 +96,8 @@ public:
transactional_storage& operator=(transactional_storage&& other)
{
if (this == &other) return *this;
if (this == &other)
return *this;
pool = std::move(other.pool);
@ -153,7 +152,6 @@ public:
}
private:
shared_mutex current_mutex{};
std::shared_ptr<T> current{};
std::shared_ptr<universal_pool> pool{};

View file

@ -99,4 +99,4 @@ namespace utils
return 0;
}
}
} // namespace utils

View file

@ -27,12 +27,7 @@ namespace utils
public:
constexpr version(uint hi, uint mid, uint lo, version_type type, uint type_index, const char* postfix)
: m_hi(hi)
, m_mid(mid)
, m_lo(lo)
, m_type(type)
, m_type_index(type_index)
, m_postfix(postfix)
: m_hi(hi), m_mid(mid), m_lo(lo), m_type(type), m_type_index(type_index), m_postfix(postfix)
{
}
@ -72,4 +67,4 @@ namespace utils
// Generic version comparison (e.g. 0.0.5 vs 1.3)
int compare_versions(const std::string& v1, const std::string& v2, bool& ok);
}
} // namespace utils

View file

@ -29,8 +29,11 @@
std::string to_hex(std::uint64_t value, bool prfx = true)
{
char buf[20]{}, *ptr = buf + 19;
do *--ptr = "0123456789abcdef"[value % 16], value /= 16; while (value);
if (!prfx) return ptr;
do
*--ptr = "0123456789abcdef"[value % 16], value /= 16;
while (value);
if (!prfx)
return ptr;
*--ptr = 'x';
*--ptr = '0';
return ptr;
@ -200,7 +203,9 @@ int main(int argc, char* argv[])
}
else
{
while ((dup2(fds[1], STDOUT_FILENO) == -1) && (errno == EINTR)) {}
while ((dup2(fds[1], STDOUT_FILENO) == -1) && (errno == EINTR))
{
}
close(fds[1]);
close(fds[0]);
// Fallthrough

View file

@ -40,10 +40,7 @@
#ifndef GET_UINT32_LE
#define GET_UINT32_LE(n, b, i) \
{ \
(n) = ( static_cast<uint32_t>((b)[(i) ]) ) \
| ( static_cast<uint32_t>((b)[(i) + 1]) << 8 ) \
| ( static_cast<uint32_t>((b)[(i) + 2]) << 16 ) \
| ( static_cast<uint32_t>((b)[(i) + 3]) << 24 );\
(n) = (static_cast<uint32_t>((b)[(i)])) | (static_cast<uint32_t>((b)[(i) + 1]) << 8) | (static_cast<uint32_t>((b)[(i) + 2]) << 16) | (static_cast<uint32_t>((b)[(i) + 3]) << 24); \
}
#endif
@ -94,8 +91,7 @@ static const unsigned char FSb[256] =
0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94,
0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
};
0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16};
/*
* Forward tables
@ -221,8 +217,7 @@ static const unsigned char RSb[256] =
0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0,
0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26,
0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
};
0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D};
/*
* Reverse tables
@ -319,8 +314,7 @@ static const uint32_t RCON[10] =
{
0x00000001, 0x00000002, 0x00000004, 0x00000008,
0x00000010, 0x00000020, 0x00000040, 0x00000080,
0x0000001B, 0x00000036
};
0x0000001B, 0x00000036};
#else
@ -391,10 +385,14 @@ static void aes_gen_tables( void )
{
x = pow[255 - log[i]];
y = x; y = ( (y << 1) | (y >> 7) ) & 0xFF;
x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF;
x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF;
x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF;
y = x;
y = ((y << 1) | (y >> 7)) & 0xFF;
x ^= y;
y = ((y << 1) | (y >> 7)) & 0xFF;
x ^= y;
y = ((y << 1) | (y >> 7)) & 0xFF;
x ^= y;
y = ((y << 1) | (y >> 7)) & 0xFF;
x ^= y ^ 0x63;
FSb[i] = (unsigned char)x;
@ -447,7 +445,6 @@ int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int key
{
aes_gen_tables();
aes_init_done = 1;
}
#endif
@ -672,10 +669,14 @@ int aes_crypt_ecb( aes_context *ctx,
RK = ctx->rk;
GET_UINT32_LE( X0, input, 0 ); X0 ^= *RK++;
GET_UINT32_LE( X1, input, 4 ); X1 ^= *RK++;
GET_UINT32_LE( X2, input, 8 ); X2 ^= *RK++;
GET_UINT32_LE( X3, input, 12 ); X3 ^= *RK++;
GET_UINT32_LE(X0, input, 0);
X0 ^= *RK++;
GET_UINT32_LE(X1, input, 4);
X1 ^= *RK++;
GET_UINT32_LE(X2, input, 8);
X2 ^= *RK++;
GET_UINT32_LE(X3, input, 12);
X3 ^= *RK++;
if (mode == AES_DECRYPT)
{
@ -687,25 +688,25 @@ int aes_crypt_ecb( aes_context *ctx,
AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3);
X0 = *RK++ ^ \
X0 = *RK++ ^
(static_cast<uint32_t>(RSb[(Y0) & 0xFF])) ^
(static_cast<uint32_t>(RSb[(Y3 >> 8) & 0xFF]) << 8) ^
(static_cast<uint32_t>(RSb[(Y2 >> 16) & 0xFF]) << 16) ^
(static_cast<uint32_t>(RSb[(Y1 >> 24) & 0xFF]) << 24);
X1 = *RK++ ^ \
X1 = *RK++ ^
(static_cast<uint32_t>(RSb[(Y1) & 0xFF])) ^
(static_cast<uint32_t>(RSb[(Y0 >> 8) & 0xFF]) << 8) ^
(static_cast<uint32_t>(RSb[(Y3 >> 16) & 0xFF]) << 16) ^
(static_cast<uint32_t>(RSb[(Y2 >> 24) & 0xFF]) << 24);
X2 = *RK++ ^ \
X2 = *RK++ ^
(static_cast<uint32_t>(RSb[(Y2) & 0xFF])) ^
(static_cast<uint32_t>(RSb[(Y1 >> 8) & 0xFF]) << 8) ^
(static_cast<uint32_t>(RSb[(Y0 >> 16) & 0xFF]) << 16) ^
(static_cast<uint32_t>(RSb[(Y3 >> 24) & 0xFF]) << 24);
X3 = *RK++ ^ \
X3 = *RK++ ^
(static_cast<uint32_t>(RSb[(Y3) & 0xFF])) ^
(static_cast<uint32_t>(RSb[(Y2 >> 8) & 0xFF]) << 8) ^
(static_cast<uint32_t>(RSb[(Y1 >> 16) & 0xFF]) << 16) ^
@ -721,25 +722,25 @@ int aes_crypt_ecb( aes_context *ctx,
AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3);
X0 = *RK++ ^ \
X0 = *RK++ ^
(static_cast<uint32_t>(FSb[(Y0) & 0xFF])) ^
(static_cast<uint32_t>(FSb[(Y1 >> 8) & 0xFF]) << 8) ^
(static_cast<uint32_t>(FSb[(Y2 >> 16) & 0xFF]) << 16) ^
(static_cast<uint32_t>(FSb[(Y3 >> 24) & 0xFF]) << 24);
X1 = *RK++ ^ \
X1 = *RK++ ^
(static_cast<uint32_t>(FSb[(Y1) & 0xFF])) ^
(static_cast<uint32_t>(FSb[(Y2 >> 8) & 0xFF]) << 8) ^
(static_cast<uint32_t>(FSb[(Y3 >> 16) & 0xFF]) << 16) ^
(static_cast<uint32_t>(FSb[(Y0 >> 24) & 0xFF]) << 24);
X2 = *RK++ ^ \
X2 = *RK++ ^
(static_cast<uint32_t>(FSb[(Y2) & 0xFF])) ^
(static_cast<uint32_t>(FSb[(Y3 >> 8) & 0xFF]) << 8) ^
(static_cast<uint32_t>(FSb[(Y0 >> 16) & 0xFF]) << 16) ^
(static_cast<uint32_t>(FSb[(Y1 >> 24) & 0xFF]) << 24);
X3 = *RK++ ^ \
X3 = *RK++ ^
(static_cast<uint32_t>(FSb[(Y3) & 0xFF])) ^
(static_cast<uint32_t>(FSb[(Y0 >> 8) & 0xFF]) << 8) ^
(static_cast<uint32_t>(FSb[(Y1 >> 16) & 0xFF]) << 16) ^
@ -868,7 +869,8 @@ int aes_crypt_ctr( aes_context *ctx,
while (length--)
{
if( n == 0 ) {
if (n == 0)
{
aes_crypt_ecb(ctx, AES_ENCRYPT, nonce_counter, stream_block);
for (i = 16; i > 0; i--)
@ -890,12 +892,10 @@ int aes_crypt_ctr( aes_context *ctx,
unsigned char const_Rb[16] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87
};
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87};
unsigned char const_Zero[16] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
void leftshift_onebit(const unsigned char* input, unsigned char* output)
{
@ -924,14 +924,17 @@ void generate_subkey(aes_context *ctx, unsigned char *K1, unsigned char *K2)
unsigned char tmp[16];
int i;
for (i = 0; i < 16; i++) Z[i] = 0;
for (i = 0; i < 16; i++)
Z[i] = 0;
aes_crypt_ecb(ctx, AES_ENCRYPT, Z, L);
if ((L[0] & 0x80) == 0)
{
leftshift_onebit(L, K1);
} else {
}
else
{
leftshift_onebit(L, tmp);
xor_128(tmp, const_Rb, K1);
}
@ -939,7 +942,9 @@ void generate_subkey(aes_context *ctx, unsigned char *K1, unsigned char *K2)
if ((K1[0] & 0x80) == 0)
{
leftshift_onebit(K1, K2);
} else {
}
else
{
leftshift_onebit(K1, tmp);
xor_128(tmp, const_Rb, K2);
}
@ -970,7 +975,9 @@ void aes_cmac(aes_context *ctx, size_t length, unsigned char *input, unsigned ch
{
n = 1;
flag = 0;
} else {
}
else
{
if ((length % 16) == 0)
flag = 1;
else
@ -980,12 +987,15 @@ void aes_cmac(aes_context *ctx, size_t length, unsigned char *input, unsigned ch
if (flag)
{
xor_128(&input[16 * (n - 1)], K1, M_last);
} else {
}
else
{
padding(&input[16 * (n - 1)], padded, length % 16);
xor_128(padded, K2, M_last);
}
for (i = 0; i < 16; i++) X[i] = 0;
for (i = 0; i < 16; i++)
X[i] = 0;
for (size_t i = 0; i < n - 1; i++)
{
xor_128(X, &input[16 * i], Y);

View file

@ -52,11 +52,11 @@ typedef struct
int nr; /*!< number of rounds */
uint32_t* rk; /*!< AES round keys */
uint32_t buf[68]; /*!< unaligned data */
}
aes_context;
} aes_context;
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
/**

View file

@ -33,7 +33,8 @@
#define POLARSSL_AESNI_CLMUL 0x00000002u
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
/**

View file

@ -65,22 +65,134 @@ static void bn_sub(u8* d, const u8* a, const u8* b, const u8* N, u32 n)
}
static constexpr u8 inv256[0x80] = {
0x01, 0xab, 0xcd, 0xb7, 0x39, 0xa3, 0xc5, 0xef,
0xf1, 0x1b, 0x3d, 0xa7, 0x29, 0x13, 0x35, 0xdf,
0xe1, 0x8b, 0xad, 0x97, 0x19, 0x83, 0xa5, 0xcf,
0xd1, 0xfb, 0x1d, 0x87, 0x09, 0xf3, 0x15, 0xbf,
0xc1, 0x6b, 0x8d, 0x77, 0xf9, 0x63, 0x85, 0xaf,
0xb1, 0xdb, 0xfd, 0x67, 0xe9, 0xd3, 0xf5, 0x9f,
0xa1, 0x4b, 0x6d, 0x57, 0xd9, 0x43, 0x65, 0x8f,
0x91, 0xbb, 0xdd, 0x47, 0xc9, 0xb3, 0xd5, 0x7f,
0x81, 0x2b, 0x4d, 0x37, 0xb9, 0x23, 0x45, 0x6f,
0x71, 0x9b, 0xbd, 0x27, 0xa9, 0x93, 0xb5, 0x5f,
0x61, 0x0b, 0x2d, 0x17, 0x99, 0x03, 0x25, 0x4f,
0x51, 0x7b, 0x9d, 0x07, 0x89, 0x73, 0x95, 0x3f,
0x41, 0xeb, 0x0d, 0xf7, 0x79, 0xe3, 0x05, 0x2f,
0x31, 0x5b, 0x7d, 0xe7, 0x69, 0x53, 0x75, 0x1f,
0x21, 0xcb, 0xed, 0xd7, 0x59, 0xc3, 0xe5, 0x0f,
0x11, 0x3b, 0x5d, 0xc7, 0x49, 0x33, 0x55, 0xff,
0x01,
0xab,
0xcd,
0xb7,
0x39,
0xa3,
0xc5,
0xef,
0xf1,
0x1b,
0x3d,
0xa7,
0x29,
0x13,
0x35,
0xdf,
0xe1,
0x8b,
0xad,
0x97,
0x19,
0x83,
0xa5,
0xcf,
0xd1,
0xfb,
0x1d,
0x87,
0x09,
0xf3,
0x15,
0xbf,
0xc1,
0x6b,
0x8d,
0x77,
0xf9,
0x63,
0x85,
0xaf,
0xb1,
0xdb,
0xfd,
0x67,
0xe9,
0xd3,
0xf5,
0x9f,
0xa1,
0x4b,
0x6d,
0x57,
0xd9,
0x43,
0x65,
0x8f,
0x91,
0xbb,
0xdd,
0x47,
0xc9,
0xb3,
0xd5,
0x7f,
0x81,
0x2b,
0x4d,
0x37,
0xb9,
0x23,
0x45,
0x6f,
0x71,
0x9b,
0xbd,
0x27,
0xa9,
0x93,
0xb5,
0x5f,
0x61,
0x0b,
0x2d,
0x17,
0x99,
0x03,
0x25,
0x4f,
0x51,
0x7b,
0x9d,
0x07,
0x89,
0x73,
0x95,
0x3f,
0x41,
0xeb,
0x0d,
0xf7,
0x79,
0xe3,
0x05,
0x2f,
0x31,
0x5b,
0x7d,
0xe7,
0x69,
0x53,
0x75,
0x1f,
0x21,
0xcb,
0xed,
0xd7,
0x59,
0xc3,
0xe5,
0x0f,
0x11,
0x3b,
0x5d,
0xc7,
0x49,
0x33,
0x55,
0xff,
};
static void bn_mon_muladd_dig(u8* d, const u8* a, u8 b, const u8* N, u32 n)
@ -384,7 +496,8 @@ static bool check_ecdsa(const struct point* Q, u8* R, u8* S, const u8* hash)
void ecdsa_set_curve(const u8* p, const u8* a, const u8* b, const u8* N, const u8* Gx, const u8* Gy)
{
if (ec_curve_initialized) return;
if (ec_curve_initialized)
return;
memcpy(ec_p, p, 20);
memcpy(ec_a, a, 20);
@ -403,7 +516,8 @@ void ecdsa_set_curve(const u8* p, const u8* a, const u8* b, const u8* N, const u
void ecdsa_set_pub(const u8* Q)
{
if (ec_pub_initialized) return;
if (ec_pub_initialized)
return;
memcpy(ec_Q.x, Q, 20);
memcpy(ec_Q.y, Q + 20, 20);

View file

@ -65,151 +65,116 @@ constexpr u8 SC_ISO_SERIES_INTERNAL_KEY_3[PASSPHRASE_KEY_LEN] = {
};
constexpr u8 PKG_AES_KEY_IDU[0x10] = {
0x5d, 0xb9, 0x11, 0xe6, 0xb7, 0xe5, 0x0a, 0x7d, 0x32, 0x15, 0x38, 0xfd, 0x7c, 0x66, 0xf1, 0x7b
};
0x5d, 0xb9, 0x11, 0xe6, 0xb7, 0xe5, 0x0a, 0x7d, 0x32, 0x15, 0x38, 0xfd, 0x7c, 0x66, 0xf1, 0x7b};
constexpr u8 PKG_AES_KEY[0x10] = {
0x2e, 0x7b, 0x71, 0xd7, 0xc9, 0xc9, 0xa1, 0x4e, 0xa3, 0x22, 0x1f, 0x18, 0x88, 0x28, 0xb8, 0xf8
};
0x2e, 0x7b, 0x71, 0xd7, 0xc9, 0xc9, 0xa1, 0x4e, 0xa3, 0x22, 0x1f, 0x18, 0x88, 0x28, 0xb8, 0xf8};
constexpr u8 PKG_AES_KEY2[0x10] = {
0x07, 0xf2, 0xc6, 0x82, 0x90, 0xb5, 0x0d, 0x2c, 0x33, 0x81, 0x8d, 0x70, 0x9b, 0x60, 0xe6, 0x2b
};
0x07, 0xf2, 0xc6, 0x82, 0x90, 0xb5, 0x0d, 0x2c, 0x33, 0x81, 0x8d, 0x70, 0x9b, 0x60, 0xe6, 0x2b};
constexpr u8 PKG_AES_KEY_VITA_1[0x10] = {
0xE3, 0x1A, 0x70, 0xC9, 0xCE, 0x1D, 0xD7, 0x2B, 0xF3, 0xC0, 0x62, 0x29, 0x63, 0xF2, 0xEC, 0xCB
};
0xE3, 0x1A, 0x70, 0xC9, 0xCE, 0x1D, 0xD7, 0x2B, 0xF3, 0xC0, 0x62, 0x29, 0x63, 0xF2, 0xEC, 0xCB};
constexpr u8 PKG_AES_KEY_VITA_2[0x10] = {
0x42, 0x3A, 0xCA, 0x3A, 0x2B, 0xD5, 0x64, 0x9F, 0x96, 0x86, 0xAB, 0xAD, 0x6F, 0xD8, 0x80, 0x1F
};
0x42, 0x3A, 0xCA, 0x3A, 0x2B, 0xD5, 0x64, 0x9F, 0x96, 0x86, 0xAB, 0xAD, 0x6F, 0xD8, 0x80, 0x1F};
constexpr u8 PKG_AES_KEY_VITA_3[0x10] = {
0xAF, 0x07, 0xFD, 0x59, 0x65, 0x25, 0x27, 0xBA, 0xF1, 0x33, 0x89, 0x66, 0x8B, 0x17, 0xD9, 0xEA
};
0xAF, 0x07, 0xFD, 0x59, 0x65, 0x25, 0x27, 0xBA, 0xF1, 0x33, 0x89, 0x66, 0x8B, 0x17, 0xD9, 0xEA};
constexpr u8 NP_IDPS[0x10] = {
0x5E, 0x06, 0xE0, 0x4F, 0xD9, 0x4A, 0x71, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
};
0x5E, 0x06, 0xE0, 0x4F, 0xD9, 0x4A, 0x71, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
constexpr u8 NP_KLIC_FREE[0x10] = {
0x72, 0xF9, 0x90, 0x78, 0x8F, 0x9C, 0xFF, 0x74, 0x57, 0x25, 0xF0, 0x8E, 0x4C, 0x12, 0x83, 0x87
};
0x72, 0xF9, 0x90, 0x78, 0x8F, 0x9C, 0xFF, 0x74, 0x57, 0x25, 0xF0, 0x8E, 0x4C, 0x12, 0x83, 0x87};
constexpr u8 NP_OMAC_KEY_2[0x10] = {
0x6B, 0xA5, 0x29, 0x76, 0xEF, 0xDA, 0x16, 0xEF, 0x3C, 0x33, 0x9F, 0xB2, 0x97, 0x1E, 0x25, 0x6B
};
0x6B, 0xA5, 0x29, 0x76, 0xEF, 0xDA, 0x16, 0xEF, 0x3C, 0x33, 0x9F, 0xB2, 0x97, 0x1E, 0x25, 0x6B};
constexpr u8 NP_OMAC_KEY_3[0x10] = {
0x9B, 0x51, 0x5F, 0xEA, 0xCF, 0x75, 0x06, 0x49, 0x81, 0xAA, 0x60, 0x4D, 0x91, 0xA5, 0x4E, 0x97
};
0x9B, 0x51, 0x5F, 0xEA, 0xCF, 0x75, 0x06, 0x49, 0x81, 0xAA, 0x60, 0x4D, 0x91, 0xA5, 0x4E, 0x97};
constexpr u8 NP_KLIC_KEY[0x10] = {
0xF2, 0xFB, 0xCA, 0x7A, 0x75, 0xB0, 0x4E, 0xDC, 0x13, 0x90, 0x63, 0x8C, 0xCD, 0xFD, 0xD1, 0xEE
};
0xF2, 0xFB, 0xCA, 0x7A, 0x75, 0xB0, 0x4E, 0xDC, 0x13, 0x90, 0x63, 0x8C, 0xCD, 0xFD, 0xD1, 0xEE};
constexpr u8 NP_RIF_KEY[0x10] = {
0xDA, 0x7D, 0x4B, 0x5E, 0x49, 0x9A, 0x4F, 0x53, 0xB1, 0xC1, 0xA1, 0x4A, 0x74, 0x84, 0x44, 0x3B
};
0xDA, 0x7D, 0x4B, 0x5E, 0x49, 0x9A, 0x4F, 0x53, 0xB1, 0xC1, 0xA1, 0x4A, 0x74, 0x84, 0x44, 0x3B};
// PSP Minis
constexpr u8 NP_PSP_KEY_1[0x10] = {
0x2A, 0x6A, 0xFB, 0xCF, 0x43, 0xD1, 0x57, 0x9F, 0x7D, 0x73, 0x87, 0x41, 0xA1, 0x3B, 0xD4, 0x2E
};
0x2A, 0x6A, 0xFB, 0xCF, 0x43, 0xD1, 0x57, 0x9F, 0x7D, 0x73, 0x87, 0x41, 0xA1, 0x3B, 0xD4, 0x2E};
// PSP Remasters
constexpr u8 NP_PSP_KEY_2[0x10] = {
0x0D, 0xB8, 0x57, 0x32, 0x36, 0x6C, 0xD7, 0x34, 0xFC, 0x87, 0x9E, 0x74, 0x33, 0x43, 0xBB, 0x4F
};
0x0D, 0xB8, 0x57, 0x32, 0x36, 0x6C, 0xD7, 0x34, 0xFC, 0x87, 0x9E, 0x74, 0x33, 0x43, 0xBB, 0x4F};
constexpr u8 NP_PSX_KEY[0x10] = {
0x52, 0xC0, 0xB5, 0xCA, 0x76, 0xD6, 0x13, 0x4B, 0xB4, 0x5F, 0xC6, 0x6C, 0xA6, 0x37, 0xF2, 0xC1
};
0x52, 0xC0, 0xB5, 0xCA, 0x76, 0xD6, 0x13, 0x4B, 0xB4, 0x5F, 0xC6, 0x6C, 0xA6, 0x37, 0xF2, 0xC1};
constexpr u8 RAP_KEY[0x10] = {
0x86, 0x9F, 0x77, 0x45, 0xC1, 0x3F, 0xD8, 0x90, 0xCC, 0xF2, 0x91, 0x88, 0xE3, 0xCC, 0x3E, 0xDF
};
0x86, 0x9F, 0x77, 0x45, 0xC1, 0x3F, 0xD8, 0x90, 0xCC, 0xF2, 0x91, 0x88, 0xE3, 0xCC, 0x3E, 0xDF};
constexpr u8 RAP_PBOX[0x10] = {
0x0C, 0x03, 0x06, 0x04, 0x01, 0x0B, 0x0F, 0x08, 0x02, 0x07, 0x00, 0x05, 0x0A, 0x0E, 0x0D, 0x09
};
0x0C, 0x03, 0x06, 0x04, 0x01, 0x0B, 0x0F, 0x08, 0x02, 0x07, 0x00, 0x05, 0x0A, 0x0E, 0x0D, 0x09};
constexpr u8 RAP_E1[0x10] = {
0xA9, 0x3E, 0x1F, 0xD6, 0x7C, 0x55, 0xA3, 0x29, 0xB7, 0x5F, 0xDD, 0xA6, 0x2A, 0x95, 0xC7, 0xA5
};
0xA9, 0x3E, 0x1F, 0xD6, 0x7C, 0x55, 0xA3, 0x29, 0xB7, 0x5F, 0xDD, 0xA6, 0x2A, 0x95, 0xC7, 0xA5};
constexpr u8 RAP_E2[0x10] = {
0x67, 0xD4, 0x5D, 0xA3, 0x29, 0x6D, 0x00, 0x6A, 0x4E, 0x7C, 0x53, 0x7B, 0xF5, 0x53, 0x8C, 0x74
};
0x67, 0xD4, 0x5D, 0xA3, 0x29, 0x6D, 0x00, 0x6A, 0x4E, 0x7C, 0x53, 0x7B, 0xF5, 0x53, 0x8C, 0x74};
constexpr u8 SDAT_KEY[0x10] = {
0x0D, 0x65, 0x5E, 0xF8, 0xE6, 0x74, 0xA9, 0x8A, 0xB8, 0x50, 0x5C, 0xFA, 0x7D, 0x01, 0x29, 0x33
};
0x0D, 0x65, 0x5E, 0xF8, 0xE6, 0x74, 0xA9, 0x8A, 0xB8, 0x50, 0x5C, 0xFA, 0x7D, 0x01, 0x29, 0x33};
constexpr u8 EDAT_KEY_0[0x10] = {
0xBE, 0x95, 0x9C, 0xA8, 0x30, 0x8D, 0xEF, 0xA2, 0xE5, 0xE1, 0x80, 0xC6, 0x37, 0x12, 0xA9, 0xAE
};
0xBE, 0x95, 0x9C, 0xA8, 0x30, 0x8D, 0xEF, 0xA2, 0xE5, 0xE1, 0x80, 0xC6, 0x37, 0x12, 0xA9, 0xAE};
constexpr u8 EDAT_HASH_0[0x10] = {
0xEF, 0xFE, 0x5B, 0xD1, 0x65, 0x2E, 0xEB, 0xC1, 0x19, 0x18, 0xCF, 0x7C, 0x04, 0xD4, 0xF0, 0x11
};
0xEF, 0xFE, 0x5B, 0xD1, 0x65, 0x2E, 0xEB, 0xC1, 0x19, 0x18, 0xCF, 0x7C, 0x04, 0xD4, 0xF0, 0x11};
constexpr u8 EDAT_KEY_1[0x10] = {
0x4C, 0xA9, 0xC1, 0x4B, 0x01, 0xC9, 0x53, 0x09, 0x96, 0x9B, 0xEC, 0x68, 0xAA, 0x0B, 0xC0, 0x81
};
0x4C, 0xA9, 0xC1, 0x4B, 0x01, 0xC9, 0x53, 0x09, 0x96, 0x9B, 0xEC, 0x68, 0xAA, 0x0B, 0xC0, 0x81};
constexpr u8 EDAT_HASH_1[0x10] = {
0x3D, 0x92, 0x69, 0x9B, 0x70, 0x5B, 0x07, 0x38, 0x54, 0xD8, 0xFC, 0xC6, 0xC7, 0x67, 0x27, 0x47
};
0x3D, 0x92, 0x69, 0x9B, 0x70, 0x5B, 0x07, 0x38, 0x54, 0xD8, 0xFC, 0xC6, 0xC7, 0x67, 0x27, 0x47};
constexpr u8 EDAT_IV[0x10] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
constexpr u8 VSH_CURVE_P[0x14] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
constexpr u8 VSH_CURVE_A[0x14] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC
};
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC};
constexpr u8 VSH_CURVE_B[0x14] = {
0xA6, 0x8B, 0xED, 0xC3, 0x34, 0x18, 0x02, 0x9C, 0x1D, 0x3C, 0xE3, 0x3B, 0x9A, 0x32, 0x1F, 0xCC, 0xBB, 0x9E, 0x0F, 0x0B
};
0xA6, 0x8B, 0xED, 0xC3, 0x34, 0x18, 0x02, 0x9C, 0x1D, 0x3C, 0xE3, 0x3B, 0x9A, 0x32, 0x1F, 0xCC, 0xBB, 0x9E, 0x0F, 0x0B};
constexpr u8 VSH_CURVE_N[0x15] = {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xB5, 0xAE, 0x3C, 0x52, 0x3E, 0x63, 0x94, 0x4F, 0x21, 0x27
};
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xB5, 0xAE, 0x3C, 0x52, 0x3E, 0x63, 0x94, 0x4F, 0x21, 0x27};
constexpr u8 VSH_CURVE_GX[0x14] = {
0x12, 0x8E, 0xC4, 0x25, 0x64, 0x87, 0xFD, 0x8F, 0xDF, 0x64, 0xE2, 0x43, 0x7B, 0xC0, 0xA1, 0xF6, 0xD5, 0xAF, 0xDE, 0x2C
};
0x12, 0x8E, 0xC4, 0x25, 0x64, 0x87, 0xFD, 0x8F, 0xDF, 0x64, 0xE2, 0x43, 0x7B, 0xC0, 0xA1, 0xF6, 0xD5, 0xAF, 0xDE, 0x2C};
constexpr u8 VSH_CURVE_GY[0x14] = {
0x59, 0x58, 0x55, 0x7E, 0xB1, 0xDB, 0x00, 0x12, 0x60, 0x42, 0x55, 0x24, 0xDB, 0xC3, 0x79, 0xD5, 0xAC, 0x5F, 0x4A, 0xDF
};
0x59, 0x58, 0x55, 0x7E, 0xB1, 0xDB, 0x00, 0x12, 0x60, 0x42, 0x55, 0x24, 0xDB, 0xC3, 0x79, 0xD5, 0xAC, 0x5F, 0x4A, 0xDF};
constexpr u8 VSH_PUB[0x28] = {
0x62, 0x27, 0xB0, 0x0A, 0x02, 0x85, 0x6F, 0xB0, 0x41, 0x08, 0x87, 0x67, 0x19, 0xE0, 0xA0, 0x18, 0x32, 0x91, 0xEE, 0xB9,
0x6E, 0x73, 0x6A, 0xBF, 0x81, 0xF7, 0x0E, 0xE9, 0x16, 0x1B, 0x0D, 0xDE, 0xB0, 0x26, 0x76, 0x1A, 0xFF, 0x7B, 0xC8, 0x5B
};
0x6E, 0x73, 0x6A, 0xBF, 0x81, 0xF7, 0x0E, 0xE9, 0x16, 0x1B, 0x0D, 0xDE, 0xB0, 0x26, 0x76, 0x1A, 0xFF, 0x7B, 0xC8, 0x5B};
constexpr u8 SCEPKG_RIV[0x10] = {
0x4A, 0xCE, 0xF0, 0x12, 0x24, 0xFB, 0xEE, 0xDF, 0x82, 0x45, 0xF8, 0xFF, 0x10, 0x21, 0x1E, 0x6E
};
0x4A, 0xCE, 0xF0, 0x12, 0x24, 0xFB, 0xEE, 0xDF, 0x82, 0x45, 0xF8, 0xFF, 0x10, 0x21, 0x1E, 0x6E};
constexpr u8 SCEPKG_ERK[0x20] = {
0xA9, 0x78, 0x18, 0xBD, 0x19, 0x3A, 0x67, 0xA1, 0x6F, 0xE8, 0x3A, 0x85, 0x5E, 0x1B, 0xE9, 0xFB, 0x56, 0x40, 0x93, 0x8D,
0x4D, 0xBC, 0xB2, 0xCB, 0x52, 0xC5, 0xA2, 0xF8, 0xB0, 0x2B, 0x10, 0x31
};
0x4D, 0xBC, 0xB2, 0xCB, 0x52, 0xC5, 0xA2, 0xF8, 0xB0, 0x2B, 0x10, 0x31};
constexpr u8 PUP_KEY[0x40] = {
0xF4, 0x91, 0xAD, 0x94, 0xC6, 0x81, 0x10, 0x96, 0x91, 0x5F, 0xD5, 0xD2, 0x44, 0x81, 0xAE, 0xDC, 0xED, 0xED, 0xBE, 0x6B,
0xE5, 0x13, 0x72, 0x4D, 0xD8, 0xF7, 0xB6, 0x91, 0xE8, 0x8A, 0x38, 0xF4, 0xB5, 0x16, 0x2B, 0xFB, 0xEC, 0xBE, 0x3A, 0x62,
0x18, 0x5D, 0xD7, 0xC9, 0x4D, 0xA2, 0x22, 0x5A, 0xDA, 0x3F, 0xBF, 0xCE, 0x55, 0x5B, 0x9E, 0xA9, 0x64, 0x98, 0x29, 0xEB,
0x30, 0xCE, 0x83, 0x66
};
0x30, 0xCE, 0x83, 0x66};
// name; location; notes
constexpr s64 PAID_01 = 0x0003CD28CB47D3C1L; // spu_token_processor.self; CoreOS; Only for 2E - 083.007

View file

@ -22,13 +22,15 @@ int decode_bit(unsigned int *range, unsigned int *code, int *index, unsigned cha
unsigned int val = ((*range) >> 8) * (*c);
*c -= ((*c) >> 3);
if (index) (*index) <<= 1;
if (index)
(*index) <<= 1;
if (*code < val)
{
*range = val;
*c += 31;
if (index) (*index)++;
if (index)
(*index)++;
return 1;
}
else
@ -163,8 +165,10 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
if (!decode_bit(&range, &code, 0, &in, tmp_sect1)) // Raw char.
{
// Adjust offset and check for stream end.
if (offset > 0) offset--;
if (start == end) return static_cast<int>(start - out);
if (offset > 0)
offset--;
if (start == end)
return static_cast<int>(start - out);
// Locate first section.
int sect = ((((((static_cast<int>(start - out)) & 7) << 8) + prev) >> head) & 7) * 0xFF - 1;
@ -205,7 +209,8 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
// Decode the data length (8 bit fields).
data_length = decode_number(tmp_sect1, index, &bit_flag, &range, &code, &in);
if (data_length == 0xFF) return static_cast<int>(start - out); // End of stream.
if (data_length == 0xFF)
return static_cast<int>(start - out); // End of stream.
}
else
{
@ -234,7 +239,8 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
if ((diff > 0) || (bit_flag != 0))
{
// Adjust diff if needed.
if (bit_flag == 0) diff -= 8;
if (bit_flag == 0)
diff -= 8;
// Locate section.
tmp_sect3 = tmp + 0x928 + diff;
@ -272,7 +278,6 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
{
*start++ = *buf_start++;
} while (start < buf_end);
}
prev = *(start - 1);
}

View file

@ -39,10 +39,7 @@
#ifndef GET_UINT32_LE
#define GET_UINT32_LE(n, b, i) \
{ \
(n) = ( static_cast<uint32_t>((b)[(i) ]) ) \
| ( static_cast<uint32_t>((b)[(i) + 1]) << 8 ) \
| ( static_cast<uint32_t>((b)[(i) + 2]) << 16 ) \
| ( static_cast<uint32_t>((b)[(i) + 3]) << 24 );\
(n) = (static_cast<uint32_t>((b)[(i)])) | (static_cast<uint32_t>((b)[(i) + 1]) << 8) | (static_cast<uint32_t>((b)[(i) + 2]) << 16) | (static_cast<uint32_t>((b)[(i) + 3]) << 24); \
}
#endif
@ -125,7 +122,8 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
#define P(a, b, c, d, k, s, t) \
{ \
a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
a += F(b, c, d) + X[k] + t; \
a = S(a, s) + b; \
}
A = ctx->state[0];
@ -330,8 +328,7 @@ int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
/*
* Add message length
*/
high = ( ctx->total[0] >> 29 )
| ( ctx->total[1] << 3 );
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
low = (ctx->total[0] << 3);
PUT_UINT32_LE(low, ctx->buffer, 56);
@ -410,13 +407,11 @@ static const unsigned char md5_test_buf[7][81] =
{"abcdefghijklmnopqrstuvwxyz"},
{"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"},
{"12345678901234567890123456789012345678901234567890123456789012"
"345678901234567890" }
};
"345678901234567890"}};
static const size_t md5_test_buflen[7] =
{
0, 1, 3, 14, 26, 62, 80
};
0, 1, 3, 14, 26, 62, 80};
static const unsigned char md5_test_sum[7][16] =
{
@ -433,8 +428,7 @@ static const unsigned char md5_test_sum[7][16] =
{0xD1, 0x74, 0xAB, 0x98, 0xD2, 0x77, 0xD9, 0xF5,
0xA5, 0x61, 0x1C, 0x2C, 0x9F, 0x41, 0x9D, 0x9F},
{0x57, 0xED, 0xF4, 0xA2, 0x2B, 0xE3, 0xC9, 0x55,
0xAC, 0x49, 0xDA, 0x2E, 0x21, 0x07, 0xB6, 0x7A }
};
0xAC, 0x49, 0xDA, 0x2E, 0x21, 0x07, 0xB6, 0x7A}};
/*
* Checkup routine

View file

@ -37,7 +37,8 @@
#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
#if !defined(MBEDTLS_MD5_ALT)
@ -57,8 +58,7 @@ typedef struct mbedtls_md5_context
uint32_t total[2]; /*!< number of bytes processed */
uint32_t state[4]; /*!< intermediate digest state */
unsigned char buffer[64]; /*!< data block being processed */
}
mbedtls_md5_context;
} mbedtls_md5_context;
#else /* MBEDTLS_MD5_ALT */
#include "md5_alt.h"

View file

@ -37,10 +37,7 @@
#ifndef GET_UINT32_BE
#define GET_UINT32_BE(n, b, i) \
{ \
(n) = ( static_cast<uint32_t>((b)[(i) ]) << 24 ) \
| ( static_cast<uint32_t>((b)[(i) + 1]) << 16 ) \
| ( static_cast<uint32_t>((b)[(i) + 2]) << 8 ) \
| ( static_cast<uint32_t>((b)[(i) + 3]) );\
(n) = (static_cast<uint32_t>((b)[(i)]) << 24) | (static_cast<uint32_t>((b)[(i) + 1]) << 16) | (static_cast<uint32_t>((b)[(i) + 2]) << 8) | (static_cast<uint32_t>((b)[(i) + 3])); \
}
#endif
@ -96,12 +93,12 @@ void sha1_process( sha1_context *ctx, const unsigned char data[64] )
( \
temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \
W[(t - 14) & 0x0F] ^ W[t & 0x0F], \
( W[t & 0x0F] = S(temp,1) ) \
)
(W[t & 0x0F] = S(temp, 1)))
#define P(a, b, c, d, e, x) \
{ \
e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \
e += S(a, 5) + F(b, c, d) + K + x; \
b = S(b, 30); \
}
A = ctx->state[0];
@ -271,8 +268,7 @@ static const unsigned char sha1_padding[64] =
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
/*
* SHA-1 final digest
@ -283,8 +279,7 @@ void sha1_finish( sha1_context *ctx, unsigned char output[20] )
uint32_t high, low;
unsigned char msglen[8];
high = ( ctx->total[0] >> 29 )
| ( ctx->total[1] << 3 );
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
low = (ctx->total[0] << 3);
PUT_UINT32_BE(high, msglen, 0);

View file

@ -51,11 +51,11 @@ typedef struct
unsigned char ipad[64]; /*!< HMAC: inner padding */
unsigned char opad[64]; /*!< HMAC: outer padding */
}
sha1_context;
} sha1_context;
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
/**
@ -90,7 +90,8 @@ void sha1_process( sha1_context *ctx, const unsigned char data[64] );
#endif
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
/**

View file

@ -53,17 +53,16 @@
*/
#ifndef GET_UINT32_BE
#define GET_UINT32_BE(n, b, i) \
do { \
(n) = ( static_cast<uint32_t>((b)[(i) ]) << 24 ) \
| ( static_cast<uint32_t>((b)[(i) + 1]) << 16 ) \
| ( static_cast<uint32_t>((b)[(i) + 2]) << 8 ) \
| ( static_cast<uint32_t>((b)[(i) + 3]) );\
do \
{ \
(n) = (static_cast<uint32_t>((b)[(i)]) << 24) | (static_cast<uint32_t>((b)[(i) + 1]) << 16) | (static_cast<uint32_t>((b)[(i) + 2]) << 8) | (static_cast<uint32_t>((b)[(i) + 3])); \
} while (0)
#endif
#ifndef PUT_UINT32_BE
#define PUT_UINT32_BE(n, b, i) \
do { \
do \
{ \
(b)[(i)] = static_cast<unsigned char>((n) >> 24); \
(b)[(i) + 1] = static_cast<unsigned char>((n) >> 16); \
(b)[(i) + 2] = static_cast<unsigned char>((n) >> 8); \
@ -147,22 +146,70 @@ void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
#if !defined(MBEDTLS_SHA256_PROCESS_ALT)
static const uint32_t K[] =
{
0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2,
0x428A2F98,
0x71374491,
0xB5C0FBCF,
0xE9B5DBA5,
0x3956C25B,
0x59F111F1,
0x923F82A4,
0xAB1C5ED5,
0xD807AA98,
0x12835B01,
0x243185BE,
0x550C7DC3,
0x72BE5D74,
0x80DEB1FE,
0x9BDC06A7,
0xC19BF174,
0xE49B69C1,
0xEFBE4786,
0x0FC19DC6,
0x240CA1CC,
0x2DE92C6F,
0x4A7484AA,
0x5CB0A9DC,
0x76F988DA,
0x983E5152,
0xA831C66D,
0xB00327C8,
0xBF597FC7,
0xC6E00BF3,
0xD5A79147,
0x06CA6351,
0x14292967,
0x27B70A85,
0x2E1B2138,
0x4D2C6DFC,
0x53380D13,
0x650A7354,
0x766A0ABB,
0x81C2C92E,
0x92722C85,
0xA2BFE8A1,
0xA81A664B,
0xC24B8B70,
0xC76C51A3,
0xD192E819,
0xD6990624,
0xF40E3585,
0x106AA070,
0x19A4C116,
0x1E376C08,
0x2748774C,
0x34B0BCB5,
0x391C0CB3,
0x4ED8AA4A,
0x5B9CCA4F,
0x682E6FF3,
0x748F82EE,
0x78A5636F,
0x84C87814,
0x8CC70208,
0x90BEFFFA,
0xA4506CEB,
0xBEF9A3F7,
0xC67178F2,
};
#define SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
@ -180,15 +227,15 @@ static const uint32_t K[] =
#define R(t) \
( \
W[t] = S1(W[(t) - 2]) + W[(t) - 7] + \
S0(W[(t) - 15]) + W[(t) - 16] \
)
S0(W[(t) - 15]) + W[(t) - 16])
#define P(a, b, c, d, e, f, g, h, x, K) \
do \
{ \
temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x); \
temp2 = S2(a) + F0((a), (b), (c)); \
(d) += temp1; (h) = temp1 + temp2; \
(d) += temp1; \
(h) = temp1 + temp2; \
} while (0)
int mbedtls_internal_sha256_process(mbedtls_sha256_context* ctx,
@ -214,8 +261,15 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
P(A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], W[i], K[i]);
temp1 = A[7]; A[7] = A[6]; A[6] = A[5]; A[5] = A[4]; A[4] = A[3];
A[3] = A[2]; A[2] = A[1]; A[1] = A[0]; A[0] = temp1;
temp1 = A[7];
A[7] = A[6];
A[6] = A[5];
A[5] = A[4];
A[4] = A[3];
A[3] = A[2];
A[2] = A[1];
A[1] = A[0];
A[0] = temp1;
}
#else /* MBEDTLS_SHA256_SMALLER */
for (i = 0; i < 16; i++)
@ -362,8 +416,7 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
/*
* Add message length
*/
high = ( ctx->total[0] >> 29 )
| ( ctx->total[1] << 3 );
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
low = (ctx->total[0] << 3);
PUT_UINT32_BE(high, ctx->buffer, 56);

View file

@ -37,7 +37,8 @@
#define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA -0x0074 /**< SHA-256 input data was malformed. */
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
#if !defined(MBEDTLS_SHA256_ALT)
@ -58,8 +59,7 @@ typedef struct mbedtls_sha256_context
unsigned char buffer[64]; /*!< The data block being processed. */
int is224; /*!< Determines which function to use:
0: Use SHA-256, or 1: Use SHA-224. */
}
mbedtls_sha256_context;
} mbedtls_sha256_context;
#else /* MBEDTLS_SHA256_ALT */
#include "sha256_alt.h"

View file

@ -20,7 +20,10 @@ struct loaded_npdrm_keys
void install_decryption_key(u128 key)
{
dec_keys_pos.atomic_op([&](u64& pos) { dec_keys[pos++ % std::size(dec_keys)] = key; });
dec_keys_pos.atomic_op([&](u64& pos)
{
dec_keys[pos++ % std::size(dec_keys)] = key;
});
}
// TODO: Check if correct for ELF files usage
@ -84,20 +87,12 @@ struct EDATADecrypter final : fs::file_base
public:
EDATADecrypter(fs::file&& input, u128 dec_key = {}, std::string file_name = {}, bool is_key_final = true) noexcept
: m_edata_file(std::move(input))
, edata_file(m_edata_file)
, m_file_name(std::move(file_name))
, m_is_key_final(is_key_final)
, dec_key(dec_key)
: m_edata_file(std::move(input)), edata_file(m_edata_file), m_file_name(std::move(file_name)), m_is_key_final(is_key_final), dec_key(dec_key)
{
}
EDATADecrypter(const fs::file& input, u128 dec_key = {}, std::string file_name = {}, bool is_key_final = true) noexcept
: m_edata_file(fs::file{})
, edata_file(input)
, m_file_name(std::move(file_name))
, m_is_key_final(is_key_final)
, dec_key(dec_key)
: m_edata_file(fs::file{}), edata_file(input), m_file_name(std::move(file_name)), m_is_key_final(is_key_final), dec_key(dec_key)
{
}
@ -140,7 +135,8 @@ public:
const s64 new_pos =
whence == fs::seek_set ? offset :
whence == fs::seek_cur ? offset + pos :
whence == fs::seek_end ? offset + size() : -1;
whence == fs::seek_end ? offset + size() :
-1;
if (new_pos < 0)
{
@ -152,7 +148,10 @@ public:
return pos;
}
u64 size() override { return file_size; }
u64 size() override
{
return file_size;
}
fs::file_id get_id() override
{

View file

@ -17,8 +17,7 @@
LOG_CHANNEL(pkg_log, "PKG");
package_reader::package_reader(const std::string& path, fs::file file)
: m_path(path)
, m_file(std::move(file))
: m_path(path), m_file(std::move(file))
{
if (!m_file && !m_file.open(path))
{
@ -500,7 +499,9 @@ bool package_reader::set_decryption_key()
// TODO: Not all the keys seem to match the content types. I was only able to install a dlc (0x16) with PKG_AES_KEY_VITA_1
aes_context ctx;
aes_setkey_enc(&ctx, m_metadata.content_type == 0x15u ? PKG_AES_KEY_VITA_1 : m_metadata.content_type == 0x16u ? PKG_AES_KEY_VITA_2 : PKG_AES_KEY_VITA_3, 128);
aes_setkey_enc(&ctx, m_metadata.content_type == 0x15u ? PKG_AES_KEY_VITA_1 : m_metadata.content_type == 0x16u ? PKG_AES_KEY_VITA_2 :
PKG_AES_KEY_VITA_3,
128);
aes_crypt_ecb(&ctx, AES_ENCRYPT, reinterpret_cast<const uchar*>(&m_header.klicensee), m_dec_key.data());
return true;
}
@ -915,14 +916,12 @@ bool package_reader::fill_data(std::map<std::string, install_entry*>& all_instal
auto map_ptr = &*all_install_entries.try_emplace(true_path).first;
m_install_entries.push_back({
.weak_reference = map_ptr,
m_install_entries.push_back({.weak_reference = map_ptr,
.name = std::string(name),
.file_offset = entry.file_offset,
.file_size = entry.file_size,
.type = entry.type,
.pad = entry.pad
});
.pad = entry.pad});
if (map_ptr->second && !(entry.type & PKG_FILE_ENTRY_OVERWRITE))
{
@ -964,7 +963,8 @@ void package_reader::extract_worker()
}
return false;
}).first;
})
.first;
if (index >= m_install_entries.size())
{
@ -1038,9 +1038,7 @@ void package_reader::extract_worker()
usz m_pos;
explicit pkg_file_reader(std::function<u64(u64, void* buffer, u64)> read_func, const install_entry& entry) noexcept
: m_read_func(std::move(read_func))
, m_entry(entry)
, m_pos(0)
: m_read_func(std::move(read_func)), m_entry(entry), m_pos(0)
{
}
@ -1078,7 +1076,8 @@ void package_reader::extract_worker()
const s64 new_pos =
whence == fs::seek_set ? offset :
whence == fs::seek_cur ? offset + m_pos :
whence == fs::seek_end ? offset + size() : -1;
whence == fs::seek_end ? offset + size() :
-1;
if (new_pos < 0)
{
@ -1178,7 +1177,8 @@ void package_reader::extract_worker()
}
return read_size + size_cache_end;
}, entry);
},
entry);
fs::file in_data;
in_data.reset(std::move(reader));
@ -1373,7 +1373,8 @@ package_install_result package_reader::extract_data(std::deque<package_reader>&
void package_reader::archive_seek(const s64 new_offset, const fs::seek_mode damode)
{
if (m_file) m_file.seek(new_offset, damode);
if (m_file)
m_file.seek(new_offset, damode);
}
u64 package_reader::archive_read(void* data_ptr, const u64 num_bytes)

View file

@ -144,6 +144,7 @@ private:
}
return result;
}
public:
be_t<u32> drm_type{0};
be_t<u32> content_type{0};
@ -346,11 +347,20 @@ public:
error_dirty
};
bool is_valid() const { return m_is_valid; }
bool is_valid() const
{
return m_is_valid;
}
package_install_result check_target_app_version() const;
static package_install_result extract_data(std::deque<package_reader>& readers, std::deque<std::string>& bootable_paths);
const psf::registry& get_psf() const { return m_psf; }
result get_result() const { return m_result; };
const psf::registry& get_psf() const
{
return m_psf;
}
result get_result() const
{
return m_result;
};
int get_progress(int maximum = 100) const;

View file

@ -188,7 +188,6 @@ void WriteShdr(const fs::file& f, Elf32_Shdr& shdr)
Write32(f, shdr.sh_entsize);
}
void program_identification_header::Load(const fs::file& f)
{
program_authority_id = Read64(f);
@ -601,8 +600,7 @@ void ext_hdr::Load(const fs::file& f)
}
SCEDecrypter::SCEDecrypter(const fs::file& s)
: sce_f(s)
, data_buf_length(0)
: sce_f(s), data_buf_length(0)
{
}
@ -789,15 +787,15 @@ std::vector<fs::file> SCEDecrypter::MakeFile()
if (out_f.pos() != out_f.size())
fmt::throw_exception("MakeELF written bytes (%llu) does not equal buffer size (%llu).", out_f.pos(), out_f.size());
if (is_valid) vec.push_back(std::move(out_f));
if (is_valid)
vec.push_back(std::move(out_f));
}
return vec;
}
SELFDecrypter::SELFDecrypter(const fs::file& s)
: self_f(s)
, key_v()
: self_f(s), key_v()
{
}
@ -1257,7 +1255,8 @@ bool SELFDecrypter::GetKeyFromRap(const char* content_id, u8* npdrm_key)
{
self_log.fatal("Failed to locate the game license file: %s."
"\nEnsure the .rap license file is placed in the dev_hdd0/home/%s/exdata folder with a lowercase file extension."
"\nIf you need assistance on dumping the license file from your PS3, read our quickstart guide: https://rpcs3.net/quickstart", rap_path, Emu.GetUsr());
"\nIf you need assistance on dumping the license file from your PS3, read our quickstart guide: https://rpcs3.net/quickstart",
rap_path, Emu.GetUsr());
return false;
}
@ -1277,7 +1276,8 @@ bool SELFDecrypter::GetKeyFromRap(const char* content_id, u8* npdrm_key)
static bool IsSelfElf32(const fs::file& f)
{
if (!f) return false;
if (!f)
return false;
f.seek(0);

View file

@ -155,7 +155,6 @@ struct supplemental_header
void Show() const;
};
struct MetadataInfo
{
u8 key[0x10];
@ -265,9 +264,18 @@ struct Elf32_Ehdr
void Load(const fs::file& f);
static void Show() {}
bool IsLittleEndian() const { return e_data == 1; }
bool CheckMagic() const { return e_magic == 0x7F454C46; }
u32 GetEntry() const { return e_entry; }
bool IsLittleEndian() const
{
return e_data == 1;
}
bool CheckMagic() const
{
return e_magic == 0x7F454C46;
}
u32 GetEntry() const
{
return e_entry;
}
};
struct Elf32_Shdr
@ -329,8 +337,14 @@ struct Elf64_Ehdr
void Load(const fs::file& f);
static void Show() {}
bool CheckMagic() const { return e_magic == 0x7F454C46; }
u64 GetEntry() const { return e_entry; }
bool CheckMagic() const
{
return e_magic == 0x7F454C46;
}
u64 GetEntry() const
{
return e_entry;
}
};
struct Elf64_Shdr
@ -377,7 +391,10 @@ struct SceHeader
void Load(const fs::file& f);
static void Show() {}
bool CheckMagic() const { return se_magic == 0x53434500; }
bool CheckMagic() const
{
return se_magic == 0x53434500;
}
};
struct ext_hdr

View file

@ -64,7 +64,6 @@ void hex_to_bytes(unsigned char* data, const char* hex_str, unsigned int str_len
}
}
// Crypto functions (AES128-CBC, AES128-ECB, SHA1-HMAC and AES-CMAC).
void aescbc128_decrypt(unsigned char* key, unsigned char* iv, unsigned char* in, unsigned char* out, usz len)
{
@ -166,7 +165,6 @@ void mbedtls_zeroize(void *v, size_t n)
(void)unop_memset(v, 0, n);
}
// SC passphrase crypto
void sc_form_key(const u8* sc_key, const std::array<u8, PASSPHRASE_KEY_LEN>& laid_paid, u8* key)

View file

@ -8,7 +8,10 @@
#include <stdlib.h>
enum { CRYPTO_MAX_PATH = 4096 };
enum
{
CRYPTO_MAX_PATH = 4096
};
char* extract_file_name(const char* file_path, char real_file_name[CRYPTO_MAX_PATH]);

View file

@ -49,7 +49,6 @@ enum class AudioStateEvent : u32
class AudioBackend
{
public:
struct VolumeParam
{
f32 initial_volume = 1.0f;
@ -93,7 +92,10 @@ public:
virtual f64 GetCallbackFrameLen() = 0;
// Returns true if audio is currently being played, false otherwise. Reflects end result of Play() and Pause() calls.
virtual bool IsPlaying() { return m_playing; }
virtual bool IsPlaying()
{
return m_playing;
}
// Start playing enqueued data.
virtual void Play() = 0;
@ -105,17 +107,26 @@ public:
* This virtual method should be reimplemented if backend can fail to be initialized under non-error conditions
* eg. when there is no audio devices attached
*/
virtual bool Initialized() { return true; }
virtual bool Initialized()
{
return true;
}
/*
* This virtual method should be reimplemented if backend can fail during normal operation
*/
virtual bool Operational() { return true; }
virtual bool Operational()
{
return true;
}
/*
* This virtual method should be reimplemented if backend can report device changes
*/
virtual bool DefaultDeviceChanged() { return false; }
virtual bool DefaultDeviceChanged()
{
return false;
}
/*
* Helper methods
@ -184,7 +195,8 @@ public:
static void downmix(u32 sample_cnt, const f32* src, f32* dst)
{
const u32 dst_ch_cnt = default_layout_channel_count(dst_layout);
if (static_cast<u32>(src_ch_cnt) <= dst_ch_cnt) fmt::throw_exception("src channel count must be bigger than dst channel count");
if (static_cast<u32>(src_ch_cnt) <= dst_ch_cnt)
fmt::throw_exception("src channel count must be bigger than dst channel count");
static constexpr f32 center_coef = std::numbers::sqrt2_v<f32> / 2;
static constexpr f32 surround_coef = std::numbers::sqrt2_v<f32> / 2;
@ -385,6 +397,5 @@ protected:
bool m_playing = false;
private:
static constexpr f32 VOLUME_CHANGE_DURATION = 0.016f; // sec
};

View file

@ -34,12 +34,7 @@ struct WAVHeader
FMTHeader() = default;
FMTHeader(AudioChannelCnt ch, AudioFreq sample_rate, AudioSampleSize sample_size)
: AudioFormat(sample_size == AudioSampleSize::FLOAT ? 3 : 1)
, NumChannels(static_cast<u16>(ch))
, SampleRate(static_cast<u32>(sample_rate))
, ByteRate(SampleRate * NumChannels * static_cast<u32>(sample_size))
, BlockAlign(NumChannels * static_cast<u32>(sample_size))
, BitsPerSample(static_cast<u32>(sample_size) * 8)
: AudioFormat(sample_size == AudioSampleSize::FLOAT ? 3 : 1), NumChannels(static_cast<u16>(ch)), SampleRate(static_cast<u32>(sample_rate)), ByteRate(SampleRate * NumChannels * static_cast<u32>(sample_size)), BlockAlign(NumChannels * static_cast<u32>(sample_size)), BitsPerSample(static_cast<u32>(sample_size) * 8)
{
}
} FMT;
@ -64,10 +59,7 @@ struct WAVHeader
WAVHeader() = default;
WAVHeader(AudioChannelCnt ch, AudioFreq sample_rate, AudioSampleSize sample_size)
: RIFF(sizeof(RIFFHeader) + sizeof(FMTHeader))
, FMT(ch, sample_rate, sample_size)
, FACT(0)
, Size(0)
: RIFF(sizeof(RIFFHeader) + sizeof(FMTHeader)), FMT(ch, sample_rate, sample_size), FACT(0), Size(0)
{
}
};
@ -85,6 +77,12 @@ public:
void Close();
void WriteData(const void* buffer, u32 size);
u16 GetCh() const { return m_header.FMT.NumChannels; }
u16 GetSampleSize() const { return m_header.FMT.BitsPerSample / 8; }
u16 GetCh() const
{
return m_header.FMT.NumChannels;
}
u16 GetSampleSize() const
{
return m_header.FMT.BitsPerSample / 8;
}
};

View file

@ -6,7 +6,7 @@
#include "Emu/Audio/audio_device_enumerator.h"
#ifdef _WIN32
#include <Windows.h>
#include <windows.h>
#include <system_error>
#endif
@ -112,8 +112,10 @@ bool CubebBackend::Open(std::string_view dev_id, AudioFreq freq, AudioSampleSize
const bool use_default_device = dev_id.empty() || dev_id == audio_device_enumerator::DEFAULT_DEV_ID;
if (use_default_device) Cubeb.notice("Trying to open default device");
else Cubeb.notice("Trying to open device with dev_id='%s'", dev_id);
if (use_default_device)
Cubeb.notice("Trying to open default device");
else
Cubeb.notice("Trying to open device with dev_id='%s'", dev_id);
device_handle device = GetDevice(use_default_device ? "" : dev_id);
@ -240,7 +242,8 @@ void CubebBackend::Play()
return;
}
if (m_playing) return;
if (m_playing)
return;
std::lock_guard lock(m_cb_mutex);
m_playing = true;
@ -254,7 +257,8 @@ void CubebBackend::Pause()
return;
}
if (!m_playing) return;
if (!m_playing)
return;
std::lock_guard lock(m_cb_mutex);
m_playing = false;
@ -283,8 +287,10 @@ CubebBackend::device_handle CubebBackend::GetDevice(std::string_view dev_id)
{
const bool default_dev = dev_id.empty();
if (default_dev) Cubeb.notice("Searching for default device");
else Cubeb.notice("Searching for device with dev_id='%s'", dev_id);
if (default_dev)
Cubeb.notice("Searching for default device");
else
Cubeb.notice("Searching for device with dev_id='%s'", dev_id);
cubeb_device_collection dev_collection{};
if (int err = cubeb_enumerate_devices(m_ctx, CUBEB_DEVICE_TYPE_OUTPUT, &dev_collection))
@ -368,8 +374,7 @@ CubebBackend::device_handle CubebBackend::GetDefaultDeviceAlt(AudioFreq freq, Au
.rate = static_cast<u32>(freq),
.channels = static_cast<u32>(ch_cnt),
.layout = CUBEB_LAYOUT_UNDEFINED,
.prefs = CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING
};
.prefs = CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING};
u32 min_latency{};
if (int err = cubeb_get_min_latency(m_ctx, &param, &min_latency))
@ -379,7 +384,10 @@ CubebBackend::device_handle CubebBackend::GetDefaultDeviceAlt(AudioFreq freq, Au
}
cubeb_stream* tmp_stream{};
static auto dummy_data_cb = [](cubeb_stream*, void*, void const*, void*, long) -> long { return 0; };
static auto dummy_data_cb = [](cubeb_stream*, void*, void const*, void*, long) -> long
{
return 0;
};
static auto dummy_state_cb = [](cubeb_stream*, void*, cubeb_state) {};
if (int err = cubeb_stream_init(m_ctx, &tmp_stream, "Default device detector", nullptr, nullptr, nullptr, &param, min_latency, dummy_data_cb, dummy_state_cb, nullptr))

View file

@ -14,7 +14,10 @@ public:
CubebBackend(const CubebBackend&) = delete;
CubebBackend& operator=(const CubebBackend&) = delete;
std::string_view GetName() const override { return "Cubeb"sv; }
std::string_view GetName() const override
{
return "Cubeb"sv;
}
bool Initialized() override;
bool Operational() override;

View file

@ -3,7 +3,7 @@
#include <algorithm>
#ifdef _WIN32
#include <Windows.h>
#include <windows.h>
#include <system_error>
#endif
@ -81,8 +81,7 @@ std::vector<audio_device_enumerator::audio_device> cubeb_enumerator::get_output_
{
.id = std::string{dev_info.device_id},
.name = std::string{dev_info.friendly_name},
.max_ch = dev_info.max_channels
};
.max_ch = dev_info.max_channels};
if (dev.id.empty())
{

View file

@ -7,14 +7,12 @@
class cubeb_enumerator final : public audio_device_enumerator
{
public:
cubeb_enumerator();
~cubeb_enumerator() override;
std::vector<audio_device> get_output_devices() override;
private:
cubeb* ctx{};
#ifdef _WIN32
bool com_init_success = false;

View file

@ -54,7 +54,8 @@ void FAudioBackend::Play()
return;
}
if (m_playing) return;
if (m_playing)
return;
std::lock_guard lock(m_cb_mutex);
m_playing = true;
@ -68,7 +69,8 @@ void FAudioBackend::Pause()
return;
}
if (!m_playing) return;
if (!m_playing)
return;
{
std::lock_guard lock(m_cb_mutex);

View file

@ -17,7 +17,10 @@ public:
FAudioBackend(const FAudioBackend&) = delete;
FAudioBackend& operator=(const FAudioBackend&) = delete;
std::string_view GetName() const override { return "FAudio"sv; }
std::string_view GetName() const override
{
return "FAudio"sv;
}
bool Initialized() override;
bool Operational() override;

View file

@ -68,8 +68,7 @@ std::vector<audio_device_enumerator::audio_device> faudio_enumerator::get_output
{
.id = std::to_string(dev_idx),
.name = utf16_to_utf8(std::bit_cast<char16_t*>(&dev_info.DisplayName[0])),
.max_ch = dev_info.OutputFormat.Format.nChannels
};
.max_ch = dev_info.OutputFormat.Format.nChannels};
if (dev.name.empty())
{

View file

@ -10,13 +10,11 @@
class faudio_enumerator final : public audio_device_enumerator
{
public:
faudio_enumerator();
~faudio_enumerator() override;
std::vector<audio_device> get_output_devices() override;
private:
FAudio* instance{};
};

View file

@ -8,20 +8,38 @@ public:
NullAudioBackend() {}
~NullAudioBackend() {}
std::string_view GetName() const override { return "Null"sv; }
std::string_view GetName() const override
{
return "Null"sv;
}
bool Open(std::string_view /* dev_id */, AudioFreq /* freq */, AudioSampleSize /* sample_size */, AudioChannelCnt /* ch_cnt */, audio_channel_layout /*layout*/) override
{
Close();
return true;
}
void Close() override { m_playing = false; }
void Close() override
{
m_playing = false;
}
f64 GetCallbackFrameLen() override { return 0.01; };
f64 GetCallbackFrameLen() override
{
return 0.01;
};
void Play() override { m_playing = true; }
void Pause() override { m_playing = false; }
bool IsPlaying() override { return m_playing; }
void Play() override
{
m_playing = true;
}
void Pause() override
{
m_playing = false;
}
bool IsPlaying() override
{
return m_playing;
}
private:
bool m_playing = false;

View file

@ -5,9 +5,11 @@
class null_enumerator final : public audio_device_enumerator
{
public:
null_enumerator() {};
~null_enumerator() override {};
std::vector<audio_device> get_output_devices() override { return {}; }
std::vector<audio_device> get_output_devices() override
{
return {};
}
};

View file

@ -9,7 +9,7 @@
#include "Utilities/StrUtil.h"
#include "XAudio2Backend.h"
#include <Windows.h>
#include <windows.h>
#include <system_error>
#ifndef XAUDIO2_USE_DEFAULT_PROCESSOR
@ -135,7 +135,8 @@ void XAudio2Backend::Play()
return;
}
if (m_playing) return;
if (m_playing)
return;
std::lock_guard lock(m_cb_mutex);
m_playing = true;
@ -184,7 +185,8 @@ void XAudio2Backend::Pause()
return;
}
if (!m_playing) return;
if (!m_playing)
return;
{
std::lock_guard lock(m_cb_mutex);

View file

@ -20,7 +20,10 @@ public:
XAudio2Backend(const XAudio2Backend&) = delete;
XAudio2Backend& operator=(const XAudio2Backend&) = delete;
std::string_view GetName() const override { return "XAudio2"sv; }
std::string_view GetName() const override
{
return "XAudio2"sv;
}
bool Initialized() override;
bool Operational() override;
@ -68,13 +71,36 @@ private:
void OnCriticalError(HRESULT Error) override;
// IMMNotificationClient callbacks
IFACEMETHODIMP_(ULONG) AddRef() override { return 1; };
IFACEMETHODIMP_(ULONG) Release() override { return 1; };
IFACEMETHODIMP QueryInterface(REFIID /*iid*/, void** /*object*/) override { return E_NOINTERFACE; };
IFACEMETHODIMP OnPropertyValueChanged(LPCWSTR /*device_id*/, const PROPERTYKEY /*key*/) override { return S_OK; };
IFACEMETHODIMP OnDeviceAdded(LPCWSTR /*device_id*/) override { return S_OK; };
IFACEMETHODIMP OnDeviceRemoved(LPCWSTR /*device_id*/) override { return S_OK; };
IFACEMETHODIMP OnDeviceStateChanged(LPCWSTR /*device_id*/, DWORD /*new_state*/) override { return S_OK; };
IFACEMETHODIMP_(ULONG)
AddRef() override
{
return 1;
};
IFACEMETHODIMP_(ULONG)
Release() override
{
return 1;
};
IFACEMETHODIMP QueryInterface(REFIID /*iid*/, void** /*object*/) override
{
return E_NOINTERFACE;
};
IFACEMETHODIMP OnPropertyValueChanged(LPCWSTR /*device_id*/, const PROPERTYKEY /*key*/) override
{
return S_OK;
};
IFACEMETHODIMP OnDeviceAdded(LPCWSTR /*device_id*/) override
{
return S_OK;
};
IFACEMETHODIMP OnDeviceRemoved(LPCWSTR /*device_id*/) override
{
return S_OK;
};
IFACEMETHODIMP OnDeviceStateChanged(LPCWSTR /*device_id*/, DWORD /*new_state*/) override
{
return S_OK;
};
IFACEMETHODIMP OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR new_default_device_id) override;
void CloseUnlocked();

View file

@ -8,7 +8,7 @@
#include <algorithm>
#include <wrl/client.h>
#include <Windows.h>
#include <windows.h>
#include <system_error>
#include <mmdeviceapi.h>
#include <Functiondiscoverykeys_devpkey.h>

View file

@ -9,7 +9,6 @@
class xaudio2_enumerator final : public audio_device_enumerator
{
public:
xaudio2_enumerator();
~xaudio2_enumerator() override;

View file

@ -7,7 +7,6 @@
class audio_device_enumerator
{
public:
static constexpr std::string_view DEFAULT_DEV_ID = "@@@default@@@";
struct audio_device

View file

@ -24,16 +24,18 @@ namespace audio
void change_volume(s32 delta)
{
// Ignore if muted
if (g_fxo->get<audio_fxo>().audio_muted) return;
if (g_fxo->get<audio_fxo>().audio_muted)
return;
const s32 old_volume = g_cfg.audio.volume;
const s32 new_volume = old_volume + delta;
if (old_volume == new_volume) return;
if (old_volume == new_volume)
return;
g_cfg.audio.volume.set(std::clamp<s32>(new_volume, g_cfg.audio.volume.min, g_cfg.audio.volume.max));
Emu.GetCallbacks().update_emu_settings();
rsx::overlays::queue_message(get_localized_string(localized_string_id::AUDIO_CHANGED, fmt::format("%d%%", g_cfg.audio.volume.get()).c_str()), 3'000'000);
}
}
} // namespace audio

View file

@ -11,4 +11,4 @@ namespace audio
void toggle_mute();
void change_volume(s32 delta);
}
} // namespace audio

View file

@ -53,8 +53,7 @@ namespace aarch64
{
int arg_id = 0;
fmt_replacement_list_t repl = {
{ "{0}", arg0.to_string(&arg_id) }
};
{"{0}", arg0.to_string(&arg_id)}};
compiled_instruction_t i{};
i.asm_ = fmt::replace_all(inst, repl);
@ -135,48 +134,42 @@ namespace aarch64
{
return Arg{
.type = ArgType::LLVMInt,
.value = v
};
.value = v};
}
UASM::Arg UASM::Imm(s64 v)
{
return Arg{
.type = ArgType::Immediate,
.imm = v
};
.imm = v};
}
UASM::Arg UASM::Reg(gpr reg)
{
return Arg{
.type = ArgType::Register,
.reg = reg
};
.reg = reg};
}
UASM::Arg UASM::Reg(spr reg)
{
return Arg{
.type = ArgType::SRegister,
.sreg = reg
};
.sreg = reg};
}
UASM::Arg UASM::Ptr(llvm::Value* v)
{
return Arg{
.type = ArgType::LLVMPtr,
.value = v
};
.value = v};
}
UASM::Arg UASM::Var(llvm::Value* v)
{
return Arg{
.type = ArgType::LLVMReg,
.value = v
};
.value = v};
}
void UASM::mov(gpr dst, gpr src)
@ -295,4 +288,4 @@ namespace aarch64
return std::string("$") + std::to_string(*id++);
}
}
}
} // namespace aarch64

Some files were not shown because too many files have changed in this diff Show more