From 70d1b4994cfcb888f03518d81782026ff790f120 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 24 Oct 2021 20:45:29 +0100 Subject: [PATCH] Enable Wconversion and fix warnings produced --- app/CMakeLists.txt | 2 +- app/src/main/cpp/emu_jni.cpp | 12 +++--- app/src/main/cpp/loader_jni.cpp | 4 +- app/src/main/cpp/skyline/audio.cpp | 4 +- app/src/main/cpp/skyline/common.h | 2 +- app/src/main/cpp/skyline/common/base.h | 8 ++-- .../main/cpp/skyline/common/circular_buffer.h | 14 +++---- app/src/main/cpp/skyline/common/signal.cpp | 10 ++--- app/src/main/cpp/skyline/common/span.h | 2 +- app/src/main/cpp/skyline/common/utils.h | 30 +++++++------- .../main/cpp/skyline/crypto/aes_cipher.cpp | 2 +- app/src/main/cpp/skyline/crypto/key_store.cpp | 4 +- app/src/main/cpp/skyline/gpu.cpp | 4 +- .../gpu/interconnect/command_nodes.cpp | 6 +-- .../gpu/interconnect/graphics_context.h | 9 ++-- .../cpp/skyline/gpu/presentation_engine.cpp | 12 +++--- .../cpp/skyline/gpu/presentation_engine.h | 2 +- app/src/main/cpp/skyline/input/npad.cpp | 6 +-- .../main/cpp/skyline/input/npad_device.cpp | 5 ++- app/src/main/cpp/skyline/input/touch.cpp | 10 ++--- app/src/main/cpp/skyline/jvm.cpp | 10 ++--- app/src/main/cpp/skyline/jvm.h | 2 +- app/src/main/cpp/skyline/kernel/ipc.cpp | 4 +- app/src/main/cpp/skyline/kernel/ipc.h | 2 +- app/src/main/cpp/skyline/kernel/memory.cpp | 12 +++--- app/src/main/cpp/skyline/kernel/scheduler.cpp | 2 +- app/src/main/cpp/skyline/kernel/scheduler.h | 10 ++--- app/src/main/cpp/skyline/kernel/svc.cpp | 40 +++++++++--------- .../cpp/skyline/kernel/types/KProcess.cpp | 8 ++-- .../main/cpp/skyline/kernel/types/KProcess.h | 2 +- .../main/cpp/skyline/kernel/types/KThread.cpp | 8 ++-- .../main/cpp/skyline/kernel/types/KThread.h | 10 ++--- app/src/main/cpp/skyline/loader/nso.cpp | 2 +- app/src/main/cpp/skyline/nce.cpp | 41 ++++++++++--------- app/src/main/cpp/skyline/nce/instructions.h | 6 +-- .../services/am/storage/IStorageAccessor.cpp | 6 +-- .../services/audio/IAudioRendererManager.cpp | 18 ++++---- .../services/codec/IHardwareOpusDecoder.cpp | 12 +++--- .../services/codec/IHardwareOpusDecoder.h | 14 +++---- .../codec/IHardwareOpusDecoderManager.cpp | 4 +- .../main/cpp/skyline/services/fssrv/IFile.cpp | 4 +- .../cpp/skyline/services/fssrv/IStorage.cpp | 2 +- .../services/glue/ITimeZoneService.cpp | 2 +- .../cpp/skyline/services/hid/IHidServer.cpp | 2 +- .../hosbinder/GraphicBufferProducer.cpp | 22 +++++----- .../cpp/skyline/services/hosbinder/parcel.cpp | 2 +- .../skyline/services/nvdrv/INvDrvServices.cpp | 4 +- .../nvdrv/devices/deserialisation/types.h | 16 ++++---- .../services/nvdrv/devices/nvhost/as_gpu.cpp | 12 +++--- .../services/nvdrv/devices/nvhost/ctrl.cpp | 5 +-- .../nvdrv/devices/nvhost/gpu_channel.cpp | 2 +- .../nvdrv/devices/nvhost/gpu_channel.h | 2 +- .../skyline/services/nvdrv/devices/nvmap.cpp | 8 ++-- .../cpp/skyline/services/nvdrv/driver.cpp | 10 ++--- .../main/cpp/skyline/services/nvdrv/driver.h | 10 ++--- .../skyline/services/pl/shared_font_core.h | 8 ++-- .../services/settings/ISettingsServer.cpp | 2 +- .../cpp/skyline/services/timesrv/common.h | 8 ++-- .../cpp/skyline/services/timesrv/core.cpp | 4 +- .../services/timesrv/time_manager_server.cpp | 2 +- .../services/timesrv/time_manager_server.h | 2 +- .../services/timesrv/time_shared_memory.cpp | 4 +- .../services/timesrv/timezone_manager.cpp | 4 +- .../engines/maxwell/macro_interpreter.cpp | 5 ++- .../skyline/soc/gm20b/engines/maxwell_3d.cpp | 15 +++---- .../cpp/skyline/vfs/android_asset_backing.cpp | 4 +- app/src/main/cpp/skyline/vfs/backing.h | 2 +- app/src/main/cpp/skyline/vfs/npdm.cpp | 3 +- app/src/main/cpp/skyline/vfs/npdm.h | 2 +- app/src/main/cpp/skyline/vfs/os_backing.cpp | 8 ++-- .../main/cpp/skyline/vfs/os_filesystem.cpp | 2 +- 71 files changed, 277 insertions(+), 262 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 4591715c..54222b1c 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -232,4 +232,4 @@ add_library(skyline SHARED target_include_directories(skyline PRIVATE ${source_DIR}/skyline) # target_precompile_headers(skyline PRIVATE ${source_DIR}/skyline/common.h) # PCH will currently break Intellisense target_link_libraries(skyline android perfetto fmt lz4_static tzcode oboe vkma mbedcrypto opus Boost::container) -target_compile_options(skyline PRIVATE -Wall -Wno-unknown-attributes -Wno-c++20-extensions -Wno-c++17-extensions -Wno-c99-designator -Wno-reorder -Wno-missing-braces -Wno-unused-variable -Wno-unused-private-field -Wno-dangling-else) +target_compile_options(skyline PRIVATE -Wall -Wno-unknown-attributes -Wno-c++20-extensions -Wno-c++17-extensions -Wno-c99-designator -Wno-reorder -Wno-missing-braces -Wno-unused-variable -Wno-unused-private-field -Wno-dangling-else -Wconversion) diff --git a/app/src/main/cpp/emu_jni.cpp b/app/src/main/cpp/emu_jni.cpp index e54926df..d4627b63 100644 --- a/app/src/main/cpp/emu_jni.cpp +++ b/app/src/main/cpp/emu_jni.cpp @@ -67,7 +67,8 @@ extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_executeApplication( jobject assetManager ) { skyline::signal::ScopedStackBlocker stackBlocker; // We do not want anything to unwind past JNI code as there are invalid stack frames which can lead to a segmentation fault - Fps = AverageFrametimeMs = AverageFrametimeDeviationMs = 0; + Fps = 0; + AverageFrametimeMs = AverageFrametimeDeviationMs = 0.0f; pthread_setname_np(pthread_self(), "EmuMain"); @@ -178,7 +179,7 @@ extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_updatePerformanceSt extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_setController(JNIEnv *, jobject, jint index, jint type, jint partnerIndex) { auto input{InputWeak.lock()}; std::lock_guard guard(input->npad.mutex); - input->npad.controllers[index] = skyline::input::GuestController{static_cast(type), static_cast(partnerIndex)}; + input->npad.controllers[static_cast(index)] = skyline::input::GuestController{static_cast(type), static_cast(partnerIndex)}; } extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_updateControllers(JNIEnv *, jobject) { @@ -189,7 +190,7 @@ extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_setButtonSt auto input{InputWeak.lock()}; if (!input) return; // We don't mind if we miss button updates while input hasn't been initialized - auto device{input->npad.controllers[index].device}; + auto device{input->npad.controllers[static_cast(index)].device}; if (device) device->SetButtonState(skyline::input::NpadButton{.raw = static_cast(mask)}, pressed); } @@ -198,7 +199,7 @@ extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_setAxisValu auto input{InputWeak.lock()}; if (!input) return; // We don't mind if we miss axis updates while input hasn't been initialized - auto device{input->npad.controllers[index].device}; + auto device{input->npad.controllers[static_cast(index)].device}; if (device) device->SetAxisValue(static_cast(axis), value); } @@ -211,7 +212,8 @@ extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_setTouchSta return; // We don't mind if we miss touch updates while input hasn't been initialized jboolean isCopy{false}; - skyline::span points(reinterpret_cast(env->GetIntArrayElements(pointsJni, &isCopy)), env->GetArrayLength(pointsJni) / (sizeof(Point) / sizeof(jint))); + skyline::span points(reinterpret_cast(env->GetIntArrayElements(pointsJni, &isCopy)), + static_cast(env->GetArrayLength(pointsJni)) / (sizeof(Point) / sizeof(jint))); input->touch.SetState(points); env->ReleaseIntArrayElements(pointsJni, reinterpret_cast(points.data()), JNI_ABORT); } diff --git a/app/src/main/cpp/loader_jni.cpp b/app/src/main/cpp/loader_jni.cpp index 5689e636..5e3ad7a5 100644 --- a/app/src/main/cpp/loader_jni.cpp +++ b/app/src/main/cpp/loader_jni.cpp @@ -61,8 +61,8 @@ extern "C" JNIEXPORT jint JNICALL Java_emu_skyline_loader_RomFile_populate(JNIEn env->SetObjectField(thiz, applicationAuthorField, env->NewStringUTF(loader->nacp->GetApplicationPublisher(language).c_str())); auto icon{loader->GetIcon(language)}; - jbyteArray iconByteArray{env->NewByteArray(icon.size())}; - env->SetByteArrayRegion(iconByteArray, 0, icon.size(), reinterpret_cast(icon.data())); + jbyteArray iconByteArray{env->NewByteArray(static_cast(icon.size()))}; + env->SetByteArrayRegion(iconByteArray, 0, static_cast(icon.size()), reinterpret_cast(icon.data())); env->SetObjectField(thiz, rawIconField, iconByteArray); } diff --git a/app/src/main/cpp/skyline/audio.cpp b/app/src/main/cpp/skyline/audio.cpp index e4dfbdf8..a450a8c3 100644 --- a/app/src/main/cpp/skyline/audio.cpp +++ b/app/src/main/cpp/skyline/audio.cpp @@ -40,7 +40,7 @@ namespace skyline::audio { oboe::DataCallbackResult Audio::onAudioReady(oboe::AudioStream *audioStream, void *audioData, int32_t numFrames) { auto destBuffer{static_cast(audioData)}; - auto streamSamples{static_cast(numFrames) * audioStream->getChannelCount()}; + auto streamSamples{static_cast(numFrames) * static_cast(audioStream->getChannelCount())}; size_t writtenSamples{}; { @@ -54,7 +54,7 @@ namespace skyline::audio { auto trackSamples{track->samples.Read(span(destBuffer, streamSamples), [](i16 *source, i16 *destination) { *destination = Saturate(static_cast(*destination) + static_cast(*source)); - }, writtenSamples)}; + }, static_cast(writtenSamples))}; writtenSamples = std::max(trackSamples, writtenSamples); diff --git a/app/src/main/cpp/skyline/common.h b/app/src/main/cpp/skyline/common.h index cca42ab0..6df6dad3 100644 --- a/app/src/main/cpp/skyline/common.h +++ b/app/src/main/cpp/skyline/common.h @@ -27,7 +27,7 @@ namespace skyline { private: std::mutex mutex; //!< Synchronizes all output I/O to ensure there are no races std::ofstream logFile; //!< An output stream to the log file - u64 start; //!< A timestamp in milliseconds for when the logger was started, this is used as the base for all log timestamps + i64 start; //!< A timestamp in milliseconds for when the logger was started, this is used as the base for all log timestamps public: enum class LogLevel { diff --git a/app/src/main/cpp/skyline/common/base.h b/app/src/main/cpp/skyline/common/base.h index d60a45eb..50cce139 100644 --- a/app/src/main/cpp/skyline/common/base.h +++ b/app/src/main/cpp/skyline/common/base.h @@ -37,10 +37,10 @@ namespace skyline { namespace constant { // Time - constexpr u64 NsInMicrosecond{1000}; //!< The amount of nanoseconds in a microsecond - constexpr u64 NsInSecond{1000000000}; //!< The amount of nanoseconds in a second - constexpr u64 NsInMillisecond{1000000}; //!< The amount of nanoseconds in a millisecond - constexpr u64 NsInDay{86400000000000UL}; //!< The amount of nanoseconds in a day + constexpr i64 NsInMicrosecond{1000}; //!< The amount of nanoseconds in a microsecond + constexpr i64 NsInSecond{1000000000}; //!< The amount of nanoseconds in a second + constexpr i64 NsInMillisecond{1000000}; //!< The amount of nanoseconds in a millisecond + constexpr i64 NsInDay{86400000000000UL}; //!< The amount of nanoseconds in a day } namespace util { diff --git a/app/src/main/cpp/skyline/common/circular_buffer.h b/app/src/main/cpp/skyline/common/circular_buffer.h index a08defcb..c3b13cee 100644 --- a/app/src/main/cpp/skyline/common/circular_buffer.h +++ b/app/src/main/cpp/skyline/common/circular_buffer.h @@ -55,11 +55,11 @@ namespace skyline { copyFunction(source, destination); if (copyOffset != -1) { - std::memcpy(pointer + copyOffset, start + copyOffset, (sizeEnd - copyOffset) * sizeof(Type)); + std::memcpy(pointer + copyOffset, start + copyOffset, static_cast(sizeEnd - copyOffset) * sizeof(Type)); copyOffset -= sizeEnd; } } else { - std::memcpy(pointer, start, sizeEnd * sizeof(Type)); + std::memcpy(pointer, start, static_cast(sizeEnd) * sizeof(Type)); } pointer += sizeEnd; @@ -72,9 +72,9 @@ namespace skyline { copyFunction(source, destination); if (copyOffset != -1) - std::memcpy(array.begin() + copyOffset, pointer + copyOffset, (sizeBegin - copyOffset) * sizeof(Type)); + std::memcpy(array.begin() + copyOffset, pointer + copyOffset, static_cast(sizeBegin - copyOffset) * sizeof(Type)); } else { - std::memcpy(pointer, array.begin(), sizeBegin * sizeof(Type)); + std::memcpy(pointer, array.begin(), static_cast(sizeBegin) * sizeof(Type)); } start = array.begin() + sizeBegin; @@ -99,7 +99,7 @@ namespace skyline { while (size) { if (start <= end && end != array.end()) { auto sizeEnd{std::min(array.end() - end, size)}; - std::memcpy(end, pointer, sizeEnd * sizeof(Type)); + std::memcpy(end, pointer, static_cast(sizeEnd) * sizeof(Type)); pointer += sizeEnd; size -= sizeEnd; @@ -110,7 +110,7 @@ namespace skyline { auto sizePostStart{std::min(array.end() - start, size - sizePreStart)}; if (sizePreStart) - std::memcpy((end == array.end()) ? array.begin() : end, pointer, sizePreStart * sizeof(Type)); + std::memcpy((end == array.end()) ? array.begin() : end, pointer, static_cast(sizePreStart) * sizeof(Type)); if (end == array.end()) end = array.begin() + sizePreStart; @@ -121,7 +121,7 @@ namespace skyline { size -= sizePreStart; if (sizePostStart) - std::memcpy(end, pointer, sizePostStart * sizeof(Type)); + std::memcpy(end, pointer, static_cast(sizePostStart) * sizeof(Type)); if (start == array.end()) start = array.begin() + sizePostStart; diff --git a/app/src/main/cpp/skyline/common/signal.cpp b/app/src/main/cpp/skyline/common/signal.cpp index 58da88f3..52ed4769 100644 --- a/app/src/main/cpp/skyline/common/signal.cpp +++ b/app/src/main/cpp/skyline/common/signal.cpp @@ -157,11 +157,11 @@ namespace skyline::signal { if (TlsRestorer) tls = TlsRestorer(); - auto handler{ThreadSignalHandlers.at(signal)}; + auto handler{ThreadSignalHandlers.at(static_cast(signal))}; if (handler) { handler(signal, info, context, &tls); } else { - auto defaultHandler{DefaultSignalHandlers.at(signal).function}; + auto defaultHandler{DefaultSignalHandlers.at(static_cast(signal)).function}; if (defaultHandler) defaultHandler(signal, info, context); } @@ -179,7 +179,7 @@ namespace skyline::signal { }; for (int signal : signals) { - std::call_once(signalHandlerOnce[signal], [signal, &action]() { + std::call_once(signalHandlerOnce[static_cast(signal)], [signal, &action]() { struct sigaction oldAction; Sigaction(signal, &action, &oldAction); if (oldAction.sa_flags) { @@ -189,9 +189,9 @@ namespace skyline::signal { throw exception("Old sigaction flags aren't equivalent to the replaced signal: {:#b} | {:#b}", oldAction.sa_flags, action.sa_flags); } - DefaultSignalHandlers.at(signal).function = (oldAction.sa_flags & SA_SIGINFO) ? oldAction.sa_sigaction : reinterpret_cast(oldAction.sa_handler); + DefaultSignalHandlers.at(static_cast(signal)).function = (oldAction.sa_flags & SA_SIGINFO) ? oldAction.sa_sigaction : reinterpret_cast(oldAction.sa_handler); }); - ThreadSignalHandlers.at(signal) = function; + ThreadSignalHandlers.at(static_cast(signal)) = function; } } diff --git a/app/src/main/cpp/skyline/common/span.h b/app/src/main/cpp/skyline/common/span.h index 67536b17..2d0f8c72 100644 --- a/app/src/main/cpp/skyline/common/span.h +++ b/app/src/main/cpp/skyline/common/span.h @@ -47,7 +47,7 @@ namespace skyline { * @param nullTerminated If true and the string is null-terminated, a view of it will be returned (not including the null terminator itself), otherwise the entire span will be returned as a string view */ constexpr std::string_view as_string(bool nullTerminated = false) { - return std::string_view(reinterpret_cast(span::data()), nullTerminated ? (std::find(span::begin(), span::end(), 0) - span::begin()) : span::size_bytes()); + return std::string_view(reinterpret_cast(span::data()), nullTerminated ? static_cast(std::find(span::begin(), span::end(), 0) - span::begin()) : span::size_bytes()); } template diff --git a/app/src/main/cpp/skyline/common/utils.h b/app/src/main/cpp/skyline/common/utils.h index 2f5f5e5a..b37f124d 100644 --- a/app/src/main/cpp/skyline/common/utils.h +++ b/app/src/main/cpp/skyline/common/utils.h @@ -13,12 +13,12 @@ namespace skyline::util { * @brief Returns the current time in nanoseconds * @return The current time in nanoseconds */ - inline u64 GetTimeNs() { + inline i64 GetTimeNs() { u64 frequency; asm("MRS %0, CNTFRQ_EL0" : "=r"(frequency)); u64 ticks; asm("MRS %0, CNTVCT_EL0" : "=r"(ticks)); - return ((ticks / frequency) * constant::NsInSecond) + (((ticks % frequency) * constant::NsInSecond + (frequency / 2)) / frequency); + return static_cast(((ticks / frequency) * constant::NsInSecond) + (((ticks % frequency) * constant::NsInSecond + (frequency / 2)) / frequency)); } /** @@ -52,18 +52,19 @@ namespace skyline::util { if constexpr (std::is_pointer::value) return reinterpret_cast(item); else - return item; + return static_cast(item); } template - concept IsPointerOrIntegral = std::is_integral_v || std::is_pointer_v; + concept IsPointerOrUnsignedIntegral = (std::is_unsigned_v && std::is_integral_v) || std::is_pointer_v; /** * @return The value aligned up to the next multiple * @note The multiple needs to be a power of 2 */ - template - constexpr TypeVal AlignUp(TypeVal value, TypeMul multiple) { + template + requires IsPointerOrUnsignedIntegral + constexpr TypeVal AlignUp(TypeVal value, size_t multiple) { multiple--; return ValuePointer((PointerValue(value) + multiple) & ~(multiple)); } @@ -72,17 +73,18 @@ namespace skyline::util { * @return The value aligned down to the previous multiple * @note The multiple needs to be a power of 2 */ - template - constexpr TypeVal AlignDown(TypeVal value, TypeMul multiple) { + template + requires IsPointerOrUnsignedIntegral + constexpr TypeVal AlignDown(TypeVal value, size_t multiple) { return ValuePointer(PointerValue(value) & ~(multiple - 1)); } /** * @return If the address is aligned with the multiple */ - template - requires (IsPointerOrIntegral && IsPointerOrIntegral) - constexpr bool IsAligned(TypeVal value, TypeMul multiple) { + template + requires IsPointerOrUnsignedIntegral + constexpr bool IsAligned(TypeVal value, size_t multiple) { if ((multiple & (multiple - 1)) == 0) return !(PointerValue(value) & (multiple - 1U)); else @@ -90,13 +92,13 @@ namespace skyline::util { } template - requires IsPointerOrIntegral + requires IsPointerOrUnsignedIntegral constexpr bool IsPageAligned(TypeVal value) { return IsAligned(value, PAGE_SIZE); } template - requires IsPointerOrIntegral + requires IsPointerOrUnsignedIntegral constexpr bool IsWordAligned(TypeVal value) { return IsAligned(value, WORD_BIT / 8); } @@ -136,7 +138,7 @@ namespace skyline::util { std::array result; for (size_t i{}; i < Size; i++) { size_t index{i * 2}; - result[i] = (HexDigitToNibble(string[index]) << 4) | HexDigitToNibble(string[index + 1]); + result[i] = static_cast(HexDigitToNibble(string[index]) << 4) | HexDigitToNibble(string[index + 1]); } return result; } diff --git a/app/src/main/cpp/skyline/crypto/aes_cipher.cpp b/app/src/main/cpp/skyline/crypto/aes_cipher.cpp index f78eb95e..439b7eb2 100644 --- a/app/src/main/cpp/skyline/crypto/aes_cipher.cpp +++ b/app/src/main/cpp/skyline/crypto/aes_cipher.cpp @@ -9,7 +9,7 @@ namespace skyline::crypto { if (mbedtls_cipher_setup(&decryptContext, mbedtls_cipher_info_from_type(type)) != 0) throw exception("Failed to setup decryption context"); - if (mbedtls_cipher_setkey(&decryptContext, key.data(), key.size() * 8, MBEDTLS_DECRYPT) != 0) + if (mbedtls_cipher_setkey(&decryptContext, key.data(), static_cast(key.size() * 8), MBEDTLS_DECRYPT) != 0) throw exception("Failed to set key for decryption context"); } diff --git a/app/src/main/cpp/skyline/crypto/key_store.cpp b/app/src/main/cpp/skyline/crypto/key_store.cpp index b69b1c9c..46a7028e 100644 --- a/app/src/main/cpp/skyline/crypto/key_store.cpp +++ b/app/src/main/cpp/skyline/crypto/key_store.cpp @@ -24,8 +24,8 @@ namespace skyline::crypto { if (keyEnd == lineEnd) throw exception("Invalid key file"); - std::string_view key(&*lineStart, keyEnd - lineStart); - std::string_view value(&*(keyEnd + 1), lineEnd - keyEnd - 1); + std::string_view key(&*lineStart, static_cast(keyEnd - lineStart)); + std::string_view value(&*(keyEnd + 1), static_cast(lineEnd - keyEnd - 1)); (this->*callback)(key, value); lineStart = lineEnd + 1; diff --git a/app/src/main/cpp/skyline/gpu.cpp b/app/src/main/cpp/skyline/gpu.cpp index 99cb88df..3a0f23f1 100644 --- a/app/src/main/cpp/skyline/gpu.cpp +++ b/app/src/main/cpp/skyline/gpu.cpp @@ -8,7 +8,7 @@ namespace skyline::gpu { vk::raii::Instance GPU::CreateInstance(const DeviceState &state, const vk::raii::Context &context) { vk::ApplicationInfo applicationInfo{ .pApplicationName = "Skyline", - .applicationVersion = state.jvm->GetVersionCode(), // Get the application version from JNI + .applicationVersion = static_cast(state.jvm->GetVersionCode()), // Get the application version from JNI .pEngineName = "FTX1", // "Fast Tegra X1" .apiVersion = VkApiVersion, }; @@ -111,7 +111,7 @@ namespace skyline::gpu { #undef IGNORE_TYPE } - logger->Write(severityLookup.at(std::countr_zero(static_cast(flags))), util::Format("Vk{}:{}[0x{:X}]:I{}:L{}: {}", layerPrefix, vk::to_string(vk::DebugReportObjectTypeEXT(objectType)), object, messageCode, location, message)); + logger->Write(severityLookup.at(static_cast(std::countr_zero(static_cast(flags)))), util::Format("Vk{}:{}[0x{:X}]:I{}:L{}: {}", layerPrefix, vk::to_string(vk::DebugReportObjectTypeEXT(objectType)), object, messageCode, location, message)); return VK_FALSE; } diff --git a/app/src/main/cpp/skyline/gpu/interconnect/command_nodes.cpp b/app/src/main/cpp/skyline/gpu/interconnect/command_nodes.cpp index 325ca112..b32382f6 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/command_nodes.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/command_nodes.cpp @@ -32,7 +32,7 @@ namespace skyline::gpu::interconnect::node { return static_cast(attachments.size() - 1); } else { // If we've got a match from a previous subpass, we need to preserve the attachment till the current subpass - auto attachmentIndex{std::distance(attachments.begin(), attachment)}; + auto attachmentIndex{static_cast(std::distance(attachments.begin(), attachment))}; auto it{subpassDescriptions.begin()}; auto getSubpassAttachmentRange{[this] (const vk::SubpassDescription& subpassDescription) { @@ -74,7 +74,7 @@ namespace skyline::gpu::interconnect::node { continue; // If a subpass uses an attachment then it doesn't need to be preserved } - auto &subpassPreserveAttachments{preserveAttachmentReferences[std::distance(subpassDescriptions.begin(), it)]}; + auto &subpassPreserveAttachments{preserveAttachmentReferences[static_cast(std::distance(subpassDescriptions.begin(), it))]}; if (std::find(subpassPreserveAttachments.begin(), subpassPreserveAttachments.end(), attachmentIndex) != subpassPreserveAttachments.end()) subpassPreserveAttachments.push_back(attachmentIndex); } @@ -174,7 +174,7 @@ namespace skyline::gpu::interconnect::node { else subpassDescription.pDepthStencilAttachment = nullptr; - subpassDescription.preserveAttachmentCount = preserveAttachmentIt->size(); + subpassDescription.preserveAttachmentCount = static_cast(preserveAttachmentIt->size()); subpassDescription.pPreserveAttachments = preserveAttachmentIt->data(); preserveAttachmentIt++; } diff --git a/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h b/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h index 613c3f09..374035ab 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h @@ -186,9 +186,10 @@ namespace skyline::gpu::interconnect { void SetRenderTargetBaseLayer(size_t index, u32 baseArrayLayer) { auto &renderTarget{renderTargets.at(index)}; - renderTarget.guest.baseArrayLayer = baseArrayLayer; if (baseArrayLayer > std::numeric_limits::max()) throw exception("Base array layer ({}) exceeds the range of array count ({}) (with layer count = {})", baseArrayLayer, std::numeric_limits::max(), renderTarget.guest.layerCount); + + renderTarget.guest.baseArrayLayer = static_cast(baseArrayLayer); renderTarget.view.reset(); } @@ -263,8 +264,10 @@ namespace skyline::gpu::interconnect { return; auto scissor{scissors.at(renderTargetIndex)}; - scissor.extent.width = std::min(renderTarget.backing->dimensions.width - scissor.offset.x, scissor.extent.width); - scissor.extent.height = std::min(renderTarget.backing->dimensions.height - scissor.offset.y, scissor.extent.height); + scissor.extent.width = static_cast(std::min(static_cast(renderTarget.backing->dimensions.width) - scissor.offset.x, + static_cast(scissor.extent.width))); + scissor.extent.height = static_cast(std::min(static_cast(renderTarget.backing->dimensions.height) - scissor.offset.y, + static_cast(scissor.extent.height))); if (scissor.extent.width == 0 || scissor.extent.height == 0) return; diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp index e131d70f..d9ad7e3c 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp @@ -210,7 +210,7 @@ namespace skyline::gpu { } } - void PresentationEngine::Present(const std::shared_ptr &texture, u64 timestamp, u64 swapInterval, AndroidRect crop, NativeWindowScalingMode scalingMode, NativeWindowTransform transform, u64 &frameId) { + void PresentationEngine::Present(const std::shared_ptr &texture, i64 timestamp, u64 swapInterval, AndroidRect crop, NativeWindowScalingMode scalingMode, NativeWindowTransform transform, u64 &frameId) { std::unique_lock lock(mutex); surfaceCondition.wait(lock, [this]() { return vkSurface.has_value(); }); @@ -257,7 +257,7 @@ namespace skyline::gpu { // If the timestamp is specified, we need to convert it from the util::GetTimeNs base to the CLOCK_MONOTONIC one // We do so by getting an offset from the current time in nanoseconds and then adding it to the current time in CLOCK_MONOTONIC // Note: It's important we do this right before present as going past the timestamp could lead to fewer Binder IPC calls - auto current{util::GetTimeNs()}; + i64 current{util::GetTimeNs()}; if (current < timestamp) { timespec time; if (clock_gettime(CLOCK_MONOTONIC, &time)) @@ -270,7 +270,7 @@ namespace skyline::gpu { if (swapInterval > 1) // If we have a swap interval above 1 we have to adjust the timestamp to emulate the swap interval - timestamp = std::max(timestamp, lastChoreographerTime + (refreshCycleDuration * swapInterval * 2)); + timestamp = std::max(timestamp, lastChoreographerTime + (refreshCycleDuration * static_cast(swapInterval) * 2)); auto lastTimestamp{std::exchange(windowLastTimestamp, timestamp)}; if (!timestamp && lastTimestamp) @@ -293,8 +293,8 @@ namespace skyline::gpu { } if (frameTimestamp) { - i64 now{static_cast(util::GetTimeNs())}; - i64 sampleWeight{static_cast(swapInterval ? constant::NsInSecond / (refreshCycleDuration * swapInterval) : 10)}; //!< The weight of each sample in calculating the average, we arbitrarily average 10 samples for unlocked FPS + i64 now{util::GetTimeNs()}; + i64 sampleWeight{swapInterval ? constant::NsInSecond / (refreshCycleDuration * static_cast(swapInterval)) : 10}; //!< The weight of each sample in calculating the average, we arbitrarily average 10 samples for unlocked FPS auto weightedAverage{[](auto weight, auto previousAverage, auto current) { return (((weight - 1) * previousAverage) + current) / weight; @@ -314,7 +314,7 @@ namespace skyline::gpu { frameTimestamp = now; } else { - frameTimestamp = static_cast(util::GetTimeNs()); + frameTimestamp = util::GetTimeNs(); } } diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.h b/app/src/main/cpp/skyline/gpu/presentation_engine.h index 9eeab661..7433c7d0 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.h +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.h @@ -89,7 +89,7 @@ namespace skyline::gpu { * @param frameId The ID of this frame for correlating it with presentation timing readouts * @note The texture **must** be locked prior to calling this */ - void Present(const std::shared_ptr &texture, u64 timestamp, u64 swapInterval, service::hosbinder::AndroidRect crop, service::hosbinder::NativeWindowScalingMode scalingMode, service::hosbinder::NativeWindowTransform transform, u64 &frameId); + void Present(const std::shared_ptr &texture, i64 timestamp, u64 swapInterval, service::hosbinder::AndroidRect crop, service::hosbinder::NativeWindowScalingMode scalingMode, service::hosbinder::NativeWindowTransform transform, u64 &frameId); /** * @return A transform that the application should render with to elide costly transforms later diff --git a/app/src/main/cpp/skyline/input/npad.cpp b/app/src/main/cpp/skyline/input/npad.cpp index 02bbb052..867a2ed8 100644 --- a/app/src/main/cpp/skyline/input/npad.cpp +++ b/app/src/main/cpp/skyline/input/npad.cpp @@ -50,15 +50,15 @@ namespace skyline::input { if (style.raw) { if (style.proController || style.joyconHandheld || style.joyconLeft || style.joyconRight) { device.Connect(controller.type); - device.index = static_cast(&controller - controllers.data()); + device.index = static_cast(&controller - controllers.data()); device.partnerIndex = -1; controller.device = &device; } else if (style.joyconDual && orientation == NpadJoyOrientation::Vertical && device.GetAssignment() == NpadJoyAssignment::Dual) { device.Connect(NpadControllerType::JoyconDual); - device.index = static_cast(&controller - controllers.data()); + device.index = static_cast(&controller - controllers.data()); device.partnerIndex = controller.partnerIndex; controller.device = &device; - controllers.at(controller.partnerIndex).device = &device; + controllers.at(static_cast(controller.partnerIndex)).device = &device; } else { continue; } diff --git a/app/src/main/cpp/skyline/input/npad_device.cpp b/app/src/main/cpp/skyline/input/npad_device.cpp index 82a1ea4b..335ce889 100644 --- a/app/src/main/cpp/skyline/input/npad_device.cpp +++ b/app/src/main/cpp/skyline/input/npad_device.cpp @@ -362,7 +362,10 @@ namespace skyline::input { jlong start; jlong end; - VibrationInfo(float frequency, float amplitude) : period(MsInSecond / frequency), amplitude(amplitude), start(0), end(period) {} + VibrationInfo(float frequency, float amplitude) + : period(static_cast(MsInSecond / frequency)), + amplitude(static_cast(amplitude)), + start(0), end(period) {} }; template diff --git a/app/src/main/cpp/skyline/input/touch.cpp b/app/src/main/cpp/skyline/input/touch.cpp index 3247ccaf..6eb5faf5 100644 --- a/app/src/main/cpp/skyline/input/touch.cpp +++ b/app/src/main/cpp/skyline/input/touch.cpp @@ -29,11 +29,11 @@ namespace skyline::input { for (size_t i{}; i < points.size(); i++) { const auto &host{points[i]}; auto &guest{entry.data[i]}; - guest.index = i; - guest.positionX = host.x; - guest.positionY = host.y; - guest.minorAxis = host.minor; - guest.majorAxis = host.major; + guest.index = static_cast(i); + guest.positionX = static_cast(host.x); + guest.positionY = static_cast(host.y); + guest.minorAxis = static_cast(host.minor); + guest.majorAxis = static_cast(host.major); guest.angle = host.angle; } diff --git a/app/src/main/cpp/skyline/jvm.cpp b/app/src/main/cpp/skyline/jvm.cpp index 6a148c67..ae7bdb51 100644 --- a/app/src/main/cpp/skyline/jvm.cpp +++ b/app/src/main/cpp/skyline/jvm.cpp @@ -76,10 +76,10 @@ namespace skyline { } void JvmManager::VibrateDevice(jint index, const span &timings, const span &litudes) { - auto jTimings{env->NewLongArray(timings.size())}; - env->SetLongArrayRegion(jTimings, 0, timings.size(), timings.data()); - auto jAmplitudes{env->NewIntArray(amplitudes.size())}; - env->SetIntArrayRegion(jAmplitudes, 0, amplitudes.size(), amplitudes.data()); + auto jTimings{env->NewLongArray(static_cast(timings.size()))}; + env->SetLongArrayRegion(jTimings, 0, static_cast(timings.size()), timings.data()); + auto jAmplitudes{env->NewIntArray(static_cast(amplitudes.size()))}; + env->SetIntArrayRegion(jAmplitudes, 0, static_cast(amplitudes.size()), amplitudes.data()); env->CallVoidMethod(instance, vibrateDeviceId, index, jTimings, jAmplitudes); @@ -91,7 +91,7 @@ namespace skyline { env->CallVoidMethod(instance, clearVibrationDeviceId, index); } - u32 JvmManager::GetVersionCode() { + i32 JvmManager::GetVersionCode() { return env->CallIntMethod(instance, getVersionCodeId); } } diff --git a/app/src/main/cpp/skyline/jvm.h b/app/src/main/cpp/skyline/jvm.h index 9406daee..b2b18397 100644 --- a/app/src/main/cpp/skyline/jvm.h +++ b/app/src/main/cpp/skyline/jvm.h @@ -99,7 +99,7 @@ namespace skyline { * @brief A call to EmulationActivity.getVersionCode in Kotlin * @return A version code in Vulkan's format with 14-bit patch + 10-bit major and minor components */ - u32 GetVersionCode(); + i32 GetVersionCode(); private: jmethodID initializeControllersId; diff --git a/app/src/main/cpp/skyline/kernel/ipc.cpp b/app/src/main/cpp/skyline/kernel/ipc.cpp index ae4a76ab..dbc98249 100644 --- a/app/src/main/cpp/skyline/kernel/ipc.cpp +++ b/app/src/main/cpp/skyline/kernel/ipc.cpp @@ -64,7 +64,7 @@ namespace skyline::kernel::ipc { auto bufCPointer{pointer + header->rawSize * sizeof(u32)}; - auto offset{pointer - tls}; // We calculate the relative offset as the absolute one might differ + size_t offset{static_cast(pointer - tls)}; // We calculate the relative offset as the absolute one might differ auto padding{util::AlignUp(offset, constant::IpcPaddingSum) - offset}; // Calculate the amount of padding at the front pointer += padding; @@ -154,7 +154,7 @@ namespace skyline::kernel::ipc { } } - auto offset{pointer - tls}; // We calculate the relative offset as the absolute one might differ + size_t offset{static_cast(pointer - tls)}; // We calculate the relative offset as the absolute one might differ auto padding{util::AlignUp(offset, constant::IpcPaddingSum) - offset}; // Calculate the amount of padding at the front pointer += padding; diff --git a/app/src/main/cpp/skyline/kernel/ipc.h b/app/src/main/cpp/skyline/kernel/ipc.h index 55ce65a9..2a2e9b6c 100644 --- a/app/src/main/cpp/skyline/kernel/ipc.h +++ b/app/src/main/cpp/skyline/kernel/ipc.h @@ -134,7 +134,7 @@ namespace skyline { } u16 Counter() { - return static_cast(counter0_5) | static_cast(counter9_11) << 9; + return static_cast(counter0_5) | static_cast(static_cast(counter9_11) << 9); } }; static_assert(sizeof(BufferDescriptorX) == 8); diff --git a/app/src/main/cpp/skyline/kernel/memory.cpp b/app/src/main/cpp/skyline/kernel/memory.cpp index 452e89f6..780136b3 100644 --- a/app/src/main/cpp/skyline/kernel/memory.cpp +++ b/app/src/main/cpp/skyline/kernel/memory.cpp @@ -146,7 +146,7 @@ namespace skyline::kernel { if (upper != chunks.end() && upper->ptr < chunk.ptr + chunk.size) { auto end{upper->ptr + upper->size}; upper->ptr = chunk.ptr + chunk.size; - upper->size = end - upper->ptr; + upper->size = static_cast(end - upper->ptr); } auto lower{std::prev(upper)}; @@ -157,16 +157,16 @@ namespace skyline::kernel { } else if (lower->ptr + lower->size > chunk.ptr + chunk.size) { auto lowerExtension{*lower}; lowerExtension.ptr = chunk.ptr + chunk.size; - lowerExtension.size = (lower->ptr + lower->size) - lowerExtension.ptr; + lowerExtension.size = static_cast((lower->ptr + lower->size) - lowerExtension.ptr); - lower->size = chunk.ptr - lower->ptr; + lower->size = static_cast(chunk.ptr - lower->ptr); if (lower->size) { upper = chunks.insert(upper, lowerExtension); chunks.insert(upper, chunk); } else { auto lower2{std::prev(lower)}; if (chunk.IsCompatible(*lower2) && lower2->ptr + lower2->size >= chunk.ptr) { - lower2->size = chunk.ptr + chunk.size - lower2->ptr; + lower2->size = static_cast(chunk.ptr + chunk.size - lower2->ptr); upper = chunks.erase(lower); } else { *lower = chunk; @@ -174,10 +174,10 @@ namespace skyline::kernel { upper = chunks.insert(upper, lowerExtension); } } else if (chunk.IsCompatible(*lower) && lower->ptr + lower->size >= chunk.ptr) { - lower->size = chunk.ptr + chunk.size - lower->ptr; + lower->size = static_cast(chunk.ptr + chunk.size - lower->ptr); } else { if (lower->ptr + lower->size > chunk.ptr) - lower->size = chunk.ptr - lower->ptr; + lower->size = static_cast(chunk.ptr - lower->ptr); if (upper != chunks.end() && chunk.IsCompatible(*upper) && chunk.ptr + chunk.size >= upper->ptr) { upper->ptr = chunk.ptr; upper->size = chunk.size + upper->size; diff --git a/app/src/main/cpp/skyline/kernel/scheduler.cpp b/app/src/main/cpp/skyline/kernel/scheduler.cpp index db1d71c5..f4ce272c 100644 --- a/app/src/main/cpp/skyline/kernel/scheduler.cpp +++ b/app/src/main/cpp/skyline/kernel/scheduler.cpp @@ -8,7 +8,7 @@ #include "scheduler.h" namespace skyline::kernel { - Scheduler::CoreContext::CoreContext(u8 id, u8 preemptionPriority) : id(id), preemptionPriority(preemptionPriority) {} + Scheduler::CoreContext::CoreContext(u8 id, i8 preemptionPriority) : id(id), preemptionPriority(preemptionPriority) {} Scheduler::Scheduler(const DeviceState &state) : state(state) {} diff --git a/app/src/main/cpp/skyline/kernel/scheduler.h b/app/src/main/cpp/skyline/kernel/scheduler.h index acfb5e96..22f4407b 100644 --- a/app/src/main/cpp/skyline/kernel/scheduler.h +++ b/app/src/main/cpp/skyline/kernel/scheduler.h @@ -20,8 +20,8 @@ namespace skyline { * @note Lower priority values result in a higher priority, similar to niceness on Linux */ struct Priority { - u8 min; //!< Numerically lowest priority, highest scheduler priority - u8 max; //!< Numerically highest priority, lowest scheduler priority + i8 min; //!< Numerically lowest priority, highest scheduler priority + i8 max; //!< Numerically highest priority, lowest scheduler priority /** * @return A bitmask with each bit corresponding to if scheduler priority with the same index is valid @@ -30,7 +30,7 @@ namespace skyline { return (std::numeric_limits::max() >> ((std::numeric_limits::digits - 1 + min) - max)) << min; } - constexpr bool Valid(u8 value) const { + constexpr bool Valid(i8 value) const { return (value >= min) && (value <= max); } }; @@ -45,11 +45,11 @@ namespace skyline { struct CoreContext { u8 id; - u8 preemptionPriority; //!< The priority at which this core becomes preemptive as opposed to cooperative + i8 preemptionPriority; //!< The priority at which this core becomes preemptive as opposed to cooperative std::mutex mutex; //!< Synchronizes all operations on the queue std::list> queue; //!< A queue of threads which are running or to be run on this core - CoreContext(u8 id, u8 preemptionPriority); + CoreContext(u8 id, i8 preemptionPriority); }; std::array cores{CoreContext(0, 59), CoreContext(1, 59), CoreContext(2, 59), CoreContext(3, 63)}; diff --git a/app/src/main/cpp/skyline/kernel/svc.cpp b/app/src/main/cpp/skyline/kernel/svc.cpp index 88129414..83c969e1 100644 --- a/app/src/main/cpp/skyline/kernel/svc.cpp +++ b/app/src/main/cpp/skyline/kernel/svc.cpp @@ -230,10 +230,10 @@ namespace skyline::kernel::svc { auto entry{reinterpret_cast(state.ctx->gpr.x1)}; auto entryArgument{state.ctx->gpr.x2}; auto stackTop{reinterpret_cast(state.ctx->gpr.x3)}; - auto priority{static_cast(static_cast(state.ctx->gpr.w4))}; - auto idealCore{static_cast(static_cast(state.ctx->gpr.w5))}; + auto priority{static_cast(state.ctx->gpr.w4)}; + auto idealCore{static_cast(state.ctx->gpr.w5)}; - idealCore = (idealCore == IdealCoreUseProcessValue) ? state.process->npdm.meta.idealCore : idealCore; + idealCore = (idealCore == IdealCoreUseProcessValue) ? static_cast(state.process->npdm.meta.idealCore) : idealCore; if (idealCore < 0 || idealCore >= constant::CoreCount) { state.ctx->gpr.w0 = result::InvalidCoreId; state.logger->Warn("'idealCore' invalid: {}", idealCore); @@ -250,7 +250,7 @@ namespace skyline::kernel::svc { if (!stack) throw exception("svcCreateThread: Cannot find memory object in handle table for thread stack: 0x{:X}", stackTop); - auto thread{state.process->CreateThread(entry, entryArgument, stackTop, priority, idealCore)}; + auto thread{state.process->CreateThread(entry, entryArgument, stackTop, priority, static_cast(idealCore))}; if (thread) { state.logger->Debug("Created thread #{} with handle 0x{:X} (Entry Point: 0x{:X}, Argument: 0x{:X}, Stack Pointer: 0x{:X}, Priority: {}, Ideal Core: {})", thread->id, thread->handle, entry, entryArgument, stackTop, priority, idealCore); @@ -335,10 +335,10 @@ namespace skyline::kernel::svc { KHandle handle{state.ctx->gpr.w1}; try { auto thread{state.process->GetHandle(handle)}; - u8 priority{thread->priority}; + i8 priority{thread->priority}; state.logger->Debug("Retrieving thread #{}'s priority: {}", thread->id, priority); - state.ctx->gpr.w1 = priority; + state.ctx->gpr.w1 = static_cast(priority); state.ctx->gpr.w0 = Result{}; } catch (const std::out_of_range &) { state.logger->Warn("'handle' invalid: 0x{:X}", handle); @@ -348,7 +348,7 @@ namespace skyline::kernel::svc { void SetThreadPriority(const DeviceState &state) { KHandle handle{state.ctx->gpr.w0}; - u8 priority{static_cast(state.ctx->gpr.w1)}; + i8 priority{static_cast(state.ctx->gpr.w1)}; if (!state.process->npdm.threadInfo.priority.Valid(priority)) { state.logger->Warn("'priority' invalid: 0x{:X}", priority); state.ctx->gpr.w0 = result::InvalidPriority; @@ -359,7 +359,7 @@ namespace skyline::kernel::svc { state.logger->Debug("Setting thread #{}'s priority to {}", thread->id, priority); if (thread->priority != priority) { thread->basePriority = priority; - u8 newPriority{}; + i8 newPriority{}; do { // Try to CAS the priority of the thread with its new base priority // If the new priority is equivalent to the current priority then we don't need to CAS @@ -385,7 +385,7 @@ namespace skyline::kernel::svc { state.logger->Debug("Getting thread #{}'s Ideal Core ({}) + Affinity Mask ({})", thread->id, idealCore, affinityMask); state.ctx->gpr.x2 = affinityMask.to_ullong(); - state.ctx->gpr.w1 = idealCore; + state.ctx->gpr.w1 = static_cast(idealCore); state.ctx->gpr.w0 = Result{}; } catch (const std::out_of_range &) { state.logger->Warn("'handle' invalid: 0x{:X}", handle); @@ -402,7 +402,7 @@ namespace skyline::kernel::svc { if (idealCore == IdealCoreUseProcessValue) { idealCore = state.process->npdm.meta.idealCore; - affinityMask.reset().set(idealCore); + affinityMask.reset().set(static_cast(idealCore)); } else if (idealCore == IdealCoreNoUpdate) { idealCore = thread->idealCore; } else if (idealCore == IdealCoreDontCare) { @@ -416,7 +416,7 @@ namespace skyline::kernel::svc { return; } - if (affinityMask.none() || !affinityMask.test(idealCore)) { + if (affinityMask.none() || !affinityMask.test(static_cast(idealCore))) { state.logger->Warn("'affinityMask' invalid: {} (Ideal Core: {})", affinityMask, idealCore); state.ctx->gpr.w0 = result::InvalidCombination; return; @@ -425,19 +425,19 @@ namespace skyline::kernel::svc { state.logger->Debug("Setting thread #{}'s Ideal Core ({}) + Affinity Mask ({})", thread->id, idealCore, affinityMask); std::lock_guard guard(thread->coreMigrationMutex); - thread->idealCore = idealCore; + thread->idealCore = static_cast(idealCore); thread->affinityMask = affinityMask; - if (!affinityMask.test(thread->coreId) && thread->coreId != constant::ParkedCoreId) { + if (!affinityMask.test(static_cast(thread->coreId)) && thread->coreId != constant::ParkedCoreId) { state.logger->Debug("Migrating thread #{} to Ideal Core C{} -> C{}", thread->id, thread->coreId, idealCore); if (thread == state.thread) { state.scheduler->RemoveThread(); - thread->coreId = idealCore; + thread->coreId = static_cast(idealCore); state.scheduler->InsertThread(state.thread); state.scheduler->WaitSchedule(); } else if (!thread->running) { - thread->coreId = idealCore; + thread->coreId = static_cast(idealCore); } else { state.scheduler->UpdateCore(thread); } @@ -452,7 +452,7 @@ namespace skyline::kernel::svc { void GetCurrentProcessorNumber(const DeviceState &state) { std::lock_guard guard(state.thread->coreMigrationMutex); - auto coreId{state.thread->coreId}; + u8 coreId{state.thread->coreId}; state.logger->Debug("C{}", coreId); state.ctx->gpr.w0 = coreId; } @@ -490,7 +490,7 @@ namespace skyline::kernel::svc { return; } - memory::Permission permission(state.ctx->gpr.w3); + memory::Permission permission(static_cast(state.ctx->gpr.w3)); if ((permission.w && !permission.r) || (permission.x && !permission.r)) { state.logger->Warn("'permission' invalid: {}{}{}", permission.r ? 'R' : '-', permission.w ? 'W' : '-', permission.x ? 'X' : '-'); state.ctx->gpr.w0 = result::InvalidNewMemoryPermission; @@ -553,7 +553,7 @@ namespace skyline::kernel::svc { return; } - memory::Permission permission(state.ctx->gpr.w3); + memory::Permission permission(static_cast(state.ctx->gpr.w3)); if ((permission.w && !permission.r) || (permission.x && !permission.r)) { state.logger->Warn("'permission' invalid: {}{}{}", permission.r ? 'R' : '-', permission.w ? 'W' : '-', permission.x ? 'X' : '-'); state.ctx->gpr.w0 = result::InvalidNewMemoryPermission; @@ -1067,10 +1067,10 @@ namespace skyline::kernel::svc { item->Resize(0); state.process->CloseHandle(memory->handle); } else { - item->Remap(pointer + size, item->size - (size + (item->ptr - pointer))); + item->Remap(pointer + size, item->size - (size + static_cast(item->ptr - pointer))); } } else if (item->ptr < pointer) { - item->Resize(pointer - item->ptr); + item->Resize(static_cast(pointer - item->ptr)); } } pointer += initialSize; diff --git a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp index 5c7938a3..657568ca 100644 --- a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp @@ -57,7 +57,7 @@ namespace skyline::kernel::type { return tlsPage->ReserveSlot(); } - std::shared_ptr KProcess::CreateThread(void *entry, u64 argument, void *stackTop, std::optional priority, std::optional idealCore) { + std::shared_ptr KProcess::CreateThread(void *entry, u64 argument, void *stackTop, std::optional priority, std::optional idealCore) { std::lock_guard guard(threadMutex); if (disableThreadCreation) return nullptr; @@ -172,14 +172,14 @@ namespace skyline::kernel::type { if (!waiters.empty()) { // If there are threads still waiting on us then try to inherit their priority auto highestPriorityThread{waiters.front()}; - u8 newPriority, basePriority; + i8 newPriority, basePriority; do { basePriority = state.thread->basePriority.load(); newPriority = std::min(basePriority, highestPriorityThread->priority.load()); } while (basePriority != newPriority && state.thread->priority.compare_exchange_strong(basePriority, newPriority)); state.scheduler->UpdatePriority(state.thread); } else { - u8 priority, basePriority; + i8 priority, basePriority; do { basePriority = state.thread->basePriority.load(); priority = state.thread->priority.load(); @@ -190,7 +190,7 @@ namespace skyline::kernel::type { if (nextWaiter) { // If there is a waiter on the new owner then try to inherit its priority - u8 priority, ownerPriority; + i8 priority, ownerPriority; do { ownerPriority = nextOwner->priority.load(); priority = std::min(ownerPriority, nextWaiter->priority.load()); diff --git a/app/src/main/cpp/skyline/kernel/types/KProcess.h b/app/src/main/cpp/skyline/kernel/types/KProcess.h index d65ee223..70e36044 100644 --- a/app/src/main/cpp/skyline/kernel/types/KProcess.h +++ b/app/src/main/cpp/skyline/kernel/types/KProcess.h @@ -94,7 +94,7 @@ namespace skyline { * @return A shared pointer to a KThread initialized with the specified values or nullptr, if thread creation has been disabled * @note The default values are for the main thread and will use values from the NPDM */ - std::shared_ptr CreateThread(void *entry, u64 argument = 0, void *stackTop = nullptr, std::optional priority = std::nullopt, std::optional idealCore = std::nullopt); + std::shared_ptr CreateThread(void *entry, u64 argument = 0, void *stackTop = nullptr, std::optional priority = std::nullopt, std::optional idealCore = std::nullopt); /** * @brief The output for functions that return created kernel objects diff --git a/app/src/main/cpp/skyline/kernel/types/KThread.cpp b/app/src/main/cpp/skyline/kernel/types/KThread.cpp index c1a0970c..48288da3 100644 --- a/app/src/main/cpp/skyline/kernel/types/KThread.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KThread.cpp @@ -11,7 +11,7 @@ #include "KThread.h" namespace skyline::kernel::type { - KThread::KThread(const DeviceState &state, KHandle handle, KProcess *parent, size_t id, void *entry, u64 argument, void *stackTop, u8 priority, i8 idealCore) : handle(handle), parent(parent), id(id), entry(entry), entryArgument(argument), stackTop(stackTop), priority(priority), basePriority(priority), idealCore(idealCore), coreId(idealCore), KSyncObject(state, KType::KThread) { + KThread::KThread(const DeviceState &state, KHandle handle, KProcess *parent, size_t id, void *entry, u64 argument, void *stackTop, i8 priority, u8 idealCore) : handle(handle), parent(parent), id(id), entry(entry), entryArgument(argument), stackTop(stackTop), priority(priority), basePriority(priority), idealCore(idealCore), coreId(idealCore), KSyncObject(state, KType::KThread) { affinityMask.set(coreId); } @@ -235,7 +235,7 @@ namespace skyline::kernel::type { statusCondition.wait(lock, [this]() { return ready || killed; }); if (!killed && running) { struct itimerspec spec{.it_value = { - .tv_nsec = std::min(timeToFire.count(), static_cast(constant::NsInSecond)), + .tv_nsec = std::min(static_cast(timeToFire.count()), constant::NsInSecond), .tv_sec = std::max(std::chrono::duration_cast(timeToFire).count() - 1, 0LL), }}; timer_settime(preemptionTimer, 0, &spec, nullptr); @@ -258,9 +258,9 @@ namespace skyline::kernel::type { void KThread::UpdatePriorityInheritance() { auto waitingOn{waitThread}; - u8 currentPriority{priority.load()}; + i8 currentPriority{priority.load()}; while (waitingOn) { - u8 ownerPriority; + i8 ownerPriority; do { // Try to CAS the priority of the owner with the current thread // If the new priority is equivalent to the current priority then we don't need to CAS diff --git a/app/src/main/cpp/skyline/kernel/types/KThread.h b/app/src/main/cpp/skyline/kernel/types/KThread.h index a2b640df..e9c36f06 100644 --- a/app/src/main/cpp/skyline/kernel/types/KThread.h +++ b/app/src/main/cpp/skyline/kernel/types/KThread.h @@ -47,12 +47,12 @@ namespace skyline { void *stackTop; //!< The top of the guest's stack, this is set to the initial guest stack pointer std::condition_variable scheduleCondition; //!< Signalled to wake the thread when it's scheduled or its resident core changes - std::atomic basePriority; //!< The priority of the thread for the scheduler without any priority-inheritance - std::atomic priority; //!< The priority of the thread for the scheduler including priority-inheritance + std::atomic basePriority; //!< The priority of the thread for the scheduler without any priority-inheritance + std::atomic priority; //!< The priority of the thread for the scheduler including priority-inheritance std::mutex coreMigrationMutex; //!< Synchronizes operations which depend on which core the thread is running on - i8 idealCore; //!< The ideal CPU core for this thread to run on - i8 coreId; //!< The CPU core on which this thread is running + u8 idealCore; //!< The ideal CPU core for this thread to run on + u8 coreId; //!< The CPU core on which this thread is running CoreMask affinityMask{}; //!< A mask of CPU cores this thread is allowed to run on u64 timesliceStart{}; //!< A timestamp in host CNTVCT ticks of when the thread's current timeslice started @@ -72,7 +72,7 @@ namespace skyline { bool cancelSync{false}; //!< Whether to cancel the SvcWaitSynchronization call this thread currently is in/the next one it joins type::KSyncObject *wakeObject{}; //!< A pointer to the synchronization object responsible for waking this thread up - KThread(const DeviceState &state, KHandle handle, KProcess *parent, size_t id, void *entry, u64 argument, void *stackTop, u8 priority, i8 idealCore); + KThread(const DeviceState &state, KHandle handle, KProcess *parent, size_t id, void *entry, u64 argument, void *stackTop, i8 priority, u8 idealCore); ~KThread(); diff --git a/app/src/main/cpp/skyline/loader/nso.cpp b/app/src/main/cpp/skyline/loader/nso.cpp index e6200c7d..228e7a24 100644 --- a/app/src/main/cpp/skyline/loader/nso.cpp +++ b/app/src/main/cpp/skyline/loader/nso.cpp @@ -21,7 +21,7 @@ namespace skyline::loader { std::vector compressedBuffer(compressedSize); backing->Read(compressedBuffer, segment.fileOffset); - LZ4_decompress_safe(reinterpret_cast(compressedBuffer.data()), reinterpret_cast(outputBuffer.data()), compressedSize, segment.decompressedSize); + LZ4_decompress_safe(reinterpret_cast(compressedBuffer.data()), reinterpret_cast(outputBuffer.data()), static_cast(compressedSize), static_cast(segment.decompressedSize)); } else { backing->Read(outputBuffer, segment.fileOffset); } diff --git a/app/src/main/cpp/skyline/nce.cpp b/app/src/main/cpp/skyline/nce.cpp index 3b0f69da..92d5ca73 100644 --- a/app/src/main/cpp/skyline/nce.cpp +++ b/app/src/main/cpp/skyline/nce.cpp @@ -166,30 +166,31 @@ namespace skyline::nce { auto svc{*reinterpret_cast(instruction)}; auto mrs{*reinterpret_cast(instruction)}; auto msr{*reinterpret_cast(instruction)}; + auto instructionOffset{static_cast(instruction - start)}; if (svc.Verify()) { size += 7; - offsets.push_back(instruction - start); + offsets.push_back(instructionOffset); } else if (mrs.Verify()) { if (mrs.srcReg == TpidrroEl0 || mrs.srcReg == TpidrEl0) { size += ((mrs.destReg != registers::X0) ? 6 : 3); - offsets.push_back(instruction - start); + offsets.push_back(instructionOffset); } else { if (rescaleClock) { if (mrs.srcReg == CntpctEl0) { size += guest::RescaleClockSize + 3; - offsets.push_back(instruction - start); + offsets.push_back(instructionOffset); } else if (mrs.srcReg == CntfrqEl0) { size += 3; - offsets.push_back(instruction - start); + offsets.push_back(instructionOffset); } } else if (mrs.srcReg == CntpctEl0) { - offsets.push_back(instruction - start); + offsets.push_back(instructionOffset); } } } else if (msr.Verify() && msr.destReg == TpidrEl0) { size += 6; - offsets.push_back(instruction - start); + offsets.push_back(instructionOffset); } } return {util::AlignUp(size * sizeof(u32), PAGE_SIZE), offsets}; @@ -248,33 +249,35 @@ namespace skyline::nce { auto svc{*reinterpret_cast(instruction)}; auto mrs{*reinterpret_cast(instruction)}; auto msr{*reinterpret_cast(instruction)}; + auto endOffset{[&] { return static_cast(end - patch); }}; + auto startOffset{[&] { return static_cast(start - patch); }}; if (svc.Verify()) { /* Per-SVC Trampoline */ /* Rewrite SVC with B to trampoline */ - *instruction = instructions::B((end - patch) + offset, true).raw; + *instruction = instructions::B(static_cast(endOffset() + offset), true).raw; /* Save Context */ *patch++ = 0xF81F0FFE; // STR LR, [SP, #-16]! - *patch = instructions::BL(start - patch).raw; + *patch = instructions::BL(static_cast(startOffset())).raw; patch++; /* Jump to main SVC trampoline */ *patch++ = instructions::Movz(registers::W0, static_cast(svc.value)).raw; - *patch = instructions::BL((start - patch) + guest::SaveCtxSize).raw; + *patch = instructions::BL(static_cast(startOffset() + guest::SaveCtxSize)).raw; patch++; /* Restore Context and Return */ - *patch = instructions::BL((start - patch) + guest::SaveCtxSize + MainSvcTrampolineSize).raw; + *patch = instructions::BL(static_cast(startOffset() + guest::SaveCtxSize + MainSvcTrampolineSize)).raw; patch++; *patch++ = 0xF84107FE; // LDR LR, [SP], #16 - *patch = instructions::B((end - patch) + offset + 1).raw; + *patch = instructions::B(static_cast(endOffset() + offset + 1)).raw; patch++; } else if (mrs.Verify()) { if (mrs.srcReg == TpidrroEl0 || mrs.srcReg == TpidrEl0) { /* Emulated TLS Register Load */ /* Rewrite MRS with B to trampoline */ - *instruction = instructions::B((end - patch) + offset, true).raw; + *instruction = instructions::B(static_cast(endOffset() + offset), true).raw; /* Allocate Scratch Register */ if (mrs.destReg != registers::X0) @@ -292,14 +295,14 @@ namespace skyline::nce { *patch++ = instructions::Mov(registers::X(mrs.destReg), registers::X0).raw; *patch++ = 0xF84107E0; // LDR X0, [SP], #16 } - *patch = instructions::B((end - patch) + offset + 1).raw; + *patch = instructions::B(static_cast(endOffset() + offset + 1)).raw; patch++; } else { if (rescaleClock) { if (mrs.srcReg == CntpctEl0) { /* Physical Counter Load Emulation (With Rescaling) */ /* Rewrite MRS with B to trampoline */ - *instruction = instructions::B((end - patch) + offset, true).raw; + *instruction = instructions::B(static_cast(endOffset() + offset), true).raw; /* Rescale host clock */ std::memcpy(patch, reinterpret_cast(&guest::RescaleClock), guest::RescaleClockSize * sizeof(u32)); @@ -312,17 +315,17 @@ namespace skyline::nce { /* Free 32B stack allocation by RescaleClock and Return */ *patch++ = {0x910083FF}; // ADD SP, SP, #32 - *patch = instructions::B((end - patch) + offset + 1).raw; + *patch = instructions::B(static_cast(endOffset() + offset + 1)).raw; patch++; } else if (mrs.srcReg == CntfrqEl0) { /* Physical Counter Frequency Load Emulation */ /* Rewrite MRS with B to trampoline */ - *instruction = instructions::B((end - patch) + offset, true).raw; + *instruction = instructions::B(static_cast(endOffset() + offset), true).raw; /* Write back Tegra X1 Counter Frequency and Return */ for (const auto &mov : instructions::MoveRegister(registers::X(mrs.destReg), TegraX1Freq)) *patch++ = mov; - *patch = instructions::B((end - patch) + offset + 1).raw; + *patch = instructions::B(static_cast(endOffset() + offset + 1)).raw; patch++; } } else if (mrs.srcReg == CntpctEl0) { @@ -334,7 +337,7 @@ namespace skyline::nce { } else if (msr.Verify() && msr.destReg == TpidrEl0) { /* Emulated TLS Register Store */ /* Rewrite MSR with B to trampoline */ - *instruction = instructions::B((end - patch) + offset, true).raw; + *instruction = instructions::B(static_cast(endOffset() + offset), true).raw; /* Allocate Scratch Registers */ bool x0x1{mrs.srcReg != registers::X0 && mrs.srcReg != registers::X1}; @@ -347,7 +350,7 @@ namespace skyline::nce { /* Restore Scratch Registers and Return */ *patch++ = x0x1 ? 0xA8C107E0 : 0xA8C10FE2; // LDP X(0/2), X(1/3), [SP], #16 - *patch = instructions::B((end - patch) + offset + 1).raw; + *patch = instructions::B(static_cast(endOffset() + offset + 1)).raw; patch++; } } diff --git a/app/src/main/cpp/skyline/nce/instructions.h b/app/src/main/cpp/skyline/nce/instructions.h index 605dbce6..a116fb85 100644 --- a/app/src/main/cpp/skyline/nce/instructions.h +++ b/app/src/main/cpp/skyline/nce/instructions.h @@ -104,13 +104,13 @@ namespace skyline::nce { /** * @param negate The direction of the supplied offset */ - constexpr B(i64 offset, bool negate = false) : offset(negate ? -offset : offset), sig(0x5) {} + constexpr B(i32 offset, bool negate = false) : offset(negate ? -offset : offset), sig(0x5) {} /** * @return The offset encoded within the instruction in bytes */ constexpr i32 Offset() { - return offset * sizeof(u32); + return offset * static_cast(sizeof(u32)); } constexpr bool Verify() { @@ -138,7 +138,7 @@ namespace skyline::nce { * @return The offset encoded within the instruction in bytes */ constexpr i32 Offset() { - return offset * sizeof(u32); + return offset * static_cast(sizeof(u32)); } constexpr bool Verify() { diff --git a/app/src/main/cpp/skyline/services/am/storage/IStorageAccessor.cpp b/app/src/main/cpp/skyline/services/am/storage/IStorageAccessor.cpp index e6f1ac0a..897a075b 100644 --- a/app/src/main/cpp/skyline/services/am/storage/IStorageAccessor.cpp +++ b/app/src/main/cpp/skyline/services/am/storage/IStorageAccessor.cpp @@ -8,7 +8,7 @@ namespace skyline::service::am { IStorageAccessor::IStorageAccessor(const DeviceState &state, ServiceManager &manager, std::shared_ptr parent) : parent(std::move(parent)), BaseService(state, manager) {} Result IStorageAccessor::GetSize(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { - response.Push(parent->content.size()); + response.Push(static_cast(parent->content.size())); return {}; } @@ -18,7 +18,7 @@ namespace skyline::service::am { if (offset < 0 || offset > parent->content.size()) return result::OutOfBounds; - auto size{std::min(static_cast(request.inputBuf.at(0).size()), static_cast(parent->content.size()) - offset)}; + size_t size{std::min(request.inputBuf.at(0).size(), parent->content.size() - static_cast(offset))}; if (size) span(parent->content).copy_from(request.inputBuf.at(0), size); @@ -32,7 +32,7 @@ namespace skyline::service::am { if (offset < 0 || offset > parent->content.size()) return result::OutOfBounds; - auto size{std::min(static_cast(request.outputBuf.at(0).size()), static_cast(parent->content.size()) - offset)}; + size_t size{std::min(request.outputBuf.at(0).size(), parent->content.size() - static_cast(offset))}; if (size) request.outputBuf.at(0).copy_from(span(parent->content.data() + offset, size)); diff --git a/app/src/main/cpp/skyline/services/audio/IAudioRendererManager.cpp b/app/src/main/cpp/skyline/services/audio/IAudioRendererManager.cpp index 285bbbef..43f86a3d 100644 --- a/app/src/main/cpp/skyline/services/audio/IAudioRendererManager.cpp +++ b/app/src/main/cpp/skyline/services/audio/IAudioRendererManager.cpp @@ -26,7 +26,7 @@ namespace skyline::service::audio { u32 totalMixCount{params.subMixCount + 1}; - i64 size{util::AlignUp(params.mixBufferCount * 4, constant::BufferAlignment) + + u64 size{util::AlignUp(params.mixBufferCount * 4, constant::BufferAlignment) + params.subMixCount * 0x400 + totalMixCount * 0x940 + params.voiceCount * 0x3F0 + @@ -35,21 +35,21 @@ namespace skyline::service::audio { util::AlignUp(((params.sinkCount + params.subMixCount) * 0x3C0 + params.sampleCount * 4) * (params.mixBufferCount + 6), constant::BufferAlignment) + (params.sinkCount + params.subMixCount) * 0x2C0 + (params.effectCount + params.voiceCount * 4) * 0x30 + 0x50}; if (revisionInfo.SplitterSupported()) { - i32 nodeStateWorkSize{util::AlignUp(totalMixCount, constant::BufferAlignment)}; + i32 nodeStateWorkSize{static_cast(util::AlignUp(totalMixCount, constant::BufferAlignment))}; if (nodeStateWorkSize < 0) nodeStateWorkSize |= 7; - nodeStateWorkSize = 4 * (totalMixCount * totalMixCount) + 12 * totalMixCount + 2 * (nodeStateWorkSize / 8); + nodeStateWorkSize = static_cast(4 * (totalMixCount * totalMixCount) + 12 * totalMixCount + static_cast(2 * (nodeStateWorkSize / 8))); - i32 edgeMatrixWorkSize{util::AlignUp(totalMixCount * totalMixCount, constant::BufferAlignment)}; + i32 edgeMatrixWorkSize{static_cast(util::AlignUp(totalMixCount * totalMixCount, constant::BufferAlignment))}; if (edgeMatrixWorkSize < 0) edgeMatrixWorkSize |= 7; edgeMatrixWorkSize /= 8; - size += util::AlignUp(edgeMatrixWorkSize + nodeStateWorkSize, 16); + size += util::AlignUp(static_cast(edgeMatrixWorkSize + nodeStateWorkSize), 16); } - i64 splitterWorkSize{}; + u64 splitterWorkSize{}; if (revisionInfo.SplitterSupported()) { splitterWorkSize += params.splitterDestinationDataCount * 0xE0 + params.splitterCount * 0x20; @@ -57,7 +57,7 @@ namespace skyline::service::audio { splitterWorkSize += util::AlignUp(4 * params.splitterDestinationDataCount, 16); } - size = params.sinkCount * 0x170 + (params.sinkCount + params.subMixCount) * 0x280 + params.effectCount * 0x4C0 + ((size + splitterWorkSize + 0x30 * params.effectCount + (4 * params.voiceCount) + 0x8F) & ~0x3FL) + ((params.voiceCount << 8) | 0x40); + size = params.sinkCount * 0x170 + (params.sinkCount + params.subMixCount) * 0x280 + params.effectCount * 0x4C0 + ((size + splitterWorkSize + 0x30 * params.effectCount + (4 * params.voiceCount) + 0x8F) & ~0x3FUL) + ((params.voiceCount << 8) | 0x40); if (params.performanceManagerCount > 0) { i64 performanceMetricsBufferSize{}; @@ -67,7 +67,7 @@ namespace skyline::service::audio { performanceMetricsBufferSize = ((static_cast((params.voiceCount + params.effectCount + totalMixCount + params.sinkCount)) << 32) >> 0x1C) + 0x658; } - size += (performanceMetricsBufferSize * (params.performanceManagerCount + 1) + 0xFF) & ~0x3FL; + size += static_cast((performanceMetricsBufferSize * (params.performanceManagerCount + 1) + 0xFF) & ~0x3FL); } if (revisionInfo.VaradicCommandBufferSizeSupported()) { @@ -79,7 +79,7 @@ namespace skyline::service::audio { size = util::AlignUp(size, 0x1000); state.logger->Debug("Work buffer size: 0x{:X}", size); - response.Push(size); + response.Push(size); return {}; } diff --git a/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoder.cpp b/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoder.cpp index f1496934..e70d563d 100644 --- a/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoder.cpp +++ b/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoder.cpp @@ -7,8 +7,8 @@ #include "IHardwareOpusDecoder.h" namespace skyline::service::codec { - size_t CalculateOutBufferSize(i32 sampleRate, i32 channelCount, i32 frameSize) { - return util::AlignUp(frameSize * channelCount / (OpusFullbandSampleRate / sampleRate), 0x40); + u32 CalculateOutBufferSize(i32 sampleRate, i32 channelCount, i32 frameSize) { + return util::AlignUp(static_cast(frameSize * channelCount / (OpusFullbandSampleRate / sampleRate)), 0x40); } IHardwareOpusDecoder::IHardwareOpusDecoder(const DeviceState &state, ServiceManager &manager, i32 sampleRate, i32 channelCount, u32 workBufferSize, KHandle workBufferHandle) @@ -54,8 +54,8 @@ namespace skyline::service::codec { if (dataIn.size() <= sizeof(OpusDataHeader)) throw exception("Incorrect Opus data size: 0x{:X} (Should be > 0x{:X})", dataIn.size(), sizeof(OpusDataHeader)); - u32 opusPacketSize{dataIn.as().GetPacketSize()}; - i32 requiredInSize{static_cast(opusPacketSize + sizeof(OpusDataHeader))}; + i32 opusPacketSize{dataIn.as().GetPacketSize()}; + i32 requiredInSize{opusPacketSize + static_cast(sizeof(OpusDataHeader))}; if (opusPacketSize > MaxInputBufferSize || dataIn.size() < requiredInSize) throw exception("Opus packet size mismatch: 0x{:X} (Requested: 0x{:X})", dataIn.size() - sizeof(OpusDataHeader), opusPacketSize); @@ -63,7 +63,7 @@ namespace skyline::service::codec { auto sampleDataIn = dataIn.subspan(sizeof(OpusDataHeader)); auto perfTimer{timesrv::TimeSpanType::FromNanoseconds(util::GetTimeNs())}; - i32 decodedCount{opus_decode(decoderState, sampleDataIn.data(), opusPacketSize, dataOut.data(), decoderOutputBufferSize, false)}; + i32 decodedCount{opus_decode(decoderState, sampleDataIn.data(), opusPacketSize, dataOut.data(), static_cast(decoderOutputBufferSize), false)}; perfTimer = timesrv::TimeSpanType::FromNanoseconds(util::GetTimeNs()) - perfTimer; if (decodedCount < 0) @@ -72,7 +72,7 @@ namespace skyline::service::codec { response.Push(requiredInSize); // Decoded data size is equal to opus packet size + header response.Push(decodedCount); if (writeDecodeTime) - response.Push(perfTimer.Microseconds()); + response.Push(perfTimer.Microseconds()); return {}; } diff --git a/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoder.h b/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoder.h index a41f474e..9521c314 100644 --- a/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoder.h +++ b/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoder.h @@ -13,11 +13,11 @@ namespace skyline::service::codec { /** * @return The required output buffer size for decoding an Opus stream with the given parameters */ - size_t CalculateOutBufferSize(i32 sampleRate, i32 channelCount, i32 frameSize); + u32 CalculateOutBufferSize(i32 sampleRate, i32 channelCount, i32 frameSize); - static constexpr u32 OpusFullbandSampleRate{48000}; - static constexpr u32 MaxFrameSizeNormal = OpusFullbandSampleRate * 0.040; //!< 40ms frame size limit for normal decoders - static constexpr u32 MaxFrameSizeEx = OpusFullbandSampleRate * 0.120; //!< 120ms frame size limit for ex decoders added in 12.0.0 + static constexpr i32 OpusFullbandSampleRate{48000}; + static constexpr i32 MaxFrameSizeNormal{static_cast(OpusFullbandSampleRate * 0.040f)}; //!< 40ms frame size limit for normal decoders + static constexpr i32 MaxFrameSizeEx{static_cast(OpusFullbandSampleRate * 0.120f)}; //!< 120ms frame size limit for ex decoders added in 12.0.0 static constexpr u32 MaxInputBufferSize{0x600}; //!< Maximum allocated size of the input buffer /** @@ -30,7 +30,7 @@ namespace skyline::service::codec { OpusDecoder *decoderState{}; i32 sampleRate; i32 channelCount; - i32 decoderOutputBufferSize; + u32 decoderOutputBufferSize; /** * @brief Holds information about the Opus packet to be decoded @@ -41,8 +41,8 @@ namespace skyline::service::codec { u32 sizeBe; //!< Size of the packet following this header u32 finalRangeBe; //!< Final range of the codec encoder's entropy coder (can be zero) - u32 GetPacketSize() { - return util::SwapEndianness(sizeBe); + i32 GetPacketSize() { + return static_cast(util::SwapEndianness(sizeBe)); } }; static_assert(sizeof(OpusDataHeader) == 0x8); diff --git a/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoderManager.cpp b/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoderManager.cpp index 6b2cbe37..cc12d2a9 100644 --- a/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoderManager.cpp +++ b/app/src/main/cpp/skyline/services/codec/IHardwareOpusDecoderManager.cpp @@ -7,8 +7,8 @@ #include "IHardwareOpusDecoder.h" namespace skyline::service::codec { - static size_t CalculateBufferSize(i32 sampleRate, i32 channelCount) { - i32 requiredSize{opus_decoder_get_size(channelCount)}; + static u32 CalculateBufferSize(i32 sampleRate, i32 channelCount) { + u32 requiredSize{static_cast(opus_decoder_get_size(channelCount))}; requiredSize += MaxInputBufferSize + CalculateOutBufferSize(sampleRate, channelCount, MaxFrameSizeNormal); return requiredSize; } diff --git a/app/src/main/cpp/skyline/services/fssrv/IFile.cpp b/app/src/main/cpp/skyline/services/fssrv/IFile.cpp index 68c582c2..cc3a06ed 100644 --- a/app/src/main/cpp/skyline/services/fssrv/IFile.cpp +++ b/app/src/main/cpp/skyline/services/fssrv/IFile.cpp @@ -23,7 +23,7 @@ namespace skyline::service::fssrv { return result::InvalidSize; } - response.Push(static_cast(backing->ReadUnchecked(request.outputBuf.at(0), offset))); + response.Push(backing->ReadUnchecked(request.outputBuf.at(0), static_cast(offset))); return {}; } @@ -48,7 +48,7 @@ namespace skyline::service::fssrv { return result::InvalidSize; } - if (backing->Write(request.inputBuf.at(0), offset) != size) { + if (backing->Write(request.inputBuf.at(0), static_cast(offset)) != size) { state.logger->Warn("Failed to write all data to the backing"); return result::UnexpectedFailure; } diff --git a/app/src/main/cpp/skyline/services/fssrv/IStorage.cpp b/app/src/main/cpp/skyline/services/fssrv/IStorage.cpp index 7c1c547d..f9a3d71f 100644 --- a/app/src/main/cpp/skyline/services/fssrv/IStorage.cpp +++ b/app/src/main/cpp/skyline/services/fssrv/IStorage.cpp @@ -21,7 +21,7 @@ namespace skyline::service::fssrv { return result::InvalidSize; } - backing->Read(request.outputBuf.at(0), offset); + backing->Read(request.outputBuf.at(0), static_cast(offset)); return {}; } diff --git a/app/src/main/cpp/skyline/services/glue/ITimeZoneService.cpp b/app/src/main/cpp/skyline/services/glue/ITimeZoneService.cpp index 9457d6ab..2baee315 100644 --- a/app/src/main/cpp/skyline/services/glue/ITimeZoneService.cpp +++ b/app/src/main/cpp/skyline/services/glue/ITimeZoneService.cpp @@ -42,7 +42,7 @@ namespace skyline::service::glue { outList.copy_from(span(timesrvCore.locationNameList).subspan(offset, outList.size())); - response.Push(outList.size()); + response.Push(static_cast(outList.size())); return {}; } diff --git a/app/src/main/cpp/skyline/services/hid/IHidServer.cpp b/app/src/main/cpp/skyline/services/hid/IHidServer.cpp index e80a66b4..9b2791ea 100644 --- a/app/src/main/cpp/skyline/services/hid/IHidServer.cpp +++ b/app/src/main/cpp/skyline/services/hid/IHidServer.cpp @@ -70,7 +70,7 @@ namespace skyline::service::hid { Result IHidServer::GetPlayerLedPattern(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto id{request.Pop()}; - response.Push([id] { + response.Push([id]() -> u64 { switch (id) { case NpadId::Player1: return 0b0001; diff --git a/app/src/main/cpp/skyline/services/hosbinder/GraphicBufferProducer.cpp b/app/src/main/cpp/skyline/services/hosbinder/GraphicBufferProducer.cpp index 4b0ff4b4..ec265a50 100644 --- a/app/src/main/cpp/skyline/services/hosbinder/GraphicBufferProducer.cpp +++ b/app/src/main/cpp/skyline/services/hosbinder/GraphicBufferProducer.cpp @@ -34,7 +34,7 @@ namespace skyline::service::hosbinder { return AndroidStatus::BadValue; } - auto &bufferSlot{queue[slot]}; + auto &bufferSlot{queue[static_cast(slot)]}; bufferSlot.wasBufferRequested = true; buffer = bufferSlot.graphicBuffer.get(); @@ -77,7 +77,7 @@ namespace skyline::service::hosbinder { state.logger->Warn("Setting the active slot count ({}) higher than the amount of slots with preallocated buffers ({})", count, preallocatedBufferCount); } - activeSlotCount = count; + activeSlotCount = static_cast(count); bufferEvent->Signal(); return AndroidStatus::Ok; @@ -157,7 +157,7 @@ namespace skyline::service::hosbinder { return AndroidStatus::BadValue; } - auto &bufferSlot{queue[slot]}; + auto &bufferSlot{queue[static_cast(slot)]}; if (bufferSlot.state != BufferState::Dequeued) [[unlikely]] { state.logger->Warn("#{} was '{}' instead of being dequeued", slot, ToString(bufferSlot.state)); return AndroidStatus::BadValue; @@ -245,10 +245,10 @@ namespace skyline::service::hosbinder { FreeGraphicBufferNvMap(*bufferSlot->graphicBuffer); bufferSlot->graphicBuffer = std::make_unique(graphicBuffer); - slot = std::distance(queue.begin(), bufferSlot); + slot = static_cast(std::distance(queue.begin(), bufferSlot)); - preallocatedBufferCount = std::count_if(queue.begin(), queue.end(), [](const BufferSlot &slot) { return slot.graphicBuffer && slot.isPreallocated; }); - activeSlotCount = std::count_if(queue.begin(), queue.end(), [](const BufferSlot &slot) { return slot.graphicBuffer != nullptr; }); + preallocatedBufferCount = static_cast(std::count_if(queue.begin(), queue.end(), [](const auto &slot) { return slot.graphicBuffer && slot.isPreallocated; })); + activeSlotCount = static_cast(std::count_if(queue.begin(), queue.end(), [](const auto &slot) { return slot.graphicBuffer != nullptr; })); state.logger->Debug("#{} - Dimensions: {}x{} [Stride: {}], Format: {}, Layout: {}, {}: {}, Usage: 0x{:X}, NvMap {}: {}, Buffer Start/End: 0x{:X} -> 0x{:X}", slot, surface.width, surface.height, handle.stride, ToString(handle.format), ToString(surface.layout), surface.layout == NvSurfaceLayout::Blocklinear ? "Block Height" : "Pitch", surface.layout == NvSurfaceLayout::Blocklinear ? 1U << surface.blockHeightLog2 : surface.pitch, graphicBuffer.usage, surface.nvmapHandle ? "Handle" : "ID", surface.nvmapHandle ? surface.nvmapHandle : handle.nvmapId, surface.offset, surface.offset + surface.size); return AndroidStatus::Ok; @@ -273,7 +273,7 @@ namespace skyline::service::hosbinder { return AndroidStatus::BadValue; } - auto &buffer{queue[slot]}; + auto &buffer{queue[static_cast(slot)]}; if (buffer.state != BufferState::Dequeued) [[unlikely]] { state.logger->Warn("#{} was '{}' instead of being dequeued", slot, ToString(buffer.state)); return AndroidStatus::BadValue; @@ -411,7 +411,7 @@ namespace skyline::service::hosbinder { return; } - auto &buffer{queue[slot]}; + auto &buffer{queue[static_cast(slot)]}; if (buffer.state != BufferState::Dequeued) [[unlikely]] { state.logger->Warn("#{} is not owned by the producer as it is '{}' instead of being dequeued", slot, ToString(buffer.state)); return; @@ -544,7 +544,7 @@ namespace skyline::service::hosbinder { return AndroidStatus::BadValue; } - auto &buffer{queue[slot]}; + auto &buffer{queue[static_cast(slot)]}; buffer.state = BufferState::Free; buffer.frameNumber = 0; buffer.wasBufferRequested = false; @@ -578,8 +578,8 @@ namespace skyline::service::hosbinder { state.logger->Debug("#{} - No GraphicBuffer", slot); } - preallocatedBufferCount = std::count_if(queue.begin(), queue.end(), [](const BufferSlot &slot) { return slot.graphicBuffer && slot.isPreallocated; }); - activeSlotCount = std::count_if(queue.begin(), queue.end(), [](const BufferSlot &slot) { return slot.graphicBuffer != nullptr; }); + preallocatedBufferCount = static_cast(std::count_if(queue.begin(), queue.end(), [](const BufferSlot &slot) { return slot.graphicBuffer && slot.isPreallocated; })); + activeSlotCount = static_cast(std::count_if(queue.begin(), queue.end(), [](const BufferSlot &slot) { return slot.graphicBuffer != nullptr; })); bufferEvent->Signal(); diff --git a/app/src/main/cpp/skyline/services/hosbinder/parcel.cpp b/app/src/main/cpp/skyline/services/hosbinder/parcel.cpp index fcc7b108..3d20b19f 100644 --- a/app/src/main/cpp/skyline/services/hosbinder/parcel.cpp +++ b/app/src/main/cpp/skyline/services/hosbinder/parcel.cpp @@ -26,7 +26,7 @@ namespace skyline::service::hosbinder { header.dataOffset = sizeof(ParcelHeader); header.objectsSize = static_cast(objects.size()); - header.objectsOffset = sizeof(ParcelHeader) + data.size(); + header.objectsOffset = static_cast(sizeof(ParcelHeader) + data.size()); auto totalSize{sizeof(ParcelHeader) + header.dataSize + header.objectsSize}; diff --git a/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp b/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp index 93552250..49c222a1 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/INvDrvServices.cpp @@ -72,7 +72,7 @@ namespace skyline::service::nvdrv { } Result INvDrvServices::Close(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { - auto fd{request.Pop()}; + auto fd{request.Pop()}; state.logger->Debug("Closing NVDRV device ({})", fd); driver.CloseDevice(fd); @@ -85,7 +85,7 @@ namespace skyline::service::nvdrv { } Result INvDrvServices::QueryEvent(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { - auto fd{request.Pop()}; + auto fd{request.Pop()}; auto eventId{request.Pop()}; auto event{driver.QueryEvent(fd, eventId)}; diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/deserialisation/types.h b/app/src/main/cpp/skyline/services/nvdrv/devices/deserialisation/types.h index 91df017e..ea5761cf 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/deserialisation/types.h +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/deserialisation/types.h @@ -106,11 +106,11 @@ namespace skyline::service::nvdrv::deserialisation { constexpr static u32 Raw() { u32 raw{Function}; - i8 offset{8}; - raw |= Magic << offset; offset += 8; - raw |= Size << offset; offset += 14; - raw |= In << offset; offset++; - raw |= Out << offset; offset++; + int offset{8}; + raw |= static_cast(Magic << offset); offset += 8; + raw |= static_cast(Size << offset); offset += 14; + raw |= (In ? 1U : 0U) << offset; offset++; + raw |= (Out ? 1U : 0U) << offset; offset++; return raw; } }; @@ -130,10 +130,10 @@ namespace skyline::service::nvdrv::deserialisation { u32 raw{Function}; i8 offset{8}; - raw |= Magic << offset; offset += 8; + raw |= static_cast(Magic << offset); offset += 8; offset += 14; // Use a 0 size for raw - raw |= In << offset; offset++; - raw |= Out << offset; offset++; + raw |= (In ? 1U : 0U) << offset; offset++; + raw |= (Out ? 1U : 0U) << offset; offset++; return raw; } }; diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.cpp b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.cpp index bf1e9c7b..9d3e9c89 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/as_gpu.cpp @@ -66,7 +66,7 @@ namespace skyline::service::nvdrv::device::nvhost { auto &allocator{pageSize == VM::PageSize ? *vm.smallPageAllocator : *vm.bigPageAllocator}; if (flags.fixed) - allocator.AllocateFixed(offset >> pageSizeBits, pages); + allocator.AllocateFixed(static_cast(offset >> pageSizeBits), pages); else offset = static_cast(allocator.Allocate(pages)) << pageSizeBits; @@ -91,7 +91,7 @@ namespace skyline::service::nvdrv::device::nvhost { auto &allocator{mapping->bigPage ? *vm.bigPageAllocator : *vm.smallPageAllocator}; u32 pageSizeBits{mapping->bigPage ? vm.bigPageSizeBits : VM::PageSizeBits}; - allocator.Free(mapping->offset >> pageSizeBits, mapping->size >> pageSizeBits); + allocator.Free(static_cast(mapping->offset >> pageSizeBits), static_cast(mapping->size >> pageSizeBits)); } // Sparse mappings shouldn't be fully unmapped, just returned to their sparse state @@ -128,7 +128,7 @@ namespace skyline::service::nvdrv::device::nvhost { auto &allocator{pageSize == VM::PageSize ? *vm.smallPageAllocator : *vm.bigPageAllocator}; u32 pageSizeBits{pageSize == VM::PageSize ? VM::PageSizeBits : vm.bigPageSizeBits}; - allocator.Free(offset >> pageSizeBits, allocation.size >> pageSizeBits); + allocator.Free(static_cast(offset >> pageSizeBits), static_cast(allocation.size >> pageSizeBits)); allocationMap.erase(offset); } catch (const std::out_of_range &e) { return PosixResult::InvalidArgument; @@ -152,7 +152,7 @@ namespace skyline::service::nvdrv::device::nvhost { auto &allocator{mapping->bigPage ? *vm.bigPageAllocator : *vm.smallPageAllocator}; u32 pageSizeBits{mapping->bigPage ? vm.bigPageSizeBits : VM::PageSizeBits}; - allocator.Free(mapping->offset >> pageSizeBits, mapping->size >> pageSizeBits); + allocator.Free(static_cast(mapping->offset >> pageSizeBits), static_cast(mapping->size >> pageSizeBits)); } // Sparse mappings shouldn't be fully unmapped, just returned to their sparse state @@ -235,7 +235,7 @@ namespace skyline::service::nvdrv::device::nvhost { u32 pageSize{bigPage ? vm.bigPageSize : VM::PageSize}; u32 pageSizeBits{bigPage ? vm.bigPageSizeBits : VM::PageSizeBits}; - offset = static_cast(allocator.Allocate(util::AlignUp(size, pageSize) >> pageSizeBits)) << pageSizeBits; + offset = static_cast(allocator.Allocate(static_cast(util::AlignUp(size, pageSize) >> pageSizeBits))) << pageSizeBits; asCtx->gmmu.Map(offset, cpuPtr, size); auto mapping{std::make_shared(cpuPtr, offset, size, false, bigPage, false)}; @@ -297,7 +297,7 @@ namespace skyline::service::nvdrv::device::nvhost { } vm.bigPageSize = bigPageSize; - vm.bigPageSizeBits = std::countr_zero(bigPageSize); + vm.bigPageSizeBits = static_cast(std::countr_zero(bigPageSize)); vm.vaRangeStart = bigPageSize << VM::VaStartShift; } diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl.cpp b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl.cpp index 2d095534..d672c786 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl.cpp @@ -118,7 +118,7 @@ namespace skyline::service::nvdrv::device::nvhost { value.val = 0; if (allocate) { - value.syncpointIdForAllocation = fence.id; + value.syncpointIdForAllocation = static_cast(fence.id); value.eventAllocated = true; } else { value.syncpointId = fence.id; @@ -215,11 +215,10 @@ namespace skyline::service::nvdrv::device::nvhost { // Avoid repeated locks/unlocks by just locking now std::lock_guard lock(syncpointEventMutex); - for (int i{}; i < 64; i++) { + for (u32 i{}; i < std::numeric_limits::digits; i++) if (bitmask & (1 << i)) if (auto freeErr{SyncpointFreeEventLocked(i)}; freeErr != PosixResult::Success) err = freeErr; - } return err; } diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.cpp b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.cpp index cce97cf7..50f57eff 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.cpp @@ -181,7 +181,7 @@ namespace skyline::service::nvdrv::device::nvhost { pushBufferMemory.resize(pushBufferWords); // Allocate pages in the GPU AS - pushBufferAddr = static_cast(asAllocator->Allocate((pushBufferWords >> AsGpu::VM::PageSizeBits) + 1)) << AsGpu::VM::PageSizeBits; + pushBufferAddr = static_cast(asAllocator->Allocate((static_cast(pushBufferWords) >> AsGpu::VM::PageSizeBits) + 1)) << AsGpu::VM::PageSizeBits; // Map onto the GPU asCtx->gmmu.Map(pushBufferAddr, reinterpret_cast(pushBufferMemory.data()), pushBufferSize); diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.h b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.h index 55a119ea..5207dbb5 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.h +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/gpu_channel.h @@ -17,7 +17,7 @@ namespace skyline::service::nvdrv::device::nvhost { class GpuChannel : public NvDevice { private: u32 channelSyncpoint{}; //!< The syncpoint for submissions allocated to this channel in `AllocGpfifo` - u32 channelUserData{}; + u64 channelUserData{}; std::mutex channelMutex; std::shared_ptr smExceptionBreakpointIntReportEvent; std::shared_ptr smExceptionBreakpointPauseReportEvent; diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.cpp b/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.cpp index 926e769b..092d5122 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvmap.cpp @@ -9,7 +9,7 @@ namespace skyline::service::nvdrv::device { NvMap::NvMap(const DeviceState &state, Driver &driver, Core &core, const SessionContext &ctx) : NvDevice(state, driver, core, ctx) {} PosixResult NvMap::Create(In size, Out handle) { - auto handleDesc{core.nvMap.CreateHandle(util::AlignUp(size, PAGE_SIZE))}; + auto handleDesc{core.nvMap.CreateHandle(util::AlignUp(static_cast(size), PAGE_SIZE))}; if (handleDesc) { (*handleDesc)->origSize = size; // Orig size is the unaligned size handle = (*handleDesc)->id; @@ -92,13 +92,13 @@ namespace skyline::service::nvdrv::device { switch (param) { case HandleParameterType::Size: - result = handleDesc->origSize; + result = static_cast(handleDesc->origSize); return PosixResult::Success; case HandleParameterType::Alignment: - result = handleDesc->align; + result = static_cast(handleDesc->align); return PosixResult::Success; case HandleParameterType::Base: - result = -static_cast(PosixResult::InvalidArgument); + result = static_cast(-static_cast(PosixResult::InvalidArgument)); return PosixResult::Success; case HandleParameterType::Heap: if (handleDesc->allocated) diff --git a/app/src/main/cpp/skyline/services/nvdrv/driver.cpp b/app/src/main/cpp/skyline/services/nvdrv/driver.cpp index 4f5cfebb..a0d651ea 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/driver.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/driver.cpp @@ -74,7 +74,7 @@ namespace skyline::service::nvdrv { } } - NvResult Driver::Ioctl(u32 fd, IoctlDescriptor cmd, span buffer) { + NvResult Driver::Ioctl(FileDescriptor fd, IoctlDescriptor cmd, span buffer) { state.logger->Debug("fd: {}, cmd: 0x{:X}, device: {}", fd, cmd.raw, devices.at(fd)->GetName()); try { @@ -85,7 +85,7 @@ namespace skyline::service::nvdrv { } } - NvResult Driver::Ioctl2(u32 fd, IoctlDescriptor cmd, span buffer, span inlineBuffer) { + NvResult Driver::Ioctl2(FileDescriptor fd, IoctlDescriptor cmd, span buffer, span inlineBuffer) { state.logger->Debug("fd: {}, cmd: 0x{:X}, device: {}", fd, cmd.raw, devices.at(fd)->GetName()); try { @@ -96,7 +96,7 @@ namespace skyline::service::nvdrv { } } - NvResult Driver::Ioctl3(u32 fd, IoctlDescriptor cmd, span buffer, span inlineBuffer) { + NvResult Driver::Ioctl3(FileDescriptor fd, IoctlDescriptor cmd, span buffer, span inlineBuffer) { state.logger->Debug("fd: {}, cmd: 0x{:X}, device: {}", fd, cmd.raw, devices.at(fd)->GetName()); try { @@ -107,7 +107,7 @@ namespace skyline::service::nvdrv { } } - void Driver::CloseDevice(u32 fd) { + void Driver::CloseDevice(FileDescriptor fd) { try { std::unique_lock lock(deviceMutex); devices.erase(fd); @@ -116,7 +116,7 @@ namespace skyline::service::nvdrv { } } - std::shared_ptr Driver::QueryEvent(u32 fd, u32 eventId) { + std::shared_ptr Driver::QueryEvent(FileDescriptor fd, u32 eventId) { state.logger->Debug("fd: {}, eventId: 0x{:X}, device: {}", fd, eventId, devices.at(fd)->GetName()); try { diff --git a/app/src/main/cpp/skyline/services/nvdrv/driver.h b/app/src/main/cpp/skyline/services/nvdrv/driver.h index c3d2a4bb..f34713ed 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/driver.h +++ b/app/src/main/cpp/skyline/services/nvdrv/driver.h @@ -41,26 +41,26 @@ namespace skyline::service::nvdrv { /** * @brief Calls an IOCTL on the device specified by `fd` */ - NvResult Ioctl(u32 fd, IoctlDescriptor cmd, span buffer); + NvResult Ioctl(FileDescriptor fd, IoctlDescriptor cmd, span buffer); /** * @brief Calls an IOCTL on the device specified by `fd` using the given inline input buffer */ - NvResult Ioctl2(u32 fd, IoctlDescriptor cmd, span buffer, span inlineBuffer); + NvResult Ioctl2(FileDescriptor fd, IoctlDescriptor cmd, span buffer, span inlineBuffer); /** * @brief Calls an IOCTL on the device specified by `fd` using the given inline output buffer */ - NvResult Ioctl3(u32 fd, IoctlDescriptor cmd, span buffer, span inlineBuffer); + NvResult Ioctl3(FileDescriptor fd, IoctlDescriptor cmd, span buffer, span inlineBuffer); /** * @brief Queries a KEvent for the given `eventId` for the device specified by `fd` */ - std::shared_ptr QueryEvent(u32 fd, u32 eventId); + std::shared_ptr QueryEvent(FileDescriptor fd, u32 eventId); /** * @brief Closes the device specified by `fd` */ - void CloseDevice(u32 fd); + void CloseDevice(FileDescriptor fd); }; } diff --git a/app/src/main/cpp/skyline/services/pl/shared_font_core.h b/app/src/main/cpp/skyline/services/pl/shared_font_core.h index a49cfcff..32c879bc 100644 --- a/app/src/main/cpp/skyline/services/pl/shared_font_core.h +++ b/app/src/main/cpp/skyline/services/pl/shared_font_core.h @@ -17,8 +17,8 @@ namespace skyline::service::pl { struct FontEntry { std::string path; //!< The path of the font asset - size_t length; //!< The length of the font TTF data - size_t offset; //!< The offset of the font in shared memory + u32 length; //!< The length of the font TTF data + u32 offset; //!< The offset of the font in shared memory }; std::array fonts{ @@ -42,7 +42,7 @@ namespace skyline::service::pl { for (auto &font : fonts) { *ptr++ = 0x18029a7f; *ptr++ = util::SwapEndianness(font.length ^ 0x49621806); - font.offset = reinterpret_cast(ptr) - reinterpret_cast(sharedFontMemory->host.ptr); + font.offset = static_cast(reinterpret_cast(ptr) - reinterpret_cast(sharedFontMemory->host.ptr)); std::shared_ptr fontFile; if (fontsDirectory->FileExists(font.path)) @@ -50,7 +50,7 @@ namespace skyline::service::pl { else fontFile = state.os->assetFileSystem->OpenFile("fonts/" + font.path); - font.length = fontFile->size; + font.length = static_cast(fontFile->size); fontFile->Read(span(reinterpret_cast(ptr), font.length)); ptr = reinterpret_cast(reinterpret_cast(ptr) + font.length); } diff --git a/app/src/main/cpp/skyline/services/settings/ISettingsServer.cpp b/app/src/main/cpp/skyline/services/settings/ISettingsServer.cpp index 7a59b504..604e22bc 100644 --- a/app/src/main/cpp/skyline/services/settings/ISettingsServer.cpp +++ b/app/src/main/cpp/skyline/services/settings/ISettingsServer.cpp @@ -14,7 +14,7 @@ namespace skyline::service::settings { } Result ISettingsServer::MakeLanguageCode(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { - response.Push(language::LanguageCodeList.at(request.Pop())); + response.Push(language::LanguageCodeList.at(static_cast(request.Pop()))); return {}; } diff --git a/app/src/main/cpp/skyline/services/timesrv/common.h b/app/src/main/cpp/skyline/services/timesrv/common.h index b8f50f95..919fd1f5 100644 --- a/app/src/main/cpp/skyline/services/timesrv/common.h +++ b/app/src/main/cpp/skyline/services/timesrv/common.h @@ -24,11 +24,11 @@ namespace skyline::service::timesrv { } static constexpr TimeSpanType FromSeconds(i64 s) { - return {s * static_cast(skyline::constant::NsInSecond)}; + return {s * skyline::constant::NsInSecond}; } static constexpr TimeSpanType FromDays(i64 d) { - return {d * static_cast(skyline::constant::NsInDay)}; + return {d * skyline::constant::NsInDay}; } constexpr i64 Nanoseconds() const { @@ -36,11 +36,11 @@ namespace skyline::service::timesrv { } constexpr i64 Microseconds() const { - return ns / static_cast(skyline::constant::NsInMicrosecond); + return ns / skyline::constant::NsInMicrosecond; } constexpr i64 Seconds() const { - return ns / static_cast(skyline::constant::NsInSecond); + return ns / skyline::constant::NsInSecond; } constexpr friend bool operator>(const TimeSpanType &lhs, const TimeSpanType &rhs) { diff --git a/app/src/main/cpp/skyline/services/timesrv/core.cpp b/app/src/main/cpp/skyline/services/timesrv/core.cpp index 5acfd088..ccf08862 100644 --- a/app/src/main/cpp/skyline/services/timesrv/core.cpp +++ b/app/src/main/cpp/skyline/services/timesrv/core.cpp @@ -270,7 +270,7 @@ namespace skyline::service::timesrv::core { for (auto it{buffer.begin()}; it != buffer.end(); it++) { if (*it == '\n' && prev != it) { timesrv::LocationName name{}; - span(prev.base(), std::distance(prev, std::prev(it))).as_string().copy(name.data(), name.size()); + span(prev.base(), static_cast(std::distance(prev, std::prev(it)))).as_string().copy(name.data(), name.size()); locationNameList.push_back(name); if (std::next(it) != buffer.end()) @@ -286,6 +286,6 @@ namespace skyline::service::timesrv::core { buffer.resize(timeZoneBinaryFile->size); timeZoneBinaryFile->Read(buffer); - managerServer.SetupTimeZoneManager(state.os->deviceTimeZone, *timezoneUpdateTime, locationNameList.size(), timeZoneBinaryVersion, buffer); + managerServer.SetupTimeZoneManager(state.os->deviceTimeZone, *timezoneUpdateTime, static_cast(locationNameList.size()), timeZoneBinaryVersion, buffer); } } \ No newline at end of file diff --git a/app/src/main/cpp/skyline/services/timesrv/time_manager_server.cpp b/app/src/main/cpp/skyline/services/timesrv/time_manager_server.cpp index b22477b2..610847de 100644 --- a/app/src/main/cpp/skyline/services/timesrv/time_manager_server.cpp +++ b/app/src/main/cpp/skyline/services/timesrv/time_manager_server.cpp @@ -33,7 +33,7 @@ namespace skyline::service::timesrv { return {}; } - Result TimeManagerServer::SetupTimeZoneManager(std::string_view locationName, const SteadyClockTimePoint &updateTime, size_t locationCount, std::array binaryVersion, span binary) { + Result TimeManagerServer::SetupTimeZoneManager(std::string_view locationName, const SteadyClockTimePoint &updateTime, int locationCount, std::array binaryVersion, span binary) { return core.timeZoneManager.Setup(locationName, updateTime, locationCount, binaryVersion, binary); } diff --git a/app/src/main/cpp/skyline/services/timesrv/time_manager_server.h b/app/src/main/cpp/skyline/services/timesrv/time_manager_server.h index 89e832ee..b7e3edaa 100644 --- a/app/src/main/cpp/skyline/services/timesrv/time_manager_server.h +++ b/app/src/main/cpp/skyline/services/timesrv/time_manager_server.h @@ -70,7 +70,7 @@ namespace skyline::service::timesrv { /** * @url https://switchbrew.org/w/index.php?title=PSC_services#SetupTimeZoneServiceCore */ - Result SetupTimeZoneManager(std::string_view locationName, const SteadyClockTimePoint &updateTime, size_t locationCount, std::array binaryVersion, span binary); + Result SetupTimeZoneManager(std::string_view locationName, const SteadyClockTimePoint &updateTime, int locationCount, std::array binaryVersion, span binary); /** * @url https://switchbrew.org/w/index.php?title=PSC_services#SetupEphemeralNetworkSystemClockCore diff --git a/app/src/main/cpp/skyline/services/timesrv/time_shared_memory.cpp b/app/src/main/cpp/skyline/services/timesrv/time_shared_memory.cpp index 7d4424d7..3e7291a5 100644 --- a/app/src/main/cpp/skyline/services/timesrv/time_shared_memory.cpp +++ b/app/src/main/cpp/skyline/services/timesrv/time_shared_memory.cpp @@ -61,7 +61,7 @@ namespace skyline::service::timesrv::core { void TimeSharedMemory::SetupStandardSteadyClock(UUID rtcId, TimeSpanType baseTimePoint) { SteadyClockTimePoint context{ - .timePoint = baseTimePoint.Nanoseconds() - static_cast(util::GetTimeNs()), + .timePoint = baseTimePoint.Nanoseconds() - util::GetTimeNs(), .clockSourceId = rtcId }; @@ -70,7 +70,7 @@ namespace skyline::service::timesrv::core { void TimeSharedMemory::SetSteadyClockRawTimePoint(TimeSpanType timePoint) { auto context{ReadTimeSharedMemoryItem(timeSharedMemory->standardSteadyClockContextEntry.updateCount, timeSharedMemory->standardSteadyClockContextEntry.context)}; - context.timePoint = timePoint.Nanoseconds() - static_cast(util::GetTimeNs()); + context.timePoint = timePoint.Nanoseconds() - util::GetTimeNs(); UpdateTimeSharedMemoryItem(timeSharedMemory->standardSteadyClockContextEntry.updateCount, timeSharedMemory->standardSteadyClockContextEntry.context, context); } diff --git a/app/src/main/cpp/skyline/services/timesrv/timezone_manager.cpp b/app/src/main/cpp/skyline/services/timesrv/timezone_manager.cpp index b05dc1d1..5874209f 100644 --- a/app/src/main/cpp/skyline/services/timesrv/timezone_manager.cpp +++ b/app/src/main/cpp/skyline/services/timesrv/timezone_manager.cpp @@ -27,7 +27,7 @@ namespace skyline::service::timesrv::core { Result TimeZoneManager::SetNewLocation(std::string_view pLocationName, span binary) { std::lock_guard lock(mutex); - rule = tz_tzalloc(binary.data(), binary.size()); + rule = tz_tzalloc(binary.data(), static_cast(binary.size())); if (!rule) return result::RuleConversionFailed; @@ -79,7 +79,7 @@ namespace skyline::service::timesrv::core { } Result TimeZoneManager::ParseTimeZoneBinary(span binary, span ruleOut) { - auto ruleObj{tz_tzalloc(binary.data(), binary.size())}; + auto ruleObj{tz_tzalloc(binary.data(), static_cast(binary.size()))}; if (!ruleObj) return result::RuleConversionFailed; diff --git a/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell/macro_interpreter.cpp b/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell/macro_interpreter.cpp index 340f51d3..ed346c53 100644 --- a/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell/macro_interpreter.cpp +++ b/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell/macro_interpreter.cpp @@ -29,7 +29,8 @@ namespace skyline::soc::gm20b::engine::maxwell3d { } case Opcode::Operation::AddImmediate: - HandleAssignment(opcode->assignmentOperation, opcode->dest, registers[opcode->srcA] + opcode->immediate); + HandleAssignment(opcode->assignmentOperation, opcode->dest, + static_cast(static_cast(registers[opcode->srcA]) + opcode->immediate)); break; case Opcode::Operation::BitfieldReplace: { @@ -70,7 +71,7 @@ namespace skyline::soc::gm20b::engine::maxwell3d { } case Opcode::Operation::ReadImmediate: { - u32 result{maxwell3D.registers.raw[registers[opcode->srcA] + opcode->immediate]}; + u32 result{maxwell3D.registers.raw[static_cast(static_cast(registers[opcode->srcA]) + opcode->immediate)]}; HandleAssignment(opcode->assignmentOperation, opcode->dest, result); break; } diff --git a/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp b/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp index 7e3c795b..45023d24 100644 --- a/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp +++ b/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp @@ -84,7 +84,7 @@ namespace skyline::soc::gm20b::engine::maxwell3d { if (!(method & 1)) { if (macroInvocation.index != -1) { // Flush the current macro as we are switching to another one - macroInterpreter.Execute(macroPositions[macroInvocation.index], macroInvocation.arguments); + macroInterpreter.Execute(macroPositions[static_cast(macroInvocation.index)], macroInvocation.arguments); macroInvocation.arguments.clear(); } @@ -96,7 +96,7 @@ namespace skyline::soc::gm20b::engine::maxwell3d { // Flush macro after all of the data in the method call has been sent if (lastCall && macroInvocation.index != -1) { - macroInterpreter.Execute(macroPositions[macroInvocation.index], macroInvocation.arguments); + macroInterpreter.Execute(macroPositions[static_cast(macroInvocation.index)], macroInvocation.arguments); macroInvocation.arguments.clear(); macroInvocation.index = -1; } @@ -313,13 +313,14 @@ namespace skyline::soc::gm20b::engine::maxwell3d { case type::SemaphoreInfo::StructureSize::FourWords: { // Convert the current nanosecond time to GPU ticks - constexpr u64 NsToTickNumerator{384}; - constexpr u64 NsToTickDenominator{625}; + constexpr i64 NsToTickNumerator{384}; + constexpr i64 NsToTickDenominator{625}; - u64 nsTime{util::GetTimeNs()}; - u64 timestamp{(nsTime / NsToTickDenominator) * NsToTickNumerator + ((nsTime % NsToTickDenominator) * NsToTickNumerator) / NsToTickDenominator}; + i64 nsTime{util::GetTimeNs()}; + i64 timestamp{(nsTime / NsToTickDenominator) * NsToTickNumerator + ((nsTime % NsToTickDenominator) * NsToTickNumerator) / NsToTickDenominator}; - channelCtx.asCtx->gmmu.Write(registers.semaphore.address.Pack(), FourWordResult{result, timestamp}); + channelCtx.asCtx->gmmu.Write(registers.semaphore.address.Pack(), + FourWordResult{result, static_cast(timestamp)}); break; } } diff --git a/app/src/main/cpp/skyline/vfs/android_asset_backing.cpp b/app/src/main/cpp/skyline/vfs/android_asset_backing.cpp index e91104d7..da16828a 100644 --- a/app/src/main/cpp/skyline/vfs/android_asset_backing.cpp +++ b/app/src/main/cpp/skyline/vfs/android_asset_backing.cpp @@ -10,7 +10,7 @@ namespace skyline::vfs { if (mode.write || mode.append) throw exception("AndroidAssetBacking doesn't support writing"); - size = AAsset_getLength64(asset); + size = static_cast(AAsset_getLength64(asset)); } AndroidAssetBacking::~AndroidAssetBacking() { @@ -18,7 +18,7 @@ namespace skyline::vfs { } size_t AndroidAssetBacking::ReadImpl(span output, size_t offset) { - if (AAsset_seek64(asset, offset, SEEK_SET) != offset) + if (AAsset_seek64(asset, static_cast(offset), SEEK_SET) != offset) throw exception("Failed to seek asset position"); auto result{AAsset_read(asset, output.data(), output.size())}; diff --git a/app/src/main/cpp/skyline/vfs/backing.h b/app/src/main/cpp/skyline/vfs/backing.h index 490bd05f..713e3944 100644 --- a/app/src/main/cpp/skyline/vfs/backing.h +++ b/app/src/main/cpp/skyline/vfs/backing.h @@ -110,7 +110,7 @@ namespace skyline::vfs { if (!mode.write) throw exception("Attempting to write to a backing that is not writable"); - if (input.size() > (static_cast(size) - offset)) { + if (input.size() > (static_cast(size) - static_cast(offset))) { if (mode.append) Resize(offset + input.size()); else diff --git a/app/src/main/cpp/skyline/vfs/npdm.cpp b/app/src/main/cpp/skyline/vfs/npdm.cpp index f82f0ab2..8888047d 100644 --- a/app/src/main/cpp/skyline/vfs/npdm.cpp +++ b/app/src/main/cpp/skyline/vfs/npdm.cpp @@ -54,7 +54,8 @@ namespace skyline::vfs { auto trailingOnes{std::countr_zero(~capability.raw)}; switch (trailingOnes) { case 3: - threadInfo.priority = kernel::Priority{capability.threadInfo.highestPriority, capability.threadInfo.lowestPriority}; + threadInfo.priority = kernel::Priority{static_cast(capability.threadInfo.highestPriority), + static_cast(capability.threadInfo.lowestPriority)}; threadInfo.coreMask = {}; for (u8 core{capability.threadInfo.minCoreId}; core <= capability.threadInfo.maxCoreId; core++) diff --git a/app/src/main/cpp/skyline/vfs/npdm.h b/app/src/main/cpp/skyline/vfs/npdm.h index 628cfec7..3e51fecd 100644 --- a/app/src/main/cpp/skyline/vfs/npdm.h +++ b/app/src/main/cpp/skyline/vfs/npdm.h @@ -44,7 +44,7 @@ namespace skyline { u8 raw{}; } flags; u8 _unk1_; - u8 mainThreadPriority; + i8 mainThreadPriority; u8 idealCore; u32 _unk2_; u32 systemResourceSize; //!< 3.0.0+ diff --git a/app/src/main/cpp/skyline/vfs/os_backing.cpp b/app/src/main/cpp/skyline/vfs/os_backing.cpp index bf0457f5..ae9c7676 100644 --- a/app/src/main/cpp/skyline/vfs/os_backing.cpp +++ b/app/src/main/cpp/skyline/vfs/os_backing.cpp @@ -12,7 +12,7 @@ namespace skyline::vfs { if (fstat(fd, &fileInfo)) throw exception("Failed to stat fd: {}", strerror(errno)); - size = fileInfo.st_size; + size = static_cast(fileInfo.st_size); } OsBacking::~OsBacking() { @@ -21,7 +21,7 @@ namespace skyline::vfs { } size_t OsBacking::ReadImpl(span output, size_t offset) { - auto ret{pread64(fd, output.data(), output.size(), offset)}; + auto ret{pread64(fd, output.data(), output.size(), static_cast(offset))}; if (ret < 0) throw exception("Failed to read from fd: {}", strerror(errno)); @@ -29,7 +29,7 @@ namespace skyline::vfs { } size_t OsBacking::WriteImpl(span input, size_t offset) { - auto ret{pwrite64(fd, input.data(), input.size(), offset)}; + auto ret{pwrite64(fd, input.data(), input.size(), static_cast(offset))}; if (ret < 0) throw exception("Failed to write to fd: {}", strerror(errno)); @@ -37,7 +37,7 @@ namespace skyline::vfs { } void OsBacking::ResizeImpl(size_t pSize) { - int ret{ftruncate(fd, pSize)}; + int ret{ftruncate(fd, static_cast(pSize))}; if (ret < 0) throw exception("Failed to resize file: {}", strerror(errno)); diff --git a/app/src/main/cpp/skyline/vfs/os_filesystem.cpp b/app/src/main/cpp/skyline/vfs/os_filesystem.cpp index 4407fa5e..dd367855 100644 --- a/app/src/main/cpp/skyline/vfs/os_filesystem.cpp +++ b/app/src/main/cpp/skyline/vfs/os_filesystem.cpp @@ -29,7 +29,7 @@ namespace skyline::vfs { } // Truncate the file to desired length - int ret{ftruncate(fd, size)}; + int ret{ftruncate(fd, static_cast(size))}; close(fd); if (ret < 0)