mirror of
https://github.com/decompals/wibo.git
synced 2025-12-12 22:56:13 +00:00
Initial macOS support (x86_64 with Rosetta 2)
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include "common.h"
|
||||
#include "context.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
|
||||
namespace kernel32 {
|
||||
@@ -11,22 +10,22 @@ namespace kernel32 {
|
||||
LONG WINAPI InterlockedIncrement(LONG volatile *Addend) {
|
||||
HOST_CONTEXT_GUARD();
|
||||
VERBOSE_LOG("InterlockedIncrement(%p)\n", Addend);
|
||||
std::atomic_ref<LONG> a(*const_cast<LONG *>(Addend));
|
||||
return a.fetch_add(1, std::memory_order_seq_cst) + 1;
|
||||
auto *ptr = const_cast<LONG *>(Addend);
|
||||
return __atomic_add_fetch(ptr, 1, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
|
||||
LONG WINAPI InterlockedDecrement(LONG volatile *Addend) {
|
||||
HOST_CONTEXT_GUARD();
|
||||
VERBOSE_LOG("InterlockedDecrement(%p)\n", Addend);
|
||||
std::atomic_ref<LONG> a(*const_cast<LONG *>(Addend));
|
||||
return a.fetch_sub(1, std::memory_order_seq_cst) - 1;
|
||||
auto *ptr = const_cast<LONG *>(Addend);
|
||||
return __atomic_sub_fetch(ptr, 1, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
|
||||
LONG WINAPI InterlockedExchange(LONG volatile *Target, LONG Value) {
|
||||
HOST_CONTEXT_GUARD();
|
||||
VERBOSE_LOG("InterlockedExchange(%p, %ld)\n", Target, static_cast<long>(Value));
|
||||
std::atomic_ref<LONG> a(*const_cast<LONG *>(Target));
|
||||
return a.exchange(Value, std::memory_order_seq_cst);
|
||||
auto *ptr = const_cast<LONG *>(Target);
|
||||
return __atomic_exchange_n(ptr, Value, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
|
||||
LONG WINAPI InterlockedCompareExchange(LONG volatile *Destination, LONG Exchange, LONG Comperand) {
|
||||
@@ -34,9 +33,9 @@ LONG WINAPI InterlockedCompareExchange(LONG volatile *Destination, LONG Exchange
|
||||
VERBOSE_LOG("InterlockedCompareExchange(%p, %ld, %ld)\n", Destination, static_cast<long>(Exchange),
|
||||
static_cast<long>(Comperand));
|
||||
|
||||
std::atomic_ref<LONG> a(*const_cast<LONG *>(Destination));
|
||||
auto *ptr = const_cast<LONG *>(Destination);
|
||||
LONG expected = Comperand;
|
||||
a.compare_exchange_strong(expected, Exchange, std::memory_order_seq_cst);
|
||||
__atomic_compare_exchange_n(ptr, &expected, Exchange, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
|
||||
return expected;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user