brk.S 2.1 KB

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