1 /* 2 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com> 3 * Copyright (c) 2016-2017 The strace developers. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include "tests.h" 30 #include <asm/unistd.h> 31 32 #ifdef HAVE_READAHEAD 33 /* Check for glibc readahead argument passing bugs. */ 34 # ifdef __GLIBC__ 35 /* 36 * glibc < 2.8 had an incorrect order of higher and lower parts of offset, 37 * see https://sourceware.org/bugzilla/show_bug.cgi?id=5208 38 */ 39 # if !(defined __GLIBC_MINOR__ && \ 40 (__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 8) 41 # undef HAVE_READAHEAD 42 # endif /* glibc < 2.8 */ 43 /* 44 * glibc < 2.25 had an incorrect implementation on mips n64, 45 * see https://sourceware.org/bugzilla/show_bug.cgi?id=21026 46 */ 47 # if defined LINUX_MIPSN64 && !(defined __GLIBC_MINOR__ && \ 48 (__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 25) 49 # undef HAVE_READAHEAD 50 # endif /* LINUX_MIPSN64 && glibc < 2.25 */ 51 # endif /* __GLIBC__ */ 52 #endif /* HAVE_READAHEAD */ 53 54 #ifdef HAVE_READAHEAD 55 56 # include <fcntl.h> 57 # include <stdio.h> 58 59 static const int fds[] = { 60 -0x80000000, 61 -100, 62 -1, 63 0, 64 1, 65 2, 66 0x7fffffff, 67 }; 68 69 static const off64_t offsets[] = { 70 -0x8000000000000000LL, 71 -0x5060708090a0b0c0LL, 72 -1LL, 73 0, 74 1, 75 0xbadfaced, 76 0x7fffffffffffffffLL, 77 }; 78 79 static const unsigned long counts[] = { 80 0UL, 81 0xdeadca75, 82 (unsigned long) 0xface1e55beeff00dULL, 83 (unsigned long) 0xffffffffffffffffULL, 84 }; 85 86 int 87 main(void) 88 { 89 unsigned i; 90 unsigned j; 91 unsigned k; 92 ssize_t rc; 93 94 for (i = 0; i < ARRAY_SIZE(fds); i++) 95 for (j = 0; j < ARRAY_SIZE(offsets); j++) 96 for (k = 0; k < ARRAY_SIZE(counts); k++) { 97 rc = readahead(fds[i], offsets[j], counts[k]); 98 99 printf("readahead(%d, %lld, %lu) = %s\n", 100 fds[i], (long long) offsets[j], 101 counts[k], sprintrc(rc)); 102 } 103 104 puts("+++ exited with 0 +++"); 105 return 0; 106 } 107 108 #else 109 110 SKIP_MAIN_UNDEFINED("HAVE_READAHEAD") 111 112 #endif 113