forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from jacob-hughes/fsa_raw_pointers
Prevent raw pointer dereferences in finalizers
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![feature(gc)] | ||
#![feature(negative_impls)] | ||
#![feature(rustc_private)] | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
include!{"./auxiliary/types.rs"} | ||
|
||
struct S(*mut u8); | ||
|
||
impl Drop for S { | ||
fn drop(&mut self) { | ||
use_val(self.0); | ||
} | ||
} | ||
|
||
struct T(*mut u8); | ||
|
||
unsafe impl Send for T {} | ||
unsafe impl Sync for T {} | ||
|
||
fn main() { | ||
Gc::new(S(std::ptr::null_mut())); | ||
//~^ ERROR: The drop method for `S` cannot be safely finalized. | ||
|
||
Gc::new(T(std::ptr::null_mut())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error: The drop method for `S` cannot be safely finalized. | ||
--> $DIR/raw_pointers.rs:22:13 | ||
| | ||
LL | use_val(self.0); | ||
| ------ | ||
| | | ||
| a finalizer cannot safely dereference this `*mut u8` | ||
| because it might not live long enough | ||
| or be safe to use across threads. | ||
... | ||
LL | Gc::new(S(std::ptr::null_mut())); | ||
| --------^^^^^^^^^^^^^^^^^^^^^^^- caused by trying to construct a `Gc<S>` here. | ||
| | ||
= help: `Gc` runs finalizers on a separate thread, so drop methods | ||
cannot safely dereference raw pointers. If you are sure that this is safe, | ||
consider wrapping it in a type which implements `Send + Sync`. | ||
|
||
error: aborting due to 1 previous error | ||
|