Commit 294ec5c
committed
Skip breakpoints on read-only bytecode pages instead of aborting
The debugger installs breakpoints by overwriting an opcode in the
bytecode stream with Debugger, which requires the page to be
writable. The patcher uses mprotect to make the page RW; on
failure it called hermes_fatal and aborted the process.
If the bytecode lives in a read-only segment (e.g. statically
linked into the binary as a const array, ending up in
__DATA_CONST / __TEXT_CONST on macOS), mprotect is rejected by
the OS (EACCES under hardened runtime) and the abort takes down
the whole process. This is reachable in practice because step /
restoration / on-load breakpoints install at offset 0 of every
CodeBlock about to execute, so stepping into such a CodeBlock
from anywhere kills the runtime.
Make the patch best-effort:
- CodeBlock::installBreakpointAtOffset and the static makeWritable
helper now return bool. On failure no state is modified.
- Debugger::installBreakpoint returns BreakpointLocation* (nullptr
on failure), rolling back the partial breakpointLocations_ entry
it just inserted.
- doSetNonUserBreakpoint and setOnLoadBreakpoint silently skip when
installBreakpoint fails. Step / restoration / on-load breakpoints
are best-effort hints; the only loss is that stepping cannot
pause at the entry of a CodeBlock whose page cannot be patched.
- setUserBreakpoint now returns bool so callers can propagate
failure to their clients (e.g. CDP could surface a proper error
back to DevTools instead of aborting).
- The four call sites that re-install a previously-installed
breakpoint (the page is known writable since the original
install succeeded) assert the result.1 parent c8dd0b1 commit 294ec5c
4 files changed
Lines changed: 91 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
374 | | - | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
375 | 379 | | |
376 | 380 | | |
377 | 381 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
476 | | - | |
477 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
478 | 483 | | |
479 | 484 | | |
480 | 485 | | |
| |||
489 | 494 | | |
490 | 495 | | |
491 | 496 | | |
492 | | - | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
493 | 502 | | |
494 | 503 | | |
495 | 504 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
336 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
337 | 339 | | |
338 | 340 | | |
339 | 341 | | |
| |||
343 | 345 | | |
344 | 346 | | |
345 | 347 | | |
346 | | - | |
| 348 | + | |
347 | 349 | | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | 350 | | |
352 | 351 | | |
353 | | - | |
| 352 | + | |
354 | 353 | | |
355 | 354 | | |
356 | 355 | | |
| |||
362 | 361 | | |
363 | 362 | | |
364 | 363 | | |
365 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
366 | 367 | | |
367 | 368 | | |
| 369 | + | |
368 | 370 | | |
369 | 371 | | |
370 | 372 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
424 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
425 | 430 | | |
426 | 431 | | |
427 | 432 | | |
| |||
767 | 772 | | |
768 | 773 | | |
769 | 774 | | |
770 | | - | |
| 775 | + | |
771 | 776 | | |
772 | 777 | | |
773 | | - | |
774 | | - | |
775 | | - | |
776 | | - | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
777 | 782 | | |
778 | 783 | | |
779 | | - | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
780 | 793 | | |
781 | | - | |
| 794 | + | |
782 | 795 | | |
783 | 796 | | |
784 | 797 | | |
| |||
796 | 809 | | |
797 | 810 | | |
798 | 811 | | |
799 | | - | |
| 812 | + | |
800 | 813 | | |
801 | 814 | | |
802 | 815 | | |
803 | | - | |
804 | | - | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
805 | 822 | | |
806 | 823 | | |
807 | 824 | | |
808 | 825 | | |
809 | 826 | | |
810 | 827 | | |
811 | 828 | | |
812 | | - | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
813 | 837 | | |
814 | 838 | | |
815 | | - | |
816 | | - | |
| 839 | + | |
| 840 | + | |
817 | 841 | | |
818 | 842 | | |
819 | | - | |
820 | | - | |
| 843 | + | |
| 844 | + | |
821 | 845 | | |
822 | 846 | | |
823 | 847 | | |
| |||
828 | 852 | | |
829 | 853 | | |
830 | 854 | | |
831 | | - | |
| 855 | + | |
832 | 856 | | |
833 | | - | |
| 857 | + | |
834 | 858 | | |
835 | 859 | | |
836 | 860 | | |
| |||
843 | 867 | | |
844 | 868 | | |
845 | 869 | | |
846 | | - | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
847 | 876 | | |
848 | 877 | | |
849 | 878 | | |
850 | 879 | | |
851 | 880 | | |
852 | 881 | | |
853 | | - | |
854 | | - | |
| 882 | + | |
| 883 | + | |
855 | 884 | | |
856 | | - | |
| 885 | + | |
857 | 886 | | |
858 | 887 | | |
859 | 888 | | |
| |||
1017 | 1046 | | |
1018 | 1047 | | |
1019 | 1048 | | |
1020 | | - | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
1021 | 1052 | | |
| 1053 | + | |
| 1054 | + | |
1022 | 1055 | | |
1023 | 1056 | | |
1024 | 1057 | | |
| |||
1046 | 1079 | | |
1047 | 1080 | | |
1048 | 1081 | | |
1049 | | - | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
1050 | 1086 | | |
1051 | 1087 | | |
1052 | 1088 | | |
| |||
1092 | 1128 | | |
1093 | 1129 | | |
1094 | 1130 | | |
1095 | | - | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
1096 | 1135 | | |
1097 | 1136 | | |
1098 | 1137 | | |
| |||
0 commit comments