mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #98 from SamG-Coder/codex/videoout-vblank-timing
fix(runtime): run converted SDK samples through clean C++ shutdown
This commit is contained in:
@@ -7,6 +7,7 @@ target_sources(libc PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Strings.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/AllocatingStrings.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/WideConversion.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Multibyte.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/StringExtensions.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Math.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Time.cpp
|
||||
|
||||
@@ -39,6 +39,7 @@ class FileStream {
|
||||
std::byte _reserved[256 - sizeof(GuestFilePrefix)]{};
|
||||
std::FILE* _handle;
|
||||
bool _dynamic;
|
||||
bool encodingError = false;
|
||||
|
||||
public:
|
||||
explicit FileStream(std::FILE* handle, bool dynamic = false) : _handle(handle), _dynamic(dynamic) {
|
||||
@@ -68,6 +69,7 @@ public:
|
||||
bool Reopen(const char* filename, const char* mode) {
|
||||
auto* previous = GetHandle();
|
||||
_guest = {};
|
||||
encodingError = false;
|
||||
_handle = std::freopen(filename, mode, previous);
|
||||
if (!_handle) return false;
|
||||
_guest.flags = 0x10;
|
||||
@@ -83,7 +85,18 @@ public:
|
||||
_guest.readRemaining = 0;
|
||||
_guest.writeRemaining = 0;
|
||||
_guest.flags = static_cast<std::int16_t>((_guest.flags & ~0x60) |
|
||||
(std::feof(GetHandle()) ? 0x20 : 0) | (std::ferror(GetHandle()) ? 0x40 : 0));
|
||||
(std::feof(GetHandle()) ? 0x20 : 0) | (std::ferror(GetHandle()) || encodingError ? 0x40 : 0));
|
||||
}
|
||||
|
||||
void SetEncodingError() {
|
||||
encodingError = true;
|
||||
SyncStatus();
|
||||
}
|
||||
|
||||
void ClearError() {
|
||||
std::clearerr(GetHandle());
|
||||
encodingError = false;
|
||||
SyncStatus();
|
||||
}
|
||||
|
||||
void Close() {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef CORE_LIBS_PRX_LIBC_INCLUDE_WINDOWSSCANNING_HPP
|
||||
#define CORE_LIBS_PRX_LIBC_INCLUDE_WINDOWSSCANNING_HPP
|
||||
|
||||
#include "WindowsFormatting.hpp"
|
||||
#include "General.hpp"
|
||||
#include <cerrno>
|
||||
|
||||
namespace LibcDetail {
|
||||
|
||||
inline int ScanWindows(const char* input, const char* format, const void* source) {
|
||||
if (!input || !format || !source) { errno = 22; return EOF; }
|
||||
std::string translated;
|
||||
std::vector<void*> pointers;
|
||||
FormatArguments args(source);
|
||||
while (*format) {
|
||||
const char value = *format++;
|
||||
translated += value;
|
||||
if (value != '%') continue;
|
||||
if (*format == '%') { translated += *format++; continue; }
|
||||
const bool suppressed = *format == '*';
|
||||
if (suppressed) translated += *format++;
|
||||
while (*format >= '0' && *format <= '9') translated += *format++;
|
||||
std::string length;
|
||||
if (*format && std::strchr("hljztL", *format)) {
|
||||
length += *format++;
|
||||
if ((length == "h" && *format == 'h') || (length == "l" && *format == 'l')) length += *format++;
|
||||
}
|
||||
const char conversion = *format;
|
||||
if (!conversion) { errno = 22; return EOF; }
|
||||
if (!std::strchr("diouxXaAeEfFgGcspn[", conversion)) {
|
||||
NotImplemented_nid_no_patch("vsscanf format conversion");
|
||||
return EOF;
|
||||
}
|
||||
++format;
|
||||
if (std::strchr("diouxXn", conversion) && (length == "l" || length == "j" || length == "z" || length == "t"))
|
||||
translated += "ll";
|
||||
else translated += length;
|
||||
translated += conversion;
|
||||
if (conversion == '[') {
|
||||
if (*format == '^') translated += *format++;
|
||||
if (*format == ']') translated += *format++;
|
||||
while (*format && *format != ']') translated += *format++;
|
||||
if (*format != ']') { errno = 22; return EOF; }
|
||||
translated += *format++;
|
||||
}
|
||||
if (!suppressed) pointers.push_back(args.Next<void*>());
|
||||
}
|
||||
return std::vsscanf(input, translated.c_str(), reinterpret_cast<char*>(pointers.data()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,99 @@
|
||||
#ifndef CORE_LIBS_PRX_LIBC_INCLUDE_WINDOWSWIDEFORMATTING_HPP
|
||||
#define CORE_LIBS_PRX_LIBC_INCLUDE_WINDOWSWIDEFORMATTING_HPP
|
||||
|
||||
#include "WindowsFormatting.hpp"
|
||||
#include "General.hpp"
|
||||
#include <cerrno>
|
||||
#include <cwchar>
|
||||
#include <deque>
|
||||
|
||||
namespace LibcDetail {
|
||||
|
||||
inline int FormatWideWindows(wchar_t* output, size_t capacity, const wchar_t* format, const void* source) {
|
||||
if (!capacity) return -1;
|
||||
if (!output || !format || !source) { errno = 22; return -1; }
|
||||
static_assert(sizeof(wchar_t) == 2);
|
||||
FormatArguments args(source);
|
||||
std::wstring translated;
|
||||
std::wstring result;
|
||||
std::vector<std::uint64_t> slots;
|
||||
std::deque<long double> extended;
|
||||
auto append = [&slots](auto value) {
|
||||
static_assert(sizeof(value) <= 8);
|
||||
std::uint64_t bits = 0;
|
||||
std::memcpy(&bits, &value, sizeof(value));
|
||||
slots.push_back(bits);
|
||||
};
|
||||
while (*format) {
|
||||
const wchar_t value = *format++;
|
||||
if (value != L'%') { result += value; continue; }
|
||||
if (*format == L'%') { result += *format++; continue; }
|
||||
translated = L"%";
|
||||
slots.clear();
|
||||
extended.clear();
|
||||
bool nullCharacter = false;
|
||||
while (*format && std::wcschr(L"-+ #0", *format)) translated += *format++;
|
||||
if (*format == L'*') { translated += *format++; append(args.Next<int>()); }
|
||||
else while (*format >= L'0' && *format <= L'9') translated += *format++;
|
||||
if (*format == L'.') {
|
||||
translated += *format++;
|
||||
if (*format == L'*') { translated += *format++; append(args.Next<int>()); }
|
||||
else while (*format >= L'0' && *format <= L'9') translated += *format++;
|
||||
}
|
||||
std::wstring length;
|
||||
if (*format && std::wcschr(L"hljztL", *format)) {
|
||||
length += *format++;
|
||||
if ((length == L"h" && *format == L'h') || (length == L"l" && *format == L'l')) length += *format++;
|
||||
}
|
||||
const wchar_t conversion = *format;
|
||||
if (!conversion) { errno = 22; return -1; }
|
||||
if (!std::wcschr(L"diouxXaAeEfFgGcspn", conversion)) {
|
||||
NotImplemented_nid_no_patch("swprintf format conversion");
|
||||
return -1;
|
||||
}
|
||||
++format;
|
||||
if (std::wcschr(L"diouxXn", conversion) && (length == L"l" || length == L"j" || length == L"z" || length == L"t"))
|
||||
translated += L"ll";
|
||||
else if (conversion == L's' && length.empty()) translated += L"h";
|
||||
else if (conversion == L'c' && length.empty()) translated += L"l";
|
||||
else translated += length;
|
||||
translated += conversion;
|
||||
if (conversion == L'n') {
|
||||
void* pointer = args.Next<void*>();
|
||||
if (length == L"hh") *static_cast<signed char*>(pointer) = static_cast<signed char>(result.size());
|
||||
else if (length == L"h") *static_cast<short*>(pointer) = static_cast<short>(result.size());
|
||||
else if (length.empty()) *static_cast<int*>(pointer) = static_cast<int>(result.size());
|
||||
else *static_cast<std::int64_t*>(pointer) = static_cast<std::int64_t>(result.size());
|
||||
continue;
|
||||
}
|
||||
if (conversion == L's' || conversion == L'p') append(args.Next<void*>());
|
||||
else if (conversion == L'c') {
|
||||
const int character = args.Next<int>();
|
||||
const int converted = length.empty() ? static_cast<int>(static_cast<unsigned char>(character)) : character;
|
||||
nullCharacter = converted == 0;
|
||||
append(nullCharacter ? 1 : converted);
|
||||
}
|
||||
else if (std::wcschr(L"aAeEfFgG", conversion)) {
|
||||
if (length == L"L") {
|
||||
extended.push_back(args.Next<long double>());
|
||||
append(&extended.back());
|
||||
} else append(args.Next<double>());
|
||||
} else if (length.empty() || length == L"h" || length == L"hh") append(args.Next<unsigned int>());
|
||||
else append(args.Next<std::uint64_t>());
|
||||
if (result.size() >= capacity) return -1;
|
||||
std::vector<wchar_t> part(capacity - result.size());
|
||||
const int count = std::vswprintf(part.data(), part.size(), translated.c_str(), reinterpret_cast<char*>(slots.data()));
|
||||
if (count < 0 || static_cast<size_t>(count) >= part.size()) return -1;
|
||||
if (nullCharacter) {
|
||||
for (int i = 0; i < count; ++i) if (part[i] == 1) part[i] = 0;
|
||||
}
|
||||
result.append(part.data(), static_cast<size_t>(count));
|
||||
}
|
||||
if (result.size() >= capacity || result.size() > INT_MAX) return -1;
|
||||
std::memcpy(output, result.c_str(), (result.size() + 1) * sizeof(wchar_t));
|
||||
return static_cast<int>(result.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -6,14 +6,20 @@
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
|
||||
#include "prx/libc/include/General.hpp"
|
||||
#include "SceTypes.hpp"
|
||||
#include "prx/libc/include/VarArgsAbi.hpp"
|
||||
#include "prx/libc/include/FileStream.hpp"
|
||||
#include "prx/libc/include/ApplicationHeap.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "prx/libc/include/WindowsFormatting.hpp"
|
||||
#include "prx/libc/include/WindowsScanning.hpp"
|
||||
#include "prx/libc/include/WindowsWideFormatting.hpp"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
@@ -125,6 +131,47 @@ int ScanGuest(const char* buffer, const char* format, bool secure, NextPointer n
|
||||
|
||||
extern "C" {
|
||||
|
||||
int APS5_VABI swprintf_nid_postfix(wchar_t* output, size_t capacity, const wchar_t* format, ...) {
|
||||
#ifdef _WIN32
|
||||
__builtin_sysv_va_list args;
|
||||
__builtin_sysv_va_start(args, format);
|
||||
const int result = LibcDetail::FormatWideWindows(output, capacity, format, args);
|
||||
__builtin_sysv_va_end(args);
|
||||
#else
|
||||
std::va_list args;
|
||||
va_start(args, format);
|
||||
const int result = std::vswprintf(output, capacity, format, args);
|
||||
va_end(args);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
int APS5_VABI vasprintf_nid_postfix(char** destination, const char* format, VaList* args) {
|
||||
if (!destination) { errno = 22; return -1; }
|
||||
*destination = nullptr;
|
||||
if (!format || !args) { errno = 22; return -1; }
|
||||
try {
|
||||
#ifdef _WIN32
|
||||
std::string text;
|
||||
const int count = LibcDetail::FormatWindows(nullptr, 0, format, args, &text);
|
||||
const char* source = text.c_str();
|
||||
#else
|
||||
char* text = nullptr;
|
||||
const int count = ::vasprintf(&text, format, *reinterpret_cast<std::va_list*>(args));
|
||||
std::unique_ptr<char, decltype(&std::free)> owner(text, std::free);
|
||||
if (count < 0) return -1;
|
||||
const char* source = text;
|
||||
#endif
|
||||
auto* output = static_cast<char*>(ApplicationHeapAllocate_nid_no_patch(static_cast<size_t>(count) + 1));
|
||||
std::memcpy(output, source, static_cast<size_t>(count) + 1);
|
||||
*destination = output;
|
||||
return count;
|
||||
} catch (const std::bad_alloc&) {
|
||||
errno = 12;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int APS5_VABI vfprintf_nid_postfix(FileStream* stream, const char* format, VaList* args) {
|
||||
auto* native = GetNativeStream(stream);
|
||||
#ifdef _WIN32
|
||||
@@ -259,8 +306,23 @@ int APS5_VABI sprintf_nid_postfix(VA_ARGS) {
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
int APS5_VABI vsscanf_nid_postfix(const char* input, const char* format, VaList* args) {
|
||||
#ifdef _WIN32
|
||||
return LibcDetail::ScanWindows(input, format, args);
|
||||
#else
|
||||
return std::vsscanf(input, format, *reinterpret_cast<std::va_list*>(args));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
int APS5_VABI sscanf_nid_postfix(const char* input, const char* format, ...) {
|
||||
__builtin_sysv_va_list args;
|
||||
__builtin_sysv_va_start(args, format);
|
||||
const int result = vsscanf_nid_postfix(input, format, reinterpret_cast<VaList*>(args));
|
||||
__builtin_sysv_va_end(args);
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
int APS5_VABI sscanf_nid_postfix(VA_ARGS) {
|
||||
LibcDetail::RegSaveArea regs;
|
||||
LibcDetail::FillRegSaveArea(regs, rdx, rcx, r8, r9, 0, 0,
|
||||
@@ -274,19 +336,10 @@ int APS5_VABI sscanf_nid_postfix(VA_ARGS) {
|
||||
*va
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
int APS5_VABI sscanf_nid_postfix(const char* buffer, const char* format, ...) {
|
||||
__builtin_sysv_va_list args;
|
||||
__builtin_sysv_va_start(args, format);
|
||||
const int result = ScanGuest(buffer, format, false, [&] { return __builtin_va_arg(args, void*); }, [&] { return __builtin_va_arg(args, unsigned int); });
|
||||
__builtin_sysv_va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
int APS5_VABI sscanf_s_nid_postfix(const char* buffer, const char* format, ...) {
|
||||
__builtin_sysv_va_list args;
|
||||
__builtin_sysv_va_start(args, format);
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#include "prx/libc/include/general/VabiMacros.hpp"
|
||||
#include <cerrno>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
extern "C" {
|
||||
|
||||
int __mb_cur_max_nid_postfix = 1;
|
||||
|
||||
int APS5_VABI ___mb_cur_max_nid_postfix() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int APS5_VABI mbsinit_nid_postfix(const void*) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::size_t APS5_VABI mbrtowc_nid_postfix(std::uint16_t* destination, const char* source, std::size_t count, void*) {
|
||||
if (!source) return 0;
|
||||
if (!count) return static_cast<std::size_t>(-2);
|
||||
const auto value = static_cast<unsigned char>(*source);
|
||||
if (destination) *destination = value;
|
||||
return value != 0;
|
||||
}
|
||||
|
||||
std::size_t APS5_VABI mbrlen_nid_postfix(const char* source, std::size_t count, void* state) {
|
||||
return mbrtowc_nid_postfix(nullptr, source, count, state);
|
||||
}
|
||||
|
||||
int APS5_VABI mbtowc_nid_postfix(std::uint16_t* destination, const char* source, std::size_t count) {
|
||||
const auto result = mbrtowc_nid_postfix(destination, source, count, nullptr);
|
||||
if (result == static_cast<std::size_t>(-2)) {
|
||||
errno = 86;
|
||||
return -1;
|
||||
}
|
||||
return static_cast<int>(result);
|
||||
}
|
||||
|
||||
std::size_t APS5_VABI wcrtomb_nid_postfix(char* destination, std::uint16_t value, void*) {
|
||||
if (!destination) return 1;
|
||||
if (value > 255) {
|
||||
errno = 86;
|
||||
return static_cast<std::size_t>(-1);
|
||||
}
|
||||
*destination = static_cast<char>(value);
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::size_t APS5_VABI mbsrtowcs_nid_postfix(std::uint16_t* destination, const char** source, std::size_t capacity, void*) {
|
||||
if (!destination) return std::strlen(*source);
|
||||
std::size_t converted = 0;
|
||||
while (converted < capacity) {
|
||||
const auto value = static_cast<unsigned char>((*source)[converted]);
|
||||
destination[converted] = value;
|
||||
if (value == 0) {
|
||||
*source = nullptr;
|
||||
return converted;
|
||||
}
|
||||
++converted;
|
||||
}
|
||||
*source += converted;
|
||||
return converted;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,19 @@ std::exception_ptr shutdownFailure;
|
||||
std::stop_source shutdownSource;
|
||||
std::atomic<bool> exitRequested{false};
|
||||
std::atomic<bool> exitStarted{false};
|
||||
using GuestExitCallback = void (APS5_VABI*)();
|
||||
std::mutex exitCallbackMutex;
|
||||
std::vector<GuestExitCallback> exitCallbacks;
|
||||
|
||||
void runGuestExitCallback() {
|
||||
GuestExitCallback callback;
|
||||
{
|
||||
std::lock_guard lock(exitCallbackMutex);
|
||||
callback = exitCallbacks.back();
|
||||
exitCallbacks.pop_back();
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -139,10 +152,14 @@ int* APS5_VABI __error_nid_postfix() {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
int APS5_VABI atexit_nid_postfix(atexit_func_t func) {
|
||||
int APS5_VABI atexit_nid_postfix(GuestExitCallback func) {
|
||||
if (func == nullptr)
|
||||
return 0;
|
||||
return std::atexit(func);
|
||||
std::lock_guard lock(exitCallbackMutex);
|
||||
exitCallbacks.push_back(func);
|
||||
const int result = std::atexit(runGuestExitCallback);
|
||||
if (result != 0) exitCallbacks.pop_back();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "prx/libc/include/FileStream.hpp"
|
||||
#include "prx/libc/include/general/VabiMacros.hpp"
|
||||
#include <cerrno>
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#else
|
||||
@@ -18,6 +19,21 @@ int APS5_VABI fgetc_nid_postfix(FileStream* stream) {
|
||||
stream->SyncStatus();
|
||||
return result;
|
||||
}
|
||||
std::int32_t APS5_VABI fgetwc_nid_postfix(FileStream* stream) {
|
||||
return fgetc_nid_postfix(stream);
|
||||
}
|
||||
|
||||
std::int32_t APS5_VABI ungetwc_nid_postfix(std::int32_t value, FileStream* stream) {
|
||||
if (value == -1) return -1;
|
||||
if (value < 0 || value > 255) {
|
||||
errno = 86;
|
||||
stream->SetEncodingError();
|
||||
return -1;
|
||||
}
|
||||
const int result = std::ungetc(value, GetNativeStream(stream));
|
||||
stream->SyncStatus();
|
||||
return result;
|
||||
}
|
||||
int APS5_VABI getc_nid_postfix(FileStream* stream) { return fgetc_nid_postfix(stream); }
|
||||
int APS5_VABI __srget_nid_postfix(FileStream* stream) { return fgetc_nid_postfix(stream); }
|
||||
int APS5_VABI getchar_nid_postfix() { return fgetc_nid_postfix(__stdinp_nid_postfix); }
|
||||
@@ -48,8 +64,7 @@ int APS5_VABI ferror_nid_postfix(FileStream* stream) {
|
||||
return (stream->GuestState().flags & 0x40) != 0;
|
||||
}
|
||||
void APS5_VABI clearerr_nid_postfix(FileStream* stream) {
|
||||
std::clearerr(GetNativeStream(stream));
|
||||
stream->SyncStatus();
|
||||
stream->ClearError();
|
||||
}
|
||||
int APS5_VABI fileno_nid_postfix(FileStream* stream) {
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <cctype>
|
||||
#include <cwchar>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
|
||||
#include "prx/libc/include/General.hpp"
|
||||
|
||||
@@ -15,6 +16,10 @@ void* APS5_VABI memset_nid_postfix(void* s, int c, size_t n) {
|
||||
return std::memset(s, c, n);
|
||||
}
|
||||
|
||||
void APS5_VABI bzero_nid_postfix(void* destination, size_t count) {
|
||||
std::memset(destination, 0, count);
|
||||
}
|
||||
|
||||
void* APS5_VABI memcpy_nid_postfix(void* dest, const void* src, size_t n) {
|
||||
return std::memcpy(dest, src, n);
|
||||
}
|
||||
@@ -317,6 +322,12 @@ float APS5_VABI wcstof_nid_postfix(const wchar_t* str, wchar_t** endptr) {
|
||||
return std::wcstof(str, endptr);
|
||||
}
|
||||
|
||||
long double APS5_VABI wcstold_nid_postfix(const wchar_t* str, wchar_t** endptr) {
|
||||
static_assert(sizeof(long double) == 16);
|
||||
static_assert(std::numeric_limits<long double>::digits == 64);
|
||||
return std::wcstold(str, endptr);
|
||||
}
|
||||
|
||||
long long APS5_VABI wcstol_nid_postfix(const wchar_t* str, wchar_t** endptr, int base) {
|
||||
return std::wcstoll(str, endptr, base);
|
||||
}
|
||||
@@ -325,4 +336,24 @@ long long APS5_VABI wcstoll_nid_postfix(const wchar_t* str, wchar_t** endptr, in
|
||||
return std::wcstoll(str, endptr, base);
|
||||
}
|
||||
|
||||
unsigned long long APS5_VABI wcstoul_nid_postfix(const wchar_t* str, wchar_t** endptr, int base) {
|
||||
return std::wcstoull(str, endptr, base);
|
||||
}
|
||||
|
||||
unsigned long long APS5_VABI wcstoull_nid_postfix(const wchar_t* str, wchar_t** endptr, int base) {
|
||||
return std::wcstoull(str, endptr, base);
|
||||
}
|
||||
|
||||
int APS5_VABI wcscoll_nid_postfix(const wchar_t* first, const wchar_t* second) {
|
||||
return std::wcscoll(first, second);
|
||||
}
|
||||
|
||||
size_t APS5_VABI wcsxfrm_nid_postfix(wchar_t* destination, const wchar_t* source, size_t count) {
|
||||
return std::wcsxfrm(destination, source, count);
|
||||
}
|
||||
|
||||
size_t APS5_VABI strxfrm_nid_postfix(char* destination, const char* source, size_t count) {
|
||||
return std::strxfrm(destination, source, count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,11 @@ int toPosix(int result) {
|
||||
|
||||
extern "C" {
|
||||
|
||||
int APS5_VABI pthread_cond_destroy_nid_postfix(PthreadCond* cond) {
|
||||
if (!cond) return PosixThread::GUEST_EINVAL;
|
||||
return toPosix(scePthreadCondDestroy(cond));
|
||||
}
|
||||
|
||||
int APS5_VABI pthread_cond_broadcast_nid_postfix(PthreadCond* cond) {
|
||||
return toPosix(scePthreadCondBroadcast(cond));
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ struct GuestImport {
|
||||
struct GuestRuntime {
|
||||
std::string Path;
|
||||
std::vector<GuestImport> Imports;
|
||||
std::vector<std::uint32_t> InitArrayRvas;
|
||||
std::vector<std::uint32_t> FiniArrayRvas;
|
||||
std::uint32_t InitRva = 0;
|
||||
std::uint32_t FiniRva = 0;
|
||||
bool UsePlatformTlsResolver = true;
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
void Finalize(WindowsStubEmitter& code, const std::vector<Domain::GuestRuntime>& modules, std::uint32_t handles, std::uint32_t finished) const;
|
||||
std::uint32_t EmitTlsResolver(WindowsStubEmitter& code) const;
|
||||
private:
|
||||
void callLifecycle(WindowsStubEmitter& code, std::uint32_t handle, std::uint32_t rva) const;
|
||||
void callLifecycle(WindowsStubEmitter& code, std::uint32_t handle, std::uint32_t rva, bool indirect = false) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Elfpatcher::Windows {
|
||||
|
||||
class WindowsLoadImage {
|
||||
public:
|
||||
WindowsLoadImage(const std::vector<std::uint8_t>& source, const std::vector<Domain::ProgramHeader>& headers);
|
||||
WindowsLoadImage(const std::vector<std::uint8_t>& source, const std::vector<Domain::ProgramHeader>& headers, bool requireEntry = true);
|
||||
std::uint32_t GetRva(std::uint64_t address, std::uint64_t size = 1) const;
|
||||
std::uint32_t GetEndRva() const;
|
||||
std::uint32_t GetEntryRva() const;
|
||||
@@ -22,7 +22,7 @@ private:
|
||||
std::vector<std::uint8_t> data;
|
||||
std::vector<std::uint32_t> pageFlags;
|
||||
std::uint64_t firstAddress;
|
||||
std::uint32_t entryRva;
|
||||
std::uint32_t entryRva = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -96,6 +96,8 @@ std::vector<std::uint8_t> GuestModuleWriter::WriteLinux(const Relinker::GuestIma
|
||||
tag(20, 7);
|
||||
tag(3, image.Got);
|
||||
}
|
||||
if (!image.InitArray.empty()) { tag(25, image.InitArray.front()); tag(27, image.InitArray.size() * 8); }
|
||||
if (!image.FiniArray.empty()) { tag(26, image.FiniArray.front()); tag(28, image.FiniArray.size() * 8); }
|
||||
if (init != 0) tag(12, init);
|
||||
if (fini != 0) tag(13, fini);
|
||||
tag(30, 8);
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace {
|
||||
|
||||
constexpr std::uint32_t PathCapacity = 32768;
|
||||
constexpr std::uint32_t ErrorMessageCapacity = 32768;
|
||||
constexpr std::uint32_t ArgumentCapacity = 32768;
|
||||
constexpr std::uint32_t ArgumentTextCapacity = ArgumentCapacity * 3;
|
||||
|
||||
std::string normalizeRunPath(std::string path) {
|
||||
if (path.empty() || std::any_of(path.begin(), path.end(), [](const unsigned char value) { return value == 0 || value >= 128; }))
|
||||
@@ -54,6 +56,12 @@ WindowsEntryStub WindowsEntryStubBuilder::Build(const std::uint32_t dataRva, con
|
||||
|
||||
const auto programPath = reserve(PathCapacity);
|
||||
const auto modulePath = reserve(PathCapacity);
|
||||
const auto argumentBlock = reserve(8);
|
||||
const auto argumentCount = reserve(4);
|
||||
const auto wideArguments = reserve(8);
|
||||
const auto shellHandle = reserve(8);
|
||||
const auto shellLibrary = addString("shell32.dll");
|
||||
const auto parseArguments = addString("CommandLineToArgvW");
|
||||
const auto handles = reserve(libraries.size() * 8);
|
||||
const auto guestFinished = reserve(4);
|
||||
const WindowsGuestStartup guestStartup;
|
||||
@@ -98,6 +106,8 @@ WindowsEntryStub WindowsEntryStubBuilder::Build(const std::uint32_t dataRva, con
|
||||
std::vector<std::string> errors = {"FAIL: cannot obtain executable path\n", "FAIL: executable or library path is too long\n", "FAIL: executable path has no directory\n"};
|
||||
for (const auto& import : imports)
|
||||
errors.push_back("FAIL: unresolved ELF import " + import.Name + "\n");
|
||||
const auto argumentError = errors.size();
|
||||
errors.push_back("FAIL: cannot prepare command-line arguments\n");
|
||||
std::vector<std::uint32_t> errorRvas;
|
||||
for (const auto& error : errors)
|
||||
errorRvas.push_back(addString(error));
|
||||
@@ -327,9 +337,54 @@ WindowsEntryStub WindowsEntryStubBuilder::Build(const std::uint32_t dataRva, con
|
||||
|
||||
guestStartup.Initialize(code, guestModules, handles);
|
||||
writeString(enteringElf);
|
||||
code.Emit({0x48, 0xc7, 0x44, 0x24, 0x40, 1, 0, 0, 0});
|
||||
code.Rip({0x48, 0x8d, 0x05}, programPath);
|
||||
code.Emit({0x48, 0x89, 0x44, 0x24, 0x48, 0x31, 0xc0, 0x48, 0x89, 0x44, 0x24, 0x50, 0x48, 0x89, 0x44, 0x24, 0x58, 0x48, 0x8d, 0x7c, 0x24, 0x40});
|
||||
code.Rip({0x48, 0x8d, 0x0d}, shellLibrary);
|
||||
code.Emit({0x31, 0xd2, 0x41, 0xb8, 0, 8, 0, 0});
|
||||
call("LoadLibraryExA");
|
||||
requireNonzero(argumentError, 0xc0000135u);
|
||||
code.Rip({0x48, 0x89, 0x05}, shellHandle);
|
||||
code.Emit({0x48, 0x89, 0xc1});
|
||||
code.Rip({0x48, 0x8d, 0x15}, parseArguments);
|
||||
call("GetProcAddress");
|
||||
requireNonzero(argumentError, 0xc0000139u);
|
||||
code.Emit({0x48, 0x89, 0xc3});
|
||||
call("GetCommandLineW");
|
||||
code.Emit({0x48, 0x89, 0xc1});
|
||||
code.Rip({0x48, 0x8d, 0x15}, argumentCount);
|
||||
code.Emit({0xff, 0xd3});
|
||||
requireNonzero(argumentError, 0xc000000du);
|
||||
code.Rip({0x48, 0x89, 0x05}, wideArguments);
|
||||
code.Emit({0x48, 0x89, 0xc3});
|
||||
code.Rip({0x8b, 0x2d}, argumentCount);
|
||||
code.Emit({0x8d, 0x45, 0xff, 0x3d});
|
||||
code.U32(ArgumentCapacity - 1);
|
||||
const auto countFits = code.Branch({0x0f, 0x82});
|
||||
fail(argumentError, 0xc000000du);
|
||||
code.PatchBranch(countFits, code.GetRva());
|
||||
code.Emit({0x31, 0xc9, 0xba});
|
||||
code.U32((ArgumentCapacity + 3) * 8 + ArgumentTextCapacity);
|
||||
code.Emit({0x41, 0xb8, 0, 0x30, 0, 0, 0x41, 0xb9, 4, 0, 0, 0});
|
||||
call("VirtualAlloc");
|
||||
requireNonzero(argumentError, 0xc0000017u);
|
||||
code.Rip({0x48, 0x89, 0x05}, argumentBlock);
|
||||
code.Emit({0x48, 0x89, 0x28, 0x48, 0x8d, 0x70, 8, 0x48, 0x8d, 0xb8});
|
||||
code.U32((ArgumentCapacity + 3) * 8);
|
||||
code.Emit({0x41, 0xbc});
|
||||
code.U32(ArgumentTextCapacity);
|
||||
const auto convertArgument = code.GetRva();
|
||||
code.Emit({0x48, 0x89, 0x3e, 0xb9});
|
||||
code.U32(65001);
|
||||
code.Emit({0xba, 0x80, 0, 0, 0, 0x4c, 0x8b, 0x03, 0x41, 0xb9, 0xff, 0xff, 0xff, 0xff});
|
||||
code.Emit({0x48, 0x89, 0x7c, 0x24, 0x20, 0x44, 0x89, 0x64, 0x24, 0x28});
|
||||
code.Emit({0x48, 0xc7, 0x44, 0x24, 0x30, 0, 0, 0, 0, 0x48, 0xc7, 0x44, 0x24, 0x38, 0, 0, 0, 0});
|
||||
call("WideCharToMultiByte");
|
||||
requireNonzero(argumentError, 0xc000000du);
|
||||
code.Emit({0x48, 0x01, 0xc7, 0x41, 0x29, 0xc4, 0x48, 0x83, 0xc3, 8, 0x48, 0x83, 0xc6, 8, 0xff, 0xcd});
|
||||
code.Rip({0x0f, 0x85}, convertArgument);
|
||||
code.Rip({0x48, 0x8b, 0x0d}, wideArguments);
|
||||
call("LocalFree");
|
||||
code.Rip({0x48, 0x8b, 0x0d}, shellHandle);
|
||||
call("FreeLibrary");
|
||||
code.Rip({0x48, 0x8b, 0x3d}, argumentBlock);
|
||||
const auto exitCallback = code.Branch({0x48, 0x8d, 0x35});
|
||||
code.Rip({0xe8}, entryRva);
|
||||
code.Emit({0x89, 0x44, 0x24, 0x58});
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Elfpatcher {
|
||||
|
||||
std::vector<std::uint8_t> GuestModuleWriter::WriteWindows(const Relinker::GuestImage& guest, Domain::GuestRuntime& runtime) const {
|
||||
using namespace Windows;
|
||||
WindowsLoadImage image(guest.Bytes, guest.Headers);
|
||||
WindowsLoadImage image(guest.Bytes, guest.Headers, false);
|
||||
std::vector<std::uint32_t> relocations;
|
||||
std::vector<std::pair<std::uint64_t, std::uint32_t>> tlsModules;
|
||||
std::map<std::uint64_t, std::uint64_t> targets;
|
||||
@@ -164,6 +164,8 @@ std::vector<std::uint8_t> GuestModuleWriter::WriteWindows(const Relinker::GuestI
|
||||
}
|
||||
const auto entry = nextRva;
|
||||
sections.push_back({".dllmain", entry, SectionRead | SectionExecute | 0x20u, {0xb8, 1, 0, 0, 0, 0xc3}});
|
||||
for (const auto slot : guest.InitArray) runtime.InitArrayRvas.push_back(image.GetRva(slot, 8));
|
||||
for (const auto slot : guest.FiniArray) runtime.FiniArrayRvas.push_back(image.GetRva(slot, 8));
|
||||
runtime.InitRva = guest.Init == 0 ? 0 : image.GetRva(guest.Init);
|
||||
runtime.FiniRva = guest.Fini == 0 ? 0 : image.GetRva(guest.Fini);
|
||||
auto result = WindowsPeWriter().Write(sections, entry, directories);
|
||||
|
||||
@@ -13,16 +13,26 @@ void WindowsGuestStartup::WriteImport(WindowsStubEmitter& code, const PeImport&
|
||||
code.Emit({0x4a, 0x89, 0x04, 0x02});
|
||||
}
|
||||
|
||||
void WindowsGuestStartup::callLifecycle(WindowsStubEmitter& code, const std::uint32_t handle, const std::uint32_t rva) const {
|
||||
void WindowsGuestStartup::callLifecycle(WindowsStubEmitter& code, const std::uint32_t handle, const std::uint32_t rva, const bool indirect) const {
|
||||
if (rva == 0) return;
|
||||
code.Rip({0x48, 0x8b, 0x05}, handle);
|
||||
code.Emit({0xb9});
|
||||
code.U32(rva);
|
||||
code.Emit({0x48, 0x01, 0xc8, 0x31, 0xff, 0x31, 0xf6, 0x31, 0xd2, 0xff, 0xd0});
|
||||
code.Emit({0x48, 0x01, 0xc8});
|
||||
if (indirect) {
|
||||
code.Emit({0x48, 0x8b, 0x00, 0x48, 0x85, 0xc0});
|
||||
const auto skip = code.Branch({0x0f, 0x84});
|
||||
code.Emit({0x31, 0xff, 0x31, 0xf6, 0x31, 0xd2, 0xff, 0xd0});
|
||||
code.PatchBranch(skip, code.GetRva());
|
||||
} else code.Emit({0x31, 0xff, 0x31, 0xf6, 0x31, 0xd2, 0xff, 0xd0});
|
||||
}
|
||||
|
||||
void WindowsGuestStartup::Initialize(WindowsStubEmitter& code, const std::vector<Domain::GuestRuntime>& modules, const std::uint32_t handles) const {
|
||||
for (std::size_t index = 0; index < modules.size(); ++index) callLifecycle(code, CheckedRva(handles + index * 8), modules[index].InitRva);
|
||||
for (std::size_t index = 0; index < modules.size(); ++index) {
|
||||
const auto handle = CheckedRva(handles + index * 8);
|
||||
callLifecycle(code, handle, modules[index].InitRva);
|
||||
for (const auto slot : modules[index].InitArrayRvas) callLifecycle(code, handle, slot, true);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowsGuestStartup::Finalize(WindowsStubEmitter& code, const std::vector<Domain::GuestRuntime>& modules, const std::uint32_t handles, const std::uint32_t finished) const {
|
||||
@@ -30,7 +40,12 @@ void WindowsGuestStartup::Finalize(WindowsStubEmitter& code, const std::vector<D
|
||||
code.Rip({0x87, 0x05}, finished);
|
||||
code.Emit({0x85, 0xc0});
|
||||
const auto skip = code.Branch({0x0f, 0x85});
|
||||
for (std::size_t index = modules.size(); index > 0; --index) callLifecycle(code, CheckedRva(handles + (index - 1) * 8), modules[index - 1].FiniRva);
|
||||
for (std::size_t index = modules.size(); index > 0; --index) {
|
||||
const auto handle = CheckedRva(handles + (index - 1) * 8);
|
||||
const auto& module = modules[index - 1];
|
||||
for (auto slot = module.FiniArrayRvas.rbegin(); slot != module.FiniArrayRvas.rend(); ++slot) callLifecycle(code, handle, *slot, true);
|
||||
callLifecycle(code, handle, module.FiniRva);
|
||||
}
|
||||
code.PatchBranch(skip, code.GetRva());
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace Elfpatcher::Windows {
|
||||
|
||||
WindowsImports WindowsImportBuilder::Build(const std::uint32_t sectionRva) const {
|
||||
const std::vector<std::string> names = {"ExitProcess", "FormatMessageA", "GetFileAttributesA", "GetLastError", "GetModuleFileNameA", "GetModuleHandleA", "GetProcAddress", "GetStdHandle", "GetSystemDirectoryA", "LoadLibraryExA", "RaiseException", "VirtualAlloc", "WriteFile", "lstrcatA", "lstrcmpA", "lstrcmpiA", "lstrcpyA", "lstrlenA"};
|
||||
const std::vector<std::string> names = {"ExitProcess", "FormatMessageA", "FreeLibrary", "GetCommandLineW", "GetFileAttributesA", "GetLastError", "GetModuleFileNameA", "GetModuleHandleA", "GetProcAddress", "GetStdHandle", "GetSystemDirectoryA", "LoadLibraryExA", "LocalFree", "RaiseException", "VirtualAlloc", "WideCharToMultiByte", "WriteFile", "lstrcatA", "lstrcmpA", "lstrcmpiA", "lstrcpyA", "lstrlenA"};
|
||||
WindowsImports result{{".idata", sectionRva, SectionRead | SectionWrite | 0x40u, std::vector<std::uint8_t>(40)}, {sectionRva, 40}, {}, {}};
|
||||
auto& bytes = result.Section.Data;
|
||||
const auto lookupOffset = bytes.size();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace Elfpatcher::Windows {
|
||||
|
||||
WindowsLoadImage::WindowsLoadImage(const std::vector<std::uint8_t>& source, const std::vector<Domain::ProgramHeader>& headers) {
|
||||
WindowsLoadImage::WindowsLoadImage(const std::vector<std::uint8_t>& source, const std::vector<Domain::ProgramHeader>& headers, const bool requireEntry) {
|
||||
if (source.size() < 64 || Io::ReadU32(source, 0) != 0x464c457f || source[4] != 2 || source[5] != 1 || source[6] != 1 || Io::ReadU16(source, 18) != 62)
|
||||
throw Domain::RelinkerException("Windows output requires a little-endian ELF64 x86-64 image");
|
||||
const auto type = Io::ReadU16(source, 16);
|
||||
@@ -50,6 +50,7 @@ WindowsLoadImage::WindowsLoadImage(const std::vector<std::uint8_t>& source, cons
|
||||
pageFlags[page] |= flags;
|
||||
}
|
||||
const auto entry = Io::ReadU64(source, 24);
|
||||
if (!requireEntry && entry == 0) return;
|
||||
entryRva = GetRva(entry);
|
||||
if ((pageFlags[(entryRva - LoadRva) / SectionAlignment] & SectionExecute) == 0)
|
||||
throw Domain::RelinkerException("ELF entry point is not executable", entry);
|
||||
|
||||
@@ -24,12 +24,15 @@ struct GuestSymbol {
|
||||
struct GuestImage {
|
||||
std::filesystem::path SourcePath;
|
||||
std::string OutputName;
|
||||
std::string Soname;
|
||||
std::vector<std::uint8_t> Bytes;
|
||||
std::vector<Codegen::TrampolineSite> Trampolines;
|
||||
std::vector<Domain::ProgramHeader> Headers;
|
||||
std::vector<GuestSymbol> Symbols;
|
||||
std::vector<std::string> Dependencies;
|
||||
Domain::SysVDynamicSection Dynamic;
|
||||
std::vector<std::uint64_t> InitArray;
|
||||
std::vector<std::uint64_t> FiniArray;
|
||||
std::uint64_t Init = 0;
|
||||
std::uint64_t Fini = 0;
|
||||
std::uint64_t Got = 0;
|
||||
|
||||
@@ -146,10 +146,14 @@ GuestImage GuestImageReader::Read(const std::filesystem::path& path, std::vector
|
||||
Io::AppendString(image.Dynamic.DynStrData, name);
|
||||
image.Symbols.push_back({name, info, visibility, section, value, size});
|
||||
}
|
||||
if (tags.contains(14)) {
|
||||
image.Soname = string(tags.at(14));
|
||||
if (image.Soname.empty() || image.Soname.find_first_of("\\:$\r\n") != std::string::npos) fail("Invalid guest SONAME: " + image.Soname);
|
||||
}
|
||||
std::set<std::string> dependencies;
|
||||
for (const auto offset : needed) {
|
||||
const auto name = string(offset);
|
||||
if (name.empty() || name.find_first_of("/\\:$") != std::string::npos || !dependencies.insert(name).second) fail("Invalid or duplicate dependency: " + name);
|
||||
if (name.empty() || name.find_first_of("\\:$\r\n") != std::string::npos || !dependencies.insert(name).second) fail("Invalid or duplicate dependency: " + name);
|
||||
image.Dependencies.push_back(name);
|
||||
}
|
||||
std::map<std::uint64_t, std::uint64_t> relocationTargets;
|
||||
@@ -192,7 +196,38 @@ GuestImage GuestImageReader::Read(const std::filesystem::path& path, std::vector
|
||||
if (tags.contains(13)) image.Fini = tags.at(13);
|
||||
if (image.Init != 0) mapped(image.Init, 1, 1);
|
||||
if (image.Fini != 0) mapped(image.Fini, 1, 1);
|
||||
if ((tags.contains(27) && tags.at(27) != 0) || (tags.contains(28) && tags.at(28) != 0)) fail("Separate guest INIT_ARRAY/FINI_ARRAY is not supported");
|
||||
const auto readLifecycleArray = [&](std::uint64_t addressTag, std::uint64_t sizeTag, std::vector<std::uint64_t>& entries) {
|
||||
if (!tags.contains(addressTag) && !tags.contains(sizeTag)) return;
|
||||
if (!tags.contains(sizeTag) || (tags.at(sizeTag) != 0 && !tags.contains(addressTag))) fail("Incomplete guest lifecycle array");
|
||||
const auto size = tags.at(sizeTag);
|
||||
if (size == 0) return;
|
||||
if (size % 8 != 0) fail("Unaligned guest lifecycle array size");
|
||||
const auto address = tags.at(addressTag);
|
||||
mapped(address, size, 4);
|
||||
const auto fileOffset = translate(address, size);
|
||||
for (std::uint64_t offset = 0; offset < size; offset += 8) {
|
||||
bool relocated = false;
|
||||
for (const auto* table : {&image.Dynamic.RelaData, &image.Dynamic.RelaPltData}) {
|
||||
for (std::size_t position = 0; position < table->size(); position += 24) {
|
||||
if (Io::ReadU64(*table, position) != address + offset) continue;
|
||||
relocated = true;
|
||||
const auto info = Io::ReadU64(*table, position + 8);
|
||||
const auto addend = Io::ReadU64(*table, position + 16);
|
||||
const auto type = static_cast<std::uint32_t>(info);
|
||||
if (type == 8) mapped(addend, 1, 1);
|
||||
else if (type == 1) {
|
||||
const auto& symbol = image.Symbols.at(info >> 32);
|
||||
if ((symbol.Info & 15) != 2 || addend != 0) fail("Invalid guest lifecycle function relocation");
|
||||
if (symbol.Section != 0) mapped(symbol.Value, 1, 1);
|
||||
} else fail("Unsupported guest lifecycle relocation");
|
||||
}
|
||||
}
|
||||
if (!relocated && Io::ReadU64(bytes, fileOffset + offset) != 0) fail("Unrelocated guest lifecycle pointer");
|
||||
entries.push_back(address + offset);
|
||||
}
|
||||
};
|
||||
readLifecycleArray(25, 27, image.InitArray);
|
||||
readLifecycleArray(26, 28, image.FiniArray);
|
||||
if (tags.contains(33) && tags.at(33) != 0 && image.Init == 0) fail("Guest PREINIT_ARRAY has no module initializer");
|
||||
image.Bytes = std::move(bytes);
|
||||
return image;
|
||||
|
||||
@@ -71,9 +71,21 @@ std::vector<GuestArtifact> GuestModuleBuilder::Build(const std::filesystem::path
|
||||
}
|
||||
images.push_back(std::move(image));
|
||||
}
|
||||
std::map<std::string, std::size_t> guestNames;
|
||||
for (std::size_t index = 0; index < images.size(); ++index) {
|
||||
for (const auto& name : {images[index].SourcePath.filename().string(), images[index].Soname}) {
|
||||
if (name.empty()) continue;
|
||||
const auto [found, inserted] = guestNames.emplace(name, index);
|
||||
if (!inserted && found->second != index) throw Domain::RelinkerException("Ambiguous guest dependency name: " + name);
|
||||
}
|
||||
}
|
||||
std::vector<std::set<std::size_t>> dependencies(images.size());
|
||||
for (auto& image : images) image.UsePlatformTlsResolver = !exports.contains("vNe1w4diLCs");
|
||||
for (std::size_t index = 0; index < images.size(); ++index) {
|
||||
for (const auto& name : images[index].Dependencies) {
|
||||
const auto found = guestNames.find(name);
|
||||
if (found != guestNames.end() && found->second != index) dependencies[index].insert(found->second);
|
||||
}
|
||||
for (const auto& symbol : images[index].Symbols) {
|
||||
if (symbol.Section != 0 || symbol.Name.empty()) continue;
|
||||
const auto found = exports.find(symbol.Name);
|
||||
@@ -99,6 +111,7 @@ std::vector<GuestArtifact> GuestModuleBuilder::Build(const std::filesystem::path
|
||||
std::vector<std::string> hostLibraries;
|
||||
std::set<std::string> uniqueHosts;
|
||||
const auto addHost = [&](const std::string& name) {
|
||||
if (guestNames.contains(name)) return;
|
||||
if (name.empty() || name.find_first_of("/\\:$") != std::string::npos) throw Domain::RelinkerException("Invalid host dependency: " + name);
|
||||
if (uniqueHosts.insert(name).second) hostLibraries.push_back(name);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user