Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up FunctionABI and SyscallABI type signatures #39

Open
RyanGlScott opened this issue Jul 23, 2024 · 0 comments
Open

Clean up FunctionABI and SyscallABI type signatures #39

RyanGlScott opened this issue Jul 23, 2024 · 0 comments
Labels
tech-debt Technical debt

Comments

@RyanGlScott
Copy link
Collaborator

The type signatures used in the fields of FunctionABI and SyscallABI are somewhat messy. This is a mega-issue dedicated to cleaning them up. These will likely involve some backwards-incompatible API changes.

Inconsistent use of IO versus OverrideSim in return types

The syscallArgumentRegisters and syscallNumberRegister functions return IO, but the syscallReturnRegisters function returns OverrideSim. This seems very inconsistent, given that all of these functions do very similar things. I propose that these functions either all return IO or all return OverrideSim.

Similarly, functionIntegerArguments and functionReturnAddr return IO, but functionIntegerReturnRegisters returns OverrideSim.

functionReturnAddr should return an Either, not a Maybe

(Spun off from a discussion at #38 (comment))

Currently, the return type of functionReturnAddr is IO (Maybe (MemWord (ArchAddrWidth arch))), but this arguably doesn't capture the full range of ways that this function could fail. This is best explained by looking at one implementation of functionReturnAddr:

x86_64LinuxReturnAddr bak archVals regs mem = do
let ?ptrWidth = WI.knownNat @64
addrPtr <- LCLM.doLoad bak mem
(LCS.regValue stackPointer)
(LCLM.bitvectorType 8)
(LCLM.LLVMPointerRepr ?ptrWidth)
LCLD.noAlignment
res <- AVC.resolveSymBVAs bak WT.knownNat $ LCLMP.llvmPointerOffset addrPtr
case res of
Left AVC.UnsatInitialAssumptions -> do
loc <- WI.getCurrentProgramLoc sym
AP.panic AP.FunctionOverride "x86_64LinuxReturnAddr"
["Initial assumptions are unsatisfiable at " ++ show (PP.pretty (WP.plSourceLoc loc))]
-- This can genuinely happen if a function is invoked as a tail call, so
-- which the main reason why this returns a Maybe instead of panicking.
Left AVC.MultipleModels ->
pure Nothing
-- I'm unclear if this case can ever happen under normal circumstances, but
-- we'll return Nothing here just to be on the safe side.
Left AVC.SolverUnknown ->
pure Nothing
Right addrBV ->
pure $ Just $ fromIntegral $ BVS.asUnsigned addrBV

Some of these cases return Nothing, while others panic. Moreover, it's conceivable that the panicking case could be reachable from user-written code.

Really, functionReturnAddr ought to return Either e (MemWord (ArchAddrWidth arch)), where e is some suitable enumeration type that covers all of the different possible failures.

syscallReturnRegisters takes a redundant CtxRepr argument

(Spun off from a discussion at #38 (comment))

Currently, syscallReturnRegisters takes both a CtxRepr atps argument as well as a RegEntry sym (StructType atps) argument. The CtxRepr atps argument is redundant, however, as it can be recovered from the RegEntry. We should remove the CtxRepr atps argument.

@RyanGlScott RyanGlScott added the tech-debt Technical debt label Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tech-debt Technical debt
Projects
None yet
Development

No branches or pull requests

1 participant