更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_syscall.h 文件参考

浏览源代码.

类型定义

typedef int(* PollFun) (struct pollfd *fds, nfds_t nfds, int timeout)
 

函数

unsigned int SysGetGroupId (void)
 
unsigned int SysGetTid (void)
 获取当前任务ID 更多...
 
void SysSchedYield (int type)
 
int SysSchedGetScheduler (int id, int flag)
 
int SysSchedSetScheduler (int id, int policy, int prio, int flag)
 
int SysSchedGetParam (int id, int flag)
 
int SysSchedSetParam (int id, unsigned int prio, int flag)
 
int SysSetProcessPriority (int which, int who, unsigned int prio)
 
int SysGetProcessPriority (int which, int who)
 
int SysSchedGetPriorityMin (int policy)
 
int SysSchedGetPriorityMax (int policy)
 
int SysSchedRRGetInterval (int pid, struct timespec *tp)
 
int SysWait (int pid, USER int *status, int options, void *rusage)
 
int SysWaitid (idtype_t type, int pid, USER siginfo_t *info, int options, void *rusage)
 
int SysFork (void)
 
int SysVfork (void)
 
unsigned int SysGetPID (void)
 
unsigned int SysGetPPID (void)
 
int SysSetGroupID (unsigned int gid)
 
int SysGetGroupID (void)
 
int SysGetUserID (void)
 获取用户ID 更多...
 
int SysGetEffUserID (void)
 
int SysGetEffGID (void)
 
int SysSetUserID (int uid)
 
int SysGetRealEffSaveUserID (int *ruid, int *euid, int *suid)
 
int SysGetRealEffSaveGroupID (int *rgid, int *egid, int *sgid)
 
int SysSetRealEffUserID (int ruid, int euid)
 
int SysSetRealEffGroupID (int rgid, int egid)
 
int SysSetRealEffSaveGroupID (int rgid, int egid, int sgid)
 
int SysSetRealEffSaveUserID (int ruid, int euid, int suid)
 
int SysGetGroups (int size, int list[])
 
int SysSetGroups (int size, int list[])
 
int SysGetCurrProcessGroupID (void)
 获取当前进程组ID 更多...
 
int SysGetProcessGroupID (unsigned int pid)
 获取指定进程的组ID,为0时返回当前进程ID 更多...
 
int SysSetProcessGroupID (unsigned int pid, unsigned int gid)
 为指定进程设置进程组ID 更多...
 
unsigned int SysCreateUserThread (const TSK_ENTRY_FUNC func, const UserTaskParam *userParam, bool joinable)
 
int SysSetThreadArea (const char *area)
 
char * SysGetThreadArea (void)
 
int SysUserThreadSetDetach (unsigned int taskID)
 
int SysUserThreadDetach (unsigned int taskID)
 
int SysThreadJoin (unsigned int taskID)
 
void SysUserExitGroup (int status)
 
void SysThreadExit (int status)
 
int SysFutex (const unsigned int *uAddr, unsigned int flags, int val, unsigned int absTime, const unsigned int *newUserAddr)
 SysFutex 操作用户态快速互斥锁 系统调用 更多...
 
int SysSchedGetAffinity (int id, unsigned int *cpuset, int flag)
 
int SysSchedSetAffinity (int id, const unsigned short cpuset, int flag)
 
mqd_t SysMqOpen (const char *mqName, int openFlag, mode_t mode, struct mq_attr *attr)
 打开一个消息队列,由posix接口封装 更多...
 
int SysMqClose (mqd_t personal)
 关闭一个消息队列 更多...
 
int SysMqGetSetAttr (mqd_t mqd, const struct mq_attr *new, struct mq_attr *old)
 封装posix的标准接口,获取和设置消息队列的属性 更多...
 
int SysMqUnlink (const char *mqName)
 
int SysMqSend (mqd_t personal, const char *msgPtr, size_t msgLen, unsigned int msgPrio)
 
int SysMqTimedSend (mqd_t personal, const char *msg, size_t msgLen, unsigned int msgPrio, const struct timespec *absTimeout)
 定时时间发送消息,任务将被阻塞,等待被唤醒写入消息 更多...
 
ssize_t SysMqTimedReceive (mqd_t personal, char *msg, size_t msgLen, unsigned int *msgPrio, const struct timespec *absTimeout)
 定时接收消息,任务将被阻塞,等待被唤醒读取 更多...
 
int SysMqNotify (mqd_t personal, const struct sigevent *sigev)
 
int SysSigAction (int sig, const sigaction_t *restrict sa, sigaction_t *restrict old, size_t sigsetsize)
 注册信号,鸿蒙内核只捕捉了SIGSYS 信号 更多...
 
int SysSigprocMask (int how, const sigset_t_l *restrict setl, sigset_t_l *restrict oldl, size_t sigsetsize)
 系统调用之进程信号屏蔽, 什么意思?简单说就是 一个信号来了进程要不要处理,屏蔽就是不处理,注意不能屏蔽SIGKILL和SIGSTOP信号,必须要处理. 更多...
 
int SysKill (pid_t pid, int sig)
 系统调用之向进程发送信号 更多...
 
int SysPthreadKill (pid_t pid, int sig)
 系统调用之之向进程发送信号 更多...
 
int SysSigTimedWait (const sigset_t_l *setl, siginfo_t *info, const struct timespec *timeout, size_t sigsetsize)
 
int SysPause (void)
 系统调用之暂停任务 更多...
 
int SysSigPending (sigset_t_l *setl)
 获取阻塞当前任务的信号集 更多...
 
int SysSigSuspend (sigset_t_l *setl)
 
int SysMkFifo (const char *pathName, mode_t mode)
 
int SysSocket (int domain, int type, int protocol)
 
int SysBind (int s, const struct sockaddr *name, socklen_t namelen)
 
int SysConnect (int s, const struct sockaddr *name, socklen_t namelen)
 
int SysListen (int sockfd, int backlog)
 
int SysAccept (int socket, struct sockaddr *address, socklen_t *addressLen)
 
int SysGetSockName (int s, struct sockaddr *name, socklen_t *namelen)
 
int SysGetPeerName (int s, struct sockaddr *name, socklen_t *namelen)
 
ssize_t SysSend (int s, const void *dataptr, size_t size, int flags)
 
ssize_t SysSendTo (int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
 
ssize_t SysRecv (int socket, void *buffer, size_t length, int flags)
 
ssize_t SysRecvFrom (int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *addressLen)
 
int SysShutdown (int socket, int how)
 
int SysSetSockOpt (int socket, int level, int optName, const void *optValue, socklen_t optLen)
 
int SysGetSockOpt (int sockfd, int level, int optName, void *optValue, socklen_t *optLen)
 
ssize_t SysSendMsg (int s, const struct msghdr *message, int flags)
 
ssize_t SysRecvMsg (int s, struct msghdr *message, int flags)
 
voidSysMmap (void *addr, size_t size, int prot, int flags, int fd, size_t offset)
 系统调用|申请虚拟内存(分配线性地址区间)
鸿蒙与Linux标准库的差异 http://weharmonyos.com/zh-cn/device-dev/kernel/%E4%B8%8ELinux%E6%A0%87%E5%87%86%E5%BA%93%E7%9A%84%E5%B7%AE%E5%BC%82/ 更多...
 
int SysMunmap (void *addr, size_t size)
 释放虚拟内存 更多...
 
int SysMprotect (void *vaddr, size_t len, int prot)
 修改访问权限 更多...
 
voidSysMremap (void *oldAddr, size_t oldLen, size_t newLen, int flags, void *newAddr)
 
voidSysBrk (void *addr)
 brk也是申请堆内存的一种方式,一般小于 128K 会使用它 更多...
 
int SysShmGet (key_t key, size_t size, int shmflg)
 得到一个共享内存标识符或创建一个共享内存对象 更多...
 
voidSysShmAt (int shmid, const void *shmaddr, int shmflg)
 
int SysShmCtl (int shmid, int cmd, struct shmid_ds *buf)
 完成对共享内存的控制 此函数可以对shmid指定的共享存储进行多种操作(删除、取信息、加锁、解锁等) 更多...
 
int SysShmDt (const void *shmaddr)
 与shmat函数相反,是用来断开与共享内存附加点的地址,禁止本进程访问此片共享内存 更多...
 
int SysUname (struct utsname *name)
 
int SysInfo (struct sysinfo *info)
 系统信息 更多...
 
int SysNanoSleep (const struct timespec *rqtp, struct timespec *rmtp)
 
clock_t SysTimes (struct tms *buf)
 
time_t SysTime (time_t *tloc)
 
int SysSetiTimer (int which, const struct itimerval *value, struct itimerval *ovalue)
 
int SysGetiTimer (int which, struct itimerval *value)
 
int SysTimerCreate (clockid_t clockID, struct ksigevent *evp, timer_t *timerID)
 
int SysTimerGettime (timer_t timerID, struct itimerspec *value)
 
int SysTimerGetoverrun (timer_t timerID)
 
int SysTimerDelete (timer_t timerID)
 
int SysClockSettime (clockid_t clockID, const struct timespec *tp)
 
int SysClockGettime (clockid_t clockID, struct timespec *tp)
 获取系统时间 更多...
 
int SysClockGetres (clockid_t clockID, struct timespec *tp)
 
int SysClockNanoSleep (clockid_t clk, int flags, const struct timespec *req, struct timespec *rem)
 
int SysUtime (const char *path, const struct utimbuf *ptimes)
 
int SysTimerSettime (timer_t timerID, int flags, const struct itimerspec *value, struct itimerspec *oldValue)
 
int SysClockSettime64 (clockid_t clockID, const struct timespec64 *tp)
 
int SysClockGettime64 (clockid_t clockID, struct timespec64 *tp)
 
int SysClockGetres64 (clockid_t clockID, struct timespec64 *tp)
 
int SysClockNanoSleep64 (clockid_t clk, int flags, const struct timespec64 *req, struct timespec64 *rem)
 
int SysTimerGettime64 (timer_t timerID, struct itimerspec64 *value)
 
int SysTimerSettime64 (timer_t timerID, int flags, const struct itimerspec64 *value, struct itimerspec64 *oldValue)
 
int fp_open (char *fullpath, int oflags, mode_t mode)
 
int do_open (int dirfd, const char *path, int oflags, mode_t mode)
 
int do_unlink (int dirfd, const char *pathname)
 
int do_mkdir (int dirfd, const char *pathname, mode_t mode)
 
int do_rmdir (int dirfd, const char *pathname)
 
int do_rename (int oldfd, const char *oldpath, int newfd, const char *newpath)
 
int do_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout, PollFun poll)
 
int do_readdir (int fd, struct dirent **de, unsigned int count)
 
ssize_t preadv (int __fd, const struct iovec *__iov, int __count, off_t __offset)
 
ssize_t pwritev (int __fd, const struct iovec *__iov, int __count, off_t __offset)
 
int chattr (const char *pathname, struct IATTR *attr)
 
int SysClose (int fd)
 
ssize_t SysRead (int fd, void *buf, size_t nbytes)
 系统调用|读文件:从文件中读取nbytes长度的内容到buf中(用户空间) 更多...
 
ssize_t SysWrite (int fd, const void *buf, size_t nbytes)
 系统调用|写文件:将buf中(用户空间)nbytes长度的内容写到文件中 更多...
 
int SysOpen (const char *path, int oflags,...)
 系统调用|打开文件, 正常情况下返回进程的FD值 更多...
 
int SysCreat (const char *pathname, mode_t mode)
 创建文件,从实现看 SysCreat 和 SysOpen 并没有太大的区别,只有打开方式的区别
SysCreat函数完全可以被SysOpen函数替代 更多...
 
int SysLink (const char *path1, const char *path2)
 
ssize_t SysReadlink (const char *pathname, char *buf, size_t bufsize)
 
int SysSymlink (const char *target, const char *linkpath)
 
int SysLinkat (int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags)
 
int SysSymlinkat (const char *target, int dirfd, const char *linkpath)
 
ssize_t SysReadlinkat (int dirfd, const char *pathname, char *buf, size_t bufsize)
 
int SysUnlink (const char *pathname)
 删除链:删除由装入点管理的文件 更多...
 
int SysExecve (const char *fileName, char *const *argv, char *const *envp)
 动态加载程序过程 更多...
 
int SysFchdir (int fd)
 
int SysChdir (const char *path)
 
int SysUtimensat (int fd, const char *path, struct timespec times[2], int flag)
 
int SysFchmodat (int fd, const char *path, mode_t mode, int flag)
 
int SysFchmod (int fd, mode_t mode)
 
int SysChmod (const char *path, mode_t mode)
 
int SysFchownat (int fd, const char *path, uid_t owner, gid_t group, int flag)
 
int SysFchown (int fd, uid_t owner, gid_t group)
 
int SysChown (const char *pathname, uid_t owner, gid_t group)
 
off_t SysLseek (int fd, off_t offset, int whence)
 移动文件指针 更多...
 
off64_t SysLseek64 (int fd, int offsetHigh, int offsetLow, off64_t *result, int whence)
 
int SysMount (const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data)
 SysMount 挂载文件系统 挂载是指将一个存储设备挂接到一个已存在的路径上。我们要访问存储设备中的文件,必须将文件所在的分区挂载到一个已存在的路径上, 然后通过这个路径来访问存储设备。如果只有一个存储设备,则可以直接挂载到根目录 / 上,变成根文件系统 更多...
 
int SysUmount (const char *target)
 卸载文件系统,当某个文件系统不需要再使用了,那么可以将它卸载掉。 更多...
 
int SysAccess (const char *path, int amode)
 确定文件的可存取性 更多...
 
int SysFaccessat (int fd, const char *filename, int amode, int flag)
 
int SysRename (const char *oldpath, const char *newpath)
 重命名文件 更多...
 
int SysMkdir (const char *pathname, mode_t mode)
 创建目录 更多...
 
int SysRmdir (const char *pathname)
 删除目录 更多...
 
int SysDup (int fd)
 
int SysUmount2 (const char *target, int flags)
 卸载文件系统 更多...
 
int SysIoctl (int fd, int req, void *arg)
 I/O总控制函数 更多...
 
int SysFcntl (int fd, int cmd, void *arg)
 
int SysDup2 (int fd1, int fd2)
 复制文件描述符 更多...
 
int SysSelect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
 SysSelect 系统调用|文件系统|select .鸿蒙liteos目前也支持epoll方式 更多...
 
int SysPselect6 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const long data[2])
 
int SysTruncate (const char *path, off_t length)
 系统调用|文件系统|截断功能 更多...
 
int SysFtruncate (int fd, off_t length)
 系统调用|文件系统|截断功能 更多...
 
int SysStatfs (const char *path, struct statfs *buf)
 获取指定路径下文件的文件系统信息 更多...
 
int SysStatfs64 (const char *path, size_t sz, struct statfs *buf)
 获取文件系统信息 更多...
 
int SysFstatfs (int fd, struct statfs *buf)
 
int SysFstatfs64 (int fd, size_t sz, struct statfs *buf)
 
int SysStat (const char *path, struct kstat *buf)
 获取文件状态信息 更多...
 
int SysLstat (const char *path, struct kstat *buffer)
 参见SysStat 更多...
 
int SysFstat (int fields, struct kstat *buf)
 参见SysStat 更多...
 
int SysStatx (int fd, const char *restrict path, int flag, unsigned mask, struct statx *restrict stx)
 
int SysFsync (int fd)
 把文件在内存中的部分写回磁盘 更多...
 
ssize_t SysReadv (int fd, const struct iovec *iov, int iovcnt)
 通过FD读入数据到缓冲数组中,fd为进程描述符 更多...
 
ssize_t SysWritev (int fd, const struct iovec *iov, int iovcnt)
 将缓冲数组里的数据写入文件 更多...
 
int SysPipe (int pipefd[2])
 
int SysFormat (const char *dev, int sectors, int option)
 
int SysFstat64 (int fd, struct kstat *buf)
 
int SysFstatat64 (int fd, const char *restrict path, struct kstat *restrict buf, int flag)
 
int SysFcntl64 (int fd, int cmd, void *arg)
 
int SysPoll (struct pollfd *fds, nfds_t nfds, int timeout)
 SysPoll I/O多路转换
更多...
 
int SysPpoll (struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigmask, int nsig)
 
int SysPrctl (int option,...)
 对进程进行特定操作 更多...
 
ssize_t SysPread64 (int fd, void *buf, size_t nbytes, off64_t offset)
 对进程进行特定操作 更多...
 
ssize_t SysPwrite64 (int fd, const void *buf, size_t nbytes, off64_t offset)
 
int SysEpollCreate (int size)
 
int SysEpollCreate1 (int size)
 
int SysEpollCtl (int epfd, int op, int fd, struct epoll_event *ev)
 
int SysEpollWait (int epfd, struct epoll_event *evs, int maxevents, int timeout)
 
int SysEpollPwait (int epfd, struct epoll_event *evs, int maxevents, int timeout, const sigset_t *mask)
 
char * SysGetcwd (char *buf, size_t n)
 
ssize_t SysSendFile (int outfd, int infd, off_t *offset, size_t count)
 
int SysTruncate64 (const char *path, off64_t length)
 系统调用|文件系统|截断功能 更多...
 
int SysFtruncate64 (int fd, off64_t length)
 
int SysOpenat (int dirfd, const char *path, int oflags,...)
 
int SysMkdirat (int dirfd, const char *pathname, mode_t mode)
 
int SysUnlinkat (int dirfd, const char *pathname, int flag)
 
int SysRenameat (int oldfd, const char *oldpath, int newdfd, const char *newpath)
 
int SysFallocate (int fd, int mode, off_t offset, off_t len)
 
int SysFallocate64 (int fd, int mode, off64_t offset, off64_t len)
 
ssize_t SysPreadv (int fd, const struct iovec *iov, int iovcnt, long loffset, long hoffset)
 
ssize_t SysPwritev (int fd, const struct iovec *iov, int iovcnt, long loffset, long hoffset)
 
void SysSync (void)
 将内存缓冲区数据写回硬盘 更多...
 
int SysGetdents64 (int fd, struct dirent *de_user, unsigned int count)
 
int do_opendir (const char *path, int oflags)
 
char * SysRealpath (const char *path, char *resolvedPath)
 
int SysUmask (int mask)
 
int SysShellExec (const char *msgName, const char *cmdString)
 执行 shell 命令 更多...
 
int SysReboot (int magic, int magic2, int type)
 重启系统 更多...
 
int SysGetrusage (int what, struct rusage *ru)
 
long SysSysconf (int name)
 系统配置 更多...
 
int SysUgetrlimit (int resource, unsigned long long k_rlim[2])
 
int SysSetrlimit (int resource, unsigned long long k_rlim[2])
 

详细描述

什么情况下会发生从用户态向内核态切换。这里细分为3种情况:

1、发生系统调用时

这是处于用户态的进程主动请求切换到内核态的一种方式。用户态的进程通过系统调用
申请使用操作系统提供的系统调用服务例程来处理任务。而系统调用的机制,其核心仍
是使用了操作系统为用户特别开发的一个中断机制来实现的,即软中断。

2、产生异常时

当CPU执行运行在用户态下的程序时,发生了某些事先不可知的异常,这时会触发由当前
运行的进程切换到处理此异常的内核相关的程序中,也就是转到了内核态,如缺页异常。

3、外设产生中断时

当外围设备完成用户请求的操作后,会向CPU发出相应的中断信号,这时CPU会暂停执行下
一条即将要执行的指令转而去执行与中断信号对应的处理程序,如果先前执行的指令是
用户态下的程序,那么这个转换的过程自然也就发生了由用户态到内核态的切换。
比如硬盘读写操作的完成,系统会切换到硬盘读写的中断处理程序中执行后续操作等。
可以看到上述三种由用户态切换到内核态的情况中,只有系统调用是进程主动请求发生切换的,
中断和异常都是被动的。

https://blog.csdn.net/piyongduo3393/article/details/89378243

在文件 los_syscall.h 中定义.

类型定义说明

◆ PollFun

typedef int(* PollFun) (struct pollfd *fds, nfds_t nfds, int timeout)

在文件 los_syscall.h237 行定义.

函数说明

◆ chattr()

int chattr ( const char *  pathname,
struct IATTR attr 
)

在文件 vfs_chattr.c58 行定义.

59{
60 struct Vnode *vnode = NULL;
61 int ret;
62
63 if (pathname == NULL || attr == NULL) {
64 set_errno(EINVAL);
65 return VFS_ERROR;
66 }
67
68 VnodeHold();
69 ret = VnodeLookup(pathname, &vnode, 0);
70 if (ret != LOS_OK) {
71 goto errout_with_lock;
72 }
73
74 if ((vnode->originMount) && (vnode->originMount->mountFlags & MS_RDONLY)) {
75 ret = -EROFS;
76 goto errout_with_lock;
77 }
78
79 /* The way we handle the stat depends on the type of vnode that we
80 * are dealing with.
81 */
82
83 if (vnode->vop != NULL && vnode->vop->Chattr != NULL) {
84 ret = vnode->vop->Chattr(vnode, attr);
85 } else {
86 ret = -ENOSYS;
87 }
88 VnodeDrop();
89
90 if (ret < 0) {
91 goto errout;
92 }
93
94 return OK;
95
96 /* Failure conditions always set the errno appropriately */
97
98errout_with_lock:
99 VnodeDrop();
100errout:
101 set_errno(-ret);
102 return VFS_ERROR;
103}
unsigned long mountFlags
Definition: mount.h:80
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
Definition: vnode.h:164
struct VnodeOps * vop
Definition: vnode.h:174
struct Mount * originMount
Definition: vnode.h:180
int(* Chattr)(struct Vnode *vnode, struct IATTR *attr)
改变节点属性(change attr)
Definition: vnode.h:214
int VnodeDrop(void)
归还锁
Definition: vnode.c:292
int VnodeHold(void)
拿锁,封装互斥量
Definition: vnode.c:283
int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags)
通过路径查询vnode节点
Definition: vnode.c:491

◆ do_mkdir()

int do_mkdir ( int  dirfd,
const char *  pathname,
mode_t  mode 
)
这是这个函数的调用关系图:

◆ do_open()

int do_open ( int  dirfd,
const char *  path,
int  oflags,
mode_t  mode 
)
这是这个函数的调用关系图:

◆ do_opendir()

int do_opendir ( const char *  path,
int  oflags 
)
这是这个函数的调用关系图:

◆ do_readdir()

int do_readdir ( int  fd,
struct dirent **  de,
unsigned int  count 
)
这是这个函数的调用关系图:

◆ do_rename()

int do_rename ( int  oldfd,
const char *  oldpath,
int  newfd,
const char *  newpath 
)
这是这个函数的调用关系图:

◆ do_rmdir()

int do_rmdir ( int  dirfd,
const char *  pathname 
)
这是这个函数的调用关系图:

◆ do_select()

int do_select ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds,
struct timeval *  timeout,
PollFun  poll 
)
这是这个函数的调用关系图:

◆ do_unlink()

int do_unlink ( int  dirfd,
const char *  pathname 
)
这是这个函数的调用关系图:

◆ fp_open()

int fp_open ( char *  fullpath,
int  oflags,
mode_t  mode 
)

◆ preadv()

ssize_t preadv ( int  __fd,
const struct iovec *  __iov,
int  __count,
off_t  __offset 
)

在文件 vfs_preadv.c47 行定义.

48{
49 return vfs_readv(fd, iov, iovcnt, &offset);
50}
ssize_t vfs_readv(int fd, const struct iovec *iov, int iovcnt, off_t *offset)
供系统调用
Definition: vfs_readv.c:91
函数调用图:
这是这个函数的调用关系图:

◆ pwritev()

ssize_t pwritev ( int  __fd,
const struct iovec *  __iov,
int  __count,
off_t  __offset 
)

在文件 vfs_pwritev.c47 行定义.

48{
49 return vfs_writev(fd, iov, iovcnt, &offset);
50}
ssize_t vfs_writev(int fd, const struct iovec *iov, int iovcnt, off_t *offset)
Definition: vfs_writev.c:80
函数调用图:
这是这个函数的调用关系图:

◆ SysAccept()

int SysAccept ( int  socket,
struct sockaddr *  address,
socklen_t *  addressLen 
)

在文件 net_syscall.c138 行定义.

140{
141 int ret;
142
143 SOCKET_U2K(socket);
144
145 CHECK_ASPACE(addressLen, sizeof(socklen_t));
146 CPY_FROM_USER(addressLen);
147
148 CHECK_ASPACE(address, LEN(addressLen));
149 DUP_FROM_USER_NOCOPY(address, LEN(addressLen));
150
151 ret = accept(socket, address, addressLen);
152 if (ret == -1) {
153 FREE_DUP(address);
154 return -get_errno();
155 }
156
157 CPY_TO_USER(addressLen, close(ret); FREE_DUP(address));
158 DUP_TO_USER(address, LEN(addressLen), close(ret); FREE_DUP(address));
159 FREE_DUP(address);
160
161 SOCKET_K2U(ret);
162 return ret;
163}
int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
Definition: socket.c:70
int socket(int domain, int type, int protocol)
Definition: socket.c:314
函数调用图:

◆ SysAccess()

int SysAccess ( const char *  path,
int  amode 
)

确定文件的可存取性

在文件 fs_syscall.c762 行定义.

763{
764 int ret;
765 char *pathRet = NULL;
766
767 if (path != NULL) {
768 ret = UserPathCopy(path, &pathRet);
769 if (ret != 0) {
770 goto OUT;
771 }
772 }
773
774 ret = access(pathRet, amode);
775 if (ret < 0) {
776 ret = -get_errno();
777 }
778
779OUT:
780 if (pathRet != NULL) {
781 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
782 }
783
784 return ret;
785}
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
Definition: los_memory.c:1369
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
int UserPathCopy(const char *userPath, char **pathBuf)
Definition: syscall_pub.c:105
int access(const char *path, int amode)
Definition: vfs_other.c:293
函数调用图:

◆ SysBind()

int SysBind ( int  s,
const struct sockaddr *  name,
socklen_t  namelen 
)

在文件 net_syscall.c79 行定义.

80{
81 int ret;
82
83 SOCKET_U2K(s);
84 CHECK_ASPACE(name, namelen);
85
86 DUP_FROM_USER(name, namelen);
87
88 if (name == NULL) {
89 set_errno(EFAULT);
90 ret = -1;
91 } else {
92 ret = bind(s, name, namelen);
93 }
94 FREE_DUP(name);
95 if (ret == -1) {
96 return -get_errno();
97 }
98
99 return ret;
100}
int bind(int s, const struct sockaddr *name, socklen_t namelen)
Definition: socket.c:94
函数调用图:

◆ SysBrk()

void * SysBrk ( void addr)

brk也是申请堆内存的一种方式,一般小于 128K 会使用它

参数
addr
返回
void*

在文件 vm_syscall.c110 行定义.

111{
112 return LOS_DoBrk(addr);
113}
VOID * LOS_DoBrk(VOID *addr)
函数调用图:

◆ SysChdir()

int SysChdir ( const char *  path)

在文件 fs_syscall.c578 行定义.

579{
580 int ret;
581 char *pathRet = NULL;
582
583 if (path != NULL) {
584 ret = UserPathCopy(path, &pathRet);
585 if (ret != 0) {
586 goto OUT;
587 }
588 }
589
590 ret = chdir(path ? pathRet : NULL);
591 if (ret < 0) {
592 ret = -get_errno();
593 }
594
595OUT:
596 if (pathRet != NULL) {
597 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
598 }
599 return ret;
600}
int chdir(const char *path)
Definition: vfs_other.c:150
函数调用图:

◆ SysChmod()

int SysChmod ( const char *  path,
mode_t  mode 
)

在文件 fs_syscall.c2337 行定义.

2338{
2339 int ret;
2340 char *pathRet = NULL;
2341
2342 if (pathname != NULL) {
2343 ret = UserPathCopy(pathname, &pathRet);
2344 if (ret != 0) {
2345 goto OUT;
2346 }
2347 }
2348
2349 ret = chmod(pathRet, mode);
2350 if (ret < 0) {
2351 ret = -get_errno();
2352 }
2353
2354OUT:
2355 if (pathRet != NULL) {
2356 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
2357 }
2358 return ret;
2359}
int chmod(const char *path, mode_t mode)
Definition: vfs_other.c:256
函数调用图:

◆ SysChown()

int SysChown ( const char *  pathname,
uid_t  owner,
gid_t  group 
)

在文件 fs_syscall.c2495 行定义.

2496{
2497 int ret;
2498 char *pathRet = NULL;
2499
2500 if (pathname != NULL) {
2501 ret = UserPathCopy(pathname, &pathRet);
2502 if (ret != 0) {
2503 goto OUT;
2504 }
2505 }
2506
2507 ret = chown(pathRet, owner, group);
2508 if (ret < 0) {
2509 ret = -get_errno();
2510 }
2511
2512OUT:
2513 if (pathRet != NULL) {
2514 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
2515 }
2516 return ret;
2517}
int chown(const char *pathname, uid_t owner, gid_t group)
Definition: vfs_other.c:271
函数调用图:

◆ SysClockGetres()

int SysClockGetres ( clockid_t  clockID,
struct timespec *  tp 
)

在文件 time_syscall.c308 行定义.

309{
310 int ret;
311 struct timespec stp;
312
313 if (tp == NULL) {
314 errno = EINVAL;
315 return -EINVAL;
316 }
317
318 ret = clock_getres(clockID, &stp);
319 if (ret < 0) {
320 return -get_errno();
321 }
322
323 if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec))) {
324 errno = EFAULT;
325 return -EFAULT;
326 }
327
328 return ret;
329}
int clock_getres(clockid_t clockID, struct timespec *tp)
Definition: time.c:676
size_t LOS_ArchCopyToUser(void *dst, const void *src, size_t len)
从内核空间拷贝到用户空间
Definition: user_copy.c:79
函数调用图:

◆ SysClockGetres64()

int SysClockGetres64 ( clockid_t  clockID,
struct timespec64 *  tp 
)

在文件 time_syscall.c462 行定义.

463{
464 int ret;
465 struct timespec t;
466 struct timespec64 stp;
467
468 if (tp == NULL) {
469 errno = EINVAL;
470 return -EINVAL;
471 }
472
473 ret = clock_getres(clockID, &t);
474 if (ret < 0) {
475 return -get_errno();
476 }
477
478 stp.tv_sec = t.tv_sec;
479 stp.tv_nsec = t.tv_nsec;
480
481 if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec64))) {
482 errno = EFAULT;
483 return -EFAULT;
484 }
485
486 return ret;
487}
函数调用图:

◆ SysClockGettime()

int SysClockGettime ( clockid_t  clockID,
struct timespec *  tp 
)

获取系统时间

在文件 time_syscall.c285 行定义.

286{
287 int ret;
288 struct timespec stp;
289
290 if (tp == NULL) {
291 errno = EINVAL;
292 return -EINVAL;
293 }
294
295 ret = clock_gettime(clockID, &stp);
296 if (ret < 0) {
297 return -get_errno();
298 }
299
300 if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec))) {
301 errno = EFAULT;
302 return -EFAULT;
303 }
304
305 return ret;
306}
int clock_gettime(clockid_t clockID, struct timespec *tp)
当用户程序进行特定系统调用时(例如clock_gettime(CLOCK_REALTIME_COARSE, &ts)),VDSO代码页会将其拦截;
Definition: time.c:614
函数调用图:

◆ SysClockGettime64()

int SysClockGettime64 ( clockid_t  clockID,
struct timespec64 *  tp 
)

在文件 time_syscall.c435 行定义.

436{
437 int ret;
438 struct timespec t;
439 struct timespec64 stp;
440
441 if (tp == NULL) {
442 errno = EINVAL;
443 return -EINVAL;
444 }
445
446 ret = clock_gettime(clockID, &t);
447 if (ret < 0) {
448 return -get_errno();
449 }
450
451 stp.tv_sec = t.tv_sec;
452 stp.tv_nsec = t.tv_nsec;
453
454 if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec64))) {
455 errno = EFAULT;
456 return -EFAULT;
457 }
458
459 return ret;
460}
函数调用图:

◆ SysClockNanoSleep()

int SysClockNanoSleep ( clockid_t  clk,
int  flags,
const struct timespec *  req,
struct timespec *  rem 
)

在文件 time_syscall.c331 行定义.

332{
333 int ret;
334 struct timespec sreq;
335 struct timespec srem = { 0 };
336
337 if (!req || LOS_ArchCopyFromUser(&sreq, req, sizeof(struct timespec))) {
338 errno = EFAULT;
339 return -EFAULT;
340 }
341
342 ret = clock_nanosleep(clk, flags, &sreq, rem ? &srem : NULL);
343 if (ret < 0) {
344 return -get_errno();
345 }
346
347 if (rem && LOS_ArchCopyToUser(rem, &srem, sizeof(struct timespec))) {
348 errno = EFAULT;
349 return -EFAULT;
350 }
351
352 return ret;
353}
int clock_nanosleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem)
Definition: time.c:718
size_t LOS_ArchCopyFromUser(void *dst, const void *src, size_t len)
Definition: user_copy.c:58
函数调用图:

◆ SysClockNanoSleep64()

int SysClockNanoSleep64 ( clockid_t  clk,
int  flags,
const struct timespec64 *  req,
struct timespec64 *  rem 
)

在文件 time_syscall.c489 行定义.

490{
491 int ret;
492 struct timespec rq;
493 struct timespec rm = { 0 };
494 struct timespec64 sreq;
495 struct timespec64 srem = { 0 };
496
497 if (!req || LOS_ArchCopyFromUser(&sreq, req, sizeof(struct timespec64))) {
498 errno = EFAULT;
499 return -EFAULT;
500 }
501
502 if (req != NULL) {
503 rq.tv_sec = (sreq.tv_sec > UINT32_MAX) ? UINT32_MAX : sreq.tv_sec;
504 rq.tv_nsec = sreq.tv_nsec;
505 }
506
507 ret = clock_nanosleep(clk, flags, &rq, rem ? &rm : NULL);
508 if (ret < 0) {
509 return -get_errno();
510 }
511
512 if (rem != NULL) {
513 srem.tv_sec = rm.tv_sec;
514 srem.tv_nsec = rm.tv_nsec;
515 if (LOS_ArchCopyToUser(rem, &srem, sizeof(struct timespec64))) {
516 errno = EFAULT;
517 return -EFAULT;
518 }
519 }
520
521 return ret;
522}
函数调用图:

◆ SysClockSettime()

int SysClockSettime ( clockid_t  clockID,
const struct timespec *  tp 
)

在文件 time_syscall.c263 行定义.

264{
265 int ret;
266 struct timespec stp;
267
268 if (tp == NULL) {
269 errno = EINVAL;
270 return -EINVAL;
271 }
272
273 if (LOS_ArchCopyFromUser(&stp, tp, sizeof(struct timespec))) {
274 errno = EFAULT;
275 return -EFAULT;
276 }
277
278 ret = clock_settime(clockID, &stp);
279 if (ret < 0) {
280 return -get_errno();
281 }
282 return ret;
283}
int clock_settime(clockid_t clockID, const struct timespec *tp)
Definition: time.c:452
函数调用图:

◆ SysClockSettime64()

int SysClockSettime64 ( clockid_t  clockID,
const struct timespec64 *  tp 
)

在文件 time_syscall.c405 行定义.

406{
407 int ret;
408 struct timespec t;
409 struct timespec64 stp;
410
411 if (tp == NULL) {
412 errno = EINVAL;
413 return -EINVAL;
414 }
415
416 if (LOS_ArchCopyFromUser(&stp, tp, sizeof(struct timespec64))) {
417 errno = EFAULT;
418 return -EFAULT;
419 }
420
421 if (stp.tv_sec > UINT32_MAX) {
422 errno = ENOSYS;
423 return -ENOSYS;
424 }
425 t.tv_sec = stp.tv_sec;
426 t.tv_nsec = stp.tv_nsec;
427
428 ret = clock_settime(clockID, &t);
429 if (ret < 0) {
430 return -get_errno();
431 }
432 return ret;
433}
函数调用图:

◆ SysClose()

int SysClose ( int  fd)

在文件 fs_syscall.c236 行定义.

237{
238 int ret;
239
240 /* Process fd convert to system global fd */
241 int sysfd = DisassociateProcessFd(fd);//先解除关联
242
243 ret = close(sysfd);//关闭文件,个人认为应该先 close - > DisassociateProcessFd
244 if (ret < 0) {//关闭失败时
245 AssociateSystemFd(fd, sysfd);//继续关联
246 return -get_errno();
247 }
248 FreeProcessFd(fd);//释放进程fd
249 return ret;
250}
void AssociateSystemFd(int procFd, int sysFd)
参数进程FD和参数系统FD进行绑定(关联)
Definition: vfs_procfd.c:105
void FreeProcessFd(int procFd)
释放进程文件描述符
Definition: vfs_procfd.c:191
int DisassociateProcessFd(int procFd)
解绑系统文件描述符,返回系统文件描述符
Definition: vfs_procfd.c:206
函数调用图:

◆ SysConnect()

int SysConnect ( int  s,
const struct sockaddr *  name,
socklen_t  namelen 
)

在文件 net_syscall.c102 行定义.

103{
104 int ret;
105
106 SOCKET_U2K(s);
107 CHECK_ASPACE(name, namelen);
108
109 DUP_FROM_USER(name, namelen);
110
111 if (name == NULL) {
112 set_errno(EFAULT);
113 ret = -1;
114 } else {
115 ret = connect(s, name, namelen);
116 }
117 FREE_DUP(name);
118 if (ret == -1) {
119 return -get_errno();
120 }
121
122 return ret;
123}
int connect(int s, const struct sockaddr *name, socklen_t namelen)
Definition: socket.c:185
函数调用图:

◆ SysCreat()

int SysCreat ( const char *  pathname,
mode_t  mode 
)

创建文件,从实现看 SysCreat 和 SysOpen 并没有太大的区别,只有打开方式的区别
SysCreat函数完全可以被SysOpen函数替代

参数
pathname
mode
常用标签如下:
   O_CREAT:若文件存在,此标志无用;若不存在,建新文件
   O_TRUNC:若文件存在,则长度被截为0,属性不变
   O_WRONLY:写文件 
   O_RDONLY:读文件
   O_BINARY:此标志可显示地给出以二进制方式打开文件 
   O_TEXT :此标志可用于显示地给出以文本方式打开文件
   O_RDWR :即读也写
   O_APPEND:即读也写,但每次写总是在文件尾添加
* 
返回
int

在文件 fs_syscall.c372 行定义.

373{
374 int ret = 0;
375 char *pathRet = NULL;
376
377 if (pathname != NULL) {
378 ret = UserPathCopy(pathname, &pathRet);
379 if (ret != 0) {
380 goto OUT;
381 }
382 }
383
384 int procFd = AllocProcessFd();
385 if (procFd < 0) {
386 ret = -EMFILE;
387 goto OUT;
388 }
389 // 调用关系 open -> do_open chmod 666
390 ret = open((pathname ? pathRet : NULL), O_CREAT | O_TRUNC | O_WRONLY, mode);
391 if (ret < 0) {
392 FreeProcessFd(procFd);
393 ret = -get_errno();
394 } else {
395 AssociateSystemFd(procFd, ret);
396 ret = procFd;
397 }
398
399OUT:
400 if (pathRet != NULL) {
401 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
402 }
403 return ret;
404}
int AllocProcessFd(void)
分配文件描述符
Definition: vfs_procfd.c:228
函数调用图:

◆ SysCreateUserThread()

unsigned int SysCreateUserThread ( const TSK_ENTRY_FUNC  func,
const UserTaskParam userParam,
bool  joinable 
)

在文件 process_syscall.c882 行定义.

883{
884 TSK_INIT_PARAM_S param = { 0 };
885 int ret;
886
887 ret = LOS_ArchCopyFromUser(&(param.userParam), userParam, sizeof(UserTaskParam));
888 if (ret != 0) {
889 return OS_INVALID_VALUE;
890 }
891
892 param.pfnTaskEntry = func;
893 if (joinable == TRUE) {
894 param.uwResved = LOS_TASK_ATTR_JOINABLE;
895 } else {
896 param.uwResved = LOS_TASK_STATUS_DETACHED;
897 }
898
899 return OsCreateUserTask(OS_INVALID_VALUE, &param);
900}
LITE_OS_SEC_TEXT_INIT UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam)
创建一个用户态任务
Definition: los_task.c:1434
TSK_ENTRY_FUNC pfnTaskEntry
Definition: los_task.h:504
UserTaskParam userParam
任务用户态运行时任何参数
Definition: los_task.h:517
UINT32 uwResved
Definition: los_task.h:513
函数调用图:

◆ SysDup()

int SysDup ( int  fd)

在文件 fs_syscall.c871 行定义.

872{
873 int sysfd = GetAssociatedSystemFd(fd);
874 /* Check if the param is valid, note that: socket fd is not support dup2 */
875 if ((sysfd < 0) || (sysfd >= CONFIG_NFILE_DESCRIPTORS)) {
876 return -EBADF;
877 }
878
879 int dupfd = AllocProcessFd();
880 if (dupfd < 0) {
881 return -EMFILE;
882 }
883
884 files_refer(sysfd);
885 AssociateSystemFd(dupfd, sysfd);
886 return dupfd;
887}
void files_refer(int fd)
int GetAssociatedSystemFd(int procFd)
获取绑定的系统描述符
Definition: vfs_procfd.c:133
函数调用图:

◆ SysDup2()

int SysDup2 ( int  fd1,
int  fd2 
)

复制文件描述符

在文件 fs_syscall.c1038 行定义.

1039{
1040 int ret;
1041 int sysfd1 = GetAssociatedSystemFd(fd1);
1042 int sysfd2 = GetAssociatedSystemFd(fd2);
1043 //检查参数是否有效,注意:socket fd不支持dup2
1044 /* Check if the param is valid, note that: socket fd is not support dup2 */
1045 if ((sysfd1 < 0) || (sysfd1 >= CONFIG_NFILE_DESCRIPTORS) || (CheckProcessFd(fd2) != OK)) {//socket的fd必大于CONFIG_NFILE_DESCRIPTORS
1046 return -EBADF;
1047 }
1048
1049 /* Handle special circumstances */
1050 if (fd1 == fd2) {
1051 return fd2;
1052 }
1053
1054 ret = AllocSpecifiedProcessFd(fd2);
1055 if (ret != OK) {
1056 return ret;
1057 }
1058
1059 /* close the sysfd2 in need */
1060 if (sysfd2 >= 0) {
1061 ret = close(sysfd2);
1062 if (ret < 0) {
1063 AssociateSystemFd(fd2, sysfd2);
1064 return -get_errno();
1065 }
1066 }
1067
1068 files_refer(sysfd1);
1069 AssociateSystemFd(fd2, sysfd1);
1070
1071 /* if fd1 is not equal to fd2, the FD_CLOEXEC flag associated with fd2 shall be cleared */
1072 ClearCloexecFlag(fd2);
1073 return fd2;
1074}
void ClearCloexecFlag(int procFd)
Definition: vfs_cloexec.c:89
int CheckProcessFd(int procFd)
Definition: vfs_procfd.c:122
int AllocSpecifiedProcessFd(int procFd)
Definition: vfs_procfd.c:162
函数调用图:

◆ SysEpollCreate()

int SysEpollCreate ( int  size)

在文件 fs_syscall.c2751 行定义.

2752{
2753 (void)size;
2754 return DoEpollCreate1(0);
2755}
static int DoEpollCreate1(int flags)
Definition: fs_syscall.c:2731
函数调用图:

◆ SysEpollCreate1()

int SysEpollCreate1 ( int  size)

在文件 fs_syscall.c2757 行定义.

2758{
2759 return DoEpollCreate1(flags);
2760}
函数调用图:

◆ SysEpollCtl()

int SysEpollCtl ( int  epfd,
int  op,
int  fd,
struct epoll_event ev 
)

在文件 fs_syscall.c2762 行定义.

2763{
2764 int ret;
2765
2766 CHECK_ASPACE(ev, sizeof(struct epoll_event));
2767 CPY_FROM_USER(ev);
2768
2769 fd = GetAssociatedSystemFd(fd);
2770 epfd = GetAssociatedSystemFd(epfd);
2771 if ((fd < 0) || (epfd < 0)) {
2772 ret = -EBADF;
2773 goto OUT;
2774 }
2775
2776 ret = epoll_ctl(epfd, op, fd, ev);
2777 if (ret < 0) {
2778 ret = -EBADF;
2779 goto OUT;
2780 }
2781
2782 CPY_TO_USER(ev);
2783OUT:
2784 return (ret == -1) ? -get_errno() : ret;
2785}
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
Definition: fs_epoll.c:233
函数调用图:

◆ SysEpollPwait()

int SysEpollPwait ( int  epfd,
struct epoll_event evs,
int  maxevents,
int  timeout,
const sigset_t *  mask 
)

在文件 fs_syscall.c2810 行定义.

2811{
2812 sigset_t_l origMask;
2813 sigset_t_l setl;
2814 int ret = 0;
2815
2816 CHECK_ASPACE(mask, sizeof(sigset_t));
2817
2818 if (mask != NULL) {
2819 ret = LOS_ArchCopyFromUser(&setl, mask, sizeof(sigset_t));
2820 if (ret != 0) {
2821 return -EFAULT;
2822 }
2823 }
2824
2825 CHECK_ASPACE(evs, sizeof(struct epoll_event));
2826 CPY_FROM_USER(evs);
2827
2828 epfd = GetAssociatedSystemFd(epfd);
2829 if (epfd < 0) {
2830 ret = -EBADF;
2831 goto OUT;
2832 }
2833
2834 OsSigprocMask(SIG_SETMASK, &setl, &origMask);
2835 ret = epoll_wait(epfd, evs, maxevents, timeout);
2836 if (ret < 0) {
2837 ret = -get_errno();
2838 }
2839
2840 OsSigprocMask(SIG_SETMASK, &origMask, NULL);
2841
2842 CPY_TO_USER(evs);
2843OUT:
2844 return (ret == -1) ? -get_errno() : ret;
2845}
int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout)
Definition: fs_epoll.c:297
int OsSigprocMask(int how, const sigset_t_l *set, sigset_t_l *oldset)
Definition: los_signal.c:233
函数调用图:

◆ SysEpollWait()

int SysEpollWait ( int  epfd,
struct epoll_event evs,
int  maxevents,
int  timeout 
)

在文件 fs_syscall.c2787 行定义.

2788{
2789 int ret = 0;
2790
2791 CHECK_ASPACE(evs, sizeof(struct epoll_event));
2792 CPY_FROM_USER(evs);
2793
2794 epfd = GetAssociatedSystemFd(epfd);
2795 if (epfd < 0) {
2796 ret = -EBADF;
2797 goto OUT;
2798 }
2799
2800 ret = epoll_wait(epfd, evs, maxevents, timeout);
2801 if (ret < 0) {
2802 ret = -get_errno();
2803 }
2804
2805 CPY_TO_USER(evs);
2806OUT:
2807 return (ret == -1) ? -get_errno() : ret;
2808}
函数调用图:

◆ SysExecve()

int SysExecve ( const char *  fileName,
char *const *  argv,
char *const *  envp 
)

动态加载程序过程

在文件 fs_syscall.c548 行定义.

549{
550 return LOS_DoExecveFile(fileName, argv, envp);
551}
INT32 LOS_DoExecveFile(const CHAR *fileName, CHAR *const *argv, CHAR *const *envp)
LOS_DoExecveFile 根据fileName执行一个新的用户程序 LOS_DoExecveFile接口一般由用户通过execve系列接口利用系统调用机制调用创建新的进程,内核不能直接调用该接口...
Definition: los_exec_elf.c:165
函数调用图:

◆ SysFaccessat()

int SysFaccessat ( int  fd,
const char *  filename,
int  amode,
int  flag 
)

在文件 fs_syscall.c2566 行定义.

2567{
2568 int ret;
2569 struct stat buf;
2570 struct statfs fsBuf;
2571 char *fullDirectory = NULL;
2572
2573 ret = GetFullpath(fd, filename, &fullDirectory);
2574 if (ret < 0) {
2575 goto OUT;
2576 }
2577
2578 ret = statfs(fullDirectory, &fsBuf);
2579 if (ret != 0) {
2580 ret = -get_errno();
2581 goto OUT;
2582 }
2583
2584 if ((fsBuf.f_flags & MS_RDONLY) && ((unsigned int)amode & W_OK)) {
2585 ret = -EROFS;
2586 goto OUT;
2587 }
2588
2589 ret = stat(fullDirectory, &buf);
2590 if (ret != 0) {
2591 ret = -get_errno();
2592 goto OUT;
2593 }
2594
2595 if (VfsPermissionCheck(buf.st_uid, buf.st_gid, buf.st_mode, amode)) {
2596 ret = -EACCES;
2597 }
2598
2599OUT:
2600 PointerFree(fullDirectory);
2601
2602 return ret;
2603}
int GetFullpath(int fd, const char *path, char **fullpath)
Definition: syscall_pub.c:64
int VfsPermissionCheck(uint fuid, uint fgid, mode_t fileMode, int accMode)
函数调用图:

◆ SysFallocate()

int SysFallocate ( int  fd,
int  mode,
off_t  offset,
off_t  len 
)

在文件 fs_syscall.c2067 行定义.

2068{
2069 int ret;
2070
2071 /* Process fd convert to system global fd */
2072 fd = GetAssociatedSystemFd(fd);
2073
2074 ret = fallocate(fd, mode, offset, len);
2075 if (ret < 0) {
2076 return -get_errno();
2077 }
2078 return ret;
2079}
int fallocate(int fd, int mode, off_t offset, off_t len)
函数调用图:

◆ SysFallocate64()

int SysFallocate64 ( int  fd,
int  mode,
off64_t  offset,
off64_t  len 
)

在文件 fs_syscall.c2081 行定义.

2082{
2083 int ret;
2084
2085 /* Process fd convert to system global fd */
2086 fd = GetAssociatedSystemFd(fd);
2087
2088 ret = fallocate64(fd, mode, offset, len);
2089 if (ret < 0) {
2090 return -get_errno();
2091 }
2092 return ret;
2093}
int fallocate64(int fd, int mode, off64_t offset, off64_t len)
函数调用图:

◆ SysFchdir()

int SysFchdir ( int  fd)

在文件 fs_syscall.c554 行定义.

555{
556 int ret;
557 int sysFd;
558 struct file *file = NULL;
559
560 sysFd = GetAssociatedSystemFd(fd);
561 if (sysFd < 0) {
562 return -EBADF;
563 }
564
565 ret = fs_getfilep(sysFd, &file);
566 if (ret < 0) {
567 return -get_errno();
568 }
569
570 ret = chdir(file->f_path);
571 if (ret < 0) {
572 ret = -get_errno();
573 }
574
575 return ret;
576}
char * f_path
函数调用图:

◆ SysFchmod()

int SysFchmod ( int  fd,
mode_t  mode 
)

在文件 fs_syscall.c2400 行定义.

2401{
2402 int ret;
2403 int sysFd;
2404 struct IATTR attr = {
2405 .attr_chg_mode = mode,
2406 .attr_chg_valid = CHG_MODE, /* change mode */
2407 };
2408 struct file *file = NULL;
2409
2410 sysFd = GetAssociatedSystemFd(fd);
2411 if (sysFd < 0) {
2412 return -EBADF;
2413 }
2414
2415 ret = fs_getfilep(sysFd, &file);
2416 if (ret < 0) {
2417 return -get_errno();
2418 }
2419
2420 ret = chattr(file->f_path, &attr);
2421 if (ret < 0) {
2422 return -get_errno();
2423 }
2424
2425 return ret;
2426}
int chattr(const char *pathname, struct IATTR *attr)
Definition: vfs_chattr.c:58
此结构用于记录 vnode 的属性
Definition: vnode.h:81
unsigned attr_chg_mode
确定了文件的类型,以及它的所有者、它的group、其它用户访问此文件的权限 (S_IWUSR | ...)
Definition: vnode.h:85
函数调用图:

◆ SysFchmodat()

int SysFchmodat ( int  fd,
const char *  path,
mode_t  mode,
int  flag 
)

在文件 fs_syscall.c2361 行定义.

2362{
2363 int ret;
2364 char *pathRet = NULL;
2365 char *fullpath = NULL;
2366 struct IATTR attr = {
2367 .attr_chg_mode = mode,
2368 .attr_chg_valid = CHG_MODE,
2369 };
2370
2371 if (path != NULL) {
2372 ret = UserPathCopy(path, &pathRet);
2373 if (ret != 0) {
2374 goto OUT;
2375 }
2376 }
2377
2378 if (fd != AT_FDCWD) {
2379 /* Process fd convert to system global fd */
2380 fd = GetAssociatedSystemFd(fd);
2381 }
2382
2383 ret = vfs_normalize_pathat(fd, pathRet, &fullpath);
2384 if (ret < 0) {
2385 goto OUT;
2386 }
2387
2388 ret = chattr(fullpath, &attr);
2389 if (ret < 0) {
2390 ret = -get_errno();
2391 }
2392
2393OUT:
2394 PointerFree(pathRet);
2395 PointerFree(fullpath);
2396
2397 return ret;
2398}
int vfs_normalize_pathat(int dirfd, const char *filename, char **pathname)
Definition: fullpath.c:309
函数调用图:

◆ SysFchown()

int SysFchown ( int  fd,
uid_t  owner,
gid_t  group 
)

在文件 fs_syscall.c2461 行定义.

2462{
2463 int ret;
2464 int sysFd;
2465 struct IATTR attr = {0};
2466 attr.attr_chg_valid = 0;
2467 struct file *file = NULL;
2468
2469 sysFd = GetAssociatedSystemFd(fd);
2470 if (sysFd < 0) {
2471 return -EBADF;
2472 }
2473
2474 ret = fs_getfilep(sysFd, &file);
2475 if (ret < 0) {
2476 return -get_errno();
2477 }
2478
2479 if (owner != (uid_t)-1) {
2480 attr.attr_chg_uid = owner;
2481 attr.attr_chg_valid |= CHG_UID;
2482 }
2483 if (group != (gid_t)-1) {
2484 attr.attr_chg_gid = group;
2485 attr.attr_chg_valid |= CHG_GID;
2486 }
2487 ret = chattr(file->f_path, &attr);
2488 if (ret < 0) {
2489 ret = -get_errno();
2490 }
2491
2492 return ret;
2493}
unsigned attr_chg_uid
用户ID
Definition: vnode.h:86
unsigned attr_chg_gid
组ID
Definition: vnode.h:87
unsigned int attr_chg_valid
节点改变有效性 (CHG_MODE | CHG_UID | ... )
Definition: vnode.h:83
函数调用图:

◆ SysFchownat()

int SysFchownat ( int  fd,
const char *  path,
uid_t  owner,
gid_t  group,
int  flag 
)

在文件 fs_syscall.c2428 行定义.

2429{
2430 int ret;
2431 char *fullpath = NULL;
2432 struct IATTR attr = {
2433 .attr_chg_valid = 0,
2434 };
2435
2436 ret = GetFullpath(fd, path, &fullpath);
2437 if (ret < 0) {
2438 goto OUT;
2439 }
2440
2441 if (owner != (uid_t)-1) {
2442 attr.attr_chg_uid = owner;
2443 attr.attr_chg_valid |= CHG_UID;
2444 }
2445 if (group != (gid_t)-1) {
2446 attr.attr_chg_gid = group;
2447 attr.attr_chg_valid |= CHG_GID;
2448 }
2449
2450 ret = chattr(fullpath, &attr);
2451 if (ret < 0) {
2452 ret = -get_errno();
2453 }
2454
2455OUT:
2456 PointerFree(fullpath);
2457
2458 return ret;
2459}
函数调用图:

◆ SysFcntl()

int SysFcntl ( int  fd,
int  cmd,
void arg 
)
用来修改已经打开文件的属性的函数包含5个功能:
1.复制一个已有文件描述符,功能和dup和dup2相同,对应的cmd:F_DUPFD、F_DUPFD_CLOEXEC。
    当使用这两个cmd时,需要传入第三个参数,fcntl返回复制后的文件描述符,此返回值是之前未被占用的描述符,
    并且必须一个大于等于第三个参数值。
    F_DUPFD命令要求返回的文件描述符会清除对应的FD_CLOEXEC
    F_DUPFD_CLOEXEC要求设置新描述符的FD_CLOEXEC标志。

2.获取、设置文件描述符标志,对应的cmd:F_GETFD、F_SETFD。
    用于设置FD_CLOEXEC标志,此标志的含义是:当进程执行exec系统调用后此文件描述符会被自动关闭。

3.获取、设置文件访问状态标志,对应的cmd:F_GETFL、F_SETFL。
    获取当前打开文件的访问标志,设置对应的访问标志,一般常用来设置做非阻塞读写操作。

4.获取、设置记录锁功能,对应的cmd:F_GETLK、F_SETLK、F_SETLKW。

5.获取、设置异步I/O所有权,对应的cmd:F_GETOWN、F_SETOWN。
    获取和设置用来接收SIGIO/SIGURG信号的进程id或者进程组id。返回对应的进程id或者进程组id取负值。
 * 
参数
fd
cmd
arg
返回
int

在文件 fs_syscall.c957 行定义.

958{
959 /* Process fd convert to system global fd */
960 int sysfd = GetAssociatedSystemFd(fd);
961
962 int ret = VfsFcntl(fd, cmd, arg);
963 if (ret == CONTINE_NUTTX_FCNTL) {
964 ret = fcntl(sysfd, cmd, arg);
965 }
966
967 if (ret < 0) {
968 return -get_errno();
969 }
970 return ret;
971}
int VfsFcntl(int fd, int cmd,...)
Definition: vfs_fcntl.c:68
函数调用图:

◆ SysFcntl64()

int SysFcntl64 ( int  fd,
int  cmd,
void arg 
)

在文件 fs_syscall.c2223 行定义.

2224{
2225 /* Process fd convert to system global fd */
2226 int sysfd = GetAssociatedSystemFd(fd);
2227
2228 int ret = VfsFcntl(fd, cmd, arg);
2229 if (ret == CONTINE_NUTTX_FCNTL) {
2230 ret = fcntl64(sysfd, cmd, arg);
2231 }
2232
2233 if (ret < 0) {
2234 return -get_errno();
2235 }
2236 return ret;
2237}
函数调用图:

◆ SysFork()

int SysFork ( void  )

在文件 process_syscall.c350 行定义.

351{
352 return OsClone(0, 0, 0);
353}
LITE_OS_SEC_TEXT INT32 OsClone(UINT32 flags, UINTPTR sp, UINT32 size)
OsClone 进程克隆
Definition: los_process.c:2049
函数调用图:

◆ SysFormat()

int SysFormat ( const char *  dev,
int  sectors,
int  option 
)

在文件 fs_syscall.c2173 行定义.

2174{
2175 int ret;
2176 char *devRet = NULL;
2177
2178 if (!IsCapPermit(CAP_FS_FORMAT)) {
2179 return -EPERM;
2180 }
2181
2182 if (dev != NULL) {
2183 ret = UserPathCopy(dev, &devRet);
2184 if (ret != 0) {
2185 goto OUT;
2186 }
2187 }
2188
2189 ret = format((dev ? devRet : NULL), sectors, option);
2190 if (ret < 0) {
2191 ret = -get_errno();
2192 }
2193
2194OUT:
2195 if (devRet != NULL) {
2196 (void)LOS_MemFree(OS_SYS_MEM_ADDR, devRet);
2197 }
2198 return ret;
2199}
BOOL IsCapPermit(UINT32 capIndex)
Definition: capability.c:43
int format(const char *dev, int sectors, int option)
formatting sd card
Definition: format.c:44
函数调用图:

◆ SysFstat()

int SysFstat ( int  fields,
struct kstat *  buf 
)

参见SysStat

在文件 fs_syscall.c1401 行定义.

1402{
1403 int ret;
1404 struct stat bufRet = {0};
1405 struct file *filep = NULL;
1406
1407 /* Process fd convert to system global fd */
1408 fd = GetAssociatedSystemFd(fd);
1409
1410 ret = fs_getfilep(fd, &filep);
1411 if (ret < 0) {
1412 return -get_errno();
1413 }
1414
1415 if (filep->f_oflags & O_DIRECTORY) {
1416 return -EBADF;
1417 }
1418
1419 ret = stat(filep->f_path, (buf ? (&bufRet) : NULL));
1420 if (ret < 0) {
1421 return -get_errno();
1422 }
1423
1424 ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct kstat));
1425 if (ret != 0) {
1426 return -EFAULT;
1427 }
1428
1429 return ret;
1430}
int f_oflags
函数调用图:

◆ SysFstat64()

int SysFstat64 ( int  fd,
struct kstat *  buf 
)

在文件 fs_syscall.c2202 行定义.

2203{
2204 int ret;
2205 struct stat64 bufRet = {0};
2206
2207 /* Process fd convert to system global fd */
2208 fd = GetAssociatedSystemFd(fd);
2209
2210 ret = fstat64(fd, (buf ? (&bufRet) : NULL));
2211 if (ret < 0) {
2212 return -get_errno();
2213 }
2214
2215 ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct kstat));
2216 if (ret != 0) {
2217 return -EFAULT;
2218 }
2219
2220 return ret;
2221}
int fstat64(int fd, struct stat64 *buf)
Definition: vfs_other.c:63
函数调用图:

◆ SysFstatat64()

int SysFstatat64 ( int  fd,
const char *restrict  path,
struct kstat *restrict  buf,
int  flag 
)

在文件 fs_syscall.c2519 行定义.

2520{
2521 int ret;
2522 struct stat bufRet = {0};
2523 char *pathRet = NULL;
2524 char *fullpath = NULL;
2525
2526 if (path != NULL) {
2527 ret = UserPathCopy(path, &pathRet);
2528 if (ret != 0) {
2529 goto OUT;
2530 }
2531 }
2532
2533 if (dirfd != AT_FDCWD) {
2534 /* Process fd convert to system global fd */
2535 dirfd = GetAssociatedSystemFd(dirfd);
2536 }
2537
2538 ret = vfs_normalize_pathat(dirfd, pathRet, &fullpath);
2539 if (ret < 0) {
2540 goto OUT;
2541 }
2542
2543 ret = stat(fullpath, &bufRet);
2544 if (ret < 0) {
2545 ret = -get_errno();
2546 goto OUT;
2547 }
2548
2549 ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct kstat));
2550 if (ret != 0) {
2551 ret = -EFAULT;
2552 goto OUT;
2553 }
2554
2555OUT:
2556 if (pathRet != NULL) {
2557 LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
2558 }
2559
2560 if (fullpath != NULL) {
2561 free(fullpath);
2562 }
2563 return ret;
2564}
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
函数调用图:

◆ SysFstatfs()

int SysFstatfs ( int  fd,
struct statfs *  buf 
)

在文件 fs_syscall.c2605 行定义.

2606{
2607 int ret;
2608 struct file *filep = NULL;
2609 struct statfs bufRet = {0};
2610
2611 /* Process fd convert to system global fd */
2612 fd = GetAssociatedSystemFd(fd);
2613
2614 ret = fs_getfilep(fd, &filep);
2615 if (ret < 0) {
2616 ret = -get_errno();
2617 return ret;
2618 }
2619
2620 ret = statfs(filep->f_path, &bufRet);
2621 if (ret < 0) {
2622 ret = -get_errno();
2623 return ret;
2624 }
2625
2626 ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct statfs));
2627 if (ret != 0) {
2628 ret = -EFAULT;
2629 }
2630
2631 return ret;
2632}
函数调用图:
这是这个函数的调用关系图:

◆ SysFstatfs64()

int SysFstatfs64 ( int  fd,
size_t  sz,
struct statfs *  buf 
)

在文件 fs_syscall.c2634 行定义.

2635{
2636 int ret;
2637
2638 if (sz != sizeof(struct statfs)) {
2639 ret = -EINVAL;
2640 return ret;
2641 }
2642
2643 ret = SysFstatfs(fd, buf);
2644
2645 return ret;
2646}
int SysFstatfs(int fd, struct statfs *buf)
Definition: fs_syscall.c:2605
函数调用图:

◆ SysFsync()

int SysFsync ( int  fd)

把文件在内存中的部分写回磁盘

在文件 fs_syscall.c1437 行定义.

1438{
1439 int ret;
1440 struct file *filep = NULL;
1441
1442 /* Process fd convert to system global fd */
1443 fd = GetAssociatedSystemFd(fd);
1444
1445 /* Get the file structure corresponding to the file descriptor. */
1446 ret = fs_getfilep(fd, &filep);
1447 if (ret < 0) {
1448 /* The errno value has already been set */
1449 return -get_errno();
1450 }
1451
1452 if (filep->f_oflags & O_DIRECTORY) {
1453 return -EBADF;
1454 }
1455
1456 /* Perform the fsync operation */
1457 ret = file_fsync(filep);
1458 if (ret < 0) {
1459 return -get_errno();
1460 }
1461 return ret;
1462}
函数调用图:

◆ SysFtruncate()

int SysFtruncate ( int  fd,
off_t  length 
)

系统调用|文件系统|截断功能

在文件 fs_syscall.c1258 行定义.

1259{
1260 int ret;
1261
1262 /* Process fd convert to system global fd */
1263 fd = GetAssociatedSystemFd(fd);
1264
1265 ret = ftruncate(fd, length);
1266 if (ret < 0) {
1267 return -get_errno();
1268 }
1269 return ret;
1270}
函数调用图:

◆ SysFtruncate64()

int SysFtruncate64 ( int  fd,
off64_t  length 
)

在文件 fs_syscall.c1767 行定义.

1768{
1769 int ret;
1770
1771 /* Process fd convert to system global fd */
1772 fd = GetAssociatedSystemFd(fd);
1773
1774 ret = ftruncate64(fd, length);
1775 if (ret < 0) {
1776 return -get_errno();
1777 }
1778 return ret;
1779}
函数调用图:

◆ SysFutex()

int SysFutex ( const unsigned int uAddr,
unsigned int  flags,
int  val,
unsigned int  absTime,
const unsigned int newUserAddr 
)

SysFutex 操作用户态快速互斥锁 系统调用

参数
absTime绝对时间
flags操作标识(FUTEX_WAKE | FUTEX_WAIT)
newUserAddrFUTEX_REQUEUE下调整后带回新的用户空间地址
uAddr用户态下共享内存的地址,里面存放的是一个对齐的整型计数器
val
返回
参见

在文件 process_syscall.c1022 行定义.

1024{
1025 if ((flags & FUTEX_MASK) == FUTEX_REQUEUE) {//调整队列标识
1026 return -OsFutexRequeue(uAddr, flags, val, absTime, newUserAddr);
1027 }
1028
1029 if ((flags & FUTEX_MASK) == FUTEX_WAKE) {//唤醒标识
1030 return -OsFutexWake(uAddr, flags, val);//最多唤醒val个等待在uaddr上进程
1031 }
1032 //FUTEX_WAIT
1033 return -OsFutexWait(uAddr, flags, val, absTime);//设置线程等待 原子性的检查uaddr中计数器的值是否为val,
1034 //如果是则让进程休眠,直到FUTEX_WAKE或者超时(time-out)。也就是把进程挂到uaddr相对应的等待队列上去。
1035}
INT32 OsFutexWait(const UINT32 *userVaddr, UINT32 flags, UINT32 val, UINT32 absTime)
设置线程等待 | 向Futex表中插入代表被阻塞的线程的node
Definition: los_futex.c:693
INT32 OsFutexRequeue(const UINT32 *userVaddr, UINT32 flags, INT32 wakeNumber, INT32 count, const UINT32 *newUserVaddr)
调整指定锁在Futex表中的位置
Definition: los_futex.c:1022
INT32 OsFutexWake(const UINT32 *userVaddr, UINT32 flags, INT32 wakeNumber)
唤醒一个被指定锁阻塞的线程
Definition: los_futex.c:815
函数调用图:

◆ SysGetCurrProcessGroupID()

int SysGetCurrProcessGroupID ( void  )

获取当前进程组ID

在文件 process_syscall.c401 行定义.

402{
404}
LITE_OS_SEC_TEXT INT32 LOS_GetCurrProcessGroupID(VOID)
获取当前进程的组ID
Definition: los_process.c:1485
函数调用图:

◆ SysGetcwd()

char * SysGetcwd ( char *  buf,
size_t  n 
)

在文件 fs_syscall.c1706 行定义.

1707{
1708 char *ret = NULL;
1709 char *bufRet = NULL;
1710 size_t bufLen = n;
1711 int retVal;
1712
1713 if (bufLen > PATH_MAX) {
1714 bufLen = PATH_MAX;
1715 }
1716
1717 bufRet = (char *)LOS_MemAlloc(OS_SYS_MEM_ADDR, bufLen);
1718 if (bufRet == NULL) {
1719 return (char *)(intptr_t)-ENOMEM;
1720 }
1721 (void)memset_s(bufRet, bufLen, 0, bufLen);
1722
1723 ret = getcwd((buf ? bufRet : NULL), bufLen);
1724 if (ret == NULL) {
1725 (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
1726 return (char *)(intptr_t)-get_errno();
1727 }
1728
1729 retVal = LOS_ArchCopyToUser(buf, bufRet, bufLen);
1730 if (retVal != 0) {
1731 (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
1732 return (char *)(intptr_t)-EFAULT;
1733 }
1734 ret = buf;
1735
1736 (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
1737 return ret;
1738}
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
Definition: los_memory.c:1123
char * getcwd(char *buf, size_t n)
Definition: vfs_other.c:222
函数调用图:

◆ SysGetdents64()

int SysGetdents64 ( int  fd,
struct dirent *  de_user,
unsigned int  count 
)

在文件 fs_syscall.c2239 行定义.

2240{
2241 if (!LOS_IsUserAddressRange((VADDR_T)(UINTPTR)de_user, count)) {
2242 return -EFAULT;
2243 }
2244
2245 struct dirent *de_knl = NULL;
2246
2247 /* Process fd convert to system global fd */
2248 fd = GetAssociatedSystemFd(fd);
2249
2250 int ret = do_readdir(fd, &de_knl, count);
2251 if (ret < 0) {
2252 return ret;
2253 }
2254 if (de_knl != NULL) {
2255 int cpy_ret = LOS_ArchCopyToUser(de_user, de_knl, ret);
2256 if (cpy_ret != 0)
2257 {
2258 return -EFAULT;
2259 }
2260 }
2261 return ret;
2262}
int do_readdir(int fd, struct dirent **de, unsigned int count)
unsigned long VADDR_T
Definition: los_typedef.h:208
unsigned long UINTPTR
Definition: los_typedef.h:68
STATIC INLINE BOOL LOS_IsUserAddressRange(VADDR_T vaddr, size_t len)
虚拟地址[vaddr,vaddr + len]是否在用户空间
Definition: los_vm_map.h:281
函数调用图:

◆ SysGetEffGID()

int SysGetEffGID ( void  )

在文件 syscall_lookup.h198 行定义.

函数调用图:

◆ SysGetEffUserID()

int SysGetEffUserID ( void  )

在文件 process_syscall.c411 行定义.

412{
413#ifdef LOSCFG_SECURITY_CAPABILITY
414 UINT32 intSave;
415 int euid;
416
417 SCHEDULER_LOCK(intSave);
418 euid = (int)OsCurrUserGet()->effUserID;
419 SCHEDULER_UNLOCK(intSave);
420 return euid;
421#else
422 return 0;
423#endif
424}
STATIC INLINE User * OsCurrUserGet(VOID)
unsigned int UINT32
Definition: los_typedef.h:57
UINT32 effUserID
ARG_NUM_3 int
函数调用图:

◆ SysGetGroupId()

unsigned int SysGetGroupId ( void  )

◆ SysGetGroupID()

int SysGetGroupID ( void  )

在文件 syscall_lookup.h151 行定义.

函数调用图:

◆ SysGetGroups()

int SysGetGroups ( int  size,
int  list[] 
)

在文件 process_syscall.c799 行定义.

800{
801#ifdef LOSCFG_SECURITY_CAPABILITY
802 return GetGroups(size, list);
803#else
804 int group = 0;
805 int groupCount = 1;
806 int ret;
807
808 if (size == 0) {
809 return groupCount;
810 } else if (list == NULL) {
811 return -EFAULT;
812 } else if (size < groupCount) {
813 return -EINVAL;
814 }
815
816 ret = LOS_ArchCopyToUser(list, &group, sizeof(int));
817 if (ret != 0) {
818 return -EFAULT;
819 }
820
821 return groupCount;
822#endif
823}
static int GetGroups(int size, int list[])
函数调用图:

◆ SysGetiTimer()

int SysGetiTimer ( int  which,
struct itimerval *  value 
)

在文件 time_syscall.c137 行定义.

138{
139 int ret;
140 struct itimerval svalue;
141
142 if (value == NULL) {
143 errno = EINVAL;
144 return -EINVAL;
145 }
146
147 ret = getitimer(which, &svalue);
148 if (ret < 0) {
149 return -get_errno();
150 }
151
152 if (LOS_ArchCopyToUser(value, &svalue, sizeof(struct itimerval))) {
153 errno = EFAULT;
154 return -EFAULT;
155 }
156
157 return ret;
158}
int getitimer(int which, struct itimerval *value)
Definition: time.c:1172
函数调用图:

◆ SysGetPeerName()

int SysGetPeerName ( int  s,
struct sockaddr *  name,
socklen_t *  namelen 
)

在文件 net_syscall.c194 行定义.

195{
196 int ret;
197
198 SOCKET_U2K(s);
199
200 CHECK_ASPACE(namelen, sizeof(socklen_t));
201 CPY_FROM_USER(namelen);
202
203 CHECK_ASPACE(name, LEN(namelen));
204 DUP_FROM_USER_NOCOPY(name, LEN(namelen));
205
206 if (name == NULL || namelen == NULL) {
207 set_errno(EFAULT);
208 ret = -1;
209 } else {
210 ret = getpeername(s, name, namelen);
211 }
212 if (ret == -1) {
213 FREE_DUP(name);
214 return -get_errno();
215 }
216
217 CPY_TO_USER(namelen, FREE_DUP(name));
218 DUP_TO_USER(name, LEN(namelen), FREE_DUP(name));
219 FREE_DUP(name);
220 return ret;
221}
int getpeername(int s, struct sockaddr *name, socklen_t *namelen)
获取对等名称 = getsockname
Definition: socket.c:129
函数调用图:

◆ SysGetPID()

unsigned int SysGetPID ( void  )

在文件 process_syscall.c365 行定义.

366{
367 return LOS_GetCurrProcessID();
368}
LITE_OS_SEC_TEXT UINT32 LOS_GetCurrProcessID(VOID)
获取当前进程的进程ID
Definition: los_process.c:2161
函数调用图:

◆ SysGetPPID()

unsigned int SysGetPPID ( void  )

在文件 syscall_lookup.h153 行定义.

函数调用图:

◆ SysGetProcessGroupID()

int SysGetProcessGroupID ( unsigned int  pid)

获取指定进程的组ID,为0时返回当前进程ID

在文件 process_syscall.c392 行定义.

393{
394 if (pid == 0) {
395 pid = LOS_GetCurrProcessID();
396 }
397
398 return LOS_GetProcessGroupID(pid);
399}
LITE_OS_SEC_TEXT INT32 LOS_GetProcessGroupID(UINT32 pid)
Definition: los_process.c:1461
函数调用图:

◆ SysGetProcessPriority()

int SysGetProcessPriority ( int  which,
int  who 
)

在文件 process_syscall.c227 行定义.

228{
229 if (who == 0) {
230 who = (int)LOS_GetCurrProcessID();
231 }
232
233 return OsGetProcessPriority(which, who);
234}
LITE_OS_SEC_TEXT INT32 OsGetProcessPriority(INT32 which, INT32 pid)
接口封装 - 获取进程优先级 which:标识进程,进程组,用户
Definition: los_process.c:1055
函数调用图:

◆ SysGetRealEffSaveGroupID()

int SysGetRealEffSaveGroupID ( int rgid,
int egid,
int sgid 
)

在文件 process_syscall.c622 行定义.

623{
624 int ret;
625 int realGroupID, effGroupID, saveGroupID;
626#ifdef LOSCFG_SECURITY_CAPABILITY
627 unsigned int intSave;
628
629 SCHEDULER_LOCK(intSave);
630 realGroupID = OsCurrUserGet()->gid;
631 effGroupID = OsCurrUserGet()->effGid;
632 saveGroupID = OsCurrUserGet()->effGid;
633 SCHEDULER_UNLOCK(intSave);
634#else
635 realGroupID = 0;
636 effGroupID = 0;
637 saveGroupID = 0;
638#endif
639
640 ret = LOS_ArchCopyToUser(rgid, &realGroupID, sizeof(int));
641 if (ret != 0) {
642 return -EFAULT;
643 }
644
645 ret = LOS_ArchCopyToUser(egid, &effGroupID, sizeof(int));
646 if (ret != 0) {
647 return -EFAULT;
648 }
649
650 ret = LOS_ArchCopyToUser(sgid, &saveGroupID, sizeof(int));
651 if (ret != 0) {
652 return -EFAULT;
653 }
654
655 return 0;
656}
UINT32 gid
用户组ID [0,60000],0为root用户组
UINT32 effGid
函数调用图:

◆ SysGetRealEffSaveUserID()

int SysGetRealEffSaveUserID ( int ruid,
int euid,
int suid 
)

在文件 process_syscall.c441 行定义.

442{
443 int ret;
444 int realUserID, effUserID, saveUserID;
445#ifdef LOSCFG_SECURITY_CAPABILITY
446 unsigned int intSave;
447
448 SCHEDULER_LOCK(intSave);
449 realUserID = OsCurrUserGet()->userID;
450 effUserID = OsCurrUserGet()->effUserID;
451 saveUserID = OsCurrUserGet()->effUserID;
452 SCHEDULER_UNLOCK(intSave);
453#else
454 realUserID = 0;
455 effUserID = 0;
456 saveUserID = 0;
457#endif
458
459 ret = LOS_ArchCopyToUser(ruid, &realUserID, sizeof(int));
460 if (ret != 0) {
461 return -EFAULT;
462 }
463
464 ret = LOS_ArchCopyToUser(euid, &effUserID, sizeof(int));
465 if (ret != 0) {
466 return -EFAULT;
467 }
468
469 ret = LOS_ArchCopyToUser(suid, &saveUserID, sizeof(int));
470 if (ret != 0) {
471 return -EFAULT;
472 }
473
474 return 0;
475}
UINT32 userID
用户ID [0,60000],0为root用户
函数调用图:

◆ SysGetrusage()

int SysGetrusage ( int  what,
struct rusage *  ru 
)

在文件 misc_syscall.c158 行定义.

159{
160 int ret;
161 struct tms time;
162 clock_t usec, sec;
163 struct rusage kru;
164
165 ret = LOS_ArchCopyFromUser(&kru, ru, sizeof(struct rusage));
166 if (ret != 0) {
167 return -EFAULT;
168 }
169
170 if (times(&time) == -1) {
171 return -EFAULT;
172 }
173
174 switch (what) {
175 case RUSAGE_SELF: {
176 usec = time.tms_utime;
177 sec = time.tms_stime;
178 break;
179 }
180 case RUSAGE_CHILDREN: {
181 usec = time.tms_cutime;
182 sec = time.tms_cstime;
183 break;
184 }
185 default:
186 return -EINVAL;
187 }
188 ConvertClocks(&kru.ru_utime, usec);
189 ConvertClocks(&kru.ru_stime, sec);
190
191 ret = LOS_ArchCopyToUser(ru, &kru, sizeof(struct rusage));
192 if (ret != 0) {
193 return -EFAULT;
194 }
195 return 0;
196}
static void ConvertClocks(struct timeval *time, clock_t clk)
Definition: misc_syscall.c:152
clock_t times(struct tms *buf)
Definition: time.c:1107
time_t time(time_t *t)
Definition: time.c:1224
函数调用图:

◆ SysGetSockName()

int SysGetSockName ( int  s,
struct sockaddr *  name,
socklen_t *  namelen 
)

在文件 net_syscall.c165 行定义.

166{
167 int ret;
168
169 SOCKET_U2K(s);
170
171 CHECK_ASPACE(namelen, sizeof(socklen_t));
172 CPY_FROM_USER(namelen);
173
174 CHECK_ASPACE(name, LEN(namelen));
175 DUP_FROM_USER_NOCOPY(name, LEN(namelen));
176
177 if (name == NULL || namelen == NULL) {
178 set_errno(EFAULT);
179 ret = -1;
180 } else {
181 ret = getsockname(s, name, namelen);
182 }
183 if (ret == -1) {
184 FREE_DUP(name);
185 return -get_errno();
186 }
187
188 CPY_TO_USER(namelen, FREE_DUP(name));
189 DUP_TO_USER(name, LEN(namelen), FREE_DUP(name));
190 FREE_DUP(name);
191 return ret;
192}
int getsockname(int s, struct sockaddr *name, socklen_t *namelen)
获取socket名称和长度
Definition: socket.c:136
函数调用图:

◆ SysGetSockOpt()

int SysGetSockOpt ( int  sockfd,
int  level,
int  optName,
void optValue,
socklen_t *  optLen 
)

在文件 net_syscall.c366 行定义.

368{
369 int ret;
370
371 SOCKET_U2K(sockfd);
372
373 CHECK_ASPACE(optLen, sizeof(socklen_t));
374 CPY_FROM_USER(optLen);
375
376 CHECK_ASPACE(optValue, LEN(optLen));
377 DUP_FROM_USER_NOCOPY(optValue, LEN(optLen));
378
379 if (optLen == NULL) {
380 set_errno(EFAULT);
381 ret = -1;
382 } else {
383 ret = getsockopt(sockfd, level, optName, optValue, optLen);
384 }
385 if (ret == -1) {
386 FREE_DUP(optValue);
387 return -get_errno();
388 }
389
390 CPY_TO_USER(optLen, FREE_DUP(optValue));
391 DUP_TO_USER(optValue, LEN(optLen), FREE_DUP(optValue));
392 FREE_DUP(optValue);
393 return ret;
394}
int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
获取 socket 配置项
Definition: socket.c:143
函数调用图:

◆ SysGetThreadArea()

char * SysGetThreadArea ( void  )

在文件 syscall_lookup.h217 行定义.

函数调用图:

◆ SysGetTid()

unsigned int SysGetTid ( void  )

获取当前任务ID

在文件 process_syscall.c1037 行定义.

1038{
1039 return OsCurrTaskGet()->taskID;
1040}
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
UINT32 taskID
函数调用图:

◆ SysGetUserID()

int SysGetUserID ( void  )

获取用户ID

在文件 process_syscall.c406 行定义.

407{
408 return LOS_GetUserID();
409}
LITE_OS_SEC_TEXT INT32 LOS_GetUserID(VOID)
Definition: los_process.c:826
函数调用图:

◆ SysInfo()

int SysInfo ( struct sysinfo *  info)

系统信息

在文件 misc_syscall.c71 行定义.

72{
73 int ret;
74 struct sysinfo tmpInfo = { 0 };
75
76 tmpInfo.totalram = LOS_MemPoolSizeGet(m_aucSysMem1);
78 tmpInfo.sharedram = 0;
79 tmpInfo.bufferram = 0;
80 tmpInfo.totalswap = 0;
81 tmpInfo.freeswap = 0;
82
83 ret = LOS_ArchCopyToUser(info, &tmpInfo, sizeof(struct sysinfo));
84 if (ret != 0) {
85 return -EFAULT;
86 }
87 return 0;
88}
UINT8 * m_aucSysMem1
系统动态内存池地址的起始地址 @note_thinking 能否不要用 0,1来命名核心变量 ???
Definition: los_memory.c:108
UINT32 LOS_MemPoolSizeGet(const VOID *pool)
获取指定动态内存池的总大小
Definition: los_memory.c:1603
UINT32 LOS_MemTotalUsedGet(VOID *pool)
获取指定动态内存池的总使用量大小
Definition: los_memory.c:1628
函数调用图:

◆ SysIoctl()

int SysIoctl ( int  fd,
int  req,
void arg 
)

I/O总控制函数

在文件 fs_syscall.c902 行定义.

903{
904 int ret;
905 unsigned int size = _IOC_SIZE((unsigned int)req);
906 unsigned int dir = _IOC_DIR((unsigned int)req);
907 if ((size == 0) && (dir != _IOC_NONE)) {
908 return -EINVAL;
909 }
910
911 if ((dir != _IOC_NONE) && (((void *)(uintptr_t)arg) == NULL)) {
912 return -EINVAL;
913 }
914
915 if ((dir & _IOC_READ) || (dir & _IOC_WRITE)) {
916 if (!LOS_IsUserAddressRange((uintptr_t)arg, size)) {
917 return -EFAULT;
918 }
919 }
920
921 /* Process fd convert to system global fd */
922 fd = GetAssociatedSystemFd(fd);
923
924 ret = ioctl(fd, req, arg);
925 if (ret < 0) {
926 return -get_errno();
927 }
928 return ret;
929}
函数调用图:

◆ SysKill()

int SysKill ( pid_t  pid,
int  sig 
)

系统调用之向进程发送信号

在文件 ipc_syscall.c302 行定义.

303{
304 return OsKillLock(pid, sig);
305}
int OsKillLock(pid_t pid, int sig)
给发送信号过程加锁
Definition: los_signal.c:480
函数调用图:

◆ SysLink()

int SysLink ( const char *  path1,
const char *  path2 
)

在文件 fs_syscall.c406 行定义.

407{
408 int ret;
409 char *oldpathRet = NULL;
410 char *newpathRet = NULL;
411
412 if (oldpath != NULL) {
413 ret = UserPathCopy(oldpath, &oldpathRet);
414 if (ret != 0) {
415 goto OUT;
416 }
417 }
418
419 if (newpath != NULL) {
420 ret = UserPathCopy(newpath, &newpathRet);
421 if (ret != 0) {
422 goto OUT;
423 }
424 }
425
426 ret = link(oldpathRet, newpathRet);
427 if (ret < 0) {
428 ret = -get_errno();
429 }
430
431OUT:
432 if (oldpathRet != NULL) {
433 (void)LOS_MemFree(OS_SYS_MEM_ADDR, oldpathRet);
434 }
435 if (newpathRet != NULL) {
436 (void)LOS_MemFree(OS_SYS_MEM_ADDR, newpathRet);
437 }
438 return ret;
439}
函数调用图:

◆ SysLinkat()

int SysLinkat ( int  olddirfd,
const char *  oldpath,
int  newdirfd,
const char *  newpath,
int  flags 
)

在文件 fs_syscall.c1870 行定义.

1871{
1872 int ret;
1873 char *oldpathRet = NULL;
1874 char *newpathRet = NULL;
1875
1876 if (oldpath != NULL) {
1877 ret = UserPathCopy(oldpath, &oldpathRet);
1878 if (ret != 0) {
1879 goto OUT;
1880 }
1881 }
1882
1883 if (newpath != NULL) {
1884 ret = UserPathCopy(newpath, &newpathRet);
1885 if (ret != 0) {
1886 goto OUT;
1887 }
1888 }
1889
1890 if (olddirfd != AT_FDCWD) {
1891 /* Process fd convert to system global fd */
1892 olddirfd = GetAssociatedSystemFd(olddirfd);
1893 }
1894
1895 if (newdirfd != AT_FDCWD) {
1896 /* Process fd convert to system global fd */
1897 newdirfd = GetAssociatedSystemFd(newdirfd);
1898 }
1899
1900 ret = linkat(olddirfd, oldpathRet, newdirfd, newpathRet, flags);
1901 if (ret < 0) {
1902 ret = -get_errno();
1903 }
1904
1905OUT:
1906 if (oldpathRet != NULL) {
1907 (void)LOS_MemFree(OS_SYS_MEM_ADDR, oldpathRet);
1908 }
1909 if (newpathRet != NULL) {
1910 (void)LOS_MemFree(OS_SYS_MEM_ADDR, newpathRet);
1911 }
1912 return ret;
1913}
函数调用图:

◆ SysListen()

int SysListen ( int  sockfd,
int  backlog 
)

在文件 net_syscall.c125 行定义.

126{
127 int ret;
128
129 SOCKET_U2K(sockfd);
130 ret = listen(sockfd, backlog);
131 if (ret == -1) {
132 return -get_errno();
133 }
134
135 return ret;
136}
int listen(int s, int backlog)
Definition: socket.c:209
函数调用图:

◆ SysLseek()

off_t SysLseek ( int  fd,
off_t  offset,
int  whence 
)

移动文件指针

在文件 fs_syscall.c602 行定义.

603{
604 /* Process fd convert to system global fd */
605 fd = GetAssociatedSystemFd(fd);
606
607 return _lseek(fd, offset, whence);
608}
off_t _lseek(int fd, off_t offset, int whence)
Definition: stdio.c:38
函数调用图:

◆ SysLseek64()

off64_t SysLseek64 ( int  fd,
int  offsetHigh,
int  offsetLow,
off64_t result,
int  whence 
)

在文件 fs_syscall.c611 行定义.

612{
613 off64_t ret;
614 off64_t res;
615 int retVal;
616
617 /* Process fd convert to system global fd */
618 fd = GetAssociatedSystemFd(fd);
619
620 ret = _lseek64(fd, offsetHigh, offsetLow, &res, whence);
621 if (ret != 0) {
622 return ret;
623 }
624
625 retVal = LOS_ArchCopyToUser(result, &res, sizeof(off64_t));
626 if (retVal != 0) {
627 return -EFAULT;
628 }
629
630 return 0;
631}
off64_t _lseek64(int fd, int offsetHigh, int offsetLow, off64_t *result, int whence)
Definition: stdio.c:77
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 off64_t
函数调用图:

◆ SysLstat()

int SysLstat ( const char *  path,
struct kstat *  buffer 
)

参见SysStat

在文件 fs_syscall.c1370 行定义.

1371{
1372 int ret;
1373 char *pathRet = NULL;
1374 struct stat bufRet = {0};
1375
1376 if (path != NULL) {
1377 ret = UserPathCopy(path, &pathRet);
1378 if (ret != 0) {
1379 goto OUT;
1380 }
1381 }
1382
1383 ret = stat((path ? pathRet : NULL), (buffer ? (&bufRet) : NULL));
1384 if (ret < 0) {
1385 ret = -get_errno();
1386 goto OUT;
1387 }
1388
1389 ret = LOS_ArchCopyToUser(buffer, &bufRet, sizeof(struct kstat));
1390 if (ret != 0) {
1391 ret = -EFAULT;
1392 }
1393
1394OUT:
1395 if (pathRet != NULL) {
1396 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
1397 }
1398 return ret;
1399}
函数调用图:

◆ SysMkdir()

int SysMkdir ( const char *  pathname,
mode_t  mode 
)

创建目录

在文件 fs_syscall.c823 行定义.

824{
825 int ret;
826 char *pathRet = NULL;
827
828 if (pathname != NULL) {
829 ret = UserPathCopy(pathname, &pathRet);
830 if (ret != 0) {
831 goto OUT;
832 }
833 }
834
835 ret = do_mkdir(AT_FDCWD, (pathname ? pathRet : NULL), mode);
836 if (ret < 0) {
837 ret = -get_errno();
838 }
839
840OUT:
841 if (pathRet != NULL) {
842 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
843 }
844 return ret;
845}
int do_mkdir(int dirfd, const char *pathname, mode_t mode)
函数调用图:

◆ SysMkdirat()

int SysMkdirat ( int  dirfd,
const char *  pathname,
mode_t  mode 
)

在文件 fs_syscall.c1841 行定义.

1842{
1843 int ret;
1844 char *pathRet = NULL;
1845
1846 if (pathname != NULL) {
1847 ret = UserPathCopy(pathname, &pathRet);
1848 if (ret != 0) {
1849 goto OUT;
1850 }
1851 }
1852
1853 if (dirfd != AT_FDCWD) {
1854 /* Process fd convert to system global fd */
1855 dirfd = GetAssociatedSystemFd(dirfd);
1856 }
1857
1858 ret = do_mkdir(dirfd, (pathname ? pathRet : NULL), mode);
1859 if (ret < 0) {
1860 ret = -get_errno();
1861 }
1862
1863OUT:
1864 if (pathRet != NULL) {
1865 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
1866 }
1867 return ret;
1868}
函数调用图:

◆ SysMkFifo()

int SysMkFifo ( const char *  pathName,
mode_t  mode 
)

在文件 ipc_syscall.c389 行定义.

390{
391 int retValue;
392 char kPathName[PATH_MAX + 1] = { 0 };
393
394 retValue = LOS_StrncpyFromUser(kPathName, pathName, PATH_MAX);
395 if (retValue < 0) {
396 return retValue;
397 }
398 return mkfifo(kPathName, mode);
399}
INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count)
函数调用图:

◆ SysMmap()

void * SysMmap ( void addr,
size_t  size,
int  prot,
int  flags,
int  fd,
size_t  offset 
)

系统调用|申请虚拟内存(分配线性地址区间)
鸿蒙与Linux标准库的差异 http://weharmonyos.com/zh-cn/device-dev/kernel/%E4%B8%8ELinux%E6%A0%87%E5%87%86%E5%BA%93%E7%9A%84%E5%B7%AE%E5%BC%82/

参数
addr用来请求使用某个特定的虚拟内存地址。如果取NULL,结果地址就将自动分配(这是推荐的做法), 否则会降低程序的可移植性,因为不同系统的可用地址范围不一样。
size内存段的大小。
prot用于设置内存段的访问权限,有如下权限:
PROT_READ:允许读该内存段。
PROT_WRITE:允许写该内存段。
PROT_EXEC:允许执行该内存段。
PROT_NONE:不能访问。
flags控制程序对内存段的改变所造成的影响,有如下属性:
MAP_PRIVATE:标志指定线性区中的页可以被进程独享
MAP_SHARED:标志指定线性区中的页可以被几个进程共享
fd打开的文件描述符,如果新的线性区将把一个文件映射到内存的情况
offset用以改变经共享内存段访问的文件中数据的起始偏移值。
返回
void* 成功返回:虚拟内存地址,这地址是页对齐。
失败返回:(void *)-1。

在文件 vm_syscall.c58 行定义.

59{
60 /* Process fd convert to system global fd */
61 fd = GetAssociatedSystemFd(fd);
62
63 return (void *)LOS_MMap((uintptr_t)addr, size, prot, flags, fd, offset);//分配线性地址区间
64}
VADDR_T LOS_MMap(VADDR_T vaddr, size_t len, unsigned prot, unsigned long flags, int fd, unsigned long pgoff)
函数调用图:

◆ SysMount()

int SysMount ( const char *  source,
const char *  target,
const char *  filesystemtype,
unsigned long  mountflags,
const void data 
)

SysMount 挂载文件系统 挂载是指将一个存储设备挂接到一个已存在的路径上。我们要访问存储设备中的文件,必须将文件所在的分区挂载到一个已存在的路径上, 然后通过这个路径来访问存储设备。如果只有一个存储设备,则可以直接挂载到根目录 / 上,变成根文件系统

参数
data特定文件系统的私有数据
filesystemtype挂载的文件系统类型
mountflags读写标志位
source已经格式化的块设备名称
target挂载路径,即挂载点
返回
参见

在文件 fs_syscall.c666 行定义.

668{
669 int ret;
670 char *sourceRet = NULL;
671 char *targetRet = NULL;
672 char *dataRet = NULL;
673 char fstypeRet[FILESYSTEM_TYPE_MAX + 1] = {0};
674
675 if (!IsCapPermit(CAP_FS_MOUNT)) {
676 return -EPERM;
677 }
678
679 if (target != NULL) {
680 ret = UserPathCopy(target, &targetRet);
681 if (ret != 0) {
682 goto OUT;
683 }
684 }
685
686 if (filesystemtype != NULL) {
687 ret = LOS_StrncpyFromUser(fstypeRet, filesystemtype, FILESYSTEM_TYPE_MAX + 1);
688 if (ret < 0) {
689 goto OUT;
690 } else if (ret > FILESYSTEM_TYPE_MAX) {
691 ret = -ENODEV;
692 goto OUT;
693 }
694
695 if (strcmp(fstypeRet, "ramfs") && (source != NULL)) {
696 ret = UserPathCopy(source, &sourceRet);
697 if (ret != 0) {
698 goto OUT;
699 }
700 }
701#ifdef LOSCFG_FS_NFS
702 if (strcmp(fstypeRet, "nfs") == 0) {
703 ret = NfsMount(sourceRet, targetRet, 0, 0);
704 goto OUT;
705 }
706#endif
707 }
708
709 if (data != NULL) {
710 ret = UserPathCopy(data, &dataRet);
711 if (ret != 0) {
712 goto OUT;
713 }
714 }
715
716 ret = mount(sourceRet, targetRet, (filesystemtype ? fstypeRet : NULL), mountflags, dataRet);
717 if (ret < 0) {
718 ret = -get_errno();
719 }
720
721OUT:
722 if (sourceRet != NULL) {
723 (void)LOS_MemFree(OS_SYS_MEM_ADDR, sourceRet);
724 }
725 if (targetRet != NULL) {
726 (void)LOS_MemFree(OS_SYS_MEM_ADDR, targetRet);
727 }
728 if (dataRet != NULL) {
729 (void)LOS_MemFree(OS_SYS_MEM_ADDR, dataRet);
730 }
731 return ret;
732}
static int NfsMount(const char *serverIpAndPath, const char *mountPath, unsigned int uid, unsigned int gid)
Definition: fs_syscall.c:637
函数调用图:

◆ SysMprotect()

int SysMprotect ( void vaddr,
size_t  len,
int  prot 
)

修改访问权限

参数
addr
返回
void*

在文件 vm_syscall.c100 行定义.

101{
102 return LOS_DoMprotect((uintptr_t)vaddr, len, (unsigned long)prot);
103}
INT32 LOS_DoMprotect(VADDR_T vaddr, size_t len, unsigned long prot)
修改内存段的访问权限
函数调用图:

◆ SysMqClose()

int SysMqClose ( mqd_t  personal)

关闭一个消息队列

在文件 ipc_syscall.c106 行定义.

107{
108 int ret;
109 int ufd = (INTPTR)personal;
110
111 MQUEUE_FD_U2K(personal);
112 ret = mq_close(personal);
113 if (ret < 0) {
114 return -get_errno();
115 }
116 FreeProcessFd(ufd);
117 return ret;
118}
int mq_close(mqd_t personal)
Definition: mqueue.c:550
signed long INTPTR
Definition: los_typedef.h:69
函数调用图:

◆ SysMqGetSetAttr()

int SysMqGetSetAttr ( mqd_t  mqd,
const struct mq_attr new,
struct mq_attr old 
)

封装posix的标准接口,获取和设置消息队列的属性

参数
mqd
new判断是否是获取还是设置功能,new==null 获取 否则为设置
old
返回
int

在文件 ipc_syscall.c138 行定义.

139{
140 int ret;
141 struct mq_attr knew, kold;
142
143 if (new != NULL) {
144 ret = LOS_ArchCopyFromUser(&knew, new, sizeof(struct mq_attr));
145 if (ret != 0) {
146 return -EFAULT;
147 }
148 }
149 MQUEUE_FD_U2K(mqd);
150 ret = mq_getsetattr(mqd, new ? &knew : NULL, old ? &kold : NULL);
151 if (ret < 0) {
152 return -get_errno();
153 }
154 if (old != NULL) {
155 ret = LOS_ArchCopyToUser(old, &kold, sizeof(struct mq_attr));
156 if (ret != 0) {
157 return -EFAULT;
158 }
159 }
160 return ret;
161}
int mq_getsetattr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr *MqOldAttr)
Definition: mqueue.c:648
函数调用图:

◆ SysMqNotify()

int SysMqNotify ( mqd_t  personal,
const struct sigevent *  sigev 
)

在文件 ipc_syscall.c119 行定义.

120{
121 int ret;
122
123 MQUEUE_FD_U2K(personal);
124 ret = OsMqNotify(personal, sigev);
125 if (ret < 0) {
126 return -get_errno();
127 }
128 return ret;
129}
int OsMqNotify(mqd_t personal, const struct sigevent *sigev)
Definition: mqueue.c:891
函数调用图:

◆ SysMqOpen()

mqd_t SysMqOpen ( const char *  mqName,
int  openFlag,
mode_t  mode,
struct mq_attr attr 
)

打开一个消息队列,由posix接口封装

   IPC(Inter-Process Communication,进程间通信)
   每个进程各自有不同的用户地址空间,进程之间地址保护,相互隔离,任何一个进程的信息在另一个进程中都看不到,
   所以进程之间要交换数据必须通过内核,在内核中开辟一块缓冲区,进程A把数据从用户空间拷到内核缓冲区,
   进程B再从内核缓冲区把数据读走,

   IPC实现方式之消息队列:
   消息队列特点总结:
   (1)消息队列是消息的链表,具有特定的格式,存放在内存中并由消息队列标识符标识.
   (2)消息队列允许一个或多个进程向它写入与读取消息.
   (3)管道和消息队列的通信数据都是先进先出的原则。
   (4)消息队列可以实现消息的随机查询,消息不一定要以先进先出的次序读取,也可以按消息的类型读取.比FIFO更有优势。
   (5)消息队列克服了信号承载信息量少,管道只能承载无格式字节流以及缓冲区大小受限等缺点。
   (6)目前主要有两种类型的消息队列:POSIX消息队列以及System V消息队列,System V消息队列是随内核持续的,
       只有在内核重起或者人工删除时,该消息队列才会被删除。
       
   鸿蒙liteos 支持POSIX消息队列并加入了一种自研的消息队列 liteipc,此处重点讲 posix消息队列
* 
参数
mqName
openFlag
mode
attr
返回
mqd_t

在文件 ipc_syscall.c87 行定义.

88{
89 mqd_t ret;
90 int retValue;
91 char kMqName[PATH_MAX + 1] = { 0 };
92
93 retValue = LOS_StrncpyFromUser(kMqName, mqName, PATH_MAX);
94 if (retValue < 0) {
95 return retValue;
96 }
97 ret = mq_open(kMqName, openFlag, mode, attr);//posix ,一个消息队列可以有多个进程向它读写消息
98 if (ret == -1) {
99 return (mqd_t)-get_errno();
100 }
101 /* SysFd to procFd */
102 MQUEUE_FD_K2U(ret);
103 return ret;
104}
mqd_t mq_open(const char *mqName, int openFlag,...)
Definition: mqueue.c:486
UINTPTR mqd_t
Definition: mqueue.h:127
函数调用图:

◆ SysMqSend()

int SysMqSend ( mqd_t  personal,
const char *  msgPtr,
size_t  msgLen,
unsigned int  msgPrio 
)

◆ SysMqTimedReceive()

ssize_t SysMqTimedReceive ( mqd_t  personal,
char *  msg,
size_t  msgLen,
unsigned int msgPrio,
const struct timespec *  absTimeout 
)

定时接收消息,任务将被阻塞,等待被唤醒读取

在文件 ipc_syscall.c230 行定义.

232{
233 int ret, receiveLen;
234 struct timespec timeout;
235 char *msgIntr = NULL;
236 unsigned int kMsgPrio;
237
238 if (absTimeout != NULL) {
239 ret = LOS_ArchCopyFromUser(&timeout, absTimeout, sizeof(struct timespec));
240 if (ret != 0) {
241 return -EFAULT;
242 }
243 }
244 if (msgLen == 0) {
245 return -EINVAL;
246 }
247 msgIntr = (char *)malloc(msgLen);
248 if (msgIntr == NULL) {
249 return -ENOMEM;
250 }
251 MQUEUE_FD_U2K(personal);
252 receiveLen = mq_timedreceive(personal, msgIntr, msgLen, &kMsgPrio, absTimeout ? &timeout : NULL);//posix 接口的实现
253 if (receiveLen < 0) {
254 free(msgIntr);
255 return -get_errno();
256 }
257
258 if (msgPrio != NULL) {
259 ret = LOS_ArchCopyToUser(msgPrio, &kMsgPrio, sizeof(unsigned int));
260 if (ret != 0) {
261 free(msgIntr);
262 return -EFAULT;
263 }
264 }
265
266 ret = LOS_ArchCopyToUser(msg, msgIntr, receiveLen);
267 free(msgIntr);
268 if (ret != 0) {
269 return -EFAULT;
270 }
271 return receiveLen;
272}
ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *msgPrio, const struct timespec *absTimeout)
Definition: mqueue.c:801
void * malloc(size_t size)
动态分配内存块大小
Definition: malloc.c:81
函数调用图:

◆ SysMqTimedSend()

int SysMqTimedSend ( mqd_t  personal,
const char *  msg,
size_t  msgLen,
unsigned int  msgPrio,
const struct timespec *  absTimeout 
)

定时时间发送消息,任务将被阻塞,等待被唤醒写入消息

在文件 ipc_syscall.c195 行定义.

197{
198 int ret;
199 struct timespec timeout;
200 char *msgIntr = NULL;
201
202 if (absTimeout != NULL) {
203 ret = LOS_ArchCopyFromUser(&timeout, absTimeout, sizeof(struct timespec));
204 if (ret != 0) {
205 return -EFAULT;
206 }
207 }
208 if (msgLen == 0) {
209 return -EINVAL;
210 }
211 msgIntr = (char *)malloc(msgLen);
212 if (msgIntr == NULL) {
213 return -ENOMEM;
214 }
215 ret = LOS_ArchCopyFromUser(msgIntr, msg, msgLen);
216 if (ret != 0) {
217 free(msgIntr);
218 return -EFAULT;
219 }
220 MQUEUE_FD_U2K(personal);
221 ret = mq_timedsend(personal, msgIntr, msgLen, msgPrio, absTimeout ? &timeout : NULL);//posix 接口的实现
222 free(msgIntr);
223 if (ret < 0) {
224 return -get_errno();
225 }
226 return ret;
227}
int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int msgPrio, const struct timespec *absTimeout)
Definition: mqueue.c:759
函数调用图:

◆ SysMqUnlink()

int SysMqUnlink ( const char *  mqName)
   从内核中删除名为mqName的消息队列
   如果该函数被调用了,但是仍然有进程已经打开了这个消息队列,那么这个消息队列
   的销毁会被推迟到所有的引用都被关闭时执行.并且函数 mq_unlink() 不需要阻塞
   到所有的引用都被关闭为止,它会立即返回.函数 mq_unlink()调用成功后, 如果在
   随后调用 mq_open() 时重用这个消息队列名字,效果就像这个名字的消息队列不存在,
   如果没有设置O_CREAT标志,函数mq_open() 会返回失败,否则会创建一个新的消息队列.
* 
参数
mqName
返回
int

在文件 ipc_syscall.c176 行定义.

177{
178 int ret;
179 int retValue;
180 char kMqName[PATH_MAX + 1] = { 0 };
181
182 retValue = LOS_StrncpyFromUser(kMqName, mqName, PATH_MAX);
183 if (retValue < 0) {
184 return retValue;
185 }
186
187 ret = mq_unlink(kMqName);
188 if (ret < 0) {
189 return -get_errno();
190 }
191 return ret;
192}
int mq_unlink(const char *mqName)
Definition: mqueue.c:656
函数调用图:

◆ SysMremap()

void * SysMremap ( void oldAddr,
size_t  oldLen,
size_t  newLen,
int  flags,
void newAddr 
)
参数
oldAddr需要扩大(或缩小)的内存段的原始地址。注意old_address必须是页对齐。
oldLen内存段的原始大小。
newLen新内存段的大小。
flags如果没有足够的空间在当前位置展开映射,则返回失败
MREMAP_MAYMOVE:允许内核将映射重定位到新的虚拟地址。
MREMAP_FIXED:mremap()接受第五个参数,void *new_address,该参数指定映射地址必须页对齐;
newAddr在new_address和new_size指定的地址范围内的所有先前映射都被解除映射。如果指定了MREMAP_FIXED,
还必须指定MREMAP_MAYMOVE。
返回
void* 成功返回:重新映射后的虚拟内存地址
失败返回:((void *)-1)。

在文件 vm_syscall.c90 行定义.

91{
92 return (void *)LOS_DoMremap((vaddr_t)oldAddr, oldLen, newLen, flags, (vaddr_t)newAddr);
93}
unsigned long vaddr_t
Definition: los_typedef.h:206
VADDR_T LOS_DoMremap(VADDR_T oldAddress, size_t oldSize, size_t newSize, int flags, VADDR_T newAddr)
重新映射虚拟内存地址。
函数调用图:

◆ SysMunmap()

int SysMunmap ( void addr,
size_t  size 
)

释放虚拟内存

参数
addr虚拟内存起始位置
size内存段的大小
返回
int 成功返回0 失败返回-1。

在文件 vm_syscall.c72 行定义.

73{
74 return LOS_UnMMap((uintptr_t)addr, size);
75}
STATUS_T LOS_UnMMap(VADDR_T addr, size_t size)
解除映射关系
函数调用图:

◆ SysNanoSleep()

int SysNanoSleep ( const struct timespec *  rqtp,
struct timespec *  rmtp 
)

在文件 time_syscall.c355 行定义.

356{
357 int ret;
358 struct timespec srqtp;
359 struct timespec srmtp;
360
361 if (!rqtp || LOS_ArchCopyFromUser(&srqtp, rqtp, sizeof(struct timespec))) {
362 errno = EFAULT;
363 return -EFAULT;
364 }
365
366 if (rmtp && LOS_ArchCopyFromUser(&srmtp, rmtp, sizeof(struct timespec))) {
367 errno = EFAULT;
368 return -EFAULT;
369 }
370
371 ret = nanosleep(&srqtp, rmtp ? &srmtp : NULL);
372 if (ret < 0) {
373 return -get_errno();
374 }
375
376 if (rmtp && LOS_ArchCopyToUser(rmtp, &srmtp, sizeof(struct timespec))) {
377 errno = EFAULT;
378 return -EFAULT;
379 }
380
381 return ret;
382}
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
Definition: time.c:1068
函数调用图:

◆ SysOpen()

int SysOpen ( const char *  path,
int  oflags,
  ... 
)

系统调用|打开文件, 正常情况下返回进程的FD值

在文件 fs_syscall.c294 行定义.

295{
296 int ret;
297 int procFd;
298 mode_t mode = DEFAULT_FILE_MODE; /* 0666: File read-write properties. */
299 char *pathRet = NULL;
300
301 if (path != NULL) {
302 ret = UserPathCopy(path, &pathRet);
303 if (ret != 0) {
304 return ret;
305 }
306 }
307
308 procFd = AllocProcessFd();//分配进程描述符
309 if (procFd < 0) {
310 ret = -EMFILE;
311 goto ERROUT;
312 }
313
314 if (oflags & O_CLOEXEC) {
315 SetCloexecFlag(procFd);
316 }
317
318 if ((unsigned int)oflags & O_DIRECTORY) {//目录标签
319 ret = do_opendir(pathRet, oflags);//打开目录
320 } else {
321
322#ifdef LOSCFG_FILE_MODE //文件权限开关
323 va_list ap;
324
325 va_start(ap, oflags);
326 mode = va_arg(ap, int);//可变参数读取mode值
327 va_end(ap);
328#endif
329//当fd参数的值是AT_FDCWD,并且path参数是一个相对路径名,fstatat会计算相对于当前目录的path参数。
330//如果path是一个绝对路径,fd参数就会被忽略
331 ret = do_open(AT_FDCWD, pathRet, oflags, mode);//打开文件,返回系统描述符
332 }
333
334 if (ret < 0) {
335 ret = -get_errno();
336 goto ERROUT;
337 }
338
339 AssociateSystemFd(procFd, ret);//进程<->系统描述符 关联/绑定
340 if (pathRet != NULL) {
341 LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
342 }
343 return procFd;//返回进程描述符
344
345ERROUT:
346 if (pathRet != NULL) {
347 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
348 }
349 if (procFd >= 0) {
350 FreeProcessFd(procFd);
351 }
352 return ret;
353}
void SetCloexecFlag(int procFd)
Definition: vfs_cloexec.c:62
int do_open(int dirfd, const char *path, int oflags, mode_t mode)
int do_opendir(const char *path, int oflags)
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 ARG_NUM_3 void ARG_NUM_1 ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_5 ARG_NUM_3 ARG_NUM_3 ARG_NUM_4 ARG_NUM_1 ARG_NUM_1 ARG_NUM_3 ARG_NUM_2 mode_t
函数调用图:

◆ SysOpenat()

int SysOpenat ( int  dirfd,
const char *  path,
int  oflags,
  ... 
)

在文件 fs_syscall.c1781 行定义.

1782{
1783 int ret;
1784 int procFd;
1785 char *pathRet = NULL;
1786 mode_t mode;
1787#ifdef LOSCFG_FILE_MODE
1788 va_list ap;
1789
1790 va_start(ap, oflags);
1791 mode = va_arg(ap, int);
1792 va_end(ap);
1793#else
1794 mode = 0666; /* 0666: File read-write properties. */
1795#endif
1796
1797 if (path != NULL) {
1798 ret = UserPathCopy(path, &pathRet);
1799 if (ret != 0) {
1800 return ret;
1801 }
1802 }
1803
1804 procFd = AllocProcessFd();
1805 if (procFd < 0) {
1806 ret = -EMFILE;
1807 goto ERROUT;
1808 }
1809
1810 if (oflags & O_CLOEXEC) {
1811 SetCloexecFlag(procFd);
1812 }
1813
1814 if (dirfd != AT_FDCWD) {
1815 /* Process fd convert to system global fd */
1816 dirfd = GetAssociatedSystemFd(dirfd);
1817 }
1818
1819 ret = do_open(dirfd, (path ? pathRet : NULL), oflags, mode);
1820 if (ret < 0) {
1821 ret = -get_errno();
1822 goto ERROUT;
1823 }
1824
1825 AssociateSystemFd(procFd, ret);
1826 if (pathRet != NULL) {
1827 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
1828 }
1829 return procFd;
1830
1831ERROUT:
1832 if (pathRet != NULL) {
1833 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
1834 }
1835 if (procFd >= 0) {
1836 FreeProcessFd(procFd);
1837 }
1838 return ret;
1839}
函数调用图:

◆ SysPause()

int SysPause ( void  )

系统调用之暂停任务

在文件 syscall_lookup.h143 行定义.

函数调用图:

◆ SysPipe()

int SysPipe ( int  pipefd[2])
   管道是一种最基本的IPC机制,作用于有血缘关系的进程之间,完成数据传递。
   调用pipe系统函数即可创建一个管道。有如下特质:

   1. 其本质是一个伪文件(实为内核缓冲区)
   2. 由两个文件描述符引用,一个表示读端,一个表示写端。
   3. 规定数据从管道的写端流入管道,从读端流出。

   管道的原理: 管道实为内核使用环形队列机制,借助内核缓冲区(4k)实现。
   管道的局限性:
       ① 数据自己读不能自己写。
       ② 数据一旦被读走,便不在管道中存在,不可反复读取。
       ③ 由于管道采用半双工通信方式。因此,数据只能在一个方向上流动。
       ④ 只能在有公共祖先的进程间使用管道。
   常见的通信方式有,单工通信、半双工通信、全双工通信。
* 
参数
pipefd
返回
int

在文件 fs_syscall.c995 行定义.

996{
997 int ret;
998 int pipeFdIntr[2] = {0}; /* 2 : pipe fds for read and write */
999
1000 int procFd0 = AllocProcessFd();//读端管道,像 stdin对应标准输入
1001 if (procFd0 < 0) {
1002 return -EMFILE;
1003 }
1004 int procFd1 = AllocProcessFd();//写端管道,像 stdout对应标准输出
1005 if (procFd1 < 0) {
1006 FreeProcessFd(procFd0);
1007 return -EMFILE;
1008 }
1009
1010 ret = pipe(pipeFdIntr);//创建管道
1011 if (ret < 0) {
1012 FreeProcessFd(procFd0);
1013 FreeProcessFd(procFd1);
1014 return -get_errno();
1015 }
1016 int sysPipeFd0 = pipeFdIntr[0];
1017 int sysPipeFd1 = pipeFdIntr[1];
1018
1019 AssociateSystemFd(procFd0, sysPipeFd0);//进程FD和系统FD绑定
1020 AssociateSystemFd(procFd1, sysPipeFd1);
1021
1022 pipeFdIntr[0] = procFd0;
1023 pipeFdIntr[1] = procFd1;
1024
1025 ret = LOS_ArchCopyToUser(pipefd, pipeFdIntr, sizeof(pipeFdIntr));//参数都走两个进程FD
1026 if (ret != 0) {
1027 FreeProcessFd(procFd0);
1028 FreeProcessFd(procFd1);
1029 close(sysPipeFd0);
1030 close(sysPipeFd1);
1031 return -EFAULT;
1032 }
1033 return ret;
1034}
函数调用图:

◆ SysPoll()

int SysPoll ( struct pollfd *  fds,
nfds_t  nfds,
int  timeout 
)

SysPoll I/O多路转换

参数
fdsfds是一个struct pollfd类型的数组,用于存放需要检测其状态的socket描述符,并且调用poll函数之后fds数组不会被清空; 一个pollfd结构体表示一个被监视的文件描述符,通过传递fds指示 poll() 监视多个文件描述符。
nfds记录数组fds中描述符的总数量。
timeout指定等待的毫秒数,无论 I/O 是否准备好,poll() 都会返回,和select函数是类似的。
返回
函数返回fds集合中就绪的读、写,或出错的描述符数量,返回0表示超时,返回-1表示出错; poll改变了文件描述符集合的描述方式,使用了pollfd结构而不是select的fd_set结构,使得poll支持的文件描述符集合限制远大于select的1024。 这也是和select不同的地方。
参见

在文件 fs_syscall.c1552 行定义.

1553{
1554 int ret;
1555 struct pollfd *kfds = NULL;
1556
1557 if ((nfds >= MAX_POLL_NFDS) || (nfds == 0) || (fds == NULL)) {
1558 return -EINVAL;
1559 }
1560
1561 kfds = (struct pollfd *)malloc(sizeof(struct pollfd) * nfds);
1562 if (kfds != NULL) {
1563 if (LOS_ArchCopyFromUser(kfds, fds, sizeof(struct pollfd) * nfds) != 0) {
1564 ret = -EFAULT;
1565 goto OUT_KFD;
1566 }
1567 }
1568
1569 int *pollFds = NULL;
1570 ret = PollfdToSystem(kfds, nfds, &pollFds);
1571 if (ret < 0) {
1572 ret = -get_errno();
1573 goto OUT_KFD;
1574 }
1575
1576 ret = poll(kfds, nfds, timeout);
1577 if (ret < 0) {
1578 ret = -get_errno();
1579 goto OUT;
1580 }
1581
1582 if (kfds != NULL) {
1583 RestorePollfd(kfds, nfds, pollFds);
1584 if (LOS_ArchCopyToUser(fds, kfds, sizeof(struct pollfd) * nfds) != 0) {
1585 ret = -EFAULT;
1586 goto OUT;
1587 }
1588 }
1589
1590OUT:
1591 free(pollFds);
1592OUT_KFD:
1593 free(kfds);
1594 return ret;
1595}
static int PollfdToSystem(struct pollfd *fds, nfds_t nfds, int **pollFdsBak)
Definition: fs_syscall.c:180
static void RestorePollfd(struct pollfd *fds, nfds_t nfds, const int *pollFds)
Definition: fs_syscall.c:208
函数调用图:
这是这个函数的调用关系图:

◆ SysPpoll()

int SysPpoll ( struct pollfd *  fds,
nfds_t  nfds,
const struct timespec *  tmo_p,
const sigset_t *  sigmask,
int  nsig 
)

在文件 fs_syscall.c2648 行定义.

2649{
2650 int timeout, retVal;
2651 sigset_t_l origMask = {0};
2652 sigset_t_l set = {0};
2653
2654 CHECK_ASPACE(tmo_p, sizeof(struct timespec));
2655 CPY_FROM_USER(tmo_p);
2656
2657 if (tmo_p != NULL) {
2658 timeout = tmo_p->tv_sec * OS_SYS_US_PER_MS + tmo_p->tv_nsec / OS_SYS_NS_PER_MS;
2659 if (timeout < 0) {
2660 return -EINVAL;
2661 }
2662 } else {
2663 timeout = -1;
2664 }
2665
2666 if (sigMask != NULL) {
2667 retVal = LOS_ArchCopyFromUser(&set, sigMask, sizeof(sigset_t));
2668 if (retVal != 0) {
2669 return -EFAULT;
2670 }
2671 (VOID)OsSigprocMask(SIG_SETMASK, &set, &origMask);
2672 } else {
2673 (VOID)OsSigprocMask(SIG_SETMASK, NULL, &origMask);
2674 }
2675
2676 retVal = SysPoll(fds, nfds, timeout);
2677 (VOID)OsSigprocMask(SIG_SETMASK, &origMask, NULL);
2678
2679 return retVal;
2680}
int SysPoll(struct pollfd *fds, nfds_t nfds, int timeout)
SysPoll I/O多路转换
Definition: fs_syscall.c:1552
函数调用图:

◆ SysPrctl()

int SysPrctl ( int  option,
  ... 
)

对进程进行特定操作

在文件 fs_syscall.c1597 行定义.

1598{
1599 unsigned long name;
1600 va_list ap;
1601 errno_t err;
1602
1603 va_start(ap, option);
1604 if (option != PR_SET_NAME) {
1605 PRINT_ERR("%s: %d, no support option : 0x%x\n", __FUNCTION__, __LINE__, option);
1606 err = EOPNOTSUPP;
1607 goto ERROR;
1608 }
1609
1610 name = va_arg(ap, unsigned long);
1611 if (!LOS_IsUserAddress(name)) {
1612 err = EFAULT;
1613 goto ERROR;
1614 }
1615
1616 err = OsSetTaskName(OsCurrTaskGet(), (const char *)(uintptr_t)name, TRUE);
1617 if (err != LOS_OK) {
1618 goto ERROR;
1619 }
1620
1621 va_end(ap);
1622 return ENOERR;
1623
1624ERROR:
1625 va_end(ap);
1626 return -err;
1627}
LITE_OS_SEC_TEXT INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName)
Definition: los_task.c:1337
STATIC INLINE BOOL LOS_IsUserAddress(VADDR_T vaddr)
虚拟地址是否在用户空间
Definition: los_vm_map.h:275
函数调用图:

◆ SysPread64()

ssize_t SysPread64 ( int  fd,
void buf,
size_t  nbytes,
off64_t  offset 
)

对进程进行特定操作

在文件 fs_syscall.c1629 行定义.

1630{
1631 int ret, retVal;
1632 char *bufRet = NULL;
1633
1634 /* Process fd convert to system global fd */
1635 fd = GetAssociatedSystemFd(fd);
1636
1637 if (nbytes == 0) {
1638 ret = pread64(fd, buf, nbytes, offset);
1639 if (ret < 0) {
1640 return -get_errno();
1641 } else {
1642 return ret;
1643 }
1644 }
1645
1646 bufRet = (char *)LOS_MemAlloc(OS_SYS_MEM_ADDR, nbytes);
1647 if (bufRet == NULL) {
1648 return -ENOMEM;
1649 }
1650
1651 ret = pread64(fd, (buf ? bufRet : NULL), nbytes, offset);
1652 if (ret < 0) {
1653 (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
1654 return -get_errno();
1655 }
1656
1657 retVal = LOS_ArchCopyToUser(buf, bufRet, ret);
1658 if (retVal != 0) {
1659 (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
1660 return -EFAULT;
1661 }
1662
1663 (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
1664 return ret;
1665}
函数调用图:

◆ SysPreadv()

ssize_t SysPreadv ( int  fd,
const struct iovec *  iov,
int  iovcnt,
long  loffset,
long  hoffset 
)

在文件 fs_syscall.c2095 行定义.

2096{
2097 off_t offsetflag;
2098 offsetflag = (off_t)((unsigned long long)loffset | (((unsigned long long)hoffset) << HIGH_SHIFT_BIT));
2099
2100 int ret;
2101 int valid_iovcnt = -1;
2102 struct iovec *iovRet = NULL;
2103
2104 /* Process fd convert to system global fd */
2105 fd = GetAssociatedSystemFd(fd);
2106 if ((iov == NULL) || (iovcnt < 0) || (iovcnt > IOV_MAX)) {
2107 return -EINVAL;
2108 }
2109
2110 if (iovcnt == 0) {
2111 return 0;
2112 }
2113
2114 ret = UserIovCopy(&iovRet, iov, iovcnt, &valid_iovcnt);
2115 if (ret != 0) {
2116 return ret;
2117 }
2118
2119 if (valid_iovcnt <= 0) {
2120 ret = -EFAULT;
2121 goto OUT_FREE;
2122 }
2123
2124 ret = preadv(fd, iovRet, valid_iovcnt, offsetflag);
2125 if (ret < 0) {
2126 ret = -get_errno();
2127 }
2128
2129OUT_FREE:
2130 (void)(void)LOS_MemFree(OS_SYS_MEM_ADDR, iovRet);
2131 return ret;
2132}
static int UserIovCopy(struct iovec **iovBuf, const struct iovec *iov, const int iovcnt, int *valid_iovcnt)
Definition: fs_syscall.c:152
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 ARG_NUM_3 void ARG_NUM_1 ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_5 ARG_NUM_3 ARG_NUM_3 ARG_NUM_4 ARG_NUM_1 ARG_NUM_1 ARG_NUM_3 ARG_NUM_2 ARG_NUM_1 ARG_NUM_4 ARG_NUM_4 ARG_NUM_5 ARG_NUM_3 ARG_NUM_2 void ARG_NUM_6 unsigned ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_3 ARG_NUM_3 ARG_NUM_2 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_1 char ARG_NUM_0 ARG_NUM_4 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_2 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_6 ARG_NUM_6 ARG_NUM_5 ARG_NUM_3 void ARG_NUM_3 ARG_NUM_3 ARG_NUM_5 ARG_NUM_1 unsigned ARG_NUM_3 long
ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
Definition: vfs_preadv.c:47
函数调用图:

◆ SysPselect6()

int SysPselect6 ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds,
const struct timespec *  timeout,
const long  data[2] 
)

在文件 fs_syscall.c2682 行定义.

2684{
2685 int ret;
2686 int retVal;
2687 sigset_t_l origMask;
2688 sigset_t_l setl;
2689
2690 CHECK_ASPACE(readfds, sizeof(fd_set));
2691 CHECK_ASPACE(writefds, sizeof(fd_set));
2692 CHECK_ASPACE(exceptfds, sizeof(fd_set));
2693 CHECK_ASPACE(timeout, sizeof(struct timeval));
2694
2695 CPY_FROM_USER(readfds);
2696 CPY_FROM_USER(writefds);
2697 CPY_FROM_USER(exceptfds);
2698 DUP_FROM_USER(timeout, sizeof(struct timeval));
2699
2700 if (timeout != NULL) {
2701 ((struct timeval *)timeout)->tv_usec = timeout->tv_nsec / 1000; /* 1000, convert ns to us */
2702 }
2703
2704 if (data != NULL) {
2705 retVal = LOS_ArchCopyFromUser(&(setl.sig[0]), (int *)((UINTPTR)data[0]), sizeof(sigset_t));
2706 if (retVal != 0) {
2707 ret = -EFAULT;
2708 FREE_DUP(timeout);
2709 return ret;
2710 }
2711 }
2712
2713 OsSigprocMask(SIG_SETMASK, &setl, &origMask);
2714 ret = do_select(nfds, readfds, writefds, exceptfds, (struct timeval *)timeout, UserPoll);
2715 if (ret < 0) {
2716 /* do not copy parameter back to user mode if do_select failed */
2717 ret = -get_errno();
2718 FREE_DUP(timeout);
2719 return ret;
2720 }
2721 OsSigprocMask(SIG_SETMASK, &origMask, NULL);
2722
2723 CPY_TO_USER(readfds);
2724 CPY_TO_USER(writefds);
2725 CPY_TO_USER(exceptfds);
2726 FREE_DUP(timeout);
2727
2728 return ret;
2729}
static int UserPoll(struct pollfd *fds, nfds_t nfds, int timeout)
使用poll方式 实现IO多路复用的机制
Definition: fs_syscall.c:219
int do_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout, PollFun poll)
unsigned long sig[MAX_SIG_ARRAY_IN_MUSL/sizeof(unsigned long)]
Definition: los_signal.h:166
函数调用图:

◆ SysPthreadKill()

int SysPthreadKill ( pid_t  pid,
int  sig 
)

系统调用之之向进程发送信号

在文件 ipc_syscall.c307 行定义.

308{
309 return OsPthreadKill(pid, sig);
310}
int OsPthreadKill(UINT32 tid, int signo)
发送信号
Definition: los_signal.c:509
函数调用图:

◆ SysPwrite64()

ssize_t SysPwrite64 ( int  fd,
const void buf,
size_t  nbytes,
off64_t  offset 
)

在文件 fs_syscall.c1667 行定义.

1668{
1669 int ret;
1670 char *bufRet = NULL;
1671
1672 /* Process fd convert to system global fd */
1673 fd = GetAssociatedSystemFd(fd);
1674
1675 if (nbytes == 0) {
1676 ret = pwrite64(fd, buf, nbytes, offset);
1677 if (ret < 0) {
1678 return -get_errno();
1679 }
1680 return ret;
1681 }
1682
1683 bufRet = (char *)LOS_MemAlloc(OS_SYS_MEM_ADDR, nbytes);
1684 if (bufRet == NULL) {
1685 return -ENOMEM;
1686 }
1687
1688 if (buf != NULL) {
1689 ret = LOS_ArchCopyFromUser(bufRet, buf, nbytes);
1690 if (ret != 0) {
1691 (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
1692 return -EFAULT;
1693 }
1694 }
1695
1696 ret = pwrite64(fd, (buf ? bufRet : NULL), nbytes, offset);
1697 if (ret < 0) {
1698 (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
1699 return -get_errno();
1700 }
1701
1702 (void)LOS_MemFree(OS_SYS_MEM_ADDR, bufRet);
1703 return ret;
1704}
函数调用图:

◆ SysPwritev()

ssize_t SysPwritev ( int  fd,
const struct iovec *  iov,
int  iovcnt,
long  loffset,
long  hoffset 
)

在文件 fs_syscall.c2134 行定义.

2135{
2136 off_t offsetflag;
2137 offsetflag = (off_t)((unsigned long long)loffset | (((unsigned long long)hoffset) << HIGH_SHIFT_BIT));
2138 int ret;
2139 int valid_iovcnt = -1;
2140 struct iovec *iovRet = NULL;
2141
2142 /* Process fd convert to system global fd */
2143 fd = GetAssociatedSystemFd(fd);
2144 if ((iov == NULL) || (iovcnt < 0) || (iovcnt > IOV_MAX)) {
2145 return -EINVAL;
2146 }
2147
2148 if (iovcnt == 0) {
2149 return 0;
2150 }
2151
2152 ret = UserIovCopy(&iovRet, iov, iovcnt, &valid_iovcnt);
2153 if (ret != 0) {
2154 return ret;
2155 }
2156
2157 if (valid_iovcnt != iovcnt) {
2158 ret = -EFAULT;
2159 goto OUT_FREE;
2160 }
2161
2162 ret = pwritev(fd, iovRet, valid_iovcnt, offsetflag);
2163 if (ret < 0) {
2164 ret = -get_errno();
2165 }
2166
2167OUT_FREE:
2168 (void)LOS_MemFree(OS_SYS_MEM_ADDR, iovRet);
2169 return ret;
2170}
ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
Definition: vfs_pwritev.c:47
函数调用图:

◆ SysRead()

ssize_t SysRead ( int  fd,
void buf,
size_t  nbytes 
)

系统调用|读文件:从文件中读取nbytes长度的内容到buf中(用户空间)

在文件 fs_syscall.c252 行定义.

253{
254 int ret;
255
256 if (nbytes == 0) {
257 return 0;
258 }
259 //[buf,buf+nbytes]地址必须在用户空间
260 if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buf, nbytes)) {
261 return -EFAULT;
262 }
263
264 /* Process fd convert to system global fd */
265 fd = GetAssociatedSystemFd(fd);//获得关联的系统fd,因为真正的read,write是需要sysFd的
266 ret = read(fd, buf, nbytes);
267 if (ret < 0) {
268 return -get_errno();
269 }
270 return ret;
271}
函数调用图:

◆ SysReadlink()

ssize_t SysReadlink ( const char *  pathname,
char *  buf,
size_t  bufsize 
)

在文件 fs_syscall.c441 行定义.

442{
443 ssize_t ret;
444 char *pathRet = NULL;
445
446 if (bufsize == 0) {
447 return -EINVAL;
448 }
449
450 if (pathname != NULL) {
451 ret = UserPathCopy(pathname, &pathRet);
452 if (ret != 0) {
453 goto OUT;
454 }
455 }
456
457 if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buf, bufsize)) {
458 ret = -EFAULT;
459 goto OUT;
460 }
461
462 ret = readlink(pathRet, buf, bufsize);
463 if (ret < 0) {
464 ret = -get_errno();
465 }
466
467OUT:
468 if (pathRet != NULL) {
469 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
470 }
471 return ret;
472}
INT64 ssize_t
Definition: los_typedef.h:79
函数调用图:

◆ SysReadlinkat()

ssize_t SysReadlinkat ( int  dirfd,
const char *  pathname,
char *  buf,
size_t  bufsize 
)

在文件 fs_syscall.c1956 行定义.

1957{
1958 ssize_t ret;
1959 char *pathRet = NULL;
1960
1961 if (bufsize == 0) {
1962 return -EINVAL;
1963 }
1964
1965 if (pathname != NULL) {
1966 ret = UserPathCopy(pathname, &pathRet);
1967 if (ret != 0) {
1968 goto OUT;
1969 }
1970 }
1971
1972 if (dirfd != AT_FDCWD) {
1973 /* Process fd convert to system global fd */
1974 dirfd = GetAssociatedSystemFd(dirfd);
1975 }
1976
1977 if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buf, bufsize)) {
1978 ret = -EFAULT;
1979 goto OUT;
1980 }
1981
1982 ret = readlinkat(dirfd, pathRet, buf, bufsize);
1983 if (ret < 0) {
1984 ret = -get_errno();
1985 }
1986
1987OUT:
1988 if (pathRet != NULL) {
1989 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
1990 }
1991 return ret;
1992}
函数调用图:

◆ SysReadv()

ssize_t SysReadv ( int  fd,
const struct iovec *  iov,
int  iovcnt 
)

通过FD读入数据到缓冲数组中,fd为进程描述符

在文件 fs_syscall.c1464 行定义.

1465{
1466 int ret;
1467 int valid_iovcnt = -1;
1468 struct iovec *iovRet = NULL;
1469
1470 /* Process fd convert to system global fd */
1471 fd = GetAssociatedSystemFd(fd);//进程FD转成系统FD
1472 if ((iov == NULL) || (iovcnt < 0) || (iovcnt > IOV_MAX)) {
1473 return -EINVAL;
1474 }
1475
1476 if (iovcnt == 0) {
1477 return 0;
1478 }
1479
1480 ret = UserIovCopy(&iovRet, iov, iovcnt, &valid_iovcnt);
1481 if (ret != 0) {
1482 return ret;
1483 }
1484
1485 if (valid_iovcnt <= 0) {
1486 ret = -EFAULT;
1487 goto OUT;
1488 }
1489
1490 ret = vfs_readv(fd, iovRet, valid_iovcnt, NULL);
1491 if (ret < 0) {
1492 ret = -get_errno();
1493 }
1494
1495OUT:
1496 (void)LOS_MemFree(OS_SYS_MEM_ADDR, iovRet);
1497 return ret;
1498}
函数调用图:

◆ SysRealpath()

char * SysRealpath ( const char *  path,
char *  resolvedPath 
)

在文件 fs_syscall.c2264 行定义.

2265{
2266 char *pathRet = NULL;
2267 char *resolved_pathRet = NULL;
2268 char *result = NULL;
2269 int ret;
2270
2271 if (resolved_path == NULL) {
2272 return (char *)(intptr_t)-EINVAL;
2273 }
2274
2275 if (path != NULL) {
2276 ret = UserPathCopy(path, &pathRet);
2277 if (ret != 0) {
2278 result = (char *)(intptr_t)ret;
2279 goto OUT;
2280 }
2281 }
2282
2283 resolved_pathRet = realpath((path ? pathRet : NULL), NULL);
2284 if (resolved_pathRet == NULL) {
2285 result = (char *)(intptr_t)-get_errno();
2286 goto OUT;
2287 }
2288
2289 ret = LOS_ArchCopyToUser(resolved_path, resolved_pathRet, strlen(resolved_pathRet) + 1);
2290 if (ret != 0) {
2291 result = (char *)(intptr_t)-EFAULT;
2292 goto OUT;
2293 }
2294 result = resolved_path;
2295
2296OUT:
2297 if (pathRet != NULL) {
2298 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
2299 }
2300 if (resolved_pathRet != NULL) {
2301 (void)LOS_MemFree(OS_SYS_MEM_ADDR, resolved_pathRet);
2302 }
2303 return result;
2304}
char * realpath(const char *path, char *resolved_path)
Definition: vfs_other.c:651
函数调用图:

◆ SysReboot()

int SysReboot ( int  magic,
int  magic2,
int  type 
)

重启系统

在文件 misc_syscall.c90 行定义.

91{
92 (void)magic;
93 (void)magic2;
94 if (!IsCapPermit(CAP_REBOOT)) {
95 return -EPERM;
96 }
97 SystemRebootFunc rebootHook = OsGetRebootHook();
98 if ((type == RB_AUTOBOOT) && (rebootHook != NULL)) {
99 rebootHook();
100 return 0;
101 }
102 return -EFAULT;
103}
SystemRebootFunc OsGetRebootHook(VOID)
获取系统重启钩子函数
Definition: los_config.c:63
VOID(* SystemRebootFunc)(VOID)
Definition: los_config.h:475
函数调用图:

◆ SysRecv()

ssize_t SysRecv ( int  socket,
void buffer,
size_t  length,
int  flags 
)

在文件 net_syscall.c273 行定义.

274{
275 int ret;
276
277 SOCKET_U2K(socket);
278 CHECK_ASPACE(buffer, length);
279
280 DUP_FROM_USER_NOCOPY(buffer, length);
281
282 if (buffer == NULL) {
283 set_errno(EFAULT);
284 ret = -1;
285 } else {
286 ret = recv(socket, buffer, length, flags);
287 }
288 if (ret == -1) {
289 FREE_DUP(buffer);
290 return -get_errno();
291 }
292
293 DUP_TO_USER(buffer, ret, FREE_DUP(buffer));
294 FREE_DUP(buffer);
295 return ret;
296}
ssize_t recv(int s, void *mem, size_t len, int flags)
Definition: socket.c:234
函数调用图:

◆ SysRecvFrom()

ssize_t SysRecvFrom ( int  socket,
void buffer,
size_t  length,
int  flags,
struct sockaddr *  address,
socklen_t *  addressLen 
)

在文件 net_syscall.c298 行定义.

301{
302 int ret;
303
304 SOCKET_U2K(socket);
305 CHECK_ASPACE(buffer, length);
306
307 CHECK_ASPACE(addressLen, sizeof(socklen_t));
308 CPY_FROM_USER(addressLen);
309
310 CHECK_ASPACE(address, LEN(addressLen));
311 DUP_FROM_USER_NOCOPY(address, LEN(addressLen));
312
313 DUP_FROM_USER_NOCOPY(buffer, length, FREE_DUP(address));
314
315 if (buffer == NULL || (address != NULL && addressLen == NULL)) {
316 set_errno(EFAULT);
317 ret = -1;
318 } else {
319 ret = recvfrom(socket, buffer, length, flags, address, addressLen);
320 }
321 if (ret == -1) {
322 FREE_DUP(address);
323 FREE_DUP(buffer);
324 return -get_errno();
325 }
326
327 CPY_TO_USER(addressLen, FREE_DUP(address); FREE_DUP(buffer));
328 DUP_TO_USER(address, LEN(addressLen), FREE_DUP(address); FREE_DUP(buffer));
329 DUP_TO_USER(buffer, ret, FREE_DUP(address); FREE_DUP(buffer));
330 FREE_DUP(address);
331 FREE_DUP(buffer);
332 return ret;
333}
ssize_t recvfrom(int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
区别是返回源地址,意思是这些数据是从哪个地址过来的
Definition: socket.c:240
函数调用图:

◆ SysRecvMsg()

ssize_t SysRecvMsg ( int  s,
struct msghdr *  message,
int  flags 
)

在文件 net_syscall.c444 行定义.

445{
446 int ret;
447
448 SOCKET_U2K(s);
449
450 CHECK_ASPACE(message, sizeof(struct msghdr));
451 CPY_FROM_NONCONST_USER(message);
452
453 if (message && message->msg_iovlen > IOV_MAX) {
454 set_errno(EMSGSIZE);
455 return -get_errno();
456 }
457
458 CHECK_FIELD_ASPACE(message, msg_name, message->msg_namelen);
459 CHECK_FIELD_ASPACE(message, msg_iov, message->msg_iovlen * sizeof(struct iovec));
460 CHECK_FIELD_ASPACE(message, msg_control, message->msg_controllen);
461
462 DUP_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen * sizeof(struct iovec));
463 CHECK_ARRAY_FIELD_ASPACE(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
464 FREE_DUP_FIELD(message, msg_iov));
465 DUP_FIELD_FROM_USER_NOCOPY(message, msg_name, message->msg_namelen,
466 FREE_DUP_FIELD(message, msg_iov));
467 DUP_FIELD_FROM_USER_NOCOPY(message, msg_control, message->msg_controllen,
468 FREE_DUP_FIELD(message, msg_iov);
469 FREE_DUP_FIELD(message, msg_name));
470 DUP_ARRAY_FIELD_FROM_USER_NOCOPY(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
471 FREE_DUP_FIELD(message, msg_control);
472 FREE_DUP_FIELD(message, msg_iov);
473 FREE_DUP_FIELD(message, msg_name));
474
475 if (message == NULL) {
476 set_errno(EFAULT);
477 ret = -1;
478 } else {
479 ret = recvmsg(s, message, flags);
480 }
481 if (ret == -1) {
482 goto OUT;
483 }
484
485 CPY_TO_USER(message, ret = -1; goto OUT);
486 DUP_FIELD_TO_USER(message, msg_control, message->msg_controllen, ret = -1; goto OUT);
487 DUP_FIELD_TO_USER(message, msg_iov, message->msg_iovlen * sizeof(struct iovec), ret = -1; goto OUT);
488 DUP_FIELD_TO_USER(message, msg_name, message->msg_namelen, ret = -1; goto OUT);
489 DUP_ARRAY_FIELD_TO_USER(message, msg_iov, message->msg_iovlen, iov_base, iov_len, ret = -1; goto OUT);
490OUT:
491 FREE_DUP_ARRAY_FIELD(message, msg_iov, message->msg_iovlen, iov_base);
492 FREE_DUP_FIELD(message, msg_control);
493 FREE_DUP_FIELD(message, msg_iov);
494 FREE_DUP_FIELD(message, msg_name);
495 return (ret == -1) ? -get_errno() : ret;
496}
ssize_t recvmsg(int s, struct msghdr *message, int flags)
只是数据的格式的不同
Definition: socket.c:247
函数调用图:

◆ SysRename()

int SysRename ( const char *  oldpath,
const char *  newpath 
)

重命名文件

在文件 fs_syscall.c787 行定义.

788{
789 int ret;
790 char *pathOldRet = NULL;
791 char *pathNewRet = NULL;
792
793 if (oldpath != NULL) {
794 ret = UserPathCopy(oldpath, &pathOldRet);
795 if (ret != 0) {
796 goto OUT;
797 }
798 }
799
800 if (newpath != NULL) {
801 ret = UserPathCopy(newpath, &pathNewRet);
802 if (ret != 0) {
803 goto OUT;
804 }
805 }
806
807 ret = do_rename(AT_FDCWD, (oldpath ? pathOldRet : NULL), AT_FDCWD,
808 (newpath ? pathNewRet : NULL));
809 if (ret < 0) {
810 ret = -get_errno();
811 }
812
813OUT:
814 if (pathOldRet != NULL) {
815 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathOldRet);
816 }
817 if (pathNewRet != NULL) {
818 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathNewRet);
819 }
820 return ret;
821}
int do_rename(int oldfd, const char *oldpath, int newfd, const char *newpath)
函数调用图:

◆ SysRenameat()

int SysRenameat ( int  oldfd,
const char *  oldpath,
int  newdfd,
const char *  newpath 
)

在文件 fs_syscall.c2023 行定义.

2024{
2025 int ret;
2026 char *pathOldRet = NULL;
2027 char *pathNewRet = NULL;
2028
2029 if (oldpath != NULL) {
2030 ret = UserPathCopy(oldpath, &pathOldRet);
2031 if (ret != 0) {
2032 goto OUT;
2033 }
2034 }
2035
2036 if (newpath != NULL) {
2037 ret = UserPathCopy(newpath, &pathNewRet);
2038 if (ret != 0) {
2039 goto OUT;
2040 }
2041 }
2042
2043 if (oldfd != AT_FDCWD) {
2044 /* Process fd convert to system global fd */
2045 oldfd = GetAssociatedSystemFd(oldfd);
2046 }
2047 if (newdfd != AT_FDCWD) {
2048 /* Process fd convert to system global fd */
2049 newdfd = GetAssociatedSystemFd(newdfd);
2050 }
2051
2052 ret = do_rename(oldfd, (oldpath ? pathOldRet : NULL), newdfd, (newpath ? pathNewRet : NULL));
2053 if (ret < 0) {
2054 ret = -get_errno();
2055 }
2056
2057OUT:
2058 if (pathOldRet != NULL) {
2059 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathOldRet);
2060 }
2061 if (pathNewRet != NULL) {
2062 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathNewRet);
2063 }
2064 return ret;
2065}
函数调用图:

◆ SysRmdir()

int SysRmdir ( const char *  pathname)

删除目录

在文件 fs_syscall.c847 行定义.

848{
849 int ret;
850 char *pathRet = NULL;
851
852 if (pathname != NULL) {
853 ret = UserPathCopy(pathname, &pathRet);
854 if (ret != 0) {
855 goto OUT;
856 }
857 }
858
859 ret = do_rmdir(AT_FDCWD, (pathname ? pathRet : NULL));
860 if (ret < 0) {
861 ret = -get_errno();
862 }
863
864OUT:
865 if (pathRet != NULL) {
866 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
867 }
868 return ret;
869}
int do_rmdir(int dirfd, const char *pathname)
函数调用图:

◆ SysSchedGetAffinity()

int SysSchedGetAffinity ( int  id,
unsigned int cpuset,
int  flag 
)

在文件 process_syscall.c1062 行定义.

1063{
1064 int ret;
1065 unsigned int processID;
1066 unsigned int taskID;
1067 unsigned int intSave;
1068 unsigned int cpuAffiMask;
1069
1070 ret = SchedAffinityParameterPreprocess(id, flag, &taskID, &processID);
1071 if (ret != LOS_OK) {
1072 return ret;
1073 }
1074
1075 SCHEDULER_LOCK(intSave);
1076 if (flag >= 0) {
1077 if (OsProcessIsInactive(OS_PCB_FROM_PID(processID))) {
1078 SCHEDULER_UNLOCK(intSave);
1079 return -ESRCH;
1080 }
1081 } else {
1082 ret = OsUserTaskOperatePermissionsCheck(OS_TCB_FROM_TID(taskID));
1083 if (ret != LOS_OK) {
1084 SCHEDULER_UNLOCK(intSave);
1085 if (ret == EINVAL) {
1086 return -ESRCH;
1087 }
1088 return -ret;
1089 }
1090 }
1091
1092#ifdef LOSCFG_KERNEL_SMP
1093 cpuAffiMask = (unsigned int)OS_TCB_FROM_TID(taskID)->cpuAffiMask;
1094#else
1095 cpuAffiMask = 1;
1096#endif /* LOSCFG_KERNEL_SMP */
1097
1098 SCHEDULER_UNLOCK(intSave);
1099 ret = LOS_ArchCopyToUser(cpuset, &cpuAffiMask, sizeof(unsigned int));
1100 if (ret != LOS_OK) {
1101 return -EFAULT;
1102 }
1103
1104 return LOS_OK;
1105}
STATIC INLINE BOOL OsProcessIsInactive(const LosProcessCB *processCB)
进程不活跃函数定义:身上贴有不使用且不活跃标签的进程
INT32 OsUserTaskOperatePermissionsCheck(const LosTaskCB *taskCB)
Definition: los_task.c:1380
static int SchedAffinityParameterPreprocess(int id, int flag, unsigned int *taskID, unsigned int *processID)
函数调用图:

◆ SysSchedGetParam()

int SysSchedGetParam ( int  id,
int  flag 
)

在文件 process_syscall.c164 行定义.

165{
166 SchedParam param = { 0 };
167 unsigned int intSave;
168
169 if (flag < 0) {
170 if (OS_TID_CHECK_INVALID(id)) {
171 return -EINVAL;
172 }
173
174 LosTaskCB *taskCB = OS_TCB_FROM_TID(id);
175 SCHEDULER_LOCK(intSave);
176 int ret = OsUserTaskOperatePermissionsCheck(taskCB);
177 if (ret != LOS_OK) {
178 SCHEDULER_UNLOCK(intSave);
179 return -ret;
180 }
181
182 taskCB->ops->schedParamGet(taskCB, &param);
183 SCHEDULER_UNLOCK(intSave);
184 return (int)param.priority;
185 }
186
187 if (id == 0) {
189 }
190
191 if (OS_PID_CHECK_INVALID(id)) {
192 return -EINVAL;
193 }
194
195 return OsGetProcessPriority(LOS_PRIO_PROCESS, id);
196}
UINT32(* schedParamGet)(const LosTaskCB *taskCB, SchedParam *param)
获取调度参数
UINT16 priority
const SchedOps * ops
函数调用图:

◆ SysSchedGetPriorityMax()

int SysSchedGetPriorityMax ( int  policy)

在文件 process_syscall.c245 行定义.

246{
247 if (policy != LOS_SCHED_RR) {
248 return -EINVAL;
249 }
250
251 return OS_USER_PROCESS_PRIORITY_LOWEST;
252}

◆ SysSchedGetPriorityMin()

int SysSchedGetPriorityMin ( int  policy)

在文件 process_syscall.c236 行定义.

237{
238 if (policy != LOS_SCHED_RR) {
239 return -EINVAL;
240 }
241
242 return OS_USER_PROCESS_PRIORITY_HIGHEST;
243}

◆ SysSchedGetScheduler()

int SysSchedGetScheduler ( int  id,
int  flag 
)

在文件 process_syscall.c113 行定义.

114{
115 unsigned int intSave;
116 SchedParam param = { 0 };
117 int ret;
118
119 if (flag < 0) {
120 if (OS_TID_CHECK_INVALID(id)) {
121 return -EINVAL;
122 }
123
124 LosTaskCB *taskCB = OS_TCB_FROM_TID(id);
125 SCHEDULER_LOCK(intSave);
127 if (ret != LOS_OK) {
128 SCHEDULER_UNLOCK(intSave);
129 return -ret;
130 }
131
132 taskCB->ops->schedParamGet(taskCB, &param);
133 SCHEDULER_UNLOCK(intSave);
134 return (int)param.policy;
135 }
136
137 return LOS_GetProcessScheduler(id);
138}
LITE_OS_SEC_TEXT INT32 LOS_GetProcessScheduler(INT32 pid)
获得指定进程的调度策略
Definition: los_process.c:1030
UINT16 policy
函数调用图:

◆ SysSchedRRGetInterval()

int SysSchedRRGetInterval ( int  pid,
struct timespec *  tp 
)

在文件 process_syscall.c254 行定义.

255{
256 unsigned int intSave;
257 int ret;
258 SchedParam param = { 0 };
259 time_t timeSlice = 0;
260 struct timespec tv;
261 LosTaskCB *taskCB = NULL;
262 LosProcessCB *processCB = NULL;
263
264 if (tp == NULL) {
265 return -EINVAL;
266 }
267
268 if (OS_PID_CHECK_INVALID(pid)) {
269 return -EINVAL;
270 }
271
272 if (pid == 0) {
273 processCB = OsCurrProcessGet();
274 } else {
275 processCB = OS_PCB_FROM_PID(pid);
276 }
277
278 SCHEDULER_LOCK(intSave);
279 /* if can not find process by pid return ESRCH */
280 if (OsProcessIsInactive(processCB)) {
281 SCHEDULER_UNLOCK(intSave);
282 return -ESRCH;
283 }
284
285 LOS_DL_LIST_FOR_EACH_ENTRY(taskCB, &processCB->threadSiblingList, LosTaskCB, threadList) {
286 if (!OsTaskIsInactive(taskCB)) {
287 taskCB->ops->schedParamGet(taskCB, &param);
288 if (param.policy == LOS_SCHED_RR) {
289 timeSlice += param.timeSlice;
290 }
291 }
292 }
293
294 SCHEDULER_UNLOCK(intSave);
295
296 timeSlice = timeSlice * OS_NS_PER_CYCLE;
297 tv.tv_sec = timeSlice / OS_SYS_NS_PER_SECOND;
298 tv.tv_nsec = timeSlice % OS_SYS_NS_PER_SECOND;
299 ret = LOS_ArchCopyToUser(tp, &tv, sizeof(struct timespec));
300 if (ret != 0) {
301 return -EFAULT;
302 }
303
304 return 0;
305}
STATIC INLINE LosProcessCB * OsCurrProcessGet(VOID)
STATIC INLINE BOOL OsTaskIsInactive(const LosTaskCB *taskCB)
LOS_DL_LIST threadSiblingList
UINT32 timeSlice
函数调用图:

◆ SysSchedSetAffinity()

int SysSchedSetAffinity ( int  id,
const unsigned short  cpuset,
int  flag 
)

在文件 process_syscall.c1108 行定义.

1109{
1110 int ret;
1111 unsigned int processID;
1112 unsigned int taskID;
1113 unsigned int intSave;
1114 unsigned short currCpuMask;
1115 bool needSched = FALSE;
1116
1117 if (cpuset > LOSCFG_KERNEL_CPU_MASK) {
1118 return -EINVAL;
1119 }
1120
1121 ret = SchedAffinityParameterPreprocess(id, flag, &taskID, &processID);
1122 if (ret != LOS_OK) {
1123 return ret;
1124 }
1125
1126 if (flag >= 0) {
1127 ret = OsPermissionToCheck(processID, LOS_GetCurrProcessID());
1128 if (ret != LOS_OK) {
1129 return ret;
1130 }
1131 SCHEDULER_LOCK(intSave);
1132 if (OsProcessIsInactive(OS_PCB_FROM_PID(processID))) {
1133 SCHEDULER_UNLOCK(intSave);
1134 return -ESRCH;
1135 }
1136 } else {
1137 SCHEDULER_LOCK(intSave);
1138 ret = OsUserTaskOperatePermissionsCheck(OS_TCB_FROM_TID(taskID));
1139 if (ret != LOS_OK) {
1140 SCHEDULER_UNLOCK(intSave);
1141 if (ret == EINVAL) {
1142 return -ESRCH;
1143 }
1144 return -ret;
1145 }
1146 }
1147
1148 needSched = OsTaskCpuAffiSetUnsafe(taskID, cpuset, &currCpuMask);
1149 SCHEDULER_UNLOCK(intSave);
1150 if (needSched && OS_SCHEDULER_ACTIVE) {
1151 LOS_MpSchedule(currCpuMask);
1152 LOS_Schedule();
1153 }
1154
1155 return LOS_OK;
1156}
VOID LOS_Schedule(VOID)
Trigger active task scheduling.
Definition: los_sched.c:469
VOID LOS_MpSchedule(UINT32 target)
Definition: los_mp.c:76
LITE_OS_SEC_TEXT BOOL OsTaskCpuAffiSetUnsafe(UINT32 taskID, UINT16 newCpuAffiMask, UINT16 *oldCpuAffiMask)
CPU亲和性(affinity)将任务绑在指定CPU上,用于多核CPU情况,(该函数仅在SMP模式下支持)
Definition: los_task.c:1212
static int OsPermissionToCheck(unsigned int pid, unsigned int who)
函数调用图:

◆ SysSchedSetParam()

int SysSchedSetParam ( int  id,
unsigned int  prio,
int  flag 
)

在文件 process_syscall.c218 行定义.

219{
220 if (flag < 0) {
221 return -OsUserTaskSchedulerSet(id, LOS_SCHED_RR, prio, false);
222 }
223
224 return SysSetProcessPriority(LOS_PRIO_PROCESS, id, prio);
225}
static int OsUserTaskSchedulerSet(unsigned int tid, unsigned short policy, unsigned short priority, bool policyFlag)
设置用户级任务调度信息
int SysSetProcessPriority(int which, int who, unsigned int prio)
函数调用图:

◆ SysSchedSetScheduler()

int SysSchedSetScheduler ( int  id,
int  policy,
int  prio,
int  flag 
)

在文件 process_syscall.c140 行定义.

141{
142 int ret;
143
144 if (flag < 0) {
145 return -OsUserTaskSchedulerSet(id, policy, prio, true);
146 }
147
148 if (prio < OS_USER_PROCESS_PRIORITY_HIGHEST) {
149 return -EINVAL;
150 }
151
152 if (id == 0) {
154 }
155
157 if (ret < 0) {
158 return ret;
159 }
160
161 return OsSetProcessScheduler(LOS_PRIO_PROCESS, id, prio, policy);
162}
LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy)
设置进程调度计划
Definition: los_process.c:983
函数调用图:

◆ SysSchedYield()

void SysSchedYield ( int  type)

在文件 process_syscall.c105 行定义.

106{
107 (void)type;
108
110 return;
111}
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID)
Change the scheduling sequence of tasks with the same priority.
Definition: los_task.c:1115
函数调用图:

◆ SysSelect()

int SysSelect ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds,
struct timeval *  timeout 
)

SysSelect 系统调用|文件系统|select .鸿蒙liteos目前也支持epoll方式

参数
exceptfds文件集将监视文件集中的任何文件是否发生错误,可用于其他的用途, 例如,监视带外数据OOB,带外数据使用MSG_OOB标志发送到套接字上。当select函数返回的时候, exceptfds将清除其中的其他文件描述符,只留下标记有OOB数据的文件描述符。
nfdsselect监视的文件句柄数,一般设为要监视各文件中的最大文件描述符值加1。
readfds文件描述符集合监视文件集中的任何文件是否有数据可读,当select函数返回的时候, readfds将清除其中不可读的文件描述符,只留下可读的文件描述符。
timeout参数是一个指向 struct timeval 类型的指针,它可以使 select()在等待 timeout 时间后 若没有文件描述符准备好则返回。其timeval结构用于指定这段时间的秒数和微秒数。它可以使select处于三种状态: (1) 若将NULL以形参传入,即不传入时间结构,就是将select置于阻塞状态,一定等到监视文件描述符集合中某个文件描述符发生变化为止; (2) 若将时间值设为0秒0毫秒,就变成一个纯粹的非阻塞函数,不管文件描述符是否有变化,都立刻返回继续执行,文件无变化返回0,有变化返回一个正值; (3) timeout的值大于0,这就是等待的超时时间,即select在timeout时间内阻塞,超时时间之内有事件到来就返回了,否则在超时后不管怎样一定返回,返回值同上述。
writefds文件描述符集合监视文件集中的任何文件是否有数据可写,当select函数返回的时候, writefds将清除其中不可写的文件描述符,只留下可写的文件描述符。
返回
参见

在文件 fs_syscall.c1135 行定义.

1136{
1137 int ret;
1138 fd_set *fdsRet = NULL;
1139 fd_set *readfdsRet = NULL;
1140 fd_set *writefdsRet = NULL;
1141 fd_set *exceptfdsRet = NULL;
1142 struct timeval timeoutRet = {0};
1143
1144 ret = SelectParamCheckCopy(readfds, writefds, exceptfds, &fdsRet);//检查参数
1145 if (ret != 0) {
1146 return ret;
1147 }
1148
1149 readfdsRet = fdsRet; /* LOS_MemAlloc 3 sizeof(fd_set) space,first use for readfds */
1150 writefdsRet = fdsRet + 1; /* 1: LOS_MemAlloc 3 sizeof(fd_set) space,second use for writefds */
1151 exceptfdsRet = fdsRet + 2; /* 2: LOS_MemAlloc 3 sizeof(fd_set) space,thired use for exceptfds */
1152
1153 if (timeout != NULL) {
1154 if (LOS_ArchCopyFromUser(&timeoutRet, timeout, sizeof(struct timeval)) != 0) {
1155 goto ERROUT;
1156 }
1157 }
1158 //poll()是在NuttX下执行此类监视操作的基本API
1159 ret = do_select(nfds, (readfds ? readfdsRet : NULL), (writefds ? writefdsRet : NULL),
1160 (exceptfds ? exceptfdsRet : NULL), (timeout ? (&timeoutRet) : NULL), UserPoll);
1161 if (ret < 0) {
1162 (void)LOS_MemFree(OS_SYS_MEM_ADDR, fdsRet);
1163 return -get_errno();
1164 }
1165
1166 if (readfds != NULL) {
1167 if (LOS_ArchCopyToUser(readfds, readfdsRet, sizeof(fd_set)) != 0) {
1168 goto ERROUT;
1169 }
1170 }
1171
1172 if (writefds != NULL) {
1173 if (LOS_ArchCopyToUser(writefds, writefdsRet, sizeof(fd_set)) != 0) {
1174 goto ERROUT;
1175 }
1176 }
1177
1178 if (exceptfds != 0) {
1179 if (LOS_ArchCopyToUser(exceptfds, exceptfdsRet, sizeof(fd_set)) != 0) {
1180 goto ERROUT;
1181 }
1182 }
1183
1184 (void)LOS_MemFree(OS_SYS_MEM_ADDR, fdsRet);
1185 return ret;
1186
1187ERROUT:
1188 (void)LOS_MemFree(OS_SYS_MEM_ADDR, fdsRet);
1189 return -EFAULT;
1190}
static int SelectParamCheckCopy(fd_set *readfds, fd_set *writefds, fd_set *exceptfds, fd_set **fdsBuf)
select()参数检查
Definition: fs_syscall.c:1076
函数调用图:

◆ SysSend()

ssize_t SysSend ( int  s,
const void dataptr,
size_t  size,
int  flags 
)

在文件 net_syscall.c223 行定义.

224{
225 int ret;
226
227 SOCKET_U2K(s);
228 CHECK_ASPACE(dataptr, size);
229
230 DUP_FROM_USER(dataptr, size);
231
232 if (dataptr == NULL) {
233 set_errno(EFAULT);
234 ret = -1;
235 } else {
236 ret = send(s, dataptr, size, flags);
237 }
238 FREE_DUP(dataptr);
239 if (ret == -1) {
240 return -get_errno();
241 }
242
243 return ret;
244}
ssize_t send(int s, const void *dataptr, size_t size, int flags)
相当于文件操作的 write 功能,区别是第四个参数 同 recv
Definition: socket.c:257
函数调用图:

◆ SysSendFile()

ssize_t SysSendFile ( int  outfd,
int  infd,
off_t *  offset,
size_t  count 
)

在文件 fs_syscall.c1740 行定义.

1741{
1742 int ret, retVal;
1743 off_t offsetRet;
1744
1745 retVal = LOS_ArchCopyFromUser(&offsetRet, offset, sizeof(off_t));
1746 if (retVal != 0) {
1747 return -EFAULT;
1748 }
1749
1750 /* Process fd convert to system global fd */
1751 outfd = GetAssociatedSystemFd(outfd);
1752 infd = GetAssociatedSystemFd(infd);
1753
1754 ret = sendfile(outfd, infd, (offset ? (&offsetRet) : NULL), count);
1755 if (ret < 0) {
1756 return -get_errno();
1757 }
1758
1759 retVal = LOS_ArchCopyToUser(offset, &offsetRet, sizeof(off_t));
1760 if (retVal != 0) {
1761 return -EFAULT;
1762 }
1763
1764 return ret;
1765}
函数调用图:

◆ SysSendMsg()

ssize_t SysSendMsg ( int  s,
const struct msghdr *  message,
int  flags 
)

在文件 net_syscall.c396 行定义.

397{
398 int ret;
399
400 SOCKET_U2K(s);
401
402 CHECK_ASPACE(message, sizeof(struct msghdr));
403 CPY_FROM_CONST_USER(struct msghdr, message);
404
405 if (message && message->msg_iovlen > IOV_MAX) {
406 set_errno(EMSGSIZE);
407 return -get_errno();
408 }
409
410 CHECK_FIELD_ASPACE(message, msg_name, message->msg_namelen);
411 CHECK_FIELD_ASPACE(message, msg_iov, message->msg_iovlen * sizeof(struct iovec));
412 CHECK_FIELD_ASPACE(message, msg_control, message->msg_controllen);
413
414 DUP_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen * sizeof(struct iovec));
415 CHECK_ARRAY_FIELD_ASPACE(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
416 FREE_DUP_FIELD(message, msg_iov));
417 DUP_FIELD_FROM_USER(message, msg_name, message->msg_namelen,
418 FREE_DUP_FIELD(message, msg_iov));
419 DUP_FIELD_FROM_USER(message, msg_control, message->msg_controllen,
420 FREE_DUP_FIELD(message, msg_iov);
421 FREE_DUP_FIELD(message, msg_name));
422 DUP_ARRAY_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
423 FREE_DUP_FIELD(message, msg_control);
424 FREE_DUP_FIELD(message, msg_iov);
425 FREE_DUP_FIELD(message, msg_name));
426
427 if (message == NULL) {
428 set_errno(EFAULT);
429 ret = -1;
430 } else {
431 ret = sendmsg(s, message, flags);
432 }
433 FREE_DUP_ARRAY_FIELD(message, msg_iov, message->msg_iovlen, iov_base);
434 FREE_DUP_FIELD(message, msg_control);
435 FREE_DUP_FIELD(message, msg_iov);
436 FREE_DUP_FIELD(message, msg_name);
437 if (ret == -1) {
438 return -get_errno();
439 }
440
441 return ret;
442}
ssize_t sendmsg(int s, const struct msghdr *message, int flags)
只是发送数据的格式的不同
Definition: socket.c:263
函数调用图:

◆ SysSendTo()

ssize_t SysSendTo ( int  s,
const void dataptr,
size_t  size,
int  flags,
const struct sockaddr *  to,
socklen_t  tolen 
)

在文件 net_syscall.c246 行定义.

248{
249 int ret;
250
251 SOCKET_U2K(s);
252 CHECK_ASPACE(dataptr, size);
253 CHECK_ASPACE(to, tolen);
254
255 DUP_FROM_USER(dataptr, size);
256 DUP_FROM_USER(to, tolen, FREE_DUP(dataptr));
257
258 if (dataptr == NULL) {
259 set_errno(EFAULT);
260 ret = -1;
261 } else {
262 ret = sendto(s, dataptr, size, flags, to, tolen);
263 }
264 FREE_DUP(dataptr);
265 FREE_DUP(to);
266 if (ret == -1) {
267 return -get_errno();
268 }
269
270 return ret;
271}
ssize_t sendto(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
区别是送达地址,意思是这些数据要发给哪个地址的
Definition: socket.c:268
函数调用图:

◆ SysSetGroupID()

int SysSetGroupID ( unsigned int  gid)

◆ SysSetGroups()

int SysSetGroups ( int  size,
int  list[] 
)

在文件 process_syscall.c825 行定义.

826{
827#ifdef LOSCFG_SECURITY_CAPABILITY
828 int ret;
829 int gid;
830 int listSize = size;
831 unsigned int count;
832 int *safeList = NULL;
833#endif
834
835 if ((size != 0) && (list == NULL)) {
836 return -EFAULT;
837 }
838
839 if ((size < 0) || (size > OS_GROUPS_NUMBER_MAX)) {
840 return -EINVAL;
841 }
842
843#ifdef LOSCFG_SECURITY_CAPABILITY
844 if (!IsCapPermit(CAP_SETGID)) {
845 return -EPERM;
846 }
847
848 if (size != 0) {
849 safeList = LOS_MemAlloc(m_aucSysMem1, size * sizeof(int));
850 if (safeList == NULL) {
851 return -ENOMEM;
852 }
853
854 ret = LOS_ArchCopyFromUser(safeList, list, size * sizeof(int));
855 if (ret != 0) {
856 ret = -EFAULT;
857 goto EXIT;
858 }
859 gid = OsCurrUserGet()->gid;
860 for (count = 0; count < size; count++) {
861 if (safeList[count] == gid) {
862 listSize = size - 1;
863 } else if (safeList[count] < 0) {
864 ret = -EINVAL;
865 goto EXIT;
866 }
867 }
868 }
869
870 ret = SetGroups(listSize, safeList, size);
871EXIT:
872 if (safeList != NULL) {
873 (void)LOS_MemFree(m_aucSysMem1, safeList);
874 }
875
876 return ret;
877#else
878 return 0;
879#endif
880}
static int SetGroups(int listSize, const int *safeList, int size)
函数调用图:

◆ SysSetiTimer()

int SysSetiTimer ( int  which,
const struct itimerval *  value,
struct itimerval *  ovalue 
)

在文件 time_syscall.c108 行定义.

109{
110 int ret;
111 struct itimerval svalue;
112 struct itimerval sovalue;
113
114 if (value == NULL) {
115 errno = EINVAL;
116 return -EINVAL;
117 }
118
119 if (LOS_ArchCopyFromUser(&svalue, value, sizeof(struct itimerval))) {
120 errno = EFAULT;
121 return -EFAULT;
122 }
123
124 ret = setitimer(which, &svalue, &sovalue);
125 if (ret < 0) {
126 return -get_errno();
127 }
128
129 if (ovalue && LOS_ArchCopyToUser(ovalue, &sovalue, sizeof(struct itimerval))) {
130 errno = EFAULT;
131 return -EFAULT;
132 }
133
134 return ret;
135}
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue)
Definition: time.c:1117
函数调用图:

◆ SysSetProcessGroupID()

int SysSetProcessGroupID ( unsigned int  pid,
unsigned int  gid 
)

为指定进程设置进程组ID

在文件 process_syscall.c370 行定义.

371{
372 int ret;
373
374 if (pid == 0) {//无指定进程ID时 @note_thinking 此处会不会有风险, 直接返回会不会好些 ?
375 pid = LOS_GetCurrProcessID();//获取当前进程ID,给当前进程设置组ID
376 }
377
378 if (gid == 0) {
379 gid = pid;
380 } else if (gid <= OS_USER_PRIVILEGE_PROCESS_GROUP) {
381 return -EPERM;
382 }
383
384 ret = OsPermissionToCheck(pid, gid);
385 if (ret < 0) {
386 return ret;
387 }
388
389 return OsSetProcessGroupID(pid, gid);
390}
LITE_OS_SEC_TEXT INT32 OsSetProcessGroupID(UINT32 pid, UINT32 gid)
Definition: los_process.c:1439
函数调用图:

◆ SysSetProcessPriority()

int SysSetProcessPriority ( int  which,
int  who,
unsigned int  prio 
)

在文件 process_syscall.c198 行定义.

199{
200 int ret;
201
202 if (prio < OS_USER_PROCESS_PRIORITY_HIGHEST) {
203 return -EINVAL;
204 }
205
206 if (who == 0) {
207 who = (int)LOS_GetCurrProcessID();
208 }
209
211 if (ret < 0) {
212 return ret;
213 }
214
215 return OsSetProcessScheduler(which, who, prio, LOS_GetProcessScheduler(who));
216}
函数调用图:
这是这个函数的调用关系图:

◆ SysSetRealEffGroupID()

int SysSetRealEffGroupID ( int  rgid,
int  egid 
)

在文件 process_syscall.c713 行定义.

714{
715#ifdef LOSCFG_SECURITY_CAPABILITY
716 return SysSetRealEffSaveGroupID(rgid, egid, -1);
717#else
718 if ((rgid != 0) || (egid != 0)) {
719 return -EPERM;
720 }
721 return 0;
722#endif
723}
int SysSetRealEffSaveGroupID(int rgid, int egid, int sgid)
函数调用图:

◆ SysSetRealEffSaveGroupID()

int SysSetRealEffSaveGroupID ( int  rgid,
int  egid,
int  sgid 
)

在文件 process_syscall.c677 行定义.

678{
679#ifdef LOSCFG_SECURITY_CAPABILITY
680 int ret;
681
682 if ((rgid == -1) && (egid == -1) && (sgid == -1)) {
683 return 0;
684 }
685
686 ret = SetRealEffSaveGroupIDCheck(rgid, egid, sgid);
687 if (ret != 0) {
688 return ret;
689 }
690
691 if (rgid >= 0) {
692 if (((egid != -1) && (egid != rgid)) || ((sgid != -1) && (sgid != rgid))) {
693 return -EPERM;
694 }
695 return SysSetGroupID(rgid);
696 } else if (egid >= 0) {
697 if ((sgid != -1) && (sgid != egid)) {
698 return -EPERM;
699 }
700 return SysSetGroupID(egid);
701 } else {
702 return SysSetGroupID(sgid);
703 }
704
705#else
706 if ((rgid != 0) || (egid != 0) || (sgid != 0)) {
707 return -EPERM;
708 }
709 return 0;
710#endif
711}
int SysSetGroupID(int gid)
static int SetRealEffSaveGroupIDCheck(int rgid, int egid, int sgid)
函数调用图:
这是这个函数的调用关系图:

◆ SysSetRealEffSaveUserID()

int SysSetRealEffSaveUserID ( int  ruid,
int  euid,
int  suid 
)

在文件 process_syscall.c530 行定义.

531{
532#ifdef LOSCFG_SECURITY_CAPABILITY
533 int ret;
534
535 if ((ruid == -1) && (euid == -1) && (suid == -1)) {
536 return 0;
537 }
538
539 ret = SetRealEffSaveUserIDCheck(ruid, euid, suid);
540 if (ret != 0) {
541 return ret;
542 }
543
544 if (ruid >= 0) {
545 if (((euid != -1) && (euid != ruid)) || ((suid != -1) && (suid != ruid))) {
546 return -EPERM;
547 }
548 return SysSetUserID(ruid);
549 } else if (euid >= 0) {
550 if ((suid != -1) && (suid != euid)) {
551 return -EPERM;
552 }
553 return SysSetUserID(euid);
554 } else {
555 return SysSetUserID(suid);
556 }
557#else
558 if ((ruid != 0) || (euid != 0) || (suid != 0)) {
559 return -EPERM;
560 }
561 return 0;
562#endif
563}
static int SetRealEffSaveUserIDCheck(int ruid, int euid, int suid)
int SysSetUserID(int uid)
函数调用图:
这是这个函数的调用关系图:

◆ SysSetRealEffUserID()

int SysSetRealEffUserID ( int  ruid,
int  euid 
)

在文件 process_syscall.c565 行定义.

566{
567#ifdef LOSCFG_SECURITY_CAPABILITY
568 return SysSetRealEffSaveUserID(ruid, euid, -1);
569#else
570 if ((ruid != 0) || (euid != 0)) {
571 return -EPERM;
572 }
573 return 0;
574#endif
575}
int SysSetRealEffSaveUserID(int ruid, int euid, int suid)
函数调用图:

◆ SysSetrlimit()

int SysSetrlimit ( int  resource,
unsigned long long  k_rlim[2] 
)

在文件 misc_syscall.c228 行定义.

229{
230 int ret;
231 struct rlimit lim;
232
233 if(!IsCapPermit(CAP_CAPSET)) {
234 return -EPERM;
235 }
236
237 ret = LOS_ArchCopyFromUser(&lim, k_rlim, sizeof(struct rlimit));
238 if (ret != 0) {
239 return -EFAULT;
240 }
241 ret = setrlimit(resource, &lim);
242
243 return ret;
244}
int setrlimit(int resource, const struct rlimit *rlim)
重新设置当前进程资源限制。
Definition: misc.c:189
函数调用图:

◆ SysSetSockOpt()

int SysSetSockOpt ( int  socket,
int  level,
int  optName,
const void optValue,
socklen_t  optLen 
)

在文件 net_syscall.c348 行定义.

350{
351 int ret;
352
353 SOCKET_U2K(socket);
354 CHECK_ASPACE(optValue, optLen);
355
356 DUP_FROM_USER(optValue, optLen);
357 ret = setsockopt(socket, level, optName, optValue, optLen);
358 FREE_DUP(optValue);
359 if (ret == -1) {
360 return -get_errno();
361 }
362
363 return ret;
364}
int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
设置socket 配置项
Definition: socket.c:148
函数调用图:

◆ SysSetThreadArea()

int SysSetThreadArea ( const char *  area)

在文件 process_syscall.c902 行定义.

903{
904 unsigned int intSave;
905 int ret = LOS_OK;
906
907 if (!LOS_IsUserAddress((unsigned long)(uintptr_t)area)) {
908 return EINVAL;
909 }
910
911 LosTaskCB *taskCB = OsCurrTaskGet();
912 SCHEDULER_LOCK(intSave);
913 LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
914 if (processCB->processMode != OS_USER_MODE) {
915 ret = EPERM;
916 goto OUT;
917 }
918
919 taskCB->userArea = (unsigned long)(uintptr_t)area;
920OUT:
921 SCHEDULER_UNLOCK(intSave);
922 return ret;
923}
UINT16 processMode
UINT32 processID
UINTPTR userArea
用户空间的堆区开始位置
函数调用图:

◆ SysSetUserID()

int SysSetUserID ( int  uid)

在文件 process_syscall.c477 行定义.

478{
479#ifdef LOSCFG_SECURITY_CAPABILITY
480 int ret = -EPERM;
481 unsigned int intSave;
482
483 if (uid < 0) {
484 return -EINVAL;
485 }
486
487 SCHEDULER_LOCK(intSave);
488 User *user = OsCurrUserGet();
489 if (IsCapPermit(CAP_SETUID)) {
490 user->userID = uid;
491 user->effUserID = uid;
492 /* add process to a user */
493 } else if (user->userID != uid) {
494 goto EXIT;
495 }
496
497 ret = LOS_OK;
498 /* add process to a user */
499EXIT:
500 SCHEDULER_UNLOCK(intSave);
501 return ret;
502#else
503 if (uid != 0) {
504 return -EPERM;
505 }
506
507 return 0;
508#endif
509}
函数调用图:
这是这个函数的调用关系图:

◆ SysShellExec()

int SysShellExec ( const char *  msgName,
const char *  cmdString 
)

执行 shell 命令

在文件 misc_syscall.c106 行定义.

107{
108 int ret;
109 unsigned int uintRet;
110 errno_t err;
111 CmdParsed cmdParsed;
112 char msgNameDup[CMD_KEY_LEN + 1] = { 0 };
113 char cmdStringDup[CMD_MAX_LEN + 1] = { 0 };
114
115 if (!IsCapPermit(CAP_SHELL_EXEC)) {//1.先鉴权
116 return -EPERM;
117 }
118 //2.由内核栈空间接走用户空间的参数,注意还是同一个任务,只是从任务的用户空间移到内核栈.
119 ret = LOS_StrncpyFromUser(msgNameDup, msgName, CMD_KEY_LEN + 1);
120 if (ret < 0) {
121 return -EFAULT;
122 } else if (ret > CMD_KEY_LEN) {
123 return -ENAMETOOLONG;
124 }
125
126 ret = LOS_StrncpyFromUser(cmdStringDup, cmdString, CMD_MAX_LEN + 1);
127 if (ret < 0) {
128 return -EFAULT;
129 } else if (ret > CMD_MAX_LEN) {
130 return -ENAMETOOLONG;
131 }
132
133 err = memset_s(&cmdParsed, sizeof(CmdParsed), 0, sizeof(CmdParsed));
134 if (err != EOK) {
135 return -EFAULT;
136 }
137 //获取消息类型
138 uintRet = ShellMsgTypeGet(&cmdParsed, msgNameDup);
139 if (uintRet != LOS_OK) {
140 PRINTK("%s:command not found\n", msgNameDup);
141 return -EFAULT;
142 } else {
143 (void)OsCmdExec(&cmdParsed, (char *)cmdStringDup);//执行shell命令,回调命令注册时的 函数指针
144 }
145
146 return 0;
147}
unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr)
执行命令,shell是运行程序的程序.
Definition: shcmd.c:586
UINT32 ShellMsgTypeGet(CmdParsed *cmdParsed, const CHAR *cmdType)
获取shell消息类型
Definition: shmsg.c:222
函数调用图:

◆ SysShmAt()

void * SysShmAt ( int  shmid,
const void shmaddr,
int  shmflg 
)
 连接共享内存标识符为shmid的共享内存,连接成功后把共享内存区对象映射到调用进程的地址空间,随后可像本地空间一样访问
 一旦创建/引用了一个共享存储段,那么进程就可调用shmat函数将其连接到它的地址空间中
 如果shmat成功执行,那么内核将使与该共享存储相关的shmid_ds结构中的shm_nattch计数器值加1
参数
shmid
shmaddr
shmflg
返回
void*

在文件 vm_syscall.c152 行定义.

153{
154 void *ret = NULL;
155
156 ret = ShmAt(shmid, shmaddr, shmflg);
157 if (ret == (void *)-1) {
158 return (void *)(intptr_t)-get_errno();
159 }
160
161 return ret;
162}
VOID * ShmAt(INT32 shmid, const VOID *shmaddr, INT32 shmflg)
ShmAt 用来启动对该共享内存的访问,并把共享内存连接到当前进程的地址空间。
Definition: shm.c:634
函数调用图:

◆ SysShmCtl()

int SysShmCtl ( int  shmid,
int  cmd,
struct shmid_ds buf 
)

完成对共享内存的控制 此函数可以对shmid指定的共享存储进行多种操作(删除、取信息、加锁、解锁等)

参数
shmid共享内存标识符
cmdIPC_STAT:得到共享内存的状态,把共享内存的shmid_ds结构复制到buf中
IPC_SET:改变共享内存的状态,把buf所指的shmid_ds结构中的uid、gid、mode复制到共享内存的shmid_ds结构内
IPC_RMID:删除这片共享内存
buf共享内存管理结构体。
返回
int

在文件 vm_syscall.c174 行定义.

175{
176 int ret;
177
178 ret = ShmCtl(shmid, cmd, buf);
179 if (ret < 0) {
180 return -get_errno();
181 }
182
183 return ret;
184}
INT32 ShmCtl(INT32 shmid, INT32 cmd, struct shmid_ds *buf)
ShmCtl 此函数可以对shmid指定的共享存储进行多种操作(删除、取信息、加锁、解锁等)
Definition: shm.c:703
函数调用图:

◆ SysShmDt()

int SysShmDt ( const void shmaddr)

与shmat函数相反,是用来断开与共享内存附加点的地址,禁止本进程访问此片共享内存

参数
shmaddr连接的共享内存的起始地址
本函数调用并不删除所指定的共享内存区,而只是将先前用shmat函数连接(attach)好的共享内存脱离(detach)目前的进程
返回
int 返回值 成功:0 出错:-1,错误原因存于error中

在文件 vm_syscall.c192 行定义.

193{
194 int ret;
195
196 ret = ShmDt(shmaddr);
197 if (ret < 0) {
198 return -get_errno();
199 }
200
201 return ret;
202}
INT32 ShmDt(const VOID *shmaddr)
当对共享存储的操作已经结束时,则调用shmdt与该存储段分离 如果shmat成功执行,那么内核将使与该共享存储相关的shmid_ds结构中的shm_nattch计数器值减1
Definition: shm.c:824
函数调用图:

◆ SysShmGet()

int SysShmGet ( key_t  key,
size_t  size,
int  shmflg 
)

得到一个共享内存标识符或创建一个共享内存对象

参数
key建立新共享内存对象 标识符是IPC对象的内部名。为使多个合作进程能够在同一IPC对象上汇聚,需要提供一个外部命名方案。
为此,每个IPC对象都与一个键(key)相关联,这个键作为该对象的外部名,无论何时创建IPC结构(通过msgget、semget、shmget创建),
都应给IPC指定一个键, key_t由ftok创建,ftok当然在本工程里找不到,所以要写这么多.
size新建的共享内存大小,以字节为单位
shmflgIPC_CREAT IPC_EXCL
IPC_CREAT: 在创建新的IPC时,如果key参数是IPC_PRIVATE或者和当前某种类型的IPC结构无关,则需要指明flag参数的IPC_CREAT标志位,
则用来创建一个新的IPC结构。(如果IPC结构已存在,并且指定了IPC_CREAT,则IPC_CREAT什么都不做,函数也不出错)
IPC_EXCL: 此参数一般与IPC_CREAT配合使用来创建一个新的IPC结构。如果创建的IPC结构已存在函数就出错返回,
返回EEXIST(这与open函数指定O_CREAT和O_EXCL标志原理相同)
返回
int

在文件 vm_syscall.c129 行定义.

130{
131 int ret;
132
133 ret = ShmGet(key, size, shmflg);
134 if (ret < 0) {
135 return -get_errno();
136 }
137
138 return ret;
139}
INT32 ShmGet(key_t key, size_t size, INT32 shmflg)
ShmGet 得到一个共享内存标识符或创建一个共享内存对象
Definition: shm.c:515
函数调用图:

◆ SysShutdown()

int SysShutdown ( int  socket,
int  how 
)

在文件 net_syscall.c335 行定义.

336{
337 int ret;
338
339 SOCKET_U2K(socket);
340 ret = shutdown(socket, how);
341 if (ret == -1) {
342 return -get_errno();
343 }
344
345 return ret;
346}
int shutdown(int s, int how)
Definition: socket.c:124
函数调用图:

◆ SysSigAction()

int SysSigAction ( int  sig,
const sigaction_t *restrict  sa,
sigaction_t *restrict  old,
size_t  sigsetsize 
)

注册信号,鸿蒙内核只捕捉了SIGSYS 信号

在文件 ipc_syscall.c274 行定义.

275{
276 return OsSigAction(sig, sa, old);
277}
int OsSigAction(int sig, const sigaction_t *act, sigaction_t *oact)
Definition: los_signal.c:677
函数调用图:

◆ SysSigPending()

int SysSigPending ( sigset_t_l setl)

获取阻塞当前任务的信号集

在文件 ipc_syscall.c355 行定义.

356{
357 sigset_t set;
358 int ret;
359
360 ret = LOS_ArchCopyFromUser(&set, &(setl->sig[0]), sizeof(sigset_t));
361 if (ret != 0) {
362 return -EFAULT;
363 }
364 ret = OsSigPending(&set);
365 if (ret != LOS_OK) {
366 return ret;
367 }
368 ret = LOS_ArchCopyToUser(&(setl->sig[0]), &set, sizeof(sigset_t));
369 if (ret != LOS_OK) {
370 return -EFAULT;
371 }
372 return ret;
373}
int OsSigPending(sigset_t *set)
获取阻塞当前任务的信号集
Definition: los_signal.c:541
函数调用图:

◆ SysSigprocMask()

int SysSigprocMask ( int  how,
const sigset_t_l *restrict  setl,
sigset_t_l *restrict  oldl,
size_t  sigsetsize 
)

系统调用之进程信号屏蔽, 什么意思?简单说就是 一个信号来了进程要不要处理,屏蔽就是不处理,注意不能屏蔽SIGKILL和SIGSTOP信号,必须要处理.

参数
howSIG_BLOCK 加入信号到进程屏蔽。set包含了希望阻塞的附加信号
SIG_UNBLOCK 从进程屏蔽里将信号删除。set包含了希望解除阻塞的信号
SIG_SETMASK 将set的值设定为新的进程屏蔽
setl
oldl
sigsetsize
返回
int

在文件 ipc_syscall.c290 行定义.

291{
292 CHECK_ASPACE(setl, sizeof(sigset_t_l));
293 CHECK_ASPACE(oldl, sizeof(sigset_t_l));
294 CPY_FROM_USER(setl);
295 CPY_FROM_USER(oldl);
296 /* Let OsSigprocMask do all of the work */
297 int ret = OsSigprocMask(how, setl, oldl);
298 CPY_TO_USER(oldl);
299 return ret;
300}
函数调用图:

◆ SysSigSuspend()

int SysSigSuspend ( sigset_t_l setl)

在文件 ipc_syscall.c375 行定义.

376{
377 sigset_t set;
378 int retVal;
379
380 retVal = LOS_ArchCopyFromUser(&set, &(setl->sig[0]), sizeof(sigset_t));
381 if (retVal != 0) {
382 return -EFAULT;
383 }
384
385 return OsSigSuspend(&set);
386}
int OsSigSuspend(const sigset_t *set)
用参数set代替进程的原有掩码,并暂停进程执行,直到收到信号再恢复原有掩码并继续执行进程。
Definition: los_signal.c:627
函数调用图:

◆ SysSigTimedWait()

int SysSigTimedWait ( const sigset_t_l setl,
siginfo_t *  info,
const struct timespec *  timeout,
size_t  sigsetsize 
)

在文件 ipc_syscall.c312 行定义.

313{
314 sigset_t set;
315 unsigned int tick;
316 int retVal, ret;
317 siginfo_t infoIntr;
318 struct timespec timeoutIntr;
319
320 retVal = LOS_ArchCopyFromUser(&set, &(setl->sig[0]), sizeof(sigset_t));
321 if (retVal != 0) {
322 return -EFAULT;
323 }
324
325 if (timeout == NULL) {
326 tick = LOS_WAIT_FOREVER;
327 } else {
328 retVal = LOS_ArchCopyFromUser(&timeoutIntr, timeout, sizeof(struct timespec));
329 if (retVal != 0) {
330 return -EFAULT;
331 }
332 if (!ValidTimeSpec(&timeoutIntr)) {
333 return -EINVAL;
334 }
335 tick = OsTimeSpec2Tick(&timeoutIntr);
336 }
337 ret = OsSigTimedWait(&set, &infoIntr, tick);
338 if (ret < 0) {
339 return ret;
340 }
341 if (info != NULL) {
342 retVal = LOS_ArchCopyToUser(info, &infoIntr, sizeof(siginfo_t));
343 if (retVal != 0) {
344 return -EFAULT;
345 }
346 }
347 return (ret == 0 ? infoIntr.si_signo : ret);
348}
int OsSigTimedWait(sigset_t *set, siginfo_t *info, unsigned int timeout)
让当前任务等待的信号
Definition: los_signal.c:604
STATIC INLINE BOOL ValidTimeSpec(const struct timespec *tp)
Definition: time_posix.h:53
STATIC INLINE UINT32 OsTimeSpec2Tick(const struct timespec *tp)
Definition: time_posix.h:68
函数调用图:

◆ SysSocket()

int SysSocket ( int  domain,
int  type,
int  protocol 
)

在文件 net_syscall.c66 行定义.

67{
68 int ret;
69
70 ret = socket(domain, type, protocol);
71 if (ret == -1) {
72 return -get_errno();
73 }
74
75 SOCKET_K2U(ret);
76 return ret;
77}
函数调用图:

◆ SysStat()

int SysStat ( const char *  path,
struct kstat *  buf 
)

获取文件状态信息

在文件 fs_syscall.c1339 行定义.

1340{
1341 int ret;
1342 char *pathRet = NULL;
1343 struct stat bufRet = {0};
1344
1345 if (path != NULL) {
1346 ret = UserPathCopy(path, &pathRet);
1347 if (ret != 0) {
1348 goto OUT;
1349 }
1350 }
1351
1352 ret = stat((path ? pathRet : NULL), (buf ? (&bufRet) : NULL));
1353 if (ret < 0) {
1354 ret = -get_errno();
1355 goto OUT;
1356 }
1357
1358 ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct kstat));
1359 if (ret != 0) {
1360 ret = -EFAULT;
1361 }
1362
1363OUT:
1364 if (pathRet != NULL) {
1365 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
1366 }
1367 return ret;
1368}
函数调用图:

◆ SysStatfs()

int SysStatfs ( const char *  path,
struct statfs *  buf 
)

获取指定路径下文件的文件系统信息

在文件 fs_syscall.c1272 行定义.

1273{
1274 int ret;
1275 char *pathRet = NULL;
1276 struct statfs bufRet = {0};
1277
1278 if (path != NULL) {
1279 ret = UserPathCopy(path, &pathRet);
1280 if (ret != 0) {
1281 goto OUT;
1282 }
1283 }
1284
1285 ret = statfs((path ? pathRet : NULL), (buf ? (&bufRet) : NULL));
1286 if (ret < 0) {
1287 ret = -get_errno();
1288 goto OUT;
1289 }
1290
1291 ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct statfs));
1292 if (ret != 0) {
1293 ret = -EFAULT;
1294 }
1295
1296OUT:
1297 if (pathRet != NULL) {
1298 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
1299 }
1300 return ret;
1301}
函数调用图:

◆ SysStatfs64()

int SysStatfs64 ( const char *  path,
size_t  sz,
struct statfs *  buf 
)

获取文件系统信息

在文件 fs_syscall.c1303 行定义.

1304{
1305 int ret;
1306 char *pathRet = NULL;
1307 struct statfs bufRet = {0};
1308
1309 if (path != NULL) {
1310 ret = UserPathCopy(path, &pathRet);
1311 if (ret != 0) {
1312 goto OUT;
1313 }
1314 }
1315
1316 if (sz != sizeof(*buf)) {
1317 ret = -EINVAL;
1318 goto OUT;
1319 }
1320
1321 ret = statfs((path ? pathRet : NULL), (buf ? (&bufRet) : NULL));
1322 if (ret < 0) {
1323 ret = -get_errno();
1324 goto OUT;
1325 }
1326
1327 ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct statfs));
1328 if (ret != 0) {
1329 ret = -EFAULT;
1330 }
1331
1332OUT:
1333 if (pathRet != NULL) {
1334 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
1335 }
1336 return ret;
1337}
函数调用图:

◆ SysStatx()

int SysStatx ( int  fd,
const char *restrict  path,
int  flag,
unsigned  mask,
struct statx *restrict  stx 
)

在文件 fs_syscall.c1432 行定义.

1433{
1434 return -ENOSYS;
1435}

◆ SysSymlink()

int SysSymlink ( const char *  target,
const char *  linkpath 
)

在文件 fs_syscall.c474 行定义.

475{
476 int ret;
477 char *targetRet = NULL;
478 char *pathRet = NULL;
479
480 if (target != NULL) {
481 ret = UserPathCopy(target, &targetRet);
482 if (ret != 0) {
483 goto OUT;
484 }
485 }
486
487 if (linkpath != NULL) {
488 ret = UserPathCopy(linkpath, &pathRet);
489 if (ret != 0) {
490 goto OUT;
491 }
492 }
493
494 ret = symlink(targetRet, pathRet);
495 if (ret < 0) {
496 ret = -get_errno();
497 }
498
499OUT:
500 if (pathRet != NULL) {
501 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
502 }
503
504 if (targetRet != NULL) {
505 (void)LOS_MemFree(OS_SYS_MEM_ADDR, targetRet);
506 }
507 return ret;
508}
函数调用图:

◆ SysSymlinkat()

int SysSymlinkat ( const char *  target,
int  dirfd,
const char *  linkpath 
)

在文件 fs_syscall.c1915 行定义.

1916{
1917 int ret;
1918 char *pathRet = NULL;
1919 char *targetRet = NULL;
1920
1921 if (target != NULL) {
1922 ret = UserPathCopy(target, &targetRet);
1923 if (ret != 0) {
1924 goto OUT;
1925 }
1926 }
1927
1928 if (linkpath != NULL) {
1929 ret = UserPathCopy(linkpath, &pathRet);
1930 if (ret != 0) {
1931 goto OUT;
1932 }
1933 }
1934
1935 if (dirfd != AT_FDCWD) {
1936 /* Process fd convert to system global fd */
1937 dirfd = GetAssociatedSystemFd(dirfd);
1938 }
1939
1940 ret = symlinkat(targetRet, dirfd, pathRet);
1941 if (ret < 0) {
1942 ret = -get_errno();
1943 }
1944
1945OUT:
1946 if (pathRet != NULL) {
1947 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
1948 }
1949
1950 if (targetRet != NULL) {
1951 (void)LOS_MemFree(OS_SYS_MEM_ADDR, targetRet);
1952 }
1953 return ret;
1954}
函数调用图:

◆ SysSync()

void SysSync ( void  )

将内存缓冲区数据写回硬盘

在文件 syscall_lookup.h62 行定义.

◆ SysSysconf()

long SysSysconf ( int  name)

系统配置

在文件 misc_syscall.c198 行定义.

199{
200 long ret;
201
202 ret = sysconf(name);
203 if (ret == -1) {
204 return -get_errno();
205 }
206
207 return ret;
208}
long sysconf(int name)
Definition: misc.c:82
函数调用图:

◆ SysThreadExit()

void SysThreadExit ( int  status)

在文件 process_syscall.c1005 行定义.

1006{
1007 OsRunningTaskToExit(OsCurrTaskGet(), (unsigned int)status);
1008}
LITE_OS_SEC_TEXT VOID OsRunningTaskToExit(LosTaskCB *runTask, UINT32 status)
Definition: los_task.c:908
函数调用图:

◆ SysThreadJoin()

int SysThreadJoin ( unsigned int  taskID)

在文件 process_syscall.c976 行定义.

977{
978 unsigned int intSave;
979 int ret;
980
981 if (OS_TID_CHECK_INVALID(taskID)) {
982 return EINVAL;
983 }
984
985 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
986 SCHEDULER_LOCK(intSave);
988 if (ret != LOS_OK) {
989 goto EXIT;
990 }
991
992 ret = (int)OsTaskJoinPendUnsafe(OS_TCB_FROM_TID(taskID));
993
994EXIT:
995 SCHEDULER_UNLOCK(intSave);
996 return ret;
997}
LITE_OS_SEC_TEXT UINT32 OsTaskJoinPendUnsafe(LosTaskCB *taskCB)
挂起任务,任务进入等待链表,Join代表是支持通过一个任务去唤醒其他的任务
Definition: los_task.c:224
函数调用图:

◆ SysTime()

time_t SysTime ( time_t *  tloc)

在文件 time_syscall.c90 行定义.

91{
92 int ret;
93 time_t stloc;
94
95 ret = time(tloc ? &stloc : NULL);
96 if (ret < 0) {
97 return -get_errno();
98 }
99
100 if (tloc && LOS_ArchCopyToUser(tloc, &stloc, sizeof(time_t))) {
101 errno = EFAULT;
102 ret = -EFAULT;
103 }
104
105 return ret;
106}
函数调用图:

◆ SysTimerCreate()

int SysTimerCreate ( clockid_t  clockID,
struct ksigevent evp,
timer_t *  timerID 
)

在文件 time_syscall.c160 行定义.

161{
162 int ret;
163 timer_t stimerID;
164 struct ksigevent ksevp;
165
166 if (timerID == NULL) {
167 errno = EINVAL;
168 return -EINVAL;
169 }
170
171 if (evp && LOS_ArchCopyFromUser(&ksevp, evp, sizeof(struct ksigevent))) {
172 errno = EFAULT;
173 return -EFAULT;
174 }
175
176 ret = OsTimerCreate(clockID, evp ? &ksevp : NULL, &stimerID);
177 if (ret < 0) {
178 return -get_errno();
179 }
180
181 if (LOS_ArchCopyToUser(timerID, &stimerID, sizeof(timer_t))) {
182 errno = EFAULT;
183 return -EFAULT;
184 }
185
186 return ret;
187}
int OsTimerCreate(clockid_t, struct ksigevent *__restrict, timer_t *__restrict)
Definition: time.c:842
函数调用图:

◆ SysTimerDelete()

int SysTimerDelete ( timer_t  timerID)

在文件 time_syscall.c252 行定义.

253{
254 int ret;
255
256 ret = timer_delete(timerID);
257 if (ret < 0) {
258 return -get_errno();
259 }
260 return ret;
261}
int timer_delete(timer_t timerID)
Definition: time.c:897
函数调用图:

◆ SysTimerGetoverrun()

int SysTimerGetoverrun ( timer_t  timerID)

在文件 time_syscall.c241 行定义.

242{
243 int ret;
244
245 ret = timer_getoverrun(timerID);
246 if (ret < 0) {
247 return -get_errno();
248 }
249 return ret;
250}
int timer_getoverrun(timer_t timerID)
Definition: time.c:1024
函数调用图:

◆ SysTimerGettime()

int SysTimerGettime ( timer_t  timerID,
struct itimerspec *  value 
)

在文件 time_syscall.c189 行定义.

190{
191 int ret;
192 struct itimerspec svalue;
193
194 if (value == NULL) {
195 errno = EINVAL;
196 return -EINVAL;
197 }
198
199 ret = timer_gettime(timerID, &svalue);
200 if (ret < 0) {
201 return -get_errno();
202 }
203
204 if (LOS_ArchCopyToUser(value, &svalue, sizeof(struct itimerspec))) {
205 errno = EFAULT;
206 return -EFAULT;
207 }
208
209 return ret;
210}
int timer_gettime(timer_t timerID, struct itimerspec *value)
Definition: time.c:995
函数调用图:

◆ SysTimerGettime64()

int SysTimerGettime64 ( timer_t  timerID,
struct itimerspec64 *  value 
)

在文件 time_syscall.c524 行定义.

525{
526 int ret;
527 struct itimerspec val;
528 struct itimerspec64 svalue;
529
530 if (value == NULL) {
531 errno = EINVAL;
532 return -EINVAL;
533 }
534
535 ret = timer_gettime(timerID, &val);
536 if (ret < 0) {
537 return -get_errno();
538 }
539
540 svalue.it_interval.tv_sec = val.it_interval.tv_sec;
541 svalue.it_interval.tv_nsec = val.it_interval.tv_nsec;
542 svalue.it_value.tv_sec = val.it_value.tv_sec;
543 svalue.it_value.tv_nsec = val.it_value.tv_nsec;
544
545 if (LOS_ArchCopyToUser(value, &svalue, sizeof(struct itimerspec64))) {
546 errno = EFAULT;
547 return -EFAULT;
548 }
549
550 return ret;
551}
函数调用图:

◆ SysTimerSettime()

int SysTimerSettime ( timer_t  timerID,
int  flags,
const struct itimerspec *  value,
struct itimerspec *  oldValue 
)

在文件 time_syscall.c212 行定义.

213{
214 int ret;
215 struct itimerspec svalue;
216 struct itimerspec soldValue;
217
218 if (value == NULL) {
219 errno = EINVAL;
220 return -EINVAL;
221 }
222
223 if (LOS_ArchCopyFromUser(&svalue, value, sizeof(struct itimerspec))) {
224 errno = EFAULT;
225 return -EFAULT;
226 }
227
228 ret = timer_settime(timerID, flags, &svalue, &soldValue);
229 if (ret < 0) {
230 return -get_errno();
231 }
232
233 if (oldValue && LOS_ArchCopyToUser(oldValue, &soldValue, sizeof(struct itimerspec))) {
234 errno = EFAULT;
235 return -EFAULT;
236 }
237
238 return ret;
239}
int timer_settime(timer_t timerID, int flags, const struct itimerspec *value, struct itimerspec *oldValue)
Definition: time.c:929
函数调用图:

◆ SysTimerSettime64()

int SysTimerSettime64 ( timer_t  timerID,
int  flags,
const struct itimerspec64 *  value,
struct itimerspec64 *  oldValue 
)

在文件 time_syscall.c553 行定义.

554{
555 int ret;
556 struct itimerspec val;
557 struct itimerspec oldVal;
558 struct itimerspec64 svalue;
559 struct itimerspec64 soldValue;
560
561 if (value == NULL) {
562 errno = EINVAL;
563 return -EINVAL;
564 }
565
566 if (LOS_ArchCopyFromUser(&svalue, value, sizeof(struct itimerspec64))) {
567 errno = EFAULT;
568 return -EFAULT;
569 }
570
571 if (svalue.it_interval.tv_sec > UINT32_MAX || svalue.it_value.tv_sec > UINT32_MAX) {
572 errno = ENOSYS;
573 return -ENOSYS;
574 }
575
576 val.it_interval.tv_sec = svalue.it_interval.tv_sec;
577 val.it_interval.tv_nsec = svalue.it_interval.tv_nsec;
578 val.it_value.tv_sec = svalue.it_value.tv_sec;
579 val.it_value.tv_nsec = svalue.it_value.tv_nsec;
580
581 ret = timer_settime(timerID, flags, &val, oldValue ? &oldVal : NULL);
582 if (ret < 0) {
583 return -get_errno();
584 }
585
586 if (oldValue != NULL) {
587 soldValue.it_interval.tv_sec = oldVal.it_interval.tv_sec;
588 soldValue.it_interval.tv_nsec = oldVal.it_interval.tv_nsec;
589 soldValue.it_value.tv_sec = oldVal.it_value.tv_sec;
590 soldValue.it_value.tv_nsec = oldVal.it_value.tv_nsec;
591
592 if (LOS_ArchCopyToUser(oldValue, &soldValue, sizeof(struct itimerspec64))) {
593 errno = EFAULT;
594 return -EFAULT;
595 }
596 }
597
598 return ret;
599}
函数调用图:

◆ SysTimes()

clock_t SysTimes ( struct tms *  buf)

在文件 time_syscall.c384 行定义.

385{
386 clock_t ret;
387 struct tms sbuf;
388
389 if (buf == NULL) {
390 errno = EFAULT;
391 return -EFAULT;
392 }
393 ret = times(&sbuf);
394 if (ret == -1) {
395 return -get_errno();
396 }
397 if (LOS_ArchCopyToUser(buf, &sbuf, sizeof(struct tms))) {
398 errno = EFAULT;
399 return -EFAULT;
400 }
401
402 return ret;
403}
函数调用图:

◆ SysTruncate()

int SysTruncate ( const char *  path,
off_t  length 
)

系统调用|文件系统|截断功能

在文件 fs_syscall.c1192 行定义.

1193{
1194 int ret;
1195 int fd = -1;
1196 char *pathRet = NULL;
1197
1198 if (path != NULL) {
1199 ret = UserPathCopy(path, &pathRet);
1200 if (ret != 0) {
1201 goto OUT;
1202 }
1203 }
1204
1205 fd = open((path ? pathRet : NULL), O_RDWR);
1206 if (fd < 0) {
1207 /* The errno value has already been set */
1208 ret = -get_errno();
1209 goto OUT;
1210 }
1211
1212 ret = ftruncate(fd, length);
1213 close(fd);
1214 if (ret < 0) {
1215 ret = -get_errno();
1216 }
1217
1218OUT:
1219 if (pathRet != NULL) {
1220 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
1221 }
1222 return ret;
1223}
函数调用图:

◆ SysTruncate64()

int SysTruncate64 ( const char *  path,
off64_t  length 
)

系统调用|文件系统|截断功能

在文件 fs_syscall.c1225 行定义.

1226{
1227 int ret;
1228 int fd = -1;
1229 char *pathRet = NULL;
1230
1231 if (path != NULL) {
1232 ret = UserPathCopy(path, &pathRet);
1233 if (ret != 0) {
1234 goto OUT;
1235 }
1236 }
1237
1238 fd = open((path ? pathRet : NULL), O_RDWR);
1239 if (fd < 0) {
1240 /* The errno value has already been set */
1241 ret = -get_errno();
1242 goto OUT;
1243 }
1244
1245 ret = ftruncate64(fd, length);
1246 close(fd);
1247 if (ret < 0) {
1248 ret = -get_errno();
1249 }
1250
1251OUT:
1252 if (pathRet != NULL) {
1253 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
1254 }
1255 return ret;
1256}
函数调用图:

◆ SysUgetrlimit()

int SysUgetrlimit ( int  resource,
unsigned long long  k_rlim[2] 
)

在文件 misc_syscall.c210 行定义.

211{
212 int ret;
213 struct rlimit lim;
214
215 ret = getrlimit(resource, &lim);
216 if (ret < 0) {
217 return ret;
218 }
219
220 ret = LOS_ArchCopyToUser(k_rlim, &lim, sizeof(struct rlimit));
221 if (ret != 0) {
222 return -EFAULT;
223 }
224
225 return ret;
226}
int getrlimit(int resource, struct rlimit *rlim)
获取当前进程资源限制。
Definition: misc.c:155
函数调用图:

◆ SysUmask()

int SysUmask ( int  mask)

◆ SysUmount()

int SysUmount ( const char *  target)

卸载文件系统,当某个文件系统不需要再使用了,那么可以将它卸载掉。

在文件 fs_syscall.c734 行定义.

735{
736 int ret;
737 char *pathRet = NULL;
738
739 if (!IsCapPermit(CAP_FS_MOUNT)) {
740 return -EPERM;
741 }
742
743 if (target != NULL) {
744 ret = UserPathCopy(target, &pathRet);
745 if (ret != 0) {
746 goto OUT;
747 }
748 }
749
750 ret = umount(target ? pathRet : NULL);
751 if (ret < 0) {
752 ret = -get_errno();
753 }
754
755OUT:
756 if (pathRet != NULL) {
757 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
758 }
759 return ret;
760}
函数调用图:
这是这个函数的调用关系图:

◆ SysUmount2()

int SysUmount2 ( const char *  target,
int  flags 
)

卸载文件系统

在文件 fs_syscall.c894 行定义.

895{
896 if (flags != 0) {
897 return -EINVAL;
898 }
899 return SysUmount(target);
900}
int SysUmount(const char *target)
卸载文件系统,当某个文件系统不需要再使用了,那么可以将它卸载掉。
Definition: fs_syscall.c:734
函数调用图:

◆ SysUname()

int SysUname ( struct utsname *  name)

在文件 misc_syscall.c52 行定义.

53{
54 int ret;
55 struct utsname tmpName;
56 ret = LOS_ArchCopyFromUser(&tmpName, name, sizeof(struct utsname));
57 if (ret != 0) {
58 return -EFAULT;
59 }
60 ret = uname(&tmpName);
61 if (ret < 0) {
62 return ret;
63 }
64 ret = LOS_ArchCopyToUser(name, &tmpName, sizeof(struct utsname));
65 if (ret != 0) {
66 return -EFAULT;
67 }
68 return ret;
69}
int uname(struct utsname *name)
Definition: misc.c:55
函数调用图:

◆ SysUnlink()

int SysUnlink ( const char *  pathname)

删除链:删除由装入点管理的文件

   执行unlink()函数并不一定会真正的删除文件,它先会检查文件系统中此文件的连接数是否为1,
   如果不是1说明此文件还有其他链接对象,因此只对此文件的连接数进行减1操作。若连接数为1,
   并且在此时没有任何进程打开该文件,此内容才会真正地被删除掉。在有进程打开此文件的情况下,
   则暂时不会删除,直到所有打开该文件的进程都结束时文件就会被删除。
* 

在文件 fs_syscall.c519 行定义.

520{
521 int ret;
522 char *pathRet = NULL;
523
524 if (pathname != NULL) {
525 ret = UserPathCopy(pathname, &pathRet);
526 if (ret != 0) {
527 goto OUT;
528 }
529 }
530 //删除由装入点管理的文件
531 ret = do_unlink(AT_FDCWD, (pathname ? pathRet : NULL));
532 if (ret < 0) {
533 ret = -get_errno();
534 }
535
536OUT:
537 if (pathRet != NULL) {
538 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
539 }
540 return ret;
541}
int do_unlink(int dirfd, const char *pathname)
函数调用图:

◆ SysUnlinkat()

int SysUnlinkat ( int  dirfd,
const char *  pathname,
int  flag 
)

在文件 fs_syscall.c1994 行定义.

1995{
1996 int ret;
1997 char *pathRet = NULL;
1998
1999 if (pathname != NULL) {
2000 ret = UserPathCopy(pathname, &pathRet);
2001 if (ret != 0) {
2002 goto OUT;
2003 }
2004 }
2005
2006 if (dirfd != AT_FDCWD) {
2007 /* Process fd convert to system global fd */
2008 dirfd = GetAssociatedSystemFd(dirfd);
2009 }
2010
2011 ret = unlinkat(dirfd, (pathname ? pathRet : NULL), flag);
2012 if (ret < 0) {
2013 ret = -get_errno();
2014 }
2015
2016OUT:
2017 if (pathRet != NULL) {
2018 (void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
2019 }
2020 return ret;
2021}
函数调用图:

◆ SysUserExitGroup()

void SysUserExitGroup ( int  status)

在文件 process_syscall.c999 行定义.

1000{
1001 (void)status;
1003}
LITE_OS_SEC_TEXT VOID OsProcessThreadGroupDestroy(VOID)
Definition: los_process.c:2200
函数调用图:

◆ SysUserThreadDetach()

int SysUserThreadDetach ( unsigned int  taskID)

在文件 process_syscall.c953 行定义.

954{
955 unsigned int intSave;
956 int ret;
957
958 if (OS_TID_CHECK_INVALID(taskID)) {
959 return EINVAL;
960 }
961
962 SCHEDULER_LOCK(intSave);
963 ret = OsUserTaskOperatePermissionsCheck(OS_TCB_FROM_TID(taskID));
964 SCHEDULER_UNLOCK(intSave);
965 if (ret != LOS_OK) {
966 return ret;
967 }
968
969 if (LOS_TaskDelete(taskID) != LOS_OK) {
970 return ESRCH;
971 }
972
973 return LOS_OK;
974}
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
Delete a task.
Definition: los_task.c:968
函数调用图:

◆ SysUserThreadSetDetach()

int SysUserThreadSetDetach ( unsigned int  taskID)

在文件 process_syscall.c930 行定义.

931{
932 unsigned int intSave;
933 int ret;
934
935 if (OS_TID_CHECK_INVALID(taskID)) {
936 return EINVAL;
937 }
938
939 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
940 SCHEDULER_LOCK(intSave);
942 if (ret != LOS_OK) {
943 goto EXIT;
944 }
945
946 ret = (int)OsTaskSetDetachUnsafe(taskCB);
947
948EXIT:
949 SCHEDULER_UNLOCK(intSave);
950 return ret;
951}
LITE_OS_SEC_TEXT UINT32 OsTaskSetDetachUnsafe(LosTaskCB *taskCB)
任务设置分离模式 Deatch和JOIN是一对有你没我的状态
Definition: los_task.c:243
函数调用图:

◆ SysUtime()

int SysUtime ( const char *  path,
const struct utimbuf *  ptimes 
)

在文件 time_syscall.c45 行定义.

46{
47 int ret;
48 char *spath = NULL;
49 struct utimbuf sptimes;
50
51 if (path == NULL) {
52 errno = EINVAL;
53 return -EINVAL;
54 }
55
56 spath = LOS_MemAlloc(m_aucSysMem0, PATH_MAX + 1);
57 if (spath == NULL) {
58 errno = ENOMEM;
59 return -ENOMEM;
60 }
61
62 ret = LOS_StrncpyFromUser(spath, path, PATH_MAX + 1);
63 if (ret == -EFAULT) {
65 return ret;
66 } else if (ret > PATH_MAX) {
68 PRINT_ERR("%s[%d], path exceeds maxlen: %d\n", __FUNCTION__, __LINE__, PATH_MAX);
69 return -ENAMETOOLONG;
70 }
71 spath[ret] = '\0';
72
73 if (ptimes && LOS_ArchCopyFromUser(&sptimes, ptimes, sizeof(struct utimbuf))) {
75 errno = EFAULT;
76 return -EFAULT;
77 }
78
79 ret = utime(spath, ptimes ? &sptimes : NULL);
80 if (ret < 0) {
81 ret = -get_errno();
82 }
83
85
86 return ret;
87}
UINT8 * m_aucSysMem0
异常交互动态内存池地址的起始地址,当不支持异常交互特性时,m_aucSysMem0等于m_aucSysMem1。
Definition: los_memory.c:107
int utime(const char *path, const struct utimbuf *ptimes)
Definition: vfs_utime.c:50
函数调用图:

◆ SysUtimensat()

int SysUtimensat ( int  fd,
const char *  path,
struct timespec  times[2],
int  flag 
)

◆ SysVfork()

int SysVfork ( void  )

在文件 syscall_lookup.h141 行定义.

函数调用图:

◆ SysWait()

int SysWait ( int  pid,
USER int status,
int  options,
void rusage 
)

在文件 process_syscall.c307 行定义.

308{
309 (void)rusage;
310
311 return LOS_Wait(pid, status, (unsigned int)options, NULL);
312}
LITE_OS_SEC_TEXT INT32 LOS_Wait(INT32 pid, USER INT32 *status, UINT32 options, VOID *rusage)
Definition: los_process.c:1313
函数调用图:

◆ SysWaitid()

int SysWaitid ( idtype_t  type,
int  pid,
USER siginfo_t *  info,
int  options,
void rusage 
)

在文件 process_syscall.c314 行定义.

315{
316 (void)rusage;
317 int ret;
318 int truepid = 0;
319
320 switch (type) {
321 case P_ALL:
322 /* Wait for any child; id is ignored. */
323 truepid = -1;
324 break;
325 case P_PID:
326 /* Wait for the child whose process ID matches id */
327 if (pid <= 0) {
328 return -EINVAL;
329 }
330 truepid = pid;
331 break;
332 case P_PGID:
333 /* Wait for any child whose process group ID matches id */
334 if (pid <= 1) {
335 return -EINVAL;
336 }
337 truepid = -pid;
338 break;
339 default:
340 return -EINVAL;
341 }
342
343 ret = LOS_Waitid(truepid, info, (unsigned int)options, NULL);
344 if (ret > 0) {
345 ret = 0;
346 }
347 return ret;
348}
LITE_OS_SEC_TEXT INT32 LOS_Waitid(INT32 pid, USER siginfo_t *info, UINT32 options, VOID *rusage)
Definition: los_process.c:1350
函数调用图:

◆ SysWrite()

ssize_t SysWrite ( int  fd,
const void buf,
size_t  nbytes 
)

系统调用|写文件:将buf中(用户空间)nbytes长度的内容写到文件中

在文件 fs_syscall.c273 行定义.

274{
275 int ret;
276
277 if (nbytes == 0) {
278 return 0;
279 }
280 //[buf,buf+nbytes]地址必须在用户空间
281 if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buf, nbytes)) {
282 return -EFAULT;
283 }
284
285 /* Process fd convert to system global fd */
286 int sysfd = GetAssociatedSystemFd(fd);
287 ret = write(sysfd, buf, nbytes);
288 if (ret < 0) {
289 return -get_errno();
290 }
291 return ret;
292}
函数调用图:

◆ SysWritev()

ssize_t SysWritev ( int  fd,
const struct iovec *  iov,
int  iovcnt 
)

将缓冲数组里的数据写入文件

在文件 fs_syscall.c1500 行定义.

1501{
1502 int ret;
1503 int valid_iovcnt = -1;
1504 struct iovec *iovRet = NULL;
1505
1506 /* Process fd convert to system global fd */
1507 int sysfd = GetAssociatedSystemFd(fd);
1508 if ((iovcnt < 0) || (iovcnt > IOV_MAX)) {
1509 return -EINVAL;
1510 }
1511
1512 if (iovcnt == 0) {
1513 return 0;
1514 }
1515
1516 if (iov == NULL) {
1517 return -EFAULT;
1518 }
1519
1520 ret = UserIovCopy(&iovRet, iov, iovcnt, &valid_iovcnt);
1521 if (ret != 0) {
1522 return ret;
1523 }
1524
1525 if (valid_iovcnt != iovcnt) {
1526 ret = -EFAULT;
1527 goto OUT_FREE;
1528 }
1529
1530 ret = writev(sysfd, iovRet, valid_iovcnt);
1531 if (ret < 0) {
1532 ret = -get_errno();
1533 }
1534
1535OUT_FREE:
1536 (void)LOS_MemFree(OS_SYS_MEM_ADDR, iovRet);
1537 return ret;
1538}
ssize_t writev(int fd, const struct iovec *iov, int iovcnt)
Definition: vfs_writev.c:136
函数调用图: