我看到所有系统调用(比如x)都与另一个叫做sys_x()的调用相关联: 例如:fork和sys_fork(),open()和sys_open()等。
这些sys_x()调用的意义是什么?我们在哪里可以使用这些调用?
我看到所有系统调用(比如x)都与另一个叫做sys_x()的调用相关联: 例如:fork和sys_fork(),open()和sys_open()等。
这些sys_x()调用的意义是什么?我们在哪里可以使用这些调用?
sys_fork()
会很有用的例子。fork()
,而是直接发出系统调用:#if !defined (HOST_WIN32)
/**
* fork_crash_safe:
*
* Version of \c fork that is safe to call from an async context such as a
* signal handler even if the process crashed inside libc.
*
* Returns 0 to the child process, >0 to the parent process or <0 on error.
*/
static pid_t
fork_crash_safe (void)
{
pid_t pid;
/*
* glibc fork acquires some locks, so if the crash happened inside malloc/free,
* it will deadlock. Call the syscall directly instead.
*/
#if defined(HOST_ANDROID)
/* SYS_fork is defined to be __NR_fork which is not defined in some ndk versions */
g_assert_not_reached ();
#elif !defined(HOST_DARWIN) && defined(SYS_fork)
pid = (pid_t) syscall (SYS_fork);
#elif HAVE_FORK
pid = (pid_t) fork ();
#else
g_assert_not_reached ();
#endif
return pid;
}
#endif