libc {
GLIBC_2.0 {
- # necessary for the Hurd brk implementation
- _end;
-
# variables used in macros & inline functions
__hurd_threadvar_stack_mask; __hurd_threadvar_stack_offset;
CFLAGS-brk.o = $(no-stack-protector)
CFLAGS-brk.op = $(no-stack-protector)
+tests += tst-sbrk tst-sbrk-pie tst-sbrk-static
+tests-pie += tst-sbrk-pie
+tests-static += tst-sbrk-static
+
include ../Rules
$(objpfx)libg.a: $(dep-dummy-lib); $(make-dummy-lib)
--- /dev/null
+/* Test sbrk with -pie. */
+
+#include <tst-sbrk.c>
--- /dev/null
+/* Test sbrk with -static. */
+
+#include <tst-sbrk.c>
--- /dev/null
+/* Test sbrk.
+
+ Copyright (C) 2013-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+static int
+do_test (void)
+{
+ /* Try to advance the program break by 1 MiB. */
+ void *one_mib = sbrk (1 * 1024 * 1024);
+ if (one_mib == (void *) -1)
+ {
+ if (errno != ENOMEM)
+ printf ("sbrk (1 MiB) failed, and with wrong errno: %m\n");
+ else
+ printf ("sbrk (1 MiB) failed\n");
+
+ return 1;
+ }
+ else
+ printf ("sbrk at %p\n", one_mib);
+
+ return 0;
+}
+
+/* TODO: fix rlimit bug. 64 MiB (test-skeleton.c's default) should be
+ enough. */
+#define TEST_DATA_LIMIT RLIM_INFINITY
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
#include <hurd.h>
#include <hurd/resource.h>
#include <cthreads.h> /* For `struct mutex'. */
+#include <vm_param.h>
/* Initial maximum size of the data segment (this is arbitrary). */
struct mutex _hurd_brk_lock;
-extern int __data_start, _end;
-weak_extern (__data_start)
-static vm_address_t static_data_start;
+static vm_address_t brk_start;
/* Set the end of the process's data space to INADDR.
rlimit = _hurd_rlimits[RLIMIT_DATA].rlim_cur;
__mutex_unlock (&_hurd_rlimit_lock);
- if (addr - static_data_start > rlimit)
+ if (addr - brk_start > rlimit)
{
/* Need to increase the resource limit. */
errno = ENOMEM;
__mutex_init (&_hurd_brk_lock);
- static_data_start = (vm_address_t) (&__data_start ?: &_end);
+ brk_start = (vm_address_t) BRK_START;
/* If _hurd_brk is already set, don't change it. The assumption is that
it was set in a previous run before something like Emacs's unexec was
called and dumped all the data up to the break at that point. */
- if (_hurd_brk == 0)
- _hurd_brk = (vm_address_t) &_end;
+ if (_hurd_brk == 0) {
+ _hurd_brk = (vm_address_t) BRK_START;
+ }
pagend = round_page (_hurd_brk);
- _hurd_data_end = round_page (static_data_start + DATA_SIZE);
+ _hurd_data_end = round_page (brk_start + DATA_SIZE);
if (pagend < _hurd_data_end)
{
GLIBC_2.2.6 _authenticate F
GLIBC_2.2.6 _dl_mcount_wrapper F
GLIBC_2.2.6 _dl_mcount_wrapper_check F
-GLIBC_2.2.6 _end D 0x0
GLIBC_2.2.6 _environ D 0x4
GLIBC_2.2.6 _exit F
GLIBC_2.2.6 _flushlbf F
--- /dev/null
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _I386_VM_PARAM_H
+#define _I386_VM_PARAM_H
+
+/* Arbitrary start of the brk. This is after usual binary and library mappings. */
+#define BRK_START 0x10000000
+
+#endif /* i386/vm_param.h */