Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libcs/msg.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
22
/*
23
* syscall message interface
24
*/
25
26
#ifndef _MSG_H
27
#define _MSG_H
28
29
#include <ast.h>
30
31
#define EMSGIO (-1)
32
33
#define MSG_VERSION 1
34
35
#define MSG_TIMEOUT 8000
36
37
#define MSG_ARG_number 1
38
#define MSG_ARG_string 2
39
#define MSG_ARG_file 3
40
#define MSG_ARG_input 4
41
#define MSG_ARG_output 5
42
#define MSG_ARG_array 6
43
#define MSG_ARG_vector 7
44
45
#define MSG_ARG_CALL 11
46
#define MSG_ARG_INDEX 5
47
#define MSG_ARG_TYPE 3
48
#define MSG_ARG(c,n) (((c)>>(MSG_ARG_CALL+MSG_ARG_TYPE*(n)))&((1<<MSG_ARG_TYPE)-1))
49
#define MSG_EXT(t,n) ((t)<<(MSG_ARG_CALL+MSG_ARG_TYPE*(n)))
50
51
#define MSG_CHANNEL_SYS(n) ((n)&((1<<16)-1))
52
#define MSG_CHANNEL_USR(n) (((n)>>16)&((1<<16)-1))
53
#define MSG_CHANNEL(u,s) (((u)<<16)|((s)&((1<<16)-1)))
54
55
#define MSG_LIST_ID (1<<0) /* list channel id */
56
#define MSG_LIST_STAMP (1<<1) /* include time stamp */
57
#define MSG_LIST_USER (1<<8) /* first user bit */
58
59
#define MSG_SIZE_ACK 4
60
#define MSG_SIZE_ARG 6
61
#define MSG_SIZE_BITS 8
62
#define MSG_SIZE_BUF 4096
63
#define MSG_SIZE_IO (MSG_SIZE_BUF-128)
64
#define MSG_SIZE_SIZE 2
65
66
#define MSG_VAR_FILE (1<<MSG_ARG_INDEX) /* file variant */
67
#define MSG_VAR_IPC (2<<MSG_ARG_INDEX) /* ipc variant */
68
#define MSG_VAR_SYM (3<<MSG_ARG_INDEX) /* symlink variant */
69
70
#define MSG_ACK (1<<(MSG_ARG_INDEX+2)) /* msgcall() ack */
71
#define MSG_FLUSH (1<<(MSG_ARG_INDEX+3)) /* msgcall() msg flush */
72
#define MSG_RETURN (1<<(MSG_ARG_INDEX+4)) /* msgcall()+msgreturn()*/
73
#define MSG_VALUE (1<<(MSG_ARG_INDEX+5)) /* args have value */
74
75
#define MSG_CALL(c) ((c)&((1<<MSG_ARG_INDEX)-1))
76
#define MSG_MASK(c) (1<<MSG_CALL(c))
77
#define MSG_PURE(c) ((c)&~(((1<<MSG_ARG_CALL)-1)&~((1<<MSG_ARG_INDEX)-1)))
78
#define MSG_VAR(c) ((c)&(3<<MSG_ARG_INDEX))
79
#define MSG_SYS(c) ((c)&((1<<(MSG_ARG_INDEX+2))-1))
80
81
#define MSG_INIT(c,a,v) (MSG_CALL(c)|((a)<<MSG_ARG_CALL)|(v))
82
83
#define MSG_nop MSG_INIT( 0, 00000000, 0)
84
#define MSG_break MSG_INIT( 1, 00000011, 0)
85
#define MSG_chmod MSG_INIT( 2, 00000121, MSG_VAR_FILE)
86
#define MSG_chown MSG_INIT( 3, 00001121, MSG_VAR_FILE)
87
#define MSG_close MSG_INIT( 4, 00000131, 0)
88
#define MSG_control MSG_INIT( 5, 00001521, 0)
89
#define MSG_dup MSG_INIT( 6, 00000033, 0)
90
#define MSG_exec MSG_INIT( 7, 00007721, MSG_VAR_FILE)
91
#define MSG_exit MSG_INIT( 8, 00000011, 0)
92
#define MSG_fork MSG_INIT( 9, 00000001, 0)
93
#define MSG_getdents MSG_INIT(10, 00001531, 0)
94
#define MSG_kill MSG_INIT(11, 00000111, 0)
95
#define MSG_link MSG_INIT(12, 00000221, MSG_VAR_FILE)
96
#define MSG_lock MSG_INIT(13, 00011131, 0)
97
#define MSG_mkdir MSG_INIT(14, 00000121, MSG_VAR_FILE)
98
#define MSG_mknod MSG_INIT(15, 00001121, MSG_VAR_FILE)
99
#define MSG_mount MSG_INIT(16, 00112221, 0)
100
#define MSG_open MSG_INIT(17, 00011123, MSG_VAR_FILE)
101
#define MSG_pathconf MSG_INIT(18, 00000121, MSG_VAR_FILE)
102
#define MSG_pipe MSG_INIT(19, 00000051, 0)
103
#define MSG_read MSG_INIT(20, 00001531, 0)
104
#define MSG_remove MSG_INIT(21, 00000021, MSG_VAR_FILE)
105
#define MSG_rename MSG_INIT(22, 00000221, MSG_VAR_FILE)
106
#define MSG_rmdir MSG_INIT(23, 00000021, MSG_VAR_FILE)
107
#define MSG_seek MSG_INIT(24, 00001131, 0)
108
#define MSG_stat MSG_INIT(25, 00000521, MSG_VAR_FILE)
109
#define MSG_statfs MSG_INIT(26, 00000521, MSG_VAR_FILE)
110
#define MSG_sync MSG_INIT(27, 00000001, MSG_VAR_FILE)
111
#define MSG_truncate MSG_INIT(28, 00000121, MSG_VAR_FILE)
112
#define MSG_utime MSG_INIT(29, 00001121, MSG_VAR_FILE)
113
#define MSG_wait MSG_INIT(30, 00001511, 0)
114
#define MSG_write MSG_INIT(31, 00001431, 0)
115
116
#define MSG_STD 31
117
118
/* common fd variants */
119
120
#define MSG_fchmod MSG_INIT(MSG_chmod, 00000131, MSG_VAR_FILE)
121
#define MSG_fchown MSG_INIT(MSG_chown, 00001131, MSG_VAR_FILE)
122
#define MSG_fpathconf MSG_INIT(MSG_pathconf, 00000131, MSG_VAR_FILE)
123
#define MSG_fstat MSG_INIT(MSG_stat, 00000531, MSG_VAR_FILE)
124
#define MSG_fstatfs MSG_INIT(MSG_statfs, 00000531, MSG_VAR_FILE)
125
#define MSG_fsync MSG_INIT(MSG_sync, 00000031, MSG_VAR_FILE)
126
#define MSG_ftruncate MSG_INIT(MSG_truncate, 00000131, MSG_VAR_FILE)
127
128
/* common ipc variants */
129
130
#define MSG_accept MSG_INIT(MSG_dup, 00005533, MSG_VAR_IPC)
131
#define MSG_bind MSG_INIT(MSG_rename, 00001531, MSG_VAR_IPC)
132
#define MSG_connect MSG_INIT(MSG_link, 00001531, MSG_VAR_IPC)
133
#define MSG_recv MSG_INIT(MSG_read, 00011531, MSG_VAR_IPC)
134
#define MSG_recvmsg MSG_INIT(MSG_read, 05511531, MSG_VAR_IPC)
135
#define MSG_send MSG_INIT(MSG_write, 00011431, MSG_VAR_IPC)
136
#define MSG_sendmsg MSG_INIT(MSG_write, 01411431, MSG_VAR_IPC)
137
#define MSG_socket MSG_INIT(MSG_open, 00001113, MSG_VAR_IPC)
138
139
/* common symbolic variants */
140
141
#define MSG_lstat MSG_INIT(MSG_stat, 00000521, MSG_VAR_SYM)
142
#define MSG_readlink MSG_INIT(MSG_read, 00001521, MSG_VAR_SYM)
143
#define MSG_symlink MSG_INIT(MSG_link, 00000221, MSG_VAR_SYM)
144
145
typedef struct
146
{
147
long fid[2];
148
} Msg_file_t;
149
150
typedef union
151
{
152
long* array;
153
Msg_file_t* file;
154
unsigned long number;
155
char* pointer;
156
char* string;
157
char** vector;
158
} Msg_arg_t;
159
160
typedef union
161
{
162
Msg_file_t file;
163
unsigned long number;
164
} Msg_return_t;
165
166
typedef struct
167
{
168
char data[MSG_SIZE_BUF];
169
char value[MSG_SIZE_BUF];
170
int version;
171
unsigned long call;
172
size_t size;
173
unsigned long channel;
174
unsigned long stamp;
175
struct
176
{
177
unsigned long addr;
178
unsigned long port;
179
} ack;
180
int argc;
181
Msg_arg_t argv[MSG_SIZE_ARG];
182
Msg_return_t ret;
183
} Msg_call_t;
184
185
typedef struct
186
{
187
int timeout;
188
int timestamp;
189
const char* name[MSG_STD + 1];
190
} Msg_info_t;
191
192
#define msg_info _msg_info_
193
194
#if _BLD_cs && defined(__EXPORT__)
195
#define extern __EXPORT__
196
#endif
197
#if !_BLD_cs && defined(__IMPORT__)
198
#define extern extern __IMPORT__
199
#endif
200
201
extern Msg_info_t msg_info;
202
203
#undef extern
204
205
#ifndef msgreserve
206
#define msgreserve(p)
207
#endif
208
209
#define msggetsize(p) ((((p)[0]&((1<<MSG_SIZE_BITS)-1))<<MSG_SIZE_BITS)|((p)[1]&((1<<MSG_SIZE_BITS)-1)))
210
211
#define msgsetsize(p,n) ((p)[0]=((n)>>MSG_SIZE_BITS)&((1<<MSG_SIZE_BITS)-1),(p)[1]=(n)&((1<<MSG_SIZE_BITS)-1))
212
213
#if _BLD_cs && defined(__EXPORT__)
214
#define extern __EXPORT__
215
#endif
216
217
extern int msggetmask(char*, int, unsigned long);
218
extern int msgindex(const char*);
219
extern int msglist(Sfio_t*, Msg_call_t*, int, unsigned long);
220
extern const char* msgname(unsigned long);
221
extern unsigned long msgsetmask(const char*);
222
223
extern unsigned long msggetu(char**, char*);
224
extern int msgputu(char**, char*, unsigned long);
225
extern size_t msggetz(char**, char*, void*, size_t);
226
extern int msgputz(char**, char*, void*, size_t);
227
228
extern ssize_t msgcall(int, unsigned long, unsigned long, Msg_return_t*, ...);
229
extern ssize_t msgvcall(int, unsigned long, unsigned long, Msg_return_t*, void**, va_list);
230
extern long msgreturn(int, unsigned long, ...);
231
extern long msgvreturn(int, unsigned long, void**, va_list);
232
233
extern ssize_t msgblast(Msg_call_t*);
234
extern ssize_t msgread(int, char*, size_t);
235
extern ssize_t msgrecv(int, Msg_call_t*);
236
extern ssize_t msgsend(int, Msg_call_t*, unsigned long, long, int, void*);
237
238
#undef extern
239
240
#endif
241
242