aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2018-06-04 19:35:15 +0000
committerMark Johnston <markj@FreeBSD.org>2018-06-04 19:35:15 +0000
commit9f9c9b22ecfd9e87cbe9e1becf946faeb5fbcac6 (patch)
tree24c82053b6f8c91479e5436ee9b61f6a8e6a75ea /lib
parentede2f7731def0fbe8529ab825b19fddb75adfee5 (diff)
downloadsrc-9f9c9b22ecfd9e87cbe9e1becf946faeb5fbcac6.tar.gz
src-9f9c9b22ecfd9e87cbe9e1becf946faeb5fbcac6.zip
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
Notes
Notes: svn path=/head/; revision=334626
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/amd64/Symbol.map1
-rw-r--r--lib/libc/amd64/sys/Makefile.inc4
-rw-r--r--lib/libc/amd64/sys/brk.S82
-rw-r--r--lib/libc/amd64/sys/sbrk.S85
-rw-r--r--lib/libc/arm/Symbol.map1
-rw-r--r--lib/libc/arm/sys/Makefile.inc4
-rw-r--r--lib/libc/arm/sys/brk.S95
-rw-r--r--lib/libc/arm/sys/sbrk.S82
-rw-r--r--lib/libc/i386/Symbol.map1
-rw-r--r--lib/libc/i386/sys/Makefile.inc4
-rw-r--r--lib/libc/i386/sys/brk.S85
-rw-r--r--lib/libc/i386/sys/sbrk.S88
-rw-r--r--lib/libc/mips/Symbol.map1
-rw-r--r--lib/libc/mips/sys/Makefile.inc4
-rw-r--r--lib/libc/mips/sys/brk.S71
-rw-r--r--lib/libc/mips/sys/sbrk.S73
-rw-r--r--lib/libc/powerpc/Symbol.map1
-rw-r--r--lib/libc/powerpc/sys/Makefile.inc2
-rw-r--r--lib/libc/powerpc/sys/brk.S76
-rw-r--r--lib/libc/powerpc/sys/sbrk.S73
-rw-r--r--lib/libc/powerpc64/Symbol.map1
-rw-r--r--lib/libc/powerpc64/sys/Makefile.inc2
-rw-r--r--lib/libc/powerpc64/sys/brk.S74
-rw-r--r--lib/libc/powerpc64/sys/sbrk.S69
-rw-r--r--lib/libc/riscv/sys/Makefile.inc2
-rw-r--r--lib/libc/sparc64/Symbol.map1
-rw-r--r--lib/libc/sparc64/sys/Makefile.inc2
-rw-r--r--lib/libc/sparc64/sys/brk.S65
-rw-r--r--lib/libc/sparc64/sys/sbrk.S71
-rw-r--r--lib/libc/sys/Makefile.inc4
-rw-r--r--lib/libc/sys/brk.27
-rw-r--r--lib/libc/sys/brk.c107
-rw-r--r--lib/libc/tests/sys/Makefile1
-rw-r--r--lib/libc/tests/sys/brk_test.c149
34 files changed, 277 insertions, 1111 deletions
diff --git a/lib/libc/amd64/Symbol.map b/lib/libc/amd64/Symbol.map
index 7405e4c1dede..7b1f7b7301ca 100644
--- a/lib/libc/amd64/Symbol.map
+++ b/lib/libc/amd64/Symbol.map
@@ -63,7 +63,6 @@ FBSDprivate_1.0 {
signalcontext;
__siglongjmp;
_brk;
- _end;
__sys_vfork;
_vfork;
};
diff --git a/lib/libc/amd64/sys/Makefile.inc b/lib/libc/amd64/sys/Makefile.inc
index 750d5a886be3..8463750692c6 100644
--- a/lib/libc/amd64/sys/Makefile.inc
+++ b/lib/libc/amd64/sys/Makefile.inc
@@ -8,7 +8,7 @@ SRCS+= \
amd64_set_fsbase.c \
amd64_set_gsbase.c
-MDASM= vfork.S brk.S cerror.S getcontext.S sbrk.S
+MDASM= vfork.S cerror.S getcontext.S
# Don't generate default code for these syscalls:
-NOASM+= vfork.o
+NOASM+= sbrk.o vfork.o
diff --git a/lib/libc/amd64/sys/brk.S b/lib/libc/amd64/sys/brk.S
deleted file mode 100644
index 60ecd96087e6..000000000000
--- a/lib/libc/amd64/sys/brk.S
+++ /dev/null
@@ -1,82 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)brk.s 5.2 (Berkeley) 12/17/90"
-#endif /* SYSLIBC_SCCS and not lint */
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
- .globl HIDENAME(curbrk)
- .globl HIDENAME(minbrk)
-ENTRY(_brk)
- pushq %rdi
- jmp ok
-END(_brk)
-
-ENTRY(brk)
- pushq %rdi
- movq %rdi,%rax
-#ifdef PIC
- movq PIC_GOT(HIDENAME(minbrk)),%rdx
- cmpq %rax,(%rdx)
-#else
- cmpq %rax,HIDENAME(minbrk)(%rip)
-#endif
- jbe ok
-#ifdef PIC
- movq (%rdx),%rdi
-#else
- movq HIDENAME(minbrk)(%rip),%rdi
-#endif
-ok:
- movq $SYS_break,%rax
- KERNCALL
- jb err
- movq 0(%rsp),%rax
-#ifdef PIC
- movq PIC_GOT(HIDENAME(curbrk)),%rdx
- movq %rax,(%rdx)
-#else
- movq %rax,HIDENAME(curbrk)(%rip)
-#endif
- movq $0,%rax
- popq %rdi
- ret
-err:
- addq $8, %rsp
- jmp HIDENAME(cerror)
-END(brk)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/amd64/sys/sbrk.S b/lib/libc/amd64/sys/sbrk.S
deleted file mode 100644
index 025282ed226e..000000000000
--- a/lib/libc/amd64/sys/sbrk.S
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)sbrk.s 5.1 (Berkeley) 4/23/90"
-#endif /* SYSLIBC_SCCS and not lint */
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
- .globl CNAME(_end)
- .globl HIDENAME(minbrk)
- .globl HIDENAME(curbrk)
-
- .data
-HIDENAME(minbrk): .quad CNAME(_end)
-HIDENAME(curbrk): .quad CNAME(_end)
- .text
-
-ENTRY(sbrk)
- pushq %rdi
- movq %rdi,%rcx
-#ifdef PIC
- movq PIC_GOT(HIDENAME(curbrk)),%rdx
- movq (%rdx),%rax
-#else
- movq HIDENAME(curbrk)(%rip),%rax
-#endif
- testq %rcx,%rcx
- jz back
- addq %rax,%rdi
- mov $SYS_break,%eax
- KERNCALL
- jb err
-#ifdef PIC
- movq PIC_GOT(HIDENAME(curbrk)),%rdx
- movq (%rdx),%rax
-#else
- movq HIDENAME(curbrk)(%rip),%rax
-#endif
- movq 0(%rsp), %rcx
-#ifdef PIC
- addq %rcx,(%rdx)
-#else
- addq %rcx,HIDENAME(curbrk)(%rip)
-#endif
-back:
- addq $8, %rsp
- ret
-err:
- addq $8, %rsp
- jmp HIDENAME(cerror)
-END(sbrk)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/arm/Symbol.map b/lib/libc/arm/Symbol.map
index ad1b1b01ffec..6c3f2765f8b0 100644
--- a/lib/libc/arm/Symbol.map
+++ b/lib/libc/arm/Symbol.map
@@ -58,7 +58,6 @@ FBSDprivate_1.0 {
__sys_vfork;
_vfork;
_brk;
- _end;
_sbrk;
_libc_arm_fpu_present;
diff --git a/lib/libc/arm/sys/Makefile.inc b/lib/libc/arm/sys/Makefile.inc
index 42afe22a5e99..be6a58f8aaf5 100644
--- a/lib/libc/arm/sys/Makefile.inc
+++ b/lib/libc/arm/sys/Makefile.inc
@@ -2,7 +2,7 @@
SRCS+= __vdso_gettc.c
-MDASM= Ovfork.S brk.S cerror.S sbrk.S syscall.S
+MDASM= Ovfork.S cerror.S syscall.S
# Don't generate default code for these syscalls:
-NOASM+= vfork.o
+NOASM+= sbrk.o vfork.o
diff --git a/lib/libc/arm/sys/brk.S b/lib/libc/arm/sys/brk.S
deleted file mode 100644
index bf1b4fb61d7b..000000000000
--- a/lib/libc/arm/sys/brk.S
+++ /dev/null
@@ -1,95 +0,0 @@
-/* $NetBSD: brk.S,v 1.6 2003/08/07 16:42:04 agc Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)brk.s 5.2 (Berkeley) 12/17/90
- */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-#include "SYS.h"
-
- .globl _C_LABEL(_end)
- .globl CURBRK
-
-#ifdef WEAK_ALIAS
-WEAK_ALIAS(brk, _brk)
-#endif
-
- .data
- .align 0
- .globl _C_LABEL(minbrk)
- .type _C_LABEL(minbrk),#object
-_C_LABEL(minbrk):
- .word _C_LABEL(_end)
-
-/*
- * Change the data segment size
- */
-ENTRY(_brk)
- /* Setup the GOT */
- GOT_INIT(r3, .Lgot, .L1)
- GOT_GET(r1, r3, .Lminbrk)
-
- /* Get the minimum allowable brk address */
- ldr r1, [r1]
-
- /*
- * Valid the address specified and set to the minimum
- * if the address is below minbrk.
- */
- cmp r0, r1
- it lt
- movlt r0, r1
- mov r2, r0
- SYSTRAP(break)
- bcs PIC_SYM(CERROR, PLT)
-
-#ifdef PIC
- ldr r1, .Lcurbrk
- ldr r1, [r3, r1]
-#else
- ldr r1, .Lcurbrk
-#endif
- /* Store the new address in curbrk */
- str r2, [r1]
-
- /* Return 0 for success */
- mov r0, #0x00000000
- RET
-
- .align 2
- GOT_INITSYM(.Lgot, .L1)
-.Lminbrk:
- .word PIC_SYM(_C_LABEL(minbrk), GOT)
-.Lcurbrk:
- .word PIC_SYM(CURBRK, GOT)
-END(_brk)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/arm/sys/sbrk.S b/lib/libc/arm/sys/sbrk.S
deleted file mode 100644
index 25622c4a809b..000000000000
--- a/lib/libc/arm/sys/sbrk.S
+++ /dev/null
@@ -1,82 +0,0 @@
-/* $NetBSD: sbrk.S,v 1.7 2003/08/07 16:42:05 agc Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)sbrk.s 5.1 (Berkeley) 4/23/90
- */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-#include "SYS.h"
-
- .globl _C_LABEL(_end)
-
-#ifdef WEAK_ALIAS
-WEAK_ALIAS(sbrk, _sbrk)
-#endif
-
- .data
- .align 0
- .globl CURBRK
- .type CURBRK,#object
-CURBRK:
- .word _C_LABEL(_end)
-
-/*
- * Change the data segment size
- */
-ENTRY(_sbrk)
- /* Setup the GOT */
- GOT_INIT(r3, .Lgot, .L1)
- GOT_GET(r2, r3, .Lcurbrk)
-
- /* Get the current brk address */
- ldr r1, [r2]
-
- /* Calculate new value */
- mov r3, r0
- add r0, r0, r1
- SYSTRAP(break)
- bcs PIC_SYM(CERROR, PLT)
-
- /* Store new curbrk value */
- ldr r0, [r2]
- add r1, r0, r3
- str r1, [r2]
-
- /* Return old curbrk value */
- RET
-
- .align 0
- GOT_INITSYM(.Lgot, .L1)
-.Lcurbrk:
- .word PIC_SYM(CURBRK, GOT)
-END(_sbrk)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/i386/Symbol.map b/lib/libc/i386/Symbol.map
index ca0296b9bc26..cdc2db6bb01a 100644
--- a/lib/libc/i386/Symbol.map
+++ b/lib/libc/i386/Symbol.map
@@ -61,6 +61,5 @@ FBSDprivate_1.0 {
__siglongjmp;
__sys_vfork;
_vfork;
- _end;
_brk;
};
diff --git a/lib/libc/i386/sys/Makefile.inc b/lib/libc/i386/sys/Makefile.inc
index 6c6bebdbdfaa..cf5d390ca094 100644
--- a/lib/libc/i386/sys/Makefile.inc
+++ b/lib/libc/i386/sys/Makefile.inc
@@ -7,9 +7,9 @@ SRCS+= i386_clr_watch.c i386_set_watch.c i386_vm86.c
SRCS+= i386_get_fsbase.c i386_get_gsbase.c i386_get_ioperm.c i386_get_ldt.c \
i386_set_fsbase.c i386_set_gsbase.c i386_set_ioperm.c i386_set_ldt.c
-MDASM= Ovfork.S brk.S cerror.S getcontext.S sbrk.S syscall.S
+MDASM= Ovfork.S cerror.S getcontext.S syscall.S
-NOASM+= vfork.o
+NOASM+= sbrk.o vfork.o
MAN+= i386_get_ioperm.2 i386_get_ldt.2 i386_vm86.2
MAN+= i386_set_watch.3
diff --git a/lib/libc/i386/sys/brk.S b/lib/libc/i386/sys/brk.S
deleted file mode 100644
index 227c819316ba..000000000000
--- a/lib/libc/i386/sys/brk.S
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)brk.s 5.2 (Berkeley) 12/17/90"
-#endif /* SYSLIBC_SCCS and not lint */
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
- .globl HIDENAME(curbrk)
- .globl HIDENAME(minbrk)
-ENTRY(_brk)
- jmp ok
-END(_brk)
-
-ENTRY(brk)
-#ifdef PIC
- movl 4(%esp),%eax
- PIC_PROLOGUE
- movl PIC_GOT(HIDENAME(curbrk)),%edx # set up GOT addressing
- movl PIC_GOT(HIDENAME(minbrk)),%ecx #
- PIC_EPILOGUE
- cmpl %eax,(%ecx)
- jbe ok
- movl (%ecx),%eax
- movl %eax,4(%esp)
-ok:
- mov $SYS_break,%eax
- KERNCALL
- jb HIDENAME(cerror)
- movl 4(%esp),%eax
- movl %eax,(%edx)
- movl $0,%eax
- ret
-
-#else
-
- movl 4(%esp),%eax
- cmpl %eax,HIDENAME(minbrk)
- jbe ok
- movl HIDENAME(minbrk),%eax
- movl %eax,4(%esp)
-ok:
- mov $SYS_break,%eax
- KERNCALL
- jb HIDENAME(cerror)
- movl 4(%esp),%eax
- movl %eax,HIDENAME(curbrk)
- movl $0,%eax
- ret
-#endif
-END(brk)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/i386/sys/sbrk.S b/lib/libc/i386/sys/sbrk.S
deleted file mode 100644
index 56e504fd39cd..000000000000
--- a/lib/libc/i386/sys/sbrk.S
+++ /dev/null
@@ -1,88 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)sbrk.s 5.1 (Berkeley) 4/23/90"
-#endif /* SYSLIBC_SCCS and not lint */
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
- .globl CNAME(_end)
- .globl HIDENAME(minbrk)
- .globl HIDENAME(curbrk)
-
- .data
-HIDENAME(minbrk): .long CNAME(_end)
-HIDENAME(curbrk): .long CNAME(_end)
- .text
-
-ENTRY(sbrk)
-#ifdef PIC
- movl 4(%esp),%ecx
- PIC_PROLOGUE
- movl PIC_GOT(HIDENAME(curbrk)),%edx
- movl (%edx),%eax
- PIC_EPILOGUE
- testl %ecx,%ecx
- jz back
- addl %eax,4(%esp)
- mov $SYS_break,%eax
- KERNCALL
- jb HIDENAME(cerror)
- PIC_PROLOGUE
- movl PIC_GOT(HIDENAME(curbrk)),%edx
- movl (%edx),%eax
- addl %ecx,(%edx)
- PIC_EPILOGUE
-back:
- ret
-
-#else /* !PIC */
-
- movl 4(%esp),%ecx
- movl HIDENAME(curbrk),%eax
- testl %ecx,%ecx
- jz back
- addl %eax,4(%esp)
- mov $SYS_break,%eax
- KERNCALL
- jb HIDENAME(cerror)
- movl HIDENAME(curbrk),%eax
- addl %ecx,HIDENAME(curbrk)
-back:
- ret
-#endif /* PIC */
-END(sbrk)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/mips/Symbol.map b/lib/libc/mips/Symbol.map
index 6663a5f25f5d..4eba7eab57c2 100644
--- a/lib/libc/mips/Symbol.map
+++ b/lib/libc/mips/Symbol.map
@@ -50,7 +50,6 @@ FBSDprivate_1.0 {
__siglongjmp;
__sys_vfork;
_vfork;
- _end;
_brk;
_sbrk;
};
diff --git a/lib/libc/mips/sys/Makefile.inc b/lib/libc/mips/sys/Makefile.inc
index 5e6eec1ee535..d7cc70d01b07 100644
--- a/lib/libc/mips/sys/Makefile.inc
+++ b/lib/libc/mips/sys/Makefile.inc
@@ -2,7 +2,7 @@
SRCS+= trivial-vdso_tc.c
-MDASM= Ovfork.S brk.S cerror.S sbrk.S syscall.S
+MDASM= Ovfork.S cerror.S syscall.S
# Don't generate default code for these syscalls:
-NOASM+= vfork.o
+NOASM+= sbrk.o vfork.o
diff --git a/lib/libc/mips/sys/brk.S b/lib/libc/mips/sys/brk.S
deleted file mode 100644
index 68f0bd45b32a..000000000000
--- a/lib/libc/mips/sys/brk.S
+++ /dev/null
@@ -1,71 +0,0 @@
-/* $NetBSD: brk.S,v 1.16 2003/08/07 16:42:17 agc Exp $ */
-
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Ralph Campbell.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-#include "SYS.h"
-
-#if defined(LIBC_SCCS) && !defined(lint)
- ASMSTR("from: @(#)brk.s 8.1 (Berkeley) 6/4/93")
- ASMSTR("$NetBSD: brk.S,v 1.16 2003/08/07 16:42:17 agc Exp $")
-#endif /* LIBC_SCCS and not lint */
-
- .globl _C_LABEL(minbrk)
- .globl _C_LABEL(__curbrk)
- .globl _C_LABEL(_end)
-
- .data
-_C_LABEL(minbrk):
- PTR_WORD _C_LABEL(_end)
-
- .text
-LEAF(__sys_brk)
- WEAK_ALIAS(brk, __sys_brk)
- WEAK_ALIAS(_brk, __sys_brk)
- PIC_PROLOGUE(__sys_brk)
- PTR_LA v0, _C_LABEL(minbrk)
- PTR_L v0, 0(v0)
- bgeu a0, v0, 1f
- move a0, v0 # dont allow break < minbrk
-1:
- li v0, SYS_break
- syscall
- bne a3, zero, 2f
- PTR_LA t0, _C_LABEL(__curbrk)
- PTR_S a0, 0(t0)
- move v0, zero
- PIC_RETURN()
-2:
- PIC_TAILCALL(__cerror)
-END(__sys_brk)
diff --git a/lib/libc/mips/sys/sbrk.S b/lib/libc/mips/sys/sbrk.S
deleted file mode 100644
index 0989493a6172..000000000000
--- a/lib/libc/mips/sys/sbrk.S
+++ /dev/null
@@ -1,73 +0,0 @@
-/* $NetBSD: sbrk.S,v 1.16 2005/04/22 06:58:01 simonb Exp $ */
-
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Ralph Campbell.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-#include "SYS.h"
-
-#if defined(LIBC_SCCS) && !defined(lint)
- ASMSTR("from: @(#)sbrk.s 8.1 (Berkeley) 6/4/93")
- ASMSTR("$NetBSD: sbrk.S,v 1.16 2005/04/22 06:58:01 simonb Exp $")
-#endif /* LIBC_SCCS and not lint */
-
- .globl _C_LABEL(__curbrk)
- .globl _C_LABEL(_end)
-
- .data
-_C_LABEL(__curbrk):
- PTR_WORD _C_LABEL(_end)
- .text
-
-LEAF(__sys_sbrk)
- WEAK_ALIAS(sbrk, __sys_sbrk)
- WEAK_ALIAS(_sbrk, __sys_sbrk)
- PIC_PROLOGUE(__sys_sbrk)
- PTR_LA t0, _C_LABEL(__curbrk)
- PTR_L t0, 0(t0)
- PTR_ADDU a0, a0, t0
-
- li v0, SYS_break
- syscall
-
- bne a3, zero, 1f
- nop
- move v0, t0 # return old val of curbrk from above
- PTR_LA t0, _C_LABEL(__curbrk)
- PTR_S a0, 0(t0) # save current val of curbrk from above
- PIC_RETURN()
- j ra
-
-1:
- PIC_TAILCALL(__cerror)
-END(__sys_sbrk)
diff --git a/lib/libc/powerpc/Symbol.map b/lib/libc/powerpc/Symbol.map
index ae0da985463b..38f9bf579cfb 100644
--- a/lib/libc/powerpc/Symbol.map
+++ b/lib/libc/powerpc/Symbol.map
@@ -54,5 +54,4 @@ FBSDprivate_1.0 {
signalcontext;
__signalcontext;
__syncicache;
- _end;
};
diff --git a/lib/libc/powerpc/sys/Makefile.inc b/lib/libc/powerpc/sys/Makefile.inc
index f2b5e794120c..ac7f38cb863b 100644
--- a/lib/libc/powerpc/sys/Makefile.inc
+++ b/lib/libc/powerpc/sys/Makefile.inc
@@ -1,3 +1,3 @@
# $FreeBSD$
-MDASM+= brk.S cerror.S sbrk.S
+MDASM+= cerror.S
diff --git a/lib/libc/powerpc/sys/brk.S b/lib/libc/powerpc/sys/brk.S
deleted file mode 100644
index e14be1058b51..000000000000
--- a/lib/libc/powerpc/sys/brk.S
+++ /dev/null
@@ -1,76 +0,0 @@
-/*-
- * Copyright (c) 2002 Peter Grehan.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/* $NetBSD: brk.S,v 1.9 2000/06/26 06:25:43 kleink Exp $ */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
- .globl HIDENAME(curbrk)
- .globl HIDENAME(minbrk)
- .globl CNAME(_end)
-
- .data
-HIDENAME(minbrk):
- .long CNAME(_end)
-
- .text
-
-ENTRY(brk)
-#ifdef PIC
- mflr %r10
- bl _GLOBAL_OFFSET_TABLE_@local-4
- mflr %r9
- mtlr %r10
- lwz %r5,HIDENAME(minbrk)@got(%r9)
- lwz %r6,0(%r5)
-#else
- lis %r5,HIDENAME(minbrk)@ha
- lwz %r6,HIDENAME(minbrk)@l(%r5)
-#endif
- cmplw %r6,%r3 /* if (minbrk <= r3) */
- bgt 0f
- mr %r6,%r3 /* r6 = r3 */
-0:
- mr %r3,%r6 /* new break value */
- li %r0,SYS_break
- sc /* assume, that r5 is kept */
- bso 1f
-#ifdef PIC
- lwz %r7,HIDENAME(curbrk)@got(%r9)
- stw %r6,0(%r7)
-#else
- lis %r7,HIDENAME(curbrk)@ha /* record new break */
- stw %r6,HIDENAME(curbrk)@l(%r7)
-#endif
- blr /* return 0 */
-
-1:
- b PIC_PLT(HIDENAME(cerror))
-END(brk)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/powerpc/sys/sbrk.S b/lib/libc/powerpc/sys/sbrk.S
deleted file mode 100644
index f058d112e863..000000000000
--- a/lib/libc/powerpc/sys/sbrk.S
+++ /dev/null
@@ -1,73 +0,0 @@
-/*-
- * Copyright (c) 2002 Peter Grehan.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/* $NetBSD: sbrk.S,v 1.8 2000/06/26 06:25:44 kleink Exp $ */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
- .globl HIDENAME(curbrk)
- .globl CNAME(_end)
-
- .data
-HIDENAME(curbrk):
- .long CNAME(_end)
-
- .text
-ENTRY(sbrk)
-
-#ifdef PIC
- mflr %r10
- bl _GLOBAL_OFFSET_TABLE_@local-4
- mflr %r5
- mtlr %r10
- lwz %r5,HIDENAME(curbrk)@got(%r5)
- lwz %r6,0(%r5)
-#else
- lis %r5,HIDENAME(curbrk)@ha
- lwz %r6,HIDENAME(curbrk)@l(%r5) /* r6 = old break */
-#endif
- cmpwi %r3,0 /* sbrk(0) - return curbrk */
- beq 1f
- add %r3,%r3,%r6
- mr %r7,%r3 /* r7 = new break */
- li %r0,SYS_break
- sc /* break(new_break) */
- bso 2f
-#ifdef PIC
- stw %r7,0(%r5)
-#else
- stw %r7,HIDENAME(curbrk)@l(%r5) /* record new break */
-#endif
-1:
- mr %r3,%r6 /* set return value */
- blr
-2:
- b PIC_PLT(HIDENAME(cerror))
-END(sbrk)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/powerpc64/Symbol.map b/lib/libc/powerpc64/Symbol.map
index a45cd055157a..c1e2d9ce8e69 100644
--- a/lib/libc/powerpc64/Symbol.map
+++ b/lib/libc/powerpc64/Symbol.map
@@ -50,5 +50,4 @@ FBSDprivate_1.0 {
signalcontext;
__signalcontext;
__syncicache;
- _end;
};
diff --git a/lib/libc/powerpc64/sys/Makefile.inc b/lib/libc/powerpc64/sys/Makefile.inc
index f2b5e794120c..ac7f38cb863b 100644
--- a/lib/libc/powerpc64/sys/Makefile.inc
+++ b/lib/libc/powerpc64/sys/Makefile.inc
@@ -1,3 +1,3 @@
# $FreeBSD$
-MDASM+= brk.S cerror.S sbrk.S
+MDASM+= cerror.S
diff --git a/lib/libc/powerpc64/sys/brk.S b/lib/libc/powerpc64/sys/brk.S
deleted file mode 100644
index cbcecc7abb11..000000000000
--- a/lib/libc/powerpc64/sys/brk.S
+++ /dev/null
@@ -1,74 +0,0 @@
-/*-
- * Copyright (c) 2002 Peter Grehan.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/* $NetBSD: brk.S,v 1.9 2000/06/26 06:25:43 kleink Exp $ */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
- .globl HIDENAME(curbrk)
- .globl HIDENAME(minbrk)
- .globl CNAME(_end)
-
- .data
- .align 3
-HIDENAME(minbrk):
- .llong CNAME(_end)
-
- .text
-
-ENTRY(brk)
- addis %r6,%r2,HIDENAME(minbrk)@toc@ha
- ld %r6,HIDENAME(minbrk)@toc@l(%r6)
- cmpld %r6,%r3 /* if (minbrk <= r3) */
- bgt 0f
- mr %r6,%r3 /* r6 = r3 */
-0:
- mr %r3,%r6 /* new break value */
- li %r0,SYS_break
- sc /* assume, that r5 is kept */
- bso 1f
-
- /* record new break */
- addis %r7,%r2,HIDENAME(curbrk)@toc@ha
- std %r6,HIDENAME(curbrk)@toc@l(%r7)
-
- blr /* return 0 */
-
-1:
- mflr %r0
- std %r0,16(%r1)
- stdu %r1,-48(%r1)
- bl HIDENAME(cerror)
- nop
- ld %r1,0(%r1)
- ld %r0,16(%r1)
- mtlr %r0
- blr
-END(brk)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/powerpc64/sys/sbrk.S b/lib/libc/powerpc64/sys/sbrk.S
deleted file mode 100644
index 4e3b57abf458..000000000000
--- a/lib/libc/powerpc64/sys/sbrk.S
+++ /dev/null
@@ -1,69 +0,0 @@
-/*-
- * Copyright (c) 2002 Peter Grehan.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/* $NetBSD: sbrk.S,v 1.8 2000/06/26 06:25:44 kleink Exp $ */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
- .globl HIDENAME(curbrk)
- .globl CNAME(_end)
-
- .data
- .align 3
-HIDENAME(curbrk):
- .llong CNAME(_end)
-
- .text
-ENTRY(sbrk)
- addis %r5,%r2,HIDENAME(curbrk)@toc@ha
- addi %r5,%r5,HIDENAME(curbrk)@toc@l
- ld %r6,0(%r5) /* r6 = old break */
- cmpdi %r3,0 /* sbrk(0) - return curbrk */
- beq 1f
- add %r3,%r3,%r6
- mr %r7,%r3 /* r7 = new break */
- li %r0,SYS_break
- sc /* break(new_break) */
- bso 2f
- std %r7,0(%r5)
-1:
- mr %r3,%r6 /* set return value */
- blr
-2:
- mflr %r0
- std %r0,16(%r1)
- stdu %r1,-48(%r1)
- bl HIDENAME(cerror)
- nop
- ld %r1,0(%r1)
- ld %r0,16(%r1)
- mtlr %r0
- blr
-END(sbrk)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/riscv/sys/Makefile.inc b/lib/libc/riscv/sys/Makefile.inc
index 34d81b618dc9..0e94e6652645 100644
--- a/lib/libc/riscv/sys/Makefile.inc
+++ b/lib/libc/riscv/sys/Makefile.inc
@@ -7,4 +7,4 @@ MDASM= cerror.S \
vfork.S
# Don't generate default code for these syscalls:
-NOASM+= vfork.o
+NOASM+= sbrk.o vfork.o
diff --git a/lib/libc/sparc64/Symbol.map b/lib/libc/sparc64/Symbol.map
index e81b07753cce..551fae915158 100644
--- a/lib/libc/sparc64/Symbol.map
+++ b/lib/libc/sparc64/Symbol.map
@@ -81,7 +81,6 @@ FBSDprivate_1.0 {
__siglongjmp;
__sys_brk;
_brk;
- _end;
__sys_sbrk;
_sbrk;
__sys_vfork;
diff --git a/lib/libc/sparc64/sys/Makefile.inc b/lib/libc/sparc64/sys/Makefile.inc
index e0f8d24b2e7f..fd6368c4de7a 100644
--- a/lib/libc/sparc64/sys/Makefile.inc
+++ b/lib/libc/sparc64/sys/Makefile.inc
@@ -12,4 +12,4 @@ SRCS+= __sparc_sigtramp_setup.c \
CFLAGS+= -I${LIBC_SRCTOP}/sparc64/fpu
-MDASM+= brk.S cerror.S sbrk.S sigaction1.S
+MDASM+= cerror.S sigaction1.S
diff --git a/lib/libc/sparc64/sys/brk.S b/lib/libc/sparc64/sys/brk.S
deleted file mode 100644
index dc99b2239a32..000000000000
--- a/lib/libc/sparc64/sys/brk.S
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: Header: brk.s,v 1.3 92/06/25 12:56:05 mccanne Exp
- */
-
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)brk.s 8.1 (Berkeley) 6/4/93"
-#if 0
- RCSID("$NetBSD: brk.S,v 1.9 2000/07/25 20:15:40 mycroft Exp $")
-#endif
-#endif /* SYSLIBC_SCCS and not lint */
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
- .globl HIDENAME(curbrk)
- .globl HIDENAME(minbrk)
-
-_SYSENTRY(brk)
- PIC_PROLOGUE(%o3, %o2)
- SET(HIDENAME(minbrk), %o2, %o3)
- ldx [%o3], %o4
- cmp %o4, %o0
- movg %xcc, %o4, %o0
- mov %o0, %o4
- mov SYS_break, %g1
- ta %xcc, ST_SYSCALL
- bcc,a,pt %xcc, 1f
- nop
- ERROR()
-1: SET(HIDENAME(curbrk), %o2, %o3)
- retl
- stx %o4, [%o3]
-_SYSEND(brk)
diff --git a/lib/libc/sparc64/sys/sbrk.S b/lib/libc/sparc64/sys/sbrk.S
deleted file mode 100644
index 671bdc10d6fe..000000000000
--- a/lib/libc/sparc64/sys/sbrk.S
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: Header: brk.s,v 1.3 92/06/25 12:56:05 mccanne Exp
- */
-
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)sbrk.s 8.1 (Berkeley) 6/4/93"
-#if 0
- RCSID("$NetBSD: sbrk.S,v 1.7 2000/07/25 15:14:46 mycroft Exp $")
-#endif
-#endif /* SYSLIBC_SCCS and not lint */
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
- .data
- .globl HIDENAME(curbrk)
- .globl HIDENAME(minbrk)
- .type HIDENAME(curbrk),@object
- .type HIDENAME(minbrk),@object
- .align 8
-HIDENAME(curbrk):
- .xword CNAME(_end)
-HIDENAME(minbrk):
- .xword CNAME(_end)
-
-_SYSENTRY(sbrk)
- PIC_PROLOGUE(%o3, %o2)
- SET(HIDENAME(curbrk), %o2, %o3)
- ldx [%o3], %o4
- add %o4, %o0, %o5
- mov %o5, %o0
- mov SYS_break, %g1
- ta %xcc, ST_SYSCALL
- bcc,a,pt %xcc, 1f
- mov %o4, %o0
- ERROR()
-1: retl
- stx %o5, [%o3]
-_SYSEND(sbrk)
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index 84a9be128082..98a2233bcd9a 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -17,8 +17,7 @@
# While historically machine dependent, all architectures have the following
# declarations in common:
#
-NOASM= break.o \
- exit.o \
+NOASM= exit.o \
getlogin.o \
sstk.o \
yield.o
@@ -45,6 +44,7 @@ SRCS+= getdirentries.c
NOASM+= getdirentries.o
PSEUDO+= _getdirentries.o
+SRCS+= brk.c
SRCS+= pipe.c
SRCS+= vadvise.c
diff --git a/lib/libc/sys/brk.2 b/lib/libc/sys/brk.2
index a5247c9227d9..fc10e2ccf65a 100644
--- a/lib/libc/sys/brk.2
+++ b/lib/libc/sys/brk.2
@@ -28,7 +28,7 @@
.\" @(#)brk.2 8.4 (Berkeley) 5/1/95
.\" $FreeBSD$
.\"
-.Dd May 24, 2018
+.Dd June 2, 2018
.Dt BRK 2
.Os
.Sh NAME
@@ -183,3 +183,8 @@ is sometimes used to monitor heap use by calling with an argument of 0.
The result is unlikely to reflect actual utilization in combination with an
.Xr mmap 2
based malloc.
+.Pp
+.Fn brk
+and
+.Fn sbrk
+are not thread-safe.
diff --git a/lib/libc/sys/brk.c b/lib/libc/sys/brk.c
new file mode 100644
index 000000000000..7e50737d3e18
--- /dev/null
+++ b/lib/libc/sys/brk.c
@@ -0,0 +1,107 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2018 Mark Johnston <markj@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+void *__sys_break(char *nsize);
+
+static uintptr_t curbrk, minbrk;
+static int curbrk_initted;
+
+static int
+initbrk(void)
+{
+ void *newbrk;
+
+ if (!curbrk_initted) {
+ newbrk = __sys_break(NULL);
+ if (newbrk == (void *)-1)
+ return (-1);
+ curbrk = minbrk = (uintptr_t)newbrk;
+ curbrk_initted = 1;
+ }
+ return (0);
+}
+
+static void *
+mvbrk(void *addr)
+{
+ uintptr_t oldbrk;
+
+ if ((uintptr_t)addr < minbrk) {
+ /* Emulate legacy error handling in the syscall. */
+ errno = EINVAL;
+ return ((void *)-1);
+ }
+ if (__sys_break(addr) == (void *)-1)
+ return ((void *)-1);
+ oldbrk = curbrk;
+ curbrk = (uintptr_t)addr;
+ return ((void *)oldbrk);
+}
+
+int
+brk(const void *addr)
+{
+
+ if (initbrk() == -1)
+ return (-1);
+ if ((uintptr_t)addr < minbrk)
+ addr = (void *)minbrk;
+ return (mvbrk(__DECONST(void *, addr)) == (void *)-1 ? -1 : 0);
+}
+
+int
+_brk(const void *addr)
+{
+
+ if (initbrk() == -1)
+ return (-1);
+ return (mvbrk(__DECONST(void *, addr)) == (void *)-1 ? -1 : 0);
+}
+
+void *
+sbrk(intptr_t incr)
+{
+
+ if (initbrk() == -1)
+ return ((void *)-1);
+ if ((incr > 0 && curbrk + incr < curbrk) ||
+ (incr < 0 && curbrk + incr > curbrk)) {
+ /* Emulate legacy error handling in the syscall. */
+ errno = EINVAL;
+ return ((void *)-1);
+ }
+ return (mvbrk((void *)(curbrk + incr)));
+}
diff --git a/lib/libc/tests/sys/Makefile b/lib/libc/tests/sys/Makefile
index 5b1a867bf29a..3abcb9924ee5 100644
--- a/lib/libc/tests/sys/Makefile
+++ b/lib/libc/tests/sys/Makefile
@@ -4,6 +4,7 @@ PACKAGE= tests
.include <bsd.own.mk>
+ATF_TESTS_C+= brk_test
ATF_TESTS_C+= queue_test
# TODO: clone, lwp_create, lwp_ctl, posix_fadvise, recvmmsg,
diff --git a/lib/libc/tests/sys/brk_test.c b/lib/libc/tests/sys/brk_test.c
new file mode 100644
index 000000000000..57b3d605e775
--- /dev/null
+++ b/lib/libc/tests/sys/brk_test.c
@@ -0,0 +1,149 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2018 Mark Johnston <markj@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/mman.h>
+
+#include <errno.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+ATF_TC(brk_basic);
+ATF_TC_HEAD(brk_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Verify basic brk() functionality");
+}
+ATF_TC_BODY(brk_basic, tc)
+{
+ void *oldbrk, *newbrk;
+ int error;
+
+ /* Reset the break. */
+ error = brk(0);
+ ATF_REQUIRE_MSG(error == 0, "brk: %s", strerror(errno));
+
+ oldbrk = sbrk(0);
+ ATF_REQUIRE(oldbrk != (void *)-1);
+
+ /* Try to allocate a page. */
+ error = brk((void *)((intptr_t)oldbrk + PAGE_SIZE * 2));
+ ATF_REQUIRE_MSG(error == 0, "brk: %s", strerror(errno));
+
+ /*
+ * Attempt to set the break below minbrk. This should have no effect.
+ */
+ error = brk((void *)((intptr_t)oldbrk - 1));
+ ATF_REQUIRE_MSG(error == 0, "brk: %s", strerror(errno));
+ newbrk = sbrk(0);
+ ATF_REQUIRE_MSG(newbrk != (void *)-1, "sbrk: %s", strerror(errno));
+ ATF_REQUIRE(newbrk == oldbrk);
+}
+
+ATF_TC(sbrk_basic);
+ATF_TC_HEAD(sbrk_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Verify basic sbrk() functionality");
+}
+ATF_TC_BODY(sbrk_basic, tc)
+{
+ void *newbrk, *oldbrk;
+ int *p;
+
+ oldbrk = sbrk(0);
+ ATF_REQUIRE_MSG(oldbrk != (void *)-1, "sbrk: %s", strerror(errno));
+ p = sbrk(sizeof(*p));
+ *p = 0;
+ ATF_REQUIRE(oldbrk == p);
+
+ newbrk = sbrk(-sizeof(*p));
+ ATF_REQUIRE_MSG(newbrk != (void *)-1, "sbrk: %s", strerror(errno));
+ ATF_REQUIRE(oldbrk == sbrk(0));
+
+ oldbrk = sbrk(PAGE_SIZE * 2 + 1);
+ ATF_REQUIRE_MSG(oldbrk != (void *)-1, "sbrk: %s", strerror(errno));
+ memset(oldbrk, 0, PAGE_SIZE * 2 + 1);
+ newbrk = sbrk(-(PAGE_SIZE * 2 + 1));
+ ATF_REQUIRE_MSG(newbrk != (void *)-1, "sbrk: %s", strerror(errno));
+ ATF_REQUIRE(sbrk(0) == oldbrk);
+}
+
+ATF_TC(mlockfuture);
+ATF_TC_HEAD(mlockfuture, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Verify that mlockall(MCL_FUTURE) applies to the data segment");
+}
+ATF_TC_BODY(mlockfuture, tc)
+{
+ void *oldbrk, *n, *newbrk;
+ int error;
+ char v;
+
+ error = mlockall(MCL_FUTURE);
+ ATF_REQUIRE_MSG(error == 0,
+ "mlockall: %s", strerror(errno));
+
+ /*
+ * Advance the break so that at least one page is added to the data
+ * segment. This page should be automatically faulted in to the address
+ * space.
+ */
+ oldbrk = sbrk(0);
+ ATF_REQUIRE(oldbrk != (void *)-1);
+ newbrk = sbrk(PAGE_SIZE * 2);
+ ATF_REQUIRE(newbrk != (void *)-1);
+
+ n = (void *)(((uintptr_t)oldbrk + PAGE_SIZE) & ~PAGE_SIZE);
+ v = 0;
+ error = mincore(n, PAGE_SIZE, &v);
+ ATF_REQUIRE_MSG(error == 0,
+ "mincore: %s", strerror(errno));
+ ATF_REQUIRE_MSG((v & MINCORE_INCORE) != 0,
+ "unexpected page flags %#x", v);
+
+ error = brk(oldbrk);
+ ATF_REQUIRE(error == 0);
+
+ error = munlockall();
+ ATF_REQUIRE_MSG(error == 0,
+ "munlockall: %s", strerror(errno));
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, brk_basic);
+ ATF_TP_ADD_TC(tp, sbrk_basic);
+ ATF_TP_ADD_TC(tp, mlockfuture);
+
+ return (atf_no_error());
+}