Implement pthread_getattr_np
This commit is contained in:
@@ -10,8 +10,8 @@ use crate::{
|
||||
};
|
||||
|
||||
// Setup a stack starting from the very end of the address space, and then growing downwards.
|
||||
pub(crate) const STACK_TOP: usize = 1 << 47;
|
||||
pub(crate) const STACK_SIZE: usize = 1024 * 1024;
|
||||
pub const STACK_TOP: usize = 1 << 47;
|
||||
pub const STACK_SIZE: usize = 1024 * 1024;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[repr(C)]
|
||||
|
||||
@@ -10,8 +10,8 @@ use crate::{
|
||||
};
|
||||
|
||||
// Setup a stack starting from the very end of the address space, and then growing downwards.
|
||||
pub(crate) const STACK_TOP: usize = 1 << 31;
|
||||
pub(crate) const STACK_SIZE: usize = 1024 * 1024;
|
||||
pub const STACK_TOP: usize = 1 << 31;
|
||||
pub const STACK_SIZE: usize = 1024 * 1024;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[repr(C)]
|
||||
|
||||
@@ -10,8 +10,8 @@ use core::{mem::offset_of, ptr::NonNull, sync::atomic::Ordering};
|
||||
use syscall::{data::*, error::*};
|
||||
|
||||
// Setup a stack starting from the very end of the address space, and then growing downwards.
|
||||
pub(crate) const STACK_TOP: usize = 1 << 47;
|
||||
pub(crate) const STACK_SIZE: usize = 1024 * 1024;
|
||||
pub const STACK_TOP: usize = 1 << 47;
|
||||
pub const STACK_SIZE: usize = 1024 * 1024;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[repr(C)]
|
||||
|
||||
@@ -18,8 +18,8 @@ use crate::{
|
||||
};
|
||||
|
||||
// Setup a stack starting from the very end of the address space, and then growing downwards.
|
||||
pub(crate) const STACK_TOP: usize = 1 << 47;
|
||||
pub(crate) const STACK_SIZE: usize = 1024 * 1024;
|
||||
pub const STACK_TOP: usize = 1 << 47;
|
||||
pub const STACK_SIZE: usize = 1024 * 1024;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[repr(C)]
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
use core::{ptr, sync::atomic::Ordering};
|
||||
|
||||
use super::*;
|
||||
|
||||
use crate::header::bits_pthread::pthread_attr_t;
|
||||
use crate::{
|
||||
header::bits_pthread::{pthread_attr_t, pthread_t},
|
||||
pthread::{Pthread, PthreadFlags},
|
||||
};
|
||||
|
||||
impl Default for RlctAttr {
|
||||
fn default() -> Self {
|
||||
@@ -185,3 +190,21 @@ pub unsafe extern "C" fn pthread_attr_setstacksize(
|
||||
(*attr.cast::<RlctAttr>()).stacksize = stacksize;
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pthread_getattr_np(
|
||||
thread_ptr: pthread_t,
|
||||
attr_ptr: *mut pthread_attr_t,
|
||||
) -> c_int {
|
||||
let thread = &*thread_ptr.cast::<Pthread>();
|
||||
let attr_ptr = attr_ptr.cast::<RlctAttr>();
|
||||
ptr::write(attr_ptr, RlctAttr::default());
|
||||
let attr = &mut *attr_ptr;
|
||||
if thread.flags.load(Ordering::Acquire) & PthreadFlags::DETACHED.bits() != 0 {
|
||||
attr.detachstate = PTHREAD_CREATE_DETACHED as _;
|
||||
}
|
||||
attr.stack = thread.stack_base as usize;
|
||||
attr.stacksize = thread.stack_size;
|
||||
//TODO: more values?
|
||||
0
|
||||
}
|
||||
|
||||
+17
-7
@@ -3,7 +3,7 @@
|
||||
use core::{
|
||||
cell::{Cell, UnsafeCell},
|
||||
mem::{offset_of, MaybeUninit},
|
||||
ptr::{addr_of, NonNull},
|
||||
ptr::{self, addr_of, NonNull},
|
||||
sync::atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||
};
|
||||
|
||||
@@ -24,9 +24,7 @@ use crate::sync::{waitval::Waitval, Mutex};
|
||||
|
||||
/// Called only by the main thread, as part of relibc_start.
|
||||
pub unsafe fn init() {
|
||||
Tcb::current()
|
||||
.expect_notls("no TCB present for main thread")
|
||||
.pthread = Pthread {
|
||||
let mut thread = Pthread {
|
||||
waitval: Waitval::new(),
|
||||
has_enabled_cancelation: AtomicBool::new(false),
|
||||
has_queued_cancelation: AtomicBool::new(false),
|
||||
@@ -34,12 +32,24 @@ pub unsafe fn init() {
|
||||
|
||||
//index: FIRST_THREAD_IDX,
|
||||
|
||||
// TODO
|
||||
stack_base: core::ptr::null_mut(),
|
||||
// TODO: set these values on Linux as well
|
||||
stack_base: ptr::null_mut(),
|
||||
stack_size: 0,
|
||||
|
||||
os_tid: UnsafeCell::new(Sys::current_os_tid()),
|
||||
};
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
{
|
||||
//TODO: what is the best way to get these values?
|
||||
use redox_rt::arch::{STACK_SIZE, STACK_TOP};
|
||||
thread.stack_base = (STACK_TOP - STACK_SIZE) as *mut c_void;
|
||||
thread.stack_size = STACK_SIZE;
|
||||
}
|
||||
|
||||
Tcb::current()
|
||||
.expect_notls("no TCB present for main thread")
|
||||
.pthread = thread;
|
||||
}
|
||||
|
||||
//static NEXT_INDEX: AtomicU32 = AtomicU32::new(FIRST_THREAD_IDX + 1);
|
||||
@@ -52,7 +62,7 @@ pub unsafe fn terminate_from_main_thread() {
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
struct PthreadFlags: usize {
|
||||
pub struct PthreadFlags: usize {
|
||||
const DETACHED = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user