diff --git a/.clang-tidy b/.clang-tidy index da3d27f7..2e100510 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,7 +2,7 @@ Checks: 'clang-diagnostic-*,clang-analyzer-*,*, android-*, -bugprone-bool-pointer-implicit-conversion, -cert-env33-c, -cert-dcl50-cpp, -cert-dcl59-cpp, -cppcoreguidelines-no-malloc, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-type-const-cast, -cppcoreguidelines-pro-type-cstyle-cast, -cppcoreguidelines-pro-type-reinterpret-cast, -cppcoreguidelines-pro-type-union-access, -cppcoreguidelines-pro-type-vararg, -cppcoreguidelines-special-member-functions, -fuchsia-*, -google-*, google-default-arguments, google-explicit-constructor, google-runtime-member-string-references, google-runtime-operator, -hicpp-braces-around-statements, -hicpp-braces-around-statements, -hicpp-named-parameter, -hicpp-no-array-decay, -hicpp-no-assembler, -hicpp-no-malloc, -hicpp-function-size, -hicpp-special-member-functions, -hicpp-vararg, -llvm-*, -objc-*, -readability-else-after-return, -readability-implicit-bool-conversion, -readability-named-parameter, -readability-simplify-boolean-expr, -readability-braces-around-statements, - -readability-identifier-naming, -readability-function-size, -readability-redundant-member-init, -misc-bool-pointer-implicit-conversion, -misc-definitions-in-headers, -misc-unused-alias-decls, -misc-unused-parameters, -misc-unused-using-decls, -modernize-use-using, -modernize-use-default-member-init, -clang-diagnostic-*, -clang-analyzer-*, -hicpp-signed-bitwise' + -readability-identifier-naming, -readability-function-size, -readability-redundant-member-init, -misc-bool-pointer-implicit-conversion, -misc-definitions-in-headers, -misc-unused-alias-decls, -misc-unused-parameters, -misc-unused-using-decls, -modernize-use-using, -modernize-use-default-member-init, -clang-diagnostic-*, -clang-analyzer-*, -hicpp-signed-bitwise, -misc-non-private-member-variables-in-classes' WarningsAsErrors: '' HeaderFilterRegex: '' AnalyzeTemporaryDtors: false diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8c90edf5..43655bb9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,7 +12,7 @@ Debug("svcSleepThread: Yielding thread: {}", in); break; default: + struct timespec spec = { + .tv_sec = static_cast(state.ctx->registers.x0 / 1000000000), + .tv_nsec = static_cast(state.ctx->registers.x0 % 1000000000) + }; + nanosleep(&spec, nullptr); state.logger->Debug("svcSleepThread: Thread sleeping for {} ns", in); } } diff --git a/app/src/main/cpp/skyline/kernel/types/KPrivateMemory.cpp b/app/src/main/cpp/skyline/kernel/types/KPrivateMemory.cpp index 28c6662b..cb62a99b 100644 --- a/app/src/main/cpp/skyline/kernel/types/KPrivateMemory.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KPrivateMemory.cpp @@ -19,10 +19,6 @@ namespace skyline::kernel::type { this->address = fregs.x0; } - u64 RemapPrivateFunc(u64 address, size_t oldSize, size_t size, u64 flags) { - return reinterpret_cast(mremap(reinterpret_cast(address), oldSize, size, static_cast(flags))); - } - u64 KPrivateMemory::Resize(size_t newSize, bool canMove) { Registers fregs{}; fregs.x0 = address; @@ -38,10 +34,6 @@ namespace skyline::kernel::type { return address; } - u64 UpdatePermissionPrivateFunc(u64 address, size_t size, u64 perms) { - return static_cast(mprotect(reinterpret_cast(address), size, static_cast(perms))); - } - void KPrivateMemory::UpdatePermission(memory::Permission permission) { Registers fregs{}; fregs.x0 = address; @@ -73,10 +65,6 @@ namespace skyline::kernel::type { return info; } - u64 UnmapPrivateFunc(u64 address, size_t size) { - return static_cast(munmap(reinterpret_cast(address), size)); - } - KPrivateMemory::~KPrivateMemory() { try { if (state.process) { diff --git a/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp b/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp index 6fb21d1d..e229fbc7 100644 --- a/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp @@ -6,10 +6,6 @@ #include namespace skyline::kernel::type { - u64 MapSharedFunc(u64 address, size_t size, u64 perms, u64 fd) { - return reinterpret_cast(mmap(reinterpret_cast(address), size, static_cast(perms), MAP_SHARED | ((address) ? MAP_FIXED : 0), static_cast(fd), 0)); - } - KSharedMemory::KSharedMemory(const DeviceState &state, u64 address, size_t size, const memory::Permission permission, memory::Type type) : type(type), KObject(state, KType::KSharedMemory) { fd = ASharedMemory_create("", size); if (fd < 0) @@ -35,36 +31,13 @@ namespace skyline::kernel::type { return fregs.x0; } - u64 UnmapSharedFunc(u64 address, size_t size) { - return static_cast(munmap(reinterpret_cast(address), size)); - } - - KSharedMemory::~KSharedMemory() { - try { - if (guest.valid() && state.process) { - Registers fregs{}; - fregs.x0 = guest.address; - fregs.x1 = guest.size; - fregs.x8 = __NR_munmap; - state.nce->ExecuteFunction(ThreadCall::Syscall, fregs, state.process->pid); - } - if (kernel.valid()) - UnmapSharedFunc(kernel.address, kernel.size); - } catch (const std::exception &) { - } - close(fd); - } - - u64 RemapSharedFunc(u64 address, size_t oldSize, size_t size) { - return reinterpret_cast(mremap(reinterpret_cast(address), oldSize, size, 0)); - } - void KSharedMemory::Resize(size_t size) { if (guest.valid()) { Registers fregs{}; fregs.x0 = guest.address; fregs.x1 = guest.size; fregs.x2 = size; + fregs.x8 = __NR_mremap; state.nce->ExecuteFunction(ThreadCall::Syscall, fregs, state.thread->pid); if (fregs.x0 < 0) throw exception("An error occurred while remapping shared region in child process"); @@ -77,16 +50,13 @@ namespace skyline::kernel::type { } } - u64 UpdatePermissionSharedFunc(u64 address, size_t size, u64 perms) { - return static_cast(mprotect(reinterpret_cast(address), size, static_cast(perms))); - } - void KSharedMemory::UpdatePermission(memory::Permission permission, bool host) { if (guest.valid() && !host) { Registers fregs{}; fregs.x0 = guest.address; fregs.x1 = guest.size; fregs.x2 = static_cast(guest.permission.Get()); + fregs.x8 = __NR_mprotect; state.nce->ExecuteFunction(ThreadCall::Syscall, fregs, state.thread->pid); if (fregs.x0 < 0) throw exception("An error occurred while updating shared region's permissions in child process"); @@ -113,4 +83,20 @@ namespace skyline::kernel::type { info.deviceRefCount = deviceRefCount; return info; } + + KSharedMemory::~KSharedMemory() { + try { + if (guest.valid() && state.process) { + Registers fregs{}; + fregs.x0 = guest.address; + fregs.x1 = guest.size; + fregs.x8 = __NR_munmap; + state.nce->ExecuteFunction(ThreadCall::Syscall, fregs, state.process->pid); + } + if (kernel.valid()) + munmap(reinterpret_cast(kernel.address), kernel.size); + } catch (const std::exception &) { + } + close(fd); + } }; diff --git a/app/src/main/cpp/skyline/kernel/types/KTransferMemory.cpp b/app/src/main/cpp/skyline/kernel/types/KTransferMemory.cpp index 6e6b3b47..fb19ae45 100644 --- a/app/src/main/cpp/skyline/kernel/types/KTransferMemory.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KTransferMemory.cpp @@ -4,10 +4,6 @@ #include namespace skyline::kernel::type { - u64 MapTransferFunc(u64 address, size_t size, u64 perms) { - return reinterpret_cast(mmap(reinterpret_cast(address), size, static_cast(perms), MAP_ANONYMOUS | MAP_PRIVATE | ((address) ? MAP_FIXED : 0), -1, 0)); - } - KTransferMemory::KTransferMemory(const DeviceState &state, pid_t pid, u64 address, size_t size, const memory::Permission permission) : owner(pid), cSize(size), permission(permission), KObject(state, KType::KTransferMemory) { if (pid) { Registers fregs{}; @@ -43,7 +39,7 @@ namespace skyline::kernel::type { throw exception("An error occurred while mapping transfer memory in child process"); address = fregs.x0; } else { - address = MapTransferFunc(address, size, static_cast(permission.Get())); + address = reinterpret_cast(mmap(reinterpret_cast(address), size, permission.Get(), MAP_ANONYMOUS | MAP_PRIVATE | ((address) ? MAP_FIXED : 0), -1, 0)); if (reinterpret_cast(address) == MAP_FAILED) throw exception("An error occurred while mapping transfer memory in kernel"); } @@ -94,6 +90,7 @@ namespace skyline::kernel::type { Registers fregs{}; fregs.x0 = cAddress; fregs.x1 = cSize; + fregs.x8 = __NR_munmap; state.nce->ExecuteFunction(ThreadCall::Syscall, fregs, state.process->pid); } } catch (const std::exception &) { diff --git a/app/src/main/cpp/skyline/nce.cpp b/app/src/main/cpp/skyline/nce.cpp index 6158b78f..793ffd74 100644 --- a/app/src/main/cpp/skyline/nce.cpp +++ b/app/src/main/cpp/skyline/nce.cpp @@ -139,7 +139,8 @@ namespace skyline { if (ctx->sp) regStr += fmt::format("\nStack Pointer: 0x{:X}", ctx->sp); for (u16 index = 0; index < constant::NumRegs - 1; index += 2) { - regStr += fmt::format("\nX{}: 0x{:X}, X{}: 0x{:X}", index, ctx->registers.regs[index], index + 1, ctx->registers.regs[index + 1]); + auto xStr = index < 10 ? " X" : "X"; + regStr += fmt::format("\n{}{}: 0x{:<16X} {}{}: 0x{:X}", xStr, index, ctx->registers.regs[index], xStr, index + 1, ctx->registers.regs[index + 1]); } if (numHist) { state.logger->Debug("Process Trace:{}", trace); diff --git a/app/src/main/cpp/skyline/nce/guest.cpp b/app/src/main/cpp/skyline/nce/guest.cpp index 6d019012..8f4c1126 100644 --- a/app/src/main/cpp/skyline/nce/guest.cpp +++ b/app/src/main/cpp/skyline/nce/guest.cpp @@ -112,7 +112,7 @@ namespace skyline::guest { "MOV LR, SP\n\t" "SVC #0\n\t" "MOV SP, LR\n\t" - "LDR LR, [SP], #16":: : "x0", "x1", "x2", "x3", "x4", "x5", "x8"); + "LDR LR, [SP], #16" :: : "x0", "x1", "x2", "x3", "x4", "x5", "x8"); break; } default: { @@ -120,8 +120,8 @@ namespace skyline::guest { .tv_sec = static_cast(ctx->registers.x0 / 1000000000), .tv_nsec = static_cast(ctx->registers.x0 % 1000000000) }; - volatile register __unused timespec *specPtr asm("x0") = &spec; - asm("MOV X1, XZR\n\t" + asm("MOV X0, %0\n\t" + "MOV X1, XZR\n\t" "MOV X2, XZR\n\t" "MOV X3, XZR\n\t" "MOV X4, XZR\n\t" @@ -131,11 +131,11 @@ namespace skyline::guest { "MOV LR, SP\n\t" "SVC #0\n\t" "MOV SP, LR\n\t" - "LDR LR, [SP], #16":: : "x0", "x1", "x2", "x3", "x4", "x5", "x8"); + "LDR LR, [SP], #16" :: "r"(&spec) : "x0", "x1", "x2", "x3", "x4", "x5", "x8"); } } return; - } else if (svc == 0x1E) { + } else if (svc == 0x1E) { // svcGetSystemTick asm("STP X1, X2, [SP, #-16]!\n\t" "STR Q0, [SP, #-16]!\n\t" "STR Q1, [SP, #-16]!\n\t" @@ -153,7 +153,7 @@ namespace skyline::guest { "LDR Q2, [SP], #16\n\t" "LDR Q1, [SP], #16\n\t" "LDR Q0, [SP], #16\n\t" - "LDP X1, X2, [SP], #16"::"r"(ctx->registers.x0)); + "LDP X1, X2, [SP], #16" :: "r"(ctx->registers.x0)); return; } while (true) { diff --git a/app/src/main/cpp/skyline/services/am/appletController.cpp b/app/src/main/cpp/skyline/services/am/appletController.cpp index 5d868a0c..478f3885 100644 --- a/app/src/main/cpp/skyline/services/am/appletController.cpp +++ b/app/src/main/cpp/skyline/services/am/appletController.cpp @@ -21,7 +21,7 @@ namespace skyline::service::am { void ICommonStateGetter::GetEventHandle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto handle = state.process->InsertItem(messageEvent); - state.logger->Debug("Event Handle: 0x{:X}", handle); + state.logger->Debug("Applet Event Handle: 0x{:X}", handle); response.copyHandles.push_back(handle); } diff --git a/app/src/main/cpp/skyline/services/nvnflinger/dispdrv.cpp b/app/src/main/cpp/skyline/services/nvnflinger/dispdrv.cpp index 61594196..786ae841 100644 --- a/app/src/main/cpp/skyline/services/nvnflinger/dispdrv.cpp +++ b/app/src/main/cpp/skyline/services/nvnflinger/dispdrv.cpp @@ -63,7 +63,7 @@ namespace skyline::service::nvnflinger { void dispdrv::GetNativeHandle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { handle_t handle = state.process->InsertItem(state.gpu->bufferEvent); - state.logger->Debug("BufferEvent Handle: 0x{:X}", handle); + state.logger->Debug("Display Buffer Event Handle: 0x{:X}", handle); response.copyHandles.push_back(handle); response.Push(constant::status::Success); } diff --git a/app/src/main/cpp/skyline/services/vi/vi_m.cpp b/app/src/main/cpp/skyline/services/vi/vi_m.cpp index bede4b77..f125b54b 100644 --- a/app/src/main/cpp/skyline/services/vi/vi_m.cpp +++ b/app/src/main/cpp/skyline/services/vi/vi_m.cpp @@ -115,9 +115,7 @@ namespace skyline::service::vi { {0x908, SFUNC(IDisplayService::CreateStrayLayer)} }) {} - void ISystemDisplayService::SetLayerZ(skyline::kernel::type::KSession &session, skyline::kernel::ipc::IpcRequest &request, skyline::kernel::ipc::IpcResponse &response) { - response.Push(constant::status::Success); - } + void ISystemDisplayService::SetLayerZ(skyline::kernel::type::KSession &session, skyline::kernel::ipc::IpcRequest &request, skyline::kernel::ipc::IpcResponse &response) {} IManagerDisplayService::IManagerDisplayService(const DeviceState &state, ServiceManager &manager) : IDisplayService(state, manager, Service::vi_IManagerDisplayService, { {0x7DA, SFUNC(IManagerDisplayService::CreateManagedLayer)}, @@ -144,7 +142,5 @@ namespace skyline::service::vi { response.Push(constant::status::Success); } - void IManagerDisplayService::AddToLayerStack(skyline::kernel::type::KSession &session, skyline::kernel::ipc::IpcRequest &request, skyline::kernel::ipc::IpcResponse &response) { - response.Push(constant::status::Success); - } + void IManagerDisplayService::AddToLayerStack(skyline::kernel::type::KSession &session, skyline::kernel::ipc::IpcRequest &request, skyline::kernel::ipc::IpcResponse &response) {} }