Skip to content

Commit 02a0c4c

Browse files
committed
tokio: limit taskdumps to specific, blessed platforms
Taskdumps depend on backtrace-rs, whose unwinding behavior is platform-dependent. Taskdumps should not be enabled on a platform without first assessing and mitigating platform-dependent behavior. ref: https://github.com/tokio-rs/tokio/pull/5608/files#r1162746834
1 parent 39ab744 commit 02a0c4c

File tree

11 files changed

+104
-15
lines changed

11 files changed

+104
-15
lines changed

examples/dump.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
//! This example demonstrates tokio's experimental taskdumping functionality.
22
3-
#[cfg(all(tokio_unstable, target_os = "linux"))]
3+
#[cfg(all(
4+
tokio_unstable,
5+
target_os = "linux",
6+
any(target_arch = "aarch64", target_arch = "i686", target_arch = "x86_64")
7+
))]
48
#[tokio::main(flavor = "current_thread")]
59
async fn main() {
610
use std::hint::black_box;
@@ -34,7 +38,11 @@ async fn main() {
3438
}
3539
}
3640

37-
#[cfg(not(all(tokio_unstable, target_os = "linux")))]
41+
#[cfg(not(all(
42+
tokio_unstable,
43+
target_os = "linux",
44+
any(target_arch = "aarch64", target_arch = "i686", target_arch = "x86_64")
45+
)))]
3846
fn main() {
3947
println!("task dumps are not available")
4048
}

tokio/src/macros/cfg.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,26 @@ macro_rules! cfg_not_rt_multi_thread {
376376
macro_rules! cfg_taskdump {
377377
($($item:item)*) => {
378378
$(
379-
#[cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))]
380-
#[cfg_attr(docsrs, doc(cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))))]
379+
#[cfg(all(
380+
tokio_unstable,
381+
feature = "taskdump",
382+
target_os = "linux",
383+
any(
384+
target_arch = "aarch64",
385+
target_arch = "i686",
386+
target_arch = "x86_64"
387+
)
388+
))]
389+
#[cfg_attr(docsrs, doc(cfg(all(
390+
tokio_unstable,
391+
feature = "taskdump",
392+
target_os = "linux",
393+
any(
394+
target_arch = "aarch64",
395+
target_arch = "i686",
396+
target_arch = "x86_64"
397+
)
398+
))))]
381399
$item
382400
)*
383401
};

tokio/src/runtime/context.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ struct Context {
5050
/// the sheduler
5151
budget: Cell<coop::Budget>,
5252

53-
#[cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))]
53+
#[cfg(all(
54+
tokio_unstable,
55+
feature = "taskdump",
56+
target_os = "linux",
57+
any(target_arch = "aarch64", target_arch = "i686", target_arch = "x86_64")
58+
))]
5459
trace: trace::Context,
5560
}
5661

@@ -83,7 +88,16 @@ tokio_thread_local! {
8388

8489
budget: Cell::new(coop::Budget::unconstrained()),
8590

86-
#[cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))]
91+
#[cfg(all(
92+
tokio_unstable,
93+
feature = "taskdump",
94+
target_os = "linux",
95+
any(
96+
target_arch = "aarch64",
97+
target_arch = "i686",
98+
target_arch = "x86_64"
99+
)
100+
))]
87101
trace: trace::Context::new(),
88102
}
89103
}

tokio/src/runtime/handle.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,12 @@ impl Handle {
252252
/// [`tokio::time`]: crate::time
253253
#[track_caller]
254254
pub fn block_on<F: Future>(&self, future: F) -> F::Output {
255-
#[cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))]
255+
#[cfg(all(
256+
tokio_unstable,
257+
feature = "taskdump",
258+
target_os = "linux",
259+
any(target_arch = "aarch64", target_arch = "i686", target_arch = "x86_64")
260+
))]
256261
let future = super::task::trace::Trace::root(future);
257262

258263
#[cfg(all(tokio_unstable, feature = "tracing"))]
@@ -277,7 +282,12 @@ impl Handle {
277282
F::Output: Send + 'static,
278283
{
279284
let id = crate::runtime::task::Id::next();
280-
#[cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))]
285+
#[cfg(all(
286+
tokio_unstable,
287+
feature = "taskdump",
288+
target_os = "linux",
289+
any(target_arch = "aarch64", target_arch = "i686", target_arch = "x86_64")
290+
))]
281291
let future = super::task::trace::Trace::root(future);
282292
#[cfg(all(tokio_unstable, feature = "tracing"))]
283293
let future = crate::util::trace::task(future, "task", _name, id.as_u64());

tokio/src/runtime/runtime.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,12 @@ impl Runtime {
288288
/// [handle]: fn@Handle::block_on
289289
#[track_caller]
290290
pub fn block_on<F: Future>(&self, future: F) -> F::Output {
291-
#[cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))]
291+
#[cfg(all(
292+
tokio_unstable,
293+
feature = "taskdump",
294+
target_os = "linux",
295+
any(target_arch = "aarch64", target_arch = "i686", target_arch = "x86_64")
296+
))]
292297
let future = super::task::trace::Trace::root(future);
293298

294299
#[cfg(all(tokio_unstable, feature = "tracing"))]

tokio/src/runtime/scheduler/current_thread.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,12 @@ impl Handle {
378378
}
379379

380380
/// Capture a snapshot of this runtime's state.
381-
#[cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))]
381+
#[cfg(all(
382+
tokio_unstable,
383+
feature = "taskdump",
384+
target_os = "linux",
385+
any(target_arch = "aarch64", target_arch = "i686", target_arch = "x86_64")
386+
))]
382387
pub(crate) fn dump(&self) -> crate::runtime::Dump {
383388
use crate::runtime::dump;
384389
use task::trace::trace_current_thread;

tokio/src/runtime/task/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,12 @@ impl<S: 'static> Task<S> {
344344
}
345345
}
346346

347-
#[cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))]
347+
#[cfg(all(
348+
tokio_unstable,
349+
feature = "taskdump",
350+
target_os = "linux",
351+
any(target_arch = "aarch64", target_arch = "i686", target_arch = "x86_64")
352+
))]
348353
pub(crate) fn as_raw(&self) -> RawTask {
349354
self.raw
350355
}

tokio/src/runtime/task/state.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ impl State {
271271
}
272272

273273
/// Transitions the state to `NOTIFIED`, unconditionally increasing the ref count.
274-
#[cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))]
274+
#[cfg(all(
275+
tokio_unstable,
276+
feature = "taskdump",
277+
target_os = "linux",
278+
any(target_arch = "aarch64", target_arch = "i686", target_arch = "x86_64")
279+
))]
275280
pub(super) fn transition_to_notified_for_tracing(&self) {
276281
self.fetch_update_action(|mut snapshot| {
277282
snapshot.set_notified();

tokio/src/task/spawn.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,16 @@ cfg_rt! {
179179
T::Output: Send + 'static,
180180
{
181181
use crate::runtime::task;
182-
#[cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))]
182+
#[cfg(all(
183+
tokio_unstable,
184+
feature = "taskdump",
185+
target_os = "linux",
186+
any(
187+
target_arch = "aarch64",
188+
target_arch = "i686",
189+
target_arch = "x86_64"
190+
)
191+
))]
183192
let future = task::trace::Trace::root(future);
184193
let id = task::Id::next();
185194
let task = crate::util::trace::task(future, "task", name, id.as_u64());

tokio/src/task/yield_now.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ pub async fn yield_now() {
4646
type Output = ();
4747

4848
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
49-
#[cfg(all(tokio_unstable, feature = "taskdump", target_os = "linux"))]
49+
#[cfg(all(
50+
tokio_unstable,
51+
feature = "taskdump",
52+
target_os = "linux",
53+
any(target_arch = "aarch64", target_arch = "i686", target_arch = "x86_64")
54+
))]
5055
crate::runtime::task::trace::Trace::leaf();
5156

5257
if self.yielded {

tokio/tests/dump_current_thread.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#![cfg(all(feature = "taskdump", tokio_unstable, target_os = "linux"))]
1+
#![cfg(all(
2+
tokio_unstable,
3+
feature = "taskdump",
4+
target_os = "linux",
5+
any(target_arch = "aarch64", target_arch = "i686", target_arch = "x86_64")
6+
))]
27

38
use std::hint::black_box;
49
use tokio::runtime;

0 commit comments

Comments
 (0)