Added subject module
This commit is contained in:
parent
cf0d403716
commit
447431ae45
@ -11,7 +11,7 @@ file(MAKE_DIRECTORY "${SUBJECT_SPSLR_METADIR}")
|
|||||||
|
|
||||||
add_library(subject_objs OBJECT ${SUBJECT_SRC})
|
add_library(subject_objs OBJECT ${SUBJECT_SRC})
|
||||||
target_include_directories(subject_objs PRIVATE .)
|
target_include_directories(subject_objs PRIVATE .)
|
||||||
target_link_libraries(subject_objs PRIVATE spslr_selfpatch)
|
target_link_libraries(subject_objs PRIVATE spslr_selfpatch dl)
|
||||||
add_dependencies(subject_objs spslr_pinpoint)
|
add_dependencies(subject_objs spslr_pinpoint)
|
||||||
|
|
||||||
target_compile_options(subject_objs PRIVATE
|
target_compile_options(subject_objs PRIVATE
|
||||||
@ -66,3 +66,73 @@ target_include_directories(subject PRIVATE .)
|
|||||||
target_link_libraries(subject PRIVATE spslr_selfpatch)
|
target_link_libraries(subject PRIVATE spslr_selfpatch)
|
||||||
add_dependencies(subject spslr_selfpatch)
|
add_dependencies(subject spslr_selfpatch)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
set(MODULE_SRC
|
||||||
|
module.c
|
||||||
|
)
|
||||||
|
|
||||||
|
set(MODULE_SPSLR_METADIR "${CMAKE_CURRENT_BINARY_DIR}/spslr_module")
|
||||||
|
set(MODULE_SPSLR_SRCROOT "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
|
||||||
|
file(MAKE_DIRECTORY "${MODULE_SPSLR_METADIR}")
|
||||||
|
|
||||||
|
add_library(spslr_module_objs OBJECT ${MODULE_SRC})
|
||||||
|
target_include_directories(spslr_module_objs PRIVATE .)
|
||||||
|
add_dependencies(spslr_module_objs spslr_pinpoint)
|
||||||
|
|
||||||
|
target_compile_options(spslr_module_objs PRIVATE
|
||||||
|
-O1
|
||||||
|
-fPIC
|
||||||
|
-fplugin=$<TARGET_FILE:spslr_pinpoint>
|
||||||
|
-fplugin-arg-spslr_pinpoint-srcroot=${MODULE_SPSLR_SRCROOT}
|
||||||
|
-fplugin-arg-spslr_pinpoint-metadir=${MODULE_SPSLR_METADIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
set(MODULE_SPSLR_FILES "")
|
||||||
|
foreach(src IN LISTS MODULE_SRC)
|
||||||
|
get_filename_component(abs_src "${src}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
file(RELATIVE_PATH rel_src "${MODULE_SPSLR_SRCROOT}" "${abs_src}")
|
||||||
|
file(TO_CMAKE_PATH "${rel_src}" rel_src)
|
||||||
|
list(APPEND MODULE_SPSLR_FILES "${MODULE_SPSLR_METADIR}/${rel_src}.spslr")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set(MODULE_SPSLR_ASM "${CMAKE_CURRENT_BINARY_DIR}/spslr_module_program.S")
|
||||||
|
set(MODULE_SPSLR_OBJ "${CMAKE_CURRENT_BINARY_DIR}/spslr_module_program.o")
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${MODULE_SPSLR_ASM}"
|
||||||
|
COMMAND $<TARGET_FILE:spslr_patchcompile>
|
||||||
|
--out=${MODULE_SPSLR_ASM}
|
||||||
|
${MODULE_SPSLR_FILES}
|
||||||
|
DEPENDS
|
||||||
|
spslr_patchcompile
|
||||||
|
$<TARGET_OBJECTS:spslr_module_objs>
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${MODULE_SPSLR_OBJ}"
|
||||||
|
COMMAND ${CMAKE_C_COMPILER}
|
||||||
|
-fPIC
|
||||||
|
-c "${MODULE_SPSLR_ASM}"
|
||||||
|
-o "${MODULE_SPSLR_OBJ}"
|
||||||
|
DEPENDS "${MODULE_SPSLR_ASM}"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
|
||||||
|
set_source_files_properties("${MODULE_SPSLR_OBJ}" PROPERTIES
|
||||||
|
GENERATED TRUE
|
||||||
|
EXTERNAL_OBJECT TRUE
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(spslr_module SHARED
|
||||||
|
$<TARGET_OBJECTS:spslr_module_objs>
|
||||||
|
"${MODULE_SPSLR_OBJ}"
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(spslr_module PRIVATE .)
|
||||||
|
set_target_properties(spslr_module PROPERTIES
|
||||||
|
OUTPUT_NAME "spslr_module"
|
||||||
|
PREFIX "lib"
|
||||||
|
)
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
#include <spslr.h>
|
#include <spslr.h>
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "task_struct.h"
|
#include "task_struct.h"
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
|
|
||||||
@ -18,6 +22,32 @@ struct task_struct global = { .pid = 42, .comm = "main_global", .arrfun = {
|
|||||||
|
|
||||||
EXPORT_SYMBOL(global);
|
EXPORT_SYMBOL(global);
|
||||||
|
|
||||||
|
static int do_module_test_access_pid(const char *path, const struct task_struct *t) {
|
||||||
|
typedef int (*module_test_access_fn)(const struct task_struct *t);
|
||||||
|
|
||||||
|
void *handle = dlopen(path, RTLD_NOW | RTLD_LOCAL);
|
||||||
|
if (!handle) {
|
||||||
|
fprintf(stderr, "dlopen failed for %s: %s\n", path, dlerror());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dlerror();
|
||||||
|
|
||||||
|
module_test_access_fn fn = (module_test_access_fn)dlsym(handle, "module_test_access_pid");
|
||||||
|
|
||||||
|
const char *err = dlerror();
|
||||||
|
if (err) {
|
||||||
|
fprintf(stderr, "dlsym failed: %s\n", err);
|
||||||
|
dlclose(handle);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = fn(t);
|
||||||
|
|
||||||
|
dlclose(handle);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void print_layout() {
|
static void print_layout() {
|
||||||
// TODO -> Make builtin __spslr_initial_offsetof(type, field) that is not patched
|
// TODO -> Make builtin __spslr_initial_offsetof(type, field) that is not patched
|
||||||
printf("Current task_struct layout:\n");
|
printf("Current task_struct layout:\n");
|
||||||
@ -77,6 +107,9 @@ int main(void)
|
|||||||
|
|
||||||
arr_test();
|
arr_test();
|
||||||
|
|
||||||
|
int module_pid = do_module_test_access_pid("./subject/libspslr_module.so", &global);
|
||||||
|
printf("module_test_access returned %d (should be 42)\n", module_pid);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
subject/module.c
Normal file
5
subject/module.c
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include "module.h"
|
||||||
|
|
||||||
|
int module_test_access_pid(const struct task_struct* t) {
|
||||||
|
return t->pid;
|
||||||
|
}
|
||||||
3
subject/module.h
Normal file
3
subject/module.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#include "task_struct.h"
|
||||||
|
|
||||||
|
int module_test_access_pid(const struct task_struct* t);
|
||||||
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef HDR_TASK_STRUCT
|
||||||
|
#define HDR_TASK_STRUCT
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
@ -81,3 +84,4 @@ struct task_struct {
|
|||||||
int stuck1, stuck2;
|
int stuck1, stuck2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user