Wed May 29 00:57:37 1996 David Mosberger-Tang <davidm@azstarnet.com>
[platform/upstream/glibc.git] / sysdeps / unix / sysv / linux / alpha / brk.S
1 /* Copyright (C) 1993, 1995 Free Software Foundation, Inc.
2    Contributed by Brendan Kehoe (brendan@zen.org).
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB.  If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA.  */
18
19 /* __brk is a special syscall under Linux since it never returns an
20 error.  Instead, the error condition is indicated by returning the old
21 break value (instead of the new, requested one).  */
22
23 #include <sysdep.h>
24 #include <errnos.h>
25
26 .comm __curbrk, 8
27
28         .text
29 LEAF(__brk, 0)
30         ldgp    gp, 0(t12)
31         .prologue 1
32
33         ldi     v0, __NR_brk
34         call_pal PAL_callsys
35
36         /* Correctly handle the brk(0) query case.  */
37         cmoveq  a0, v0, a0
38
39         subq    a0, v0, t0
40         bne     t0, error
41
42         /* Update __curbrk and return cleanly.  */
43         stq     a0, __curbrk
44         mov     zero, v0
45         ret
46
47         /* What a horrible way to die.  */
48 error:  ldi     v0, ENOMEM
49         jmp     zero, syscall_error
50
51         END(__brk)
52
53 weak_alias (__brk, brk)