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