/*************************************************************** __CPU_SYSDEPS.H This file contains HOST-dependent system call wrapper declarations and internal MCPU syscall ABI constants. PART OF : CPU - library . USAGE : Internal only . NOTE : Include "libmcpu.h" before this FILE . Copyright (C) 2026 by Andrew V.Kosteltsev. All Rights Reserved. ***************************************************************/ #ifndef __CPU_SYSDEPS_H #define __CPU_SYSDEPS_H #include #ifdef __cplusplus extern "C" { #endif /* MCPU open(2) ABI. These values are HOST-independent. */ #define __CPU_O_ACCMODE 00000003U #define __CPU_O_RDONLY 00000000U #define __CPU_O_WRONLY 00000001U #define __CPU_O_RDWR 00000002U #define __CPU_O_CREAT 00000100U #define __CPU_O_EXCL 00000200U #define __CPU_O_NOCTTY 00000400U #define __CPU_O_TRUNC 00001000U #define __CPU_O_APPEND 00002000U #define __CPU_O_NONBLOCK 00004000U #define __CPU_O_SUPPORTED ( __CPU_O_ACCMODE | __CPU_O_CREAT | __CPU_O_EXCL | \ __CPU_O_NOCTTY | __CPU_O_TRUNC | __CPU_O_APPEND | \ __CPU_O_NONBLOCK ) /* MCPU fcntl(2) ABI. Commands and descriptor flags are guest values. */ #define __CPU_F_DUPFD 0U #define __CPU_F_GETFD 1U #define __CPU_F_SETFD 2U #define __CPU_F_GETFL 3U #define __CPU_F_SETFL 4U #define __CPU_FD_CLOEXEC 1U #define __CPU_FD_SUPPORTED __CPU_FD_CLOEXEC /* F_SETFL accepts access-mode bits for the conventional GETFL/SETFL cycle, but only APPEND and NONBLOCK are mutable file-status flags. */ #define __CPU_F_SETFL_SUPPORTED \ ( __CPU_O_ACCMODE | __CPU_O_APPEND | __CPU_O_NONBLOCK ) /* MCPU pipe2(2) ABI. O_CLOEXEC is guest descriptor state; only O_NONBLOCK is translated to a HOST file-status flag. */ #define __CPU_O_CLOEXEC 02000000U #define __CPU_PIPE2_SUPPORTED ( __CPU_O_NONBLOCK | __CPU_O_CLOEXEC ) #define __CPU_PIPEFD_SIZE 16U #define __CPU_PIPEFD_READ 0U #define __CPU_PIPEFD_WRITE 8U /* MCPU mode bits used by open(2) when O_CREAT is present. */ #define __CPU_S_ISUID 00004000U #define __CPU_S_ISGID 00002000U #define __CPU_S_ISVTX 00001000U #define __CPU_S_IRUSR 00000400U #define __CPU_S_IWUSR 00000200U #define __CPU_S_IXUSR 00000100U #define __CPU_S_IRGRP 00000040U #define __CPU_S_IWGRP 00000020U #define __CPU_S_IXGRP 00000010U #define __CPU_S_IROTH 00000004U #define __CPU_S_IWOTH 00000002U #define __CPU_S_IXOTH 00000001U #define __CPU_S_SUPPORTED 00007777U /* MCPU chown(2) ABI. UINT64_MAX means "leave this ID unchanged". */ #define __CPU_ID_NO_CHANGE ((__mpu_uint64_t)-1) #define __CPU_SEEK_SET 0U #define __CPU_SEEK_CUR 1U #define __CPU_SEEK_END 2U /* MCPU access(2) ABI. These values are HOST-independent. */ #define __CPU_F_OK 0U #define __CPU_X_OK 1U #define __CPU_W_OK 2U #define __CPU_R_OK 4U #define __CPU_ACCESS_SUPPORTED (__CPU_X_OK | __CPU_W_OK | __CPU_R_OK) /* MCPU time ABI. All time values use signed 64-bit seconds and a separate signed 64-bit fractional field. Clock IDs are HOST-independent. */ #define __CPU_CLOCK_REALTIME 0U #define __CPU_CLOCK_MONOTONIC 1U #define __CPU_TIMER_ABSTIME 1U #define __CPU_TIMEVAL_SIZE 16U #define __CPU_TIMEVAL_TV_SEC 0U #define __CPU_TIMEVAL_TV_USEC 8U #define __CPU_TIMESPEC_SIZE 16U #define __CPU_TIMESPEC_TV_SEC 0U #define __CPU_TIMESPEC_TV_NSEC 8U struct __cpu_timeval { __mpu_int64_t tv_sec; __mpu_int64_t tv_usec; }; struct __cpu_timespec { __mpu_int64_t tv_sec; __mpu_int64_t tv_nsec; }; /* MCPU select(2) ABI. Descriptor sets contain four target-order u64 words, for a total of 256 guest descriptor bits. The timeout is input-only. */ #define __CPU_FD_SETSIZE 256U #define __CPU_FD_SET_WORDS 4U #define __CPU_FD_SET_SIZE 32U #define __CPU_SELECT_READ 0x01U #define __CPU_SELECT_WRITE 0x02U #define __CPU_SELECT_EXCEPT 0x04U struct __cpu_select_entry { unsigned int guest_fd; int host_fd; unsigned int events; unsigned int revents; }; /* MCPU stat(2) ABI. The structure is always exactly 128 bytes. */ #define __CPU_STAT_SIZE 128U #define __CPU_STAT_ST_DEV 0U #define __CPU_STAT_ST_INO 8U #define __CPU_STAT_ST_MODE 16U #define __CPU_STAT_ST_NLINK 24U #define __CPU_STAT_ST_UID 32U #define __CPU_STAT_ST_GID 40U #define __CPU_STAT_ST_RDEV 48U #define __CPU_STAT_ST_SIZE 56U #define __CPU_STAT_ST_BLKSIZE 64U #define __CPU_STAT_ST_BLOCKS 72U #define __CPU_STAT_ST_ATIME_SEC 80U #define __CPU_STAT_ST_ATIME_NSEC 88U #define __CPU_STAT_ST_MTIME_SEC 96U #define __CPU_STAT_ST_MTIME_NSEC 104U #define __CPU_STAT_ST_CTIME_SEC 112U #define __CPU_STAT_ST_CTIME_NSEC 120U #define __CPU_S_IFMT 000170000U #define __CPU_S_IFIFO 000010000U #define __CPU_S_IFCHR 000020000U #define __CPU_S_IFDIR 000040000U #define __CPU_S_IFBLK 000060000U #define __CPU_S_IFREG 000100000U #define __CPU_S_IFLNK 000120000U #define __CPU_S_IFSOCK 000140000U /* MCPU getdents(2) ABI. Records are fixed at 288 bytes. */ #define __CPU_DIRENT_SIZE 288U #define __CPU_DIRENT_D_INO 0U #define __CPU_DIRENT_D_OFF 8U #define __CPU_DIRENT_D_RECLEN 16U #define __CPU_DIRENT_D_TYPE 24U #define __CPU_DIRENT_D_NAME 32U #define __CPU_DIRENT_NAME_SIZE 256U #define __CPU_DT_UNKNOWN 0U #define __CPU_DT_FIFO 1U #define __CPU_DT_CHR 2U #define __CPU_DT_DIR 4U #define __CPU_DT_BLK 6U #define __CPU_DT_REG 8U #define __CPU_DT_LNK 10U #define __CPU_DT_SOCK 12U struct __cpu_dirent { __mpu_uint64_t d_ino; __mpu_int64_t d_off; __mpu_uint64_t d_reclen; __mpu_uint64_t d_type; unsigned char d_name[__CPU_DIRENT_NAME_SIZE]; }; struct __cpu_stat { __mpu_uint64_t st_dev; __mpu_uint64_t st_ino; __mpu_uint64_t st_mode; __mpu_uint64_t st_nlink; __mpu_uint64_t st_uid; __mpu_uint64_t st_gid; __mpu_uint64_t st_rdev; __mpu_int64_t st_size; __mpu_int64_t st_blksize; __mpu_int64_t st_blocks; __mpu_int64_t st_atime_sec; __mpu_uint64_t st_atime_nsec; __mpu_int64_t st_mtime_sec; __mpu_uint64_t st_mtime_nsec; __mpu_int64_t st_ctime_sec; __mpu_uint64_t st_ctime_nsec; }; /* Translate a positive HOST errno value into the stable positive MCPU errno namespace. Zero maps to zero; unknown values map to __MCPU_EUNKNOWN. */ extern int __cpu_errno_from_host( int errnum ); extern __mpu_int64_t __cpu_sys_cwd_init( void ); extern __mpu_int64_t __cpu_sys_chdir( int dirfd, const char *path ); extern __mpu_int64_t __cpu_sys_fchdir( int fd ); extern __mpu_int64_t __cpu_sys_open ( int dirfd, const char *path, __mpu_uint64_t flags, __mpu_uint64_t mode ); extern __mpu_int64_t __cpu_sys_creat( int dirfd, const char *path, __mpu_uint64_t mode ); extern __mpu_int64_t __cpu_sys_close( int fd ); extern __mpu_int64_t __cpu_sys_dup ( int fd ); extern __mpu_int64_t __cpu_sys_read ( int fd, void *buf, __mpu_uint64_t count ); extern __mpu_int64_t __cpu_sys_write( int fd, const void *buf, __mpu_uint64_t count ); extern __mpu_int64_t __cpu_sys_lseek( int fd, __mpu_int64_t offset, __mpu_uint64_t whence ); extern __mpu_int64_t __cpu_sys_link ( int dirfd, const char *oldpath, const char *newpath ); extern __mpu_int64_t __cpu_sys_unlink( int dirfd, const char *path ); extern __mpu_int64_t __cpu_sys_rename( int dirfd, const char *oldpath, const char *newpath ); extern __mpu_int64_t __cpu_sys_symlink( int dirfd, const char *target, const char *linkpath ); extern __mpu_int64_t __cpu_sys_readlink( int dirfd, const char *path, void *buf, __mpu_uint64_t count ); extern __mpu_int64_t __cpu_sys_mkdir ( int dirfd, const char *path, __mpu_uint64_t mode ); extern __mpu_int64_t __cpu_sys_chmod ( int dirfd, const char *path, __mpu_uint64_t mode ); extern __mpu_int64_t __cpu_sys_chown ( int dirfd, const char *path, __mpu_uint64_t uid, __mpu_uint64_t gid ); extern __mpu_int64_t __cpu_sys_rmdir ( int dirfd, const char *path ); extern __mpu_int64_t __cpu_sys_access( int dirfd, const char *path, __mpu_uint64_t mode ); extern __mpu_int64_t __cpu_sys_stat ( int dirfd, const char *path, struct __cpu_stat *st ); extern __mpu_int64_t __cpu_sys_fstat( int fd, struct __cpu_stat *st ); extern __mpu_int64_t __cpu_sys_lstat( int dirfd, const char *path, struct __cpu_stat *st ); extern __mpu_int64_t __cpu_sys_getdents( int fd, struct __cpu_dirent *dirp, __mpu_uint64_t count ); extern __mpu_int64_t __cpu_sys_fsync( int fd ); extern __mpu_int64_t __cpu_sys_truncate( int dirfd, const char *path, __mpu_int64_t length ); extern __mpu_int64_t __cpu_sys_ftruncate( int fd, __mpu_int64_t length ); extern __mpu_int64_t __cpu_sys_fchmod( int fd, __mpu_uint64_t mode ); extern __mpu_int64_t __cpu_sys_fchown( int fd, __mpu_uint64_t uid, __mpu_uint64_t gid ); extern __mpu_int64_t __cpu_sys_fcntl( int fd, __mpu_uint64_t cmd, __mpu_uint64_t arg ); extern __mpu_int64_t __cpu_sys_pipe2( int pipefd[2], __mpu_uint64_t flags ); extern __mpu_int64_t __cpu_sys_select( struct __cpu_select_entry *entries, __mpu_uint64_t count, const struct __cpu_timeval *timeout ); extern __mpu_int64_t __cpu_sys_clock_gettime( __mpu_uint64_t clockid, struct __cpu_timespec *tp ); extern __mpu_int64_t __cpu_sys_clock_getres( __mpu_uint64_t clockid, struct __cpu_timespec *res ); extern __mpu_int64_t __cpu_sys_clock_nanosleep( __mpu_uint64_t clockid, __mpu_uint64_t flags, const struct __cpu_timespec *req, struct __cpu_timespec *rem ); #ifdef __cplusplus } /* ... extern "C" */ #endif #endif /* __CPU_SYSDEPS_H */