brk.S 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Brendan Kehoe <brendan@zen.org>, 1993.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. /* __brk is a special syscall under Linux since it never returns an
  17. error. Instead, the error condition is indicated by returning the old
  18. break value (instead of the new, requested one). */
  19. #include <features.h>
  20. #define _ERRNO_H
  21. #include <bits/errno.h>
  22. #include <sys/syscall.h>
  23. #ifdef __PIC__
  24. .section .bss
  25. .align 3
  26. .globl __curbrk
  27. __curbrk: .skip 8
  28. .type __curbrk,@object
  29. .size __curbrk,8
  30. #else
  31. .comm __curbrk, 8
  32. #endif
  33. .text
  34. .globl __brk;
  35. .hidden __brk;
  36. .align 3;
  37. .ent __brk , 0;
  38. __brk:
  39. .frame $30 , 8 , $26
  40. ldgp $29, 0($27)
  41. subq $30, 8, $30
  42. .prologue 1
  43. /* Save the requested brk across the system call. */
  44. stq $16, 0($30)
  45. ldiq $0, __NR_brk
  46. call_pal 131
  47. ldq $16, 0($30)
  48. /* Be prepared for an OSF-style brk. */
  49. bne $19, $err1
  50. beq $0, $ok
  51. /* Correctly handle the brk(0) query case. */
  52. cmoveq $16, $0, $16
  53. xor $16, $0, $1
  54. bne $1, $err0
  55. /* Update __curbrk and return cleanly. */
  56. mov $31, $0
  57. $ok: stq $16, __curbrk
  58. addq $30, 8, $30
  59. ret
  60. /* What a horrible way to die. */
  61. $err0: ldi $0, ENOMEM
  62. $err1: addq $30, 8, $30
  63. jmp $31, __syscall_error
  64. .end __brk
  65. .weak brk;
  66. brk = __brk