Skip to content

Instantly share code, notes, and snippets.

@stesla
Created September 26, 2010 03:20
Show Gist options
  • Save stesla/597560 to your computer and use it in GitHub Desktop.
Save stesla/597560 to your computer and use it in GitHub Desktop.
[samuel@Dahlia:~/Projects/objection][master*]$ ./a.out
page 0: 0x100021000
page 0: 0x100022000
^Z
[1]+ Stopped ./a.out
[samuel@Dahlia:~/Projects/objection][master*]$ vmmap a.out
Virtual Memory Map of process 31789 (a.out)
Output report format: 2.2 -- 64-bit process
==== Non-writable regions for process 31789
__TEXT 0000000100000000-0000000100001000 [ 4K] r-x/rwx SM=COW /Users/samuel/Projects/objection/a.out
__LINKEDIT 0000000100002000-0000000100003000 [ 4K] r--/rwx SM=COW /Users/samuel/Projects/objection/a.out
STACK GUARD 0000000100003000-0000000100004000 [ 4K] ---/rwx SM=NUL
STACK GUARD 0000000100005000-0000000100007000 [ 8K] ---/rwx SM=NUL
STACK GUARD 0000000100012000-0000000100014000 [ 8K] ---/rwx SM=NUL
STACK GUARD 000000010001f000-0000000100020000 [ 4K] ---/rwx SM=NUL
MALLOC (admin) 0000000100020000-0000000100021000 [ 4K] r--/rwx SM=PRV
STACK GUARD 00007fff5bc00000-00007fff5f400000 [ 56.0M] ---/rwx SM=NUL
__TEXT 00007fff5fc00000-00007fff5fc3c000 [ 240K] r-x/rwx SM=COW /usr/lib/dyld
__LINKEDIT 00007fff5fc7b000-00007fff5fc8f000 [ 80K] r--/rwx SM=COW /usr/lib/dyld
__TEXT 00007fff80642000-00007fff80647000 [ 20K] r-x/r-x SM=COW /usr/lib/system/libmathCommon.A.dylib
__TEXT 00007fff8806c000-00007fff8822d000 [ 1796K] r-x/r-x SM=COW /usr/lib/libSystem.B.dylib
__LINKEDIT 00007fff89297000-00007fff8b1dd000 [ 31.3M] r--/r-- SM=COW /usr/lib/system/libmathCommon.A.dylib
==== Writable regions for process 31789
__DATA 0000000100001000-0000000100002000 [ 4K] rw-/rwx SM=PRV /Users/samuel/Projects/objection/a.out
MALLOC (admin) 0000000100004000-0000000100005000 [ 4K] rw-/rwx SM=PRV
MALLOC (admin) 0000000100007000-0000000100012000 [ 44K] rw-/rwx SM=PRV
MALLOC (admin) 0000000100014000-000000010001f000 [ 44K] rw-/rwx SM=PRV
VM_ALLOCATE 0000000100021000-0000000100022000 [ 4K] rw-/rwx SM=NUL
Memory tag=240 0000000100022000-0000000100023000 [ 4K] rw-/rwx SM=NUL
MALLOC_TINY 0000000100100000-0000000100200000 [ 1024K] rw-/rwx SM=PRV DefaultMallocZone_0x100004000
MALLOC_SMALL 0000000100800000-0000000101000000 [ 8192K] rw-/rwx SM=PRV DefaultMallocZone_0x100004000
Stack 00007fff5f400000-00007fff5fc00000 [ 8192K] rw-/rwx SM=PRV thread 0
__DATA 00007fff5fc3c000-00007fff5fc7b000 [ 252K] rw-/rwx SM=COW /usr/lib/dyld
__DATA 00007fff710c3000-00007fff710e6000 [ 140K] rw-/rwx SM=COW /usr/lib/libSystem.B.dylib
==== Legend
SM=sharing mode:
COW=copy_on_write PRV=private NUL=empty ALI=aliased
SHM=shared ZER=zero_filled S/A=shared_alias
==== Summary for process 31789
ReadOnly portion of Libraries: Total=33.4M resident=6064K(18%) swapped_out_or_unallocated=27.4M(82%)
Writable regions: Total=17.1M written=64K(0%) resident=64K(0%) swapped_out=0K(0%) unallocated=17.0M(100%)
REGION TYPE [ VIRTUAL]
=========== [ =======]
MALLOC [ 9312K]
Memory tag=240 [ 4K]
STACK GUARD [ 56.0M]
Stack [ 8192K]
VM_ALLOCATE [ 4K]
__DATA [ 396K]
__LINKEDIT [ 31.4M]
__TEXT [ 2060K]
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <mach/vm_statistics.h>
#define SIZE 4096
int main(int argc, char **argv, char **envp) {
int i;
void *page = NULL;
/* Just pass -1 as the fd */
page = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
printf("page %i: %p\n", i, page);
/* Use special Mach page tag */
page = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, VM_MAKE_TAG(240), 0);
printf("page %i: %p\n", i, page);
for (;;) sleep(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment