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

Expose functionality for building crucible FnHandles from stubs FunctionOverrides #16

Open
RyanGlScott opened this issue Nov 15, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@RyanGlScott
Copy link
Collaborator

stubs-common defines functionality for turning a FunctionOverride into an FnHandle suitable for use within crucible:

mkAndBindOverride :: forall fnArgs fnRet rtp blocks r ctx
. LCS.CrucibleState p sym ext rtp blocks r ctx
-> AF.FunctionOverride p sym fnArgs arch fnRet
-> [ AF.SomeFunctionOverride p sym arch ]
-> IO ( LCF.FnHandle args ret
, LCS.CrucibleState p sym ext rtp blocks r ctx
)
mkAndBindOverride state0 fnOverride parents = do
-- First, construct an override for the function.
let retOV :: forall r'
. LCSO.OverrideSim p sym ext r' args ret
(Ctx.Assignment (LCS.RegValue' sym)
(DMS.CtxToCrucibleType (DMS.ArchRegContext arch)))
retOV = do
mem <- LCS.readGlobal $ SM.imMemVar initialMem
argMap <- LCS.getOverrideArgs
let argReg = massageRegAssignment $ LCS.regMap argMap
(args, getVarArg) <- liftIO $
SM.functionIntegerArguments abi bak
(AF.functionArgTypes fnOverride)
argReg mem
retVal <- AF.functionOverride fnOverride bak args getVarArg parents
SM.functionIntegerReturnRegisters abi bak archVals
(AF.functionReturnType fnOverride)
retVal
argReg
let ov :: LCSO.Override p sym ext args ret
ov = LCSO.mkOverride' (AF.functionName fnOverride) regsRepr retOV
-- Next, register any externs, auxiliary functions, or forward
-- declarations that are used in the override.
let LCS.FnBindings curHandles = state0 ^. LCS.stateContext ^. LCS.functionBindings
let curGlobals = state0 ^. LCSE.stateGlobals
(newHandles, newGlobals) <-
insertFunctionOverrideReferences bak abi fnOverride curHandles curGlobals
let state1 = state0 & LCS.stateContext . LCS.functionBindings
.~ LCS.FnBindings newHandles
& LCSE.stateGlobals
.~ newGlobals
-- Finally, build a function handle for the override and insert it into
-- the state.
bindOverrideHandle state1 hdlAlloc (Ctx.singleton regsRepr) crucRegTypes ov

Unfortunately, this functionality is defined as a local function within Stubs.Memory.Common.lookupFunction, which makes it impossible to use by downstream clients. We should factor out the relevant bits of mkAndBindOverride into top-level functions that can be called independently.

@RyanGlScott RyanGlScott added the enhancement New feature or request label Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant