Use .clang-tidy and remove madvise DO_FORK/DONT_FORK calls

This commit causes Android Studio to use the .clang-tidy file for configuration and removes madvise DO_FORK/DONT_FORK calls as they cause problems on many devices and are mostly unnecessary.
This commit is contained in:
◱ PixelyIon 2020-01-12 02:11:54 +05:30 committed by ◱ PixelyIon
parent 81dba3da4b
commit 493a1a93ec
4 changed files with 21 additions and 27 deletions

View File

@ -129,6 +129,9 @@
<option name="m_limit" value="64" /> <option name="m_limit" value="64" />
</inspection_tool> </inspection_tool>
<inspection_tool class="CheckedExceptionClass" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="CheckedExceptionClass" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ClangTidyInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="useCustomListOfClangTidyChecks" value="false" />
</inspection_tool>
<inspection_tool class="ClassComplexity" enabled="true" level="WARNING" enabled_by_default="true"> <inspection_tool class="ClassComplexity" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_limit" value="80" /> <option name="m_limit" value="80" />
</inspection_tool> </inspection_tool>

View File

@ -90,30 +90,30 @@ namespace skyline::kernel::type {
} }
void KProcess::ReadMemory(void *destination, u64 offset, size_t size) const { void KProcess::ReadMemory(void *destination, u64 offset, size_t size) const {
struct iovec local[1]; struct iovec local {
struct iovec remote[1]; .iov_base = destination,
.iov_len = size
};
struct iovec remote {
.iov_base = reinterpret_cast<void*>(offset),
.iov_len = size
};
remote[0].iov_base = reinterpret_cast<void*>(offset); if (process_vm_readv(pid, &local, 1, &remote, 1, 0) < 0)
remote[0].iov_len = size;
local[0].iov_base = destination;
local[0].iov_len = size;
if (process_vm_readv(pid, local, 1, remote, 1, 0) < 0)
pread64(memFd, destination, size, offset); pread64(memFd, destination, size, offset);
} }
void KProcess::WriteMemory(void *source, u64 offset, size_t size) const { void KProcess::WriteMemory(void *source, u64 offset, size_t size) const {
struct iovec local[1]; struct iovec local {
struct iovec remote[1]; .iov_base = source,
.iov_len = size
};
struct iovec remote {
.iov_base = reinterpret_cast<void*>(offset),
.iov_len = size
};
remote[0].iov_base = reinterpret_cast<void*>(offset); if (process_vm_writev(pid, &local, 1, &remote, 1, 0) < 0)
remote[0].iov_len = size;
local[0].iov_base = source;
local[0].iov_len = size;
if (process_vm_writev(pid, local, 1, remote, 1, 0) < 0)
pwrite64(memFd, source, size, offset); pwrite64(memFd, source, size, offset);
} }

View File

@ -18,9 +18,7 @@ namespace skyline::kernel {
} }
std::shared_ptr<type::KProcess> OS::CreateProcess(u64 entry, u64 argument, size_t stackSize) { std::shared_ptr<type::KProcess> OS::CreateProcess(u64 entry, u64 argument, size_t stackSize) {
madvise(reinterpret_cast<void *>(constant::BaseAddr), constant::BaseEnd, MADV_DONTFORK);
auto *stack = static_cast<u8 *>(mmap(nullptr, stackSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS | MAP_STACK, -1, 0)); auto *stack = static_cast<u8 *>(mmap(nullptr, stackSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS | MAP_STACK, -1, 0));
madvise(stack, reinterpret_cast<size_t>(stack) + stackSize, MADV_DOFORK);
if (stack == MAP_FAILED) if (stack == MAP_FAILED)
throw exception("Failed to allocate stack memory"); throw exception("Failed to allocate stack memory");
if (mprotect(stack, PAGE_SIZE, PROT_NONE)) { if (mprotect(stack, PAGE_SIZE, PROT_NONE)) {
@ -29,7 +27,6 @@ namespace skyline::kernel {
} }
auto tlsMem = std::make_shared<type::KSharedMemory>(state, 0, (sizeof(ThreadContext) + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1), memory::Permission(true, true, false), memory::Type::Reserved); auto tlsMem = std::make_shared<type::KSharedMemory>(state, 0, (sizeof(ThreadContext) + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1), memory::Permission(true, true, false), memory::Type::Reserved);
tlsMem->guest = tlsMem->kernel; tlsMem->guest = tlsMem->kernel;
madvise(reinterpret_cast<void *>(tlsMem->guest.address), tlsMem->guest.size, MADV_DOFORK);
pid_t pid = clone(reinterpret_cast<int (*)(void *)>(&guest::entry), stack + stackSize, CLONE_FILES | CLONE_FS | CLONE_SETTLS | SIGCHLD, reinterpret_cast<void *>(entry), nullptr, reinterpret_cast<void *>(tlsMem->guest.address)); pid_t pid = clone(reinterpret_cast<int (*)(void *)>(&guest::entry), stack + stackSize, CLONE_FILES | CLONE_FS | CLONE_SETTLS | SIGCHLD, reinterpret_cast<void *>(entry), nullptr, reinterpret_cast<void *>(tlsMem->guest.address));
if (pid == -1) if (pid == -1)
throw exception("Call to clone() has failed: {}", strerror(errno)); throw exception("Call to clone() has failed: {}", strerror(errno));

View File

@ -49,11 +49,5 @@ namespace skyline::kernel {
* @param pid The PID of the thread * @param pid The PID of the thread
*/ */
void KillThread(pid_t pid); void KillThread(pid_t pid);
/**
* @brief Handles a particular SuperVisor Call
* @param svc The ID of the SVC to be called
*/
void SvcHandler(const u16 svc);
}; };
} }