From cd045eff06920e6463b8a0325cc2efa46f532301 Mon Sep 17 00:00:00 2001 From: York Jasper Niebuhr Date: Sun, 5 Apr 2026 18:50:30 +0200 Subject: [PATCH] Implemented spslr_field_fixed attribute --- pinpoint/pinpoint_config.h | 1 + pinpoint/safegcc/safe-attribs.h | 8 ++++++++ pinpoint/stage0/on_register_attributes.cpp | 14 ++++++++++++++ pinpoint/stage0/target.cpp | 8 +++++++- subject/task_struct.h | 10 +++++++++- 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 pinpoint/safegcc/safe-attribs.h diff --git a/pinpoint/pinpoint_config.h b/pinpoint/pinpoint_config.h index d26cc65..216b891 100644 --- a/pinpoint/pinpoint_config.h +++ b/pinpoint/pinpoint_config.h @@ -1,6 +1,7 @@ #pragma once #define SPSLR_ATTRIBUTE "spslr" +#define SPSLR_FIELD_FIXED_ATTRIBUTE "spslr_field_fixed" #define SPSLR_PINPOINT_STAGE0_SEPARATOR "__spslr_offsetof" #define SPSLR_PINFILE_EXTENSION ".spslr" #define SPSLR_PINPOINT_STAGE2_PIN "__spslr_ipin_" /* suffixed with "_" */ diff --git a/pinpoint/safegcc/safe-attribs.h b/pinpoint/safegcc/safe-attribs.h new file mode 100644 index 0000000..0881abc --- /dev/null +++ b/pinpoint/safegcc/safe-attribs.h @@ -0,0 +1,8 @@ +#include + +#ifndef SAFEGCC_ATTRIBS_H +#define SAFEGCC_ATTRIBS_H + +#include + +#endif diff --git a/pinpoint/stage0/on_register_attributes.cpp b/pinpoint/stage0/on_register_attributes.cpp index d651f3c..9bdfef9 100644 --- a/pinpoint/stage0/on_register_attributes.cpp +++ b/pinpoint/stage0/on_register_attributes.cpp @@ -1,5 +1,6 @@ #include #include +#include static tree log_new_target(tree* node, tree name, tree args, int flags, bool* no_add_attrs) { if (node) @@ -8,11 +9,24 @@ static tree log_new_target(tree* node, tree name, tree args, int flags, bool* no return NULL_TREE; } +static tree check_field_fixed_attribute(tree* node, tree name, tree args, int flags, bool* no_add_attrs) { + if (!node || !*node || TREE_CODE(*node) != FIELD_DECL) { + *no_add_attrs = true; + fprintf(stderr, "%qs attribute only applies to struct/union fields", SPSLR_FIELD_FIXED_ATTRIBUTE); + } + return NULL_TREE; +} + static struct attribute_spec spslr_attribute = { SPSLR_ATTRIBUTE, 0, 0, false, false, false, false, log_new_target, NULL }; +static struct attribute_spec spslr_fixed_field_attribute = { + SPSLR_FIELD_FIXED_ATTRIBUTE, 0, 0, false, false, false, false, check_field_fixed_attribute, NULL +}; + void on_register_attributes(void* plugin_data, void* user_data) { register_attribute(&spslr_attribute); + register_attribute(&spslr_fixed_field_attribute); } diff --git a/pinpoint/stage0/target.cpp b/pinpoint/stage0/target.cpp index 185ef28..1de12b6 100644 --- a/pinpoint/stage0/target.cpp +++ b/pinpoint/stage0/target.cpp @@ -2,6 +2,9 @@ #include #include +#include + +#include static UID next_uid = 0; static std::unordered_map targets; @@ -251,7 +254,10 @@ static bool foreach_record_field(tree t, std::function Any static pointer into a randomized object must be patched too + */ + struct list_head tasks __spslr_field_fixed; // linkage for global task list randomized_struct_fields_end