Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/libs/prx/libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,6 @@ if(BUILD_TESTING)
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
if(UNIX)
add_test_executable(exception_runtime_tests ${LIBS_INCLUDE_DIR}/tests/ExceptionRuntime.cpp)
target_include_directories(exception_runtime_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(exception_runtime_tests PRIVATE libc)
add_test(NAME exception_runtime COMMAND exception_runtime_tests)
add_test_executable(exception_personality_tests ${LIBS_INCLUDE_DIR}/tests/ExceptionPersonality.cpp)
target_include_directories(exception_personality_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(exception_personality_tests PRIVATE libc)
Expand All @@ -835,6 +831,10 @@ if(BUILD_TESTING)
add_test(NAME guest_path_lifetime COMMAND guest_path_lifetime_tests)
set_tests_properties(guest_path_lifetime PROPERTIES TIMEOUT 20)
if(NOT APPLE)
add_test_executable(exception_runtime_tests ${LIBS_INCLUDE_DIR}/tests/ExceptionRuntime.cpp)
target_include_directories(exception_runtime_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(exception_runtime_tests PRIVATE libc)
add_test(NAME exception_runtime COMMAND exception_runtime_tests)
enable_language(C)
add_test_executable(exception_c_cleanup_tests ${LIBS_INCLUDE_DIR}/tests/ExceptionCCleanup.cpp ${LIBS_INCLUDE_DIR}/tests/ExceptionCCleanup.c)
set_source_files_properties(${LIBS_INCLUDE_DIR}/tests/ExceptionCCleanup.c PROPERTIES COMPILE_OPTIONS -fexceptions)
Expand Down
4 changes: 2 additions & 2 deletions core/libs/prx/libc/include/FileStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ class FileStream {
const bool endOfFile = std::feof(GetHandle()) != 0;
const bool error = std::ferror(GetHandle()) != 0;
#else
const bool endOfFile = ::feof_unlocked(GetHandle()) != 0;
const bool error = ::ferror_unlocked(GetHandle()) != 0;
const bool endOfFile = feof_unlocked(GetHandle()) != 0;
const bool error = ferror_unlocked(GetHandle()) != 0;
#endif
_guest.flags = static_cast<std::int16_t>((_guest.flags & ~0x60) |
(endOfFile ? 0x20 : 0) | (error || guestError ? 0x40 : 0));
Expand Down
6 changes: 5 additions & 1 deletion core/libs/prx/libc/include/general/ExportMacros.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef CORE_LIBS_PRX_LIBC_INCLUDE_GENERAL_EXPORTMACROS_HPP
#define CORE_LIBS_PRX_LIBC_INCLUDE_GENERAL_EXPORTMACROS_HPP

#if defined(__GNUC__) || defined(__clang__)
#if defined(__APPLE__)
#define APS5_EXPORT(exportName, funcName) \
__asm__(".globl \"_" exportName "_nid_no_patch_cut\"\n\t" \
".set \"_" exportName "_nid_no_patch_cut\", _" #funcName)
#elif defined(__GNUC__) || defined(__clang__)
#define APS5_EXPORT(exportName, funcName) \
__asm__(".globl \"" exportName "_nid_no_patch_cut\"\n\t" \
".set \"" exportName "_nid_no_patch_cut\", " #funcName)
Expand Down
22 changes: 13 additions & 9 deletions core/libs/prx/libc/src/CxxAbiSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,22 @@ int APS5_VABI __cxa_thread_atexit_impl_nid_postfix(void (APS5_VABI *func)(void*)
auto* context = new (std::nothrow) ThreadAtexitContext{func, arg};
if (context == nullptr)
return -1;
const int result = __cxxabiv1::__cxa_thread_atexit(
[](void* opaque) {
auto* context = static_cast<ThreadAtexitContext*>(opaque);
const auto destructor = context->destructor;
void* object = context->object;
delete context;
destructor(object);
},
context, dso);
const auto run = [](void* opaque) {
auto* context = static_cast<ThreadAtexitContext*>(opaque);
const auto destructor = context->destructor;
void* object = context->object;
delete context;
destructor(object);
};
#ifdef __APPLE__
__cxxabiv1::__cxa_thread_atexit(run, context, dso);
return 0;
#else
const int result = __cxxabiv1::__cxa_thread_atexit(run, context, dso);
if (result != 0)
delete context;
return result;
#endif
}

int APS5_VABI __cxa_thread_atexit_nid_postfix(void (APS5_VABI *func)(void*), void* arg, void* dso) {
Expand Down
8 changes: 8 additions & 0 deletions core/libs/prx/libc/src/General.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ bool NotBefore(const WriteMark& time, const WriteMark& mark) {
using WriteMark = timespec;
WriteMark Now() {
timespec now;
#ifdef __APPLE__
clock_gettime(CLOCK_REALTIME, &now);
#else
clock_gettime(CLOCK_REALTIME_COARSE, &now);
#endif
return now;
}
bool NotBefore(const WriteMark& time, const WriteMark& mark) {
Expand Down Expand Up @@ -415,7 +419,11 @@ void FlushPath(const std::filesystem::path& path) {
#else
std::optional<WriteMark> WriteTime(const std::filesystem::path& path) {
struct stat data;
#ifdef __APPLE__
if (::stat(path.c_str(), &data) == 0) return data.st_mtimespec;
#else
if (::stat(path.c_str(), &data) == 0) return data.st_mtim;
#endif
if (errno == ENOENT || errno == ENOTDIR) return std::nullopt;
throw std::system_error(errno, std::generic_category(), "Reading the write time of " + path.string());
}
Expand Down
4 changes: 2 additions & 2 deletions core/libs/prx/libc/src/StandardStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int APS5_VABI getc_unlocked_nid_postfix(FileStream* stream) {
#ifdef _WIN32
const int result = _fgetc_nolock(native);
#else
const int result = ::getc_unlocked(native);
const int result = getc_unlocked(native);
#endif
stream->SyncUnlockedStatus();
stream->KeepDirectoryReadError(result == -1);
Expand All @@ -115,7 +115,7 @@ int APS5_VABI putc_unlocked_nid_postfix(int value, FileStream* stream) {
#ifdef _WIN32
const int result = _fputc_nolock(value, GetNativeStream(stream));
#else
const int result = ::putc_unlocked(value, GetNativeStream(stream));
const int result = putc_unlocked(value, GetNativeStream(stream));
#endif
stream->SyncUnlockedStatus();
return result;
Expand Down
4 changes: 4 additions & 0 deletions core/libs/prx/libc/src/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ std::tm toHostTm(const GuestTm& guest) {
host.tm_isdst = guest.tm_isdst;
#ifndef _WIN32
host.tm_gmtoff = static_cast<long>(guest.tm_gmtoff);
#ifdef __APPLE__
host.tm_zone = const_cast<char*>(guest.tm_zone);
#else
host.tm_zone = guest.tm_zone;
#endif
#endif
return host;
}
Expand Down
4 changes: 4 additions & 0 deletions core/libs/prx/libc/src/specifics/gcc/StackGuard.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include <cstdint>
#include <cstdlib>

#ifdef __APPLE__
extern "C" std::uintptr_t __stack_chk_guard_nid_postfix = 0xDEADBEEFCAFEBABEull;
#else
std::uintptr_t __stack_chk_guard = 0xDEADBEEFCAFEBABEull;
#endif
7 changes: 7 additions & 0 deletions core/libs/tests/Formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
#include <stdexcept>
#include <cstdint>
#include <cstdio>
#include <cstdarg>

#if defined(__clang__) && !defined(_WIN32)
#define __builtin_sysv_va_list va_list
#define __builtin_sysv_va_start va_start
#define __builtin_sysv_va_end va_end
#endif

extern "C" {
int APS5_VABI snprintf_nid_postfix(char*, size_t, const char*, ...);
Expand Down
2 changes: 1 addition & 1 deletion core/libs/tests/GuestFiopen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int main() {
Require(stream != nullptr && std::fgetc(stream->GetHandle()) == 'k');
fclose_nid_postfix(stream);

#ifndef _WIN32
#ifdef __linux__
auto* full = std::fopen("/dev/full", "wb");
Require(full != nullptr);
auto* fullStream = new FileStream(full, true);
Expand Down
Loading