Skip to content

Commit 0385009

Browse files
committed
panda arch: special case retval from aarch64
1 parent 0ae118a commit 0385009

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

panda/python/core/pandare/arch.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,11 @@ def get_retval(self, cpu, convention='default'):
250250
rv = self.get_reg(cpu, reg)
251251

252252
if convention == 'syscall':
253-
rv = self.panda.from_unsigned_guest(rv)
253+
bits = None
254+
if self.panda.arch_name == "aarch64":
255+
if cpu.env_ptr.aarch64 == 0:
256+
bits = 32
257+
rv = self.panda.from_unsigned_guest(rv, bits=bits)
254258
return rv
255259

256260

panda/python/core/pandare/panda.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ def to_unsigned_guest(self, x):
10571057
else:
10581058
raise ValueError("Unsupported number of bits")
10591059

1060-
def from_unsigned_guest(self, x):
1060+
def from_unsigned_guest(self, x, bits=None):
10611061
'''
10621062
Convert an unsigned int32/unsigned int64 from the guest
10631063
(depending on guest bit-size) to a (signed) python int
@@ -1068,8 +1068,10 @@ def from_unsigned_guest(self, x):
10681068
Returns:
10691069
int: Python integer representing x as a signed value
10701070
'''
1071-
if x >= 2**(self.bits-1): # If highest bit is set, it's negative
1072-
return (x - 2**self.bits)
1071+
if bits is None:
1072+
bits = self.bits
1073+
if x >= 2**(bits-1): # If highest bit is set, it's negative
1074+
return (x - 2**bits)
10731075
else: # Else it's positive
10741076
return x
10751077

0 commit comments

Comments
 (0)