@@ -471,30 +471,27 @@ def protect(self, addr, size, perms):
471471 self .ql .uc .mem_protect (aligned_address , aligned_size , perms )
472472
473473
474- def map (self , addr , size , perms = UC_PROT_ALL , info = None , ptr = None ):
475- '''
476- The main function of mem_mmap is to implement memory allocation in unicorn,
477- which is slightly similar to the function of syscall_mmap.
474+ def map (self , addr : int , size : int , perms : int = UC_PROT_ALL , info : str = None ):
475+ """Map a new memory range.
476+
477+ Args:
478+ addr: memory range base address
479+ size: memory range size (in bytes)
480+ perms: requested permissions mask
481+ info: range label string
482+ ptr: pointer to use (if any)
483+
484+ Raises:
485+ QlMemoryMappedError: in case requested memory range is not fully available
486+ """
478487
479- When the memory can satisfy the given addr and size,
480- it needs to be allocated to the corresponding address space.
481-
482- Upon successful completion, mem_map() shall return 0;
488+ assert perms & ~ UC_PROT_ALL == 0 , f'unexpected permissions mask { perms } '
483489
484- otherwise, it shall return -1 and set errno to indicate the error.
485-
486- is should call other API to get_available mainly gives a length,
487- and then the memory manager returns an address that can apply for that length.
490+ if not self .is_available (addr , size ):
491+ raise QlMemoryMappedError ('Requested memory is unavailable' )
488492
489- '''
490- if ptr == None :
491- if self .is_mapped (addr , size ) == False :
492- self .ql .uc .mem_map (addr , size , perms )
493- self .add_mapinfo (addr , addr + size , perms , info if info else "[mapped]" )
494- else :
495- raise QlMemoryMappedError ("Memory Mapped" )
496- else :
497- self .ql .uc .mem_map_ptr (addr , size , perms , ptr )
493+ self .ql .uc .mem_map (addr , size , perms )
494+ self .add_mapinfo (addr , addr + size , perms , info or '[mapped]' )
498495
499496 def get_mapped (self ):
500497 for idx , val in enumerate (self .ql .uc .mem_regions ()):
0 commit comments