Python mmap 模块,MAP_PRIVATE 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用mmap.MAP_PRIVATE

项目:darkc0de-old-stuff    作者:tuwid    | 项目源码 | 文件源码
def open(self, mode, typeaccess=0, mmapmode = mmap.MAP_PRIVATE) :
        self.typeaccess = typeaccess
        try :
            self.__fd = open("/dev/mem", mode)
        except IOError :
            print "Mem::open IOErreur"
            sys.exit(-1)

        if(self.typeaccess != 0):
            try :
                self.__data = mmap.mmap(self.__fd.fileno(), 100 * 1024 * 1024, mmapmode)
                #print self.__data
            except TypeError :
                print "Mem::open TypeError"
                sys.exit(-1)
项目:manticore    作者:trailofbits    | 项目源码 | 文件源码
def _mmap(fd, offset, size):
        prot = MMAP.PROT_READ | MMAP.PROT_WRITE
        flags = MMAP.MAP_PRIVATE

        if size &0xfff !=0:
            size = (size & ~0xfff) + 0x1000

        assert size > 0

        result = mmap_function(0, size, prot, flags, fd, offset)
        return ctypes.cast(result, ctypes.POINTER(ctypes.c_char))
项目:tracer    作者:trnila    | 项目源码 | 文件源码
def __init__(
            self,
            process,
            length,
            prot=mmap.PROT_READ | mmap.PROT_WRITE,
            flags=mmap.MAP_ANONYMOUS | mmap.MAP_PRIVATE):
        self.length = length
        self.process = process
        self.mapped = True
        self.caller_frame = inspect.stack()[1]

        parameters = [0, length, prot, flags, -1, 0]
        self.addr = inject_syscall(process, SYSCALL_MMAP, parameters)
项目:tracer    作者:trnila    | 项目源码 | 文件源码
def check(self):
        if not self.flags & mmap.MAP_PRIVATE:
            return

        try:
            with open("/proc/%d/pagemap" % self.pid, 'rb') as file:
                for page in self.accessed.not_used(self.start, self.start + self.size):
                    file.seek(int(page / PAGE_SIZE) * PAGEMAP_ENTRY, 0)
                    val = file.read(8)
                    num = struct.unpack('Q', val)[0]
                    occupied = (num & (1 << 63)) > 0
                    if occupied:
                        self.accessed.add(page)
        except Exception as e:  # TODO: fix
            logging.error("failed reading pagemap %s", e.args)