Small errors in proc_modules
[signduterre.git] / proc_modules.py
blobb76a932d52f6045fd1a44e60bc79b389c63eb73a
1 # proc_modules
2 #
3 # Signature-du-Terroir module to handle /proc/modules
5 # Help text
6 help_text = """
7 Values:
8 modulelist: List of module names
9 moduledict: Dictionary of [module-name] = {'size', 'loadnum', 'dependencies', 'state', 'offset'}
10 moduledict['video']['offset'] -> offset adress in kernel of the 'video' module
11 min_address: Lowest offset address
12 max_load: Highest offset address
13 max_address: max_load + size-of-last-module
14 sum_sizes: sum of all module sizes
15 memory_range: max_address - min_address
17 Functions:
18 sorted_sizes_table(): Alphabetically sorted table of modules+sizes as a string
19 sorted_offset_table(): Alphabetically sorted table of modules+offset as a string
20 sorted_loadnum_table(): Alphabetically sorted table of modules+loadnum as a string
21 sorted_dependencies_table(): Alphabetically sorted table of modules+dependencies as a string
22 sorted_state_table(): Alphabetically sorted table of modules+state as a string
23 """
25 import re;
26 modulelist = [];
27 moduledict = {};
28 min_address = 10**100;
29 max_address = -1;
30 max_load = -1;
31 sum_sizes = 0;
32 with open('/proc/modules') as m:
33 for l in m:
34 module_value = re.split(r'\s+', l.rstrip('\s\n'));
35 (module, size, loadnum, dependencies, state, offset) = module_value[0:6];
36 modulelist.append(module);
37 size = int(size);
38 loadnum = int(loadnum);
39 offset = int(offset, 16);
40 module_entry = {'size':size, 'loadnum':loadnum, 'dependencies':dependencies, 'state':state, 'offset':offset};
41 moduledict[module] = module_entry;
42 if min_address > offset: min_address = offset;
43 if max_address < offset+size: max_address = offset + size;
44 if max_load < offset: max_load = offset;
45 sum_sizes += size;
47 memory_range = max_address - min_address
49 def sorted_sizes_table():
50 modulelist.sort();
51 s="";
52 for m in modulelist:
53 s += m+"\t"+str(moduledict[m]['size'])+"\n";
54 return s;
56 def sorted_offset_table():
57 modulelist.sort();
58 s="";
59 for m in modulelist:
60 s += m+"\t"+str(moduledict[m]['offset'])+"\n";
61 return s;
63 def sorted_loadnum_table():
64 modulelist.sort();
65 s="";
66 for m in modulelist:
67 s += m+"\t"+str(moduledict[m]['loadnum'])+"\n";
68 return s;
70 def sorted_dependencies_table():
71 modulelist.sort();
72 s="";
73 for m in modulelist:
74 s += m+"\t"+str(moduledict[m]['dependencies'])+"\n";
75 return s;
77 def sorted_state_table ():
78 modulelist.sort();
79 s="";
80 for m in modulelist:
81 s += m+"\t"+str(moduledict[m]['state'])+"\n";
82 return s;
84 def dump_module_binary (name):
85 module_binary = open('/proc/kcore');
87 if __name__ == "__main__":
88 print(help_text);