Fix Clippy warnings
This commit is contained in:
@@ -92,7 +92,7 @@ pub unsafe extern "C" fn gethostent() -> *mut hostent {
|
||||
|
||||
let mut _host_aliases: Vec<Vec<u8>> = Vec::new();
|
||||
|
||||
while let Some(s) = iter.next() {
|
||||
for s in iter {
|
||||
let mut alias = s.as_bytes().to_vec();
|
||||
alias.push(b'\0');
|
||||
_host_aliases.push(alias);
|
||||
|
||||
@@ -32,7 +32,7 @@ pub fn lookup_host(host: &str) -> Result<LookupHost, c_int> {
|
||||
|
||||
let dns_vec: Vec<u8> = dns_string
|
||||
.trim()
|
||||
.split(".")
|
||||
.split('.')
|
||||
.map(|octet| octet.parse::<u8>().unwrap_or(0))
|
||||
.collect();
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ pub unsafe extern "C" fn gethostbyaddr(
|
||||
Ok(s) => {
|
||||
_HOST_ADDR_LIST = mem::transmute::<u32, [u8; 4]>(addr.s_addr);
|
||||
HOST_ADDR_LIST = [_HOST_ADDR_LIST.as_mut_ptr() as *mut c_char, ptr::null_mut()];
|
||||
let mut host_name = s[0].to_vec();
|
||||
let host_name = s[0].to_vec();
|
||||
HOST_NAME = Some(host_name);
|
||||
HOST_ENTRY = hostent {
|
||||
h_name: HOST_NAME.as_mut().unwrap().as_mut_ptr() as *mut c_char,
|
||||
@@ -431,7 +431,7 @@ pub unsafe extern "C" fn getprotoent() -> *mut protoent {
|
||||
PROTO_NUM = Some(atoi(num.as_mut_slice().as_mut_ptr() as *mut i8));
|
||||
|
||||
let mut _proto_aliases: Vec<Vec<u8>> = Vec::new();
|
||||
while let Some(s) = iter.next() {
|
||||
for s in iter {
|
||||
let mut alias = s.as_bytes().to_vec();
|
||||
alias.push(b'\0');
|
||||
_proto_aliases.push(alias);
|
||||
|
||||
@@ -72,7 +72,7 @@ where
|
||||
};
|
||||
|
||||
// Parse into passwd
|
||||
let mut parts: [&[u8]; 7] = sys::split(&line);
|
||||
let parts: [&[u8]; 7] = sys::split(&line);
|
||||
|
||||
if !callback(&parts) {
|
||||
continue;
|
||||
|
||||
@@ -31,7 +31,7 @@ pub const L_tmpnam: c_int = 7;
|
||||
pub const TMP_MAX: int32_t = 2_147_483_647;
|
||||
// XXX: defined manually in bits/stdio.h as well because cbindgen can't handle
|
||||
// string constants in any form AFAICT
|
||||
pub const P_tmpdir: &'static [u8; 5] = b"/tmp\0";
|
||||
pub const P_tmpdir: &[u8; 5] = b"/tmp\0";
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type fpos_t = off_t;
|
||||
|
||||
@@ -319,7 +319,7 @@ pub unsafe extern "C" fn fgets(
|
||||
|
||||
// TODO: When NLL is a thing, this block can be flattened out
|
||||
let (read, exit) = {
|
||||
let mut buf = match stream.fill_buf() {
|
||||
let buf = match stream.fill_buf() {
|
||||
Ok(buf) => buf,
|
||||
Err(_) => return ptr::null_mut(),
|
||||
};
|
||||
@@ -580,7 +580,7 @@ pub unsafe extern "C" fn fwrite(
|
||||
let buf = slice::from_raw_parts_mut(ptr as *mut u8, size as usize * nitems as usize);
|
||||
let mut written = 0;
|
||||
while written < buf.len() {
|
||||
match stream.write(&mut buf[written..]) {
|
||||
match stream.write(&buf[written..]) {
|
||||
Ok(0) | Err(_) => break,
|
||||
Ok(n) => written += n,
|
||||
}
|
||||
@@ -885,8 +885,8 @@ pub unsafe extern "C" fn tempnam(dir: *const c_char, pfx: *const c_char) -> *mut
|
||||
let dirname = {
|
||||
let tmpdir = stdlib::getenv(b"TMPDIR\0".as_ptr() as _);
|
||||
[tmpdir, dir, P_tmpdir.as_ptr() as _]
|
||||
.into_iter()
|
||||
.map(|&d| d)
|
||||
.iter()
|
||||
.copied()
|
||||
.skip_while(|&d| !is_appropriate(d))
|
||||
.next()
|
||||
.unwrap_or(b"/tmp\0".as_ptr() as _)
|
||||
@@ -934,7 +934,7 @@ pub unsafe extern "C" fn tmpfile() -> *mut FILE {
|
||||
Sys::unlink(file_name);
|
||||
}
|
||||
|
||||
if fp == ptr::null_mut() {
|
||||
if fp.is_null() {
|
||||
Sys::close(fd);
|
||||
}
|
||||
|
||||
|
||||
+23
-22
@@ -307,7 +307,7 @@ fn float_string(float: c_double, precision: usize, trim: bool) -> String {
|
||||
let mut string = format!("{:.p$}", float, p = precision);
|
||||
if trim {
|
||||
let truncate = {
|
||||
let mut slice = string.trim_end_matches('0');
|
||||
let slice = string.trim_end_matches('0');
|
||||
if slice.ends_with('.') {
|
||||
slice.len() - 1
|
||||
} else {
|
||||
@@ -678,22 +678,23 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
|
||||
// add an extra zero if octal.
|
||||
let no_precision = precision.map(|pad| pad < string.len()).unwrap_or(true);
|
||||
|
||||
let mut len = string.len();
|
||||
let mut final_len = string.len().max(precision.unwrap_or(0))
|
||||
+ if alternate && string != "0" {
|
||||
match fmt {
|
||||
b'o' if no_precision => 1,
|
||||
b'x' | b'X' => 2,
|
||||
_ => 0,
|
||||
}
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
if zero {
|
||||
let len;
|
||||
let final_len = if zero {
|
||||
len = 0;
|
||||
final_len = 0;
|
||||
}
|
||||
0
|
||||
} else {
|
||||
len = string.len();
|
||||
len.max(precision.unwrap_or(0))
|
||||
+ if alternate && string != "0" {
|
||||
match fmt {
|
||||
b'o' if no_precision => 1,
|
||||
b'x' | b'X' => 2,
|
||||
_ => 0,
|
||||
}
|
||||
} else {
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
pad(w, !left, b' ', final_len..pad_space)?;
|
||||
|
||||
@@ -714,7 +715,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
|
||||
pad(w, left, b' ', final_len..pad_space)?;
|
||||
}
|
||||
FmtKind::Scientific => {
|
||||
let mut float = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
let float = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
VaArg::c_double(i) => i,
|
||||
_ => panic!("this should not be possible"),
|
||||
};
|
||||
@@ -725,7 +726,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
|
||||
)?;
|
||||
}
|
||||
FmtKind::Decimal => {
|
||||
let mut float = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
let float = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
VaArg::c_double(i) => i,
|
||||
_ => panic!("this should not be possible"),
|
||||
};
|
||||
@@ -734,7 +735,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
|
||||
fmt_float_normal(w, false, precision, float, left, pad_space, pad_zero)?;
|
||||
}
|
||||
FmtKind::AnyNotation => {
|
||||
let mut float = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
let float = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
VaArg::c_double(i) => i,
|
||||
_ => panic!("this should not be possible"),
|
||||
};
|
||||
@@ -758,7 +759,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
|
||||
FmtKind::String => {
|
||||
// if intkind == IntKind::Long || intkind == IntKind::LongLong, handle *const wchar_t
|
||||
|
||||
let mut ptr = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
let ptr = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
VaArg::pointer(p) => p,
|
||||
_ => panic!("this should not be possible"),
|
||||
} as *const c_char;
|
||||
@@ -790,7 +791,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
|
||||
pad(w, left, b' ', 1..pad_space)?;
|
||||
}
|
||||
FmtKind::Pointer => {
|
||||
let mut ptr = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
let ptr = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
VaArg::pointer(p) => p,
|
||||
_ => panic!("this should not be possible"),
|
||||
};
|
||||
@@ -815,7 +816,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
|
||||
pad(w, left, b' ', len..pad_space)?;
|
||||
}
|
||||
FmtKind::GetWritten => {
|
||||
let mut ptr = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
let ptr = match varargs.get(index, &mut ap, Some(&arg)) {
|
||||
VaArg::pointer(p) => p,
|
||||
_ => panic!("this should not be possible"),
|
||||
};
|
||||
|
||||
@@ -349,7 +349,7 @@ unsafe fn inner_scanf<R: Read>(
|
||||
}
|
||||
}
|
||||
b'c' => {
|
||||
let mut ptr: Option<*mut c_char> = if ignore { None } else { Some(ap.arg()) };
|
||||
let ptr: Option<*mut c_char> = if ignore { None } else { Some(ap.arg()) };
|
||||
|
||||
for i in 0..width.unwrap_or(1) {
|
||||
if let Some(ptr) = ptr {
|
||||
@@ -370,11 +370,12 @@ unsafe fn inner_scanf<R: Read>(
|
||||
c = next_byte(&mut format)?;
|
||||
|
||||
let mut matches = Vec::new();
|
||||
let mut invert = false;
|
||||
if c == b'^' {
|
||||
let invert = if c == b'^' {
|
||||
c = next_byte(&mut format)?;
|
||||
invert = true;
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let mut prev;
|
||||
loop {
|
||||
|
||||
@@ -265,6 +265,7 @@ pub unsafe extern "C" fn exit(status: c_int) {
|
||||
|
||||
// Look for the neighbor functions in memory until the end
|
||||
let mut f = &__fini_array_end as *const _;
|
||||
#[allow(clippy::op_ref)]
|
||||
while f > &__fini_array_start {
|
||||
f = f.offset(-1);
|
||||
(*f)();
|
||||
@@ -846,7 +847,7 @@ pub unsafe fn convert_hex(s: *const c_char) -> Option<(c_ulong, isize, bool)> {
|
||||
|
||||
pub unsafe fn convert_integer(s: *const c_char, base: c_int) -> Option<(c_ulong, isize, bool)> {
|
||||
// -1 means the character is invalid
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#[rustfmt::skip]
|
||||
const LOOKUP_TABLE: [c_long; 256] = [
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
|
||||
@@ -107,7 +107,7 @@ fn heapify(
|
||||
// we start at the last parent in the heap (the parent of the last child)
|
||||
let last_parent = (nel - 2) / 2;
|
||||
|
||||
for start in (0..last_parent + 1).rev() {
|
||||
for start in (0..=last_parent).rev() {
|
||||
heap_sift_down(base, start, nel - 1, width, comp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ pub fn select_epoll(
|
||||
if fd_set.isset(fd) {
|
||||
let mut event = epoll_event {
|
||||
events: EPOLLIN,
|
||||
data: epoll_data { fd: fd },
|
||||
data: epoll_data { fd },
|
||||
..Default::default()
|
||||
};
|
||||
if epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &mut event) < 0 {
|
||||
@@ -92,7 +92,7 @@ pub fn select_epoll(
|
||||
if fd_set.isset(fd) {
|
||||
let mut event = epoll_event {
|
||||
events: EPOLLOUT,
|
||||
data: epoll_data { fd: fd },
|
||||
data: epoll_data { fd },
|
||||
..Default::default()
|
||||
};
|
||||
if epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &mut event) < 0 {
|
||||
@@ -110,7 +110,7 @@ pub fn select_epoll(
|
||||
if fd_set.isset(fd) {
|
||||
let mut event = epoll_event {
|
||||
events: EPOLLERR,
|
||||
data: epoll_data { fd: fd },
|
||||
data: epoll_data { fd },
|
||||
..Default::default()
|
||||
};
|
||||
if epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &mut event) < 0 {
|
||||
|
||||
@@ -176,7 +176,7 @@ pub unsafe extern "C" fn execvp(file: *const c_char, argv: *const *mut c_char) -
|
||||
let path_env = getenv(c_str!("PATH\0").as_ptr());
|
||||
if !path_env.is_null() {
|
||||
let path_env = CStr::from_ptr(path_env);
|
||||
for mut path in path_env.to_bytes().split(|&b| b == PATH_SEPARATOR) {
|
||||
for path in path_env.to_bytes().split(|&b| b == PATH_SEPARATOR) {
|
||||
let mut program = path.to_vec();
|
||||
program.push(b'/');
|
||||
program.extend_from_slice(file.to_bytes());
|
||||
|
||||
@@ -301,7 +301,7 @@ pub unsafe extern "C" fn wcschr(ws: *const wchar_t, wc: wchar_t) -> *mut wchar_t
|
||||
if *ws.add(i) == wc {
|
||||
return ws.add(i) as *mut wchar_t;
|
||||
} else if *ws.add(i) == 0 {
|
||||
return 0 as *mut wchar_t;
|
||||
return ptr::null_mut();
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
@@ -523,7 +523,7 @@ pub unsafe extern "C" fn wmemchr(ws: *const wchar_t, wc: wchar_t, n: size_t) ->
|
||||
return ws.add(i) as *mut wchar_t;
|
||||
}
|
||||
}
|
||||
0 as *mut wchar_t
|
||||
ptr::null_mut()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
+52
-64
@@ -403,41 +403,35 @@ impl Linker {
|
||||
|
||||
// Protect pages
|
||||
for ph in elf.program_headers.iter() {
|
||||
match ph.p_type {
|
||||
program_header::PT_LOAD => {
|
||||
let voff = ph.p_vaddr as usize % PAGE_SIZE;
|
||||
let vaddr = ph.p_vaddr as usize - voff;
|
||||
let vsize =
|
||||
((ph.p_memsz as usize + voff + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
|
||||
if ph.p_type == program_header::PT_LOAD {
|
||||
let voff = ph.p_vaddr as usize % PAGE_SIZE;
|
||||
let vaddr = ph.p_vaddr as usize - voff;
|
||||
let vsize =
|
||||
((ph.p_memsz as usize + voff + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
|
||||
|
||||
let mut prot = 0;
|
||||
let mut prot = 0;
|
||||
|
||||
if ph.p_flags & program_header::PF_R == program_header::PF_R {
|
||||
prot |= sys_mman::PROT_READ;
|
||||
}
|
||||
|
||||
// W ^ X. If it is executable, do not allow it to be writable, even if requested
|
||||
if ph.p_flags & program_header::PF_X == program_header::PF_X {
|
||||
prot |= sys_mman::PROT_EXEC;
|
||||
} else if ph.p_flags & program_header::PF_W == program_header::PF_W {
|
||||
prot |= sys_mman::PROT_WRITE;
|
||||
}
|
||||
|
||||
let res = unsafe {
|
||||
let ptr = mmap.as_mut_ptr().add(vaddr);
|
||||
println!(" prot {:#x}, {:#x}: {:p}, {:#x}", vaddr, vsize, ptr, prot);
|
||||
|
||||
sys_mman::mprotect(ptr as *mut c_void, vsize, prot)
|
||||
};
|
||||
|
||||
if res < 0 {
|
||||
return Err(Error::Malformed(format!(
|
||||
"failed to mprotect {}",
|
||||
elf_name
|
||||
)));
|
||||
}
|
||||
if ph.p_flags & program_header::PF_R == program_header::PF_R {
|
||||
prot |= sys_mman::PROT_READ;
|
||||
}
|
||||
|
||||
// W ^ X. If it is executable, do not allow it to be writable, even if requested
|
||||
if ph.p_flags & program_header::PF_X == program_header::PF_X {
|
||||
prot |= sys_mman::PROT_EXEC;
|
||||
} else if ph.p_flags & program_header::PF_W == program_header::PF_W {
|
||||
prot |= sys_mman::PROT_WRITE;
|
||||
}
|
||||
|
||||
let res = unsafe {
|
||||
let ptr = mmap.as_mut_ptr().add(vaddr);
|
||||
println!(" prot {:#x}, {:#x}: {:p}, {:#x}", vaddr, vsize, ptr, prot);
|
||||
|
||||
sys_mman::mprotect(ptr as *mut c_void, vsize, prot)
|
||||
};
|
||||
|
||||
if res < 0 {
|
||||
return Err(Error::Malformed(format!("failed to mprotect {}", elf_name)));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -497,41 +491,35 @@ impl Linker {
|
||||
|
||||
// Protect pages
|
||||
for ph in elf.program_headers.iter() {
|
||||
match ph.p_type {
|
||||
program_header::PT_LOAD => {
|
||||
let voff = ph.p_vaddr as usize % PAGE_SIZE;
|
||||
let vaddr = ph.p_vaddr as usize - voff;
|
||||
let vsize =
|
||||
((ph.p_memsz as usize + voff + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
|
||||
if let program_header::PT_LOAD = ph.p_type {
|
||||
let voff = ph.p_vaddr as usize % PAGE_SIZE;
|
||||
let vaddr = ph.p_vaddr as usize - voff;
|
||||
let vsize =
|
||||
((ph.p_memsz as usize + voff + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
|
||||
|
||||
let mut prot = 0;
|
||||
let mut prot = 0;
|
||||
|
||||
if ph.p_flags & program_header::PF_R == program_header::PF_R {
|
||||
prot |= sys_mman::PROT_READ;
|
||||
}
|
||||
|
||||
// W ^ X. If it is executable, do not allow it to be writable, even if requested
|
||||
if ph.p_flags & program_header::PF_X == program_header::PF_X {
|
||||
prot |= sys_mman::PROT_EXEC;
|
||||
} else if ph.p_flags & program_header::PF_W == program_header::PF_W {
|
||||
prot |= sys_mman::PROT_WRITE;
|
||||
}
|
||||
|
||||
let res = unsafe {
|
||||
let ptr = mmap.as_mut_ptr().add(vaddr);
|
||||
println!(" prot {:#x}, {:#x}: {:p}, {:#x}", vaddr, vsize, ptr, prot);
|
||||
|
||||
sys_mman::mprotect(ptr as *mut c_void, vsize, prot)
|
||||
};
|
||||
|
||||
if res < 0 {
|
||||
return Err(Error::Malformed(format!(
|
||||
"failed to mprotect {}",
|
||||
elf_name
|
||||
)));
|
||||
}
|
||||
if ph.p_flags & program_header::PF_R == program_header::PF_R {
|
||||
prot |= sys_mman::PROT_READ;
|
||||
}
|
||||
|
||||
// W ^ X. If it is executable, do not allow it to be writable, even if requested
|
||||
if ph.p_flags & program_header::PF_X == program_header::PF_X {
|
||||
prot |= sys_mman::PROT_EXEC;
|
||||
} else if ph.p_flags & program_header::PF_W == program_header::PF_W {
|
||||
prot |= sys_mman::PROT_WRITE;
|
||||
}
|
||||
|
||||
let res = unsafe {
|
||||
let ptr = mmap.as_mut_ptr().add(vaddr);
|
||||
println!(" prot {:#x}, {:#x}: {:p}, {:#x}", vaddr, vsize, ptr, prot);
|
||||
|
||||
sys_mman::mprotect(ptr as *mut c_void, vsize, prot)
|
||||
};
|
||||
|
||||
if res < 0 {
|
||||
return Err(Error::Malformed(format!("failed to mprotect {}", elf_name)));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -59,9 +59,8 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize {
|
||||
let mut parts = arg_str.splitn(2, '=');
|
||||
if let Some(key) = parts.next() {
|
||||
if let Some(value) = parts.next() {
|
||||
match key {
|
||||
"LD_LIBRARY_PATH" => library_path = value,
|
||||
_ => (),
|
||||
if let "LD_LIBRARY_PATH" = key {
|
||||
library_path = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ impl Tcb {
|
||||
Self {
|
||||
tls_end: tls.as_mut_ptr().add(tls.len()),
|
||||
tls_len: tls.len(),
|
||||
tcb_ptr: tcb_ptr,
|
||||
tcb_ptr,
|
||||
tcb_len: tcb_page.len(),
|
||||
masters_ptr: ptr::null_mut(),
|
||||
masters_len: 0,
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#![feature(const_vec_new)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(global_asm)]
|
||||
// FIXME: Stable on nightly, remove once redox fork is updated
|
||||
#![feature(iter_copied)]
|
||||
#![feature(lang_items)]
|
||||
#![feature(linkage)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
+5
-10
@@ -48,7 +48,7 @@ static mut LOCALS: *mut BTreeMap<c_uint, *mut c_void> = ptr::null_mut();
|
||||
static NEXT_KEY: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
unsafe fn locals() -> &'static mut BTreeMap<c_uint, *mut c_void> {
|
||||
if LOCALS == ptr::null_mut() {
|
||||
if LOCALS.is_null() {
|
||||
LOCALS = Box::into_raw(Box::new(BTreeMap::new()));
|
||||
}
|
||||
&mut *LOCALS
|
||||
@@ -316,10 +316,8 @@ pub unsafe extern "C" fn pte_osMutexUnlock(handle: pte_osMutexHandle) -> pte_osR
|
||||
return PTE_OS_OK;
|
||||
}
|
||||
for _i in 0..100 {
|
||||
if *handle != 0 {
|
||||
if intrinsics::atomic_cxchg(handle, 1, 2).0 != 0 {
|
||||
return PTE_OS_OK;
|
||||
}
|
||||
if *handle != 0 && intrinsics::atomic_cxchg(handle, 1, 2).0 != 0 {
|
||||
return PTE_OS_OK;
|
||||
}
|
||||
}
|
||||
Sys::futex(handle, FUTEX_WAKE, 1);
|
||||
@@ -367,7 +365,7 @@ pub unsafe extern "C" fn pte_osSemaphorePend(
|
||||
let mut acquired = false;
|
||||
while !acquired {
|
||||
pte_osMutexLock(&mut semaphore.lock);
|
||||
if intrinsics::atomic_load(&mut semaphore.count) > 0 {
|
||||
if intrinsics::atomic_load(&semaphore.count) > 0 {
|
||||
intrinsics::atomic_xsub(&mut semaphore.count, 1);
|
||||
acquired = true;
|
||||
}
|
||||
@@ -423,10 +421,7 @@ pub unsafe extern "C" fn pte_osTlsSetValue(index: c_uint, value: *mut c_void) ->
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osTlsGetValue(index: c_uint) -> *mut c_void {
|
||||
locals()
|
||||
.get_mut(&index)
|
||||
.map(|x| *x)
|
||||
.unwrap_or(ptr::null_mut())
|
||||
locals().get_mut(&index).copied().unwrap_or(ptr::null_mut())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ impl RawLineBuffer {
|
||||
pub fn next(&mut self) -> Line {
|
||||
// Remove last line
|
||||
if let Some(newline) = self.newline {
|
||||
self.buf.drain(..newline + 1);
|
||||
self.buf.drain(..=newline);
|
||||
}
|
||||
|
||||
loop {
|
||||
|
||||
+3
-1
@@ -29,7 +29,7 @@ impl Stack {
|
||||
unsafe fn copy_string_array(array: *const *const c_char, len: usize) -> Vec<*mut c_char> {
|
||||
let mut vec = Vec::with_capacity(len + 1);
|
||||
for i in 0..len {
|
||||
let mut item = *array.add(i);
|
||||
let item = *array.add(i);
|
||||
let mut len = 0;
|
||||
while *item.add(len) != 0 {
|
||||
len += 1;
|
||||
@@ -96,6 +96,7 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
|
||||
// Run preinit array
|
||||
{
|
||||
let mut f = &__preinit_array_start as *const _;
|
||||
#[allow(clippy::op_ref)]
|
||||
while f < &__preinit_array_end {
|
||||
(*f)();
|
||||
f = f.offset(1);
|
||||
@@ -108,6 +109,7 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
|
||||
// Run init array
|
||||
{
|
||||
let mut f = &__init_array_start as *const _;
|
||||
#[allow(clippy::op_ref)]
|
||||
while f < &__init_array_end {
|
||||
(*f)();
|
||||
f = f.offset(1);
|
||||
|
||||
Reference in New Issue
Block a user