bug.c (4ccb6aea4b3eb97c94575d1ed4bf10744169f082) bug.c (19d436268dde95389c616bb3819da73f0a8b28a8)
1/*
2 Generic support for BUG()
3
4 This respects the following config options:
5
6 CONFIG_BUG - emit BUG traps. Nothing happens without this.
7 CONFIG_GENERIC_BUG - enable this code.
8 CONFIG_GENERIC_BUG_RELATIVE_POINTERS - use 32-bit pointers relative to

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

42
43#include <linux/list.h>
44#include <linux/module.h>
45#include <linux/kernel.h>
46#include <linux/bug.h>
47#include <linux/sched.h>
48#include <linux/rculist.h>
49
1/*
2 Generic support for BUG()
3
4 This respects the following config options:
5
6 CONFIG_BUG - emit BUG traps. Nothing happens without this.
7 CONFIG_GENERIC_BUG - enable this code.
8 CONFIG_GENERIC_BUG_RELATIVE_POINTERS - use 32-bit pointers relative to

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

42
43#include <linux/list.h>
44#include <linux/module.h>
45#include <linux/kernel.h>
46#include <linux/bug.h>
47#include <linux/sched.h>
48#include <linux/rculist.h>
49
50extern const struct bug_entry __start___bug_table[], __stop___bug_table[];
50extern struct bug_entry __start___bug_table[], __stop___bug_table[];
51
52static inline unsigned long bug_addr(const struct bug_entry *bug)
53{
54#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
55 return bug->bug_addr;
56#else
57 return (unsigned long)bug + bug->bug_addr_disp;
58#endif
59}
60
61#ifdef CONFIG_MODULES
62/* Updates are protected by module mutex */
63static LIST_HEAD(module_bug_list);
64
51
52static inline unsigned long bug_addr(const struct bug_entry *bug)
53{
54#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
55 return bug->bug_addr;
56#else
57 return (unsigned long)bug + bug->bug_addr_disp;
58#endif
59}
60
61#ifdef CONFIG_MODULES
62/* Updates are protected by module mutex */
63static LIST_HEAD(module_bug_list);
64
65static const struct bug_entry *module_find_bug(unsigned long bugaddr)
65static struct bug_entry *module_find_bug(unsigned long bugaddr)
66{
67 struct module *mod;
66{
67 struct module *mod;
68 const struct bug_entry *bug = NULL;
68 struct bug_entry *bug = NULL;
69
70 rcu_read_lock_sched();
71 list_for_each_entry_rcu(mod, &module_bug_list, bug_list) {
72 unsigned i;
73
74 bug = mod->bug_table;
75 for (i = 0; i < mod->num_bugs; ++i, ++bug)
76 if (bugaddr == bug_addr(bug))

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

117void module_bug_cleanup(struct module *mod)
118{
119 lockdep_assert_held(&module_mutex);
120 list_del_rcu(&mod->bug_list);
121}
122
123#else
124
69
70 rcu_read_lock_sched();
71 list_for_each_entry_rcu(mod, &module_bug_list, bug_list) {
72 unsigned i;
73
74 bug = mod->bug_table;
75 for (i = 0; i < mod->num_bugs; ++i, ++bug)
76 if (bugaddr == bug_addr(bug))

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

117void module_bug_cleanup(struct module *mod)
118{
119 lockdep_assert_held(&module_mutex);
120 list_del_rcu(&mod->bug_list);
121}
122
123#else
124
125static inline const struct bug_entry *module_find_bug(unsigned long bugaddr)
125static inline struct bug_entry *module_find_bug(unsigned long bugaddr)
126{
127 return NULL;
128}
129#endif
130
126{
127 return NULL;
128}
129#endif
130
131const struct bug_entry *find_bug(unsigned long bugaddr)
131struct bug_entry *find_bug(unsigned long bugaddr)
132{
132{
133 const struct bug_entry *bug;
133 struct bug_entry *bug;
134
135 for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)
136 if (bugaddr == bug_addr(bug))
137 return bug;
138
139 return module_find_bug(bugaddr);
140}
141
142enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
143{
134
135 for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)
136 if (bugaddr == bug_addr(bug))
137 return bug;
138
139 return module_find_bug(bugaddr);
140}
141
142enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
143{
144 const struct bug_entry *bug;
144 struct bug_entry *bug;
145 const char *file;
145 const char *file;
146 unsigned line, warning;
146 unsigned line, warning, once, done;
147
148 if (!is_valid_bugaddr(bugaddr))
149 return BUG_TRAP_TYPE_NONE;
150
151 bug = find_bug(bugaddr);
152
153 file = NULL;
154 line = 0;

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

159#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
160 file = bug->file;
161#else
162 file = (const char *)bug + bug->file_disp;
163#endif
164 line = bug->line;
165#endif
166 warning = (bug->flags & BUGFLAG_WARNING) != 0;
147
148 if (!is_valid_bugaddr(bugaddr))
149 return BUG_TRAP_TYPE_NONE;
150
151 bug = find_bug(bugaddr);
152
153 file = NULL;
154 line = 0;

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

159#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
160 file = bug->file;
161#else
162 file = (const char *)bug + bug->file_disp;
163#endif
164 line = bug->line;
165#endif
166 warning = (bug->flags & BUGFLAG_WARNING) != 0;
167 once = (bug->flags & BUGFLAG_ONCE) != 0;
168 done = (bug->flags & BUGFLAG_DONE) != 0;
169
170 if (warning && once) {
171 if (done)
172 return BUG_TRAP_TYPE_WARN;
173
174 /*
175 * Since this is the only store, concurrency is not an issue.
176 */
177 bug->flags |= BUGFLAG_DONE;
178 }
167 }
168
169 if (warning) {
170 /* this is a WARN_ON rather than BUG/BUG_ON */
171 __warn(file, line, (void *)bugaddr, BUG_GET_TAINT(bug), regs,
172 NULL);
173 return BUG_TRAP_TYPE_WARN;
174 }
175
176 printk(KERN_DEFAULT "------------[ cut here ]------------\n");
177
178 if (file)
179 pr_crit("kernel BUG at %s:%u!\n", file, line);
180 else
181 pr_crit("Kernel BUG at %p [verbose debug info unavailable]\n",
182 (void *)bugaddr);
183
184 return BUG_TRAP_TYPE_BUG;
185}
179 }
180
181 if (warning) {
182 /* this is a WARN_ON rather than BUG/BUG_ON */
183 __warn(file, line, (void *)bugaddr, BUG_GET_TAINT(bug), regs,
184 NULL);
185 return BUG_TRAP_TYPE_WARN;
186 }
187
188 printk(KERN_DEFAULT "------------[ cut here ]------------\n");
189
190 if (file)
191 pr_crit("kernel BUG at %s:%u!\n", file, line);
192 else
193 pr_crit("Kernel BUG at %p [verbose debug info unavailable]\n",
194 (void *)bugaddr);
195
196 return BUG_TRAP_TYPE_BUG;
197}