Skip to content

Commit a1df183

Browse files
committed
Bug 1465709 - Hook rust OOM handler on rustc 1.28. r=froydnj
Bug 1458161 added a rust OOM handler based on an unstable API that was removed in 1.27, replaced with something that didn't allow to get the failed allocation size. Latest 1.28 nightly (2018-06-13) has rust-lang/rust#50880, rust-lang/rust#51264 and rust-lang/rust#51241 merged, which allow to hook the OOM handler and get the failed allocation size again. Because this is still an unstable API, we explicitly depend on strict versions of rustc. We also explicitly error out if automation builds end up using a rustc version that doesn't allow us to get the allocation size for rust OOM, because we don't want that to happen without knowing. UltraBlame original commit: 5182bca90d0609f182d5a7b6b48ed2ffbbce32c2
1 parent 25b39cb commit a1df183

File tree

7 files changed

+255
-0
lines changed

7 files changed

+255
-0
lines changed

toolkit/crashreporter/nsExceptionHandler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,11 @@ install_rust_panic_hook
765765
(
766766
)
767767
;
768+
void
769+
install_rust_oom_hook
770+
(
771+
)
772+
;
768773
bool
769774
get_rust_panic_reason
770775
(
@@ -7332,6 +7337,10 @@ install_rust_panic_hook
73327337
(
73337338
)
73347339
;
7340+
install_rust_oom_hook
7341+
(
7342+
)
7343+
;
73357344
InitThreadAnnotation
73367345
(
73377346
)

toolkit/library/gtest/rust/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ shared
143143
oom_with_global_alloc
144144
"
145145
]
146+
oom_with_hook
147+
=
148+
[
149+
"
150+
gkrust
151+
-
152+
shared
153+
/
154+
oom_with_hook
155+
"
156+
]
146157
moz_memory
147158
=
148159
[

toolkit/library/rust/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ shared
141141
oom_with_global_alloc
142142
"
143143
]
144+
oom_with_hook
145+
=
146+
[
147+
"
148+
gkrust
149+
-
150+
shared
151+
/
152+
oom_with_hook
153+
"
154+
]
144155
moz_memory
145156
=
146157
[

toolkit/library/rust/gkrust-features.mozbuild

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,88 @@ gkrust_features
310310
oom_with_global_alloc
311311
'
312312
]
313+
elif
314+
CONFIG
315+
[
316+
'
317+
RUSTC_VERSION
318+
'
319+
]
320+
>
321+
=
322+
"
323+
1
324+
.
325+
28
326+
"
327+
and
328+
CONFIG
329+
[
330+
'
331+
RUSTC_VERSION
332+
'
333+
]
334+
<
335+
"
336+
1
337+
.
338+
29
339+
"
340+
:
341+
gkrust_features
342+
+
343+
=
344+
[
345+
'
346+
oom_with_hook
347+
'
348+
]
349+
elif
350+
not
351+
CONFIG
352+
[
353+
'
354+
MOZ_AUTOMATION
355+
'
356+
]
357+
:
358+
#
359+
We
360+
don
361+
'
362+
t
363+
want
364+
builds
365+
on
366+
automation
367+
to
368+
unwillingly
369+
stop
370+
annotating
371+
OOM
372+
#
373+
crash
374+
reports
375+
from
376+
rust
377+
.
378+
error
379+
(
380+
'
381+
Builds
382+
on
383+
automation
384+
must
385+
use
386+
a
387+
version
388+
of
389+
rust
390+
that
391+
supports
392+
OOM
393+
'
394+
'
395+
hooking
396+
'
397+
)

toolkit/library/rust/shared/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,10 @@ oom_with_global_alloc
679679
=
680680
[
681681
]
682+
oom_with_hook
683+
=
684+
[
685+
]
682686
moz_memory
683687
=
684688
[

toolkit/library/rust/shared/build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ main
77
[
88
cfg
99
(
10+
any
11+
(
1012
feature
1113
=
1214
"
1315
oom_with_global_alloc
1416
"
17+
feature
18+
=
19+
"
20+
oom_with_hook
21+
"
22+
)
1523
)
1624
]
1725
println

toolkit/library/rust/shared/lib.rs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ allocator_api
1818
)
1919
]
2020
#
21+
!
22+
[
23+
cfg_attr
24+
(
25+
feature
26+
=
27+
"
28+
oom_with_hook
29+
"
30+
feature
31+
(
32+
oom_hook
33+
)
34+
)
35+
]
36+
#
2137
[
2238
cfg
2339
(
@@ -1153,3 +1169,114 @@ global_alloc
11531169
:
11541170
GeckoHeap
11551171
;
1172+
#
1173+
[
1174+
cfg
1175+
(
1176+
feature
1177+
=
1178+
"
1179+
oom_with_hook
1180+
"
1181+
)
1182+
]
1183+
mod
1184+
oom_hook
1185+
{
1186+
use
1187+
std
1188+
:
1189+
:
1190+
alloc
1191+
:
1192+
:
1193+
{
1194+
Layout
1195+
set_oom_hook
1196+
}
1197+
;
1198+
extern
1199+
"
1200+
C
1201+
"
1202+
{
1203+
fn
1204+
GeckoHandleOOM
1205+
(
1206+
size
1207+
:
1208+
usize
1209+
)
1210+
-
1211+
>
1212+
!
1213+
;
1214+
}
1215+
pub
1216+
fn
1217+
hook
1218+
(
1219+
layout
1220+
:
1221+
Layout
1222+
)
1223+
{
1224+
unsafe
1225+
{
1226+
GeckoHandleOOM
1227+
(
1228+
layout
1229+
.
1230+
size
1231+
(
1232+
)
1233+
)
1234+
;
1235+
}
1236+
}
1237+
pub
1238+
fn
1239+
install
1240+
(
1241+
)
1242+
{
1243+
set_oom_hook
1244+
(
1245+
hook
1246+
)
1247+
;
1248+
}
1249+
}
1250+
#
1251+
[
1252+
no_mangle
1253+
]
1254+
pub
1255+
extern
1256+
"
1257+
C
1258+
"
1259+
fn
1260+
install_rust_oom_hook
1261+
(
1262+
)
1263+
{
1264+
#
1265+
[
1266+
cfg
1267+
(
1268+
feature
1269+
=
1270+
"
1271+
oom_with_hook
1272+
"
1273+
)
1274+
]
1275+
oom_hook
1276+
:
1277+
:
1278+
install
1279+
(
1280+
)
1281+
;
1282+
}

0 commit comments

Comments
 (0)