-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello-ptr.c
26 lines (22 loc) · 937 Bytes
/
hello-ptr.c
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
#define _GNU_SOURCE
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <dlfcn.h>
const char *s="hello world"; /* stored in data */
int main() { /* stored in text */
/* do something */
char *b; /* stored on stack */
b=malloc(sizeof(s)); /* reserve heap - added to VSZ */
memcpy(b, s, strlen(s)); /* touch page - added to RSS */
printf("%s\n", b); /* system call into kernel */
free(b); /* free heap allocation */
/* dump addresses */
printf("\n/* memory addresses */\n");
printf("main = %14p (text)\n", (void *) main);
printf("&s = %14p (data)\n", (void *) &s);
printf("b = %14p (heap)\n", (void *) b);
printf("&b = %14p (stack)\n\n", (void *) &b);
printf("printf = %14p (pointer)\n", (void *) printf);
printf("printf = %14p (address)\n", (void *) dlsym(RTLD_NEXT, "printf"));
}