mirror of https://github.com/InoriRus/Kyty.git
Merge 274d514e4b
into 4733b7e1c9
This commit is contained in:
commit
b83f575b21
|
@ -0,0 +1,3 @@
|
|||
# These are supported funding model platforms
|
||||
|
||||
github:[Smiril,InoriRus] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
|
@ -1,3 +1,4 @@
|
|||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
.idea/
|
||||
.DS_Stor*
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
PS3='Please enter your choice: '
|
||||
options=("Debug" "Debug Final" "Release" "Release Final" "Exit")
|
||||
select opt in "${options[@]}"
|
||||
do
|
||||
case $opt in
|
||||
"Debug")
|
||||
DirName=_DebugMacOSMakeClang
|
||||
Options="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX=_bin ../../source"
|
||||
;;
|
||||
"Debug Final")
|
||||
DirName=_DebugFinalMacOSMakeClang
|
||||
Options="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -D CMAKE_BUILD_TYPE=Debug -D KYTY_FINAL=1 -D CMAKE_INSTALL_PREFIX=_bin ../../source"
|
||||
;;
|
||||
"Release")
|
||||
DirName=_ReleaseMacOSMakeClang
|
||||
Options="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=_bin ../../source"
|
||||
;;
|
||||
"Release Final")
|
||||
DirName=_ReleaseFinalMacOSMakeClang
|
||||
Options="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -D CMAKE_BUILD_TYPE=Release -D KYTY_FINAL=1 -D CMAKE_INSTALL_PREFIX=_bin ../../source"
|
||||
;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
|
||||
if [ -z "$DirName" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
mkdir $DirName
|
||||
cd $DirName
|
||||
echo make >_build
|
||||
echo make install/strip >>_build
|
||||
chmod +x _build
|
||||
cmake -G "Unix Makefiles" $Options
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
PS3='Please enter your choice: '
|
||||
options=("Debug" "Debug Final" "Release" "Release Final" "Exit")
|
||||
select opt in "${options[@]}"
|
||||
do
|
||||
case $opt in
|
||||
"Debug")
|
||||
DirName=_DebugMacOSMakeGcc
|
||||
Options="-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX=_bin ../../source"
|
||||
;;
|
||||
"Debug Final")
|
||||
DirName=_DebugFinalMacOSMakeGcc
|
||||
Options="-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -D CMAKE_BUILD_TYPE=Debug -D KYTY_FINAL=1 -D CMAKE_INSTALL_PREFIX=_bin ../../source"
|
||||
;;
|
||||
"Release")
|
||||
DirName=_ReleaseMacOSMakeGcc
|
||||
Options="-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=_bin ../../source"
|
||||
;;
|
||||
"Release Final")
|
||||
DirName=_ReleaseFinalMacOSMakeGcc
|
||||
Options="-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -D CMAKE_BUILD_TYPE=Release -D KYTY_FINAL=1 -D CMAKE_INSTALL_PREFIX=_bin ../../source"
|
||||
;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
|
||||
if [ -z "$DirName" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
mkdir $DirName
|
||||
cd $DirName
|
||||
echo make >_build
|
||||
echo make install/strip >>_build
|
||||
chmod +x _build
|
||||
cmake -G "Unix Makefiles" $Options
|
|
@ -62,22 +62,15 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(EASY_PROFILER_VERSION_MAJOR) || !defined(EASY_PROFILER_VERSION_MINOR) || !defined(EASY_PROFILER_VERSION_PATCH)
|
||||
# ifdef _WIN32
|
||||
# error EASY_PROFILER_VERSION_MAJOR and EASY_PROFILER_VERSION_MINOR and EASY_PROFILER_VERSION_PATCH macros must be defined
|
||||
# else
|
||||
# error "EASY_PROFILER_VERSION_MAJOR and EASY_PROFILER_VERSION_MINOR and EASY_PROFILER_VERSION_PATCH macros must be defined"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define EASY_PROFILER_PRODUCT_VERSION "v" EASY_STRINGIFICATION(EASY_PROFILER_VERSION_MAJOR) "." \
|
||||
EASY_STRINGIFICATION(EASY_PROFILER_VERSION_MINOR) "." \
|
||||
EASY_STRINGIFICATION(EASY_PROFILER_VERSION_PATCH)
|
||||
#define EASY_PROFILER_PRODUCT_VERSION "v" EASY_STRINGIFICATION(EASY_PROFILER_VERSION) "." \
|
||||
EASY_STRINGIFICATION(EASY_PROFILER_VERSION) "." \
|
||||
EASY_STRINGIFICATION(EASY_PROFILER_VERSION)
|
||||
|
||||
extern const uint32_t EASY_PROFILER_SIGNATURE = ('E' << 24) | ('a' << 16) | ('s' << 8) | 'y';
|
||||
extern const uint32_t EASY_PROFILER_VERSION = (static_cast<uint32_t>(EASY_PROFILER_VERSION_MAJOR) << 24) |
|
||||
(static_cast<uint32_t>(EASY_PROFILER_VERSION_MINOR) << 16) |
|
||||
static_cast<uint32_t>(EASY_PROFILER_VERSION_PATCH);
|
||||
extern const uint32_t EASY_PROFILER_VERSION = (static_cast<uint32_t>(EASY_PROFILER_VERSION) << 24) |
|
||||
(static_cast<uint32_t>(EASY_PROFILER_VERSION) << 16) |
|
||||
static_cast<uint32_t>(EASY_PROFILER_VERSION);
|
||||
|
||||
#undef EASY_VERSION_INT
|
||||
|
||||
|
@ -85,29 +78,6 @@ extern const uint32_t EASY_PROFILER_VERSION = (static_cast<uint32_t>(EASY_PROFIL
|
|||
|
||||
extern "C" {
|
||||
|
||||
PROFILER_API uint8_t versionMajor()
|
||||
{
|
||||
static_assert(0 <= EASY_PROFILER_VERSION_MAJOR && EASY_PROFILER_VERSION_MAJOR <= 255,
|
||||
"EASY_PROFILER_VERSION_MAJOR must be defined in range [0, 255]");
|
||||
|
||||
return EASY_PROFILER_VERSION_MAJOR;
|
||||
}
|
||||
|
||||
PROFILER_API uint8_t versionMinor()
|
||||
{
|
||||
static_assert(0 <= EASY_PROFILER_VERSION_MINOR && EASY_PROFILER_VERSION_MINOR <= 255,
|
||||
"EASY_PROFILER_VERSION_MINOR must be defined in range [0, 255]");
|
||||
|
||||
return EASY_PROFILER_VERSION_MINOR;
|
||||
}
|
||||
|
||||
PROFILER_API uint16_t versionPatch()
|
||||
{
|
||||
static_assert(0 <= EASY_PROFILER_VERSION_PATCH && EASY_PROFILER_VERSION_PATCH <= 65535,
|
||||
"EASY_PROFILER_VERSION_PATCH must be defined in range [0, 65535]");
|
||||
|
||||
return EASY_PROFILER_VERSION_PATCH;
|
||||
}
|
||||
|
||||
PROFILER_API uint32_t version()
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -53,7 +53,7 @@
|
|||
static const AudioObjectPropertyAddress devlist_address = {
|
||||
kAudioHardwarePropertyDevices,
|
||||
kAudioObjectPropertyScopeGlobal,
|
||||
kAudioObjectPropertyElementMaster
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
|
||||
typedef void (*addDevFn)(const char *name, SDL_AudioSpec *spec, const int iscapture, AudioDeviceID devId, void *data);
|
||||
|
@ -131,17 +131,17 @@ build_device_list(int iscapture, addDevFn addfn, void *addfndata)
|
|||
const AudioObjectPropertyAddress addr = {
|
||||
kAudioDevicePropertyStreamConfiguration,
|
||||
iscapture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMaster
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
const AudioObjectPropertyAddress nameaddr = {
|
||||
kAudioObjectPropertyName,
|
||||
iscapture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMaster
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
const AudioObjectPropertyAddress freqaddr = {
|
||||
kAudioDevicePropertyNominalSampleRate,
|
||||
iscapture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMaster
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
|
||||
result = AudioObjectGetPropertyDataSize(dev, &addr, 0, NULL, &size);
|
||||
|
@ -635,7 +635,7 @@ static const AudioObjectPropertyAddress alive_address =
|
|||
{
|
||||
kAudioDevicePropertyDeviceIsAlive,
|
||||
kAudioObjectPropertyScopeGlobal,
|
||||
kAudioObjectPropertyElementMaster
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
|
||||
static OSStatus
|
||||
|
@ -756,7 +756,7 @@ prepare_device(_THIS)
|
|||
AudioObjectPropertyAddress addr = {
|
||||
0,
|
||||
kAudioObjectPropertyScopeGlobal,
|
||||
kAudioObjectPropertyElementMaster
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
|
||||
if (handle == NULL) {
|
||||
|
@ -803,7 +803,7 @@ assign_device_to_audioqueue(_THIS)
|
|||
const AudioObjectPropertyAddress prop = {
|
||||
kAudioDevicePropertyDeviceUID,
|
||||
this->iscapture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMaster
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
|
||||
OSStatus result;
|
||||
|
@ -952,7 +952,7 @@ audioqueue_thread(void *arg)
|
|||
const AudioObjectPropertyAddress default_device_address = {
|
||||
this->iscapture ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice,
|
||||
kAudioObjectPropertyScopeGlobal,
|
||||
kAudioObjectPropertyElementMaster
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
|
||||
if (this->handle == NULL) { /* opened the default device? Register to know if the user picks a new default. */
|
||||
|
|
|
@ -167,7 +167,7 @@ SDL_SYS_HapticInit(void)
|
|||
}
|
||||
|
||||
/* Now search I/O Registry for matching devices. */
|
||||
result = IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iter);
|
||||
result = IOServiceGetMatchingServices(kIOMainPortDefault, match, &iter);
|
||||
if (result != kIOReturnSuccess) {
|
||||
return SDL_SetError("Haptic: Couldn't create a HID object iterator.");
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ HIDAPI_InitializeDiscovery()
|
|||
#endif /* defined(__WIN32__) || defined(__WINGDK__) */
|
||||
|
||||
#if defined(__MACOSX__)
|
||||
SDL_HIDAPI_discovery.m_notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
|
||||
SDL_HIDAPI_discovery.m_notificationPort = IONotificationPortCreate(kIOMainPortDefault);
|
||||
if (SDL_HIDAPI_discovery.m_notificationPort) {
|
||||
{
|
||||
io_iterator_t portIterator = 0;
|
||||
|
|
|
@ -415,7 +415,7 @@ IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controlle
|
|||
device->nhats = 1; /* d-pad */
|
||||
device->nbuttons = nbuttons;
|
||||
|
||||
} else if (controller.gamepad) {
|
||||
} else if (controller.extendedGamepad) {
|
||||
BOOL is_switch_joyconL = IsControllerSwitchJoyConL(controller);
|
||||
BOOL is_switch_joyconR = IsControllerSwitchJoyConR(controller);
|
||||
int nbuttons = 0;
|
||||
|
@ -606,8 +606,8 @@ IOS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
|
|||
if (device->controller) {
|
||||
/* The controller was explicitly retained in the struct, so it
|
||||
* should be explicitly released before freeing the struct. */
|
||||
GCController *controller = CFBridgingRelease((__bridge CFTypeRef)(device->controller));
|
||||
controller.controllerPausedHandler = nil;
|
||||
//GCController *controller = CFBridgingRelease((__bridge CFTypeRef)(device->controller));
|
||||
//controller.controllerPausedHandler = nil;
|
||||
device->controller = nil;
|
||||
}
|
||||
}
|
||||
|
@ -816,12 +816,12 @@ IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
|||
} else {
|
||||
#ifdef SDL_JOYSTICK_MFI
|
||||
if (device->uses_pause_handler) {
|
||||
GCController *controller = device->controller;
|
||||
controller.controllerPausedHandler = ^(GCController *c) {
|
||||
if (joystick->hwdata) {
|
||||
++joystick->hwdata->num_pause_presses;
|
||||
}
|
||||
};
|
||||
//GCController *controller = device->controller;
|
||||
//controller.controllerPausedHandler = ^(GCController *c) {
|
||||
// if (joystick->hwdata) {
|
||||
// ++joystick->hwdata->num_pause_presses;
|
||||
// }
|
||||
//};
|
||||
}
|
||||
|
||||
#ifdef ENABLE_MFI_SENSORS
|
||||
|
@ -1089,8 +1089,8 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
|
|||
}
|
||||
#endif /* ENABLE_MFI_SENSORS */
|
||||
|
||||
} else if (controller.gamepad) {
|
||||
GCGamepad *gamepad = controller.gamepad;
|
||||
} else if (controller.extendedGamepad) {
|
||||
GCExtendedGamepad *gamepad = controller.extendedGamepad;
|
||||
|
||||
/* Button order matches the XInput Windows mappings. */
|
||||
Uint8 buttons[joystick->nbuttons];
|
||||
|
@ -1595,7 +1595,7 @@ IOS_JoystickClose(SDL_Joystick *joystick)
|
|||
} else if (device->controller) {
|
||||
#ifdef SDL_JOYSTICK_MFI
|
||||
GCController *controller = device->controller;
|
||||
controller.controllerPausedHandler = nil;
|
||||
//controller.controllerPausedHandler = nil;
|
||||
controller.playerIndex = -1;
|
||||
|
||||
#ifdef ENABLE_MFI_SYSTEM_GESTURE_STATE
|
||||
|
@ -1711,8 +1711,8 @@ GetDirectionalPadForController(GCController *controller)
|
|||
return controller.extendedGamepad.dpad;
|
||||
}
|
||||
|
||||
if (controller.gamepad) {
|
||||
return controller.gamepad.dpad;
|
||||
if (controller.extendedGamepad) {
|
||||
return controller.extendedGamepad.dpad;
|
||||
}
|
||||
|
||||
if (controller.microGamepad) {
|
||||
|
|
|
@ -288,10 +288,9 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
|
|||
*/
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
|
||||
/* Get more aggressive for Catalina: activate the Dock first so we definitely reset all activation state. */
|
||||
for (NSRunningApplication *i in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"]) {
|
||||
[i activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
||||
break;
|
||||
}
|
||||
//for (NSRunningApplication *i in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"]) {
|
||||
// break;
|
||||
//}
|
||||
SDL_Delay(300); /* !!! FIXME: this isn't right. */
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
|
|
@ -123,25 +123,19 @@ static Uint32
|
|||
GetDisplayModePixelFormat(CGDisplayModeRef vidmode)
|
||||
{
|
||||
/* This API is deprecated in 10.11 with no good replacement (as of 10.15). */
|
||||
CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
|
||||
Uint32 pixelformat = SDL_PIXELFORMAT_UNKNOWN;
|
||||
|
||||
if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels),
|
||||
kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||
pixelformat = SDL_PIXELFORMAT_ARGB8888;
|
||||
} else if (CFStringCompare(fmt, CFSTR(IO16BitDirectPixels),
|
||||
kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||
pixelformat = SDL_PIXELFORMAT_ARGB1555;
|
||||
} else if (CFStringCompare(fmt, CFSTR(kIO30BitDirectPixels),
|
||||
kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||
pixelformat = SDL_PIXELFORMAT_ARGB2101010;
|
||||
} else {
|
||||
/* ignore 8-bit and such for now. */
|
||||
//CGDisplayModeRef vidmode = CGDisplayCopyDisplayMode(eDisplay);
|
||||
CFDictionaryRef dict = (CFDictionaryRef)*((int64_t *)vidmode + 2);
|
||||
CFTypeRef num;
|
||||
Uint32 bpp = 0;
|
||||
if (CFGetTypeID(dict) == CFDictionaryGetTypeID()
|
||||
&& CFDictionaryGetValueIfPresent(dict, kCGDisplayBitsPerPixel, (const void**)&num))
|
||||
{
|
||||
CFNumberGetValue(num, kCFNumberSInt32Type, (void*)&bpp);
|
||||
}
|
||||
|
||||
CFRelease(fmt);
|
||||
CFRelease(num);
|
||||
|
||||
return pixelformat;
|
||||
return bpp;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
|
|
|
@ -161,7 +161,7 @@
|
|||
{ @autoreleasepool
|
||||
{
|
||||
NSPasteboard *pasteboard = [sender draggingPasteboard];
|
||||
NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
|
||||
NSArray *types = [NSArray arrayWithObject:NSPasteboardTypeFileURL];
|
||||
NSString *desiredType = [pasteboard availableTypeFromArray:types];
|
||||
SDL_Window *sdlwindow = [self findSDLWindow];
|
||||
NSData *data;
|
||||
|
@ -179,8 +179,8 @@
|
|||
return NO;
|
||||
}
|
||||
|
||||
SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
|
||||
array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
|
||||
SDL_assert([desiredType isEqualToString:NSPasteboardTypeFileURL]);
|
||||
array = [pasteboard propertyListForType:@"NSPasteboardTypeFileURL"];
|
||||
|
||||
/* Code addon to update the mouse location */
|
||||
point = [sender draggingLocation];
|
||||
|
@ -1678,7 +1678,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, NSView *nsview,
|
|||
/* Prevents the window's "window device" from being destroyed when it is
|
||||
* hidden. See http://www.mikeash.com/pyblog/nsopenglcontext-and-one-shot.html
|
||||
*/
|
||||
[nswindow setOneShot:NO];
|
||||
//[nswindow setOneShot:NO];
|
||||
|
||||
/* All done! */
|
||||
window->driverdata = (void *)CFBridgingRetain(data);
|
||||
|
|
|
@ -33,6 +33,7 @@ clr::blue::operator const char*() { return "\x1b[34m"; }
|
|||
|
||||
} // namespace spvtools
|
||||
#elif defined(SPIRV_WINDOWS)
|
||||
#if defined(WIN32)
|
||||
#include <windows.h>
|
||||
|
||||
namespace spvtools {
|
||||
|
@ -107,6 +108,7 @@ clr::blue::operator const char*() {
|
|||
}
|
||||
|
||||
} // namespace spvtools
|
||||
#endif
|
||||
#else
|
||||
namespace spvtools {
|
||||
|
||||
|
|
|
@ -6,9 +6,6 @@ if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
|
|||
set(LINUX TRUE)
|
||||
endif()
|
||||
|
||||
if (NOT ((WIN32 AND (MINGW OR MSVC)) OR LINUX))
|
||||
message(FATAL_ERROR "only mingw and msvc supported (or linux)")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
|
|
@ -1649,7 +1649,7 @@ int KYTY_SYSV_ABI Ngs2SystemCreateWithAllocator(const Ngs2SystemOption* option,
|
|||
printf("\t sample_rate = %u\n", option->sample_rate);
|
||||
printf("\t alloc_handler = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(allocator->alloc_handler));
|
||||
printf("\t free_handler = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(allocator->free_handler));
|
||||
printf("\t user_data = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(allocator->user_data));
|
||||
//printf("\t user_data = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(allocator->user_data));
|
||||
|
||||
Ngs2ContextBufferInfo buf {};
|
||||
buf.host_buffer = nullptr;
|
||||
|
@ -1697,7 +1697,7 @@ int KYTY_SYSV_ABI Ngs2RackCreate(uintptr_t system_handle, uint32_t rack_id, cons
|
|||
printf("\t max_matrices = %u\n", option->max_matrices);
|
||||
printf("\t max_ports = %u\n", option->max_ports);
|
||||
printf("\t host_buffer = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(buffer_info->host_buffer));
|
||||
printf("\t host_buffer_size = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(buffer_info->host_buffer_size));
|
||||
//printf("\t host_buffer_size = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(buffer_info->host_buffer_size));
|
||||
|
||||
auto* ngs = reinterpret_cast<Ngs2Internal*>(system_handle);
|
||||
auto* rack = static_cast<Ngs2RackInternal*>(buffer_info->host_buffer);
|
||||
|
@ -1779,7 +1779,7 @@ int KYTY_SYSV_ABI Ngs2RackCreateWithAllocator(uintptr_t system_handle, uint32_t
|
|||
printf("\t max_ports = %u\n", option->max_ports);
|
||||
printf("\t alloc_handler = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(allocator->alloc_handler));
|
||||
printf("\t free_handler = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(allocator->free_handler));
|
||||
printf("\t user_data = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(allocator->user_data));
|
||||
//printf("\t user_data = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(allocator->user_data));
|
||||
|
||||
Ngs2ContextBufferInfo buf {};
|
||||
buf.host_buffer = nullptr;
|
||||
|
|
|
@ -847,7 +847,7 @@ int KYTY_SYSV_ABI KernelMprotect(const void* addr, size_t len, int prot)
|
|||
auto vaddr = reinterpret_cast<uint64_t>(addr);
|
||||
|
||||
printf("\t addr = 0x%016" PRIx64 "\n", vaddr);
|
||||
printf("\t len = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(len));
|
||||
//printf("\t len = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(len));
|
||||
|
||||
VirtualMemory::Mode mode = VirtualMemory::Mode::NoAccess;
|
||||
Graphics::GpuMemoryMode gpu_mode = Graphics::GpuMemoryMode::NoAccess;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include <pthread.h>
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
#if defined(__WIN64__)
|
||||
#include <pthread_time.h>
|
||||
#endif
|
||||
|
||||
|
@ -380,7 +380,7 @@ static void pthread_attr_dbg_print(const PthreadAttr* src)
|
|||
printf("\tsched_priority = %d\n", param.sched_priority);
|
||||
printf("\tpolicy = %d\n", policy);
|
||||
printf("\tstack_addr = 0x%016" PRIx64 "\n", reinterpret_cast<uint64_t>(stack_addr));
|
||||
printf("\tstack_size = %" PRIu64 "\n", reinterpret_cast<uint64_t>(stack_size));
|
||||
//printf("\tstack_size = %" PRIu64 "\n", reinterpret_cast<uint64_t>(stack_size));
|
||||
}
|
||||
|
||||
static void usec_to_timespec(struct timespec* ts, KernelUseconds usec)
|
||||
|
@ -1434,7 +1434,7 @@ int KYTY_SYSV_ABI PthreadRwlockTimedrdlock(PthreadRwlock* rwlock, KernelUseconds
|
|||
timespec t {};
|
||||
usec_to_timespec(&t, usec);
|
||||
|
||||
int result = pthread_rwlock_timedrdlock(&(*rwlock)->p, &t);
|
||||
int result = pthread_rwlock_timedrdlock(&(*rwlock)->p,&t);
|
||||
|
||||
// printf("\trwlock timedrdlock: %s, %d\n", (*rwlock)->name.C_Str(), result);
|
||||
|
||||
|
@ -1462,7 +1462,8 @@ int KYTY_SYSV_ABI PthreadRwlockTimedwrlock(PthreadRwlock* rwlock, KernelUseconds
|
|||
timespec t {};
|
||||
usec_to_timespec(&t, usec);
|
||||
|
||||
int result = pthread_rwlock_timedwrlock(&(*rwlock)->p, &t);
|
||||
|
||||
int result = pthread_rwlock_timedrdlock(&(*rwlock)->p,&t);
|
||||
|
||||
// printf("\trwlock timedwrlock: %s, %d\n", (*rwlock)->name.C_Str(), result);
|
||||
|
||||
|
@ -1480,12 +1481,12 @@ int KYTY_SYSV_ABI PthreadRwlockTryrdlock(PthreadRwlock* rwlock)
|
|||
{
|
||||
PRINT_NAME();
|
||||
|
||||
if (rwlock == nullptr)
|
||||
if (rwlock == 0)
|
||||
{
|
||||
return KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
EXIT_NOT_IMPLEMENTED(*rwlock == nullptr);
|
||||
EXIT_NOT_IMPLEMENTED(*rwlock == 0);
|
||||
|
||||
int result = pthread_rwlock_tryrdlock(&(*rwlock)->p);
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef SYS_MACOS_INCLUDE_KYTY_SYSDBG_H_
|
||||
#define SYS_MACOS_INCLUDE_KYTY_SYSDBG_H_
|
||||
|
||||
// IWYU pragma: private
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sys_dbg_stack_info_t
|
||||
{
|
||||
uintptr_t code_addr;
|
||||
uintptr_t addr;
|
||||
uintptr_t commited_addr;
|
||||
size_t commited_size;
|
||||
size_t total_size;
|
||||
size_t code_size;
|
||||
};
|
||||
|
||||
using exception_filter_func_t = void (*)(void* addr);
|
||||
|
||||
void sys_stack_walk(void** stack, int* depth);
|
||||
void sys_stack_usage(sys_dbg_stack_info_t& s);
|
||||
void sys_stack_usage_print(sys_dbg_stack_info_t& stack);
|
||||
void sys_get_code_info(uintptr_t* addr, size_t* size);
|
||||
void sys_set_exception_filter(exception_filter_func_t func);
|
||||
|
||||
} // namespace Kyty
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* SYS_MACOS_INCLUDE_KYTY_SYSDBG_H_ */
|
|
@ -0,0 +1,108 @@
|
|||
#ifndef SYS_MACOS_INCLUDE_KYTY_SYSFILEIO_H_
|
||||
#define SYS_MACOS_INCLUDE_KYTY_SYSFILEIO_H_
|
||||
|
||||
// IWYU pragma: private
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include "Kyty/Core/String.h"
|
||||
#include "Kyty/Sys/MacOS/SysMacOSTimer.h"
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
enum sys_file_type_t
|
||||
{
|
||||
SYS_FILE_ERROR, // NOLINT(readability-identifier-naming)
|
||||
SYS_FILE_MEMORY_STAT, // NOLINT(readability-identifier-naming)
|
||||
SYS_FILE_FILE, // NOLINT(readability-identifier-naming)
|
||||
SYS_FILE_MEMORY_DYN // NOLINT(readability-identifier-naming)
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
enum sys_file_cache_type_t
|
||||
{
|
||||
SYS_FILE_CACHE_AUTO = 0, // NOLINT(readability-identifier-naming)
|
||||
SYS_FILE_CACHE_RANDOM_ACCESS = 1, // NOLINT(readability-identifier-naming)
|
||||
SYS_FILE_CACHE_SEQUENTIAL_SCAN = 2 // NOLINT(readability-identifier-naming)
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sys_file_mem_buf_t
|
||||
{
|
||||
uint8_t* base;
|
||||
uint8_t* ptr;
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sys_file_t
|
||||
{
|
||||
sys_file_type_t type;
|
||||
union
|
||||
{
|
||||
FILE* f;
|
||||
sys_file_mem_buf_t* buf;
|
||||
};
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sys_file_find_t
|
||||
{
|
||||
String path_with_name;
|
||||
SysFileTimeStruct last_access_time;
|
||||
SysFileTimeStruct last_write_time;
|
||||
uint64_t size;
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sys_dir_entry_t
|
||||
{
|
||||
String name;
|
||||
bool is_file;
|
||||
};
|
||||
|
||||
void sys_file_read(void* data, uint32_t size, sys_file_t& f, uint32_t* bytes_read = nullptr);
|
||||
void sys_file_write(const void* data, uint32_t size, sys_file_t& f, uint32_t* bytes_written = nullptr);
|
||||
void sys_file_read_r(void* data, uint32_t size, sys_file_t& f);
|
||||
void sys_file_write_r(const void* data, uint32_t size, sys_file_t& f);
|
||||
sys_file_t* sys_file_create(const String& file_name);
|
||||
sys_file_t* sys_file_open_r(const String& file_name, sys_file_cache_type_t cache_type = SYS_FILE_CACHE_AUTO);
|
||||
sys_file_t* sys_file_open_w(const String& file_name, sys_file_cache_type_t cache_type = SYS_FILE_CACHE_AUTO);
|
||||
sys_file_t* sys_file_open(uint8_t* buf, uint32_t buf_size);
|
||||
sys_file_t* sys_file_create();
|
||||
sys_file_t* sys_file_open_rw(const String& file_name, sys_file_cache_type_t cache_type = SYS_FILE_CACHE_AUTO);
|
||||
void sys_file_close(sys_file_t* f);
|
||||
uint64_t sys_file_size(sys_file_t& f);
|
||||
bool sys_file_seek(sys_file_t& f, uint64_t offset);
|
||||
uint64_t sys_file_tell(sys_file_t& f);
|
||||
bool sys_file_truncate(sys_file_t& f, uint64_t size);
|
||||
void sys_file_write(uint32_t n, sys_file_t& f);
|
||||
void sys_file_write_r(uint32_t n, sys_file_t& f);
|
||||
uint64_t sys_file_size(const String& file_name);
|
||||
bool sys_file_is_error(sys_file_t& f);
|
||||
bool sys_file_io_init();
|
||||
bool sys_file_is_directory_existing(const String& path);
|
||||
bool sys_file_is_file_existing(const String& name);
|
||||
bool sys_file_create_directory(const String& path);
|
||||
bool sys_file_delete_directory(const String& path);
|
||||
bool sys_file_delete_file(const String& name);
|
||||
bool sys_file_flush(sys_file_t& f);
|
||||
SysFileTimeStruct sys_file_get_last_access_time_utc(const String& name);
|
||||
SysFileTimeStruct sys_file_get_last_write_time_utc(const String& name);
|
||||
void sys_file_get_last_access_and_write_time_utc(const String& name, SysFileTimeStruct& a, SysFileTimeStruct& w);
|
||||
void sys_file_get_last_access_and_write_time_utc(sys_file_t& f, SysFileTimeStruct& a, SysFileTimeStruct& w);
|
||||
bool sys_file_set_last_access_time_utc(const String& name, SysFileTimeStruct& access);
|
||||
bool sys_file_set_last_write_time_utc(const String& name, SysFileTimeStruct& write);
|
||||
bool sys_file_set_last_access_and_write_time_utc(const String& name, SysFileTimeStruct& access, SysFileTimeStruct& write);
|
||||
void sys_file_find_files(const String& path, Kyty::Vector<sys_file_find_t>& out);
|
||||
void sys_file_get_dents(const String& path, Kyty::Vector<sys_dir_entry_t>& out);
|
||||
bool sys_file_copy_file(const String& src, const String& dst);
|
||||
bool sys_file_move_file(const String& src, const String& dst);
|
||||
void sys_file_remove_readonly(const String& name);
|
||||
|
||||
} // namespace Kyty
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* SYS_LINUX_INCLUDE_KYTY_SYSFILEIO_H_ */
|
|
@ -0,0 +1,102 @@
|
|||
#ifndef SYS_MACOS_INCLUDE_KYTY_SYSHEAP_H_
|
||||
#define SYS_MACOS_INCLUDE_KYTY_SYSHEAP_H_
|
||||
|
||||
// IWYU pragma: private
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include "Kyty/Sys/MacOS/SysMacOSSync.h"
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
using sys_heap_id_t = SysCS*;
|
||||
|
||||
inline sys_heap_id_t sys_heap_create()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline sys_heap_id_t sys_heap_deafult()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void* sys_heap_alloc(sys_heap_id_t /*heap_id*/, size_t size)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
void* m = malloc(size);
|
||||
|
||||
EXIT_IF(m == 0);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void* sys_heap_realloc(sys_heap_id_t /*heap_id*/, void* p, size_t size)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
void* m = p != 0 ? realloc(p, size) : malloc(size);
|
||||
|
||||
if (m == 0)
|
||||
{
|
||||
EXIT_IF(m == 0);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void sys_heap_free(sys_heap_id_t /*heap_id*/, void* p)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
free(p);
|
||||
}
|
||||
|
||||
inline sys_heap_id_t sys_heap_create_s()
|
||||
{
|
||||
auto* cs = new SysCS;
|
||||
cs->Init();
|
||||
return cs;
|
||||
}
|
||||
|
||||
inline void* sys_heap_alloc_s(sys_heap_id_t heap_id, size_t size)
|
||||
{
|
||||
heap_id->Enter();
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
void* m = malloc(size);
|
||||
|
||||
heap_id->Leave();
|
||||
|
||||
EXIT_IF(m == 0);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void* sys_heap_realloc_s(sys_heap_id_t heap_id, void* p, size_t size)
|
||||
{
|
||||
heap_id->Enter();
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
void* m = p != 0 ? realloc(p, size) : malloc(size);
|
||||
|
||||
heap_id->Leave();
|
||||
|
||||
EXIT_IF(m == 0);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void sys_heap_free_s(sys_heap_id_t heap_id, void* p)
|
||||
{
|
||||
heap_id->Enter();
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
free(p);
|
||||
|
||||
heap_id->Leave();
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* SYS_MACOS_INCLUDE_KYTY_SYSHEAP_H_ */
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef SYS_MACOS_INCLUDE_KYTY_SYSSTDIO_H_
|
||||
#define SYS_MACOS_INCLUDE_KYTY_SYSSTDIO_H_
|
||||
|
||||
// IWYU pragma: private
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
//#include <stdio.h>
|
||||
#include <cstdarg>
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
inline uint32_t sys_vscprintf(const char* format, va_list argptr)
|
||||
{
|
||||
va_list argcopy;
|
||||
va_copy(argcopy, argptr);
|
||||
int len = vsnprintf(nullptr, 0, format, argcopy);
|
||||
va_end(argcopy);
|
||||
return len < 0 ? 0 : len;
|
||||
}
|
||||
|
||||
inline uint32_t sys_vsnprintf(char* dest, size_t count, const char* format, va_list args)
|
||||
{
|
||||
int len = vsnprintf(dest, count + 1, format, args);
|
||||
return len < 0 ? 0 : len;
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* SYS_MACOS_INCLUDE_KYTY_SYSSTDIO_H_ */
|
|
@ -0,0 +1,53 @@
|
|||
#ifndef SYS_MACOS_INCLUDE_KYTY_SYSSTDLIB_H_
|
||||
#define SYS_MACOS_INCLUDE_KYTY_SYSSTDLIB_H_
|
||||
|
||||
// IWYU pragma: private
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
inline float sys_strtof(const char* nptr, char** endptr)
|
||||
{
|
||||
return strtof(nptr, endptr);
|
||||
}
|
||||
|
||||
inline double sys_strtod(const char* nptr, char** endptr)
|
||||
{
|
||||
return strtod(nptr, endptr);
|
||||
}
|
||||
|
||||
inline int32_t sys_strtoi32(const char* nptr, char** endptr, int base)
|
||||
{
|
||||
int64_t r = strtol(nptr, endptr, base);
|
||||
if (r >= static_cast<int64_t>(INT32_MAX))
|
||||
{
|
||||
return INT32_MAX;
|
||||
}
|
||||
if (r <= static_cast<int64_t>(INT32_MIN))
|
||||
{
|
||||
return INT32_MIN;
|
||||
}
|
||||
return static_cast<int32_t>(r);
|
||||
}
|
||||
|
||||
inline uint32_t sys_strtoui32(const char* nptr, char** endptr, int base)
|
||||
{
|
||||
return strtoul(nptr, endptr, base);
|
||||
}
|
||||
|
||||
inline int64_t sys_strtoi64(const char* nptr, char** endptr, int base)
|
||||
{
|
||||
return strtoll(nptr, endptr, base);
|
||||
}
|
||||
|
||||
inline uint64_t sys_strtoui64(const char* nptr, char** endptr, int base)
|
||||
{
|
||||
return strtoull(nptr, endptr, base);
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* SYS_MACOS_INCLUDE_KYTY_SYSSTDLIB_H_ */
|
|
@ -0,0 +1,82 @@
|
|||
#ifndef SYS_MACOS_INCLUDE_KYTY_SYSSYNC_H_
|
||||
#define SYS_MACOS_INCLUDE_KYTY_SYSSYNC_H_
|
||||
|
||||
// IWYU pragma: private
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
class SysCS
|
||||
{
|
||||
public:
|
||||
SysCS() = default;
|
||||
|
||||
void Init()
|
||||
{
|
||||
EXIT_IF(m_check_ptr != nullptr);
|
||||
|
||||
m_check_ptr = this;
|
||||
|
||||
pthread_mutexattr_t attr {};
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&m_mutex, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
}
|
||||
|
||||
void Delete()
|
||||
{
|
||||
EXIT_IF(m_check_ptr != this);
|
||||
|
||||
m_check_ptr = nullptr;
|
||||
pthread_mutex_destroy(&m_mutex);
|
||||
}
|
||||
|
||||
~SysCS() { EXIT_IF(m_check_ptr != nullptr); }
|
||||
|
||||
void Enter()
|
||||
{
|
||||
EXIT_IF(m_check_ptr != this);
|
||||
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
}
|
||||
|
||||
bool TryEnter()
|
||||
{
|
||||
EXIT_IF(m_check_ptr != this);
|
||||
|
||||
return pthread_mutex_trylock(&m_mutex) == 0;
|
||||
}
|
||||
|
||||
void Leave()
|
||||
{
|
||||
EXIT_IF(m_check_ptr != this);
|
||||
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
}
|
||||
|
||||
KYTY_CLASS_NO_COPY(SysCS);
|
||||
|
||||
private:
|
||||
SysCS* m_check_ptr = nullptr;
|
||||
pthread_mutex_t m_mutex {};
|
||||
};
|
||||
|
||||
inline void sys_sleep(uint32_t ms)
|
||||
{
|
||||
struct timespec ts
|
||||
{
|
||||
};
|
||||
ts.tv_sec = ms / 1000;
|
||||
ts.tv_nsec = static_cast<int64_t>(ms % 1000) * 1000000;
|
||||
nanosleep(&ts, nullptr);
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* SYS_MACOS_INCLUDE_KYTY_SYSSYNC_H_ */
|
|
@ -0,0 +1,149 @@
|
|||
#ifndef SYS_MACOS_INCLUDE_KYTY_SYSTIMER_H_
|
||||
#define SYS_MACOS_INCLUDE_KYTY_SYSTIMER_H_
|
||||
|
||||
// IWYU pragma: private
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include <ctime>
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
struct SysTimeStruct
|
||||
{
|
||||
uint16_t Year;
|
||||
uint16_t Month;
|
||||
uint16_t Day;
|
||||
uint16_t Hour;
|
||||
uint16_t Minute;
|
||||
uint16_t Second;
|
||||
uint16_t Milliseconds;
|
||||
bool is_invalid;
|
||||
};
|
||||
|
||||
struct SysFileTimeStruct
|
||||
{
|
||||
time_t time;
|
||||
bool is_invalid;
|
||||
};
|
||||
|
||||
inline void sys_file_to_system_time_utc(const SysFileTimeStruct& f, SysTimeStruct& t)
|
||||
{
|
||||
struct tm i
|
||||
{
|
||||
};
|
||||
|
||||
if (f.is_invalid || gmtime_r(&f.time, &i) == nullptr)
|
||||
{
|
||||
t.is_invalid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
t.is_invalid = false;
|
||||
t.Year = i.tm_year + 1900;
|
||||
t.Month = i.tm_mon + 1;
|
||||
t.Day = i.tm_mday;
|
||||
t.Hour = i.tm_hour;
|
||||
t.Minute = i.tm_min;
|
||||
t.Second = (i.tm_sec == 60 ? 59 : i.tm_sec);
|
||||
t.Milliseconds = 0;
|
||||
}
|
||||
|
||||
inline void sys_time_t_to_system(time_t t, SysTimeStruct& s)
|
||||
{
|
||||
SysFileTimeStruct ft {};
|
||||
ft.time = t;
|
||||
ft.is_invalid = false;
|
||||
sys_file_to_system_time_utc(ft, s);
|
||||
}
|
||||
|
||||
inline time_t sys_timegm(struct tm* tm)
|
||||
{
|
||||
return timegm(tm);
|
||||
// time_t t = mktime(tm);
|
||||
// return t == (time_t)-1 ? (time_t)-1 : t + localtime(&t)->tm_gmtoff;
|
||||
}
|
||||
|
||||
inline void sys_system_to_file_time_utc(const SysTimeStruct& f, SysFileTimeStruct& t)
|
||||
{
|
||||
struct tm i
|
||||
{
|
||||
};
|
||||
|
||||
i.tm_year = f.Year - 1900;
|
||||
i.tm_mon = f.Month - 1;
|
||||
i.tm_mday = f.Day;
|
||||
i.tm_hour = f.Hour;
|
||||
i.tm_min = f.Minute;
|
||||
i.tm_sec = f.Second;
|
||||
|
||||
t.is_invalid = (f.is_invalid || (t.time = sys_timegm(&i)) == static_cast<time_t>(-1));
|
||||
}
|
||||
|
||||
// Retrieves the current local date and time
|
||||
inline void sys_get_system_time(SysTimeStruct& t)
|
||||
{
|
||||
time_t st {};
|
||||
struct tm i
|
||||
{
|
||||
};
|
||||
|
||||
if (time(&st) == static_cast<time_t>(-1) || localtime_r(&st, &i) == nullptr)
|
||||
{
|
||||
t.is_invalid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
t.is_invalid = false;
|
||||
t.Year = i.tm_year + 1900;
|
||||
t.Month = i.tm_mon + 1;
|
||||
t.Day = i.tm_mday;
|
||||
t.Hour = i.tm_hour;
|
||||
t.Minute = i.tm_min;
|
||||
t.Second = (i.tm_sec == 60 ? 59 : i.tm_sec);
|
||||
t.Milliseconds = 0;
|
||||
}
|
||||
|
||||
// Retrieves the current system date and time in Coordinated Universal Time (UTC).
|
||||
inline void sys_get_system_time_utc(SysTimeStruct& t)
|
||||
{
|
||||
time_t st {};
|
||||
struct tm i
|
||||
{
|
||||
};
|
||||
|
||||
if (time(&st) == static_cast<time_t>(-1) || gmtime_r(&st, &i) == nullptr)
|
||||
{
|
||||
t.is_invalid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
t.is_invalid = false;
|
||||
t.Year = i.tm_year + 1900;
|
||||
t.Month = i.tm_mon + 1;
|
||||
t.Day = i.tm_mday;
|
||||
t.Hour = i.tm_hour;
|
||||
t.Minute = i.tm_min;
|
||||
t.Second = (i.tm_sec == 60 ? 59 : i.tm_sec);
|
||||
t.Milliseconds = 0;
|
||||
}
|
||||
|
||||
inline void sys_query_performance_frequency(uint64_t* freq)
|
||||
{
|
||||
*freq = 1000000000LL;
|
||||
}
|
||||
|
||||
inline void sys_query_performance_counter(uint64_t* counter)
|
||||
{
|
||||
struct timespec now
|
||||
{
|
||||
};
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
*counter = now.tv_sec * 1000000000LL + now.tv_nsec;
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* SYS_MACOS_INCLUDE_KYTY_SYSTIMER_H_ */
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef INCLUDE_KYTY_SYS_MACOS_SYSLINUXVIRTUAL_H_
|
||||
#define INCLUDE_KYTY_SYS_MACOS_SYSLINUXVIRTUAL_H_
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Core/String.h"
|
||||
#include "Kyty/Core/VirtualMemory.h"
|
||||
|
||||
namespace Kyty::Core {
|
||||
|
||||
void sys_get_system_info(SystemInfo* info);
|
||||
|
||||
void sys_virtual_init();
|
||||
|
||||
uint64_t sys_virtual_alloc(uint64_t address, uint64_t size, VirtualMemory::Mode mode);
|
||||
uint64_t sys_virtual_alloc_aligned(uint64_t address, uint64_t size, VirtualMemory::Mode mode, uint64_t alignment);
|
||||
bool sys_virtual_alloc_fixed(uint64_t address, uint64_t size, VirtualMemory::Mode mode);
|
||||
bool sys_virtual_free(uint64_t address);
|
||||
bool sys_virtual_protect(uint64_t address, uint64_t size, VirtualMemory::Mode mode, VirtualMemory::Mode* old_mode = nullptr);
|
||||
bool sys_virtual_flush_instruction_cache(uint64_t address, uint64_t size);
|
||||
bool sys_virtual_patch_replace(uint64_t vaddr, uint64_t value);
|
||||
|
||||
} // namespace Kyty::Core
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_MACOS_SYSLINUXVIRTUAL_H_ */
|
|
@ -2,7 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSDBG_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxDbg.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsDbg.h" // IWYU pragma: export
|
||||
#elif defined(__linux__)
|
||||
#include "Kyty/Sys/Linux/SysLinuxDbg.h" // IWYU pragma: export
|
||||
#elif defined(__APPLE__)
|
||||
#include "Kyty/Sys/MacOS/SysMacOSDbg.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSDBG_H_ */
|
||||
|
|
|
@ -2,7 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSFILEIO_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxFileIO.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsFileIO.h" // IWYU pragma: export
|
||||
#elif defined(__linux__)
|
||||
#include "Kyty/Sys/Linux/SysLinuxFileIO.h" // IWYU pragma: export
|
||||
#elif defined(__APPLE__)
|
||||
#include "Kyty/Sys/MacOS/SysMacOSFileIO.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSFILEIO_H_ */
|
||||
|
|
|
@ -2,7 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSHEAP_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxHeap.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsHeap.h" // IWYU pragma: export
|
||||
#elif defined(__linux__)
|
||||
#include "Kyty/Sys/Linux/SysLinuxHeap.h" // IWYU pragma: export
|
||||
#elif defined(__APPLE__)
|
||||
#include "Kyty/Sys/MacOS/SysMacOSHeap.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSHEAP_H_ */
|
||||
|
|
|
@ -2,7 +2,15 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSSTDIO_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxStdio.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Windows/SysWindowsStdio.h" // IWYU pragma: export
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsStdio.h" //
|
||||
#elif defined(__APPLE__)
|
||||
#include "Kyty/Sys/MacOS/SysMacOSStdio.h" //
|
||||
#elif defined(__linux__)
|
||||
#include "Kyty/Sys/Linux/SysLinuxStdio.h" //
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSSTDIO_H_ */
|
||||
|
|
|
@ -2,7 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSSTDLIB_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxStdlib.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsStdlib.h" // IWYU pragma: export
|
||||
#elif defined(__linux__)
|
||||
#include "Kyty/Sys/Linux/SysLinuxStdlib.h" // IWYU pragma: export
|
||||
#elif defined(__APPLE__)
|
||||
#include "Kyty/Sys/MacOS/SysMacOSStdlib.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSSTDLIB_H_ */
|
||||
|
|
|
@ -2,7 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSSYNC_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxSync.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsSync.h" // IWYU pragma: export
|
||||
#elif defined(__linux__)
|
||||
#include "Kyty/Sys/Linux/SysLinuxSync.h" // IWYU pragma: export
|
||||
#elif defined(__APPLE__)
|
||||
#include "Kyty/Sys/MacOS/SysMacOSSync.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSSYNC_H_ */
|
||||
|
|
|
@ -2,7 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSTIMER_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxTimer.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsTimer.h" // IWYU pragma: export
|
||||
#elif defined(__linux__)
|
||||
#include "Kyty/Sys/Linux/SysLinuxTimer.h" // IWYU pragma: export
|
||||
#elif defined(__APPLE__)
|
||||
#include "Kyty/Sys/MacOS/SysMacOSTimer.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSTIMER_H_ */
|
||||
|
|
|
@ -2,7 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSVIRTUAL_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxVirtual.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsVirtual.h" // IWYU pragma: export
|
||||
#elif defined(__linux__)
|
||||
#include "Kyty/Sys/Linux/SysLinuxVirtual.h" // IWYU pragma: export
|
||||
#elif defined(__APPLE__)
|
||||
#include "Kyty/Sys/MacOS/SysMacOSVirtual.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSVIRTUAL_H_ */
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
|
||||
// IWYU pragma: private
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS
|
||||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS"
|
||||
#else
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Core/String.h"
|
||||
|
|
|
@ -7,122 +7,124 @@
|
|||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS"
|
||||
#else
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
struct SysTimeStruct
|
||||
{
|
||||
uint16_t Year; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Month; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Day; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Hour; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Minute; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Second; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Milliseconds; // NOLINT(readability-identifier-naming)
|
||||
bool is_invalid; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Year; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Month; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Day; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Hour; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Minute; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Second; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Milliseconds; // NOLINT(readability-identifier-naming)
|
||||
bool is_invalid; // NOLINT(readability-identifier-naming)
|
||||
};
|
||||
|
||||
struct SysFileTimeStruct
|
||||
{
|
||||
FILETIME time;
|
||||
bool is_invalid;
|
||||
FILETIME time;
|
||||
bool is_invalid;
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
inline void sys_file_to_system_time_utc(const SysFileTimeStruct& f, SysTimeStruct& t)
|
||||
{
|
||||
SYSTEMTIME s;
|
||||
SYSTEMTIME s;
|
||||
|
||||
if (f.is_invalid || (FileTimeToSystemTime(&f.time, &s) == 0))
|
||||
{
|
||||
t.is_invalid = true;
|
||||
return;
|
||||
}
|
||||
if (f.is_invalid || (FileTimeToSystemTime(&f.time, &s) == 0))
|
||||
{
|
||||
t.is_invalid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
inline void sys_time_t_to_system(time_t t, SysTimeStruct& s)
|
||||
{
|
||||
SysFileTimeStruct ft {};
|
||||
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
|
||||
ft.time.dwLowDateTime = static_cast<DWORD>(ll);
|
||||
ft.time.dwHighDateTime = static_cast<DWORD>(static_cast<uint64_t>(ll) >> 32u);
|
||||
ft.is_invalid = false;
|
||||
sys_file_to_system_time_utc(ft, s);
|
||||
SysFileTimeStruct ft {};
|
||||
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
|
||||
ft.time.dwLowDateTime = static_cast<DWORD>(ll);
|
||||
ft.time.dwHighDateTime = static_cast<DWORD>(static_cast<uint64_t>(ll) >> 32u);
|
||||
ft.is_invalid = false;
|
||||
sys_file_to_system_time_utc(ft, s);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
inline void sys_system_to_file_time_utc(const SysTimeStruct& f, SysFileTimeStruct& t)
|
||||
{
|
||||
SYSTEMTIME s;
|
||||
SYSTEMTIME s;
|
||||
|
||||
s.wYear = f.Year;
|
||||
s.wMonth = f.Month;
|
||||
s.wDay = f.Day;
|
||||
s.wHour = f.Hour;
|
||||
s.wMinute = f.Minute;
|
||||
s.wSecond = f.Second;
|
||||
s.wMilliseconds = f.Milliseconds;
|
||||
s.wYear = f.Year;
|
||||
s.wMonth = f.Month;
|
||||
s.wDay = f.Day;
|
||||
s.wHour = f.Hour;
|
||||
s.wMinute = f.Minute;
|
||||
s.wSecond = f.Second;
|
||||
s.wMilliseconds = f.Milliseconds;
|
||||
|
||||
t.is_invalid = (f.is_invalid || (SystemTimeToFileTime(&s, &t.time) == 0));
|
||||
t.is_invalid = (f.is_invalid || (SystemTimeToFileTime(&s, &t.time) == 0));
|
||||
}
|
||||
|
||||
// Retrieves the current local date and time
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
inline void sys_get_system_time(SysTimeStruct& t)
|
||||
{
|
||||
SYSTEMTIME s;
|
||||
GetLocalTime(&s);
|
||||
SYSTEMTIME s;
|
||||
GetLocalTime(&s);
|
||||
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
}
|
||||
|
||||
// Retrieves the current system date and time in Coordinated Universal Time (UTC).
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
inline void sys_get_system_time_utc(SysTimeStruct& t)
|
||||
{
|
||||
SYSTEMTIME s;
|
||||
GetSystemTime(&s);
|
||||
SYSTEMTIME s;
|
||||
GetSystemTime(&s);
|
||||
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
}
|
||||
|
||||
inline void sys_query_performance_frequency(uint64_t* freq)
|
||||
{
|
||||
LARGE_INTEGER f;
|
||||
QueryPerformanceFrequency(&f);
|
||||
*freq = f.QuadPart;
|
||||
LARGE_INTEGER f;
|
||||
QueryPerformanceFrequency(&f);
|
||||
*freq = f.QuadPart;
|
||||
}
|
||||
|
||||
inline void sys_query_performance_counter(uint64_t* counter)
|
||||
{
|
||||
LARGE_INTEGER c;
|
||||
QueryPerformanceCounter(&c);
|
||||
*counter = c.QuadPart;
|
||||
LARGE_INTEGER c;
|
||||
QueryPerformanceCounter(&c);
|
||||
*counter = c.QuadPart;
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
@ -130,3 +132,5 @@ inline void sys_query_performance_counter(uint64_t* counter)
|
|||
#endif
|
||||
|
||||
#endif /* SYS_WIN32_INCLUDE_KYTY_SYSTIMER_H_ */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#define KYTY_PLATFORM_WINDOWS 1
|
||||
#define KYTY_PLATFORM_ANDROID 2
|
||||
#define KYTY_PLATFORM_OSX 3
|
||||
#define KYTY_PLATFORM_MACOS 3
|
||||
#define KYTY_PLATFORM_IOS 4
|
||||
#define KYTY_PLATFORM_LINUX 5
|
||||
|
||||
|
|
|
@ -47,13 +47,6 @@ endif()
|
|||
|
||||
add_dependencies(launcher KytyGitVersion)
|
||||
|
||||
if(NOT LINUX)
|
||||
find_program(QT_WINDEPLOYQT NAMES windeployqt PATHS "${Qt5_DIR}/../../../bin")
|
||||
if(NOT QT_WINDEPLOYQT)
|
||||
message(FATAL_ERROR "Could not find windeployqt")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(launcher_name "launcher")
|
||||
|
||||
set_target_properties(launcher PROPERTIES OUTPUT_NAME ${launcher_name})
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include "ui_main_dialog.h"
|
||||
|
||||
#ifndef __linux__
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#endif
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
|||
|
||||
class QWidget;
|
||||
|
||||
#ifdef __linux__
|
||||
#ifdef __linux__ || __APPLE__
|
||||
constexpr char SCRIPT_EXE[] = "fc_script";
|
||||
#else
|
||||
constexpr char SCRIPT_EXE[] = "fc_script.exe";
|
||||
|
@ -59,7 +59,7 @@ constexpr char KYTY_LOAD_SYMBOLS_ALL[] = "kyty_load_symbols_all";
|
|||
constexpr char KYTY_LOAD_PARAM_SFO[] = "kyty_load_param_sfo";
|
||||
constexpr char KYTY_INIT[] = "kyty_init";
|
||||
constexpr char KYTY_LUA_FILE[] = "kyty_run.lua";
|
||||
#ifndef __linux__
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
constexpr DWORD CMD_X_CHARS = 175;
|
||||
constexpr DWORD CMD_Y_CHARS = 1000;
|
||||
#endif
|
||||
|
@ -359,7 +359,7 @@ void MainDialog::RunInterpreter(QProcess* process, Kyty::Configuration* info, [[
|
|||
}
|
||||
#endif
|
||||
process->setWorkingDirectory(dir.path());
|
||||
#ifndef __linux__
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
process->setCreateProcessArgumentsModifier(
|
||||
[](QProcess::CreateProcessArguments* args)
|
||||
{
|
||||
|
|
|
@ -1185,18 +1185,55 @@ bool ZipReader::GetFileStat(int file_index, ZipFileStat* o)
|
|||
|
||||
if (mz_zip_reader_file_stat(&m_p->zip, file_index, &s) != 0)
|
||||
{
|
||||
o->m_file_index = s.m_file_index;
|
||||
o->m_file_index = s.m_file_index;
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
//define something for Windows (32-bit and 64-bit, this part is common)
|
||||
SysTimeStruct at = {0};
|
||||
sys_time_t_to_system(s.m_time, at);
|
||||
o->m_time = DateTime(Date(at.Year, at.Month, at.Day), Time(at.Hour, at.Minute, at.Second, at.Milliseconds));
|
||||
|
||||
SysTimeStruct at = {0};
|
||||
sys_time_t_to_system(s.m_time, at);
|
||||
o->m_time = DateTime(Date(at.Year, at.Month, at.Day), Time(at.Hour, at.Minute, at.Second, at.Milliseconds));
|
||||
o->m_crc32 = s.m_crc32;
|
||||
o->m_comp_size = s.m_comp_size;
|
||||
o->m_uncomp_size = s.m_uncomp_size;
|
||||
o->m_filename = String::FromUtf8(s.m_filename);
|
||||
o->m_comment = String::FromUtf8(s.m_comment);
|
||||
#ifdef _WIN64
|
||||
//define something for Windows (64-bit only)
|
||||
SysTimeStruct at = {0};
|
||||
sys_time_t_to_system(s.m_time, at);
|
||||
o->m_time = DateTime(Date(at.Year, at.Month, at.Day), Time(at.Hour, at.Minute, at.Second, at.Milliseconds));
|
||||
|
||||
o->m_crc32 = s.m_crc32;
|
||||
o->m_comp_size = s.m_comp_size;
|
||||
o->m_uncomp_size = s.m_uncomp_size;
|
||||
o->m_filename = String::FromUtf8(s.m_filename);
|
||||
o->m_comment = String::FromUtf8(s.m_comment);
|
||||
o->m_crc32 = s.m_crc32;
|
||||
o->m_comp_size = s.m_comp_size;
|
||||
o->m_uncomp_size = s.m_uncomp_size;
|
||||
o->m_filename = String::FromUtf8(s.m_filename);
|
||||
o->m_comment = String::FromUtf8(s.m_comment);
|
||||
#else
|
||||
//define something for Windows (32-bit only)
|
||||
#endif
|
||||
#elif __APPLE__
|
||||
// apple
|
||||
#elif __ANDROID__
|
||||
// Below __linux__ check should be enough to handle Android,
|
||||
// but something may be unique to Android.
|
||||
#elif __linux__
|
||||
// linux
|
||||
SysTimeStruct at = {0};
|
||||
sys_time_t_to_system(s.m_time, at);
|
||||
o->m_time = DateTime(Date(at.Year, at.Month, at.Day), Time(at.Hour, at.Minute, at.Second, at.Milliseconds));
|
||||
|
||||
o->m_crc32 = s.m_crc32;
|
||||
o->m_comp_size = s.m_comp_size;
|
||||
o->m_uncomp_size = s.m_uncomp_size;
|
||||
o->m_filename = String::FromUtf8(s.m_filename);
|
||||
o->m_comment = String::FromUtf8(s.m_comment);
|
||||
#elif __unix__ // all unices not caught above
|
||||
// Unix
|
||||
#elif defined(_POSIX_VERSION)
|
||||
// POSIX
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <ctime>
|
||||
#include "Kyty/Core/DateTime.h"
|
||||
|
||||
#include "Kyty/Core/DbgAssert.h"
|
||||
|
@ -414,18 +415,19 @@ Date Date::FromMacros(const String& date)
|
|||
|
||||
Date Date::FromSystem()
|
||||
{
|
||||
SysTimeStruct t {};
|
||||
sys_get_system_time(t);
|
||||
SysTimeStruct t {};
|
||||
sys_get_system_time(t);
|
||||
|
||||
return Date(t.Year, t.Month, t.Day);
|
||||
return Date(t.Year, t.Month, t.Day);
|
||||
}
|
||||
|
||||
Date Date::FromSystemUTC()
|
||||
{
|
||||
SysTimeStruct t {};
|
||||
sys_get_system_time_utc(t);
|
||||
|
||||
return Date(t.Year, t.Month, t.Day);
|
||||
SysTimeStruct t {};
|
||||
|
||||
sys_get_system_time_utc(t);
|
||||
|
||||
return Date(t.Year, t.Month, t.Day);
|
||||
}
|
||||
|
||||
Time::Time(int hour, int minute, int second, int msec)
|
||||
|
@ -435,18 +437,19 @@ Time::Time(int hour, int minute, int second, int msec)
|
|||
|
||||
Time Time::FromSystem()
|
||||
{
|
||||
SysTimeStruct t {};
|
||||
sys_get_system_time(t);
|
||||
SysTimeStruct t {};
|
||||
|
||||
sys_get_system_time(t);
|
||||
|
||||
return Time(t.Hour, t.Minute, t.Second, t.Milliseconds);
|
||||
return Time(t.Hour, t.Minute, t.Second, t.Milliseconds);
|
||||
}
|
||||
|
||||
Time Time::FromSystemUTC()
|
||||
{
|
||||
SysTimeStruct t {};
|
||||
sys_get_system_time_utc(t);
|
||||
SysTimeStruct t {};
|
||||
sys_get_system_time_utc(t);
|
||||
|
||||
return Time(t.Hour, t.Minute, t.Second, t.Milliseconds);
|
||||
return Time(t.Hour, t.Minute, t.Second, t.Milliseconds);
|
||||
}
|
||||
|
||||
void Time::Set(int hour, int minute, int second, int msec)
|
||||
|
@ -763,28 +766,28 @@ Time Time::operator-=(int secs)
|
|||
|
||||
DateTime DateTime::FromSystem()
|
||||
{
|
||||
SysTimeStruct t {};
|
||||
sys_get_system_time(t);
|
||||
SysTimeStruct t {};
|
||||
sys_get_system_time(t);
|
||||
|
||||
if (t.is_invalid)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
if (t.is_invalid)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return DateTime(Date(t.Year, t.Month, t.Day), Time(t.Hour, t.Minute, t.Second, t.Milliseconds));
|
||||
return DateTime(Date(t.Year, t.Month, t.Day), Time(t.Hour, t.Minute, t.Second, t.Milliseconds));
|
||||
}
|
||||
|
||||
DateTime DateTime::FromSystemUTC()
|
||||
{
|
||||
SysTimeStruct t {};
|
||||
sys_get_system_time_utc(t);
|
||||
SysTimeStruct t {};
|
||||
sys_get_system_time_utc(t);
|
||||
|
||||
if (t.is_invalid)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
if (t.is_invalid)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return DateTime(Date(t.Year, t.Month, t.Day), Time(t.Hour, t.Minute, t.Second, t.Milliseconds));
|
||||
return DateTime(Date(t.Year, t.Month, t.Day), Time(t.Hour, t.Minute, t.Second, t.Milliseconds));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
#include "Kyty/Core/Subsystems.h"
|
||||
|
||||
#include <cstdarg>
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
// IWYU pragma: no_include <debugapi.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace Kyty::Core {
|
||||
|
||||
|
@ -18,7 +19,7 @@ constexpr int PRINT_STACK_FROM = 4;
|
|||
#else
|
||||
constexpr int PRINT_STACK_FROM = 2;
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_LINUX
|
||||
int IsDebuggerPresent()
|
||||
{
|
||||
|
@ -48,7 +49,7 @@ int IsDebuggerPresent()
|
|||
return (dbg ? 1 : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
void dbg_print_stack()
|
||||
{
|
||||
DebugStack s;
|
||||
|
@ -110,8 +111,10 @@ void dbg_exit(int status)
|
|||
|
||||
bool dbg_is_debugger_present()
|
||||
{
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__linux__)
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS || KYTY_PLATFORM == KYTY_PLATFORM_LINUX
|
||||
return !(IsDebuggerPresent() == 0);
|
||||
#endif
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -87,8 +87,9 @@ static void exception_filter(void* /*addr*/)
|
|||
|
||||
void core_debug_init(const char* app_name)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
sys_set_exception_filter(exception_filter);
|
||||
|
||||
#endif
|
||||
g_exe_name = new String(String::FromUtf8(app_name));
|
||||
g_dbg_map = new DebugMap;
|
||||
// g_dbg_map->LoadMap();
|
||||
|
@ -792,6 +793,7 @@ static const T* find_info(const T* data, uintptr_t addr, uint32_t low, uint32_t
|
|||
|
||||
void DebugMapPrivate::FixBaseAddress()
|
||||
{
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
uintptr_t code_base = 0;
|
||||
size_t code_size = 0;
|
||||
sys_get_code_info(&code_base, &code_size);
|
||||
|
@ -811,6 +813,7 @@ void DebugMapPrivate::FixBaseAddress()
|
|||
p.addr += code_base;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
const DebugFunctionInfo* DebugMapPrivate::FindFunc(DebugMap* map, uintptr_t addr)
|
||||
|
@ -864,31 +867,35 @@ void DebugMap::LoadCsv(const String& name)
|
|||
m_p->buf[size] = 0;
|
||||
char* context = nullptr;
|
||||
|
||||
[[maybe_unused]] char* p = strtok_s(m_p->buf, "\r\n;", &context);
|
||||
[[maybe_unused]] char* p = strtok_r(m_p->buf, "\r\n;", &context);
|
||||
EXIT_IF(String::FromUtf8(p) != U"Addr");
|
||||
p = strtok_s(nullptr, "\r\n;", &context);
|
||||
p = strtok_r(nullptr, "\r\n;", &context);
|
||||
EXIT_IF(String::FromUtf8(p) != U"Size");
|
||||
p = strtok_s(nullptr, "\r\n;", &context);
|
||||
p = strtok_r(nullptr, "\r\n;", &context);
|
||||
EXIT_IF(String::FromUtf8(p) != U"Func");
|
||||
p = strtok_s(nullptr, "\r\n;", &context);
|
||||
p = strtok_r(nullptr, "\r\n;", &context);
|
||||
EXIT_IF(String::FromUtf8(p) != U"Obj");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
char* s1 = strtok_s(nullptr, "\r\n;", &context);
|
||||
char* s2 = strtok_s(nullptr, "\r\n;", &context);
|
||||
char* s3 = strtok_s(nullptr, "\r\n;", &context);
|
||||
char* s4 = strtok_s(nullptr, "\r\n;", &context);
|
||||
char* s1 = strtok_r(nullptr, "\r\n;", &context);
|
||||
char* s2 = strtok_r(nullptr, "\r\n;", &context);
|
||||
char* s3 = strtok_r(nullptr, "\r\n;", &context);
|
||||
char* s4 = strtok_r(nullptr, "\r\n;", &context);
|
||||
|
||||
if ((s1 == nullptr) || (s2 == nullptr) || (s3 == nullptr) || (s4 == nullptr))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__linux__)
|
||||
DebugFunctionInfo2 inf = {static_cast<uintptr_t>(sys_strtoui64(s1 + 2, nullptr, 16)),
|
||||
static_cast<uintptr_t>(sys_strtoui64(s2, nullptr, 10)), s3, s4};
|
||||
static_cast<uintptr_t>(sys_strtoui64(s2, nullptr, 10)), s3, s4};
|
||||
|
||||
m_p->data2.Add(inf);
|
||||
#elif __APPLE__
|
||||
|
||||
m_p->data2.Add(inf);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -913,8 +920,10 @@ void DebugStack::Print(int from, bool with_name) const
|
|||
|
||||
void DebugStack::Trace(DebugStack* stack)
|
||||
{
|
||||
stack->depth = DEBUG_MAX_STACK_DEPTH;
|
||||
sys_stack_walk(stack->stack, &stack->depth);
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__linux__)
|
||||
stack->depth = DEBUG_MAX_STACK_DEPTH;
|
||||
sys_stack_walk(stack->stack, &stack->depth);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DebugStack::PrintAndroid(int from, bool with_name) const
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace Kyty::Core {
|
|||
struct File::FilePrivate
|
||||
{
|
||||
Encoding e;
|
||||
sys_file_t* f;
|
||||
sys_file_t* f;
|
||||
};
|
||||
|
||||
String* g_assets_dir = nullptr;
|
||||
|
|
|
@ -20,25 +20,31 @@ namespace Kyty::Core {
|
|||
#define MEM_ALLOC_ALIGNED
|
||||
|
||||
#ifdef MEM_ALLOC_ALIGNED
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_ANDROID
|
||||
#if defined(__ANDROID__)
|
||||
constexpr int MEM_ALLOC_ALIGN = 8;
|
||||
#else
|
||||
constexpr int MEM_ALLOC_ALIGN = 16;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS && KYTY_BITNESS == 64
|
||||
#if defined(__WIN64__)
|
||||
[[maybe_unused]] constexpr int STACK_CHECK_FROM = 5;
|
||||
#elif KYTY_PLATFORM == KYTY_PLATFORM_ANDROID
|
||||
#elif defined(__ANDROID__)
|
||||
[[maybe_unused]] constexpr int STACK_CHECK_FROM = 4;
|
||||
#else
|
||||
[[maybe_unused]] constexpr int STACK_CHECK_FROM = 2;
|
||||
#endif
|
||||
|
||||
#if defined(__WIN64__) || defined(__linux__)
|
||||
static SysCS* g_mem_cs = nullptr;
|
||||
static bool g_mem_initialized = false;
|
||||
static sys_heap_id_t g_default_heap = nullptr;
|
||||
static size_t g_mem_max_size = 0;
|
||||
#else
|
||||
static SysCS* g_mem_cs = 0;
|
||||
static bool g_mem_initialized = false;
|
||||
static sys_heap_id_t g_default_heap = 0;
|
||||
static size_t g_mem_max_size = 0;
|
||||
#endif
|
||||
|
||||
#ifdef MEM_TRACKER
|
||||
|
||||
|
@ -210,7 +216,7 @@ void* mem_alloc(size_t size)
|
|||
{
|
||||
if (size == 0)
|
||||
{
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_LINUX
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
size = 1;
|
||||
#else
|
||||
EXIT("size == 0\n");
|
||||
|
|
|
@ -12,11 +12,11 @@
|
|||
#include <condition_variable> // IWYU pragma: keep
|
||||
#include <mutex>
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS && KYTY_COMPILER == KYTY_COMPILER_CLANG
|
||||
#if defined(__WIN64__)
|
||||
#define KYTY_WIN_CS
|
||||
#endif
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS && KYTY_PLATFORM != KYTY_PLATFORM_LINUX
|
||||
#if defined(__APPLE__)
|
||||
#define KYTY_SDL_THREADS
|
||||
#define KYTY_SDL_CS
|
||||
#endif
|
||||
|
@ -42,6 +42,7 @@
|
|||
#endif
|
||||
|
||||
#if !(defined(KYTY_DEBUG_LOCKS) || defined(KYTY_DEBUG_LOCKS_TIMED)) && defined(KYTY_WIN_CS)
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
// IWYU pragma: no_include <winbase.h>
|
||||
constexpr DWORD KYTY_CS_SPIN_COUNT = 4000;
|
||||
|
@ -92,6 +93,7 @@ static SleepConditionVariableCS_func_t ResolveSleepConditionVariableCS()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace Kyty::Core {
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
#include "Kyty/Sys/SysVirtual.h"
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#define KYTY_HAS_EXCEPTIONS
|
||||
#endif
|
||||
|
||||
#ifdef KYTY_HAS_EXCEPTIONS
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#endif
|
||||
|
||||
|
|
|
@ -859,7 +859,7 @@ ScriptVar ScriptTable::GetValue(uint32_t index) const
|
|||
void ScriptFuncResult::SetError(const String& msg)
|
||||
{
|
||||
m_ok = false;
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
strncpy_s(m_msg, SCRIPT_FUNC_ERR_SIZE + 1, msg.C_Str(), SCRIPT_FUNC_ERR_SIZE);
|
||||
#else
|
||||
strncpy(m_msg, msg.C_Str(), SCRIPT_FUNC_ERR_SIZE);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_LINUX
|
||||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_LINUX"
|
||||
#else
|
||||
#if defined(__linux__)
|
||||
|
||||
#include "Kyty/Sys/SysDbg.h"
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_LINUX
|
||||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_LINUX"
|
||||
#else
|
||||
#if defined(__linux__)
|
||||
|
||||
#include "Kyty/Core/DbgAssert.h"
|
||||
#include "Kyty/Core/MemoryAlloc.h"
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_LINUX
|
||||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_LINUX"
|
||||
#else
|
||||
#if defined(__linux__)
|
||||
|
||||
#include "Kyty/Core/DbgAssert.h"
|
||||
#include "Kyty/Core/String.h"
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include "Kyty/Sys/SysDbg.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
static thread_local sys_dbg_stack_info_t g_stack = {0};
|
||||
|
||||
void sys_stack_walk(void** /*stack*/, int* depth)
|
||||
{
|
||||
*depth = 0;
|
||||
}
|
||||
|
||||
void sys_stack_usage_print(sys_dbg_stack_info_t& stack)
|
||||
{
|
||||
printf("stack: (0x%" PRIx64 ", %" PRIu64 ")\n", static_cast<uint64_t>(stack.commited_addr), static_cast<uint64_t>(stack.commited_size));
|
||||
printf("code: (0x%" PRIx64 ", %" PRIu64 ")\n", static_cast<uint64_t>(stack.code_addr), static_cast<uint64_t>(stack.code_size));
|
||||
}
|
||||
|
||||
void sys_stack_usage(sys_dbg_stack_info_t& s)
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
|
||||
// printf("pid = %"I64"d\n", (int64_t)pid);
|
||||
|
||||
[[maybe_unused]] int result = 0;
|
||||
|
||||
char str[1024];
|
||||
char str2[1024];
|
||||
result = snprintf(str, 1024, "/proc/%d/exe", static_cast<int>(pid));
|
||||
|
||||
ssize_t buff_len = 0;
|
||||
if ((buff_len = readlink(str, str2, 1023)) == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
str2[buff_len] = '\0';
|
||||
const char* name = basename(str2);
|
||||
|
||||
result = snprintf(str, 1024,"/proc/%d/maps", static_cast<int>(pid));
|
||||
|
||||
memset(&s, 0, sizeof(sys_dbg_stack_info_t));
|
||||
|
||||
FILE* f = fopen(str, "r");
|
||||
|
||||
if (f == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// printf("&str = %"I64"x\n", (uint64_t)&str);
|
||||
|
||||
uint64_t addr = 0;
|
||||
uint64_t endaddr = 0;
|
||||
[[maybe_unused]] uint64_t size = 0;
|
||||
uint64_t offset = 0;
|
||||
uint64_t inode = 0;
|
||||
char permissions[8] = {};
|
||||
char device[8] = {};
|
||||
char filename[MAXPATHLEN] = {};
|
||||
|
||||
auto check_addr = reinterpret_cast<uintptr_t>(&f);
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (feof(f) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (fgets(str, sizeof(str), f) == nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
filename[0];
|
||||
permissions[0] = 0;
|
||||
addr = 0;
|
||||
size = 0;
|
||||
|
||||
// printf("%s", str);
|
||||
|
||||
// NOLINTNEXTLINE(cert-err34-c)
|
||||
result = sscanf(str, "%" SCNx64 "-%" SCNx64 " %s %" SCNx64 " %s %" SCNx64 " %s", &addr, &endaddr, permissions, &offset, device,
|
||||
&inode, filename);
|
||||
|
||||
size = endaddr - addr;
|
||||
|
||||
bool read = (strchr(permissions, 'r') != nullptr);
|
||||
bool write = (strchr(permissions, 'w') != nullptr);
|
||||
bool exec = (strchr(permissions, 'x') != nullptr);
|
||||
|
||||
// printf("%016"I64"x, %"I64"d, %s, %d, %d\n", addr, size, filename, read, write);
|
||||
|
||||
if (read && write && !exec && strncmp(filename, "[stack", 6) == 0)
|
||||
{
|
||||
// printf("stack: %016"I64"x, %"I64"d\n", addr, size);
|
||||
|
||||
if (check_addr >= addr && check_addr < addr + size)
|
||||
{
|
||||
s.addr = addr;
|
||||
s.total_size = size;
|
||||
s.commited_addr = addr;
|
||||
s.commited_size = size;
|
||||
|
||||
if (s.code_addr != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (read && !write && exec && strstr(filename, name) != nullptr)
|
||||
{
|
||||
s.code_addr = addr;
|
||||
s.code_size = size;
|
||||
|
||||
if (s.addr != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = fclose(f);
|
||||
}
|
||||
|
||||
void sys_get_code_info(uintptr_t* addr, size_t* size)
|
||||
{
|
||||
if (g_stack.code_size == 0)
|
||||
{
|
||||
sys_stack_usage(g_stack);
|
||||
}
|
||||
|
||||
*addr = g_stack.code_addr;
|
||||
*size = g_stack.code_size;
|
||||
}
|
||||
|
||||
void sys_set_exception_filter(exception_filter_func_t) {}
|
||||
|
||||
} // namespace Kyty
|
||||
#endif
|
|
@ -0,0 +1,670 @@
|
|||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include "Kyty/Core/DbgAssert.h"
|
||||
#include "Kyty/Core/MemoryAlloc.h"
|
||||
#include "Kyty/Core/String.h"
|
||||
#include "Kyty/Sys/SysFileIO.h"
|
||||
#include "Kyty/Sys/SysTimer.h"
|
||||
|
||||
#include "SDL_system.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <utime.h>
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
template <typename T>
|
||||
class Vector;
|
||||
|
||||
static String* g_internal_files_dir = nullptr;
|
||||
|
||||
static String get_internal_name(const String& name)
|
||||
{
|
||||
return name.StartsWith(U"/") ? name : *g_internal_files_dir + U"/" + name;
|
||||
}
|
||||
|
||||
bool sys_file_io_init()
|
||||
{
|
||||
g_internal_files_dir = new String();
|
||||
|
||||
*g_internal_files_dir = U".";
|
||||
|
||||
return !g_internal_files_dir->IsEmpty();
|
||||
}
|
||||
|
||||
void sys_file_read(void* data, uint32_t size, sys_file_t& f, uint32_t* bytes_read)
|
||||
{
|
||||
if (f.type == SYS_FILE_FILE)
|
||||
{
|
||||
size_t w = fread(data, 1, size, f.f);
|
||||
if (bytes_read != nullptr)
|
||||
{
|
||||
*bytes_read = w;
|
||||
}
|
||||
} else if (f.type == SYS_FILE_MEMORY_STAT)
|
||||
{
|
||||
uint32_t s = size;
|
||||
if (f.buf->size != 0)
|
||||
{
|
||||
uint32_t l = f.buf->size - (f.buf->ptr - f.buf->base);
|
||||
if (s > l)
|
||||
{
|
||||
s = l;
|
||||
}
|
||||
}
|
||||
memcpy(data, f.buf->ptr, s);
|
||||
f.buf->ptr += s;
|
||||
if (bytes_read != nullptr)
|
||||
{
|
||||
*bytes_read = s;
|
||||
}
|
||||
} else if (f.type == SYS_FILE_MEMORY_DYN)
|
||||
{
|
||||
uint32_t s = size;
|
||||
if (f.buf->size != 0)
|
||||
{
|
||||
uint32_t l = f.buf->size - (f.buf->ptr - f.buf->base);
|
||||
if (s > l)
|
||||
{
|
||||
s = l;
|
||||
}
|
||||
} else
|
||||
{
|
||||
s = 0;
|
||||
}
|
||||
memcpy(data, f.buf->ptr, s);
|
||||
f.buf->ptr += s;
|
||||
if (bytes_read != nullptr)
|
||||
{
|
||||
*bytes_read = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sys_file_write(const void* data, uint32_t size, sys_file_t& f, uint32_t* bytes_written)
|
||||
{
|
||||
if (f.type == SYS_FILE_FILE)
|
||||
{
|
||||
size_t w = fwrite(data, 1, size, f.f);
|
||||
if (bytes_written != nullptr)
|
||||
{
|
||||
*bytes_written = w;
|
||||
}
|
||||
} else if (f.type == SYS_FILE_MEMORY_STAT)
|
||||
{
|
||||
uint32_t s = size;
|
||||
if (f.buf->size != 0)
|
||||
{
|
||||
uint32_t l = f.buf->size - (f.buf->ptr - f.buf->base);
|
||||
if (s > l)
|
||||
{
|
||||
s = l;
|
||||
}
|
||||
}
|
||||
memcpy(f.buf->ptr, data, s);
|
||||
f.buf->ptr += s;
|
||||
if (bytes_written != nullptr)
|
||||
{
|
||||
*bytes_written = s;
|
||||
}
|
||||
} else if (f.type == SYS_FILE_MEMORY_DYN)
|
||||
{
|
||||
uint32_t pos = f.buf->ptr - f.buf->base;
|
||||
if (f.buf->size < pos + size)
|
||||
{
|
||||
f.buf->base = static_cast<uint8_t*>(Core::mem_realloc(f.buf->base, pos + size));
|
||||
f.buf->ptr = f.buf->base + pos;
|
||||
f.buf->size = pos + size;
|
||||
}
|
||||
memcpy(f.buf->ptr, data, size);
|
||||
f.buf->ptr += size;
|
||||
if (bytes_written != nullptr)
|
||||
{
|
||||
*bytes_written = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sys_file_read_r(void* data, uint32_t size, sys_file_t& f)
|
||||
{
|
||||
// DWORD w;
|
||||
// ReadFile(f, data, size, &w, 0);
|
||||
|
||||
sys_file_read(data, size, f);
|
||||
|
||||
for (uint32_t i = 0; i < size / 2; i++)
|
||||
{
|
||||
char t = (static_cast<char*>(data))[i];
|
||||
(static_cast<char*>(data))[i] = (static_cast<char*>(data))[size - i - 1];
|
||||
(static_cast<char*>(data))[size - i - 1] = t;
|
||||
}
|
||||
}
|
||||
|
||||
void sys_file_write_r(const void* data, uint32_t size, sys_file_t& f)
|
||||
{
|
||||
char* data_r = new char[size];
|
||||
for (uint32_t i = 0; i < size; i++)
|
||||
{
|
||||
data_r[i] = (static_cast<const char*>(data))[size - i - 1];
|
||||
}
|
||||
|
||||
sys_file_write(data_r, size, f);
|
||||
|
||||
delete[] data_r;
|
||||
}
|
||||
|
||||
void sys_file_write(uint32_t n, sys_file_t& f)
|
||||
{
|
||||
sys_file_write(&n, 4, f);
|
||||
}
|
||||
|
||||
void sys_file_write_r(uint32_t n, sys_file_t& f)
|
||||
{
|
||||
sys_file_write_r(&n, 4, f);
|
||||
}
|
||||
|
||||
sys_file_t* sys_file_create(const String& file_name)
|
||||
{
|
||||
auto* ret = new sys_file_t;
|
||||
|
||||
String real_name = get_internal_name(file_name);
|
||||
|
||||
ret->f = fopen(real_name.utf8_str().GetData(), "w+");
|
||||
|
||||
if (ret->f == nullptr)
|
||||
{
|
||||
printf("can't create file: %s\n", real_name.utf8_str().GetData());
|
||||
}
|
||||
|
||||
ret->type = SYS_FILE_FILE;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
sys_file_t* sys_file_open_r(const String& file_name, sys_file_cache_type_t /*cache_type*/)
|
||||
{
|
||||
auto* ret = new sys_file_t;
|
||||
|
||||
ret->type = SYS_FILE_FILE;
|
||||
|
||||
String internal_name = get_internal_name(file_name);
|
||||
;
|
||||
|
||||
FILE* f = fopen(internal_name.utf8_str().GetData(), "r");
|
||||
|
||||
if (f == nullptr)
|
||||
{
|
||||
ret->type = SYS_FILE_ERROR;
|
||||
}
|
||||
|
||||
ret->f = f;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
sys_file_t* sys_file_open(uint8_t* buf, uint32_t buf_size)
|
||||
{
|
||||
auto* ret = new sys_file_t;
|
||||
|
||||
ret->type = SYS_FILE_MEMORY_STAT;
|
||||
ret->buf = new sys_file_mem_buf_t;
|
||||
ret->buf->base = buf;
|
||||
ret->buf->ptr = buf;
|
||||
ret->buf->size = buf_size;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
sys_file_t* sys_file_create()
|
||||
{
|
||||
auto* ret = new sys_file_t;
|
||||
|
||||
ret->type = SYS_FILE_MEMORY_DYN;
|
||||
ret->buf = new sys_file_mem_buf_t;
|
||||
ret->buf->base = nullptr;
|
||||
ret->buf->ptr = nullptr;
|
||||
ret->buf->size = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
sys_file_t* sys_file_open_w(const String& file_name, sys_file_cache_type_t /*cache_type*/)
|
||||
{
|
||||
auto* ret = new sys_file_t;
|
||||
|
||||
String real_name = get_internal_name(file_name);
|
||||
;
|
||||
|
||||
FILE* f = fopen(real_name.utf8_str().GetData(), "r+");
|
||||
|
||||
if (f == nullptr)
|
||||
{
|
||||
ret->type = SYS_FILE_ERROR;
|
||||
} else
|
||||
{
|
||||
ret->type = SYS_FILE_FILE;
|
||||
}
|
||||
|
||||
ret->f = f;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
sys_file_t* sys_file_open_rw(const String& file_name, sys_file_cache_type_t /*cache_type*/)
|
||||
{
|
||||
auto* ret = new sys_file_t;
|
||||
|
||||
String real_name = get_internal_name(file_name);
|
||||
|
||||
FILE* f = fopen(real_name.utf8_str().GetData(), "r+");
|
||||
|
||||
if (f == nullptr)
|
||||
{
|
||||
ret->type = SYS_FILE_ERROR;
|
||||
} else
|
||||
{
|
||||
ret->type = SYS_FILE_FILE;
|
||||
}
|
||||
|
||||
ret->f = f;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void sys_file_close(sys_file_t* f)
|
||||
{
|
||||
[[maybe_unused]] int result = 0;
|
||||
|
||||
if (f->type == SYS_FILE_FILE && f->f != nullptr)
|
||||
{
|
||||
result = fclose(f->f);
|
||||
} else if (f->type == SYS_FILE_MEMORY_STAT)
|
||||
{
|
||||
delete f->buf;
|
||||
} else if (f->type == SYS_FILE_MEMORY_DYN)
|
||||
{
|
||||
Core::mem_free(f->buf->base);
|
||||
delete f->buf;
|
||||
}
|
||||
|
||||
// f.type = SYS_FILE_ERROR;
|
||||
delete f;
|
||||
}
|
||||
|
||||
uint64_t sys_file_size(sys_file_t& f)
|
||||
{
|
||||
[[maybe_unused]] int result = 0;
|
||||
|
||||
if (f.type == SYS_FILE_FILE)
|
||||
{
|
||||
uint32_t pos = ftell(f.f);
|
||||
result = fseek(f.f, 0, SEEK_END);
|
||||
uint32_t size = ftell(f.f);
|
||||
result = fseek(f.f, pos, SEEK_SET);
|
||||
return size;
|
||||
}
|
||||
|
||||
if (f.type == SYS_FILE_MEMORY_STAT || f.type == SYS_FILE_MEMORY_DYN)
|
||||
{
|
||||
return f.buf->size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t sys_file_size(const String& file_name)
|
||||
{
|
||||
sys_file_t* f = sys_file_open_r(file_name);
|
||||
uint64_t size = sys_file_size(*f);
|
||||
sys_file_close(f);
|
||||
return size;
|
||||
}
|
||||
|
||||
bool sys_file_truncate(sys_file_t& /*f*/, uint64_t /*size*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sys_file_seek(sys_file_t& f, uint64_t offset)
|
||||
{
|
||||
bool ok = true;
|
||||
if (f.type == SYS_FILE_FILE)
|
||||
{
|
||||
ok = (fseek(f.f, static_cast<int64_t>(offset), SEEK_SET) == 0);
|
||||
// LARGE_INTEGER s;
|
||||
// s.QuadPart = offset;
|
||||
// SetFilePointerEx(f.handle, s, 0, FILE_BEGIN);
|
||||
// printf("seek: %u\n", offset);
|
||||
} else if (f.type == SYS_FILE_MEMORY_STAT || f.type == SYS_FILE_MEMORY_DYN)
|
||||
{
|
||||
f.buf->ptr = f.buf->base + offset;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
uint64_t sys_file_tell(sys_file_t& f)
|
||||
{
|
||||
if (f.type == SYS_FILE_FILE)
|
||||
{
|
||||
return ftell(f.f);
|
||||
}
|
||||
|
||||
if (f.type == SYS_FILE_MEMORY_STAT || f.type == SYS_FILE_MEMORY_DYN)
|
||||
{
|
||||
return f.buf->ptr - f.buf->base;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool sys_file_is_error(sys_file_t& f)
|
||||
{
|
||||
return f.type == SYS_FILE_ERROR || (f.type == SYS_FILE_FILE && f.f == nullptr);
|
||||
}
|
||||
|
||||
bool sys_file_is_directory_existing(const String& path)
|
||||
{
|
||||
String real_name = get_internal_name(path);
|
||||
|
||||
struct stat s
|
||||
{
|
||||
};
|
||||
|
||||
if (0 != stat(real_name.utf8_str().GetData(), &s))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return S_ISDIR(s.st_mode); // NOLINT
|
||||
}
|
||||
|
||||
bool sys_file_is_file_existing(const String& name)
|
||||
{
|
||||
String real_name = get_internal_name(name);
|
||||
|
||||
struct stat s
|
||||
{
|
||||
};
|
||||
|
||||
if (0 != stat(real_name.utf8_str().GetData(), &s))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !S_ISDIR(s.st_mode); // NOLINT
|
||||
}
|
||||
|
||||
bool sys_file_create_directory(const String& path)
|
||||
{
|
||||
String real_name = get_internal_name(path);
|
||||
|
||||
mode_t m = S_IRWXU | S_IRWXG | S_IRWXO; // NOLINT
|
||||
|
||||
String::Utf8 u = real_name.utf8_str();
|
||||
|
||||
int r = mkdir(u.GetDataConst(), m);
|
||||
|
||||
if (r != 0)
|
||||
{
|
||||
int e = errno;
|
||||
if (e == EEXIST)
|
||||
{
|
||||
printf("mkdir(%s, %" PRIx32 ") failed: The named file exists\n", real_name.C_Str(), static_cast<uint32_t>(m));
|
||||
} else
|
||||
{
|
||||
printf("mkdir(%s, %" PRIx32 ") failed: %d\n", real_name.C_Str(), static_cast<uint32_t>(m), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sys_file_delete_directory(const String& path)
|
||||
{
|
||||
String real_name = get_internal_name(path);
|
||||
|
||||
return 0 == remove(real_name.utf8_str().GetData());
|
||||
}
|
||||
|
||||
bool sys_file_delete_file(const String& name)
|
||||
{
|
||||
String real_name = get_internal_name(name);
|
||||
|
||||
return 0 == unlink(real_name.utf8_str().GetData());
|
||||
}
|
||||
|
||||
bool sys_file_flush(sys_file_t& f)
|
||||
{
|
||||
if (f.type == SYS_FILE_FILE && f.f != nullptr)
|
||||
{
|
||||
return (fflush(f.f) == 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SysFileTimeStruct sys_file_get_last_access_time_utc(const String& name)
|
||||
{
|
||||
SysFileTimeStruct r {};
|
||||
|
||||
String real_name = get_internal_name(name);
|
||||
|
||||
struct stat s
|
||||
{
|
||||
};
|
||||
|
||||
if (0 != stat(real_name.utf8_str().GetData(), &s))
|
||||
{
|
||||
r.is_invalid = true;
|
||||
} else
|
||||
{
|
||||
r.is_invalid = false;
|
||||
r.time = s.st_atime;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
SysFileTimeStruct sys_file_get_last_write_time_utc(const String& name)
|
||||
{
|
||||
SysFileTimeStruct r {};
|
||||
|
||||
String real_name = get_internal_name(name);
|
||||
|
||||
struct stat s
|
||||
{
|
||||
};
|
||||
|
||||
if (0 != stat(real_name.utf8_str().GetData(), &s))
|
||||
{
|
||||
r.is_invalid = true;
|
||||
} else
|
||||
{
|
||||
r.is_invalid = false;
|
||||
r.time = s.st_mtime;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void sys_file_get_last_access_and_write_time_utc(const String& name, SysFileTimeStruct& a, SysFileTimeStruct& w)
|
||||
{
|
||||
String real_name = get_internal_name(name);
|
||||
|
||||
struct stat s
|
||||
{
|
||||
};
|
||||
|
||||
if (0 != stat(real_name.utf8_str().GetData(), &s))
|
||||
{
|
||||
a.is_invalid = true;
|
||||
w.is_invalid = true;
|
||||
} else
|
||||
{
|
||||
a.is_invalid = false;
|
||||
w.is_invalid = false;
|
||||
a.time = s.st_atime;
|
||||
w.time = s.st_mtime;
|
||||
}
|
||||
}
|
||||
|
||||
void sys_file_get_last_access_and_write_time_utc(sys_file_t& /*f*/, SysFileTimeStruct& /*a*/, SysFileTimeStruct& /*w*/)
|
||||
{
|
||||
EXIT("not implemented\n");
|
||||
}
|
||||
|
||||
bool sys_file_set_last_access_time_utc(const String& name, SysFileTimeStruct& access)
|
||||
{
|
||||
if (access.is_invalid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String real_name = get_internal_name(name);
|
||||
|
||||
struct stat s
|
||||
{
|
||||
};
|
||||
|
||||
String::Utf8 n = real_name.utf8_str();
|
||||
|
||||
if (0 != stat(n.GetData(), &s))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
utimbuf times {};
|
||||
times.actime = access.time;
|
||||
times.modtime = s.st_mtime;
|
||||
|
||||
return !(0 != utime(n.GetData(), ×));
|
||||
|
||||
// if (0 != stat(n.GetData(), &s))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// times.actime += times.actime - s.st_atime;
|
||||
// times.modtime += times.modtime - s.st_mtime;
|
||||
//
|
||||
// if (0 != utime(n.GetData(), ×))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
bool sys_file_set_last_write_time_utc(const String& name, SysFileTimeStruct& write)
|
||||
{
|
||||
if (write.is_invalid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String real_name = get_internal_name(name);
|
||||
|
||||
struct stat s
|
||||
{
|
||||
};
|
||||
|
||||
String::Utf8 n = real_name.utf8_str();
|
||||
|
||||
if (0 != stat(n.GetData(), &s))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
utimbuf times {};
|
||||
times.actime = s.st_atime;
|
||||
times.modtime = write.time;
|
||||
|
||||
return !(0 != utime(n.GetData(), ×));
|
||||
|
||||
// if (0 != stat(n.GetData(), &s))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// times.actime += times.actime - s.st_atime;
|
||||
// times.modtime += times.modtime - s.st_mtime;
|
||||
//
|
||||
// if (0 != utime(n.GetData(), ×))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
bool sys_file_set_last_access_and_write_time_utc(const String& name, SysFileTimeStruct& access, SysFileTimeStruct& write)
|
||||
{
|
||||
if (access.is_invalid || write.is_invalid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String real_name = get_internal_name(name);
|
||||
|
||||
struct stat s
|
||||
{
|
||||
};
|
||||
|
||||
String::Utf8 n = real_name.utf8_str();
|
||||
|
||||
if (0 != stat(n.GetData(), &s))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
utimbuf times {};
|
||||
times.actime = access.time;
|
||||
times.modtime = write.time;
|
||||
|
||||
return !(0 != utime(n.GetData(), ×));
|
||||
|
||||
// if (0 != stat(n.GetData(), &s))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// times.actime += times.actime - s.st_atime;
|
||||
// times.modtime += times.modtime - s.st_mtime;
|
||||
//
|
||||
// if (0 != utime(n.GetData(), ×))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
void sys_file_find_files(const String& /*path*/, Vector<sys_file_find_t>& /*out*/)
|
||||
{
|
||||
EXIT("not implemented\n");
|
||||
}
|
||||
|
||||
void sys_file_get_dents(const String& /*path*/, Kyty::Vector<sys_dir_entry_t>& /*out*/)
|
||||
{
|
||||
EXIT("not implemented\n");
|
||||
}
|
||||
|
||||
bool sys_file_copy_file(const String& /*src*/, const String& /*dst*/)
|
||||
{
|
||||
EXIT("not implemented\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sys_file_move_file(const String& /*src*/, const String& /*dst*/)
|
||||
{
|
||||
EXIT("not implemented\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
void sys_file_remove_readonly(const String& /*name*/)
|
||||
{
|
||||
EXIT("not implemented\n");
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
||||
#endif
|
|
@ -0,0 +1,371 @@
|
|||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include "Kyty/Core/DbgAssert.h"
|
||||
#include "Kyty/Core/String.h"
|
||||
#include "Kyty/Core/VirtualMemory.h"
|
||||
#include "Kyty/Sys/SysVirtual.h"
|
||||
|
||||
#include "cpuinfo.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <map>
|
||||
#include <pthread.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
// IWYU pragma: no_include <asm/mman-common.h>
|
||||
// IWYU pragma: no_include <asm/mman.h>
|
||||
// IWYU pragma: no_include <bits/pthread_types.h>
|
||||
// IWYU pragma: no_include <linux/mman.h>
|
||||
|
||||
#if defined(MAP_FIXED_NOREPLACE) && KYTY_PLATFORM == KYTY_PLATFORM_MACOS
|
||||
#define KYTY_FIXED_NOREPLACE
|
||||
#endif
|
||||
|
||||
namespace Kyty::Core {
|
||||
|
||||
static pthread_mutex_t g_virtual_mutex {};
|
||||
static std::map<uintptr_t, size_t>* g_allocs = nullptr;
|
||||
static std::map<uintptr_t, int>* g_protects = nullptr;
|
||||
|
||||
void sys_get_system_info(SystemInfo* info)
|
||||
{
|
||||
EXIT_IF(info == nullptr);
|
||||
|
||||
const auto* p = cpuinfo_get_package(0);
|
||||
|
||||
EXIT_IF(p == nullptr);
|
||||
|
||||
info->ProcessorName = String::FromUtf8(p->name);
|
||||
}
|
||||
|
||||
void sys_virtual_init()
|
||||
{
|
||||
pthread_mutexattr_t attr {};
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_LINUX
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_FAST_NP);
|
||||
#else
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
|
||||
#endif
|
||||
pthread_mutex_init(&g_virtual_mutex, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
|
||||
g_allocs = new std::map<uintptr_t, size_t>;
|
||||
g_protects = new std::map<uintptr_t, int>;
|
||||
|
||||
cpuinfo_initialize();
|
||||
}
|
||||
|
||||
static int get_protection_flag(VirtualMemory::Mode mode)
|
||||
{
|
||||
int protect = PROT_NONE;
|
||||
switch (mode)
|
||||
{
|
||||
case VirtualMemory::Mode::Read: protect = PROT_READ; break;
|
||||
case VirtualMemory::Mode::Write:
|
||||
case VirtualMemory::Mode::ReadWrite: protect = PROT_READ | PROT_WRITE; break; // NOLINT
|
||||
case VirtualMemory::Mode::Execute: protect = PROT_EXEC; break;
|
||||
case VirtualMemory::Mode::ExecuteRead: protect = PROT_EXEC | PROT_READ; break; // NOLINT
|
||||
case VirtualMemory::Mode::ExecuteWrite:
|
||||
case VirtualMemory::Mode::ExecuteReadWrite: protect = PROT_EXEC | PROT_WRITE | PROT_READ; break; // NOLINT
|
||||
case VirtualMemory::Mode::NoAccess:
|
||||
default: protect = PROT_NONE; break;
|
||||
}
|
||||
return protect;
|
||||
}
|
||||
|
||||
static VirtualMemory::Mode get_protection_flag(int mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case PROT_NONE: return VirtualMemory::Mode::NoAccess;
|
||||
case PROT_READ: return VirtualMemory::Mode::Read;
|
||||
case PROT_WRITE: return VirtualMemory::Mode::Write;
|
||||
case PROT_READ | PROT_WRITE: return VirtualMemory::Mode::ReadWrite; // NOLINT
|
||||
case PROT_EXEC: return VirtualMemory::Mode::Execute;
|
||||
case PROT_EXEC | PROT_WRITE: return VirtualMemory::Mode::ExecuteWrite; // NOLINT
|
||||
case PROT_EXEC | PROT_READ: return VirtualMemory::Mode::ExecuteRead; // NOLINT
|
||||
case PROT_EXEC | PROT_WRITE | PROT_READ: return VirtualMemory::Mode::ExecuteReadWrite; // NOLINT
|
||||
default: return VirtualMemory::Mode::NoAccess;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t sys_virtual_alloc(uint64_t address, uint64_t size, VirtualMemory::Mode mode)
|
||||
{
|
||||
EXIT_IF(g_allocs == nullptr);
|
||||
|
||||
auto addr = static_cast<uintptr_t>(address);
|
||||
|
||||
int protect = get_protection_flag(mode);
|
||||
|
||||
void* ptr = mmap(reinterpret_cast<void*>(addr), size, protect, MAP_PRIVATE | MAP_ANON, -1, 0); // NOLINT
|
||||
|
||||
auto ret_addr = reinterpret_cast<uintptr_t>(ptr);
|
||||
|
||||
if (ptr != MAP_FAILED)
|
||||
{
|
||||
pthread_mutex_lock(&g_virtual_mutex);
|
||||
(*g_allocs)[ret_addr] = size;
|
||||
uintptr_t page_start = ret_addr >> 12u;
|
||||
uintptr_t page_end = (ret_addr + size - 1) >> 12u;
|
||||
for (uintptr_t page = page_start; page <= page_end; page++)
|
||||
{
|
||||
(*g_protects)[page] = protect;
|
||||
}
|
||||
pthread_mutex_unlock(&g_virtual_mutex);
|
||||
}
|
||||
|
||||
return ret_addr;
|
||||
}
|
||||
|
||||
static uintptr_t align_up(uintptr_t addr, uint64_t alignment)
|
||||
{
|
||||
return (addr + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
||||
uint64_t sys_virtual_alloc_aligned(uint64_t address, uint64_t size, VirtualMemory::Mode mode, uint64_t alignment)
|
||||
{
|
||||
if (alignment == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXIT_IF(g_allocs == nullptr);
|
||||
|
||||
auto addr = static_cast<uintptr_t>(address);
|
||||
int protect = get_protection_flag(mode);
|
||||
|
||||
void* ptr = mmap(reinterpret_cast<void*>(addr), size, protect, MAP_PRIVATE | MAP_ANON, -1, 0); // NOLINT
|
||||
|
||||
auto ret_addr = reinterpret_cast<uintptr_t>(ptr);
|
||||
|
||||
if (ptr != MAP_FAILED && ((ret_addr & (alignment - 1)) != 0))
|
||||
{
|
||||
munmap(ptr, size);
|
||||
|
||||
ptr = mmap(reinterpret_cast<void*>(addr), size + alignment, protect, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0); // NOLINT
|
||||
ret_addr = reinterpret_cast<uintptr_t>(ptr);
|
||||
if (ptr != MAP_FAILED)
|
||||
{
|
||||
munmap(ptr, size + alignment);
|
||||
auto aligned_addr = align_up(ret_addr, alignment);
|
||||
#ifdef KYTY_FIXED_NOREPLACE
|
||||
// NOLINTNEXTLINE
|
||||
ptr = mmap(reinterpret_cast<void*>(aligned_addr), size, protect, MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
#else
|
||||
// NOLINTNEXTLINE
|
||||
ptr = mmap(reinterpret_cast<void*>(aligned_addr), size, protect, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
#endif
|
||||
ret_addr = reinterpret_cast<uintptr_t>(ptr);
|
||||
if (ptr == MAP_FAILED)
|
||||
{
|
||||
[[maybe_unused]] int err = errno;
|
||||
// printf("mmap failed: %d\n", err);
|
||||
}
|
||||
if (ptr != MAP_FAILED && ((ret_addr & (alignment - 1)) != 0))
|
||||
{
|
||||
munmap(ptr, size);
|
||||
ret_addr = 0;
|
||||
ptr = MAP_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr == MAP_FAILED)
|
||||
{
|
||||
return sys_virtual_alloc_aligned(address, size, mode, alignment << 1u);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_virtual_mutex);
|
||||
(*g_allocs)[ret_addr] = size;
|
||||
uintptr_t page_start = ret_addr >> 12u;
|
||||
uintptr_t page_end = (ret_addr + size - 1) >> 12u;
|
||||
for (uintptr_t page = page_start; page <= page_end; page++)
|
||||
{
|
||||
(*g_protects)[page] = protect;
|
||||
}
|
||||
pthread_mutex_unlock(&g_virtual_mutex);
|
||||
|
||||
return ret_addr;
|
||||
}
|
||||
|
||||
[[maybe_unused]] static bool is_mmaped(void* ptr, size_t length)
|
||||
{
|
||||
FILE* file = fopen("/proc/self/maps", "r");
|
||||
char line[1024];
|
||||
bool ret = false;
|
||||
auto addr = reinterpret_cast<uintptr_t>(ptr);
|
||||
|
||||
[[maybe_unused]] int result = 0;
|
||||
|
||||
while (feof(file) == 0)
|
||||
{
|
||||
if (fgets(line, 1024, file) == nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
uint64_t start = 0;
|
||||
uint64_t end = 0;
|
||||
// NOLINTNEXTLINE(cert-err34-c)
|
||||
if (sscanf(line, "%" SCNx64 "-%" SCNx64, &start, &end) != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (addr >= start && addr + length <= end)
|
||||
{
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
result = fclose(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool sys_virtual_alloc_fixed(uint64_t address, uint64_t size, VirtualMemory::Mode mode)
|
||||
{
|
||||
EXIT_IF(g_allocs == nullptr);
|
||||
|
||||
auto addr = static_cast<uintptr_t>(address);
|
||||
int protect = get_protection_flag(mode);
|
||||
|
||||
#ifdef KYTY_FIXED_NOREPLACE
|
||||
// NOLINTNEXTLINE
|
||||
void* ptr = mmap(reinterpret_cast<void*>(addr), size, protect, MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
#else
|
||||
// NOLINTNEXTLINE
|
||||
void* ptr = (is_mmaped(reinterpret_cast<void*>(addr), size)
|
||||
? MAP_FAILED
|
||||
: mmap(reinterpret_cast<void*>(addr), size, protect, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0));
|
||||
#endif
|
||||
|
||||
auto ret_addr = reinterpret_cast<uintptr_t>(ptr);
|
||||
|
||||
if (ptr != MAP_FAILED && ret_addr != addr)
|
||||
{
|
||||
munmap(ptr, size);
|
||||
ret_addr = 0;
|
||||
ptr = MAP_FAILED;
|
||||
}
|
||||
|
||||
if (ptr != MAP_FAILED)
|
||||
{
|
||||
pthread_mutex_lock(&g_virtual_mutex);
|
||||
(*g_allocs)[ret_addr] = size;
|
||||
uintptr_t page_start = ret_addr >> 12u;
|
||||
uintptr_t page_end = (ret_addr + size - 1) >> 12u;
|
||||
for (uintptr_t page = page_start; page <= page_end; page++)
|
||||
{
|
||||
(*g_protects)[page] = protect;
|
||||
}
|
||||
pthread_mutex_unlock(&g_virtual_mutex);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sys_virtual_free(uint64_t address)
|
||||
{
|
||||
EXIT_IF(g_allocs == nullptr);
|
||||
size_t size = 0;
|
||||
|
||||
auto addr = static_cast<uintptr_t>(address & ~static_cast<uint64_t>(0xfffu));
|
||||
|
||||
pthread_mutex_lock(&g_virtual_mutex);
|
||||
if (auto s = g_allocs->find(addr); s != g_allocs->end())
|
||||
{
|
||||
size = s->second;
|
||||
g_allocs->erase(s);
|
||||
}
|
||||
pthread_mutex_unlock(&g_virtual_mutex);
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (munmap(reinterpret_cast<void*>(addr), size) == 0)
|
||||
{
|
||||
uintptr_t page_start = addr >> 12u;
|
||||
uintptr_t page_end = (addr + size - 1) >> 12u;
|
||||
pthread_mutex_lock(&g_virtual_mutex);
|
||||
for (uintptr_t page = page_start; page <= page_end; page++)
|
||||
{
|
||||
if (auto s = g_protects->find(page); s != g_protects->end())
|
||||
{
|
||||
g_protects->erase(s);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_virtual_mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sys_virtual_protect(uint64_t address, uint64_t size, VirtualMemory::Mode mode, VirtualMemory::Mode* old_mode)
|
||||
{
|
||||
auto addr = static_cast<uintptr_t>(address);
|
||||
|
||||
pthread_mutex_lock(&g_virtual_mutex);
|
||||
if (old_mode != nullptr)
|
||||
{
|
||||
if (auto s = g_protects->find(addr >> 12u); s != g_protects->end())
|
||||
{
|
||||
*old_mode = get_protection_flag(s->second);
|
||||
} else
|
||||
{
|
||||
*old_mode = VirtualMemory::Mode::NoAccess;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_virtual_mutex);
|
||||
|
||||
uintptr_t page_start = addr >> 12u;
|
||||
uintptr_t page_end = (addr + size - 1) >> 12u;
|
||||
if (mprotect(reinterpret_cast<void*>(page_start << 12u), (page_end - page_start + 1) << 12u, get_protection_flag(mode)) == 0)
|
||||
{
|
||||
pthread_mutex_lock(&g_virtual_mutex);
|
||||
for (uintptr_t page = page_start; page <= page_end; page++)
|
||||
{
|
||||
(*g_protects)[page] = get_protection_flag(mode);
|
||||
}
|
||||
pthread_mutex_unlock(&g_virtual_mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sys_virtual_flush_instruction_cache(uint64_t /*address*/, uint64_t /*size*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sys_virtual_patch_replace(uint64_t vaddr, uint64_t value)
|
||||
{
|
||||
VirtualMemory::Mode old_mode {};
|
||||
sys_virtual_protect(vaddr, 8, VirtualMemory::Mode::ReadWrite, &old_mode);
|
||||
|
||||
auto* ptr = reinterpret_cast<uint64_t*>(vaddr);
|
||||
|
||||
bool ret = (*ptr != value);
|
||||
|
||||
*ptr = value;
|
||||
|
||||
sys_virtual_protect(vaddr, 8, old_mode);
|
||||
|
||||
if (VirtualMemory::IsExecute(old_mode))
|
||||
{
|
||||
sys_virtual_flush_instruction_cache(vaddr, 8);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace Kyty::Core
|
||||
|
||||
#endif
|
|
@ -10,18 +10,19 @@
|
|||
// IWYU pragma: no_include <excpt.h>
|
||||
// IWYU pragma: no_include <winbase.h>
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS
|
||||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS"
|
||||
#else
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
|
||||
#include "Kyty/Core/DbgAssert.h"
|
||||
#include "Kyty/Sys/SysDbg.h"
|
||||
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#include <psapi.h> // IWYU pragma: keep
|
||||
|
||||
|
||||
#if KYTY_COMPILER == KYTY_COMPILER_MSVC
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
#include <psapi.h> // IWYU pragma: keep
|
||||
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
|
@ -35,10 +36,9 @@ static thread_local sys_dbg_stack_info_t g_stack = {0};
|
|||
|
||||
struct FrameS
|
||||
{
|
||||
struct FrameS* next;
|
||||
void* ret_addr;
|
||||
struct FrameS* next;
|
||||
void* ret_addr;
|
||||
};
|
||||
|
||||
constexpr DWORD READABLE =
|
||||
(static_cast<DWORD>(PAGE_EXECUTE_READ) | static_cast<DWORD>(PAGE_EXECUTE_READWRITE) | static_cast<DWORD>(PAGE_EXECUTE_WRITECOPY) |
|
||||
static_cast<DWORD>(PAGE_READONLY) | static_cast<DWORD>(PAGE_READWRITE) | static_cast<DWORD>(PAGE_WRITECOPY));
|
||||
|
@ -48,94 +48,94 @@ exception_filter_func_t g_exception_filter_func = nullptr;
|
|||
|
||||
bool sys_mem_read_allowed(void* ptr)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
|
||||
size_t s = VirtualQuery(ptr, &mbi, sizeof(mbi));
|
||||
size_t s = VirtualQuery(ptr, &mbi, sizeof(mbi));
|
||||
|
||||
if (s == 0)
|
||||
{
|
||||
EXIT_IF(s == 0);
|
||||
}
|
||||
if (s == 0)
|
||||
{
|
||||
EXIT_IF(s == 0);
|
||||
}
|
||||
|
||||
return ((mbi.Protect & PROTECTED) == 0u) && ((mbi.State & static_cast<DWORD>(MEM_COMMIT)) != 0u) &&
|
||||
((mbi.AllocationProtect & READABLE) != 0u);
|
||||
return ((mbi.Protect & PROTECTED) == 0u) && ((mbi.State & static_cast<DWORD>(MEM_COMMIT)) != 0u) &&
|
||||
((mbi.AllocationProtect & READABLE) != 0u);
|
||||
}
|
||||
|
||||
// LONG WINAPI
|
||||
// VectoredHandlerSkip(struct _EXCEPTION_POINTERS *ExceptionInfo)
|
||||
//{
|
||||
// PCONTEXT Context;
|
||||
// PCONTEXT Context;
|
||||
//
|
||||
// g_need_break = true;
|
||||
// g_need_break = true;
|
||||
//
|
||||
// Context = ExceptionInfo->ContextRecord;
|
||||
// Context = ExceptionInfo->ContextRecord;
|
||||
//#ifdef _AMD64_
|
||||
// Context->Rip++;
|
||||
// Context->Rip++;
|
||||
//#else
|
||||
// Context->Eip++;
|
||||
// Context->Eip++;
|
||||
//#endif
|
||||
// return EXCEPTION_CONTINUE_EXECUTION;
|
||||
// return EXCEPTION_CONTINUE_EXECUTION;
|
||||
//}
|
||||
|
||||
#if KYTY_BITNESS == 32
|
||||
static void stackwalk(void* ebp, void** stack, int* depth, uintptr_t stack_addr, size_t stack_size)
|
||||
{
|
||||
frame_t* frame = (frame_t*)ebp;
|
||||
frame_t* frame = (frame_t*)ebp;
|
||||
|
||||
int d = *depth;
|
||||
int d = *depth;
|
||||
|
||||
int i;
|
||||
int i;
|
||||
|
||||
// printf("1\n");
|
||||
for (i = 0; i < KYTY_FRAME_SKIP; i++)
|
||||
{
|
||||
// if (uintptr_t(frame) <= 0xffff || (uintptr_t(frame) & 0xf0000000)
|
||||
// || frame->ret_addr == 0
|
||||
// || (uintptr_t(frame->ret_addr) & 0xf0000000)
|
||||
// || (uintptr_t(frame->next) & 0xf0000000)) break;
|
||||
// if (!sys_mem_read_allowed(&frame->next)) break;
|
||||
if (!(uintptr_t(frame) >= stack_addr && uintptr_t(frame) < stack_addr + stack_size)) break;
|
||||
// printf("1\n");
|
||||
for (i = 0; i < KYTY_FRAME_SKIP; i++)
|
||||
{
|
||||
// if (uintptr_t(frame) <= 0xffff || (uintptr_t(frame) & 0xf0000000)
|
||||
// || frame->ret_addr == 0
|
||||
// || (uintptr_t(frame->ret_addr) & 0xf0000000)
|
||||
// || (uintptr_t(frame->next) & 0xf0000000)) break;
|
||||
// if (!sys_mem_read_allowed(&frame->next)) break;
|
||||
if (!(uintptr_t(frame) >= stack_addr && uintptr_t(frame) < stack_addr + stack_size)) break;
|
||||
|
||||
frame = frame->next;
|
||||
}
|
||||
// printf("2\n");
|
||||
for (i = 0; i < d; i++)
|
||||
{
|
||||
//#ifdef _MSC_VER
|
||||
// __try
|
||||
// {
|
||||
//#endif
|
||||
// FILE *f = fopen("_sw", "wt");
|
||||
// printf("%d, %08x\n", i, (uint32_t)frame);
|
||||
// fflush(stdout);
|
||||
// fclose(f);
|
||||
// printf("%d, %08x, %08x, %08x\n", i, (uint32_t)frame,
|
||||
// (uint32_t)frame->ret_addr, (uint32_t)frame->next);
|
||||
frame = frame->next;
|
||||
}
|
||||
// printf("2\n");
|
||||
for (i = 0; i < d; i++)
|
||||
{
|
||||
//#ifdef _MSC_VER
|
||||
// __try
|
||||
// {
|
||||
//#endif
|
||||
// FILE *f = fopen("_sw", "wt");
|
||||
// printf("%d, %08x\n", i, (uint32_t)frame);
|
||||
// fflush(stdout);
|
||||
// fclose(f);
|
||||
// printf("%d, %08x, %08x, %08x\n", i, (uint32_t)frame,
|
||||
// (uint32_t)frame->ret_addr, (uint32_t)frame->next);
|
||||
|
||||
// if (uintptr_t(frame) <= 0xffff || (uintptr_t(frame) & 0xf0000000)
|
||||
// || frame->ret_addr == 0
|
||||
// || (uintptr_t(frame->ret_addr) & 0xf0000000)
|
||||
// || (uintptr_t(frame->next) & 0xf0000000)) break;
|
||||
// if (uintptr_t(frame) == 0 || frame->ret_addr == 0 ) break;
|
||||
// if (uintptr_t(frame) <= 0xffff || (uintptr_t(frame) & 0xf0000000)
|
||||
// || frame->ret_addr == 0
|
||||
// || (uintptr_t(frame->ret_addr) & 0xf0000000)
|
||||
// || (uintptr_t(frame->next) & 0xf0000000)) break;
|
||||
// if (uintptr_t(frame) == 0 || frame->ret_addr == 0 ) break;
|
||||
|
||||
// if (!sys_mem_read_allowed(&frame->next) || !sys_mem_read_allowed(&frame->ret_addr)) break;
|
||||
if (!(uintptr_t(frame) >= stack_addr && uintptr_t(frame) < stack_addr + stack_size)) break;
|
||||
// if (!sys_mem_read_allowed(&frame->next) || !sys_mem_read_allowed(&frame->ret_addr)) break;
|
||||
if (!(uintptr_t(frame) >= stack_addr && uintptr_t(frame) < stack_addr + stack_size)) break;
|
||||
|
||||
// if (g_need_break) break;
|
||||
// if (g_need_break) break;
|
||||
|
||||
stack[i] = frame->ret_addr;
|
||||
stack[i] = frame->ret_addr;
|
||||
|
||||
frame = frame->next;
|
||||
//#ifdef _MSC_VER
|
||||
// } __except(EXCEPTION_EXECUTE_HANDLER)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
// printf("3\n");
|
||||
frame = frame->next;
|
||||
//#ifdef _MSC_VER
|
||||
// } __except(EXCEPTION_EXECUTE_HANDLER)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
// printf("3\n");
|
||||
|
||||
*depth = i;
|
||||
*depth = i;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -143,157 +143,157 @@ static void stackwalk(void* ebp, void** stack, int* depth, uintptr_t stack_addr,
|
|||
void sys_stack_walk(void** stack, int* depth)
|
||||
{
|
||||
#if KYTY_COMPILER == KYTY_COMPILER_MSVC
|
||||
void* ebp = (size_t*)_AddressOfReturnAddress() - 1;
|
||||
void* ebp = (size_t*)_AddressOfReturnAddress() - 1;
|
||||
#else
|
||||
void* ebp = __builtin_frame_address(0);
|
||||
void* ebp = __builtin_frame_address(0);
|
||||
#endif
|
||||
|
||||
// g_need_break = false;
|
||||
// g_need_break = false;
|
||||
|
||||
//#ifndef _MSC_VER
|
||||
// PVOID p = AddVectoredExceptionHandler(1000, VectoredHandlerSkip);
|
||||
// if (!g_stack_addr) g_stack_addr = (uintptr_t)&depth;
|
||||
///#endif
|
||||
//#ifndef _MSC_VER
|
||||
// PVOID p = AddVectoredExceptionHandler(1000, VectoredHandlerSkip);
|
||||
// if (!g_stack_addr) g_stack_addr = (uintptr_t)&depth;
|
||||
///#endif
|
||||
|
||||
if (g_stack.total_size == 0)
|
||||
{
|
||||
sys_stack_usage(g_stack);
|
||||
}
|
||||
if (g_stack.total_size == 0)
|
||||
{
|
||||
sys_stack_usage(g_stack);
|
||||
}
|
||||
|
||||
stackwalk(ebp, stack, depth, g_stack.addr, g_stack.total_size);
|
||||
stackwalk(ebp, stack, depth, g_stack.addr, g_stack.total_size);
|
||||
|
||||
//#ifndef _MSC_VER
|
||||
// RemoveVectoredExceptionHandler(p);
|
||||
//#endif
|
||||
//#ifndef _MSC_VER
|
||||
// RemoveVectoredExceptionHandler(p);
|
||||
//#endif
|
||||
}
|
||||
#else
|
||||
//#include <unwind.h>
|
||||
// struct unwind_info_t
|
||||
//{
|
||||
// void **stack;
|
||||
// int depth;
|
||||
// int max_depth;
|
||||
// void **stack;
|
||||
// int depth;
|
||||
// int max_depth;
|
||||
//};
|
||||
//_Unwind_Reason_Code trace_fcn(_Unwind_Context *ctx, void *d)
|
||||
//{
|
||||
// unwind_info_t *info = (unwind_info_t*)d;
|
||||
// unwind_info_t *info = (unwind_info_t*)d;
|
||||
// //printf("\t#%d: program counter at %08x\n", *depth, _Unwind_GetIP(ctx));
|
||||
// //(*depth)++;
|
||||
// if (info->depth < info->max_depth)
|
||||
// {
|
||||
// void *ptr = (void*)_Unwind_GetIP(ctx);
|
||||
// info->stack[info->depth] = ptr;
|
||||
// info->depth++;
|
||||
// }
|
||||
// if (info->depth < info->max_depth)
|
||||
// {
|
||||
// void *ptr = (void*)_Unwind_GetIP(ctx);
|
||||
// info->stack[info->depth] = ptr;
|
||||
// info->depth++;
|
||||
// }
|
||||
// return _URC_NO_REASON;
|
||||
//}
|
||||
int WalkStack(int z_stack_depth, void** z_stack_trace)
|
||||
{
|
||||
CONTEXT context;
|
||||
// KNONVOLATILE_CONTEXT_POINTERS NvContext;
|
||||
PRUNTIME_FUNCTION runtime_function = nullptr;
|
||||
PVOID handler_data = nullptr;
|
||||
ULONG64 establisher_frame = 0;
|
||||
ULONG64 image_base = 0;
|
||||
CONTEXT context;
|
||||
// KNONVOLATILE_CONTEXT_POINTERS NvContext;
|
||||
PRUNTIME_FUNCTION runtime_function = nullptr;
|
||||
PVOID handler_data = nullptr;
|
||||
ULONG64 establisher_frame = 0;
|
||||
ULONG64 image_base = 0;
|
||||
|
||||
RtlCaptureContext(&context);
|
||||
RtlCaptureContext(&context);
|
||||
|
||||
int frame = 0;
|
||||
int frame = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (frame >= z_stack_depth)
|
||||
{
|
||||
break;
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
if (frame >= z_stack_depth)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
z_stack_trace[frame] = reinterpret_cast<void*>(context.Rip);
|
||||
z_stack_trace[frame] = reinterpret_cast<void*>(context.Rip);
|
||||
|
||||
frame++;
|
||||
frame++;
|
||||
|
||||
runtime_function = RtlLookupFunctionEntry(context.Rip, &image_base, nullptr);
|
||||
runtime_function = RtlLookupFunctionEntry(context.Rip, &image_base, nullptr);
|
||||
|
||||
if (runtime_function == nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (runtime_function == nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// RtlZeroMemory(&NvContext, sizeof(KNONVOLATILE_CONTEXT_POINTERS));
|
||||
RtlVirtualUnwind(0, image_base, context.Rip, runtime_function, &context, &handler_data, &establisher_frame, nullptr /*&NvContext*/);
|
||||
// RtlZeroMemory(&NvContext, sizeof(KNONVOLATILE_CONTEXT_POINTERS));
|
||||
RtlVirtualUnwind(0, image_base, context.Rip, runtime_function, &context, &handler_data, &establisher_frame, nullptr /*&NvContext*/);
|
||||
|
||||
if (context.Rip == 0u)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (context.Rip == 0u)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return frame;
|
||||
return frame;
|
||||
}
|
||||
|
||||
void sys_stack_walk(void** stack, int* depth)
|
||||
{
|
||||
// USHORT n = CaptureStackBackTrace(KYTY_FRAME_SKIP, *depth, stack, 0);
|
||||
int n = WalkStack(*depth, stack);
|
||||
*depth = n;
|
||||
// unwind_info_t info = {stack, 0, *depth};
|
||||
// _Unwind_Backtrace(&trace_fcn, &info);
|
||||
// *depth = info.depth;
|
||||
// USHORT n = CaptureStackBackTrace(KYTY_FRAME_SKIP, *depth, stack, 0);
|
||||
int n = WalkStack(*depth, stack);
|
||||
*depth = n;
|
||||
// unwind_info_t info = {stack, 0, *depth};
|
||||
// _Unwind_Backtrace(&trace_fcn, &info);
|
||||
// *depth = info.depth;
|
||||
}
|
||||
#endif
|
||||
|
||||
void sys_stack_usage_print(sys_dbg_stack_info_t& stack)
|
||||
{
|
||||
printf("stack: (0x%" PRIx64 ", %" PRIu64 ") + (0x%" PRIx64 ", %" PRIu64 ") + (0x%" PRIx64 ", %" PRIu64 ")\n",
|
||||
static_cast<uint64_t>(stack.reserved_addr), static_cast<uint64_t>(stack.reserved_size), static_cast<uint64_t>(stack.guard_addr),
|
||||
static_cast<uint64_t>(stack.guard_size), static_cast<uint64_t>(stack.commited_addr), static_cast<uint64_t>(stack.commited_size));
|
||||
printf("stack: (0x%" PRIx64 ", %" PRIu64 ") + (0x%" PRIx64 ", %" PRIu64 ") + (0x%" PRIx64 ", %" PRIu64 ")\n",
|
||||
static_cast<uint64_t>(stack.reserved_addr), static_cast<uint64_t>(stack.reserved_size), static_cast<uint64_t>(stack.guard_addr),
|
||||
static_cast<uint64_t>(stack.guard_size), static_cast<uint64_t>(stack.commited_addr), static_cast<uint64_t>(stack.commited_size));
|
||||
}
|
||||
|
||||
void sys_stack_usage(sys_dbg_stack_info_t& s)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi {};
|
||||
[[maybe_unused]] size_t ss = VirtualQuery(&mbi, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
PVOID reserved = mbi.AllocationBase;
|
||||
ss = VirtualQuery(reserved, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
size_t reserved_size = mbi.RegionSize;
|
||||
ss = VirtualQuery(static_cast<char*>(reserved) + reserved_size, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
void* guard_page = mbi.BaseAddress;
|
||||
size_t guard_page_size = mbi.RegionSize;
|
||||
ss = VirtualQuery(static_cast<char*>(guard_page) + guard_page_size, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
void* commited = mbi.BaseAddress;
|
||||
size_t commited_size = mbi.RegionSize;
|
||||
s.reserved_addr = reinterpret_cast<uintptr_t>(reserved);
|
||||
s.reserved_size = reserved_size;
|
||||
s.guard_addr = reinterpret_cast<uintptr_t>(guard_page);
|
||||
s.guard_size = guard_page_size;
|
||||
s.commited_addr = reinterpret_cast<uintptr_t>(commited);
|
||||
s.commited_size = commited_size;
|
||||
MEMORY_BASIC_INFORMATION mbi {};
|
||||
[[maybe_unused]] size_t ss = VirtualQuery(&mbi, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
PVOID reserved = mbi.AllocationBase;
|
||||
ss = VirtualQuery(reserved, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
size_t reserved_size = mbi.RegionSize;
|
||||
ss = VirtualQuery(static_cast<char*>(reserved) + reserved_size, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
void* guard_page = mbi.BaseAddress;
|
||||
size_t guard_page_size = mbi.RegionSize;
|
||||
ss = VirtualQuery(static_cast<char*>(guard_page) + guard_page_size, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
void* commited = mbi.BaseAddress;
|
||||
size_t commited_size = mbi.RegionSize;
|
||||
s.reserved_addr = reinterpret_cast<uintptr_t>(reserved);
|
||||
s.reserved_size = reserved_size;
|
||||
s.guard_addr = reinterpret_cast<uintptr_t>(guard_page);
|
||||
s.guard_size = guard_page_size;
|
||||
s.commited_addr = reinterpret_cast<uintptr_t>(commited);
|
||||
s.commited_size = commited_size;
|
||||
|
||||
s.addr = s.reserved_addr;
|
||||
s.total_size = s.reserved_size + s.guard_size + s.commited_size;
|
||||
s.addr = s.reserved_addr;
|
||||
s.total_size = s.reserved_size + s.guard_size + s.commited_size;
|
||||
}
|
||||
|
||||
void sys_get_code_info(uintptr_t* addr, size_t* size)
|
||||
{
|
||||
MODULEINFO info {};
|
||||
GetModuleInformation(GetCurrentProcess(), GetModuleHandle(nullptr), &info, sizeof(MODULEINFO));
|
||||
*addr = reinterpret_cast<uintptr_t>(info.lpBaseOfDll);
|
||||
*size = static_cast<size_t>(info.SizeOfImage);
|
||||
MODULEINFO info {};
|
||||
GetModuleInformation(GetCurrentProcess(), GetModuleHandle(nullptr), &info, sizeof(MODULEINFO));
|
||||
*addr = reinterpret_cast<uintptr_t>(info.lpBaseOfDll);
|
||||
*size = static_cast<size_t>(info.SizeOfImage);
|
||||
}
|
||||
|
||||
static LONG WINAPI ExceptionFilter(PEXCEPTION_POINTERS exception)
|
||||
{
|
||||
g_exception_filter_func(exception->ExceptionRecord->ExceptionAddress);
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
g_exception_filter_func(exception->ExceptionRecord->ExceptionAddress);
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
|
||||
void sys_set_exception_filter(exception_filter_func_t func)
|
||||
{
|
||||
g_exception_filter_func = func;
|
||||
SetUnhandledExceptionFilter(ExceptionFilter);
|
||||
g_exception_filter_func = func;
|
||||
SetUnhandledExceptionFilter(ExceptionFilter);
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS
|
||||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS"
|
||||
#else
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
|
||||
#include "Kyty/Core/MemoryAlloc.h"
|
||||
#include "Kyty/Core/String.h"
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS
|
||||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS"
|
||||
#else
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
|
||||
#include "Kyty/Core/DbgAssert.h"
|
||||
#include "Kyty/Core/String.h"
|
||||
|
@ -10,7 +8,6 @@
|
|||
#include "Kyty/Sys/SysVirtual.h"
|
||||
|
||||
#include "cpuinfo.h"
|
||||
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
|
||||
// IWYU pragma: no_include <basetsd.h>
|
||||
|
|
Loading…
Reference in New Issue