mirror of https://github.com/ossrs/srs.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
719 B
C++
31 lines
719 B
C++
/*
|
|
g++ mmap1.cpp -g -O0 -o mmap && ./mmap
|
|
*/
|
|
#include <stdio.h>
|
|
#include <assert.h>
|
|
#include <sys/mman.h>
|
|
#include <string.h>
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
int zero_fd = -1;
|
|
int size = 64 * 1024;
|
|
int mmap_flags = MAP_PRIVATE | MAP_ANON;
|
|
char* vaddr = (char*)mmap(NULL, size, PROT_READ | PROT_WRITE, mmap_flags, zero_fd, 0);
|
|
assert (vaddr != (void *)MAP_FAILED);
|
|
printf("vaddr=%p, size=%d\n", vaddr, size);
|
|
|
|
vaddr[0] = 0x0f;
|
|
printf("OK: access vaddr p[0]=%x\n", vaddr[0]);
|
|
|
|
munmap(vaddr, size);
|
|
printf("munmap vaddr=%p, size=%d\n", vaddr, size);
|
|
|
|
printf("try to access vaddr\n");
|
|
vaddr[0] = 0x0f;
|
|
printf("OK: access vaddr p[0]=%x\n", vaddr[0]);
|
|
|
|
return 0;
|
|
}
|
|
|