Created
July 12, 2020 04:03
-
-
Save udzura/c9f14dc7f4defada560b33703bbc661c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
int main(int argc, char* argv){ | |
printf("PID=%d\n", getpid()); | |
printf("Run bpftrace background and hit return:\n"); | |
(void)fgetc(stdin); | |
char *relm1, *relm2, *relm3; | |
char cmd[256] = {0}; | |
snprintf(cmd, 256,\ | |
"cat /proc/%d/maps", getpid()); | |
system(cmd); | |
int i; | |
relm1 = malloc(1024); | |
// relm1 = malloc(1 * 1024 * 1024 * 1024); | |
relm1[0] = 'a'; | |
printf("relm1: %p\n", relm1); | |
sleep(1); | |
relm2 = malloc(1024 * 1024 * 1024); | |
printf("relm2: %p\n", relm2); | |
sleep(1); | |
puts(""); | |
snprintf(cmd, 256,\ | |
"cat /proc/%d/maps", getpid()); | |
system(cmd); | |
(void)fgetc(stdin); | |
free(relm2); | |
free(relm1); | |
printf("All freed.\n"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./chkheap | |
PID=7319 | |
Run bpftrace background and hit return: | |
55a46e740000-55a46e741000 r-xp 00000000 08:01 22338 /home/vagrant/chkheap | |
55a46e940000-55a46e941000 r--p 00000000 08:01 22338 /home/vagrant/chkheap | |
55a46e941000-55a46e942000 rw-p 00001000 08:01 22338 /home/vagrant/chkheap | |
55a4705d0000-55a4705f1000 rw-p 00000000 00:00 0 [heap] | |
7f341d659000-7f341d840000 r-xp 00000000 08:01 21679 /lib/x86_64-linux-gnu/libc-2.27.so | |
7f341d840000-7f341da40000 ---p 001e7000 08:01 21679 /lib/x86_64-linux-gnu/libc-2.27.so | |
7f341da40000-7f341da44000 r--p 001e7000 08:01 21679 /lib/x86_64-linux-gnu/libc-2.27.so | |
7f341da44000-7f341da46000 rw-p 001eb000 08:01 21679 /lib/x86_64-linux-gnu/libc-2.27.so | |
7f341da46000-7f341da4a000 rw-p 00000000 00:00 0 | |
7f341da4a000-7f341da71000 r-xp 00000000 08:01 21675 /lib/x86_64-linux-gnu/ld-2.27.so | |
7f341dc65000-7f341dc67000 rw-p 00000000 00:00 0 | |
7f341dc71000-7f341dc72000 r--p 00027000 08:01 21675 /lib/x86_64-linux-gnu/ld-2.27.so | |
7f341dc72000-7f341dc73000 rw-p 00028000 08:01 21675 /lib/x86_64-linux-gnu/ld-2.27.so | |
7f341dc73000-7f341dc74000 rw-p 00000000 00:00 0 | |
7ffeb1150000-7ffeb1171000 rw-p 00000000 00:00 0 [stack] | |
7ffeb11cf000-7ffeb11d2000 r--p 00000000 00:00 0 [vvar] | |
7ffeb11d2000-7ffeb11d3000 r-xp 00000000 00:00 0 [vdso] | |
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] | |
relm1: 0x55a4705d0a80 | |
relm2: 0x7f33dd658010 | |
55a46e740000-55a46e741000 r-xp 00000000 08:01 22338 /home/vagrant/chkheap | |
55a46e940000-55a46e941000 r--p 00000000 08:01 22338 /home/vagrant/chkheap | |
55a46e941000-55a46e942000 rw-p 00001000 08:01 22338 /home/vagrant/chkheap | |
55a4705d0000-55a4705f1000 rw-p 00000000 00:00 0 [heap] | |
7f33dd658000-7f341d659000 rw-p 00000000 00:00 0 | |
7f341d659000-7f341d840000 r-xp 00000000 08:01 21679 /lib/x86_64-linux-gnu/libc-2.27.so | |
7f341d840000-7f341da40000 ---p 001e7000 08:01 21679 /lib/x86_64-linux-gnu/libc-2.27.so | |
7f341da40000-7f341da44000 r--p 001e7000 08:01 21679 /lib/x86_64-linux-gnu/libc-2.27.so | |
7f341da44000-7f341da46000 rw-p 001eb000 08:01 21679 /lib/x86_64-linux-gnu/libc-2.27.so | |
7f341da46000-7f341da4a000 rw-p 00000000 00:00 0 | |
7f341da4a000-7f341da71000 r-xp 00000000 08:01 21675 /lib/x86_64-linux-gnu/ld-2.27.so | |
7f341dc65000-7f341dc67000 rw-p 00000000 00:00 0 | |
7f341dc71000-7f341dc72000 r--p 00027000 08:01 21675 /lib/x86_64-linux-gnu/ld-2.27.so | |
7f341dc72000-7f341dc73000 rw-p 00028000 08:01 21675 /lib/x86_64-linux-gnu/ld-2.27.so | |
7f341dc73000-7f341dc74000 rw-p 00000000 00:00 0 | |
7ffeb1150000-7ffeb1171000 rw-p 00000000 00:00 0 [stack] | |
7ffeb11cf000-7ffeb11d2000 r--p 00000000 00:00 0 [vvar] | |
7ffeb11d2000-7ffeb11d3000 r-xp 00000000 00:00 0 [vdso] | |
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] | |
All freed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment