Add needed functions for acid to link.
This commit is contained in:
@@ -219,8 +219,8 @@ impl Pal for Sys {
|
||||
e(unsafe { syscall!(FTRUNCATE, fildes, length) }) as c_int
|
||||
}
|
||||
|
||||
fn futex(addr: *mut c_int, op: c_int, val: c_int, val2: usize) -> c_int {
|
||||
unsafe { syscall!(FUTEX, addr, op, val, val2, 0, 0) as c_int }
|
||||
fn futex(addr: *mut c_int, op: c_int, val: c_int, val2: usize) -> Result<c_long, crate::pthread::Errno> {
|
||||
e_raw(unsafe { syscall!(FUTEX, addr, op, val, val2, 0, 0)}).map(|r| r as c_long).map_err(|e| Errno(e as c_int))
|
||||
}
|
||||
|
||||
fn futimens(fd: c_int, times: *const timespec) -> c_int {
|
||||
|
||||
@@ -73,7 +73,7 @@ pub trait Pal {
|
||||
|
||||
fn ftruncate(fildes: c_int, length: off_t) -> c_int;
|
||||
|
||||
fn futex(addr: *mut c_int, op: c_int, val: c_int, val2: usize) -> c_int;
|
||||
fn futex(addr: *mut c_int, op: c_int, val: c_int, val2: usize) -> Result<c_long, crate::pthread::Errno>;
|
||||
|
||||
fn futimens(fd: c_int, times: *const timespec) -> c_int;
|
||||
|
||||
|
||||
@@ -51,10 +51,6 @@ static LOCALS: UnsafeCell<BTreeMap<c_uint, *mut c_void>> = UnsafeCell::new(BTree
|
||||
|
||||
static NEXT_KEY: AtomicU32 = AtomicU32::new(0);
|
||||
|
||||
unsafe fn locals<'a>() -> &'a mut BTreeMap<c_uint, *mut c_void> {
|
||||
&mut *LOCALS.get()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osThreadStart(handle: pte_osThreadHandle) -> pte_osResult {
|
||||
let mut ret = PTE_OS_GENERAL_FAILURE;
|
||||
@@ -250,64 +246,3 @@ pub unsafe extern "C" fn pte_osSemaphorePend(
|
||||
Err(()) => PTE_OS_TIMEOUT,
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osSemaphoreCancellablePend(
|
||||
handle: pte_osSemaphoreHandle,
|
||||
pTimeout: *mut c_uint,
|
||||
) -> pte_osResult {
|
||||
//TODO: thread cancel
|
||||
pte_osSemaphorePend(handle, pTimeout)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osAtomicExchange(ptarg: *mut c_int, val: c_int) -> c_int {
|
||||
intrinsics::atomic_xchg_seqcst(ptarg, val)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osAtomicCompareExchange(
|
||||
pdest: *mut c_int,
|
||||
exchange: c_int,
|
||||
comp: c_int,
|
||||
) -> c_int {
|
||||
intrinsics::atomic_cxchg_seqcst_seqcst(pdest, comp, exchange).0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osAtomicExchangeAdd(pAppend: *mut c_int, value: c_int) -> c_int {
|
||||
intrinsics::atomic_xadd_seqcst(pAppend, value)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osAtomicDecrement(pdest: *mut c_int) -> c_int {
|
||||
intrinsics::atomic_xadd_seqcst(pdest, -1) - 1
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osAtomicIncrement(pdest: *mut c_int) -> c_int {
|
||||
intrinsics::atomic_xadd_seqcst(pdest, 1) + 1
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osTlsSetValue(index: c_uint, value: *mut c_void) -> pte_osResult {
|
||||
locals().insert(index, value);
|
||||
PTE_OS_OK
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osTlsGetValue(index: c_uint) -> *mut c_void {
|
||||
locals().get_mut(&index).copied().unwrap_or(ptr::null_mut())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osTlsAlloc(pKey: *mut c_uint) -> pte_osResult {
|
||||
*pKey = NEXT_KEY.fetch_add(1, Ordering::Relaxed);
|
||||
PTE_OS_OK
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pte_osTlsFree(index: c_uint) -> pte_osResult {
|
||||
// XXX free keys
|
||||
PTE_OS_OK
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ impl Pal for Sys {
|
||||
e(syscall::ftruncate(fd as usize, len as usize)) as c_int
|
||||
}
|
||||
|
||||
fn futex(addr: *mut c_int, op: c_int, val: c_int, val2: usize) -> c_int {
|
||||
fn futex(addr: *mut c_int, op: c_int, val: c_int, val2: usize) -> Result<c_long, crate::pthread::Errno> {
|
||||
match unsafe {
|
||||
syscall::futex(
|
||||
addr as *mut i32,
|
||||
@@ -343,8 +343,8 @@ impl Pal for Sys {
|
||||
ptr::null_mut(),
|
||||
)
|
||||
} {
|
||||
Ok(success) => success as c_int,
|
||||
Err(err) => -(err.errno as c_int),
|
||||
Ok(success) => Ok(success as c_long),
|
||||
Err(err) => Err(crate::pthread::Errno(err.errno)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ pub type pthread_barrier_t = crate::header::pthread::barrier::Barrier;
|
||||
pub type pthread_barrierattr_t = crate::header::pthread::barrier::BarrierAttr;
|
||||
pub type pthread_cond_t = crate::header::pthread::cond::Cond;
|
||||
pub type pthread_condattr_t = crate::header::pthread::cond::CondAttr;
|
||||
pub type pthread_key_t = *mut c_void;
|
||||
pub type pthread_key_t = u32;
|
||||
pub type pthread_mutex_t = crate::header::pthread::mutex::Mutex;
|
||||
pub type pthread_mutexattr_t = crate::header::pthread::mutex::MutexAttr;
|
||||
pub type pthread_once_t = crate::header::pthread::once::Once;
|
||||
|
||||
Reference in New Issue
Block a user