selfpatch-slr/subject/task_struct.h

84 lines
1.9 KiB
C

#include <stdio.h>
#include <stddef.h>
#define container_of(ptr, type, member) ({ \
const typeof(((type*)0)->member)* __mptr = (ptr); \
(type*)((char*)__mptr - offsetof(type, member)); })
# define randomized_struct_fields_start struct {
# define randomized_struct_fields_end } __attribute__((spslr));
# define __spslr_field_fixed __attribute__((spslr_field_fixed))
// Minimal doubly linked list
struct list_head {
struct list_head *next, *prev;
};
static inline void INIT_LIST_HEAD(struct list_head *list)
{
list->next = list;
list->prev = list;
}
static inline void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
{
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
static inline void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
__list_add(new, head->prev, head);
}
#define list_entry(ptr, type, member) \
container_of(ptr, type, member)
#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
#define LIST_HEAD_SELF(name) { .next = &(name), .prev = &(name)}
struct ArrayFun {
int a, b, c;
double d;
} __attribute__((spslr));
// A small struct like the Linux kernel's task_struct
struct task_struct {
int stuck0;
randomized_struct_fields_start
randomized_struct_fields_start
int pid;
const char *comm;
struct ArrayFun arrfun[5];
randomized_struct_fields_end
/*
* TODO
* This field is used to statically initialize list heads.
* To make the offset available at compile-time, it must be fixed.
* The actual solution to this problem is dppins
* -> 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
int stuck1, stuck2;
};