kern_module.c (71999) | kern_module.c (82749) |
---|---|
1/*- 2 * Copyright (c) 1997 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 1997 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/kern/kern_module.c 71999 2001-02-04 13:13:25Z phk $ | 26 * $FreeBSD: head/sys/kern/kern_module.c 82749 2001-09-01 19:04:37Z dillon $ |
27 */ 28 29#include <sys/param.h> 30#include <sys/kernel.h> 31#include <sys/systm.h> 32#include <sys/eventhandler.h> 33#include <sys/malloc.h> 34#include <sys/sysproto.h> 35#include <sys/sysent.h> 36#include <sys/module.h> 37#include <sys/linker.h> 38#include <sys/proc.h> | 27 */ 28 29#include <sys/param.h> 30#include <sys/kernel.h> 31#include <sys/systm.h> 32#include <sys/eventhandler.h> 33#include <sys/malloc.h> 34#include <sys/sysproto.h> 35#include <sys/sysent.h> 36#include <sys/module.h> 37#include <sys/linker.h> 38#include <sys/proc.h> |
39#include <sys/lock.h> 40#include <sys/mutex.h> |
|
39 40static MALLOC_DEFINE(M_MODULE, "module", "module data structures"); 41 42typedef TAILQ_HEAD(, module) modulelist_t; 43struct module { 44 TAILQ_ENTRY(module) link; /* chain together all modules */ 45 TAILQ_ENTRY(module) flink; /* all modules in a file */ 46 struct linker_file* file; /* file which contains this module */ --- 164 unchanged lines hidden (view full) --- 211module_setspecific(module_t mod, modspecific_t *datap) 212{ 213 mod->data = *datap; 214} 215 216/* 217 * Syscalls. 218 */ | 41 42static MALLOC_DEFINE(M_MODULE, "module", "module data structures"); 43 44typedef TAILQ_HEAD(, module) modulelist_t; 45struct module { 46 TAILQ_ENTRY(module) link; /* chain together all modules */ 47 TAILQ_ENTRY(module) flink; /* all modules in a file */ 48 struct linker_file* file; /* file which contains this module */ --- 164 unchanged lines hidden (view full) --- 213module_setspecific(module_t mod, modspecific_t *datap) 214{ 215 mod->data = *datap; 216} 217 218/* 219 * Syscalls. 220 */ |
221/* 222 * MPSAFE 223 */ |
|
219int 220modnext(struct proc* p, struct modnext_args* uap) 221{ 222 module_t mod; | 224int 225modnext(struct proc* p, struct modnext_args* uap) 226{ 227 module_t mod; |
228 int error = 0; |
|
223 | 229 |
230 mtx_lock(&Giant); 231 |
|
224 p->p_retval[0] = -1; 225 if (SCARG(uap, modid) == 0) { 226 mod = TAILQ_FIRST(&modules); | 232 p->p_retval[0] = -1; 233 if (SCARG(uap, modid) == 0) { 234 mod = TAILQ_FIRST(&modules); |
227 if (mod) { | 235 if (mod) |
228 p->p_retval[0] = mod->id; | 236 p->p_retval[0] = mod->id; |
229 return 0; 230 } else 231 return ENOENT; | 237 else 238 error = ENOENT; 239 goto done2; |
232 } 233 234 mod = module_lookupbyid(SCARG(uap, modid)); | 240 } 241 242 mod = module_lookupbyid(SCARG(uap, modid)); |
235 if (!mod) 236 return ENOENT; | 243 if (mod == NULL) { 244 error = ENOENT; 245 goto done2; 246 } |
237 238 if (TAILQ_NEXT(mod, link)) 239 p->p_retval[0] = TAILQ_NEXT(mod, link)->id; 240 else 241 p->p_retval[0] = 0; | 247 248 if (TAILQ_NEXT(mod, link)) 249 p->p_retval[0] = TAILQ_NEXT(mod, link)->id; 250 else 251 p->p_retval[0] = 0; |
242 return 0; | 252done2: 253 mtx_unlock(&Giant); 254 return (error); |
243} 244 | 255} 256 |
257/* 258 * MPSAFE 259 */ |
|
245int 246modfnext(struct proc* p, struct modfnext_args* uap) 247{ 248 module_t mod; | 260int 261modfnext(struct proc* p, struct modfnext_args* uap) 262{ 263 module_t mod; |
264 int error; |
|
249 250 p->p_retval[0] = -1; 251 | 265 266 p->p_retval[0] = -1; 267 |
252 mod = module_lookupbyid(SCARG(uap, modid)); 253 if (!mod) 254 return ENOENT; | 268 mtx_lock(&Giant); |
255 | 269 |
256 if (TAILQ_NEXT(mod, flink)) 257 p->p_retval[0] = TAILQ_NEXT(mod, flink)->id; 258 else 259 p->p_retval[0] = 0; 260 return 0; | 270 mod = module_lookupbyid(SCARG(uap, modid)); 271 if (mod == NULL) { 272 error = ENOENT; 273 } else { 274 error = 0; 275 if (TAILQ_NEXT(mod, flink)) 276 p->p_retval[0] = TAILQ_NEXT(mod, flink)->id; 277 else 278 p->p_retval[0] = 0; 279 } 280 mtx_unlock(&Giant); 281 return (error); |
261} 262 263struct module_stat_v1 { 264 int version; /* set to sizeof(struct module_stat) */ 265 char name[MAXMODNAME]; 266 int refs; 267 int id; 268}; 269 | 282} 283 284struct module_stat_v1 { 285 int version; /* set to sizeof(struct module_stat) */ 286 char name[MAXMODNAME]; 287 int refs; 288 int id; 289}; 290 |
291/* 292 * MPSAFE 293 */ |
|
270int 271modstat(struct proc* p, struct modstat_args* uap) 272{ 273 module_t mod; 274 int error = 0; 275 int namelen; 276 int version; 277 struct module_stat* stat; 278 | 294int 295modstat(struct proc* p, struct modstat_args* uap) 296{ 297 module_t mod; 298 int error = 0; 299 int namelen; 300 int version; 301 struct module_stat* stat; 302 |
303 mtx_lock(&Giant); 304 |
|
279 mod = module_lookupbyid(SCARG(uap, modid)); | 305 mod = module_lookupbyid(SCARG(uap, modid)); |
280 if (!mod) 281 return ENOENT; | 306 if (mod == NULL) { 307 error = ENOENT; 308 goto out; 309 } |
282 283 stat = SCARG(uap, stat); 284 285 /* 286 * Check the version of the user's structure. 287 */ 288 if ((error = copyin(&stat->version, &version, sizeof(version))) != 0) 289 goto out; --- 20 unchanged lines hidden (view full) --- 310 if (version == sizeof(struct module_stat)) { 311 if ((error = copyout(&mod->data, &stat->data, sizeof(mod->data))) != 0) 312 goto out; 313 } 314 315 p->p_retval[0] = 0; 316 317out: | 310 311 stat = SCARG(uap, stat); 312 313 /* 314 * Check the version of the user's structure. 315 */ 316 if ((error = copyin(&stat->version, &version, sizeof(version))) != 0) 317 goto out; --- 20 unchanged lines hidden (view full) --- 338 if (version == sizeof(struct module_stat)) { 339 if ((error = copyout(&mod->data, &stat->data, sizeof(mod->data))) != 0) 340 goto out; 341 } 342 343 p->p_retval[0] = 0; 344 345out: |
346 mtx_unlock(&Giant); |
|
318 return error; 319} 320 | 347 return error; 348} 349 |
350/* 351 * MPSAFE 352 */ |
|
321int 322modfind(struct proc* p, struct modfind_args* uap) 323{ 324 int error = 0; 325 char name[MAXMODNAME]; 326 module_t mod; 327 328 if ((error = copyinstr(SCARG(uap, name), name, sizeof name, 0)) != 0) 329 goto out; 330 | 353int 354modfind(struct proc* p, struct modfind_args* uap) 355{ 356 int error = 0; 357 char name[MAXMODNAME]; 358 module_t mod; 359 360 if ((error = copyinstr(SCARG(uap, name), name, sizeof name, 0)) != 0) 361 goto out; 362 |
363 mtx_lock(&Giant); |
|
331 mod = module_lookupbyname(name); | 364 mod = module_lookupbyname(name); |
332 if (!mod) | 365 if (mod == NULL) |
333 error = ENOENT; 334 else 335 p->p_retval[0] = mod->id; | 366 error = ENOENT; 367 else 368 p->p_retval[0] = mod->id; |
336 | 369 mtx_unlock(&Giant); |
337out: 338 return error; 339} | 370out: 371 return error; 372} |