File: ioctls.h

package info (click to toggle)
trinity 1.9%2Bgit20230109.87f1530-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,116 kB
  • sloc: ansic: 33,463; sh: 536; makefile: 163
file content (59 lines) | stat: -rw-r--r-- 1,451 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once

#include <stdlib.h>
#include <sys/stat.h>
#include "syscall.h"

struct ioctl {
	const char *name;
	unsigned int request;
};

#define DEV_CHAR  1
#define DEV_BLOCK 2
#define DEV_MISC  3

struct ioctl_group {
	/* optional user visible string that describes this group of ioctl
	 * operations. */
	const char *name;

	/* Non-NULL sanitise routine for this ioctl group. Initialize to
	 * "pick_random_ioctl" to pick one random ioctl. */
	void (*sanitise)(const struct ioctl_group *, struct syscallrecord *rec);

	/* Plug the available ioctls here. */
	const struct ioctl *ioctls;
	size_t ioctls_cnt;

	/* One of the DEV_* constants. */
	int devtype;

	/* List the device names from /proc/devices or /proc/misc that these
	 * ioctl operations are valid for. */
	const char *const *devs;
	size_t devs_cnt;

	/* Optional routine that should return 0 if the file descriptor is
	 * valid for this group. */
	int (*fd_test)(int fd, const struct stat *);
};

void register_ioctl_group(const struct ioctl_group *);

const struct ioctl_group *find_ioctl_group(int fd);

const struct ioctl_group *get_random_ioctl_group(void);

void pick_random_ioctl(const struct ioctl_group *, struct syscallrecord *rec);

void dump_ioctls(void);

#define IOCTL(_request) \
	{ .request = _request, .name = #_request, }

#define REG_IOCTL_GROUP(_struct) \
	static void __attribute__((constructor)) register_##_struct(void) { \
		register_ioctl_group(&_struct); \
	}