diff --git a/ChangeLog.linux-generic b/ChangeLog.linux-generic new file mode 100644 index 0000000000..30ca51d6ac --- /dev/null +++ b/ChangeLog.linux-generic @@ -0,0 +1,80 @@ +2011-12-03 Chris Metcalf + + * sysdeps/unix/sysv/linux/generic/Makefile: New file. + * sysdeps/unix/sysv/linux/generic/____longjmp_chk.c: New file. + * sysdeps/unix/sysv/linux/generic/access.c: New file. + * sysdeps/unix/sysv/linux/generic/bits/fcntl.h: New file. + * sysdeps/unix/sysv/linux/generic/bits/sem.h: New file. + * sysdeps/unix/sysv/linux/generic/bits/stat.h: New file. + * sysdeps/unix/sysv/linux/generic/bits/statfs.h: New file. + * sysdeps/unix/sysv/linux/generic/bits/typesizes.h: New file. + * sysdeps/unix/sysv/linux/generic/brk.c: New file. + * sysdeps/unix/sysv/linux/generic/chmod.c: New file. + * sysdeps/unix/sysv/linux/generic/chown.c: New file. + * sysdeps/unix/sysv/linux/generic/creat.c: New file. + * sysdeps/unix/sysv/linux/generic/dl-origin.c: New file. + * sysdeps/unix/sysv/linux/generic/dup2.c: New file. + * sysdeps/unix/sysv/linux/generic/epoll_create.c: New file. + * sysdeps/unix/sysv/linux/generic/epoll_wait.c: New file. + * sysdeps/unix/sysv/linux/generic/futimesat.c: New file. + * sysdeps/unix/sysv/linux/generic/getdents.c: New file. + * sysdeps/unix/sysv/linux/generic/getdents64.c: New file. + * sysdeps/unix/sysv/linux/generic/inotify_init.c: New file. + * sysdeps/unix/sysv/linux/generic/kernel_stat.h: New file. + * sysdeps/unix/sysv/linux/generic/lchown.c: New file. + * sysdeps/unix/sysv/linux/generic/link.c: New file. + * sysdeps/unix/sysv/linux/generic/lxstat.c: New file. + * sysdeps/unix/sysv/linux/generic/mkdir.c: New file. + * sysdeps/unix/sysv/linux/generic/nptl/not-cancel.h: New file. + * sysdeps/unix/sysv/linux/generic/open.c: New file. + * sysdeps/unix/sysv/linux/generic/open64.c: New file. + * sysdeps/unix/sysv/linux/generic/pause.c: New file. + * sysdeps/unix/sysv/linux/generic/pipe.c: New file. + * sysdeps/unix/sysv/linux/generic/poll.c: New file. + * sysdeps/unix/sysv/linux/generic/readlink.c: New file. + * sysdeps/unix/sysv/linux/generic/readlink_chk.c: New file. + * sysdeps/unix/sysv/linux/generic/recv.c: New file. + * sysdeps/unix/sysv/linux/generic/rename.c: New file. + * sysdeps/unix/sysv/linux/generic/rmdir.c: New file. + * sysdeps/unix/sysv/linux/generic/select.c: New file. + * sysdeps/unix/sysv/linux/generic/send.c: New file. + * sysdeps/unix/sysv/linux/generic/symlink.c: New file. + * sysdeps/unix/sysv/linux/generic/syscalls.list: New file. + * sysdeps/unix/sysv/linux/generic/sysctl.c: New file. + * sysdeps/unix/sysv/linux/generic/sysdep.h: New file. + * sysdeps/unix/sysv/linux/generic/umount.c: New file. + * sysdeps/unix/sysv/linux/generic/unlink.c: New file. + * sysdeps/unix/sysv/linux/generic/ustat.c: New file. + * sysdeps/unix/sysv/linux/generic/utimes.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/Versions: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/fxstat.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/fxstatat.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat64.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/posix_fadvise.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/xstat.c: New file. + * sysdeps/unix/sysv/linux/generic/wordsize-32/xstat64.c: New file. + * sysdeps/unix/sysv/linux/generic/xmknod.c: New file. + * sysdeps/unix/sysv/linux/generic/xstat.c: New file. diff --git a/sysdeps/unix/sysv/linux/generic/Makefile b/sysdeps/unix/sysv/linux/generic/Makefile new file mode 100644 index 0000000000..c1daee2396 --- /dev/null +++ b/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/sysdeps/unix/sysv/linux/generic/____longjmp_chk.c b/sysdeps/unix/sysv/linux/generic/____longjmp_chk.c new file mode 100644 index 0000000000..62b7905aed --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/____longjmp_chk.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include + +#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/sysdeps/unix/sysv/linux/generic/access.c b/sysdeps/unix/sysv/linux/generic/access.c new file mode 100644 index 0000000000..96b1cd0955 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/access.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/bits/fcntl.h b/sysdeps/unix/sysv/linux/generic/bits/fcntl.h new file mode 100644 index 0000000000..cbea2a435c --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/fcntl.h @@ -0,0 +1,340 @@ +/* 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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _FCNTL_H +# error "Never use directly; include instead." +#endif + +#include +#include +#ifdef __USE_GNU +# include +#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/sysdeps/unix/sysv/linux/generic/bits/sem.h b/sysdeps/unix/sysv/linux/generic/bits/sem.h new file mode 100644 index 0000000000..bfb87dbef4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/sem.h @@ -0,0 +1,93 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SYS_SEM_H +# error "Never include directly; use instead." +#endif + +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h new file mode 100644 index 0000000000..d3cec6ff3e --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h @@ -0,0 +1,172 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#if !defined _SYS_STAT_H && !defined _FCNTL_H +# error "Never include directly; use instead." +#endif + +#ifndef _BITS_STAT_H +#define _BITS_STAT_H 1 + +#include +#include + +/* 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 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 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/sysdeps/unix/sysv/linux/generic/bits/statfs.h b/sysdeps/unix/sysv/linux/generic/bits/statfs.h new file mode 100644 index 0000000000..bde1958a9e --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/statfs.h @@ -0,0 +1,87 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SYS_STATFS_H +# error "Never include directly; use instead." +#endif + +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/bits/typesizes.h b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h new file mode 100644 index 0000000000..9ff568d933 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h @@ -0,0 +1,67 @@ +/* bits/typesizes.h -- underlying types for *_t. 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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _BITS_TYPES_H +# error "Never include directly; use instead." +#endif + +#ifndef _BITS_TYPESIZES_H +#define _BITS_TYPESIZES_H 1 + +/* See for the meaning of these macros. This file exists so + that 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 __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 + +/* Number of descriptors that can fit in an `fd_set'. */ +#define __FD_SETSIZE 1024 + + +#endif /* bits/typesizes.h */ diff --git a/sysdeps/unix/sysv/linux/generic/brk.c b/sysdeps/unix/sysv/linux/generic/brk.c new file mode 100644 index 0000000000..eb2bc6b9d5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/brk.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/chmod.c b/sysdeps/unix/sysv/linux/generic/chmod.c new file mode 100644 index 0000000000..96e5641c89 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/chmod.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/chown.c b/sysdeps/unix/sysv/linux/generic/chown.c new file mode 100644 index 0000000000..6ec0263f6d --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/chown.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/creat.c b/sysdeps/unix/sysv/linux/generic/creat.c new file mode 100644 index 0000000000..8ef5c03763 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/creat.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +#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/sysdeps/unix/sysv/linux/generic/dl-origin.c b/sysdeps/unix/sysv/linux/generic/dl-origin.c new file mode 100644 index 0000000000..46bbbb1180 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/dl-origin.c @@ -0,0 +1,82 @@ +/* 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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* 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/sysdeps/unix/sysv/linux/generic/dup2.c b/sysdeps/unix/sysv/linux/generic/dup2.c new file mode 100644 index 0000000000..4562f19adf --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/dup2.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/epoll_create.c b/sysdeps/unix/sysv/linux/generic/epoll_create.c new file mode 100644 index 0000000000..ab6b158a76 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/epoll_create.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +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/sysdeps/unix/sysv/linux/generic/epoll_wait.c b/sysdeps/unix/sysv/linux/generic/epoll_wait.c new file mode 100644 index 0000000000..eda64bc946 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/epoll_wait.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +libc_hidden_proto (epoll_pwait) + +int +epoll_wait (int epfd, struct epoll_event *events, int maxevents, int timeout) +{ + return epoll_pwait (epfd, events, maxevents, timeout, NULL); +} diff --git a/sysdeps/unix/sysv/linux/generic/futimesat.c b/sysdeps/unix/sysv/linux/generic/futimesat.c new file mode 100644 index 0000000000..20153661c0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/futimesat.c @@ -0,0 +1,53 @@ +/* Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* 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/sysdeps/unix/sysv/linux/generic/getdents.c b/sysdeps/unix/sysv/linux/generic/getdents.c new file mode 100644 index 0000000000..14dbbc71a0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/getdents.c @@ -0,0 +1 @@ +/* Defined in getdents64.c */ diff --git a/sysdeps/unix/sysv/linux/generic/getdents64.c b/sysdeps/unix/sysv/linux/generic/getdents64.c new file mode 100644 index 0000000000..9a01f4bf6b --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/getdents64.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/inotify_init.c b/sysdeps/unix/sysv/linux/generic/inotify_init.c new file mode 100644 index 0000000000..84c0b357e4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/inotify_init.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +libc_hidden_proto (inotify_init) + +int +inotify_init (void) +{ + return INLINE_SYSCALL (inotify_init1, 1, 0); +} +libc_hidden_def (inotify_init) diff --git a/sysdeps/unix/sysv/linux/generic/kernel_stat.h b/sysdeps/unix/sysv/linux/generic/kernel_stat.h new file mode 100644 index 0000000000..7343d83f64 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/kernel_stat.h @@ -0,0 +1,27 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + +#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/sysdeps/unix/sysv/linux/generic/lchown.c b/sysdeps/unix/sysv/linux/generic/lchown.c new file mode 100644 index 0000000000..a35ef951c9 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/lchown.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/link.c b/sysdeps/unix/sysv/linux/generic/link.c new file mode 100644 index 0000000000..bab52d1da0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/link.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/lxstat.c b/sysdeps/unix/sysv/linux/generic/lxstat.c new file mode 100644 index 0000000000..c99ead1620 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/lxstat.c @@ -0,0 +1,49 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* Ignore prototype to avoid error if we alias __lxstat and __lxstat64. */ +#define __lxstat64 __lxstat64_disable + +#include +#include +#include +#include +#include + +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/mkdir.c b/sysdeps/unix/sysv/linux/generic/mkdir.c new file mode 100644 index 0000000000..bf345bc538 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/mkdir.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include + + +/* 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/sysdeps/unix/sysv/linux/generic/nptl/not-cancel.h b/sysdeps/unix/sysv/linux/generic/nptl/not-cancel.h new file mode 100644 index 0000000000..e6a0d135c8 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/nptl/not-cancel.h @@ -0,0 +1 @@ +#include diff --git a/sysdeps/unix/sysv/linux/generic/open.c b/sysdeps/unix/sysv/linux/generic/open.c new file mode 100644 index 0000000000..c985835cae --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/open.c @@ -0,0 +1,72 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/open64.c b/sysdeps/unix/sysv/linux/generic/open64.c new file mode 100644 index 0000000000..199699a1c9 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/open64.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/pause.c b/sysdeps/unix/sysv/linux/generic/pause.c new file mode 100644 index 0000000000..f1333cb5ac --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/pause.c @@ -0,0 +1,64 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +/* 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 + +int +__pause_nocancel (void) +{ + return __syscall_pause (); +} +#endif diff --git a/sysdeps/unix/sysv/linux/generic/pipe.c b/sysdeps/unix/sysv/linux/generic/pipe.c new file mode 100644 index 0000000000..d6d5ef1ab7 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/pipe.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/poll.c b/sysdeps/unix/sysv/linux/generic/poll.c new file mode 100644 index 0000000000..1fac1e7744 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/poll.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + +#include +#include + +#include + +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/sysdeps/unix/sysv/linux/generic/readlink.c b/sysdeps/unix/sysv/linux/generic/readlink.c new file mode 100644 index 0000000000..ee46c19611 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/readlink.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/readlink_chk.c b/sysdeps/unix/sysv/linux/generic/readlink_chk.c new file mode 100644 index 0000000000..db8aa20556 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/readlink_chk.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#ifdef HAVE_INLINED_SYSCALLS +# include +# include +#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/sysdeps/unix/sysv/linux/generic/recv.c b/sysdeps/unix/sysv/linux/generic/recv.c new file mode 100644 index 0000000000..d76a9e60b0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/recv.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +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/sysdeps/unix/sysv/linux/generic/rename.c b/sysdeps/unix/sysv/linux/generic/rename.c new file mode 100644 index 0000000000..7e501a40fb --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/rename.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/rmdir.c b/sysdeps/unix/sysv/linux/generic/rmdir.c new file mode 100644 index 0000000000..2478fc6d80 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/rmdir.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + + +/* 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/sysdeps/unix/sysv/linux/generic/select.c b/sysdeps/unix/sysv/linux/generic/select.c new file mode 100644 index 0000000000..d206040d1f --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/select.c @@ -0,0 +1,75 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/send.c b/sysdeps/unix/sysv/linux/generic/send.c new file mode 100644 index 0000000000..1ff25c51b9 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/send.c @@ -0,0 +1,44 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +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/sysdeps/unix/sysv/linux/generic/symlink.c b/sysdeps/unix/sysv/linux/generic/symlink.c new file mode 100644 index 0000000000..ed2b2ab529 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/symlink.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list new file mode 100644 index 0000000000..c9602ca870 --- /dev/null +++ b/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_internal __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/sysdeps/unix/sysv/linux/generic/sysctl.c b/sysdeps/unix/sysv/linux/generic/sysctl.c new file mode 100644 index 0000000000..7cab3a4c25 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/sysctl.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + +#include +#include + +/* 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 diff --git a/sysdeps/unix/sysv/linux/generic/sysdep.h b/sysdeps/unix/sysv/linux/generic/sysdep.h new file mode 100644 index 0000000000..45151c07e1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/sysdep.h @@ -0,0 +1,42 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/umount.c b/sysdeps/unix/sysv/linux/generic/umount.c new file mode 100644 index 0000000000..9b92ffe7bd --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/umount.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* 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/sysdeps/unix/sysv/linux/generic/unlink.c b/sysdeps/unix/sysv/linux/generic/unlink.c new file mode 100644 index 0000000000..b115212d52 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/unlink.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + + +/* 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/sysdeps/unix/sysv/linux/generic/ustat.c b/sysdeps/unix/sysv/linux/generic/ustat.c new file mode 100644 index 0000000000..73e789216f --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/ustat.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + +#include +#include + +/* 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 diff --git a/sysdeps/unix/sysv/linux/generic/utimes.c b/sysdeps/unix/sysv/linux/generic/utimes.c new file mode 100644 index 0000000000..c366e6a759 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/utimes.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include + + +/* 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/sysdeps/unix/sysv/linux/generic/wordsize-32/Versions b/sysdeps/unix/sysv/linux/generic/wordsize-32/Versions new file mode 100644 index 0000000000..cdc6022015 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/Versions @@ -0,0 +1,5 @@ +libc { + GLIBC_2.15 { + fallocate64; + } +} diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c new file mode 100644 index 0000000000..6619ff7527 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c @@ -0,0 +1,88 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include /* Must come before . */ +#include +#include + +#include +#include + + +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/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c new file mode 100644 index 0000000000..aa866edde1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +#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/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c new file mode 100644 index 0000000000..d962e4528f --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c new file mode 100644 index 0000000000..b0e52b9d58 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstat.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstat.c new file mode 100644 index 0000000000..7df3240f4c --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstat.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +#include +#include + +#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/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstatat.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstatat.c new file mode 100644 index 0000000000..2ab639a73b --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstatat.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#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/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c new file mode 100644 index 0000000000..2f22b89a6c --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c @@ -0,0 +1,116 @@ +/* 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c new file mode 100644 index 0000000000..835595761e --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c @@ -0,0 +1,47 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c new file mode 100644 index 0000000000..ed5d18b1dd --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +#include +#include + +#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/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat.c new file mode 100644 index 0000000000..0fa91ecb0d --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat.c @@ -0,0 +1,44 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +#include +#include + +#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/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat64.c new file mode 100644 index 0000000000..3d65692d17 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat64.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c new file mode 100644 index 0000000000..1c2d8ddf7a --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c @@ -0,0 +1,41 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +#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/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h new file mode 100644 index 0000000000..2bfa7d9cda --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h @@ -0,0 +1,61 @@ +/* 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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/wordsize-32/posix_fadvise.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/posix_fadvise.c new file mode 100644 index 0000000000..735b676747 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/posix_fadvise.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c new file mode 100644 index 0000000000..86362107c3 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.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 , 2011. + Based on work contributed by Ulrich Drepper , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +#include +#include + +#include + +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/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c new file mode 100644 index 0000000000..1e58c3188e --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.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 , 2011. + Based on work contributed by Ulrich Drepper , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +#include +#include + +#include + +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/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c new file mode 100644 index 0000000000..e1825cebb8 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.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 , 2011. + Based on work contributed by Ulrich Drepper , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +#include +#include + +#include + +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/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c new file mode 100644 index 0000000000..ed6eeed527 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.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 , 2011. + Based on work contributed by Ulrich Drepper , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +#include +#include + +#include + +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/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c new file mode 100644 index 0000000000..84d5d2f6af --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c @@ -0,0 +1,60 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 2011. + Based on work contributed by Ulrich Drepper , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +#include +#include + +#include + +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/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c new file mode 100644 index 0000000000..f1629fa059 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c @@ -0,0 +1,60 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 2011. + Based on work contributed by Ulrich Drepper , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +#include +#include + +#include + +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/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c new file mode 100644 index 0000000000..68cdf942f4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.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 , 2011. + Based on work contributed by Ulrich Drepper , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +#include +#include + +#include + +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/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c new file mode 100644 index 0000000000..0e25d0ceb6 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.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 , 2011. + Based on work contributed by Ulrich Drepper , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +#include +#include + +#include + +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/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c new file mode 100644 index 0000000000..120fe2f09a --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c new file mode 100644 index 0000000000..a5156b8829 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +#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/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list b/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list new file mode 100644 index 0000000000..d1ae0290f5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list @@ -0,0 +1,5 @@ +# File name Caller Syscall name # args Strong name Weak names + +# rlimit APIs +getrlimit - getrlimit i:ip __getrlimit getrlimit +setrlimit - setrlimit i:ip __setrlimit setrlimit diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c new file mode 100644 index 0000000000..0692d05ca7 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c new file mode 100644 index 0000000000..b7bb0d962a --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat.c new file mode 100644 index 0000000000..721afbe954 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat.c @@ -0,0 +1,44 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +#include +#include + +#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/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat64.c new file mode 100644 index 0000000000..5358b291b2 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat64.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/xmknod.c b/sysdeps/unix/sysv/linux/generic/xmknod.c new file mode 100644 index 0000000000..6f3f535d9e --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/xmknod.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 , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +#include +#include + +/* 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/sysdeps/unix/sysv/linux/generic/xstat.c b/sysdeps/unix/sysv/linux/generic/xstat.c new file mode 100644 index 0000000000..4fd963a1d5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/xstat.c @@ -0,0 +1,49 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf , 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* Ignore prototype to avoid error if we alias __xstat and __xstat64. */ +#define __xstat64 __xstat64_disable + +#include +#include +#include +#include +#include + +#include +#include + +/* 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