diff options
author | Chris Metcalf <cmetcalf@tilera.com> | 2014-02-10 10:54:47 -0500 |
---|---|---|
committer | Chris Metcalf <cmetcalf@tilera.com> | 2014-02-10 11:04:39 -0500 |
commit | 4372980f5881e7d537a52e3c49588ce116088061 (patch) | |
tree | 138fbc88313c8cb0cabee393e0c08afd67dac6f1 /sysdeps/unix/sysv/linux/generic | |
parent | a1ffb40e32741f992c743e7b16c061fefa3747ac (diff) | |
download | glibc-4372980f5881e7d537a52e3c49588ce116088061.tar.gz glibc-4372980f5881e7d537a52e3c49588ce116088061.tar.xz glibc-4372980f5881e7d537a52e3c49588ce116088061.zip |
Move tilegx, tilepro, and linux-generic from ports to libc.
I've moved the TILE-Gx and TILEPro ports to the main sysdeps hierarchy, along with the linux-generic ports infrastructure. Beyond the README update, the move was just git mv ports/sysdeps/tile sysdeps/tile git mv ports/sysdeps/unix/sysv/linux/tile \ sysdeps/unix/sysv/linux/tile git mv ports/sysdeps/unix/sysv/linux/generic \ sysdeps/unix/sysv/linux/generic I updated the relevant ChangeLogs along the lines of the ARM move in commit c6bfe5c4d75 and tested the 64-bit tilegx build to confirm that there were no changes in "objdump -dr" output in the shared objects.
Diffstat (limited to 'sysdeps/unix/sysv/linux/generic')
81 files changed, 3748 insertions, 0 deletions
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..579cf3998f --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/____longjmp_chk.c @@ -0,0 +1,57 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <jmpbuf-offsets.h> +#include <sysdep.h> +#include <setjmp.h> +#include <signal.h> +#include <stdio.h> +#include <stackinfo.h> + +#ifdef _STACK_GROWS_DOWN +#define called_from(this, saved) ((this) < (saved)) +#else +#define called_from(this, saved) ((this) > (saved)) +#endif + +extern void ____longjmp_chk (__jmp_buf __env, int __val) + __attribute__ ((__noreturn__)); + +void ____longjmp_chk (__jmp_buf env, int val) +{ + void *this_frame = __builtin_frame_address (0); + void *saved_frame = JB_FRAME_ADDRESS (env); + INTERNAL_SYSCALL_DECL (err); + stack_t ss; + + /* If "env" is from a frame that called us, we're all set. */ + if (called_from(this_frame, saved_frame)) + __longjmp (env, val); + + /* If we can't get the current stack state, give up and do the longjmp. */ + if (INTERNAL_SYSCALL (sigaltstack, err, 2, NULL, &ss) != 0) + __longjmp (env, val); + + /* If we we are executing on the alternate stack and within the + bounds, do the longjmp. */ + if (ss.ss_flags == SS_ONSTACK && + (this_frame >= ss.ss_sp && this_frame < (ss.ss_sp + ss.ss_size))) + __longjmp (env, val); + + __fortify_fail ("longjmp causes uninitialized stack frame"); +} diff --git a/sysdeps/unix/sysv/linux/generic/access.c b/sysdeps/unix/sysv/linux/generic/access.c new file mode 100644 index 0000000000..d09ede2d7c --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/access.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <unistd.h> +#include <fcntl.h> +#include <sysdep-cancel.h> + +/* Test for access to FILE. */ +int +__access (const char *file, int type) +{ + return INLINE_SYSCALL (faccessat, 3, AT_FDCWD, file, type); +} +weak_alias (__access, access) diff --git a/sysdeps/unix/sysv/linux/generic/bits/fcntl.h b/sysdeps/unix/sysv/linux/generic/bits/fcntl.h new file mode 100644 index 0000000000..bdf9171ed1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/fcntl.h @@ -0,0 +1,56 @@ +/* O_*, F_*, FD_* bit values for the generic Linux ABI. + Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef _FCNTL_H +# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead." +#endif + +#include <bits/wordsize.h> + +#if __WORDSIZE == 64 +# define __O_LARGEFILE 0 +#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 + +/* Include generic Linux declarations. */ +#include <bits/fcntl-linux.h> diff --git a/sysdeps/unix/sysv/linux/generic/bits/msq.h b/sysdeps/unix/sysv/linux/generic/bits/msq.h new file mode 100644 index 0000000000..f3fcd8d645 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/msq.h @@ -0,0 +1,84 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_MSG_H +# error "Never use <bits/msq.h> directly; include <sys/msg.h> instead." +#endif + +#include <bits/types.h> +#include <bits/wordsize.h> + +/* Define options for message queue functions. */ +#define MSG_NOERROR 010000 /* no error if message is too big */ +#ifdef __USE_GNU +# define MSG_EXCEPT 020000 /* recv any msg except of specified type */ +# define MSG_COPY 040000 /* copy (not remove) all queue messages */ +#endif + +/* Types used in the structure definition. */ +typedef unsigned long int msgqnum_t; +typedef unsigned long int msglen_t; + +/* Structure of record for one message inside the kernel. + The type `struct msg' is opaque. */ +struct msqid_ds +{ + struct ipc_perm msg_perm; /* structure describing operation permission */ + __time_t msg_stime; /* time of last msgsnd command */ +#if __WORDSIZE == 32 + unsigned long int __glibc_reserved1; +#endif + __time_t msg_rtime; /* time of last msgrcv command */ +#if __WORDSIZE == 32 + unsigned long int __glibc_reserved2; +#endif + __time_t msg_ctime; /* time of last change */ +#if __WORDSIZE == 32 + unsigned long int __glibc_reserved3; +#endif + unsigned long int __msg_cbytes; /* current number of bytes on queue */ + msgqnum_t msg_qnum; /* number of messages currently on queue */ + msglen_t msg_qbytes; /* max number of bytes allowed on queue */ + __pid_t msg_lspid; /* pid of last msgsnd() */ + __pid_t msg_lrpid; /* pid of last msgrcv() */ + unsigned long int __glibc_reserved4; + unsigned long int __glibc_reserved5; +}; + +#ifdef __USE_MISC + +# define msg_cbytes __msg_cbytes + +/* ipcs ctl commands */ +# define MSG_STAT 11 +# define MSG_INFO 12 + +/* buffer for msgctl calls IPC_INFO, MSG_INFO */ +struct msginfo + { + int msgpool; + int msgmap; + int msgmax; + int msgmnb; + int msgmni; + int msgssz; + int msgtql; + unsigned short int msgseg; + }; + +#endif /* __USE_MISC */ diff --git a/sysdeps/unix/sysv/linux/generic/bits/sem.h b/sysdeps/unix/sysv/linux/generic/bits/sem.h new file mode 100644 index 0000000000..3c9aea86ad --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/sem.h @@ -0,0 +1,92 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_SEM_H +# error "Never include <bits/sem.h> directly; use <sys/sem.h> instead." +#endif + +#include <sys/types.h> +#include <bits/wordsize.h> + +/* Flags for `semop'. */ +#define SEM_UNDO 0x1000 /* undo the operation on exit */ + +/* Commands for `semctl'. */ +#define GETPID 11 /* get sempid */ +#define GETVAL 12 /* get semval */ +#define GETALL 13 /* get all semval's */ +#define GETNCNT 14 /* get semncnt */ +#define GETZCNT 15 /* get semzcnt */ +#define SETVAL 16 /* set semval */ +#define SETALL 17 /* set all semval's */ + + +/* Data structure describing a set of semaphores. */ +struct semid_ds +{ + struct ipc_perm sem_perm; /* operation permission struct */ + __time_t sem_otime; /* last semop() time */ +#if __WORDSIZE == 32 + unsigned long int __glibc_reserved1; +#endif + __time_t sem_ctime; /* last time changed by semctl() */ +#if __WORDSIZE == 32 + unsigned long int __glibc_reserved2; +#endif + unsigned long int sem_nsems; /* number of semaphores in set */ + unsigned long int __glibc_reserved3; + unsigned long int __glibc_reserved4; +}; + +/* 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/shm.h b/sysdeps/unix/sysv/linux/generic/bits/shm.h new file mode 100644 index 0000000000..0dbed61700 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/shm.h @@ -0,0 +1,111 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_SHM_H +# error "Never include <bits/shm.h> directly; use <sys/shm.h> instead." +#endif + +#include <bits/types.h> +#include <bits/wordsize.h> + +/* Permission flag for shmget. */ +#define SHM_R 0400 /* or S_IRUGO from <linux/stat.h> */ +#define SHM_W 0200 /* or S_IWUGO from <linux/stat.h> */ + +/* Flags for `shmat'. */ +#define SHM_RDONLY 010000 /* attach read-only else read-write */ +#define SHM_RND 020000 /* round attach address to SHMLBA */ +#define SHM_REMAP 040000 /* take-over region on attach */ +#define SHM_EXEC 0100000 /* execution access */ + +/* Commands for `shmctl'. */ +#define SHM_LOCK 11 /* lock segment (root only) */ +#define SHM_UNLOCK 12 /* unlock segment (root only) */ + +__BEGIN_DECLS + +/* Segment low boundary address multiple. */ +#define SHMLBA (__getpagesize ()) +extern int __getpagesize (void) __THROW __attribute__ ((__const__)); + + +/* Type to count number of attaches. */ +typedef unsigned long int shmatt_t; + +/* Data structure describing a shared memory segment. */ +struct shmid_ds + { + struct ipc_perm shm_perm; /* operation permission struct */ + size_t shm_segsz; /* size of segment in bytes */ + __time_t shm_atime; /* time of last shmat() */ +#if __WORDSIZE == 32 + unsigned long int __glibc_reserved1; +#endif + __time_t shm_dtime; /* time of last shmdt() */ +#if __WORDSIZE == 32 + unsigned long int __glibc_reserved2; +#endif + __time_t shm_ctime; /* time of last change by shmctl() */ +#if __WORDSIZE == 32 + unsigned long int __glibc_reserved3; +#endif + __pid_t shm_cpid; /* pid of creator */ + __pid_t shm_lpid; /* pid of last shmop */ + shmatt_t shm_nattch; /* number of current attaches */ + unsigned long int __glibc_reserved4; + unsigned long int __glibc_reserved5; + }; + +#ifdef __USE_MISC + +/* ipcs ctl commands */ +# define SHM_STAT 13 +# define SHM_INFO 14 + +/* shm_mode upper byte flags */ +# define SHM_DEST 01000 /* segment will be destroyed on last detach */ +# define SHM_LOCKED 02000 /* segment will not be swapped */ +# define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */ +# define SHM_NORESERVE 010000 /* don't check for reservations */ + +struct shminfo + { + unsigned long int shmmax; + unsigned long int shmmin; + unsigned long int shmmni; + unsigned long int shmseg; + unsigned long int shmall; + unsigned long int __glibc_reserved1; + unsigned long int __glibc_reserved2; + unsigned long int __glibc_reserved3; + unsigned long int __glibc_reserved4; + }; + +struct shm_info + { + int used_ids; + unsigned long int shm_tot; /* total allocated shm */ + unsigned long int shm_rss; /* total resident shm */ + unsigned long int shm_swp; /* total swapped shm */ + unsigned long int swap_attempts; + unsigned long int swap_successes; + }; + +#endif /* __USE_MISC */ + +__END_DECLS diff --git a/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h new file mode 100644 index 0000000000..faa28007f5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h @@ -0,0 +1,171 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#if !defined _SYS_STAT_H && !defined _FCNTL_H +# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead." +#endif + +#ifndef _BITS_STAT_H +#define _BITS_STAT_H 1 + +#include <endian.h> +#include <bits/wordsize.h> + +/* 64-bit libc uses the kernel's 'struct stat', accessed via the + stat() syscall; 32-bit libc uses the kernel's 'struct stat64' + and accesses it via the stat64() syscall. All the various + APIs offered by libc use the kernel shape for their struct stat + structure; the only difference is that 32-bit programs not + using __USE_FILE_OFFSET64 only see the low 32 bits of some + of the fields (specifically st_ino, st_size, and st_blocks). */ +#define _STAT_VER_KERNEL 0 +#define _STAT_VER_LINUX 0 +#define _STAT_VER _STAT_VER_KERNEL + +/* Versions of the `xmknod' interface. */ +#define _MKNOD_VER_LINUX 0 + +#if defined __USE_FILE_OFFSET64 +# define __field64(type, type64, name) type64 name +#elif __WORDSIZE == 64 +# define __field64(type, type64, name) type name +#elif __BYTE_ORDER == __LITTLE_ENDIAN +# define __field64(type, type64, name) \ + type name __attribute__((__aligned__ (__alignof__ (type64)))); int __##name##_pad +#else +# define __field64(type, type64, name) \ + int __##name##_pad __attribute__((__aligned__ (__alignof__ (type64)))); type name +#endif + +struct stat + { + __dev_t st_dev; /* Device. */ + __field64(__ino_t, __ino64_t, st_ino); /* File serial number. */ + __mode_t st_mode; /* File mode. */ + __nlink_t st_nlink; /* Link count. */ + __uid_t st_uid; /* User ID of the file's owner. */ + __gid_t st_gid; /* Group ID of the file's group.*/ + __dev_t st_rdev; /* Device number, if device. */ + __dev_t __pad1; + __field64(__off_t, __off64_t, st_size); /* Size of file, in bytes. */ + __blksize_t st_blksize; /* Optimal block size for I/O. */ + int __pad2; + __field64(__blkcnt_t, __blkcnt64_t, st_blocks); /* 512-byte blocks */ +#ifdef __USE_MISC + /* Nanosecond resolution timestamps are stored in a format + equivalent to 'struct timespec'. This is the type used + whenever possible but the Unix namespace rules do not allow the + identifier 'timespec' to appear in the <sys/stat.h> header. + Therefore we have to handle the use of this header in strictly + standard-compliant sources special. */ + struct timespec st_atim; /* Time of last access. */ + struct timespec st_mtim; /* Time of last modification. */ + struct timespec st_ctim; /* Time of last status change. */ +# define st_atime st_atim.tv_sec /* Backward compatibility. */ +# define st_mtime st_mtim.tv_sec +# define st_ctime st_ctim.tv_sec +#else + __time_t st_atime; /* Time of last access. */ + unsigned long int st_atimensec; /* Nscecs of last access. */ + __time_t st_mtime; /* Time of last modification. */ + unsigned long int st_mtimensec; /* Nsecs of last modification. */ + __time_t st_ctime; /* Time of last status change. */ + unsigned long int st_ctimensec; /* Nsecs of last status change. */ +#endif + int __glibc_reserved[2]; + }; + +#undef __field64 + +#ifdef __USE_LARGEFILE64 +struct stat64 + { + __dev_t st_dev; /* Device. */ + __ino64_t st_ino; /* File serial number. */ + __mode_t st_mode; /* File mode. */ + __nlink_t st_nlink; /* Link count. */ + __uid_t st_uid; /* User ID of the file's owner. */ + __gid_t st_gid; /* Group ID of the file's group.*/ + __dev_t st_rdev; /* Device number, if device. */ + __dev_t __pad1; + __off64_t st_size; /* Size of file, in bytes. */ + __blksize_t st_blksize; /* Optimal block size for I/O. */ + int __pad2; + __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */ +#ifdef __USE_MISC + /* Nanosecond resolution timestamps are stored in a format + equivalent to 'struct timespec'. This is the type used + whenever possible but the Unix namespace rules do not allow the + identifier 'timespec' to appear in the <sys/stat.h> header. + Therefore we have to handle the use of this header in strictly + standard-compliant sources special. */ + struct timespec st_atim; /* Time of last access. */ + struct timespec st_mtim; /* Time of last modification. */ + struct timespec st_ctim; /* Time of last status change. */ +#else + __time_t st_atime; /* Time of last access. */ + unsigned long int st_atimensec; /* Nscecs of last access. */ + __time_t st_mtime; /* Time of last modification. */ + unsigned long int st_mtimensec; /* Nsecs of last modification. */ + __time_t st_ctime; /* Time of last status change. */ + unsigned long int st_ctimensec; /* Nsecs of last status change. */ +#endif + int __glibc_reserved[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..e32cf76741 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/statfs.h @@ -0,0 +1,86 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_STATFS_H +# error "Never include <bits/statfs.h> directly; use <sys/statfs.h> instead." +#endif + +#include <endian.h> +#include <bits/types.h> +#include <bits/wordsize.h> + +/* 64-bit libc uses the kernel's 'struct statfs', accessed via the + statfs() syscall; 32-bit libc uses the kernel's 'struct statfs64' + and accesses it via the statfs64() syscall. All the various + APIs offered by libc use the kernel shape for their struct statfs + structure; the only difference is that 32-bit programs not + using __USE_FILE_OFFSET64 only see the low 32 bits of some + of the fields (the __fsblkcnt_t and __fsfilcnt_t fields). */ + +#if defined __USE_FILE_OFFSET64 +# define __field64(type, type64, name) type64 name +#elif __WORDSIZE == 64 +# define __field64(type, type64, name) type name +#elif __BYTE_ORDER == __LITTLE_ENDIAN +# define __field64(type, type64, name) \ + type name __attribute__((__aligned__ (__alignof__ (type64)))); int __##name##_pad +#else +# define __field64(type, type64, name) \ + int __##name##_pad __attribute__((__aligned__ (__alignof__ (type64)))); 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]; + }; + +#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]; + }; +#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..eda847da1e --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h @@ -0,0 +1,78 @@ +/* bits/typesizes.h -- underlying types for *_t. For the generic Linux ABI. + Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef _BITS_TYPES_H +# error "Never include <bits/typesizes.h> directly; use <sys/types.h> instead." +#endif + +#ifndef _BITS_TYPESIZES_H +#define _BITS_TYPESIZES_H 1 + +/* See <bits/types.h> for the meaning of these macros. This file exists so + that <bits/types.h> need not vary across different GNU platforms. */ + +#define __DEV_T_TYPE __UQUAD_TYPE +#define __UID_T_TYPE __U32_TYPE +#define __GID_T_TYPE __U32_TYPE +#define __INO_T_TYPE __ULONGWORD_TYPE +#define __INO64_T_TYPE __UQUAD_TYPE +#define __MODE_T_TYPE __U32_TYPE +#define __NLINK_T_TYPE __U32_TYPE +#define __OFF_T_TYPE __SLONGWORD_TYPE +#define __OFF64_T_TYPE __SQUAD_TYPE +#define __PID_T_TYPE __S32_TYPE +#define __RLIM_T_TYPE __ULONGWORD_TYPE +#define __RLIM64_T_TYPE __UQUAD_TYPE +#define __BLKCNT_T_TYPE __SLONGWORD_TYPE +#define __BLKCNT64_T_TYPE __SQUAD_TYPE +#define __FSBLKCNT_T_TYPE __ULONGWORD_TYPE +#define __FSBLKCNT64_T_TYPE __UQUAD_TYPE +#define __FSFILCNT_T_TYPE __ULONGWORD_TYPE +#define __FSFILCNT64_T_TYPE __UQUAD_TYPE +#define __FSWORD_T_TYPE __SWORD_TYPE +#define __ID_T_TYPE __U32_TYPE +#define __CLOCK_T_TYPE __SLONGWORD_TYPE +#define __TIME_T_TYPE __SLONGWORD_TYPE +#define __USECONDS_T_TYPE __U32_TYPE +#define __SUSECONDS_T_TYPE __SLONGWORD_TYPE +#define __DADDR_T_TYPE __S32_TYPE +#define __KEY_T_TYPE __S32_TYPE +#define __CLOCKID_T_TYPE __S32_TYPE +#define __TIMER_T_TYPE void * +#define __BLKSIZE_T_TYPE __S32_TYPE +#define __FSID_T_TYPE struct { int __val[2]; } +#define __SSIZE_T_TYPE __SWORD_TYPE +#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE +#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE + +#ifdef __LP64__ +/* Tell the libc code that off_t and off64_t are actually the same type + for all ABI purposes, even if possibly expressed as different base types + for C type-checking purposes. */ +# define __OFF_T_MATCHES_OFF64_T 1 + +/* Same for ino_t and ino64_t. */ +# define __INO_T_MATCHES_INO64_T 1 +#endif + +/* 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..214d8fd2fe --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/brk.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <unistd.h> +#include <sysdep.h> + +/* This must be initialized data because commons can't have aliases. */ +void *__curbrk = 0; + +/* Old braindamage in GCC's crtstuff.c requires this symbol in an attempt + to work around different old braindamage in the old Linux ELF dynamic + linker. */ +weak_alias (__curbrk, ___brk_addr) + +int +__brk (void *addr) +{ + INTERNAL_SYSCALL_DECL (err); + + __curbrk = (void *) INTERNAL_SYSCALL (brk, err, 1, addr); + if (__curbrk < addr) + { + __set_errno (ENOMEM); + return -1; + } + + return 0; +} +weak_alias (__brk, brk) diff --git a/sysdeps/unix/sysv/linux/generic/chmod.c b/sysdeps/unix/sysv/linux/generic/chmod.c new file mode 100644 index 0000000000..4ff6c8685e --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/chmod.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/types.h> + +/* Change the protections of FILE to MODE. */ +int +__chmod (const char *file, mode_t mode) +{ + return INLINE_SYSCALL (fchmodat, 3, AT_FDCWD, file, mode); +} +weak_alias (__chmod, chmod) diff --git a/sysdeps/unix/sysv/linux/generic/chown.c b/sysdeps/unix/sysv/linux/generic/chown.c new file mode 100644 index 0000000000..d14d574c29 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/chown.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/types.h> + +/* Change the owner and group of FILE. */ +int +__chown (const char *file, uid_t owner, gid_t group) +{ + return INLINE_SYSCALL (fchownat, 5, AT_FDCWD, file, owner, group, 0); +} +libc_hidden_def (__chown) +weak_alias (__chown, chown) diff --git a/sysdeps/unix/sysv/linux/generic/creat.c b/sysdeps/unix/sysv/linux/generic/creat.c new file mode 100644 index 0000000000..f5d046060c --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/creat.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <fcntl.h> +#include <sys/types.h> +#include <sysdep-cancel.h> + +#undef creat + +/* Create FILE with protections MODE. */ +int +__libc_creat (const char *file, mode_t mode) +{ + return __open (file, O_WRONLY | O_CREAT | O_TRUNC, mode); +} +weak_alias (__libc_creat, creat) + +/* __open handles cancellation. */ +LIBC_CANCEL_HANDLED (); + +#if __WORDSIZE == 64 +weak_alias (__libc_creat, creat64) +#endif diff --git a/sysdeps/unix/sysv/linux/generic/dl-origin.c b/sysdeps/unix/sysv/linux/generic/dl-origin.c new file mode 100644 index 0000000000..c010076f06 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/dl-origin.c @@ -0,0 +1,81 @@ +/* Find path of executable. + Copyright (C) 1998-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <assert.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/param.h> +#include <ldsodefs.h> +#include <sysdep.h> + +#include <dl-dst.h> + +/* On Linux >= 2.1 systems which have the dcache implementation we can get + the path of the application from the /proc/self/exe symlink. Try this + first and fall back on the generic method if necessary. */ + +const char * +_dl_get_origin (void) +{ + char linkval[PATH_MAX]; + char *result; + int len; + INTERNAL_SYSCALL_DECL (err); + + len = INTERNAL_SYSCALL (readlinkat, err, 4, AT_FDCWD, "/proc/self/exe", + linkval, sizeof (linkval)); + if (! INTERNAL_SYSCALL_ERROR_P (len, err) && len > 0 && linkval[0] != '[') + { + /* We can use this value. */ + assert (linkval[0] == '/'); + while (len > 1 && linkval[len - 1] != '/') + --len; + result = (char *) malloc (len + 1); + if (result == NULL) + result = (char *) -1; + else if (len == 1) + memcpy (result, "/", 2); + else + *((char *) __mempcpy (result, linkval, len - 1)) = '\0'; + } + else + { + result = (char *) -1; + /* We use the environment variable LD_ORIGIN_PATH. If it is set make + a copy and strip out trailing slashes. */ + if (GLRO(dl_origin_path) != NULL) + { + size_t len = strlen (GLRO(dl_origin_path)); + result = (char *) malloc (len + 1); + if (result == NULL) + result = (char *) -1; + else + { + char *cp = __mempcpy (result, GLRO(dl_origin_path), len); + while (cp > result + 1 && cp[-1] == '/') + --cp; + *cp = '\0'; + } + } + } + + return result; +} diff --git a/sysdeps/unix/sysv/linux/generic/dup2.c b/sysdeps/unix/sysv/linux/generic/dup2.c new file mode 100644 index 0000000000..fb8e01a954 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/dup2.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <fcntl.h> +#include <limits.h> +#include <unistd.h> + +/* Duplicate FD to FD2, closing the old FD2 and making FD2 be + open the same file as FD is. Return FD2 or -1. */ +int +__dup2 (int fd, int fd2) +{ + /* For the degenerate case, check if the fd is valid (by trying to + get the file status flags) and return it, or else return EBADF. */ + if (fd == fd2) + return __libc_fcntl (fd, F_GETFL, 0) < 0 ? -1 : fd; + + return INLINE_SYSCALL (dup3, 3, fd, fd2, 0); +} +libc_hidden_def (__dup2) +weak_alias (__dup2, dup2) diff --git a/sysdeps/unix/sysv/linux/generic/epoll_create.c b/sysdeps/unix/sysv/linux/generic/epoll_create.c new file mode 100644 index 0000000000..a6f144df0b --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/epoll_create.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <stddef.h> +#include <errno.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/epoll.h> + +libc_hidden_proto (epoll_create) + +int +epoll_create (int size) +{ + if (size <= 0) + { + __set_errno (EINVAL); + return -1; + } + + return INLINE_SYSCALL (epoll_create1, 1, 0); +} +libc_hidden_def (epoll_create) diff --git a/sysdeps/unix/sysv/linux/generic/epoll_wait.c b/sysdeps/unix/sysv/linux/generic/epoll_wait.c new file mode 100644 index 0000000000..4cd50e439a --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/epoll_wait.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <stddef.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/epoll.h> + +int +epoll_wait (int epfd, struct epoll_event *events, int maxevents, int timeout) +{ + return epoll_pwait (epfd, events, maxevents, timeout, NULL); +} diff --git a/sysdeps/unix/sysv/linux/generic/futimesat.c b/sysdeps/unix/sysv/linux/generic/futimesat.c new file mode 100644 index 0000000000..0e9c983fb1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/futimesat.c @@ -0,0 +1,52 @@ +/* Copyright (C) 2005-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <fcntl.h> +#include <stddef.h> +#include <stdio.h> +#include <string.h> +#include <utime.h> +#include <sys/time.h> +#include <sysdep.h> +#include <kernel-features.h> + + +/* Change the access time of FILE relative to FD to TVP[0] and + the modification time of FILE to TVP[1]. */ +int +futimesat (int fd, const char *file, const struct timeval tvp[2]) +{ + struct timespec tsp[2]; + int result; + + if (tvp) + { + if (tvp[0].tv_usec >= 1000000 || tvp[0].tv_usec < 0 || + tvp[1].tv_usec >= 1000000 || tvp[1].tv_usec < 0) + { + __set_errno (EINVAL); + return -1; + } + TIMEVAL_TO_TIMESPEC (&tvp[0], &tsp[0]); + TIMEVAL_TO_TIMESPEC (&tvp[1], &tsp[1]); + } + + result = INLINE_SYSCALL (utimensat, 4, fd, file, tvp ? tsp : NULL, 0); + return result; +} diff --git a/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..272799b97d --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/getdents64.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <stddef.h> +#include <stdint.h> +#include <unistd.h> +#include <sys/types.h> +#include <bits/wordsize.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +/* The kernel struct linux_dirent64 matches the 'struct getdents64' type. */ +ssize_t +__getdents64 (int fd, char *buf, size_t nbytes) +{ + return INLINE_SYSCALL (getdents64, 3, fd, buf, nbytes); +} + +#if __WORDSIZE == 64 +strong_alias (__getdents64, __getdents) +#endif diff --git a/sysdeps/unix/sysv/linux/generic/inotify_init.c b/sysdeps/unix/sysv/linux/generic/inotify_init.c new file mode 100644 index 0000000000..ced7fe8e5e --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/inotify_init.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <stddef.h> +#include <errno.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/inotify.h> + +libc_hidden_proto (inotify_init) + +int +inotify_init (void) +{ + return INLINE_SYSCALL (inotify_init1, 1, 0); +} +libc_hidden_def (inotify_init) diff --git a/sysdeps/unix/sysv/linux/generic/kernel_stat.h b/sysdeps/unix/sysv/linux/generic/kernel_stat.h new file mode 100644 index 0000000000..371a7c5a0a --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/kernel_stat.h @@ -0,0 +1,26 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <bits/wordsize.h> + +#define STAT_IS_KERNEL_STAT 1 + +/* We provide separate 32-bit API versions that check for EOVERFLOW. */ +#if __WORDSIZE == 64 +# define XSTAT_IS_XSTAT64 1 +#endif diff --git a/sysdeps/unix/sysv/linux/generic/lchown.c b/sysdeps/unix/sysv/linux/generic/lchown.c new file mode 100644 index 0000000000..a3718209c9 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/lchown.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/types.h> + +/* Change the owner and group of FILE. */ +int +__lchown (const char *file, uid_t owner, gid_t group) +{ + return INLINE_SYSCALL (fchownat, 5, AT_FDCWD, file, owner, group, + AT_SYMLINK_NOFOLLOW); +} +weak_alias (__lchown, lchown) diff --git a/sysdeps/unix/sysv/linux/generic/link.c b/sysdeps/unix/sysv/linux/generic/link.c new file mode 100644 index 0000000000..12cf700d79 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/link.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <unistd.h> +#include <fcntl.h> + +/* Make a link to FROM called TO. */ +int +__link (const char *from, const char *to) +{ + return INLINE_SYSCALL (linkat, 5, AT_FDCWD, from, AT_FDCWD, to, 0); +} + +weak_alias (__link, link) diff --git a/sysdeps/unix/sysv/linux/generic/lxstat.c b/sysdeps/unix/sysv/linux/generic/lxstat.c new file mode 100644 index 0000000000..8bb1d8e58f --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/lxstat.c @@ -0,0 +1,48 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +/* Ignore prototype to avoid error if we alias __lxstat and __lxstat64. */ +#define __lxstat64 __lxstat64_disable + +#include <errno.h> +#include <stddef.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <kernel_stat.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +/* Get information about the file NAME in BUF. */ +int +__lxstat (int vers, const char *name, struct stat *buf) +{ + if (vers == _STAT_VER_KERNEL) + return INLINE_SYSCALL (newfstatat, 4, AT_FDCWD, name, buf, + AT_SYMLINK_NOFOLLOW); + errno = EINVAL; + return -1; +} + +hidden_def (__lxstat) +weak_alias (__lxstat, _lxstat); +#ifdef XSTAT_IS_XSTAT64 +#undef __lxstat64 +strong_alias (__lxstat, __lxstat64); +hidden_ver (__lxstat, __lxstat64) +#endif diff --git a/sysdeps/unix/sysv/linux/generic/mkdir.c b/sysdeps/unix/sysv/linux/generic/mkdir.c new file mode 100644 index 0000000000..45ccf358c4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/mkdir.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <sysdep.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/types.h> + + +/* Create a directory named PATH with protections MODE. */ +int +__mkdir (const char *path, mode_t mode) +{ + return INLINE_SYSCALL (mkdirat, 3, AT_FDCWD, path, mode); +} +weak_alias (__mkdir, mkdir) diff --git a/sysdeps/unix/sysv/linux/generic/not-cancel.h b/sysdeps/unix/sysv/linux/generic/not-cancel.h new file mode 100644 index 0000000000..b8df253607 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/not-cancel.h @@ -0,0 +1,34 @@ +/* Uncancelable versions of cancelable interfaces. Linux asm-generic version. + Copyright (C) 2012-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2012. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef _LINUX_GENERIC_NOT_CANCEL_H +#define _LINUX_GENERIC_NOT_CANCEL_H + +#include <sysdeps/unix/sysv/linux/not-cancel.h> +#include <fcntl.h> + +/* Uncancelable open with openat. */ +#undef open_not_cancel +#define open_not_cancel(name, flags, mode) \ + INLINE_SYSCALL (openat, 4, AT_FDCWD, (const char *) (name), (flags), (mode)) +#undef open_not_cancel_2 +#define open_not_cancel_2(name, flags) \ + INLINE_SYSCALL (openat, 3, AT_FDCWD, (const char *) (name), (flags)) + +#endif diff --git a/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 <nptl/sysdeps/unix/sysv/linux/i386/not-cancel.h> diff --git a/sysdeps/unix/sysv/linux/generic/open.c b/sysdeps/unix/sysv/linux/generic/open.c new file mode 100644 index 0000000000..4f73fa019c --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/open.c @@ -0,0 +1,71 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <fcntl.h> +#include <stdarg.h> +#include <stdio.h> +#include <sysdep-cancel.h> + +/* Open FILE with access OFLAG. If OFLAG includes O_CREAT, + a third argument is the file protection. */ +int +__libc_open (const char *file, int oflag, ...) +{ + int mode = 0; + + if (oflag & O_CREAT) + { + va_list arg; + va_start (arg, oflag); + mode = va_arg (arg, int); + va_end (arg); + } + + if (SINGLE_THREAD_P) + return INLINE_SYSCALL (openat, 4, AT_FDCWD, file, oflag, mode); + + int oldtype = LIBC_CANCEL_ASYNC (); + + int result = INLINE_SYSCALL (openat, 4, AT_FDCWD, file, oflag, mode); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} +libc_hidden_def (__libc_open) + +weak_alias (__libc_open, __open) +libc_hidden_weak (__open) +weak_alias (__libc_open, open) + +int +__open_nocancel (const char *file, int oflag, ...) +{ + int mode = 0; + + if (oflag & O_CREAT) + { + va_list arg; + va_start (arg, oflag); + mode = va_arg (arg, int); + va_end (arg); + } + + return INLINE_SYSCALL (openat, 4, AT_FDCWD, file, oflag, mode); +} diff --git a/sysdeps/unix/sysv/linux/generic/open64.c b/sysdeps/unix/sysv/linux/generic/open64.c new file mode 100644 index 0000000000..93d79e381f --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/open64.c @@ -0,0 +1,55 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <fcntl.h> +#include <stdarg.h> +#include <stdio.h> +#include <sysdep-cancel.h> + +/* Open FILE with access OFLAG. If OFLAG includes O_CREAT, + a third argument is the file protection. */ +int +__libc_open64 (const char *file, int oflag, ...) +{ + int mode = 0; + + if (oflag & O_CREAT) + { + va_list arg; + va_start (arg, oflag); + mode = va_arg (arg, int); + va_end (arg); + } + + if (SINGLE_THREAD_P) + return INLINE_SYSCALL (openat, 4, AT_FDCWD, file, + oflag | O_LARGEFILE, mode); + + int oldtype = LIBC_CANCEL_ASYNC (); + + int result = INLINE_SYSCALL (openat, 4, AT_FDCWD, file, + oflag | O_LARGEFILE, mode); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} +weak_alias (__libc_open64, __open64) +libc_hidden_weak (__open64) +weak_alias (__libc_open64, open64) diff --git a/sysdeps/unix/sysv/linux/generic/pause.c b/sysdeps/unix/sysv/linux/generic/pause.c new file mode 100644 index 0000000000..3804ce6e99 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/pause.c @@ -0,0 +1,63 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <signal.h> +#include <unistd.h> +#include <sysdep-cancel.h> + +/* Suspend the process until a signal arrives. + This always returns -1 and sets errno to EINTR. */ + +static int +__syscall_pause (void) +{ + sigset_t set; + + int rc = + INLINE_SYSCALL (rt_sigprocmask, 4, SIG_BLOCK, NULL, &set, _NSIG / 8); + if (rc == 0) + rc = INLINE_SYSCALL (rt_sigsuspend, 2, &set, _NSIG / 8); + + return rc; +} + +int +__libc_pause (void) +{ + if (SINGLE_THREAD_P) + return __syscall_pause (); + + int oldtype = LIBC_CANCEL_ASYNC (); + + int result = __syscall_pause (); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} +weak_alias (__libc_pause, pause) + +#ifndef NO_CANCELLATION +# include <not-cancel.h> + +int +__pause_nocancel (void) +{ + return __syscall_pause (); +} +#endif diff --git a/sysdeps/unix/sysv/linux/generic/pipe.c b/sysdeps/unix/sysv/linux/generic/pipe.c new file mode 100644 index 0000000000..53bf6141a0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/pipe.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <unistd.h> +#include <stddef.h> + +/* Create a one-way communication channel (__pipe). + If successful, two file descriptors are stored in PIPEDES; + bytes written on PIPEDES[1] can be read from PIPEDES[0]. + Returns 0 if successful, -1 if not. */ +int +__pipe (int __pipedes[2]) +{ + return INLINE_SYSCALL (pipe2, 2, __pipedes, 0); +} +libc_hidden_def (__pipe) +weak_alias (__pipe, pipe) diff --git a/sysdeps/unix/sysv/linux/generic/poll.c b/sysdeps/unix/sysv/linux/generic/poll.c new file mode 100644 index 0000000000..62342779c4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/poll.c @@ -0,0 +1,53 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <sys/poll.h> + +#include <sysdep-cancel.h> +#include <sys/syscall.h> + +#include <kernel-features.h> + +int +__poll (struct pollfd *fds, nfds_t nfds, int timeout) +{ + struct timespec timeout_ts; + struct timespec *timeout_ts_p = NULL; + + if (timeout >= 0) + { + timeout_ts.tv_sec = timeout / 1000; + timeout_ts.tv_nsec = (timeout % 1000) * 1000000; + timeout_ts_p = &timeout_ts; + } + + if (SINGLE_THREAD_P) + return INLINE_SYSCALL (ppoll, 5, fds, nfds, timeout_ts_p, NULL, 0); + + int oldtype = LIBC_CANCEL_ASYNC (); + + int result = INLINE_SYSCALL (ppoll, 5, fds, nfds, timeout_ts_p, NULL, 0); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} +libc_hidden_def (__poll) +weak_alias (__poll, poll) +strong_alias (__poll, __libc_poll) diff --git a/sysdeps/unix/sysv/linux/generic/readlink.c b/sysdeps/unix/sysv/linux/generic/readlink.c new file mode 100644 index 0000000000..6f25649c6c --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/readlink.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <unistd.h> +#include <fcntl.h> + +/* Read the contents of the symbolic link PATH into no more than + LEN bytes of BUF. The contents are not null-terminated. + Returns the number of characters read, or -1 for errors. */ +ssize_t +__readlink (const char *path, char *buf, size_t len) +{ + return INLINE_SYSCALL (readlinkat, 4, AT_FDCWD, path, buf, len); +} +weak_alias (__readlink, readlink) diff --git a/sysdeps/unix/sysv/linux/generic/readlink_chk.c b/sysdeps/unix/sysv/linux/generic/readlink_chk.c new file mode 100644 index 0000000000..f73b3c577d --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/readlink_chk.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <unistd.h> +#include <fcntl.h> +#include <sys/param.h> +#ifdef HAVE_INLINED_SYSCALLS +# include <errno.h> +# include <sysdep.h> +#endif + + +ssize_t +__readlink_chk (const char *path, void *buf, size_t len, size_t buflen) +{ + if (len > buflen) + __chk_fail (); + +#ifdef HAVE_INLINED_SYSCALLS + return INLINE_SYSCALL (readlinkat, 4, AT_FDCWD, path, buf, len); +#else + return __readlink (path, buf, len); +#endif +} diff --git a/sysdeps/unix/sysv/linux/generic/recv.c b/sysdeps/unix/sysv/linux/generic/recv.c new file mode 100644 index 0000000000..1d950eb0fe --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/recv.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <stdlib.h> +#include <sys/types.h> +#include <sysdep-cancel.h> +#include <libc-symbols.h> + +ssize_t +__libc_recv (int sockfd, void *buffer, size_t len, int flags) +{ + ssize_t result; + + if (SINGLE_THREAD_P) + result = INLINE_SYSCALL (recvfrom, 6, sockfd, buffer, len, flags, + NULL, NULL); + else + { + int oldtype = LIBC_CANCEL_ASYNC (); + + result = INLINE_SYSCALL (recvfrom, 6, sockfd, buffer, len, flags, + NULL, NULL); + + LIBC_CANCEL_RESET (oldtype); + } + + return result; +} +strong_alias (__libc_recv, __recv) +weak_alias (__libc_recv, recv) diff --git a/sysdeps/unix/sysv/linux/generic/rename.c b/sysdeps/unix/sysv/linux/generic/rename.c new file mode 100644 index 0000000000..73e03c03d7 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/rename.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> +#include <sysdep.h> + +/* Rename the file OLD to NEW. */ +int +rename (const char *old, const char *new) +{ + return INLINE_SYSCALL (renameat, 4, AT_FDCWD, old, AT_FDCWD, new); +} diff --git a/sysdeps/unix/sysv/linux/generic/rmdir.c b/sysdeps/unix/sysv/linux/generic/rmdir.c new file mode 100644 index 0000000000..ff5d309df6 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/rmdir.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <unistd.h> +#include <fcntl.h> + + +/* Remove the directory PATH. */ +int +__rmdir (const char *path) +{ + return INLINE_SYSCALL (unlinkat, 3, AT_FDCWD, path, AT_REMOVEDIR); +} +weak_alias (__rmdir, rmdir) diff --git a/sysdeps/unix/sysv/linux/generic/select.c b/sysdeps/unix/sysv/linux/generic/select.c new file mode 100644 index 0000000000..03f96037f6 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/select.c @@ -0,0 +1,74 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <sys/time.h> +#include <sys/types.h> +#include <sys/select.h> +#include <errno.h> +#include <sysdep-cancel.h> + +/* Check the first NFDS descriptors each in READFDS (if not NULL) for read + readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS + (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out + after waiting the interval specified therein. Returns the number of ready + descriptors, or -1 for errors. */ + +int +__select(int nfds, fd_set *readfds, + fd_set *writefds, fd_set *exceptfds, + struct timeval *timeout) +{ + int result; + struct timespec ts, *tsp = NULL; + + if (timeout) + { + TIMEVAL_TO_TIMESPEC (timeout, &ts); + tsp = &ts; + } + + if (SINGLE_THREAD_P) + { + result = INLINE_SYSCALL (pselect6, 6, nfds, readfds, writefds, exceptfds, + tsp, NULL); + } + else + { + int oldtype = LIBC_CANCEL_ASYNC (); + + result = INLINE_SYSCALL (pselect6, 6, nfds, readfds, writefds, exceptfds, + tsp, NULL); + + LIBC_CANCEL_RESET (oldtype); + } + + if (timeout) + { + /* Linux by default will update the timeout after a pselect6 syscall + (though the pselect() glibc call suppresses this behavior). + Since select() on Linux has the same behavior as the pselect6 + syscall, we update the timeout here. */ + TIMESPEC_TO_TIMEVAL (timeout, &ts); + } + + return result; +} +libc_hidden_def (__select) + +weak_alias (__select, select) +weak_alias (__select, __libc_select) diff --git a/sysdeps/unix/sysv/linux/generic/send.c b/sysdeps/unix/sysv/linux/generic/send.c new file mode 100644 index 0000000000..2db610d4bc --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/send.c @@ -0,0 +1,43 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <stdlib.h> +#include <sys/types.h> +#include <sysdep-cancel.h> +#include <libc-symbols.h> + +ssize_t +__libc_send (int sockfd, const void *buffer, size_t len, int flags) +{ + ssize_t result; + + if (SINGLE_THREAD_P) + result = INLINE_SYSCALL (sendto, 6, sockfd, buffer, len, flags, NULL, 0); + else + { + int oldtype = LIBC_CANCEL_ASYNC (); + + result = INLINE_SYSCALL (sendto, 6, sockfd, buffer, len, flags, NULL, 0); + + LIBC_CANCEL_RESET (oldtype); + } + + return result; +} +strong_alias (__libc_send, __send) +weak_alias (__libc_send, send) diff --git a/sysdeps/unix/sysv/linux/generic/symlink.c b/sysdeps/unix/sysv/linux/generic/symlink.c new file mode 100644 index 0000000000..ad36c2cae2 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/symlink.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <unistd.h> +#include <fcntl.h> + +/* Make a link to FROM called TO. */ +int +__symlink (const char *from, const char *to) +{ + return INLINE_SYSCALL (symlinkat, 3, from, AT_FDCWD, to); +} +weak_alias (__symlink, symlink) diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list new file mode 100644 index 0000000000..4b2e74762f --- /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 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..e94237ac7c --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/sysctl.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +/* This deprecated syscall is no longer used (replaced with /proc/sys). */ +int +sysctl (int *name, int nlen, void *oldval, size_t *oldlenp, + void *newval, size_t newlen) +{ + __set_errno (ENOSYS); + return -1; +} +stub_warning (sysctl) diff --git a/sysdeps/unix/sysv/linux/generic/sysdep.h b/sysdeps/unix/sysv/linux/generic/sysdep.h new file mode 100644 index 0000000000..f1ba2589e6 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/sysdep.h @@ -0,0 +1,41 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <bits/wordsize.h> +#include <kernel-features.h> + +/* Provide the common name to allow more code reuse. */ +#define __NR__llseek __NR_llseek + +#if __WORDSIZE == 64 +/* By defining the older names, glibc will build syscall wrappers for + both pread and pread64; sysdeps/unix/sysv/linux/wordsize-64/pread64.c + will suppress generating any separate code for pread64.c. */ +#define __NR_pread __NR_pread64 +#define __NR_pwrite __NR_pwrite64 +#endif + +/* Provide a dummy argument that can be used to force register + alignment for register pairs if required by the syscall ABI. */ +#ifdef __ASSUME_ALIGNED_REGISTER_PAIRS +#define __ALIGNMENT_ARG 0, +#define __ALIGNMENT_COUNT(a,b) b +#else +#define __ALIGNMENT_ARG +#define __ALIGNMENT_COUNT(a,b) a +#endif diff --git a/sysdeps/unix/sysv/linux/generic/umount.c b/sysdeps/unix/sysv/linux/generic/umount.c new file mode 100644 index 0000000000..115dcaaaff --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/umount.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +/* Since the generic Linux syscall ABI doesn't have an oldumount system call, + do what the kernel does down here. */ + +extern long int __umount2 (const char *name, int flags); + +long int +__umount (const char *name) +{ + return __umount2 (name, 0); +} + +weak_alias (__umount, umount); diff --git a/sysdeps/unix/sysv/linux/generic/unlink.c b/sysdeps/unix/sysv/linux/generic/unlink.c new file mode 100644 index 0000000000..6fc6779c1a --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/unlink.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <unistd.h> +#include <fcntl.h> + + +/* Remove the link named NAME. */ +int +__unlink (const char *name) +{ + return INLINE_SYSCALL (unlinkat, 3, AT_FDCWD, name, 0); +} +weak_alias (__unlink, unlink) diff --git a/sysdeps/unix/sysv/linux/generic/ustat.c b/sysdeps/unix/sysv/linux/generic/ustat.c new file mode 100644 index 0000000000..a45e818aba --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/ustat.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <sys/ustat.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +/* This deprecated syscall is no longer used (replaced with fstat). */ +int +ustat (dev_t dev, struct ustat *ubuf) +{ + __set_errno (ENOSYS); + return -1; +} +stub_warning (ustat) diff --git a/sysdeps/unix/sysv/linux/generic/utimes.c b/sysdeps/unix/sysv/linux/generic/utimes.c new file mode 100644 index 0000000000..e0abd7290a --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/utimes.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <utime.h> +#include <fcntl.h> +#include <sys/time.h> +#include <sysdep.h> + + +/* Change the access time of FILE to TVP[0] and + the modification time of FILE to TVP[1]. */ +int +__utimes (const char *file, const struct timeval tvp[2]) +{ + struct timespec ts[2]; + struct timespec *tsp = NULL; + + if (tvp) + { + TIMEVAL_TO_TIMESPEC (&tvp[0], &ts[0]); + TIMEVAL_TO_TIMESPEC (&tvp[1], &ts[1]); + tsp = &ts[0]; + } + + return INLINE_SYSCALL (utimensat, 4, AT_FDCWD, file, tsp, 0); +} + +weak_alias (__utimes, utimes) diff --git a/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..2637f03451 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c @@ -0,0 +1,87 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <assert.h> +#include <errno.h> +#include <sysdep-cancel.h> /* Must come before <fcntl.h>. */ +#include <fcntl.h> +#include <stdarg.h> + +#include <sys/syscall.h> +#include <kernel-features.h> + + +static int +do_fcntl (int fd, int cmd, void *arg) +{ + if (cmd != F_GETOWN) + return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg); + + INTERNAL_SYSCALL_DECL (err); + struct f_owner_ex fex; + int res = INTERNAL_SYSCALL (fcntl64, err, 3, fd, F_GETOWN_EX, &fex); + if (!INTERNAL_SYSCALL_ERROR_P (res, err)) + return fex.type == F_OWNER_GID ? -fex.pid : fex.pid; + + __set_errno (INTERNAL_SYSCALL_ERRNO (res, err)); + return -1; +} + + +#ifndef NO_CANCELLATION +int +__fcntl_nocancel (int fd, int cmd, ...) +{ + va_list ap; + void *arg; + + va_start (ap, cmd); + arg = va_arg (ap, void *); + va_end (ap); + + return do_fcntl (fd, cmd, arg); +} +#endif + + +int +__libc_fcntl (int fd, int cmd, ...) +{ + va_list ap; + void *arg; + + va_start (ap, cmd); + arg = va_arg (ap, void *); + va_end (ap); + + if (SINGLE_THREAD_P || cmd != F_SETLKW) + return do_fcntl (fd, cmd, arg); + + int oldtype = LIBC_CANCEL_ASYNC (); + + int result = do_fcntl (fd, cmd, arg); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} +libc_hidden_def (__libc_fcntl) + +weak_alias (__libc_fcntl, __fcntl) +libc_hidden_weak (__fcntl) +weak_alias (__libc_fcntl, fcntl) diff --git a/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..bff1f4970b --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <sys/statfs.h> +#include <stddef.h> + +#include "overflow.h" + +/* Return information about the filesystem on which FD resides. */ +int +__fstatfs (int fd, struct statfs *buf) +{ + int rc = INLINE_SYSCALL (fstatfs64, 3, fd, sizeof (*buf), buf); + return rc ?: statfs_overflow (buf); +} +weak_alias (__fstatfs, fstatfs) diff --git a/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..f153a04933 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <sys/types.h> +#include <unistd.h> + +/* Truncate the file FD refers to to LENGTH bytes. */ +int +__ftruncate (int fd, off_t length) +{ + return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd, + __ALIGNMENT_ARG + __LONG_LONG_PAIR (length >> 31, length)); +} +weak_alias (__ftruncate, ftruncate) diff --git a/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..e430145828 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <sys/types.h> +#include <unistd.h> + +/* Truncate the file FD refers to to LENGTH bytes. */ +int +__ftruncate64 (int fd, off64_t length) +{ + unsigned int low = length & 0xffffffff; + unsigned int high = length >> 32; + return INLINE_SYSCALL (ftruncate64, __ALIGNMENT_COUNT (3, 4), fd, + __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low)); +} +weak_alias (__ftruncate64, ftruncate64) diff --git a/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..41850c34bd --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstat.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <kernel_stat.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +#include "overflow.h" + +/* Get information about the file FD in BUF. */ +int +__fxstat (int vers, int fd, struct stat *buf) +{ + if (vers == _STAT_VER_KERNEL) + { + int rc = INLINE_SYSCALL (fstat64, 2, fd, buf); + return rc ?: stat_overflow (buf); + } + + errno = EINVAL; + return -1; +} + +hidden_def (__fxstat) +weak_alias (__fxstat, _fxstat); diff --git a/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..94769b64e4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/fxstatat.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <fcntl.h> +#include <stddef.h> +#include <stdio.h> +#include <sys/stat.h> +#include <kernel_stat.h> + +#include <sysdep.h> +#include <sys/syscall.h> +#include <kernel-features.h> + +#include "overflow.h" + +/* Get information about the file NAME in BUF. */ +int +__fxstatat (int vers, int fd, const char *file, struct stat *buf, int flag) +{ + if (vers == _STAT_VER_KERNEL) + { + int rc = INLINE_SYSCALL (fstatat64, 4, fd, file, buf, flag); + return rc ?: stat_overflow (buf); + } + + errno = EINVAL; + return -1; +} +libc_hidden_def (__fxstatat) diff --git a/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..e4b6ee0d17 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c @@ -0,0 +1,115 @@ +/* Copyright (C) 1993-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Simplified from sysdeps/unix/sysv/linux/getdents.c. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <alloca.h> +#include <assert.h> +#include <errno.h> +#include <dirent.h> +#include <stddef.h> +#include <stdint.h> +#include <string.h> +#include <unistd.h> +#include <sys/param.h> +#include <sys/types.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +/* Pack the dirent64 struct down into 32-bit offset/inode fields, and + ensure that no overflow occurs. */ +ssize_t +__getdents (int fd, char *buf, size_t nbytes) +{ + union + { + struct dirent64 k; /* Kernel structure. */ + struct dirent u; + char b[1]; + } *kbuf = (void *) buf, *outp, *inp; + size_t kbytes = nbytes; + off64_t last_offset = -1; + ssize_t retval; + + const size_t size_diff = (offsetof (struct dirent64, d_name) + - offsetof (struct dirent, d_name)); + if (nbytes <= sizeof (struct dirent)) + { + kbytes = nbytes + offsetof (struct dirent64, d_name) + - offsetof (struct dirent, d_name); + kbuf = __alloca(kbytes); + } + + retval = INLINE_SYSCALL (getdents64, 3, fd, kbuf, kbytes); + if (retval == -1) + return -1; + + /* These two pointers might alias the same memory buffer. + Standard C requires that we always use the same type for them, + so we must use the union type. */ + inp = kbuf; + outp = (void *) buf; + + while (&inp->b < &kbuf->b + retval) + { + const size_t alignment = __alignof__ (struct dirent); + /* Since inp->k.d_reclen is already aligned for the kernel + structure this may compute a value that is bigger + than necessary. */ + size_t old_reclen = inp->k.d_reclen; + size_t new_reclen = ((old_reclen - size_diff + alignment - 1) + & ~(alignment - 1)); + + /* Copy the data out of the old structure into temporary space. + Then copy the name, which may overlap if BUF == KBUF. */ + const uint64_t d_ino = inp->k.d_ino; + const int64_t d_off = inp->k.d_off; + const uint8_t d_type = inp->k.d_type; + + memmove (outp->u.d_name, inp->k.d_name, + old_reclen - offsetof (struct dirent64, d_name)); + + /* Now we have copied the data from INP and access only OUTP. */ + + outp->u.d_ino = d_ino; + outp->u.d_off = d_off; + if ((sizeof (outp->u.d_ino) != sizeof (inp->k.d_ino) + && outp->u.d_ino != d_ino) + || (sizeof (outp->u.d_off) != sizeof (inp->k.d_off) + && outp->u.d_off != d_off)) + { + /* Overflow. If there was at least one entry before this one, + return them without error, otherwise signal overflow. */ + if (last_offset != -1) + { + __lseek64 (fd, last_offset, SEEK_SET); + return outp->b - buf; + } + __set_errno (EOVERFLOW); + return -1; + } + + last_offset = d_off; + outp->u.d_reclen = new_reclen; + outp->u.d_type = d_type; + + inp = (void *) inp + old_reclen; + outp = (void *) outp + new_reclen; + } + + return outp->b - buf; +} diff --git a/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..ce9eb9bd6d --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c @@ -0,0 +1,46 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <sys/types.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +/* Seek to OFFSET on FD, starting from WHENCE. */ +extern loff_t __llseek (int fd, loff_t offset, int whence); + +loff_t +__llseek (int fd, loff_t offset, int whence) +{ + loff_t retval; + + return (loff_t) (INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 32), + (off_t) (offset & 0xffffffff), + &retval, whence) ?: retval); +} +weak_alias (__llseek, llseek) +strong_alias (__llseek, __libc_lseek64) +strong_alias (__llseek, __lseek64) +weak_alias (__llseek, lseek64) + +/* llseek doesn't have a prototype. Since the second parameter is a + 64bit type, this results in wrong behaviour if no prototype is + provided. */ +link_warning (llseek, "\ +the `llseek' function may be dangerous; use `lseek64' instead.") diff --git a/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..96d8a35378 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <unistd.h> +#include <sys/types.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +#include "overflow.h" + +off_t +__lseek (int fd, off_t offset, int whence) +{ + loff_t res; + int rc = INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 31), + (off_t) offset, &res, whence); + return rc ?: lseek_overflow (res); +} +libc_hidden_def (__lseek) +weak_alias (__lseek, lseek) +strong_alias (__lseek, __libc_lseek) diff --git a/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..143f727d3f --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat.c @@ -0,0 +1,43 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <kernel_stat.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +#include "overflow.h" + +/* Get information about the file NAME in BUF. */ +int +__lxstat (int vers, const char *name, struct stat *buf) +{ + if (vers == _STAT_VER_KERNEL) + { + int rc = INLINE_SYSCALL (fstatat64, 4, AT_FDCWD, name, buf, + AT_SYMLINK_NOFOLLOW); + return rc ?: stat_overflow (buf); + } + errno = EINVAL; + return -1; +} +hidden_def (__lxstat) diff --git a/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..39d385cdb0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/lxstat64.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <kernel_stat.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +/* Get information about the file NAME in BUF. */ +int +__lxstat64 (int vers, const char *name, struct stat64 *buf) +{ + if (vers == _STAT_VER_KERNEL) + return INLINE_SYSCALL (fstatat64, 4, AT_FDCWD, name, buf, + AT_SYMLINK_NOFOLLOW); + errno = EINVAL; + return -1; +} +hidden_def (__lxstat64) diff --git a/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..be8ac7b100 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c @@ -0,0 +1,40 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <errno.h> +#include <sysdep.h> + +#ifndef MMAP_PAGE_SHIFT +#define MMAP_PAGE_SHIFT 12 +#endif + +__ptr_t +__mmap (__ptr_t addr, size_t len, int prot, int flags, int fd, off_t offset) +{ + if (offset & ((1 << MMAP_PAGE_SHIFT) - 1)) + { + __set_errno (EINVAL); + return MAP_FAILED; + } + return (__ptr_t) INLINE_SYSCALL (mmap2, 6, addr, len, prot, flags, fd, + offset >> MMAP_PAGE_SHIFT); +} + +weak_alias (__mmap, mmap) diff --git a/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..2acc2e5486 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h @@ -0,0 +1,60 @@ +/* Overflow tests for stat, statfs, and lseek functions. + Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <sys/stat.h> +#include <sys/statfs.h> + +/* Test for overflows of structures where we ask the kernel to fill them + in with standard 64-bit syscalls but return them through APIs that + only expose the low 32 bits of some fields. */ + +static inline off_t lseek_overflow (loff_t res) +{ + off_t retval = (off_t) res; + if (retval == res) + return retval; + + __set_errno (EOVERFLOW); + return (off_t) -1; +} + +static inline int stat_overflow (struct stat *buf) +{ + if (buf->__st_ino_pad == 0 && buf->__st_size_pad == 0 && + buf->__st_blocks_pad == 0) + return 0; + + __set_errno (EOVERFLOW); + return -1; +} + +/* Note that f_files and f_ffree may validly be a sign-extended -1. */ +static inline int statfs_overflow (struct statfs *buf) +{ + if (buf->__f_blocks_pad == 0 && buf->__f_bfree_pad == 0 && + buf->__f_bavail_pad == 0 && + (buf->__f_files_pad == 0 || + (buf->f_files == -1U && buf->__f_files_pad == -1)) && + (buf->__f_ffree_pad == 0 || + (buf->f_ffree == -1U && buf->__f_ffree_pad == -1))) + return 0; + + __set_errno (EOVERFLOW); + return -1; +} diff --git a/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..cc29817a95 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/posix_fadvise.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <fcntl.h> +#include <sysdep.h> + +/* Advice the system about the expected behaviour of the application with + respect to the file associated with FD. */ + +int +posix_fadvise (int fd, off_t offset, off_t len, int advise) +{ + INTERNAL_SYSCALL_DECL (err); + int ret = INTERNAL_SYSCALL (fadvise64_64, err, 6, fd, + __LONG_LONG_PAIR (offset >> 31, offset), + __LONG_LONG_PAIR (len >> 31, len), + advise); + if (INTERNAL_SYSCALL_ERROR_P (ret, err)) + return INTERNAL_SYSCALL_ERRNO (ret, err); + return 0; +} diff --git a/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..2bffd1fbd9 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c @@ -0,0 +1,58 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <assert.h> +#include <errno.h> +#include <endian.h> +#include <unistd.h> + +#include <sysdep-cancel.h> +#include <sys/syscall.h> + +#include <kernel-features.h> + +static ssize_t +do_pread (int fd, void *buf, size_t count, off_t offset) +{ + assert (sizeof (offset) == 4); + return INLINE_SYSCALL (pread64, __ALIGNMENT_COUNT (5, 6), fd, + buf, count, __ALIGNMENT_ARG + __LONG_LONG_PAIR (offset >> 31, offset)); +} + +ssize_t +__libc_pread (fd, buf, count, offset) + int fd; + void *buf; + size_t count; + off_t offset; +{ + if (SINGLE_THREAD_P) + return do_pread (fd, buf, count, offset); + + int oldtype = LIBC_CANCEL_ASYNC (); + + ssize_t result = do_pread (fd, buf, count, offset); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} +strong_alias (__libc_pread, __pread) +weak_alias (__libc_pread, pread) diff --git a/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..093b874814 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c @@ -0,0 +1,58 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <endian.h> +#include <unistd.h> + +#include <sysdep-cancel.h> +#include <sys/syscall.h> + +#include <kernel-features.h> + +static ssize_t +do_pread64 (int fd, void *buf, size_t count, off64_t offset) +{ + return INLINE_SYSCALL (pread64, __ALIGNMENT_COUNT (5, 6), fd, + buf, count, __ALIGNMENT_ARG + __LONG_LONG_PAIR ((off_t) (offset >> 32), + (off_t) (offset & 0xffffffff))); +} + + +ssize_t +__libc_pread64 (fd, buf, count, offset) + int fd; + void *buf; + size_t count; + off64_t offset; +{ + if (SINGLE_THREAD_P) + return do_pread64 (fd, buf, count, offset); + + int oldtype = LIBC_CANCEL_ASYNC (); + + ssize_t result = do_pread64 (fd, buf, count, offset); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} + +weak_alias (__libc_pread64, __pread64) weak_alias (__libc_pread64, pread64) diff --git a/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..1dae1272d0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c @@ -0,0 +1,55 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <assert.h> +#include <errno.h> +#include <endian.h> +#include <unistd.h> +#include <sys/uio.h> + +#include <sysdep-cancel.h> +#include <sys/syscall.h> + +#include <kernel-features.h> + +static ssize_t +do_preadv (int fd, const struct iovec *vector, int count, off_t offset) +{ + assert (sizeof (offset) == 4); + return INLINE_SYSCALL (preadv, __ALIGNMENT_COUNT (5, 6), fd, + vector, count, __ALIGNMENT_ARG + __LONG_LONG_PAIR (offset >> 31, offset)); +} + +ssize_t +__libc_preadv (int fd, const struct iovec *vector, int count, off_t offset) +{ + if (SINGLE_THREAD_P) + return do_preadv (fd, vector, count, offset); + + int oldtype = LIBC_CANCEL_ASYNC (); + + ssize_t result = do_preadv (fd, vector, count, offset); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} +strong_alias (__libc_preadv, __preadv) +weak_alias (__libc_preadv, preadv) diff --git a/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..32cc314047 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c @@ -0,0 +1,56 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <endian.h> +#include <unistd.h> +#include <sys/uio.h> + +#include <sysdep-cancel.h> +#include <sys/syscall.h> + +#include <kernel-features.h> + +static ssize_t +do_preadv64 (int fd, const struct iovec *vector, int count, off64_t offset) +{ + return INLINE_SYSCALL (preadv, __ALIGNMENT_COUNT (5, 6), fd, + vector, count, __ALIGNMENT_ARG + __LONG_LONG_PAIR ((off_t) (offset >> 32), + (off_t) (offset & 0xffffffff))); +} + + +ssize_t +__libc_preadv64 (int fd, const struct iovec *vector, int count, off64_t offset) +{ + if (SINGLE_THREAD_P) + return do_preadv64 (fd, vector, count, offset); + + int oldtype = LIBC_CANCEL_ASYNC (); + + ssize_t result = do_preadv64 (fd, vector, count, offset); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} + +strong_alias (__libc_preadv64, __preadv64) +weak_alias (__libc_preadv64, preadv64) diff --git a/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..909255bb7e --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c @@ -0,0 +1,59 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <assert.h> +#include <errno.h> +#include <endian.h> +#include <unistd.h> + +#include <sysdep-cancel.h> +#include <sys/syscall.h> + +#include <kernel-features.h> + +static ssize_t +do_pwrite (int fd, const void *buf, size_t count, off_t offset) +{ + assert (sizeof (offset) == 4); + return INLINE_SYSCALL (pwrite64, __ALIGNMENT_COUNT (5, 6), fd, + buf, count, __ALIGNMENT_ARG + __LONG_LONG_PAIR (offset >> 31, offset)); +} + + +ssize_t +__libc_pwrite (fd, buf, count, offset) + int fd; + const void *buf; + size_t count; + off_t offset; +{ + if (SINGLE_THREAD_P) + return do_pwrite (fd, buf, count, offset); + + int oldtype = LIBC_CANCEL_ASYNC (); + + ssize_t result = do_pwrite (fd, buf, count, offset); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} +strong_alias (__libc_pwrite, __pwrite) +weak_alias (__libc_pwrite, pwrite) diff --git a/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..cbdb9e9a4e --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c @@ -0,0 +1,59 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <endian.h> +#include <unistd.h> + +#include <sysdep-cancel.h> +#include <sys/syscall.h> + +#include <kernel-features.h> + +static ssize_t +do_pwrite64 (int fd, const void *buf, size_t count, off64_t offset) +{ + return INLINE_SYSCALL (pwrite64, __ALIGNMENT_COUNT (5, 6), fd, + buf, count, __ALIGNMENT_ARG + __LONG_LONG_PAIR ((off_t) (offset >> 32), + (off_t) (offset & 0xffffffff))); +} + + +ssize_t +__libc_pwrite64 (fd, buf, count, offset) + int fd; + const void *buf; + size_t count; + off64_t offset; +{ + if (SINGLE_THREAD_P) + return do_pwrite64 (fd, buf, count, offset); + + int oldtype = LIBC_CANCEL_ASYNC (); + + ssize_t result = do_pwrite64 (fd, buf, count, offset); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} + +weak_alias (__libc_pwrite64, __pwrite64) +libc_hidden_weak (__pwrite64) weak_alias (__libc_pwrite64, pwrite64) diff --git a/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..a166e32c3f --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c @@ -0,0 +1,56 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <assert.h> +#include <errno.h> +#include <endian.h> +#include <unistd.h> +#include <sys/uio.h> + +#include <sysdep-cancel.h> +#include <sys/syscall.h> + +#include <kernel-features.h> + +static ssize_t +do_pwritev (int fd, const struct iovec *vector, int count, off_t offset) +{ + assert (sizeof (offset) == 4); + return INLINE_SYSCALL (pwritev, __ALIGNMENT_COUNT (5, 6), fd, + vector, count, __ALIGNMENT_ARG + __LONG_LONG_PAIR (offset >> 31, offset)); +} + + +ssize_t +__libc_pwritev (int fd, const struct iovec *vector, int count, off_t offset) +{ + if (SINGLE_THREAD_P) + return do_pwritev (fd, vector, count, offset); + + int oldtype = LIBC_CANCEL_ASYNC (); + + ssize_t result = do_pwritev (fd, vector, count, offset); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} +strong_alias (__libc_pwritev, __pwritev) +weak_alias (__libc_pwritev, pwritev) diff --git a/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..33f4e80e66 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c @@ -0,0 +1,57 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + Based on work contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <endian.h> +#include <unistd.h> +#include <sys/uio.h> + +#include <sysdep-cancel.h> +#include <sys/syscall.h> + +#include <kernel-features.h> + +static ssize_t +do_pwritev64 (int fd, const struct iovec *vector, int count, off64_t offset) +{ + return INLINE_SYSCALL (pwritev, __ALIGNMENT_COUNT (5, 6), fd, + vector, count, __ALIGNMENT_ARG + __LONG_LONG_PAIR ((off_t) (offset >> 32), + (off_t) (offset & 0xffffffff))); +} + + +ssize_t +__libc_pwritev64 (int fd, const struct iovec *vector, int count, + off64_t offset) +{ + if (SINGLE_THREAD_P) + return do_pwritev64 (fd, vector, count, offset); + + int oldtype = LIBC_CANCEL_ASYNC (); + + ssize_t result = do_pwritev64 (fd, vector, count, offset); + + LIBC_CANCEL_RESET (oldtype); + + return result; +} + +strong_alias (__libc_pwritev64, pwritev64) +weak_alias (__libc_pwritev64, __pwritev64) diff --git a/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..c35e54a511 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/sendfile.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <sys/sendfile.h> +#include <errno.h> + +/* Send COUNT bytes from file associated with IN_FD starting at OFFSET to + descriptor OUT_FD. */ +ssize_t +sendfile (int out_fd, int in_fd, off_t *offset, size_t count) +{ + __off64_t off64; + int rc; + + if (offset != NULL) + { + if (*offset < 0 || (off_t) (*offset + count) < 0) + { + __set_errno (EINVAL); + return -1; + } + off64 = *offset; + } + + rc = INLINE_SYSCALL (sendfile64, 4, out_fd, in_fd, + offset ? &off64 : NULL, count); + if (offset) + *offset = off64; + return rc; +} diff --git a/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..7987457e8e --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <sys/statfs.h> +#include <stddef.h> + +#include "overflow.h" + +/* Return information about the filesystem on which FILE resides. */ +int +__statfs (const char *file, struct statfs *buf) +{ + int rc = INLINE_SYSCALL (statfs64, 3, file, sizeof (*buf), buf); + return rc ?: statfs_overflow (buf); +} +libc_hidden_def (__statfs) +weak_alias (__statfs, statfs) diff --git a/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..f055c68519 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list @@ -0,0 +1,7 @@ +# File name Caller Syscall name # args Strong name Weak names + +# rlimit APIs +getrlimit - getrlimit i:ip __getrlimit getrlimit +setrlimit - setrlimit i:ip __setrlimit setrlimit +prlimit64 EXTRA prlimit64 i:iipp prlimit64 +fanotify_mark EXTRA fanotify_mark i:iiiiis fanotify_mark diff --git a/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..fb31d1499c --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <sys/types.h> +#include <unistd.h> + +/* Truncate PATH to LENGTH bytes. */ +int +__truncate (const char *path, off_t length) +{ + return INLINE_SYSCALL (truncate64, __ALIGNMENT_COUNT (3, 4), path, + __ALIGNMENT_ARG + __LONG_LONG_PAIR (length >> 31, length)); +} +weak_alias (__truncate, truncate) diff --git a/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..ff19d61559 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <sys/types.h> +#include <unistd.h> + +/* Truncate the file PATH to LENGTH bytes. */ +int +truncate64 (const char *path, off64_t length) +{ + unsigned int low = length & 0xffffffff; + unsigned int high = length >> 32; + return INLINE_SYSCALL (truncate64, __ALIGNMENT_COUNT (3, 4), path, + __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low)); +} diff --git a/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..e9ca7aed16 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat.c @@ -0,0 +1,43 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <kernel_stat.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +#include "overflow.h" + +/* Get information about the file NAME in BUF. */ +int +__xstat (int vers, const char *name, struct stat *buf) +{ + if (vers == _STAT_VER_KERNEL) + { + int rc = INLINE_SYSCALL (fstatat64, 4, AT_FDCWD, name, buf, 0); + return rc ?: stat_overflow (buf); + } + + errno = EINVAL; + return -1; +} +hidden_def (__xstat) diff --git a/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..09862228db --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/xstat64.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <stddef.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <kernel_stat.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +/* Get information about the file NAME in BUF. */ +int +__xstat64 (int vers, const char *name, struct stat64 *buf) +{ + if (vers == _STAT_VER_KERNEL) + return INLINE_SYSCALL (fstatat64, 4, AT_FDCWD, name, buf, 0); + + errno = EINVAL; + return -1; +} +hidden_def (__xstat64) diff --git a/sysdeps/unix/sysv/linux/generic/xmknod.c b/sysdeps/unix/sysv/linux/generic/xmknod.c new file mode 100644 index 0000000000..e08bb0ecea --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/xmknod.c @@ -0,0 +1,54 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +/* Create a device file named PATH, with permission and special bits MODE + and device number DEV (which can be constructed from major and minor + device numbers with the `makedev' macro above). */ +int +__xmknod (int vers, const char *path, mode_t mode, dev_t *dev) +{ + unsigned long long int k_dev; + + if (vers != _MKNOD_VER) + { + __set_errno (EINVAL); + return -1; + } + + /* We must convert the value to dev_t type used by the kernel. */ + k_dev = (*dev) & ((1ULL << 32) - 1); + if (k_dev != *dev) + { + __set_errno (EINVAL); + return -1; + } + + return INLINE_SYSCALL (mknodat, 4, AT_FDCWD, path, mode, + (unsigned int) k_dev); +} +weak_alias (__xmknod, _xmknod) +libc_hidden_def (__xmknod) diff --git a/sysdeps/unix/sysv/linux/generic/xstat.c b/sysdeps/unix/sysv/linux/generic/xstat.c new file mode 100644 index 0000000000..7e37e9c6e5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/generic/xstat.c @@ -0,0 +1,48 @@ +/* Copyright (C) 2011-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <http://www.gnu.org/licenses/>. */ + +/* Ignore prototype to avoid error if we alias __xstat and __xstat64. */ +#define __xstat64 __xstat64_disable + +#include <errno.h> +#include <stddef.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <kernel_stat.h> + +#include <sysdep.h> +#include <sys/syscall.h> + +/* Get information about the file NAME in BUF. */ +int +__xstat (int vers, const char *name, struct stat *buf) +{ + if (vers == _STAT_VER_KERNEL) + return INLINE_SYSCALL (newfstatat, 4, AT_FDCWD, name, buf, 0); + + errno = EINVAL; + return -1; +} + +hidden_def (__xstat) +weak_alias (__xstat, _xstat); +#ifdef XSTAT_IS_XSTAT64 +#undef __xstat64 +strong_alias (__xstat, __xstat64); +hidden_ver (__xstat, __xstat64) +#endif |