]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Reimplement brk() and sbrk() to avoid the use of _end.
authormarkj <markj@FreeBSD.org>
Mon, 4 Jun 2018 19:35:15 +0000 (19:35 +0000)
committermarkj <markj@FreeBSD.org>
Mon, 4 Jun 2018 19:35:15 +0000 (19:35 +0000)
commit9d9fd255d646b6c389fa347cb633c665c4485aa4
tree24c82053b6f8c91479e5436ee9b61f6a8e6a75ea
parent9848d41989ddef0b82792d4db162fd13ea666c95
Reimplement brk() and sbrk() to avoid the use of _end.

Previously, libc.so would initialize its notion of the break address
using _end, a special symbol emitted by the static linker following
the bss section.  Compatibility issues between lld and ld.bfd could
cause the wrong definition of _end (libc.so's definition rather than
that of the executable) to be used, breaking the brk()/sbrk()
interface.

Avoid this problem and future interoperability issues by simply not
relying on _end.  Instead, modify the break() system call to return
the kernel's view of the current break address, and have libc
initialize its state using an extra syscall upon the first use of the
interface.  As a side effect, this appears to fix brk()/sbrk() usage
in executables run with rtld direct exec, since the kernel and libc.so
no longer maintain separate views of the process' break address.

PR: 228574
Reviewed by: kib (previous version)
MFC after: 2 months
Differential Revision: https://reviews.freebsd.org/D15663
37 files changed:
lib/libc/amd64/Symbol.map
lib/libc/amd64/sys/Makefile.inc
lib/libc/amd64/sys/brk.S [deleted file]
lib/libc/amd64/sys/sbrk.S [deleted file]
lib/libc/arm/Symbol.map
lib/libc/arm/sys/Makefile.inc
lib/libc/arm/sys/brk.S [deleted file]
lib/libc/arm/sys/sbrk.S [deleted file]
lib/libc/i386/Symbol.map
lib/libc/i386/sys/Makefile.inc
lib/libc/i386/sys/brk.S [deleted file]
lib/libc/i386/sys/sbrk.S [deleted file]
lib/libc/mips/Symbol.map
lib/libc/mips/sys/Makefile.inc
lib/libc/mips/sys/brk.S [deleted file]
lib/libc/mips/sys/sbrk.S [deleted file]
lib/libc/powerpc/Symbol.map
lib/libc/powerpc/sys/Makefile.inc
lib/libc/powerpc/sys/brk.S [deleted file]
lib/libc/powerpc/sys/sbrk.S [deleted file]
lib/libc/powerpc64/Symbol.map
lib/libc/powerpc64/sys/Makefile.inc
lib/libc/powerpc64/sys/brk.S [deleted file]
lib/libc/powerpc64/sys/sbrk.S [deleted file]
lib/libc/riscv/sys/Makefile.inc
lib/libc/sparc64/Symbol.map
lib/libc/sparc64/sys/Makefile.inc
lib/libc/sparc64/sys/brk.S [deleted file]
lib/libc/sparc64/sys/sbrk.S [deleted file]
lib/libc/sys/Makefile.inc
lib/libc/sys/brk.2
lib/libc/sys/brk.c [new file with mode: 0644]
lib/libc/tests/sys/Makefile
lib/libc/tests/sys/brk_test.c [new file with mode: 0644]
sys/compat/freebsd32/syscalls.master
sys/kern/syscalls.master
sys/vm/vm_unix.c