root / lab4 / .minix-src / include / minix / safecopies.h @ 13
History | View | Annotate | Download (3.8 KB)
1 |
#ifndef _MINIX_SAFECOPIES_H
|
---|---|
2 |
#define _MINIX_SAFECOPIES_H 1 |
3 |
|
4 |
#include <minix/sys_config.h> |
5 |
#include <sys/types.h> |
6 |
#include <minix/vm.h> |
7 |
#include <stdint.h> |
8 |
|
9 |
typedef struct { |
10 |
int cp_flags; /* CPF_* below */ |
11 |
int cp_seq; /* sequence number */ |
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 |
} cp_direct; |
19 |
struct {
|
20 |
/* CPF_INDIRECT */
|
21 |
endpoint_t cp_who_to; /* grantee */
|
22 |
endpoint_t cp_who_from; /* previous granter */
|
23 |
cp_grant_id_t cp_grant; /* previous grant */
|
24 |
} cp_indirect; |
25 |
struct {
|
26 |
/* CPF_MAGIC */
|
27 |
endpoint_t cp_who_from; /* granter */
|
28 |
endpoint_t cp_who_to; /* grantee */
|
29 |
vir_bytes cp_start; /* memory */
|
30 |
size_t cp_len; /* size in bytes */
|
31 |
} cp_magic; |
32 |
struct {
|
33 |
/* (free slot) */
|
34 |
int cp_next; /* next free or -1 */ |
35 |
} cp_free; |
36 |
} cp_u; |
37 |
cp_grant_id_t cp_faulted; /* soft fault marker (CPF_TRY only) */
|
38 |
} cp_grant_t; |
39 |
|
40 |
/* Vectored safecopy. */
|
41 |
struct vscp_vec {
|
42 |
/* Exactly one of the following must be SELF. */
|
43 |
endpoint_t v_from; /* source */
|
44 |
endpoint_t v_to; /* destination */
|
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 |
/* Grant index and sequence number split/merge/limits. */
|
56 |
#define GRANT_SHIFT 20 /* seq: upper 11 bits, idx: lower 20 */ |
57 |
#define GRANT_MAX_SEQ (1 << (31 - GRANT_SHIFT)) |
58 |
#define GRANT_MAX_IDX (1 << GRANT_SHIFT) |
59 |
#define GRANT_ID(idx, seq) ((cp_grant_id_t)((seq << GRANT_SHIFT) | (idx)))
|
60 |
#define GRANT_SEQ(g) (((g) >> GRANT_SHIFT) & (GRANT_MAX_SEQ - 1)) |
61 |
#define GRANT_IDX(g) ((g) & (GRANT_MAX_IDX - 1)) |
62 |
|
63 |
/* Operations: any combination is ok. */
|
64 |
#define CPF_READ 0x000001 /* Granted process may read. */ |
65 |
#define CPF_WRITE 0x000002 /* Granted process may write. */ |
66 |
|
67 |
/* Grant flags. */
|
68 |
#define CPF_TRY 0x000010 /* Fail fast on unmapped memory. */ |
69 |
|
70 |
/* Internal flags. */
|
71 |
#define CPF_USED 0x000100 /* Grant slot in use. */ |
72 |
#define CPF_DIRECT 0x000200 /* Grant from this process to another. */ |
73 |
#define CPF_INDIRECT 0x000400 /* Grant from grant to another. */ |
74 |
#define CPF_MAGIC 0x000800 /* Grant from any to any. */ |
75 |
#define CPF_VALID 0x001000 /* Grant slot contains valid grant. */ |
76 |
|
77 |
/* Special cpf_revoke() return values. */
|
78 |
#define GRANT_FAULTED 1 /* CPF_TRY: a soft fault occurred */ |
79 |
|
80 |
/* Prototypes for functions in libsys. */
|
81 |
void cpf_prealloc(unsigned int count); |
82 |
cp_grant_id_t cpf_grant_direct(endpoint_t who_to, vir_bytes addr, size_t bytes, |
83 |
int access);
|
84 |
cp_grant_id_t cpf_grant_indirect(endpoint_t who_to, endpoint_t who_from, |
85 |
cp_grant_id_t gr); |
86 |
cp_grant_id_t cpf_grant_magic(endpoint_t who_to, endpoint_t who_from, |
87 |
vir_bytes addr, size_t bytes, int access);
|
88 |
int cpf_revoke(cp_grant_id_t grant_id);
|
89 |
|
90 |
/* START OF DEPRECATED API */
|
91 |
int cpf_getgrants(cp_grant_id_t *grant_ids, int n); |
92 |
int cpf_setgrant_direct(cp_grant_id_t g, endpoint_t who, vir_bytes addr,
|
93 |
size_t size, int access);
|
94 |
int cpf_setgrant_indirect(cp_grant_id_t g, endpoint_t who_to, endpoint_t
|
95 |
who_from, cp_grant_id_t his_g); |
96 |
int cpf_setgrant_magic(cp_grant_id_t g, endpoint_t who_to, endpoint_t
|
97 |
who_from, vir_bytes addr, size_t bytes, int access);
|
98 |
int cpf_setgrant_disable(cp_grant_id_t grant_id);
|
99 |
/* END OF DEPRECATED API */
|
100 |
|
101 |
void cpf_reload(void); |
102 |
|
103 |
/* Set a process' grant table location and size (in-kernel only). */
|
104 |
#define _K_SET_GRANT_TABLE(rp, ptr, entries) \
|
105 |
priv(rp)->s_grant_table= (ptr); \ |
106 |
priv(rp)->s_grant_entries= (entries); \ |
107 |
priv(rp)->s_grant_endpoint= (rp)->p_endpoint; |
108 |
|
109 |
#endif /* _MINIX_SAFECOPIES_H */ |