forked from openafs/openafs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.c
305 lines (258 loc) · 5.92 KB
/
export.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
*
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
*/
/*
* export - EXPORT kernel extension
*/
/* Unsafe: conflicts with _KERNEL inclusion of headers below */
/* #include <afs/param.h> */
/* #include <afsconfig.h> */
#define _KERNEL
#include "sys/types.h"
#include "sys/user.h"
#include "sys/conf.h"
#include "sys/errno.h"
#include "sys/device.h"
#include "sys/uio.h"
#include "sys/pri.h"
#include "sys/malloc.h"
#include "sym.h"
#include "export.h"
#undef RELOC
sym_t *toc_syms; /* symbol table */
int toc_nsyms; /* # of symbols */
caddr_t toc_strs; /* string table */
int toc_size; /* size of toc_syms */
/*
* export - entry point to EXPORT kernel extension
*
* Input:
* cmd - add/delete command
* uiop - uio vector describing any config params
*/
export(cmd, uiop)
struct uio *uiop;
{
int err, monster;
static once;
err = 0;
monster = lockl(&kernel_lock, LOCK_SHORT);
switch (cmd) {
case CFG_INIT: /* add EXPORT */
if (err = config(uiop))
export_cleanup();
break;
case CFG_TERM: /* remove EXPORT */
if (err = export_cleanup())
break;
break;
default:
err = EINVAL;
break;
}
if (monster != LOCK_NEST)
unlockl(&kernel_lock);
return err;
}
/*
* config - process configuration data
*/
config(uiop)
struct uio *uiop;
{
struct k_conf conf;
struct export_nl *np;
sym_t *sym;
int err;
if (err = uiomove((char *)&conf, sizeof(conf), UIO_WRITE, uiop))
return err;
toc_nsyms = conf.nsyms;
toc_size = conf.symt_sz + conf.str_sz;
if (toc_nsyms * sizeof(sym_t) != conf.symt_sz || toc_size > (1024 * 1024))
#ifdef AFS_AIX51_ENV
return EFBIG;
#else
return EINVAL;
#endif
toc_syms = (sym_t *) xmalloc(toc_size, 2, kernel_heap);
if (!toc_syms)
return ENOMEM;
toc_strs = (char *)&toc_syms[toc_nsyms];
/*
* copy in the symbol table and the string table
*/
if (err = copyin(conf.symtab, toc_syms, conf.symt_sz)
|| (err = copyin(conf.strtab, toc_strs, conf.str_sz))) {
xmfree(toc_syms, kernel_heap);
toc_syms = 0;
return err;
}
/*
* `TOC' format in kernel has offsets relocated to point directly
* into the string table.
*/
for (sym = toc_syms; sym < &toc_syms[toc_nsyms]; ++sym)
#ifndef __XCOFF64__
if (sym->n_zeroes == 0)
#endif
sym->n_nptr = sym->n_offset + toc_strs;
return 0;
}
/*
* export_cleanup - cleanup EXPORT prior to removing kernel extension
*/
export_cleanup()
{
/*
* get rid of the symbol table
*/
if (toc_syms) {
xmfree(toc_syms, kernel_heap);
toc_syms = 0;
toc_size = 0;
toc_strs = 0;
}
return 0;
}
/*
* import_kfunc - import a kernel function that was mistakenly left
* off the exports list
*
* NOTE:
* We are assuming that the functions we are importing from the
* kernel really are within the kernel. If they are actually
* exported from some other kernel extension (but referenced in
* the /unix symbol table) we are in trouble.
*/
#ifdef __XCOFF64__
u_int64 *myg_toc;
#else
u_int32 *myg_toc;
#endif
import_kfunc(struct k_func * kfp)
{
sym_t *sym;
int i, pri;
#if 0
static caddr_t *g_toc;
#endif
if (!myg_toc) {
#ifdef __XCOFF64__
sym = sym_lookup("ktoc", 0);
#else
sym = sym_lookup("g_toc", 0);
#endif
if (!sym) {
printf("\nimport: can't ascertain kernel's TOC\n");
return EINVAL;
}
myg_toc = sym->n_value;
}
sym = sym_lookup(kfp->name, 0);
if (!sym) {
printf("\nimport: function `%s' not found\n", kfp->name);
return EINVAL;
}
kfp->fdesc[0] = sym->n_value;
kfp->fdesc[1] = *myg_toc;
kfp->fdesc[2] = 0;
#ifdef __XCOFF64__
*(u_int64 **) kfp->fpp = kfp->fdesc;
#else
*(u_int **) kfp->fpp = kfp->fdesc;
#endif
return 0;
}
/*
* import_kvar - import a kernel variable that was mistakenly left
* off the exports list
*/
import_kvar(struct k_var * kvp, caddr_t * toc)
{
sym_t *sym;
int i, pri;
label_t jmpbuf;
switch (setjmpx(&jmpbuf)) {
case 0:
break;
default:
return EINVAL;
}
sym = sym_lookup(kvp->name, 0);
if (!sym) {
printf("\nimport: variable `%s' not found\n", kvp->name);
longjmpx(EINVAL);
}
/*
* look through the caller's TOC for the reference to his surrogate
* variable.
*/
while (*toc != kvp->varp)
++toc;
printf("import(%s): replacing my TOC at 0x%x: 0x%8x with 0x%8x\n",
kvp->name, toc, *toc, sym->n_value);
/*
* replace reference to surrogate with reference real
*/
pri = i_disable(INTMAX);
*toc = (caddr_t) sym->n_value;
i_enable(pri);
clrjmpx(&jmpbuf);
return 0;
}
/*
* Call vanilla syscalls
*/
#ifndef AFS_AIX51_ENV
osetgroups(ngroups, gidset)
int ngroups;
gid_t *gidset;
{
int error;
error = setgroups(ngroups, gidset);
return (error);
}
#endif
#ifdef AFS_AIX51_ENV
#ifdef AFS_64BIT_KERNEL
okioctl(fdes, cmd, arg, ext, arg2, arg3)
#else /* AFS_64BIT_KERNEL */
okioctl32(fdes, cmd, arg, ext, arg2, arg3)
#endif /* AFS_64BIT_KERNEL */
int fdes, cmd;
caddr_t ext, arg, arg2, arg3;
#else
okioctl(fdes, cmd, arg, ext)
int fdes, cmd, arg;
caddr_t ext;
#endif
{
int error;
#ifdef AFS_AIX51_ENV
#ifdef AFS_64BIT_KERNEL
error = kioctl(fdes, cmd, arg, ext, arg2, arg3);
#else /* AFS_64BIT_KERNEL */
error = kioctl32(fdes, cmd, arg, ext, arg2, arg3);
#endif /* AFS_64BIT_KERNEL */
#else
error = kioctl(fdes, cmd, arg, ext);
#endif
return (error);
}
#ifdef notdef
ocore(signo, sigctx)
char signo;
struct sigcontext *sigctx;
{
int error;
#include <sys/user.h>
u.u_sigflags[signo] |= SA_FULLDUMP; /* XXX */
error = core(signo, sigctx);
return (error);
}
#endif