Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
loadall.c
Go to the documentation of this file.
1 #define _GNU_SOURCE
2 
3 #include <sys/mman.h>
4 #include <dlfcn.h>
5 
6 /*
7  * Wrap __libc_start_main so that we mlockall/munlockall before
8  * executing anything. This is a best-effort, least-intrusion attempt
9  * to force all of the process's virtual address text pages to be loaded
10  * before main(). They may later be *unloaded*, but by default main()
11  * will begin with all pages loaded into RAM and in the page table.
12  * Well, of course it's not guaranteed; but it should work on any
13  * reasonable kernel that is not experiencing memory pressure.
14  */
15 int __libc_start_main(int (*main) (int,char **,char **),
16  int argc,char **ubp_av,
17  void (*init) (void),
18  void (*fini)(void),
19  void (*rtld_fini)(void),
20  void (*stack_end)) {
21  int (*original__libc_start_main)(int (*main) (int,char **,char **),
22  int argc,char **ubp_av,
23  void (*init) (void),
24  void (*fini)(void),
25  void (*rtld_fini)(void),
26  void (*stack_end));
27 
28  mlockall(MCL_CURRENT);
29  munlockall();
30 
31  original__libc_start_main = dlsym(RTLD_NEXT,"__libc_start_main");
32  return original__libc_start_main(main,argc,ubp_av,
33  init,fini,rtld_fini,stack_end);
34 }
int __libc_start_main(int(*main)(int, char **, char **), int argc, char **ubp_av, void(*init)(void), void(*fini)(void), void(*rtld_fini)(void), void(*stack_end))
Definition: loadall.c:15
int main(int argc, char **argv)
Definition: debugserver.c:306