diff options
Diffstat (limited to 'flags.py')
-rw-r--r-- | flags.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/flags.py b/flags.py new file mode 100644 index 0000000..6631480 --- /dev/null +++ b/flags.py | |||
@@ -0,0 +1,78 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | # A small helper script to help decoding flag fields in various kernel | ||
4 | # data structures. VM flags only, for now. | ||
5 | |||
6 | from functools import partial | ||
7 | |||
8 | def get_flags(flag_defs, flag_word): | ||
9 | flags = [] | ||
10 | for (name, bit) in flag_defs: | ||
11 | if flag_word & bit: | ||
12 | flags.append(name) | ||
13 | return flags | ||
14 | |||
15 | def format_flags(flag_defs, flag_word): | ||
16 | return " | ".join(get_flags(flag_defs, flag_word)) | ||
17 | |||
18 | # Linux Kernel 2.6.32 | ||
19 | VM_FLAGS = [ | ||
20 | ("VM_READ", 0x00000001), | ||
21 | ("VM_WRITE", 0x00000002), | ||
22 | ("VM_EXEC", 0x00000004), | ||
23 | ("VM_SHARED", 0x00000008), | ||
24 | ("VM_MAYREAD", 0x00000010), | ||
25 | ("VM_MAYWRITE", 0x00000020), | ||
26 | ("VM_MAYEXEC", 0x00000040), | ||
27 | ("VM_MAYSHARE", 0x00000080), | ||
28 | ("VM_GROWSDOWN", 0x00000100), | ||
29 | ("VM_GROWSUP", 0x00000200), | ||
30 | ("VM_PFNMAP", 0x00000400), | ||
31 | ("VM_DENYWRITE", 0x00000800), | ||
32 | ("VM_EXECUTABLE", 0x00001000), | ||
33 | ("VM_LOCKED", 0x00002000), | ||
34 | ("VM_IO", 0x00004000), | ||
35 | ("VM_SEQ_READ", 0x00008000), | ||
36 | ("VM_RAND_READ", 0x00010000), | ||
37 | ("VM_DONTCOPY", 0x00020000), | ||
38 | ("VM_DONTEXPAND", 0x00040000), | ||
39 | ("VM_RESERVED", 0x00080000), | ||
40 | ("VM_ACCOUNT", 0x00100000), | ||
41 | ("VM_NORESERVE", 0x00200000), | ||
42 | ("VM_HUGETLB", 0x00400000), | ||
43 | ("VM_NONLINEAR", 0x00800000), | ||
44 | ("VM_MAPPED_COPY", 0x01000000), | ||
45 | ("VM_INSERTPAGE", 0x02000000), | ||
46 | ("VM_ALWAYSDUMP", 0x04000000), | ||
47 | ("VM_CAN_NONLINEAR", 0x08000000), | ||
48 | ("VM_MIXEDMAP", 0x10000000), | ||
49 | ("VM_SAO", 0x20000000), | ||
50 | ("VM_PFN_AT_MMAP", 0x40000000), | ||
51 | ("VM_MERGEABLE", 0x80000000) | ||
52 | ] | ||
53 | |||
54 | |||
55 | get_vm_flags = partial(get_flags, VM_FLAGS) | ||
56 | format_vm_flags = partial(format_flags, VM_FLAGS) | ||
57 | |||
58 | |||
59 | X86_PTE_FLAGS = [ | ||
60 | ("PAGE_BIT_PRESENT", 1 << 0), | ||
61 | ("PAGE_BIT_RW", 1 << 1), | ||
62 | ("PAGE_BIT_USER", 1 << 2), | ||
63 | ("PAGE_BIT_PWT", 1 << 3), | ||
64 | ("PAGE_BIT_PCD", 1 << 4), | ||
65 | ("PAGE_BIT_ACCESSED", 1 << 5), | ||
66 | ("PAGE_BIT_DIRTY", 1 << 6), | ||
67 | ("PAGE_BIT_PSE", 1 << 7), | ||
68 | ("PAGE_BIT_PAT", 1 << 7), | ||
69 | ("PAGE_BIT_GLOBAL", 1 << 8), | ||
70 | ("PAGE_BIT_UNUSED1", 1 << 9), | ||
71 | ("PAGE_BIT_IOMAP", 1 << 10), | ||
72 | ("PAGE_BIT_HIDDEN", 1 << 11), | ||
73 | ("PAGE_BIT_PAT_LARGE", 1 << 12), | ||
74 | ("PAGE_BIT_NX", 1 << 63), | ||
75 | ] | ||
76 | |||
77 | get_pte_flags = partial(get_flags, X86_PTE_FLAGS) | ||
78 | format_pte_flags = partial(format_flags, X86_PTE_FLAGS) | ||