Files
qse/qse/lib/cmn/syscall.h

602 lines
18 KiB
C
Raw Normal View History

2009-03-11 04:39:18 +00:00
/*
2012-08-16 03:47:55 +00:00
* $Id$
2009-03-11 04:39:18 +00:00
*
2013-12-31 10:24:12 +00:00
Copyright 2006-2014 Chung, Hyung-Hwan.
2009-09-16 04:01:02 +00:00
This file is part of QSE.
2009-03-11 04:39:18 +00:00
2009-09-16 04:01:02 +00:00
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
2009-03-11 04:39:18 +00:00
2009-09-16 04:01:02 +00:00
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
2009-03-11 04:39:18 +00:00
2009-09-16 04:01:02 +00:00
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
2009-03-11 04:39:18 +00:00
*/
2008-12-31 00:08:03 +00:00
#ifndef _QSE_LIB_CMN_SYSCALL_H_
#define _QSE_LIB_CMN_SYSCALL_H_
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# error Do not include this file
#endif
2009-01-05 07:38:55 +00:00
/* This file defines unix/linux system calls */
2012-09-11 16:19:52 +00:00
#if defined(HAVE_SYS_TYPES_H)
2009-02-24 21:57:28 +00:00
# include <sys/types.h>
2009-01-05 07:38:55 +00:00
#endif
2012-09-11 16:19:52 +00:00
#if defined(HAVE_UNISTD_H)
2009-02-24 21:57:28 +00:00
# include <unistd.h>
2008-12-31 00:08:03 +00:00
#endif
2012-09-11 16:19:52 +00:00
#if defined(HAVE_SYS_WAIT_H)
2009-02-24 21:57:28 +00:00
# include <sys/wait.h>
2009-01-05 07:38:55 +00:00
#endif
2012-09-11 16:19:52 +00:00
#if defined(HAVE_SIGNAL_H)
2009-02-24 21:57:28 +00:00
# include <signal.h>
#endif
2012-09-11 16:19:52 +00:00
#if defined(HAVE_ERRNO_H)
2009-02-24 21:57:28 +00:00
# include <errno.h>
2009-01-27 09:26:15 +00:00
#endif
2012-09-11 16:19:52 +00:00
#if defined(HAVE_FCNTL_H)
2012-02-12 13:20:39 +00:00
# include <fcntl.h>
#endif
2012-09-11 16:19:52 +00:00
#if defined(HAVE_TIME_H)
2009-06-07 23:03:44 +00:00
# include <time.h>
#endif
2012-09-11 16:19:52 +00:00
#if defined(HAVE_SYS_TIME_H)
2009-06-07 23:03:44 +00:00
# include <sys/time.h>
#endif
2012-09-11 16:19:52 +00:00
#if defined(HAVE_UTIME_H)
2009-06-09 07:09:01 +00:00
# include <utime.h>
#endif
2012-09-11 16:19:52 +00:00
#if defined(HAVE_SYS_RESOURCE_H)
# include <sys/resource.h>
#endif
2012-09-11 16:19:52 +00:00
#if defined(HAVE_SYS_STAT_H)
2010-07-29 07:27:03 +00:00
# include <sys/stat.h>
#endif
2012-09-11 16:19:52 +00:00
#if defined(HAVE_DIRENT_H)
# include <dirent.h>
#endif
2008-12-31 00:08:03 +00:00
#if defined(QSE_USE_SYSCALL) && defined(HAVE_SYS_SYSCALL_H)
2009-02-24 21:57:28 +00:00
# include <sys/syscall.h>
2008-12-31 00:08:03 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_open) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_OPEN(path,flags,mode) syscall(SYS_open,path,flags,mode)
2008-12-31 00:08:03 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_OPEN(path,flags,mode) open(path,flags,mode)
2008-12-31 00:08:03 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_close) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_CLOSE(handle) syscall(SYS_close,handle)
2008-12-31 00:08:03 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_CLOSE(handle) close(handle)
2008-12-31 00:08:03 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_read) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_READ(handle,buf,size) syscall(SYS_read,handle,buf,size)
2008-12-31 00:08:03 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_READ(handle,buf,size) read(handle,buf,size)
2008-12-31 00:08:03 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_write) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_WRITE(handle,buf,size) syscall(SYS_write,handle,buf,size)
2008-12-31 00:08:03 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_WRITE(handle,buf,size) write(handle,buf,size)
2008-12-31 00:08:03 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(SYS__llseek) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_LLSEEK(handle,hoffset,loffset,out,whence) syscall(SYS__llseek,handle,hoffset,loffset,out,whence)
2012-09-18 13:03:57 +00:00
#elif !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(HAVE__LLSEEK) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_LLSEEK(handle,hoffset,loffset,out,whence) _llseek(handle,hoffset,loffset,out,whence)
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(SYS_lseek64) && defined(QSE_USE_SYSCALL)
# define QSE_LSEEK(handle,offset,whence) syscall(SYS_lseek64,handle,offset,whence)
2012-09-18 13:03:57 +00:00
#elif defined(SYS_lseek) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_LSEEK(handle,offset,whence) syscall(SYS_lseek,handle,offset,whence)
2012-01-11 14:28:59 +00:00
#elif !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(HAVE_LSEEK64)
# define QSE_LSEEK(handle,offset,whence) lseek64(handle,offset,whence)
2009-01-05 07:38:55 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_LSEEK(handle,offset,whence) lseek(handle,offset,whence)
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(SYS_fstat64) && defined(QSE_USE_SYSCALL)
2012-02-02 14:48:06 +00:00
# define QSE_FSTAT(handle,stbuf) syscall(SYS_fstat64,handle,stbuf)
typedef struct stat64 qse_fstat_t;
2012-09-18 13:03:57 +00:00
#elif defined(SYS_fstat) && defined(QSE_USE_SYSCALL)
2012-02-02 14:48:06 +00:00
# define QSE_FSTAT(handle,stbuf) syscall(SYS_fstat,handle,stbuf)
typedef struct stat qse_fstat_t;
2012-01-11 14:28:59 +00:00
#elif !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(HAVE_FSTAT64)
2012-02-02 14:48:06 +00:00
# define QSE_FSTAT(handle,stbuf) fstat64(handle,stbuf)
typedef struct stat64 qse_fstat_t;
#else
2012-02-02 14:48:06 +00:00
# define QSE_FSTAT(handle,stbuf) fstat(handle,stbuf)
typedef struct stat qse_fstat_t;
#endif
2012-09-18 13:03:57 +00:00
#if !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(SYS_ftruncate64) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_FTRUNCATE(handle,size) syscall(SYS_ftruncate64,handle,size)
2012-09-18 13:03:57 +00:00
#elif defined(SYS_ftruncate) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_FTRUNCATE(handle,size) syscall(SYS_ftruncate,handle,size)
2012-01-11 14:28:59 +00:00
#elif !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(HAVE_FTRUNCATE64)
2009-02-24 21:57:28 +00:00
# define QSE_FTRUNCATE(handle,size) ftruncate64(handle,size)
2008-12-31 00:08:03 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_FTRUNCATE(handle,size) ftruncate(handle,size)
2008-12-31 00:08:03 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_fchmod) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_FCHMOD(handle,mode) syscall(SYS_fchmod,handle,mode)
2009-01-05 07:38:55 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_FCHMOD(handle,mode) fchmod(handle,mode)
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_fchown) && defined(QSE_USE_SYSCALL)
# define QSE_FCHOWN(handle,owner,group) syscall(SYS_fchown,handle,owner,group)
#else
# define QSE_FCHOWN(handle,owner,group) fchown(handle,owner,group)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_fsync) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_FSYNC(handle) syscall(SYS_fsync,handle)
2009-01-19 08:32:51 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_FSYNC(handle) fsync(handle)
2009-01-19 08:32:51 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_fcntl) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_FCNTL(handle,cmd,arg) syscall(SYS_fcntl,handle,cmd,arg)
2009-01-19 08:32:51 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_FCNTL(handle,cmd,arg) fcntl(handle,cmd,arg)
2009-01-19 08:32:51 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_dup2) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_DUP2(ofd,nfd) syscall(SYS_dup2,ofd,nfd)
2009-01-05 07:38:55 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_DUP2(ofd,nfd) dup2(ofd,nfd)
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_pipe) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_PIPE(pfds) syscall(SYS_pipe,pfds)
2009-01-05 07:38:55 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_PIPE(pfds) pipe(pfds)
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_exit) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_EXIT(code) syscall(SYS_exit,code)
2009-01-05 07:38:55 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_EXIT(code) _exit(code)
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_fork) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_FORK() syscall(SYS_fork)
2008-12-31 00:08:03 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_FORK() fork()
2008-12-31 00:08:03 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_vfork) && defined(QSE_USE_SYSCALL)
# define QSE_VFORK() syscall(SYS_vfork)
#else
# define QSE_VFORK() vfork()
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_execve) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_EXECVE(path,argv,envp) syscall(SYS_execve,path,argv,envp)
#else
2009-02-24 21:57:28 +00:00
# define QSE_EXECVE(path,argv,envp) execve(path,argv,envp)
#endif
2009-01-05 07:38:55 +00:00
2012-09-18 13:03:57 +00:00
#if defined(SYS_waitpid) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_WAITPID(pid,status,options) syscall(SYS_waitpid,pid,status,options)
2009-01-05 07:38:55 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_WAITPID(pid,status,options) waitpid(pid,status,options)
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_kill) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_KILL(pid,sig) syscall(SYS_kill,pid,sig)
#else
2009-02-24 21:57:28 +00:00
# define QSE_KILL(pid,sig) kill(pid,sig)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_getpid) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_GETPID() syscall(SYS_getpid)
2009-01-05 07:38:55 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_GETPID() getpid()
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_getuid) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_GETUID() syscall(SYS_getuid)
2009-01-05 07:38:55 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_GETUID() getuid()
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_geteuid) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_GETEUID() syscall(SYS_geteuid)
2009-01-05 07:38:55 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_GETEUID() geteuid()
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_getgid) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_GETGID() syscall(SYS_getgid)
2009-01-05 07:38:55 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_GETGID() getgid()
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_getegid) && defined(QSE_USE_SYSCALL)
2009-02-24 21:57:28 +00:00
# define QSE_GETEGID() syscall(SYS_getegid)
2009-01-05 07:38:55 +00:00
#else
2009-02-24 21:57:28 +00:00
# define QSE_GETEGID() getegid()
2009-01-05 07:38:55 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_gettimeofday) && defined(QSE_USE_SYSCALL)
2009-06-09 07:09:01 +00:00
# define QSE_GETTIMEOFDAY(tv,tz) syscall(SYS_gettimeofday,tv,tz)
2009-06-07 23:03:44 +00:00
#else
# define QSE_GETTIMEOFDAY(tv,tz) gettimeofday(tv,tz)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_settimeofday) && defined(QSE_USE_SYSCALL)
2009-06-09 07:09:01 +00:00
# define QSE_SETTIMEOFDAY(tv,tz) syscall(SYS_settimeofday,tv,tz)
2009-06-07 23:03:44 +00:00
#else
# define QSE_SETTIMEOFDAY(tv,tz) settimeofday(tv,tz)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_getrlimit) && defined(QSE_USE_SYSCALL)
# define QSE_GETRLIMIT(res,lim) syscall(SYS_getrlimit,res,lim)
2009-06-09 07:09:01 +00:00
#else
# define QSE_GETRLIMIT(res,lim) getrlimit(res,lim)
2009-06-09 07:09:01 +00:00
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_setrlimit) && defined(QSE_USE_SYSCALL)
# define QSE_SETRLIMIT(res,lim) syscall(SYS_setrlimit,res,lim)
2009-06-09 07:09:01 +00:00
#else
# define QSE_SETRLIMIT(res,lim) setrlimit(res,lim)
2009-06-09 07:09:01 +00:00
#endif
/* ===== FILE SYSTEM CALLS ===== */
2012-09-18 13:03:57 +00:00
#if defined(SYS_chmod) && defined(QSE_USE_SYSCALL)
# define QSE_CHMOD(path,mode) syscall(SYS_chmod,path,mode)
#else
# define QSE_CHMOD(path,mode) chmod(path,mode)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_chown) && defined(QSE_USE_SYSCALL)
# define QSE_CHOWN(path,owner,group) syscall(SYS_chown,path,owner,group)
#else
# define QSE_CHOWN(path,owner,group) chown(path,owner,group)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_chroot) && defined(QSE_USE_SYSCALL)
# define QSE_CHROOT(path) syscall(SYS_chroot,path)
#else
# define QSE_CHROOT(path) chroot(path)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_lchown) && defined(QSE_USE_SYSCALL)
# define QSE_LCHOWN(path,owner,group) syscall(SYS_lchown,path,owner,group)
#else
# define QSE_LCHOWN(path,owner,group) lchown(path,owner,group)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_link) && defined(QSE_USE_SYSCALL)
# define QSE_LINK(oldpath,newpath) syscall(SYS_link,oldpath,newpath)
#else
# define QSE_LINK(oldpath,newpath) link(oldpath,newpath)
#endif
2012-09-18 13:03:57 +00:00
#if !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(SYS_lstat64) && defined(QSE_USE_SYSCALL)
# define QSE_LSTAT(path,stbuf) syscall(SYS_lstat,path,stbuf)
typedef struct stat64 qse_lstat_t;
2012-09-18 13:03:57 +00:00
#elif defined(SYS_lstat) && defined(QSE_USE_SYSCALL)
# define QSE_LSTAT(path,stbuf) syscall(SYS_lstat,path,stbuf)
typedef struct stat qse_lstat_t;
2012-01-11 14:28:59 +00:00
#elif !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(HAVE_LSTAT64)
# define QSE_LSTAT(path,stbuf) lstat64(path,stbuf)
typedef struct stat64 qse_lstat_t;
#else
# define QSE_LSTAT(path,stbuf) lstat(path,stbuf)
typedef struct stat qse_lstat_t;
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_access) && defined(QSE_USE_SYSCALL)
2012-02-02 14:48:06 +00:00
# define QSE_ACCESS(path,mode) syscall(SYS_access,path,mode)
#else
# define QSE_ACCESS(path,mode) access(path,mode)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_rename) && defined(QSE_USE_SYSCALL)
# define QSE_RENAME(oldpath,newpath) syscall(SYS_rename,oldpath,newpath)
#else
2011-12-02 16:05:16 +00:00
int rename(const char *oldpath, const char *newpath); /* not to include stdio.h */
# define QSE_RENAME(oldpath,newpath) rename(oldpath,newpath)
#endif
#if defined(SYS_mkdir) && defined(QSE_USE_SYSCALL)
# define QSE_MKDIR(path,mode) syscall(SYS_mkdir,path,mode)
#else
# define QSE_MKDIR(path,mode) mkdir(path,mode)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_rmdir) && defined(QSE_USE_SYSCALL)
# define QSE_RMDIR(path) syscall(SYS_rmdir,path)
#else
# define QSE_RMDIR(path) rmdir(path)
#endif
2012-09-18 13:03:57 +00:00
#if !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(SYS_stat64) && defined(QSE_USE_SYSCALL)
# define QSE_STAT(path,stbuf) syscall(SYS_stat64,path,stbuf)
typedef struct stat64 qse_stat_t;
2012-09-18 13:03:57 +00:00
#elif defined(SYS_stat) && defined(QSE_USE_SYSCALL)
# define QSE_STAT(path,stbuf) syscall(SYS_stat,path,stbuf)
typedef struct stat qse_stat_t;
2012-01-11 14:28:59 +00:00
#elif !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(HAVE_STAT64)
# define QSE_STAT(path,stbuf) stat64(path,stbuf)
typedef struct stat64 qse_stat_t;
#else
# define QSE_STAT(path,stbuf) stat(path,stbuf)
typedef struct stat qse_stat_t;
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_symlink) && defined(QSE_USE_SYSCALL)
# define QSE_SYMLINK(oldpath,newpath) syscall(SYS_symlink,oldpath,newpath)
#else
# define QSE_SYMLINK(oldpath,newpath) symlink(oldpath,newpath)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_unlink) && defined(QSE_USE_SYSCALL)
# define QSE_UNLINK(path) syscall(SYS_unlink,path)
#else
# define QSE_UNLINK(path) unlink(path)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_utime) && defined(QSE_USE_SYSCALL)
# define QSE_UTIME(path,t) syscall(SYS_utime,path,t)
#else
# define QSE_UTIME(path,t) utime(path,t)
#endif
2012-09-18 13:03:57 +00:00
#if defined(SYS_utimes) && defined(QSE_USE_SYSCALL)
# define QSE_UTIMES(path,t) syscall(SYS_utimes,path,t)
#else
# define QSE_UTIMES(path,t) utimes(path,t)
#endif
2009-06-07 23:03:44 +00:00
2012-09-11 16:19:52 +00:00
/* ===== DIRECTORY - not really system calls ===== */
#define QSE_OPENDIR(name) opendir(name)
#define QSE_CLOSEDIR(dir) closedir(dir)
#define QSE_REWINDDIR(dir) rewinddir(dir)
#if defined(HAVE_DIRFD)
# define QSE_DIRFD(dir) dirfd(dir)
#elif defined(HAVE_DIR_DD_FD)
# define QSE_DIRFD(dir) ((dir)->dd_fd)
#elif defined(HAVE_DIR_D_FD)
# define QSE_DIRFD(dir) ((dir)->d_fd)
#else
# error OUCH!!! NO DIRFD AVAILABLE
#endif
#define QSE_DIR DIR
2012-09-11 16:19:52 +00:00
#if defined(HAVE_READDIR64)
typedef struct dirent64 qse_dirent_t;
# define QSE_READDIR(x) readdir64(x)
#else
typedef struct dirent qse_dirent_t;
# define QSE_READDIR(x) readdir(x)
#endif
/* ------------------------------------------------------------------------ */
#if defined(__linux) && defined(__GNUC__) && defined(__x86_64)
#include <sys/syscall.h>
2012-09-26 02:41:37 +00:00
/*
http://www.x86-64.org/documentation/abi.pdf
A.2 AMD64 Linux Kernel Conventions
The section is informative only.
A.2.1 Calling Conventions
The Linux AMD64 kernel uses internally the same calling conventions as user-
level applications (see section 3.2.3 for details). User-level applications
that like to call system calls should use the functions from the C library.
The interface between the C library and the Linux kernel is the same as for
the user-level applications with the following differences:
1. User-level applications use as integer registers for passing the sequence
%rdi, %rsi, %rdx, %rcx, %r8 and %r9. The kernel interface uses %rdi,
%rsi, %rdx, %r10, %r8 and %r9.
2. A system-call is done via the syscall instruction. The kernel destroys
registers %rcx and %r11.
3. The number of the syscall has to be passed in register %rax.
4. System-calls are limited to six arguments, no argument is passed directly
on the stack.
5. Returning from the syscall, register %rax contains the result of the
system-call. A value in the range between -4095 and -1 indicates an error,
it is -errno.
6. Only values of class INTEGER or class MEMORY are passed to the kernel.
*/
/*
#define QSE_SYSCALL0(ret,num) \
__asm__ volatile ( \
"movq %1, %%rax\n\t" \
"syscall\n" \
: "=&a"(ret) \
: "g"((qse_uint64_t)num) \
: "%rcx", "%r11")
#define QSE_SYSCALL1(ret,num,arg1) \
__asm__ volatile ( \
"movq %1, %%rax\n\t" \
"movq %2, %%rdi\n\t" \
"syscall\n" \
: "=&a"(ret) \
: "g"((qse_uint64_t)num), "g"((qse_uint64_t)arg1) \
: "%rdi", "%rcx", "%r11")
#define QSE_SYSCALL2(ret,num,arg1,arg2) \
__asm__ volatile ( \
"movq %1, %%rax\n\t" \
"movq %2, %%rdi\n\t" \
"movq %3, %%rsi\n\t" \
"syscall\n" \
: "=&a"(ret) \
: "g"((qse_uint64_t)num), "g"((qse_uint64_t)arg1), "g"((qse_uint64_t)arg2) \
: "%rdi", "%rsi", "%rcx", "%r11")
#define QSE_SYSCALL3(ret,num,arg1,arg2,arg3) \
__asm__ volatile ( \
"movq %1, %%rax\n\t" \
"movq %2, %%rdi\n\t" \
"movq %3, %%rsi\n\t" \
"movq %4, %%rdx\n\t" \
"syscall\n" \
: "=&a"(ret) \
: "g"((qse_uint64_t)num), "g"((qse_uint64_t)arg1), "g"((qse_uint64_t)arg2), "g"((qse_uint64_t)arg3) \
: "%rdi", "%rsi", "%rdx", "%rcx", "%r11")
*/
#define QSE_SYSCALL0(ret,num) \
__asm__ volatile ( \
"syscall\n" \
: "=a"(ret) \
2012-09-26 02:41:37 +00:00
: "a"((qse_uint64_t)num) \
: "memory", "cc", "%rcx", "%r11" \
)
#define QSE_SYSCALL1(ret,num,arg1) \
__asm__ volatile ( \
"syscall\n" \
: "=a"(ret) \
: "a"((qse_uint64_t)num), "D"((qse_uint64_t)arg1) \
2012-09-26 02:41:37 +00:00
: "memory", "cc", "%rcx", "%r11" \
)
#define QSE_SYSCALL2(ret,num,arg1,arg2) \
__asm__ volatile ( \
"syscall\n" \
: "=a"(ret) \
: "a"((qse_uint64_t)num), "D"((qse_uint64_t)arg1), "S"((qse_uint64_t)arg2) \
2012-09-26 02:41:37 +00:00
: "memory", "cc", "%rcx", "%r11" \
)
#define QSE_SYSCALL3(ret,num,arg1,arg2,arg3) \
__asm__ volatile ( \
"syscall\n" \
: "=a"(ret) \
: "a"((qse_uint64_t)num), "D"((qse_uint64_t)arg1), "S"((qse_uint64_t)arg2), "d"((qse_uint64_t)arg3) \
2012-09-26 02:41:37 +00:00
: "memory", "cc", "%rcx", "%r11" \
)
#define QSE_SYSCALL4(ret,num,arg1,arg2,arg3,arg4) \
__asm__ volatile ( \
"syscall\n" \
: "=a"(ret) \
: "a"((qse_uint64_t)num), "D"((qse_uint64_t)arg1), "S"((qse_uint64_t)arg2), "d"((qse_uint64_t)arg3), "c"((qse_uint64_t)arg4) \
: "memory", "cc", "%rcx", "%r11" \
)
#elif defined(__linux) && defined(__GNUC__) && defined(__i386)
#include <sys/syscall.h>
#define QSE_SYSCALL0(ret,num) \
__asm__ volatile ( \
"int $0x80\n" \
: "=a"(ret) \
: "a"((qse_uint32_t)num) \
2012-09-26 02:41:37 +00:00
: "memory" \
)
/*
#define QSE_SYSCALL1(ret,num,arg1) \
__asm__ volatile ( \
"int $0x80\n" \
: "=a"(ret) \
2012-09-26 02:41:37 +00:00
: "a"((qse_uint32_t)num), "b"((qse_uint32_t)arg1) \
: "memory" \
)
GCC in x86 PIC mode uses ebx to store the GOT table. so the macro shouldn't
clobber the ebx register. this modified version stores ebx before interrupt
and restores it after interrupt.
*/
#define QSE_SYSCALL1(ret,num,arg1) \
__asm__ volatile ( \
"push %%ebx\n\t" \
"movl %2, %%ebx\n\t" \
"int $0x80\n\t" \
"pop %%ebx\n" \
: "=a"(ret) \
: "a"((qse_uint32_t)num), "r"((qse_uint32_t)arg1) \
2012-09-26 02:41:37 +00:00
: "memory" \
)
/*
#define QSE_SYSCALL2(ret,num,arg1,arg2) \
__asm__ volatile ( \
"int $0x80\n" \
: "=a"(ret) \
2012-09-26 02:41:37 +00:00
: "a"((qse_uint32_t)num), "b"((qse_uint32_t)arg1), "c"((qse_uint32_t)arg2) \
: "memory" \
)
*/
#define QSE_SYSCALL2(ret,num,arg1,arg2) \
__asm__ volatile ( \
"push %%ebx\n\t" \
"movl %2, %%ebx\n\t" \
"int $0x80\n\t" \
"pop %%ebx\n" \
: "=a"(ret) \
: "a"((qse_uint32_t)num), "r"((qse_uint32_t)arg1), "c"((qse_uint32_t)arg2) \
2012-09-26 02:41:37 +00:00
: "memory" \
)
/*
#define QSE_SYSCALL3(ret,num,arg1,arg2,arg3) \
__asm__ volatile ( \
"int $0x80\n" \
: "=a"(ret) \
2012-09-26 02:41:37 +00:00
: "a"((qse_uint32_t)num), "b"((qse_uint32_t)arg1), "c"((qse_uint32_t)arg2), "d"((qse_uint32_t)arg3) \
: "memory" \
)
*/
#define QSE_SYSCALL3(ret,num,arg1,arg2,arg3) \
__asm__ volatile ( \
"push %%ebx\n\t" \
"movl %2, %%ebx\n\t" \
"int $0x80\n\t" \
"pop %%ebx\n" \
: "=a"(ret) \
: "a"((qse_uint32_t)num), "r"((qse_uint32_t)arg1), "c"((qse_uint32_t)arg2), "d"((qse_uint32_t)arg3) \
2012-09-26 02:41:37 +00:00
: "memory" \
)
#define QSE_SYSCALL4(ret,num,arg1,arg2,arg3,arg4) \
__asm__ volatile ( \
"push %%ebx\n\t" \
"movl %2, %%ebx\n\t" \
"int $0x80\n\t" \
2012-09-26 02:41:37 +00:00
"pop %%ebx\n" \
: "=a"(ret) \
: "a"((qse_uint32_t)num), "r"((qse_uint32_t)arg1), "c"((qse_uint32_t)arg2), "d"((qse_uint32_t)arg3), "S"((qse_uint32_t)arg4) \
: "memory" \
)
#endif
/* ------------------------------------------------------------------------ */
2008-12-31 00:08:03 +00:00
#endif