| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: subr_kcov.c,v 1.10 2019/12/01 17:41:11 kamil Exp $ */ | | 1 | /* $NetBSD: subr_kcov.c,v 1.11 2019/12/07 19:50:33 kamil Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Siddharth Muralee. | | 8 | * by Siddharth Muralee. |
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. |
| @@ -28,27 +28,26 @@ | | | @@ -28,27 +28,26 @@ |
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 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | | | 33 | |
34 | #include <sys/module.h> | | 34 | #include <sys/module.h> |
35 | #include <sys/param.h> | | 35 | #include <sys/param.h> |
36 | #include <sys/systm.h> | | 36 | #include <sys/systm.h> |
37 | #include <sys/kernel.h> | | 37 | #include <sys/kernel.h> |
38 | | | 38 | |
39 | #include <sys/conf.h> | | 39 | #include <sys/conf.h> |
40 | #include <sys/condvar.h> | | 40 | #include <sys/condvar.h> |
41 | #include <sys/cpu.h> | | | |
42 | #include <sys/file.h> | | 41 | #include <sys/file.h> |
43 | #include <sys/filedesc.h> | | 42 | #include <sys/filedesc.h> |
44 | #include <sys/kmem.h> | | 43 | #include <sys/kmem.h> |
45 | #include <sys/mman.h> | | 44 | #include <sys/mman.h> |
46 | #include <sys/mutex.h> | | 45 | #include <sys/mutex.h> |
47 | #include <sys/queue.h> | | 46 | #include <sys/queue.h> |
48 | | | 47 | |
49 | #include <uvm/uvm_extern.h> | | 48 | #include <uvm/uvm_extern.h> |
50 | #include <sys/kcov.h> | | 49 | #include <sys/kcov.h> |
51 | | | 50 | |
52 | #define KCOV_BUF_MAX_ENTRIES (256 << 10) | | 51 | #define KCOV_BUF_MAX_ENTRIES (256 << 10) |
53 | | | 52 | |
54 | #define KCOV_CMP_CONST 1 | | 53 | #define KCOV_CMP_CONST 1 |
| @@ -333,27 +332,27 @@ kcov_fops_mmap(file_t *fp, off_t *offp, | | | @@ -333,27 +332,27 @@ kcov_fops_mmap(file_t *fp, off_t *offp, |
333 | | | 332 | |
334 | *uobjp = kd->uobj; | | 333 | *uobjp = kd->uobj; |
335 | *maxprotp = prot; | | 334 | *maxprotp = prot; |
336 | *advicep = UVM_ADV_RANDOM; | | 335 | *advicep = UVM_ADV_RANDOM; |
337 | | | 336 | |
338 | out: | | 337 | out: |
339 | kcov_unlock(kd); | | 338 | kcov_unlock(kd); |
340 | return error; | | 339 | return error; |
341 | } | | 340 | } |
342 | | | 341 | |
343 | static inline bool __nomsan | | 342 | static inline bool __nomsan |
344 | in_interrupt(void) | | 343 | in_interrupt(void) |
345 | { | | 344 | { |
346 | return cpu_intr_p(); | | 345 | return curcpu()->ci_idepth >= 0; |
347 | } | | 346 | } |
348 | | | 347 | |
349 | void __sanitizer_cov_trace_pc(void); | | 348 | void __sanitizer_cov_trace_pc(void); |
350 | | | 349 | |
351 | void __nomsan | | 350 | void __nomsan |
352 | __sanitizer_cov_trace_pc(void) | | 351 | __sanitizer_cov_trace_pc(void) |
353 | { | | 352 | { |
354 | extern int cold; | | 353 | extern int cold; |
355 | uint64_t idx; | | 354 | uint64_t idx; |
356 | kcov_t *kd; | | 355 | kcov_t *kd; |
357 | | | 356 | |
358 | if (__predict_false(cold)) { | | 357 | if (__predict_false(cold)) { |
359 | /* Do not trace during boot. */ | | 358 | /* Do not trace during boot. */ |