forked from dtrace4linux/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasm.c
More file actions
66 lines (58 loc) · 1.6 KB
/
asm.c
File metadata and controls
66 lines (58 loc) · 1.6 KB
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
// some test code to get the validate_ptr working.
#define __copy_user(to,from,size) \
do { \
int __d0, __d1; \
__asm__ __volatile__( \
"0: rep; movsl\n" \
" movl %3,%0\n" \
"1: rep; movsb\n" \
"2:\n" \
".section .fixup,\"ax\"\n" \
"3: lea 0(%3,%0,4),%0\n" \
" jmp 2b\n" \
".previous\n" \
".section __ex_table,\"a\"\n" \
" .align 4\n" \
" .long 0b,3b\n" \
" .long 1b,2b\n" \
".previous" \
: "=&c"(size), "=&D" (__d0), "=&S" (__d1) \
: "r"(size & 3), "0"(size / 4), "1"(to), "2"(from) \
: "memory"); \
} while (0)
#define __validate_ptr(ptr, ret) \
__asm__ __volatile__( \
" mov $1, %0\n" \
"0: mov (%1), %1\n" \
"2:\n" \
".section .fixup,\"ax\"\n" \
"3: mov $0, %0\n" \
" jmp 2b\n" \
".previous\n" \
".section __ex_table,\"a\"\n" \
" .align 8\n" \
" .quad 0b,3b\n" \
".previous" \
: "=&a" (ret) \
: "c" (ptr) \
)
int
validate_ptr(void *ptr)
{ int ret;
__validate_ptr(ptr, ret);
return ret;
}
int glob_ptr;
int *xyzzy = &glob_ptr;
int main(int argc, char **argv)
{ char src[10];
char dst[10];
int size = sizeof(src);
int ret;
// __copy_user(dst, src, size);
if (*xyzzy)
printf("hello\n");
getpid(&xyzzy);
ret = validate_ptr(xyzzy);
printf("ret=%d\n", ret);
}