Compare commits

...

4 Commits

Author SHA1 Message Date
lizzie
4da9c6303b better script opts
Signed-off-by: lizzie <lizzie@eden-emu.dev>
2025-11-10 01:31:01 +01:00
lizzie
5478ddde87 better
Signed-off-by: lizzie <lizzie@eden-emu.dev>
2025-11-10 01:31:01 +01:00
lizzie
8f1d895932 [cpm]: Ability to override and set custom hosts (like a self hosted instance or whatever)
Signed-off-by: lizzie <lizzie@eden-emu.dev>
2025-11-10 01:31:01 +01:00
PavelBARABANOV
42863027e2 Revert "[core/memory] Remove defered heap allocation on Linux." (#2974)
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2974
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Reviewed-by: Caio Oliveira <caiooliveirafarias0@gmail.com>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Co-authored-by: PavelBARABANOV <pavelbarabanov94@gmail.com>
Co-committed-by: PavelBARABANOV <pavelbarabanov94@gmail.com>
2025-11-09 22:42:09 +01:00
15 changed files with 286 additions and 31 deletions

View File

@@ -13,6 +13,11 @@ option(CPMUTIL_FORCE_BUNDLED
option(CPMUTIL_FORCE_SYSTEM
"Force system packages for all CPM dependencies (NOT RECOMMENDED)" OFF)
set(CPMUTIL_DEFAULT_HOST github.com CACHE STRING "Sets the default host when 'git_host' isn't defined")
option(CPMUTIL_FORCE_HOST
"Force host CPMUTIL_DEFAULT_HOST to be used for all CPM dependencies even when 'git_host' is defined" OFF)
cmake_minimum_required(VERSION 3.22)
include(CPM)
@@ -293,8 +298,8 @@ function(AddPackage)
option(${PKG_ARGS_NAME}_FORCE_SYSTEM "Force the system package for ${PKG_ARGS_NAME}")
option(${PKG_ARGS_NAME}_FORCE_BUNDLED "Force the bundled package for ${PKG_ARGS_NAME}")
if (NOT DEFINED PKG_ARGS_GIT_HOST)
set(git_host github.com)
if (CPMUTIL_FORCE_HOST OR NOT DEFINED PKG_ARGS_GIT_HOST)
set(git_host ${CPMUTIL_DEFAULT_HOST})
else()
set(git_host ${PKG_ARGS_GIT_HOST})
endif()

View File

@@ -7,6 +7,8 @@ Global Options:
- `CPMUTIL_FORCE_SYSTEM` (default `OFF`): Require all CPM dependencies to use system packages. NOT RECOMMENDED!
* You may optionally override this (section)
- `CPMUTIL_FORCE_BUNDLED` (default `ON` on MSVC and Android, `OFF` elsewhere): Require all CPM dependencies to use bundled packages.
- `CPMUTIL_DEFAULT_HOST`: (default `github.com`): Sets the default `git_host`.
- `CPMUTIL_FORCE_HOST`: (default `OFF`): Forces all CPM packages to use `CPMUTIL_DEFAULT_HOST` instead, even if they have `git_host` defined.
You are highly encouraged to read AddPackage first, even if you plan to only interact with CPMUtil via `AddJsonPackage`.

View File

@@ -1,11 +1,10 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <fstream>
#include <vector>
#include "common/heap_tracker.h"
#include "common/logging/log.h"
#include "common/assert.h"
@@ -37,8 +36,6 @@ HeapTracker::~HeapTracker() = default;
void HeapTracker::Map(size_t virtual_offset, size_t host_offset, size_t length,
MemoryPermission perm, bool is_separate_heap) {
bool rebuild_required = false;
// When mapping other memory, map pages immediately.
if (!is_separate_heap) {
m_buffer.Map(virtual_offset, host_offset, length, perm, false);
@@ -60,29 +57,11 @@ void HeapTracker::Map(size_t virtual_offset, size_t host_offset, size_t length,
// Insert into mappings.
m_map_count++;
const auto it = m_mappings.insert(*map);
// Update tick before possible rebuild.
it->tick = m_tick++;
// Check if we need to rebuild.
if (m_resident_map_count >= m_max_resident_map_count) {
rebuild_required = true;
}
// Map the area.
m_buffer.Map(it->vaddr, it->paddr, it->size, it->perm, false);
// This map is now resident.
it->is_resident = true;
m_resident_map_count++;
m_resident_mappings.insert(*it);
m_mappings.insert(*map);
}
if (rebuild_required) {
// A rebuild was required, so perform it now.
this->RebuildSeparateHeapAddressSpace();
}
// Finally, map.
this->DeferredMapSeparateHeap(virtual_offset);
}
void HeapTracker::Unmap(size_t virtual_offset, size_t size, bool is_separate_heap) {
@@ -169,7 +148,6 @@ void HeapTracker::Protect(size_t virtual_offset, size_t size, MemoryPermission p
// Clamp to end.
next = (std::min)(next, end);
// Reprotect, if we need to.
if (should_protect) {
m_buffer.Protect(cur, next - cur, perm);
@@ -180,6 +158,51 @@ void HeapTracker::Protect(size_t virtual_offset, size_t size, MemoryPermission p
}
}
bool HeapTracker::DeferredMapSeparateHeap(u8* fault_address) {
if (m_buffer.IsInVirtualRange(fault_address)) {
return this->DeferredMapSeparateHeap(fault_address - m_buffer.VirtualBasePointer());
}
return false;
}
bool HeapTracker::DeferredMapSeparateHeap(size_t virtual_offset) {
bool rebuild_required = false;
{
std::scoped_lock lk{m_lock};
// Check to ensure this was a non-resident separate heap mapping.
const auto it = this->GetNearestHeapMapLocked(virtual_offset);
if (it == m_mappings.end() || it->is_resident) {
return false;
}
// Update tick before possible rebuild.
it->tick = m_tick++;
// Check if we need to rebuild.
if (m_resident_map_count > m_max_resident_map_count) {
rebuild_required = true;
}
// Map the area.
m_buffer.Map(it->vaddr, it->paddr, it->size, it->perm, false);
// This map is now resident.
it->is_resident = true;
m_resident_map_count++;
m_resident_mappings.insert(*it);
}
if (rebuild_required) {
// A rebuild was required, so perform it now.
this->RebuildSeparateHeapAddressSpace();
}
return true;
}
void HeapTracker::RebuildSeparateHeapAddressSpace() {
std::scoped_lock lk{m_rebuild_lock, m_lock};
@@ -190,8 +213,8 @@ void HeapTracker::RebuildSeparateHeapAddressSpace() {
// Despite being worse in theory, this has proven to be better in practice than more
// regularly dumping a smaller amount, because it significantly reduces average case
// lock contention.
const size_t desired_count = (std::min)(m_resident_map_count, m_max_resident_map_count) / 2;
const size_t evict_count = m_resident_map_count - desired_count;
std::size_t const desired_count = (std::min)(m_resident_map_count, m_max_resident_map_count) / 2;
std::size_t const evict_count = m_resident_map_count - desired_count;
auto it = m_resident_mappings.begin();
for (size_t i = 0; i < evict_count && it != m_resident_mappings.end(); i++) {

View File

@@ -1231,6 +1231,7 @@ endif()
if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
target_sources(core PRIVATE
arm/dynarmic/arm_dynarmic.cpp
arm/dynarmic/arm_dynarmic.h
arm/dynarmic/arm_dynarmic_64.cpp
arm/dynarmic/arm_dynarmic_64.h

View File

@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#ifdef __linux__
#include "common/signal_chain.h"
#include "core/arm/dynarmic/arm_dynarmic.h"
#include "core/hle/kernel/k_process.h"
#include "core/memory.h"
namespace Core {
namespace {
thread_local Core::Memory::Memory* g_current_memory{};
std::once_flag g_registered{};
struct sigaction g_old_segv {};
void HandleSigSegv(int sig, siginfo_t* info, void* ctx) {
if (g_current_memory && g_current_memory->InvalidateSeparateHeap(info->si_addr)) {
return;
}
return g_old_segv.sa_sigaction(sig, info, ctx);
}
} // namespace
ScopedJitExecution::ScopedJitExecution(Kernel::KProcess* process) {
g_current_memory = std::addressof(process->GetMemory());
}
ScopedJitExecution::~ScopedJitExecution() {
g_current_memory = nullptr;
}
void ScopedJitExecution::RegisterHandler() {
std::call_once(g_registered, [] {
struct sigaction sa {};
sa.sa_sigaction = &HandleSigSegv;
sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
Common::SigAction(SIGSEGV, std::addressof(sa), std::addressof(g_old_segv));
});
}
} // namespace Core
#endif

View File

@@ -29,4 +29,24 @@ constexpr HaltReason TranslateHaltReason(Dynarmic::HaltReason hr) {
return static_cast<HaltReason>(hr);
}
#ifdef __linux__
class ScopedJitExecution {
public:
explicit ScopedJitExecution(Kernel::KProcess* process);
~ScopedJitExecution();
static void RegisterHandler();
};
#else
class ScopedJitExecution {
public:
explicit ScopedJitExecution(Kernel::KProcess* process) {}
~ScopedJitExecution() {}
static void RegisterHandler() {}
};
#endif
} // namespace Core

View File

@@ -341,11 +341,15 @@ bool ArmDynarmic32::IsInThumbMode() const {
}
HaltReason ArmDynarmic32::RunThread(Kernel::KThread* thread) {
ScopedJitExecution sj(thread->GetOwnerProcess());
m_jit->ClearExclusiveState();
return TranslateHaltReason(m_jit->Run());
}
HaltReason ArmDynarmic32::StepThread(Kernel::KThread* thread) {
ScopedJitExecution sj(thread->GetOwnerProcess());
m_jit->ClearExclusiveState();
return TranslateHaltReason(m_jit->Step());
}
@@ -387,6 +391,7 @@ ArmDynarmic32::ArmDynarmic32(System& system, bool uses_wall_clock, Kernel::KProc
m_cp15(std::make_shared<DynarmicCP15>(*this)), m_core_index{core_index} {
auto& page_table_impl = process->GetPageTable().GetBasePageTable().GetImpl();
m_jit = MakeJit(&page_table_impl);
ScopedJitExecution::RegisterHandler();
}
ArmDynarmic32::~ArmDynarmic32() = default;

View File

@@ -372,11 +372,15 @@ std::shared_ptr<Dynarmic::A64::Jit> ArmDynarmic64::MakeJit(Common::PageTable* pa
}
HaltReason ArmDynarmic64::RunThread(Kernel::KThread* thread) {
ScopedJitExecution sj(thread->GetOwnerProcess());
m_jit->ClearExclusiveState();
return TranslateHaltReason(m_jit->Run());
}
HaltReason ArmDynarmic64::StepThread(Kernel::KThread* thread) {
ScopedJitExecution sj(thread->GetOwnerProcess());
m_jit->ClearExclusiveState();
return TranslateHaltReason(m_jit->Step());
}
@@ -416,6 +420,7 @@ ArmDynarmic64::ArmDynarmic64(System& system, bool uses_wall_clock, Kernel::KProc
auto& page_table = process->GetPageTable().GetBasePageTable();
auto& page_table_impl = page_table.GetImpl();
m_jit = MakeJit(&page_table_impl, page_table.GetAddressSpaceWidth());
ScopedJitExecution::RegisterHandler();
}
ArmDynarmic64::~ArmDynarmic64() = default;

View File

@@ -1230,7 +1230,22 @@ bool Memory::InvalidateNCE(Common::ProcessAddress vaddr, size_t size) {
if (rasterizer) {
impl->InvalidateGPUMemory(ptr, size);
}
#ifdef __linux__
if (!rasterizer && mapped) {
impl->buffer->DeferredMapSeparateHeap(GetInteger(vaddr));
}
#endif
return mapped && ptr != nullptr;
}
bool Memory::InvalidateSeparateHeap(void* fault_address) {
#ifdef __linux__
return impl->buffer->DeferredMapSeparateHeap(static_cast<u8*>(fault_address));
#else
return false;
#endif
}
} // namespace Core::Memory

View File

@@ -495,6 +495,8 @@ public:
bool InvalidateNCE(Common::ProcessAddress vaddr, size_t size);
bool InvalidateSeparateHeap(void* fault_address);
private:
Core::System& system;

View File

@@ -24,6 +24,7 @@ Tools for Eden and other subprojects.
- `find-unused-strings.sh`: Find any unused strings in the Android app (XML -> Kotlin).
## Android
It's recommended to run these scritps after almost any Android change, as they are relatively fast and important both for APK bloat and CI.
- `unused-strings.sh`: Finds unused strings in `strings.xml` files.
@@ -32,3 +33,7 @@ It's recommended to run these scritps after almost any Android change, as they a
## Translations
- [Translation Scripts](./translations)
## Mirror
- [Mirroring scripts](./mirror)

View File

@@ -13,7 +13,7 @@ MAXDEPTH=3
# For your project you'll want to change this to define what dirs you have cpmfiles in
# Remember to account for the MAXDEPTH variable!
# Adding ./ before each will help to remove duplicates
[ -z "$CPMFILES" ] && CPMFILES=$(find . ./src -maxdepth "$MAXDEPTH" -name cpmfile.json | sort | uniq)
[ -z "$CPMFILES" ] && CPMFILES=$(find . ./src -maxdepth "$MAXDEPTH" -name cpmfile.json -not -path build | sort | uniq)
# shellcheck disable=SC2016
[ -z "$PACKAGES" ] && PACKAGES=$(echo "$CPMFILES" | xargs jq -s 'reduce .[] as $item ({}; . * $item)')

6
tools/mirror/README.md Normal file
View File

@@ -0,0 +1,6 @@
# Mirroring scripts
Scripts for setting up a Git mirror or performing offline work (i.e no GitHub) when using systems like CPM.
- `helper.sh`: Mini helper script - made for `cgit` jails but may work for Forgejo as well.
- `common.sh`: Common functions and stuff.

30
tools/mirror/common.sh Normal file
View File

@@ -0,0 +1,30 @@
#!/bin/sh -e
# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
# SPDX-License-Identifier: GPL-3.0-or-later
git_clone_mirror_repo() {
NAME=$(echo "$1" | cut -d '/' -f 5)
ORG=$(echo "$1" | cut -d '/' -f 4)
git clone --mirror $1 $ORG/$NAME
}
git_retrieve_file() {
TMPDIR=$1
BRANCH=$(cd $TMPDIR && git rev-parse --abbrev-ref HEAD)
cd $1 && git show $BRANCH:$2 2>/dev/null | git lfs smudge 2>/dev/null
}
git_retrieve_gitmodules() {
TMP=$1
git_retrieve_file $TMP '.gitmodules' | awk '{$1=$1};1' \
| grep "url = " | sed "s,url = ,," \
| while IFS= read -r line; do
case "$line" in
../*)
# TODO: maybe one day handle case where its NOT ALL GITHUB - thanks boost
ORGAN=$(echo "$TMP" | awk -F'/' '{print $2}')
echo "$line" | sed "s|../|https://github.com/$ORGAN/|"
;;
http*)
echo "$line"
;;
esac
done
}

84
tools/mirror/helper.sh Executable file
View File

@@ -0,0 +1,84 @@
#!/bin/sh -e
# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
# SPDX-License-Identifier: GPL-3.0-or-later
# You must run this at the root of the eden git repo
CPM_DIR=$PWD
NPROC=$(nproc || echo 8)
. ./tools/mirror/common.sh
. ./tools/cpm/common.sh
die() {
echo "$@" >&2
exit 1
}
help() {
cat << EOF
--path <path> Specify the given path (must be the root of your SCM folder)
--initial Initial cloning (no submodules) - fetched from cpmfiles
--clone-submodules Clones submodules, can also be used multiple times to clone
newly referenced submodules
--remote-update Update all remotes (of the repos) - aka. sync with remote
--mirror Perform a mirror clone; URL must be specified before,
if name or organisation are not specified, it is derived from URL
--url Set URL of clone
--org Set organisation folder of clone
--name Set name of clone
EOF
}
[ -z "$SCM_ROOT_DIR" ] && SCM_ROOT_DIR="/usr/local/jails/containers/cgit-www/srv/git/repos"
op_initial() {
sudo chmod 777 $SCM_ROOT_DIR
# stuff to parse the cpmfile json and then spit out full repo path
REPOS=$(echo "$PACKAGES" \
| jq -r 'reduce .[] as $i (""; . + (if $i.git_host == null then "https://github.com" else "https://" + $i.git_host end) + "/" + $i.repo + " ")' \
| tr ' ' '\n' | xargs -I {} echo {})
# clone the stuff
cd $SCM_ROOT_DIR && echo "$REPOS" \
| xargs -P $NPROC -I {} sh -c ". $CPM_DIR/tools/mirror/common.sh && git_clone_mirror_repo {}"
sudo chmod 755 $SCM_ROOT_DIR
}
op_clone_submodules() {
sudo chmod 777 $SCM_ROOT_DIR
cd $SCM_ROOT_DIR && find . -maxdepth 2 -type d -name '*.git' -print0 \
| xargs -0 -I {} sh -c ". $CPM_DIR/tools/mirror/common.sh && git_retrieve_gitmodules {}" \
| while IFS= read -r url; do
git_clone_mirror_repo $url || echo "skipped $url"
done
sudo chmod 755 $SCM_ROOT_DIR
}
op_remote_update() {
sudo chmod 777 $SCM_ROOT_DIR
cd $SCM_ROOT_DIR && find . -maxdepth 3 -type d -name '*.git' -print0 \
| xargs -0 -P $NPROC -I {} sh -c 'cd {} && git remote update && echo {}'
sudo chmod 755 $SCM_ROOT_DIR
}
op_mirror() {
sudo chmod 777 $SCM_ROOT_DIR
[ -z "$URL" ] && die "Specify repo --url"
[ -z "$NAME" ] && NAME=$(echo "$URL" | cut -d '/' -f 5)
[ -z "$ORG" ] && ORG=$(echo "$URL" | cut -d '/' -f 4)
cd $SCM_ROOT_DIR && git clone --mirror $URL $ORG/$NAME || echo "skipped $URL"
sudo chmod 755 $SCM_ROOT_DIR
}
while true; do
case "$1" in
--path) shift; SCM_ROOT_DIR=$1; [ -z "$SCM_ROOT_DIR" ] && die "Empty target root dir";;
--initial) OP_INITIAL=1;;
--clone-submodules) OP_CLONE_SUBMODULES=1;;
--remote-update) OP_REMOTE_UPDATE=1;;
--mirror) OP_MIRROR=1;;
--url) shift; URL=$1; [ -z "$URL" ] && die "Expected url";;
--name) shift; NAME=$1; [ -z "$NAME" ] && die "Expected name";;
--org) shift; ORG=$1; [ -z "$ORG" ] && die "Expected organisation";;
--help) help "$@";;
--*) die "Invalid option $1" ;;
"$0" | "") break;;
esac
shift
done
[ "$OP_INITIAL" = 1 ] && op_initial
[ "$OP_CLONE_SUBMODULES" = 1 ] && op_clone_submodules
[ "$OP_REMOTE_UPDATE" = 1 ] && op_remote_update
[ "$OP_MIRROR" = 1 ] && op_mirror