Wed Jun 17 21:04:25 2009 UTC ()
Make kobj_stat() return ENOSYS instead of panicking ("not modular")
on non-MODULAR kernels.  Make a few kobj_stat() callers check for
a non-zero return code and deal gracefully.


(dyoung)
diff -r1.48 -r1.49 src/sys/kern/kern_module.c
diff -r1.38 -r1.39 src/sys/kern/subr_kobj.c
diff -r1.11 -r1.12 src/sys/sys/kobj.h

cvs diff -r1.48 -r1.49 src/sys/kern/kern_module.c (expand / switch to unified diff)

--- src/sys/kern/kern_module.c 2009/06/09 20:35:02 1.48
+++ src/sys/kern/kern_module.c 2009/06/17 21:04:25 1.49
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_module.c,v 1.48 2009/06/09 20:35:02 jnemeth Exp $ */ 1/* $NetBSD: kern_module.c,v 1.49 2009/06/17 21:04:25 dyoung 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.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Kernel module support. 33 * Kernel module support.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.48 2009/06/09 20:35:02 jnemeth Exp $"); 37__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.49 2009/06/17 21:04:25 dyoung Exp $");
38 38
39#ifdef _KERNEL_OPT 39#ifdef _KERNEL_OPT
40#include "opt_ddb.h" 40#include "opt_ddb.h"
41#include "opt_modular.h" 41#include "opt_modular.h"
42#endif 42#endif
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/systm.h> 45#include <sys/systm.h>
46#include <sys/kernel.h> 46#include <sys/kernel.h>
47#include <sys/fcntl.h> 47#include <sys/fcntl.h>
48#include <sys/proc.h> 48#include <sys/proc.h>
49#include <sys/kauth.h> 49#include <sys/kauth.h>
50#include <sys/kobj.h> 50#include <sys/kobj.h>
@@ -1062,27 +1062,28 @@ module_thread_kick(void) @@ -1062,27 +1062,28 @@ module_thread_kick(void)
1062 * Helper routine for DDB. 1062 * Helper routine for DDB.
1063 */ 1063 */
1064void 1064void
1065module_whatis(uintptr_t addr, void (*pr)(const char *, ...)) 1065module_whatis(uintptr_t addr, void (*pr)(const char *, ...))
1066{ 1066{
1067 module_t *mod; 1067 module_t *mod;
1068 size_t msize; 1068 size_t msize;
1069 vaddr_t maddr; 1069 vaddr_t maddr;
1070 1070
1071 TAILQ_FOREACH(mod, &module_list, mod_chain) { 1071 TAILQ_FOREACH(mod, &module_list, mod_chain) {
1072 if (mod->mod_kobj == NULL) { 1072 if (mod->mod_kobj == NULL) {
1073 continue; 1073 continue;
1074 } 1074 }
1075 kobj_stat(mod->mod_kobj, &maddr, &msize); 1075 if (kobj_stat(mod->mod_kobj, &maddr, &msize) != 0)
 1076 continue;
1076 if (addr < maddr || addr >= maddr + msize) { 1077 if (addr < maddr || addr >= maddr + msize) {
1077 continue; 1078 continue;
1078 } 1079 }
1079 (*pr)("%p is %p+%zu, in kernel module `%s'\n", 1080 (*pr)("%p is %p+%zu, in kernel module `%s'\n",
1080 (void *)addr, (void *)maddr, 1081 (void *)addr, (void *)maddr,
1081 (size_t)(addr - maddr), mod->mod_info->mi_name); 1082 (size_t)(addr - maddr), mod->mod_info->mi_name);
1082 } 1083 }
1083} 1084}
1084 1085
1085/* 1086/*
1086 * module_print_list: 1087 * module_print_list:
1087 * 1088 *
1088 * Helper routine for DDB. 1089 * Helper routine for DDB.
@@ -1102,32 +1103,31 @@ module_print_list(void (*pr)(const char  @@ -1102,32 +1103,31 @@ module_print_list(void (*pr)(const char
1102 case MODULE_SOURCE_KERNEL: 1103 case MODULE_SOURCE_KERNEL:
1103 src = "builtin"; 1104 src = "builtin";
1104 break; 1105 break;
1105 case MODULE_SOURCE_FILESYS: 1106 case MODULE_SOURCE_FILESYS:
1106 src = "filesys"; 1107 src = "filesys";
1107 break; 1108 break;
1108 case MODULE_SOURCE_BOOT: 1109 case MODULE_SOURCE_BOOT:
1109 src = "boot"; 1110 src = "boot";
1110 break; 1111 break;
1111 default: 1112 default:
1112 src = "unknown"; 1113 src = "unknown";
1113 break; 1114 break;
1114 } 1115 }
1115 if (mod->mod_kobj != NULL) { 1116 if (mod->mod_kobj == NULL) {
1116 kobj_stat(mod->mod_kobj, &maddr, &msize); 
1117 } else { 
1118 maddr = 0; 1117 maddr = 0;
1119 msize = 0; 1118 msize = 0;
1120 } 1119 } else if (kobj_stat(mod->mod_kobj, &maddr, &msize) != 0)
 1120 continue;
1121 (*pr)("%16s %16lx %8ld %8s\n", mod->mod_info->mi_name, 1121 (*pr)("%16s %16lx %8ld %8s\n", mod->mod_info->mi_name,
1122 (long)maddr, (long)msize, src); 1122 (long)maddr, (long)msize, src);
1123 } 1123 }
1124} 1124}
1125#endif /* DDB */ 1125#endif /* DDB */
1126 1126
1127/* 1127/*
1128 * module_load_plist_file: 1128 * module_load_plist_file:
1129 * 1129 *
1130 * Load a plist located in the file system into memory. 1130 * Load a plist located in the file system into memory.
1131 */ 1131 */
1132static int 1132static int
1133module_load_plist_file(const char *modpath, const bool nochroot, 1133module_load_plist_file(const char *modpath, const bool nochroot,

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

--- src/sys/kern/subr_kobj.c 2009/05/26 08:34:23 1.38
+++ src/sys/kern/subr_kobj.c 2009/06/17 21:04:25 1.39
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: subr_kobj.c,v 1.38 2009/05/26 08:34:23 jnemeth Exp $ */ 1/* $NetBSD: subr_kobj.c,v 1.39 2009/06/17 21:04:25 dyoung 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,27 +53,27 @@ @@ -53,27 +53,27 @@
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.38 2009/05/26 08:34:23 jnemeth Exp $"); 66__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.39 2009/06/17 21:04:25 dyoung Exp $");
67 67
68#include "opt_modular.h" 68#include "opt_modular.h"
69 69
70#include <sys/kobj_impl.h> 70#include <sys/kobj_impl.h>
71 71
72#ifdef MODULAR 72#ifdef MODULAR
73 73
74#include <sys/param.h> 74#include <sys/param.h>
75#include <sys/kernel.h> 75#include <sys/kernel.h>
76#include <sys/kmem.h> 76#include <sys/kmem.h>
77#include <sys/proc.h> 77#include <sys/proc.h>
78#include <sys/namei.h> 78#include <sys/namei.h>
79#include <sys/vnode.h> 79#include <sys/vnode.h>
@@ -612,36 +612,37 @@ kobj_unload(kobj_t ko) @@ -612,36 +612,37 @@ kobj_unload(kobj_t ko)
612 if (ko->ko_shstrtab) { 612 if (ko->ko_shstrtab) {
613 kobj_free(ko, ko->ko_shstrtab, ko->ko_shstrtabsz); 613 kobj_free(ko, ko->ko_shstrtab, ko->ko_shstrtabsz);
614 ko->ko_shstrtab = NULL; 614 ko->ko_shstrtab = NULL;
615 } 615 }
616 616
617 kmem_free(ko, sizeof(*ko)); 617 kmem_free(ko, sizeof(*ko));
618} 618}
619 619
620/* 620/*
621 * kobj_stat: 621 * kobj_stat:
622 * 622 *
623 * Return size and load address of an object. 623 * Return size and load address of an object.
624 */ 624 */
625void 625int
626kobj_stat(kobj_t ko, vaddr_t *address, size_t *size) 626kobj_stat(kobj_t ko, vaddr_t *address, size_t *size)
627{ 627{
628 628
629 if (address != NULL) { 629 if (address != NULL) {
630 *address = ko->ko_address; 630 *address = ko->ko_address;
631 } 631 }
632 if (size != NULL) { 632 if (size != NULL) {
633 *size = ko->ko_size; 633 *size = ko->ko_size;
634 } 634 }
 635 return 0;
635} 636}
636 637
637/* 638/*
638 * kobj_affix: 639 * kobj_affix:
639 * 640 *
640 * Set an object's name and perform global relocs. May only be 641 * Set an object's name and perform global relocs. May only be
641 * called after the module and any requisite modules are loaded. 642 * called after the module and any requisite modules are loaded.
642 */ 643 */
643int 644int
644kobj_affix(kobj_t ko, const char *name) 645kobj_affix(kobj_t ko, const char *name)
645{ 646{
646 int error; 647 int error;
647 648
@@ -1116,31 +1117,31 @@ int @@ -1116,31 +1117,31 @@ int
1116kobj_load_mem(kobj_t *kop, void *base, ssize_t size) 1117kobj_load_mem(kobj_t *kop, void *base, ssize_t size)
1117{ 1118{
1118 1119
1119 return ENOSYS; 1120 return ENOSYS;
1120} 1121}
1121 1122
1122void 1123void
1123kobj_unload(kobj_t ko) 1124kobj_unload(kobj_t ko)
1124{ 1125{
1125 1126
1126 panic("not modular"); 1127 panic("not modular");
1127} 1128}
1128 1129
1129void 1130int
1130kobj_stat(kobj_t ko, vaddr_t *base, size_t *size) 1131kobj_stat(kobj_t ko, vaddr_t *base, size_t *size)
1131{ 1132{
1132 1133
1133 panic("not modular"); 1134 return ENOSYS;
1134} 1135}
1135 1136
1136int 1137int
1137kobj_affix(kobj_t ko, const char *name) 1138kobj_affix(kobj_t ko, const char *name)
1138{ 1139{
1139 1140
1140 panic("not modular"); 1141 panic("not modular");
1141} 1142}
1142 1143
1143int 1144int
1144kobj_find_section(kobj_t ko, const char *name, void **addr, size_t *size) 1145kobj_find_section(kobj_t ko, const char *name, void **addr, size_t *size)
1145{ 1146{
1146 1147

cvs diff -r1.11 -r1.12 src/sys/sys/kobj.h (expand / switch to unified diff)

--- src/sys/sys/kobj.h 2009/05/26 08:34:22 1.11
+++ src/sys/sys/kobj.h 2009/06/17 21:04:25 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kobj.h,v 1.11 2009/05/26 08:34:22 jnemeth Exp $ */ 1/* $NetBSD: kobj.h,v 1.12 2009/06/17 21:04:25 dyoung 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 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -26,22 +26,22 @@ @@ -26,22 +26,22 @@
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#ifndef _SYS_KOBJ_H_ 29#ifndef _SYS_KOBJ_H_
30#define _SYS_KOBJ_H_ 30#define _SYS_KOBJ_H_
31 31
32typedef struct kobj *kobj_t; 32typedef struct kobj *kobj_t;
33 33
34/* External interface. */ 34/* External interface. */
35int kobj_load_file(kobj_t *, const char *, const bool); 35int kobj_load_file(kobj_t *, const char *, const bool);
36int kobj_load_mem(kobj_t *, void *, ssize_t); 36int kobj_load_mem(kobj_t *, void *, ssize_t);
37int kobj_affix(kobj_t, const char *); 37int kobj_affix(kobj_t, const char *);
38void kobj_unload(kobj_t); 38void kobj_unload(kobj_t);
39void kobj_stat(kobj_t, vaddr_t *, size_t *); 39int kobj_stat(kobj_t, vaddr_t *, size_t *);
40int kobj_find_section(kobj_t, const char *, void **, size_t *); 40int kobj_find_section(kobj_t, const char *, void **, size_t *);
41 41
42/* MI-MD interface. */ 42/* MI-MD interface. */
43uintptr_t kobj_sym_lookup(kobj_t, uintptr_t); 43uintptr_t kobj_sym_lookup(kobj_t, uintptr_t);
44int kobj_reloc(kobj_t, uintptr_t, const void *, bool, bool); 44int kobj_reloc(kobj_t, uintptr_t, const void *, bool, bool);
45int kobj_machdep(kobj_t, void *, size_t, bool); 45int kobj_machdep(kobj_t, void *, size_t, bool);
46 46
47#endif /* !_SYS_KOBJ_H_ */ 47#endif /* !_SYS_KOBJ_H_ */