From 839ac52e94f8ecf878e522dba0575466af248267 Mon Sep 17 00:00:00 2001 From: Cheng Shao <terrorjack@type.dance> Date: Thu, 26 Sep 2024 22:30:28 +0000 Subject: [PATCH] ghci: use plain malloc for mkConInfoTable on non-TNTC platforms This patch avoids using mmap() to allocate executable memory for mkConInfoTable on platforms without tables-next-to-code, see added comment for explanation. --- libraries/ghci/GHCi/InfoTable.hsc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libraries/ghci/GHCi/InfoTable.hsc b/libraries/ghci/GHCi/InfoTable.hsc index 5ac08f693c8..ee6a8b7420c 100644 --- a/libraries/ghci/GHCi/InfoTable.hsc +++ b/libraries/ghci/GHCi/InfoTable.hsc @@ -324,7 +324,19 @@ newExecConItbl tables_next_to_code obj con_desc = do -- with a 32-bit offset relative to the info table, so if we -- allocated the string separately it might be out of range. - ex_ptr <- fillExecBuffer (sz + fromIntegral lcon_desc) $ \wr_ptr ex_ptr -> do + -- Just use plain malloc on platforms without TNTC, since we + -- don't need to allocate executable memory anyway. This is + -- much faster than mmap(), and is crucial for wasm since it + -- doesn't support mmap() at all, not to mention executable + -- memory. + fill_exec_buffer = if tables_next_to_code + then fillExecBuffer + else \n cont -> do + p <- mallocBytes $ fromIntegral n + cont p p + pure p + + ex_ptr <- fill_exec_buffer (sz + fromIntegral lcon_desc) $ \wr_ptr ex_ptr -> do let cinfo = StgConInfoTable { conDesc = ex_ptr `plusPtr` fromIntegral sz , infoTable = obj } pokeConItbl tables_next_to_code wr_ptr ex_ptr cinfo -- GitLab