mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 22:13:07 +00:00
45 lines
1.6 KiB
Diff
45 lines
1.6 KiB
Diff
|
|
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
|
||
|
|
index e2dd43075..7f8c8e04e 100644
|
||
|
|
--- a/lib/system/alloc.nim
|
||
|
|
+++ b/lib/system/alloc.nim
|
||
|
|
@@ -1,4 +1,4 @@
|
||
|
|
-#
|
||
|
|
+#!fmt: off
|
||
|
|
#
|
||
|
|
# Nim's Runtime Library
|
||
|
|
# (c) Copyright 2012 Andreas Rumpf
|
||
|
|
@@ -862,6 +862,15 @@ when defined(gcDestructors):
|
||
|
|
dec maxIters
|
||
|
|
if it == nil: break
|
||
|
|
|
||
|
|
+when defined(heaptracker):
|
||
|
|
+ const heaptrackLib =
|
||
|
|
+ when defined(heaptracker_inject):
|
||
|
|
+ "libheaptrack_inject.so"
|
||
|
|
+ else:
|
||
|
|
+ "libheaptrack_preload.so"
|
||
|
|
+ proc heaptrack_malloc(a: pointer, size: int) {.cdecl, importc, dynlib: heaptrackLib.}
|
||
|
|
+ proc heaptrack_free(a: pointer) {.cdecl, importc, dynlib: heaptrackLib.}
|
||
|
|
+
|
||
|
|
proc rawAlloc(a: var MemRegion, requestedSize: int): pointer =
|
||
|
|
when defined(nimTypeNames):
|
||
|
|
inc(a.allocCounter)
|
||
|
|
@@ -984,6 +993,8 @@ proc rawAlloc(a: var MemRegion, requestedSize: int): pointer =
|
||
|
|
sysAssert(isAccessible(a, result), "rawAlloc 14")
|
||
|
|
sysAssert(allocInv(a), "rawAlloc: end")
|
||
|
|
when logAlloc: cprintf("var pointer_%p = alloc(%ld) # %p\n", result, requestedSize, addr a)
|
||
|
|
+ when defined(heaptracker):
|
||
|
|
+ heaptrack_malloc(result, requestedSize)
|
||
|
|
|
||
|
|
proc rawAlloc0(a: var MemRegion, requestedSize: int): pointer =
|
||
|
|
result = rawAlloc(a, requestedSize)
|
||
|
|
@@ -992,6 +1003,8 @@ proc rawAlloc0(a: var MemRegion, requestedSize: int): pointer =
|
||
|
|
proc rawDealloc(a: var MemRegion, p: pointer) =
|
||
|
|
when defined(nimTypeNames):
|
||
|
|
inc(a.deallocCounter)
|
||
|
|
+ when defined(heaptracker):
|
||
|
|
+ heaptrack_free(p)
|
||
|
|
#sysAssert(isAllocatedPtr(a, p), "rawDealloc: no allocated pointer")
|
||
|
|
sysAssert(allocInv(a), "rawDealloc: begin")
|
||
|
|
var c = pageAddr(p)
|