mmap64.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. movcc pc, lr
  49. b __syscall_error
  50. .Linval:
  51. mov r0, $-EINVAL
  52. ldmfd sp!, {r4, r5}
  53. b __syscall_error
  54. #else
  55. stmfd sp!, {r4, r5, lr}
  56. ldr r5, [sp, $16]
  57. ldr r4, [sp, $12]
  58. movs ip, r5, lsl $20 @ check that offset is page-aligned
  59. bne .Linval
  60. ldr ip, [sp, $20]
  61. mov r5, r5, lsr $12
  62. orr r5, r5, ip, lsl $20 @ compose page offset
  63. movs ip, ip, lsr $12
  64. bne .Linval @ check for overflow
  65. mov ip, r0
  66. DO_CALL (mmap2)
  67. cmn r0, $4096
  68. ldmccfd sp!, {r4, r5, pc}
  69. cmn r0, $ENOSYS
  70. ldmnefd sp!, {r4, r5, lr}
  71. bne __error
  72. /* The current kernel does not support mmap2. Fall back to plain
  73. mmap if the offset is small enough. */
  74. ldr r5, [sp, $20]
  75. mov r0, ip @ first arg was clobbered
  76. teq r5, $0
  77. ldmeqfd sp!, {r4, r5, lr}
  78. beq HIDDEN_JUMPTARGET(mmap)
  79. .Linval:
  80. mov r0, $-EINVAL
  81. ldmfd sp!, {r4, r5, lr}
  82. b __error
  83. __error:
  84. b __syscall_error
  85. #endif
  86. .size mmap64,.-mmap64
  87. #endif