-
Notifications
You must be signed in to change notification settings - Fork 0
/
tamis.h
131 lines (107 loc) · 3.03 KB
/
tamis.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
tamis.h - Header exporting tamis functions
Copyright (C) 2007, 2008 Frederik Deweerdt <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __TAMIS_H__
#define __TAMIS_H__
#include <sys/queue.h>
void *tamis_alloc(size_t);
void tamis_free(void *);
#ifndef __KERNEL__
#include <stdio.h>
#define printk printf
#define KERN_ERR
#endif
static void dump_line(char *data, int offset, int limit)
{
int i;
printk(KERN_ERR "%03x:", offset);
for (i = 0; i < limit; i++) {
printk(" %02x", (unsigned char)data[offset + i]);
}
printk("\n");
}
static void __attribute__((unused)) dump_zone(void *buf, int len)
{
int i;
char *data = buf;
printk(KERN_ERR "================================================================================\n");
for (i=0; i < len; i+=16) {
int limit;
limit = 16;
if (i + limit > len)
limit = len - i;
dump_line(data, i, limit);
}
printk(KERN_ERR "================================================================================\n");
}
struct tamis_private {
uint8_t old_opcode;
void *to_protect_mem;
size_t to_protect_len;
int policy;
int priority;
};
enum tamis_type {
MUTEX_LOCK_PROTECTED,
CALLBACK,
};
struct tamis_memzone {
void *mem;
void *page;
int len;
enum tamis_type type;
union {
pthread_mutex_t *m;
int (*cb)(void *);
void *action;
} action;
LIST_ENTRY(tamis_memzone) list;
};
#define __tamis __attribute__ ((aligned (4096))) __attribute__((section ("tamis")))
/**
* @brief Remove a memory zone from being protected by tamis
*
* @param p The pointer to the memory to unprotect
**/
void tamis_unprotect(void *p);
/**
* @brief Protect memory accesses to a give memory zone with tamis
*
* @param p The memory zone to protect
* @param len The length of the memory zone to protect
*
* @return 0 in case of success, -1 otherwise. errno is set with the
* approriate value
**/
int tamis_protect(void *p, size_t len, enum tamis_type t, void *arg);
/**
* @brief Initialize the tamis library
*
* @return 0 in case of success, -1 otherwise. errno is set with the
* approriate value
**/
int tamis_init();
#if defined(__i386__)
# define REG_RAX REG_EAX
# define REG_RBX REG_EBX
# define REG_RCX REG_ECX
# define REG_RDX REG_EDX
# define REG_RDI REG_EDI
# define REG_RSI REG_ESI
# define REG_RIP REG_EIP
# define REG_RBP REG_EBP
# define REG_RSP REG_ESP
#endif
#endif /* __TAMIS_H__ */