Skip to content

Commit

Permalink
llvm: Reinstate bindLLVMFunPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
langston-barrett committed Apr 26, 2024
1 parent 20504dc commit 50dcfad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
3 changes: 0 additions & 3 deletions crucible-llvm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# next

* The `doMallocHandle` function was removed.
* The `bindLLVMFunPtr` function was removed, instead use `doResolveGlobal`
to resolve a global symbol to a pointer, `someFnHandle` to construct a
`SomeFnHandle`, and pass both to `doInstallHandle`.
* The `RegOverrideM` monad was replaced by the `MakeOverride` function newtype.
* Several type parameters were removed from `OverrideTemplate`, and the `ext`
parameter was added. This had downstream effects in `basic_llvm_override`,
Expand Down
31 changes: 26 additions & 5 deletions crucible-llvm/src/Lang/Crucible/LLVM/Functions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ module Lang.Crucible.LLVM.Functions
, allocLLVMFunPtr
, allocLLVMFunPtrs
, registerFunPtr
, someFnHandle
, bindLLVMHandle
, bindLLVMCFG
, bindLLVMFunc
Expand Down Expand Up @@ -173,7 +172,7 @@ allocLLVMFunPtrs bak llvmCtx mem0 llvmMod = do
let allocLLVMFunPtr' bak' lctx mem decl = snd <$> allocLLVMFunPtr bak' lctx mem decl
foldM (allocLLVMFunPtr' bak llvmCtx) mem0 decls

-- | Turn a 'FnHandle' into a 'SomeFnHandle', for use with 'doInstallHandle'.
-- Not exported
someFnHandle :: FnHandle args ret -> SomeFnHandle
someFnHandle h =
case handleArgTypes h of
Expand All @@ -185,6 +184,29 @@ someFnHandle h =
--
-- This can overwrite existing allocation/handle associations, and is used to do
-- so when registering lazily-translated CFGs.
--
-- For a stateful version in 'OverrideSim', see 'bindLLVMHandle'.
bindLLVMFunPtr ::
(IsSymBackend sym bak, HasPtrWidth wptr) =>
bak ->
-- | Function name
L.Symbol ->
-- | Function implementation (CFG or override)
FnHandle args ret ->
-- | LLVM memory
MemImpl sym ->
IO (MemImpl sym)
bindLLVMFunPtr bak nm h mem = do
ptr <- doResolveGlobal bak mem nm
doInstallHandle bak ptr (someFnHandle h) mem

-- | Look up an existing global function allocation by name and bind a handle
-- to it.
--
-- This can overwrite existing allocation/handle associations, and is used to do
-- so when registering lazily-translated CFGs.
--
-- For a less stateful version in 'IO', see 'bindLLVMHandle'.
bindLLVMHandle ::
(IsSymInterface sym, HasPtrWidth wptr) =>
GlobalVar Mem ->
Expand All @@ -198,9 +220,8 @@ bindLLVMHandle ::
bindLLVMHandle mvar nm hdl impl = do
OverrideSim.bindFnHandle hdl impl
mem <- OverrideSim.readGlobal mvar
mem' <- OverrideSim.ovrWithBackend $ \bak -> do
ptr <- liftIO (doResolveGlobal bak mem nm)
liftIO $ doInstallHandle bak ptr (someFnHandle hdl) mem
mem' <- OverrideSim.ovrWithBackend $ \bak ->
liftIO (bindLLVMFunPtr bak nm hdl mem)
OverrideSim.writeGlobal mvar mem'

-- | Look up an existing global function allocation by name and bind a CFG to
Expand Down

0 comments on commit 50dcfad

Please sign in to comment.