Sun May 24 15:00:24 2009 UTC ()
Split out kobj structures so crash/ddb can get at them.


(ad)
diff -r1.35 -r1.36 src/sys/kern/subr_kobj.c
diff -r0 -r1.1 src/sys/sys/kobj_impl.h

cvs diff -r1.35 -r1.36 src/sys/kern/subr_kobj.c (expand / switch to unified diff)

--- src/sys/kern/subr_kobj.c 2009/05/23 15:13:57 1.35
+++ src/sys/kern/subr_kobj.c 2009/05/24 15:00:24 1.36
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: subr_kobj.c,v 1.35 2009/05/23 15:13:57 ad Exp $ */ 1/* $NetBSD: subr_kobj.c,v 1.36 2009/05/24 15:00:24 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software developed for The NetBSD Foundation 7 * This code is derived from software developed for The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -53,107 +53,48 @@ @@ -53,107 +53,48 @@
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE. 56 * SUCH DAMAGE.
57 */ 57 */
58 58
59/* 59/*
60 * Kernel loader for ELF objects. 60 * Kernel loader for ELF objects.
61 * 61 *
62 * TODO: adjust kmem_alloc() calls to avoid needless fragmentation. 62 * TODO: adjust kmem_alloc() calls to avoid needless fragmentation.
63 */ 63 */
64 64
65#include <sys/cdefs.h> 65#include <sys/cdefs.h>
66__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.35 2009/05/23 15:13:57 ad Exp $"); 66__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.36 2009/05/24 15:00:24 ad Exp $");
67 67
68#include "opt_modular.h" 68#include "opt_modular.h"
69 69
70#define ELFSIZE ARCH_ELFSIZE 70#include <sys/kobj_impl.h>
71 
72#include <sys/systm.h> 
73#include <sys/kobj.h> 
74#include <sys/errno.h> 
75 71
76#ifdef MODULAR 72#ifdef MODULAR
77 73
78#include <sys/param.h> 74#include <sys/param.h>
79#include <sys/kernel.h> 75#include <sys/kernel.h>
80#include <sys/kmem.h> 76#include <sys/kmem.h>
81#include <sys/proc.h> 77#include <sys/proc.h>
82#include <sys/namei.h> 78#include <sys/namei.h>
83#include <sys/vnode.h> 79#include <sys/vnode.h>
84#include <sys/fcntl.h> 80#include <sys/fcntl.h>
85#include <sys/ksyms.h> 81#include <sys/ksyms.h>
86#include <sys/module.h> 82#include <sys/module.h>
87#include <sys/exec.h> 
88#include <sys/exec_elf.h> 
89 83
90#include <machine/stdarg.h> 84#include <machine/stdarg.h>
91 85
92#include <uvm/uvm_extern.h> 86#include <uvm/uvm_extern.h>
93 87
94typedef struct { 
95 void *addr; 
96 Elf_Off size; 
97 int flags; 
98 int sec; /* Original section */ 
99 const char *name; 
100} progent_t; 
101 
102typedef struct { 
103 Elf_Rel *rel; 
104 int nrel; 
105 int sec; 
106 size_t size; 
107} relent_t; 
108 
109typedef struct { 
110 Elf_Rela *rela; 
111 int nrela; 
112 int sec; 
113 size_t size; 
114} relaent_t; 
115 
116typedef enum kobjtype { 
117 KT_UNSET, 
118 KT_VNODE, 
119 KT_MEMORY 
120} kobjtype_t; 
121 
122struct kobj { 
123 char ko_name[MAXMODNAME]; 
124 kobjtype_t ko_type; 
125 void *ko_source; 
126 ssize_t ko_memsize; 
127 vaddr_t ko_address; /* Relocation address */ 
128 Elf_Shdr *ko_shdr; 
129 progent_t *ko_progtab; 
130 relaent_t *ko_relatab; 
131 relent_t *ko_reltab; 
132 Elf_Sym *ko_symtab; /* Symbol table */ 
133 char *ko_strtab; /* String table */ 
134 char *ko_shstrtab; /* Section name string table */ 
135 size_t ko_size; /* Size of text/data/bss */ 
136 size_t ko_symcnt; /* Number of symbols */ 
137 size_t ko_strtabsz; /* Number of bytes in string table */ 
138 size_t ko_shstrtabsz; /* Number of bytes in scn str table */ 
139 size_t ko_shdrsz; 
140 int ko_nrel; 
141 int ko_nrela; 
142 int ko_nprogtab; 
143 bool ko_ksyms; 
144 bool ko_loaded; 
145}; 
146 
147static int kobj_relocate(kobj_t, bool); 88static int kobj_relocate(kobj_t, bool);
148static int kobj_checksyms(kobj_t, bool); 89static int kobj_checksyms(kobj_t, bool);
149static void kobj_error(const char *, ...); 90static void kobj_error(const char *, ...);
150static int kobj_read(kobj_t, void **, size_t, off_t); 91static int kobj_read(kobj_t, void **, size_t, off_t);
151static int kobj_read_bits(kobj_t, void *, size_t, off_t); 92static int kobj_read_bits(kobj_t, void *, size_t, off_t);
152static void kobj_jettison(kobj_t); 93static void kobj_jettison(kobj_t);
153static void kobj_free(kobj_t, void *, size_t); 94static void kobj_free(kobj_t, void *, size_t);
154static void kobj_close(kobj_t); 95static void kobj_close(kobj_t);
155static int kobj_load(kobj_t); 96static int kobj_load(kobj_t);
156 97
157extern struct vm_map *module_map; 98extern struct vm_map *module_map;
158 99
159/* 100/*

File Added: src/sys/sys/kobj_impl.h
/*	$NetBSD: kobj_impl.h,v 1.1 2009/05/24 15:00:24 ad Exp $	*/

/*-
 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software developed for The NetBSD Foundation
 * by Andrew Doran.
 *
 * 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.
 */

/*
 * Data structures private to kobj, shared only with kernel grovellers.
 */

#ifndef _SYS_KOBJ_IMPL_H_
#define	_SYS_KOBJ_IMPL_H_

#define	ELFSIZE		ARCH_ELFSIZE

#include <sys/systm.h>
#include <sys/kobj.h>
#include <sys/exec.h>
#include <sys/exec_elf.h>
#include <sys/module.h>

typedef struct {
	void		*addr;
	Elf_Off		size;
	int		flags;
	int		sec;		/* Original section */
	const char	*name;
} progent_t;

typedef struct {
	Elf_Rel		*rel;
	int 		nrel;
	int 		sec;
	size_t		size;
} relent_t;

typedef struct {
	Elf_Rela	*rela;
	int		nrela;
	int		sec;
	size_t		size;
} relaent_t;

typedef enum kobjtype {
	KT_UNSET,
	KT_VNODE,
	KT_MEMORY
} kobjtype_t;

struct kobj {
	char		ko_name[MAXMODNAME];
	kobjtype_t	ko_type;
	void		*ko_source;
	ssize_t		ko_memsize;
	vaddr_t		ko_address;	/* Relocation address */
	Elf_Shdr	*ko_shdr;
	progent_t	*ko_progtab;
	relaent_t	*ko_relatab;
	relent_t	*ko_reltab;
	Elf_Sym		*ko_symtab;	/* Symbol table */
	char		*ko_strtab;	/* String table */
	char		*ko_shstrtab;	/* Section name string table */
	size_t		ko_size;	/* Size of text/data/bss */
	size_t		ko_symcnt;	/* Number of symbols */
	size_t		ko_strtabsz;	/* Number of bytes in string table */
	size_t		ko_shstrtabsz;	/* Number of bytes in scn str table */
	size_t		ko_shdrsz;
	int		ko_nrel;
	int		ko_nrela;
	int		ko_nprogtab;
	bool		ko_ksyms;
	bool		ko_loaded;
};

#endif	/* _SYS_KOBJ_IMPL_H_ */