summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile19
-rw-r--r--brk_shim.c44
-rw-r--r--brk_shim.h4
-rw-r--r--ex.c3
-rw-r--r--ex_re.c2
-rw-r--r--ex_subr.c4
-rw-r--r--exrecover.c5
-rw-r--r--libuxre/re.h2
-rw-r--r--libuxre/uxre_regex.h (renamed from libuxre/regex.h)1
9 files changed, 67 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index be2666a..8ad3d20 100644
--- a/Makefile
+++ b/Makefile
@@ -79,11 +79,11 @@
# Destinations for installation. $(PRESERVEDIR) is used for recovery files.
# It will get mode 1777.
#
-PREFIX=/home/tmu/.local
+PREFIX ?=/usr/local
BINDIR = $(PREFIX)/bin
LIBEXECDIR = $(PREFIX)/libexec
MANDIR = $(PREFIX)/share/man
-PRESERVEDIR=/tmp/ex-preserve/
+PRESERVEDIR = /tmp/ex-preserve/
#
# DESTDIR is prepended to the installation paths. It is mostly useful
@@ -94,7 +94,7 @@ DESTDIR =
#
# A BSD-like install program. GNU install will fit well here, too.
#
-INSTALL=/usr/bin/install
+INSTALL =/usr/bin/install
#
# Compiler and linker flags.
@@ -247,16 +247,16 @@ OBJS = ex.o ex_addr.o ex_cmds.o ex_cmds2.o ex_cmdsub.o \
ex_set.o ex_subr.o ex_tagio.o ex_temp.o ex_tty.o ex_unix.o \
ex_v.o ex_vadj.o ex_vget.o ex_vmain.o ex_voper.o \
ex_vops.o ex_vops2.o ex_vops3.o ex_vput.o ex_vwind.o \
- printf.o ex_version.o $(MALLOC)
+ printf.o ex_version.o $(MALLOC) brk_shim.o
HDRS = ex.h ex_argv.h ex_re.h ex_temp.h ex_tty.h ex_tune.h ex_vars.h \
- ex_vis.h libterm/libterm.h
+ ex_vis.h libterm/libterm.h brk_shim.h
SRC1 = ex.c ex_addr.c ex_cmds.c ex_cmds2.c ex_cmdsub.c
SRC2 = ex_data.c ex_get.c ex_io.c ex_put.c ex_re.c
SRC3 = ex_set.c ex_subr.c ex_tagio.c ex_temp.c ex_tty.c ex_unix.c
SRC4 = ex_v.c ex_vadj.c ex_vget.c ex_vmain.c ex_voper.c
SRC5 = ex_vops.c ex_vops2.c ex_vops3.c ex_vput.c ex_vwind.c
SRC6 = printf.c expreserve.c exrecover.c ex_version.c
-SRC7 = mapmalloc.c malloc.c
+SRC7 = mapmalloc.c brk_shim.c #malloc.c
.SUFFIXES: .o .c
.c.o: ; $(CC) $(CCFLAGS) -c $<
@@ -271,8 +271,8 @@ $(TLIB): libterm/termcap.c libterm/tgoto.c libterm/tputs.c libterm/libterm.h
@cd libterm && $(MAKE) CC="$(CC)" \
COPT="$(CFLAGS) $(WARN) $(CPPFLAGS) $(OSTYPE)"
-exrecover: exrecover.o $(MALLOC)
- $(CC) -o exrecover $(LDFLAGS) exrecover.o $(MALLOC) $(LDADD)
+exrecover: exrecover.o $(MALLOC) brk_shim.o
+ $(CC) -o exrecover $(LDFLAGS) exrecover.o brk_shim.o $(MALLOC) $(LDADD)
expreserve: expreserve.o
$(CC) -o expreserve $(LDFLAGS) expreserve.o $(LDADD)
@@ -403,6 +403,7 @@ ex_vwind.o: libterm/libterm.h
expreserve.o: config.h
exrecover.o: config.h ex.h ex_proto.h ex_temp.h ex_tty.h ex_tune.h ex_vars.h
exrecover.o: libterm/libterm.h
-malloc.o: config.h
+# malloc.o: config.h
mapmalloc.o: config.h
printf.o: config.h
+brk_shim.o: brk_shim.h
diff --git a/brk_shim.c b/brk_shim.c
new file mode 100644
index 0000000..1680a18
--- /dev/null
+++ b/brk_shim.c
@@ -0,0 +1,44 @@
+#include "brk_shim.h"
+
+#include <errno.h>
+
+/*
+ * The idea is to just allocate a large buffer and rely on lazy page
+ * loading to not use more physical memory than necessary.
+ */
+
+#ifdef LARGEF
+#define SHIMSIZE 0x4000000
+/* 64MB */
+#else
+#define SHIMSIZE 0x200000
+/* 2MB */
+#endif
+
+static char shim_space[SHIMSIZE];
+static intptr_t shim_size = 0;
+
+void *shim_sbrk(intptr_t increment) {
+ void* current = (void*)(shim_space + shim_size);
+ shim_size += increment;
+ if (shim_size < 0) {
+ shim_size = 0;
+ return (void*)-1;
+ } else if (shim_size > SHIMSIZE) {
+ shim_size = SHIMSIZE;
+ return (void*)-1;
+ }
+ return current;
+}
+
+int shim_brk(void* addr) {
+ if (addr < (void*)shim_space ||
+ addr > (void*)(shim_space + SHIMSIZE)) {
+ errno = EINVAL;
+ return -1;
+ }
+ shim_size = ((void*)shim_space) - addr;
+ return 0;
+}
+
+
diff --git a/brk_shim.h b/brk_shim.h
new file mode 100644
index 0000000..3e81758
--- /dev/null
+++ b/brk_shim.h
@@ -0,0 +1,4 @@
+#include <stdint.h>
+
+int shim_brk(void *addr);
+void *shim_sbrk(intptr_t increment);
diff --git a/ex.c b/ex.c
index a6b5121..caf88f2 100644
--- a/ex.c
+++ b/ex.c
@@ -87,6 +87,7 @@ static char sccsid[] = "@(#)ex.c 1.37 (gritter) 8/4/05";
#include "ex_argv.h"
#include "ex_temp.h"
#include "ex_tty.h"
+#include "brk_shim.h"
#ifdef TRACE
char tttrace[] = { '/','d','e','v','/','t','t','y','x','x',0 };
@@ -529,7 +530,7 @@ argend:
* this as ed does, saving a little core, but it will probably
* not often make much difference.
*/
- fendcore = (line *) sbrk(0);
+ fendcore = (line *) shim_sbrk(0);
endcore = fendcore - 2;
#ifdef SIGTSTP
diff --git a/ex_re.c b/ex_re.c
index 653a8bf..99d4ad8 100644
--- a/ex_re.c
+++ b/ex_re.c
@@ -84,7 +84,7 @@ static char sccsid[] = "@(#)ex_re.c 1.60 (gritter) 8/6/05";
#ifdef UXRE
-#include "regex.h"
+#include "uxre_regex.h"
char *braslist[NBRA];
char *braelist[NBRA];
diff --git a/ex_subr.c b/ex_subr.c
index 663a78e..3d9c090 100644
--- a/ex_subr.c
+++ b/ex_subr.c
@@ -490,12 +490,12 @@ morelines(void)
pg = 4096;
pg /= sizeof (line);
}
- if ((char *)sbrk(pg * sizeof (line)) == (char *)-1)
+ if ((char *)shim_sbrk(pg * sizeof (line)) == (char *)-1)
return (-1);
endcore += pg;
return (0);
#else /* !_SC_PAGESIZE */
- if (sbrk(1024 * sizeof (line)) == (char *)-1)
+ if (shim_sbrk(1024 * sizeof (line)) == (char *)-1)
return (-1);
endcore += 1024;
return (0);
diff --git a/exrecover.c b/exrecover.c
index 17ba06f..e2fa677 100644
--- a/exrecover.c
+++ b/exrecover.c
@@ -106,6 +106,7 @@ extern int vsprintf(char *, const char *, va_list);
#include "ex.h"
#include "ex_temp.h"
#include "ex_tty.h"
+#include "brk_shim.h"
#include <dirent.h>
#include <time.h>
@@ -220,7 +221,7 @@ main(int argc, char *argv[])
/*
* Initialize as though the editor had just started.
*/
- fendcore = (line *) sbrk(0);
+ fendcore = (line *) shim_sbrk(0);
dot = zero = dol = fendcore;
one = zero + 1;
endcore = fendcore - 2;
@@ -259,7 +260,7 @@ main(int argc, char *argv[])
/*
* Allocate space for the line pointers from the temp file.
*/
- if ((char *) sbrk(H.Flines * sizeof (line)) == (char *) -1)
+ if ((char *) shim_sbrk(H.Flines * sizeof (line)) == (char *) -1)
/*
* Good grief.
*/
diff --git a/libuxre/re.h b/libuxre/re.h
index 64df2d0..9e0241e 100644
--- a/libuxre/re.h
+++ b/libuxre/re.h
@@ -35,7 +35,7 @@
/* #define __fnm_collate lc_collate */ /* <fnmatch.h> */
#include <limits.h>
-#include "regex.h"
+#include "uxre_regex.h"
/* #include <fnmatch.h> */
#include <colldata.h>
diff --git a/libuxre/regex.h b/libuxre/uxre_regex.h
index 8dbd028..068c1f9 100644
--- a/libuxre/regex.h
+++ b/libuxre/uxre_regex.h
@@ -24,7 +24,6 @@
* Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
#ifndef LIBUXRE_REGEX_H
#define LIBUXRE_REGEX_H
/* from unixsrc:usr/src/common/head/regex.h /main/uw7_nj/1 */