Example #1
0
 def _more(self):
     chunk = rffi.cast(CLOSURES, alloc(CHUNK))
     count = CHUNK//rffi.sizeof(FFI_CLOSUREP.TO)
     for i in range(count):
         rffi.cast(rffi.VOIDPP, chunk)[0] = self.free_list
         self.free_list = rffi.cast(rffi.VOIDP, chunk)
         chunk = rffi.ptradd(chunk, 1)
Example #2
0
 def _more(self):
     chunk = rffi.cast(CLOSURES, alloc(CHUNK))
     count = CHUNK // rffi.sizeof(FFI_CLOSUREP.TO)
     for i in range(count):
         rffi.cast(rffi.VOIDPP, chunk)[0] = self.free_list
         self.free_list = rffi.cast(rffi.VOIDP, chunk)
         chunk = rffi.ptradd(chunk, 1)
Example #3
0
def test_alloc_free():
    map_size = 65536
    data = alloc(map_size)
    for i in range(0, map_size, 171):
        data[i] = chr(i & 0xff)
    for i in range(0, map_size, 171):
        assert data[i] == chr(i & 0xff)
    free(data, map_size)
Example #4
0
def test_alloc_free():
    map_size = 65536
    data = alloc(map_size)
    for i in range(0, map_size, 171):
        data[i] = chr(i & 0xff)
    for i in range(0, map_size, 171):
        assert data[i] == chr(i & 0xff)
    madvise_free(data, map_size)
    free(data, map_size)
Example #5
0
def cpu_info(instr):
    data = alloc(4096)
    pos = 0
    for c in instr:
        data[pos] = c
        pos += 1
    fnptr = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Signed)), data)
    code = fnptr()
    free(data, 4096)
    return code
Example #6
0
def cpu_info(instr):
    data = alloc(4096)
    pos = 0
    for c in instr:
        data[pos] = c
        pos += 1
    fnptr = rffi.cast(CPU_ID_FUNC_PTR, data)
    code = fnptr()
    free(data, 4096)
    return code
Example #7
0
def cpu_info(instr):
    data = alloc(4096)
    pos = 0
    for c in instr:
        data[pos] = c
        pos += 1
    fnptr = rffi.cast(CPU_ID_FUNC_PTR, data)
    code = fnptr()
    free(data, 4096)
    return code
Example #8
0
def cpu_info(instr):
    data = alloc(4096)
    pos = 0
    for c in instr:
        data[pos] = c
        pos += 1
    fnptr = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Signed)), data)
    code = fnptr()
    free(data, 4096)
    return code
Example #9
0
 def _mmap_alloc(self, size):
     # overridden by a test
     data = rmmap.alloc(size)
     if not we_are_translated():
         if self._allocated is None:
             self._allocated = []
         self._allocated.append((data, size))
         if sys.maxint > 2147483647:
             # Hack to make sure that mcs are not within 32-bits of one
             # another for testing purposes
             rmmap.hint.pos += 0x80000000 - size
     return data
Example #10
0
def detect_x32_mode():
    data = alloc(4096)
    pos = 0                         # 32-bit         64-bit / x32
    for c in ("\x48"                # DEC EAX
              "\xB8\xC8\x00\x00\x00"# MOV EAX, 200   MOV RAX, 0x40404040000000C8
              "\x40\x40\x40\x40"    # 4x INC EAX
              "\xC3"):              # RET            RET
        data[pos] = c
        pos += 1
    fnptr = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Signed)), data)
    code = fnptr()
    free(data, 4096)
    assert code in (200, 204, 0x40404040000000C8)
    return code == 200
Example #11
0
def detect_sse2():
    data = alloc(4096)
    pos = 0
    for c in ("\xB8\x01\x00\x00\x00"     # MOV EAX, 1
              "\x53"                     # PUSH EBX
              "\x0F\xA2"                 # CPUID
              "\x5B"                     # POP EBX
              "\x92"                     # XCHG EAX, EDX
              "\xC3"):                   # RET
        data[pos] = c
        pos += 1
    fnptr = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Signed)), data)
    code = fnptr()
    free(data, 4096)
    return bool(code & (1<<25)) and bool(code & (1<<26))
Example #12
0
def detect_sse2():
    data = alloc(4096)
    pos = 0
    for c in ("\xB8\x01\x00\x00\x00"  # MOV EAX, 1
              "\x53"  # PUSH EBX
              "\x0F\xA2"  # CPUID
              "\x5B"  # POP EBX
              "\x92"  # XCHG EAX, EDX
              "\xC3"):  # RET
        data[pos] = c
        pos += 1
    fnptr = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Signed)), data)
    code = fnptr()
    free(data, 4096)
    return bool(code & (1 << 25)) and bool(code & (1 << 26))
Example #13
0
def detect_x32_mode():
    data = alloc(4096)
    pos = 0  # 32-bit         64-bit / x32
    for c in (
            "\x48"  # DEC EAX
            "\xB8\xC8\x00\x00\x00"  # MOV EAX, 200   MOV RAX, 0x40404040000000C8
            "\x40\x40\x40\x40"  # 4x INC EAX
            "\xC3"):  # RET            RET
        data[pos] = c
        pos += 1
    fnptr = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Signed)), data)
    code = fnptr()
    free(data, 4096)
    assert code in (200, 204, 0x40404040000000C8)
    return code == 200
Example #14
0
 def _allocate_large_block(self, minsize):
     # Compute 'size' from 'minsize': it must be rounded up to
     # 'large_alloc_size'.  Additionally, we use the following line
     # to limit how many mmap() requests the OS will see in total:
     minsize = max(minsize, intmask(self.total_memory_allocated >> 4))
     size = minsize + self.large_alloc_size - 1
     size = (size // self.large_alloc_size) * self.large_alloc_size
     data = rmmap.alloc(size)
     if not we_are_translated():
         if self._allocated is None:
             self._allocated = []
         self._allocated.append((data, size))
         if sys.maxint > 2147483647:
             # Hack to make sure that mcs are not within 32-bits of one
             # another for testing purposes
             rmmap.hint.pos += 0x80000000 - size
     self.total_memory_allocated += r_uint(size)
     data = rffi.cast(lltype.Signed, data)
     return self._add_free_block(data, data + size)
Example #15
0
 def _allocate_large_block(self, minsize):
     # Compute 'size' from 'minsize': it must be rounded up to
     # 'large_alloc_size'.  Additionally, we use the following line
     # to limit how many mmap() requests the OS will see in total:
     minsize = max(minsize, intmask(self.total_memory_allocated >> 4))
     size = minsize + self.large_alloc_size - 1
     size = (size // self.large_alloc_size) * self.large_alloc_size
     data = rmmap.alloc(size)
     if not we_are_translated():
         if self._allocated is None:
             self._allocated = []
         self._allocated.append((data, size))
         if sys.maxint > 2147483647:
             # Hack to make sure that mcs are not within 32-bits of one
             # another for testing purposes
             rmmap.hint.pos += 0x80000000 - size
     self.total_memory_allocated += r_uint(size)
     data = rffi.cast(lltype.Signed, data)
     return self._add_free_block(data, data + size)
Example #16
0
 def entry_point(argv):
     one = alloc(1024)
     free(one, 1024)
     return 0