Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ cfg_if! {
mod openbsd;
pub(crate) use openbsd::*;
} else if #[cfg(target_os = "qurt")] {
mod qurt;
pub(crate) use qurt::*;
pub mod qurt;
pub use qurt::*;
} else if #[cfg(target_os = "redox")] {
mod redox;
// pub(crate) use redox::*;
Expand Down
26 changes: 26 additions & 0 deletions src/new/qurt/dlfcn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! Header: `dlfcn.h`
//!
//! Dynamic linking functions and constants from Hexagon toolchain.

use crate::prelude::*;

// Values for dlopen `mode`
pub const RTLD_LAZY: c_int = 1;
pub const RTLD_NOW: c_int = 2;
pub const RTLD_GLOBAL: c_int = 0x100;
pub const RTLD_LOCAL: c_int = 0x200;

// Compatibility constant
pub const DL_LAZY: c_int = RTLD_LAZY;

// Special handles
pub const RTLD_NEXT: *mut c_void = -1isize as *mut c_void;
pub const RTLD_DEFAULT: *mut c_void = -2isize as *mut c_void;
pub const RTLD_SELF: *mut c_void = -3isize as *mut c_void;

extern "C" {
pub fn dlopen(filename: *const c_char, flag: c_int) -> *mut c_void;
pub fn dlclose(handle: *mut c_void) -> c_int;
pub fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void;
pub fn dlerror() -> *mut c_char;
}
5 changes: 4 additions & 1 deletion src/new/qurt/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub const O_NONBLOCK: c_int = 0x0800;
pub const O_SYNC: c_int = 0x1000;
pub const O_FSYNC: c_int = O_SYNC;
pub const O_DSYNC: c_int = 0x1000;
pub const O_DIRECTORY: c_int = 0x10000;
pub const O_NOFOLLOW: c_int = 0x20000;
pub const O_CLOEXEC: c_int = 0x80000;

// fcntl() commands
pub const F_DUPFD: c_int = 0;
Expand All @@ -31,6 +34,7 @@ pub const F_SETFL: c_int = 4;
pub const F_GETLK: c_int = 5;
pub const F_SETLK: c_int = 6;
pub const F_SETLKW: c_int = 7;
pub const F_DUPFD_CLOEXEC: c_int = 1030;

// File descriptor flags
pub const FD_CLOEXEC: c_int = 1;
Expand All @@ -43,7 +47,6 @@ pub const F_UNLCK: c_int = 2;
// Functions
extern "C" {
pub fn open(pathname: *const c_char, flags: c_int, ...) -> c_int;
pub fn openat(dirfd: c_int, pathname: *const c_char, flags: c_int, ...) -> c_int;
pub fn creat(pathname: *const c_char, mode: mode_t) -> c_int;
pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int;
}
238 changes: 224 additions & 14 deletions src/new/qurt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@

use crate::prelude::*;

// Basic C types for QRT
// Basic C types for QuRT
pub type intptr_t = isize;
pub type uintptr_t = usize;
pub type ptrdiff_t = isize;
pub type size_t = uintptr_t;
pub type ssize_t = intptr_t;
pub type ssize_t = c_int;

// Process and system types
pub type pid_t = c_int;
pub type uid_t = c_uint;
pub type gid_t = c_uint;

// Time types
pub type time_t = c_longlong;
pub type time_t = c_long;
pub type suseconds_t = c_long;
pub type useconds_t = c_ulong;
pub type clockid_t = c_int;
pub type timer_t = *mut c_void;

// File system types
pub type dev_t = c_ulong;
pub type ino_t = c_ulong;
pub type dev_t = c_ulonglong;
pub type ino_t = c_ulonglong;
pub type mode_t = c_uint;
pub type nlink_t = c_uint;
pub type off_t = c_long;
Expand Down Expand Up @@ -83,7 +83,20 @@ pub type va_list = *mut c_char;
// Additional missing types
pub type c_schar = i8;

// Division result types
// Wide character type (hexagon-specific)
pub type wchar_t = u32;

// Error type (compatible with std expectations)
pub type errno_t = c_int;

// Resource limit type (for compatibility, not fully supported on QuRT)
pub type rlim_t = c_ulong;

// Terminal types (for compatibility, not fully supported on QuRT)
pub type speed_t = c_uint;
pub type tcflag_t = c_uint;

// Division result types and structures
s! {
pub struct div_t {
pub quot: c_int,
Expand All @@ -105,12 +118,8 @@ s! {
pub st_ino: ino_t,
pub st_mode: mode_t,
pub st_nlink: nlink_t,
pub st_uid: uid_t,
pub st_gid: gid_t,
pub st_rdev: dev_t,
pub st_size: off_t,
pub st_blksize: blksize_t,
pub st_blocks: blkcnt_t,
pub st_atime: time_t,
pub st_mtime: time_t,
pub st_ctime: time_t,
Expand Down Expand Up @@ -143,13 +152,197 @@ s! {
pub it_value: timespec,
}

pub struct sigevent {
pub sigev_notify: c_int,
pub sigev_signo: c_int,
pub sigev_value: c_int,
pub struct dirent {
pub d_ino: c_long,
pub d_name: [c_char; 255],
}

pub struct DIR {
pub index: c_int,
pub entry: dirent,
}

// Terminal I/O structure (for compatibility, limited support on QuRT)
pub struct termios {
pub c_iflag: tcflag_t,
pub c_oflag: tcflag_t,
pub c_cflag: tcflag_t,
pub c_lflag: tcflag_t,
pub c_cc: [c_uchar; 32],
pub c_ispeed: speed_t,
pub c_ospeed: speed_t,
}

// Resource limit structures (for compatibility, limited support on QuRT)
pub struct rlimit {
pub rlim_cur: rlim_t,
pub rlim_max: rlim_t,
}

pub struct rusage {
pub ru_utime: timeval,
pub ru_stime: timeval,
pub ru_maxrss: c_long,
pub ru_ixrss: c_long,
pub ru_idrss: c_long,
pub ru_isrss: c_long,
pub ru_minflt: c_long,
pub ru_majflt: c_long,
pub ru_nswap: c_long,
pub ru_inblock: c_long,
pub ru_oublock: c_long,
pub ru_msgsnd: c_long,
pub ru_msgrcv: c_long,
pub ru_nsignals: c_long,
pub ru_nvcsw: c_long,
pub ru_nivcsw: c_long,
}

// File lock structure (for compatibility)
pub struct flock {
pub l_type: c_short,
pub l_whence: c_short,
pub l_start: off_t,
pub l_len: off_t,
pub l_pid: pid_t,
}
}

// Additional pthread constants
pub const PTHREAD_NAME_LEN: c_int = 16;
pub const PTHREAD_MAX_THREADS: c_uint = 512;
pub const PTHREAD_MIN_STACKSIZE: c_int = 512;
pub const PTHREAD_MAX_STACKSIZE: c_int = 1048576;
pub const PTHREAD_DEFAULT_STACKSIZE: c_int = 16384;
pub const PTHREAD_DEFAULT_PRIORITY: c_int = 1;
pub const PTHREAD_SPINLOCK_UNLOCKED: c_int = 0;
pub const PTHREAD_SPINLOCK_LOCKED: c_int = 1;

// Additional time constants
pub const TIME_CONV_SCLK_FREQ: c_int = 19200000;
pub const CLOCK_MONOTONIC_RAW: clockid_t = 4;
pub const CLOCK_REALTIME_COARSE: clockid_t = 5;
pub const CLOCK_MONOTONIC_COARSE: clockid_t = 6;
pub const CLOCK_BOOTTIME: clockid_t = 7;

// Stdio constants
pub const L_tmpnam: c_uint = 260;
pub const TMP_MAX: c_uint = 25;
pub const FOPEN_MAX: c_uint = 20;

// Error constants
pub const EOK: c_int = 0;

// Semaphore constants
pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;

// Page size constants (hexagon-specific)
pub const PAGESIZE: size_t = 4096;
pub const PAGE_SIZE: size_t = 4096;

// Directory entry types (hexagon-specific)
pub const DT_UNKNOWN: c_uchar = 0;
pub const DT_FIFO: c_uchar = 1;
pub const DT_CHR: c_uchar = 2;
pub const DT_DIR: c_uchar = 4;
pub const DT_BLK: c_uchar = 6;
pub const DT_REG: c_uchar = 8;
pub const DT_LNK: c_uchar = 10;
pub const DT_SOCK: c_uchar = 12;

// Directory functions (dirent.h)
extern "C" {
pub fn opendir(name: *const c_char) -> *mut DIR;
pub fn readdir(dirp: *mut DIR) -> *mut dirent;
pub fn closedir(dirp: *const DIR) -> c_int;
pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int;
}

// Additional pthread functions
extern "C" {
pub fn pthread_attr_getstack(
attr: *const pthread_attr_t,
stackaddr: *mut *mut c_void,
stacksize: *mut size_t,
) -> c_int;
pub fn pthread_attr_setstack(
attr: *mut pthread_attr_t,
stackaddr: *mut c_void,
stacksize: size_t,
) -> c_int;
}

// Additional time functions
extern "C" {
pub fn clock_getcpuclockid(pid: pid_t, clock_id: *mut clockid_t) -> c_int;
}

// POSIX semaphore functions
extern "C" {
pub fn sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t;
pub fn sem_close(sem: *mut sem_t) -> c_int;
pub fn sem_unlink(name: *const c_char) -> c_int;
}

// Additional stdlib functions
extern "C" {
pub fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void;
}

// String functions (string.h)
extern "C" {
pub fn strlen(s: *const c_char) -> size_t;
pub fn strcpy(dest: *mut c_char, src: *const c_char) -> *mut c_char;
pub fn strncpy(dest: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char;
pub fn strcat(dest: *mut c_char, src: *const c_char) -> *mut c_char;
pub fn strncat(dest: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char;
pub fn strcmp(s1: *const c_char, s2: *const c_char) -> c_int;
pub fn strncmp(s1: *const c_char, s2: *const c_char, n: size_t) -> c_int;
pub fn strcoll(s1: *const c_char, s2: *const c_char) -> c_int;
pub fn strxfrm(dest: *mut c_char, src: *const c_char, n: size_t) -> size_t;
pub fn strchr(s: *const c_char, c: c_int) -> *mut c_char;
pub fn strrchr(s: *const c_char, c: c_int) -> *mut c_char;
pub fn strspn(s: *const c_char, accept: *const c_char) -> size_t;
pub fn strcspn(s: *const c_char, reject: *const c_char) -> size_t;
pub fn strpbrk(s: *const c_char, accept: *const c_char) -> *mut c_char;
pub fn strstr(haystack: *const c_char, needle: *const c_char) -> *mut c_char;
pub fn strtok(s: *mut c_char, delim: *const c_char) -> *mut c_char;
pub fn strerror(errnum: c_int) -> *mut c_char;
pub fn memchr(s: *const c_void, c: c_int, n: size_t) -> *mut c_void;
pub fn memcmp(s1: *const c_void, s2: *const c_void, n: size_t) -> c_int;
pub fn memcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
pub fn memset(s: *mut c_void, c: c_int, n: size_t) -> *mut c_void;
}

// Additional unistd functions
extern "C" {
pub fn fork() -> pid_t;
pub fn execve(
filename: *const c_char,
argv: *const *const c_char,
envp: *const *const c_char,
) -> c_int;
}

// Character classification functions (ctype.h)
extern "C" {
pub fn isalnum(c: c_int) -> c_int;
pub fn isalpha(c: c_int) -> c_int;
pub fn iscntrl(c: c_int) -> c_int;
pub fn isdigit(c: c_int) -> c_int;
pub fn isgraph(c: c_int) -> c_int;
pub fn islower(c: c_int) -> c_int;
pub fn isprint(c: c_int) -> c_int;
pub fn ispunct(c: c_int) -> c_int;
pub fn isspace(c: c_int) -> c_int;
pub fn isupper(c: c_int) -> c_int;
pub fn isxdigit(c: c_int) -> c_int;
pub fn tolower(c: c_int) -> c_int;
pub fn toupper(c: c_int) -> c_int;
}

pub(crate) mod dlfcn;
pub(crate) mod errno;
pub(crate) mod fcntl;
pub(crate) mod limits;
Expand All @@ -161,3 +354,20 @@ pub(crate) mod stdlib;
pub(crate) mod sys;
pub(crate) mod time;
pub(crate) mod unistd;

// Re-export public items from submodules
pub use dlfcn::*;
pub use errno::*;
pub use fcntl::*;
pub use limits::*;
pub use pthread::*;
pub use semaphore::*;
pub use signal::*;
pub use stdio::*;
pub use stdlib::*;
pub use sys::mman::*;
pub use sys::sched::*;
pub use sys::stat::*;
pub use sys::types::*;
pub use time::*;
pub use unistd::*;
23 changes: 1 addition & 22 deletions src/new/qurt/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@

use super::*;
use crate::prelude::*;
use crate::{
cpu_set_t,
pthread_attr_t,
pthread_barrier_t,
pthread_barrierattr_t,
pthread_cond_t,
pthread_condattr_t,
pthread_key_t,
pthread_mutex_t,
pthread_mutexattr_t,
pthread_once_t,
pthread_rwlock_t,
pthread_rwlockattr_t,
pthread_spinlock_t,
pthread_t,
timespec,
};

// Thread creation attributes
pub const PTHREAD_CREATE_JOINABLE: c_int = 0;
Expand All @@ -41,11 +24,6 @@ pub const PTHREAD_PRIO_PROTECT: c_int = 2;
pub const PTHREAD_MIN_PRIORITY: c_int = 0;
pub const PTHREAD_MAX_PRIORITY: c_int = 255;

// Scheduling policies
pub const SCHED_OTHER: c_int = 0;
pub const SCHED_FIFO: c_int = 1;
pub const SCHED_RR: c_int = 2;

// Initializer constants
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = 0xFFFFFFFF;
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0xFFFFFFFF;
Expand Down Expand Up @@ -117,6 +95,7 @@ extern "C" {
// Condition variable attributes
pub fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> c_int;
pub fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> c_int;
pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t, clock_id: clockid_t) -> c_int;

// Thread-local storage
pub fn pthread_key_create(
Expand Down
Loading