forked from computee/s-keys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jl.c
56 lines (42 loc) · 1008 Bytes
/
jl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <nops.h>
#include <misc.h>
#include <asm.h>
#define STATIC_KEY_INIT_NOP P6_NOP5_ATOMIC
struct jump_entry {
uint64_t code;
uint64_t target;
uint64_t key;
};
typedef struct {
int counter;
} atomic_t;
struct static_key {
atomic_t enabled;
struct jump_entry *entries;
};
struct static_key key;
struct jump_entry __start___jump_table[] __attribute__ ((section ("__jump_table")));
struct jump_entry __stop___jump_table[] __attribute__ ((section ("__jump_table")));
static bool __always_inline f(struct static_key *k)
{
__asm__ volatile goto ("1:"
".byte " stringify(STATIC_KEY_INIT_NOP) "\n\t"
".pushsection __jump_table, \"aw\" \n\t"
_ASM_ALIGN "\n\t"
_ASM_PTR "1b, %l[l_yes], %c0 \n\t"
".popsection \n\t"
: : "i" (k) : : l_yes);
return false;
l_yes:
return true;
}
int main (int argc, char *argv[])
{
printf("before\n");
f(&key);
printf("after\n");
return 0;
}