0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. From 71f14902256e3c3529710b713e1ea43100bf4c40 Mon Sep 17 00:00:00 2001
  2. From: Khem Raj <raj.khem@gmail.com>
  3. Date: Sat, 17 Dec 2022 08:37:46 -0800
  4. Subject: [PATCH 2/2] linux-user: Replace use of lfs64 related functions and
  5. macros
  6. Builds defines -D_FILE_OFFSET_BITS=64 which makes the original functions
  7. anf macros behave same as their 64 suffixed counterparts. This also
  8. helps in compiling with latest musl C library, where these macros and
  9. functions are no more available under _GNU_SOURCE feature macro
  10. Upstream-Status: Submitted [https://lists.gnu.org/archive/html/qemu-devel/2022-12/msg02841.html]
  11. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  12. Cc: Laurent Vivier <laurent@vivier.eu>
  13. ---
  14. linux-user/syscall.c | 153 +++++++++++--------------------------------
  15. 1 file changed, 39 insertions(+), 114 deletions(-)
  16. diff --git a/linux-user/syscall.c b/linux-user/syscall.c
  17. index 1f8c10f8ef..30d83ed162 100644
  18. --- a/linux-user/syscall.c
  19. +++ b/linux-user/syscall.c
  20. @@ -795,8 +795,8 @@ safe_syscall6(ssize_t, copy_file_range, int, infd, loff_t *, pinoff,
  21. */
  22. #define safe_ioctl(...) safe_syscall(__NR_ioctl, __VA_ARGS__)
  23. /* Similarly for fcntl. Note that callers must always:
  24. - * pass the F_GETLK64 etc constants rather than the unsuffixed F_GETLK
  25. - * use the flock64 struct rather than unsuffixed flock
  26. + * pass the F_GETLK etc constants rather than the unsuffixed F_GETLK
  27. + * use the flock struct rather than unsuffixed flock
  28. * This will then work and use a 64-bit offset for both 32-bit and 64-bit hosts.
  29. */
  30. #ifdef __NR_fcntl64
  31. @@ -6797,13 +6797,13 @@ static int target_to_host_fcntl_cmd(int cmd)
  32. ret = cmd;
  33. break;
  34. case TARGET_F_GETLK:
  35. - ret = F_GETLK64;
  36. + ret = F_GETLK;
  37. break;
  38. case TARGET_F_SETLK:
  39. - ret = F_SETLK64;
  40. + ret = F_SETLK;
  41. break;
  42. case TARGET_F_SETLKW:
  43. - ret = F_SETLKW64;
  44. + ret = F_SETLKW;
  45. break;
  46. case TARGET_F_GETOWN:
  47. ret = F_GETOWN;
  48. @@ -6817,17 +6817,6 @@ static int target_to_host_fcntl_cmd(int cmd)
  49. case TARGET_F_SETSIG:
  50. ret = F_SETSIG;
  51. break;
  52. -#if TARGET_ABI_BITS == 32
  53. - case TARGET_F_GETLK64:
  54. - ret = F_GETLK64;
  55. - break;
  56. - case TARGET_F_SETLK64:
  57. - ret = F_SETLK64;
  58. - break;
  59. - case TARGET_F_SETLKW64:
  60. - ret = F_SETLKW64;
  61. - break;
  62. -#endif
  63. case TARGET_F_SETLEASE:
  64. ret = F_SETLEASE;
  65. break;
  66. @@ -6879,8 +6868,8 @@ static int target_to_host_fcntl_cmd(int cmd)
  67. * them to 5, 6 and 7 before making the syscall(). Since we make the
  68. * syscall directly, adjust to what is supported by the kernel.
  69. */
  70. - if (ret >= F_GETLK64 && ret <= F_SETLKW64) {
  71. - ret -= F_GETLK64 - 5;
  72. + if (ret >= F_GETLK && ret <= F_SETLKW) {
  73. + ret -= F_GETLK - 5;
  74. }
  75. #endif
  76. @@ -6913,55 +6902,11 @@ static int host_to_target_flock(int type)
  77. return type;
  78. }
  79. -static inline abi_long copy_from_user_flock(struct flock64 *fl,
  80. - abi_ulong target_flock_addr)
  81. -{
  82. - struct target_flock *target_fl;
  83. - int l_type;
  84. -
  85. - if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) {
  86. - return -TARGET_EFAULT;
  87. - }
  88. -
  89. - __get_user(l_type, &target_fl->l_type);
  90. - l_type = target_to_host_flock(l_type);
  91. - if (l_type < 0) {
  92. - return l_type;
  93. - }
  94. - fl->l_type = l_type;
  95. - __get_user(fl->l_whence, &target_fl->l_whence);
  96. - __get_user(fl->l_start, &target_fl->l_start);
  97. - __get_user(fl->l_len, &target_fl->l_len);
  98. - __get_user(fl->l_pid, &target_fl->l_pid);
  99. - unlock_user_struct(target_fl, target_flock_addr, 0);
  100. - return 0;
  101. -}
  102. -
  103. -static inline abi_long copy_to_user_flock(abi_ulong target_flock_addr,
  104. - const struct flock64 *fl)
  105. -{
  106. - struct target_flock *target_fl;
  107. - short l_type;
  108. -
  109. - if (!lock_user_struct(VERIFY_WRITE, target_fl, target_flock_addr, 0)) {
  110. - return -TARGET_EFAULT;
  111. - }
  112. -
  113. - l_type = host_to_target_flock(fl->l_type);
  114. - __put_user(l_type, &target_fl->l_type);
  115. - __put_user(fl->l_whence, &target_fl->l_whence);
  116. - __put_user(fl->l_start, &target_fl->l_start);
  117. - __put_user(fl->l_len, &target_fl->l_len);
  118. - __put_user(fl->l_pid, &target_fl->l_pid);
  119. - unlock_user_struct(target_fl, target_flock_addr, 1);
  120. - return 0;
  121. -}
  122. -
  123. -typedef abi_long from_flock64_fn(struct flock64 *fl, abi_ulong target_addr);
  124. -typedef abi_long to_flock64_fn(abi_ulong target_addr, const struct flock64 *fl);
  125. +typedef abi_long from_flock_fn(struct flock *fl, abi_ulong target_addr);
  126. +typedef abi_long to_flock_fn(abi_ulong target_addr, const struct flock *fl);
  127. #if defined(TARGET_ARM) && TARGET_ABI_BITS == 32
  128. -struct target_oabi_flock64 {
  129. +struct target_oabi_flock {
  130. abi_short l_type;
  131. abi_short l_whence;
  132. abi_llong l_start;
  133. @@ -6969,10 +6914,10 @@ struct target_oabi_flock64 {
  134. abi_int l_pid;
  135. } QEMU_PACKED;
  136. -static inline abi_long copy_from_user_oabi_flock64(struct flock64 *fl,
  137. +static inline abi_long copy_from_user_oabi_flock(struct flock *fl,
  138. abi_ulong target_flock_addr)
  139. {
  140. - struct target_oabi_flock64 *target_fl;
  141. + struct target_oabi_flock *target_fl;
  142. int l_type;
  143. if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) {
  144. @@ -6993,10 +6938,10 @@ static inline abi_long copy_from_user_oabi_flock64(struct flock64 *fl,
  145. return 0;
  146. }
  147. -static inline abi_long copy_to_user_oabi_flock64(abi_ulong target_flock_addr,
  148. - const struct flock64 *fl)
  149. +static inline abi_long copy_to_user_oabi_flock(abi_ulong target_flock_addr,
  150. + const struct flock *fl)
  151. {
  152. - struct target_oabi_flock64 *target_fl;
  153. + struct target_oabi_flock *target_fl;
  154. short l_type;
  155. if (!lock_user_struct(VERIFY_WRITE, target_fl, target_flock_addr, 0)) {
  156. @@ -7014,10 +6959,10 @@ static inline abi_long copy_to_user_oabi_flock64(abi_ulong target_flock_addr,
  157. }
  158. #endif
  159. -static inline abi_long copy_from_user_flock64(struct flock64 *fl,
  160. +static inline abi_long copy_from_user_flock(struct flock *fl,
  161. abi_ulong target_flock_addr)
  162. {
  163. - struct target_flock64 *target_fl;
  164. + struct target_flock *target_fl;
  165. int l_type;
  166. if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) {
  167. @@ -7038,10 +6983,10 @@ static inline abi_long copy_from_user_flock64(struct flock64 *fl,
  168. return 0;
  169. }
  170. -static inline abi_long copy_to_user_flock64(abi_ulong target_flock_addr,
  171. - const struct flock64 *fl)
  172. +static inline abi_long copy_to_user_flock(abi_ulong target_flock_addr,
  173. + const struct flock *fl)
  174. {
  175. - struct target_flock64 *target_fl;
  176. + struct target_flock *target_fl;
  177. short l_type;
  178. if (!lock_user_struct(VERIFY_WRITE, target_fl, target_flock_addr, 0)) {
  179. @@ -7060,7 +7005,7 @@ static inline abi_long copy_to_user_flock64(abi_ulong target_flock_addr,
  180. static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
  181. {
  182. - struct flock64 fl64;
  183. + struct flock fl64;
  184. #ifdef F_GETOWN_EX
  185. struct f_owner_ex fox;
  186. struct target_f_owner_ex *target_fox;
  187. @@ -7073,6 +7018,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
  188. switch(cmd) {
  189. case TARGET_F_GETLK:
  190. + case TARGET_F_OFD_GETLK:
  191. ret = copy_from_user_flock(&fl64, arg);
  192. if (ret) {
  193. return ret;
  194. @@ -7082,32 +7028,11 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
  195. ret = copy_to_user_flock(arg, &fl64);
  196. }
  197. break;
  198. -
  199. case TARGET_F_SETLK:
  200. case TARGET_F_SETLKW:
  201. - ret = copy_from_user_flock(&fl64, arg);
  202. - if (ret) {
  203. - return ret;
  204. - }
  205. - ret = get_errno(safe_fcntl(fd, host_cmd, &fl64));
  206. - break;
  207. -
  208. - case TARGET_F_GETLK64:
  209. - case TARGET_F_OFD_GETLK:
  210. - ret = copy_from_user_flock64(&fl64, arg);
  211. - if (ret) {
  212. - return ret;
  213. - }
  214. - ret = get_errno(safe_fcntl(fd, host_cmd, &fl64));
  215. - if (ret == 0) {
  216. - ret = copy_to_user_flock64(arg, &fl64);
  217. - }
  218. - break;
  219. - case TARGET_F_SETLK64:
  220. - case TARGET_F_SETLKW64:
  221. case TARGET_F_OFD_SETLK:
  222. case TARGET_F_OFD_SETLKW:
  223. - ret = copy_from_user_flock64(&fl64, arg);
  224. + ret = copy_from_user_flock(&fl64, arg);
  225. if (ret) {
  226. return ret;
  227. }
  228. @@ -7332,7 +7257,7 @@ static inline abi_long target_truncate64(CPUArchState *cpu_env, const char *arg1
  229. arg2 = arg3;
  230. arg3 = arg4;
  231. }
  232. - return get_errno(truncate64(arg1, target_offset64(arg2, arg3)));
  233. + return get_errno(truncate(arg1, target_offset64(arg2, arg3)));
  234. }
  235. #endif
  236. @@ -7346,7 +7271,7 @@ static inline abi_long target_ftruncate64(CPUArchState *cpu_env, abi_long arg1,
  237. arg2 = arg3;
  238. arg3 = arg4;
  239. }
  240. - return get_errno(ftruncate64(arg1, target_offset64(arg2, arg3)));
  241. + return get_errno(ftruncate(arg1, target_offset64(arg2, arg3)));
  242. }
  243. #endif
  244. @@ -8452,7 +8377,7 @@ static int do_getdents(abi_long dirfd, abi_long arg2, abi_long count)
  245. void *tdirp;
  246. int hlen, hoff, toff;
  247. int hreclen, treclen;
  248. - off64_t prev_diroff = 0;
  249. + off_t prev_diroff = 0;
  250. hdirp = g_try_malloc(count);
  251. if (!hdirp) {
  252. @@ -8505,7 +8430,7 @@ static int do_getdents(abi_long dirfd, abi_long arg2, abi_long count)
  253. * Return what we have, resetting the file pointer to the
  254. * location of the first record not returned.
  255. */
  256. - lseek64(dirfd, prev_diroff, SEEK_SET);
  257. + lseek(dirfd, prev_diroff, SEEK_SET);
  258. break;
  259. }
  260. @@ -8539,7 +8464,7 @@ static int do_getdents64(abi_long dirfd, abi_long arg2, abi_long count)
  261. void *tdirp;
  262. int hlen, hoff, toff;
  263. int hreclen, treclen;
  264. - off64_t prev_diroff = 0;
  265. + off_t prev_diroff = 0;
  266. hdirp = g_try_malloc(count);
  267. if (!hdirp) {
  268. @@ -8581,7 +8506,7 @@ static int do_getdents64(abi_long dirfd, abi_long arg2, abi_long count)
  269. * Return what we have, resetting the file pointer to the
  270. * location of the first record not returned.
  271. */
  272. - lseek64(dirfd, prev_diroff, SEEK_SET);
  273. + lseek(dirfd, prev_diroff, SEEK_SET);
  274. break;
  275. }
  276. @@ -11114,7 +11039,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
  277. return -TARGET_EFAULT;
  278. }
  279. }
  280. - ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5)));
  281. + ret = get_errno(pread(arg1, p, arg3, target_offset64(arg4, arg5)));
  282. unlock_user(p, arg2, ret);
  283. return ret;
  284. case TARGET_NR_pwrite64:
  285. @@ -11131,7 +11056,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
  286. return -TARGET_EFAULT;
  287. }
  288. }
  289. - ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5)));
  290. + ret = get_errno(pwrite(arg1, p, arg3, target_offset64(arg4, arg5)));
  291. unlock_user(p, arg2, 0);
  292. return ret;
  293. #endif
  294. @@ -11954,14 +11879,14 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
  295. case TARGET_NR_fcntl64:
  296. {
  297. int cmd;
  298. - struct flock64 fl;
  299. - from_flock64_fn *copyfrom = copy_from_user_flock64;
  300. - to_flock64_fn *copyto = copy_to_user_flock64;
  301. + struct flock fl;
  302. + from_flock_fn *copyfrom = copy_from_user_flock;
  303. + to_flock_fn *copyto = copy_to_user_flock;
  304. #ifdef TARGET_ARM
  305. if (!cpu_env->eabi) {
  306. - copyfrom = copy_from_user_oabi_flock64;
  307. - copyto = copy_to_user_oabi_flock64;
  308. + copyfrom = copy_from_user_oabi_flock;
  309. + copyto = copy_to_user_oabi_flock;
  310. }
  311. #endif
  312. @@ -11971,7 +11896,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
  313. }
  314. switch(arg2) {
  315. - case TARGET_F_GETLK64:
  316. + case TARGET_F_GETLK:
  317. ret = copyfrom(&fl, arg3);
  318. if (ret) {
  319. break;
  320. @@ -11982,8 +11907,8 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
  321. }
  322. break;
  323. - case TARGET_F_SETLK64:
  324. - case TARGET_F_SETLKW64:
  325. + case TARGET_F_SETLK:
  326. + case TARGET_F_SETLKW:
  327. ret = copyfrom(&fl, arg3);
  328. if (ret) {
  329. break;
  330. --
  331. 2.39.0