mmap64.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Copyright (C) 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <features.h>
  16. #define _ERRNO_H
  17. #include <bits/errno.h>
  18. #include <sys/syscall.h>
  19. #if defined __UCLIBC_HAS_LFS__ && defined __NR_mmap2
  20. /* The mmap2 system call takes six arguments, all in registers. */
  21. .text
  22. .global mmap64
  23. .type mmap64,%function
  24. .align 2
  25. mmap64:
  26. #ifdef __ARM_EABI__
  27. #ifdef __ARMEB__
  28. # define LOW_OFFSET 8 + 4
  29. /* The initial + 4 is for the stack postdecrement. */
  30. # define HIGH_OFFSET 4 + 8 + 0
  31. #else
  32. # define LOW_OFFSET 8 + 0
  33. # define HIGH_OFFSET 4 + 8 + 4
  34. #endif
  35. ldr ip, [sp, $LOW_OFFSET]
  36. str r5, [sp, #-4]!
  37. ldr r5, [sp, $HIGH_OFFSET]
  38. str r4, [sp, #-4]!
  39. movs r4, ip, lsl $20 @ check that offset is page-aligned
  40. mov ip, ip, lsr $12
  41. moveqs r4, r5, lsr $12 @ check for overflow
  42. bne .Linval
  43. ldr r4, [sp, $8] @ load fd
  44. orr r5, ip, r5, lsl $20 @ compose page offset
  45. DO_CALL (mmap2)
  46. cmn r0, $4096
  47. ldmfd sp!, {r4, r5}
  48. #if defined(__USE_BX__)
  49. bxcc lr
  50. #else
  51. movcc pc, lr
  52. #endif
  53. b __syscall_error
  54. .Linval:
  55. mov r0, $-EINVAL
  56. ldmfd sp!, {r4, r5}
  57. b __syscall_error
  58. #else
  59. stmfd sp!, {r4, r5, lr}
  60. ldr r5, [sp, $16]
  61. ldr r4, [sp, $12]
  62. movs ip, r5, lsl $20 @ check that offset is page-aligned
  63. bne .Linval
  64. ldr ip, [sp, $20]
  65. mov r5, r5, lsr $12
  66. orr r5, r5, ip, lsl $20 @ compose page offset
  67. movs ip, ip, lsr $12
  68. bne .Linval @ check for overflow
  69. mov ip, r0
  70. DO_CALL (mmap2)
  71. cmn r0, $4096
  72. ldmccfd sp!, {r4, r5, pc}
  73. cmn r0, $ENOSYS
  74. ldmnefd sp!, {r4, r5, lr}
  75. bne __error
  76. /* The current kernel does not support mmap2. Fall back to plain
  77. mmap if the offset is small enough. */
  78. ldr r5, [sp, $20]
  79. mov r0, ip @ first arg was clobbered
  80. teq r5, $0
  81. ldmeqfd sp!, {r4, r5, lr}
  82. beq HIDDEN_JUMPTARGET(mmap)
  83. .Linval:
  84. mov r0, $-EINVAL
  85. ldmfd sp!, {r4, r5, lr}
  86. b __error
  87. __error:
  88. b __syscall_error
  89. #endif
  90. .size mmap64,.-mmap64
  91. #endif