summaryrefslogtreecommitdiff
path: root/ports/sysdeps/unix/sysv/linux/generic
diff options
context:
space:
mode:
Diffstat (limited to 'ports/sysdeps/unix/sysv/linux/generic')
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/Makefile3
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/____longjmp_chk.c57
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/access.c31
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/bits/fcntl.h339
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/bits/msq.h83
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/bits/sem.h92
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/bits/shm.h111
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/bits/stat.h171
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h86
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/bits/typesizes.h69
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/brk.c45
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/chmod.c31
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/chown.c32
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/creat.c38
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/dl-origin.c81
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/dup2.c37
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/epoll_create.c38
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/epoll_wait.c28
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/futimesat.c52
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/getdents.c1
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/getdents64.c37
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/inotify_init.c32
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/kernel_stat.h26
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/lchown.c32
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/link.c31
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/lxstat.c48
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/mkdir.c33
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/not-cancel.h34
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/nptl/not-cancel.h1
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/open.c71
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/open64.c55
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/pause.c63
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/pipe.c33
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/poll.c53
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/readlink.c31
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/readlink_chk.c39
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/recv.c45
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/rename.c29
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/rmdir.c31
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/select.c74
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/send.c43
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/symlink.c30
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/syscalls.list32
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/sysctl.c33
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/sysdep.h41
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/umount.c30
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/unlink.c31
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/ustat.c33
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/utimes.c45
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/Versions5
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c87
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c32
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c31
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c32
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstat.c45
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstatat.c45
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c115
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c46
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c38
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat.c43
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat64.c38
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c40
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h60
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/posix_fadvise.c37
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c58
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c58
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c55
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c56
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c59
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c59
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c56
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c57
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c45
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c33
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list7
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c31
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c31
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat.c43
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat64.c38
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/xmknod.c54
-rw-r--r--ports/sysdeps/unix/sysv/linux/generic/xstat.c48
81 files changed, 4023 insertions, 0 deletions
diff --git a/ports/sysdeps/unix/sysv/linux/generic/Makefile b/ports/sysdeps/unix/sysv/linux/generic/Makefile
new file mode 100644
index 0000000000..c1daee2396
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/Makefile
@@ -0,0 +1,3 @@
+ifeq ($(subdir),misc)
+sysdep_routines += epoll_create epoll_wait inotify_init
+endif
diff --git a/ports/sysdeps/unix/sysv/linux/generic/____longjmp_chk.c b/ports/sysdeps/unix/sysv/linux/generic/____longjmp_chk.c
new file mode 100644
index 0000000000..619785d7e8
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/____longjmp_chk.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <jmpbuf-offsets.h>
+#include <sysdep.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stackinfo.h>
+
+#ifdef _STACK_GROWS_DOWN
+#define called_from(this, saved) ((this) < (saved))
+#else
+#define called_from(this, saved) ((this) > (saved))
+#endif
+
+extern void ____longjmp_chk (__jmp_buf __env, int __val)
+ __attribute__ ((__noreturn__));
+
+void ____longjmp_chk (__jmp_buf env, int val)
+{
+ void *this_frame = __builtin_frame_address (0);
+ void *saved_frame = JB_FRAME_ADDRESS (env);
+ INTERNAL_SYSCALL_DECL (err);
+ stack_t ss;
+
+ /* If "env" is from a frame that called us, we're all set. */
+ if (called_from(this_frame, saved_frame))
+ __longjmp (env, val);
+
+ /* If we can't get the current stack state, give up and do the longjmp. */
+ if (INTERNAL_SYSCALL (sigaltstack, err, 2, NULL, &ss) != 0)
+ __longjmp (env, val);
+
+ /* If we we are executing on the alternate stack and within the
+ bounds, do the longjmp. */
+ if (ss.ss_flags == SS_ONSTACK &&
+ (this_frame >= ss.ss_sp && this_frame < (ss.ss_sp + ss.ss_size)))
+ __longjmp (env, val);
+
+ __fortify_fail ("longjmp causes uninitialized stack frame");
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/access.c b/ports/sysdeps/unix/sysv/linux/generic/access.c
new file mode 100644
index 0000000000..177f0ed211
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/access.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sysdep-cancel.h>
+
+/* Test for access to FILE. */
+int
+__access (const char *file, int type)
+{
+ return INLINE_SYSCALL (faccessat, 3, AT_FDCWD, file, type);
+}
+weak_alias (__access, access)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/bits/fcntl.h b/ports/sysdeps/unix/sysv/linux/generic/bits/fcntl.h
new file mode 100644
index 0000000000..a8f20bd0b1
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/bits/fcntl.h
@@ -0,0 +1,339 @@
+/* O_*, F_*, FD_* bit values for the generic Linux ABI.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <sys/types.h>
+#include <bits/wordsize.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+
+
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on a few file systems. */
+#define O_ACCMODE 0003
+#define O_RDONLY 00
+#define O_WRONLY 01
+#define O_RDWR 02
+#define O_CREAT 0100 /* not fcntl */
+#define O_EXCL 0200 /* not fcntl */
+#define O_NOCTTY 0400 /* not fcntl */
+#define O_TRUNC 01000 /* not fcntl */
+#define O_APPEND 02000
+#define O_NONBLOCK 04000
+#define O_NDELAY O_NONBLOCK
+#define O_SYNC 04010000
+#define O_FSYNC O_SYNC
+#define O_ASYNC 020000
+
+#ifdef __USE_XOPEN2K8
+# define O_DIRECTORY 0200000 /* Must be a directory. */
+# define O_NOFOLLOW 0400000 /* Do not follow links. */
+# define O_CLOEXEC 02000000 /* Set close_on_exec. */
+#endif
+#ifdef __USE_GNU
+# define O_DIRECT 040000 /* Direct disk access. */
+# define O_NOATIME 01000000 /* Do not set atime. */
+# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC 010000 /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+# if __WORDSIZE == 64
+# define O_LARGEFILE 0
+# else
+# define O_LARGEFILE 0100000
+# endif
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#if __WORDSIZE == 64
+# define F_GETLK 5 /* Get record locking info. */
+# define F_SETLK 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW 7 /* Set record locking info (blocking). */
+/* Not necessary, we always have 64-bit offsets. */
+# define F_GETLK64 5 /* Get record locking info. */
+# define F_SETLK64 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW64 7 /* Set record locking info (blocking). */
+#else
+# ifndef __USE_FILE_OFFSET64
+# define F_GETLK 5 /* Get record locking info. */
+# define F_SETLK 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW 7 /* Set record locking info (blocking). */
+# else
+# define F_GETLK F_GETLK64 /* Get record locking info. */
+# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
+# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
+# endif
+# define F_GETLK64 12 /* Get record locking info. */
+# define F_SETLK64 13 /* Set record locking info (non-blocking). */
+# define F_SETLKW64 14 /* Set record locking info (blocking). */
+#endif
+
+#if defined __USE_BSD || defined __USE_UNIX98 || defined __USE_XOPEN2K8
+# define F_SETOWN 8 /* Get owner (process receiving SIGIO). */
+# define F_GETOWN 9 /* Set owner (process receiving SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+# define F_SETOWN_EX 15 /* Get owner (thread receiving SIGIO). */
+# define F_GETOWN_EX 16 /* Set owner (thread receiving SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
+# define F_GETPIPE_SZ 1032 /* Set pipe page size array. */
+#endif
+#ifdef __USE_XOPEN2K8
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set. */
+#endif
+
+/* For F_[GET|SET]FD. */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
+#define F_RDLCK 0 /* Read lock. */
+#define F_WRLCK 1 /* Write lock. */
+#define F_UNLCK 2 /* Remove lock. */
+
+/* For old implementation of bsd flock(). */
+#define F_EXLCK 4 /* or 3 */
+#define F_SHLCK 8 /* or 4 */
+
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation. */
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#endif
+
+struct flock
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+#ifndef __USE_FILE_OFFSET64
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+#else
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+#endif
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+
+#ifdef __USE_LARGEFILE64
+struct flock64
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+#endif
+
+#ifdef __USE_GNU
+/* Owner types. */
+enum __pid_type
+ {
+ F_OWNER_TID = 0, /* Kernel thread. */
+ F_OWNER_PID, /* Process. */
+ F_OWNER_PGRP, /* Process group. */
+ F_OWNER_GID = F_OWNER_PGRP /* Alternative, obsolete name. */
+ };
+
+/* Structure to use with F_GETOWN_EX and F_SETOWN_EX. */
+struct f_owner_ex
+ {
+ enum __pid_type type; /* Owner type of ID. */
+ __pid_t pid; /* ID of owner. */
+ };
+#endif
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+#endif
+
+
+#ifdef __USE_GNU
+/* Flags for SYNC_FILE_RANGE. */
+# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
+ in the range before performing the
+ write. */
+# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
+ dirty pages in the range which are
+ not presently under writeback. */
+# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
+ the range after performing the
+ write. */
+
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+
+
+/* File handle structure. */
+struct file_handle
+{
+ unsigned int handle_bytes;
+ int handle_type;
+ /* File identifier. */
+ unsigned char f_handle[0];
+};
+
+/* Maximum handle size (for now). */
+# define MAX_HANDLE_SZ 128
+#endif
+
+__BEGIN_DECLS
+
+#ifdef __USE_GNU
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+
+/* Selective file content synch'ing.
+
+ This function is a possible cancellation point and therefore not
+ marked with __THROW. */
+extern int sync_file_range (int __fd, __off64_t __offset, __off64_t __count,
+ unsigned int __flags);
+
+
+/* Splice address range into a pipe.
+
+ This function is a possible cancellation point and therefore not
+ marked with __THROW. */
+extern ssize_t vmsplice (int __fdout, const struct iovec *__iov,
+ size_t __count, unsigned int __flags);
+
+/* Splice two files together.
+
+ This function is a possible cancellation point and therefore not
+ marked with __THROW. */
+extern ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
+ __off64_t *__offout, size_t __len,
+ unsigned int __flags);
+
+/* In-kernel implementation of tee for pipe buffers.
+
+ This function is a possible cancellation point and therefore not
+ marked with __THROW. */
+extern ssize_t tee (int __fdin, int __fdout, size_t __len,
+ unsigned int __flags);
+
+/* Reserve storage for the data of the file associated with FD.
+
+ This function is a possible cancellation point and therefore not
+ marked with __THROW. */
+# ifndef __USE_FILE_OFFSET64
+extern int fallocate (int __fd, int __mode, __off_t __offset, __off_t __len);
+# else
+# ifdef __REDIRECT
+extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset,
+ __off64_t __len),
+ fallocate64);
+# else
+# define fallocate fallocate64
+# endif
+# endif
+# ifdef __USE_LARGEFILE64
+extern int fallocate64 (int __fd, int __mode, __off64_t __offset,
+ __off64_t __len);
+# endif
+
+
+/* Map file name to file handle. */
+extern int name_to_handle_at (int __dfd, const char *__name,
+ struct file_handle *__handle, int *__mnt_id,
+ int __flags) __THROW;
+
+/* Open file using the file handle.
+
+ This function is a possible cancellation point and therefore not
+ marked with __THROW. */
+extern int open_by_handle_at (int __mountdirfd, struct file_handle *__handle,
+ int __flags);
+
+#endif /* use GNU */
+
+__END_DECLS
diff --git a/ports/sysdeps/unix/sysv/linux/generic/bits/msq.h b/ports/sysdeps/unix/sysv/linux/generic/bits/msq.h
new file mode 100644
index 0000000000..bf12ba9b53
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/bits/msq.h
@@ -0,0 +1,83 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_MSG_H
+# error "Never use <bits/msq.h> directly; include <sys/msg.h> instead."
+#endif
+
+#include <bits/types.h>
+#include <bits/wordsize.h>
+
+/* Define options for message queue functions. */
+#define MSG_NOERROR 010000 /* no error if message is too big */
+#ifdef __USE_GNU
+# define MSG_EXCEPT 020000 /* recv any msg except of specified type */
+#endif
+
+/* Types used in the structure definition. */
+typedef unsigned long int msgqnum_t;
+typedef unsigned long int msglen_t;
+
+/* Structure of record for one message inside the kernel.
+ The type `struct msg' is opaque. */
+struct msqid_ds
+{
+ struct ipc_perm msg_perm; /* structure describing operation permission */
+ __time_t msg_stime; /* time of last msgsnd command */
+#if __WORDSIZE == 32
+ unsigned long int __unused1;
+#endif
+ __time_t msg_rtime; /* time of last msgrcv command */
+#if __WORDSIZE == 32
+ unsigned long int __unused2;
+#endif
+ __time_t msg_ctime; /* time of last change */
+#if __WORDSIZE == 32
+ unsigned long int __unused3;
+#endif
+ unsigned long int __msg_cbytes; /* current number of bytes on queue */
+ msgqnum_t msg_qnum; /* number of messages currently on queue */
+ msglen_t msg_qbytes; /* max number of bytes allowed on queue */
+ __pid_t msg_lspid; /* pid of last msgsnd() */
+ __pid_t msg_lrpid; /* pid of last msgrcv() */
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+};
+
+#ifdef __USE_MISC
+
+# define msg_cbytes __msg_cbytes
+
+/* ipcs ctl commands */
+# define MSG_STAT 11
+# define MSG_INFO 12
+
+/* buffer for msgctl calls IPC_INFO, MSG_INFO */
+struct msginfo
+ {
+ int msgpool;
+ int msgmap;
+ int msgmax;
+ int msgmnb;
+ int msgmni;
+ int msgssz;
+ int msgtql;
+ unsigned short int msgseg;
+ };
+
+#endif /* __USE_MISC */
diff --git a/ports/sysdeps/unix/sysv/linux/generic/bits/sem.h b/ports/sysdeps/unix/sysv/linux/generic/bits/sem.h
new file mode 100644
index 0000000000..003961717f
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/bits/sem.h
@@ -0,0 +1,92 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_SEM_H
+# error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
+#endif
+
+#include <sys/types.h>
+#include <bits/wordsize.h>
+
+/* Flags for `semop'. */
+#define SEM_UNDO 0x1000 /* undo the operation on exit */
+
+/* Commands for `semctl'. */
+#define GETPID 11 /* get sempid */
+#define GETVAL 12 /* get semval */
+#define GETALL 13 /* get all semval's */
+#define GETNCNT 14 /* get semncnt */
+#define GETZCNT 15 /* get semzcnt */
+#define SETVAL 16 /* set semval */
+#define SETALL 17 /* set all semval's */
+
+
+/* Data structure describing a set of semaphores. */
+struct semid_ds
+{
+ struct ipc_perm sem_perm; /* operation permission struct */
+ __time_t sem_otime; /* last semop() time */
+#if __WORDSIZE == 32
+ unsigned long int __unused1;
+#endif
+ __time_t sem_ctime; /* last time changed by semctl() */
+#if __WORDSIZE == 32
+ unsigned long int __unused2;
+#endif
+ unsigned long int sem_nsems; /* number of semaphores in set */
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+};
+
+/* The user should define a union like the following to use it for arguments
+ for `semctl'.
+
+ union semun
+ {
+ int val; <= value for SETVAL
+ struct semid_ds *buf; <= buffer for IPC_STAT & IPC_SET
+ unsigned short int *array; <= array for GETALL & SETALL
+ struct seminfo *__buf; <= buffer for IPC_INFO
+ };
+
+ Previous versions of this file used to define this union but this is
+ incorrect. One can test the macro _SEM_SEMUN_UNDEFINED to see whether
+ one must define the union or not. */
+#define _SEM_SEMUN_UNDEFINED 1
+
+#ifdef __USE_MISC
+
+/* ipcs ctl cmds */
+# define SEM_STAT 18
+# define SEM_INFO 19
+
+struct seminfo
+{
+ int semmap;
+ int semmni;
+ int semmns;
+ int semmnu;
+ int semmsl;
+ int semopm;
+ int semume;
+ int semusz;
+ int semvmx;
+ int semaem;
+};
+
+#endif /* __USE_MISC */
diff --git a/ports/sysdeps/unix/sysv/linux/generic/bits/shm.h b/ports/sysdeps/unix/sysv/linux/generic/bits/shm.h
new file mode 100644
index 0000000000..a22dd14ff7
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/bits/shm.h
@@ -0,0 +1,111 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_SHM_H
+# error "Never include <bits/shm.h> directly; use <sys/shm.h> instead."
+#endif
+
+#include <bits/types.h>
+#include <bits/wordsize.h>
+
+/* Permission flag for shmget. */
+#define SHM_R 0400 /* or S_IRUGO from <linux/stat.h> */
+#define SHM_W 0200 /* or S_IWUGO from <linux/stat.h> */
+
+/* Flags for `shmat'. */
+#define SHM_RDONLY 010000 /* attach read-only else read-write */
+#define SHM_RND 020000 /* round attach address to SHMLBA */
+#define SHM_REMAP 040000 /* take-over region on attach */
+#define SHM_EXEC 0100000 /* execution access */
+
+/* Commands for `shmctl'. */
+#define SHM_LOCK 11 /* lock segment (root only) */
+#define SHM_UNLOCK 12 /* unlock segment (root only) */
+
+__BEGIN_DECLS
+
+/* Segment low boundary address multiple. */
+#define SHMLBA (__getpagesize ())
+extern int __getpagesize (void) __THROW __attribute__ ((__const__));
+
+
+/* Type to count number of attaches. */
+typedef unsigned long int shmatt_t;
+
+/* Data structure describing a shared memory segment. */
+struct shmid_ds
+ {
+ struct ipc_perm shm_perm; /* operation permission struct */
+ size_t shm_segsz; /* size of segment in bytes */
+ __time_t shm_atime; /* time of last shmat() */
+#if __WORDSIZE == 32
+ unsigned long int __unused1;
+#endif
+ __time_t shm_dtime; /* time of last shmdt() */
+#if __WORDSIZE == 32
+ unsigned long int __unused2;
+#endif
+ __time_t shm_ctime; /* time of last change by shmctl() */
+#if __WORDSIZE == 32
+ unsigned long int __unused3;
+#endif
+ __pid_t shm_cpid; /* pid of creator */
+ __pid_t shm_lpid; /* pid of last shmop */
+ shmatt_t shm_nattch; /* number of current attaches */
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+ };
+
+#ifdef __USE_MISC
+
+/* ipcs ctl commands */
+# define SHM_STAT 13
+# define SHM_INFO 14
+
+/* shm_mode upper byte flags */
+# define SHM_DEST 01000 /* segment will be destroyed on last detach */
+# define SHM_LOCKED 02000 /* segment will not be swapped */
+# define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */
+# define SHM_NORESERVE 010000 /* don't check for reservations */
+
+struct shminfo
+ {
+ unsigned long int shmmax;
+ unsigned long int shmmin;
+ unsigned long int shmmni;
+ unsigned long int shmseg;
+ unsigned long int shmall;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+ };
+
+struct shm_info
+ {
+ int used_ids;
+ unsigned long int shm_tot; /* total allocated shm */
+ unsigned long int shm_rss; /* total resident shm */
+ unsigned long int shm_swp; /* total swapped shm */
+ unsigned long int swap_attempts;
+ unsigned long int swap_successes;
+ };
+
+#endif /* __USE_MISC */
+
+__END_DECLS
diff --git a/ports/sysdeps/unix/sysv/linux/generic/bits/stat.h b/ports/sysdeps/unix/sysv/linux/generic/bits/stat.h
new file mode 100644
index 0000000000..5de1bd0514
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/bits/stat.h
@@ -0,0 +1,171 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#if !defined _SYS_STAT_H && !defined _FCNTL_H
+# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
+#endif
+
+#ifndef _BITS_STAT_H
+#define _BITS_STAT_H 1
+
+#include <endian.h>
+#include <bits/wordsize.h>
+
+/* 64-bit libc uses the kernel's 'struct stat', accessed via the
+ stat() syscall; 32-bit libc uses the kernel's 'struct stat64'
+ and accesses it via the stat64() syscall. All the various
+ APIs offered by libc use the kernel shape for their struct stat
+ structure; the only difference is that 32-bit programs not
+ using __USE_FILE_OFFSET64 only see the low 32 bits of some
+ of the fields (specifically st_ino, st_size, and st_blocks). */
+#define _STAT_VER_KERNEL 0
+#define _STAT_VER_LINUX 0
+#define _STAT_VER _STAT_VER_KERNEL
+
+/* Versions of the `xmknod' interface. */
+#define _MKNOD_VER_LINUX 0
+
+#if defined __USE_FILE_OFFSET64
+# define __field64(type, type64, name) type64 name
+#elif __WORDSIZE == 64
+# define __field64(type, type64, name) type name
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+# define __field64(type, type64, name) \
+ type name __attribute__((__aligned__(8))); int __##name##_pad
+#else
+# define __field64(type, type64, name) \
+ int __##name##_pad __attribute__((__aligned__(8))); type name
+#endif
+
+struct stat
+ {
+ __dev_t st_dev; /* Device. */
+ __field64(__ino_t, __ino64_t, st_ino); /* File serial number. */
+ __mode_t st_mode; /* File mode. */
+ __nlink_t st_nlink; /* Link count. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ __dev_t st_rdev; /* Device number, if device. */
+ __dev_t __pad1;
+ __field64(__off_t, __off64_t, st_size); /* Size of file, in bytes. */
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ int __pad2;
+ __field64(__blkcnt_t, __blkcnt64_t, st_blocks); /* 512-byte blocks */
+#ifdef __USE_MISC
+ /* Nanosecond resolution timestamps are stored in a format
+ equivalent to 'struct timespec'. This is the type used
+ whenever possible but the Unix namespace rules do not allow the
+ identifier 'timespec' to appear in the <sys/stat.h> header.
+ Therefore we have to handle the use of this header in strictly
+ standard-compliant sources special. */
+ struct timespec st_atim; /* Time of last access. */
+ struct timespec st_mtim; /* Time of last modification. */
+ struct timespec st_ctim; /* Time of last status change. */
+# define st_atime st_atim.tv_sec /* Backward compatibility. */
+# define st_mtime st_mtim.tv_sec
+# define st_ctime st_ctim.tv_sec
+#else
+ __time_t st_atime; /* Time of last access. */
+ unsigned long int st_atimensec; /* Nscecs of last access. */
+ __time_t st_mtime; /* Time of last modification. */
+ unsigned long int st_mtimensec; /* Nsecs of last modification. */
+ __time_t st_ctime; /* Time of last status change. */
+ unsigned long int st_ctimensec; /* Nsecs of last status change. */
+#endif
+ int __unused[2];
+ };
+
+#undef __field64
+
+#ifdef __USE_LARGEFILE64
+struct stat64
+ {
+ __dev_t st_dev; /* Device. */
+ __ino64_t st_ino; /* File serial number. */
+ __mode_t st_mode; /* File mode. */
+ __nlink_t st_nlink; /* Link count. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ __dev_t st_rdev; /* Device number, if device. */
+ __dev_t __pad1;
+ __off64_t st_size; /* Size of file, in bytes. */
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ int __pad2;
+ __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */
+#ifdef __USE_MISC
+ /* Nanosecond resolution timestamps are stored in a format
+ equivalent to 'struct timespec'. This is the type used
+ whenever possible but the Unix namespace rules do not allow the
+ identifier 'timespec' to appear in the <sys/stat.h> header.
+ Therefore we have to handle the use of this header in strictly
+ standard-compliant sources special. */
+ struct timespec st_atim; /* Time of last access. */
+ struct timespec st_mtim; /* Time of last modification. */
+ struct timespec st_ctim; /* Time of last status change. */
+#else
+ __time_t st_atime; /* Time of last access. */
+ unsigned long int st_atimensec; /* Nscecs of last access. */
+ __time_t st_mtime; /* Time of last modification. */
+ unsigned long int st_mtimensec; /* Nsecs of last modification. */
+ __time_t st_ctime; /* Time of last status change. */
+ unsigned long int st_ctimensec; /* Nsecs of last status change. */
+#endif
+ int __unused[2];
+ };
+#endif
+
+/* Tell code we have these members. */
+#define _STATBUF_ST_BLKSIZE
+#define _STATBUF_ST_RDEV
+/* Nanosecond resolution time values are supported. */
+#define _STATBUF_ST_NSEC
+
+/* Encoding of the file mode. */
+
+#define __S_IFMT 0170000 /* These bits determine file type. */
+
+/* File types. */
+#define __S_IFDIR 0040000 /* Directory. */
+#define __S_IFCHR 0020000 /* Character device. */
+#define __S_IFBLK 0060000 /* Block device. */
+#define __S_IFREG 0100000 /* Regular file. */
+#define __S_IFIFO 0010000 /* FIFO. */
+#define __S_IFLNK 0120000 /* Symbolic link. */
+#define __S_IFSOCK 0140000 /* Socket. */
+
+/* POSIX.1b objects. Note that these macros always evaluate to zero. But
+ they do it by enforcing the correct use of the macros. */
+#define __S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode)
+#define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode)
+#define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode)
+
+/* Protection bits. */
+
+#define __S_ISUID 04000 /* Set user ID on execution. */
+#define __S_ISGID 02000 /* Set group ID on execution. */
+#define __S_ISVTX 01000 /* Save swapped text after use (sticky). */
+#define __S_IREAD 0400 /* Read by owner. */
+#define __S_IWRITE 0200 /* Write by owner. */
+#define __S_IEXEC 0100 /* Execute by owner. */
+
+#ifdef __USE_ATFILE
+# define UTIME_NOW ((1l << 30) - 1l)
+# define UTIME_OMIT ((1l << 30) - 2l)
+#endif
+
+#endif /* bits/stat.h */
diff --git a/ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h b/ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h
new file mode 100644
index 0000000000..bf479e875e
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h
@@ -0,0 +1,86 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_STATFS_H
+# error "Never include <bits/statfs.h> directly; use <sys/statfs.h> instead."
+#endif
+
+#include <endian.h>
+#include <bits/types.h>
+#include <bits/wordsize.h>
+
+/* 64-bit libc uses the kernel's 'struct statfs', accessed via the
+ statfs() syscall; 32-bit libc uses the kernel's 'struct statfs64'
+ and accesses it via the statfs64() syscall. All the various
+ APIs offered by libc use the kernel shape for their struct statfs
+ structure; the only difference is that 32-bit programs not
+ using __USE_FILE_OFFSET64 only see the low 32 bits of some
+ of the fields (the __fsblkcnt_t and __fsfilcnt_t fields). */
+
+#if defined __USE_FILE_OFFSET64
+# define __field64(type, type64, name) type64 name
+#elif __WORDSIZE == 64
+# define __field64(type, type64, name) type name
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+# define __field64(type, type64, name) \
+ type name __attribute__((__aligned__(8))); int __##name##_pad
+#else
+# define __field64(type, type64, name) \
+ int __##name##_pad __attribute__((__aligned__(8))); type name
+#endif
+
+struct statfs
+ {
+ __SWORD_TYPE f_type;
+ __SWORD_TYPE f_bsize;
+ __field64(__fsblkcnt_t, __fsblkcnt64_t, f_blocks);
+ __field64(__fsblkcnt_t, __fsblkcnt64_t, f_bfree);
+ __field64(__fsblkcnt_t, __fsblkcnt64_t, f_bavail);
+ __field64(__fsfilcnt_t, __fsfilcnt64_t, f_files);
+ __field64(__fsfilcnt_t, __fsfilcnt64_t, f_ffree);
+ __fsid_t f_fsid;
+ __SWORD_TYPE f_namelen;
+ __SWORD_TYPE f_frsize;
+ __SWORD_TYPE f_flags;
+ __SWORD_TYPE f_spare[4];
+ } __attribute__((__aligned__(8)));
+
+#undef __field64
+
+#ifdef __USE_LARGEFILE64
+struct statfs64
+ {
+ __SWORD_TYPE f_type;
+ __SWORD_TYPE f_bsize;
+ __fsblkcnt64_t f_blocks;
+ __fsblkcnt64_t f_bfree;
+ __fsblkcnt64_t f_bavail;
+ __fsfilcnt64_t f_files;
+ __fsfilcnt64_t f_ffree;
+ __fsid_t f_fsid;
+ __SWORD_TYPE f_namelen;
+ __SWORD_TYPE f_frsize;
+ __SWORD_TYPE f_flags;
+ __SWORD_TYPE f_spare[4];
+ } __attribute__((__aligned__(8)));
+#endif
+
+/* Tell code we have these members. */
+#define _STATFS_F_NAMELEN
+#define _STATFS_F_FRSIZE
+#define _STATFS_F_FLAGS
diff --git a/ports/sysdeps/unix/sysv/linux/generic/bits/typesizes.h b/ports/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
new file mode 100644
index 0000000000..948edeb96b
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
@@ -0,0 +1,69 @@
+/* bits/typesizes.h -- underlying types for *_t. For the generic Linux ABI.
+ Copyright (C) 2011-2012 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _BITS_TYPES_H
+# error "Never include <bits/typesizes.h> directly; use <sys/types.h> instead."
+#endif
+
+#ifndef _BITS_TYPESIZES_H
+#define _BITS_TYPESIZES_H 1
+
+/* See <bits/types.h> for the meaning of these macros. This file exists so
+ that <bits/types.h> need not vary across different GNU platforms. */
+
+#define __DEV_T_TYPE __UQUAD_TYPE
+#define __UID_T_TYPE __U32_TYPE
+#define __GID_T_TYPE __U32_TYPE
+#define __INO_T_TYPE __ULONGWORD_TYPE
+#define __INO64_T_TYPE __UQUAD_TYPE
+#define __MODE_T_TYPE __U32_TYPE
+#define __NLINK_T_TYPE __U32_TYPE
+#define __OFF_T_TYPE __SLONGWORD_TYPE
+#define __OFF64_T_TYPE __SQUAD_TYPE
+#define __PID_T_TYPE __S32_TYPE
+#define __RLIM_T_TYPE __ULONGWORD_TYPE
+#define __RLIM64_T_TYPE __UQUAD_TYPE
+#define __BLKCNT_T_TYPE __SLONGWORD_TYPE
+#define __BLKCNT64_T_TYPE __SQUAD_TYPE
+#define __FSBLKCNT_T_TYPE __ULONGWORD_TYPE
+#define __FSBLKCNT64_T_TYPE __UQUAD_TYPE
+#define __FSFILCNT_T_TYPE __ULONGWORD_TYPE
+#define __FSFILCNT64_T_TYPE __UQUAD_TYPE
+#define __FSWORD_T_TYPE __SWORD_TYPE
+#define __ID_T_TYPE __U32_TYPE
+#define __CLOCK_T_TYPE __SLONGWORD_TYPE
+#define __TIME_T_TYPE __SLONGWORD_TYPE
+#define __USECONDS_T_TYPE __U32_TYPE
+#define __SUSECONDS_T_TYPE __SLONGWORD_TYPE
+#define __DADDR_T_TYPE __S32_TYPE
+#define __SWBLK_T_TYPE __SLONGWORD_TYPE
+#define __KEY_T_TYPE __S32_TYPE
+#define __CLOCKID_T_TYPE __S32_TYPE
+#define __TIMER_T_TYPE void *
+#define __BLKSIZE_T_TYPE __S32_TYPE
+#define __FSID_T_TYPE struct { int __val[2]; }
+#define __SSIZE_T_TYPE __SWORD_TYPE
+#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
+#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
+
+/* Number of descriptors that can fit in an `fd_set'. */
+#define __FD_SETSIZE 1024
+
+
+#endif /* bits/typesizes.h */
diff --git a/ports/sysdeps/unix/sysv/linux/generic/brk.c b/ports/sysdeps/unix/sysv/linux/generic/brk.c
new file mode 100644
index 0000000000..006c3da079
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/brk.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sysdep.h>
+
+/* This must be initialized data because commons can't have aliases. */
+void *__curbrk = 0;
+
+/* Old braindamage in GCC's crtstuff.c requires this symbol in an attempt
+ to work around different old braindamage in the old Linux ELF dynamic
+ linker. */
+weak_alias (__curbrk, ___brk_addr)
+
+int
+__brk (void *addr)
+{
+ INTERNAL_SYSCALL_DECL (err);
+
+ __curbrk = (void *) INTERNAL_SYSCALL (brk, err, 1, addr);
+ if (__curbrk < addr)
+ {
+ __set_errno (ENOMEM);
+ return -1;
+ }
+
+ return 0;
+}
+weak_alias (__brk, brk)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/chmod.c b/ports/sysdeps/unix/sysv/linux/generic/chmod.c
new file mode 100644
index 0000000000..e3a791d96d
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/chmod.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+/* Change the protections of FILE to MODE. */
+int
+__chmod (const char *file, mode_t mode)
+{
+ return INLINE_SYSCALL (fchmodat, 3, AT_FDCWD, file, mode);
+}
+weak_alias (__chmod, chmod)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/chown.c b/ports/sysdeps/unix/sysv/linux/generic/chown.c
new file mode 100644
index 0000000000..f3e78362c4
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/chown.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+
+/* Change the owner and group of FILE. */
+int
+__chown (const char *file, uid_t owner, gid_t group)
+{
+ return INLINE_SYSCALL (fchownat, 5, AT_FDCWD, file, owner, group, 0);
+}
+libc_hidden_def (__chown)
+weak_alias (__chown, chown)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/creat.c b/ports/sysdeps/unix/sysv/linux/generic/creat.c
new file mode 100644
index 0000000000..db79e3b2f7
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/creat.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sysdep-cancel.h>
+
+#undef creat
+
+/* Create FILE with protections MODE. */
+int
+__libc_creat (const char *file, mode_t mode)
+{
+ return __open (file, O_WRONLY | O_CREAT | O_TRUNC, mode);
+}
+weak_alias (__libc_creat, creat)
+
+/* __open handles cancellation. */
+LIBC_CANCEL_HANDLED ();
+
+#if __WORDSIZE == 64
+weak_alias (__libc_creat, creat64)
+#endif
diff --git a/ports/sysdeps/unix/sysv/linux/generic/dl-origin.c b/ports/sysdeps/unix/sysv/linux/generic/dl-origin.c
new file mode 100644
index 0000000000..4502f15d01
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/dl-origin.c
@@ -0,0 +1,81 @@
+/* Find path of executable.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/param.h>
+#include <ldsodefs.h>
+#include <sysdep.h>
+
+#include <dl-dst.h>
+
+/* On Linux >= 2.1 systems which have the dcache implementation we can get
+ the path of the application from the /proc/self/exe symlink. Try this
+ first and fall back on the generic method if necessary. */
+
+const char *
+_dl_get_origin (void)
+{
+ char linkval[PATH_MAX];
+ char *result;
+ int len;
+ INTERNAL_SYSCALL_DECL (err);
+
+ len = INTERNAL_SYSCALL (readlinkat, err, 4, AT_FDCWD, "/proc/self/exe",
+ linkval, sizeof (linkval));
+ if (! INTERNAL_SYSCALL_ERROR_P (len, err) && len > 0 && linkval[0] != '[')
+ {
+ /* We can use this value. */
+ assert (linkval[0] == '/');
+ while (len > 1 && linkval[len - 1] != '/')
+ --len;
+ result = (char *) malloc (len + 1);
+ if (result == NULL)
+ result = (char *) -1;
+ else if (len == 1)
+ memcpy (result, "/", 2);
+ else
+ *((char *) __mempcpy (result, linkval, len - 1)) = '\0';
+ }
+ else
+ {
+ result = (char *) -1;
+ /* We use the environment variable LD_ORIGIN_PATH. If it is set make
+ a copy and strip out trailing slashes. */
+ if (GLRO(dl_origin_path) != NULL)
+ {
+ size_t len = strlen (GLRO(dl_origin_path));
+ result = (char *) malloc (len + 1);
+ if (result == NULL)
+ result = (char *) -1;
+ else
+ {
+ char *cp = __mempcpy (result, GLRO(dl_origin_path), len);
+ while (cp > result + 1 && cp[-1] == '/')
+ --cp;
+ *cp = '\0';
+ }
+ }
+ }
+
+ return result;
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/dup2.c b/ports/sysdeps/unix/sysv/linux/generic/dup2.c
new file mode 100644
index 0000000000..6dbcb94e6d
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/dup2.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <unistd.h>
+
+/* Duplicate FD to FD2, closing the old FD2 and making FD2 be
+ open the same file as FD is. Return FD2 or -1. */
+int
+__dup2 (int fd, int fd2)
+{
+ /* For the degenerate case, check if the fd is valid (by trying to
+ get the file status flags) and return it, or else return EBADF. */
+ if (fd == fd2)
+ return __libc_fcntl (fd, F_GETFL, 0) < 0 ? -1 : fd;
+
+ return INLINE_SYSCALL (dup3, 3, fd, fd2, 0);
+}
+libc_hidden_def (__dup2)
+weak_alias (__dup2, dup2)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/epoll_create.c b/ports/sysdeps/unix/sysv/linux/generic/epoll_create.c
new file mode 100644
index 0000000000..2e0aff4382
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/epoll_create.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stddef.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/epoll.h>
+
+libc_hidden_proto (epoll_create)
+
+int
+epoll_create (int size)
+{
+ if (size <= 0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return INLINE_SYSCALL (epoll_create1, 1, 0);
+}
+libc_hidden_def (epoll_create)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/epoll_wait.c b/ports/sysdeps/unix/sysv/linux/generic/epoll_wait.c
new file mode 100644
index 0000000000..112777a863
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/epoll_wait.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stddef.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/epoll.h>
+
+int
+epoll_wait (int epfd, struct epoll_event *events, int maxevents, int timeout)
+{
+ return epoll_pwait (epfd, events, maxevents, timeout, NULL);
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/futimesat.c b/ports/sysdeps/unix/sysv/linux/generic/futimesat.c
new file mode 100644
index 0000000000..46ce0cc8ba
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/futimesat.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <utime.h>
+#include <sys/time.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+
+
+/* Change the access time of FILE relative to FD to TVP[0] and
+ the modification time of FILE to TVP[1]. */
+int
+futimesat (int fd, const char *file, const struct timeval tvp[2])
+{
+ struct timespec tsp[2];
+ int result;
+
+ if (tvp)
+ {
+ if (tvp[0].tv_usec >= 1000000 || tvp[0].tv_usec < 0 ||
+ tvp[1].tv_usec >= 1000000 || tvp[1].tv_usec < 0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ TIMEVAL_TO_TIMESPEC (&tvp[0], &tsp[0]);
+ TIMEVAL_TO_TIMESPEC (&tvp[1], &tsp[1]);
+ }
+
+ result = INLINE_SYSCALL (utimensat, 4, fd, file, tvp ? tsp : NULL, 0);
+ return result;
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/getdents.c b/ports/sysdeps/unix/sysv/linux/generic/getdents.c
new file mode 100644
index 0000000000..14dbbc71a0
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/getdents.c
@@ -0,0 +1 @@
+/* Defined in getdents64.c */
diff --git a/ports/sysdeps/unix/sysv/linux/generic/getdents64.c b/ports/sysdeps/unix/sysv/linux/generic/getdents64.c
new file mode 100644
index 0000000000..abbb729fa9
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/getdents64.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stddef.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <bits/wordsize.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* The kernel struct linux_dirent64 matches the 'struct getdents64' type. */
+ssize_t
+__getdents64 (int fd, char *buf, size_t nbytes)
+{
+ return INLINE_SYSCALL (getdents64, 3, fd, buf, nbytes);
+}
+
+#if __WORDSIZE == 64
+strong_alias (__getdents64, __getdents)
+#endif
diff --git a/ports/sysdeps/unix/sysv/linux/generic/inotify_init.c b/ports/sysdeps/unix/sysv/linux/generic/inotify_init.c
new file mode 100644
index 0000000000..0b529b9946
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/inotify_init.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stddef.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/inotify.h>
+
+libc_hidden_proto (inotify_init)
+
+int
+inotify_init (void)
+{
+ return INLINE_SYSCALL (inotify_init1, 1, 0);
+}
+libc_hidden_def (inotify_init)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/kernel_stat.h b/ports/sysdeps/unix/sysv/linux/generic/kernel_stat.h
new file mode 100644
index 0000000000..6ae827fdfe
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/kernel_stat.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <bits/wordsize.h>
+
+#define STAT_IS_KERNEL_STAT 1
+
+/* We provide separate 32-bit API versions that check for EOVERFLOW. */
+#if __WORDSIZE == 64
+# define XSTAT_IS_XSTAT64 1
+#endif
diff --git a/ports/sysdeps/unix/sysv/linux/generic/lchown.c b/ports/sysdeps/unix/sysv/linux/generic/lchown.c
new file mode 100644
index 0000000000..f0907208b6
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/lchown.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+
+/* Change the owner and group of FILE. */
+int
+__lchown (const char *file, uid_t owner, gid_t group)
+{
+ return INLINE_SYSCALL (fchownat, 5, AT_FDCWD, file, owner, group,
+ AT_SYMLINK_NOFOLLOW);
+}
+weak_alias (__lchown, lchown)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/link.c b/ports/sysdeps/unix/sysv/linux/generic/link.c
new file mode 100644
index 0000000000..49fffb4f12
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/link.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+/* Make a link to FROM called TO. */
+int
+__link (const char *from, const char *to)
+{
+ return INLINE_SYSCALL (linkat, 5, AT_FDCWD, from, AT_FDCWD, to, 0);
+}
+
+weak_alias (__link, link)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/lxstat.c b/ports/sysdeps/unix/sysv/linux/generic/lxstat.c
new file mode 100644
index 0000000000..1336a910c0
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/lxstat.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* Ignore prototype to avoid error if we alias __lxstat and __lxstat64. */
+#define __lxstat64 __lxstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Get information about the file NAME in BUF. */
+int
+__lxstat (int vers, const char *name, struct stat *buf)
+{
+ if (vers == _STAT_VER_KERNEL)
+ return INLINE_SYSCALL (newfstatat, 4, AT_FDCWD, name, buf,
+ AT_SYMLINK_NOFOLLOW);
+ errno = EINVAL;
+ return -1;
+}
+
+hidden_def (__lxstat)
+weak_alias (__lxstat, _lxstat);
+#ifdef XSTAT_IS_XSTAT64
+#undef __lxstat64
+strong_alias (__lxstat, __lxstat64);
+hidden_ver (__lxstat, __lxstat64)
+#endif
diff --git a/ports/sysdeps/unix/sysv/linux/generic/mkdir.c b/ports/sysdeps/unix/sysv/linux/generic/mkdir.c
new file mode 100644
index 0000000000..5ad64c1104
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/mkdir.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sysdep.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+
+/* Create a directory named PATH with protections MODE. */
+int
+__mkdir (const char *path, mode_t mode)
+{
+ return INLINE_SYSCALL (mkdirat, 3, AT_FDCWD, path, mode);
+}
+weak_alias (__mkdir, mkdir)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/not-cancel.h b/ports/sysdeps/unix/sysv/linux/generic/not-cancel.h
new file mode 100644
index 0000000000..512252a8d0
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/not-cancel.h
@@ -0,0 +1,34 @@
+/* Uncancelable versions of cancelable interfaces. Linux asm-generic version.
+ Copyright (C) 2012 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2012.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _LINUX_GENERIC_NOT_CANCEL_H
+#define _LINUX_GENERIC_NOT_CANCEL_H
+
+#include <sysdeps/unix/sysv/linux/not-cancel.h>
+#include <fcntl.h>
+
+/* Uncancelable open with openat. */
+#undef open_not_cancel
+#define open_not_cancel(name, flags, mode) \
+ INLINE_SYSCALL (openat, 4, AT_FDCWD, (const char *) (name), (flags), (mode))
+#undef open_not_cancel_2
+#define open_not_cancel_2(name, flags) \
+ INLINE_SYSCALL (openat, 3, AT_FDCWD, (const char *) (name), (flags))
+
+#endif
diff --git a/ports/sysdeps/unix/sysv/linux/generic/nptl/not-cancel.h b/ports/sysdeps/unix/sysv/linux/generic/nptl/not-cancel.h
new file mode 100644
index 0000000000..e6a0d135c8
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/nptl/not-cancel.h
@@ -0,0 +1 @@
+#include <nptl/sysdeps/unix/sysv/linux/i386/not-cancel.h>
diff --git a/ports/sysdeps/unix/sysv/linux/generic/open.c b/ports/sysdeps/unix/sysv/linux/generic/open.c
new file mode 100644
index 0000000000..2f895033bf
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/open.c
@@ -0,0 +1,71 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <sysdep-cancel.h>
+
+/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
+ a third argument is the file protection. */
+int
+__libc_open (const char *file, int oflag, ...)
+{
+ int mode = 0;
+
+ if (oflag & O_CREAT)
+ {
+ va_list arg;
+ va_start (arg, oflag);
+ mode = va_arg (arg, int);
+ va_end (arg);
+ }
+
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (openat, 4, AT_FDCWD, file, oflag, mode);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = INLINE_SYSCALL (openat, 4, AT_FDCWD, file, oflag, mode);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+libc_hidden_def (__libc_open)
+
+weak_alias (__libc_open, __open)
+libc_hidden_weak (__open)
+weak_alias (__libc_open, open)
+
+int
+__open_nocancel (const char *file, int oflag, ...)
+{
+ int mode = 0;
+
+ if (oflag & O_CREAT)
+ {
+ va_list arg;
+ va_start (arg, oflag);
+ mode = va_arg (arg, int);
+ va_end (arg);
+ }
+
+ return INLINE_SYSCALL (openat, 4, AT_FDCWD, file, oflag, mode);
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/open64.c b/ports/sysdeps/unix/sysv/linux/generic/open64.c
new file mode 100644
index 0000000000..4597a79831
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/open64.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <sysdep-cancel.h>
+
+/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
+ a third argument is the file protection. */
+int
+__libc_open64 (const char *file, int oflag, ...)
+{
+ int mode = 0;
+
+ if (oflag & O_CREAT)
+ {
+ va_list arg;
+ va_start (arg, oflag);
+ mode = va_arg (arg, int);
+ va_end (arg);
+ }
+
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (openat, 4, AT_FDCWD, file,
+ oflag | O_LARGEFILE, mode);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = INLINE_SYSCALL (openat, 4, AT_FDCWD, file,
+ oflag | O_LARGEFILE, mode);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+weak_alias (__libc_open64, __open64)
+libc_hidden_weak (__open64)
+weak_alias (__libc_open64, open64)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/pause.c b/ports/sysdeps/unix/sysv/linux/generic/pause.c
new file mode 100644
index 0000000000..805b5d4bce
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/pause.c
@@ -0,0 +1,63 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <signal.h>
+#include <unistd.h>
+#include <sysdep-cancel.h>
+
+/* Suspend the process until a signal arrives.
+ This always returns -1 and sets errno to EINTR. */
+
+static int
+__syscall_pause (void)
+{
+ sigset_t set;
+
+ int rc =
+ INLINE_SYSCALL (rt_sigprocmask, 4, SIG_BLOCK, NULL, &set, _NSIG / 8);
+ if (rc == 0)
+ rc = INLINE_SYSCALL (rt_sigsuspend, 2, &set, _NSIG / 8);
+
+ return rc;
+}
+
+int
+__libc_pause (void)
+{
+ if (SINGLE_THREAD_P)
+ return __syscall_pause ();
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = __syscall_pause ();
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+weak_alias (__libc_pause, pause)
+
+#ifndef NO_CANCELLATION
+# include <not-cancel.h>
+
+int
+__pause_nocancel (void)
+{
+ return __syscall_pause ();
+}
+#endif
diff --git a/ports/sysdeps/unix/sysv/linux/generic/pipe.c b/ports/sysdeps/unix/sysv/linux/generic/pipe.c
new file mode 100644
index 0000000000..ca5c533355
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/pipe.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <stddef.h>
+
+/* Create a one-way communication channel (__pipe).
+ If successful, two file descriptors are stored in PIPEDES;
+ bytes written on PIPEDES[1] can be read from PIPEDES[0].
+ Returns 0 if successful, -1 if not. */
+int
+__pipe (int __pipedes[2])
+{
+ return INLINE_SYSCALL (pipe2, 2, __pipedes, 0);
+}
+libc_hidden_def (__pipe)
+weak_alias (__pipe, pipe)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/poll.c b/ports/sysdeps/unix/sysv/linux/generic/poll.c
new file mode 100644
index 0000000000..d1dcd8a866
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/poll.c
@@ -0,0 +1,53 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sys/poll.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+int
+__poll (struct pollfd *fds, nfds_t nfds, int timeout)
+{
+ struct timespec timeout_ts;
+ struct timespec *timeout_ts_p = NULL;
+
+ if (timeout >= 0)
+ {
+ timeout_ts.tv_sec = timeout / 1000;
+ timeout_ts.tv_nsec = (timeout % 1000) * 1000000;
+ timeout_ts_p = &timeout_ts;
+ }
+
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (ppoll, 5, fds, nfds, timeout_ts_p, NULL, 0);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = INLINE_SYSCALL (ppoll, 5, fds, nfds, timeout_ts_p, NULL, 0);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+libc_hidden_def (__poll)
+weak_alias (__poll, poll)
+strong_alias (__poll, __libc_poll)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/readlink.c b/ports/sysdeps/unix/sysv/linux/generic/readlink.c
new file mode 100644
index 0000000000..09cbf2b9a1
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/readlink.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+/* Read the contents of the symbolic link PATH into no more than
+ LEN bytes of BUF. The contents are not null-terminated.
+ Returns the number of characters read, or -1 for errors. */
+ssize_t
+__readlink (const char *path, char *buf, size_t len)
+{
+ return INLINE_SYSCALL (readlinkat, 4, AT_FDCWD, path, buf, len);
+}
+weak_alias (__readlink, readlink)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/readlink_chk.c b/ports/sysdeps/unix/sysv/linux/generic/readlink_chk.c
new file mode 100644
index 0000000000..e1724aafeb
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/readlink_chk.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/param.h>
+#ifdef HAVE_INLINED_SYSCALLS
+# include <errno.h>
+# include <sysdep.h>
+#endif
+
+
+ssize_t
+__readlink_chk (const char *path, void *buf, size_t len, size_t buflen)
+{
+ if (len > buflen)
+ __chk_fail ();
+
+#ifdef HAVE_INLINED_SYSCALLS
+ return INLINE_SYSCALL (readlinkat, 4, AT_FDCWD, path, buf, len);
+#else
+ return __readlink (path, buf, len);
+#endif
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/recv.c b/ports/sysdeps/unix/sysv/linux/generic/recv.c
new file mode 100644
index 0000000000..ebff889979
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/recv.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sysdep-cancel.h>
+#include <libc-symbols.h>
+
+ssize_t
+__libc_recv (int sockfd, void *buffer, size_t len, int flags)
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ result = INLINE_SYSCALL (recvfrom, 6, sockfd, buffer, len, flags,
+ NULL, NULL);
+ else
+ {
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ result = INLINE_SYSCALL (recvfrom, 6, sockfd, buffer, len, flags,
+ NULL, NULL);
+
+ LIBC_CANCEL_RESET (oldtype);
+ }
+
+ return result;
+}
+strong_alias (__libc_recv, __recv)
+weak_alias (__libc_recv, recv)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/rename.c b/ports/sysdeps/unix/sysv/linux/generic/rename.c
new file mode 100644
index 0000000000..50056e4ebe
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/rename.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sysdep.h>
+
+/* Rename the file OLD to NEW. */
+int
+rename (const char *old, const char *new)
+{
+ return INLINE_SYSCALL (renameat, 4, AT_FDCWD, old, AT_FDCWD, new);
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/rmdir.c b/ports/sysdeps/unix/sysv/linux/generic/rmdir.c
new file mode 100644
index 0000000000..97e0681628
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/rmdir.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+
+/* Remove the directory PATH. */
+int
+__rmdir (const char *path)
+{
+ return INLINE_SYSCALL (unlinkat, 3, AT_FDCWD, path, AT_REMOVEDIR);
+}
+weak_alias (__rmdir, rmdir)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/select.c b/ports/sysdeps/unix/sysv/linux/generic/select.c
new file mode 100644
index 0000000000..143ebc9a07
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/select.c
@@ -0,0 +1,74 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/select.h>
+#include <errno.h>
+#include <sysdep-cancel.h>
+
+/* Check the first NFDS descriptors each in READFDS (if not NULL) for read
+ readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
+ (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out
+ after waiting the interval specified therein. Returns the number of ready
+ descriptors, or -1 for errors. */
+
+int
+__select(int nfds, fd_set *readfds,
+ fd_set *writefds, fd_set *exceptfds,
+ struct timeval *timeout)
+{
+ int result;
+ struct timespec ts, *tsp = NULL;
+
+ if (timeout)
+ {
+ TIMEVAL_TO_TIMESPEC (timeout, &ts);
+ tsp = &ts;
+ }
+
+ if (SINGLE_THREAD_P)
+ {
+ result = INLINE_SYSCALL (pselect6, 6, nfds, readfds, writefds, exceptfds,
+ tsp, NULL);
+ }
+ else
+ {
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ result = INLINE_SYSCALL (pselect6, 6, nfds, readfds, writefds, exceptfds,
+ tsp, NULL);
+
+ LIBC_CANCEL_RESET (oldtype);
+ }
+
+ if (timeout)
+ {
+ /* Linux by default will update the timeout after a pselect6 syscall
+ (though the pselect() glibc call suppresses this behavior).
+ Since select() on Linux has the same behavior as the pselect6
+ syscall, we update the timeout here. */
+ TIMESPEC_TO_TIMEVAL (timeout, &ts);
+ }
+
+ return result;
+}
+libc_hidden_def (__select)
+
+weak_alias (__select, select)
+weak_alias (__select, __libc_select)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/send.c b/ports/sysdeps/unix/sysv/linux/generic/send.c
new file mode 100644
index 0000000000..28af554ed2
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/send.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sysdep-cancel.h>
+#include <libc-symbols.h>
+
+ssize_t
+__libc_send (int sockfd, const void *buffer, size_t len, int flags)
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ result = INLINE_SYSCALL (sendto, 6, sockfd, buffer, len, flags, NULL, 0);
+ else
+ {
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ result = INLINE_SYSCALL (sendto, 6, sockfd, buffer, len, flags, NULL, 0);
+
+ LIBC_CANCEL_RESET (oldtype);
+ }
+
+ return result;
+}
+strong_alias (__libc_send, __send)
+weak_alias (__libc_send, send)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/symlink.c b/ports/sysdeps/unix/sysv/linux/generic/symlink.c
new file mode 100644
index 0000000000..3d947c5e72
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/symlink.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+/* Make a link to FROM called TO. */
+int
+__symlink (const char *from, const char *to)
+{
+ return INLINE_SYSCALL (symlinkat, 3, from, AT_FDCWD, to);
+}
+weak_alias (__symlink, symlink)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/syscalls.list b/ports/sysdeps/unix/sysv/linux/generic/syscalls.list
new file mode 100644
index 0000000000..4b2e74762f
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/syscalls.list
@@ -0,0 +1,32 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+# SysV APIs
+msgget - msgget i:ii __msgget msgget
+msgctl - msgctl i:iip __msgctl msgctl
+msgrcv - msgrcv Ci:ibnii __msgrcv msgrcv
+msgsnd - msgsnd Ci:ibni __msgsnd msgsnd
+semget - semget i:iii __semget semget
+semctl - semctl i:iiii __semctl semctl
+semtimedop - semtimedop i:ipip semtimedop
+semop - semop i:ipi __semop semop
+shmget - shmget i:iii __shmget shmget
+shmctl - shmctl i:iip __shmctl shmctl
+shmat - shmat i:ipi __shmat shmat
+shmdt - shmdt i:s __shmdt shmdt
+
+# Socket APIs
+socket - socket i:iii __socket socket
+socketpair - socketpair i:iiif __socketpair socketpair
+bind - bind i:ipi __bind bind
+listen - listen i:ii __listen listen
+accept - accept Ci:iBN __libc_accept __accept accept
+connect - connect Ci:ipi __libc_connect __connect connect
+getsockname - getsockname i:ipp __getsockname getsockname
+getpeername - getpeername i:ipp __getpeername getpeername
+sendto - sendto Ci:ibnibn __libc_sendto __sendto sendto
+recvfrom - recvfrom Ci:ibniBN __libc_recvfrom __recvfrom recvfrom
+setsockopt - setsockopt i:iiibn __setsockopt setsockopt
+getsockopt - getsockopt i:iiiBN __getsockopt getsockopt
+shutdown - shutdown i:ii __shutdown shutdown
+sendmsg - sendmsg Ci:ipi __libc_sendmsg __sendmsg sendmsg
+recvmsg - recvmsg Ci:ipi __libc_recvmsg __recvmsg recvmsg
diff --git a/ports/sysdeps/unix/sysv/linux/generic/sysctl.c b/ports/sysdeps/unix/sysv/linux/generic/sysctl.c
new file mode 100644
index 0000000000..0bdb78660b
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/sysctl.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* This deprecated syscall is no longer used (replaced with /proc/sys). */
+int
+sysctl (int *name, int nlen, void *oldval, size_t *oldlenp,
+ void *newval, size_t newlen)
+{
+ __set_errno (ENOSYS);
+ return -1;
+}
+stub_warning (sysctl)
+#include <stub-tag.h>
diff --git a/ports/sysdeps/unix/sysv/linux/generic/sysdep.h b/ports/sysdeps/unix/sysv/linux/generic/sysdep.h
new file mode 100644
index 0000000000..842a196386
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/sysdep.h
@@ -0,0 +1,41 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <bits/wordsize.h>
+#include <kernel-features.h>
+
+/* Provide the common name to allow more code reuse. */
+#define __NR__llseek __NR_llseek
+
+#if __WORDSIZE == 64
+/* By defining the older names, glibc will build syscall wrappers for
+ both pread and pread64; sysdeps/unix/sysv/linux/wordsize-64/pread64.c
+ will suppress generating any separate code for pread64.c. */
+#define __NR_pread __NR_pread64
+#define __NR_pwrite __NR_pwrite64
+#endif
+
+/* Provide a dummy argument that can be used to force register
+ alignment for register pairs if required by the syscall ABI. */
+#ifdef __ASSUME_ALIGNED_REGISTER_PAIRS
+#define __ALIGNMENT_ARG 0,
+#define __ALIGNMENT_COUNT(a,b) b
+#else
+#define __ALIGNMENT_ARG
+#define __ALIGNMENT_COUNT(a,b) a
+#endif
diff --git a/ports/sysdeps/unix/sysv/linux/generic/umount.c b/ports/sysdeps/unix/sysv/linux/generic/umount.c
new file mode 100644
index 0000000000..c799b22ba6
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/umount.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* Since the generic Linux syscall ABI doesn't have an oldumount system call,
+ do what the kernel does down here. */
+
+extern long int __umount2 (const char *name, int flags);
+
+long int
+__umount (const char *name)
+{
+ return __umount2 (name, 0);
+}
+
+weak_alias (__umount, umount);
diff --git a/ports/sysdeps/unix/sysv/linux/generic/unlink.c b/ports/sysdeps/unix/sysv/linux/generic/unlink.c
new file mode 100644
index 0000000000..3969867f29
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/unlink.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+
+/* Remove the link named NAME. */
+int
+__unlink (const char *name)
+{
+ return INLINE_SYSCALL (unlinkat, 3, AT_FDCWD, name, 0);
+}
+weak_alias (__unlink, unlink)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/ustat.c b/ports/sysdeps/unix/sysv/linux/generic/ustat.c
new file mode 100644
index 0000000000..7611e82f0f
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/ustat.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sys/ustat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* This deprecated syscall is no longer used (replaced with fstat). */
+int
+ustat (dev_t dev, struct ustat *ubuf)
+{
+ __set_errno (ENOSYS);
+ return -1;
+}
+stub_warning (ustat)
+#include <stub-tag.h>
diff --git a/ports/sysdeps/unix/sysv/linux/generic/utimes.c b/ports/sysdeps/unix/sysv/linux/generic/utimes.c
new file mode 100644
index 0000000000..9ecef48c71
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/utimes.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <utime.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <sysdep.h>
+
+
+/* Change the access time of FILE to TVP[0] and
+ the modification time of FILE to TVP[1]. */
+int
+__utimes (const char *file, const struct timeval tvp[2])
+{
+ struct timespec ts[2];
+ struct timespec *tsp = NULL;
+
+ if (tvp)
+ {
+ TIMEVAL_TO_TIMESPEC (&tvp[0], &ts[0]);
+ TIMEVAL_TO_TIMESPEC (&tvp[1], &ts[1]);
+ tsp = &ts[0];
+ }
+
+ return INLINE_SYSCALL (utimensat, 4, AT_FDCWD, file, tsp, 0);
+}
+
+weak_alias (__utimes, utimes)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/Versions b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/Versions
new file mode 100644
index 0000000000..cdc6022015
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/Versions
@@ -0,0 +1,5 @@
+libc {
+ GLIBC_2.15 {
+ fallocate64;
+ }
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c
new file mode 100644
index 0000000000..b66190bc08
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <assert.h>
+#include <errno.h>
+#include <sysdep-cancel.h> /* Must come before <fcntl.h>. */
+#include <fcntl.h>
+#include <stdarg.h>
+
+#include <sys/syscall.h>
+#include <kernel-features.h>
+
+
+static int
+do_fcntl (int fd, int cmd, void *arg)
+{
+ if (cmd != F_GETOWN)
+ return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
+
+ INTERNAL_SYSCALL_DECL (err);
+ struct f_owner_ex fex;
+ int res = INTERNAL_SYSCALL (fcntl64, err, 3, fd, F_GETOWN_EX, &fex);
+ if (!INTERNAL_SYSCALL_ERROR_P (res, err))
+ return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
+
+ __set_errno (INTERNAL_SYSCALL_ERRNO (res, err));
+ return -1;
+}
+
+
+#ifndef NO_CANCELLATION
+int
+__fcntl_nocancel (int fd, int cmd, ...)
+{
+ va_list ap;
+ void *arg;
+
+ va_start (ap, cmd);
+ arg = va_arg (ap, void *);
+ va_end (ap);
+
+ return do_fcntl (fd, cmd, arg);
+}
+#endif
+
+
+int
+__libc_fcntl (int fd, int cmd, ...)
+{
+ va_list ap;
+ void *arg;
+
+ va_start (ap, cmd);
+ arg = va_arg (ap, void *);
+ va_end (ap);
+
+ if (SINGLE_THREAD_P || cmd != F_SETLKW)
+ return do_fcntl (fd, cmd, arg);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = do_fcntl (fd, cmd, arg);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+libc_hidden_def (__libc_fcntl)
+
+weak_alias (__libc_fcntl, __fcntl)
+libc_hidden_weak (__fcntl)
+weak_alias (__libc_fcntl, fcntl)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c
new file mode 100644
index 0000000000..21d92d6cb3
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sys/statfs.h>
+#include <stddef.h>
+
+#include "overflow.h"
+
+/* Return information about the filesystem on which FD resides. */
+int
+__fstatfs (int fd, struct statfs *buf)
+{
+ int rc = INLINE_SYSCALL (fstatfs64, 3, fd, sizeof (*buf), buf);
+ return rc ?: statfs_overflow (buf);
+}
+weak_alias (__fstatfs, fstatfs)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
new file mode 100644
index 0000000000..a5b5808ebe
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+/* Truncate the file FD refers to to LENGTH bytes. */
+int
+__ftruncate (int fd, off_t length)
+{
+ return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd,
+ __ALIGNMENT_ARG
+ __LONG_LONG_PAIR (length >> 31, length));
+}
+weak_alias (__ftruncate, ftruncate)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
new file mode 100644
index 0000000000..4ccfa78b4d
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+/* Truncate the file FD refers to to LENGTH bytes. */
+int
+__ftruncate64 (int fd, off64_t length)
+{
+ unsigned int low = length & 0xffffffff;
+ unsigned int high = length >> 32;
+ return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd,
+ __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
+}
+weak_alias (__ftruncate64, ftruncate64)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstat.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstat.c
new file mode 100644
index 0000000000..70551bedca
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstat.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include "overflow.h"
+
+/* Get information about the file FD in BUF. */
+int
+__fxstat (int vers, int fd, struct stat *buf)
+{
+ if (vers == _STAT_VER_KERNEL)
+ {
+ int rc = INLINE_SYSCALL (fstat64, 2, fd, buf);
+ return rc ?: stat_overflow (buf);
+ }
+
+ errno = EINVAL;
+ return -1;
+}
+
+hidden_def (__fxstat)
+weak_alias (__fxstat, _fxstat);
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstatat.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstatat.c
new file mode 100644
index 0000000000..790d85c981
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstatat.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <kernel-features.h>
+
+#include "overflow.h"
+
+/* Get information about the file NAME in BUF. */
+int
+__fxstatat (int vers, int fd, const char *file, struct stat *buf, int flag)
+{
+ if (vers == _STAT_VER_KERNEL)
+ {
+ int rc = INLINE_SYSCALL (fstatat64, 4, fd, file, buf, flag);
+ return rc ?: stat_overflow (buf);
+ }
+
+ errno = EINVAL;
+ return -1;
+}
+libc_hidden_def (__fxstatat)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c
new file mode 100644
index 0000000000..d7d0f04f43
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c
@@ -0,0 +1,115 @@
+/* Copyright (C) 1993, 1995-2003, 2004, 2006, 2007, 2011
+ This file is part of the GNU C Library.
+ Simplified from sysdeps/unix/sysv/linux/getdents.c.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <alloca.h>
+#include <assert.h>
+#include <errno.h>
+#include <dirent.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Pack the dirent64 struct down into 32-bit offset/inode fields, and
+ ensure that no overflow occurs. */
+ssize_t
+__getdents (int fd, char *buf, size_t nbytes)
+{
+ union
+ {
+ struct dirent64 k; /* Kernel structure. */
+ struct dirent u;
+ char b[1];
+ } *kbuf = (void *) buf, *outp, *inp;
+ size_t kbytes = nbytes;
+ off64_t last_offset = -1;
+ ssize_t retval;
+
+ const size_t size_diff = (offsetof (struct dirent64, d_name)
+ - offsetof (struct dirent, d_name));
+ if (nbytes <= sizeof (struct dirent))
+ {
+ kbytes = nbytes + offsetof (struct dirent64, d_name)
+ - offsetof (struct dirent, d_name);
+ kbuf = __alloca(kbytes);
+ }
+
+ retval = INLINE_SYSCALL (getdents64, 3, fd, kbuf, kbytes);
+ if (retval == -1)
+ return -1;
+
+ /* These two pointers might alias the same memory buffer.
+ Standard C requires that we always use the same type for them,
+ so we must use the union type. */
+ inp = kbuf;
+ outp = (void *) buf;
+
+ while (&inp->b < &kbuf->b + retval)
+ {
+ const size_t alignment = __alignof__ (struct dirent);
+ /* Since inp->k.d_reclen is already aligned for the kernel
+ structure this may compute a value that is bigger
+ than necessary. */
+ size_t old_reclen = inp->k.d_reclen;
+ size_t new_reclen = ((old_reclen - size_diff + alignment - 1)
+ & ~(alignment - 1));
+
+ /* Copy the data out of the old structure into temporary space.
+ Then copy the name, which may overlap if BUF == KBUF. */
+ const uint64_t d_ino = inp->k.d_ino;
+ const int64_t d_off = inp->k.d_off;
+ const uint8_t d_type = inp->k.d_type;
+
+ memmove (outp->u.d_name, inp->k.d_name,
+ old_reclen - offsetof (struct dirent64, d_name));
+
+ /* Now we have copied the data from INP and access only OUTP. */
+
+ outp->u.d_ino = d_ino;
+ outp->u.d_off = d_off;
+ if ((sizeof (outp->u.d_ino) != sizeof (inp->k.d_ino)
+ && outp->u.d_ino != d_ino)
+ || (sizeof (outp->u.d_off) != sizeof (inp->k.d_off)
+ && outp->u.d_off != d_off))
+ {
+ /* Overflow. If there was at least one entry before this one,
+ return them without error, otherwise signal overflow. */
+ if (last_offset != -1)
+ {
+ __lseek64 (fd, last_offset, SEEK_SET);
+ return outp->b - buf;
+ }
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+
+ last_offset = d_off;
+ outp->u.d_reclen = new_reclen;
+ outp->u.d_type = d_type;
+
+ inp = (void *) inp + old_reclen;
+ outp = (void *) outp + new_reclen;
+ }
+
+ return outp->b - buf;
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c
new file mode 100644
index 0000000000..699e602536
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sys/types.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Seek to OFFSET on FD, starting from WHENCE. */
+extern loff_t __llseek (int fd, loff_t offset, int whence);
+
+loff_t
+__llseek (int fd, loff_t offset, int whence)
+{
+ loff_t retval;
+
+ return (loff_t) (INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff),
+ &retval, whence) ?: retval);
+}
+weak_alias (__llseek, llseek)
+strong_alias (__llseek, __libc_lseek64)
+strong_alias (__llseek, __lseek64)
+weak_alias (__llseek, lseek64)
+
+/* llseek doesn't have a prototype. Since the second parameter is a
+ 64bit type, this results in wrong behaviour if no prototype is
+ provided. */
+link_warning (llseek, "\
+the `llseek' function may be dangerous; use `lseek64' instead.")
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c
new file mode 100644
index 0000000000..a9a75e88a0
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include "overflow.h"
+
+off_t
+__lseek (int fd, off_t offset, int whence)
+{
+ loff_t res;
+ int rc = INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 31),
+ (off_t) offset, &res, whence);
+ return rc ?: lseek_overflow (res);
+}
+libc_hidden_def (__lseek)
+weak_alias (__lseek, lseek)
+strong_alias (__lseek, __libc_lseek)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat.c
new file mode 100644
index 0000000000..db1d885a4d
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include "overflow.h"
+
+/* Get information about the file NAME in BUF. */
+int
+__lxstat (int vers, const char *name, struct stat *buf)
+{
+ if (vers == _STAT_VER_KERNEL)
+ {
+ int rc = INLINE_SYSCALL (fstatat64, 4, AT_FDCWD, name, buf,
+ AT_SYMLINK_NOFOLLOW);
+ return rc ?: stat_overflow (buf);
+ }
+ errno = EINVAL;
+ return -1;
+}
+hidden_def (__lxstat)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat64.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat64.c
new file mode 100644
index 0000000000..5a43dc6f42
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat64.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Get information about the file NAME in BUF. */
+int
+__lxstat64 (int vers, const char *name, struct stat64 *buf)
+{
+ if (vers == _STAT_VER_KERNEL)
+ return INLINE_SYSCALL (fstatat64, 4, AT_FDCWD, name, buf,
+ AT_SYMLINK_NOFOLLOW);
+ errno = EINVAL;
+ return -1;
+}
+hidden_def (__lxstat64)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c
new file mode 100644
index 0000000000..588ad6bd81
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <sysdep.h>
+
+#ifndef MMAP_PAGE_SHIFT
+#define MMAP_PAGE_SHIFT 12
+#endif
+
+__ptr_t
+__mmap (__ptr_t addr, size_t len, int prot, int flags, int fd, off_t offset)
+{
+ if (offset & ((1 << MMAP_PAGE_SHIFT) - 1))
+ {
+ __set_errno (EINVAL);
+ return MAP_FAILED;
+ }
+ return (__ptr_t) INLINE_SYSCALL (mmap2, 6, addr, len, prot, flags, fd,
+ offset >> MMAP_PAGE_SHIFT);
+}
+
+weak_alias (__mmap, mmap)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
new file mode 100644
index 0000000000..59432249e4
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
@@ -0,0 +1,60 @@
+/* Overflow tests for stat, statfs, and lseek functions.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sys/stat.h>
+#include <sys/statfs.h>
+
+/* Test for overflows of structures where we ask the kernel to fill them
+ in with standard 64-bit syscalls but return them through APIs that
+ only expose the low 32 bits of some fields. */
+
+static inline off_t lseek_overflow (loff_t res)
+{
+ off_t retval = (off_t) res;
+ if (retval == res)
+ return retval;
+
+ __set_errno (EOVERFLOW);
+ return (off_t) -1;
+}
+
+static inline int stat_overflow (struct stat *buf)
+{
+ if (buf->__st_ino_pad == 0 && buf->__st_size_pad == 0 &&
+ buf->__st_blocks_pad == 0)
+ return 0;
+
+ __set_errno (EOVERFLOW);
+ return -1;
+}
+
+/* Note that f_files and f_ffree may validly be a sign-extended -1. */
+static inline int statfs_overflow (struct statfs *buf)
+{
+ if (buf->__f_blocks_pad == 0 && buf->__f_bfree_pad == 0 &&
+ buf->__f_bavail_pad == 0 &&
+ (buf->__f_files_pad == 0 ||
+ (buf->f_files == -1U && buf->__f_files_pad == -1)) &&
+ (buf->__f_ffree_pad == 0 ||
+ (buf->f_ffree == -1U && buf->__f_ffree_pad == -1)))
+ return 0;
+
+ __set_errno (EOVERFLOW);
+ return -1;
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/posix_fadvise.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/posix_fadvise.c
new file mode 100644
index 0000000000..f8f486cb71
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/posix_fadvise.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sysdep.h>
+
+/* Advice the system about the expected behaviour of the application with
+ respect to the file associated with FD. */
+
+int
+posix_fadvise (int fd, off_t offset, off_t len, int advise)
+{
+ INTERNAL_SYSCALL_DECL (err);
+ int ret = INTERNAL_SYSCALL (fadvise64_64, err, 6, fd,
+ __LONG_LONG_PAIR (offset >> 31, offset),
+ __LONG_LONG_PAIR (len >> 31, len),
+ advise);
+ if (INTERNAL_SYSCALL_ERROR_P (ret, err))
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+ return 0;
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c
new file mode 100644
index 0000000000..5145755e80
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+ Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <assert.h>
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+static ssize_t
+do_pread (int fd, void *buf, size_t count, off_t offset)
+{
+ assert (sizeof (offset) == 4);
+ return INLINE_SYSCALL (pread64, __ALIGNMENT_COUNT (5, 6), fd,
+ buf, count, __ALIGNMENT_ARG
+ __LONG_LONG_PAIR (offset >> 31, offset));
+}
+
+ssize_t
+__libc_pread (fd, buf, count, offset)
+ int fd;
+ void *buf;
+ size_t count;
+ off_t offset;
+{
+ if (SINGLE_THREAD_P)
+ return do_pread (fd, buf, count, offset);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = do_pread (fd, buf, count, offset);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+strong_alias (__libc_pread, __pread)
+weak_alias (__libc_pread, pread)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c
new file mode 100644
index 0000000000..fd3aa1f280
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+ Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+static ssize_t
+do_pread64 (int fd, void *buf, size_t count, off64_t offset)
+{
+ return INLINE_SYSCALL (pread64, __ALIGNMENT_COUNT (5, 6), fd,
+ buf, count, __ALIGNMENT_ARG
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+}
+
+
+ssize_t
+__libc_pread64 (fd, buf, count, offset)
+ int fd;
+ void *buf;
+ size_t count;
+ off64_t offset;
+{
+ if (SINGLE_THREAD_P)
+ return do_pread64 (fd, buf, count, offset);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = do_pread64 (fd, buf, count, offset);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+weak_alias (__libc_pread64, __pread64) weak_alias (__libc_pread64, pread64)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c
new file mode 100644
index 0000000000..a110c1584d
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+ Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <assert.h>
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+#include <sys/uio.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+static ssize_t
+do_preadv (int fd, const struct iovec *vector, int count, off_t offset)
+{
+ assert (sizeof (offset) == 4);
+ return INLINE_SYSCALL (preadv, __ALIGNMENT_COUNT (5, 6), fd,
+ vector, count, __ALIGNMENT_ARG
+ __LONG_LONG_PAIR (offset >> 31, offset));
+}
+
+ssize_t
+__libc_preadv (int fd, const struct iovec *vector, int count, off_t offset)
+{
+ if (SINGLE_THREAD_P)
+ return do_preadv (fd, vector, count, offset);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = do_preadv (fd, vector, count, offset);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+strong_alias (__libc_preadv, __preadv)
+weak_alias (__libc_preadv, preadv)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c
new file mode 100644
index 0000000000..b08a470c5d
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+ Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+#include <sys/uio.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+static ssize_t
+do_preadv64 (int fd, const struct iovec *vector, int count, off64_t offset)
+{
+ return INLINE_SYSCALL (preadv, __ALIGNMENT_COUNT (5, 6), fd,
+ vector, count, __ALIGNMENT_ARG
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+}
+
+
+ssize_t
+__libc_preadv64 (int fd, const struct iovec *vector, int count, off64_t offset)
+{
+ if (SINGLE_THREAD_P)
+ return do_preadv64 (fd, vector, count, offset);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = do_preadv64 (fd, vector, count, offset);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+strong_alias (__libc_preadv64, __preadv64)
+weak_alias (__libc_preadv64, preadv64)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c
new file mode 100644
index 0000000000..0f226ff79a
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+ Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <assert.h>
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+static ssize_t
+do_pwrite (int fd, const void *buf, size_t count, off_t offset)
+{
+ assert (sizeof (offset) == 4);
+ return INLINE_SYSCALL (pwrite64, __ALIGNMENT_COUNT (5, 6), fd,
+ buf, count, __ALIGNMENT_ARG
+ __LONG_LONG_PAIR (offset >> 31, offset));
+}
+
+
+ssize_t
+__libc_pwrite (fd, buf, count, offset)
+ int fd;
+ const void *buf;
+ size_t count;
+ off_t offset;
+{
+ if (SINGLE_THREAD_P)
+ return do_pwrite (fd, buf, count, offset);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = do_pwrite (fd, buf, count, offset);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+strong_alias (__libc_pwrite, __pwrite)
+weak_alias (__libc_pwrite, pwrite)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c
new file mode 100644
index 0000000000..1afc13d245
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+ Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+static ssize_t
+do_pwrite64 (int fd, const void *buf, size_t count, off64_t offset)
+{
+ return INLINE_SYSCALL (pwrite64, __ALIGNMENT_COUNT (5, 6), fd,
+ buf, count, __ALIGNMENT_ARG
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+}
+
+
+ssize_t
+__libc_pwrite64 (fd, buf, count, offset)
+ int fd;
+ const void *buf;
+ size_t count;
+ off64_t offset;
+{
+ if (SINGLE_THREAD_P)
+ return do_pwrite64 (fd, buf, count, offset);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = do_pwrite64 (fd, buf, count, offset);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+weak_alias (__libc_pwrite64, __pwrite64)
+libc_hidden_weak (__pwrite64) weak_alias (__libc_pwrite64, pwrite64)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c
new file mode 100644
index 0000000000..cc6bf5dd02
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+ Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <assert.h>
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+#include <sys/uio.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+static ssize_t
+do_pwritev (int fd, const struct iovec *vector, int count, off_t offset)
+{
+ assert (sizeof (offset) == 4);
+ return INLINE_SYSCALL (pwritev, __ALIGNMENT_COUNT (5, 6), fd,
+ vector, count, __ALIGNMENT_ARG
+ __LONG_LONG_PAIR (offset >> 31, offset));
+}
+
+
+ssize_t
+__libc_pwritev (int fd, const struct iovec *vector, int count, off_t offset)
+{
+ if (SINGLE_THREAD_P)
+ return do_pwritev (fd, vector, count, offset);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = do_pwritev (fd, vector, count, offset);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+strong_alias (__libc_pwritev, __pwritev)
+weak_alias (__libc_pwritev, pwritev)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c
new file mode 100644
index 0000000000..752cbcab83
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+ Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+#include <sys/uio.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+static ssize_t
+do_pwritev64 (int fd, const struct iovec *vector, int count, off64_t offset)
+{
+ return INLINE_SYSCALL (pwritev, __ALIGNMENT_COUNT (5, 6), fd,
+ vector, count, __ALIGNMENT_ARG
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+}
+
+
+ssize_t
+__libc_pwritev64 (int fd, const struct iovec *vector, int count,
+ off64_t offset)
+{
+ if (SINGLE_THREAD_P)
+ return do_pwritev64 (fd, vector, count, offset);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = do_pwritev64 (fd, vector, count, offset);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+strong_alias (__libc_pwritev64, pwritev64)
+weak_alias (__libc_pwritev64, __pwritev64)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c
new file mode 100644
index 0000000000..eb4a13ea4c
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sys/sendfile.h>
+#include <errno.h>
+
+/* Send COUNT bytes from file associated with IN_FD starting at OFFSET to
+ descriptor OUT_FD. */
+ssize_t
+sendfile (int out_fd, int in_fd, off_t *offset, size_t count)
+{
+ __off64_t off64;
+ int rc;
+
+ if (offset != NULL)
+ {
+ if (*offset < 0 || (off_t) (*offset + count) < 0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ off64 = *offset;
+ }
+
+ rc = INLINE_SYSCALL (sendfile64, 4, out_fd, in_fd,
+ offset ? &off64 : NULL, count);
+ if (offset)
+ *offset = off64;
+ return rc;
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c
new file mode 100644
index 0000000000..a451a2c5c3
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sys/statfs.h>
+#include <stddef.h>
+
+#include "overflow.h"
+
+/* Return information about the filesystem on which FILE resides. */
+int
+__statfs (const char *file, struct statfs *buf)
+{
+ int rc = INLINE_SYSCALL (statfs64, 3, file, sizeof (*buf), buf);
+ return rc ?: statfs_overflow (buf);
+}
+libc_hidden_def (__statfs)
+weak_alias (__statfs, statfs)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list
new file mode 100644
index 0000000000..58b4057f4b
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list
@@ -0,0 +1,7 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+# rlimit APIs
+getrlimit - getrlimit i:ip __getrlimit getrlimit
+setrlimit - setrlimit i:ip __setrlimit setrlimit
+prlimit64 EXTRA prlimit64 i:iipp prlimit64
+fanotify_mark EXTRA fanotify_mark i:iiiiis fanotify_mark
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
new file mode 100644
index 0000000000..c07f830937
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+/* Truncate PATH to LENGTH bytes. */
+int
+__truncate (const char *path, off_t length)
+{
+ return INLINE_SYSCALL (truncate64, __ALIGNMENT_COUNT (3, 4), path,
+ __ALIGNMENT_ARG
+ __LONG_LONG_PAIR (length >> 31, length));
+}
+weak_alias (__truncate, truncate)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
new file mode 100644
index 0000000000..27ddb1bd02
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+/* Truncate the file PATH to LENGTH bytes. */
+int
+truncate64 (const char *path, off64_t length)
+{
+ unsigned int low = length & 0xffffffff;
+ unsigned int high = length >> 32;
+ return INLINE_SYSCALL (truncate64, __ALIGNMENT_COUNT (3, 4), path,
+ __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
+}
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat.c
new file mode 100644
index 0000000000..7431a37b60
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include "overflow.h"
+
+/* Get information about the file NAME in BUF. */
+int
+__xstat (int vers, const char *name, struct stat *buf)
+{
+ if (vers == _STAT_VER_KERNEL)
+ {
+ int rc = INLINE_SYSCALL (fstatat64, 4, AT_FDCWD, name, buf, 0);
+ return rc ?: stat_overflow (buf);
+ }
+
+ errno = EINVAL;
+ return -1;
+}
+hidden_def (__xstat)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat64.c b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat64.c
new file mode 100644
index 0000000000..b4ad5b6c7c
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat64.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Get information about the file NAME in BUF. */
+int
+__xstat64 (int vers, const char *name, struct stat64 *buf)
+{
+ if (vers == _STAT_VER_KERNEL)
+ return INLINE_SYSCALL (fstatat64, 4, AT_FDCWD, name, buf, 0);
+
+ errno = EINVAL;
+ return -1;
+}
+hidden_def (__xstat64)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/xmknod.c b/ports/sysdeps/unix/sysv/linux/generic/xmknod.c
new file mode 100644
index 0000000000..924092dfff
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/xmknod.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Create a device file named PATH, with permission and special bits MODE
+ and device number DEV (which can be constructed from major and minor
+ device numbers with the `makedev' macro above). */
+int
+__xmknod (int vers, const char *path, mode_t mode, dev_t *dev)
+{
+ unsigned long long int k_dev;
+
+ if (vers != _MKNOD_VER)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* We must convert the value to dev_t type used by the kernel. */
+ k_dev = (*dev) & ((1ULL << 32) - 1);
+ if (k_dev != *dev)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return INLINE_SYSCALL (mknodat, 4, AT_FDCWD, path, mode,
+ (unsigned int) k_dev);
+}
+weak_alias (__xmknod, _xmknod)
+libc_hidden_def (__xmknod)
diff --git a/ports/sysdeps/unix/sysv/linux/generic/xstat.c b/ports/sysdeps/unix/sysv/linux/generic/xstat.c
new file mode 100644
index 0000000000..14cea4aa18
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/generic/xstat.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
+
+ The GNU C Library 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 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* Ignore prototype to avoid error if we alias __xstat and __xstat64. */
+#define __xstat64 __xstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Get information about the file NAME in BUF. */
+int
+__xstat (int vers, const char *name, struct stat *buf)
+{
+ if (vers == _STAT_VER_KERNEL)
+ return INLINE_SYSCALL (newfstatat, 4, AT_FDCWD, name, buf, 0);
+
+ errno = EINVAL;
+ return -1;
+}
+
+hidden_def (__xstat)
+weak_alias (__xstat, _xstat);
+#ifdef XSTAT_IS_XSTAT64
+#undef __xstat64
+strong_alias (__xstat, __xstat64);
+hidden_ver (__xstat, __xstat64)
+#endif