Skip to content

Commit bb63189

Browse files
richard-townsend-armJohn Kleinschmidt
authored andcommitted
fix: crash reporting on Windows on Arm (electron#19391)
* feat: cherry-pick V8 unwinding support This commit backports [1] (originally written by @ThomsonTan) into V8 7.6. With this patch in place, calls made from JS into the atom core which crash electron.exe will now generate crash dumps on Windows on Arm rather than silently dying. [1] https://chromium-review.googlesource.com/c/v8/v8/+/1701133/11 * feat: backport crashpad cpu capture context Backport of [1] (originally written by @kaadam) to Chromium 76's crashpad. This lets you see the register values within the crash dump. [1] https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1632749 * build: make win on arm patches only apply for win on arm builds * Update .patches * Update .patches * Update DEPS * fix: update the patch to the as-landed version * fix: remove accidental revert of crashpad_pid_check.patch
1 parent 64026de commit bb63189

File tree

6 files changed

+1731
-0
lines changed

6 files changed

+1731
-0
lines changed

DEPS

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ vars = {
3131
# To be able to build clean Chromium from sources.
3232
'apply_patches': True,
3333

34+
# Apply the patches specific to windows on arm64
35+
'apply_win_arm64_patches': False,
36+
3437
# Python interface to Amazon Web Services. Is used for releases only.
3538
'checkout_boto': False,
3639

@@ -96,6 +99,16 @@ hooks = [
9699
'src/electron/patches/common/config.json',
97100
],
98101
},
102+
{
103+
'name': 'patch_chromium',
104+
'condition': '(checkout_chromium and apply_patches) and apply_win_arm64_patches',
105+
'pattern': 'src/electron',
106+
'action': [
107+
'python',
108+
'src/electron/script/apply_all_patches.py',
109+
'src/electron/patches/win_arm64/config.json',
110+
],
111+
},
99112
{
100113
'name': 'electron_external_binaries',
101114
'pattern': 'src/electron/script/update-external-binaries.py',

patches/win_arm64/chromium/.patches

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
backport_crashpad_cpu_context_capture.patch
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Richard Townsend <Richard.Townsend@arm.com>
3+
Date: Tue, 23 Jul 2019 15:36:43 +0100
4+
Subject: feat: backport crashpad CPU context capture
5+
6+
Backport of [1] for Windows on Arm (originally writen by @kaadam).
7+
This allows you to see register values within the crash report.
8+
9+
[1] https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1632749
10+
11+
diff --git a/third_party/crashpad/crashpad/handler/BUILD.gn b/third_party/crashpad/crashpad/handler/BUILD.gn
12+
index dc32b94e651c906f9ab1868165448805c71fe258..67c77e5fbc131d789b77dcca215f507027fd1fd0 100644
13+
--- a/third_party/crashpad/crashpad/handler/BUILD.gn
14+
+++ b/third_party/crashpad/crashpad/handler/BUILD.gn
15+
@@ -180,8 +180,6 @@ if (crashpad_is_android) {
16+
if (crashpad_is_in_chromium) {
17+
no_default_deps = true
18+
}
19+
- remove_configs =
20+
- [ "//build/config/android:default_orderfile_instrumentation" ]
21+
}
22+
}
23+
24+
diff --git a/third_party/crashpad/crashpad/util/BUILD.gn b/third_party/crashpad/crashpad/util/BUILD.gn
25+
index 620ae2550a0ba81fb9ad903d570d5ddbb8915b79..088a7b59a4e34bb5489ab34a0ac928f706efc8d3 100644
26+
--- a/third_party/crashpad/crashpad/util/BUILD.gn
27+
+++ b/third_party/crashpad/crashpad/util/BUILD.gn
28+
@@ -396,8 +396,17 @@ static_library("util") {
29+
"win/safe_terminate_process.asm",
30+
]
31+
} else {
32+
- # TODO: Add assembly code of CaptureContext for Windows ARM64.
33+
- sources += [ "misc/capture_context_broken.cc" ]
34+
+ # Most Crashpad builds use Microsoft's armasm64.exe macro assembler for
35+
+ # .asm source files. When building in Chromium, clang-cl is used as the
36+
+ # assembler instead. Since the two assemblers recognize different
37+
+ # assembly dialects, the same .asm file can't be used for each. As a
38+
+ # workaround, use a prebuilt .obj file when the Microsoft-dialect
39+
+ # assembler isn't available.
40+
+ if (crashpad_is_in_chromium) {
41+
+ sources += [ "misc/capture_context_win_arm64.obj" ]
42+
+ } else {
43+
+ sources += [ "misc/capture_context_win_arm64.asm" ]
44+
+ }
45+
}
46+
} else {
47+
sources += [
48+
diff --git a/third_party/crashpad/crashpad/util/misc/capture_context_fuchsia.S b/third_party/crashpad/crashpad/util/misc/capture_context_fuchsia.S
49+
index 21aefad0b1ed0e05112060e427bbef8fd86dfee2..0ebc7f7fe8ca159268bec6dd34c2e043bc1cfc63 100644
50+
--- a/third_party/crashpad/crashpad/util/misc/capture_context_fuchsia.S
51+
+++ b/third_party/crashpad/crashpad/util/misc/capture_context_fuchsia.S
52+
@@ -116,7 +116,7 @@ CAPTURECONTEXT_SYMBOL:
53+
movq 0x90(%rdi), %rax
54+
movq 0x28(%rdi), %r8
55+
56+
- // TODO(scottmg): save floating-point registers.
57+
+ // TODO(https://crashpad.chromium.org/bug/300): save floating-point registers.
58+
59+
popfq
60+
61+
@@ -166,7 +166,7 @@ CAPTURECONTEXT_SYMBOL:
62+
// Restore x1 from the saved context.
63+
ldr x1, [x0, #0xc0]
64+
65+
- // TODO(scottmg): save floating-point registers.
66+
+ // TODO(https://crashpad.chromium.org/bug/300): save floating-point registers.
67+
68+
ret
69+
70+
diff --git a/third_party/crashpad/crashpad/util/misc/capture_context_linux.S b/third_party/crashpad/crashpad/util/misc/capture_context_linux.S
71+
index 657a979a76ea1cfc02633e8553d41005fd1a2749..de71e7231273ac2a79b3eebfde2357e3eda9f94d 100644
72+
--- a/third_party/crashpad/crashpad/util/misc/capture_context_linux.S
73+
+++ b/third_party/crashpad/crashpad/util/misc/capture_context_linux.S
74+
@@ -282,7 +282,7 @@ CAPTURECONTEXT_SYMBOL2:
75+
// Restore r1.
76+
ldr r1, [r0, #0x24]
77+
78+
- // TODO(jperaza): save floating-point registers.
79+
+ // TODO(https://crashpad.chromium.org/bug/300): save floating-point registers.
80+
81+
mov PC, LR
82+
83+
@@ -326,7 +326,7 @@ CAPTURECONTEXT_SYMBOL2:
84+
// Restore x1 from the saved context.
85+
ldr x1, [x0, #0xc0]
86+
87+
- // TODO(jperaza): save floating-point registers.
88+
+ // TODO(https://crashpad.chromium.org/bug/300): save floating-point registers.
89+
90+
ret
91+
#elif defined(__mips__)
92+
diff --git a/third_party/crashpad/crashpad/util/misc/capture_context_win_arm64.asm b/third_party/crashpad/crashpad/util/misc/capture_context_win_arm64.asm
93+
new file mode 100644
94+
index 0000000000000000000000000000000000000000..5630698f8d8ef198eb9f8cf28692eeaf97a961a5
95+
--- /dev/null
96+
+++ b/third_party/crashpad/crashpad/util/misc/capture_context_win_arm64.asm
97+
@@ -0,0 +1,64 @@
98+
+; Copyright 2019 The Crashpad Authors. All rights reserved.
99+
+;
100+
+; Licensed under the Apache License, Version 2.0 (the "License");
101+
+; you may not use this file except in compliance with the License.
102+
+; You may obtain a copy of the License at
103+
+;
104+
+; http://www.apache.org/licenses/LICENSE-2.0
105+
+;
106+
+; Unless required by applicable law or agreed to in writing, software
107+
+; distributed under the License is distributed on an "AS IS" BASIS,
108+
+; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
109+
+; See the License for the specific language governing permissions and
110+
+; limitations under the License.
111+
+
112+
+ EXPORT |?CaptureContext@crashpad@@YAXPEAU_CONTEXT@@@Z|
113+
+ AREA |.text|, CODE
114+
+|?CaptureContext@crashpad@@YAXPEAU_CONTEXT@@@Z| PROC
115+
+ ; Save general purpose registers in context.regs[i].
116+
+ ; The original x0 can't be recovered.
117+
+ stp x0, x1, [x0, #0x008]
118+
+ stp x2, x3, [x0, #0x018]
119+
+ stp x4, x5, [x0, #0x028]
120+
+ stp x6, x7, [x0, #0x038]
121+
+ stp x8, x9, [x0, #0x048]
122+
+ stp x10, x11, [x0, #0x058]
123+
+ stp x12, x13, [x0, #0x068]
124+
+ stp x14, x15, [x0, #0x078]
125+
+ stp x16, x17, [x0, #0x088]
126+
+ stp x18, x19, [x0, #0x098]
127+
+ stp x20, x21, [x0, #0x0a8]
128+
+ stp x22, x23, [x0, #0x0b8]
129+
+ stp x24, x25, [x0, #0x0c8]
130+
+ stp x26, x27, [x0, #0x0d8]
131+
+ stp x28, x29, [x0, #0x0e8]
132+
+
133+
+ ; The original LR can't be recovered.
134+
+ str LR, [x0, #0x0f8]
135+
+
136+
+ ; Use x1 as a scratch register.
137+
+ mov x1, SP
138+
+ str x1, [x0, #0x100] ; context.sp
139+
+
140+
+ ; The link register holds the return address for this function.
141+
+ str LR, [x0, #0x108] ; context.pc
142+
+
143+
+ ; pstate should hold SPSR but NZCV are the only bits we know about.
144+
+ mrs x1, NZCV
145+
+
146+
+ ; Enable Control flags, such as CONTEXT_ARM64, CONTEXT_CONTROL,
147+
+ ; CONTEXT_INTEGER
148+
+ ldr w1, =0x00400003
149+
+
150+
+ ; Set ControlFlags /0x000/ and pstate /0x004/ at the same time.
151+
+ str x1, [x0, #0x000]
152+
+
153+
+ ; Restore x1 from the saved context.
154+
+ ldr x1, [x0, #0x010]
155+
+
156+
+ ; TODO(https://crashpad.chromium.org/bug/300): save floating-point registers
157+
+
158+
+ ret
159+
+ ENDP
160+
+
161+
+ END
162+
diff --git a/third_party/crashpad/crashpad/util/misc/capture_context_win_arm64.obj b/third_party/crashpad/crashpad/util/misc/capture_context_win_arm64.obj
163+
new file mode 100644
164+
index 0000000000000000000000000000000000000000..11c76a1aae15f8331d37063a3adc5e6ad37fcc8f
165+
GIT binary patch
166+
literal 614
167+
zcmYdU#l-MIOFuS-k%57S0Rr?&QY%WJY!H<K#YjR73JeYjdMT+%rRgfcF!3os#t9e)
168+
zN;@zJI5D&^tYqq8T*)$pX(ihn=9L^vSXOeaVO`0yg>5C@9`=<2M>tjro#9+5a)oQ9
169+
z*d6Yb5>I$mO1<G-Df5MIrCbfe&xgzm6B!#Ae#*5l{A6^pzS_vZAOUplPeu-hp9h%Z
170+
zuQ4+?Ft7ma`v}AxK<vT5C<wCN*(#>EC^;s%D6u%BATb5OC@sm%iOJ0@2FfKCl#~{w
171+
z#wX|Jfjk{wo|zY)Sd?pKqL-hP#lT?0U?a%P#K7<kWE>dqF$gfs$Yf;j%}g%JFV0UZ
172+
zQP2p|RB#OPRq#y&iYPc17pLYX<)jt?RXZf-=N9N?rp(A>X8ix3fdS~wwA92BJp%&)
173+
zpe#g0FD)}C6=F2QKcJd)7K&V*Sey$ri~%_ofuY5~%m|7{RDc|VKyL!ofZ`AnfI=4p
174+
sK;|$p7y(IpXGq97LjukL7RU|`k&Y1ou8yJc&i;NOt`Q*)4h~Ta0HmRmk^lez
175+
176+
literal 0
177+
HcmV?d00001
178+

patches/win_arm64/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"src/electron/patches/win_arm64/chromium": "src",
3+
4+
"src/electron/patches/win_arm64/v8": "src/v8"
5+
}

patches/win_arm64/v8/.patches

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
unwind_v8_frames_correctly_on_windows_arm64.patch

0 commit comments

Comments
 (0)