twn_textures.c: support for .so rodata inference
This commit is contained in:
@ -140,3 +140,10 @@ bool game_object_try_reloading(void) {
|
||||
void game_object_tick(void) {
|
||||
game_tick_callback();
|
||||
}
|
||||
|
||||
void *game_object_get_game_tick_address(void) {
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
return (void *)&game_tick_callback;
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
@ -19,3 +19,10 @@ bool game_object_try_reloading(void) {
|
||||
void game_object_tick(void) {
|
||||
game_tick();
|
||||
}
|
||||
|
||||
void *game_object_get_game_tick_address(void) {
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
return (void *)&game_tick;
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
@ -1,10 +1,13 @@
|
||||
#include "elf.h"
|
||||
#include "twn_elf.h"
|
||||
#include "twn_game_object_c.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/auxv.h>
|
||||
#include <elf.h>
|
||||
#include <linux/limits.h>
|
||||
#define __USE_GNU
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@ -17,10 +20,21 @@ bool infer_elf_section_bounds(const char *const restrict name,
|
||||
{
|
||||
bool result = false;
|
||||
char buf[PATH_MAX];
|
||||
ssize_t l = readlink("/proc/self/exe", buf, PATH_MAX);
|
||||
if (l == -1)
|
||||
goto ERR_CANT_READLINK;
|
||||
buf[l] = 0; /* readlink() doesn't write a terminator */
|
||||
bool from_shared_object;
|
||||
Dl_info info;
|
||||
|
||||
if (!dladdr(game_object_get_game_tick_address(), &info)) {
|
||||
/* statically linked */
|
||||
from_shared_object = false;
|
||||
ssize_t l = readlink("/proc/self/exe", buf, PATH_MAX);
|
||||
if (l == -1)
|
||||
goto ERR_CANT_READLINK;
|
||||
buf[l] = 0; /* readlink() doesn't write a terminator */
|
||||
} else {
|
||||
/* dynamically linked */
|
||||
from_shared_object = true;
|
||||
memcpy(buf, "libgame.so", sizeof "libgame.so");
|
||||
}
|
||||
|
||||
int elf = open(buf, O_RDONLY);
|
||||
if (elf == -1)
|
||||
@ -51,8 +65,15 @@ bool infer_elf_section_bounds(const char *const restrict name,
|
||||
|
||||
if (strcmp(&sh[shdr.sh_name], name) == 0) {
|
||||
result = true;
|
||||
*vm_start = getauxval(AT_ENTRY) - ehdr.e_entry + (char *)shdr.sh_addr;
|
||||
*vm_end = getauxval(AT_ENTRY) - ehdr.e_entry + (char *)shdr.sh_addr + shdr.sh_size;
|
||||
|
||||
if (!from_shared_object) {
|
||||
*vm_start = getauxval(AT_ENTRY) - ehdr.e_entry + (char *)shdr.sh_addr;
|
||||
*vm_end = getauxval(AT_ENTRY) - ehdr.e_entry + (char *)shdr.sh_addr + shdr.sh_size;
|
||||
} else {
|
||||
*vm_start = (uintptr_t)info.dli_fbase + (char *)shdr.sh_addr;
|
||||
*vm_end = (uintptr_t)info.dli_fbase + (char *)shdr.sh_addr + shdr.sh_size;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
#if defined(TWN_FEATURE_DYNLIB_GAME)
|
||||
#if defined(__linux__)
|
||||
#include "game_object/twn_linux_game_object_c.h"
|
||||
#elif defined(_WIN32)
|
||||
#include "game_object/twn_win32_game_object_c.h"
|
||||
#else
|
||||
#warning "TWN_FEATURE_DYNLIB_GAME is set, but not supported"
|
||||
#include "game_object/twn_static_game_object_c.h"
|
||||
#endif
|
||||
#else
|
||||
#include "game_object/twn_static_game_object_c.h"
|
||||
#endif
|
@ -18,5 +18,6 @@ bool game_object_try_reloading(void);
|
||||
|
||||
void game_object_tick(void);
|
||||
|
||||
void *game_object_get_game_tick_address(void);
|
||||
|
||||
#endif
|
||||
|
@ -413,7 +413,7 @@ void textures_update_atlas(struct texture_cache *cache) {
|
||||
}
|
||||
|
||||
/* EXPERIMANTAL: LIKELY TO BE REMOVED! */
|
||||
#if defined(__linux__) && !defined(HOT_RELOAD_SUPPORT) /* use rodata elf section for fast lookups of repeating textures */
|
||||
#if defined(__linux__) /* use rodata elf section for fast lookups of repeating textures */
|
||||
|
||||
#include "system/linux/twn_elf.h"
|
||||
|
||||
|
Reference in New Issue
Block a user