brk.S 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. .align 3;
  36. .ent __brk , 0;
  37. __brk:
  38. .frame $30 , 8 , $26
  39. ldgp $29, 0($27)
  40. subq $30, 8, $30
  41. .prologue 1
  42. /* Save the requested brk across the system call. */
  43. stq $16, 0($30)
  44. ldiq $0, __NR_brk
  45. call_pal 131
  46. ldq $16, 0($30)
  47. /* Be prepared for an OSF-style brk. */
  48. bne $19, $err1
  49. beq $0, $ok
  50. /* Correctly handle the brk(0) query case. */
  51. cmoveq $16, $0, $16
  52. xor $16, $0, $1
  53. bne $1, $err0
  54. /* Update __curbrk and return cleanly. */
  55. mov $31, $0
  56. $ok: stq $16, __curbrk
  57. addq $30, 8, $30
  58. ret
  59. /* What a horrible way to die. */
  60. $err0: ldi $0, ENOMEM
  61. $err1: addq $30, 8, $30
  62. jmp $31, __syscall_error
  63. .end __brk
  64. .weak brk;
  65. brk = __brk