1 /*
2  * posix_fadvise64() for uClibc
3  * http://www.opengroup.org/onlinepubs/009695399/functions/posix_fadvise.html
4  *
5  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
6  *
7  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8  */
9 
10 #include <_lfs_64.h>
11 #include <sys/syscall.h>
12 #include <bits/wordsize.h>
13 
14 #ifdef __NR_arm_fadvise64_64
15 # define __NR_fadvise64_64 __NR_arm_fadvise64_64
16 #endif
17 
18 #if defined __NR_fadvise64_64 && __WORDSIZE == 32
19 # include <fcntl.h>
20 # include <endian.h>
21 
posix_fadvise64(int fd,off64_t offset,off64_t len,int advice)22 int posix_fadvise64(int fd, off64_t offset, off64_t len, int advice)
23 {
24 	int ret;
25 	INTERNAL_SYSCALL_DECL (err);
26 	/* ARM has always been funky. */
27 #if defined (__arm__) || defined (__nds32__) || defined (__csky__) || \
28     (defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) && (defined(__powerpc__) || defined(__xtensa__)))
29 	/* arch with 64-bit data in even reg alignment #1: [powerpc/xtensa]
30 	 * custom syscall handler (rearranges @advice to avoid register hole punch) */
31 	ret = INTERNAL_SYSCALL (fadvise64_64, err, 6, fd, advice,
32 			OFF64_HI_LO (offset), OFF64_HI_LO (len));
33 #elif defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
34 	/* arch with 64-bit data in even reg alignment #2: [arcv2/others-in-future]
35 	 * stock syscall handler in kernel (reg hole punched) */
36 	ret = INTERNAL_SYSCALL (fadvise64_64, err, 7, fd, 0,
37 			OFF64_HI_LO (offset), OFF64_HI_LO (len),
38 			advice);
39 # else
40 	ret = INTERNAL_SYSCALL (fadvise64_64, err, 6, fd,
41 			OFF64_HI_LO (offset), OFF64_HI_LO (len),
42 			advice);
43 # endif
44 	if (INTERNAL_SYSCALL_ERROR_P (ret, err))
45 		return INTERNAL_SYSCALL_ERRNO (ret, err);
46 	return 0;
47 }
48 #endif
49