From eac6e7e5c64db525b2174713f730af1883dcc752 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Mon, 17 Jun 2019 18:08:51 +0300 Subject: [PATCH] removed malloc/free from Kernel --- src/cpfront/posix/generic/System/Mod/Kernel.cp | 14 ++++++++++---- src/native/linux/generic/System/Mod/Kernel.cp | 14 ++++++++++---- src/native/posix/generic/System/Mod/Kernel.cp | 14 ++++++++++---- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/cpfront/posix/generic/System/Mod/Kernel.cp b/src/cpfront/posix/generic/System/Mod/Kernel.cp index 82cac15..8d4c334 100644 --- a/src/cpfront/posix/generic/System/Mod/Kernel.cp +++ b/src/cpfront/posix/generic/System/Mod/Kernel.cp @@ -460,12 +460,18 @@ MODULE Kernel; PROCEDURE AllocHeapMem (size: INTEGER; VAR c: Cluster); CONST N = 65536; (* cluster size for dll *) - VAR adr, allocated: INTEGER; + VAR adr, allocated, newsize: INTEGER; BEGIN INC(size, 16); ASSERT(size > 0, 100); adr := 0; - IF size < N THEN adr := stdlib.malloc(N) END; - IF adr = 0 THEN adr := stdlib.malloc(size); allocated := size ELSE allocated := N END; + IF size < N THEN + adr := AllocMem(N, newsize); + allocated := newsize + END; + IF adr = 0 THEN + adr := AllocMem(size, newsize); + allocated := newsize + END; IF adr = 0 THEN c := NIL ELSE c := S.VAL(Cluster, (adr + 15) DIV 16 * 16); c.max := adr; @@ -479,7 +485,7 @@ MODULE Kernel; PROCEDURE FreeHeapMem (c: Cluster); BEGIN DEC(used, c.size); DEC(total, c.size); - stdlib.free(S.VAL(ADDRESS, c.max)) + FreeMem(S.VAL(ADDRESS, c.max), c.size) END FreeHeapMem; PROCEDURE HeapFull (size: INTEGER): BOOLEAN; diff --git a/src/native/linux/generic/System/Mod/Kernel.cp b/src/native/linux/generic/System/Mod/Kernel.cp index 3e0ee50..115a773 100644 --- a/src/native/linux/generic/System/Mod/Kernel.cp +++ b/src/native/linux/generic/System/Mod/Kernel.cp @@ -459,12 +459,18 @@ MODULE Kernel; PROCEDURE AllocHeapMem (size: INTEGER; VAR c: Cluster); CONST N = 65536; (* cluster size for dll *) - VAR adr, allocated: INTEGER; + VAR adr, allocated, newsize: INTEGER; BEGIN INC(size, 16); ASSERT(size > 0, 100); adr := 0; - IF size < N THEN adr := stdlib.malloc(N) END; - IF adr = 0 THEN adr := stdlib.malloc(size); allocated := size ELSE allocated := N END; + IF size < N THEN + adr := AllocMem(N, newsize); + allocated := newsize + END; + IF adr = 0 THEN + adr := AllocMem(size, newsize); + allocated := newsize + END; IF adr = 0 THEN c := NIL ELSE c := S.VAL(Cluster, (adr + 15) DIV 16 * 16); c.max := adr; @@ -478,7 +484,7 @@ MODULE Kernel; PROCEDURE FreeHeapMem (c: Cluster); BEGIN DEC(used, c.size); DEC(total, c.size); - stdlib.free(S.VAL(ADDRESS, c.max)) + FreeMem(S.VAL(ADDRESS, c.max), c.size) END FreeHeapMem; PROCEDURE HeapFull (size: INTEGER): BOOLEAN; diff --git a/src/native/posix/generic/System/Mod/Kernel.cp b/src/native/posix/generic/System/Mod/Kernel.cp index 083c997..986425d 100644 --- a/src/native/posix/generic/System/Mod/Kernel.cp +++ b/src/native/posix/generic/System/Mod/Kernel.cp @@ -459,12 +459,18 @@ MODULE Kernel; PROCEDURE AllocHeapMem (size: INTEGER; VAR c: Cluster); CONST N = 65536; (* cluster size for dll *) - VAR adr, allocated: INTEGER; + VAR adr, allocated, newsize: INTEGER; BEGIN INC(size, 16); ASSERT(size > 0, 100); adr := 0; - IF size < N THEN adr := stdlib.malloc(N) END; - IF adr = 0 THEN adr := stdlib.malloc(size); allocated := size ELSE allocated := N END; + IF size < N THEN + adr := AllocMem(N, newsize); + allocated := newsize + END; + IF adr = 0 THEN + adr := AllocMem(size, newsize); + allocated := newsize + END; IF adr = 0 THEN c := NIL ELSE c := S.VAL(Cluster, (adr + 15) DIV 16 * 16); c.max := adr; @@ -478,7 +484,7 @@ MODULE Kernel; PROCEDURE FreeHeapMem (c: Cluster); BEGIN DEC(used, c.size); DEC(total, c.size); - stdlib.free(S.VAL(ADDRESS, c.max)) + FreeMem(S.VAL(ADDRESS, c.max), c.size) END FreeHeapMem; PROCEDURE HeapFull (size: INTEGER): BOOLEAN; -- 2.29.2