-
Notifications
You must be signed in to change notification settings - Fork 5k
Pass the job to JobContext::run and FileOpener::get_fd by pointer, not &mut #37820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,9 +238,19 @@ pub trait JobContext: Sized + 'static { | |
| /// Return `done` to complete now; keep it (e.g. across async I/O that | ||
| /// finishes on another thread) and call [`Completion::finish`] later to | ||
| /// complete then. Work that outlives this call runs under no borrow and | ||
| /// must touch only `off`. | ||
| fn run( | ||
| off: &mut Self::OffThread, | ||
| /// must touch only the off-thread part. | ||
| /// | ||
| /// `off` is a pointer, not `&mut`: a body that keeps `done` hands the job | ||
| /// on before returning, and the JS thread then frees it through the job's | ||
| /// own pointer (`Job::complete`), which is UB while a reference argument | ||
| /// is still protected here. Such a body reborrows only for work that ends | ||
| /// before the hand-over, which is its last access. | ||
| /// | ||
| /// # Safety | ||
| /// `off` is the live job's off-thread part and nothing else touches it | ||
| /// until this returns `Some(done)` or the body hands the job on. | ||
|
Comment on lines
+241
to
+251
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code |
||
| unsafe fn run( | ||
| off: *mut Self::OffThread, | ||
| vm: &Borrow, | ||
| done: Completion<Self>, | ||
| ) -> Option<Completion<Self>>; | ||
|
|
@@ -388,7 +398,9 @@ impl<C: JobContext> Job<C> { | |
| return done.finish(); | ||
| }; | ||
| // SAFETY: as above; the borrow keeps the VM (and any JsPtr target) alive. | ||
| if let Some(done) = C::run(unsafe { &mut (*this).off }, &vm, done) { | ||
| // On `None` the job may already be freed; nothing below touches it | ||
| // (`vm` is released through our own `handle` clone). | ||
|
Comment on lines
+401
to
+402
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code |
||
| if let Some(done) = unsafe { C::run(&raw mut (*this).off, &vm, done) } { | ||
| drop(vm); | ||
| done.finish(); | ||
| } | ||
|
|
@@ -541,7 +553,7 @@ pub enum Never {} | |
| impl JobContext for Never { | ||
| type OffThread = (); | ||
| type Js = (); | ||
| fn run(_: &mut (), _: &Borrow, done: Completion<Self>) -> Option<Completion<Self>> { | ||
| unsafe fn run(_: *mut (), _: &Borrow, done: Completion<Self>) -> Option<Completion<Self>> { | ||
| Some(done) | ||
| } | ||
| fn then(_: (), _: (), _: &JsThread<'_>) -> JsResult<()> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code