diff options
author | christos <christos@NetBSD.org> | 2003-04-21 01:25:27 +0000 |
---|---|---|
committer | christos <christos@NetBSD.org> | 2003-04-21 01:25:27 +0000 |
commit | d24d9f34316870446a7e6d0990536f2b361b4064 (patch) | |
tree | 2d12c3d01dc294c7f8b612b0c39955a7050d35fe | |
parent | 6b63b6a7513084a7b8d5bfe71638ce78312a2834 (diff) | |
download | bsdgames-darwin-d24d9f34316870446a7e6d0990536f2b361b4064.tar.gz bsdgames-darwin-d24d9f34316870446a7e6d0990536f2b361b4064.tar.zst bsdgames-darwin-d24d9f34316870446a7e6d0990536f2b361b4064.zip |
PR/8247: Simon Burge: monop(6) save/restore doesn't work.
With the advent of elf and mmaping malloc, assumptions that the code made
before about location and contents of the data segment broke. We supplied
an sbrk() only malloc, and recorded the break point at the beginning of
the program, so now save and restore works, in the traditional monop style.
-rw-r--r-- | monop/execute.c | 9 | ||||
-rw-r--r-- | monop/monop.c | 6 |
2 files changed, 9 insertions, 6 deletions
diff --git a/monop/execute.c b/monop/execute.c index 2eb9aa8c..608688ec 100644 --- a/monop/execute.c +++ b/monop/execute.c @@ -1,4 +1,4 @@ -/* $NetBSD: execute.c,v 1.8 2001/08/29 18:23:44 jsm Exp $ */ +/* $NetBSD: execute.c,v 1.9 2003/04/21 01:25:27 christos Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)execute.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: execute.c,v 1.8 2001/08/29 18:23:44 jsm Exp $"); +__RCSID("$NetBSD: execute.c,v 1.9 2003/04/21 01:25:27 christos Exp $"); #endif #endif /* not lint */ @@ -59,6 +59,7 @@ typedef struct tm TIME; static char buf[257]; static bool new_play; /* set if move on to new player */ +extern void *heapstart; static void show_move __P((void)); @@ -209,7 +210,7 @@ save() for (sp = buf; *sp != '\n'; sp++) continue; *sp = '\0'; - start = 0; + start = heapstart; end = sbrk(0); while (start < end) { /* write out entire data space */ num = start + 16 * 1024 > end ? end - start : 16 * 1024; @@ -258,7 +259,7 @@ rest_f(file) perror(file); exit(1); } - start = 0; + start = heapstart; brk(end = start + sbuf.st_size); while (start < end) { /* write out entire data space */ num = start + 16 * 1024 > end ? end - start : 16 * 1024; diff --git a/monop/monop.c b/monop/monop.c index 51387156..12d3b5fe 100644 --- a/monop/monop.c +++ b/monop/monop.c @@ -1,4 +1,4 @@ -/* $NetBSD: monop.c,v 1.12 2001/09/18 18:15:49 wiz Exp $ */ +/* $NetBSD: monop.c,v 1.13 2003/04/21 01:25:27 christos Exp $ */ /* * Copyright (c) 1980, 1993 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\ #if 0 static char sccsid[] = "@(#)monop.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: monop.c,v 1.12 2001/09/18 18:15:49 wiz Exp $"); +__RCSID("$NetBSD: monop.c,v 1.13 2003/04/21 01:25:27 christos Exp $"); #endif #endif /* not lint */ @@ -58,6 +58,7 @@ static void getplayers __P((void)); static void init_players __P((void)); static void init_monops __P((void)); static void do_quit __P((int)); +void *heapstart; /* * This program implements a monopoly game @@ -71,6 +72,7 @@ main(ac, av) setgid(getgid()); srand(getpid()); + heapstart = sbrk(0); if (ac > 1) { if (!rest_f(av[1])) restore(); |