Deleted Added
sdiff udiff text old ( 38764 ) new ( 39178 )
full compact
1/*-
2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
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 * $Id: module.c,v 1.2 1998/08/31 21:10:42 msmith Exp $
27 */
28
29/*
30 * module function dispatcher, support, etc.
31 *
32 * XXX need a 'searchmodule' function that takes a name and
33 * traverses a search path.
34 */
35
36#include <stand.h>
37#include <string.h>
38
39#include "bootstrap.h"
40
41static struct loaded_module *mod_loadmodule(char *name, int argc, char *argv[]);
42static char *mod_searchdep(struct loaded_module *mp);
43static char *mod_searchmodule(char *name);
44static void mod_append(struct loaded_module *mp);
45
46/* XXX load address should be tweaked by first module loaded (kernel) */
47static vm_offset_t loadaddr = 0;
48
49struct loaded_module *loaded_modules = NULL;
50
51/*
52 * load an object, either a disk file or code module.
53 *
54 * To load a file, the syntax is:
55 *
56 * load -t <type> <path>

--- 169 unchanged lines hidden (view full) ---

226 vm_offset_t laddr;
227
228 /* We can't load first */
229 if ((mod_findmodule(NULL, NULL)) == NULL) {
230 command_errmsg = "can't load file before kernel";
231 return(CMD_ERROR);
232 }
233
234 /* Try to come up with a fully-qualified name if we don't have one */
235 if ((cp = mod_searchmodule(name)) != NULL)
236 name = cp;
237
238 if ((fd = open(name, O_RDONLY)) < 0) {
239 sprintf(command_errbuf, "can't open '%s': %s", name, strerror(errno));
240 return(CMD_ERROR);
241 }
242
243 laddr = loadaddr;
244 for (;;) {

--- 32 unchanged lines hidden (view full) ---

277 */
278static struct loaded_module *
279mod_loadmodule(char *name, int argc, char *argv[])
280{
281 struct loaded_module *mp;
282 int i, err;
283 char *cp;
284
285 /* Try to come up with a fully-qualified name if we don't have one */
286 if ((cp = mod_searchmodule(name)) != NULL)
287 name = cp;
288 err = 0;
289 for (i = 0, mp = NULL; (module_formats[i] != NULL) && (mp == NULL); i++) {
290 if ((err = (module_formats[i]->l_load)(name, loadaddr, &mp)) != 0) {
291
292 /* Unknown to this handler? */
293 if (err == EFTYPE)
294 continue;
295

--- 121 unchanged lines hidden (view full) ---

417
418 for (md = mp->m_metadata; md != NULL; md = md->md_next)
419 if (md->md_type == type)
420 break;
421 return(md);
422}
423
424/*
425 * Attempt to locate a kernel module file for the module (name).
426 * If (name) is qualified in any way, we simply check it and
427 * return it or NULL. If it is not qualified, then we attempt
428 * to construct a path using entries in the environment variable
429 * module_path.
430 *
431 * The path we return a pointer to need never be freed, as we manage
432 * it internally.
433 */
434static char *
435mod_searchmodule(char *name)
436{
437 static char *result = NULL;
438 static char *defpath = "/boot", *path;
439 char *cp, *sp;
440 struct stat sb;
441
442 /* Don't look for nothing */
443 if ((name == NULL) || (*name == 0))
444 return(name);
445
446 /*

--- 6 unchanged lines hidden (view full) ---

453 return(name);
454 return(NULL);
455 }
456
457 /*
458 * Get the module path
459 */
460 if ((cp = getenv("module_path")) == NULL)
461 cp = defpath;
462 sp = path = strdup(cp);
463
464 /*
465 * Traverse the path, splitting off ';'-delimited components.
466 */
467 if (result != NULL)
468 free(result);
469 while((cp = strsep(&path, ";")) != NULL) {
470 result = malloc(strlen(cp) + strlen(name) + 2);
471 sprintf(result, "%s/%s", cp, name);
472 if (stat(result, &sb) == 0)
473 break;
474 free(result);
475 result = NULL;
476 }
477 free(sp);
478 return(result);
479}
480
481/*
482 * Throw a module away
483 */
484void
485mod_discard(struct loaded_module *mp)
486{
487 struct module_metadata *md;
488
489 while (mp->m_metadata != NULL) {
490 md = mp->m_metadata;
491 mp->m_metadata = mp->m_metadata->md_next;
492 free(md);
493 }
494 if (mp->m_name != NULL)
495 free(mp->m_name);
496 if (mp->m_type != NULL)
497 free(mp->m_type);
498 if (mp->m_args != NULL)
499 free(mp->m_args);
500 free(mp);
501}
502
503/*
504 * Add a module to the chain
505 */
506static void
507mod_append(struct loaded_module *mp)
508{
509 struct loaded_module *cm;
510
511 /* Append to list of loaded modules */
512 mp->m_next = NULL;
513 if (loaded_modules == NULL) {
514 loaded_modules = mp;
515 } else {
516 for (cm = loaded_modules; cm->m_next != NULL; cm = cm->m_next)
517 ;
518 cm->m_next = mp;
519 }
520}