20 #include "posixSyscallNumbers.h" 24 #define errno (*__errno()) 25 extern int *__errno(
void);
28 #include "posix-syscall.h" 35 #include <netinet/in.h> 36 #include <semaphore.h> 43 #include <sys/mount.h> 44 #include <sys/resource.h> 46 #include <sys/reent.h> 50 #include <pedigree_config.h> 52 #define PEDIGREE_SYSCALLS_LIBC 53 #include <pedigree-syscalls.h> 56 #define BS16(x) (((x & 0xFF00) >> 8) | ((x & 0x00FF) << 8)) 58 (((x & 0xFF000000) >> 24) | ((x & 0x00FF0000) >> 8) | \ 59 ((x & 0x0000FF00) << 8) | ((x & 0x000000FF) << 24)) 64 #define LITTLE_TO_HOST8(x) (x) 65 #define LITTLE_TO_HOST16(x) (x) 66 #define LITTLE_TO_HOST32(x) (x) 67 #define LITTLE_TO_HOST64(x) (x) 69 #define HOST_TO_LITTLE8(x) (x) 70 #define HOST_TO_LITTLE16(x) (x) 71 #define HOST_TO_LITTLE32(x) (x) 72 #define HOST_TO_LITTLE64(x) (x) 74 #define BIG_TO_HOST8(x) BS8((x)) 75 #define BIG_TO_HOST16(x) BS16((x)) 76 #define BIG_TO_HOST32(x) BS32((x)) 77 #define BIG_TO_HOST64(x) BS64((x)) 79 #define HOST_TO_BIG8(x) BS8((x)) 80 #define HOST_TO_BIG16(x) BS16((x)) 81 #define HOST_TO_BIG32(x) BS32((x)) 82 #define HOST_TO_BIG64(x) BS64((x)) 84 #else // else Big endian 86 #define BIG_TO_HOST8(x) (x) 87 #define BIG_TO_HOST16(x) (x) 88 #define BIG_TO_HOST32(x) (x) 89 #define BIG_TO_HOST64(x) (x) 91 #define HOST_TO_BIG8(x) (x) 92 #define HOST_TO_BIG16(x) (x) 93 #define HOST_TO_BIG32(x) (x) 94 #define HOST_TO_BIG64(x) (x) 96 #define LITTLE_TO_HOST8(x) BS8((x)) 97 #define LITTLE_TO_HOST16(x) BS16((x)) 98 #define LITTLE_TO_HOST32(x) BS32((x)) 99 #define LITTLE_TO_HOST64(x) BS64((x)) 101 #define HOST_TO_LITTLE8(x) BS8((x)) 102 #define HOST_TO_LITTLE16(x) BS16((x)) 103 #define HOST_TO_LITTLE32(x) BS32((x)) 104 #define HOST_TO_LITTLE64(x) BS64((x)) 110 const char *safepathchars =
111 "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
112 #define SAFE_PATH_LEN (sizeof safepathchars) 114 #define STUBBED(str) \ 115 syscall1(POSIX_STUBBED, (long) (str)); \ 118 #define NUM_ATFORK_HANDLERS 32 // (* 3) 129 void (*prepare)(void);
130 void (*parent)(void);
135 static struct forkHandler atforkHandlers[NUM_ATFORK_HANDLERS];
138 static int nHandlers = 0;
140 int ftruncate(
int a, off_t b)
142 return syscall2(POSIX_FTRUNCATE, a, (
long) b);
145 int truncate(
const char *path, off_t length)
147 int fd = open(path, O_WRONLY);
150 int r = ftruncate(fd, length);
156 char *getcwd(
char *buf,
unsigned long size)
163 else if (!buf && !size)
172 buf = (
char *) malloc(size);
180 long r = syscall2(POSIX_GETCWD, (
long) buf, (
long) size);
181 char *result = (
char *) r;
192 return (
char *) result;
195 int mkdir(
const char *p, mode_t mode)
197 return (
long) syscall2(POSIX_MKDIR, (
long) p, mode);
202 return (
long) syscall1(POSIX_CLOSE, file);
205 int _execve(
char *name,
char **argv,
char **env)
207 return (
long) syscall3(POSIX_EXECVE, (
long) name, (
long) argv, (
long) env);
212 syscall1(POSIX_EXIT, val);
221 for (
int i = 0; i < nHandlers; i++)
223 if (atforkHandlers[i].prepare)
224 atforkHandlers[i].prepare();
228 int pid = (long) syscall0(POSIX_FORK);
234 for (
int i = 0; i < nHandlers; i++)
236 if (atforkHandlers[i].child)
237 atforkHandlers[i].child();
245 for (
int i = 0; i < nHandlers; i++)
247 if (atforkHandlers[i].parent)
248 atforkHandlers[i].parent();
261 int fstat(
int file,
struct stat *st)
263 return (
long) syscall2(POSIX_FSTAT, (
long) file, (
long) st);
266 int _isatty(
int file)
268 return (
long) syscall1(POSIX_ISATTY, file);
271 int link(
const char *old,
const char *_new)
273 return (
long) syscall2(POSIX_LINK, (
long) old, (
long) _new);
276 off_t lseek(
int file, off_t ptr,
int dir)
278 return (off_t) syscall3(POSIX_LSEEK, file, ptr, dir);
281 int open(
const char *name,
int flags, ...)
297 mode = va_arg(ap,
int);
301 return (
long) syscall3(POSIX_OPEN, (
long) name, flags, mode);
304 _READ_WRITE_RETURN_TYPE read(
int file,
void *ptr,
size_t len)
308 syslog(LOG_NOTICE,
"[%d] read: bad file given\n", getpid());
314 syslog(LOG_NOTICE,
"[%d] read: bad length given\n", getpid());
318 return (_READ_WRITE_RETURN_TYPE) syscall3(
319 POSIX_READ, file, (
long) ptr, len);
322 void *sbrk(ptrdiff_t incr)
324 uintptr_t result = syscall1(POSIX_SBRK, incr);
325 return (
void *) result;
328 int stat(
const char *file,
struct stat *st)
330 return (
long) syscall2(POSIX_STAT, (
long) file, (
long) st);
334 clock_t times(
struct tms *buf)
336 return syscall1(POSIX_TIMES, (
long) buf);
340 int utimes(
const char *filename,
const struct timeval times[2])
342 return syscall2(POSIX_UTIMES, (
long) filename, (
long) times);
345 int unlink(
const char *name)
347 return (
long) syscall1(POSIX_UNLINK, (
long) name);
350 int wait(
int *status)
352 return waitpid(-1, status, 0);
355 int waitpid(
int pid,
int *status,
int options)
357 return (
long) syscall3(POSIX_WAITPID, pid, (
long) status, options);
360 _READ_WRITE_RETURN_TYPE write(
int file,
const void *ptr,
size_t len)
364 syslog(LOG_NOTICE,
"[%d] write: bad file given\n", getpid());
368 return (_READ_WRITE_RETURN_TYPE) syscall3(
369 POSIX_WRITE, file, (
long) ptr, len);
372 ssize_t readv(
int fd,
const struct iovec *iov,
int iovcnt)
374 if (!iov || !iovcnt || (fd == -1))
382 for (i = 0; i < iovcnt; i++)
386 ssize_t r = read(fd, iov[i].iov_base, iov[i].iov_len);
393 ssize_t writev(
int fd,
const struct iovec *iov,
int iovcnt)
395 if (!iov || !iovcnt || (fd == -1))
403 for (i = 0; i < iovcnt; i++)
407 ssize_t r = write(fd, iov[i].iov_base, iov[i].iov_len);
414 int lstat(
const char *file,
struct stat *st)
416 return (
long) syscall2(POSIX_LSTAT, (
long) file, (
long) st);
419 DIR *opendir(
const char *dir)
421 DIR *p = (DIR *) malloc(
sizeof(DIR));
422 int r = syscall2(POSIX_OPENDIR, (
long) dir, (
long) p);
423 if (r < 0 || p->fd < 0)
431 struct dirent *readdir(DIR *dir)
439 int old_errno = errno;
448 if (dir->totalpos >= dir->count)
453 else if (dir->pos >= 64)
456 if (syscall1(POSIX_READDIR, (
long) dir) < 0)
467 struct dirent *result = &dir->ent[dir->pos];
474 void rewinddir(DIR *dir)
481 if (dir->totalpos < 64)
484 dir->pos = dir->totalpos = 0;
486 else if (dir->totalpos != 0)
488 dir->pos = dir->totalpos = 0;
489 syscall1(POSIX_READDIR, (
long) dir);
493 int closedir(DIR *dir)
501 syscall1(POSIX_CLOSEDIR, (
long) dir);
506 int _rename(
const char *old,
const char *
new)
508 return (
long) syscall2(POSIX_RENAME, (
long) old, (
long)
new);
511 int tcgetattr(
int fd,
struct termios *p)
513 return (
long) syscall2(POSIX_TCGETATTR, fd, (
long) p);
516 int tcsetattr(
int fd,
int optional_actions,
const struct termios *p)
518 return (
long) syscall3(POSIX_TCSETATTR, fd, optional_actions, (
long) p);
521 int tcsendbreak(
int fildes,
int duration)
523 STUBBED(
"tcsendbreak");
533 int tcflush(
int fd,
int queue_selector)
535 intptr_t selector = queue_selector;
536 return ioctl(fd, TIOCFLUSH, (
void *) selector);
539 int tcflow(
int fd,
int action)
545 void cfmakeraw(
struct termios *t)
548 ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
549 t->c_oflag &= ~OPOST;
550 t->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
551 t->c_cflag &= ~(CSIZE | PARENB);
555 int cfgetospeed(
const struct termios *t)
557 STUBBED(
"cfgetospeed");
561 int cfgetispeed(
const struct termios *t)
563 STUBBED(
"cfgetispeed");
567 int cfsetospeed(
const struct termios *t,
int speed)
569 STUBBED(
"cfsetospeed");
573 int cfsetispeed(
const struct termios *t,
int speed)
575 STUBBED(
"cfsetispeed");
579 int tcsetpgrp(
int fd, pid_t pgid_id)
581 return (
int) syscall2(POSIX_TCSETPGRP, fd, pgid_id);
584 pid_t tcgetpgrp(
int fd)
586 return (pid_t) syscall1(POSIX_TCGETPGRP, fd);
589 int mkfifo(
const char *_path, mode_t __mode)
595 int gethostname(
char *name,
size_t len)
602 result = pedigree_config_query(
603 "select * from 'network_generic' WHERE `key` = 'hostname';");
604 if ((result == -1) || (pedigree_config_was_successful(result) == -1) ||
605 (pedigree_config_numrows(result) == 0))
608 pedigree_config_freeresult(result);
609 strncpy(name,
"pedigree", len);
613 pedigree_config_getstr_s(result, 0,
"value", name, len);
614 pedigree_config_freeresult(result);
618 int sethostname(
char *name,
size_t len)
620 if (!name || len > 255 || !len)
629 "update 'network_generic' set `value`= '%s' WHERE `key` = 'hostname'";
630 char *tmp = pedigree_config_escape_string(name);
631 char *buffer = (
char *) malloc(strlen(query) + strlen(tmp) - 2 + 1);
633 sprintf(buffer, query, tmp);
635 int result = pedigree_config_query(buffer);
638 pedigree_config_freeresult(result);
646 int ioctl(
int fd,
int command, ...)
649 va_start(ap, command);
652 void *buf = va_arg(ap,
void *);
656 return (
long) syscall3(POSIX_IOCTL, fd, command, (
long) buf);
659 const char *
const sys_siglist[] = {0,
663 "Illegal instruction",
668 "Floating point exception",
671 "Segmentation violation",
672 "Bad argument to system call",
677 const char *strsignal(
int sig)
680 return sys_siglist[sig];
687 return (
long) syscall0(POSIX_GETUID);
692 return (
long) syscall0(POSIX_GETGID);
697 return (uid_t) syscall0(POSIX_GETEUID);
702 return (gid_t) syscall0(POSIX_GETEGID);
705 int setuid(uid_t uid)
707 return syscall1(POSIX_SETUID, uid);
710 int setgid(gid_t gid)
712 return syscall1(POSIX_SETGID, gid);
715 int seteuid(uid_t uid)
717 return syscall1(POSIX_SETEUID, uid);
720 int setegid(gid_t gid)
722 return syscall1(POSIX_SETEGID, gid);
725 int setresuid(uid_t ruid, uid_t euid, uid_t suid)
727 STUBBED(
"setresuid");
731 int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
733 STUBBED(
"setresgid");
739 STUBBED(
"issetugid");
743 unsigned int alarm(
unsigned int seconds)
745 return (
unsigned int) syscall1(POSIX_ALARM, seconds);
748 mode_t umask(mode_t mask)
750 return syscall1(POSIX_UMASK, mask);
753 int chmod(
const char *path, mode_t mode)
755 return syscall2(POSIX_CHMOD, (
long) path, mode);
758 int fchmod(
int fildes, mode_t mode)
760 return syscall2(POSIX_FCHMOD, fildes, mode);
763 int chown(
const char *path, uid_t owner, gid_t group)
765 return syscall3(POSIX_CHOWN, (
long) path, owner, group);
768 int fchown(
int fildes, uid_t owner, uid_t group)
770 return syscall3(POSIX_FCHOWN, fildes, owner, group);
773 int utime(
const char *path,
const struct utimbuf *times)
775 return syscall2(POSIX_UTIME, (
long) path, (
long) times);
778 int access(
const char *path,
int amode)
780 return (
long) syscall2(POSIX_ACCESS, (
long) path, amode);
783 const char *
const sys_errlist[] = {};
784 const int sys_nerr = 0;
787 long pathconf(
const char *path,
int name)
793 long fpathconf(
int filedes,
int name)
795 STUBBED(
"fpathconf");
800 int nfds,
struct fd_set *readfds,
struct fd_set *writefds,
801 struct fd_set *errorfds,
struct timeval *timeout)
803 return (
long) syscall5(
804 POSIX_SELECT, nfds, (
long) readfds, (
long) writefds, (
long) errorfds,
818 struct group *getgrent(
void)
825 static struct passwd g_passwd;
826 int g_passwd_num = 0;
827 char g_passwd_str[256];
838 struct passwd *getpwent(
void)
841 POSIX_GETPWENT, (
long) &g_passwd, g_passwd_num,
842 (
long) &g_passwd_str) != 0)
848 struct passwd *getpwuid(uid_t uid)
850 if (syscall3(POSIX_GETPWENT, (
long) &g_passwd, uid, (
long) &g_passwd_str) !=
856 struct passwd *getpwnam(
const char *name)
859 POSIX_GETPWNAM, (
long) &g_passwd, (
long) name,
860 (
long) &g_passwd_str) != 0)
865 int chdir(
const char *path)
867 return (
long) syscall1(POSIX_CHDIR, (
long) path);
870 int fchdir(
int fildes)
872 return syscall1(POSIX_FCHDIR, fildes);
877 return (
long) syscall1(POSIX_DUP, fileno);
880 int dup2(
int fildes,
int fildes2)
882 return (
long) syscall2(POSIX_DUP2, fildes, fildes2);
885 int pipe(
int filedes[2])
887 return (
long) syscall1(POSIX_PIPE, (
long) filedes);
890 int fcntl(
int fildes,
int cmd, ...)
894 void *arg = va_arg(ap,
void *);
897 return syscall3(POSIX_FCNTL, fildes,
cmd, (
long) arg);
900 int sigprocmask(
int how,
const sigset_t *
set, sigset_t *oset)
902 return (
long) syscall3(POSIX_SIGPROCMASK, how, (
long)
set, (
long) oset);
905 int rmdir(
const char *path)
907 return syscall1(POSIX_RMDIR, (
long) path);
910 int socket(
int domain,
int type,
int protocol)
912 return (
long) syscall3(POSIX_SOCKET, domain, type, protocol);
915 int connect(
int sock,
const struct sockaddr *address,
size_t addrlen)
917 return (
long) syscall3(POSIX_CONNECT, sock, (
long) address, (
long) addrlen);
920 ssize_t send(
int sock,
const void *buff,
size_t bufflen,
int flags)
922 return (ssize_t) syscall4(
923 POSIX_SEND, sock, (
long) buff, (
long) bufflen, flags);
926 ssize_t recv(
int sock,
void *buff,
size_t bufflen,
int flags)
928 return (ssize_t) syscall4(
929 POSIX_RECV, sock, (
long) buff, (
long) bufflen, flags);
932 int accept(
int sock,
struct sockaddr *remote_addr,
size_t *addrlen)
934 return (
long) syscall3(
935 POSIX_ACCEPT, sock, (
long) remote_addr, (
long) addrlen);
938 int bind(
int sock,
const struct sockaddr *local_addr,
size_t addrlen)
940 return (
long) syscall3(POSIX_BIND, sock, (
long) local_addr, (
long) addrlen);
943 int getpeername(
int sock,
struct sockaddr *addr,
size_t *addrlen)
945 return syscall3(POSIX_GETPEERNAME, sock, (
long) addr, (
long) addrlen);
948 int getsockname(
int sock,
struct sockaddr *addr,
size_t *addrlen)
950 return syscall3(POSIX_GETSOCKNAME, sock, (
long) addr, (
long) addrlen);
953 int getsockopt(
int sock,
int level,
int optname,
void *optvalue,
size_t *optlen)
956 POSIX_GETSOCKOPT, sock, level, optname, (
long) optvalue, (
long) optlen);
959 int listen(
int sock,
int backlog)
961 return (
long) syscall2(POSIX_LISTEN, sock, backlog);
970 const struct sockaddr *remote_addr;
971 const socklen_t *addrlen;
980 struct sockaddr *remote_addr;
985 int sock,
void *buff,
size_t bufflen,
int flags,
986 struct sockaddr *remote_addr,
size_t *addrlen)
992 tmp->bufflen = bufflen;
994 tmp->remote_addr = remote_addr;
995 tmp->addrlen = addrlen;
997 int ret = syscall1(POSIX_RECVFROM, (
long) tmp);
1004 ssize_t recvmsg(
int sock,
struct msghdr *msg,
int flags)
1010 ssize_t sendmsg(
int sock,
const struct msghdr *msg,
int flags)
1017 int sock,
const void *buff,
size_t bufflen,
int flags,
1018 const struct sockaddr *remote_addr, socklen_t addrlen)
1024 tmp->bufflen = bufflen;
1026 tmp->remote_addr = remote_addr;
1027 tmp->addrlen = &addrlen;
1029 int ret = syscall1(POSIX_SENDTO, (
long) tmp);
1037 int sock,
int level,
int optname,
const void *optvalue,
1038 unsigned long optlen)
1040 STUBBED(
"setsockopt");
1044 int shutdown(
int sock,
int how)
1046 return (
long) syscall2(POSIX_SHUTDOWN, sock, how);
1049 int sockatmark(
int sock)
1051 STUBBED(
"sockatmark");
1055 int socketpair(
int domain,
int type,
int protocol,
int sock_vec[2])
1057 STUBBED(
"socketpair");
1061 struct group *getgrnam(
const char *name)
1063 static struct group ret = {0, 0, 0, 0};
1068 free(ret.gr_passwd);
1070 ret.gr_name = (
char *) malloc(256);
1071 ret.gr_passwd = (
char *) malloc(256);
1072 int r = syscall2(POSIX_GETGRNAM, (
long) name, (
long) &ret);
1081 struct group *getgrgid(gid_t
id)
1083 static struct group ret = {0, 0, 0, 0};
1085 ret.gr_name = (
char *) malloc(256);
1086 ret.gr_passwd = (
char *) malloc(256);
1087 int r = syscall2(POSIX_GETGRGID,
id, (
long) &ret);
1096 int symlink(
const char *path1,
const char *path2)
1098 return (
long) syscall2(POSIX_SYMLINK, (
long) path1, (
long) path2);
1103 return syscall1(POSIX_FSYNC, fd);
1106 ssize_t readlink(
const char *path,
char *buf,
size_t bufsize)
1108 return (
long) syscall3(POSIX_READLINK, (
long) path, (
long) buf, bufsize);
1111 int ftime(
struct timeb *tp)
1125 STUBBED(
"sigblock");
1129 int sigsetmask(
int mask)
1131 STUBBED(
"sigsetmask");
1135 int siggetmask(
void)
1137 STUBBED(
"siggetmask");
1141 int sigaction(
int sig,
const struct sigaction *act,
struct sigaction *oact)
1143 return (
long) syscall3(POSIX_SIGACTION, sig, (
long) act, (
long) oact);
1146 _sig_func_ptr signal(
int s, _sig_func_ptr func)
1150 static struct sigaction act;
1151 static struct sigaction tmp;
1152 unsigned long mask = 0;
1153 sigprocmask(0, 0, &mask);
1155 act.sa_handler = func;
1157 memset(&tmp, 0,
sizeof(
struct sigaction));
1158 if (sigaction(s, &act, &tmp) == 0)
1160 return tmp.sa_handler;
1164 return (_sig_func_ptr) -1;
1167 int kill(pid_t pid,
int sig)
1169 return (
long) syscall2(POSIX_KILL, pid, sig);
1172 int sigpending(
long *
set)
1174 STUBBED(
"sigpending");
1178 int sigsuspend(
const long *sigmask)
1180 STUBBED(
"sigsuspend");
1184 void _init_signals(
void)
1189 int fdatasync(
int fildes)
1192 return syscall1(POSIX_FSYNC, fildes);
1200 extern void *_libload_dlopen(
const char *,
int)
__attribute__((weak));
1201 extern void *_libload_dlsym(
void *,
const char *)
__attribute__((weak));
1204 void *dlopen(
const char *file,
int mode)
1206 return _libload_dlopen(file, mode);
1209 void *dlsym(
void *handle,
const char *name)
1211 return _libload_dlsym(handle, name);
1214 int dlclose(
void *handle)
1216 return _libload_dlclose(handle);
1225 int poll(
struct pollfd fds[],
unsigned int nfds,
int timeout)
1227 return (
long) syscall3(POSIX_POLL, (
long) fds, nfds, timeout);
1230 unsigned int htonl(
unsigned int n)
1232 return HOST_TO_BIG32(n);
1234 unsigned int ntohl(
unsigned int n)
1236 return BIG_TO_HOST32(n);
1239 unsigned short htons(
unsigned short n)
1241 return HOST_TO_BIG16(n);
1243 unsigned short ntohs(
unsigned short n)
1245 return BIG_TO_HOST16(n);
1253 int mknod(
const char *path, mode_t mode, dev_t dev)
1260 uid_t uid,
struct passwd *pwd,
char *buffer,
size_t bufsize,
1261 struct passwd **result)
1263 STUBBED(
"getpwuid_r");
1268 gid_t gid,
struct group *grp,
char *buffer,
size_t bufsize,
1269 struct group **result)
1271 STUBBED(
"getgrgid_r");
1276 const char *name,
struct passwd *pwd,
char *buffer,
size_t bufsize,
1277 struct passwd **result)
1279 STUBBED(
"getpwnam_r");
1284 const char *name,
struct group *grp,
char *buffer,
size_t bufsize,
1285 struct group **result)
1287 STUBBED(
"getgrnam_r");
1291 void err(
int eval,
const char *fmt, ...) _ATTRIBUTE((noreturn));
1292 void err(
int eval,
const char *fmt, ...)
1295 "err: %d: (todo: print format string based on arguments): %s\n", errno,
1300 long timegm(
struct tm *tm)
1306 int chroot(
const char *path)
1308 return syscall1(POSIX_CHROOT, (
long) path);
1311 char *mkdtemp(
char *
template)
1320 size_t template_len = strlen(
template);
1321 if (template_len < 6)
1327 for (
size_t i = (template_len - 6); i < template_len; ++i)
1329 if (
template[i] !=
'X')
1339 for (
size_t i = (template_len - 6); i < template_len; ++i)
1340 template[i] = safepathchars[rand() % SAFE_PATH_LEN];
1342 if (mkdir(
template, 0700) == 0)
1344 else if (errno != EEXIST)
1354 int getitimer(
int which,
struct itimerval *value)
1356 STUBBED(
"getitimer");
1361 int which,
const struct itimerval *value,
struct itimerval *ovalue)
1363 STUBBED(
"setitimer");
1377 void *mmap(
void *addr,
size_t len,
int prot,
int flags,
int fildes, off_t off)
1387 uintptr_t result = syscall1(POSIX_MMAP, (
long) &t);
1388 return (
void *) result;
1391 int msync(
void *addr,
size_t len,
int flags)
1393 return (
int) syscall3(POSIX_MSYNC, (
long) addr, (
long) len, flags);
1396 int munmap(
void *addr,
size_t len)
1398 return (
long) syscall2(POSIX_MUNMAP, (
long) addr, (
long) len);
1401 int getgroups(
int gidsetsize, gid_t grouplist[])
1403 if (gidsetsize == 0)
1415 grouplist[0] = getgid();
1420 size_t getpagesize(
void)
1424 static size_t sz = (size_t) ~0;
1425 if (sz == (
size_t) ~0)
1426 sz = sysconf(_SC_PAGESIZE);
1430 char *realpath(
const char *file_name,
char *resolved_name)
1440 resolved_name = (
char *) malloc(PATH_MAX);
1444 POSIX_REALPATH, (
long) file_name, (
long) resolved_name, PATH_MAX);
1448 return resolved_name;
1453 return syscall0(POSIX_SETSID);
1456 int setpgid(pid_t pid, pid_t pgid)
1458 return syscall2(POSIX_SETPGID, (
long) pid, (
long) pgid);
1461 pid_t getpgid(pid_t pid)
1474 return syscall0(POSIX_GETPGRP);
1479 return syscall0(POSIX_GETPPID);
1482 int getrlimit(
int resource,
struct rlimit *rlp)
1484 STUBBED(
"setrlimit");
1488 int setrlimit(
int resource,
const struct rlimit *rlp)
1490 STUBBED(
"setrlimit");
1495 int getmntinfo(
struct statvfs **mntbufp,
int flags)
1497 STUBBED(
"getmntinfo");
1501 FILE *setmntent(
const char *filename,
const char *type)
1503 STUBBED(
"setmntent");
1507 struct mntent *getmntent(
FILE *fp)
1509 STUBBED(
"getmntent");
1513 int endmntent(
FILE *fp)
1515 STUBBED(
"endmntent");
1519 int statvfs(
const char *path,
struct statvfs *buf)
1521 return syscall2(POSIX_STATVFS, (
long) path, (
long) buf);
1524 int fstatvfs(
int fd,
struct statvfs *buf)
1526 return syscall2(POSIX_FSTATVFS, fd, (
long) buf);
1529 struct fstab *getfsent(
void)
1531 STUBBED(
"getfsent");
1535 struct fstab *getfsfile(
const char *mount_point)
1537 STUBBED(
"getfsfile");
1541 struct fstab *getfsspec(
const char *special_file)
1543 STUBBED(
"getfsspec");
1549 STUBBED(
"setfsent");
1555 STUBBED(
"endfsent");
1558 int getrusage(
int who,
struct rusage *r_usage)
1560 return syscall2(POSIX_GETRUSAGE, who, (
long) r_usage);
1563 int sigaltstack(
const struct stack_t *stack,
struct stack_t *oldstack)
1565 return syscall2(POSIX_SIGALTSTACK, (
long) stack, (
long) oldstack);
1568 int sem_close(sem_t *sem)
1570 return syscall1(POSIX_SEM_CLOSE, (
long) sem);
1573 int sem_destroy(sem_t *sem)
1575 return syscall1(POSIX_SEM_DESTROY, (
long) sem);
1578 int sem_getvalue(sem_t *sem,
int *val)
1580 return syscall2(POSIX_SEM_GETVALUE, (
long) sem, (
long) val);
1583 int sem_init(sem_t *sem,
int pshared,
unsigned value)
1585 return syscall3(POSIX_SEM_INIT, (
long) sem, pshared, value);
1588 sem_t *sem_open(
const char *name,
int mode, ...)
1590 STUBBED(
"sem_open");
1594 int sem_post(sem_t *sem)
1596 return syscall1(POSIX_SEM_POST, (
long) sem);
1599 int sem_timedwait(sem_t *sem,
const struct timespec *tm)
1601 return syscall2(POSIX_SEM_TIMEWAIT, (
long) sem, (
long) tm);
1604 int sem_trywait(sem_t *sem)
1606 return syscall1(POSIX_SEM_TRYWAIT, (
long) sem);
1609 int sem_unlink(
const char *name)
1611 STUBBED(
"sem_unlink");
1615 int sem_wait(sem_t *sem)
1617 return syscall1(POSIX_SEM_WAIT, (
long) sem);
1621 void (*prepare)(
void),
void (*parent)(
void),
void (*child)(
void))
1624 if (nHandlers == NUM_ATFORK_HANDLERS)
1632 handler.prepare = prepare;
1633 handler.parent = parent;
1634 handler.child = child;
1635 atforkHandlers[nHandlers++] = handler;
1643 void openlog(
const char *log,
int logopt,
int facility)
1647 int setlogmask(
int mask)
1652 void syslog(
int prio,
const char *fmt, ...)
1654 static char print_temp[1024];
1656 va_start(argptr, fmt);
1657 vsnprintf(print_temp,
sizeof print_temp, fmt, argptr);
1658 syscall2(POSIX_SYSLOG, (
long) print_temp, prio);
1669 int *amaster,
char *name,
struct termios *termp,
struct winsize *winp)
1676 struct utmp *pututline(
struct utmp *ut)
1678 STUBBED(
"pututline");
1682 void logwtmp(
const char *line,
const char *name,
const char *host)
1687 unsigned if_nametoindex(
const char *name)
1689 STUBBED(
"if_nametoindex");
1693 char *if_indextoname(
unsigned index,
char *buf)
1695 STUBBED(
"if_indextoname");
1700 struct if_nameindex *if_nameindex()
1702 STUBBED(
"if_nameindex");
1707 void if_freenameindex(
struct if_nameindex *nameindex)
1709 STUBBED(
"if_freenameindex");
1712 int sigsetjmp(sigjmp_buf env,
int savemask)
1718 void siglongjmp(sigjmp_buf env,
int val)
1723 char *basename(
char *path)
1725 static char bad[2] = {
'.', 0};
1726 if ((path == NULL) || (path && !*path))
1729 char *p = strrchr(path,
'/');
1736 int reboot(
int howto)
1738 return pedigree_reboot();
1741 int initgroups(
const char *user, gid_t group)
1743 STUBBED(
"initgroups");
1747 int setgroups(
int ngroups,
const gid_t *gidset)
1749 STUBBED(
"setgroups");
1753 ssize_t getdelim(
char **a,
size_t *b,
int c,
FILE *d)
1755 return __getdelim(a, b, c, d);
1757 ssize_t getline(
char **a,
size_t *b,
FILE *c)
1759 return __getline(a, b, c);
1764 return syscall0(POSIX_SCHED_YIELD);
1769 STUBBED(
"getdtablesize");
1772 getrlimit(RLIMIT_NOFILE, &tmp);
1773 return tmp.rlim_cur;
1776 int mprotect(
void *addr,
size_t len,
int prot)
1778 return syscall3(POSIX_MPROTECT, (
long) addr, len, prot);
1781 int nanosleep(
const struct timespec *rqtp,
struct timespec *rmtp)
1789 return syscall2(POSIX_NANOSLEEP, (
long) rqtp, (
long) rmtp);
1792 int clock_getres(clockid_t clock_id,
struct timespec *res)
1807 int setreuid(uid_t ruid, uid_t euid)
1809 STUBBED(
"setreuid");
1813 int grantpt(
int fildes)
1819 int unlockpt(
int fildes)
1821 STUBBED(
"unlockpt");
1825 char *ptsname(
int fildes)
1827 static char ret[256] = {0};
1829 int res = syscall2(POSIX_PTSNAME, fildes, (
long) ret);
1835 char *ttyname(
int fildes)
1837 static char ret[256] = {0};
1839 int res = syscall2(POSIX_TTYNAME, fildes, (
long) ret);
1845 char *crypt(
const char *key,
const char *salt)
1851 int ffsl(
long int i)
1853 return __builtin_ffs(i);
1856 int ffsll(
long long int i)
1858 return __builtin_ffsll(i);
1861 void __pedigree_revoke_signal_context()
1864 syscall0(PEDIGREE_UNWIND_SIGNAL);
1872 void *_malloc_r(
struct _reent *ptr,
size_t sz)
1877 void *_calloc_r(
struct _reent *ptr,
size_t a,
size_t b)
1879 return calloc(a, b);
1882 void *_realloc_r(
struct _reent *ptr,
void *p,
size_t sz)
1884 return realloc(p, sz);
1887 void *_memalign_r(
struct _reent *ptr,
size_t align,
size_t nbytes)
1889 return memalign(align, nbytes);
1892 void _free_r(
struct _reent *ptr,
void *p)
1897 int posix_openpt(
int oflag)
1900 char name[16] = {0};
1903 oflag &= O_RDWR | O_NOCTTY;
1905 strcpy(name,
"/dev/ptyXX");
1906 for (x =
"pqrstuvwxyzabcde"; *x; ++x)
1908 for (y =
"0123456789abcdef"; *y; ++y)
1913 master = open(name, oflag);
1916 else if (errno == ENOENT)
1931 int *amaster,
int *aslave,
char *name,
const struct termios *termp,
1932 const struct winsize *winp)
1934 if (amaster == NULL)
1941 *amaster = posix_openpt(O_RDWR);
1946 char *slavename = ptsname(*amaster);
1947 *aslave = open(slavename, O_RDWR | O_NOCTTY);
1949 strcpy(name, slavename);
1955 tcsetattr(*aslave, TCSANOW, termp);
1961 ioctl(*amaster, TIOCSWINSZ, winp);
#define IN6ADDR_LOOPBACK_INIT
const struct in6_addr in6addr_any