00001
00002
00003
00004
00005
00006
00007 #include "wvshmzone.h"
00008 #include <sys/mman.h>
00009 #include <sys/types.h>
00010 #include <sys/stat.h>
00011 #include <fcntl.h>
00012 #include <assert.h>
00013 #include <errno.h>
00014 #include <unistd.h>
00015
00016 WvShmZone::WvShmZone(size_t _size)
00017 {
00018 size = (int)_size;
00019 assert(size > 0);
00020
00021 buf = NULL;
00022
00023 fd = open("/dev/zero", O_RDWR);
00024 if (fd < 0)
00025 {
00026 seterr(errno);
00027 return;
00028 }
00029
00030 buf = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
00031
00032 if (!buf)
00033 {
00034 seterr(errno);
00035 return;
00036 }
00037 }
00038
00039
00040 WvShmZone::~WvShmZone()
00041 {
00042 if (buf)
00043 munmap(buf, size);
00044 if (fd >= 0)
00045 close(fd);
00046 }
00047
00048