Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5e4edba

Browse files
authored
Rollup merge ofrust-lang#127789 - Sword-Destiny:master, r=petrochenkov
delete #![allow(unsafe_op_in_unsafe_fn)] in teeosdeny unsafe_op_in_unsafe_fn for teeos
2 parents686f75b +8b1d874 commit5e4edba

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

‎std/src/sys/pal/teeos/alloc.rs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@ unsafe impl GlobalAlloc for System {
1111
// Also see <https://github.com/rust-lang/rust/issues/45955> and
1212
// <https://github.com/rust-lang/rust/issues/62251#issuecomment-507580914>.
1313
if layout.align() <=MIN_ALIGN && layout.align() <= layout.size(){
14-
libc::malloc(layout.size())as*mutu8
14+
unsafe{libc::malloc(layout.size())as*mutu8}
1515
}else{
16-
aligned_malloc(&layout)
16+
unsafe{aligned_malloc(&layout)}
1717
}
1818
}
1919

2020
#[inline]
2121
unsafefnalloc_zeroed(&self,layout:Layout) ->*mutu8{
2222
// See the comment above in `alloc` for why this check looks the way it does.
2323
if layout.align() <=MIN_ALIGN && layout.align() <= layout.size(){
24-
libc::calloc(layout.size(),1)as*mutu8
24+
unsafe{libc::calloc(layout.size(),1)as*mutu8}
2525
}else{
26-
let ptr =self.alloc(layout);
26+
let ptr =unsafe{self.alloc(layout)};
2727
if !ptr.is_null(){
28-
ptr::write_bytes(ptr,0, layout.size());
28+
unsafe{ptr::write_bytes(ptr,0, layout.size())};
2929
}
3030
ptr
3131
}
3232
}
3333

3434
#[inline]
3535
unsafefndealloc(&self,ptr:*mutu8,_layout:Layout){
36-
libc::free(ptras*mut libc::c_void)
36+
unsafe{libc::free(ptras*mut libc::c_void)}
3737
}
3838

3939
#[inline]
4040
unsafefnrealloc(&self,ptr:*mutu8,layout:Layout,new_size:usize) ->*mutu8{
4141
if layout.align() <=MIN_ALIGN && layout.align() <= new_size{
42-
libc::realloc(ptras*mut libc::c_void, new_size)as*mutu8
42+
unsafe{libc::realloc(ptras*mut libc::c_void, new_size)as*mutu8}
4343
}else{
44-
realloc_fallback(self, ptr, layout, new_size)
44+
unsafe{realloc_fallback(self, ptr, layout, new_size)}
4545
}
4646
}
4747
}
@@ -52,6 +52,6 @@ unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
5252
// posix_memalign requires that the alignment be a multiple of `sizeof(void*)`.
5353
// Since these are all powers of 2, we can just use max.
5454
let align = layout.align().max(crate::mem::size_of::<usize>());
55-
let ret = libc::posix_memalign(&mut out, align, layout.size());
55+
let ret =unsafe{libc::posix_memalign(&mut out, align, layout.size())};
5656
if ret !=0{ ptr::null_mut()}else{ outas*mutu8}
5757
}

‎std/src/sys/pal/teeos/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! This module contains the facade (aka platform-specific) implementations of
44
//! OS level functionality for Teeos.
5-
#![allow(unsafe_op_in_unsafe_fn)]
5+
#![deny(unsafe_op_in_unsafe_fn)]
66
#![allow(unused_variables)]
77
#![allow(dead_code)]
88

‎std/src/sys/pal/teeos/thread.rs‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,24 @@ impl Thread {
2828
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
2929
pubunsafefnnew(stack:usize,p:Box<dynFnOnce()>) -> io::Result<Thread>{
3030
let p =Box::into_raw(Box::new(p));
31-
letmut native: libc::pthread_t = mem::zeroed();
32-
letmut attr: libc::pthread_attr_t = mem::zeroed();
33-
assert_eq!(libc::pthread_attr_init(&mut attr),0);
31+
letmut native: libc::pthread_t =unsafe{mem::zeroed()};
32+
letmut attr: libc::pthread_attr_t =unsafe{mem::zeroed()};
33+
assert_eq!(unsafe{libc::pthread_attr_init(&mut attr)},0);
3434
assert_eq!(
35-
libc::pthread_attr_settee(
36-
&mut attr,
37-
libc::TEESMP_THREAD_ATTR_CA_INHERIT,
38-
libc::TEESMP_THREAD_ATTR_TASK_ID_INHERIT,
39-
libc::TEESMP_THREAD_ATTR_HAS_SHADOW,
40-
),
35+
unsafe{
36+
libc::pthread_attr_settee(
37+
&mut attr,
38+
libc::TEESMP_THREAD_ATTR_CA_INHERIT,
39+
libc::TEESMP_THREAD_ATTR_TASK_ID_INHERIT,
40+
libc::TEESMP_THREAD_ATTR_HAS_SHADOW,
41+
)
42+
},
4143
0,
4244
);
4345

4446
let stack_size = cmp::max(stack,min_stack_size(&attr));
4547

46-
match libc::pthread_attr_setstacksize(&mut attr, stack_size){
48+
matchunsafe{libc::pthread_attr_setstacksize(&mut attr, stack_size)}{
4749
0 =>{}
4850
n =>{
4951
assert_eq!(n, libc::EINVAL);
@@ -54,20 +56,20 @@ impl Thread {
5456
let page_size = os::page_size();
5557
let stack_size =
5658
(stack_size + page_size -1)&(-(page_sizeasisize -1)asusize -1);
57-
assert_eq!(libc::pthread_attr_setstacksize(&mut attr, stack_size),0);
59+
assert_eq!(unsafe{libc::pthread_attr_setstacksize(&mut attr, stack_size)},0);
5860
}
5961
};
6062

6163
let ret = libc::pthread_create(&mut native,&attr, thread_start, pas*mut_);
6264
// Note: if the thread creation fails and this assert fails, then p will
6365
// be leaked. However, an alternative design could cause double-free
6466
// which is clearly worse.
65-
assert_eq!(libc::pthread_attr_destroy(&mut attr),0);
67+
assert_eq!(unsafe{libc::pthread_attr_destroy(&mut attr)},0);
6668

6769
returnif ret !=0{
6870
// The thread failed to start and as a result p was not consumed. Therefore, it is
6971
// safe to reconstruct the box so that it gets deallocated.
70-
drop(Box::from_raw(p));
72+
drop(unsafe{Box::from_raw(p)});
7173
Err(io::Error::from_raw_os_error(ret))
7274
}else{
7375
// The new thread will start running earliest after the next yield.

‎std/src/sys/sync/condvar/teeos.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,24 @@ impl Condvar {
7676

7777
#[inline]
7878
pubunsafefnwait(&self,mutex:&Mutex){
79-
let mutex = mutex::raw(mutex);
79+
let mutex =unsafe{mutex::raw(mutex)};
8080
self.verify(mutex);
81-
let r = libc::pthread_cond_wait(raw(self), mutex);
81+
let r =unsafe{libc::pthread_cond_wait(raw(self), mutex)};
8282
debug_assert_eq!(r,0);
8383
}
8484

8585
pubunsafefnwait_timeout(&self,mutex:&Mutex,dur:Duration) ->bool{
8686
usecrate::sys::time::Timespec;
8787

88-
let mutex = mutex::raw(mutex);
88+
let mutex =unsafe{mutex::raw(mutex)};
8989
self.verify(mutex);
9090

9191
let timeout =Timespec::now(libc::CLOCK_MONOTONIC)
9292
.checked_add_duration(&dur)
9393
.and_then(|t| t.to_timespec())
9494
.unwrap_or(TIMESPEC_MAX);
9595

96-
let r =pthread_cond_timedwait(raw(self), mutex,&timeout);
96+
let r =unsafe{pthread_cond_timedwait(raw(self), mutex,&timeout)};
9797
assert!(r == libc::ETIMEDOUT || r ==0);
9898
r ==0
9999
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp