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. .hidden __curbrk
  28. __curbrk: .skip 8
  29. .type __curbrk,@object
  30. .size __curbrk,8
  31. #else
  32. .comm __curbrk, 8
  33. #endif
  34. .text
  35. .globl 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. libc_hidden_def(brk)