brk.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. /* __brk is a special syscall under Linux since it never returns an
  16. error. Instead, the error condition is indicated by returning the old
  17. break value (instead of the new, requested one). */
  18. #include <features.h>
  19. #define _ERRNO_H
  20. #include <bits/errno.h>
  21. #include <sys/syscall.h>
  22. #ifdef __PIC__
  23. .section .bss
  24. .align 3
  25. .globl __curbrk
  26. .hidden __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. libc_hidden_def(brk)