Fix reversed snprintf arguments.
[dragonfly.git] / sys / sys / msgport.h
... / ...
CommitLineData
1/*
2 * SYS/MSGPORT.H
3 *
4 * Implements LWKT messages and ports.
5 *
6 * $DragonFly: src/sys/sys/msgport.h,v 1.11 2003/11/24 20:46:05 dillon Exp $
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#ifndef _SYS_STDINT_H_
16#include <sys/stdint.h>
17#endif
18
19struct lwkt_msg;
20struct lwkt_port;
21struct thread;
22
23typedef struct lwkt_msg *lwkt_msg_t;
24typedef struct lwkt_port *lwkt_port_t;
25
26typedef TAILQ_HEAD(lwkt_msg_queue, lwkt_msg) lwkt_msg_queue;
27
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.
32 *
33 * NOTE! 64-bit-align this structure.
34 */
35typedef struct lwkt_msg {
36 TAILQ_ENTRY(lwkt_msg) ms_node; /* link node (not always used) */
37 union {
38 struct lwkt_msg *ms_next; /* chaining / cache */
39 union sysunion *ms_sysunnext; /* chaining / cache */
40 struct lwkt_msg *ms_umsg; /* user message (UVA address) */
41 } opaque;
42 lwkt_port_t ms_target_port; /* current target or relay port */
43 lwkt_port_t ms_reply_port; /* asynch replies returned here */
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 */
50 union {
51 void *ms_resultp; /* misc pointer data or result */
52 int ms_result; /* standard 'int'eger result */
53 long ms_lresult; /* long result */
54 int ms_fds[2]; /* two int bit results */
55 __int32_t ms_result32; /* 32 bit result */
56 __int64_t ms_result64; /* 64 bit result */
57 __off_t ms_offset; /* off_t result */
58 } u;
59#define ms_copyout_end ms_pad[0]
60 int ms_pad[2]; /* future use */
61} lwkt_msg;
62
63#define ms_copyout_size (offsetof(struct lwkt_msg, ms_copyout_end) - offsetof(struct lwkt_msg, ms_copyout_start))
64
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 */
69#define MSGF_ABORTED 0x0010 /* message was aborted flag */
70
71#define MSG_CMD_CDEV 0x00010000
72#define MSG_CMD_VFS 0x00020000
73#define MSG_CMD_SYSCALL 0x00030000
74#define MSG_CMD_NETMSG 0x00040000
75#define MSG_SUBCMD_MASK 0x0000FFFF
76
77typedef struct lwkt_port {
78 lwkt_msg_queue mp_msgq;
79 int mp_flags;
80 int mp_refs; /* references to port structure */
81 struct thread *mp_td;
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);
86} lwkt_port;
87
88#define MSGPORTF_WAITING 0x0001
89
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 */
95extern void lwkt_initport(lwkt_port_t, struct thread *);
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);
100
101#endif