engine: whereami: sync with upstream

This commit is contained in:
Alibek Omarov 2025-01-21 20:03:20 +03:00
parent b7c025b167
commit 4eaa32fc10
2 changed files with 22 additions and 9 deletions

View file

@ -68,7 +68,13 @@ extern "C" {
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(pop) #pragma warning(pop)
#endif #endif
#if (_MSC_VER >= 1900)
#include <stdbool.h> #include <stdbool.h>
#else
#define bool int
#define false 0
#define true 1
#endif
static int WAI_PREFIX(getModulePath_)(HMODULE module, char* out, int capacity, int* dirname_length) static int WAI_PREFIX(getModulePath_)(HMODULE module, char* out, int capacity, int* dirname_length)
{ {
@ -243,6 +249,11 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
#endif #endif
#endif #endif
#if !defined(WAI_STRINGIZE)
#define WAI_STRINGIZE(s)
#define WAI_STRINGIZE_(s) #s
#endif
#if defined(__ANDROID__) || defined(ANDROID) #if defined(__ANDROID__) || defined(ANDROID)
#include <fcntl.h> #include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
@ -265,20 +276,20 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
for (;;) for (;;)
{ {
char buffer[PATH_MAX < 1024 ? 1024 : PATH_MAX]; char buffer[128 + PATH_MAX];
uint64_t low, high; uintptr_t low, high;
char perms[5]; char perms[5];
uint64_t offset; uint64_t offset;
uint32_t major, minor; uint32_t major, minor, inode;
char path[PATH_MAX]; char path[PATH_MAX + 1];
uint32_t inode;
if (!fgets(buffer, sizeof(buffer), maps)) if (!fgets(buffer, sizeof(buffer), maps))
break; break;
if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) if (sscanf(buffer, "%" SCNxPTR "-%" SCNxPTR " %s %" SCNx64 " %x:%x %u %" WAI_STRINGIZE(PATH_MAX) "[^\n]\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8)
{ {
uint64_t addr = (uintptr_t)WAI_RETURN_ADDRESS(); void* _addr = WAI_RETURN_ADDRESS();
uintptr_t addr = (uintptr_t)_addr;
if (low <= addr && addr <= high) if (low <= addr && addr <= high)
{ {
char* resolved; char* resolved;

View file

@ -31,7 +31,8 @@ extern "C" {
* @param out destination buffer, optional * @param out destination buffer, optional
* @param capacity destination buffer capacity * @param capacity destination buffer capacity
* @param dirname_length optional recipient for the length of the dirname part * @param dirname_length optional recipient for the length of the dirname part
* of the path. * of the path. Available only when `capacity` is large enough to retrieve the
* path.
* *
* @return the length of the executable path on success (without a terminal NUL * @return the length of the executable path on success (without a terminal NUL
* character), otherwise `-1` * character), otherwise `-1`
@ -52,7 +53,8 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length);
* @param out destination buffer, optional * @param out destination buffer, optional
* @param capacity destination buffer capacity * @param capacity destination buffer capacity
* @param dirname_length optional recipient for the length of the dirname part * @param dirname_length optional recipient for the length of the dirname part
* of the path. * of the path. Available only when `capacity` is large enough to retrieve the
* path.
* *
* @return the length of the module path on success (without a terminal NUL * @return the length of the module path on success (without a terminal NUL
* character), otherwise `-1` * character), otherwise `-1`