コード例 #1
0
 def _load_memory_mappings(self):
   """ make the python objects"""
   self_mappings = []
   for _start, _end, permissions, offset, devices, inode, mmap_pathname in self.metalines:
     start,end = int(_start,16),int(_end,16 )
     offset = int(offset,16)
     inode = int(inode)
     #rebuild filename
     mmap_fname = "%s-%s" % (utils.formatAddress(start), utils.formatAddress(end))
     # get devices nums
     major_device, minor_device = devices.split(':')
     major_device = int(major_device,16)
     minor_device = int(minor_device,16)
     log.debug('Loading %s - %s'%(mmap_fname, mmap_pathname))
     # open the file in the archive
     try:
       mmap_content_file = self._protected_open_file(mmap_fname, mmap_pathname)
     except (IOError, KeyError), e:
       log.debug('Ignore absent file : %s'%(e))
       mmap = memory_mapping.MemoryMapping( start, end, permissions, offset, 
                               major_device, minor_device, inode,pathname=mmap_pathname)
       self_mappings.append(mmap)
       continue
     #except ValueError,e: # explicit non-loading
     #  log.debug('Ignore useless file : %s'%(e))
     #  mmap = memory_mapping.MemoryMapping(start, end, permissions, offset, 
     #                          major_device, minor_device, inode,pathname=mmap_pathname)
     #  self_mappings.append(mmap)
     #  continue
     except LazyLoadingException,e: 
       mmap = memory_mapping.FilenameBackedMemoryMapping(e._filename, start, end, permissions, offset, 
                               major_device, minor_device, inode,pathname=mmap_pathname)
       self_mappings.append(mmap)
       continue
コード例 #2
0
def makeMMap(seq, start=Config.MMAP_START, offset=Config.STRUCT_OFFSET):
    nsig = [offset]
    nsig.extend(seq)
    indices = [i for i in accumulate(nsig)]
    dump = []  #b''
    values = []
    for i in range(0, Config.MMAP_LENGTH, Config.WORDSIZE):
        if i in indices:
            dump.append(struct.pack('I', start + i))
            values.append(start + i)
        else:
            dump.append(struct.pack('I', 0x2e2e2e2e))

    if len(dump) != Config.MMAP_LENGTH / Config.WORDSIZE:
        raise ValueError('error on length dump %d expected %d' %
                         (len(dump), (Config.MMAP_LENGTH / Config.WORDSIZE)))
    dump2 = ''.join(dump)
    #print repr(dump2[:16]), Config.WORDSIZE, Config.MMAP_LENGTH
    if len(dump) * Config.WORDSIZE != len(dump2):
        raise ValueError('error on length dump %d dump2 %d' %
                         (len(dump), len(dump2)))
    stop = start + len(dump2)
    mmap = memory_mapping.MemoryMapping(start, stop, '-rwx', 0, 0, 0, 0,
                                        'test_mmap')
    mmap2 = memory_mapping.LocalMemoryMapping.fromBytebuffer(mmap, dump2)
    return mmap2, values
コード例 #3
0
ファイル: dump_loader.py プロジェクト: sumit-fueled/tastypie
 def _load_mappings(self):
     """Loads the mappings content from the dump to a MemoryMappings.
 
 If an underlying file containing a memory dump does not exists, still
 create a MemoryMap for metadata purposes.
 If the memory map is > Config.MAX_MAPPING_SIZE_FOR_MMAP, use a slow FileBackedMemoryMapping.
 Else, load the mapping in memory.
 """
     mappingsFile = self._open_file(self.archive, self.indexFilename)
     self.metalines = []
     for l in mappingsFile.readlines():
         fields = l.strip().split(' ')
         if '' in fields:
             fields.remove('')
         self.metalines.append((fields[0], fields[1], fields[2], fields[3],
                                fields[4], fields[5], ' '.join(fields[6:])))
     self_mappings = []
     for start, end, permissions, offset, devices, inode, mmap_pathname in self.metalines:
         start, end = int(start, 16), int(end, 16)
         offset = int(offset, 16)
         inode = int(inode)
         #rebuild filename
         mmap_fname = "%s-%s" % (dbg.formatAddress(start),
                                 dbg.formatAddress(end))
         # get devices nums
         major_device, minor_device = devices.split(':')
         major_device = int(major_device, 16)
         minor_device = int(minor_device, 16)
         log.debug('Loading %s - %s' % (mmap_fname, mmap_pathname))
         # open the file in the archive
         try:
             mmap_content_file = self._protected_open_file(
                 mmap_fname, mmap_pathname)
         except (IOError, KeyError), e:
             log.debug('Ignore absent file : %s' % (e))
             raise e
             mmap = memory_mapping.MemoryMapping(start,
                                                 end,
                                                 permissions,
                                                 offset,
                                                 major_device,
                                                 minor_device,
                                                 inode,
                                                 pathname=mmap_pathname)
             self_mappings.append(mmap)
             continue
         except ValueError, e:  # explicit non-loading
             log.debug('Ignore useless file : %s' % (e))
             mmap_content_file = file(
                 os.path.sep.join(
                     [self.archive, self.filePrefix + mmap_fname]), 'rb')
             mmap = memory_mapping.FileBackedMemoryMapping(
                 mmap_content_file,
                 start,
                 end,
                 permissions,
                 offset,
                 major_device,
                 minor_device,
                 inode,
                 pathname=mmap_pathname)
             self_mappings.append(mmap)
             continue
コード例 #4
0
ファイル: dump_loader.py プロジェクト: sumit-fueled/tastypie
                    permissions,
                    offset,
                    major_device,
                    minor_device,
                    inode,
                    pathname=mmap_pathname)
                self_mappings.append(mmap)
                continue

            if isinstance(self.archive, zipfile.ZipFile):  # ZipExtFile is lame
                log.warning(
                    'Using a local memory mapping . Zipfile sux. thx ruby.')
                mmap = memory_mapping.MemoryMapping(start,
                                                    end,
                                                    permissions,
                                                    offset,
                                                    major_device,
                                                    minor_device,
                                                    inode,
                                                    pathname=mmap_pathname)
                mmap = memory_mapping.LocalMemoryMapping.fromBytebuffer(
                    mmap, mmap_content_file.read())
            elif end - start > Config.MAX_MAPPING_SIZE_FOR_MMAP:  # use file mmap when file is too big
                log.warning(
                    'Using a file backed memory mapping. no mmap in memory for this memorymap (%s).'
                    % (mmap_pathname) + ' Search will fail. Buffer is needed.')
                mmap = memory_mapping.FileBackedMemoryMapping(
                    mmap_content_file,
                    start,
                    end,
                    permissions,
                    offset,