Address CR Comments + Fix Clock Rescaling

This commit is contained in:
◱ PixelyIon 2020-11-22 15:11:01 +05:30 committed by ◱ PixelyIon
parent a3dd759a1c
commit fbf9f06244
26 changed files with 73 additions and 66 deletions

View File

@ -31,6 +31,6 @@ namespace skyline::audio {
/** /**
* @brief Decodes a buffer of ADPCM data into I16 PCM * @brief Decodes a buffer of ADPCM data into I16 PCM
*/ */
std::vector<i16> Decode(span<u8> adpcmData); std::vector<i16> Decode(span <u8> adpcmData);
}; };
} }

View File

@ -20,6 +20,6 @@ namespace skyline::audio {
* @param ratio The conversion ratio needed * @param ratio The conversion ratio needed
* @param channelCount The amount of channels the buffer contains * @param channelCount The amount of channels the buffer contains
*/ */
std::vector<i16> ResampleBuffer(span<i16> inputBuffer, double ratio, u8 channelCount); std::vector<i16> ResampleBuffer(span <i16> inputBuffer, double ratio, u8 channelCount);
}; };
} }

View File

@ -30,9 +30,9 @@ namespace fmt {
/** /**
* @brief A std::bitset formatter for {fmt} * @brief A std::bitset formatter for {fmt}
*/ */
template <size_t N> template<size_t N>
struct formatter<std::bitset<N>>: formatter<std::string> { struct formatter<std::bitset<N>> : formatter<std::string> {
template <typename FormatContext> template<typename FormatContext>
constexpr auto format(const std::bitset<N> &s, FormatContext &ctx) { constexpr auto format(const std::bitset<N> &s, FormatContext &ctx) {
return formatter<std::string>::format(s.to_string(), ctx); return formatter<std::string>::format(s.to_string(), ctx);
} }
@ -92,9 +92,9 @@ namespace skyline {
namespace util { namespace util {
/** /**
* @brief A way to implicitly cast all pointers to u64s, this is used for {fmt} as we use 0x{:X} to print pointers * @brief A way to implicitly cast all pointers to uintptr_t, this is used for {fmt} as we use 0x{:X} to print pointers
* @note There's the exception of signed char pointers as they represent C Strings * @note There's the exception of signed char pointers as they represent C Strings
* @note This does not cover std::shared_ptr or std::unique_ptr and those will have to be explicitly casted to u64 or passed through fmt::ptr * @note This does not cover std::shared_ptr or std::unique_ptr and those will have to be explicitly casted to uintptr_t or passed through fmt::ptr
*/ */
template<class T> template<class T>
constexpr auto FmtCast(T object) { constexpr auto FmtCast(T object) {
@ -102,7 +102,7 @@ namespace skyline {
if constexpr (std::is_same<char, typename std::remove_cv<typename std::remove_pointer<T>::type>::type>::value) if constexpr (std::is_same<char, typename std::remove_cv<typename std::remove_pointer<T>::type>::type>::value)
return reinterpret_cast<typename std::common_type<char *, T>::type>(object); return reinterpret_cast<typename std::common_type<char *, T>::type>(object);
else else
return reinterpret_cast<const u64>(object); return reinterpret_cast<const uintptr_t>(object);
else else
return object; return object;
} }
@ -153,7 +153,7 @@ namespace skyline {
} }
template<class T> template<class T>
size_t PointerValue(T *item) { uintptr_t PointerValue(T *item) {
return reinterpret_cast<uintptr_t>(item); return reinterpret_cast<uintptr_t>(item);
} }
@ -244,7 +244,7 @@ namespace skyline {
template<size_t Size> template<size_t Size>
constexpr std::array<u8, Size> HexStringToArray(std::string_view string) { constexpr std::array<u8, Size> HexStringToArray(std::string_view string) {
if (string.size() != Size * 2) if (string.size() != Size * 2)
throw exception("Invalid size"); throw exception("String size: {} (Expected {})", string.size(), Size);
std::array<u8, Size> result; std::array<u8, Size> result;
for (size_t i{}; i < Size; i++) { for (size_t i{}; i < Size; i++) {
size_t index{i * 2}; size_t index{i * 2};
@ -255,9 +255,11 @@ namespace skyline {
template<class Type> template<class Type>
constexpr Type HexStringToInt(std::string_view string) { constexpr Type HexStringToInt(std::string_view string) {
if (string.size() > sizeof(Type) * 2)
throw exception("String size larger than type: {} (sizeof(Type): {})", string.size(), sizeof(Type));
Type result{}; Type result{};
size_t offset{(sizeof(Type) * 8) - 4}; size_t offset{(sizeof(Type) * 8) - 4};
for (size_t index{}; index < std::min(sizeof(Type) * 2, string.size()); index++, offset -= 4) { for (size_t index{}; index < string.size(); index++, offset -= 4) {
char digit{string[index]}; char digit{string[index]};
if (digit >= '0' && digit <= '9') if (digit >= '0' && digit <= '9')
result |= static_cast<Type>(digit - '0') << offset; result |= static_cast<Type>(digit - '0') << offset;

View File

@ -28,7 +28,7 @@ namespace skyline {
* @param copyOffset The offset into the buffer after which to use memcpy rather than copyFunction, -1 will use it for the entire buffer * @param copyOffset The offset into the buffer after which to use memcpy rather than copyFunction, -1 will use it for the entire buffer
* @return The amount of data written into the input buffer in units of Type * @return The amount of data written into the input buffer in units of Type
*/ */
inline size_t Read(span<Type> buffer, void copyFunction(Type *, Type *) = {}, ssize_t copyOffset = -1) { inline size_t Read(span <Type> buffer, void copyFunction(Type *, Type *) = {}, ssize_t copyOffset = -1) {
std::lock_guard guard(mtx); std::lock_guard guard(mtx);
if (empty) if (empty)
@ -91,7 +91,7 @@ namespace skyline {
/** /**
* @brief Appends data from the specified buffer into this buffer * @brief Appends data from the specified buffer into this buffer
*/ */
inline void Append(span<Type> buffer) { inline void Append(span <Type> buffer) {
std::lock_guard guard(mtx); std::lock_guard guard(mtx);
Type *pointer{buffer.data()}; Type *pointer{buffer.data()};

View File

@ -23,6 +23,16 @@ namespace skyline {
public: public:
inline CircularQueue(size_t size) : vector((size + 1) * sizeof(Type)) {} inline CircularQueue(size_t size) : vector((size + 1) * sizeof(Type)) {}
inline CircularQueue(const CircularQueue &) = delete;
inline CircularQueue &operator=(const CircularQueue &) = delete;
inline CircularQueue(CircularQueue &&other) : vector(std::move(other.vector)), consumptionMutex(std::move(other.consumptionMutex)), consumeCondition(std::move(other.consumeCondition)), productionMutex(std::move(other.productionMutex)), produceCondition(std::move(other.produceCondition)) {
this->start = other.start;
this->end = other.end;
other.start = other.end = nullptr;
}
inline ~CircularQueue() { inline ~CircularQueue() {
while (start != end) { while (start != end) {
auto next{start + 1}; auto next{start + 1};
@ -66,9 +76,9 @@ namespace skyline {
produceCondition.notify_one(); produceCondition.notify_one();
} }
inline void Append(span<Type> buffer) { inline void Append(span <Type> buffer) {
std::unique_lock lock(productionMutex); std::unique_lock lock(productionMutex);
for (auto &item : buffer) { for (const auto &item : buffer) {
auto next{end + 1}; auto next{end + 1};
next = (next == reinterpret_cast<Type *>(vector.end().base())) ? reinterpret_cast<Type *>(vector.begin().base()) : next; next = (next == reinterpret_cast<Type *>(vector.end().base())) ? reinterpret_cast<Type *>(vector.begin().base()) : next;
if (next == start) { if (next == start) {
@ -86,9 +96,9 @@ namespace skyline {
* @param tranformation A function that takes in an item of TransformedType as input and returns an item of Type * @param tranformation A function that takes in an item of TransformedType as input and returns an item of Type
*/ */
template<typename TransformedType, typename Transformation> template<typename TransformedType, typename Transformation>
inline void AppendTranform(span<TransformedType> buffer, Transformation transformation) { inline void AppendTranform(span <TransformedType> buffer, Transformation transformation) {
std::unique_lock lock(productionMutex); std::unique_lock lock(productionMutex);
for (auto &item : buffer) { for (const auto &item : buffer) {
auto next{end + 1}; auto next{end + 1};
next = (next == reinterpret_cast<Type *>(vector.end().base())) ? reinterpret_cast<Type *>(vector.begin().base()) : next; next = (next == reinterpret_cast<Type *>(vector.end().base())) ? reinterpret_cast<Type *>(vector.begin().base()) : next;
if (next == start) { if (next == start) {

View File

@ -48,7 +48,7 @@ namespace skyline::signal {
signalException.signal = signal; signalException.signal = signal;
signalException.pc = context->uc_mcontext.pc; signalException.pc = context->uc_mcontext.pc;
if (signal == SIGSEGV) if (signal == SIGSEGV)
signalException.faultAddress = info->si_addr; signalException.fault = info->si_addr;
SignalExceptionPtr = std::make_exception_ptr(signalException); SignalExceptionPtr = std::make_exception_ptr(signalException);
context->uc_mcontext.pc = reinterpret_cast<u64>(&ExceptionThrow); context->uc_mcontext.pc = reinterpret_cast<u64>(&ExceptionThrow);

View File

@ -15,13 +15,13 @@ namespace skyline::signal {
public: public:
int signal{}; int signal{};
u64 pc{}; u64 pc{};
void *faultAddress{}; void *fault{};
inline std::string what() const { inline std::string what() const {
if (!faultAddress) if (!fault)
return fmt::format("Signal: {} (PC: 0x{:X})", strsignal(signal), pc); return fmt::format("Signal: {} (PC: 0x{:X})", strsignal(signal), pc);
else else
return fmt::format("Signal: {} @ 0x{:X} (PC: 0x{:X})", strsignal(signal), reinterpret_cast<u64>(faultAddress), pc); return fmt::format("Signal: {} @ 0x{:X} (PC: 0x{:X})", strsignal(signal), reinterpret_cast<uintptr_t>(fault), pc);
} }
}; };

View File

@ -99,14 +99,13 @@ namespace skyline {
*/ */
bool Unmap(u64 virtAddr, u64 size); bool Unmap(u64 virtAddr, u64 size);
void Read(u8 *destination, u64 virtAddr, u64 size) const; void Read(u8 *destination, u64 virtAddr, u64 size) const;
/** /**
* @brief Reads in a span from a region of the virtual address space * @brief Reads in a span from a region of the virtual address space
*/ */
template<typename T> template<typename T>
void Read(span<T> destination, u64 virtAddr) const { void Read(span <T> destination, u64 virtAddr) const {
Read(reinterpret_cast<u8 *>(destination.data()), virtAddr, destination.size_bytes()); Read(reinterpret_cast<u8 *>(destination.data()), virtAddr, destination.size_bytes());
} }
@ -127,7 +126,7 @@ namespace skyline {
* @brief Writes out a span to a region of the virtual address space * @brief Writes out a span to a region of the virtual address space
*/ */
template<typename T> template<typename T>
void Write(span<T> source, u64 virtAddr) const { void Write(span <T> source, u64 virtAddr) const {
Write(reinterpret_cast<u8 *>(source.data()), virtAddr, source.size_bytes()); Write(reinterpret_cast<u8 *>(source.data()), virtAddr, source.size_bytes());
} }

View File

@ -41,7 +41,7 @@ namespace skyline::kernel {
// Search for a suitable carveout in host AS to fit the guest AS inside of // Search for a suitable carveout in host AS to fit the guest AS inside of
std::ifstream mapsFile("/proc/self/maps"); std::ifstream mapsFile("/proc/self/maps");
std::string maps((std::istreambuf_iterator<char>(mapsFile)), std::istreambuf_iterator<char>()); std::string maps((std::istreambuf_iterator<char>(mapsFile)), std::istreambuf_iterator<char>());
size_t line{}, start{1ULL << 35}, alignedStart{1ULL << 35}; // 1 << 35 is where QC KGSL (Kernel Graphic Support Layer) maps down from, we skip over this or KGSL goes OOM size_t line{}, start{1ULL << 35}, alignedStart{1ULL << 35}; // Qualcomm KGSL (Kernel Graphic Support Layer/Kernel GPU driver) maps below 35-bits, reserving it causes KGSL to go OOM
do { do {
auto end{util::HexStringToInt<u64>(std::string_view(maps.data() + line, sizeof(u64) * 2))}; auto end{util::HexStringToInt<u64>(std::string_view(maps.data() + line, sizeof(u64) * 2))};
if (end < start) if (end < start)

View File

@ -186,12 +186,6 @@ namespace skyline {
}; };
} }
namespace loader {
class NroLoader;
class NsoLoader;
class NcaLoader;
}
namespace kernel { namespace kernel {
struct ChunkDescriptor { struct ChunkDescriptor {
u8 *ptr; u8 *ptr;

View File

@ -113,7 +113,7 @@ namespace skyline::kernel::svc {
} }
state.process->NewHandle<type::KPrivateMemory>(destination, size, chunk->permission, memory::states::Stack); state.process->NewHandle<type::KPrivateMemory>(destination, size, chunk->permission, memory::states::Stack);
memcpy(destination, source, size); std::memcpy(destination, source, size);
auto object{state.process->GetMemoryObject(source)}; auto object{state.process->GetMemoryObject(source)};
if (!object) if (!object)
@ -281,12 +281,11 @@ namespace skyline::kernel::svc {
} }
void SleepThread(const DeviceState &state) { void SleepThread(const DeviceState &state) {
u64 in{state.ctx->gpr.x0}; i64 in{static_cast<i64>(state.ctx->gpr.x0)};
switch (in) { switch (in) {
case 0: case 0:
case 1: case -1:
case 2: case -2:
state.logger->Debug("svcSleepThread: Yielding thread: {}", in); state.logger->Debug("svcSleepThread: Yielding thread: {}", in);
break; break;
default: default:
@ -553,7 +552,7 @@ namespace skyline::kernel::svc {
break; break;
} }
uint index{}; u32 index{};
for (const auto &object : objectTable) { for (const auto &object : objectTable) {
if (object->signalled) { if (object->signalled) {
state.logger->Debug("svcWaitSynchronization: Signalled handle: 0x{:X}", waitHandles[index]); state.logger->Debug("svcWaitSynchronization: Signalled handle: 0x{:X}", waitHandles[index]);

View File

@ -183,7 +183,7 @@ namespace skyline {
throw exception("GetHandle was called with a deleted handle: 0x{:X}", handle); throw exception("GetHandle was called with a deleted handle: 0x{:X}", handle);
else else
throw exception("Tried to get kernel object (0x{:X}) with different type: {} when object is {}", handle, objectType, item->objectType); throw exception("Tried to get kernel object (0x{:X}) with different type: {} when object is {}", handle, objectType, item->objectType);
} catch (const std::out_of_range&) { } catch (const std::out_of_range &) {
throw std::out_of_range(fmt::format("GetHandle was called with an invalid handle: 0x{:X}", handle)); throw std::out_of_range(fmt::format("GetHandle was called with an invalid handle: 0x{:X}", handle));
} }
} }

View File

@ -2,6 +2,7 @@
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
#include <kernel/types/KProcess.h> #include <kernel/types/KProcess.h>
#include <vfs/npdm.h>
#include "nso.h" #include "nso.h"
#include "nca.h" #include "nca.h"
@ -19,7 +20,7 @@ namespace skyline::loader {
if (nsoFile == nullptr) if (nsoFile == nullptr)
throw exception("Cannot load an ExeFS that doesn't contain rtld"); throw exception("Cannot load an ExeFS that doesn't contain rtld");
state.process->memory.InitializeVmm(memory::AddressSpaceType::AddressSpace39Bit); state.process->memory.InitializeVmm(process->npdm.meta.flags.type);
auto loadInfo{NsoLoader::LoadNso(nsoFile, process, state)}; auto loadInfo{NsoLoader::LoadNso(nsoFile, process, state)};
u64 offset{loadInfo.size}; u64 offset{loadInfo.size};

View File

@ -270,7 +270,7 @@ namespace skyline::nce {
*instruction = instr::B((end - patch) + offset, true).raw; *instruction = instr::B((end - patch) + offset, true).raw;
/* Rescale host clock */ /* Rescale host clock */
std::memcpy(patch, reinterpret_cast<void *>(&guest::RescaleClock), guest::RescaleClockSize); std::memcpy(patch, reinterpret_cast<void *>(&guest::RescaleClock), guest::RescaleClockSize * sizeof(u32));
patch += guest::RescaleClockSize; patch += guest::RescaleClockSize;
/* Load result from stack into destination register */ /* Load result from stack into destination register */

View File

@ -39,7 +39,7 @@ namespace skyline {
/** /**
* @brief Writes a vector of 128-bit user IDs to an output buffer * @brief Writes a vector of 128-bit user IDs to an output buffer
*/ */
Result WriteUserList(span<u8> buffer, std::vector<UserId> userIds); Result WriteUserList(span <u8> buffer, std::vector<UserId> userIds);
public: public:
IAccountServiceForApplication(const DeviceState &state, ServiceManager &manager); IAccountServiceForApplication(const DeviceState &state, ServiceManager &manager);

View File

@ -27,43 +27,43 @@ namespace skyline::service::nvdrv::device {
* @brief Binds a channel to the address space * @brief Binds a channel to the address space
* @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_BIND_CHANNEL * @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_BIND_CHANNEL
*/ */
NvStatus BindChannel(IoctlType type, span<u8> buffer, span<u8> inlineBuffer); NvStatus BindChannel(IoctlType type, span <u8> buffer, span <u8> inlineBuffer);
/** /**
* @brief Reserves a region in the GPU address space * @brief Reserves a region in the GPU address space
* @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_ALLOC_SPACE * @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_ALLOC_SPACE
*/ */
NvStatus AllocSpace(IoctlType type, span<u8> buffer, span<u8> inlineBuffer); NvStatus AllocSpace(IoctlType type, span <u8> buffer, span <u8> inlineBuffer);
/** /**
* @brief Unmaps a region in the GPU address space * @brief Unmaps a region in the GPU address space
* @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_UNMAP_BUFFER * @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_UNMAP_BUFFER
*/ */
NvStatus UnmapBuffer(IoctlType type, span<u8> buffer, span<u8> inlineBuffer); NvStatus UnmapBuffer(IoctlType type, span <u8> buffer, span <u8> inlineBuffer);
/** /**
* @brief Maps a region in the GPU address space * @brief Maps a region in the GPU address space
* @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_MODIFY * @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_MODIFY
*/ */
NvStatus Modify(IoctlType type, span<u8> buffer, span<u8> inlineBuffer); NvStatus Modify(IoctlType type, span <u8> buffer, span <u8> inlineBuffer);
/** /**
* @brief Returns the application's GPU address space * @brief Returns the application's GPU address space
* @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_GET_VA_REGIONS * @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_GET_VA_REGIONS
*/ */
NvStatus GetVaRegions(IoctlType type, span<u8> buffer, span<u8> inlineBuffer); NvStatus GetVaRegions(IoctlType type, span <u8> buffer, span <u8> inlineBuffer);
/** /**
* @brief Initializes the application's GPU address space * @brief Initializes the application's GPU address space
* @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_ALLOC_AS_EX * @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_ALLOC_AS_EX
*/ */
NvStatus AllocAsEx(IoctlType type, span<u8> buffer, span<u8> inlineBuffer); NvStatus AllocAsEx(IoctlType type, span <u8> buffer, span <u8> inlineBuffer);
/** /**
* @brief Remaps a region of the GPU address space * @brief Remaps a region of the GPU address space
* @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_REMAP * @url https://switchbrew.org/wiki/NV_services#NVGPU_AS_IOCTL_REMAP
*/ */
NvStatus Remap(IoctlType type, span<u8> buffer, span<u8> inlineBuffer); NvStatus Remap(IoctlType type, span <u8> buffer, span <u8> inlineBuffer);
NVDEVICE_DECL( NVDEVICE_DECL(
NVFUNC(0x4101, NvHostAsGpu, BindChannel), NVFUNC(0x4101, NvHostAsGpu, BindChannel),

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -42,13 +42,13 @@ namespace skyline::vfs {
* @param offset The offset to start reading from * @param offset The offset to start reading from
* @return The amount of bytes read * @return The amount of bytes read
*/ */
virtual size_t Read(span<u8> output, size_t offset = 0) = 0; virtual size_t Read(span <u8> output, size_t offset = 0) = 0;
/** /**
* @brief Implicit casting for reading into spans of different types * @brief Implicit casting for reading into spans of different types
*/ */
template<class T, typename std::enable_if<!std::is_same_v<T, u8>, bool>::type = true> template<class T, typename std::enable_if<!std::is_same_v<T, u8>, bool>::type = true>
inline size_t Read(span<T> output, size_t offset = 0) { inline size_t Read(span <T> output, size_t offset = 0) {
return Read(output.template cast<u8>(), offset); return Read(output.template cast<u8>(), offset);
} }
@ -70,7 +70,7 @@ namespace skyline::vfs {
* @param offset The offset where the input buffer should be written * @param offset The offset where the input buffer should be written
* @return The amount of bytes written * @return The amount of bytes written
*/ */
virtual size_t Write(span<u8> input, size_t offset = 0) { virtual size_t Write(span <u8> input, size_t offset = 0) {
throw exception("This backing does not support being written to"); throw exception("This backing does not support being written to");
} }

View File

@ -38,4 +38,5 @@ namespace skyline::vfs {
OsFileSystemDirectory(const std::string &path, ListMode listMode); OsFileSystemDirectory(const std::string &path, ListMode listMode);
std::vector<Entry> Read(); std::vector<Entry> Read();
};} };
}

View File

@ -22,7 +22,7 @@ namespace skyline::vfs {
*/ */
RegionBacking(const std::shared_ptr<vfs::Backing> &backing, size_t offset, size_t size, Mode mode = {true, false, false}) : Backing(mode, size), backing(backing), baseOffset(offset) {}; RegionBacking(const std::shared_ptr<vfs::Backing> &backing, size_t offset, size_t size, Mode mode = {true, false, false}) : Backing(mode, size), backing(backing), baseOffset(offset) {};
size_t Read(span<u8> output, size_t offset = 0) { size_t Read(span <u8> output, size_t offset = 0) {
if (!mode.read) if (!mode.read)
throw exception("Attempting to read a backing that is not readable"); throw exception("Attempting to read a backing that is not readable");
if (size - offset < output.size()) if (size - offset < output.size())

View File

@ -8,7 +8,8 @@
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:orientation="vertical" android:orientation="vertical"
android:padding="16dp"> android:paddingVertical="8dp"
android:paddingHorizontal="16dp">
<TextView <TextView
android:id="@+id/text_title" android:id="@+id/text_title"