aboutsummaryrefslogtreecommitdiff
path: root/libexec/rtld-aout/rtld.c
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/rtld-aout/rtld.c')
-rw-r--r--libexec/rtld-aout/rtld.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/libexec/rtld-aout/rtld.c b/libexec/rtld-aout/rtld.c
index 0cccd23d12c0..2f9e361fa638 100644
--- a/libexec/rtld-aout/rtld.c
+++ b/libexec/rtld-aout/rtld.c
@@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: rtld.c,v 1.3 1993/11/09 04:44:30 paul Exp $
+ * $Id: rtld.c,v 1.4 1993/11/22 19:05:27 jkh Exp $
*/
#include <machine/vmparam.h>
@@ -240,6 +240,9 @@ struct link_dynamic *dp;
if (link_map_head)
ldp->ldd_sym_loaded = 1;
}
+
+ /* Close our file descriptor */
+ (void)close(crtp->crt_ldfd);
}
@@ -1055,6 +1058,63 @@ xprintf("sbrk: incr = %#x, curbrk = %#x\n", incr, curbrk);
if (mmap(curbrk, incr,
PROT_READ|PROT_WRITE,
MAP_ANON|MAP_FIXED|MAP_COPY, fd, 0) == (caddr_t)-1) {
+ xprintf("Cannot map anonymous memory");
+ _exit(1);
+ }
+
+#ifdef NEED_DEV_ZERO
+ close(fd);
+#endif
+
+ oldbrk = curbrk;
+#if TRY_THIS_FOR_A_CHANGE
+ curbrk -= incr;
+#else
+ curbrk += incr;
+#endif
+
+ return oldbrk;
+}
+#else
+
+caddr_t
+sbrk(incr)
+int incr;
+{
+ int fd = -1;
+ caddr_t oldbrk;
+
+xprintf("sbrk: incr = %#x, curbrk = %#x\n", incr, curbrk);
+#if DEBUG
+xprintf("sbrk: incr = %#x, curbrk = %#x\n", incr, curbrk);
+#endif
+ if (curbrk == 0 && (curbrk = mmap(0, PAGSIZ,
+ PROT_READ|PROT_WRITE,
+ MAP_ANON|MAP_COPY, fd, 0)) == (caddr_t)-1) {
+ xprintf("Cannot map anonymous memory");
+ _exit(1);
+ }
+
+ /* There's valid memory from `curbrk' to next page boundary */
+ if ((long)curbrk + incr <= (((long)curbrk + PAGSIZ) & ~(PAGSIZ - 1))) {
+ oldbrk = curbrk;
+ curbrk += incr;
+ return oldbrk;
+ }
+ /*
+ * If asking for than currently left in this chunk,
+ * go somewhere completely different.
+ */
+
+#ifdef NEED_DEV_ZERO
+ fd = open("/dev/zero", O_RDWR, 0);
+ if (fd == -1)
+ perror("/dev/zero");
+#endif
+
+ if ((curbrk = mmap(0, incr,
+ PROT_READ|PROT_WRITE,
+ MAP_ANON|MAP_COPY, fd, 0)) == (caddr_t)-1) {
perror("Cannot map anonymous memory");
}