xref: /minix/minix/include/minix/safecopies.h (revision 0a6a1f1d)
1 
2 #ifndef _MINIX_SAFECOPIES_H
3 #define _MINIX_SAFECOPIES_H 1
4 
5 #include <minix/sys_config.h>
6 #include <sys/types.h>
7 #include <minix/vm.h>
8 #include <stdint.h>
9 
10 typedef struct {
11 	int cp_flags;	/* CPF_* below */
12 	union ixfer_cp_u{
13 		struct {
14 			/* CPF_DIRECT */
15 			endpoint_t	cp_who_to;	/* grantee */
16 			vir_bytes	cp_start;	/* memory */
17 			size_t		cp_len;		/* size in bytes */
18 			char		cp_reserved[8]; /* future use */
19 		} cp_direct;
20 		struct {
21 			/* CPF_INDIRECT */
22 			endpoint_t	cp_who_to;	/* grantee */
23 			endpoint_t	cp_who_from;	/* previous granter */
24 			cp_grant_id_t	cp_grant;	/* previous grant */
25 			char		cp_reserved[8];/* future use */
26 		} cp_indirect;
27 		struct {
28 			/* CPF_MAGIC */
29 			endpoint_t	cp_who_from;	/* granter */
30 			endpoint_t	cp_who_to;	/* grantee */
31 			vir_bytes	cp_start;	/* memory */
32 			size_t		cp_len;		/* size in bytes */
33 			char		cp_reserved[8]; /* future use */
34 		} cp_magic;
35 	} cp_u;
36 	char cp_reserved[8];				/* future use */
37 } cp_grant_t;
38 
39 /* Vectored safecopy. */
40 struct vscp_vec {
41         /* Exactly one of the following must be SELF. */
42         endpoint_t      v_from;         /* source */
43         endpoint_t      v_to;           /* destination */
44 
45         cp_grant_id_t   v_gid;          /* grant id of other process */
46         size_t          v_offset;       /* offset in other grant */
47         vir_bytes       v_addr;         /* address in copier's space */
48         size_t          v_bytes;        /* no. of bytes */
49 };
50 
51 /* Invalid grant number. */
52 #define GRANT_INVALID	((cp_grant_id_t) -1)
53 #define GRANT_VALID(g)	((g) > GRANT_INVALID)
54 
55 /* Operations: any combination is ok. */
56 #define CPF_READ	0x000001 /* Granted process may read. */
57 #define CPF_WRITE	0x000002 /* Granted process may write. */
58 
59 /* Grant flags. */
60 #define CPF_TRY		0x000010 /* Fail fast on unmapped memory. */
61 
62 /* Internal flags. */
63 #define CPF_USED	0x000100 /* Grant slot in use. */
64 #define CPF_DIRECT	0x000200 /* Grant from this process to another. */
65 #define CPF_INDIRECT	0x000400 /* Grant from grant to another. */
66 #define CPF_MAGIC	0x000800 /* Grant from any to any. */
67 #define CPF_VALID	0x001000 /* Grant slot contains valid grant. */
68 
69 /* Prototypes for functions in libsys. */
70 cp_grant_id_t cpf_grant_direct(endpoint_t, vir_bytes, size_t, int);
71 cp_grant_id_t cpf_grant_indirect(endpoint_t, endpoint_t, cp_grant_id_t);
72 cp_grant_id_t cpf_grant_magic(endpoint_t, endpoint_t, vir_bytes, size_t,
73 	int);
74 int cpf_revoke(cp_grant_id_t grant_id);
75 int cpf_lookup(cp_grant_id_t g, endpoint_t *ep, endpoint_t *ep2);
76 
77 int cpf_getgrants(cp_grant_id_t *grant_ids, int n);
78 int cpf_setgrant_direct(cp_grant_id_t g, endpoint_t who, vir_bytes addr,
79 	size_t size, int access);
80 int cpf_setgrant_indirect(cp_grant_id_t g, endpoint_t who_to, endpoint_t
81 	who_from, cp_grant_id_t his_g);
82 int cpf_setgrant_magic(cp_grant_id_t g, endpoint_t who_to, endpoint_t
83 	who_from, vir_bytes addr, size_t bytes, int access);
84 int cpf_setgrant_disable(cp_grant_id_t grant_id);
85 void cpf_reload(void);
86 
87 /* Set a process' grant table location and size (in-kernel only). */
88 #define _K_SET_GRANT_TABLE(rp, ptr, entries)	\
89 	priv(rp)->s_grant_table= (ptr);		\
90 	priv(rp)->s_grant_entries= (entries);   \
91 	priv(rp)->s_grant_endpoint= (rp)->p_endpoint;
92 
93 #endif	/* _MINIX_SAFECOPIES_H */
94 
95