Fix reversed snprintf arguments.
[dragonfly.git] / sys / sys / msgport.h
CommitLineData
ece04fd0
MD
1/*
2 * SYS/MSGPORT.H
3 *
4 * Implements LWKT messages and ports.
5 *
c95cd171 6 * $DragonFly: src/sys/sys/msgport.h,v 1.11 2003/11/24 20:46:05 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
05220613
MD
15#ifndef _SYS_STDINT_H_
16#include <sys/stdint.h>
17#endif
ece04fd0
MD
18
19struct lwkt_msg;
20struct lwkt_port;
335dda38 21struct thread;
ece04fd0
MD
22
23typedef struct lwkt_msg *lwkt_msg_t;
24typedef struct lwkt_port *lwkt_port_t;
25
335dda38
MD
26typedef TAILQ_HEAD(lwkt_msg_queue, lwkt_msg) lwkt_msg_queue;
27
ece04fd0
MD
28/*
29 * The standard message and port structure for communications between
30 * threads. See kern/lwkt_msgport.c for documentation on how messages and
31 * ports work.
a64ba182
MD
32 *
33 * NOTE! 64-bit-align this structure.
ece04fd0
MD
34 */
35typedef struct lwkt_msg {
36 TAILQ_ENTRY(lwkt_msg) ms_node; /* link node (not always used) */
4fd10eb6 37 union {
c7114eea 38 struct lwkt_msg *ms_next; /* chaining / cache */
245e4f17 39 union sysunion *ms_sysunnext; /* chaining / cache */
c7114eea 40 struct lwkt_msg *ms_umsg; /* user message (UVA address) */
4fd10eb6 41 } opaque;
df2244e3 42 lwkt_port_t ms_target_port; /* current target or relay port */
ece04fd0 43 lwkt_port_t ms_reply_port; /* asynch replies returned here */
df2244e3
MD
44 int ms_maxsize; /* maximum returned message size */
45 int ms_cmd; /* message command */
46 int ms_flags; /* message flags */
47#define ms_copyout_start ms_msgsize
48 int ms_msgsize; /* sent/returned size of message */
49 int ms_error; /* positive error code or 0 */
a64ba182 50 union {
df2244e3 51 void *ms_resultp; /* misc pointer data or result */
90b9818c
MD
52 int ms_result; /* standard 'int'eger result */
53 long ms_lresult; /* long result */
54 int ms_fds[2]; /* two int bit results */
05220613
MD
55 __int32_t ms_result32; /* 32 bit result */
56 __int64_t ms_result64; /* 64 bit result */
57 __off_t ms_offset; /* off_t result */
a64ba182 58 } u;
245e4f17 59#define ms_copyout_end ms_pad[0]
a64ba182 60 int ms_pad[2]; /* future use */
ece04fd0
MD
61} lwkt_msg;
62
245e4f17
MD
63#define ms_copyout_size (offsetof(struct lwkt_msg, ms_copyout_end) - offsetof(struct lwkt_msg, ms_copyout_start))
64
ece04fd0
MD
65#define MSGF_DONE 0x0001 /* asynch message is complete */
66#define MSGF_REPLY 0x0002 /* asynch message has been returned */
67#define MSGF_QUEUED 0x0004 /* message has been queued sanitychk */
68#define MSGF_ASYNC 0x0008 /* sync/async hint */
df2244e3 69#define MSGF_ABORTED 0x0010 /* message was aborted flag */
ece04fd0 70
335dda38
MD
71#define MSG_CMD_CDEV 0x00010000
72#define MSG_CMD_VFS 0x00020000
73#define MSG_CMD_SYSCALL 0x00030000
bf82f9b7 74#define MSG_CMD_NETMSG 0x00040000
335dda38
MD
75#define MSG_SUBCMD_MASK 0x0000FFFF
76
ece04fd0
MD
77typedef struct lwkt_port {
78 lwkt_msg_queue mp_msgq;
79 int mp_flags;
245e4f17 80 int mp_refs; /* references to port structure */
335dda38 81 struct thread *mp_td;
df2244e3
MD
82 int (*mp_putport)(lwkt_port_t, lwkt_msg_t);
83 void * (*mp_waitport)(lwkt_port_t, lwkt_msg_t);
84 void (*mp_replyport)(lwkt_port_t, lwkt_msg_t);
85 void (*mp_abortport)(lwkt_port_t, lwkt_msg_t);
ece04fd0
MD
86} lwkt_port;
87
88#define MSGPORTF_WAITING 0x0001
89
df2244e3
MD
90/*
91 * These functions are good for userland as well as the kernel. The
92 * messaging function support for userland is provided by the kernel's
93 * kern/lwkt_msgport.c. The port functions are provided by userland.
94 */
c95cd171 95extern void lwkt_initport(lwkt_port_t, struct thread *);
df2244e3
MD
96extern void lwkt_initmsg_td(lwkt_msg_t, struct thread *);
97extern void lwkt_sendmsg(lwkt_port_t, lwkt_msg_t);
98extern int lwkt_domsg(lwkt_port_t, lwkt_msg_t);
99extern void *lwkt_getport(lwkt_port_t);
ece04fd0 100
ece04fd0 101#endif