mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-06-05 18:23:16 +00:00
Add initial macOS support.
This commit is contained in:
parent
36d528743a
commit
66fa29059c
29 changed files with 523 additions and 26 deletions
|
@ -1,7 +1,8 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <core/libraries/error_codes.h>
|
||||
#include <thread>
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "event_flag_obj.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <thread>
|
||||
#include "common/assert.h"
|
||||
#include "core/libraries/kernel/event_queue.h"
|
||||
|
||||
|
|
|
@ -3,11 +3,13 @@
|
|||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <date/tz.h>
|
||||
|
||||
#include <boost/asio/io_context.hpp>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/polyfill_thread.h"
|
||||
#include "common/singleton.h"
|
||||
#include "common/thread.h"
|
||||
#include "core/file_format/psf.h"
|
||||
|
@ -56,7 +58,7 @@ static void KernelServiceThread(std::stop_token stoken) {
|
|||
HLE_TRACE;
|
||||
{
|
||||
std::unique_lock lock{m_asio_req};
|
||||
cv_asio_req.wait(lock, stoken, [] { return asio_requests != 0; });
|
||||
Common::CondvarWait(cv_asio_req, lock, stoken, [] { return asio_requests != 0; });
|
||||
}
|
||||
if (stoken.stop_requested()) {
|
||||
break;
|
||||
|
@ -180,7 +182,7 @@ s64 PS4_SYSV_ABI ps4__write(int d, const void* buf, std::size_t nbytes) {
|
|||
int PS4_SYSV_ABI sceKernelConvertUtcToLocaltime(time_t time, time_t* local_time,
|
||||
struct OrbisTimesec* st, unsigned long* dst_sec) {
|
||||
LOG_TRACE(Kernel, "Called");
|
||||
const auto* time_zone = std::chrono::current_zone();
|
||||
const auto* time_zone = date::current_zone();
|
||||
auto info = time_zone->get_info(std::chrono::system_clock::now());
|
||||
|
||||
*local_time = info.offset.count() + info.save.count() * 60 + time;
|
||||
|
|
|
@ -74,7 +74,12 @@ s32 PS4_SYSV_ABI sceKernelAvailableDirectMemorySize(u64 searchStart, u64 searchE
|
|||
LOG_WARNING(Kernel_Vmm, "called searchStart = {:#x}, searchEnd = {:#x}, alignment = {:#x}",
|
||||
searchStart, searchEnd, alignment);
|
||||
auto* memory = Core::Memory::Instance();
|
||||
return memory->DirectQueryAvailable(searchStart, searchEnd, alignment, physAddrOut, sizeOut);
|
||||
|
||||
PAddr physAddr;
|
||||
s32 size = memory->DirectQueryAvailable(searchStart, searchEnd, alignment, &physAddr, sizeOut);
|
||||
*physAddrOut = static_cast<u64>(physAddr);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
s32 PS4_SYSV_ABI sceKernelVirtualQuery(const void* addr, int flags, OrbisVirtualQueryInfo* info,
|
||||
|
|
|
@ -848,6 +848,37 @@ int PS4_SYSV_ABI posix_pthread_mutexattr_setprotocol(ScePthreadMutexattr* attr,
|
|||
return result;
|
||||
}
|
||||
|
||||
#ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
|
||||
static int pthread_mutex_timedlock(pthread_mutex_t* mutex, const struct timespec* abstime) {
|
||||
int rc;
|
||||
while ((rc = pthread_mutex_trylock(mutex)) == EBUSY) {
|
||||
struct timespec curr_time;
|
||||
clock_gettime(CLOCK_REALTIME, &curr_time);
|
||||
|
||||
s64 remaining_ns = 0;
|
||||
remaining_ns +=
|
||||
(static_cast<s64>(abstime->tv_sec) - static_cast<s64>(curr_time.tv_sec)) * 1000000000L;
|
||||
remaining_ns += static_cast<s64>(abstime->tv_nsec) - static_cast<s64>(curr_time.tv_nsec);
|
||||
|
||||
if (remaining_ns <= 0) {
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
|
||||
struct timespec sleep_time;
|
||||
sleep_time.tv_sec = 0;
|
||||
if (remaining_ns < 5000000L) {
|
||||
sleep_time.tv_nsec = remaining_ns;
|
||||
} else {
|
||||
sleep_time.tv_nsec = 5000000;
|
||||
}
|
||||
|
||||
nanosleep(&sleep_time, nullptr);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexTimedlock(ScePthreadMutex* mutex, u64 usec) {
|
||||
mutex = createMutex(mutex);
|
||||
if (mutex == nullptr) {
|
||||
|
@ -1232,7 +1263,10 @@ int PS4_SYSV_ABI posix_pthread_create(ScePthread* thread, const ScePthreadAttr*
|
|||
using Destructor = void (*)(void*);
|
||||
|
||||
int PS4_SYSV_ABI posix_pthread_key_create(u32* key, Destructor func) {
|
||||
return pthread_key_create(key, func);
|
||||
pthread_key_t thread_key;
|
||||
int rc = pthread_key_create(&thread_key, func);
|
||||
*key = static_cast<u32>(thread_key);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI posix_pthread_setspecific(int key, const void* value) {
|
||||
|
|
|
@ -12,7 +12,10 @@ int PS4_SYSV_ABI scePthreadKeyCreate(OrbisPthreadKey* key, PthreadKeyDestructor
|
|||
return ORBIS_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_key_create(key, nullptr);
|
||||
pthread_key_t thread_key;
|
||||
int result = pthread_key_create(&thread_key, nullptr);
|
||||
*key = static_cast<OrbisPthreadKey>(thread_key);
|
||||
|
||||
if (destructor) {
|
||||
auto thread = scePthreadSelf();
|
||||
thread->key_destructors.emplace_back(*key, destructor);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "common/ntapi.h"
|
||||
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue