(root)/
strace-6.5/
tests-m32/
ioctl_random.c
       1  /*
       2   * Check decoding of RND* commands of ioctl syscall.
       3   *
       4   * Copyright (c) 2018-2019 The strace developers.
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  
      12  #include <stdio.h>
      13  #include <string.h>
      14  #include <sys/ioctl.h>
      15  #include <linux/types.h>
      16  #include <linux/random.h>
      17  
      18  #define XLAT_MACROS_ONLY
      19  #include "xlat/random_ioctl_cmds.h"
      20  #undef XLAT_MACROS_ONLY
      21  
      22  #define RVAL_EBADF " = -1 EBADF (%m)\n"
      23  
      24  int
      25  main(void)
      26  {
      27  	union {
      28  		char c[sizeof(struct rand_pool_info) + 8];
      29  		struct rand_pool_info info;
      30  	} u;
      31  	struct rand_pool_info *info = &u.info;
      32  	int cnt = 6;
      33  
      34  	memcpy(info->buf, "12345678", 8);
      35  	info->buf_size = 8;
      36  	info->entropy_count = 3;
      37  
      38  	ioctl(-1, RNDGETENTCNT, &cnt);
      39  	printf("ioctl(-1, RNDGETENTCNT, %p)" RVAL_EBADF, &cnt);
      40  	ioctl(-1, RNDADDTOENTCNT, &cnt);
      41  	printf("ioctl(-1, RNDADDTOENTCNT, [6])" RVAL_EBADF);
      42  
      43  	ioctl(-1, RNDADDENTROPY, NULL);
      44  	printf("ioctl(-1, RNDADDENTROPY, NULL)" RVAL_EBADF);
      45  	ioctl(-1, RNDADDENTROPY, info);
      46  	printf("ioctl(-1, RNDADDENTROPY, {entropy_count=3, buf_size=8, buf=\"12345678\"})" RVAL_EBADF);
      47  
      48  	ioctl(-1, RNDZAPENTCNT);
      49  	printf("ioctl(-1, FASTRPC_IOCTL_INIT_ATTACH or RNDZAPENTCNT)"
      50  	       RVAL_EBADF);
      51  	ioctl(-1, RNDCLEARPOOL);
      52  	printf("ioctl(-1, RNDCLEARPOOL)" RVAL_EBADF);
      53  	ioctl(-1, RNDRESEEDCRNG);
      54  	printf("ioctl(-1, RNDRESEEDCRNG)" RVAL_EBADF);
      55  
      56  	ioctl(-1, _IO('R', 0xff), NULL);
      57  	printf("ioctl(-1, _IOC(_IOC_NONE, %#x, 0xff, 0), 0)" RVAL_EBADF, 'R');
      58  
      59  	puts("+++ exited with 0 +++");
      60  	return 0;
      61  }