File: getamap.c

package info (click to toggle)
paxtest 0.9.6-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 360 kB
  • ctags: 145
  • sloc: ansic: 962; makefile: 587; asm: 53; sh: 44
file content (31 lines) | stat: -rw-r--r-- 606 bytes parent folder | download
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
27
28
29
30
31
/* getamap.c - Get the address of the first anonymous mapping
 *
 * Copyright (c)2003 by Peter Busser <peter@adamantix.org>
 * This file has been released under the GNU Public Licence version 2 or later
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>


#ifdef __OpenBSD__
#define MAP_ANONYMOUS MAP_ANON
#endif

int main( int argc, char *argv[] )
{
	char *buf;

	buf = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
	if( buf == NULL ) {
		fprintf( stderr, "mmap() returned NULL\n" );
		exit( 1 );
	}

	printf( "%0p\n", buf );

	exit( 0 );
}