1 /*
2 * Copyright (c) 2018-2021 The strace developers.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
8 #include "defs.h"
9
10 #include <linux/types.h>
11 #include <linux/random.h>
12
13 #define XLAT_MACROS_ONLY
14 #include "xlat/random_ioctl_cmds.h"
15 #undef XLAT_MACROS_ONLY
16
17 /*
18 * RNDGETPOOL was removed in 2.6.9, so non-ancient kernels always
19 * return -EINVAL for that.
20 */
21
22 int
23 random_ioctl(struct tcb *const tcp, const unsigned int code,
24 const kernel_ulong_t arg)
25 {
26 struct rand_pool_info info;
27 kernel_ulong_t buf;
28
29 switch (code) {
30 case RNDGETENTCNT:
31 if (entering(tcp))
32 return 0;
33 ATTRIBUTE_FALLTHROUGH;
34 case RNDADDTOENTCNT:
35 tprint_arg_next();
36 printnum_int(tcp, arg, "%d");
37 break;
38
39 case RNDADDENTROPY:
40 tprint_arg_next();
41 if (!umove_or_printaddr(tcp, arg, &info)) {
42 tprint_struct_begin();
43 PRINT_FIELD_D(info, entropy_count);
44 tprint_struct_next();
45 PRINT_FIELD_D(info, buf_size);
46 tprint_struct_next();
47 tprints_field_name("buf");
48 buf = arg + offsetof(struct rand_pool_info, buf);
49 printstrn(tcp, buf, info.buf_size);
50 tprint_struct_end();
51 }
52 break;
53
54 /* ioctls with no parameters */
55 case RNDZAPENTCNT:
56 case RNDCLEARPOOL:
57 case RNDRESEEDCRNG:
58 break;
59 default:
60 return RVAL_DECODED;
61 }
62 return RVAL_IOCTL_DECODED;
63 }