[cmake] enable clang-cl and WoA builds (#348)

Compilation and CMake fixes for both Windows on ARM and clang-cl, meaning Windows can now be built on both MSVC and clang on both amd64 and aarch64.

Compiling on clang is *dramatically* faster so this should be useful for CI.

Co-authored-by: crueter <crueter@eden-emu.dev>
Co-authored-by: crueter <crueter@crueter.xyz>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/348
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Reviewed-by: crueter <crueter@eden-emu.dev>
Co-authored-by: lizzie <lizzie@eden-emu.dev>
Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie 2025-09-09 20:47:49 +02:00 committed by crueter
parent 428f136a75
commit 9d2681ecc9
No known key found for this signature in database
GPG key ID: 425ACD2D4830EBC6
276 changed files with 973 additions and 1010 deletions

View file

@ -133,7 +133,7 @@ void SetupPoolPartitionMemoryRegions(KMemoryLayout& memory_layout) {
// Decide on starting addresses for our pools.
const u64 application_pool_start = pool_end - application_pool_size;
const u64 applet_pool_start = application_pool_start - applet_pool_size;
const u64 unsafe_system_pool_start = std::min(
const u64 unsafe_system_pool_start = (std::min)(
kernel_dram_start + CarveoutSizeMax,
Common::AlignDown(applet_pool_start - unsafe_system_pool_min_size, CarveoutAlignment));
const size_t unsafe_system_pool_size = applet_pool_start - unsafe_system_pool_start;

View file

@ -182,13 +182,13 @@ namespace {
template <typename F>
u64 GenerateUniformRange(u64 min, u64 max, F f) {
// Handle the case where the difference is too large to represent.
if (max == std::numeric_limits<u64>::max() && min == std::numeric_limits<u64>::min()) {
if (max == (std::numeric_limits<u64>::max)() && min == (std::numeric_limits<u64>::min)()) {
return f();
}
// Iterate until we get a value in range.
const u64 range_size = ((max + 1) - min);
const u64 effective_max = (std::numeric_limits<u64>::max() / range_size) * range_size;
const u64 effective_max = ((std::numeric_limits<u64>::max)() / range_size) * range_size;
while (true) {
if (const u64 rnd = f(); rnd < effective_max) {
return min + (rnd % range_size);
@ -201,7 +201,7 @@ u64 GenerateUniformRange(u64 min, u64 max, F f) {
u64 KSystemControl::GenerateRandomU64() {
std::random_device device;
std::mt19937 gen(device());
std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max());
std::uniform_int_distribution<u64> distribution(1, (std::numeric_limits<u64>::max)());
return distribution(gen);
}

View file

@ -110,7 +110,7 @@ public:
// Update our tracking.
m_page_bitmap.ClearBit(offset);
m_peak = std::max(m_peak, (++m_used));
m_peak = (std::max)(m_peak, (++m_used));
return GetPointer<PageBuffer>(m_aligned_address) + offset;
}
@ -131,7 +131,7 @@ public:
// Update our tracking.
m_page_bitmap.ClearRange(offset, count);
m_used += count;
m_peak = std::max(m_peak, m_used);
m_peak = (std::max)(m_peak, m_used);
return GetPointer<PageBuffer>(m_aligned_address) + offset;
}

View file

@ -179,7 +179,7 @@ private:
m_free_head_index = m_entry_infos[index].GetNextFreeIndex();
m_max_count = std::max(m_max_count, ++m_count);
m_max_count = (std::max)(m_max_count, ++m_count);
return index;
}

View file

@ -19,7 +19,7 @@ void KHardwareTimer::Initialize() {
void KHardwareTimer::Finalize() {
m_kernel.System().CoreTiming().UnscheduleEvent(m_event_type);
m_wakeup_time = std::numeric_limits<s64>::max();
m_wakeup_time = (std::numeric_limits<s64>::max)();
m_event_type.reset();
}
@ -37,7 +37,7 @@ void KHardwareTimer::DoTask() {
// Disable the timer interrupt while we handle this.
// Not necessary due to core timing already having popped this event to call it.
// this->DisableInterrupt();
m_wakeup_time = std::numeric_limits<s64>::max();
m_wakeup_time = (std::numeric_limits<s64>::max)();
if (const s64 next_time = this->DoInterruptTaskImpl(GetTick());
0 < next_time && next_time <= m_wakeup_time) {
@ -63,7 +63,7 @@ void KHardwareTimer::EnableInterrupt(s64 wakeup_time) {
void KHardwareTimer::DisableInterrupt() {
m_kernel.System().CoreTiming().UnscheduleEvent(m_event_type,
Core::Timing::UnscheduleEventType::NoWait);
m_wakeup_time = std::numeric_limits<s64>::max();
m_wakeup_time = (std::numeric_limits<s64>::max)();
}
s64 KHardwareTimer::GetTick() const {
@ -71,7 +71,7 @@ s64 KHardwareTimer::GetTick() const {
}
bool KHardwareTimer::GetInterruptEnabled() {
return m_wakeup_time != std::numeric_limits<s64>::max();
return m_wakeup_time != (std::numeric_limits<s64>::max)();
}
} // namespace Kernel

View file

@ -40,7 +40,7 @@ private:
private:
// Absolute time in nanoseconds
s64 m_wakeup_time{std::numeric_limits<s64>::max()};
s64 m_wakeup_time{(std::numeric_limits<s64>::max)()};
std::shared_ptr<Core::Timing::EventType> m_event_type{};
};

View file

@ -11,7 +11,7 @@ namespace Kernel {
namespace {
constexpr u64 InvalidThreadId = std::numeric_limits<u64>::max();
constexpr u64 InvalidThreadId = (std::numeric_limits<u64>::max)();
class ThreadQueueImplForKLightServerSessionRequest final : public KThreadQueue {
private:

View file

@ -19,7 +19,7 @@ private:
KLightSession* m_parent{};
KThread::WaiterList m_request_list{};
KThread* m_current_request{};
u64 m_server_thread_id{std::numeric_limits<u64>::max()};
u64 m_server_thread_id{(std::numeric_limits<u64>::max)()};
KThread* m_server_thread{};
public:

View file

@ -551,7 +551,7 @@ public:
}
m_device_disable_merge_left_count =
std::min(m_device_disable_merge_left_count, m_device_use_count);
(std::min)(m_device_disable_merge_left_count, m_device_use_count);
if (m_device_disable_merge_left_count == 0) {
m_disable_merge_attribute = static_cast<KMemoryBlockDisableMergeAttribute>(

View file

@ -66,7 +66,7 @@ bool KMemoryRegionTree::Insert(u64 address, size_t size, u32 type_id, u32 new_at
this->insert(*found);
// Insert a new region for the split.
const u64 new_pair = (old_pair != std::numeric_limits<u64>::max())
const u64 new_pair = (old_pair != (std::numeric_limits<u64>::max)())
? old_pair + (address - old_address)
: old_pair;
this->insert(*AllocateRegion(m_memory_region_allocator, address, inserted_region_last,
@ -75,7 +75,7 @@ bool KMemoryRegionTree::Insert(u64 address, size_t size, u32 type_id, u32 new_at
// If we need to insert a region after the region, do so.
if (old_last != inserted_region_last) {
const u64 after_pair = (old_pair != std::numeric_limits<u64>::max())
const u64 after_pair = (old_pair != (std::numeric_limits<u64>::max)())
? old_pair + (inserted_region_end - old_address)
: old_pair;
this->insert(*AllocateRegion(m_memory_region_allocator, inserted_region_end, old_last,

View file

@ -323,7 +323,7 @@ Result KMemoryManager::AllocateAndOpen(KPageGroup* out, size_t num_pages, u32 op
// Process part or all of the block.
const size_t cur_pages =
std::min(remaining_pages, manager.GetPageOffsetToEnd(cur_address));
(std::min)(remaining_pages, manager.GetPageOffsetToEnd(cur_address));
manager.OpenFirst(cur_address, cur_pages);
// Advance.
@ -385,7 +385,7 @@ Result KMemoryManager::AllocateForProcess(KPageGroup* out, size_t num_pages, u32
// Process part or all of the block.
const size_t cur_pages =
std::min(remaining_pages, manager.GetPageOffsetToEnd(cur_address));
(std::min)(remaining_pages, manager.GetPageOffsetToEnd(cur_address));
any_new = manager.ProcessOptimizedAllocation(m_system.Kernel(), cur_address,
cur_pages, fill_pattern);
@ -409,7 +409,7 @@ Result KMemoryManager::AllocateForProcess(KPageGroup* out, size_t num_pages, u32
// Track some or all of the current pages.
const size_t cur_pages =
std::min(remaining_pages, manager.GetPageOffsetToEnd(cur_address));
(std::min)(remaining_pages, manager.GetPageOffsetToEnd(cur_address));
manager.TrackOptimizedAllocation(m_system.Kernel(), cur_address, cur_pages);
// Advance.

View file

@ -68,7 +68,7 @@ public:
// Repeatedly open references until we've done so for all pages.
while (num_pages) {
auto& manager = this->GetManager(address);
const size_t cur_pages = std::min(num_pages, manager.GetPageOffsetToEnd(address));
const size_t cur_pages = (std::min)(num_pages, manager.GetPageOffsetToEnd(address));
{
KScopedLightLock lk(m_pool_locks[static_cast<size_t>(manager.GetPool())]);
@ -84,7 +84,7 @@ public:
// Repeatedly open references until we've done so for all pages.
while (num_pages) {
auto& manager = this->GetManager(address);
const size_t cur_pages = std::min(num_pages, manager.GetPageOffsetToEnd(address));
const size_t cur_pages = (std::min)(num_pages, manager.GetPageOffsetToEnd(address));
{
KScopedLightLock lk(m_pool_locks[static_cast<size_t>(manager.GetPool())]);
@ -100,7 +100,7 @@ public:
// Repeatedly close references until we've done so for all pages.
while (num_pages) {
auto& manager = this->GetManager(address);
const size_t cur_pages = std::min(num_pages, manager.GetPageOffsetToEnd(address));
const size_t cur_pages = (std::min)(num_pages, manager.GetPageOffsetToEnd(address));
{
KScopedLightLock lk(m_pool_locks[static_cast<size_t>(manager.GetPool())]);

View file

@ -28,7 +28,7 @@ public:
: m_address(address), m_last_address(last_address), m_pair_address(pair_address),
m_attributes(attributes), m_type_id(type_id) {}
constexpr KMemoryRegion(u64 address, u64 last_address, u32 attributes, u32 type_id)
: KMemoryRegion(address, last_address, std::numeric_limits<u64>::max(), attributes,
: KMemoryRegion(address, last_address, (std::numeric_limits<u64>::max)(), attributes,
type_id) {}
~KMemoryRegion() = default;

View file

@ -83,7 +83,7 @@ public:
}
// Determine how many bits to take this round.
const auto cur_bits = std::min(num_bits, m_bits_available);
const auto cur_bits = (std::min)(num_bits, m_bits_available);
// Generate mask for our current bits.
const u64 mask = (static_cast<u64>(1) << cur_bits) - 1;

View file

@ -75,7 +75,7 @@ public:
}
static constexpr s32 GetAlignedBlockIndex(size_t num_pages, size_t align_pages) {
const size_t target_pages = std::max(num_pages, align_pages);
const size_t target_pages = (std::max)(num_pages, align_pages);
for (size_t i = 0; i < NumMemoryBlockPageShifts; i++) {
if (target_pages <= (static_cast<size_t>(1) << MemoryBlockPageShifts[i]) / PageSize) {
return static_cast<s32>(i);

View file

@ -1731,7 +1731,7 @@ void KPageTableBase::RemapPageGroup(PageLinkedList* page_list, KProcessAddress a
}
// Map whatever we can.
const size_t cur_pages = std::min(pg_pages, map_pages);
const size_t cur_pages = (std::min)(pg_pages, map_pages);
R_ASSERT(this->Operate(page_list, map_address, map_pages, pg_phys_addr, true,
map_properties, OperationType::Map, true));
@ -1929,7 +1929,7 @@ Result KPageTableBase::GetContiguousMemoryRangeWithState(
}
// Take the minimum size for our region.
size = std::min(size, contig_size);
size = (std::min)(size, contig_size);
// Check that the memory is contiguous (modulo the reference count bit).
const KMemoryState test_state_mask = state_mask | KMemoryState::FlagReferenceCounted;
@ -5297,7 +5297,7 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) {
KMemoryPermission::None, false, false,
DisableMergeAttribute::None};
const size_t cur_pages =
std::min(KProcessAddress(info.GetEndAddress()) - cur_address,
(std::min)(KProcessAddress(info.GetEndAddress()) - cur_address,
last_unmap_address + 1 - cur_address) /
PageSize;
@ -5345,7 +5345,7 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) {
? DisableMergeAttribute::DisableHead
: DisableMergeAttribute::None};
size_t map_pages =
std::min(KProcessAddress(info.GetEndAddress()) - cur_address,
(std::min)(KProcessAddress(info.GetEndAddress()) - cur_address,
last_address + 1 - cur_address) /
PageSize;
@ -5373,7 +5373,7 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) {
}
// Add whatever we can to the current block.
const size_t cur_pages = std::min(pg_pages, remain_pages);
const size_t cur_pages = (std::min)(pg_pages, remain_pages);
R_TRY(cur_pg.AddBlock(pg_phys_addr +
((pg_pages - cur_pages) * PageSize),
cur_pages));
@ -5535,7 +5535,7 @@ Result KPageTableBase::UnmapPhysicalMemory(KProcessAddress address, size_t size)
// Determine the range to unmap.
const KPageProperties unmap_properties = {KMemoryPermission::None, false, false,
DisableMergeAttribute::None};
const size_t cur_pages = std::min(KProcessAddress(info.GetEndAddress()) - cur_address,
const size_t cur_pages = (std::min)(KProcessAddress(info.GetEndAddress()) - cur_address,
last_address + 1 - cur_address) /
PageSize;
@ -5656,7 +5656,7 @@ Result KPageTableBase::UnmapProcessMemory(KProcessAddress dst_address, size_t si
}
// Update our current size.
m_cur_size = std::min(m_remaining_size, m_cur_size + m_entry.block_size);
m_cur_size = (std::min)(m_remaining_size, m_cur_size + m_entry.block_size);
}
}
};

View file

@ -59,7 +59,7 @@ public:
static constexpr u64 InitialProcessIdMax = 0x50;
static constexpr u64 ProcessIdMin = InitialProcessIdMax + 1;
static constexpr u64 ProcessIdMax = std::numeric_limits<u64>::max();
static constexpr u64 ProcessIdMax = (std::numeric_limits<u64>::max)();
private:
using SharedMemoryInfoList = Common::IntrusiveListBaseTraits<KSharedMemoryInfo>::ListType;

View file

@ -111,7 +111,7 @@ bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) {
if (m_current_values[index] + value <= m_limit_values[index]) {
m_current_values[index] += value;
m_current_hints[index] += value;
m_peak_values[index] = std::max(m_peak_values[index], m_current_values[index]);
m_peak_values[index] = (std::max)(m_peak_values[index], m_current_values[index]);
return true;
}

View file

@ -149,7 +149,7 @@ public:
size_t GetObjectIndex(const void* obj) const {
if constexpr (SupportDynamicExpansion) {
if (!this->Contains(reinterpret_cast<uintptr_t>(obj))) {
return std::numeric_limits<size_t>::max();
return (std::numeric_limits<size_t>::max)();
}
}

View file

@ -1016,7 +1016,7 @@ void KThread::RestorePriority(KernelCore& kernel, KThread* thread) {
s32 new_priority = thread->GetBasePriority();
for (const auto& held_lock : thread->m_held_lock_info_list) {
new_priority =
std::min(new_priority, held_lock.GetHighestPriorityWaiter()->GetPriority());
(std::min)(new_priority, held_lock.GetHighestPriorityWaiter()->GetPriority());
}
// If the priority we would inherit is not different from ours, don't do anything.

View file

@ -507,7 +507,7 @@ struct KernelCore::Impl {
constexpr size_t MiscRegionAlign = KernelAslrAlignment;
constexpr size_t MiscRegionMinimumSize = 32_MiB;
const size_t misc_region_size = Common::AlignUp(
std::max(misc_region_needed_size, MiscRegionMinimumSize), MiscRegionAlign);
(std::max)(misc_region_needed_size, MiscRegionMinimumSize), MiscRegionAlign);
ASSERT(misc_region_size > 0);
// Setup the misc region.

View file

@ -58,10 +58,10 @@ Result WaitForAddress(Core::System& system, u64 address, ArbitrationType arb_typ
if (offset_tick > 0) {
timeout = system.Kernel().HardwareTimer().GetTick() + offset_tick + 2;
if (timeout <= 0) {
timeout = std::numeric_limits<s64>::max();
timeout = (std::numeric_limits<s64>::max)();
}
} else {
timeout = std::numeric_limits<s64>::max();
timeout = (std::numeric_limits<s64>::max)();
}
} else {
timeout = timeout_ns;

View file

@ -31,10 +31,10 @@ Result WaitProcessWideKeyAtomic(Core::System& system, u64 address, u64 cv_key, u
if (offset_tick > 0) {
timeout = system.Kernel().HardwareTimer().GetTick() + offset_tick + 2;
if (timeout <= 0) {
timeout = std::numeric_limits<s64>::max();
timeout = (std::numeric_limits<s64>::max)();
}
} else {
timeout = std::numeric_limits<s64>::max();
timeout = (std::numeric_limits<s64>::max)();
}
} else {
timeout = timeout_ns;

View file

@ -61,10 +61,10 @@ Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t mes
if (offset_tick > 0) {
timeout = kernel.HardwareTimer().GetTick() + offset_tick + 2;
if (timeout <= 0) {
timeout = std::numeric_limits<s64>::max();
timeout = (std::numeric_limits<s64>::max)();
}
} else {
timeout = std::numeric_limits<s64>::max();
timeout = (std::numeric_limits<s64>::max)();
}
} else {
timeout = timeout_ns;

View file

@ -82,7 +82,7 @@ Result GetProcessList(Core::System& system, s32* out_num_processes, u64 out_proc
const auto num_processes = process_list.size();
const auto copy_amount =
std::min(static_cast<std::size_t>(out_process_ids_size), num_processes);
(std::min)(static_cast<std::size_t>(out_process_ids_size), num_processes);
for (std::size_t i = 0; i < copy_amount && it != process_list.end(); ++i, ++it) {
memory.Write64(out_process_ids, (*it)->GetProcessId());

View file

@ -117,10 +117,10 @@ void SleepThread(Core::System& system, s64 ns) {
if (offset_tick > 0) {
timeout = kernel.HardwareTimer().GetTick() + offset_tick + 2;
if (timeout <= 0) {
timeout = std::numeric_limits<s64>::max();
timeout = (std::numeric_limits<s64>::max)();
}
} else {
timeout = std::numeric_limits<s64>::max();
timeout = (std::numeric_limits<s64>::max)();
}
// Sleep.
@ -226,7 +226,7 @@ Result GetThreadList(Core::System& system, s32* out_num_threads, u64 out_thread_
auto& memory = GetCurrentMemory(system.Kernel());
const auto& thread_list = current_process->GetThreadList();
const auto num_threads = thread_list.size();
const auto copy_amount = std::min(static_cast<std::size_t>(out_thread_ids_size), num_threads);
const auto copy_amount = (std::min)(static_cast<std::size_t>(out_thread_ids_size), num_threads);
auto list_iter = thread_list.cbegin();
for (std::size_t i = 0; i < copy_amount; ++i, ++list_iter) {