Added EXPORT_SYMBOL to subject

This commit is contained in:
York Jasper Niebuhr 2026-04-08 11:19:39 +02:00
parent fc40f620fb
commit 1ab19d488c
2 changed files with 35 additions and 0 deletions

32
subject/export.h Normal file
View File

@ -0,0 +1,32 @@
#include <stdio.h>
#define __stringify_1(x) #x
#define __stringify(x) __stringify_1(x)
#define __ADDRESSABLE(sym) \
static void * __addressable_##sym __attribute__((used)) = (void *)&(sym)
#define __GENDWARFKSYMS_EXPORT(sym) /* nothing */
#define ASM_NL "\n"
#define __EXPORT_SYMBOL_REF(sym) \
".balign 8" ASM_NL \
".quad " __stringify(sym)
#define ___EXPORT_SYMBOL(sym, license, ns...) \
".section \".export_symbol\",\"a\"" ASM_NL \
"__export_symbol_" __stringify(sym) ":" ASM_NL \
".asciz \"" license "\"" ASM_NL \
".ascii \"" ns "\\0\"" ASM_NL \
__EXPORT_SYMBOL_REF(sym) ASM_NL \
".previous"
#define __EXPORT_SYMBOL(sym, license, ns) \
extern typeof(sym) sym; \
__ADDRESSABLE(sym); \
__GENDWARFKSYMS_EXPORT(sym); \
asm(___EXPORT_SYMBOL(sym, license, ns))
#define EXPORT_SYMBOL(sym) __EXPORT_SYMBOL(sym, "license", "namespace")

View File

@ -1,6 +1,7 @@
#include <spslr.h>
#include "task_struct.h"
#include "export.h"
int second_pid();
const char* second_comm();
@ -15,6 +16,8 @@ struct task_struct global = { .pid = 42, .comm = "main_global", .arrfun = {
{ .a = 17, .b = 18, .c = 19, .d = 20.0 }
}, .tasks = LIST_HEAD_SELF(global.tasks) };
EXPORT_SYMBOL(global);
static void print_layout() {
// TODO -> Make builtin __spslr_initial_offsetof(type, field) that is not patched
printf("Current task_struct layout:\n");