riscv64: fix linking with binutils 2.40
[uclibc-ng.git] / libc / sysdeps / linux / i386 / brk.c
bloba513886e3831fb67703b934e03b39f8faa213f08
1 /* brk system call for Linux/i386.
2 Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc.
3 Copyright (c) 2015 mirabilos <tg@mirbsd.org>
4 This file is part of uclibc-ng, derived from the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <errno.h>
21 #include <unistd.h>
22 #include <sys/syscall.h>
24 /* This must be initialized data because commons can't have aliases. */
25 void *__curbrk attribute_hidden = 0;
27 int brk(void *addr)
29 void *newbrk;
32 * EBC is used in PIC code, we need to save/restore it manually.
33 * Unfortunately, GCC won't do that for us even if we use con-
34 * straints, and we cannot push it either as ESP clobbers are
35 * silently ignored, but EDX is preserved, so it's scratch space.
37 __asm__("xchgl %%edx,%%ebx"
38 "\n int $0x80"
39 "\n xchgl %%edx,%%ebx"
40 : "=a" (newbrk)
41 : "0" (__NR_brk), "d" (addr)
42 : "cc"
45 __curbrk = newbrk;
47 if (newbrk < addr) {
48 __set_errno(ENOMEM);
49 return -1;
52 return 0;
54 libc_hidden_def(brk)