brk.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Copyright (C) 1997-2017 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. /* __brk is a special syscall under Linux since it never returns an
  15. error. Instead, the error condition is indicated by returning the old
  16. break value (instead of the new, requested one). */
  17. #include <sysdep.h>
  18. #define _ERRNO_H
  19. #include <bits/errno.h>
  20. #ifdef __PIC__
  21. .section .bss
  22. .align 8
  23. .globl __curbrk
  24. __curbrk: .skip 8
  25. .type __curbrk,@object
  26. .size __curbrk,8
  27. #else
  28. .common __curbrk, 8, 8
  29. #endif
  30. .text
  31. ENTRY (__brk)
  32. save %sp, -192, %sp
  33. cfi_def_cfa_register(%fp)
  34. cfi_window_save
  35. cfi_register(%o7, %i7)
  36. #ifdef __PIC__
  37. SETUP_PIC_REG(l7)
  38. #endif
  39. LOADSYSCALL(brk)
  40. mov %i0, %o0
  41. ta 0x6d
  42. /* All the ways we can fail... */
  43. bcs,pn %xcc, .Lerr1
  44. nop
  45. brz,pt %i0, .Lok
  46. subcc %i0, %o0, %g0
  47. bne,pn %xcc, .Lerr0
  48. nop
  49. /* Update __curbrk and return cleanly. */
  50. .Lok:
  51. #ifndef __PIC__
  52. sethi %hi(__curbrk), %g1
  53. or %g1, %lo(__curbrk), %g1
  54. #else
  55. sethi %gdop_hix22(__curbrk), %g1
  56. xor %g1, %gdop_lox10(__curbrk), %g1
  57. ldx [%l7 + %g1], %g1, %gdop(__curbrk)
  58. #endif
  59. stx %o0, [%g1]
  60. mov %g0, %i0
  61. /* Don't use "ret" cause the preprocessor will eat it. */
  62. jmpl %i7+8, %g0
  63. restore
  64. /* What a horrible way to die. */
  65. .Lerr0: set ENOMEM, %o0
  66. .Lerr1:
  67. #ifndef _LIBC_REENTRANT
  68. #ifndef __PIC__
  69. sethi %hi(errno), %g1
  70. or %g1, %lo(errno), %g1
  71. #else
  72. sethi %gdop_hix22(errno), %g1
  73. xor %g1, %gdop_lox10(errno), %g1
  74. ldx [%l7 + %g1], %g1, %gdop(errno)
  75. #endif
  76. st %o0, [%g1]
  77. #else
  78. call HIDDEN_JUMPTARGET(__errno_location)
  79. mov %o0,%l1
  80. st %l1, [%o0]
  81. #endif
  82. sub %g0, 1, %i0
  83. jmpl %i7+8, %g0
  84. restore
  85. END (__brk)
  86. weak_alias (__brk, brk)
  87. libc_hidden_def(brk)