summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-03-26 18:22:42 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-03-26 18:22:42 +0800
commit29c15f61e0b5b58b39d499bc3526333a0b06e373 (patch)
treefdb63e0733ab531e077e93111cff7c6bc6bf6fc2
parent67278caff081fa2e2047d807023f5ebb51afa574 (diff)
downloadpttbbs-29c15f61e0b5b58b39d499bc3526333a0b06e373.tar
pttbbs-29c15f61e0b5b58b39d499bc3526333a0b06e373.tar.gz
pttbbs-29c15f61e0b5b58b39d499bc3526333a0b06e373.tar.bz2
pttbbs-29c15f61e0b5b58b39d499bc3526333a0b06e373.tar.lz
pttbbs-29c15f61e0b5b58b39d499bc3526333a0b06e373.tar.xz
pttbbs-29c15f61e0b5b58b39d499bc3526333a0b06e373.tar.zst
pttbbs-29c15f61e0b5b58b39d499bc3526333a0b06e373.zip
CRITICAL_MEMORY
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@712 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/proto.h10
-rw-r--r--mbbsd/stuff.c27
2 files changed, 35 insertions, 2 deletions
diff --git a/include/proto.h b/include/proto.h
index 0fb19043..ef5693cc 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -1,4 +1,4 @@
-/* $Id: proto.h,v 1.37 2003/02/12 14:31:36 victor Exp $ */
+/* $Id: proto.h,v 1.38 2003/03/26 10:21:29 in2 Exp $ */
#ifndef INCLUDE_PROTO_H
#define INCLUDE_PROTO_H
@@ -449,6 +449,13 @@ int not_alpha(char ch);
int valid_ident(char *ident);
int userid_is_BM(char *userid, char *list);
int is_uBM(char *list, char *id);
+#ifndef CRITICAL_MEMORY
+ #define MALLOC(p) malloc(p)
+ #define FREE(p) free(p)
+#else
+ void *MALLOC(int size);
+ void FREE(void *ptr);
+#endif
/* syspost */
int post_msg(char* bname, char* title, char *msg, char* author);
@@ -583,4 +590,5 @@ void touchbtotal(int bid);
/* util_cache.c */
void reload_pttcache(void);
+
#endif
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