| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: subr_kcov.c,v 1.8 2019/05/26 05:41:45 kamil Exp $ */ | | 1 | /* $NetBSD: subr_kcov.c,v 1.9 2019/11/15 09:44:44 maxv 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. |
| @@ -329,35 +329,35 @@ kcov_fops_mmap(file_t *fp, off_t *offp, | | | @@ -329,35 +329,35 @@ kcov_fops_mmap(file_t *fp, off_t *offp, |
329 | } | | 329 | } |
330 | | | 330 | |
331 | uao_reference(kd->uobj); | | 331 | uao_reference(kd->uobj); |
332 | | | 332 | |
333 | *uobjp = kd->uobj; | | 333 | *uobjp = kd->uobj; |
334 | *maxprotp = prot; | | 334 | *maxprotp = prot; |
335 | *advicep = UVM_ADV_RANDOM; | | 335 | *advicep = UVM_ADV_RANDOM; |
336 | | | 336 | |
337 | out: | | 337 | out: |
338 | kcov_unlock(kd); | | 338 | kcov_unlock(kd); |
339 | return error; | | 339 | return error; |
340 | } | | 340 | } |
341 | | | 341 | |
342 | static inline bool | | 342 | static inline bool __nomsan |
343 | in_interrupt(void) | | 343 | in_interrupt(void) |
344 | { | | 344 | { |
345 | return curcpu()->ci_idepth >= 0; | | 345 | return curcpu()->ci_idepth >= 0; |
346 | } | | 346 | } |
347 | | | 347 | |
348 | void __sanitizer_cov_trace_pc(void); | | 348 | void __sanitizer_cov_trace_pc(void); |
349 | | | 349 | |
350 | void | | 350 | void __nomsan |
351 | __sanitizer_cov_trace_pc(void) | | 351 | __sanitizer_cov_trace_pc(void) |
352 | { | | 352 | { |
353 | extern int cold; | | 353 | extern int cold; |
354 | uint64_t idx; | | 354 | uint64_t idx; |
355 | kcov_t *kd; | | 355 | kcov_t *kd; |
356 | | | 356 | |
357 | if (__predict_false(cold)) { | | 357 | if (__predict_false(cold)) { |
358 | /* Do not trace during boot. */ | | 358 | /* Do not trace during boot. */ |
359 | return; | | 359 | return; |
360 | } | | 360 | } |
361 | | | 361 | |
362 | if (in_interrupt()) { | | 362 | if (in_interrupt()) { |
363 | /* Do not trace in interrupts. */ | | 363 | /* Do not trace in interrupts. */ |
| @@ -378,27 +378,27 @@ __sanitizer_cov_trace_pc(void) | | | @@ -378,27 +378,27 @@ __sanitizer_cov_trace_pc(void) |
378 | if (kd->mode != KCOV_MODE_TRACE_PC) { | | 378 | if (kd->mode != KCOV_MODE_TRACE_PC) { |
379 | /* PC tracing mode not enabled */ | | 379 | /* PC tracing mode not enabled */ |
380 | return; | | 380 | return; |
381 | } | | 381 | } |
382 | | | 382 | |
383 | idx = kd->buf[0]; | | 383 | idx = kd->buf[0]; |
384 | if (idx < kd->bufnent) { | | 384 | if (idx < kd->bufnent) { |
385 | kd->buf[idx+1] = | | 385 | kd->buf[idx+1] = |
386 | (intptr_t)__builtin_return_address(0); | | 386 | (intptr_t)__builtin_return_address(0); |
387 | kd->buf[0] = idx + 1; | | 387 | kd->buf[0] = idx + 1; |
388 | } | | 388 | } |
389 | } | | 389 | } |
390 | | | 390 | |
391 | static void | | 391 | static void __nomsan |
392 | trace_cmp(uint64_t type, uint64_t arg1, uint64_t arg2, intptr_t pc) | | 392 | trace_cmp(uint64_t type, uint64_t arg1, uint64_t arg2, intptr_t pc) |
393 | { | | 393 | { |
394 | extern int cold; | | 394 | extern int cold; |
395 | uint64_t idx; | | 395 | uint64_t idx; |
396 | kcov_t *kd; | | 396 | kcov_t *kd; |
397 | | | 397 | |
398 | if (__predict_false(cold)) { | | 398 | if (__predict_false(cold)) { |
399 | /* Do not trace during boot. */ | | 399 | /* Do not trace during boot. */ |
400 | return; | | 400 | return; |
401 | } | | 401 | } |
402 | | | 402 | |
403 | if (in_interrupt()) { | | 403 | if (in_interrupt()) { |
404 | /* Do not trace in interrupts. */ | | 404 | /* Do not trace in interrupts. */ |
| @@ -423,107 +423,107 @@ trace_cmp(uint64_t type, uint64_t arg1, | | | @@ -423,107 +423,107 @@ trace_cmp(uint64_t type, uint64_t arg1, |
423 | | | 423 | |
424 | idx = kd->buf[0]; | | 424 | idx = kd->buf[0]; |
425 | if ((idx * 4 + 4) <= kd->bufnent) { | | 425 | if ((idx * 4 + 4) <= kd->bufnent) { |
426 | kd->buf[idx * 4 + 1] = type; | | 426 | kd->buf[idx * 4 + 1] = type; |
427 | kd->buf[idx * 4 + 2] = arg1; | | 427 | kd->buf[idx * 4 + 2] = arg1; |
428 | kd->buf[idx * 4 + 3] = arg2; | | 428 | kd->buf[idx * 4 + 3] = arg2; |
429 | kd->buf[idx * 4 + 4] = pc; | | 429 | kd->buf[idx * 4 + 4] = pc; |
430 | kd->buf[0] = idx + 1; | | 430 | kd->buf[0] = idx + 1; |
431 | } | | 431 | } |
432 | } | | 432 | } |
433 | | | 433 | |
434 | void __sanitizer_cov_trace_cmp1(uint8_t arg1, uint8_t arg2); | | 434 | void __sanitizer_cov_trace_cmp1(uint8_t arg1, uint8_t arg2); |
435 | | | 435 | |
436 | void | | 436 | void __nomsan |
437 | __sanitizer_cov_trace_cmp1(uint8_t arg1, uint8_t arg2) | | 437 | __sanitizer_cov_trace_cmp1(uint8_t arg1, uint8_t arg2) |
438 | { | | 438 | { |
439 | | | 439 | |
440 | trace_cmp(KCOV_CMP_SIZE(0), arg1, arg2, | | 440 | trace_cmp(KCOV_CMP_SIZE(0), arg1, arg2, |
441 | (intptr_t)__builtin_return_address(0)); | | 441 | (intptr_t)__builtin_return_address(0)); |
442 | } | | 442 | } |
443 | | | 443 | |
444 | void __sanitizer_cov_trace_cmp2(uint16_t arg1, uint16_t arg2); | | 444 | void __sanitizer_cov_trace_cmp2(uint16_t arg1, uint16_t arg2); |
445 | | | 445 | |
446 | void | | 446 | void __nomsan |
447 | __sanitizer_cov_trace_cmp2(uint16_t arg1, uint16_t arg2) | | 447 | __sanitizer_cov_trace_cmp2(uint16_t arg1, uint16_t arg2) |
448 | { | | 448 | { |
449 | | | 449 | |
450 | trace_cmp(KCOV_CMP_SIZE(1), arg1, arg2, | | 450 | trace_cmp(KCOV_CMP_SIZE(1), arg1, arg2, |
451 | (intptr_t)__builtin_return_address(0)); | | 451 | (intptr_t)__builtin_return_address(0)); |
452 | } | | 452 | } |
453 | | | 453 | |
454 | void __sanitizer_cov_trace_cmp4(uint32_t arg1, uint32_t arg2); | | 454 | void __sanitizer_cov_trace_cmp4(uint32_t arg1, uint32_t arg2); |
455 | | | 455 | |
456 | void | | 456 | void __nomsan |
457 | __sanitizer_cov_trace_cmp4(uint32_t arg1, uint32_t arg2) | | 457 | __sanitizer_cov_trace_cmp4(uint32_t arg1, uint32_t arg2) |
458 | { | | 458 | { |
459 | | | 459 | |
460 | trace_cmp(KCOV_CMP_SIZE(2), arg1, arg2, | | 460 | trace_cmp(KCOV_CMP_SIZE(2), arg1, arg2, |
461 | (intptr_t)__builtin_return_address(0)); | | 461 | (intptr_t)__builtin_return_address(0)); |
462 | } | | 462 | } |
463 | | | 463 | |
464 | void __sanitizer_cov_trace_cmp8(uint64_t arg1, uint64_t arg2); | | 464 | void __sanitizer_cov_trace_cmp8(uint64_t arg1, uint64_t arg2); |
465 | | | 465 | |
466 | void | | 466 | void __nomsan |
467 | __sanitizer_cov_trace_cmp8(uint64_t arg1, uint64_t arg2) | | 467 | __sanitizer_cov_trace_cmp8(uint64_t arg1, uint64_t arg2) |
468 | { | | 468 | { |
469 | | | 469 | |
470 | trace_cmp(KCOV_CMP_SIZE(3), arg1, arg2, | | 470 | trace_cmp(KCOV_CMP_SIZE(3), arg1, arg2, |
471 | (intptr_t)__builtin_return_address(0)); | | 471 | (intptr_t)__builtin_return_address(0)); |
472 | } | | 472 | } |
473 | | | 473 | |
474 | void __sanitizer_cov_trace_const_cmp1(uint8_t arg1, uint8_t arg2); | | 474 | void __sanitizer_cov_trace_const_cmp1(uint8_t arg1, uint8_t arg2); |
475 | | | 475 | |
476 | void | | 476 | void __nomsan |
477 | __sanitizer_cov_trace_const_cmp1(uint8_t arg1, uint8_t arg2) | | 477 | __sanitizer_cov_trace_const_cmp1(uint8_t arg1, uint8_t arg2) |
478 | { | | 478 | { |
479 | | | 479 | |
480 | trace_cmp(KCOV_CMP_SIZE(0) | KCOV_CMP_CONST, arg1, arg2, | | 480 | trace_cmp(KCOV_CMP_SIZE(0) | KCOV_CMP_CONST, arg1, arg2, |
481 | (intptr_t)__builtin_return_address(0)); | | 481 | (intptr_t)__builtin_return_address(0)); |
482 | } | | 482 | } |
483 | | | 483 | |
484 | void __sanitizer_cov_trace_const_cmp2(uint16_t arg1, uint16_t arg2); | | 484 | void __sanitizer_cov_trace_const_cmp2(uint16_t arg1, uint16_t arg2); |
485 | | | 485 | |
486 | void | | 486 | void __nomsan |
487 | __sanitizer_cov_trace_const_cmp2(uint16_t arg1, uint16_t arg2) | | 487 | __sanitizer_cov_trace_const_cmp2(uint16_t arg1, uint16_t arg2) |
488 | { | | 488 | { |
489 | | | 489 | |
490 | trace_cmp(KCOV_CMP_SIZE(1) | KCOV_CMP_CONST, arg1, arg2, | | 490 | trace_cmp(KCOV_CMP_SIZE(1) | KCOV_CMP_CONST, arg1, arg2, |
491 | (intptr_t)__builtin_return_address(0)); | | 491 | (intptr_t)__builtin_return_address(0)); |
492 | } | | 492 | } |
493 | | | 493 | |
494 | void __sanitizer_cov_trace_const_cmp4(uint32_t arg1, uint32_t arg2); | | 494 | void __sanitizer_cov_trace_const_cmp4(uint32_t arg1, uint32_t arg2); |
495 | | | 495 | |
496 | void | | 496 | void __nomsan |
497 | __sanitizer_cov_trace_const_cmp4(uint32_t arg1, uint32_t arg2) | | 497 | __sanitizer_cov_trace_const_cmp4(uint32_t arg1, uint32_t arg2) |
498 | { | | 498 | { |
499 | | | 499 | |
500 | trace_cmp(KCOV_CMP_SIZE(2) | KCOV_CMP_CONST, arg1, arg2, | | 500 | trace_cmp(KCOV_CMP_SIZE(2) | KCOV_CMP_CONST, arg1, arg2, |
501 | (intptr_t)__builtin_return_address(0)); | | 501 | (intptr_t)__builtin_return_address(0)); |
502 | } | | 502 | } |
503 | | | 503 | |
504 | void __sanitizer_cov_trace_const_cmp8(uint64_t arg1, uint64_t arg2); | | 504 | void __sanitizer_cov_trace_const_cmp8(uint64_t arg1, uint64_t arg2); |
505 | | | 505 | |
506 | void | | 506 | void __nomsan |
507 | __sanitizer_cov_trace_const_cmp8(uint64_t arg1, uint64_t arg2) | | 507 | __sanitizer_cov_trace_const_cmp8(uint64_t arg1, uint64_t arg2) |
508 | { | | 508 | { |
509 | | | 509 | |
510 | trace_cmp(KCOV_CMP_SIZE(3) | KCOV_CMP_CONST, arg1, arg2, | | 510 | trace_cmp(KCOV_CMP_SIZE(3) | KCOV_CMP_CONST, arg1, arg2, |
511 | (intptr_t)__builtin_return_address(0)); | | 511 | (intptr_t)__builtin_return_address(0)); |
512 | } | | 512 | } |
513 | | | 513 | |
514 | void __sanitizer_cov_trace_switch(uint64_t val, uint64_t *cases); | | 514 | void __sanitizer_cov_trace_switch(uint64_t val, uint64_t *cases); |
515 | | | 515 | |
516 | void | | 516 | void __nomsan |
517 | __sanitizer_cov_trace_switch(uint64_t val, uint64_t *cases) | | 517 | __sanitizer_cov_trace_switch(uint64_t val, uint64_t *cases) |
518 | { | | 518 | { |
519 | uint64_t i, nbits, ncases, type; | | 519 | uint64_t i, nbits, ncases, type; |
520 | intptr_t pc; | | 520 | intptr_t pc; |
521 | | | 521 | |
522 | pc = (intptr_t)__builtin_return_address(0); | | 522 | pc = (intptr_t)__builtin_return_address(0); |
523 | ncases = cases[0]; | | 523 | ncases = cases[0]; |
524 | nbits = cases[1]; | | 524 | nbits = cases[1]; |
525 | | | 525 | |
526 | switch (nbits) { | | 526 | switch (nbits) { |
527 | case 8: | | 527 | case 8: |
528 | type = KCOV_CMP_SIZE(0); | | 528 | type = KCOV_CMP_SIZE(0); |
529 | break; | | 529 | break; |