From 29c15f61e0b5b58b39d499bc3526333a0b06e373 Mon Sep 17 00:00:00 2001
From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>
Date: Wed, 26 Mar 2003 10:22:42 +0000
Subject: CRITICAL_MEMORY

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@712 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 mbbsd/stuff.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

(limited to 'mbbsd')

diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c
index 41d5d93e..f79ec1ae 100644
--- a/mbbsd/stuff.c
+++ b/mbbsd/stuff.c
@@ -1,4 +1,4 @@
-/* $Id: stuff.c,v 1.10 2003/01/16 11:58:04 kcwu Exp $ */
+/* $Id: stuff.c,v 1.11 2003/03/26 10:22:42 in2 Exp $ */
 #include "bbs.h"
 
 /* ----------------------------------------------------- */
@@ -613,3 +613,28 @@ show_help(char *helptext[])
     }
     pressanykey();
 }
+
+/* ----------------------------------------------------- */
+/* use mmap() to malloc large memory in CRITICAL_MEMORY  */
+/* ----------------------------------------------------- */
+#ifdef CRITICAL_MEMORY
+void *MALLOC(int size)
+{
+    int     *p;
+    p = (int *)mmap(NULL, (size + 4), PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
+    p[0] = size;
+#ifdef DEBUG
+    vmsg("critical malloc %d bytes", size);
+#endif
+    return (void *)&p[1];
+}
+
+void FREE(void *ptr)
+{
+    int     size = ((int *)ptr)[-1];
+    munmap((void *)(&(((int *)ptr)[-1])), size);
+#ifdef DEBUG
+    vmsg("critical free %d bytes", size);
+#endif
+}
+#endif
-- 
cgit v1.2.3