更新日期: 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 
)

系统调用|申请虚拟内存(分配线性地址区间) <