2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * export - EXPORT kernel extension
14 /* Unsafe: conflicts with _KERNEL inclusion of headers below */
15 /* #include <afs/param.h> */
16 /* #include <afsconfig.h> */
17 /* RCSID("$Header$"); */
20 #include "sys/types.h"
23 #include "sys/errno.h"
24 #include "sys/device.h"
27 #include "sys/malloc.h"
33 sym_t *toc_syms; /* symbol table */
34 int toc_nsyms; /* # of symbols */
35 caddr_t toc_strs; /* string table */
36 int toc_size; /* size of toc_syms */
39 * export - entry point to EXPORT kernel extension
42 * cmd - add/delete command
43 * uiop - uio vector describing any config params
51 monster = lockl(&kernel_lock, LOCK_SHORT);
54 case CFG_INIT: /* add EXPORT */
55 if (err = config(uiop))
59 case CFG_TERM: /* remove EXPORT */
60 if (err = export_cleanup())
69 if (monster != LOCK_NEST)
70 unlockl(&kernel_lock);
76 * config - process configuration data
79 register struct uio *uiop; {
81 register struct export_nl *np;
85 if (err = uiomove((char *)&conf, sizeof (conf), UIO_WRITE, uiop))
88 toc_nsyms = conf.nsyms;
89 toc_size = conf.symt_sz + conf.str_sz;
91 if (toc_nsyms * sizeof (sym_t) != conf.symt_sz
92 || toc_size > (1024 * 1024))
99 toc_syms = (sym_t *) xmalloc(toc_size, 2, kernel_heap);
104 toc_strs = (char *) &toc_syms[toc_nsyms];
107 * copy in the symbol table and the string table
109 if (err = copyin(conf.symtab, toc_syms, conf.symt_sz)
110 || (err = copyin(conf.strtab, toc_strs, conf.str_sz))) {
111 xmfree(toc_syms, kernel_heap);
117 * `TOC' format in kernel has offsets relocated to point directly
118 * into the string table.
120 for (sym = toc_syms; sym < &toc_syms[toc_nsyms]; ++sym)
122 if (sym->n_zeroes == 0)
124 sym->n_nptr = sym->n_offset + toc_strs;
130 * export_cleanup - cleanup EXPORT prior to removing kernel extension
135 * get rid of the symbol table
138 xmfree(toc_syms, kernel_heap);
148 * import_kfunc - import a kernel function that was mistakenly left
149 * off the exports list
152 * We are assuming that the functions we are importing from the
153 * kernel really are within the kernel. If they are actually
154 * exported from some other kernel extension (but referenced in
155 * the /unix symbol table) we are in trouble.
163 import_kfunc(struct k_func *kfp) {
167 static caddr_t *g_toc;
172 sym = sym_lookup("ktoc", 0);
174 sym = sym_lookup("g_toc", 0);
177 printf("\nimport: can't ascertain kernel's TOC\n");
180 myg_toc = sym->n_value;
183 sym = sym_lookup(kfp->name, 0);
185 printf("\nimport: function `%s' not found\n", kfp->name);
189 kfp->fdesc[0] = sym->n_value;
190 kfp->fdesc[1] = *myg_toc;
194 *(u_int64**) kfp->fpp = kfp->fdesc;
196 *(u_int **) kfp->fpp = kfp->fdesc;
203 * import_kvar - import a kernel variable that was mistakenly left
204 * off the exports list
206 import_kvar(struct k_var *kvp, caddr_t *toc) {
211 switch (setjmpx(&jmpbuf)) {
219 sym = sym_lookup(kvp->name, 0);
221 printf("\nimport: variable `%s' not found\n", kvp->name);
226 * look through the caller's TOC for the reference to his surrogate
229 while (*toc != kvp->varp)
232 printf("import(%s): replacing my TOC at 0x%x: 0x%8x with 0x%8x\n"
233 , kvp->name, toc, *toc, sym->n_value);
236 * replace reference to surrogate with reference real
238 pri = i_disable(INTMAX);
239 *toc = (caddr_t) sym->n_value;
249 * Call vanilla syscalls
251 #ifndef AFS_AIX51_ENV
252 osetgroups(ngroups, gidset)
258 error = setgroups(ngroups, gidset);
264 #ifdef AFS_64BIT_KERNEL
265 okioctl(fdes, cmd, arg, ext, arg2, arg3)
266 #else /* AFS_64BIT_KERNEL */
267 okioctl32(fdes, cmd, arg, ext, arg2, arg3)
268 #endif /* AFS_64BIT_KERNEL */
270 caddr_t ext, arg, arg2, arg3;
272 okioctl(fdes, cmd, arg, ext)
280 #ifdef AFS_64BIT_KERNEL
281 error = kioctl(fdes, cmd, arg, ext, arg2, arg3);
282 #else /* AFS_64BIT_KERNEL */
283 error = kioctl32(fdes, cmd, arg, ext, arg2, arg3);
284 #endif /* AFS_64BIT_KERNEL */
286 error = kioctl(fdes, cmd, arg, ext);
294 struct sigcontext *sigctx;
297 #include <sys/user.h>
298 u.u_sigflags[signo] |= SA_FULLDUMP; /* XXX */
299 error = core(signo, sigctx);