Skip to content

Commit

Permalink
Return RewriterEnv from ELF rewriter
Browse files Browse the repository at this point in the history
  • Loading branch information
langston-barrett committed Feb 21, 2020
1 parent 02791bf commit 3f3dbf3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions renovate/src/Renovate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module Renovate
RW.RewriteSite(..),
E.SomeBlocks(..),
E.RewriterInfo,
E.RewriterEnv,
E.SectionInfo(..),
E.riSmallBlockCount,
E.riReusedByteCount,
Expand Down
9 changes: 5 additions & 4 deletions renovate/src/Renovate/BinaryFormat/ELF.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Renovate.BinaryFormat.ELF (
rewriteElf,
analyzeElf,
RewriterInfo,
RewriterEnv,
SomeBlocks(..),
RE.SectionInfo(..),
reSegmentMaximumSize,
Expand Down Expand Up @@ -191,13 +192,13 @@ rewriteElf :: (B.InstructionConstraints arch,
-- (including statically-allocated data)
-> RE.LayoutStrategy
-- ^ The layout strategy for blocks in the new binary
-> IO (E.Elf (MM.ArchAddrWidth arch), b arch, RewriterInfo lm arch)
-> IO (E.Elf (MM.ArchAddrWidth arch), b arch, RewriterInfo lm arch, RewriterEnv arch)
rewriteElf cfg hdlAlloc e loadedBinary strat = do
(analysisResult, ri) <- runElfRewriter cfg e $ do
(analysisResult, ri, env) <- runElfRewriter cfg e $ do
-- FIXME: Use the symbol map from the loaded binary (which we still need to add)
symmap <- withCurrentELF buildSymbolMap
doRewrite cfg hdlAlloc loadedBinary symmap strat
return (_riELF ri, analysisResult, ri)
return (_riELF ri, analysisResult, ri, env)

-- | Run an analysis over an ELF file
--
Expand All @@ -217,7 +218,7 @@ analyzeElf :: (B.InstructionConstraints arch,
-- (including statically-allocated data)
-> IO (b arch, [RE.Diagnostic])
analyzeElf cfg hdlAlloc e loadedBinary = do
(b, ri) <- runElfRewriter cfg e $ do
(b, ri, _env) <- runElfRewriter cfg e $ do
symmap <- withCurrentELF buildSymbolMap
textSection <- withCurrentELF findTextSection
let textRange = sectionAddressRange textSection
Expand Down
10 changes: 6 additions & 4 deletions renovate/src/Renovate/BinaryFormat/ELF/Rewriter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ runElfRewriter :: E.ElfWidthConstraints (MM.ArchAddrWidth arch)
=> RenovateConfig arch binFmt callbacks b
-> E.Elf (MM.ArchAddrWidth arch)
-> ElfRewriter lm arch a
-> IO (a, RewriterInfo lm arch)
-> IO (a, RewriterInfo lm arch, Env.RewriterEnv arch)
runElfRewriter config e a = do
env <- Env.makeRewriterEnv config e
S.runStateT
(R.runReaderT (unElfRewrite a) env)
(emptyRewriterInfo e)
(result, info) <-
S.runStateT
(R.runReaderT (unElfRewrite a) env)
(emptyRewriterInfo e)
return (result, info, env)

emptyRewriterInfo :: E.Elf (MM.ArchAddrWidth arch) -> RewriterInfo lm arch
emptyRewriterInfo e = RewriterInfo { _riOverwrittenRegions = []
Expand Down

0 comments on commit 3f3dbf3

Please sign in to comment.