#include #include #include #include #include #include #include #include #include int main() { int sock; int ret; void *mem; size_t mapsize; struct tpacket_req req; sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP)); assert(sock != - 1); memset(&req, 0, sizeof(req)); req.tp_block_size = 4096; req.tp_frame_size = 2048; req.tp_block_nr = 4; req.tp_frame_nr = 8; ret = setsockopt(sock, SOL_SOCKET, PACKET_RX_RING, (void *) &req, sizeof(req)); assert(ret == 0); mapsize = req.tp_block_nr * req.tp_block_size; mem = mmap(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, sock, 0 ); assert(mem != MAP_FAILED); //... //poll() //... close(sock); return 0; } /* .config: [...] CONFIG_MMU=y CONFIG_PACKET=y CONFIG_PACKET_MMAP=y [...] output: $ uname -a Linux darkstar-laptop 2.6.30.3 #1 SMP Thu Jul 30 23:00:10 CEST 2009 i686 GNU/Linux $ gcc -Wall ./test_mmap.c $ sudo ./a.out a.out: ./test_mmap.c:34: main: Assertion `mem != ((void *) -1)' failed. Aborted */ ------snip--------------------------------------> strace says: execve("./a.out", ["./a.out"], [/* 38 vars */]) = 0 brk(0) = 0x87d9000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb8012000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=80440, ...}) = 0 mmap2(NULL, 80440, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7ffe000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/tls/i686/cmov/libc.so.6", O_RDONLY) = 3 read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\260e\1"..., 512) = 512 fstat64(3, {st_mode=S_IFREG|0755, st_size=1364388, ...}) = 0 mmap2(NULL, 1369712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7eaf000 mmap2(0xb7ff8000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x149) = 0xb7ff8000 mmap2(0xb7ffb000, 9840, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7ffb000 close(3) = 0 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7eae000 set_thread_area({entry_number:-1 -> 6, base_addr:0xb7eae6b0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0 mprotect(0xb7ff8000, 4096, PROT_READ) = 0 munmap(0xb7ffe000, 80440) = 0 socket(PF_PACKET, SOCK_RAW, 8) = 3 setsockopt(3, SOL_SOCKET, SO_DONTROUTE, "\0\20\0\0\4\0\0\0\0\10\0\0\10\0\0\0", 16) = 0 mmap2(NULL, 16384, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = -1 EINVAL (Invalid argument) brk(0) = 0x87d9000 brk(0x87fa000) = 0x87fa000 write(2, "a.out: ./test_mmap.c:34: main: A"..., 72a.out: ./test_mmap.c:34: main: Assertion `mem != ((void *) -1)' failed. ) = 72 rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0 gettid() = 6846 tgkill(6846, 6846, SIGABRT) = 0 --- SIGABRT (Aborted) @ 0 (0) --- +++ killed by SIGABRT +++