ref: 38f03e07a073bba716564f05dcc9e8ee891805cd
parent: 52ef32b73c4bb6a8a039a5c72d7c81b953953262
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat May 16 16:10:11 EDT 2020
libc: Fix _getheap() for linux Linux is adding randomization to brk() calls, which means that it breaksall the software using brk() that was also using the end symbol. This patch modifies _getheap() to use brk(0) to obtain the base of the heap.
--- a/src/libc/arch/amd64/linux/_getheap.c
+++ b/src/libc/arch/amd64/linux/_getheap.c
@@ -1,1 +1,1 @@
-#include "../../posix/_getheap.c"
+#include "../../linux/_getheap.c"
--- a/src/libc/arch/amd64/netbsd/crt.s
+++ b/src/libc/arch/amd64/netbsd/crt.s
@@ -1,2 +1,2 @@
- .include "../../crt-netbsd.s"
+ .include "../../netbsd/crt.s"
.include "../crt-posix.s"
--- a/src/libc/arch/amd64/openbsd/crt.s
+++ b/src/libc/arch/amd64/openbsd/crt.s
@@ -1,2 +1,2 @@
- .include "../../crt-openbsd.s"
+ .include "../../openbsd/crt.s"
.include "../crt-posix.s"
--- a/src/libc/arch/arm32/linux/_getheap.c
+++ b/src/libc/arch/arm32/linux/_getheap.c
@@ -1,1 +1,1 @@
-#include "../../posix/_getheap.c"
+#include "../../linux/_getheap.c"
--- a/src/libc/arch/arm64/linux/_getheap.c
+++ b/src/libc/arch/arm64/linux/_getheap.c
@@ -1,1 +1,1 @@
-#include "../../posix/_getheap.c"
+#include "../../linux/_getheap.c"
--- a/src/libc/arch/crt-netbsd.s
+++ /dev/null
@@ -1,9 +1,0 @@
- .file "crt-netbsd.s"
- .section ".note.netbsd.ident", "a"
- .p2align 2
-
- .long 7
- .long 4
- .long 1
- .ascii "NetBSD\0\0"
- .long 800000000
--- a/src/libc/arch/crt-openbsd.s
+++ /dev/null
@@ -1,9 +1,0 @@
- .file "crt-openbsd.s"
- .section ".note.openbsd.ident", "a"
- .p2align 2
- .long 8
- .long 4
- .long 1
- .ascii "OpenBSD\0"
- .long 0
- .p2align 2
--- a/src/libc/arch/i386/linux/_getheap.c
+++ b/src/libc/arch/i386/linux/_getheap.c
@@ -1,1 +1,1 @@
-#include "../../posix/_getheap.c"
+#include "../../linux/_getheap.c"
--- /dev/null
+++ b/src/libc/arch/linux/_getheap.c
@@ -1,0 +1,10 @@
+#include <stddef.h>
+
+#include "../../libc.h"
+#include "../../syscall.h"
+
+void *
+_getheap(void)
+{
+ return _brk(0);
+}
--- /dev/null
+++ b/src/libc/arch/netbsd/crt.s
@@ -1,0 +1,9 @@
+ .file "crt-netbsd.s"
+ .section ".note.netbsd.ident", "a"
+ .p2align 2
+
+ .long 7
+ .long 4
+ .long 1
+ .ascii "NetBSD\0\0"
+ .long 800000000
--- /dev/null
+++ b/src/libc/arch/openbsd/crt.s
@@ -1,0 +1,9 @@
+ .file "crt-openbsd.s"
+ .section ".note.openbsd.ident", "a"
+ .p2align 2
+ .long 8
+ .long 4
+ .long 1
+ .ascii "OpenBSD\0"
+ .long 0
+ .p2align 2
--- a/src/libc/arch/ppc32/linux/_getheap.c
+++ b/src/libc/arch/ppc32/linux/_getheap.c
@@ -1,1 +1,1 @@
-#include "../../posix/_getheap.c"
+#include "../../linux/_getheap.c"