1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00
rpcs3/Utilities/File.cpp

2588 lines
53 KiB
C++
Raw Normal View History

#include "File.h"
#include "mutex.h"
2016-02-01 22:55:43 +01:00
#include "StrFmt.h"
2024-01-13 15:42:49 +01:00
#include "StrUtil.h"
2016-07-11 21:00:12 +02:00
#include "Crypto/sha1.h"
2016-02-01 22:55:43 +01:00
#include <unordered_map>
#include <algorithm>
2017-04-16 03:31:58 +02:00
#include <cstring>
2018-08-13 00:06:03 +02:00
#include <map>
#include <iostream>
2014-07-11 19:06:59 +02:00
#include "util/asm.hpp"
#include "util/coro.hpp"
2017-04-16 03:31:58 +02:00
using namespace std::literals::string_literals;
2014-07-11 19:06:59 +02:00
#ifdef _WIN32
2016-01-06 00:52:48 +01:00
#include <cwchar>
#include <Windows.h>
2015-04-15 16:27:37 +02:00
static std::unique_ptr<wchar_t[]> to_wchar(const std::string& source)
2015-04-13 20:10:31 +02:00
{
2016-08-14 19:22:07 +02:00
// String size + null terminator
2020-12-18 08:39:54 +01:00
const usz buf_size = source.size() + 1;
2015-04-15 16:27:37 +02:00
2016-08-14 19:22:07 +02:00
// Safe size
const int size = narrow<int>(buf_size);
2015-04-15 16:27:37 +02:00
2016-08-14 19:22:07 +02:00
// Buffer for max possible output length
std::unique_ptr<wchar_t[]> buffer(new wchar_t[buf_size + 8 + 32768]);
2015-04-15 16:27:37 +02:00
// Prepend wide path prefix (4 characters)
std::memcpy(buffer.get() + 32768, L"\\\\\?\\", 4 * sizeof(wchar_t));
// Test whether additional UNC prefix is required
const bool unc = source.size() > 2 && (source[0] == '\\' || source[0] == '/') && source[1] == source[0];
if (unc)
{
// Use \\?\UNC\ prefix
std::memcpy(buffer.get() + 32768 + 4, L"UNC\\", 4 * sizeof(wchar_t));
}
ensure(MultiByteToWideChar(CP_UTF8, 0, source.c_str(), size, buffer.get() + 32768 + (unc ? 8 : 4), size)); // "to_wchar"
// Canonicalize wide path (replace '/', ".", "..", \\ repetitions, etc)
ensure(GetFullPathNameW(buffer.get() + 32768, 32768, buffer.get(), nullptr) - 1 < 32768 - 1); // "to_wchar"
2015-04-15 16:27:37 +02:00
return buffer;
}
static time_t to_time(const ULARGE_INTEGER& ft)
2015-04-19 19:57:04 +02:00
{
return ft.QuadPart / 10000000ULL - 11644473600ULL;
}
static time_t to_time(const LARGE_INTEGER& ft)
2015-04-19 21:25:04 +02:00
{
ULARGE_INTEGER v;
v.LowPart = ft.LowPart;
v.HighPart = ft.HighPart;
return to_time(v);
2015-04-19 21:25:04 +02:00
}
static time_t to_time(const FILETIME& ft)
2015-04-15 16:27:37 +02:00
{
2015-04-19 21:25:04 +02:00
ULARGE_INTEGER v;
2015-04-15 16:27:37 +02:00
v.LowPart = ft.dwLowDateTime;
v.HighPart = ft.dwHighDateTime;
return to_time(v);
2014-07-11 19:06:59 +02:00
}
2015-04-15 16:27:37 +02:00
2017-01-26 13:01:21 +01:00
static FILETIME from_time(s64 _time)
{
FILETIME result;
2017-11-23 20:18:38 +01:00
if (_time <= -11644473600ll)
{
result.dwLowDateTime = 0;
result.dwHighDateTime = 0;
}
else if (_time > s64{smax} / 10000000ll - 11644473600ll)
2017-11-23 20:18:38 +01:00
{
result.dwLowDateTime = 0xffffffff;
result.dwHighDateTime = 0x7fffffff;
}
else
{
const ullong wtime = (_time + 11644473600ull) * 10000000ull;
result.dwLowDateTime = static_cast<DWORD>(wtime);
result.dwHighDateTime = static_cast<DWORD>(wtime >> 32);
}
2017-01-26 13:01:21 +01:00
return result;
}
2016-05-13 16:01:48 +02:00
static fs::error to_error(DWORD e)
{
switch (e)
{
case ERROR_FILE_NOT_FOUND: return fs::error::noent;
case ERROR_PATH_NOT_FOUND: return fs::error::noent;
2017-02-12 00:52:20 +01:00
case ERROR_ACCESS_DENIED: return fs::error::acces;
2016-05-13 16:01:48 +02:00
case ERROR_ALREADY_EXISTS: return fs::error::exist;
case ERROR_FILE_EXISTS: return fs::error::exist;
case ERROR_NEGATIVE_SEEK: return fs::error::inval;
2016-06-02 17:16:01 +02:00
case ERROR_DIRECTORY: return fs::error::inval;
case ERROR_INVALID_NAME: return fs::error::inval;
2017-08-27 15:09:34 +02:00
case ERROR_SHARING_VIOLATION: return fs::error::acces;
2017-09-12 19:05:38 +02:00
case ERROR_DIR_NOT_EMPTY: return fs::error::notempty;
case ERROR_NOT_READY: return fs::error::noent;
case ERROR_FILENAME_EXCED_RANGE: return fs::error::toolong;
2020-05-02 08:04:05 +02:00
case ERROR_DISK_FULL: return fs::error::nospace;
2023-07-21 11:06:46 +02:00
case ERROR_NOT_SAME_DEVICE: return fs::error::xdev;
2020-03-07 09:18:23 +01:00
default: return fs::error::unknown;
2016-05-13 16:01:48 +02:00
}
}
2015-04-13 16:46:10 +02:00
#else
2016-01-06 00:52:48 +01:00
#include <sys/mman.h>
2015-04-19 18:02:35 +02:00
#include <sys/stat.h>
#include <sys/types.h>
2017-04-24 17:45:58 +02:00
#include <sys/statvfs.h>
2017-11-19 14:44:06 +01:00
#include <sys/file.h>
#include <sys/uio.h>
2015-04-25 22:21:06 +02:00
#include <dirent.h>
2015-04-13 16:46:10 +02:00
#include <fcntl.h>
#include <libgen.h>
#include <string.h>
2015-04-13 16:46:10 +02:00
#include <unistd.h>
2017-01-26 13:01:21 +01:00
#include <utime.h>
2016-01-06 00:52:48 +01:00
Improve portability for BSDs (#2813) * sys_net: don't use fds_bits from a system header on FreeBSD rpcs3/Emu/Cell/Modules/sys_net.cpp:137:14: error: no member named '__fds_bits' in 'sys_net::fd_set'; did you mean 'fds_bits'? if (src->fds_bits[i] & (1 << bit)) ^~~~~~~~ fds_bits /usr/include/sys/select.h:75:18: note: expanded from macro 'fds_bits' #define fds_bits __fds_bits ^ rpcs3/Emu/Cell/Modules/sys_net.h:114:13: note: 'fds_bits' declared here be_t<u32> fds_bits[32]; ^ * GUI: fallback to xdg-open on other Unices rpcs3/Gui/GameViewer.cpp:289:26: error: use of undeclared identifier 'command' wxExecute(fmt::FromUTF8(command)); ^ * File: FreeBSD never supported copyfile(3) but sendfile(2) works fine Utilities/File.cpp:114:10: fatal error: 'copyfile.h' file not found #include <copyfile.h> ^~~~~~~~~~~~ * Thread: add signal handling for BSDs Utilities/Thread.cpp:761:23: error: use of undeclared identifier 'REG_RAX' static const decltype(REG_RAX) reg_table[] = ^ Utilities/Thread.cpp:763:2: error: use of undeclared identifier 'REG_RAX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:11: error: use of undeclared identifier 'REG_RCX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:20: error: use of undeclared identifier 'REG_RDX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:29: error: use of undeclared identifier 'REG_RBX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:38: error: use of undeclared identifier 'REG_RSP' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:47: error: use of undeclared identifier 'REG_RBP' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:56: error: use of undeclared identifier 'REG_RSI' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:65: error: use of undeclared identifier 'REG_RDI' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:764:2: error: use of undeclared identifier 'REG_R8' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:10: error: use of undeclared identifier 'REG_R9' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:18: error: use of undeclared identifier 'REG_R10' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:27: error: use of undeclared identifier 'REG_R11' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:36: error: use of undeclared identifier 'REG_R12' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:45: error: use of undeclared identifier 'REG_R13' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:54: error: use of undeclared identifier 'REG_R14' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:63: error: use of undeclared identifier 'REG_R15' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:72: error: use of undeclared identifier 'REG_RIP' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:792:26: error: no member named 'gregs' in '__mcontext' const u64 reg_value = *X64REG(context, reg - X64R_RAX); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:804:21: error: no member named 'gregs' in '__mcontext' out_value = (u8)(*X64REG(context, reg - X64R_AL)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:809:21: error: no member named 'gregs' in '__mcontext' out_value = (u8)(*X64REG(context, reg - X64R_AH) >> 8); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:815:31: error: no member named 'gregs' in '__mcontext' const s8 imm_value = *(s8*)(RIP(context) + i_size - 1); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:827:33: error: no member named 'gregs' in '__mcontext' const s16 imm_value = *(s16*)(RIP(context) + i_size - 2); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:836:33: error: no member named 'gregs' in '__mcontext' const s32 imm_value = *(s32*)(RIP(context) + i_size - 4); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:846:20: error: no member named 'gregs' in '__mcontext' out_value = (u32)RCX(context); ^~~~~~~~~~~~ Utilities/Thread.cpp:779:18: note: expanded from macro 'RCX' #define RCX(c) (*X64REG((c), 1)) ^~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:851:19: error: no member named 'gregs' in '__mcontext' const u32 _cf = EFLAGS(context) & 0x1; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:851:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:852:19: error: no member named 'gregs' in '__mcontext' const u32 _zf = EFLAGS(context) & 0x40; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:852:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:853:19: error: no member named 'gregs' in '__mcontext' const u32 _sf = EFLAGS(context) & 0x80; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:853:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:854:19: error: no member named 'gregs' in '__mcontext' const u32 _of = EFLAGS(context) & 0x800; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:854:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:855:19: error: no member named 'gregs' in '__mcontext' const u32 _pf = EFLAGS(context) & 0x4; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:855:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:885:12: error: no member named 'gregs' in '__mcontext' case 1: *X64REG(context, reg - X64R_RAX) = value & 0xff | *X64REG(context, re... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:885:62: error: no member named 'gregs' in '__mcontext' ...*X64REG(context, reg - X64R_RAX) = value & 0xff | *X64REG(context, reg - X64R_RAX) & 0xffffff... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:886:12: error: no member named 'gregs' in '__mcontext' case 2: *X64REG(context, reg - X64R_RAX) = value & 0xffff | *X64REG(context, ... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:886:64: error: no member named 'gregs' in '__mcontext' ...reg - X64R_RAX) = value & 0xffff | *X64REG(context, reg - X64R_RAX) & 0xffff0000; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:887:12: error: no member named 'gregs' in '__mcontext' case 4: *X64REG(context, reg - X64R_RAX) = value & 0xffffffff; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:888:12: error: no member named 'gregs' in '__mcontext' case 8: *X64REG(context, reg - X64R_RAX) = value; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:913:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x1; // set CF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:913:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:917:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x1; // clear CF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:917:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:922:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x40; // set ZF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:922:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:926:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x40; // clear ZF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:926:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:931:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x80; // set SF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:931:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:935:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x80; // clear SF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:935:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:940:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x800; // set OF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:940:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:944:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x800; // clear OF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:944:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:953:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x4; // set PF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:953:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:957:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x4; // clear PF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:957:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:962:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x10; // set AF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:962:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:966:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x10; // clear AF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:966:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:976:7: error: no member named 'gregs' in '__mcontext' if (EFLAGS(context) & 0x400 /* direction flag */) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:976:7: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:1020:25: error: no member named 'gregs' in '__mcontext' auto code = (const u8*)RIP(context); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1146:3: error: no member named 'gregs' in '__mcontext' RIP(context) += i_size; ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1368:47: error: no member named 'gregs' in '__mcontext' const bool is_writing = context->uc_mcontext.gregs[REG_ERR] & 0x2; ~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1368:53: error: use of undeclared identifier 'REG_ERR' const bool is_writing = context->uc_mcontext.gregs[REG_ERR] & 0x2; ^ Utilities/Thread.cpp:1393:89: error: no member named 'gregs' in '__mcontext' ...%s location %p at %p.", cause, info->si_addr, RIP(context))); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ * Thread: add explict casts for incomplete pthread_t on some platforms Utilities/Thread.cpp:1467:17: error: no viable overloaded '=' ctrl->m_thread = thread; ~~~~~~~~~~~~~~ ^ ~~~~~~ Utilities/Atomic.h:776:12: note: candidate function not viable: cannot convert argument of incomplete type 'pthread_t' (aka 'pthread *') to 'const atomic_t<unsigned long>' for 1st argument atomic_t& operator =(const atomic_t&) = delete; ^ Utilities/Atomic.h:902:7: note: candidate function not viable: cannot convert argument of incomplete type 'pthread_t' (aka 'pthread *') to 'const type' (aka 'const unsigned long') for 1st argument type operator =(const type& rhs) ^ Utilities/Thread.cpp:1656:3: error: no matching function for call to 'pthread_detach' pthread_detach(m_thread.raw()); ^~~~~~~~~~~~~~ /usr/include/pthread.h:218:6: note: candidate function not viable: no known conversion from 'type' (aka 'unsigned long') to 'pthread_t' (aka 'pthread *') for 1st argument int pthread_detach(pthread_t); ^ * build: dlopen() maybe in libc /usr/bin/ld: cannot find -ldl c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: iconv() maybe available on some BSDs in libc /usr/bin/ld: cannot find -liconv c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: hidapi-hidraw is only built on Linux /usr/bin/ld: cannot find -lhidapi-hidraw c++: error: linker command failed with exit code 1 (use -v to see invocation) * Thread: use getrusage() on more POSIX-like systems * Qt: don't return NULL handle on other platforms rpcs3/rpcs3qt/gs_frame.cpp:120:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ * build: properly disable Vulkan on other platforms In file included from rpcs3/rpcs3_app.cpp:40: In file included from rpcs3/Emu/RSX/VK/VKGSRender.h:3: rpcs3/Emu/RSX/VK/VKHelpers.h:1209:42: error: unknown type name 'device_queues' std::vector<VkBool32> supportsPresent(device_queues); ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1211:4: error: expected member name or ';' after declaration specifiers for (u32 index = 0; index < device_queues; index++) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1221:4: error: expected member name or ';' after declaration specifiers for (u32 i = 0; i < device_queues; i++) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1256:4: error: expected member name or ';' after declaration specifiers if (graphicsQueueNodeIndex != presentQueueNodeIndex) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1261:4: error: expected member name or ';' after declaration specifiers CHECK_RESULT(vkGetPhysicalDeviceSurfaceFormatsKHR(dev, surface, &formatCount, nullptr)); ^ [...] /usr/bin/ld: cannot find -lvulkan c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: make install/strip work by moving commands * Qt: create surface for GL context if it wasn't ready #0 strlen (str=0x0) at /usr/src/lib/libc/string/strlen.c:100 #1 0x000000000090f02e in std::__1::char_traits<char>::length (__s=0x0) at /usr/include/c++/v1/__string:215 #2 std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string (__s=0x0, this=<optimized out>) at /usr/include/c++/v1/string:1547 #3 gl::capabilities::initialize (this=0x2ba32a0 <gl::g_driver_caps>) at rpcs3/Emu/RSX/GL/GLHelpers.h:133 #4 0x000000000090d3dd in gl::get_driver_caps () at rpcs3/Emu/RSX/GL/GLHelpers.cpp:56 #5 0x00000000008fa511 in GLGSRender::on_init_thread (this=0x838d30018) at rpcs3/Emu/RSX/GL/GLGSRender.cpp:484 #6 0x0000000000938f9e in rsx::thread::on_task (this=0x838d30018) at rpcs3/Emu/RSX/RSXThread.cpp:334 #7 0x0000000000abc329 in task_stack::task_type<named_thread::start_thread(std::__1::shared_ptr<void> const&)::$_10>::invoke() () #8 0x0000000000abc114 in thread_ctrl::start(std::__1::shared_ptr<thread_ctrl> const&, task_stack)::$_7::__invoke(void*) () #9 0x0000000801e60c35 in thread_start (curthread=0x843650a00) at /usr/src/lib/libthr/thread/thr_create.c:289 #10 0x0000000000000000 in ?? () * build: don't abort without git metadata -- Found Git: /usr/local/bin/git (found version "2.13.1") fatal: Not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). CMake Warning at git-version.cmake:12 (message): git rev-list failed, unable to include version. * build: non-parallel needs git-version.h earlier rpcs3/rpcs3_version.cpp:3:10: fatal error: 'git-version.h' file not found #include "git-version.h" ^~~~~~~~~~~~~~~ 1 error generated.
2017-06-22 20:03:41 +02:00
#if defined(__APPLE__)
2015-04-13 16:46:10 +02:00
#include <copyfile.h>
#include <mach-o/dyld.h>
#include <limits.h>
Improve portability for BSDs (#2813) * sys_net: don't use fds_bits from a system header on FreeBSD rpcs3/Emu/Cell/Modules/sys_net.cpp:137:14: error: no member named '__fds_bits' in 'sys_net::fd_set'; did you mean 'fds_bits'? if (src->fds_bits[i] & (1 << bit)) ^~~~~~~~ fds_bits /usr/include/sys/select.h:75:18: note: expanded from macro 'fds_bits' #define fds_bits __fds_bits ^ rpcs3/Emu/Cell/Modules/sys_net.h:114:13: note: 'fds_bits' declared here be_t<u32> fds_bits[32]; ^ * GUI: fallback to xdg-open on other Unices rpcs3/Gui/GameViewer.cpp:289:26: error: use of undeclared identifier 'command' wxExecute(fmt::FromUTF8(command)); ^ * File: FreeBSD never supported copyfile(3) but sendfile(2) works fine Utilities/File.cpp:114:10: fatal error: 'copyfile.h' file not found #include <copyfile.h> ^~~~~~~~~~~~ * Thread: add signal handling for BSDs Utilities/Thread.cpp:761:23: error: use of undeclared identifier 'REG_RAX' static const decltype(REG_RAX) reg_table[] = ^ Utilities/Thread.cpp:763:2: error: use of undeclared identifier 'REG_RAX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:11: error: use of undeclared identifier 'REG_RCX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:20: error: use of undeclared identifier 'REG_RDX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:29: error: use of undeclared identifier 'REG_RBX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:38: error: use of undeclared identifier 'REG_RSP' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:47: error: use of undeclared identifier 'REG_RBP' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:56: error: use of undeclared identifier 'REG_RSI' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:65: error: use of undeclared identifier 'REG_RDI' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:764:2: error: use of undeclared identifier 'REG_R8' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:10: error: use of undeclared identifier 'REG_R9' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:18: error: use of undeclared identifier 'REG_R10' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:27: error: use of undeclared identifier 'REG_R11' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:36: error: use of undeclared identifier 'REG_R12' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:45: error: use of undeclared identifier 'REG_R13' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:54: error: use of undeclared identifier 'REG_R14' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:63: error: use of undeclared identifier 'REG_R15' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:72: error: use of undeclared identifier 'REG_RIP' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:792:26: error: no member named 'gregs' in '__mcontext' const u64 reg_value = *X64REG(context, reg - X64R_RAX); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:804:21: error: no member named 'gregs' in '__mcontext' out_value = (u8)(*X64REG(context, reg - X64R_AL)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:809:21: error: no member named 'gregs' in '__mcontext' out_value = (u8)(*X64REG(context, reg - X64R_AH) >> 8); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:815:31: error: no member named 'gregs' in '__mcontext' const s8 imm_value = *(s8*)(RIP(context) + i_size - 1); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:827:33: error: no member named 'gregs' in '__mcontext' const s16 imm_value = *(s16*)(RIP(context) + i_size - 2); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:836:33: error: no member named 'gregs' in '__mcontext' const s32 imm_value = *(s32*)(RIP(context) + i_size - 4); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:846:20: error: no member named 'gregs' in '__mcontext' out_value = (u32)RCX(context); ^~~~~~~~~~~~ Utilities/Thread.cpp:779:18: note: expanded from macro 'RCX' #define RCX(c) (*X64REG((c), 1)) ^~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:851:19: error: no member named 'gregs' in '__mcontext' const u32 _cf = EFLAGS(context) & 0x1; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:851:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:852:19: error: no member named 'gregs' in '__mcontext' const u32 _zf = EFLAGS(context) & 0x40; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:852:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:853:19: error: no member named 'gregs' in '__mcontext' const u32 _sf = EFLAGS(context) & 0x80; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:853:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:854:19: error: no member named 'gregs' in '__mcontext' const u32 _of = EFLAGS(context) & 0x800; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:854:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:855:19: error: no member named 'gregs' in '__mcontext' const u32 _pf = EFLAGS(context) & 0x4; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:855:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:885:12: error: no member named 'gregs' in '__mcontext' case 1: *X64REG(context, reg - X64R_RAX) = value & 0xff | *X64REG(context, re... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:885:62: error: no member named 'gregs' in '__mcontext' ...*X64REG(context, reg - X64R_RAX) = value & 0xff | *X64REG(context, reg - X64R_RAX) & 0xffffff... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:886:12: error: no member named 'gregs' in '__mcontext' case 2: *X64REG(context, reg - X64R_RAX) = value & 0xffff | *X64REG(context, ... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:886:64: error: no member named 'gregs' in '__mcontext' ...reg - X64R_RAX) = value & 0xffff | *X64REG(context, reg - X64R_RAX) & 0xffff0000; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:887:12: error: no member named 'gregs' in '__mcontext' case 4: *X64REG(context, reg - X64R_RAX) = value & 0xffffffff; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:888:12: error: no member named 'gregs' in '__mcontext' case 8: *X64REG(context, reg - X64R_RAX) = value; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:913:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x1; // set CF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:913:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:917:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x1; // clear CF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:917:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:922:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x40; // set ZF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:922:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:926:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x40; // clear ZF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:926:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:931:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x80; // set SF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:931:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:935:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x80; // clear SF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:935:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:940:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x800; // set OF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:940:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:944:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x800; // clear OF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:944:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:953:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x4; // set PF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:953:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:957:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x4; // clear PF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:957:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:962:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x10; // set AF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:962:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:966:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x10; // clear AF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:966:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:976:7: error: no member named 'gregs' in '__mcontext' if (EFLAGS(context) & 0x400 /* direction flag */) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:976:7: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:1020:25: error: no member named 'gregs' in '__mcontext' auto code = (const u8*)RIP(context); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1146:3: error: no member named 'gregs' in '__mcontext' RIP(context) += i_size; ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1368:47: error: no member named 'gregs' in '__mcontext' const bool is_writing = context->uc_mcontext.gregs[REG_ERR] & 0x2; ~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1368:53: error: use of undeclared identifier 'REG_ERR' const bool is_writing = context->uc_mcontext.gregs[REG_ERR] & 0x2; ^ Utilities/Thread.cpp:1393:89: error: no member named 'gregs' in '__mcontext' ...%s location %p at %p.", cause, info->si_addr, RIP(context))); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ * Thread: add explict casts for incomplete pthread_t on some platforms Utilities/Thread.cpp:1467:17: error: no viable overloaded '=' ctrl->m_thread = thread; ~~~~~~~~~~~~~~ ^ ~~~~~~ Utilities/Atomic.h:776:12: note: candidate function not viable: cannot convert argument of incomplete type 'pthread_t' (aka 'pthread *') to 'const atomic_t<unsigned long>' for 1st argument atomic_t& operator =(const atomic_t&) = delete; ^ Utilities/Atomic.h:902:7: note: candidate function not viable: cannot convert argument of incomplete type 'pthread_t' (aka 'pthread *') to 'const type' (aka 'const unsigned long') for 1st argument type operator =(const type& rhs) ^ Utilities/Thread.cpp:1656:3: error: no matching function for call to 'pthread_detach' pthread_detach(m_thread.raw()); ^~~~~~~~~~~~~~ /usr/include/pthread.h:218:6: note: candidate function not viable: no known conversion from 'type' (aka 'unsigned long') to 'pthread_t' (aka 'pthread *') for 1st argument int pthread_detach(pthread_t); ^ * build: dlopen() maybe in libc /usr/bin/ld: cannot find -ldl c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: iconv() maybe available on some BSDs in libc /usr/bin/ld: cannot find -liconv c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: hidapi-hidraw is only built on Linux /usr/bin/ld: cannot find -lhidapi-hidraw c++: error: linker command failed with exit code 1 (use -v to see invocation) * Thread: use getrusage() on more POSIX-like systems * Qt: don't return NULL handle on other platforms rpcs3/rpcs3qt/gs_frame.cpp:120:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ * build: properly disable Vulkan on other platforms In file included from rpcs3/rpcs3_app.cpp:40: In file included from rpcs3/Emu/RSX/VK/VKGSRender.h:3: rpcs3/Emu/RSX/VK/VKHelpers.h:1209:42: error: unknown type name 'device_queues' std::vector<VkBool32> supportsPresent(device_queues); ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1211:4: error: expected member name or ';' after declaration specifiers for (u32 index = 0; index < device_queues; index++) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1221:4: error: expected member name or ';' after declaration specifiers for (u32 i = 0; i < device_queues; i++) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1256:4: error: expected member name or ';' after declaration specifiers if (graphicsQueueNodeIndex != presentQueueNodeIndex) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1261:4: error: expected member name or ';' after declaration specifiers CHECK_RESULT(vkGetPhysicalDeviceSurfaceFormatsKHR(dev, surface, &formatCount, nullptr)); ^ [...] /usr/bin/ld: cannot find -lvulkan c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: make install/strip work by moving commands * Qt: create surface for GL context if it wasn't ready #0 strlen (str=0x0) at /usr/src/lib/libc/string/strlen.c:100 #1 0x000000000090f02e in std::__1::char_traits<char>::length (__s=0x0) at /usr/include/c++/v1/__string:215 #2 std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string (__s=0x0, this=<optimized out>) at /usr/include/c++/v1/string:1547 #3 gl::capabilities::initialize (this=0x2ba32a0 <gl::g_driver_caps>) at rpcs3/Emu/RSX/GL/GLHelpers.h:133 #4 0x000000000090d3dd in gl::get_driver_caps () at rpcs3/Emu/RSX/GL/GLHelpers.cpp:56 #5 0x00000000008fa511 in GLGSRender::on_init_thread (this=0x838d30018) at rpcs3/Emu/RSX/GL/GLGSRender.cpp:484 #6 0x0000000000938f9e in rsx::thread::on_task (this=0x838d30018) at rpcs3/Emu/RSX/RSXThread.cpp:334 #7 0x0000000000abc329 in task_stack::task_type<named_thread::start_thread(std::__1::shared_ptr<void> const&)::$_10>::invoke() () #8 0x0000000000abc114 in thread_ctrl::start(std::__1::shared_ptr<thread_ctrl> const&, task_stack)::$_7::__invoke(void*) () #9 0x0000000801e60c35 in thread_start (curthread=0x843650a00) at /usr/src/lib/libthr/thread/thr_create.c:289 #10 0x0000000000000000 in ?? () * build: don't abort without git metadata -- Found Git: /usr/local/bin/git (found version "2.13.1") fatal: Not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). CMake Warning at git-version.cmake:12 (message): git rev-list failed, unable to include version. * build: non-parallel needs git-version.h earlier rpcs3/rpcs3_version.cpp:3:10: fatal error: 'git-version.h' file not found #include "git-version.h" ^~~~~~~~~~~~~~~ 1 error generated.
2017-06-22 20:03:41 +02:00
#elif defined(__linux__) || defined(__sun)
2015-04-13 16:46:10 +02:00
#include <sys/sendfile.h>
2019-04-13 12:46:56 +02:00
#include <sys/syscall.h>
#include <linux/fs.h>
#else
#include <fstream>
2015-04-13 16:46:10 +02:00
#endif
2016-05-13 16:01:48 +02:00
static fs::error to_error(int e)
{
switch (e)
{
case ENOENT: return fs::error::noent;
case EEXIST: return fs::error::exist;
case EINVAL: return fs::error::inval;
2017-02-12 00:52:20 +01:00
case EACCES: return fs::error::acces;
2017-09-12 19:05:38 +02:00
case ENOTEMPTY: return fs::error::notempty;
2019-09-02 04:50:44 +02:00
case EROFS: return fs::error::readonly;
case EISDIR: return fs::error::isdir;
2020-05-02 08:04:05 +02:00
case ENOSPC: return fs::error::nospace;
2023-07-21 11:06:46 +02:00
case EXDEV: return fs::error::xdev;
2020-03-07 09:18:23 +01:00
default: return fs::error::unknown;
2016-05-13 16:01:48 +02:00
}
}
2016-01-06 00:52:48 +01:00
#endif
static std::string path_append(std::string_view path, std::string_view more)
{
std::string result;
2020-12-18 08:39:54 +01:00
if (const usz src_slash_pos = path.find_last_not_of('/'); src_slash_pos != path.npos)
{
path.remove_suffix(path.length() - src_slash_pos - 1);
result = path;
}
result.push_back('/');
2020-12-18 08:39:54 +01:00
if (const usz dst_slash_pos = more.find_first_not_of('/'); dst_slash_pos != more.npos)
{
more.remove_prefix(dst_slash_pos);
result.append(more);
}
return result;
}
2016-02-01 22:55:43 +01:00
namespace fs
{
2016-05-13 16:01:48 +02:00
thread_local error g_tls_error = error::ok;
2016-02-01 22:55:43 +01:00
class device_manager final
{
2021-03-30 17:31:46 +02:00
mutable shared_mutex m_mutex{};
2016-02-01 22:55:43 +01:00
std::unordered_map<std::string, shared_ptr<device_base>> m_map{};
2016-02-01 22:55:43 +01:00
public:
shared_ptr<device_base> get_device(const std::string& path);
shared_ptr<device_base> set_device(const std::string& name, shared_ptr<device_base>);
2016-02-01 22:55:43 +01:00
};
static device_manager& get_device_manager()
{
// Use magic static
static device_manager instance;
return instance;
}
2017-01-25 00:22:19 +01:00
file_base::~file_base()
{
}
2023-12-29 18:33:29 +01:00
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4646)
#endif
[[noreturn]] stat_t file_base::get_stat()
{
fmt::throw_exception("fs::file::get_stat() not supported.");
}
2023-12-29 18:33:29 +01:00
#ifdef _MSC_VER
#pragma warning(pop)
#endif
void file_base::sync()
{
// Do notning
}
2019-04-13 12:46:56 +02:00
fs::native_handle fs::file_base::get_handle()
{
#ifdef _WIN32
return INVALID_HANDLE_VALUE;
#else
return -1;
#endif
}
file_id file_base::get_id()
{
return {};
}
u64 file_base::write_gather(const iovec_clone* buffers, u64 buf_count)
{
u64 total = 0;
for (u64 i = 0; i < buf_count; i++)
{
if (!buffers[i].iov_base || buffers[i].iov_len + total < total)
{
g_tls_error = error::inval;
return -1;
}
total += buffers[i].iov_len;
}
2019-06-04 18:13:30 +02:00
const auto buf = std::make_unique<uchar[]>(total);
u64 copied = 0;
for (u64 i = 0; i < buf_count; i++)
{
std::memcpy(buf.get() + copied, buffers[i].iov_base, buffers[i].iov_len);
copied += buffers[i].iov_len;
}
return this->write(buf.get(), total);
}
file_id::operator bool() const
{
return !type.empty() && !data.empty();
}
// Test if identical
// For example: when LHS writes one byte to a file at X offset, RHS file be able to read that exact byte at X offset)
bool file_id::is_mirror_of(const file_id& rhs) const
{
// If either is an invalid ID we cannot compare safely, return false
return rhs && type == rhs.type && data == rhs.data;
}
// Test if both files point to the same file
// For example: if a file descriptor pointing to the complete file exists and is being truncated to 0 bytes from non-
// -zero size state: this has to affect both RHS and LHS files.
bool file_id::is_coherent_with(const file_id& rhs) const
{
struct id_view
{
std::string_view type_view;
std::basic_string_view<u8> data_view;
};
id_view _rhs{rhs.type, {rhs.data.data(), rhs.data.size()}};
id_view _lhs{type, {data.data(), data.size()}};
// Peek through fs::file wrappers
auto peek_wrapppers = [](id_view& id)
{
u64 offset_count = 0;
constexpr auto lv2_view = "lv2_file::file_view: "sv;
for (usz pos = 0; (pos = id.type_view.find(lv2_view, pos)) != umax; pos += lv2_view.size())
{
offset_count++;
}
// Remove offsets data
id.data_view.remove_suffix(sizeof(u64) * offset_count);
// Get last category identifier
if (usz sep = id.type_view.rfind(": "); sep != umax)
{
id.type_view.remove_prefix(sep + 2);
}
};
peek_wrapppers(_rhs);
peek_wrapppers(_lhs);
// If either is an invalid ID we cannot compare safely, return false
if (_rhs.type_view.empty() || _rhs.data_view.empty())
{
return false;
}
return _rhs.type_view == _lhs.type_view && _rhs.data_view == _lhs.data_view;
}
2017-01-25 00:22:19 +01:00
dir_base::~dir_base()
{
}
device_base::device_base()
: fs_prefix(fmt::format("/vfsv0_%s%s_", fmt::base57(reinterpret_cast<u64>(this)), fmt::base57(utils::get_unique_tsc())))
{
}
2017-01-25 00:22:19 +01:00
device_base::~device_base()
{
}
bool device_base::remove_dir(const std::string&)
{
g_tls_error = error::readonly;
return false;
}
bool device_base::create_dir(const std::string&)
{
g_tls_error = error::readonly;
return false;
}
bool device_base::create_symlink(const std::string&)
{
g_tls_error = error::readonly;
return false;
}
bool device_base::rename(const std::string&, const std::string&)
{
g_tls_error = error::readonly;
return false;
}
bool device_base::remove(const std::string&)
{
g_tls_error = error::readonly;
return false;
}
bool device_base::trunc(const std::string&, u64)
{
g_tls_error = error::readonly;
return false;
}
bool device_base::utime(const std::string&, s64, s64)
{
g_tls_error = error::readonly;
return false;
}
2016-02-01 22:55:43 +01:00
}
shared_ptr<fs::device_base> fs::device_manager::get_device(const std::string& path)
2016-02-01 22:55:43 +01:00
{
reader_lock lock(m_mutex);
const usz prefix = path.find_first_of('_', 7) + 1;
2016-02-01 22:55:43 +01:00
const auto found = m_map.find(path.substr(prefix, path.find_first_of('/', 1) - prefix));
if (found == m_map.end() || !path.starts_with(found->second->fs_prefix))
2016-02-01 22:55:43 +01:00
{
return null_ptr;
2016-02-01 22:55:43 +01:00
}
return found->second;
}
shared_ptr<fs::device_base> fs::device_manager::set_device(const std::string& name, shared_ptr<device_base> device)
2016-02-01 22:55:43 +01:00
{
std::lock_guard lock(m_mutex);
2016-02-01 22:55:43 +01:00
if (device)
{
// Adding
if (auto [it, ok] = m_map.try_emplace(name, std::move(device)); ok)
{
return it->second;
}
g_tls_error = error::exist;
}
else
{
// Removing
if (auto found = m_map.find(name); found != m_map.end())
{
device = std::move(found->second);
m_map.erase(found);
return device;
}
g_tls_error = error::noent;
}
return null_ptr;
2016-02-01 22:55:43 +01:00
}
shared_ptr<fs::device_base> fs::get_virtual_device(const std::string& path)
2016-02-01 22:55:43 +01:00
{
// Every virtual device path must have specific name at the beginning
if (path.starts_with("/vfsv0_") && path.size() >= 8 + 22 && path[29] == '_' && path.find_first_of('/', 1) > 29)
2016-02-01 22:55:43 +01:00
{
return get_device_manager().get_device(path);
2016-02-01 22:55:43 +01:00
}
return null_ptr;
2016-02-01 22:55:43 +01:00
}
shared_ptr<fs::device_base> fs::set_virtual_device(const std::string& name, shared_ptr<device_base> device)
2016-02-01 22:55:43 +01:00
{
return get_device_manager().set_device(name, std::move(device));
2016-02-01 22:55:43 +01:00
}
std::string_view fs::get_parent_dir_view(std::string_view path, u32 parent_level)
2016-01-06 00:52:48 +01:00
{
2023-06-24 08:59:20 +02:00
std::string_view result = path;
2015-04-15 16:27:37 +02:00
2023-06-24 08:59:20 +02:00
// Number of path components to remove
usz to_remove = parent_level;
2023-06-24 08:59:20 +02:00
while (to_remove--)
{
2023-06-24 08:59:20 +02:00
// Trim contiguous delimiters at the end
if (usz sz = result.find_last_not_of(delim) + 1)
{
result = result.substr(0, sz);
}
else
2023-06-24 08:59:20 +02:00
{
return "/";
}
const auto elem = result.substr(result.find_last_of(delim) + 1);
if (elem.empty() || elem.size() == result.size())
{
break;
2023-06-24 08:59:20 +02:00
}
if (elem == ".")
{
to_remove += 1;
}
if (elem == "..")
{
to_remove += 2;
}
result.remove_suffix(elem.size());
}
if (usz sz = result.find_last_not_of(delim) + 1)
{
result = result.substr(0, sz);
}
else
{
return "/";
}
return result;
2016-01-06 00:52:48 +01:00
}
2023-07-18 23:30:36 +02:00
bool fs::get_stat(const std::string& path, stat_t& info)
2016-01-06 00:52:48 +01:00
{
// Ensure consistent information on failure
info = {};
2016-02-01 22:55:43 +01:00
if (auto device = get_virtual_device(path))
{
return device->stat(path, info);
}
#ifdef _WIN32
std::string_view epath = path;
// '/' and '\\' Not allowed by FindFirstFileExW at the end of path but we should allow it
2020-09-25 08:42:41 +02:00
if (auto not_del = epath.find_last_not_of(delim); not_del != umax && not_del != epath.size() - 1)
{
2020-09-20 19:24:32 +02:00
epath.remove_suffix(epath.size() - 1 - not_del);
}
// Handle drives specially
2020-09-25 08:42:41 +02:00
if (epath.find_first_of(delim) == umax && epath.ends_with(':'))
2020-09-20 19:24:32 +02:00
{
WIN32_FILE_ATTRIBUTE_DATA attrs{};
2020-09-20 19:24:32 +02:00
// Must end with a delimiter
if (!GetFileAttributesExW(to_wchar(std::string(epath) + '/').get(), GetFileExInfoStandard, &attrs))
{
g_tls_error = to_error(GetLastError());
return false;
2020-09-20 19:24:32 +02:00
}
info.is_directory = true; // Handle drives as directories
info.is_writable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
info.size = attrs.nFileSizeLow | (u64{attrs.nFileSizeHigh} << 32);
info.atime = to_time(attrs.ftLastAccessTime);
info.mtime = to_time(attrs.ftLastWriteTime);
info.ctime = info.mtime;
if (info.atime < info.mtime)
info.atime = info.mtime;
return true;
}
// Allowed by FindFirstFileExW but we should not allow it
if (epath.ends_with("*"))
{
g_tls_error = fs::error::noent;
return false;
}
WIN32_FIND_DATA attrs{};
const auto wchar_ptr = to_wchar(std::string(epath));
const std::wstring_view wpath_view = wchar_ptr.get();
const HANDLE handle = FindFirstFileExW(wpath_view.data(), FindExInfoStandard, &attrs, FindExSearchNameMatch, nullptr, FIND_FIRST_EX_CASE_SENSITIVE);
if (handle == INVALID_HANDLE_VALUE)
2015-04-15 16:27:37 +02:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(GetLastError());
return false;
}
2015-04-15 16:27:37 +02:00
struct close_t
{
HANDLE handle;
~close_t() { FindClose(handle); }
};
2020-09-25 08:42:41 +02:00
for (close_t find_manage{handle}; attrs.cFileName != wpath_view.substr(wpath_view.find_last_of(wdelim) + 1);)
{
if (!FindNextFileW(handle, &attrs))
{
if (const DWORD err = GetLastError(); err != ERROR_NO_MORE_FILES)
{
g_tls_error = to_error(err);
return false;
}
g_tls_error = fs::error::noent;
return false;
}
}
2015-04-24 23:38:11 +02:00
info.is_directory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
info.is_symlink = (attrs.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
2015-04-24 23:38:11 +02:00
info.is_writable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
info.size = attrs.nFileSizeLow | (u64{attrs.nFileSizeHigh} << 32);
info.atime = to_time(attrs.ftLastAccessTime);
info.mtime = to_time(attrs.ftLastWriteTime);
info.ctime = info.mtime;
#else
2016-01-06 00:52:48 +01:00
struct ::stat file_info;
if (::stat(path.c_str(), &file_info) != 0)
2015-04-15 16:27:37 +02:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(errno);
return false;
}
2015-04-24 23:38:11 +02:00
info.is_directory = S_ISDIR(file_info.st_mode);
info.is_symlink = S_ISLNK(file_info.st_mode);
2015-04-24 23:38:11 +02:00
info.is_writable = file_info.st_mode & 0200; // HACK: approximation
2015-04-15 16:27:37 +02:00
info.size = file_info.st_size;
info.atime = file_info.st_atime;
info.mtime = file_info.st_mtime;
info.ctime = info.mtime;
#endif
2015-04-25 21:15:53 +02:00
if (info.atime < info.mtime)
info.atime = info.mtime;
return true;
}
2015-04-24 23:38:11 +02:00
bool fs::exists(const std::string& path)
2015-04-20 17:53:31 +02:00
{
fs::stat_t info{};
2023-07-18 23:30:36 +02:00
return fs::get_stat(path, info);
2015-04-20 17:53:31 +02:00
}
2016-01-06 00:52:48 +01:00
bool fs::is_file(const std::string& path)
2015-04-20 17:53:31 +02:00
{
fs::stat_t info{};
2023-07-18 23:30:36 +02:00
if (!fs::get_stat(path, info))
2015-04-20 17:53:31 +02:00
{
return false;
}
if (info.is_directory)
2015-04-20 17:53:31 +02:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = error::exist;
2015-04-20 17:53:31 +02:00
return false;
}
2016-01-06 00:52:48 +01:00
return true;
2015-04-20 17:53:31 +02:00
}
2016-01-06 00:52:48 +01:00
bool fs::is_dir(const std::string& path)
2015-04-15 16:27:37 +02:00
{
fs::stat_t info{};
2023-07-18 23:30:36 +02:00
if (!fs::get_stat(path, info))
2016-02-01 22:55:43 +01:00
{
2015-04-15 16:27:37 +02:00
return false;
}
if (!info.is_directory)
2015-04-18 15:38:42 +02:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = error::exist;
2015-04-18 15:38:42 +02:00
return false;
}
return true;
}
bool fs::is_symlink(const std::string& path)
{
fs::stat_t info{};
if (!fs::get_stat(path, info))
{
return false;
}
if (!info.is_symlink)
{
g_tls_error = error::exist;
return false;
}
return true;
}
2017-04-24 17:45:58 +02:00
bool fs::statfs(const std::string& path, fs::device_stat& info)
{
if (auto device = get_virtual_device(path))
{
return device->statfs(path, info);
}
#ifdef _WIN32
ULARGE_INTEGER avail_free;
ULARGE_INTEGER total_size;
ULARGE_INTEGER total_free;
// Convert path and return it back to the "short" format
const bool unc = path.size() > 2 && (path[0] == '\\' || path[0] == '/') && path[1] == path[0];
std::wstring str = to_wchar(path).get() + (unc ? 6 : 4);
if (unc)
{
str[0] = '\\';
str[1] = '\\';
}
// Keep cutting path from right until it's short enough
while (str.size() > 256)
{
2020-12-18 08:39:54 +01:00
if (usz x = str.find_last_of('\\') + 1)
str.resize(x - 1);
else
break;
}
if (!GetDiskFreeSpaceExW(str.c_str(), &avail_free, &total_size, &total_free))
2017-04-24 17:45:58 +02:00
{
g_tls_error = to_error(GetLastError());
return false;
}
info.block_size = 4096; // TODO
info.total_size = total_size.QuadPart;
info.total_free = total_free.QuadPart;
info.avail_free = avail_free.QuadPart;
#else
struct ::statvfs buf;
2017-05-14 22:45:22 +02:00
if (::statvfs(path.c_str(), &buf) != 0)
2017-04-24 17:45:58 +02:00
{
g_tls_error = to_error(errno);
return false;
}
info.block_size = buf.f_frsize;
info.total_size = info.block_size * buf.f_blocks;
info.total_free = info.block_size * buf.f_bfree;
info.avail_free = info.block_size * buf.f_bavail;
#endif
return true;
}
2016-01-06 00:52:48 +01:00
bool fs::create_dir(const std::string& path)
{
2016-02-01 22:55:43 +01:00
if (auto device = get_virtual_device(path))
{
return device->create_dir(path);
}
#ifdef _WIN32
2021-04-09 21:12:47 +02:00
if (!CreateDirectoryW(to_wchar(path).get(), nullptr))
2016-01-06 00:52:48 +01:00
{
2021-04-10 06:41:55 +02:00
int res = GetLastError();
if (res == ERROR_ACCESS_DENIED && is_dir(path))
{
// May happen on drives
res = ERROR_ALREADY_EXISTS;
}
g_tls_error = to_error(res);
2016-01-06 00:52:48 +01:00
return false;
}
return true;
#else
if (::mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0)
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(errno);
return false;
}
return true;
#endif
2016-01-06 00:52:48 +01:00
}
2015-04-20 17:53:31 +02:00
2016-01-06 00:52:48 +01:00
bool fs::create_path(const std::string& path)
{
const std::string parent = get_parent_dir(path);
2016-01-06 00:52:48 +01:00
#ifdef _WIN32
// Workaround: don't call is_dir with naked drive letter
if (parent.size() < path.size() && (parent.empty() || (parent.back() != ':' && !is_dir(parent) && !create_path(parent))))
#else
if (parent.size() < path.size() && !is_dir(parent) && !create_path(parent))
#endif
2016-01-06 00:52:48 +01:00
{
return false;
2016-01-06 00:52:48 +01:00
}
if (!create_dir(path) && g_tls_error != error::exist)
{
return false;
}
return true;
}
2016-01-06 00:52:48 +01:00
bool fs::remove_dir(const std::string& path)
{
if (path.empty())
{
// Don't allow removing empty path (TODO)
g_tls_error = fs::error::noent;
return false;
}
2016-02-01 22:55:43 +01:00
if (auto device = get_virtual_device(path))
{
return device->remove_dir(path);
}
#ifdef _WIN32
2016-01-06 00:52:48 +01:00
if (!RemoveDirectoryW(to_wchar(path).get()))
2014-10-24 15:24:09 +02:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(GetLastError());
return false;
}
2016-01-06 00:52:48 +01:00
#else
if (::rmdir(path.c_str()) != 0)
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(errno);
return false;
}
#endif
return true;
}
bool fs::create_symlink(const std::string& path, const std::string& target)
{
if (auto device = get_virtual_device(path))
{
return device->create_symlink(path);
}
#ifdef _WIN32
const DWORD flags = is_dir(target) ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0;
if (!CreateSymbolicLinkW(to_wchar(path).get(), to_wchar(target).get(), flags))
{
g_tls_error = to_error(GetLastError());
return false;
}
return true;
#else
if (::symlink(target.c_str(), path.c_str()) != 0)
{
g_tls_error = to_error(errno);
return false;
}
return true;
#endif
}
bool fs::rename(const std::string& from, const std::string& to, bool overwrite)
{
if (from.empty() || to.empty())
{
// Don't allow opening empty path (TODO)
g_tls_error = fs::error::noent;
return false;
}
2016-02-01 22:55:43 +01:00
const auto device = get_virtual_device(from);
if (device != get_virtual_device(to))
{
fmt::throw_exception("fs::rename() between different devices not implemented.\nFrom: %s\nTo: %s", from, to);
2016-02-01 22:55:43 +01:00
}
if (device)
{
return device->rename(from, to);
}
#ifdef _WIN32
const auto ws1 = to_wchar(from);
const auto ws2 = to_wchar(to);
if (!MoveFileExW(ws1.get(), ws2.get(), overwrite ? MOVEFILE_REPLACE_EXISTING : 0))
2015-04-13 16:46:10 +02:00
{
DWORD error1 = GetLastError();
if (overwrite && error1 == ERROR_ACCESS_DENIED && is_dir(from) && is_dir(to))
{
if (RemoveDirectoryW(ws2.get()))
{
if (MoveFileW(ws1.get(), ws2.get()))
{
return true;
}
error1 = GetLastError();
2021-04-09 21:12:47 +02:00
CreateDirectoryW(ws2.get(), nullptr); // TODO
}
else
{
error1 = GetLastError();
}
}
g_tls_error = to_error(error1);
2015-04-13 16:46:10 +02:00
return false;
}
return true;
2016-01-06 00:52:48 +01:00
#else
2019-04-13 12:46:56 +02:00
#ifdef __linux__
if (syscall(SYS_renameat2, AT_FDCWD, from.c_str(), AT_FDCWD, to.c_str(), overwrite ? 0 : 1 /* RENAME_NOREPLACE */) == 0)
{
return true;
}
// If the filesystem doesn't support RENAME_NOREPLACE, it returns EINVAL. Retry with fallback method in that case.
if (errno != EINVAL || overwrite)
{
g_tls_error = to_error(errno);
return false;
}
#endif
if (!overwrite && exists(to))
{
g_tls_error = fs::error::exist;
return false;
}
if (::rename(from.c_str(), to.c_str()) != 0)
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(errno);
return false;
}
return true;
2016-01-06 00:52:48 +01:00
#endif
2015-04-13 16:46:10 +02:00
}
2016-01-06 00:52:48 +01:00
bool fs::copy_file(const std::string& from, const std::string& to, bool overwrite)
2015-04-13 16:46:10 +02:00
{
2016-02-01 22:55:43 +01:00
const auto device = get_virtual_device(from);
if (device != get_virtual_device(to) || device) // TODO
{
fmt::throw_exception("fs::copy_file() for virtual devices not implemented.\nFrom: %s\nTo: %s", from, to);
2016-02-01 22:55:43 +01:00
}
2016-01-06 00:52:48 +01:00
#ifdef _WIN32
if (!CopyFileW(to_wchar(from).get(), to_wchar(to).get(), !overwrite))
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(GetLastError());
2016-01-06 00:52:48 +01:00
return false;
}
return true;
#elif defined(__APPLE__) || defined(__linux__) || defined(__sun)
/* Source: http://stackoverflow.com/questions/2180079/how-can-i-copy-a-file-on-unix-using-c */
2015-04-13 16:46:10 +02:00
2016-01-06 00:52:48 +01:00
const int input = ::open(from.c_str(), O_RDONLY);
if (input == -1)
2015-04-13 16:46:10 +02:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(errno);
2016-01-06 00:52:48 +01:00
return false;
2015-04-13 16:46:10 +02:00
}
2016-01-06 00:52:48 +01:00
const int output = ::open(to.c_str(), O_WRONLY | O_CREAT | (overwrite ? O_TRUNC : O_EXCL), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (output == -1)
2015-04-13 16:46:10 +02:00
{
2016-01-06 00:52:48 +01:00
const int err = errno;
::close(input);
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(err);
2016-01-06 00:52:48 +01:00
return false;
2015-04-13 16:46:10 +02:00
}
2016-01-06 00:52:48 +01:00
// Here we use kernel-space copying for performance reasons
Improve portability for BSDs (#2813) * sys_net: don't use fds_bits from a system header on FreeBSD rpcs3/Emu/Cell/Modules/sys_net.cpp:137:14: error: no member named '__fds_bits' in 'sys_net::fd_set'; did you mean 'fds_bits'? if (src->fds_bits[i] & (1 << bit)) ^~~~~~~~ fds_bits /usr/include/sys/select.h:75:18: note: expanded from macro 'fds_bits' #define fds_bits __fds_bits ^ rpcs3/Emu/Cell/Modules/sys_net.h:114:13: note: 'fds_bits' declared here be_t<u32> fds_bits[32]; ^ * GUI: fallback to xdg-open on other Unices rpcs3/Gui/GameViewer.cpp:289:26: error: use of undeclared identifier 'command' wxExecute(fmt::FromUTF8(command)); ^ * File: FreeBSD never supported copyfile(3) but sendfile(2) works fine Utilities/File.cpp:114:10: fatal error: 'copyfile.h' file not found #include <copyfile.h> ^~~~~~~~~~~~ * Thread: add signal handling for BSDs Utilities/Thread.cpp:761:23: error: use of undeclared identifier 'REG_RAX' static const decltype(REG_RAX) reg_table[] = ^ Utilities/Thread.cpp:763:2: error: use of undeclared identifier 'REG_RAX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:11: error: use of undeclared identifier 'REG_RCX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:20: error: use of undeclared identifier 'REG_RDX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:29: error: use of undeclared identifier 'REG_RBX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:38: error: use of undeclared identifier 'REG_RSP' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:47: error: use of undeclared identifier 'REG_RBP' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:56: error: use of undeclared identifier 'REG_RSI' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:65: error: use of undeclared identifier 'REG_RDI' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:764:2: error: use of undeclared identifier 'REG_R8' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:10: error: use of undeclared identifier 'REG_R9' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:18: error: use of undeclared identifier 'REG_R10' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:27: error: use of undeclared identifier 'REG_R11' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:36: error: use of undeclared identifier 'REG_R12' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:45: error: use of undeclared identifier 'REG_R13' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:54: error: use of undeclared identifier 'REG_R14' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:63: error: use of undeclared identifier 'REG_R15' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:72: error: use of undeclared identifier 'REG_RIP' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:792:26: error: no member named 'gregs' in '__mcontext' const u64 reg_value = *X64REG(context, reg - X64R_RAX); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:804:21: error: no member named 'gregs' in '__mcontext' out_value = (u8)(*X64REG(context, reg - X64R_AL)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:809:21: error: no member named 'gregs' in '__mcontext' out_value = (u8)(*X64REG(context, reg - X64R_AH) >> 8); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:815:31: error: no member named 'gregs' in '__mcontext' const s8 imm_value = *(s8*)(RIP(context) + i_size - 1); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:827:33: error: no member named 'gregs' in '__mcontext' const s16 imm_value = *(s16*)(RIP(context) + i_size - 2); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:836:33: error: no member named 'gregs' in '__mcontext' const s32 imm_value = *(s32*)(RIP(context) + i_size - 4); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:846:20: error: no member named 'gregs' in '__mcontext' out_value = (u32)RCX(context); ^~~~~~~~~~~~ Utilities/Thread.cpp:779:18: note: expanded from macro 'RCX' #define RCX(c) (*X64REG((c), 1)) ^~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:851:19: error: no member named 'gregs' in '__mcontext' const u32 _cf = EFLAGS(context) & 0x1; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:851:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:852:19: error: no member named 'gregs' in '__mcontext' const u32 _zf = EFLAGS(context) & 0x40; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:852:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:853:19: error: no member named 'gregs' in '__mcontext' const u32 _sf = EFLAGS(context) & 0x80; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:853:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:854:19: error: no member named 'gregs' in '__mcontext' const u32 _of = EFLAGS(context) & 0x800; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:854:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:855:19: error: no member named 'gregs' in '__mcontext' const u32 _pf = EFLAGS(context) & 0x4; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:855:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:885:12: error: no member named 'gregs' in '__mcontext' case 1: *X64REG(context, reg - X64R_RAX) = value & 0xff | *X64REG(context, re... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:885:62: error: no member named 'gregs' in '__mcontext' ...*X64REG(context, reg - X64R_RAX) = value & 0xff | *X64REG(context, reg - X64R_RAX) & 0xffffff... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:886:12: error: no member named 'gregs' in '__mcontext' case 2: *X64REG(context, reg - X64R_RAX) = value & 0xffff | *X64REG(context, ... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:886:64: error: no member named 'gregs' in '__mcontext' ...reg - X64R_RAX) = value & 0xffff | *X64REG(context, reg - X64R_RAX) & 0xffff0000; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:887:12: error: no member named 'gregs' in '__mcontext' case 4: *X64REG(context, reg - X64R_RAX) = value & 0xffffffff; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:888:12: error: no member named 'gregs' in '__mcontext' case 8: *X64REG(context, reg - X64R_RAX) = value; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:913:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x1; // set CF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:913:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:917:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x1; // clear CF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:917:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:922:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x40; // set ZF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:922:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:926:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x40; // clear ZF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:926:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:931:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x80; // set SF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:931:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:935:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x80; // clear SF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:935:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:940:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x800; // set OF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:940:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:944:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x800; // clear OF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:944:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:953:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x4; // set PF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:953:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:957:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x4; // clear PF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:957:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:962:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x10; // set AF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:962:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:966:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x10; // clear AF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:966:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:976:7: error: no member named 'gregs' in '__mcontext' if (EFLAGS(context) & 0x400 /* direction flag */) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:976:7: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:1020:25: error: no member named 'gregs' in '__mcontext' auto code = (const u8*)RIP(context); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1146:3: error: no member named 'gregs' in '__mcontext' RIP(context) += i_size; ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1368:47: error: no member named 'gregs' in '__mcontext' const bool is_writing = context->uc_mcontext.gregs[REG_ERR] & 0x2; ~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1368:53: error: use of undeclared identifier 'REG_ERR' const bool is_writing = context->uc_mcontext.gregs[REG_ERR] & 0x2; ^ Utilities/Thread.cpp:1393:89: error: no member named 'gregs' in '__mcontext' ...%s location %p at %p.", cause, info->si_addr, RIP(context))); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ * Thread: add explict casts for incomplete pthread_t on some platforms Utilities/Thread.cpp:1467:17: error: no viable overloaded '=' ctrl->m_thread = thread; ~~~~~~~~~~~~~~ ^ ~~~~~~ Utilities/Atomic.h:776:12: note: candidate function not viable: cannot convert argument of incomplete type 'pthread_t' (aka 'pthread *') to 'const atomic_t<unsigned long>' for 1st argument atomic_t& operator =(const atomic_t&) = delete; ^ Utilities/Atomic.h:902:7: note: candidate function not viable: cannot convert argument of incomplete type 'pthread_t' (aka 'pthread *') to 'const type' (aka 'const unsigned long') for 1st argument type operator =(const type& rhs) ^ Utilities/Thread.cpp:1656:3: error: no matching function for call to 'pthread_detach' pthread_detach(m_thread.raw()); ^~~~~~~~~~~~~~ /usr/include/pthread.h:218:6: note: candidate function not viable: no known conversion from 'type' (aka 'unsigned long') to 'pthread_t' (aka 'pthread *') for 1st argument int pthread_detach(pthread_t); ^ * build: dlopen() maybe in libc /usr/bin/ld: cannot find -ldl c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: iconv() maybe available on some BSDs in libc /usr/bin/ld: cannot find -liconv c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: hidapi-hidraw is only built on Linux /usr/bin/ld: cannot find -lhidapi-hidraw c++: error: linker command failed with exit code 1 (use -v to see invocation) * Thread: use getrusage() on more POSIX-like systems * Qt: don't return NULL handle on other platforms rpcs3/rpcs3qt/gs_frame.cpp:120:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ * build: properly disable Vulkan on other platforms In file included from rpcs3/rpcs3_app.cpp:40: In file included from rpcs3/Emu/RSX/VK/VKGSRender.h:3: rpcs3/Emu/RSX/VK/VKHelpers.h:1209:42: error: unknown type name 'device_queues' std::vector<VkBool32> supportsPresent(device_queues); ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1211:4: error: expected member name or ';' after declaration specifiers for (u32 index = 0; index < device_queues; index++) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1221:4: error: expected member name or ';' after declaration specifiers for (u32 i = 0; i < device_queues; i++) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1256:4: error: expected member name or ';' after declaration specifiers if (graphicsQueueNodeIndex != presentQueueNodeIndex) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1261:4: error: expected member name or ';' after declaration specifiers CHECK_RESULT(vkGetPhysicalDeviceSurfaceFormatsKHR(dev, surface, &formatCount, nullptr)); ^ [...] /usr/bin/ld: cannot find -lvulkan c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: make install/strip work by moving commands * Qt: create surface for GL context if it wasn't ready #0 strlen (str=0x0) at /usr/src/lib/libc/string/strlen.c:100 #1 0x000000000090f02e in std::__1::char_traits<char>::length (__s=0x0) at /usr/include/c++/v1/__string:215 #2 std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string (__s=0x0, this=<optimized out>) at /usr/include/c++/v1/string:1547 #3 gl::capabilities::initialize (this=0x2ba32a0 <gl::g_driver_caps>) at rpcs3/Emu/RSX/GL/GLHelpers.h:133 #4 0x000000000090d3dd in gl::get_driver_caps () at rpcs3/Emu/RSX/GL/GLHelpers.cpp:56 #5 0x00000000008fa511 in GLGSRender::on_init_thread (this=0x838d30018) at rpcs3/Emu/RSX/GL/GLGSRender.cpp:484 #6 0x0000000000938f9e in rsx::thread::on_task (this=0x838d30018) at rpcs3/Emu/RSX/RSXThread.cpp:334 #7 0x0000000000abc329 in task_stack::task_type<named_thread::start_thread(std::__1::shared_ptr<void> const&)::$_10>::invoke() () #8 0x0000000000abc114 in thread_ctrl::start(std::__1::shared_ptr<thread_ctrl> const&, task_stack)::$_7::__invoke(void*) () #9 0x0000000801e60c35 in thread_start (curthread=0x843650a00) at /usr/src/lib/libthr/thread/thr_create.c:289 #10 0x0000000000000000 in ?? () * build: don't abort without git metadata -- Found Git: /usr/local/bin/git (found version "2.13.1") fatal: Not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). CMake Warning at git-version.cmake:12 (message): git rev-list failed, unable to include version. * build: non-parallel needs git-version.h earlier rpcs3/rpcs3_version.cpp:3:10: fatal error: 'git-version.h' file not found #include "git-version.h" ^~~~~~~~~~~~~~~ 1 error generated.
2017-06-22 20:03:41 +02:00
#if defined(__APPLE__)
// fcopyfile works on OS X 10.5+
2016-01-06 00:52:48 +01:00
if (::fcopyfile(input, output, 0, COPYFILE_ALL))
Improve portability for BSDs (#2813) * sys_net: don't use fds_bits from a system header on FreeBSD rpcs3/Emu/Cell/Modules/sys_net.cpp:137:14: error: no member named '__fds_bits' in 'sys_net::fd_set'; did you mean 'fds_bits'? if (src->fds_bits[i] & (1 << bit)) ^~~~~~~~ fds_bits /usr/include/sys/select.h:75:18: note: expanded from macro 'fds_bits' #define fds_bits __fds_bits ^ rpcs3/Emu/Cell/Modules/sys_net.h:114:13: note: 'fds_bits' declared here be_t<u32> fds_bits[32]; ^ * GUI: fallback to xdg-open on other Unices rpcs3/Gui/GameViewer.cpp:289:26: error: use of undeclared identifier 'command' wxExecute(fmt::FromUTF8(command)); ^ * File: FreeBSD never supported copyfile(3) but sendfile(2) works fine Utilities/File.cpp:114:10: fatal error: 'copyfile.h' file not found #include <copyfile.h> ^~~~~~~~~~~~ * Thread: add signal handling for BSDs Utilities/Thread.cpp:761:23: error: use of undeclared identifier 'REG_RAX' static const decltype(REG_RAX) reg_table[] = ^ Utilities/Thread.cpp:763:2: error: use of undeclared identifier 'REG_RAX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:11: error: use of undeclared identifier 'REG_RCX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:20: error: use of undeclared identifier 'REG_RDX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:29: error: use of undeclared identifier 'REG_RBX' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:38: error: use of undeclared identifier 'REG_RSP' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:47: error: use of undeclared identifier 'REG_RBP' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:56: error: use of undeclared identifier 'REG_RSI' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:763:65: error: use of undeclared identifier 'REG_RDI' REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI, ^ Utilities/Thread.cpp:764:2: error: use of undeclared identifier 'REG_R8' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:10: error: use of undeclared identifier 'REG_R9' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:18: error: use of undeclared identifier 'REG_R10' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:27: error: use of undeclared identifier 'REG_R11' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:36: error: use of undeclared identifier 'REG_R12' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:45: error: use of undeclared identifier 'REG_R13' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:54: error: use of undeclared identifier 'REG_R14' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:63: error: use of undeclared identifier 'REG_R15' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:764:72: error: use of undeclared identifier 'REG_RIP' REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RIP ^ Utilities/Thread.cpp:792:26: error: no member named 'gregs' in '__mcontext' const u64 reg_value = *X64REG(context, reg - X64R_RAX); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:804:21: error: no member named 'gregs' in '__mcontext' out_value = (u8)(*X64REG(context, reg - X64R_AL)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:809:21: error: no member named 'gregs' in '__mcontext' out_value = (u8)(*X64REG(context, reg - X64R_AH) >> 8); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:815:31: error: no member named 'gregs' in '__mcontext' const s8 imm_value = *(s8*)(RIP(context) + i_size - 1); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:827:33: error: no member named 'gregs' in '__mcontext' const s16 imm_value = *(s16*)(RIP(context) + i_size - 2); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:836:33: error: no member named 'gregs' in '__mcontext' const s32 imm_value = *(s32*)(RIP(context) + i_size - 4); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:846:20: error: no member named 'gregs' in '__mcontext' out_value = (u32)RCX(context); ^~~~~~~~~~~~ Utilities/Thread.cpp:779:18: note: expanded from macro 'RCX' #define RCX(c) (*X64REG((c), 1)) ^~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:851:19: error: no member named 'gregs' in '__mcontext' const u32 _cf = EFLAGS(context) & 0x1; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:851:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:852:19: error: no member named 'gregs' in '__mcontext' const u32 _zf = EFLAGS(context) & 0x40; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:852:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:853:19: error: no member named 'gregs' in '__mcontext' const u32 _sf = EFLAGS(context) & 0x80; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:853:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:854:19: error: no member named 'gregs' in '__mcontext' const u32 _of = EFLAGS(context) & 0x800; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:854:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:855:19: error: no member named 'gregs' in '__mcontext' const u32 _pf = EFLAGS(context) & 0x4; ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:855:19: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:885:12: error: no member named 'gregs' in '__mcontext' case 1: *X64REG(context, reg - X64R_RAX) = value & 0xff | *X64REG(context, re... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:885:62: error: no member named 'gregs' in '__mcontext' ...*X64REG(context, reg - X64R_RAX) = value & 0xff | *X64REG(context, reg - X64R_RAX) & 0xffffff... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:886:12: error: no member named 'gregs' in '__mcontext' case 2: *X64REG(context, reg - X64R_RAX) = value & 0xffff | *X64REG(context, ... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:886:64: error: no member named 'gregs' in '__mcontext' ...reg - X64R_RAX) = value & 0xffff | *X64REG(context, reg - X64R_RAX) & 0xffff0000; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:887:12: error: no member named 'gregs' in '__mcontext' case 4: *X64REG(context, reg - X64R_RAX) = value & 0xffffffff; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:888:12: error: no member named 'gregs' in '__mcontext' case 8: *X64REG(context, reg - X64R_RAX) = value; return true; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:913:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x1; // set CF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:913:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:917:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x1; // clear CF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:917:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:922:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x40; // set ZF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:922:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:926:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x40; // clear ZF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:926:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:931:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x80; // set SF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:931:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:935:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x80; // clear SF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:935:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:940:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x800; // set OF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:940:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:944:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x800; // clear OF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:944:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:953:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x4; // set PF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:953:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:957:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x4; // clear PF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:957:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:962:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) |= 0x10; // set AF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:962:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:966:3: error: no member named 'gregs' in '__mcontext' EFLAGS(context) &= ~0x10; // clear AF ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:966:3: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:976:7: error: no member named 'gregs' in '__mcontext' if (EFLAGS(context) & 0x400 /* direction flag */) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:769:49: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:976:7: error: use of undeclared identifier 'REG_EFL' Utilities/Thread.cpp:769:55: note: expanded from macro 'EFLAGS' #define EFLAGS(context) ((context)->uc_mcontext.gregs[REG_EFL]) ^ Utilities/Thread.cpp:1020:25: error: no member named 'gregs' in '__mcontext' auto code = (const u8*)RIP(context); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1146:3: error: no member named 'gregs' in '__mcontext' RIP(context) += i_size; ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1368:47: error: no member named 'gregs' in '__mcontext' const bool is_writing = context->uc_mcontext.gregs[REG_ERR] & 0x2; ~~~~~~~~~~~~~~~~~~~~ ^ Utilities/Thread.cpp:1368:53: error: use of undeclared identifier 'REG_ERR' const bool is_writing = context->uc_mcontext.gregs[REG_ERR] & 0x2; ^ Utilities/Thread.cpp:1393:89: error: no member named 'gregs' in '__mcontext' ...%s location %p at %p.", cause, info->si_addr, RIP(context))); ^~~~~~~~~~~~ Utilities/Thread.cpp:784:18: note: expanded from macro 'RIP' #define RIP(c) (*X64REG((c), 16)) ^~~~~~~~~~~~~~~ Utilities/Thread.cpp:767:55: note: expanded from macro 'X64REG' #define X64REG(context, reg) (&(context)->uc_mcontext.gregs[reg_table[reg]]) ~~~~~~~~~~~~~~~~~~~~~~ ^ * Thread: add explict casts for incomplete pthread_t on some platforms Utilities/Thread.cpp:1467:17: error: no viable overloaded '=' ctrl->m_thread = thread; ~~~~~~~~~~~~~~ ^ ~~~~~~ Utilities/Atomic.h:776:12: note: candidate function not viable: cannot convert argument of incomplete type 'pthread_t' (aka 'pthread *') to 'const atomic_t<unsigned long>' for 1st argument atomic_t& operator =(const atomic_t&) = delete; ^ Utilities/Atomic.h:902:7: note: candidate function not viable: cannot convert argument of incomplete type 'pthread_t' (aka 'pthread *') to 'const type' (aka 'const unsigned long') for 1st argument type operator =(const type& rhs) ^ Utilities/Thread.cpp:1656:3: error: no matching function for call to 'pthread_detach' pthread_detach(m_thread.raw()); ^~~~~~~~~~~~~~ /usr/include/pthread.h:218:6: note: candidate function not viable: no known conversion from 'type' (aka 'unsigned long') to 'pthread_t' (aka 'pthread *') for 1st argument int pthread_detach(pthread_t); ^ * build: dlopen() maybe in libc /usr/bin/ld: cannot find -ldl c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: iconv() maybe available on some BSDs in libc /usr/bin/ld: cannot find -liconv c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: hidapi-hidraw is only built on Linux /usr/bin/ld: cannot find -lhidapi-hidraw c++: error: linker command failed with exit code 1 (use -v to see invocation) * Thread: use getrusage() on more POSIX-like systems * Qt: don't return NULL handle on other platforms rpcs3/rpcs3qt/gs_frame.cpp:120:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ * build: properly disable Vulkan on other platforms In file included from rpcs3/rpcs3_app.cpp:40: In file included from rpcs3/Emu/RSX/VK/VKGSRender.h:3: rpcs3/Emu/RSX/VK/VKHelpers.h:1209:42: error: unknown type name 'device_queues' std::vector<VkBool32> supportsPresent(device_queues); ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1211:4: error: expected member name or ';' after declaration specifiers for (u32 index = 0; index < device_queues; index++) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1221:4: error: expected member name or ';' after declaration specifiers for (u32 i = 0; i < device_queues; i++) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1256:4: error: expected member name or ';' after declaration specifiers if (graphicsQueueNodeIndex != presentQueueNodeIndex) ^ rpcs3/Emu/RSX/VK/VKHelpers.h:1261:4: error: expected member name or ';' after declaration specifiers CHECK_RESULT(vkGetPhysicalDeviceSurfaceFormatsKHR(dev, surface, &formatCount, nullptr)); ^ [...] /usr/bin/ld: cannot find -lvulkan c++: error: linker command failed with exit code 1 (use -v to see invocation) * build: make install/strip work by moving commands * Qt: create surface for GL context if it wasn't ready #0 strlen (str=0x0) at /usr/src/lib/libc/string/strlen.c:100 #1 0x000000000090f02e in std::__1::char_traits<char>::length (__s=0x0) at /usr/include/c++/v1/__string:215 #2 std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string (__s=0x0, this=<optimized out>) at /usr/include/c++/v1/string:1547 #3 gl::capabilities::initialize (this=0x2ba32a0 <gl::g_driver_caps>) at rpcs3/Emu/RSX/GL/GLHelpers.h:133 #4 0x000000000090d3dd in gl::get_driver_caps () at rpcs3/Emu/RSX/GL/GLHelpers.cpp:56 #5 0x00000000008fa511 in GLGSRender::on_init_thread (this=0x838d30018) at rpcs3/Emu/RSX/GL/GLGSRender.cpp:484 #6 0x0000000000938f9e in rsx::thread::on_task (this=0x838d30018) at rpcs3/Emu/RSX/RSXThread.cpp:334 #7 0x0000000000abc329 in task_stack::task_type<named_thread::start_thread(std::__1::shared_ptr<void> const&)::$_10>::invoke() () #8 0x0000000000abc114 in thread_ctrl::start(std::__1::shared_ptr<thread_ctrl> const&, task_stack)::$_7::__invoke(void*) () #9 0x0000000801e60c35 in thread_start (curthread=0x843650a00) at /usr/src/lib/libthr/thread/thr_create.c:289 #10 0x0000000000000000 in ?? () * build: don't abort without git metadata -- Found Git: /usr/local/bin/git (found version "2.13.1") fatal: Not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). CMake Warning at git-version.cmake:12 (message): git rev-list failed, unable to include version. * build: non-parallel needs git-version.h earlier rpcs3/rpcs3_version.cpp:3:10: fatal error: 'git-version.h' file not found #include "git-version.h" ^~~~~~~~~~~~~~~ 1 error generated.
2017-06-22 20:03:41 +02:00
#elif defined(__linux__) || defined(__sun)
2016-01-06 00:52:48 +01:00
// sendfile will work with non-socket output (i.e. regular file) on Linux 2.6.33+
struct ::stat fileinfo = { 0 };
bool result = ::fstat(input, &fileinfo) != -1;
if (result)
{
for (off_t bytes_copied = 0; bytes_copied < fileinfo.st_size; /* Do nothing, bytes_copied is increased by sendfile. */)
{
if (::sendfile(output, input, &bytes_copied, fileinfo.st_size - bytes_copied) == -1)
{
result = false;
break;
}
}
}
if (!result)
#else
#error "Native file copy implementation is missing"
2015-04-13 16:46:10 +02:00
#endif
2016-01-06 00:52:48 +01:00
{
const int err = errno;
2015-04-13 16:46:10 +02:00
2016-01-06 00:52:48 +01:00
::close(input);
::close(output);
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(err);
2016-01-06 00:52:48 +01:00
return false;
}
2015-04-13 16:46:10 +02:00
2016-01-06 00:52:48 +01:00
::close(input);
::close(output);
return true;
#else // fallback
{
std::ifstream out{to, std::ios::binary};
if (out.good() && !overwrite)
{
g_tls_error = to_error(EEXIST);
return false;
}
}
std::ifstream in{from, std::ios::binary};
std::ofstream out{to, std::ios::binary};
if (!in.good() || !out.good())
{
g_tls_error = to_error(errno);
return false;
}
std::istreambuf_iterator<char> bin(in);
std::istreambuf_iterator<char> ein;
std::ostreambuf_iterator<char> bout(out);
std::copy(bin, ein, bout);
2016-01-06 00:52:48 +01:00
return true;
2015-04-13 16:46:10 +02:00
#endif
2016-01-06 00:52:48 +01:00
}
2015-04-13 16:46:10 +02:00
2016-01-06 00:52:48 +01:00
bool fs::remove_file(const std::string& path)
2015-04-13 16:46:10 +02:00
{
2016-02-01 22:55:43 +01:00
if (auto device = get_virtual_device(path))
{
return device->remove(path);
}
2015-04-13 16:46:10 +02:00
#ifdef _WIN32
2016-01-06 00:52:48 +01:00
if (!DeleteFileW(to_wchar(path).get()))
2015-03-16 17:20:02 +01:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(GetLastError());
2015-03-16 17:20:02 +01:00
return false;
}
2015-04-13 16:46:10 +02:00
2015-03-16 17:20:02 +01:00
return true;
2016-01-06 00:52:48 +01:00
#else
if (::unlink(path.c_str()) != 0)
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(errno);
return false;
}
return true;
2016-01-06 00:52:48 +01:00
#endif
}
2016-01-06 00:52:48 +01:00
bool fs::truncate_file(const std::string& path, u64 length)
{
2016-02-01 22:55:43 +01:00
if (auto device = get_virtual_device(path))
{
return device->trunc(path, length);
}
#ifdef _WIN32
2016-01-06 00:52:48 +01:00
// Open the file
2021-04-09 21:12:47 +02:00
const auto handle = CreateFileW(to_wchar(path).get(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
2016-01-06 00:52:48 +01:00
if (handle == INVALID_HANDLE_VALUE)
2014-10-24 15:24:09 +02:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(GetLastError());
2014-08-04 01:52:36 +02:00
return false;
}
2015-04-18 15:38:42 +02:00
2017-09-04 00:55:03 +02:00
FILE_END_OF_FILE_INFO _eof;
_eof.EndOfFile.QuadPart = length;
2017-09-04 00:55:03 +02:00
if (!SetFileInformationByHandle(handle, FileEndOfFileInfo, &_eof, sizeof(_eof)))
2015-04-18 15:38:42 +02:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(GetLastError());
2016-01-06 00:52:48 +01:00
CloseHandle(handle);
2015-04-18 15:38:42 +02:00
return false;
}
2016-01-06 00:52:48 +01:00
CloseHandle(handle);
2014-08-04 01:52:36 +02:00
return true;
2016-01-06 00:52:48 +01:00
#else
if (::truncate(path.c_str(), length) != 0)
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(errno);
return false;
}
return true;
2016-01-06 00:52:48 +01:00
#endif
}
2017-01-26 13:01:21 +01:00
bool fs::utime(const std::string& path, s64 atime, s64 mtime)
{
if (auto device = get_virtual_device(path))
{
return device->utime(path, atime, mtime);
}
#ifdef _WIN32
// Open the file
2021-04-09 21:12:47 +02:00
const auto handle = CreateFileW(to_wchar(path).get(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_NORMAL, NULL);
2017-01-26 13:01:21 +01:00
if (handle == INVALID_HANDLE_VALUE)
{
g_tls_error = to_error(GetLastError());
return false;
}
FILETIME _atime = from_time(atime);
FILETIME _mtime = from_time(mtime);
if (!SetFileTime(handle, nullptr, &_atime, &_mtime))
{
const DWORD last_error = GetLastError();
g_tls_error = to_error(last_error);
// Some filesystems fail to set a date lower than 01/01/1980 00:00:00
if (last_error == ERROR_INVALID_PARAMETER && (atime < 315532800 || mtime < 315532800))
{
// Try again with 01/01/1980 00:00:00
_atime = from_time(std::max<s64>(atime, 315532800));
_mtime = from_time(std::max<s64>(mtime, 315532800));
if (SetFileTime(handle, nullptr, &_atime, &_mtime))
{
CloseHandle(handle);
return true;
}
}
2017-01-26 13:01:21 +01:00
CloseHandle(handle);
return false;
}
CloseHandle(handle);
return true;
#else
::utimbuf buf;
buf.actime = atime;
buf.modtime = mtime;
if (::utime(path.c_str(), &buf) != 0)
{
g_tls_error = to_error(errno);
return false;
}
return true;
#endif
}
2021-02-23 11:09:20 +01:00
void fs::sync()
{
#ifdef _WIN32
fs::g_tls_error = fs::error::unknown;
#else
::sync();
fs::g_tls_error = fs::error::ok;
#endif
}
[[noreturn]] void fs::xnull(const src_loc& loc)
{
fmt::throw_exception("Null object.%s", loc);
2015-04-19 18:02:35 +02:00
}
[[noreturn]] void fs::xfail(const src_loc& loc)
{
fmt::throw_exception("Unexpected fs::error %s%s", g_tls_error, loc);
}
[[noreturn]] void fs::xovfl()
{
fmt::throw_exception("Stream overflow.");
2016-02-01 22:55:43 +01:00
}
2017-01-28 11:11:06 +01:00
fs::file::file(const std::string& path, bs_t<open_mode> mode)
2016-02-01 22:55:43 +01:00
{
if (path.empty())
{
// Don't allow opening empty path (TODO)
g_tls_error = fs::error::noent;
return;
}
2016-02-01 22:55:43 +01:00
if (auto device = get_virtual_device(path))
{
2016-02-01 22:55:43 +01:00
if (auto&& _file = device->open(path, mode))
{
m_file = std::move(_file);
2017-01-28 11:11:06 +01:00
return;
2016-02-01 22:55:43 +01:00
}
2017-01-28 11:11:06 +01:00
return;
2015-04-19 18:02:35 +02:00
}
2016-02-01 22:55:43 +01:00
#ifdef _WIN32
DWORD access = 0;
if (mode & fs::read) access |= GENERIC_READ;
if (mode & fs::write) access |= DELETE | (mode & fs::append ? FILE_APPEND_DATA : GENERIC_WRITE);
2016-02-01 22:55:43 +01:00
2015-04-19 15:19:24 +02:00
DWORD disp = 0;
if (mode & fs::create)
2015-04-19 15:19:24 +02:00
{
2016-02-01 22:55:43 +01:00
disp =
mode & fs::excl ? CREATE_NEW :
mode & fs::trunc ? CREATE_ALWAYS : OPEN_ALWAYS;
2016-02-01 22:55:43 +01:00
}
else
{
if (mode & fs::excl)
2016-02-01 22:55:43 +01:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = error::inval;
2017-01-28 11:11:06 +01:00
return;
2016-02-01 22:55:43 +01:00
}
disp = mode & fs::trunc ? TRUNCATE_EXISTING : OPEN_EXISTING;
2015-04-19 18:02:35 +02:00
}
2020-09-12 06:13:11 +02:00
DWORD share = FILE_SHARE_DELETE;
if (!(mode & fs::unread) || !(mode & fs::write))
{
share |= FILE_SHARE_READ;
}
if (!(mode & (fs::lock + fs::unread)) || !(mode & fs::write))
{
2020-09-12 06:13:11 +02:00
share |= FILE_SHARE_WRITE;
}
2021-04-09 21:12:47 +02:00
const HANDLE handle = CreateFileW(to_wchar(path).get(), access, share, nullptr, disp, FILE_ATTRIBUTE_NORMAL, NULL);
2016-01-06 00:52:48 +01:00
2016-02-01 22:55:43 +01:00
if (handle == INVALID_HANDLE_VALUE)
2015-04-19 15:19:24 +02:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(GetLastError());
2017-01-28 11:11:06 +01:00
return;
2015-04-19 15:19:24 +02:00
}
class windows_file final : public file_base
2015-04-19 18:02:35 +02:00
{
2016-02-01 22:55:43 +01:00
const HANDLE m_handle;
atomic_t<u64> m_pos;
2015-04-19 18:02:35 +02:00
2016-02-01 22:55:43 +01:00
public:
windows_file(HANDLE handle)
: m_handle(handle)
, m_pos(0)
2016-01-06 00:52:48 +01:00
{
}
2016-02-01 22:55:43 +01:00
~windows_file() override
2016-01-06 00:52:48 +01:00
{
2016-02-01 22:55:43 +01:00
CloseHandle(m_handle);
2016-01-06 00:52:48 +01:00
}
stat_t get_stat() override
2016-02-01 22:55:43 +01:00
{
FILE_BASIC_INFO basic_info;
ensure(GetFileInformationByHandleEx(m_handle, FileBasicInfo, &basic_info, sizeof(FILE_BASIC_INFO))); // "file::stat"
2016-02-01 22:55:43 +01:00
stat_t info;
info.is_directory = (basic_info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
info.is_writable = (basic_info.FileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
info.size = this->size();
info.atime = to_time(basic_info.LastAccessTime);
info.mtime = to_time(basic_info.LastWriteTime);
info.ctime = info.mtime;
2016-02-01 22:55:43 +01:00
if (info.atime < info.mtime)
info.atime = info.mtime;
2016-02-01 22:55:43 +01:00
return info;
}
2016-01-06 00:52:48 +01:00
void sync() override
{
ensure(FlushFileBuffers(m_handle)); // "file::sync"
}
2016-02-01 22:55:43 +01:00
bool trunc(u64 length) override
2016-01-06 00:52:48 +01:00
{
2017-09-04 00:55:03 +02:00
FILE_END_OF_FILE_INFO _eof;
_eof.EndOfFile.QuadPart = length;
2016-02-01 22:55:43 +01:00
2017-09-04 00:55:03 +02:00
if (!SetFileInformationByHandle(m_handle, FileEndOfFileInfo, &_eof, sizeof(_eof)))
2016-02-01 22:55:43 +01:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(GetLastError());
2016-02-01 22:55:43 +01:00
return false;
}
2016-08-14 02:22:19 +02:00
return true;
2016-01-06 00:52:48 +01:00
}
2015-04-19 19:57:04 +02:00
2016-02-01 22:55:43 +01:00
u64 read(void* buffer, u64 count) override
2016-01-06 00:52:48 +01:00
{
u64 nread_sum = 0;
2016-02-01 22:55:43 +01:00
for (char* data = static_cast<char*>(buffer); count;)
{
const DWORD size = static_cast<DWORD>(std::min<u64>(count, DWORD{umax} & -4096));
DWORD nread = 0;
OVERLAPPED ovl{};
const u64 pos = m_pos;
ovl.Offset = DWORD(pos);
ovl.OffsetHigh = DWORD(pos >> 32);
ensure(ReadFile(m_handle, data, size, &nread, &ovl) || GetLastError() == ERROR_HANDLE_EOF); // "file::read"
nread_sum += nread;
m_pos += nread;
if (nread < size)
{
break;
}
count -= size;
data += size;
}
2016-02-01 22:55:43 +01:00
return nread_sum;
2016-01-06 00:52:48 +01:00
}
2015-04-19 15:19:24 +02:00
u64 read_at(u64 offset, void* buffer, u64 count) override
{
u64 nread_sum = 0;
for (char* data = static_cast<char*>(buffer); count;)
{
const DWORD size = static_cast<DWORD>(std::min<u64>(count, DWORD{umax} & -4096));
DWORD nread = 0;
OVERLAPPED ovl{};
ovl.Offset = DWORD(offset);
ovl.OffsetHigh = DWORD(offset >> 32);
ensure(ReadFile(m_handle, data, size, &nread, &ovl) || GetLastError() == ERROR_HANDLE_EOF); // "file::read"
nread_sum += nread;
if (nread < size)
{
break;
}
count -= size;
data += size;
offset += size;
}
return nread_sum;
}
2016-02-01 22:55:43 +01:00
u64 write(const void* buffer, u64 count) override
{
u64 nwritten_sum = 0;
2016-02-01 22:55:43 +01:00
for (const char* data = static_cast<const char*>(buffer); count;)
{
const DWORD size = static_cast<DWORD>(std::min<u64>(count, DWORD{umax} & -4096));
DWORD nwritten = 0;
OVERLAPPED ovl{};
const u64 pos = m_pos.fetch_add(size);
ovl.Offset = DWORD(pos);
ovl.OffsetHigh = DWORD(pos >> 32);
ensure(WriteFile(m_handle, data, size, &nwritten, &ovl)); // "file::write"
ensure(nwritten == size);
nwritten_sum += nwritten;
if (nwritten < size)
{
break;
}
count -= size;
data += size;
}
2016-02-01 22:55:43 +01:00
return nwritten_sum;
2016-02-01 22:55:43 +01:00
}
2016-02-01 22:55:43 +01:00
u64 seek(s64 offset, seek_mode whence) override
2016-01-06 00:52:48 +01:00
{
if (whence > seek_end)
{
fmt::throw_exception("Invalid whence (0x%x)", whence);
}
const s64 new_pos =
whence == fs::seek_set ? offset :
whence == fs::seek_cur ? offset + m_pos :
whence == fs::seek_end ? offset + size() : -1;
2016-02-01 22:55:43 +01:00
if (new_pos < 0)
2017-03-23 19:32:59 +01:00
{
fs::g_tls_error = fs::error::inval;
2017-03-23 19:32:59 +01:00
return -1;
}
2016-02-01 22:55:43 +01:00
m_pos = new_pos;
return m_pos;
2016-01-06 00:52:48 +01:00
}
2016-02-01 22:55:43 +01:00
u64 size() override
{
LARGE_INTEGER size;
ensure(GetFileSizeEx(m_handle, &size)); // "file::size"
2016-02-01 22:55:43 +01:00
return size.QuadPart;
}
2017-08-22 20:05:51 +02:00
2019-04-13 12:46:56 +02:00
native_handle get_handle() override
2017-08-22 20:05:51 +02:00
{
return m_handle;
}
file_id get_id() override
{
file_id id{"windows_file"};
id.data.resize(sizeof(FILE_ID_INFO));
FILE_ID_INFO info;
if (!GetFileInformationByHandleEx(m_handle, FileIdInfo, &info, sizeof(info)))
{
// Try GetFileInformationByHandle as a fallback
BY_HANDLE_FILE_INFORMATION info2;
ensure(GetFileInformationByHandle(m_handle, &info2));
info = {};
info.VolumeSerialNumber = info2.dwVolumeSerialNumber;
std::memcpy(&info.FileId, &info2.nFileIndexHigh, 8);
}
std::memcpy(id.data.data(), &info, sizeof(info));
return id;
}
2016-02-01 22:55:43 +01:00
};
2015-04-19 19:57:04 +02:00
2016-02-01 22:55:43 +01:00
m_file = std::make_unique<windows_file>(handle);
2015-04-19 19:57:04 +02:00
#else
2019-09-11 09:55:43 +02:00
int flags = O_CLOEXEC; // Ensures all files are closed on execl for auto updater
2015-04-25 21:15:53 +02:00
if (mode & fs::read && mode & fs::write) flags |= O_RDWR;
else if (mode & fs::read) flags |= O_RDONLY;
else if (mode & fs::write) flags |= O_WRONLY;
2015-04-19 19:57:04 +02:00
if (mode & fs::append) flags |= O_APPEND;
if (mode & fs::create) flags |= O_CREAT;
if (mode & fs::trunc && !(mode & fs::lock)) flags |= O_TRUNC;
if (mode & fs::excl) flags |= O_EXCL;
2015-04-24 16:06:30 +02:00
int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
if (mode & fs::write && mode & fs::unread)
{
if (!(mode & (fs::excl + fs::lock)) && mode & fs::trunc)
{
// Alternative to truncation for "unread" flag (TODO)
if (mode & fs::create)
{
::unlink(path.c_str());
}
}
perm = 0;
}
const int fd = ::open(path.c_str(), flags, perm);
2015-04-24 16:06:30 +02:00
2016-02-01 22:55:43 +01:00
if (fd == -1)
2016-01-06 00:52:48 +01:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(errno);
2017-01-28 11:11:06 +01:00
return;
2016-01-06 00:52:48 +01:00
}
2016-02-01 22:55:43 +01:00
if (mode & fs::write && mode & fs::lock && ::flock(fd, LOCK_EX | LOCK_NB) != 0)
2017-11-19 14:44:06 +01:00
{
g_tls_error = errno == EWOULDBLOCK ? fs::error::acces : to_error(errno);
::close(fd);
return;
}
if (mode & fs::trunc && mode & fs::lock && mode & fs::write)
{
// Postpone truncation in order to avoid using O_TRUNC on a locked file
ensure(::ftruncate(fd, 0) == 0);
}
class unix_file final : public file_base
2016-01-06 00:52:48 +01:00
{
2016-02-01 22:55:43 +01:00
const int m_fd;
2016-02-01 22:55:43 +01:00
public:
unix_file(int fd)
: m_fd(fd)
{
}
2016-02-01 22:55:43 +01:00
~unix_file() override
2016-01-06 00:52:48 +01:00
{
2016-02-01 22:55:43 +01:00
::close(m_fd);
2016-01-06 00:52:48 +01:00
}
stat_t get_stat() override
2016-02-01 22:55:43 +01:00
{
struct ::stat file_info;
ensure(::fstat(m_fd, &file_info) == 0); // "file::stat"
2016-02-01 22:55:43 +01:00
stat_t info;
info.is_directory = S_ISDIR(file_info.st_mode);
info.is_writable = file_info.st_mode & 0200; // HACK: approximation
info.size = file_info.st_size;
info.atime = file_info.st_atime;
info.mtime = file_info.st_mtime;
info.ctime = info.mtime;
2016-02-01 22:55:43 +01:00
if (info.atime < info.mtime)
info.atime = info.mtime;
2016-02-01 22:55:43 +01:00
return info;
}
2015-04-19 15:19:24 +02:00
void sync() override
{
ensure(::fsync(m_fd) == 0); // "file::sync"
}
2016-02-01 22:55:43 +01:00
bool trunc(u64 length) override
{
if (::ftruncate(m_fd, length) != 0)
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(errno);
2016-02-01 22:55:43 +01:00
return false;
}
2016-02-01 22:55:43 +01:00
return true;
}
u64 read(void* buffer, u64 count) override
2016-01-06 00:52:48 +01:00
{
u64 result = 0;
// Loop because (huge?) read can be processed partially
while (auto r = ::read(m_fd, buffer, count))
{
ensure(r > 0); // "file::read"
count -= r;
result += r;
buffer = static_cast<u8*>(buffer) + r;
if (!count)
break;
}
2016-02-01 22:55:43 +01:00
return result;
2016-01-06 00:52:48 +01:00
}
u64 read_at(u64 offset, void* buffer, u64 count) override
{
u64 result = 0;
// For safety; see read()
while (auto r = ::pread(m_fd, buffer, count, offset))
{
ensure(r > 0); // "file::read_at"
count -= r;
offset += r;
result += r;
buffer = static_cast<u8*>(buffer) + r;
if (!count)
break;
}
return result;
}
2016-02-01 22:55:43 +01:00
u64 write(const void* buffer, u64 count) override
{
u64 result = 0;
// For safety; see read()
while (auto r = ::write(m_fd, buffer, count))
{
ensure(r > 0); // "file::write"
count -= r;
result += r;
buffer = static_cast<const u8*>(buffer) + r;
if (!count)
break;
}
2016-02-01 22:55:43 +01:00
return result;
}
2015-04-19 15:19:24 +02:00
2016-02-01 22:55:43 +01:00
u64 seek(s64 offset, seek_mode whence) override
{
if (whence > seek_end)
{
fmt::throw_exception("Invalid whence (0x%x)", whence);
}
2016-02-01 22:55:43 +01:00
const int mode =
whence == seek_set ? SEEK_SET :
whence == seek_cur ? SEEK_CUR : SEEK_END;
2016-02-01 22:55:43 +01:00
const auto result = ::lseek(m_fd, offset, mode);
2017-03-23 19:32:59 +01:00
if (result == -1)
{
g_tls_error = to_error(errno);
return -1;
}
2016-02-01 22:55:43 +01:00
return result;
}
u64 size() override
{
struct ::stat file_info;
ensure(::fstat(m_fd, &file_info) == 0); // "file::size"
2016-02-01 22:55:43 +01:00
return file_info.st_size;
}
2017-08-22 20:05:51 +02:00
2019-04-13 12:46:56 +02:00
native_handle get_handle() override
2017-08-22 20:05:51 +02:00
{
return m_fd;
}
file_id get_id() override
{
struct ::stat file_info;
ensure(::fstat(m_fd, &file_info) == 0); // "file::get_id"
file_id id{"unix_file"};
id.data.resize(sizeof(file_info.st_dev) + sizeof(file_info.st_ino));
std::memcpy(id.data.data(), &file_info.st_dev, sizeof(file_info.st_dev));
std::memcpy(id.data.data() + sizeof(file_info.st_dev), &file_info.st_ino, sizeof(file_info.st_ino));
return id;
}
u64 write_gather(const iovec_clone* buffers, u64 buf_count) override
{
static_assert(sizeof(iovec) == sizeof(iovec_clone), "Weird iovec size");
static_assert(offsetof(iovec, iov_len) == offsetof(iovec_clone, iov_len), "Weird iovec::iov_len offset");
u64 result = 0;
while (buf_count)
{
iovec arg[256];
const auto count = std::min<u64>(buf_count, 256);
std::memcpy(&arg, buffers, sizeof(iovec) * count);
const auto added = ::writev(m_fd, arg, count);
ensure(added != -1); // "file::write_gather"
result += added;
buf_count -= count;
buffers += count;
}
return result;
}
2016-02-01 22:55:43 +01:00
};
m_file = std::make_unique<unix_file>(fd);
2022-01-29 20:10:48 +01:00
if (mode & fs::isfile && !(mode & fs::write) && get_stat().is_directory)
2022-01-29 20:10:48 +01:00
{
m_file.reset();
g_tls_error = error::isdir;
}
2015-04-19 15:19:24 +02:00
#endif
}
2020-12-18 08:39:54 +01:00
fs::file::file(const void* ptr, usz size)
{
class memory_stream : public file_base
2016-01-06 00:52:48 +01:00
{
2016-05-13 16:01:48 +02:00
u64 m_pos{};
const char* const m_ptr;
const u64 m_size;
2016-02-01 22:55:43 +01:00
public:
memory_stream(const void* ptr, u64 size)
: m_ptr(static_cast<const char*>(ptr))
, m_size(size)
2016-01-06 00:52:48 +01:00
{
}
2021-03-30 17:31:46 +02:00
memory_stream(const memory_stream&) = delete;
memory_stream& operator=(const memory_stream&) = delete;
2021-03-05 20:05:37 +01:00
bool trunc(u64) override
2016-02-01 22:55:43 +01:00
{
return false;
2016-02-01 22:55:43 +01:00
}
2016-02-01 22:55:43 +01:00
u64 read(void* buffer, u64 count) override
{
if (m_pos < m_size)
{
// Get readable size
if (const u64 result = std::min<u64>(count, m_size - m_pos))
{
std::memcpy(buffer, m_ptr + m_pos, result);
m_pos += result;
return result;
}
}
return 0;
2016-02-01 22:55:43 +01:00
}
u64 read_at(u64 offset, void* buffer, u64 count) override
{
if (offset < m_size)
{
// Get readable size
if (const u64 result = std::min<u64>(count, m_size - offset))
{
std::memcpy(buffer, m_ptr + offset, result);
return result;
}
}
return 0;
}
2021-03-05 20:05:37 +01:00
u64 write(const void*, u64) override
2016-01-06 00:52:48 +01:00
{
return 0;
2016-01-06 00:52:48 +01:00
}
2016-02-01 22:55:43 +01:00
u64 seek(s64 offset, fs::seek_mode whence) override
{
2017-03-23 19:32:59 +01:00
const s64 new_pos =
whence == fs::seek_set ? offset :
whence == fs::seek_cur ? offset + m_pos :
whence == fs::seek_end ? offset + size() : -1;
2017-03-23 19:32:59 +01:00
if (new_pos < 0)
{
fs::g_tls_error = fs::error::inval;
return -1;
}
m_pos = new_pos;
return m_pos;
2016-02-01 22:55:43 +01:00
}
2015-04-19 15:19:24 +02:00
2016-02-01 22:55:43 +01:00
u64 size() override
{
return m_size;
}
};
2015-04-19 15:19:24 +02:00
2016-02-01 22:55:43 +01:00
m_file = std::make_unique<memory_stream>(ptr, size);
}
2017-08-22 20:05:51 +02:00
fs::native_handle fs::file::get_handle() const
{
if (m_file)
2017-08-22 20:05:51 +02:00
{
2019-04-13 12:46:56 +02:00
return m_file->get_handle();
2017-08-22 20:05:51 +02:00
}
#ifdef _WIN32
return INVALID_HANDLE_VALUE;
#else
return -1;
#endif
}
fs::file_id fs::file::get_id() const
{
if (m_file)
{
return m_file->get_id();
}
return {};
}
2016-02-01 22:55:43 +01:00
bool fs::dir::open(const std::string& path)
{
if (path.empty())
{
// Don't allow opening empty path (TODO)
g_tls_error = fs::error::noent;
return false;
}
2016-02-01 22:55:43 +01:00
if (auto device = get_virtual_device(path))
2015-04-25 21:15:53 +02:00
{
2016-02-01 22:55:43 +01:00
if (auto&& _dir = device->open_dir(path))
{
m_dir = std::move(_dir);
return true;
}
2015-04-25 21:15:53 +02:00
return false;
}
#ifdef _WIN32
WIN32_FIND_DATAW found;
2021-04-09 21:12:47 +02:00
const auto handle = FindFirstFileExW(to_wchar(path + "/*").get(), FindExInfoBasic, &found, FindExSearchNameMatch, nullptr, FIND_FIRST_EX_CASE_SENSITIVE | FIND_FIRST_EX_LARGE_FETCH);
2015-04-25 21:15:53 +02:00
2016-02-01 22:55:43 +01:00
if (handle == INVALID_HANDLE_VALUE)
2015-04-25 22:55:15 +02:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(GetLastError());
2016-02-01 22:55:43 +01:00
return false;
2016-01-06 00:52:48 +01:00
}
2016-02-01 22:55:43 +01:00
class windows_dir final : public dir_base
2016-01-06 00:52:48 +01:00
{
2016-02-01 22:55:43 +01:00
std::vector<dir_entry> m_entries;
2020-12-18 08:39:54 +01:00
usz m_pos = 0;
2016-02-01 22:55:43 +01:00
void add_entry(const WIN32_FIND_DATAW& found)
2016-01-06 00:52:48 +01:00
{
2016-02-01 22:55:43 +01:00
dir_entry info;
2024-01-13 15:42:49 +01:00
info.name = wchar_to_utf8(found.cFileName);
2016-02-01 22:55:43 +01:00
info.is_directory = (found.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
info.is_writable = (found.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
info.size = (static_cast<u64>(found.nFileSizeHigh) << 32) | static_cast<u64>(found.nFileSizeLow);
2016-02-01 22:55:43 +01:00
info.atime = to_time(found.ftLastAccessTime);
info.mtime = to_time(found.ftLastWriteTime);
info.ctime = info.mtime;
2016-02-01 22:55:43 +01:00
if (info.atime < info.mtime)
info.atime = info.mtime;
2016-02-01 22:55:43 +01:00
m_entries.emplace_back(std::move(info));
}
public:
windows_dir(HANDLE handle, WIN32_FIND_DATAW& found)
{
2016-02-01 22:55:43 +01:00
add_entry(found);
2016-01-06 00:52:48 +01:00
while (FindNextFileW(handle, &found))
{
add_entry(found);
}
ensure(ERROR_NO_MORE_FILES == GetLastError()); // "dir::read"
FindClose(handle);
2016-01-06 00:52:48 +01:00
}
2016-02-01 22:55:43 +01:00
bool read(dir_entry& out) override
{
if (m_pos >= m_entries.size())
2016-02-01 22:55:43 +01:00
{
return false;
2016-02-01 22:55:43 +01:00
}
out = m_entries[m_pos++];
return true;
}
2015-04-25 21:15:53 +02:00
2016-02-01 22:55:43 +01:00
void rewind() override
{
m_pos = 0;
}
};
2015-04-25 21:15:53 +02:00
2016-02-01 22:55:43 +01:00
m_dir = std::make_unique<windows_dir>(handle, found);
2015-04-25 21:15:53 +02:00
#else
2016-02-01 22:55:43 +01:00
::DIR* const ptr = ::opendir(path.c_str());
2015-04-25 21:15:53 +02:00
2016-02-01 22:55:43 +01:00
if (!ptr)
2015-04-25 21:15:53 +02:00
{
2016-05-13 16:01:48 +02:00
g_tls_error = to_error(errno);
2015-04-25 21:15:53 +02:00
return false;
}
2016-02-01 22:55:43 +01:00
class unix_dir final : public dir_base
{
::DIR* m_dd;
2015-04-25 21:15:53 +02:00
2016-02-01 22:55:43 +01:00
public:
unix_dir(::DIR* dd)
: m_dd(dd)
{
}
2015-04-25 21:15:53 +02:00
2021-03-30 17:31:46 +02:00
unix_dir(const unix_dir&) = delete;
unix_dir& operator=(const unix_dir&) = delete;
2016-02-01 22:55:43 +01:00
~unix_dir() override
{
::closedir(m_dd);
}
2016-02-01 22:55:43 +01:00
bool read(dir_entry& info) override
{
const auto found = ::readdir(m_dd);
if (!found)
{
return false;
}
struct ::stat file_info;
if (::fstatat(::dirfd(m_dd), found->d_name, &file_info, 0) != 0)
{
//failed metadata (broken symlink?), ignore and skip to next file
return read(info);
}
2016-02-01 22:55:43 +01:00
info.name = found->d_name;
info.is_directory = S_ISDIR(file_info.st_mode);
info.is_writable = file_info.st_mode & 0200; // HACK: approximation
info.size = file_info.st_size;
info.atime = file_info.st_atime;
info.mtime = file_info.st_mtime;
info.ctime = info.mtime;
2016-02-01 22:55:43 +01:00
if (info.atime < info.mtime)
info.atime = info.mtime;
2016-02-01 22:55:43 +01:00
return true;
}
void rewind() override
{
::rewinddir(m_dd);
}
};
m_dir = std::make_unique<unix_dir>(ptr);
#endif
2016-02-01 22:55:43 +01:00
return true;
}
2024-02-15 12:55:08 +01:00
bool fs::file::strict_read_check(u64 offset, u64 _size, u64 type_size) const
{
2024-02-15 12:55:08 +01:00
if (usz pos0 = offset, size0 = size(); (pos0 >= size0 ? 0 : (size0 - pos0)) / type_size < _size)
{
fs::g_tls_error = fs::error::inval;
return false;
}
return true;
}
std::string fs::get_executable_path()
{
// Use magic static
static const std::string s_exe_path = []
{
#if defined(_WIN32)
constexpr DWORD size = 32767;
std::vector<wchar_t> buffer(size);
GetModuleFileNameW(nullptr, buffer.data(), size);
return wchar_to_utf8(buffer.data());
#elif defined(__APPLE__)
char bin_path[PATH_MAX];
uint32_t bin_path_size = sizeof(bin_path);
if (_NSGetExecutablePath(bin_path, &bin_path_size) != 0)
{
std::cerr << "Failed to find app binary path" << std::endl;
return std::string{};
}
// App bundle directory is three levels up from the binary.
return get_parent_dir(bin_path, 3);
#else
if (const char* appimage_path = ::getenv("APPIMAGE"))
{
std::cout << "Found AppImage path: " << appimage_path << std::endl;
return std::string(appimage_path);
}
std::cout << "No AppImage path found, checking for executable" << std::endl;
char exe_path[PATH_MAX];
const ssize_t len = ::readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
if (len == -1)
{
std::cerr << "Failed to find executable path" << std::endl;
return std::string{};
}
exe_path[len] = '\0';
std::cout << "Found exec path: " << exe_path << std::endl;
return std::string(exe_path);
#endif
}();
return s_exe_path;
}
std::string fs::get_executable_dir()
{
// Use magic static
static const std::string s_exe_dir = []
{
std::string exe_path = get_executable_path();
if (exe_path.empty())
{
return exe_path;
}
2024-01-20 23:28:04 +01:00
return get_parent_dir(exe_path) + "/";
}();
return s_exe_dir;
}
2016-01-06 00:52:48 +01:00
const std::string& fs::get_config_dir()
{
2016-02-01 22:55:43 +01:00
// Use magic static
static const std::string s_dir = []
{
std::string dir;
// Check if a portable directory exists.
std::string portable_dir = get_executable_dir() + "/portable/";
if (is_dir(portable_dir))
{
return portable_dir;
}
2017-02-22 14:08:53 +01:00
#ifdef _WIN32
std::vector<wchar_t> buf;
// Check if RPCS3_CONFIG_DIR is set and get the required buffer size
DWORD size = GetEnvironmentVariable(L"RPCS3_CONFIG_DIR", nullptr, 0);
if (size > 0)
2017-02-22 14:08:53 +01:00
{
// Resize buffer and fetch RPCS3_CONFIG_DIR
buf.resize(size);
if (GetEnvironmentVariable(L"RPCS3_CONFIG_DIR", buf.data(), size) != (size - 1))
{
// Clear buffer on failure and notify user
MessageBoxA(nullptr, fmt::format("GetEnvironmentVariable(RPCS3_CONFIG_DIR) failed: error: %s", fmt::win_error{GetLastError(), nullptr}).c_str(), "fs::get_config_dir()", MB_ICONERROR);
buf.clear();
}
}
// Fallback to executable path if needed
for (DWORD buf_size = MAX_PATH; size == 0; buf_size += MAX_PATH)
{
buf.resize(buf_size);
size = GetModuleFileName(nullptr, buf.data(), buf_size);
if (size == 0)
{
MessageBoxA(nullptr, fmt::format("GetModuleFileName() failed: error: %s", fmt::win_error{GetLastError(), nullptr}).c_str(), "fs::get_config_dir()", MB_ICONERROR);
return dir; // empty
}
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
// Try again with increased buffer size
size = 0;
continue;
}
2017-02-22 14:08:53 +01:00
}
dir = wchar_to_utf8(buf.data());
2017-02-22 14:08:53 +01:00
std::replace(dir.begin(), dir.end(), '\\', '/');
dir.resize(dir.rfind('/') + 1);
#else
#ifdef __APPLE__
if (const char* home = ::getenv("HOME"))
dir = home + "/Library/Application Support"s;
#else
if (const char* conf = ::getenv("XDG_CONFIG_HOME"))
dir = conf;
else if (const char* home = ::getenv("HOME"))
dir = home + "/.config"s;
#endif
else // Just in case
dir = "./config";
dir += "/rpcs3/";
if (!create_path(dir))
{
std::printf("Failed to create configuration directory '%s' (%d).\n", dir.c_str(), errno);
}
#endif
return dir;
}();
return s_dir;
}
2016-02-01 22:55:43 +01:00
const std::string& fs::get_cache_dir()
{
static const std::string s_dir = []
{
std::string dir;
#ifdef _WIN32
dir = get_config_dir();
#else
#ifdef __APPLE__
if (const char* home = ::getenv("HOME"))
dir = home + "/Library/Caches"s;
#else
if (const char* cache = ::getenv("XDG_CACHE_HOME"))
dir = cache;
else if (const char* conf = ::getenv("XDG_CONFIG_HOME"))
dir = conf;
else if (const char* home = ::getenv("HOME"))
dir = home + "/.cache"s;
#endif
else // Just in case
dir = "./cache";
dir += "/rpcs3/";
if (!create_path(dir))
{
std::printf("Failed to create configuration directory '%s' (%d).\n", dir.c_str(), errno);
}
#endif
return dir;
}();
return s_dir;
}
const std::string& fs::get_temp_dir()
{
static const std::string s_dir = []
{
std::string dir;
#ifdef _WIN32
wchar_t buf[MAX_PATH + 2]{};
if (GetTempPathW(MAX_PATH + 1, buf) - 1 > MAX_PATH)
{
2023-03-04 11:05:32 +01:00
MessageBoxA(nullptr, fmt::format("GetTempPath() failed: error: %s", fmt::win_error{GetLastError(), nullptr}).c_str(), "fs::get_temp_dir()", MB_ICONERROR);
return dir; // empty
}
2024-01-13 15:42:49 +01:00
dir = wchar_to_utf8(buf);
#else
const char* tmp_dir = getenv("TMPDIR");
if (tmp_dir == nullptr || tmp_dir[0] == '\0')
{
// Fall back to cache directory
dir = get_cache_dir();
}
else
{
dir = tmp_dir;
if (!dir.ends_with("/"))
{
// Ensure path ends with a separator
dir += "/";
}
}
#endif
return dir;
}();
return s_dir;
}
bool fs::remove_all(const std::string& path, bool remove_root, bool is_no_dir_ok)
2016-02-01 22:55:43 +01:00
{
2019-08-12 14:35:57 +02:00
if (const auto root_dir = dir(path))
2016-02-01 22:55:43 +01:00
{
2019-08-12 14:35:57 +02:00
for (const auto& entry : root_dir)
2016-02-01 22:55:43 +01:00
{
2019-08-12 14:35:57 +02:00
if (entry.name == "." || entry.name == "..")
{
continue;
}
2016-02-01 22:55:43 +01:00
if (!entry.is_directory)
{
if (!remove_file(path_append(path, entry.name)))
2019-08-12 14:35:57 +02:00
{
return false;
}
}
else
{
if (!remove_all(path_append(path, entry.name)))
2019-08-12 14:35:57 +02:00
{
return false;
}
}
2016-02-01 22:55:43 +01:00
}
}
2019-08-12 14:35:57 +02:00
else
{
return is_no_dir_ok;
2019-08-12 14:35:57 +02:00
}
2016-06-27 20:53:56 +02:00
if (remove_root)
{
return remove_dir(path);
2016-06-27 20:53:56 +02:00
}
return true;
2016-02-01 22:55:43 +01:00
}
u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment, atomic_t<bool>* cancel_flag)
2016-02-01 22:55:43 +01:00
{
u64 result = 0;
const auto root_dir = dir(path);
if (!root_dir)
{
return -1;
}
for (const auto& entry : root_dir)
2016-02-01 22:55:43 +01:00
{
if (cancel_flag && *cancel_flag)
{
return umax;
}
2016-02-01 22:55:43 +01:00
if (entry.name == "." || entry.name == "..")
{
continue;
}
if (!entry.is_directory)
2016-02-01 22:55:43 +01:00
{
result += utils::align(entry.size, rounding_alignment);
2016-02-01 22:55:43 +01:00
}
else
2016-02-01 22:55:43 +01:00
{
const u64 size = get_dir_size(path_append(path, entry.name), rounding_alignment);
if (size == umax)
{
return size;
}
result += size;
2016-02-01 22:55:43 +01:00
}
}
return result;
}
2018-08-13 00:06:03 +02:00
fs::file fs::make_gather(std::vector<fs::file> files)
{
struct gather_stream : file_base
{
u64 pos = 0;
u64 end = 0;
2021-03-30 17:31:46 +02:00
std::vector<file> files{};
std::map<u64, u64> ends{}; // Fragment End Offset -> Index
2018-08-13 00:06:03 +02:00
gather_stream(std::vector<fs::file> arg)
: files(std::move(arg))
{
// Preprocess files
for (auto&& f : files)
{
end += f.size();
ends.emplace(end, ends.size());
}
}
~gather_stream() override
{
}
fs::stat_t get_stat() override
2018-08-13 00:06:03 +02:00
{
fs::stat_t result{};
if (!files.empty())
{
result = files[0].get_stat();
2018-08-13 00:06:03 +02:00
}
result.is_directory = false;
result.is_writable = false;
result.size = end;
return result;
}
2021-03-05 20:05:37 +01:00
bool trunc(u64) override
2018-08-13 00:06:03 +02:00
{
return false;
}
u64 read(void* buffer, u64 size) override
{
if (pos < end)
{
// Current pos
const u64 start = pos;
// Get readable size
if (const u64 max = std::min<u64>(size, end - pos))
{
u8* buf_out = static_cast<u8*>(buffer);
u64 buf_max = max;
for (auto it = ends.upper_bound(pos); it != ends.end(); ++it)
{
// Set position for the fragment
files[it->second].seek(pos - it->first, fs::seek_end);
const u64 count = std::min<u64>(it->first - pos, buf_max);
const u64 read = files[it->second].read(buf_out, count);
buf_out += count;
buf_max -= count;
pos += read;
if (read < count || buf_max == 0)
{
break;
}
}
return pos - start;
}
}
return 0;
}
u64 read_at(u64 start, void* buffer, u64 size) override
{
if (start < end)
{
u64 pos = start;
// Get readable size
if (const u64 max = std::min<u64>(size, end - pos))
{
u8* buf_out = static_cast<u8*>(buffer);
u64 buf_max = max;
for (auto it = ends.upper_bound(pos); it != ends.end(); ++it)
{
const u64 count = std::min<u64>(it->first - pos, buf_max);
const u64 read = files[it->second].read_at(files[it->second].size() + pos - it->first, buf_out, count);
buf_out += count;
buf_max -= count;
pos += read;
if (read < count || buf_max == 0)
{
break;
}
}
return pos - start;
}
}
return 0;
}
2021-03-05 20:05:37 +01:00
u64 write(const void*, u64) override
2018-08-13 00:06:03 +02:00
{
return 0;
}
u64 seek(s64 offset, seek_mode whence) override
{
const s64 new_pos =
whence == fs::seek_set ? offset :
whence == fs::seek_cur ? offset + pos :
whence == fs::seek_end ? offset + end : -1;
2018-08-13 00:06:03 +02:00
if (new_pos < 0)
{
fs::g_tls_error = fs::error::inval;
return -1;
}
pos = new_pos;
return pos;
}
u64 size() override
{
return end;
}
};
fs::file result;
result.reset(std::make_unique<gather_stream>(std::move(files)));
return result;
}
bool fs::pending_file::open(std::string_view path)
2021-02-21 20:55:07 +01:00
{
file.close();
if (!m_path.empty())
{
fs::remove_file(m_path);
}
if (path.empty())
{
fs::g_tls_error = fs::error::noent;
m_dest.clear();
return false;
}
2021-02-21 20:55:07 +01:00
do
{
m_path = fmt::format(u8"%s/%s.%s.tmp", get_parent_dir(path), path.substr(path.find_last_of(fs::delim) + 1), fmt::base57(utils::get_unique_tsc()));
2021-02-21 20:55:07 +01:00
if (file.open(m_path, fs::create + fs::write + fs::read + fs::excl))
{
2023-11-15 20:07:42 +01:00
#ifdef _WIN32
// Auto-delete pending log file
FILE_DISPOSITION_INFO disp;
disp.DeleteFileW = true;
SetFileInformationByHandle(file.get_handle(), FileDispositionInfo, &disp, sizeof(disp));
#endif
2021-02-21 20:55:07 +01:00
m_dest = path;
break;
}
m_path.clear();
}
while (fs::g_tls_error == fs::error::exist); // Only retry if failed due to existing file
return file.operator bool();
2021-02-21 20:55:07 +01:00
}
fs::pending_file::~pending_file()
{
file.close();
if (!m_path.empty())
{
fs::remove_file(m_path);
}
}
bool fs::pending_file::commit(bool overwrite)
{
if (m_path.empty())
2021-02-21 20:55:07 +01:00
{
fs::g_tls_error = fs::error::noent;
return false;
}
// The temporary file's contents must be on disk before rename
#ifndef _WIN32
if (file)
{
file.sync();
}
#endif
2023-11-15 20:07:42 +01:00
#ifdef _WIN32
// Disable auto-delete
FILE_DISPOSITION_INFO disp;
disp.DeleteFileW = false;
SetFileInformationByHandle(file.get_handle(), FileDispositionInfo, &disp, sizeof(disp));
#endif
2021-02-21 20:55:07 +01:00
file.close();
#ifdef _WIN32
const auto ws1 = to_wchar(m_path);
const auto ws2 = to_wchar(m_dest);
if (MoveFileExW(ws1.get(), ws2.get(), overwrite ? MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH : MOVEFILE_WRITE_THROUGH))
{
// Disable the destructor
m_path.clear();
return true;
}
g_tls_error = to_error(GetLastError());
#else
2021-02-21 20:55:07 +01:00
if (fs::rename(m_path, m_dest, overwrite))
{
// Disable the destructor
m_path.clear();
return true;
}
#endif
2021-02-21 20:55:07 +01:00
return false;
}
stx::generator<fs::dir_entry&> fs::list_dir_recursively(std::string path)
{
for (auto& entry : fs::dir(path))
{
if (entry.name == "." || entry.name == "..")
{
continue;
}
std::string new_path = path_append(path, entry.name);
if (entry.is_directory)
{
for (auto& nested : fs::list_dir_recursively(new_path))
{
co_yield nested;
}
}
entry.name = std::move(new_path);
co_yield entry;
}
}
template<>
void fmt_class_string<fs::seek_mode>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto arg)
{
switch (arg)
{
STR_CASE(fs::seek_mode::seek_set);
STR_CASE(fs::seek_mode::seek_cur);
STR_CASE(fs::seek_mode::seek_end);
}
return unknown;
});
}
template<>
void fmt_class_string<fs::error>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto arg)
{
switch (arg)
{
case fs::error::ok: return "OK";
case fs::error::inval: return "Invalid arguments";
case fs::error::noent: return "Not found";
case fs::error::exist: return "Already exists";
2017-03-23 19:32:59 +01:00
case fs::error::acces: return "Access violation";
2017-09-12 19:05:38 +02:00
case fs::error::notempty: return "Not empty";
2019-09-02 04:50:44 +02:00
case fs::error::readonly: return "Read only";
case fs::error::isdir: return "Is a directory";
case fs::error::toolong: return "Path too long";
2020-05-02 08:04:05 +02:00
case fs::error::nospace: return "Not enough space on the device";
2023-07-21 11:06:46 +02:00
case fs::error::xdev: return "Device mismatch";
2020-03-07 09:18:23 +01:00
case fs::error::unknown: return "Unknown system error";
}
return unknown;
});
}
template<>
void fmt_class_string<fs::file_id>::format(std::string& out, u64 arg)
{
const fs::file_id& id = get_object(arg);
// TODO: Format data
fmt::append(out, "{type='%s'}", id.type);
}