def mprotect_libc(addr, size, flags):
libc = ctypes.CDLL(ctypes.util.find_library('libc'), use_errno=True)
libc.mprotect.argtypes = [c_void_p, c_size_t, c_int]
libc.mprotect.restype = c_int
addr_align = addr & ~(PAGE_SIZE - 1)
mem_end = (addr + size) & ~(PAGE_SIZE - 1)
if (addr + size) > mem_end:
mem_end += PAGE_SIZE
memlen = mem_end - addr_align
ret = libc.mprotect(addr_align, memlen, flags)
if ret == -1:
e = ctypes.get_errno()
raise OSError(e, errno.errorcodes[e], os.strerror(e))
评论列表
文章目录