kern_module.c (92547) | kern_module.c (98835) |
---|---|
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 92547 2002-03-18 07:45:30Z arr $ | 26 * $FreeBSD: head/sys/kern/kern_module.c 98835 2002-06-26 00:31:44Z arr $ |
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> --- 216 unchanged lines hidden (view full) --- 251 * MPSAFE 252 */ 253int 254modnext(struct thread *td, struct modnext_args *uap) 255{ 256 module_t mod; 257 int error = 0; 258 | 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> --- 216 unchanged lines hidden (view full) --- 251 * MPSAFE 252 */ 253int 254modnext(struct thread *td, struct modnext_args *uap) 255{ 256 module_t mod; 257 int error = 0; 258 |
259 mtx_lock(&Giant); 260 | |
261 td->td_retval[0] = -1; | 259 td->td_retval[0] = -1; |
260 |
|
262 MOD_SLOCK; 263 if (SCARG(uap, modid) == 0) { 264 mod = TAILQ_FIRST(&modules); 265 if (mod) 266 td->td_retval[0] = mod->id; 267 else 268 error = ENOENT; 269 goto done2; --- 4 unchanged lines hidden (view full) --- 274 goto done2; 275 } 276 if (TAILQ_NEXT(mod, link)) 277 td->td_retval[0] = TAILQ_NEXT(mod, link)->id; 278 else 279 td->td_retval[0] = 0; 280done2: 281 MOD_SUNLOCK; | 261 MOD_SLOCK; 262 if (SCARG(uap, modid) == 0) { 263 mod = TAILQ_FIRST(&modules); 264 if (mod) 265 td->td_retval[0] = mod->id; 266 else 267 error = ENOENT; 268 goto done2; --- 4 unchanged lines hidden (view full) --- 273 goto done2; 274 } 275 if (TAILQ_NEXT(mod, link)) 276 td->td_retval[0] = TAILQ_NEXT(mod, link)->id; 277 else 278 td->td_retval[0] = 0; 279done2: 280 MOD_SUNLOCK; |
282 mtx_unlock(&Giant); | |
283 return (error); 284} 285 286/* 287 * MPSAFE 288 */ 289int 290modfnext(struct thread *td, struct modfnext_args *uap) 291{ 292 module_t mod; 293 int error; 294 295 td->td_retval[0] = -1; 296 | 281 return (error); 282} 283 284/* 285 * MPSAFE 286 */ 287int 288modfnext(struct thread *td, struct modfnext_args *uap) 289{ 290 module_t mod; 291 int error; 292 293 td->td_retval[0] = -1; 294 |
297 mtx_lock(&Giant); 298 | |
299 MOD_SLOCK; 300 mod = module_lookupbyid(SCARG(uap, modid)); 301 if (mod == NULL) { 302 error = ENOENT; 303 } else { 304 error = 0; 305 if (TAILQ_NEXT(mod, flink)) 306 td->td_retval[0] = TAILQ_NEXT(mod, flink)->id; 307 else 308 td->td_retval[0] = 0; 309 } 310 MOD_SUNLOCK; | 295 MOD_SLOCK; 296 mod = module_lookupbyid(SCARG(uap, modid)); 297 if (mod == NULL) { 298 error = ENOENT; 299 } else { 300 error = 0; 301 if (TAILQ_NEXT(mod, flink)) 302 td->td_retval[0] = TAILQ_NEXT(mod, flink)->id; 303 else 304 td->td_retval[0] = 0; 305 } 306 MOD_SUNLOCK; |
311 mtx_unlock(&Giant); | |
312 return (error); 313} 314 315struct module_stat_v1 { 316 int version; /* set to sizeof(struct module_stat) */ 317 char name[MAXMODNAME]; 318 int refs; 319 int id; --- 7 unchanged lines hidden (view full) --- 327{ 328 module_t mod; 329 modspecific_t data; 330 int error = 0; 331 int id, namelen, refs, version; 332 struct module_stat *stat; 333 char *name; 334 | 307 return (error); 308} 309 310struct module_stat_v1 { 311 int version; /* set to sizeof(struct module_stat) */ 312 char name[MAXMODNAME]; 313 int refs; 314 int id; --- 7 unchanged lines hidden (view full) --- 322{ 323 module_t mod; 324 modspecific_t data; 325 int error = 0; 326 int id, namelen, refs, version; 327 struct module_stat *stat; 328 char *name; 329 |
335 mtx_lock(&Giant); 336 | |
337 MOD_SLOCK; 338 mod = module_lookupbyid(SCARG(uap, modid)); 339 if (mod == NULL) { 340 MOD_SUNLOCK; | 330 MOD_SLOCK; 331 mod = module_lookupbyid(SCARG(uap, modid)); 332 if (mod == NULL) { 333 MOD_SUNLOCK; |
341 error = ENOENT; 342 goto out; | 334 return (ENOENT); |
343 } 344 id = mod->id; 345 refs = mod->refs; 346 name = mod->name; 347 data = mod->data; 348 MOD_SUNLOCK; 349 stat = SCARG(uap, stat); 350 351 /* 352 * Check the version of the user's structure. 353 */ 354 if ((error = copyin(&stat->version, &version, sizeof(version))) != 0) | 335 } 336 id = mod->id; 337 refs = mod->refs; 338 name = mod->name; 339 data = mod->data; 340 MOD_SUNLOCK; 341 stat = SCARG(uap, stat); 342 343 /* 344 * Check the version of the user's structure. 345 */ 346 if ((error = copyin(&stat->version, &version, sizeof(version))) != 0) |
355 goto out; | 347 return (error); |
356 if (version != sizeof(struct module_stat_v1) | 348 if (version != sizeof(struct module_stat_v1) |
357 && version != sizeof(struct module_stat)) { 358 error = EINVAL; 359 goto out; 360 } | 349 && version != sizeof(struct module_stat)) 350 return (EINVAL); |
361 namelen = strlen(mod->name) + 1; 362 if (namelen > MAXMODNAME) 363 namelen = MAXMODNAME; 364 if ((error = copyout(name, &stat->name[0], namelen)) != 0) | 351 namelen = strlen(mod->name) + 1; 352 if (namelen > MAXMODNAME) 353 namelen = MAXMODNAME; 354 if ((error = copyout(name, &stat->name[0], namelen)) != 0) |
365 goto out; | 355 return (error); |
366 367 if ((error = copyout(&refs, &stat->refs, sizeof(int))) != 0) | 356 357 if ((error = copyout(&refs, &stat->refs, sizeof(int))) != 0) |
368 goto out; | 358 return (error); |
369 if ((error = copyout(&id, &stat->id, sizeof(int))) != 0) | 359 if ((error = copyout(&id, &stat->id, sizeof(int))) != 0) |
370 goto out; | 360 return (error); |
371 372 /* 373 * >v1 stat includes module data. 374 */ | 361 362 /* 363 * >v1 stat includes module data. 364 */ |
375 if (version == sizeof(struct module_stat)) { | 365 if (version == sizeof(struct module_stat)) |
376 if ((error = copyout(&data, &stat->data, 377 sizeof(data))) != 0) | 366 if ((error = copyout(&data, &stat->data, 367 sizeof(data))) != 0) |
378 goto out; 379 } | 368 return (error); |
380 td->td_retval[0] = 0; | 369 td->td_retval[0] = 0; |
381out: 382 mtx_unlock(&Giant); | |
383 return (error); 384} 385 386/* 387 * MPSAFE 388 */ 389int 390modfind(struct thread *td, struct modfind_args *uap) 391{ 392 int error = 0; 393 char name[MAXMODNAME]; 394 module_t mod; 395 396 if ((error = copyinstr(SCARG(uap, name), name, sizeof name, 0)) != 0) | 370 return (error); 371} 372 373/* 374 * MPSAFE 375 */ 376int 377modfind(struct thread *td, struct modfind_args *uap) 378{ 379 int error = 0; 380 char name[MAXMODNAME]; 381 module_t mod; 382 383 if ((error = copyinstr(SCARG(uap, name), name, sizeof name, 0)) != 0) |
397 goto out; | 384 return (error); |
398 | 385 |
399 mtx_lock(&Giant); | |
400 MOD_SLOCK; 401 mod = module_lookupbyname(name); 402 if (mod == NULL) 403 error = ENOENT; 404 else 405 td->td_retval[0] = module_getid(mod); 406 MOD_SUNLOCK; | 386 MOD_SLOCK; 387 mod = module_lookupbyname(name); 388 if (mod == NULL) 389 error = ENOENT; 390 else 391 td->td_retval[0] = module_getid(mod); 392 MOD_SUNLOCK; |
407 mtx_unlock(&Giant); 408out: | |
409 return (error); 410} | 393 return (error); 394} |