def test_follow_jump_instructions_32(): buf = lltype.malloc(rffi.CCHARP.TO, 80, flavor='raw') raw = rffi.cast(lltype.Signed, buf) mc = codebuf.MachineCodeBlockWrapper(); mc.WORD = 4; mc.relocations = [] mc.RET() mc.copy_to_raw_memory(raw) mc = codebuf.MachineCodeBlockWrapper(); mc.WORD = 4; mc.relocations = [] assert follow_jump(raw) == raw mc.JMP(imm(raw)) mc.copy_to_raw_memory(raw + 20) assert buf[20] == '\xE9' # JMP assert buf[21] == '\xE7' # -25 assert buf[22] == '\xFF' assert buf[23] == '\xFF' assert buf[24] == '\xFF' mc = codebuf.MachineCodeBlockWrapper(); mc.WORD = 4; mc.relocations = [] assert follow_jump(raw + 20) == raw mc.JMP(imm(raw)) mc.copy_to_raw_memory(raw + 40) assert buf[40] == '\xE9' # JMP assert buf[41] == '\xD3' # -45 assert buf[42] == '\xFF' assert buf[43] == '\xFF' assert buf[44] == '\xFF' assert follow_jump(raw + 40) == raw lltype.free(buf, flavor='raw')
def test_follow_jump_instructions_32(): buf = lltype.malloc(rffi.CCHARP.TO, 80, flavor='raw') raw = rffi.cast(lltype.Signed, buf) mc = Fake32CodeBlockWrapper(); mc.WORD = 4; mc.relocations = [] mc.RET() mc.copy_to_raw_memory(raw) mc = Fake32CodeBlockWrapper(); mc.WORD = 4; mc.relocations = [] assert follow_jump(raw) == raw mc.JMP(imm(raw)) mc.copy_to_raw_memory(raw + 20) assert buf[20] == '\xE9' # JMP assert buf[21] == '\xE7' # -25 assert buf[22] == '\xFF' assert buf[23] == '\xFF' assert buf[24] == '\xFF' mc = Fake32CodeBlockWrapper(); mc.WORD = 4; mc.relocations = [] assert follow_jump(raw + 20) == raw mc.JMP(imm(raw)) mc.copy_to_raw_memory(raw + 40) assert buf[40] == '\xE9' # JMP assert buf[41] == '\xD3' # -45 assert buf[42] == '\xFF' assert buf[43] == '\xFF' assert buf[44] == '\xFF' assert follow_jump(raw + 40) == raw lltype.free(buf, flavor='raw')
def test_follow_jump_instructions_32(): buf = lltype.malloc(rffi.CCHARP.TO, 80, flavor='raw') raw = rffi.cast(lltype.Signed, buf) if not fits_in_32bits(raw): lltype.free(buf, flavor='raw') py.test.skip("not testable") mc = Fake32CodeBlockWrapper() mc.WORD = 4 mc.relocations = [] mc.RET() mc.copy_to_raw_memory(raw) mc = Fake32CodeBlockWrapper() mc.WORD = 4 mc.relocations = [] assert follow_jump(raw) == raw mc.JMP(imm(raw)) mc.copy_to_raw_memory(raw + 20) assert buf[20] == '\xE9' # JMP assert buf[21] == '\xE7' # -25 assert buf[22] == '\xFF' assert buf[23] == '\xFF' assert buf[24] == '\xFF' mc = Fake32CodeBlockWrapper() mc.WORD = 4 mc.relocations = [] assert follow_jump(raw + 20) == raw mc.JMP(imm(raw)) mc.copy_to_raw_memory(raw + 40) assert buf[40] == '\xE9' # JMP assert buf[41] == '\xD3' # -45 assert buf[42] == '\xFF' assert buf[43] == '\xFF' assert buf[44] == '\xFF' assert follow_jump(raw + 40) == raw lltype.free(buf, flavor='raw')