4 * Implements an architecture independant Capability Service API
6 * $DragonFly: src/sys/sys/caps.h,v 1.3 2004/01/18 12:50:15 dillon Exp $
13 #include <sys/types.h>
15 #ifndef _SYS_MSGPORT_H_
16 #include <sys/msgport.h>
19 typedef enum caps_msg_state {
21 CAPMS_REQUEST_RETRY, /* internal / FUTURE */
23 CAPMS_REPLY_RETRY, /* internal / FUGURE */
27 typedef struct caps_msgid {
29 caps_msg_state_t c_state;
33 typedef enum caps_type {
34 CAPT_UNKNOWN, CAPT_CLIENT, CAPT_SERVICE, CAPT_REMOTE
38 * Note: upper 16 bits reserved for kernel use
40 #define CAPF_UFLAGS 0xFFFF
41 #define CAPF_USER 0x0001
42 #define CAPF_GROUP 0x0002
43 #define CAPF_WORLD 0x0004
44 #define CAPF_EXCL 0x0008
45 #define CAPF_ANYCLIENT (CAPF_USER|CAPF_GROUP|CAPF_WORLD)
46 #define CAPF_WCRED 0x0010 /* waiting for cred */
47 /* FUTURE: CAPF_ASYNC - support async services */
48 /* FUTURE: CAPF_NOGROUPS - don't bother filling in the groups[] array */
49 /* FUTURE: CAPF_TERM - send termination request to existing service */
50 /* FUTURE: CAPF_TAKE - take over existing service's connections */
51 /* FUTURE: CAPF_DISPOSE_IMM - need immediate dispose wakeups */
56 #define CAPS_ABORT_NOTIMPL 0 /* abort not implemented, no action */
57 #define CAPS_ABORT_RETURNED 1 /* already returned, no action */
58 #define CAPS_ABORT_BEFORESERVER 2 /* caught before the server got it */
59 #define CAPS_ABORT_ATSERVER 3 /* server had retrieved message */
61 #define CAPF_ABORT_HARD 0x0001 /* rip out from under server (3) */
63 #define CAPS_MAXGROUPS 16
64 #define CAPS_MAXNAMELEN 64
65 #define CAPS_MAXINPROG 128
69 typedef struct caps_port {
70 struct lwkt_port cp_lport;
71 int cp_portid; /* caps port id */
72 int cp_upcallid; /* upcall id */
75 typedef struct caps_cred {
82 gid_t groups[CAPS_MAXGROUPS];
85 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
89 TAILQ_HEAD(caps_kmsg_queue, caps_kmsg);
92 * caps_kinfo - Holds a client or service registration
94 * ci_msgpendq: holds the kernel copy of the message after it has been
95 * sent to the local port. The message is matched up against
96 * replies and automatically replied if the owner closes its
99 typedef struct caps_kinfo {
100 struct lwkt_port ci_lport; /* embedded local port */
101 struct caps_kinfo *ci_tdnext; /* per-process list */
102 struct caps_kinfo *ci_hnext; /* registration hash table */
103 struct thread *ci_td; /* owner */
104 struct caps_kmsg_queue ci_msgpendq; /* pending reply (just rcvd) */
105 struct caps_kmsg_queue ci_msguserq; /* pending reply (user holds) */
106 struct caps_kinfo *ci_rcaps; /* connected to remote */
107 int ci_cmsgcount; /* client in-progress msgs */
111 int ci_mrefs; /* message (vmspace) refs */
116 char ci_name[4]; /* variable length */
117 /* ci_name must be last element */
120 /* note: user flags are held in the low 16 bits */
121 #define CAPKF_TDLIST 0x00010000
122 #define CAPKF_HLIST 0x00020000
123 #define CAPKF_FLUSH 0x00040000
124 #define CAPKF_RCAPS 0x00080000
125 #define CAPKF_CLOSED 0x00100000
126 #define CAPKF_MWAIT 0x00200000
129 * Kernel caps message. The kernel keepps track of messagse received,
130 * undergoing processing by the service, and returned. User-supplied data
131 * is copied on reception rather then transmission.
133 typedef struct caps_kmsg {
134 TAILQ_ENTRY(caps_kmsg) km_node;
135 caps_kinfo_t km_mcaps; /* message sender */
136 void *km_umsg; /* mcaps vmspace */
137 int km_umsg_size; /* mcaps vmspace */
138 struct caps_cred km_ccr; /* caps cred for msg */
139 struct caps_msgid km_msgid;
143 #define km_state km_msgid.c_state
145 #define CAPKMF_ONUSERQ 0x0001
146 #define CAPKMF_ONPENDQ 0x0002
147 #define CAPKMF_REPLY 0x0004
148 #define CAPKMF_CDONE 0x0008
149 #define CAPKMF_PEEKED 0x0010
150 #define CAPKMF_ABORTED 0x0020
159 void caps_exit(struct thread *td);
160 void caps_fork(struct proc *p1, struct proc *p2);
165 * Userland API (libcaps)
167 caps_port_t caps_service(const char *name, uid_t uid, gid_t gid,
168 mode_t modes, int flags);
169 caps_port_t caps_client(const char *name, uid_t uid, gid_t gid, int flags);
174 int caps_sys_service(const char *name, uid_t uid, gid_t gid, int upcid, int flags);
175 int caps_sys_client(const char *name, uid_t uid, gid_t gid, int upcid, int flags);
176 off_t caps_sys_put(int portid, void *msg, int msgsize);
177 int caps_sys_reply(int portid, void *msg, int msgsize, off_t msgcid);
178 int caps_sys_get(int portid, void *msg, int maxsize, caps_msgid_t msgid, caps_cred_t ccr);
179 int caps_sys_wait(int portid, void *msg, int maxsize, caps_msgid_t msgid, caps_cred_t ccr);
180 int caps_sys_abort(int portid, off_t msgcid, int flags);