[Git][ghc/ghc][master] 2 commits: rts: expose HeapAlloc.h as public header

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Wed Mar 6 18:39:31 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
dedcf102 by Cheng Shao at 2024-03-06T13:39:04-05:00
rts: expose HeapAlloc.h as public header

This commit exposes HeapAlloc.h as a public header. The intention is
to expose HEAP_ALLOCED/HEAP_ALLOCED_GC, so they can be used in
assertions in other public headers, and they may also be useful for
user code.

- - - - -
d19441d7 by Cheng Shao at 2024-03-06T13:39:04-05:00
rts: assert pointer is indeed heap allocated in Bdescr()

This commit adds an assertion to Bdescr() to assert the pointer is
indeed heap allocated. This is useful to rule out RTS bugs that
attempt to access non-existent block descriptor of a static closure, #24492
being one such example.

- - - - -


12 changed files:

- rts/Sparks.c
- rts/include/rts/storage/Block.h
- rts/sm/HeapAlloc.h → rts/include/rts/storage/HeapAlloc.h
- rts/posix/OSMem.c
- rts/rts.cabal
- rts/sm/CNF.c
- rts/sm/GC.h
- rts/sm/NonMoving.h
- rts/sm/NonMovingMark.c
- rts/sm/Sanity.c
- rts/wasm/OSMem.c
- rts/win32/OSMem.c


Changes:

=====================================
rts/Sparks.c
=====================================
@@ -16,7 +16,7 @@
 #include "Sparks.h"
 #include "ThreadLabels.h"
 #include "sm/NonMovingMark.h"
-#include "sm/HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 
 #if defined(THREADED_RTS)
 


=====================================
rts/include/rts/storage/Block.h
=====================================
@@ -10,6 +10,10 @@
 
 #include "ghcconfig.h"
 
+#if !defined(CMINUSMINUS)
+#include "rts/storage/HeapAlloc.h"
+#endif
+
 /* The actual block and megablock-size constants are defined in
  * rts/include/Constants.h, all constants here are derived from these.
  */
@@ -190,6 +194,7 @@ typedef struct bdescr_ {
 EXTERN_INLINE bdescr *Bdescr(StgPtr p);
 EXTERN_INLINE bdescr *Bdescr(StgPtr p)
 {
+  ASSERT(HEAP_ALLOCED_GC(p));
   return (bdescr *)
     ((((W_)p &  MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT))
      | ((W_)p & ~MBLOCK_MASK)


=====================================
rts/sm/HeapAlloc.h → rts/include/rts/storage/HeapAlloc.h
=====================================
@@ -8,8 +8,6 @@
 
 #pragma once
 
-#include "BeginPrivate.h"
-
 #if defined(THREADED_RTS)
 // needed for HEAP_ALLOCED below
 extern SpinLock gc_alloc_block_sync;
@@ -227,5 +225,3 @@ StgBool HEAP_ALLOCED_GC(const void *p)
 #else
 # error HEAP_ALLOCED not defined
 #endif
-
-#include "EndPrivate.h"


=====================================
rts/posix/OSMem.c
=====================================
@@ -13,7 +13,7 @@
 
 #include "RtsUtils.h"
 #include "sm/OSMem.h"
-#include "sm/HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 
 #if defined(HAVE_UNISTD_H)
 #include <unistd.h>


=====================================
rts/rts.cabal
=====================================
@@ -303,6 +303,7 @@ library
                         rts/storage/Closures.h
                         rts/storage/FunTypes.h
                         rts/storage/Heap.h
+                        rts/storage/HeapAlloc.h
                         rts/storage/GC.h
                         rts/storage/InfoTables.h
                         rts/storage/MBlock.h


=====================================
rts/sm/CNF.c
=====================================
@@ -20,7 +20,7 @@
 #include "Storage.h"
 #include "CNF.h"
 #include "Hash.h"
-#include "HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 #include "BlockAlloc.h"
 #include "Trace.h"
 #include "sm/ShouldCompact.h"


=====================================
rts/sm/GC.h
=====================================
@@ -13,7 +13,7 @@
 
 #pragma once
 
-#include "HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 
 #include "BeginPrivate.h"
 


=====================================
rts/sm/NonMoving.h
=====================================
@@ -11,7 +11,7 @@
 #if !defined(CMINUSMINUS)
 
 #include <string.h>
-#include "HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 #include "NonMovingMark.h"
 
 #include "BeginPrivate.h"


=====================================
rts/sm/NonMovingMark.c
=====================================
@@ -14,7 +14,7 @@
 #include "NonMovingShortcut.h"
 #include "NonMoving.h"
 #include "BlockAlloc.h"  /* for countBlocks */
-#include "HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 #include "Task.h"
 #include "Trace.h"
 #include "HeapUtils.h"


=====================================
rts/sm/Sanity.c
=====================================
@@ -32,7 +32,7 @@
 #include "sm/NonMoving.h"
 #include "sm/NonMovingMark.h"
 #include "Profiling.h" // prof_arena
-#include "HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 
 /* -----------------------------------------------------------------------------
    Forward decls.


=====================================
rts/wasm/OSMem.c
=====================================
@@ -52,7 +52,7 @@
 
 #include "RtsUtils.h"
 #include "sm/OSMem.h"
-#include "sm/HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 
 #include <__macro_PAGESIZE.h>
 


=====================================
rts/win32/OSMem.c
=====================================
@@ -8,7 +8,7 @@
 
 #include "Rts.h"
 #include "sm/OSMem.h"
-#include "sm/HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 #include "RtsUtils.h"
 
 #include <windows.h>



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/21e3f3250e88640087a1a60bee2cc113bf04509f...d19441d7981778ab9463557d812d9d7cf586f9e7

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/21e3f3250e88640087a1a60bee2cc113bf04509f...d19441d7981778ab9463557d812d9d7cf586f9e7
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240306/5dbf3b9b/attachment-0001.html>


More information about the ghc-commits mailing list