Commit | Line | Data |
---|---|---|
ece04fd0 MD |
1 | /* |
2 | * SYS/MSGPORT.H | |
3 | * | |
4 | * Implements LWKT messages and ports. | |
5 | * | |
bf82f9b7 | 6 | * $DragonFly: src/sys/sys/msgport.h,v 1.8 2003/11/08 07:57:43 dillon Exp $ |
ece04fd0 MD |
7 | */ |
8 | ||
9 | #ifndef _SYS_MSGPORT_H_ | |
10 | #define _SYS_MSGPORT_H_ | |
11 | ||
12 | #ifndef _SYS_QUEUE_H_ | |
13 | #include <sys/queue.h> /* TAILQ_* macros */ | |
14 | #endif | |
15 | ||
16 | struct lwkt_msg; | |
17 | struct lwkt_port; | |
335dda38 | 18 | struct thread; |
ece04fd0 MD |
19 | |
20 | typedef struct lwkt_msg *lwkt_msg_t; | |
21 | typedef struct lwkt_port *lwkt_port_t; | |
22 | ||
335dda38 MD |
23 | typedef TAILQ_HEAD(lwkt_msg_queue, lwkt_msg) lwkt_msg_queue; |
24 | ||
ece04fd0 MD |
25 | /* |
26 | * The standard message and port structure for communications between | |
27 | * threads. See kern/lwkt_msgport.c for documentation on how messages and | |
28 | * ports work. | |
a64ba182 | 29 | * |
245e4f17 MD |
30 | * NOTE: ms_cleanupmsg() is typically used to finish up the handling of a |
31 | * message in the context of the caller. For example, so a sycall can | |
32 | * copyout() information to userland. | |
33 | * | |
a64ba182 | 34 | * NOTE! 64-bit-align this structure. |
ece04fd0 MD |
35 | */ |
36 | typedef struct lwkt_msg { | |
37 | TAILQ_ENTRY(lwkt_msg) ms_node; /* link node (not always used) */ | |
4fd10eb6 | 38 | union { |
c7114eea | 39 | struct lwkt_msg *ms_next; /* chaining / cache */ |
245e4f17 | 40 | union sysunion *ms_sysunnext; /* chaining / cache */ |
c7114eea | 41 | struct lwkt_msg *ms_umsg; /* user message (UVA address) */ |
4fd10eb6 | 42 | } opaque; |
ece04fd0 MD |
43 | lwkt_port_t ms_target_port; /* only used in certain situations */ |
44 | lwkt_port_t ms_reply_port; /* asynch replies returned here */ | |
245e4f17 MD |
45 | void (*ms_cleanupmsg)(lwkt_port_t port, lwkt_msg_t msg); |
46 | void *ms_unused; /* (alignment) */ | |
ece04fd0 MD |
47 | int ms_abortreq; /* set asynchronously */ |
48 | int ms_cmd; | |
49 | int ms_flags; | |
245e4f17 | 50 | #define ms_copyout_start ms_error |
ece04fd0 | 51 | int ms_error; |
a64ba182 | 52 | union { |
90b9818c MD |
53 | void *ms_resultp; /* misc pointer result */ |
54 | int ms_result; /* standard 'int'eger result */ | |
55 | long ms_lresult; /* long result */ | |
56 | int ms_fds[2]; /* two int bit results */ | |
57 | int32_t ms_result32; /* 32 bit result */ | |
58 | int64_t ms_result64; /* 64 bit result */ | |
59 | off_t ms_offset; /* off_t result */ | |
a64ba182 | 60 | } u; |
245e4f17 | 61 | #define ms_copyout_end ms_pad[0] |
a64ba182 | 62 | int ms_pad[2]; /* future use */ |
ece04fd0 MD |
63 | } lwkt_msg; |
64 | ||
245e4f17 MD |
65 | #define ms_copyout_size (offsetof(struct lwkt_msg, ms_copyout_end) - offsetof(struct lwkt_msg, ms_copyout_start)) |
66 | ||
ece04fd0 MD |
67 | #define MSGF_DONE 0x0001 /* asynch message is complete */ |
68 | #define MSGF_REPLY 0x0002 /* asynch message has been returned */ | |
69 | #define MSGF_QUEUED 0x0004 /* message has been queued sanitychk */ | |
70 | #define MSGF_ASYNC 0x0008 /* sync/async hint */ | |
71 | ||
335dda38 MD |
72 | #define MSG_CMD_CDEV 0x00010000 |
73 | #define MSG_CMD_VFS 0x00020000 | |
74 | #define MSG_CMD_SYSCALL 0x00030000 | |
bf82f9b7 | 75 | #define MSG_CMD_NETMSG 0x00040000 |
335dda38 MD |
76 | #define MSG_SUBCMD_MASK 0x0000FFFF |
77 | ||
ece04fd0 MD |
78 | typedef struct lwkt_port { |
79 | lwkt_msg_queue mp_msgq; | |
80 | int mp_flags; | |
245e4f17 | 81 | int mp_refs; /* references to port structure */ |
335dda38 | 82 | struct thread *mp_td; |
ece04fd0 MD |
83 | int (*mp_beginmsg)(lwkt_port_t port, lwkt_msg_t msg); |
84 | void (*mp_abortmsg)(lwkt_port_t port, lwkt_msg_t msg); | |
85 | void (*mp_returnmsg)(lwkt_port_t port, lwkt_msg_t msg); | |
86 | } lwkt_port; | |
87 | ||
88 | #define MSGPORTF_WAITING 0x0001 | |
89 | ||
90 | #ifdef _KERNEL | |
91 | ||
335dda38 | 92 | extern void lwkt_init_port(lwkt_port_t port, struct thread *td); |
4fd10eb6 | 93 | extern void lwkt_initmsg_td(lwkt_msg_t msg, struct thread *td); |
ece04fd0 MD |
94 | extern void lwkt_sendmsg(lwkt_port_t port, lwkt_msg_t msg); |
95 | extern int lwkt_domsg(lwkt_port_t port, lwkt_msg_t msg); | |
96 | extern int lwkt_waitmsg(lwkt_msg_t msg); | |
97 | extern void lwkt_replyport(lwkt_port_t port, lwkt_msg_t msg); | |
98 | extern void lwkt_abortport(lwkt_port_t port, lwkt_msg_t msg); | |
99 | extern int lwkt_putport(lwkt_port_t port, lwkt_msg_t msg); | |
100 | extern void *lwkt_getport(lwkt_port_t port); | |
101 | extern void *lwkt_waitport(lwkt_port_t port); | |
102 | ||
103 | #endif | |
104 | ||
105 | #endif |