2017-06-01 05:45:05 +03:00
|
|
|
/* $NetBSD: subr_kobj.c,v 1.62 2017/06/01 02:45:13 chs Exp $ */
|
2008-01-04 15:26:20 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2008-11-12 15:35:50 +03:00
|
|
|
* This code is derived from software developed for The NetBSD Foundation
|
|
|
|
* by Andrew Doran.
|
|
|
|
*
|
2008-01-04 15:26:20 +03:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998-2000 Doug Rabson
|
|
|
|
* Copyright (c) 2004 Peter Wemm
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kernel loader for ELF objects.
|
|
|
|
*
|
|
|
|
* TODO: adjust kmem_alloc() calls to avoid needless fragmentation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2017-06-01 05:45:05 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.62 2017/06/01 02:45:13 chs Exp $");
|
2009-02-14 01:41:00 +03:00
|
|
|
|
2015-08-25 01:50:32 +03:00
|
|
|
#ifdef _KERNEL_OPT
|
2009-02-14 01:41:00 +03:00
|
|
|
#include "opt_modular.h"
|
2015-08-25 01:50:32 +03:00
|
|
|
#endif
|
2008-01-04 15:26:20 +03:00
|
|
|
|
2009-05-24 19:00:24 +04:00
|
|
|
#include <sys/kobj_impl.h>
|
2008-05-04 16:51:44 +04:00
|
|
|
|
|
|
|
#ifdef MODULAR
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2008-01-04 15:26:20 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/kmem.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/ksyms.h>
|
2008-11-12 15:35:50 +03:00
|
|
|
#include <sys/module.h>
|
2008-01-04 15:26:20 +03:00
|
|
|
|
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
2014-07-06 19:22:31 +04:00
|
|
|
#define kobj_error(_kobj, ...) \
|
|
|
|
kobj_out(__func__, __LINE__, _kobj, __VA_ARGS__)
|
|
|
|
|
2008-05-20 17:34:44 +04:00
|
|
|
static int kobj_relocate(kobj_t, bool);
|
2008-11-16 19:23:58 +03:00
|
|
|
static int kobj_checksyms(kobj_t, bool);
|
2014-07-06 19:22:31 +04:00
|
|
|
static void kobj_out(const char *, int, kobj_t, const char *, ...)
|
2011-08-14 01:04:05 +04:00
|
|
|
__printflike(4, 5);
|
2008-05-20 17:34:44 +04:00
|
|
|
static void kobj_jettison(kobj_t);
|
2008-05-01 18:44:48 +04:00
|
|
|
static void kobj_free(kobj_t, void *, size_t);
|
2008-05-20 17:34:44 +04:00
|
|
|
static void kobj_close(kobj_t);
|
2009-11-27 20:54:11 +03:00
|
|
|
static int kobj_read_mem(kobj_t, void **, size_t, off_t, bool);
|
|
|
|
static void kobj_close_mem(kobj_t);
|
2008-01-04 15:26:20 +03:00
|
|
|
|
2008-11-12 15:35:50 +03:00
|
|
|
extern struct vm_map *module_map;
|
2008-01-04 15:26:20 +03:00
|
|
|
|
2008-01-06 17:47:26 +03:00
|
|
|
/*
|
2008-05-20 17:34:44 +04:00
|
|
|
* kobj_load_mem:
|
2008-01-06 17:47:26 +03:00
|
|
|
*
|
2008-05-20 17:34:44 +04:00
|
|
|
* Load an object already resident in memory. If size is not -1,
|
|
|
|
* the complete size of the object is known.
|
2008-01-06 17:47:26 +03:00
|
|
|
*/
|
|
|
|
int
|
2011-08-14 01:04:05 +04:00
|
|
|
kobj_load_mem(kobj_t *kop, const char *name, void *base, ssize_t size)
|
2008-01-06 17:47:26 +03:00
|
|
|
{
|
|
|
|
kobj_t ko;
|
|
|
|
|
|
|
|
ko = kmem_zalloc(sizeof(*ko), KM_SLEEP);
|
|
|
|
ko->ko_type = KT_MEMORY;
|
2011-08-14 01:04:05 +04:00
|
|
|
kobj_setname(ko, name);
|
2008-01-06 17:47:26 +03:00
|
|
|
ko->ko_source = base;
|
|
|
|
ko->ko_memsize = size;
|
2009-11-27 20:54:11 +03:00
|
|
|
ko->ko_read = kobj_read_mem;
|
|
|
|
ko->ko_close = kobj_close_mem;
|
|
|
|
|
2008-01-06 17:47:26 +03:00
|
|
|
*kop = ko;
|
2008-05-20 17:34:44 +04:00
|
|
|
return kobj_load(ko);
|
2008-01-06 17:47:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kobj_close:
|
|
|
|
*
|
2008-05-20 17:34:44 +04:00
|
|
|
* Close an open ELF object.
|
2008-01-06 17:47:26 +03:00
|
|
|
*/
|
2008-05-20 17:34:44 +04:00
|
|
|
static void
|
2008-01-06 17:47:26 +03:00
|
|
|
kobj_close(kobj_t ko)
|
|
|
|
{
|
|
|
|
|
2008-05-20 17:34:44 +04:00
|
|
|
if (ko->ko_source == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2008-01-06 17:47:26 +03:00
|
|
|
|
2009-11-27 20:54:11 +03:00
|
|
|
ko->ko_close(ko);
|
2008-01-06 17:47:26 +03:00
|
|
|
ko->ko_source = NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-27 20:54:11 +03:00
|
|
|
static void
|
|
|
|
kobj_close_mem(kobj_t ko)
|
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-06 17:47:26 +03:00
|
|
|
/*
|
|
|
|
* kobj_load:
|
|
|
|
*
|
2008-05-20 17:34:44 +04:00
|
|
|
* Load an ELF object and prepare to link into the running kernel
|
|
|
|
* image.
|
2008-01-06 17:47:26 +03:00
|
|
|
*/
|
2009-11-27 20:54:11 +03:00
|
|
|
int
|
2008-01-06 17:47:26 +03:00
|
|
|
kobj_load(kobj_t ko)
|
|
|
|
{
|
|
|
|
Elf_Ehdr *hdr;
|
|
|
|
Elf_Shdr *shdr;
|
|
|
|
Elf_Sym *es;
|
2016-07-09 10:25:00 +03:00
|
|
|
vaddr_t map_text_base;
|
|
|
|
vaddr_t map_data_base;
|
2016-07-20 16:36:19 +03:00
|
|
|
vaddr_t map_rodata_base;
|
2016-07-09 10:25:00 +03:00
|
|
|
size_t map_text_size;
|
|
|
|
size_t map_data_size;
|
2016-07-20 16:36:19 +03:00
|
|
|
size_t map_rodata_size;
|
2008-01-06 17:47:26 +03:00
|
|
|
int error;
|
|
|
|
int symtabindex;
|
|
|
|
int symstrindex;
|
|
|
|
int nsym;
|
|
|
|
int pb, rl, ra;
|
|
|
|
int alignmask;
|
|
|
|
int i, j;
|
2008-05-01 21:07:10 +04:00
|
|
|
void *addr;
|
2008-01-06 17:47:26 +03:00
|
|
|
|
|
|
|
KASSERT(ko->ko_type != KT_UNSET);
|
|
|
|
KASSERT(ko->ko_source != NULL);
|
|
|
|
|
|
|
|
shdr = NULL;
|
|
|
|
error = 0;
|
|
|
|
hdr = NULL;
|
|
|
|
|
2008-01-04 15:26:20 +03:00
|
|
|
/*
|
|
|
|
* Read the elf header from the file.
|
|
|
|
*/
|
2009-11-27 20:54:11 +03:00
|
|
|
error = ko->ko_read(ko, (void **)&hdr, sizeof(*hdr), 0, true);
|
2011-08-14 01:04:05 +04:00
|
|
|
if (error != 0) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "read failed %d", error);
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
2011-08-14 01:04:05 +04:00
|
|
|
}
|
2008-01-04 15:26:20 +03:00
|
|
|
if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "not an ELF object");
|
2008-01-04 15:26:20 +03:00
|
|
|
error = ENOEXEC;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hdr->e_ident[EI_VERSION] != EV_CURRENT ||
|
|
|
|
hdr->e_version != EV_CURRENT) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "unsupported file version %d",
|
|
|
|
hdr->e_ident[EI_VERSION]);
|
2008-01-04 15:26:20 +03:00
|
|
|
error = ENOEXEC;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (hdr->e_type != ET_REL) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "unsupported file type %d", hdr->e_type);
|
2008-01-04 15:26:20 +03:00
|
|
|
error = ENOEXEC;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
switch (hdr->e_machine) {
|
|
|
|
#if ELFSIZE == 32
|
|
|
|
ELF32_MACHDEP_ID_CASES
|
2011-01-18 11:15:51 +03:00
|
|
|
#elif ELFSIZE == 64
|
2008-01-04 15:26:20 +03:00
|
|
|
ELF64_MACHDEP_ID_CASES
|
2011-01-18 11:15:51 +03:00
|
|
|
#else
|
|
|
|
#error not defined
|
2008-01-04 15:26:20 +03:00
|
|
|
#endif
|
|
|
|
default:
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "unsupported machine %d", hdr->e_machine);
|
2008-01-04 15:26:20 +03:00
|
|
|
error = ENOEXEC;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ko->ko_nprogtab = 0;
|
|
|
|
ko->ko_shdr = 0;
|
|
|
|
ko->ko_nrel = 0;
|
|
|
|
ko->ko_nrela = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate and read in the section header.
|
|
|
|
*/
|
2014-07-09 09:50:51 +04:00
|
|
|
if (hdr->e_shnum == 0 || hdr->e_shnum > ELF_MAXSHNUM ||
|
|
|
|
hdr->e_shoff == 0 || hdr->e_shentsize != sizeof(Elf_Shdr)) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "bad sizes");
|
2008-01-04 15:26:20 +03:00
|
|
|
error = ENOEXEC;
|
|
|
|
goto out;
|
|
|
|
}
|
2014-07-09 09:50:51 +04:00
|
|
|
ko->ko_shdrsz = hdr->e_shnum * sizeof(Elf_Shdr);
|
2009-11-27 20:54:11 +03:00
|
|
|
error = ko->ko_read(ko, (void **)&shdr, ko->ko_shdrsz, hdr->e_shoff,
|
|
|
|
true);
|
2008-01-04 15:26:20 +03:00
|
|
|
if (error != 0) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "read failed %d", error);
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2008-05-01 18:44:48 +04:00
|
|
|
ko->ko_shdr = shdr;
|
2008-01-04 15:26:20 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the section header for information and table sizing.
|
|
|
|
*/
|
|
|
|
nsym = 0;
|
2014-07-06 19:35:32 +04:00
|
|
|
symtabindex = symstrindex = -1;
|
2008-01-04 15:26:20 +03:00
|
|
|
for (i = 0; i < hdr->e_shnum; i++) {
|
|
|
|
switch (shdr[i].sh_type) {
|
|
|
|
case SHT_PROGBITS:
|
|
|
|
case SHT_NOBITS:
|
|
|
|
ko->ko_nprogtab++;
|
|
|
|
break;
|
|
|
|
case SHT_SYMTAB:
|
|
|
|
nsym++;
|
|
|
|
symtabindex = i;
|
|
|
|
symstrindex = shdr[i].sh_link;
|
|
|
|
break;
|
|
|
|
case SHT_REL:
|
2013-08-09 09:10:14 +04:00
|
|
|
if (shdr[shdr[i].sh_info].sh_type != SHT_PROGBITS)
|
|
|
|
continue;
|
2008-01-04 15:26:20 +03:00
|
|
|
ko->ko_nrel++;
|
|
|
|
break;
|
|
|
|
case SHT_RELA:
|
2013-08-09 09:10:14 +04:00
|
|
|
if (shdr[shdr[i].sh_info].sh_type != SHT_PROGBITS)
|
|
|
|
continue;
|
2008-01-04 15:26:20 +03:00
|
|
|
ko->ko_nrela++;
|
|
|
|
break;
|
|
|
|
case SHT_STRTAB:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ko->ko_nprogtab == 0) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "file has no contents");
|
2008-01-04 15:26:20 +03:00
|
|
|
error = ENOEXEC;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (nsym != 1) {
|
|
|
|
/* Only allow one symbol table for now */
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "file has no valid symbol table");
|
2008-01-04 15:26:20 +03:00
|
|
|
error = ENOEXEC;
|
|
|
|
goto out;
|
|
|
|
}
|
2014-07-06 19:35:32 +04:00
|
|
|
KASSERT(symtabindex != -1);
|
2014-07-09 09:50:51 +04:00
|
|
|
KASSERT(symstrindex != -1);
|
|
|
|
|
|
|
|
if (symstrindex == SHN_UNDEF || symstrindex >= hdr->e_shnum ||
|
2008-01-04 15:26:20 +03:00
|
|
|
shdr[symstrindex].sh_type != SHT_STRTAB) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "file has invalid symbol strings");
|
2008-01-04 15:26:20 +03:00
|
|
|
error = ENOEXEC;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate space for tracking the load chunks.
|
|
|
|
*/
|
|
|
|
if (ko->ko_nprogtab != 0) {
|
|
|
|
ko->ko_progtab = kmem_zalloc(ko->ko_nprogtab *
|
|
|
|
sizeof(*ko->ko_progtab), KM_SLEEP);
|
|
|
|
if (ko->ko_progtab == NULL) {
|
|
|
|
error = ENOMEM;
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "out of memory");
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ko->ko_nrel != 0) {
|
|
|
|
ko->ko_reltab = kmem_zalloc(ko->ko_nrel *
|
|
|
|
sizeof(*ko->ko_reltab), KM_SLEEP);
|
|
|
|
if (ko->ko_reltab == NULL) {
|
|
|
|
error = ENOMEM;
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "out of memory");
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ko->ko_nrela != 0) {
|
|
|
|
ko->ko_relatab = kmem_zalloc(ko->ko_nrela *
|
|
|
|
sizeof(*ko->ko_relatab), KM_SLEEP);
|
|
|
|
if (ko->ko_relatab == NULL) {
|
|
|
|
error = ENOMEM;
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "out of memory");
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate space for and load the symbol table.
|
|
|
|
*/
|
|
|
|
ko->ko_symcnt = shdr[symtabindex].sh_size / sizeof(Elf_Sym);
|
|
|
|
if (ko->ko_symcnt == 0) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "no symbol table");
|
2014-07-09 09:50:51 +04:00
|
|
|
error = ENOEXEC;
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2009-11-27 20:54:11 +03:00
|
|
|
error = ko->ko_read(ko, (void **)&ko->ko_symtab,
|
2008-05-01 18:44:48 +04:00
|
|
|
ko->ko_symcnt * sizeof(Elf_Sym),
|
2009-11-27 20:54:11 +03:00
|
|
|
shdr[symtabindex].sh_offset, true);
|
2008-01-04 15:26:20 +03:00
|
|
|
if (error != 0) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "read failed %d", error);
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate space for and load the symbol strings.
|
|
|
|
*/
|
|
|
|
ko->ko_strtabsz = shdr[symstrindex].sh_size;
|
|
|
|
if (ko->ko_strtabsz == 0) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "no symbol strings");
|
2014-07-09 09:50:51 +04:00
|
|
|
error = ENOEXEC;
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2009-11-27 20:54:11 +03:00
|
|
|
error = ko->ko_read(ko, (void *)&ko->ko_strtab, ko->ko_strtabsz,
|
|
|
|
shdr[symstrindex].sh_offset, true);
|
2008-01-04 15:26:20 +03:00
|
|
|
if (error != 0) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "read failed %d", error);
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-04-27 02:58:53 +04:00
|
|
|
/*
|
|
|
|
* Adjust module symbol namespace, if necessary (e.g. with rump)
|
|
|
|
*/
|
|
|
|
error = kobj_renamespace(ko->ko_symtab, ko->ko_symcnt,
|
|
|
|
&ko->ko_strtab, &ko->ko_strtabsz);
|
|
|
|
if (error != 0) {
|
2014-07-16 17:26:33 +04:00
|
|
|
kobj_error(ko, "renamespace failed %d", error);
|
2010-04-27 02:58:53 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-01-13 02:34:48 +03:00
|
|
|
/*
|
|
|
|
* Do we have a string table for the section names?
|
|
|
|
*/
|
2014-07-09 09:50:51 +04:00
|
|
|
if (hdr->e_shstrndx != SHN_UNDEF) {
|
|
|
|
if (hdr->e_shstrndx >= hdr->e_shnum) {
|
|
|
|
kobj_error(ko, "bad shstrndx");
|
|
|
|
error = ENOEXEC;
|
2008-01-13 02:34:48 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2014-07-09 09:50:51 +04:00
|
|
|
if (shdr[hdr->e_shstrndx].sh_size != 0 &&
|
|
|
|
shdr[hdr->e_shstrndx].sh_type == SHT_STRTAB) {
|
|
|
|
ko->ko_shstrtabsz = shdr[hdr->e_shstrndx].sh_size;
|
|
|
|
error = ko->ko_read(ko, (void **)&ko->ko_shstrtab,
|
|
|
|
shdr[hdr->e_shstrndx].sh_size,
|
|
|
|
shdr[hdr->e_shstrndx].sh_offset, true);
|
|
|
|
if (error != 0) {
|
|
|
|
kobj_error(ko, "read failed %d", error);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2008-01-13 02:34:48 +03:00
|
|
|
}
|
|
|
|
|
2008-01-04 15:26:20 +03:00
|
|
|
/*
|
|
|
|
* Size up code/data(progbits) and bss(nobits).
|
|
|
|
*/
|
|
|
|
alignmask = 0;
|
2016-07-09 10:25:00 +03:00
|
|
|
map_text_size = 0;
|
|
|
|
map_data_size = 0;
|
2016-07-20 16:36:19 +03:00
|
|
|
map_rodata_size = 0;
|
2008-01-04 15:26:20 +03:00
|
|
|
for (i = 0; i < hdr->e_shnum; i++) {
|
2016-07-09 10:25:00 +03:00
|
|
|
if (shdr[i].sh_type != SHT_PROGBITS &&
|
|
|
|
shdr[i].sh_type != SHT_NOBITS)
|
|
|
|
continue;
|
|
|
|
alignmask = shdr[i].sh_addralign - 1;
|
|
|
|
if ((shdr[i].sh_flags & SHF_EXECINSTR)) {
|
|
|
|
map_text_size += alignmask;
|
|
|
|
map_text_size &= ~alignmask;
|
|
|
|
map_text_size += shdr[i].sh_size;
|
2016-07-20 16:36:19 +03:00
|
|
|
} else if (!(shdr[i].sh_flags & SHF_WRITE)) {
|
|
|
|
map_rodata_size += alignmask;
|
|
|
|
map_rodata_size &= ~alignmask;
|
|
|
|
map_rodata_size += shdr[i].sh_size;
|
2016-07-09 10:25:00 +03:00
|
|
|
} else {
|
|
|
|
map_data_size += alignmask;
|
|
|
|
map_data_size &= ~alignmask;
|
|
|
|
map_data_size += shdr[i].sh_size;
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-09 10:25:00 +03:00
|
|
|
if (map_text_size == 0) {
|
|
|
|
kobj_error(ko, "no text");
|
|
|
|
error = ENOEXEC;
|
|
|
|
goto out;
|
|
|
|
}
|
2016-08-01 18:41:05 +03:00
|
|
|
|
|
|
|
if (map_data_size != 0) {
|
|
|
|
map_data_base = uvm_km_alloc(module_map, round_page(map_data_size),
|
|
|
|
0, UVM_KMF_WIRED);
|
|
|
|
if (map_data_base == 0) {
|
|
|
|
kobj_error(ko, "out of memory");
|
|
|
|
error = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ko->ko_data_address = map_data_base;
|
|
|
|
ko->ko_data_size = map_data_size;
|
|
|
|
} else {
|
|
|
|
map_data_base = 0;
|
|
|
|
ko->ko_data_address = 0;
|
|
|
|
ko->ko_data_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map_rodata_size != 0) {
|
|
|
|
map_rodata_base = uvm_km_alloc(module_map, round_page(map_rodata_size),
|
|
|
|
0, UVM_KMF_WIRED);
|
|
|
|
if (map_rodata_base == 0) {
|
|
|
|
kobj_error(ko, "out of memory");
|
|
|
|
error = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ko->ko_rodata_address = map_rodata_base;
|
|
|
|
ko->ko_rodata_size = map_rodata_size;
|
|
|
|
} else {
|
|
|
|
map_rodata_base = 0;
|
|
|
|
ko->ko_rodata_address = 0;
|
|
|
|
ko->ko_rodata_size = 0;
|
|
|
|
}
|
2016-07-08 11:55:48 +03:00
|
|
|
|
2016-07-09 10:25:00 +03:00
|
|
|
map_text_base = uvm_km_alloc(module_map, round_page(map_text_size),
|
2016-07-08 11:55:48 +03:00
|
|
|
0, UVM_KMF_WIRED | UVM_KMF_EXEC);
|
2016-07-09 10:25:00 +03:00
|
|
|
if (map_text_base == 0) {
|
2016-07-08 11:55:48 +03:00
|
|
|
kobj_error(ko, "out of memory");
|
|
|
|
error = ENOMEM;
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2016-07-09 10:25:00 +03:00
|
|
|
ko->ko_text_address = map_text_base;
|
|
|
|
ko->ko_text_size = map_text_size;
|
2016-07-08 11:55:48 +03:00
|
|
|
|
2008-01-04 15:26:20 +03:00
|
|
|
/*
|
|
|
|
* Now load code/data(progbits), zero bss(nobits), allocate space
|
|
|
|
* for and load relocs
|
|
|
|
*/
|
|
|
|
pb = 0;
|
|
|
|
rl = 0;
|
|
|
|
ra = 0;
|
|
|
|
alignmask = 0;
|
|
|
|
for (i = 0; i < hdr->e_shnum; i++) {
|
|
|
|
switch (shdr[i].sh_type) {
|
|
|
|
case SHT_PROGBITS:
|
|
|
|
case SHT_NOBITS:
|
|
|
|
alignmask = shdr[i].sh_addralign - 1;
|
2016-07-09 10:25:00 +03:00
|
|
|
if ((shdr[i].sh_flags & SHF_EXECINSTR)) {
|
|
|
|
map_text_base += alignmask;
|
|
|
|
map_text_base &= ~alignmask;
|
|
|
|
addr = (void *)map_text_base;
|
|
|
|
map_text_base += shdr[i].sh_size;
|
2016-07-20 16:36:19 +03:00
|
|
|
} else if (!(shdr[i].sh_flags & SHF_WRITE)) {
|
|
|
|
map_rodata_base += alignmask;
|
|
|
|
map_rodata_base &= ~alignmask;
|
|
|
|
addr = (void *)map_rodata_base;
|
|
|
|
map_rodata_base += shdr[i].sh_size;
|
2016-07-09 10:25:00 +03:00
|
|
|
} else {
|
|
|
|
map_data_base += alignmask;
|
|
|
|
map_data_base &= ~alignmask;
|
|
|
|
addr = (void *)map_data_base;
|
|
|
|
map_data_base += shdr[i].sh_size;
|
|
|
|
}
|
2016-07-08 11:55:48 +03:00
|
|
|
|
2008-05-01 21:07:10 +04:00
|
|
|
ko->ko_progtab[pb].addr = addr;
|
2008-01-04 15:26:20 +03:00
|
|
|
if (shdr[i].sh_type == SHT_PROGBITS) {
|
|
|
|
ko->ko_progtab[pb].name = "<<PROGBITS>>";
|
2009-11-27 20:54:11 +03:00
|
|
|
error = ko->ko_read(ko, &addr,
|
|
|
|
shdr[i].sh_size, shdr[i].sh_offset, false);
|
2008-01-04 15:26:20 +03:00
|
|
|
if (error != 0) {
|
2014-07-16 17:26:33 +04:00
|
|
|
kobj_error(ko, "read failed %d", error);
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2016-07-08 11:55:48 +03:00
|
|
|
} else { /* SHT_NOBITS */
|
2008-01-04 15:26:20 +03:00
|
|
|
ko->ko_progtab[pb].name = "<<NOBITS>>";
|
2008-05-01 21:07:10 +04:00
|
|
|
memset(addr, 0, shdr[i].sh_size);
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
2016-07-08 11:55:48 +03:00
|
|
|
|
2008-01-04 15:26:20 +03:00
|
|
|
ko->ko_progtab[pb].size = shdr[i].sh_size;
|
|
|
|
ko->ko_progtab[pb].sec = i;
|
2008-01-13 02:34:48 +03:00
|
|
|
if (ko->ko_shstrtab != NULL && shdr[i].sh_name != 0) {
|
|
|
|
ko->ko_progtab[pb].name =
|
|
|
|
ko->ko_shstrtab + shdr[i].sh_name;
|
|
|
|
}
|
2008-01-04 15:26:20 +03:00
|
|
|
|
|
|
|
/* Update all symbol values with the offset. */
|
|
|
|
for (j = 0; j < ko->ko_symcnt; j++) {
|
|
|
|
es = &ko->ko_symtab[j];
|
|
|
|
if (es->st_shndx != i) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-05-01 21:07:10 +04:00
|
|
|
es->st_value += (Elf_Addr)addr;
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
pb++;
|
|
|
|
break;
|
|
|
|
case SHT_REL:
|
2013-08-09 09:10:14 +04:00
|
|
|
if (shdr[shdr[i].sh_info].sh_type != SHT_PROGBITS)
|
|
|
|
break;
|
2008-01-04 15:26:20 +03:00
|
|
|
ko->ko_reltab[rl].size = shdr[i].sh_size;
|
|
|
|
ko->ko_reltab[rl].size -=
|
|
|
|
shdr[i].sh_size % sizeof(Elf_Rel);
|
|
|
|
if (ko->ko_reltab[rl].size != 0) {
|
|
|
|
ko->ko_reltab[rl].nrel =
|
|
|
|
shdr[i].sh_size / sizeof(Elf_Rel);
|
|
|
|
ko->ko_reltab[rl].sec = shdr[i].sh_info;
|
2009-11-27 20:54:11 +03:00
|
|
|
error = ko->ko_read(ko,
|
2009-01-02 01:17:55 +03:00
|
|
|
(void **)&ko->ko_reltab[rl].rel,
|
2008-01-04 15:26:20 +03:00
|
|
|
ko->ko_reltab[rl].size,
|
2009-11-27 20:54:11 +03:00
|
|
|
shdr[i].sh_offset, true);
|
2008-01-04 15:26:20 +03:00
|
|
|
if (error != 0) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "read failed %d",
|
|
|
|
error);
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rl++;
|
|
|
|
break;
|
|
|
|
case SHT_RELA:
|
2013-08-09 09:10:14 +04:00
|
|
|
if (shdr[shdr[i].sh_info].sh_type != SHT_PROGBITS)
|
|
|
|
break;
|
2008-01-04 15:26:20 +03:00
|
|
|
ko->ko_relatab[ra].size = shdr[i].sh_size;
|
|
|
|
ko->ko_relatab[ra].size -=
|
|
|
|
shdr[i].sh_size % sizeof(Elf_Rela);
|
|
|
|
if (ko->ko_relatab[ra].size != 0) {
|
|
|
|
ko->ko_relatab[ra].nrela =
|
|
|
|
shdr[i].sh_size / sizeof(Elf_Rela);
|
|
|
|
ko->ko_relatab[ra].sec = shdr[i].sh_info;
|
2009-11-27 20:54:11 +03:00
|
|
|
error = ko->ko_read(ko,
|
2009-01-02 01:17:55 +03:00
|
|
|
(void **)&ko->ko_relatab[ra].rela,
|
2008-01-04 15:26:20 +03:00
|
|
|
shdr[i].sh_size,
|
2009-11-27 20:54:11 +03:00
|
|
|
shdr[i].sh_offset, true);
|
2008-01-04 15:26:20 +03:00
|
|
|
if (error != 0) {
|
2014-07-16 17:26:33 +04:00
|
|
|
kobj_error(ko, "read failed %d", error);
|
2008-01-04 15:26:20 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ra++;
|
|
|
|
break;
|
2008-05-01 21:07:10 +04:00
|
|
|
default:
|
|
|
|
break;
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pb != ko->ko_nprogtab) {
|
2013-08-09 09:10:14 +04:00
|
|
|
panic("%s:%d: %s: lost progbits", __func__, __LINE__,
|
|
|
|
ko->ko_name);
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
if (rl != ko->ko_nrel) {
|
2013-08-09 09:10:14 +04:00
|
|
|
panic("%s:%d: %s: lost rel", __func__, __LINE__,
|
|
|
|
ko->ko_name);
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
if (ra != ko->ko_nrela) {
|
2013-08-09 09:10:14 +04:00
|
|
|
panic("%s:%d: %s: lost rela", __func__, __LINE__,
|
|
|
|
ko->ko_name);
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
2016-07-09 10:25:00 +03:00
|
|
|
if (map_text_base != ko->ko_text_address + map_text_size) {
|
|
|
|
panic("%s:%d: %s: map_text_base 0x%lx != address %lx "
|
|
|
|
"+ map_text_size %ld (0x%lx)\n",
|
|
|
|
__func__, __LINE__, ko->ko_name, (long)map_text_base,
|
|
|
|
(long)ko->ko_text_address, (long)map_text_size,
|
|
|
|
(long)ko->ko_text_address + map_text_size);
|
|
|
|
}
|
|
|
|
if (map_data_base != ko->ko_data_address + map_data_size) {
|
|
|
|
panic("%s:%d: %s: map_data_base 0x%lx != address %lx "
|
|
|
|
"+ map_data_size %ld (0x%lx)\n",
|
|
|
|
__func__, __LINE__, ko->ko_name, (long)map_data_base,
|
|
|
|
(long)ko->ko_data_address, (long)map_data_size,
|
|
|
|
(long)ko->ko_data_address + map_data_size);
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
2016-07-20 16:36:19 +03:00
|
|
|
if (map_rodata_base != ko->ko_rodata_address + map_rodata_size) {
|
|
|
|
panic("%s:%d: %s: map_rodata_base 0x%lx != address %lx "
|
|
|
|
"+ map_rodata_size %ld (0x%lx)\n",
|
|
|
|
__func__, __LINE__, ko->ko_name, (long)map_rodata_base,
|
|
|
|
(long)ko->ko_rodata_address, (long)map_rodata_size,
|
|
|
|
(long)ko->ko_rodata_address + map_rodata_size);
|
|
|
|
}
|
2008-01-04 15:26:20 +03:00
|
|
|
|
|
|
|
/*
|
2008-05-20 17:34:44 +04:00
|
|
|
* Perform local relocations only. Relocations relating to global
|
|
|
|
* symbols will be done by kobj_affix().
|
2008-01-04 15:26:20 +03:00
|
|
|
*/
|
2008-11-16 19:23:58 +03:00
|
|
|
error = kobj_checksyms(ko, false);
|
2008-10-20 14:24:18 +04:00
|
|
|
if (error == 0) {
|
|
|
|
error = kobj_relocate(ko, true);
|
|
|
|
}
|
2008-01-04 15:26:20 +03:00
|
|
|
out:
|
2008-01-06 17:47:26 +03:00
|
|
|
if (hdr != NULL) {
|
2008-05-01 18:44:48 +04:00
|
|
|
kobj_free(ko, hdr, sizeof(*hdr));
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
2008-05-20 17:34:44 +04:00
|
|
|
kobj_close(ko);
|
|
|
|
if (error != 0) {
|
|
|
|
kobj_unload(ko);
|
|
|
|
}
|
2008-01-04 15:26:20 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-04-19 18:54:45 +03:00
|
|
|
static void
|
|
|
|
kobj_unload_notify(kobj_t ko, vaddr_t addr, size_t size, const char *note)
|
|
|
|
{
|
|
|
|
if (addr == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int error = kobj_machdep(ko, (void *)addr, size, false);
|
|
|
|
if (error)
|
|
|
|
kobj_error(ko, "machine dependent deinit failed (%s) %d",
|
|
|
|
note, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define KOBJ_SEGMENT_NOTIFY(ko, what) \
|
|
|
|
kobj_unload_notify(ko, (ko)->ko_ ## what ## _address, \
|
|
|
|
(ko)->ko_ ## what ## _size, # what);
|
|
|
|
|
|
|
|
#define KOBJ_SEGMENT_FREE(ko, what) \
|
|
|
|
do \
|
|
|
|
if ((ko)->ko_ ## what ## _address != 0) \
|
|
|
|
uvm_km_free(module_map, (ko)->ko_ ## what ## _address, \
|
|
|
|
round_page((ko)->ko_ ## what ## _size), UVM_KMF_WIRED); \
|
|
|
|
while (/*CONSTCOND*/ 0)
|
|
|
|
|
2008-01-04 15:26:20 +03:00
|
|
|
/*
|
|
|
|
* kobj_unload:
|
|
|
|
*
|
|
|
|
* Unload an object previously loaded by kobj_load().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
kobj_unload(kobj_t ko)
|
|
|
|
{
|
2008-05-20 17:34:44 +04:00
|
|
|
kobj_close(ko);
|
|
|
|
kobj_jettison(ko);
|
|
|
|
|
2017-04-19 18:54:45 +03:00
|
|
|
|
2008-05-20 17:34:44 +04:00
|
|
|
/*
|
|
|
|
* Notify MD code that a module has been unloaded.
|
|
|
|
*/
|
|
|
|
if (ko->ko_loaded) {
|
2017-04-19 18:54:45 +03:00
|
|
|
KOBJ_SEGMENT_NOTIFY(ko, text);
|
|
|
|
KOBJ_SEGMENT_NOTIFY(ko, data);
|
|
|
|
KOBJ_SEGMENT_NOTIFY(ko, rodata);
|
|
|
|
}
|
2016-08-01 18:41:05 +03:00
|
|
|
|
2017-04-19 18:54:45 +03:00
|
|
|
KOBJ_SEGMENT_FREE(ko, text);
|
|
|
|
KOBJ_SEGMENT_FREE(ko, data);
|
|
|
|
KOBJ_SEGMENT_FREE(ko, rodata);
|
2016-08-01 18:41:05 +03:00
|
|
|
|
2008-01-04 15:26:20 +03:00
|
|
|
if (ko->ko_ksyms == true) {
|
2008-10-20 14:24:18 +04:00
|
|
|
ksyms_modunload(ko->ko_name);
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
if (ko->ko_symtab != NULL) {
|
2008-05-01 18:44:48 +04:00
|
|
|
kobj_free(ko, ko->ko_symtab, ko->ko_symcnt * sizeof(Elf_Sym));
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
if (ko->ko_strtab != NULL) {
|
2008-05-01 18:44:48 +04:00
|
|
|
kobj_free(ko, ko->ko_strtab, ko->ko_strtabsz);
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
2008-05-02 17:00:01 +04:00
|
|
|
if (ko->ko_progtab != NULL) {
|
|
|
|
kobj_free(ko, ko->ko_progtab, ko->ko_nprogtab *
|
|
|
|
sizeof(*ko->ko_progtab));
|
|
|
|
ko->ko_progtab = NULL;
|
|
|
|
}
|
|
|
|
if (ko->ko_shstrtab) {
|
|
|
|
kobj_free(ko, ko->ko_shstrtab, ko->ko_shstrtabsz);
|
|
|
|
ko->ko_shstrtab = NULL;
|
|
|
|
}
|
2008-01-04 15:26:20 +03:00
|
|
|
|
2008-01-06 17:47:26 +03:00
|
|
|
kmem_free(ko, sizeof(*ko));
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
|
2008-01-04 17:53:32 +03:00
|
|
|
/*
|
|
|
|
* kobj_stat:
|
|
|
|
*
|
|
|
|
* Return size and load address of an object.
|
|
|
|
*/
|
2009-06-18 01:04:25 +04:00
|
|
|
int
|
2008-01-13 02:34:48 +03:00
|
|
|
kobj_stat(kobj_t ko, vaddr_t *address, size_t *size)
|
2008-01-04 17:53:32 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
if (address != NULL) {
|
2016-07-09 10:25:00 +03:00
|
|
|
*address = ko->ko_text_address;
|
2008-01-04 17:53:32 +03:00
|
|
|
}
|
|
|
|
if (size != NULL) {
|
2016-07-09 10:25:00 +03:00
|
|
|
*size = ko->ko_text_size;
|
2008-01-04 17:53:32 +03:00
|
|
|
}
|
2016-07-07 09:55:38 +03:00
|
|
|
return 0;
|
2008-01-04 17:53:32 +03:00
|
|
|
}
|
|
|
|
|
2008-01-06 17:47:26 +03:00
|
|
|
/*
|
2008-05-20 17:34:44 +04:00
|
|
|
* kobj_affix:
|
2008-01-06 17:47:26 +03:00
|
|
|
*
|
2008-05-20 17:34:44 +04:00
|
|
|
* Set an object's name and perform global relocs. May only be
|
|
|
|
* called after the module and any requisite modules are loaded.
|
2008-01-06 17:47:26 +03:00
|
|
|
*/
|
2008-01-07 21:25:56 +03:00
|
|
|
int
|
2008-05-20 17:34:44 +04:00
|
|
|
kobj_affix(kobj_t ko, const char *name)
|
2008-01-06 17:47:26 +03:00
|
|
|
{
|
2008-01-07 21:25:56 +03:00
|
|
|
int error;
|
2008-01-06 17:47:26 +03:00
|
|
|
|
2008-05-20 17:34:44 +04:00
|
|
|
KASSERT(ko->ko_ksyms == false);
|
|
|
|
KASSERT(ko->ko_loaded == false);
|
2008-01-06 17:47:26 +03:00
|
|
|
|
2011-08-14 01:04:05 +04:00
|
|
|
kobj_setname(ko, name);
|
2008-01-07 21:25:56 +03:00
|
|
|
|
2008-11-16 19:23:58 +03:00
|
|
|
/* Cache addresses of undefined symbols. */
|
|
|
|
error = kobj_checksyms(ko, true);
|
|
|
|
|
2008-10-20 14:24:18 +04:00
|
|
|
/* Now do global relocations. */
|
2008-11-16 19:23:58 +03:00
|
|
|
if (error == 0)
|
|
|
|
error = kobj_relocate(ko, false);
|
2008-10-20 14:24:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that we know the name, register the symbol table.
|
2008-11-12 15:35:50 +03:00
|
|
|
* Do after global relocations because ksyms will pack
|
|
|
|
* the table.
|
2008-10-20 14:24:18 +04:00
|
|
|
*/
|
2008-11-16 19:23:58 +03:00
|
|
|
if (error == 0) {
|
|
|
|
ksyms_modload(ko->ko_name, ko->ko_symtab, ko->ko_symcnt *
|
|
|
|
sizeof(Elf_Sym), ko->ko_strtab, ko->ko_strtabsz);
|
|
|
|
ko->ko_ksyms = true;
|
|
|
|
}
|
2008-05-20 17:34:44 +04:00
|
|
|
|
|
|
|
/* Jettison unneeded memory post-link. */
|
|
|
|
kobj_jettison(ko);
|
|
|
|
|
2009-01-08 04:03:24 +03:00
|
|
|
/*
|
|
|
|
* Notify MD code that a module has been loaded.
|
|
|
|
*
|
|
|
|
* Most architectures use this opportunity to flush their caches.
|
|
|
|
*/
|
2017-04-19 09:19:02 +03:00
|
|
|
if (error == 0 && ko->ko_text_address != 0) {
|
2016-07-09 10:25:00 +03:00
|
|
|
error = kobj_machdep(ko, (void *)ko->ko_text_address,
|
|
|
|
ko->ko_text_size, true);
|
|
|
|
if (error != 0)
|
2017-04-19 09:19:02 +03:00
|
|
|
kobj_error(ko, "machine dependent init failed (text)"
|
|
|
|
" %d", error);
|
|
|
|
}
|
2016-08-01 18:41:05 +03:00
|
|
|
|
2017-04-19 09:19:02 +03:00
|
|
|
if (error == 0 && ko->ko_data_address != 0) {
|
|
|
|
error = kobj_machdep(ko, (void *)ko->ko_data_address,
|
|
|
|
ko->ko_data_size, true);
|
|
|
|
if (error != 0)
|
|
|
|
kobj_error(ko, "machine dependent init failed (data)"
|
|
|
|
" %d", error);
|
|
|
|
}
|
2016-08-01 18:41:05 +03:00
|
|
|
|
2017-04-19 09:19:02 +03:00
|
|
|
if (error == 0 && ko->ko_rodata_address != 0) {
|
|
|
|
error = kobj_machdep(ko, (void *)ko->ko_rodata_address,
|
|
|
|
ko->ko_rodata_size, true);
|
|
|
|
if (error != 0)
|
|
|
|
kobj_error(ko, "machine dependent init failed (rodata)"
|
|
|
|
" %d", error);
|
2008-05-20 17:34:44 +04:00
|
|
|
}
|
|
|
|
|
2016-08-02 15:23:08 +03:00
|
|
|
if (error == 0) {
|
2017-04-19 09:19:02 +03:00
|
|
|
ko->ko_loaded = true;
|
|
|
|
|
2016-08-02 15:23:08 +03:00
|
|
|
/* Change the memory protections, when needed. */
|
2017-04-19 09:19:02 +03:00
|
|
|
if (ko->ko_text_address != 0) {
|
|
|
|
uvm_km_protect(module_map, ko->ko_text_address,
|
|
|
|
ko->ko_text_size, VM_PROT_READ|VM_PROT_EXECUTE);
|
|
|
|
}
|
2016-08-02 15:23:08 +03:00
|
|
|
if (ko->ko_rodata_address != 0) {
|
|
|
|
uvm_km_protect(module_map, ko->ko_rodata_address,
|
|
|
|
ko->ko_rodata_size, VM_PROT_READ);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* If there was an error, destroy the whole object. */
|
2008-05-20 17:34:44 +04:00
|
|
|
kobj_unload(ko);
|
2008-01-07 21:25:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
2008-01-06 17:47:26 +03:00
|
|
|
}
|
|
|
|
|
2008-01-13 02:34:48 +03:00
|
|
|
/*
|
|
|
|
* kobj_find_section:
|
|
|
|
*
|
|
|
|
* Given a section name, search the loaded object and return
|
|
|
|
* virtual address if present and loaded.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
kobj_find_section(kobj_t ko, const char *name, void **addr, size_t *size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
KASSERT(ko->ko_progtab != NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < ko->ko_nprogtab; i++) {
|
|
|
|
if (strcmp(ko->ko_progtab[i].name, name) == 0) {
|
|
|
|
if (addr != NULL) {
|
|
|
|
*addr = ko->ko_progtab[i].addr;
|
|
|
|
}
|
|
|
|
if (size != NULL) {
|
|
|
|
*size = ko->ko_progtab[i].size;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
|
2008-01-04 15:26:20 +03:00
|
|
|
/*
|
2008-05-20 17:34:44 +04:00
|
|
|
* kobj_jettison:
|
2008-01-04 15:26:20 +03:00
|
|
|
*
|
2008-05-20 17:34:44 +04:00
|
|
|
* Release object data not needed after performing relocations.
|
2008-01-04 15:26:20 +03:00
|
|
|
*/
|
|
|
|
static void
|
2008-05-20 17:34:44 +04:00
|
|
|
kobj_jettison(kobj_t ko)
|
2008-01-04 15:26:20 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ko->ko_reltab != NULL) {
|
2009-05-23 19:13:57 +04:00
|
|
|
for (i = 0; i < ko->ko_nrel; i++) {
|
|
|
|
if (ko->ko_reltab[i].rel) {
|
|
|
|
kobj_free(ko, ko->ko_reltab[i].rel,
|
|
|
|
ko->ko_reltab[i].size);
|
|
|
|
}
|
|
|
|
}
|
2008-05-01 18:44:48 +04:00
|
|
|
kobj_free(ko, ko->ko_reltab, ko->ko_nrel *
|
2008-01-04 15:26:20 +03:00
|
|
|
sizeof(*ko->ko_reltab));
|
|
|
|
ko->ko_reltab = NULL;
|
|
|
|
ko->ko_nrel = 0;
|
|
|
|
}
|
|
|
|
if (ko->ko_relatab != NULL) {
|
2009-05-23 19:13:57 +04:00
|
|
|
for (i = 0; i < ko->ko_nrela; i++) {
|
|
|
|
if (ko->ko_relatab[i].rela) {
|
|
|
|
kobj_free(ko, ko->ko_relatab[i].rela,
|
|
|
|
ko->ko_relatab[i].size);
|
|
|
|
}
|
|
|
|
}
|
2008-05-01 18:44:48 +04:00
|
|
|
kobj_free(ko, ko->ko_relatab, ko->ko_nrela *
|
2008-01-04 15:26:20 +03:00
|
|
|
sizeof(*ko->ko_relatab));
|
|
|
|
ko->ko_relatab = NULL;
|
|
|
|
ko->ko_nrela = 0;
|
|
|
|
}
|
|
|
|
if (ko->ko_shdr != NULL) {
|
2008-05-01 18:44:48 +04:00
|
|
|
kobj_free(ko, ko->ko_shdr, ko->ko_shdrsz);
|
2008-01-04 15:26:20 +03:00
|
|
|
ko->ko_shdr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kobj_sym_lookup:
|
|
|
|
*
|
|
|
|
* Symbol lookup function to be used when the symbol index
|
|
|
|
* is known (ie during relocation).
|
|
|
|
*/
|
|
|
|
uintptr_t
|
|
|
|
kobj_sym_lookup(kobj_t ko, uintptr_t symidx)
|
|
|
|
{
|
|
|
|
const Elf_Sym *sym;
|
|
|
|
const char *symbol;
|
|
|
|
|
|
|
|
/* Don't even try to lookup the symbol if the index is bogus. */
|
|
|
|
if (symidx >= ko->ko_symcnt)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sym = ko->ko_symtab + symidx;
|
|
|
|
|
|
|
|
/* Quick answer if there is a definition included. */
|
|
|
|
if (sym->st_shndx != SHN_UNDEF) {
|
2008-11-16 14:26:28 +03:00
|
|
|
return (uintptr_t)sym->st_value;
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get here, then it is undefined and needs a lookup. */
|
|
|
|
switch (ELF_ST_BIND(sym->st_info)) {
|
|
|
|
case STB_LOCAL:
|
|
|
|
/* Local, but undefined? huh? */
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "local symbol undefined");
|
2008-01-04 15:26:20 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case STB_GLOBAL:
|
|
|
|
/* Relative to Data or Function name */
|
|
|
|
symbol = ko->ko_strtab + sym->st_name;
|
|
|
|
|
|
|
|
/* Force a lookup failure if the symbol name is bogus. */
|
|
|
|
if (*symbol == 0) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "bad symbol name");
|
2008-01-04 15:26:20 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-16 14:26:28 +03:00
|
|
|
return (uintptr_t)sym->st_value;
|
2008-01-04 15:26:20 +03:00
|
|
|
|
|
|
|
case STB_WEAK:
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "weak symbols not supported");
|
2008-01-04 15:26:20 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kobj_findbase:
|
|
|
|
*
|
|
|
|
* Return base address of the given section.
|
|
|
|
*/
|
|
|
|
static uintptr_t
|
|
|
|
kobj_findbase(kobj_t ko, int sec)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ko->ko_nprogtab; i++) {
|
|
|
|
if (sec == ko->ko_progtab[i].sec) {
|
|
|
|
return (uintptr_t)ko->ko_progtab[i].addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-20 14:24:18 +04:00
|
|
|
/*
|
2008-11-16 14:26:28 +03:00
|
|
|
* kobj_checksyms:
|
2008-10-20 14:24:18 +04:00
|
|
|
*
|
2008-11-16 19:23:58 +03:00
|
|
|
* Scan symbol table for duplicates or resolve references to
|
2008-11-16 14:26:28 +03:00
|
|
|
* exernal symbols.
|
2008-10-20 14:24:18 +04:00
|
|
|
*/
|
|
|
|
static int
|
2008-11-16 19:23:58 +03:00
|
|
|
kobj_checksyms(kobj_t ko, bool undefined)
|
2008-10-20 14:24:18 +04:00
|
|
|
{
|
|
|
|
unsigned long rval;
|
|
|
|
Elf_Sym *sym, *ms;
|
|
|
|
const char *name;
|
2008-11-16 14:26:28 +03:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = 0;
|
2008-10-20 14:24:18 +04:00
|
|
|
|
|
|
|
for (ms = (sym = ko->ko_symtab) + ko->ko_symcnt; sym < ms; sym++) {
|
|
|
|
/* Check validity of the symbol. */
|
|
|
|
if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL ||
|
|
|
|
sym->st_name == 0)
|
|
|
|
continue;
|
2008-11-16 19:23:58 +03:00
|
|
|
if (undefined != (sym->st_shndx == SHN_UNDEF)) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-10-20 14:24:18 +04:00
|
|
|
|
2008-11-16 14:26:28 +03:00
|
|
|
/*
|
|
|
|
* Look it up. Don't need to lock, as it is known that
|
|
|
|
* the symbol tables aren't going to change (we hold
|
|
|
|
* module_lock).
|
|
|
|
*/
|
2008-10-20 14:24:18 +04:00
|
|
|
name = ko->ko_strtab + sym->st_name;
|
2008-11-16 14:26:28 +03:00
|
|
|
if (ksyms_getval_unlocked(NULL, name, &rval,
|
|
|
|
KSYMS_EXTERN) != 0) {
|
2008-11-16 19:23:58 +03:00
|
|
|
if (undefined) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "symbol `%s' not found",
|
|
|
|
name);
|
2008-11-16 14:26:28 +03:00
|
|
|
error = ENOEXEC;
|
|
|
|
}
|
2008-11-16 17:55:42 +03:00
|
|
|
continue;
|
2008-11-16 14:26:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save values of undefined globals. */
|
2008-11-16 19:23:58 +03:00
|
|
|
if (undefined) {
|
2008-11-16 14:26:28 +03:00
|
|
|
sym->st_value = (Elf_Addr)rval;
|
2008-10-20 14:24:18 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-11-16 14:26:28 +03:00
|
|
|
/* Check (and complain) about differing values. */
|
|
|
|
if (sym->st_value == rval) {
|
2008-10-20 14:24:18 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(name, "_bss_start") == 0 ||
|
|
|
|
strcmp(name, "__bss_start") == 0 ||
|
|
|
|
strcmp(name, "_bss_end__") == 0 ||
|
|
|
|
strcmp(name, "__bss_end__") == 0 ||
|
|
|
|
strcmp(name, "_edata") == 0 ||
|
|
|
|
strcmp(name, "_end") == 0 ||
|
|
|
|
strcmp(name, "__end") == 0 ||
|
|
|
|
strcmp(name, "__end__") == 0 ||
|
|
|
|
strncmp(name, "__start_link_set_", 17) == 0 ||
|
2016-05-31 06:57:04 +03:00
|
|
|
strncmp(name, "__stop_link_set_", 16) == 0) {
|
2008-10-20 14:24:18 +04:00
|
|
|
continue;
|
|
|
|
}
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "global symbol `%s' redefined",
|
|
|
|
name);
|
2008-11-16 14:26:28 +03:00
|
|
|
error = ENOEXEC;
|
2008-10-20 14:24:18 +04:00
|
|
|
}
|
|
|
|
|
2008-11-16 14:26:28 +03:00
|
|
|
return error;
|
2008-10-20 14:24:18 +04:00
|
|
|
}
|
|
|
|
|
2008-01-04 15:26:20 +03:00
|
|
|
/*
|
|
|
|
* kobj_relocate:
|
|
|
|
*
|
2008-05-20 17:34:44 +04:00
|
|
|
* Resolve relocations for the loaded object.
|
2008-01-04 15:26:20 +03:00
|
|
|
*/
|
|
|
|
static int
|
2008-05-20 17:34:44 +04:00
|
|
|
kobj_relocate(kobj_t ko, bool local)
|
2008-01-04 15:26:20 +03:00
|
|
|
{
|
|
|
|
const Elf_Rel *rellim;
|
|
|
|
const Elf_Rel *rel;
|
|
|
|
const Elf_Rela *relalim;
|
|
|
|
const Elf_Rela *rela;
|
|
|
|
const Elf_Sym *sym;
|
|
|
|
uintptr_t base;
|
2008-01-13 02:34:48 +03:00
|
|
|
int i, error;
|
2008-01-04 15:26:20 +03:00
|
|
|
uintptr_t symidx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform relocations without addend if there are any.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ko->ko_nrel; i++) {
|
|
|
|
rel = ko->ko_reltab[i].rel;
|
|
|
|
if (rel == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
rellim = rel + ko->ko_reltab[i].nrel;
|
|
|
|
base = kobj_findbase(ko, ko->ko_reltab[i].sec);
|
|
|
|
if (base == 0) {
|
2013-08-09 09:10:14 +04:00
|
|
|
panic("%s:%d: %s: lost base for e_reltab[%d] sec %d",
|
|
|
|
__func__, __LINE__, ko->ko_name, i,
|
|
|
|
ko->ko_reltab[i].sec);
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
for (; rel < rellim; rel++) {
|
|
|
|
symidx = ELF_R_SYM(rel->r_info);
|
|
|
|
if (symidx >= ko->ko_symcnt) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sym = ko->ko_symtab + symidx;
|
2008-05-20 17:34:44 +04:00
|
|
|
if (local != (ELF_ST_BIND(sym->st_info) == STB_LOCAL)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
error = kobj_reloc(ko, base, rel, false, local);
|
2008-01-13 02:34:48 +03:00
|
|
|
if (error != 0) {
|
2008-01-04 15:26:20 +03:00
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform relocations with addend if there are any.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ko->ko_nrela; i++) {
|
|
|
|
rela = ko->ko_relatab[i].rela;
|
|
|
|
if (rela == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
relalim = rela + ko->ko_relatab[i].nrela;
|
|
|
|
base = kobj_findbase(ko, ko->ko_relatab[i].sec);
|
|
|
|
if (base == 0) {
|
2013-08-09 09:10:14 +04:00
|
|
|
panic("%s:%d: %s: lost base for e_relatab[%d] sec %d",
|
|
|
|
__func__, __LINE__, ko->ko_name, i,
|
|
|
|
ko->ko_relatab[i].sec);
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
for (; rela < relalim; rela++) {
|
|
|
|
symidx = ELF_R_SYM(rela->r_info);
|
|
|
|
if (symidx >= ko->ko_symcnt) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sym = ko->ko_symtab + symidx;
|
2008-05-20 17:34:44 +04:00
|
|
|
if (local != (ELF_ST_BIND(sym->st_info) == STB_LOCAL)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
error = kobj_reloc(ko, base, rela, true, local);
|
2008-01-13 02:34:48 +03:00
|
|
|
if (error != 0) {
|
2008-01-04 15:26:20 +03:00
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-07-06 19:22:31 +04:00
|
|
|
* kobj_out:
|
2008-01-04 15:26:20 +03:00
|
|
|
*
|
|
|
|
* Utility function: log an error.
|
|
|
|
*/
|
|
|
|
static void
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_out(const char *fname, int lnum, kobj_t ko, const char *fmt, ...)
|
2008-01-04 15:26:20 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2011-08-14 01:04:05 +04:00
|
|
|
printf("%s, %d: [%s]: linker error: ", fname, lnum, ko->ko_name);
|
2008-01-04 15:26:20 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
vprintf(fmt, ap);
|
|
|
|
va_end(ap);
|
2011-08-14 01:04:05 +04:00
|
|
|
printf("\n");
|
2008-01-04 15:26:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-11-27 20:54:11 +03:00
|
|
|
kobj_read_mem(kobj_t ko, void **basep, size_t size, off_t off,
|
2011-08-14 01:04:05 +04:00
|
|
|
bool allocate)
|
2008-01-04 15:26:20 +03:00
|
|
|
{
|
2009-11-27 20:54:11 +03:00
|
|
|
void *base = *basep;
|
2008-01-04 15:26:20 +03:00
|
|
|
int error;
|
|
|
|
|
2016-07-08 11:55:48 +03:00
|
|
|
KASSERT(ko->ko_source != NULL);
|
|
|
|
|
2009-11-27 20:54:11 +03:00
|
|
|
if (ko->ko_memsize != -1 && off + size > ko->ko_memsize) {
|
2014-07-06 19:22:31 +04:00
|
|
|
kobj_error(ko, "preloaded object short");
|
2009-11-27 20:54:11 +03:00
|
|
|
error = EINVAL;
|
|
|
|
base = NULL;
|
|
|
|
} else if (allocate) {
|
2016-07-08 11:55:48 +03:00
|
|
|
base = kmem_alloc(size, KM_SLEEP);
|
2009-11-27 20:54:11 +03:00
|
|
|
error = 0;
|
|
|
|
} else {
|
|
|
|
error = 0;
|
2008-05-01 18:44:48 +04:00
|
|
|
}
|
|
|
|
|
2016-07-08 11:55:48 +03:00
|
|
|
if (error == 0) {
|
|
|
|
/* Copy the section */
|
|
|
|
memcpy(base, (uint8_t *)ko->ko_source + off, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allocate && error != 0) {
|
|
|
|
kmem_free(base, size);
|
|
|
|
base = NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-27 20:54:11 +03:00
|
|
|
if (allocate)
|
|
|
|
*basep = base;
|
2008-01-06 17:47:26 +03:00
|
|
|
|
2008-01-04 15:26:20 +03:00
|
|
|
return error;
|
|
|
|
}
|
2008-01-06 21:03:58 +03:00
|
|
|
|
2008-05-01 18:44:48 +04:00
|
|
|
/*
|
|
|
|
* kobj_free:
|
|
|
|
*
|
|
|
|
* Utility function: free memory if it was allocated from the heap.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
kobj_free(kobj_t ko, void *base, size_t size)
|
|
|
|
{
|
|
|
|
|
2016-07-08 11:55:48 +03:00
|
|
|
kmem_free(base, size);
|
2008-05-01 18:44:48 +04:00
|
|
|
}
|
|
|
|
|
2011-08-14 01:04:05 +04:00
|
|
|
extern char module_base[];
|
|
|
|
|
|
|
|
void
|
|
|
|
kobj_setname(kobj_t ko, const char *name)
|
|
|
|
{
|
|
|
|
const char *d = name, *dots = "";
|
|
|
|
size_t len, dlen;
|
|
|
|
|
|
|
|
for (char *s = module_base; *d == *s; d++, s++)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (d == name)
|
|
|
|
name = "";
|
|
|
|
else
|
|
|
|
name = "%M";
|
|
|
|
dlen = strlen(d);
|
|
|
|
len = dlen + strlen(name);
|
|
|
|
if (len >= sizeof(ko->ko_name)) {
|
|
|
|
len = (len - sizeof(ko->ko_name)) + 5; /* dots + NUL */
|
|
|
|
if (dlen >= len) {
|
|
|
|
d += len;
|
|
|
|
dots = "/...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
snprintf(ko->ko_name, sizeof(ko->ko_name), "%s%s%s", name, dots, d);
|
|
|
|
}
|
|
|
|
|
2008-01-06 21:03:58 +03:00
|
|
|
#else /* MODULAR */
|
|
|
|
|
|
|
|
int
|
2011-08-14 01:04:05 +04:00
|
|
|
kobj_load_mem(kobj_t *kop, const char *name, void *base, ssize_t size)
|
2008-01-06 21:03:58 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kobj_unload(kobj_t ko)
|
|
|
|
{
|
|
|
|
|
|
|
|
panic("not modular");
|
|
|
|
}
|
|
|
|
|
2009-06-18 01:04:25 +04:00
|
|
|
int
|
2008-01-13 02:34:48 +03:00
|
|
|
kobj_stat(kobj_t ko, vaddr_t *base, size_t *size)
|
2008-01-06 21:03:58 +03:00
|
|
|
{
|
|
|
|
|
2009-06-18 01:04:25 +04:00
|
|
|
return ENOSYS;
|
2008-01-06 21:03:58 +03:00
|
|
|
}
|
|
|
|
|
2008-01-07 23:42:48 +03:00
|
|
|
int
|
2008-05-20 17:34:44 +04:00
|
|
|
kobj_affix(kobj_t ko, const char *name)
|
2008-01-06 21:03:58 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
panic("not modular");
|
|
|
|
}
|
|
|
|
|
2008-01-13 02:34:48 +03:00
|
|
|
int
|
|
|
|
kobj_find_section(kobj_t ko, const char *name, void **addr, size_t *size)
|
|
|
|
{
|
|
|
|
|
|
|
|
panic("not modular");
|
|
|
|
}
|
|
|
|
|
2011-08-14 01:04:05 +04:00
|
|
|
void
|
|
|
|
kobj_setname(kobj_t ko, const char *name)
|
|
|
|
{
|
|
|
|
|
|
|
|
panic("not modular");
|
|
|
|
}
|
|
|
|
|
2008-01-06 21:03:58 +03:00
|
|
|
#endif /* MODULAR */
|