brk.S 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 ___brk_addr
  27. ___brk_addr: .skip 8
  28. .type ___brk_addr,@object
  29. .size ___brk_addr,8
  30. #else
  31. .comm ___brk_addr, 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. #ifdef PROF
  42. .set noat
  43. lda AT, _mcount
  44. jsr AT, (AT), _mcount
  45. .set at
  46. #endif
  47. .prologue 1
  48. /* Save the requested brk across the system call. */
  49. stq $16, 0($30)
  50. ldiq $0, __NR_brk
  51. call_pal 131
  52. ldq $16, 0($30)
  53. /* Be prepared for an OSF-style brk. */
  54. bne $19, $err1
  55. beq $0, $ok
  56. /* Correctly handle the brk(0) query case. */
  57. cmoveq $16, $0, $16
  58. xor $16, $0, $1
  59. bne $1, $err0
  60. /* Update ___brk_addr and return cleanly. */
  61. mov $31, $0
  62. $ok: stq $16, ___brk_addr
  63. addq $30, 8, $30
  64. ret
  65. /* What a horrible way to die. */
  66. $err0: ldi $0, ENOMEM
  67. $err1: addq $30, 8, $30
  68. jmp $31, __syscall_error
  69. .end __brk
  70. .weak brk;
  71. brk = __brk