Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xrc
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lukas Markeffsky
xrc
Commits
4307c685
Commit
4307c685
authored
1 year ago
by
Lukas Markeffsky
Browse files
Options
Downloads
Patches
Plain Diff
fix soundness
parent
7919ebb0
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib.rs
+32
-6
32 additions, 6 deletions
src/lib.rs
with
32 additions
and
6 deletions
src/lib.rs
+
32
−
6
View file @
4307c685
...
...
@@ -19,7 +19,7 @@ unsafe fn reclaim_shim<T: Reclaim>(erased_ptr: NonNull<Root<Erased>>) {
(
*
ptr
.as_ptr
())
.state
.set
(
STATE_UNCLAIMED
);
};
let
value
=
unsafe
{
(
*
ptr
.as_ptr
())
.target
.as
sume_init_read
()
.value
};
let
value
=
unsafe
{
ptr
::
addr_of!
((
*
(
*
ptr
.as_ptr
())
.target
.as
_ptr
()
)
.value
)
.read
()
};
let
unclaimed
=
Unclaimed
{
ptr
};
value
.reclaim
(
unclaimed
);
...
...
@@ -48,7 +48,7 @@ pub struct Root<T> {
impl
<
T
>
Drop
for
Root
<
T
>
{
fn
drop
(
&
mut
self
)
{
let
state
=
self
.state
.get
();
if
state
<
=
STATE_
SHARED_MAX
{
if
state
!
=
STATE_
UNPINNED
{
struct
Abort
;
impl
Drop
for
Abort
{
fn
drop
(
&
mut
self
)
{
...
...
@@ -132,6 +132,15 @@ pub struct Unclaimed<T> {
ptr
:
NonNull
<
Root
<
T
>>
,
}
impl
<
T
>
Drop
for
Unclaimed
<
T
>
{
fn
drop
(
&
mut
self
)
{
unsafe
{
debug_assert_eq!
((
*
self
.ptr
.as_ptr
())
.state
.get
(),
STATE_UNCLAIMED
);
(
*
self
.ptr
.as_ptr
())
.state
.set
(
STATE_UNPINNED
);
}
}
}
impl
<
T
>
Unclaimed
<
T
>
{
pub
fn
claim
(
self
,
value
:
T
)
->
Xrc
<
T
>
{
unsafe
{
...
...
@@ -147,6 +156,7 @@ impl<T> Unclaimed<T> {
// shared read-only reborrow
let
target
=
unsafe
{
(
*
self
.ptr
.as_ptr
())
.target
.assume_init_ref
()
};
let
ptr
=
NonNull
::
from
(
target
);
mem
::
forget
(
self
);
Xrc
{
ptr
}
}
}
...
...
@@ -280,7 +290,16 @@ mod tests {
#[test]
#[ignore
=
"will abort"
]
fn
abort
()
{
fn
abort_unclaimed
()
{
#[allow(clippy::needless_late_init)]
let
_unclaimed
;
let
root
=
pin!
(
Root
::
<
NoReclaim
<
()
>>
::
new
());
_unclaimed
=
root
.unclaimed
();
}
#[test]
#[ignore
=
"will abort"
]
fn
abort_xrc
()
{
#[allow(clippy::needless_late_init)]
let
_xrc
;
let
root
=
pin!
(
Root
::
new
());
...
...
@@ -288,10 +307,17 @@ mod tests {
}
#[test]
#[should_panic
=
"unclaimed called multiple times"
]
fn
multiple_unclaimed
()
{
let
mut
root
=
pin!
(
Root
::
<
NoReclaim
<
i32
>>
::
new
()
);
fn
multiple_unclaimed_separate
()
{
let
mut
root
=
pin!
(
Root
::
<
NoReclaim
<
()
>>
::
new
());
let
_
=
root
.as_mut
()
.unclaimed
(
);
let
_
=
root
.as_mut
()
.unclaimed
();
}
#[test]
#[should_panic
=
"unclaimed called multiple times"
]
fn
multiple_unclaimed_concurrent
()
{
let
mut
root
=
pin!
(
Root
::
<
NoReclaim
<
()
>>
::
new
());
let
_unclaimed
=
root
.as_mut
()
.unclaimed
();
let
_
=
root
.as_mut
()
.unclaimed
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment