(root)/
strace-6.5/
tests-m32/
readahead.c
       1  /*
       2   * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
       3   * Copyright (c) 2016-2021 The strace developers.
       4   * All rights reserved.
       5   *
       6   * SPDX-License-Identifier: GPL-2.0-or-later
       7   */
       8  
       9  #include "tests.h"
      10  #include "scno.h"
      11  
      12  #ifdef HAVE_READAHEAD
      13  /* Check for glibc readahead argument passing bugs. */
      14  /*
      15   * glibc < 2.8 had an incorrect order of higher and lower parts of offset,
      16   * see https://sourceware.org/bugzilla/show_bug.cgi?id=5208
      17   */
      18  # if GLIBC_PREREQ_LT(2, 8)
      19  #  undef HAVE_READAHEAD
      20  # endif /* glibc < 2.8 */
      21  /*
      22   * glibc < 2.25 had an incorrect implementation on mips n64,
      23   * see https://sourceware.org/bugzilla/show_bug.cgi?id=21026
      24   */
      25  # if GLIBC_PREREQ_LT(2, 25) && defined LINUX_MIPSN64
      26  #  undef HAVE_READAHEAD
      27  # endif /* LINUX_MIPSN64 && glibc < 2.25 */
      28  #endif /* HAVE_READAHEAD */
      29  
      30  #ifdef HAVE_READAHEAD
      31  
      32  # include <fcntl.h>
      33  # include <stdio.h>
      34  
      35  static const int fds[] = {
      36  	-0x80000000,
      37  	-100,
      38  	-1,
      39  	0,
      40  	1,
      41  	2,
      42  	0x7fffffff,
      43  };
      44  
      45  static const off64_t offsets[] = {
      46  	-0x8000000000000000LL,
      47  	-0x5060708090a0b0c0LL,
      48  	-1LL,
      49  	 0,
      50  	 1,
      51  	 0xbadfaced,
      52  	 0x7fffffffffffffffLL,
      53  };
      54  
      55  static const unsigned long counts[] = {
      56  	0UL,
      57  	0xdeadca75,
      58  	(unsigned long) 0xface1e55beeff00dULL,
      59  	(unsigned long) 0xffffffffffffffffULL,
      60  };
      61  
      62  int
      63  main(void)
      64  {
      65  	ssize_t rc;
      66  
      67  	for (unsigned int i = 0; i < ARRAY_SIZE(fds); ++i)
      68  		for (unsigned int j = 0; j < ARRAY_SIZE(offsets); ++j)
      69  			for (unsigned int k = 0; k < ARRAY_SIZE(counts); ++k) {
      70  				rc = readahead(fds[i], offsets[j], counts[k]);
      71  
      72  				printf("readahead(%d, %lld, %lu) = %s\n",
      73  					fds[i], (long long) offsets[j],
      74  					counts[k], sprintrc(rc));
      75  			}
      76  
      77  	puts("+++ exited with 0 +++");
      78  	return 0;
      79  }
      80  
      81  #else
      82  
      83  SKIP_MAIN_UNDEFINED("HAVE_READAHEAD")
      84  
      85  #endif