File: memlock.c

package info (click to toggle)
hping2 2.rc3-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 756 kB
  • ctags: 951
  • sloc: ansic: 6,706; makefile: 110; sh: 83
file content (29 lines) | stat: -rw-r--r-- 643 bytes parent folder | download | duplicates (4)
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
/*
 * $smu-mark$
 * $name: memlock.c$
 * $other_author: Alfonso De Gregorio <dira@speedcom.it>
 * $other_copyright: Copyright (C) 1999 by Alfonso De Gregorio
 * $license: This software is under GPL version 2 of license$
 * $date: Fri Nov  5 11:55:48 MET 1999$
 * $rev: 2$
 */

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

int memlock(char *addr, size_t size)
{
#ifdef _POSIX_MEMLOCK_RANGE
	unsigned long    page_offset, page_size;

	page_size = sysconf(_SC_PAGESIZE);	/* also <limits.h> ..  */
	page_offset = (unsigned long) addr % page_size;

	addr -= page_offset;
	size += page_offset;

	return ( mlock(addr, size) ); 
#endif
	return (-1);
}