summaryrefslogtreecommitdiff
path: root/libc/sysdeps/unix
diff options
context:
space:
mode:
Diffstat (limited to 'libc/sysdeps/unix')
-rw-r--r--libc/sysdeps/unix/Implies1
-rw-r--r--libc/sysdeps/unix/Makefile346
-rw-r--r--libc/sysdeps/unix/Subdirs1
-rw-r--r--libc/sysdeps/unix/_exit.S25
-rw-r--r--libc/sysdeps/unix/alarm.c51
-rw-r--r--libc/sysdeps/unix/alpha/Makefile3
-rw-r--r--libc/sysdeps/unix/alpha/pipe.S32
-rw-r--r--libc/sysdeps/unix/alpha/rt-sysdep.S1
-rw-r--r--libc/sysdeps/unix/alpha/sysdep.S135
-rw-r--r--libc/sysdeps/unix/alpha/sysdep.h438
-rw-r--r--libc/sysdeps/unix/bsd/Implies5
-rw-r--r--libc/sysdeps/unix/bsd/bits/dirent.h33
-rw-r--r--libc/sysdeps/unix/bsd/bits/fcntl.h139
-rw-r--r--libc/sysdeps/unix/bsd/bits/posix_opt.h5
-rw-r--r--libc/sysdeps/unix/bsd/bits/signum.h74
-rw-r--r--libc/sysdeps/unix/bsd/bits/stat.h86
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/Implies2
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/Makefile3
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/Versions6
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/bits/dirent.h55
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/bits/errno.h164
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/bits/fcntl.h113
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/bits/ioctls.h288
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/bits/sockaddr.h43
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/bits/socket.h341
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/cmsg_nxthdr.c2
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/freebsd/bits/environments.h72
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/freebsd/bits/typesizes.h66
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/freebsd/sys/sysmacros.h28
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/isatty.c3
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/sigblock.c1
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/sigsetmask.c1
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/sigvec.c1
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/syscalls.list8
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/system.c2
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/tcdrain.c28
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/tcgetattr.c41
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/tcsetattr.c63
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/wait.c33
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/wait3.c37
-rw-r--r--libc/sysdeps/unix/bsd/bsd4.4/waitpid.c44
-rw-r--r--libc/sysdeps/unix/bsd/bsdstat.h112
-rw-r--r--libc/sysdeps/unix/bsd/bsdtty.h218
-rw-r--r--libc/sysdeps/unix/bsd/clock.c44
-rw-r--r--libc/sysdeps/unix/bsd/confstr.h1
-rw-r--r--libc/sysdeps/unix/bsd/ftime.c42
-rw-r--r--libc/sysdeps/unix/bsd/getpt.c93
-rw-r--r--libc/sysdeps/unix/bsd/gtty.c29
-rw-r--r--libc/sysdeps/unix/bsd/i386/vfork.S40
-rw-r--r--libc/sysdeps/unix/bsd/i386/wait3.S44
-rw-r--r--libc/sysdeps/unix/bsd/init-posix.c33
-rw-r--r--libc/sysdeps/unix/bsd/isatty.c32
-rw-r--r--libc/sysdeps/unix/bsd/poll.c199
-rw-r--r--libc/sysdeps/unix/bsd/ptsname.c76
-rw-r--r--libc/sysdeps/unix/bsd/seekdir.c1
-rw-r--r--libc/sysdeps/unix/bsd/setegid.c35
-rw-r--r--libc/sysdeps/unix/bsd/seteuid.c35
-rw-r--r--libc/sysdeps/unix/bsd/setgid.c35
-rw-r--r--libc/sysdeps/unix/bsd/setrgid.c27
-rw-r--r--libc/sysdeps/unix/bsd/setruid.c27
-rw-r--r--libc/sysdeps/unix/bsd/setsid.c58
-rw-r--r--libc/sysdeps/unix/bsd/setuid.c35
-rw-r--r--libc/sysdeps/unix/bsd/sigaction.c63
-rw-r--r--libc/sysdeps/unix/bsd/sigprocmask.c66
-rw-r--r--libc/sysdeps/unix/bsd/sigsuspend.c48
-rw-r--r--libc/sysdeps/unix/bsd/stty.c29
-rw-r--r--libc/sysdeps/unix/bsd/sys/reboot.h84
-rw-r--r--libc/sysdeps/unix/bsd/syscalls.list14
-rw-r--r--libc/sysdeps/unix/bsd/tcdrain.c38
-rw-r--r--libc/sysdeps/unix/bsd/tcflow.c58
-rw-r--r--libc/sysdeps/unix/bsd/tcflush.c51
-rw-r--r--libc/sysdeps/unix/bsd/tcgetattr.c130
-rw-r--r--libc/sysdeps/unix/bsd/tcgetpgrp.c35
-rw-r--r--libc/sysdeps/unix/bsd/tcsendbrk.c56
-rw-r--r--libc/sysdeps/unix/bsd/tcsetattr.c188
-rw-r--r--libc/sysdeps/unix/bsd/tcsetpgrp.c31
-rw-r--r--libc/sysdeps/unix/bsd/telldir.c116
-rw-r--r--libc/sysdeps/unix/bsd/times.c72
-rw-r--r--libc/sysdeps/unix/bsd/ualarm.c43
-rw-r--r--libc/sysdeps/unix/bsd/ulimit.c92
-rw-r--r--libc/sysdeps/unix/bsd/unlockpt.c37
-rw-r--r--libc/sysdeps/unix/bsd/usleep.c35
-rw-r--r--libc/sysdeps/unix/clock_gettime.c134
-rw-r--r--libc/sysdeps/unix/clock_nanosleep.c101
-rw-r--r--libc/sysdeps/unix/clock_settime.c129
-rw-r--r--libc/sysdeps/unix/closedir.c54
-rw-r--r--libc/sysdeps/unix/common/.cvsignore4
-rw-r--r--libc/sysdeps/unix/common/bits/dirent.h33
-rw-r--r--libc/sysdeps/unix/common/bits/fcntl.h120
-rw-r--r--libc/sysdeps/unix/common/lxstat.c39
-rw-r--r--libc/sysdeps/unix/common/syscalls.list16
-rw-r--r--libc/sysdeps/unix/common/tcsendbrk.c46
-rw-r--r--libc/sysdeps/unix/confstr.h1
-rw-r--r--libc/sysdeps/unix/dirfd.c30
-rw-r--r--libc/sysdeps/unix/dirstream.h48
-rw-r--r--libc/sysdeps/unix/errnos-tmpl.c99
-rw-r--r--libc/sysdeps/unix/errnos.awk12
-rw-r--r--libc/sysdeps/unix/execve.S33
-rw-r--r--libc/sysdeps/unix/fdopendir.c52
-rw-r--r--libc/sysdeps/unix/fork.S34
-rw-r--r--libc/sysdeps/unix/fxstat.c40
-rw-r--r--libc/sysdeps/unix/get_child_max.c37
-rw-r--r--libc/sysdeps/unix/getdents.c36
-rw-r--r--libc/sysdeps/unix/getegid.S30
-rw-r--r--libc/sysdeps/unix/geteuid.S30
-rw-r--r--libc/sysdeps/unix/getlogin.c73
-rw-r--r--libc/sysdeps/unix/getlogin_r.c99
-rw-r--r--libc/sysdeps/unix/getpagesize.c40
-rw-r--r--libc/sysdeps/unix/getppid.S30
-rw-r--r--libc/sysdeps/unix/grantpt.c216
-rw-r--r--libc/sysdeps/unix/i386/brk.S47
-rw-r--r--libc/sysdeps/unix/i386/dl-brk.S1
-rw-r--r--libc/sysdeps/unix/i386/fork.S32
-rw-r--r--libc/sysdeps/unix/i386/pipe.S30
-rw-r--r--libc/sysdeps/unix/i386/sigreturn.S27
-rw-r--r--libc/sysdeps/unix/i386/start.c2
-rw-r--r--libc/sysdeps/unix/i386/syscall.S28
-rw-r--r--libc/sysdeps/unix/i386/sysdep.S106
-rw-r--r--libc/sysdeps/unix/i386/sysdep.h36
-rw-r--r--libc/sysdeps/unix/i386/vfork.S24
-rw-r--r--libc/sysdeps/unix/i386/wait.S29
-rw-r--r--libc/sysdeps/unix/inet/Subdirs7
-rw-r--r--libc/sysdeps/unix/inet/syscalls.list23
-rw-r--r--libc/sysdeps/unix/ioctls-tmpl.c134
-rw-r--r--libc/sysdeps/unix/ioctls.awk10
-rw-r--r--libc/sysdeps/unix/make-syscalls.sh342
-rw-r--r--libc/sysdeps/unix/mk-local_lim.c126
-rw-r--r--libc/sysdeps/unix/mkdir.c98
-rw-r--r--libc/sysdeps/unix/mkfifo.c30
-rw-r--r--libc/sysdeps/unix/mkfifoat.c32
-rw-r--r--libc/sysdeps/unix/mman/syscalls.list11
-rw-r--r--libc/sysdeps/unix/nice.c53
-rw-r--r--libc/sysdeps/unix/opendir.c179
-rw-r--r--libc/sysdeps/unix/powerpc/sysdep.h26
-rw-r--r--libc/sysdeps/unix/readdir.c120
-rw-r--r--libc/sysdeps/unix/readdir_r.c127
-rw-r--r--libc/sysdeps/unix/rewinddir.c37
-rw-r--r--libc/sysdeps/unix/rmdir.c78
-rw-r--r--libc/sysdeps/unix/s-proto-bp.S4
-rw-r--r--libc/sysdeps/unix/s-proto-cancel.S5
-rw-r--r--libc/sysdeps/unix/s-proto.S4
-rw-r--r--libc/sysdeps/unix/seekdir.c38
-rw-r--r--libc/sysdeps/unix/setxid.h4
-rw-r--r--libc/sysdeps/unix/sh/sysdep.S110
-rw-r--r--libc/sysdeps/unix/sh/sysdep.h29
-rw-r--r--libc/sysdeps/unix/siglist.c62
-rwxr-xr-xlibc/sysdeps/unix/snarf-ioctls49
-rw-r--r--libc/sysdeps/unix/sockatmark.c30
-rw-r--r--libc/sysdeps/unix/sparc/brk.S51
-rw-r--r--libc/sysdeps/unix/sparc/dl-brk.S1
-rw-r--r--libc/sysdeps/unix/sparc/fork.S31
-rw-r--r--libc/sysdeps/unix/sparc/pipe.S30
-rw-r--r--libc/sysdeps/unix/sparc/start.c189
-rw-r--r--libc/sysdeps/unix/sparc/sysdep.S47
-rw-r--r--libc/sysdeps/unix/sparc/sysdep.h74
-rw-r--r--libc/sysdeps/unix/sparc/vfork.S35
-rw-r--r--libc/sysdeps/unix/start.c105
-rw-r--r--libc/sysdeps/unix/stime.c41
-rw-r--r--libc/sysdeps/unix/syscall.S30
-rw-r--r--libc/sysdeps/unix/syscalls.list65
-rw-r--r--libc/sysdeps/unix/sysdep.h59
-rw-r--r--libc/sysdeps/unix/system.c2
-rw-r--r--libc/sysdeps/unix/sysv/Makefile42
-rw-r--r--libc/sysdeps/unix/sysv/Versions5
-rw-r--r--libc/sysdeps/unix/sysv/bits/dirent.h28
-rw-r--r--libc/sysdeps/unix/sysv/bits/fcntl.h94
-rw-r--r--libc/sysdeps/unix/sysv/bits/local_lim.h32
-rw-r--r--libc/sysdeps/unix/sysv/bits/signum.h56
-rw-r--r--libc/sysdeps/unix/sysv/bits/stat.h65
-rw-r--r--libc/sysdeps/unix/sysv/bits/utmp.h54
-rw-r--r--libc/sysdeps/unix/sysv/bits/utsname.h23
-rw-r--r--libc/sysdeps/unix/sysv/direct.h10
-rw-r--r--libc/sysdeps/unix/sysv/getdents.c39
-rw-r--r--libc/sysdeps/unix/sysv/gethostname.c49
-rw-r--r--libc/sysdeps/unix/sysv/i386/sysdep.h4
-rw-r--r--libc/sysdeps/unix/sysv/i386/time.S30
-rw-r--r--libc/sysdeps/unix/sysv/linux/Implies14
-rw-r--r--libc/sysdeps/unix/sysv/linux/Makefile159
-rw-r--r--libc/sysdeps/unix/sysv/linux/Versions133
-rw-r--r--libc/sysdeps/unix/sysv/linux/_exit.c43
-rw-r--r--libc/sysdeps/unix/sysv/linux/a.out.h138
-rw-r--r--libc/sysdeps/unix/sysv/linux/accept.S6
-rw-r--r--libc/sysdeps/unix/sysv/linux/adjtime.c98
-rw-r--r--libc/sysdeps/unix/sysv/linux/aio_sigqueue.c57
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/Implies4
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/Makefile38
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/Versions94
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/a.out.h197
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/adjtime.c220
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/alpha/ptrace.h18
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/alpha/regdef.h44
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/a.out.h9
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/dirent.h55
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/elfclass.h14
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/errno.h58
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h228
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/ioctls.h37
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/ipc.h55
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/mman.h118
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/msq.h74
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/netdb.h35
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/resource.h225
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/sem.h85
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/shm.h101
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/sigaction.h74
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/siginfo.h303
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/signum.h82
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/sigstack.h55
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/stat.h151
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/statfs.h67
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/termios.h226
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h66
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h30
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/brk.S81
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/clone.S149
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/dl-brk.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/dl-sysdep.c59
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/fraiseexcpt.c92
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/fxstat.c64
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/fxstatat.c99
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/getclktck.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/getcontext.S188
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/getdents.c3
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/getdents64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/gethostname.c47
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/getitimer.S113
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/getrusage.S149
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/getsysstats.c57
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/gettimeofday.S120
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/glob.c52
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/ieee_get_fp_control.S61
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/ieee_set_fp_control.S61
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/ioperm.c878
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/ipc_priv.h47
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/kernel_sigaction.h15
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/kernel_stat.h88
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/kernel_sysinfo.h6
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/kernel_termios.h44
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/lxstat.c64
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/makecontext.S164
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/msgctl.c121
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/nldbl-abi.h8
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/oldglob.c100
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/pipe.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/register-dump.h157
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/rt_sigaction.S120
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/select.S241
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/semctl.c136
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/setcontext.S35
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/setfpucw.c80
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/setitimer.S137
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/setregid.c31
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/setresgid.c33
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/setresuid.c33
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/setreuid.c31
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/settimeofday.S118
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/shmctl.c135
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sigaction.c39
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h25
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sigprocmask.c58
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sigsuspend.S33
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sizes.h24
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/swapcontext.S51
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sys/acct.h66
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sys/io.h95
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sys/procfs.h115
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sys/ucontext.h61
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sys/user.h50
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/syscall.S77
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/syscalls.list57
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sysconf.c152
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/sysdep.h99
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/ucontext-offsets.sym18
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/utimes.S123
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/wait4.S156
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/wordexp.c60
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/xstat.c64
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/xstatconv.c123
-rw-r--r--libc/sysdeps/unix/sysv/linux/alpha/xstatconv.h24
-rw-r--r--libc/sysdeps/unix/sysv/linux/bind.S5
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/a.out.h7
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/dirent.h53
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/errno.h59
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/fcntl.h3
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/in.h170
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/initspin.h1
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/ioctl-types.h78
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/ioctls.h109
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/ipc.h56
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/local_lim.h68
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/mqueue.h32
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/msq.h77
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/poll.h50
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/posix_opt.h96
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/resource.h225
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/sched.h130
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/sem.h87
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/shm.h103
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/sigaction.h77
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/sigcontext.h29
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/siginfo.h313
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/signum.h80
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/sigset.h125
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/sigstack.h55
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/socket.h320
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/stat.h163
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/statfs.h67
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/statvfs.h107
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/sys_errlist.h33
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/termios.h218
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/uio.h50
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/utsname.h29
-rw-r--r--libc/sysdeps/unix/sysv/linux/bits/waitflags.h38
-rw-r--r--libc/sysdeps/unix/sysv/linux/check_pf.c268
-rw-r--r--libc/sysdeps/unix/sysv/linux/clock.c45
-rw-r--r--libc/sysdeps/unix/sysv/linux/clock_getcpuclockid.c103
-rw-r--r--libc/sysdeps/unix/sysv/linux/clock_getres.c193
-rw-r--r--libc/sysdeps/unix/sysv/linux/clock_gettime.c193
-rw-r--r--libc/sysdeps/unix/sysv/linux/clock_nanosleep.c96
-rw-r--r--libc/sysdeps/unix/sysv/linux/clock_settime.c149
-rw-r--r--libc/sysdeps/unix/sysv/linux/cmsg_nxthdr.c39
-rw-r--r--libc/sysdeps/unix/sysv/linux/configure367
-rw-r--r--libc/sysdeps/unix/sysv/linux/configure.in292
-rw-r--r--libc/sysdeps/unix/sysv/linux/connect.S7
-rw-r--r--libc/sysdeps/unix/sysv/linux/device-nrs.h46
-rw-r--r--libc/sysdeps/unix/sysv/linux/dl-brk.c5
-rw-r--r--libc/sysdeps/unix/sysv/linux/dl-execstack.c154
-rw-r--r--libc/sysdeps/unix/sysv/linux/dl-librecon.h61
-rw-r--r--libc/sysdeps/unix/sysv/linux/dl-origin.c81
-rw-r--r--libc/sysdeps/unix/sysv/linux/dl-osinfo.h180
-rw-r--r--libc/sysdeps/unix/sysv/linux/dl-sbrk.c5
-rw-r--r--libc/sysdeps/unix/sysv/linux/dl-sysdep.c56
-rw-r--r--libc/sysdeps/unix/sysv/linux/dl-sysdep.h27
-rw-r--r--libc/sysdeps/unix/sysv/linux/errqueue.h46
-rw-r--r--libc/sysdeps/unix/sysv/linux/execve.c63
-rw-r--r--libc/sysdeps/unix/sysv/linux/exit-thread.S23
-rw-r--r--libc/sysdeps/unix/sysv/linux/faccessat.c143
-rw-r--r--libc/sysdeps/unix/sysv/linux/fatal-prepare.h39
-rw-r--r--libc/sysdeps/unix/sysv/linux/fchmodat.c106
-rw-r--r--libc/sysdeps/unix/sysv/linux/fchownat.c99
-rw-r--r--libc/sysdeps/unix/sysv/linux/fcntl.c69
-rw-r--r--libc/sysdeps/unix/sysv/linux/fd_to_filename.h46
-rw-r--r--libc/sysdeps/unix/sysv/linux/fexecve.c59
-rw-r--r--libc/sysdeps/unix/sysv/linux/fpathconf.c51
-rw-r--r--libc/sysdeps/unix/sysv/linux/fstatfs64.c72
-rw-r--r--libc/sysdeps/unix/sysv/linux/fstatvfs.c45
-rw-r--r--libc/sysdeps/unix/sysv/linux/fstatvfs64.c74
-rw-r--r--libc/sysdeps/unix/sysv/linux/ftime.c3
-rw-r--r--libc/sysdeps/unix/sysv/linux/ftruncate64.c77
-rw-r--r--libc/sysdeps/unix/sysv/linux/futimes.c101
-rw-r--r--libc/sysdeps/unix/sysv/linux/futimesat.c134
-rw-r--r--libc/sysdeps/unix/sysv/linux/fxstat.c64
-rw-r--r--libc/sysdeps/unix/sysv/linux/fxstat64.c94
-rw-r--r--libc/sysdeps/unix/sysv/linux/fxstatat.c141
-rw-r--r--libc/sysdeps/unix/sysv/linux/fxstatat64.c167
-rw-r--r--libc/sysdeps/unix/sysv/linux/gai_sigqueue.c56
-rw-r--r--libc/sysdeps/unix/sysv/linux/getclktck.c32
-rw-r--r--libc/sysdeps/unix/sysv/linux/getcwd.c222
-rw-r--r--libc/sysdeps/unix/sysv/linux/getdents.c299
-rw-r--r--libc/sysdeps/unix/sysv/linux/getdents64.c3
-rw-r--r--libc/sysdeps/unix/sysv/linux/getdirentries.c42
-rw-r--r--libc/sysdeps/unix/sysv/linux/getdirentries64.c3
-rw-r--r--libc/sysdeps/unix/sysv/linux/getdtsz.c22
-rw-r--r--libc/sysdeps/unix/sysv/linux/gethostid.c121
-rw-r--r--libc/sysdeps/unix/sysv/linux/getipv4sourcefilter.c73
-rw-r--r--libc/sysdeps/unix/sysv/linux/getloadavg.c69
-rw-r--r--libc/sysdeps/unix/sysv/linux/getpagesize.c46
-rw-r--r--libc/sysdeps/unix/sysv/linux/getpeername.S3
-rw-r--r--libc/sysdeps/unix/sysv/linux/getpriority.c45
-rw-r--r--libc/sysdeps/unix/sysv/linux/getpt.c100
-rw-r--r--libc/sysdeps/unix/sysv/linux/getsockname.S5
-rw-r--r--libc/sysdeps/unix/sysv/linux/getsockopt.S3
-rw-r--r--libc/sysdeps/unix/sysv/linux/getsourcefilter.c146
-rw-r--r--libc/sysdeps/unix/sysv/linux/getsysstats.c214
-rw-r--r--libc/sysdeps/unix/sysv/linux/grantpt.c81
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/Makefile18
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/Versions47
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/_exit.S44
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/alphasort64.c49
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/bits/a.out.h3
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/bits/environments.h62
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/bits/fcntl.h236
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/bits/mman.h103
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/bits/wchar.h26
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/bp-thunks.h4
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/brk.c53
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/call_pselect6.S65
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/chown.c159
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/clone.S159
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/dl-librecon.h63
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/dl-procinfo.h43
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/fchown.c68
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/fchownat.c196
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/fcntl.c169
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/fxstat.c101
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/fxstatat.c176
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/get_clockfreq.c91
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/getcontext.S85
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/getdents64.c40
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/getegid.c61
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/geteuid.c61
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/getgid.c62
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/getgroups.c81
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/getmsg.c38
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/getresgid.c85
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/getresuid.c84
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/getrlimit.c82
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/getrlimit64.c25
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/getuid.c65
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/glob64.c54
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/lchown.c74
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/ldconfig.h25
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/lockf64.c194
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/lxstat.c101
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/makecontext.S117
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/mmap.S107
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/mmap64.S170
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/msgctl.c159
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/olddirent.h44
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c58
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/posix_fadvise64.S162
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/profil-counter.h32
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/pselect.c18
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/putmsg.c38
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/readdir64.c44
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/readdir64_r.c44
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/readelflib.c82
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/register-dump.h256
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/scandir64.c47
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/semctl.c185
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/semtimedop.S75
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setcontext.S97
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setegid.c62
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/seteuid.c60
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setfsgid.c70
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setfsuid.c71
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setgid.c76
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setgroups.c87
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setregid.c75
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setresgid.c86
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setresuid.c86
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setreuid.c75
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setrlimit.c78
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/setuid.c75
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/shmctl.c178
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sigaction.c204
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sigcontextinfo.h51
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/socket.S124
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/swapcontext.S112
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sync_file_range.S72
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sys/debugreg.h91
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sys/elf.h26
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sys/io.h181
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sys/perm.h36
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sys/procfs.h131
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sys/reg.h43
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sys/ucontext.h129
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sys/user.h103
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sys/vm86.h35
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/syscall.S37
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/syscalls.list8
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sysconf.c410
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sysdep.S41
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/sysdep.h581
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/ucontext_i.sym30
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/versionsort64.c49
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/vfork.S88
-rw-r--r--libc/sysdeps/unix/sysv/linux/i386/xstat.c99
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/Implies1
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/Makefile27
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/Versions25
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/__longjmp.S163
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/__start_context.S52
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/endian.h7
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/fcntl.h230
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/ipc.h54
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/mman.h104
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/msq.h69
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/sem.h87
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/setjmp.h35
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/shm.h94
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/sigaction.h73
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h79
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/siginfo.h339
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/sigstack.h63
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bits/stat.h140
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/brk.S52
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bsd-_setjmp.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/bsd-setjmp.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/clock_getcpuclockid.c32
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/clone.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/clone2.S106
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/dl-brk.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/dl-cache.h25
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/dl-static.c69
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/fork.S41
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/get_clockfreq.c89
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/getclktck.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/getcontext.S158
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/getpagesize.c39
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c52
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/ioperm.c217
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/kernel_stat.h21
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/ldconfig.h25
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/ldd-rewrite.sed1
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/ldsodefs.h33
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/makecontext.c93
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/pipe.S38
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/profil-counter.h32
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/readelflib.c60
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/register-dump.h182
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/rt-sysdep.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/setcontext.S153
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/setjmp.S199
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sigaction.c59
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sigcontext-offsets.sym16
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h26
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sigpending.c39
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sigprocmask.c45
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/swapcontext.c40
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sys/io.h68
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sys/procfs.h130
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h135
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sys/rse.h78
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sys/ucontext.h66
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sys/user.h54
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/syscall.S30
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/syscalls.list50
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sysconf.c45
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sysdep.S89
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/sysdep.h384
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/system.c35
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/ucontext_i.h47
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/umount.c31
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/unwind-dw2-fde.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/vfork.S44
-rw-r--r--libc/sysdeps/unix/sysv/linux/ia64/wordexp.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/if_index.c474
-rw-r--r--libc/sysdeps/unix/sysv/linux/ifaddrs.c863
-rw-r--r--libc/sysdeps/unix/sysv/linux/ifreq.c101
-rw-r--r--libc/sysdeps/unix/sysv/linux/init-first.c109
-rw-r--r--libc/sysdeps/unix/sysv/linux/internal_statvfs.c239
-rw-r--r--libc/sysdeps/unix/sysv/linux/internal_statvfs64.c4
-rw-r--r--libc/sysdeps/unix/sysv/linux/ipc_priv.h47
-rw-r--r--libc/sysdeps/unix/sysv/linux/kernel-features.h460
-rw-r--r--libc/sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h18
-rw-r--r--libc/sysdeps/unix/sysv/linux/kernel_sigaction.h19
-rw-r--r--libc/sysdeps/unix/sysv/linux/kernel_stat.h35
-rw-r--r--libc/sysdeps/unix/sysv/linux/kernel_termios.h35
-rw-r--r--libc/sysdeps/unix/sysv/linux/ldd-rewrite.sed11
-rw-r--r--libc/sysdeps/unix/sysv/linux/lddlibc4.c88
-rw-r--r--libc/sysdeps/unix/sysv/linux/ldsodefs.h56
-rw-r--r--libc/sysdeps/unix/sysv/linux/libc_fatal.c183
-rw-r--r--libc/sysdeps/unix/sysv/linux/linkat.c115
-rw-r--r--libc/sysdeps/unix/sysv/linux/linux_fsinfo.h156
-rw-r--r--libc/sysdeps/unix/sysv/linux/listen.S5
-rw-r--r--libc/sysdeps/unix/sysv/linux/llseek.c47
-rw-r--r--libc/sysdeps/unix/sysv/linux/local-setxid.h23
-rw-r--r--libc/sysdeps/unix/sysv/linux/lseek64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/lxstat.c64
-rw-r--r--libc/sysdeps/unix/sysv/linux/lxstat64.c93
-rw-r--r--libc/sysdeps/unix/sysv/linux/makedev.c41
-rw-r--r--libc/sysdeps/unix/sysv/linux/mkdirat.c86
-rw-r--r--libc/sysdeps/unix/sysv/linux/mmap64.c89
-rw-r--r--libc/sysdeps/unix/sysv/linux/mq_close.c35
-rw-r--r--libc/sysdeps/unix/sysv/linux/mq_getattr.c35
-rw-r--r--libc/sysdeps/unix/sysv/linux/mq_notify.c44
-rw-r--r--libc/sysdeps/unix/sysv/linux/mq_open.c60
-rw-r--r--libc/sysdeps/unix/sysv/linux/mq_receive.c37
-rw-r--r--libc/sysdeps/unix/sysv/linux/mq_send.c36
-rw-r--r--libc/sysdeps/unix/sysv/linux/mq_unlink.c54
-rw-r--r--libc/sysdeps/unix/sysv/linux/msgctl.c135
-rw-r--r--libc/sysdeps/unix/sysv/linux/msgget.c37
-rw-r--r--libc/sysdeps/unix/sysv/linux/msgrcv.c66
-rw-r--r--libc/sysdeps/unix/sysv/linux/msgsnd.c49
-rw-r--r--libc/sysdeps/unix/sysv/linux/net/ethernet.h76
-rw-r--r--libc/sysdeps/unix/sysv/linux/net/if_arp.h182
-rw-r--r--libc/sysdeps/unix/sysv/linux/net/if_packet.h37
-rw-r--r--libc/sysdeps/unix/sysv/linux/net/if_ppp.h169
-rw-r--r--libc/sysdeps/unix/sysv/linux/net/if_shaper.h59
-rw-r--r--libc/sysdeps/unix/sysv/linux/net/if_slip.h25
-rw-r--r--libc/sysdeps/unix/sysv/linux/net/ppp-comp.h1
-rw-r--r--libc/sysdeps/unix/sysv/linux/net/ppp_defs.h10
-rw-r--r--libc/sysdeps/unix/sysv/linux/net/route.h145
-rw-r--r--libc/sysdeps/unix/sysv/linux/netash/ash.h40
-rw-r--r--libc/sysdeps/unix/sysv/linux/netatalk/at.h30
-rw-r--r--libc/sysdeps/unix/sysv/linux/netax25/ax25.h171
-rw-r--r--libc/sysdeps/unix/sysv/linux/neteconet/ec.h52
-rw-r--r--libc/sysdeps/unix/sysv/linux/netinet/if_ether.h105
-rw-r--r--libc/sysdeps/unix/sysv/linux/netinet/if_fddi.h37
-rw-r--r--libc/sysdeps/unix/sysv/linux/netinet/if_tr.h111
-rw-r--r--libc/sysdeps/unix/sysv/linux/netipx/ipx.h113
-rw-r--r--libc/sysdeps/unix/sysv/linux/netlinkaccess.h61
-rw-r--r--libc/sysdeps/unix/sysv/linux/netpacket/packet.h64
-rw-r--r--libc/sysdeps/unix/sysv/linux/netrom/netrom.h84
-rw-r--r--libc/sysdeps/unix/sysv/linux/netrose/rose.h116
-rw-r--r--libc/sysdeps/unix/sysv/linux/nfs/nfs.h1
-rw-r--r--libc/sysdeps/unix/sysv/linux/nice.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/not-cancel.h105
-rw-r--r--libc/sysdeps/unix/sysv/linux/nscd_setup_thread.c47
-rw-r--r--libc/sysdeps/unix/sysv/linux/ntp_gettime.c42
-rw-r--r--libc/sysdeps/unix/sysv/linux/open64.c53
-rw-r--r--libc/sysdeps/unix/sysv/linux/openat.c173
-rw-r--r--libc/sysdeps/unix/sysv/linux/openat64.c4
-rw-r--r--libc/sysdeps/unix/sysv/linux/opendir.c26
-rw-r--r--libc/sysdeps/unix/sysv/linux/opensock.c119
-rw-r--r--libc/sysdeps/unix/sysv/linux/pathconf.c181
-rw-r--r--libc/sysdeps/unix/sysv/linux/pathconf.h34
-rw-r--r--libc/sysdeps/unix/sysv/linux/paths.h74
-rw-r--r--libc/sysdeps/unix/sysv/linux/poll.c105
-rw-r--r--libc/sysdeps/unix/sysv/linux/posix_fadvise.c40
-rw-r--r--libc/sysdeps/unix/sysv/linux/posix_fadvise64.c82
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/Implies4
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/Makefile12
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/Versions7
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-dirent.h19
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-errno.h125
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-stat.h76
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-termios.h85
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/aix/direntconv.c49
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/aix/errnoconv.c143
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/aix/statconv.c53
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/aix/tcgetattr.c156
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/aix/tcsetattr.c171
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/environments.h87
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/fcntl.h236
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/ioctl-types.h5
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/ipc.h79
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h36
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/mman.h104
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/msq.h83
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/sem.h92
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/shm.h113
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/stat.h267
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/termios.h319
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h19
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/chown.c132
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/configure135
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/configure.in37
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/dl-brk.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/dl-cache.h1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.c71
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c59
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h27
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/fchownat.c223
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c117
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/getdents64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/getmsg.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/getrlimit.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/getrlimit64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c42
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/ioctl.c65
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/ipc_priv.h1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/kernel_termios.h54
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/lchown.S39
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/ldconfig.h27
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/ldd-rewrite.sed15
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/libc-start.c130
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/nldbl-abi.h8
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/oldgetrlimit64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile3
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/Versions30
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S64
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S149
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fcntl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fe_nomask.c68
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/Implies2
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c78
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstatat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext-common.S286
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S84
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/glob64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/kernel_stat.h49
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/lockf64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/lxstat.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S219
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/posix_fadvise.c40
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/posix_fadvise64.c78
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread.c87
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread64.c88
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite.c87
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite64.c89
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext-common.S293
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S85
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/socket.S121
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext-common.S517
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S84
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list5
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h297
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c79
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.sym26
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S59
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/xstat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/Implies1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions22
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/brk.S50
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S143
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/dl-cache.h25
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c72
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fe_nomask.c43
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fpu/Implies2
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S411
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/kernel_stat.h21
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/ldsodefs.h77
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S187
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pread.c85
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pread64.c84
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pwrite.c85
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pwrite64.c85
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S469
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S123
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S769
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list3
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h311
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.sym50
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/umount.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S57
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/profil-counter.h2
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/putmsg.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/readdir64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/readdir64_r.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/readelflib.c61
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/rt-sysdep.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/scandir64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/setrlimit.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h27
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/sys/procfs.h140
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h99
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h177
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/sys/user.h40
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/syscall.S31
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/syscalls.list3
-rw-r--r--libc/sysdeps/unix/sysv/linux/powerpc/sysdep.c29
-rw-r--r--libc/sysdeps/unix/sysv/linux/ppoll.c76
-rw-r--r--libc/sysdeps/unix/sysv/linux/pread.c96
-rw-r--r--libc/sysdeps/unix/sysv/linux/pread64.c93
-rw-r--r--libc/sysdeps/unix/sysv/linux/prof-freq.c51
-rw-r--r--libc/sysdeps/unix/sysv/linux/profil.c3
-rw-r--r--libc/sysdeps/unix/sysv/linux/pselect.c100
-rw-r--r--libc/sysdeps/unix/sysv/linux/ptrace.c113
-rw-r--r--libc/sysdeps/unix/sysv/linux/ptsname.c167
-rw-r--r--libc/sysdeps/unix/sysv/linux/pwrite.c96
-rw-r--r--libc/sysdeps/unix/sysv/linux/pwrite64.c94
-rw-r--r--libc/sysdeps/unix/sysv/linux/readahead.c48
-rw-r--r--libc/sysdeps/unix/sysv/linux/readdir64.c7
-rw-r--r--libc/sysdeps/unix/sysv/linux/readdir64_r.c7
-rw-r--r--libc/sysdeps/unix/sysv/linux/readlinkat.c90
-rw-r--r--libc/sysdeps/unix/sysv/linux/readonly-area.c103
-rw-r--r--libc/sysdeps/unix/sysv/linux/readv.c76
-rw-r--r--libc/sysdeps/unix/sysv/linux/reboot.c30
-rw-r--r--libc/sysdeps/unix/sysv/linux/recv.S6
-rw-r--r--libc/sysdeps/unix/sysv/linux/recvfrom.S6
-rw-r--r--libc/sysdeps/unix/sysv/linux/recvmsg.S6
-rw-r--r--libc/sysdeps/unix/sysv/linux/renameat.c184
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/Implies3
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/Makefile8
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/elfclass.h39
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/environments.h87
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/fcntl.h256
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/ipc.h61
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/mman.h104
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/msq.h84
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/sem.h92
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/shm.h110
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/sigaction.h110
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/siginfo.h311
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/stat.h256
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/statfs.h67
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/bits/typesizes.h72
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/brk.c56
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/dl-cache.h1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/fpu/Implies2
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/ldconfig.h26
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/ldd-rewrite.sed15
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/nldbl-abi.h8
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/readelflib.c60
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/rt-sysdep.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/Makefile15
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/Versions29
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/alphasort64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/chown.c120
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/clone.S76
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/fchown.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/fchownat.c159
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/fcntl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/fxstat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/fxstatat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S75
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/getdents64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/getegid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/geteuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/getgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/getgroups.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/getresgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/getresuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/getrlimit.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/getrlimit64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/getuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/lchown.c69
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/lockf64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/lxstat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c101
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/mmap.S84
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S113
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/msgctl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/oldgetrlimit64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c91
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/profil-counter.h27
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/register-dump.h130
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/scandir64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/semctl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setcontext.S72
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setegid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/seteuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setfsgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setfsuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setgroups.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setregid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setresgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setresuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setreuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setrlimit.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/setuid.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/shmctl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/socket.S143
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S108
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/syscall.S68
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list5
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S137
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h301
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/versionsort64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-32/xstat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/Implies1
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/Makefile11
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/Versions7
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/clone.S79
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/dl-cache.h25
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S75
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/kernel_stat.h21
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c100
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/mmap.S79
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/profil-counter.h27
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/register-dump.h133
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/setcontext.S72
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/sigaction.c55
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/sigpending.c38
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/sigprocmask.c41
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/socket.S137
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S108
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/syscall.S69
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/syscalls.list35
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S123
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h304
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/semtimedop.c38
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h28
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/sys/elf.h26
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/sys/procfs.h176
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/sys/ptrace.h138
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/sys/ucontext.h88
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/sys/user.h83
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/system.c34
-rw-r--r--libc/sysdeps/unix/sysv/linux/s390/ucontext_i.sym23
-rw-r--r--libc/sysdeps/unix/sysv/linux/sa_len.c59
-rw-r--r--libc/sysdeps/unix/sysv/linux/sched_getaffinity.c59
-rw-r--r--libc/sysdeps/unix/sysv/linux/sched_setaffinity.c88
-rw-r--r--libc/sysdeps/unix/sysv/linux/scsi/scsi.h226
-rw-r--r--libc/sysdeps/unix/sysv/linux/scsi/scsi_ioctl.h34
-rw-r--r--libc/sysdeps/unix/sysv/linux/scsi/sg.h275
-rw-r--r--libc/sysdeps/unix/sysv/linux/segfault.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/semctl.c192
-rw-r--r--libc/sysdeps/unix/sysv/linux/semget.c38
-rw-r--r--libc/sysdeps/unix/sysv/linux/semop.c38
-rw-r--r--libc/sysdeps/unix/sysv/linux/semtimedop.c40
-rw-r--r--libc/sysdeps/unix/sysv/linux/send.S7
-rw-r--r--libc/sysdeps/unix/sysv/linux/sendmsg.S6
-rw-r--r--libc/sysdeps/unix/sysv/linux/sendto.S6
-rw-r--r--libc/sysdeps/unix/sysv/linux/setegid.c61
-rw-r--r--libc/sysdeps/unix/sysv/linux/seteuid.c61
-rw-r--r--libc/sysdeps/unix/sysv/linux/setgid.c31
-rw-r--r--libc/sysdeps/unix/sysv/linux/sethostid.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/setipv4sourcefilter.c65
-rw-r--r--libc/sysdeps/unix/sysv/linux/setregid.c31
-rw-r--r--libc/sysdeps/unix/sysv/linux/setresgid.c32
-rw-r--r--libc/sysdeps/unix/sysv/linux/setresuid.c32
-rw-r--r--libc/sysdeps/unix/sysv/linux/setreuid.c31
-rw-r--r--libc/sysdeps/unix/sysv/linux/setsockopt.S5
-rw-r--r--libc/sysdeps/unix/sysv/linux/setsourcefilter.c78
-rw-r--r--libc/sysdeps/unix/sysv/linux/setuid.c30
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/Makefile11
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/Versions27
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/bits/atomic.h419
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/bits/fcntl.h236
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/bits/mman.h103
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/brk.c48
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/chown.c69
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/clone.S132
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/fchown.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/fchownat.c140
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/fcntl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/fxstat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/fxstatat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/getegid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/geteuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/getgroups.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/getresgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/getresuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/getrlimit.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/getrlimit64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/getuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/lchown.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/lockf64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/lxstat.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/makecontext.S145
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/msgctl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/pipe.S43
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/pread.c93
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/pread64.c94
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/profil-counter.h33
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/pwrite.c93
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/pwrite64.c96
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/semctl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/setegid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/seteuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/setfsgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/setfsuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/setgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/setgroups.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/setregid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/setresgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/setresuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/setreuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/setrlimit.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/setuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh3/getcontext.S88
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh3/register-dump.h151
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh3/setcontext.S99
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh3/swapcontext.S132
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh3/sys/ucontext.h102
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym38
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh4/getcontext.S131
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh4/register-dump.h262
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh4/setcontext.S139
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh4/swapcontext.S214
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh4/sys/ucontext.h115
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh4/sysdep.h4
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym73
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/shmctl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sigcontextinfo.h27
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/socket.S180
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sys/io.h48
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sys/procfs.h115
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sys/user.h28
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/syscall.S44
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/syscalls.list3
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sysdep.S34
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/sysdep.h391
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/vfork.S71
-rw-r--r--libc/sysdeps/unix/sysv/linux/sh/xstat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/shm_open.c248
-rw-r--r--libc/sysdeps/unix/sysv/linux/shm_unlink.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/shmat.c59
-rw-r--r--libc/sysdeps/unix/sysv/linux/shmctl.c161
-rw-r--r--libc/sysdeps/unix/sysv/linux/shmdt.c35
-rw-r--r--libc/sysdeps/unix/sysv/linux/shmget.c38
-rw-r--r--libc/sysdeps/unix/sysv/linux/shutdown.S3
-rw-r--r--libc/sysdeps/unix/sysv/linux/sigaction.c140
-rw-r--r--libc/sysdeps/unix/sysv/linux/siglist.h25
-rw-r--r--libc/sysdeps/unix/sysv/linux/signal.c3
-rw-r--r--libc/sysdeps/unix/sysv/linux/sigpending.c64
-rw-r--r--libc/sysdeps/unix/sysv/linux/sigprocmask.c91
-rw-r--r--libc/sysdeps/unix/sysv/linux/sigqueue.c52
-rw-r--r--libc/sysdeps/unix/sysv/linux/sigreturn.c3
-rw-r--r--libc/sysdeps/unix/sysv/linux/sigset-cvt-mask.h44
-rw-r--r--libc/sysdeps/unix/sysv/linux/sigstack.c69
-rw-r--r--libc/sysdeps/unix/sysv/linux/sigsuspend.c95
-rw-r--r--libc/sysdeps/unix/sysv/linux/sigtimedwait.c93
-rw-r--r--libc/sysdeps/unix/sysv/linux/sigwait.c111
-rw-r--r--libc/sysdeps/unix/sysv/linux/sigwaitinfo.c94
-rw-r--r--libc/sysdeps/unix/sysv/linux/sizes.h24
-rw-r--r--libc/sysdeps/unix/sysv/linux/sleep.c149
-rw-r--r--libc/sysdeps/unix/sysv/linux/socketcall.h48
-rw-r--r--libc/sysdeps/unix/sysv/linux/socketpair.S3
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/Makefile5
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/Versions28
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/a.out.h174
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/a.out.h13
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/environments.h87
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/errno.h58
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h255
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/ioctls.h37
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/ipc.h62
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/mman.h106
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/msq.h84
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/poll.h50
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/resource.h241
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/sem.h92
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/setjmp.h69
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/shm.h111
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/sigaction.h76
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/sigcontext.h78
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/siginfo.h318
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/signum.h84
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/sigstack.h55
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/stat.h165
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/termios.h233
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h66
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h20
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/dl-cache.h39
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/fork.S30
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/getsysstats.c55
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/kernel_termios.h38
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/ldd-rewrite.sed3
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/readelflib.c62
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/rt-sysdep.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/Implies3
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/Makefile21
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/Versions23
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/brk.c55
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/chown.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S109
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/fchown.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/fchownat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/fcntl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/fpu/Implies2
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/fxstat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/fxstatat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/getdents64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/getegid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/geteuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/getgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/getgroups.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/getpagesize.c46
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/getuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/glob64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/kernel_stat.h32
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/lchown.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/lockf64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/lxstat.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/msgctl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/nldbl-abi.h8
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S40
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/profil-counter.h26
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/register-dump.h336
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/scandir64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/semctl.c208
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/setegid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/seteuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/setfsgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/setfsuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/setgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/setgroups.c2
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/setregid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/setresgid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/setresuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/setreuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/setuid.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/shmctl.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c161
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h29
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/socket.S117
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/get_clockfreq.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/syscall.S37
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list6
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h160
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc32/xstat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/Implies1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/Makefile2
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/Versions11
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/__longjmp.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/brk.S98
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/bsd-_setjmp.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/bsd-setjmp.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S121
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/dl-brk.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/dl-cache.h25
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/fxstat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/fxstatat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c238
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/getcontext.S65
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/kernel_stat.h47
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/longjmp.S52
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/lxstat.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/makecontext.c67
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/msgctl.c38
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S41
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/profil-counter.h26
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/register-dump.h257
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/semctl.c58
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/setcontext.S39
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/setjmp.S67
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/shmctl.c37
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigaction.c85
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h32
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigjmp.S1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigpending.c36
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigprocmask.c39
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/sizes.h24
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/socket.S119
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/swapcontext.c48
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/syscall.S39
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list20
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h175
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/time.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/ucontext_i.h28
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/wordexp.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/xstat.c8
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sparc64/xstatconv.c127
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sys/procfs.h211
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sys/ptrace.h183
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sys/trap.h7
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sys/ucontext.h270
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sys/user.h85
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/syscalls.list3
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sysdep.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/sysdep.h153
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/system.c34
-rw-r--r--libc/sysdeps/unix/sysv/linux/sparc/vfork.S29
-rw-r--r--libc/sysdeps/unix/sysv/linux/speed.c111
-rw-r--r--libc/sysdeps/unix/sysv/linux/statfs64.c74
-rw-r--r--libc/sysdeps/unix/sysv/linux/statvfs.c46
-rw-r--r--libc/sysdeps/unix/sysv/linux/statvfs64.c74
-rw-r--r--libc/sysdeps/unix/sysv/linux/symlinkat.c87
-rw-r--r--libc/sysdeps/unix/sysv/linux/sync_file_range.c47
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/acct.h77
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/epoll.h110
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/fsuid.h36
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/inotify.h92
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/kd.h35
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/kdaemon.h33
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/klog.h34
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/mount.h119
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/param.h72
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/pci.h25
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/personality.h73
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/prctl.h32
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/procfs.h115
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/ptrace.h129
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/quota.h225
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/raw.h39
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/reboot.h49
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/soundcard.h1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/swap.h43
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/syscall.h35
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/sysctl.h72
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/sysinfo.h48
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/sysmacros.h69
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/timex.h127
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/ttydefaults.h100
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/ultrasound.h1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/user.h1
-rw-r--r--libc/sysdeps/unix/sysv/linux/sys/vt.h1
-rw-r--r--libc/sysdeps/unix/sysv/linux/syscalls.list97
-rw-r--r--libc/sysdeps/unix/sysv/linux/sysconf.c118
-rw-r--r--libc/sysdeps/unix/sysv/linux/sysctl.c49
-rw-r--r--libc/sysdeps/unix/sysv/linux/syslog.c10
-rw-r--r--libc/sysdeps/unix/sysv/linux/system.c78
-rw-r--r--libc/sysdeps/unix/sysv/linux/tcdrain.c41
-rw-r--r--libc/sysdeps/unix/sysv/linux/tcflow.c31
-rw-r--r--libc/sysdeps/unix/sysv/linux/tcflush.c31
-rw-r--r--libc/sysdeps/unix/sysv/linux/tcgetattr.c82
-rw-r--r--libc/sysdeps/unix/sysv/linux/tcgetpgrp.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/tcsetattr.c85
-rw-r--r--libc/sysdeps/unix/sysv/linux/tcsetpgrp.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/termio.h6
-rw-r--r--libc/sysdeps/unix/sysv/linux/testrtsig.h36
-rw-r--r--libc/sysdeps/unix/sysv/linux/time.c43
-rw-r--r--libc/sysdeps/unix/sysv/linux/truncate64.c76
-rw-r--r--libc/sysdeps/unix/sysv/linux/tst-clone.c56
-rw-r--r--libc/sysdeps/unix/sysv/linux/ttyname.c200
-rw-r--r--libc/sysdeps/unix/sysv/linux/ttyname_r.c203
-rw-r--r--libc/sysdeps/unix/sysv/linux/ualarm.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/ulimit.c86
-rw-r--r--libc/sysdeps/unix/sysv/linux/umount.S12
-rw-r--r--libc/sysdeps/unix/sysv/linux/umount2.S13
-rw-r--r--libc/sysdeps/unix/sysv/linux/unlinkat.c97
-rw-r--r--libc/sysdeps/unix/sysv/linux/unlockpt.c49
-rw-r--r--libc/sysdeps/unix/sysv/linux/updwtmp.c34
-rw-r--r--libc/sysdeps/unix/sysv/linux/usleep.c34
-rw-r--r--libc/sysdeps/unix/sysv/linux/ustat.c42
-rw-r--r--libc/sysdeps/unix/sysv/linux/utimes.c60
-rw-r--r--libc/sysdeps/unix/sysv/linux/utmp_file.c34
-rw-r--r--libc/sysdeps/unix/sysv/linux/vfork.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wait.c45
-rw-r--r--libc/sysdeps/unix/sysv/linux/wait3.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/waitid.c71
-rw-r--r--libc/sysdeps/unix/sysv/linux/waitpid.c50
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/fstatfs64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/fstatvfs.c5
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/fstatvfs64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/fxstat.c48
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/fxstat64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c109
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/fxstatat64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/getdents.c4
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/getdents64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/getrlimit64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/glob64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/internal_statvfs64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/lxstat.c48
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/lxstat64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/mmap64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/posix_fadvise.c41
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/posix_fadvise64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/pread64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/pwrite64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/readdir.c7
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/readdir64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c4
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/sendfile64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/setrlimit64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/statfs64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/statvfs.c5
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/statvfs64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list17
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/truncate64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/xstat.c47
-rw-r--r--libc/sysdeps/unix/sysv/linux/wordsize-64/xstat64.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/writev.c75
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/Implies1
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/Makefile15
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/Versions9
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/__start_context.S49
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/bits/a.out.h13
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/bits/environments.h87
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/bits/fcntl.h250
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/bits/mman.h104
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/bits/msq.h83
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/bits/sem.h87
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/bits/shm.h110
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/bits/sigcontext.h159
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/bits/stat.h203
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/brk.c42
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/clone.S120
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/dl-cache.h25
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.c5
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.h5
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/get_clockfreq.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/getcontext.S88
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/gettimeofday.S44
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/kernel_stat.h21
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/ldconfig.h26
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/ldd-rewrite.sed3
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/makecontext.c113
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/profil-counter.h32
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/readelflib.c62
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/recv.c42
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/register-dump.h346
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/send.c41
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/setcontext.S105
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sigaction.c112
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h26
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sigpending.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sigprocmask.c1
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/swapcontext.S123
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sys/debugreg.h88
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sys/epoll.h110
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sys/io.h181
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sys/perm.h36
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sys/procfs.h142
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sys/reg.h79
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sys/ucontext.h248
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sys/user.h175
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/syscall.S44
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/syscalls.list36
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sysconf.c326
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sysdep.S41
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/sysdep.h341
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/time.S42
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym34
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/umount.c31
-rw-r--r--libc/sysdeps/unix/sysv/linux/x86_64/vfork.S61
-rw-r--r--libc/sysdeps/unix/sysv/linux/xmknod.c57
-rw-r--r--libc/sysdeps/unix/sysv/linux/xmknodat.c95
-rw-r--r--libc/sysdeps/unix/sysv/linux/xstat.c64
-rw-r--r--libc/sysdeps/unix/sysv/linux/xstat64.c97
-rw-r--r--libc/sysdeps/unix/sysv/linux/xstatconv.c285
-rw-r--r--libc/sysdeps/unix/sysv/linux/xstatconv.h27
-rw-r--r--libc/sysdeps/unix/sysv/setrlimit.c57
-rw-r--r--libc/sysdeps/unix/sysv/settimeofday.c48
-rw-r--r--libc/sysdeps/unix/sysv/sigaction.c84
-rw-r--r--libc/sysdeps/unix/sysv/syscalls.list16
-rw-r--r--libc/sysdeps/unix/sysv/sysv_termio.h155
-rw-r--r--libc/sysdeps/unix/sysv/tcdrain.c33
-rw-r--r--libc/sysdeps/unix/sysv/tcflow.c47
-rw-r--r--libc/sysdeps/unix/sysv/tcflush.c45
-rw-r--r--libc/sysdeps/unix/sysv/tcgetattr.c171
-rw-r--r--libc/sysdeps/unix/sysv/tcgetpgrp.c36
-rw-r--r--libc/sysdeps/unix/sysv/tcsendbrk.c44
-rw-r--r--libc/sysdeps/unix/sysv/tcsetattr.c210
-rw-r--r--libc/sysdeps/unix/sysv/tcsetpgrp.c32
-rw-r--r--libc/sysdeps/unix/telldir.c28
-rw-r--r--libc/sysdeps/unix/time.c42
-rw-r--r--libc/sysdeps/unix/utime.c50
-rw-r--r--libc/sysdeps/unix/x86_64/sysdep.S90
-rw-r--r--libc/sysdeps/unix/x86_64/sysdep.h35
-rw-r--r--libc/sysdeps/unix/xmknod.c42
-rw-r--r--libc/sysdeps/unix/xstat.c39
1306 files changed, 92338 insertions, 0 deletions
diff --git a/libc/sysdeps/unix/Implies b/libc/sysdeps/unix/Implies
new file mode 100644
index 000000000..b3188f742
--- /dev/null
+++ b/libc/sysdeps/unix/Implies
@@ -0,0 +1 @@
+posix
diff --git a/libc/sysdeps/unix/Makefile b/libc/sysdeps/unix/Makefile
new file mode 100644
index 000000000..4ab06ba33
--- /dev/null
+++ b/libc/sysdeps/unix/Makefile
@@ -0,0 +1,346 @@
+# Copyright (C) 1991,1992,1993,1994,1995,1996,1997,1998,1999,2003, 2006
+# Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, write to the Free
+# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307 USA.
+
+# The unix-specific configure fragment writes `unix-generated' in config.make.
+config-generated := $(config-generated) $(unix-generated)
+
+ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
+ $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/local_lim.h))))))
+
+ifneq (,$(wildcard $(sysincludedir)/sys/param.h))
+mk-local_lim-CFLAGS += -DHAVE_SYS_PARAM_H
+endif
+ifneq (,$(wildcard $(sysincludedir)/sys/limits.h))
+mk-local_lim-CFLAGS += -DHAVE_SYS_LIMITS_H
+endif
+ifneq (,$(wildcard $(sysincludedir)/limits.h))
+mk-local_lim-CFLAGS += -DHAVE_LIMITS_H
+endif
+
+$(common-objpfx)bits/local_lim.h: $(common-objpfx)mk-local_lim
+ $(dir $<)$(notdir $<) > $@-t
+ mv -f $@-t $@
+$(common-objpfx)mk-local_lim: $(sysdep_dir)/unix/mk-local_lim.c
+ $(common-objdir-compile)
+
+before-compile += $(common-objpfx)bits/local_lim.h
+common-generated += bits/local_lim.h mk-local_lim
+
+endif
+
+ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
+ $(patsubst %/sys/param.h,%/,\
+ $(firstword $(wildcard $(+sysdep_dirs:%=%/sys/param.h))))))
+
+before-compile := $(before-compile) $(common-objpfx)sys/param.h
+
+$(common-objpfx)sys/param.h: $(sysincludedir)/sys/param.h
+ $(make-target-directory)
+ (echo '#ifndef _SYS_PARAM_H'; \
+ echo '#define _SYS_PARAM_H 1'; \
+ echo '#include <endian.h>'; \
+ $(AWK) < $< \
+ '/^#define[ ]*NULL/ { print "#ifndef NULL"; \
+ print $$0; \
+ print "#endif"; \
+ was_null = 1 } \
+ { if (!was_null) print $$0; \
+ was_null = 0 }'; \
+ echo '#ifndef MAXHOSTNAMELEN'; \
+ echo '#define MAXHOSTNAMELEN 64 /* XXX */'; \
+ echo '#endif /* No MAXHOSTNAMELEN. */'; \
+ echo '#endif /* sys/param.h */') > $@-tmp
+ mv $@-tmp $@
+
+$(common-objpfx)param.h.c: $(sysincludedir)/sys/param.h
+ rm -f $@
+ cp $< $@
+$(common-objpfx)param.h.dep: $(common-objpfx)param.h.c \
+ $(sysdep_dir)/unix/Makefile
+ $(+mkdep) -I$(sysincludedir) $< \
+ | sed > $@-t \
+ -e 's@$(sysincludedir)/sys/param.h@@' \
+ -e 's@^.*:@@' \
+ -e 's@$<@@g' \
+ -e 's@$(sysincludedir)/*@@g' \
+ -e 's@\\$$@@' \
+ -e 's@^@sys/param.h-includes := $$(sys/param.h-includes) @'
+ mv $@-t $@
+
+# Get the generated definition of sys/param.h-includes.
+ifndef no_deps
+-include $(common-objpfx)param.h.dep
+endif
+
+# Don't preempt our own headers.
+sys/param.h-includes := \
+ $(filter-out $(patsubst $(..)%,%,\
+ $(wildcard $(addprefix $(..),\
+ $(sys/param.h-includes)))),\
+ $(sys/param.h-includes))
+
+
+.PHONY: sys/param.h-includes
+sys/param.h-includes: $(addprefix $(common-objpfx),$(sys/param.h-includes))
+
+ifdef sys/param.h-includes
+# Copy the system files to $(common-objdir).
+$(addprefix $(common-objpfx),$(sys/param.h-includes)): $(common-objpfx)%: \
+ $(sysincludedir)/%
+ $(make-target-directory)
+# Some of these files sometimes contain conflicting declarations for htons,
+# ntohs, etc. They also often contain definitions of *_ENDIAN and
+# BYTE_ORDER, which we define ourselves in <endian.h>.
+ sed -e '/[ ]*[hn]to[nh][sl][ (]*/d' \
+ -e '/^#define[ ]*[A-Z]*_ENDIAN/d' \
+ -e '/^#define[ ]*BYTE_ORDER/d' \
+ $< > $@-t
+ mv $@-t $@
+endif
+
+common-generated := $(common-generated) \
+ sys/param.h $(sys/param.h-includes) param.h.c param.h.dep
+
+
+ifeq ($(subdir),misc)
+
+# Install system headers the system sys/param.h uses.
+
+sysdep_headers := $(sysdep_headers) $(sys/param.h-includes)
+
+endif # misc
+
+endif # No sysdep sys/param.h.
+
+ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
+ $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/errno.h))))))
+
+# These need to exist before any compiling is done,
+# so cpp doesn't instead find the generic versions.
+before-compile := $(before-compile) $(common-objpfx)bits/errno.h
+
+$(common-objpfx)bits/errno.h: $(common-objpfx)make-errnos
+ $(dir $<)$(notdir $<) > $@-tmp
+ mv $@-tmp $@
+
+$(common-objpfx)make-errnos: $(common-objpfx)make-errnos.c
+ $(common-objdir-compile)
+
+$(common-objpfx)make-errnos.c: $(sysdep_dir)/unix/errnos-tmpl.c \
+ $(sysdep_dir)/unix/errnos.awk $(common-objpfx)errnos
+ $(AWK) -f $(word 2,$^) errnos="`tr '\012' ' ' < $(word 3,$^)`" $< > $@T
+ mv $@T $@
+
+$(common-objpfx)errnos: $(wildcard $(sysincludedir)/errno.h \
+ $(sysincludedir)/sys/errno.h)
+ sed -n 's/^#define[ ]*\(E[A-Z0-9][A-Z0-9]*\)[ ].*$$/\1/p' \
+ $^ > $@-tmp
+ mv $@-tmp $@
+
+common-generated := $(common-generated) \
+ errnos.h errnos make-errnos make-errnos.c
+endif
+
+ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
+ $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/ioctls.h))))))
+
+before-compile := $(before-compile) $(common-objpfx)bits/ioctls.h
+
+$(common-objpfx)bits/ioctls.h: $(common-objpfx)make-ioctls
+ $(dir $<)$(notdir $<) > $@-tmp
+ mv $@-tmp $@
+
+ioctl-includes := sys/termios.h net/nit.h
+ioctl-includes := $(wildcard $(addprefix $(sysincludedir)/,$(ioctl-includes)))
+make-ioctls-CFLAGS := $(subst /,_,$(subst .,_,\
+ $(patsubst $(sysincludedir)/%,-DHAVE_%,\
+ $(ioctl-includes))))
+
+$(common-objpfx)make-ioctls: $(common-objpfx)make-ioctls.c
+ $(common-objdir-compile)
+
+$(common-objpfx)make-ioctls.c: $(sysdep_dir)/unix/ioctls-tmpl.c \
+ $(sysdep_dir)/unix/ioctls.awk \
+ $(common-objpfx)ioctls
+ $(AWK) -f $(word 2,$^) requests="`cat $(word 3,$^)`" $< > $@T
+ mv $@T $@
+
+
+bits_termios.h := $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/termios.h)))
+ifeq ($(bits_termios.h),$(sysdep_dir)/generic/bits/termios.h)
+bits_termios.h := # Ignore the generic version.
+endif
+
+# If there is a system-specific <bits/termios.h> file, we want to omit
+# all the symbols it defines from ioctls. Otherwise, both
+# <bits/ioctls.h> and <bits/termios.h> would define them. The
+# system-specific <bits/termios.h> file presumably defines them with
+# the same values as we find from the system's headers. We also want
+# to omit from ioctls the symbols defined in our own
+# <sys/ttydefaults.h>, to avoid multiple definition conflicts. We use
+# snarf-ioctls on these files to find what symbols we want to omit.
+# fgrep -xv gives all lines which do not match in their entirety;
+# without -x, CSTOP's presence elided TIOCSTOP.
+
+$(common-objpfx)ioctls: $(sysdep_dir)/unix/snarf-ioctls \
+ $(sysincludedir)/sys/ioctl.h $(ioctl-includes)
+ $(dir $<)$(notdir $<) $(filter-out $<,$^) \
+ | fgrep -xv "`($(dir $<)$(notdir $<) $(bits_termios.h) \
+ $(..)sysdeps/generic/sys/ttydefaults.h; \
+ echo NULL) \
+ | sort | uniq`" \
+ | sort | uniq | tr '\012' ' ' > $@-tmp
+ mv $@-tmp $@
+
+common-generated := $(common-generated) \
+ bits/ioctls.h ioctls make-ioctls make-ioctls.c
+endif
+
+ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
+ $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/sys/syscall.h))))))
+
+# The syscall code assumes a file <sys/syscall.h> that defines macros
+# `SYS_call' for syscall `call'. Variations on this I have seen include:
+# it's in <sys/syscall.h>;
+# it's in <sys.s>;
+# it defines `CALL' instead of `SYS_call'.
+# Irix has a <syscall.h> which is not what we want, so check for <sys.s> first.
+
+# Find a file that might have these. NOTE: This list of possibilities is
+# repeated in sysdeps/unix/configure and the two should be kept in sync.
+syscall.h := $(firstword $(wildcard $(addprefix $(sysincludedir)/, \
+ sys.s sys/sys.s \
+ sys.S sys/sys.S \
+ syscall.h sys/syscall.h \
+ )))
+ifdef syscall.h
+
+# Transmogrify any of several formats of the file into the one we want.
+$(common-objpfx)sys/syscall.h: $(syscall.h)
+ $(make-target-directory)
+ tr '[A-Z]' '[a-z]' < $< | \
+ sed -e 's/[ ]sys_/ /' \
+ -e 's/^#define[ ]*\([a-z0-9_]*\)[ ]*/#define SYS_\1 /' \
+ -e 's/[ ]sys_/ SYS_/' \
+ -e 's/SYS_syscall_basenum/syscall_basenum/g' \
+ -e 's/SYS_kerncall_basenum/kerncall_basenum/g' \
+ -e 's/SYS_sysvoffset/sysvoffset/g' \
+ -e '/^#/!d' \
+ -e '/^#ident/d' \
+ -e 's-\(/\*[^*]*\)$$-\1\*/-' \
+ > $@-tmp
+ mv $@-tmp $@
+
+before-compile += $(common-objpfx)sys/syscall.h
+common-generated += sys/syscall.h
+
+endif
+
+endif
+
+ifndef inhibit-unix-syscalls
+
+# Sysdep dirs unix/... can contain a file syscalls.list,
+# which specifies objects to be compiled as simple Unix system calls.
+
+-include $(common-objpfx)sysd-syscalls
+omit-deps += $(unix-syscalls)
+
+ifeq (misc,$(subdir))
+sysdep_routines += $(unix-extra-syscalls)
+
+ifdef unix-stub-syscalls
+# The system call entry points in this list are supposed to be additional
+# functions not overriding any other sysdeps/.../call.c implementation, but
+# their system call numbers are unavailable in the kernel headers we're
+# using. Instead of a system call stub, these get a function that fails
+# with ENOSYS. We just generate a single module defining one function and
+# making all these entry point names aliases for it.
+sysdep_routines += stub-syscalls
+$(objpfx)stub-syscalls.c: $(common-objpfx)sysd-syscalls \
+ $(..)sysdeps/unix/Makefile
+ $(make-target-directory)
+ (for call in $(unix-stub-syscalls); do \
+ echo "#define $$call RENAMED_$$call"; \
+ done; \
+ echo '#include <errno.h>'; \
+ for call in $(unix-stub-syscalls); do \
+ echo "#undef $$call"; \
+ done; \
+ echo 'long int _no_syscall (void)'; \
+ echo '{ __set_errno (ENOSYS); return -1L; }'; \
+ for call in $(unix-stub-syscalls); do \
+ case $$call in \
+ *@@*) ver=$${call##*@}; call=$${call%%*@}; \
+ echo "strong_alias (_no_syscall, $${call}_$${ver})"; \
+ echo "default_symbol_version \
+ ($${call}_$${ver}, $$call, $$ver);" ;; \
+ *@@*) ver=$${call##*@}; call=$${call%%*@}; \
+ echo "strong_alias (_no_syscall, $${call}_$${ver})"; \
+ echo "symbol_version ($${call}_$${ver}, $$call, $$ver);" ;; \
+ *) echo "weak_alias (_no_syscall, $$call)"; \
+ echo "stub_warning ($$call)"; \
+ echo "weak_alias (_no_syscall, __GI_$$call)" ;; \
+ esac; \
+ echo '#include <stub-tag.h>'; \
+ done) > $@T
+ mv -f $@T $@
+generated += stub-syscalls.c
+endif
+endif
+
+# This is the end of the pipeline for compiling the syscall stubs.
+# The stdin in assembler with cpp using sysdep.h macros.
+# Be sure to disable debugging info since it would all just say "<stdin>".
+compile-syscall = $(filter-out -g%,$(COMPILE.S)) -x assembler-with-cpp -o $@ -
+
+ifndef avoid-generated
+$(common-objpfx)sysd-syscalls: $(..)sysdeps/unix/make-syscalls.sh \
+ $(wildcard $(+sysdep_dirs:%=%/syscalls.list))
+ for dir in $(+sysdep_dirs); do \
+ test -f $$dir/syscalls.list && \
+ { sysdirs='$(sysdirs)' \
+ asm_CPP='$(COMPILE.S) -E -x assembler-with-cpp' \
+ $(SHELL) $(dir $<)$(notdir $<) $$dir || exit 1; }; \
+ test $$dir = $(..)sysdeps/unix && break; \
+ done > $@T
+ mv -f $@T $@
+endif
+
+# The syscall objects depend on s-proto.d or s-proto-cancel.d, which
+# are generated to specify dependencies generated syscalls have on
+# headers.
+# These deps use file names relative to a subdir, so don't
+# include them in the parent directory.
+ifneq (,$(filter $(unix-syscalls),$(routines) $(sysdep_routines) $(aux)))
+ifndef no_deps
+-include $(common-objpfx)s-proto.d
+-include $(common-objpfx)s-proto-bp.d
+-include $(common-objpfx)s-proto-cancel.d
+endif
+endif
+
+$(common-objpfx)s-%.d: $(..)sysdeps/unix/s-%.S \
+ $(wildcard $(+sysdep_dirs:%=%/syscalls.list))
+ $(+make-deps)
+
+common-generated += s-proto.d s-proto-bp.d s-proto-cancel.d
+postclean-generated += sysd-syscalls
+
+endif
diff --git a/libc/sysdeps/unix/Subdirs b/libc/sysdeps/unix/Subdirs
new file mode 100644
index 000000000..a46884d4f
--- /dev/null
+++ b/libc/sysdeps/unix/Subdirs
@@ -0,0 +1 @@
+login
diff --git a/libc/sysdeps/unix/_exit.S b/libc/sysdeps/unix/_exit.S
new file mode 100644
index 000000000..115527efa
--- /dev/null
+++ b/libc/sysdeps/unix/_exit.S
@@ -0,0 +1,25 @@
+/* Copyright (C) 1991,92,97,99,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+PSEUDO (_exit, exit, 1)
+ /* Shouldn't get here. */
+PSEUDO_END(_exit)
+libc_hidden_def (_exit)
+weak_alias (_exit, _Exit)
diff --git a/libc/sysdeps/unix/alarm.c b/libc/sysdeps/unix/alarm.c
new file mode 100644
index 000000000..84ab5a52f
--- /dev/null
+++ b/libc/sysdeps/unix/alarm.c
@@ -0,0 +1,51 @@
+/* Copyright (C) 1991,1992,1994,1997,2002,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <unistd.h>
+#include <sys/time.h>
+
+/* Schedule an alarm. In SECONDS seconds, the process will get a SIGALRM.
+ If SECONDS is zero, any currently scheduled alarm will be cancelled.
+ The function returns the number of seconds remaining until the last
+ alarm scheduled would have signaled, or zero if there wasn't one.
+ There is no return value to indicate an error, but you can set `errno'
+ to 0 and check its value after calling `alarm', and this might tell you.
+ The signal may come late due to processor scheduling. */
+unsigned int
+alarm (seconds)
+ unsigned int seconds;
+{
+ struct itimerval old, new;
+ unsigned int retval;
+
+ new.it_interval.tv_usec = 0;
+ new.it_interval.tv_sec = 0;
+ new.it_value.tv_usec = 0;
+ new.it_value.tv_sec = (long int) seconds;
+ if (__setitimer (ITIMER_REAL, &new, &old) < 0)
+ return 0;
+
+ retval = old.it_value.tv_sec;
+ /* Round to the nearest second, but never report zero seconds when
+ the alarm is still set. */
+ if (old.it_value.tv_usec >= 500000
+ || (retval == 0 && old.it_value.tv_usec > 0))
+ ++retval;
+ return retval;
+}
+libc_hidden_def (alarm)
diff --git a/libc/sysdeps/unix/alpha/Makefile b/libc/sysdeps/unix/alpha/Makefile
new file mode 100644
index 000000000..441aa02a8
--- /dev/null
+++ b/libc/sysdeps/unix/alpha/Makefile
@@ -0,0 +1,3 @@
+ifeq ($(subdir),rt)
+librt-sysdep_routines += rt-sysdep
+endif
diff --git a/libc/sysdeps/unix/alpha/pipe.S b/libc/sysdeps/unix/alpha/pipe.S
new file mode 100644
index 000000000..2da4d78ab
--- /dev/null
+++ b/libc/sysdeps/unix/alpha/pipe.S
@@ -0,0 +1,32 @@
+/* Copyright (C) 1993, 1995, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger (davidm@cs.arizona.edu).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* __pipe is a special syscall since it returns two values. */
+
+#include <sysdep.h>
+
+PSEUDO (__pipe, pipe, 0)
+ stl r0, 0(a0)
+ stl r1, 4(a0)
+ mov zero, v0
+ ret
+PSEUDO_END(__pipe)
+
+libc_hidden_def (__pipe)
+weak_alias (__pipe, pipe)
diff --git a/libc/sysdeps/unix/alpha/rt-sysdep.S b/libc/sysdeps/unix/alpha/rt-sysdep.S
new file mode 100644
index 000000000..f966bf1e5
--- /dev/null
+++ b/libc/sysdeps/unix/alpha/rt-sysdep.S
@@ -0,0 +1 @@
+#include <sysdep.S>
diff --git a/libc/sysdeps/unix/alpha/sysdep.S b/libc/sysdeps/unix/alpha/sysdep.S
new file mode 100644
index 000000000..c67a6542f
--- /dev/null
+++ b/libc/sysdeps/unix/alpha/sysdep.S
@@ -0,0 +1,135 @@
+/* Copyright (C) 1993, 1996, 1998, 2002, 2003, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Brendan Kehoe (brendan@zen.org).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <features.h>
+
+#if defined(__ELF__) && defined(PIC)
+ /* Put this at the end of libc's text segment so that all of
+ the direct branches from the syscalls are forward, and
+ thus predicted not taken. */
+ .section .text.last, "ax", @progbits
+#else
+ .text
+#endif
+
+#ifdef PIC
+ /* When building a shared library, we branch here without
+ having loaded the GP. Nor, since it was a direct branch,
+ have we loaded PV with our address. Do both. */
+# define LOADGP br pv, 1f; 1: ldgp gp, 0(pv)
+# define PROLOGUE .prologue 0
+# define EPILOGUE
+#else
+ /* When building the static library, we tail call here from
+ elsewhere, which might use a different GP. The entertaining
+ part is that we have to return with the GP of our caller
+ in place, so that linker relaxation works properly. */
+ /* ??? This is so ugly. Consider always putting the errno
+ setting code with the syscall in the static case. */
+# define GPSAVEREG t10
+# define LOADGP ldah t11, 0(pv) !gpdisp!1; \
+ br 1f; \
+ .subsection 2; \
+ 1: mov gp, GPSAVEREG; \
+ lda gp, 0(t11) !gpdisp!1; \
+ br 2f; \
+ .previous; \
+ mov gp, GPSAVEREG; \
+ 2:
+# define PROLOGUE .prologue 1
+# define EPILOGUE mov GPSAVEREG, gp
+#endif
+
+ .align 4
+ .globl __syscall_error
+ .ent __syscall_error
+__syscall_error:
+
+#if defined(_LIBC_REENTRANT) && USE___THREAD
+
+#ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+#else
+# define SYSCALL_ERROR_ERRNO errno
+#endif
+
+ LOADGP
+ PROLOGUE
+ mov v0, t0
+ call_pal PAL_rduniq
+ ldq t1, SYSCALL_ERROR_ERRNO(gp) !gottprel
+ addq v0, t1, v0
+ stl t0, 0(v0)
+ lda v0, -1
+ EPILOGUE
+ ret
+
+#elif defined(_LIBC_REENTRANT)
+
+ LOADGP
+ lda sp, -32(sp)
+ .frame sp, 32, ra, 0
+ stq ra, 0(sp)
+ stq v0, 8(sp)
+#ifdef GPSAVEREG
+ stq GPSAVEREG, 16(sp)
+#endif
+ .mask 0x4000001, -32
+ PROLOGUE
+
+ /* Find our per-thread errno address */
+#if defined PIC && !defined IS_IN_librt
+ bsr ra, __errno_location !samegp
+#else
+ jsr ra, __errno_location
+#ifndef GPSAVEREG
+ ldgp gp, 0(ra)
+#endif
+#endif
+
+ /* Store the error value. */
+ ldq t0, 8(sp)
+ stl t0, 0(v0)
+
+ /* And kick back a -1. */
+ ldi v0, -1
+
+#ifdef GPSAVEREG
+ ldq GPSAVEREG, 16(sp)
+#endif
+ ldq ra, 0(sp)
+ lda sp, 32(sp)
+ EPILOGUE
+ ret
+
+#else
+
+ LOADGP
+ PROLOGUE
+ stl v0, errno
+ lda v0, -1
+ EPILOGUE
+ ret
+
+#endif
+
+ .subsection 3
+ .end __syscall_error
diff --git a/libc/sysdeps/unix/alpha/sysdep.h b/libc/sysdeps/unix/alpha/sysdep.h
new file mode 100644
index 000000000..2e5bc798e
--- /dev/null
+++ b/libc/sysdeps/unix/alpha/sysdep.h
@@ -0,0 +1,438 @@
+/* Copyright (C) 1992, 1995, 1996, 2000, 2003, 2004, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Brendan Kehoe (brendan@zen.org).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/unix/sysdep.h>
+
+#ifdef __ASSEMBLER__
+
+#ifdef __linux__
+# include <alpha/regdef.h>
+#else
+# include <regdef.h>
+#endif
+
+#include <tls.h> /* Defines USE___THREAD. */
+
+#ifdef IS_IN_rtld
+# include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
+#endif
+
+
+#ifdef __STDC__
+#define __LABEL(x) x##:
+#else
+#define __LABEL(x) x/**/:
+#endif
+
+#define LEAF(name, framesize) \
+ .globl name; \
+ .align 4; \
+ .ent name, 0; \
+ __LABEL(name) \
+ .frame sp, framesize, ra
+
+#define ENTRY(name) \
+ .globl name; \
+ .align 4; \
+ .ent name, 0; \
+ __LABEL(name) \
+ .frame sp, 0, ra
+
+/* Mark the end of function SYM. */
+#undef END
+#define END(sym) .end sym
+
+#ifdef PROF
+# define PSEUDO_PROLOGUE \
+ .frame sp, 0, ra; \
+ ldgp gp,0(pv); \
+ .set noat; \
+ lda AT,_mcount; \
+ jsr AT,(AT),_mcount; \
+ .set at; \
+ .prologue 1
+#elif defined PIC
+# define PSEUDO_PROLOGUE \
+ .frame sp, 0, ra; \
+ .prologue 0
+#else
+# define PSEUDO_PROLOGUE \
+ .frame sp, 0, ra; \
+ ldgp gp,0(pv); \
+ .prologue 1
+#endif /* PROF */
+
+#if RTLD_PRIVATE_ERRNO
+# define SYSCALL_ERROR_LABEL $syscall_error
+# define SYSCALL_ERROR_HANDLER \
+ stl v0, rtld_errno(gp) !gprel; \
+ lda v0, -1; \
+ ret
+#elif defined(PIC)
+# define SYSCALL_ERROR_LABEL __syscall_error
+# define SYSCALL_ERROR_HANDLER \
+ br $31, __syscall_error !samegp
+#else
+# define SYSCALL_ERROR_LABEL $syscall_error
+# define SYSCALL_ERROR_HANDLER \
+ jmp $31, __syscall_error
+#endif /* RTLD_PRIVATE_ERRNO */
+
+/* Overridden by specific syscalls. */
+#undef PSEUDO_PREPARE_ARGS
+#define PSEUDO_PREPARE_ARGS /* Nothing. */
+
+#define PSEUDO(name, syscall_name, args) \
+ .globl name; \
+ .align 4; \
+ .ent name,0; \
+__LABEL(name) \
+ PSEUDO_PROLOGUE; \
+ PSEUDO_PREPARE_ARGS \
+ lda v0, SYS_ify(syscall_name); \
+ call_pal PAL_callsys; \
+ bne a3, SYSCALL_ERROR_LABEL
+
+#undef PSEUDO_END
+#if defined(PIC) && !RTLD_PRIVATE_ERRNO
+# define PSEUDO_END(sym) END(sym)
+#else
+# define PSEUDO_END(sym) \
+$syscall_error: \
+ SYSCALL_ERROR_HANDLER; \
+ END(sym)
+#endif
+
+#define PSEUDO_NOERRNO(name, syscall_name, args) \
+ .globl name; \
+ .align 4; \
+ .ent name,0; \
+__LABEL(name) \
+ PSEUDO_PROLOGUE; \
+ PSEUDO_PREPARE_ARGS \
+ lda v0, SYS_ify(syscall_name); \
+ call_pal PAL_callsys;
+
+#undef PSEUDO_END_NOERRNO
+#define PSEUDO_END_NOERRNO(sym) END(sym)
+
+#define ret_NOERRNO ret
+
+#define PSEUDO_ERRVAL(name, syscall_name, args) \
+ .globl name; \
+ .align 4; \
+ .ent name,0; \
+__LABEL(name) \
+ PSEUDO_PROLOGUE; \
+ PSEUDO_PREPARE_ARGS \
+ lda v0, SYS_ify(syscall_name); \
+ call_pal PAL_callsys;
+
+#undef PSEUDO_END_ERRVAL
+#define PSEUDO_END_ERRVAL(sym) END(sym)
+
+#define ret_ERRVAL ret
+
+#define r0 v0
+#define r1 a4
+
+#define MOVE(x,y) mov x,y
+
+#else /* !ASSEMBLER */
+
+/* ??? Linux needs to be able to override INLINE_SYSCALL for one
+ particular special case. Make this easy. */
+
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...) \
+ INLINE_SYSCALL1(name, nr, args)
+
+#define INLINE_SYSCALL1(name, nr, args...) \
+({ \
+ long _sc_ret, _sc_err; \
+ inline_syscall##nr(__NR_##name, args); \
+ if (__builtin_expect (_sc_err, 0)) \
+ { \
+ __set_errno (_sc_ret); \
+ _sc_ret = -1L; \
+ } \
+ _sc_ret; \
+})
+
+#define INTERNAL_SYSCALL(name, err_out, nr, args...) \
+ INTERNAL_SYSCALL1(name, err_out, nr, args)
+
+#define INTERNAL_SYSCALL1(name, err_out, nr, args...) \
+ INTERNAL_SYSCALL_NCS(__NR_##name, err_out, nr, args)
+
+#define INTERNAL_SYSCALL_NCS(name, err_out, nr, args...) \
+({ \
+ long _sc_ret, _sc_err; \
+ inline_syscall##nr(name, args); \
+ err_out = _sc_err; \
+ _sc_ret; \
+})
+
+#define INTERNAL_SYSCALL_DECL(err) long int err
+#define INTERNAL_SYSCALL_ERROR_P(val, err) err
+#define INTERNAL_SYSCALL_ERRNO(val, err) val
+
+#define inline_syscall_clobbers \
+ "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \
+ "$22", "$23", "$24", "$25", "$27", "$28", "memory"
+
+/* If TLS is in use, we have a conflict between the PAL_rduniq primitive,
+ as modeled within GCC, and explicit use of the R0 register. If we use
+ the register via the asm, the scheduler may place the PAL_rduniq insn
+ before we've copied the data from R0 into _sc_ret. If this happens
+ we'll get a reload abort, since R0 is live at the same time it is
+ needed for the PAL_rduniq.
+
+ Solve this by using the "v" constraint instead of an asm for the syscall
+ output. We don't do this unconditionally to allow compilation with
+ older compilers. */
+
+#ifdef HAVE___THREAD
+#define inline_syscall_r0_asm
+#define inline_syscall_r0_out_constraint "=v"
+#else
+#define inline_syscall_r0_asm __asm__("$0")
+#define inline_syscall_r0_out_constraint "=r"
+#endif
+
+/* It is moderately important optimization-wise to limit the lifetime
+ of the hard-register variables as much as possible. Thus we copy
+ in/out as close to the asm as possible. */
+
+#define inline_syscall0(name, args...) \
+{ \
+ register long _sc_0 inline_syscall_r0_asm; \
+ register long _sc_19 __asm__("$19"); \
+ \
+ _sc_0 = name; \
+ __asm__ __volatile__ \
+ ("callsys # %0 %1 <= %2" \
+ : inline_syscall_r0_out_constraint (_sc_0), \
+ "=r"(_sc_19) \
+ : "0"(_sc_0) \
+ : inline_syscall_clobbers, \
+ "$16", "$17", "$18", "$20", "$21"); \
+ _sc_ret = _sc_0, _sc_err = _sc_19; \
+}
+
+#define inline_syscall1(name,arg1) \
+{ \
+ register long _sc_0 inline_syscall_r0_asm; \
+ register long _sc_16 __asm__("$16"); \
+ register long _sc_19 __asm__("$19"); \
+ register long _tmp_16 = (long) (arg1); \
+ \
+ _sc_0 = name; \
+ _sc_16 = _tmp_16; \
+ __asm__ __volatile__ \
+ ("callsys # %0 %1 <= %2 %3" \
+ : inline_syscall_r0_out_constraint (_sc_0), \
+ "=r"(_sc_19), "=r"(_sc_16) \
+ : "0"(_sc_0), "2"(_sc_16) \
+ : inline_syscall_clobbers, \
+ "$17", "$18", "$20", "$21"); \
+ _sc_ret = _sc_0, _sc_err = _sc_19; \
+}
+
+#define inline_syscall2(name,arg1,arg2) \
+{ \
+ register long _sc_0 inline_syscall_r0_asm; \
+ register long _sc_16 __asm__("$16"); \
+ register long _sc_17 __asm__("$17"); \
+ register long _sc_19 __asm__("$19"); \
+ register long _tmp_16 = (long) (arg1); \
+ register long _tmp_17 = (long) (arg2); \
+ \
+ _sc_0 = name; \
+ _sc_16 = _tmp_16; \
+ _sc_17 = _tmp_17; \
+ __asm__ __volatile__ \
+ ("callsys # %0 %1 <= %2 %3 %4" \
+ : inline_syscall_r0_out_constraint (_sc_0), \
+ "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17) \
+ : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17) \
+ : inline_syscall_clobbers, \
+ "$18", "$20", "$21"); \
+ _sc_ret = _sc_0, _sc_err = _sc_19; \
+}
+
+#define inline_syscall3(name,arg1,arg2,arg3) \
+{ \
+ register long _sc_0 inline_syscall_r0_asm; \
+ register long _sc_16 __asm__("$16"); \
+ register long _sc_17 __asm__("$17"); \
+ register long _sc_18 __asm__("$18"); \
+ register long _sc_19 __asm__("$19"); \
+ register long _tmp_16 = (long) (arg1); \
+ register long _tmp_17 = (long) (arg2); \
+ register long _tmp_18 = (long) (arg3); \
+ \
+ _sc_0 = name; \
+ _sc_16 = _tmp_16; \
+ _sc_17 = _tmp_17; \
+ _sc_18 = _tmp_18; \
+ __asm__ __volatile__ \
+ ("callsys # %0 %1 <= %2 %3 %4 %5" \
+ : inline_syscall_r0_out_constraint (_sc_0), \
+ "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
+ "=r"(_sc_18) \
+ : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \
+ "4"(_sc_18) \
+ : inline_syscall_clobbers, "$20", "$21"); \
+ _sc_ret = _sc_0, _sc_err = _sc_19; \
+}
+
+#define inline_syscall4(name,arg1,arg2,arg3,arg4) \
+{ \
+ register long _sc_0 inline_syscall_r0_asm; \
+ register long _sc_16 __asm__("$16"); \
+ register long _sc_17 __asm__("$17"); \
+ register long _sc_18 __asm__("$18"); \
+ register long _sc_19 __asm__("$19"); \
+ register long _tmp_16 = (long) (arg1); \
+ register long _tmp_17 = (long) (arg2); \
+ register long _tmp_18 = (long) (arg3); \
+ register long _tmp_19 = (long) (arg4); \
+ \
+ _sc_0 = name; \
+ _sc_16 = _tmp_16; \
+ _sc_17 = _tmp_17; \
+ _sc_18 = _tmp_18; \
+ _sc_19 = _tmp_19; \
+ __asm__ __volatile__ \
+ ("callsys # %0 %1 <= %2 %3 %4 %5 %6" \
+ : inline_syscall_r0_out_constraint (_sc_0), \
+ "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
+ "=r"(_sc_18) \
+ : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \
+ "4"(_sc_18), "1"(_sc_19) \
+ : inline_syscall_clobbers, "$20", "$21"); \
+ _sc_ret = _sc_0, _sc_err = _sc_19; \
+}
+
+#define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5) \
+{ \
+ register long _sc_0 inline_syscall_r0_asm; \
+ register long _sc_16 __asm__("$16"); \
+ register long _sc_17 __asm__("$17"); \
+ register long _sc_18 __asm__("$18"); \
+ register long _sc_19 __asm__("$19"); \
+ register long _sc_20 __asm__("$20"); \
+ register long _tmp_16 = (long) (arg1); \
+ register long _tmp_17 = (long) (arg2); \
+ register long _tmp_18 = (long) (arg3); \
+ register long _tmp_19 = (long) (arg4); \
+ register long _tmp_20 = (long) (arg5); \
+ \
+ _sc_0 = name; \
+ _sc_16 = _tmp_16; \
+ _sc_17 = _tmp_17; \
+ _sc_18 = _tmp_18; \
+ _sc_19 = _tmp_19; \
+ _sc_20 = _tmp_20; \
+ __asm__ __volatile__ \
+ ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7" \
+ : inline_syscall_r0_out_constraint (_sc_0), \
+ "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
+ "=r"(_sc_18), "=r"(_sc_20) \
+ : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \
+ "4"(_sc_18), "1"(_sc_19), "5"(_sc_20) \
+ : inline_syscall_clobbers, "$21"); \
+ _sc_ret = _sc_0, _sc_err = _sc_19; \
+}
+
+#define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \
+{ \
+ register long _sc_0 inline_syscall_r0_asm; \
+ register long _sc_16 __asm__("$16"); \
+ register long _sc_17 __asm__("$17"); \
+ register long _sc_18 __asm__("$18"); \
+ register long _sc_19 __asm__("$19"); \
+ register long _sc_20 __asm__("$20"); \
+ register long _sc_21 __asm__("$21"); \
+ register long _tmp_16 = (long) (arg1); \
+ register long _tmp_17 = (long) (arg2); \
+ register long _tmp_18 = (long) (arg3); \
+ register long _tmp_19 = (long) (arg4); \
+ register long _tmp_20 = (long) (arg5); \
+ register long _tmp_21 = (long) (arg6); \
+ \
+ _sc_0 = name; \
+ _sc_16 = _tmp_16; \
+ _sc_17 = _tmp_17; \
+ _sc_18 = _tmp_18; \
+ _sc_19 = _tmp_19; \
+ _sc_20 = _tmp_20; \
+ _sc_21 = _tmp_21; \
+ __asm__ __volatile__ \
+ ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7 %8" \
+ : inline_syscall_r0_out_constraint (_sc_0), \
+ "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
+ "=r"(_sc_18), "=r"(_sc_20), "=r"(_sc_21) \
+ : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), "4"(_sc_18), \
+ "1"(_sc_19), "5"(_sc_20), "6"(_sc_21) \
+ : inline_syscall_clobbers); \
+ _sc_ret = _sc_0, _sc_err = _sc_19; \
+}
+
+/* Pointer mangling support. Note that tls access is slow enough that
+ we don't deoptimize things by placing the pointer check value there. */
+
+#include <stdint.h>
+
+#if defined NOT_IN_libc && defined IS_IN_rtld
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(dst, src, tmp) \
+ ldah tmp, __pointer_chk_guard_local($29) !gprelhigh; \
+ ldq tmp, __pointer_chk_guard_local(tmp) !gprellow; \
+ xor src, tmp, dst
+# define PTR_MANGLE2(dst, src, tmp) \
+ xor src, tmp, dst
+# define PTR_DEMANGLE(dst, tmp) PTR_MANGLE(dst, dst, tmp)
+# define PTR_DEMANGLE2(dst, tmp) PTR_MANGLE2(dst, dst, tmp)
+# else
+extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
+# define PTR_MANGLE(var) \
+ (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
+# define PTR_DEMANGLE(var) PTR_MANGLE(var)
+# endif
+#elif defined PIC
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(dst, src, tmp) \
+ ldq tmp, __pointer_chk_guard; \
+ xor src, tmp, dst
+# define PTR_MANGLE2(dst, src, tmp) \
+ xor src, tmp, dst
+# define PTR_DEMANGLE(dst, tmp) PTR_MANGLE(dst, dst, tmp)
+# define PTR_DEMANGLE2(dst, tmp) PTR_MANGLE2(dst, dst, tmp)
+# else
+extern uintptr_t __pointer_chk_guard attribute_relro;
+# define PTR_MANGLE(var) \
+ (var) = (void *) ((uintptr_t) (var) ^ __pointer_chk_guard)
+# define PTR_DEMANGLE(var) PTR_MANGLE(var)
+# endif
+#endif
+
+#endif /* ASSEMBLER */
diff --git a/libc/sysdeps/unix/bsd/Implies b/libc/sysdeps/unix/bsd/Implies
new file mode 100644
index 000000000..cfc44915d
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/Implies
@@ -0,0 +1,5 @@
+# The directory unix/common contains things which are common to both BSD
+# and SVR4.
+unix/common
+# The directory unix/inet implements sockets and networking in the usual way.
+unix/inet
diff --git a/libc/sysdeps/unix/bsd/bits/dirent.h b/libc/sysdeps/unix/bsd/bits/dirent.h
new file mode 100644
index 000000000..e84719712
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bits/dirent.h
@@ -0,0 +1,33 @@
+/* Directory entry structure `struct dirent'. 4.2BSD version.
+ Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _DIRENT_H
+# error "Never use <bits/dirent.h> directly; include <dirent.h> instead."
+#endif
+
+struct dirent
+ {
+ unsigned int d_fileno; /* 32 bits. */
+ unsigned short int d_reclen; /* 16 bits. */
+ unsigned short int d_namlen; /* 16 bits. */
+ char d_name[1]; /* Variable length. */
+ };
+
+#define _DIRENT_HAVE_D_RECLEN 1
+#define _DIRENT_HAVE_D_NAMLEN 1
diff --git a/libc/sysdeps/unix/bsd/bits/fcntl.h b/libc/sysdeps/unix/bsd/bits/fcntl.h
new file mode 100644
index 000000000..c992f93ef
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bits/fcntl.h
@@ -0,0 +1,139 @@
+/* O_*, F_*, FD_* bit values for 4.3 BSD.
+ Copyright (C) 1991, 1992, 1997, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+
+/* File access modes for `open' and `fcntl'. */
+#define O_RDONLY 0 /* Open read-only. */
+#define O_WRONLY 1 /* Open write-only. */
+#define O_RDWR 2 /* Open read/write. */
+
+
+/* Bits OR'd into the second argument to open. */
+#define O_CREAT 0x0200 /* Create file if it doesn't exist. */
+#define O_EXCL 0x0800 /* Fail if file already exists. */
+#define O_TRUNC 0x0400 /* Truncate file to zero length. */
+/* Apparently not assigning a controlling terminal is the default
+ behavior in BSD, so no bit is required to request that behavior. */
+#define O_NOCTTY 0 /* Don't assign a controlling terminal. */
+#if defined __USE_BSD || defined __USE_SVID
+# define O_ASYNC 0x0040 /* Send SIGIO to owner when data is ready. */
+# define O_FSYNC 0x2000 /* Synchronous writes. */
+# define O_SYNC O_FSYNC
+#endif
+
+/* File status flags for `open' and `fcntl'. */
+#define O_APPEND 0x0008 /* Writes append to the file. */
+#define O_NONBLOCK 0x0004 /* Non-blocking I/O. */
+
+#ifdef __USE_BSD
+/* BSD before 4.4 doesn't support POSIX.1 O_NONBLOCK,
+ but O_NDELAY is close. */
+# define O_NDELAY O_NONBLOCK
+#endif
+
+#ifdef __USE_BSD
+/* Bits in the file status flags returned by F_GETFL.
+ These are all the O_* flags, plus FREAD and FWRITE, which are
+ independent bits set by which of O_RDONLY, O_WRONLY, and O_RDWR, was
+ given to `open'. */
+# define FREAD 1
+# define FWRITE 2
+
+/* Traditional BSD names the O_* bits. */
+# define FASYNC O_ASYNC
+# define FCREAT O_CREAT
+# define FEXCL O_EXCL
+# define FTRUNC O_TRUNC
+# define FNOCTTY O_NOCTTY
+# define FFSYNC O_FSYNC
+# define FSYNC O_SYNC
+# define FAPPEND O_APPEND
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif
+
+/* Mask for file access modes. This is system-dependent in case
+ some system ever wants to define some other flavor of access. */
+#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
+
+/* XXX missing */
+#define O_LARGEFILE 0
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#if defined __USE_BSD || defined __USE_UNIX98
+# define F_GETOWN 5 /* Get owner (receiver of SIGIO). */
+# define F_SETOWN 6 /* Set owner (receiver of SIGIO). */
+#endif
+#define F_GETLK 7 /* Get record locking info. */
+#define F_SETLK 8 /* Set record locking info (non-blocking). */
+#define F_SETLKW 9 /* Set record locking info (blocking). */
+
+/* XXX missing */
+#define F_GETLK64 7 /* Get record locking info. */
+#define F_SETLK64 8 /* Set record locking info (non-blocking). */
+#define F_SETLKW64 9 /* Set record locking info (blocking). */
+
+/* File descriptor flags used with F_GETFD and F_SETFD. */
+#define FD_CLOEXEC 1 /* Close on exec. */
+
+
+#include <bits/types.h>
+
+/* The structure describing an advisory lock. This is the type of the third
+ argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests. */
+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
+ short int l_pid; /* Process holding the lock. */
+ short int l_xxx; /* Reserved for future use. */
+ };
+
+#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. */
+ short int l_pid; /* Process holding the lock. */
+ short int l_xxx; /* Reserved for future use. */
+ };
+#endif
+
+/* Values for the `l_type' field of a `struct flock'. */
+#define F_RDLCK 1 /* Read lock. */
+#define F_WRLCK 2 /* Write lock. */
+#define F_UNLCK 3 /* Remove lock. */
diff --git a/libc/sysdeps/unix/bsd/bits/posix_opt.h b/libc/sysdeps/unix/bsd/bits/posix_opt.h
new file mode 100644
index 000000000..7d5e5782e
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bits/posix_opt.h
@@ -0,0 +1,5 @@
+#define _POSIX_JOB_CONTROL 1
+#undef _POSIX_SAVED_IDS
+#define _POSIX_CHOWN_RESTRICTED 1
+#define _POSIX_NO_TRUNC -1
+#define _POSIX_VDISABLE ((unsigned char) -1)
diff --git a/libc/sysdeps/unix/bsd/bits/signum.h b/libc/sysdeps/unix/bsd/bits/signum.h
new file mode 100644
index 000000000..ce7d4682d
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bits/signum.h
@@ -0,0 +1,74 @@
+/* Signal number definitions. BSD version.
+ Copyright (C) 1991, 1992, 1993, 1996, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifdef _SIGNAL_H
+
+/* This file defines the fake signal functions and signal
+ number constants for 4.2 or 4.3 BSD-derived Unix system. */
+
+/* Fake signal functions. */
+#define SIG_ERR ((__sighandler_t) -1) /* Error return. */
+#define SIG_DFL ((__sighandler_t) 0) /* Default action. */
+#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */
+
+#ifdef __USE_UNIX98
+# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */
+#endif
+
+
+/* Signals. */
+#define SIGHUP 1 /* Hangup (POSIX). */
+#define SIGINT 2 /* Interrupt (ANSI). */
+#define SIGQUIT 3 /* Quit (POSIX). */
+#define SIGILL 4 /* Illegal instruction (ANSI). */
+#define SIGABRT SIGIOT /* Abort (ANSI). */
+#define SIGTRAP 5 /* Trace trap (POSIX). */
+#define SIGIOT 6 /* IOT trap (4.2 BSD). */
+#define SIGEMT 7 /* EMT trap (4.2 BSD). */
+#define SIGFPE 8 /* Floating-point exception (ANSI). */
+#define SIGKILL 9 /* Kill, unblockable (POSIX). */
+#define SIGBUS 10 /* Bus error (4.2 BSD). */
+#define SIGSEGV 11 /* Segmentation violation (ANSI). */
+#define SIGSYS 12 /* Bad argument to system call (4.2 BSD). */
+#define SIGPIPE 13 /* Broken pipe (POSIX). */
+#define SIGALRM 14 /* Alarm clock (POSIX). */
+#define SIGTERM 15 /* Termination (ANSI). */
+#define SIGURG 16 /* Urgent condition on socket (4.2 BSD). */
+#define SIGSTOP 17 /* Stop, unblockable (POSIX). */
+#define SIGTSTP 18 /* Keyboard stop (POSIX). */
+#define SIGCONT 19 /* Continue (POSIX). */
+#define SIGCHLD 20 /* Child status has changed (POSIX). */
+#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */
+#define SIGTTIN 21 /* Background read from tty (POSIX). */
+#define SIGTTOU 22 /* Background write to tty (POSIX). */
+#define SIGIO 23 /* I/O now possible (4.2 BSD). */
+#define SIGPOLL SIGIO /* Same as SIGIO? (SVID). */
+#define SIGXCPU 24 /* CPU limit exceeded (4.2 BSD). */
+#define SIGXFSZ 25 /* File size limit exceeded (4.2 BSD). */
+#define SIGVTALRM 26 /* Virtual alarm clock (4.2 BSD). */
+#define SIGPROF 27 /* Profiling alarm clock (4.2 BSD). */
+#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */
+#define SIGINFO 29 /* Information request (4.4 BSD). */
+#define SIGUSR1 30 /* User-defined signal 1 (POSIX). */
+#define SIGUSR2 31 /* User-defined signal 2 (POSIX). */
+#define SIGLOST 32 /* Resource lost (Sun); server died (GNU). */
+
+#endif /* <signal.h> included. */
+
+#define _NSIG 33 /* Biggest signal number + 1. */
diff --git a/libc/sysdeps/unix/bsd/bits/stat.h b/libc/sysdeps/unix/bsd/bits/stat.h
new file mode 100644
index 000000000..84a58ffbc
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bits/stat.h
@@ -0,0 +1,86 @@
+/* Copyright (C) 1991, 92, 96, 97, 99, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STAT_H
+# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Structure describing file characteristics. */
+struct stat
+ {
+ /* This is a short instead of dev_t for compatibility with 4.3. */
+ short int st_dev; /* Device containing the file. */
+ __ino_t st_ino; /* File serial number. */
+
+ /* This is a short instead of mode_t for compatibility with 4.3. */
+ unsigned short int st_mode; /* File mode. */
+
+ __nlink_t st_nlink; /* Link count. */
+
+ /* These are shorts instead of uid_t/gid_t for compatibility with 4.3. */
+ unsigned short int st_uid; /* User ID of the file's owner. */
+ unsigned short int st_gid; /* Group ID of the file's group.*/
+
+ /* This is a short instead of dev_t for compatibility with 4.3. */
+ short int st_rdev; /* Device number, if device. */
+
+ __off_t st_size; /* Size of file, in bytes. */
+
+ __time_t st_atime; /* Time of last access. */
+ unsigned long int st_atime_usec;
+ __time_t st_mtime; /* Time of last modification. */
+ unsigned long int st_mtime_usec;
+ __time_t st_ctime; /* Time of last status change. */
+ unsigned long int st_ctime_usec;
+
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+#define _STATBUF_ST_BLKSIZE /* Tell code we have this member. */
+
+ __blkcnt_t st_blocks; /* Number of 512-byte blocks allocated. */
+
+ long int st_spare[2];
+ };
+
+/* 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_IFLNK 0120000 /* Symbolic link. */
+#define __S_IFSOCK 0140000 /* Socket. */
+#define __S_IFIFO 0010000 /* FIFO. */
+
+/* POSIX.1b objects. */
+#define __S_TYPEISMQ(buf) (0)
+#define __S_TYPEISSEM(buf) (0)
+#define __S_TYPEISSHM(buf) (0)
+
+/* 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. */
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/Implies b/libc/sysdeps/unix/bsd/bsd4.4/Implies
new file mode 100644
index 000000000..3bdab5444
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/Implies
@@ -0,0 +1,2 @@
+# 4.4 BSD has the canonical set of <sys/mman.h> system calls.
+unix/mman
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/Makefile b/libc/sysdeps/unix/bsd/bsd4.4/Makefile
new file mode 100644
index 000000000..208fd2448
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/Makefile
@@ -0,0 +1,3 @@
+ifeq ($(subdir),socket)
+sysdep_routines += cmsg_nxthdr
+endif
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/Versions b/libc/sysdeps/unix/bsd/bsd4.4/Versions
new file mode 100644
index 000000000..99b386b67
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/Versions
@@ -0,0 +1,6 @@
+libc {
+ GLIBC_2.2.5 {
+ # functions used in inline functions or macros
+ __cmsg_nxthdr;
+ }
+}
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/bits/dirent.h b/libc/sysdeps/unix/bsd/bsd4.4/bits/dirent.h
new file mode 100644
index 000000000..3f8990cb5
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/bits/dirent.h
@@ -0,0 +1,55 @@
+/* Directory entry structure `struct dirent'. 4.4BSD version.
+ Copyright (C) 1996,97,98,2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _DIRENT_H
+# error "Never use <bits/dirent.h> directly; include <dirent.h> instead."
+#endif
+
+struct dirent
+ {
+#ifndef __USE_FILE_OFFSET64
+ __ino_t d_ino; /* File serial number. */
+#else
+ __ino64_t d_ino;
+#endif
+ unsigned short int d_reclen; /* Length of the whole `struct dirent'. */
+ unsigned char d_type; /* File type, possibly unknown. */
+ unsigned char d_namlen; /* Length of the file name. */
+
+ /* Only this member is in the POSIX standard. */
+ char d_name[1]; /* File name (actually longer). */
+ };
+
+#ifdef __USE_LARGEFILE64
+struct dirent64
+ {
+ __ino64_t d_ino;
+ unsigned short int d_reclen;
+ unsigned char d_type;
+ unsigned char d_namlen;
+
+ char d_name[1];
+ };
+#endif
+
+#define d_fileno d_ino /* Backwards compatibility. */
+
+#define _DIRENT_HAVE_D_RECLEN 1
+#define _DIRENT_HAVE_D_NAMLEN 1
+#define _DIRENT_HAVE_D_TYPE 1
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/bits/errno.h b/libc/sysdeps/unix/bsd/bsd4.4/bits/errno.h
new file mode 100644
index 000000000..48b1c8b6e
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/bits/errno.h
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)errno.h 8.5 (Berkeley) 1/21/94
+ */
+
+#ifdef _ERRNO_H
+
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* Input/output error */
+#define ENXIO 6 /* Device not configured */
+#define E2BIG 7 /* Argument list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file descriptor */
+#define ECHILD 10 /* No child processes */
+#define EDEADLK 11 /* Resource deadlock avoided */
+ /* 11 was EAGAIN */
+#define ENOMEM 12 /* Cannot allocate memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#ifdef __USE_BSD
+#define ENOTBLK 15 /* Block device required */
+#endif
+#define EBUSY 16 /* Device busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* Operation not supported by device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* Too many open files in system */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Inappropriate ioctl for device */
+#ifdef __USE_BSD
+#define ETXTBSY 26 /* Text file busy */
+#endif
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read-only file system */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+
+#endif /* <errno.h> included. */
+
+/* math software */
+
+#if !defined(__Emath_defined) && (defined(_ERRNO_H) || defined(__need_Emath))
+#define EDOM 33 /* Numerical argument out of domain */
+#endif /* Emath not defined and <errno.h> included or need Emath. */
+#if !defined(__Emath_defined) && (defined(_ERRNO_H) || defined(__need_Emath))
+#define ERANGE 34 /* Result too large */
+#endif /* Emath not defined and <errno.h> included or need Emath. */
+
+#ifdef _ERRNO_H
+
+/* non-blocking and interrupt i/o */
+#define EAGAIN 35 /* Resource temporarily unavailable */
+#ifdef __USE_BSD
+#define EWOULDBLOCK EAGAIN /* Operation would block */
+#define EINPROGRESS 36 /* Operation now in progress */
+#define EALREADY 37 /* Operation already in progress */
+
+/* ipc/network software -- argument errors */
+#define ENOTSOCK 38 /* Socket operation on non-socket */
+#define EDESTADDRREQ 39 /* Destination address required */
+#define EMSGSIZE 40 /* Message too long */
+#define EPROTOTYPE 41 /* Protocol wrong type for socket */
+#define ENOPROTOOPT 42 /* Protocol not available */
+#define EPROTONOSUPPORT 43 /* Protocol not supported */
+#define ESOCKTNOSUPPORT 44 /* Socket type not supported */
+#define EOPNOTSUPP 45 /* Operation not supported */
+#define EPFNOSUPPORT 46 /* Protocol family not supported */
+#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */
+#define EADDRINUSE 48 /* Address already in use */
+#define EADDRNOTAVAIL 49 /* Can't assign requested address */
+
+/* ipc/network software -- operational errors */
+#define ENETDOWN 50 /* Network is down */
+#define ENETUNREACH 51 /* Network is unreachable */
+#define ENETRESET 52 /* Network dropped connection on reset */
+#define ECONNABORTED 53 /* Software caused connection abort */
+#define ECONNRESET 54 /* Connection reset by peer */
+#define ENOBUFS 55 /* No buffer space available */
+#define EISCONN 56 /* Socket is already connected */
+#define ENOTCONN 57 /* Socket is not connected */
+#define ESHUTDOWN 58 /* Can't send after socket shutdown */
+#define ETOOMANYREFS 59 /* Too many references: can't splice */
+#define ETIMEDOUT 60 /* Operation timed out */
+#define ECONNREFUSED 61 /* Connection refused */
+
+#define ELOOP 62 /* Too many levels of symbolic links */
+#endif /* __USE_BSD */
+#define ENAMETOOLONG 63 /* File name too long */
+
+/* should be rearranged */
+#ifdef __USE_BSD
+#define EHOSTDOWN 64 /* Host is down */
+#define EHOSTUNREACH 65 /* No route to host */
+#endif /* __USE_BSD */
+#define ENOTEMPTY 66 /* Directory not empty */
+
+/* quotas & mush */
+#ifdef __USE_BSD
+#define EPROCLIM 67 /* Too many processes */
+#define EUSERS 68 /* Too many users */
+#define EDQUOT 69 /* Disc quota exceeded */
+
+/* Network File System */
+#define ESTALE 70 /* Stale NFS file handle */
+#define EREMOTE 71 /* Too many levels of remote in path */
+#define EBADRPC 72 /* RPC struct is bad */
+#define ERPCMISMATCH 73 /* RPC version wrong */
+#define EPROGUNAVAIL 74 /* RPC prog. not avail */
+#define EPROGMISMATCH 75 /* Program version wrong */
+#define EPROCUNAVAIL 76 /* Bad procedure for program */
+#endif /* __USE_BSD */
+
+#define ENOLCK 77 /* No locks available */
+#define ENOSYS 78 /* Function not implemented */
+
+#define EFTYPE 79 /* Inappropriate file type or format */
+
+#ifdef __USE_BSD
+#define EAUTH 80 /* Authentication error */
+#define ENEEDAUTH 81 /* Need authenticator */
+#define ELAST 81 /* Must be equal largest errno */
+#endif /* __USE_BSD */
+
+
+#endif /* <errno.h> included. */
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/bits/fcntl.h b/libc/sysdeps/unix/bsd/bsd4.4/bits/fcntl.h
new file mode 100644
index 000000000..47a67e38e
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/bits/fcntl.h
@@ -0,0 +1,113 @@
+/* O_*, F_*, FD_* bit values for 4.4 BSD.
+ Copyright (C) 1991, 1992, 1997, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+#error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+
+/* File access modes for `open' and `fcntl'. */
+#define O_RDONLY 0 /* Open read-only. */
+#define O_WRONLY 1 /* Open write-only. */
+#define O_RDWR 2 /* Open read/write. */
+
+
+/* Bits OR'd into the second argument to open. */
+#define O_CREAT 0x0200 /* Create file if it doesn't exist. */
+#define O_EXCL 0x0800 /* Fail if file already exists. */
+#define O_TRUNC 0x0400 /* Truncate file to zero length. */
+/* Apparently not assigning a controlling terminal is the default
+ behavior in BSD, so no bit is required to request that behavior. */
+#define O_NOCTTY 0 /* Don't assign a controlling terminal. */
+#ifdef __USE_MISC
+#define O_ASYNC 0x0040 /* Send SIGIO to owner when data is ready. */
+#define O_FSYNC 0x0080 /* Synchronous writes. */
+#define O_SYNC O_FSYNC
+#define O_SHLOCK 0x0010 /* Open with shared file lock. */
+#define O_EXLOCK 0x0020 /* Open with shared exclusive lock. */
+#endif
+
+/* File status flags for `open' and `fcntl'. */
+#define O_APPEND 0x0008 /* Writes append to the file. */
+#define O_NONBLOCK 0x0004 /* Non-blocking I/O. */
+
+#ifdef __USE_BSD
+#define O_NDELAY O_NONBLOCK
+#endif
+
+#ifdef __USE_BSD
+/* Bits in the file status flags returned by F_GETFL.
+ These are all the O_* flags, plus FREAD and FWRITE, which are
+ independent bits set by which of O_RDONLY, O_WRONLY, and O_RDWR, was
+ given to `open'. */
+#define FREAD 1
+#define FWRITE 2
+
+/* Traditional BSD names the O_* bits. */
+#define FASYNC O_ASYNC
+#define FCREAT O_CREAT
+#define FEXCL O_EXCL
+#define FTRUNC O_TRUNC
+#define FNOCTTY O_NOCTTY
+#define FFSYNC O_FSYNC
+#define FSYNC O_SYNC
+#define FAPPEND O_APPEND
+#define FNONBLOCK O_NONBLOCK
+#define FNDELAY O_NDELAY
+#endif
+
+/* Mask for file access modes. This is system-dependent in case
+ some system ever wants to define some other flavor of access. */
+#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#if defined __USE_BSD || defined __USE_UNIX98
+#define F_GETOWN 5 /* Get owner (receiver of SIGIO). */
+#define F_SETOWN 6 /* Set owner (receiver of SIGIO). */
+#endif
+#define F_GETLK 7 /* Get record locking info. */
+#define F_SETLK 8 /* Set record locking info (non-blocking). */
+#define F_SETLKW 9 /* Set record locking info (blocking). */
+
+/* File descriptor flags used with F_GETFD and F_SETFD. */
+#define FD_CLOEXEC 1 /* Close on exec. */
+
+
+#include <bits/types.h>
+
+/* The structure describing an advisory lock. This is the type of the third
+ argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests. */
+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'). */
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+ short int l_pid; /* Process holding the lock. */
+ };
+
+/* Values for the `l_type' field of a `struct flock'. */
+#define F_RDLCK 1 /* Read lock. */
+#define F_WRLCK 2 /* Write lock. */
+#define F_UNLCK 3 /* Remove lock. */
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/bits/ioctls.h b/libc/sysdeps/unix/bsd/bsd4.4/bits/ioctls.h
new file mode 100644
index 000000000..526bfd090
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/bits/ioctls.h
@@ -0,0 +1,288 @@
+/*-
+ * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ioctl.h 7.19 (Berkeley) 6/26/91
+ */
+
+#ifndef _IOCTLS_H_
+#define _IOCTLS_H_
+
+#define TIOCGSIZE TIOCGWINSZ
+#define TIOCSSIZE TIOCSWINSZ
+
+/*
+ * Ioctl's have the command encoded in the lower word, and the size of
+ * any in or out parameters in the upper word. The high 3 bits of the
+ * upper word are used to encode the in/out status of the parameter.
+ */
+#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */
+#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
+#define IOCBASECMD(x) ((x) & ~IOCPARM_MASK)
+#define IOCGROUP(x) (((x) >> 8) & 0xff)
+
+#define IOCPARM_MAX NBPG /* max size of ioctl, mult. of NBPG */
+#define IOC_VOID 0x20000000 /* no parameters */
+#define IOC_OUT 0x40000000 /* copy out parameters */
+#define IOC_IN 0x80000000 /* copy in parameters */
+#define IOC_INOUT (IOC_IN|IOC_OUT)
+#define IOC_DIRMASK 0xe0000000 /* mask for IN/OUT/VOID */
+
+#define _IOC(inout,group,num,len) \
+ (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
+#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0)
+#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t))
+#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t))
+/* this should be _IORW, but stdio got there first */
+#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t))
+
+#define TIOCMODG _IOR('t', 3, int) /* get modem control state */
+#define TIOCMODS _IOW('t', 4, int) /* set modem control state */
+#define TIOCM_LE 0001 /* line enable */
+#define TIOCM_DTR 0002 /* data terminal ready */
+#define TIOCM_RTS 0004 /* request to send */
+#define TIOCM_ST 0010 /* secondary transmit */
+#define TIOCM_SR 0020 /* secondary receive */
+#define TIOCM_CTS 0040 /* clear to send */
+#define TIOCM_CAR 0100 /* carrier detect */
+#define TIOCM_CD TIOCM_CAR
+#define TIOCM_RNG 0200 /* ring */
+#define TIOCM_RI TIOCM_RNG
+#define TIOCM_DSR 0400 /* data set ready */
+ /* 8-10 compat */
+#define TIOCEXCL _IO('t', 13) /* set exclusive use of tty */
+#define TIOCNXCL _IO('t', 14) /* reset exclusive use of tty */
+ /* 15 unused */
+#define TIOCFLUSH _IOW('t', 16, int) /* flush buffers */
+ /* 17-18 compat */
+#define TIOCGETA _IOR('t', 19, struct termios) /* get termios struct */
+#define TIOCSETA _IOW('t', 20, struct termios) /* set termios struct */
+#define TIOCSETAW _IOW('t', 21, struct termios) /* drain output, set */
+#define TIOCSETAF _IOW('t', 22, struct termios) /* drn out, fls in, set */
+#define TIOCGETD _IOR('t', 26, int) /* get line discipline */
+#define TIOCSETD _IOW('t', 27, int) /* set line discipline */
+ /* 127-124 compat */
+#define TIOCSBRK _IO('t', 123) /* set break bit */
+#define TIOCCBRK _IO('t', 122) /* clear break bit */
+#define TIOCSDTR _IO('t', 121) /* set data terminal ready */
+#define TIOCCDTR _IO('t', 120) /* clear data terminal ready */
+#define TIOCGPGRP _IOR('t', 119, int) /* get pgrp of tty */
+#define TIOCSPGRP _IOW('t', 118, int) /* set pgrp of tty */
+ /* 117-116 compat */
+#define TIOCOUTQ _IOR('t', 115, int) /* output queue size */
+#define TIOCSTI _IOW('t', 114, char) /* simulate terminal input */
+#define TIOCNOTTY _IO('t', 113) /* void tty association */
+#define TIOCPKT _IOW('t', 112, int) /* pty: set/clear packet mode */
+#define TIOCPKT_DATA 0x00 /* data packet */
+#define TIOCPKT_FLUSHREAD 0x01 /* flush packet */
+#define TIOCPKT_FLUSHWRITE 0x02 /* flush packet */
+#define TIOCPKT_STOP 0x04 /* stop output */
+#define TIOCPKT_START 0x08 /* start output */
+#define TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */
+#define TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */
+#define TIOCPKT_IOCTL 0x40 /* state change of pty driver */
+#define TIOCSTOP _IO('t', 111) /* stop output, like ^S */
+#define TIOCSTART _IO('t', 110) /* start output, like ^Q */
+#define TIOCMSET _IOW('t', 109, int) /* set all modem bits */
+#define TIOCMBIS _IOW('t', 108, int) /* bis modem bits */
+#define TIOCMBIC _IOW('t', 107, int) /* bic modem bits */
+#define TIOCMGET _IOR('t', 106, int) /* get all modem bits */
+#define TIOCREMOTE _IOW('t', 105, int) /* remote input editing */
+#define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */
+#define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */
+#define TIOCUCNTL _IOW('t', 102, int) /* pty: set/clr usr cntl mode */
+#define UIOCCMD(n) _IO('u', n) /* usr cntl op "n" */
+#define TIOCCONS _IOW('t', 98, int) /* become virtual console */
+#define TIOCSCTTY _IO('t', 97) /* become controlling tty */
+#define TIOCEXT _IOW('t', 96, int) /* pty: external processing */
+#define TIOCSIG _IO('t', 95) /* pty: generate signal */
+#define TIOCDRAIN _IO('t', 94) /* wait till output drained */
+
+#define TTYDISC 0 /* termios tty line discipline */
+#define TABLDISC 3 /* tablet discipline */
+#define SLIPDISC 4 /* serial IP discipline */
+
+
+#define FIOCLEX _IO('f', 1) /* set close on exec on fd */
+#define FIONCLEX _IO('f', 2) /* remove close on exec */
+#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
+#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
+#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */
+#define FIOSETOWN _IOW('f', 124, int) /* set owner */
+#define FIOGETOWN _IOR('f', 123, int) /* get owner */
+
+/* socket i/o controls */
+#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */
+#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */
+#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */
+#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */
+#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */
+#define SIOCSPGRP _IOW('s', 8, int) /* set process group */
+#define SIOCGPGRP _IOR('s', 9, int) /* get process group */
+
+#define SIOCADDRT _IOW('r', 10, struct ortentry) /* add route */
+#define SIOCDELRT _IOW('r', 11, struct ortentry) /* delete route */
+
+#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */
+#define OSIOCGIFADDR _IOWR('i',13, struct ifreq) /* get ifnet address */
+#define SIOCGIFADDR _IOWR('i',33, struct ifreq) /* get ifnet address */
+#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */
+#define OSIOCGIFDSTADDR _IOWR('i',15, struct ifreq) /* get p-p address */
+#define SIOCGIFDSTADDR _IOWR('i',34, struct ifreq) /* get p-p address */
+#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */
+#define SIOCGIFFLAGS _IOWR('i',17, struct ifreq) /* get ifnet flags */
+#define OSIOCGIFBRDADDR _IOWR('i',18, struct ifreq) /* get broadcast addr */
+#define SIOCGIFBRDADDR _IOWR('i',35, struct ifreq) /* get broadcast addr */
+#define SIOCSIFBRDADDR _IOW('i',19, struct ifreq) /* set broadcast addr */
+#define OSIOCGIFCONF _IOWR('i',20, struct ifconf) /* get ifnet list */
+#define SIOCGIFCONF _IOWR('i',36, struct ifconf) /* get ifnet list */
+#define OSIOCGIFNETMASK _IOWR('i',21, struct ifreq) /* get net addr mask */
+#define SIOCGIFNETMASK _IOWR('i',37, struct ifreq) /* get net addr mask */
+#define SIOCSIFNETMASK _IOW('i',22, struct ifreq) /* set net addr mask */
+#define SIOCGIFMETRIC _IOWR('i',23, struct ifreq) /* get IF metric */
+#define SIOCSIFMETRIC _IOW('i',24, struct ifreq) /* set IF metric */
+#define SIOCDIFADDR _IOW('i',25, struct ifreq) /* delete IF addr */
+#define SIOCAIFADDR _IOW('i',26, struct ifaliasreq) /* add/chg IF alias */
+
+#define SIOCSARP _IOW('i', 30, struct arpreq) /* set arp entry */
+#define OSIOCGARP _IOWR('i',31, struct arpreq) /* get arp entry */
+#define SIOCGARP _IOWR('i',38, struct arpreq) /* get arp entry */
+#define SIOCDARP _IOW('i', 32, struct arpreq) /* delete arp entry */
+
+
+/* Compatibility with 4.3 BSD terminal driver.
+ From 4.4 <sys/ioctl_compat.h>. */
+
+#ifdef USE_OLD_TTY
+# undef TIOCGETD
+# define TIOCGETD _IOR('t', 0, int) /* get line discipline */
+# undef TIOCSETD
+# define TIOCSETD _IOW('t', 1, int) /* set line discipline */
+#else
+# define OTIOCGETD _IOR('t', 0, int) /* get line discipline */
+# define OTIOCSETD _IOW('t', 1, int) /* set line discipline */
+#endif
+#define TIOCHPCL _IO('t', 2) /* hang up on last close */
+#define TIOCGETP _IOR('t', 8,struct sgttyb)/* get parameters -- gtty */
+#define TIOCSETP _IOW('t', 9,struct sgttyb)/* set parameters -- stty */
+#define TIOCSETN _IOW('t',10,struct sgttyb)/* as above, but no flushtty*/
+#define TIOCSETC _IOW('t',17,struct tchars)/* set special characters */
+#define TIOCGETC _IOR('t',18,struct tchars)/* get special characters */
+#define TANDEM 0x00000001 /* send stopc on out q full */
+#define CBREAK 0x00000002 /* half-cooked mode */
+#define LCASE 0x00000004 /* simulate lower case */
+#define ECHO 0x00000008 /* echo input */
+#define CRMOD 0x00000010 /* map \r to \r\n on output */
+#define RAW 0x00000020 /* no i/o processing */
+#define ODDP 0x00000040 /* get/send odd parity */
+#define EVENP 0x00000080 /* get/send even parity */
+#define ANYP 0x000000c0 /* get any parity/send none */
+#define NLDELAY 0x00000300 /* \n delay */
+#define NL0 0x00000000
+#define NL1 0x00000100 /* tty 37 */
+#define NL2 0x00000200 /* vt05 */
+#define NL3 0x00000300
+#define TBDELAY 0x00000c00 /* horizontal tab delay */
+#define TAB0 0x00000000
+#define TAB1 0x00000400 /* tty 37 */
+#define TAB2 0x00000800
+#define XTABS 0x00000c00 /* expand tabs on output */
+#define CRDELAY 0x00003000 /* \r delay */
+#define CR0 0x00000000
+#define CR1 0x00001000 /* tn 300 */
+#define CR2 0x00002000 /* tty 37 */
+#define CR3 0x00003000 /* concept 100 */
+#define VTDELAY 0x00004000 /* vertical tab delay */
+#define FF0 0x00000000
+#define FF1 0x00004000 /* tty 37 */
+#define BSDELAY 0x00008000 /* \b delay */
+#define BS0 0x00000000
+#define BS1 0x00008000
+#define ALLDELAY (NLDELAY|TBDELAY|CRDELAY|VTDELAY|BSDELAY)
+#define CRTBS 0x00010000 /* do backspacing for crt */
+#define PRTERA 0x00020000 /* \ ... / erase */
+#define CRTERA 0x00040000 /* " \b " to wipe out char */
+#define TILDE 0x00080000 /* hazeltine tilde kludge */
+#define MDMBUF 0x00100000 /*start/stop output on carrier*/
+#define LITOUT 0x00200000 /* literal output */
+#define TOSTOP 0x00400000 /*SIGSTOP on background output*/
+#define FLUSHO 0x00800000 /* flush output to terminal */
+#define NOHANG 0x01000000 /* (no-op) was no SIGHUP on carrier drop */
+#define L001000 0x02000000
+#define CRTKIL 0x04000000 /* kill line with " \b " */
+#define PASS8 0x08000000
+#define CTLECH 0x10000000 /* echo control chars as ^X */
+#define PENDIN 0x20000000 /* tp->t_rawq needs reread */
+#define DECCTQ 0x40000000 /* only ^Q starts after ^S */
+#define NOFLSH 0x80000000 /* no output flush on signal */
+#define TIOCLBIS _IOW('t', 127, int) /* bis local mode bits */
+#define TIOCLBIC _IOW('t', 126, int) /* bic local mode bits */
+#define TIOCLSET _IOW('t', 125, int) /* set entire local mode word */
+#define TIOCLGET _IOR('t', 124, int) /* get local modes */
+#define LCRTBS (CRTBS>>16)
+#define LPRTERA (PRTERA>>16)
+#define LCRTERA (CRTERA>>16)
+#define LTILDE (TILDE>>16)
+#define LMDMBUF (MDMBUF>>16)
+#define LLITOUT (LITOUT>>16)
+#define LTOSTOP (TOSTOP>>16)
+#define LFLUSHO (FLUSHO>>16)
+#define LNOHANG (NOHANG>>16)
+#define LCRTKIL (CRTKIL>>16)
+#define LPASS8 (PASS8>>16)
+#define LCTLECH (CTLECH>>16)
+#define LPENDIN (PENDIN>>16)
+#define LDECCTQ (DECCTQ>>16)
+#define LNOFLSH (NOFLSH>>16)
+#define TIOCSLTC _IOW('t',117,struct ltchars)/* set local special chars*/
+#define TIOCGLTC _IOR('t',116,struct ltchars)/* get local special chars*/
+#define OTIOCCONS _IO('t', 98) /* for hp300 -- sans int arg */
+#define OTTYDISC 0
+#define NETLDISC 1
+#define NTTYDISC 2
+
+/* From 4.4 <sys/ttydev.h>. */
+#ifdef USE_OLD_TTY
+#define B0 0
+#define B50 1
+#define B75 2
+#define B110 3
+#define B134 4
+#define B150 5
+#define B200 6
+#define B300 7
+#define B600 8
+#define B1200 9
+#define B1800 10
+#define B2400 11
+#define B4800 12
+#define B9600 13
+#define EXTA 14
+#define EXTB 15
+#endif /* USE_OLD_TTY */
+
+#endif /* !_IOCTLS_H_ */
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/bits/sockaddr.h b/libc/sysdeps/unix/bsd/bsd4.4/bits/sockaddr.h
new file mode 100644
index 000000000..934548875
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/bits/sockaddr.h
@@ -0,0 +1,43 @@
+/* Definition of `struct sockaddr_*' common members. 4.4 BSD version.
+ Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/*
+ * Never include this file directly; use <sys/socket.h> instead.
+ */
+
+#ifndef _BITS_SOCKADDR_H
+#define _BITS_SOCKADDR_H 1
+
+
+/* POSIX.1g specifies this type name for the `sa_family' member. */
+typedef unsigned char sa_family_t;
+
+/* This macro is used to declare the initial common members
+ of the data types used for socket addresses, `struct sockaddr',
+ `struct sockaddr_in', `struct sockaddr_un', etc. */
+
+#define __SOCKADDR_COMMON(sa_prefix) \
+ unsigned char sa_prefix##len; \
+ sa_family_t sa_prefix##family
+
+#define __SOCKADDR_COMMON_SIZE (2 * sizeof (unsigned char))
+
+#define _HAVE_SA_LEN 1 /* We have the sa_len field. */
+
+#endif /* bits/sockaddr.h */
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/bits/socket.h b/libc/sysdeps/unix/bsd/bsd4.4/bits/socket.h
new file mode 100644
index 000000000..b2227f10d
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/bits/socket.h
@@ -0,0 +1,341 @@
+/* System-specific socket constants and types. 4.4 BSD version.
+ Copyright (C) 1991,92,1994-2002,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef __BITS_SOCKET_H
+#define __BITS_SOCKET_H 1
+
+#if !defined _SYS_SOCKET_H && !defined _NETINET_IN_H
+# error "Never include <bits/socket.h> directly; use <sys/socket.h> instead."
+#endif
+
+#define __need_size_t
+#define __need_NULL
+#include <stddef.h>
+
+#include <limits.h> /* XXX Is this allowed? */
+#include <bits/types.h>
+
+/* Type for length arguments in socket calls. */
+#ifndef __socklen_t_defined
+typedef __socklen_t socklen_t;
+# define __socklen_t_defined
+#endif
+
+
+/* Types of sockets. */
+enum __socket_type
+{
+ SOCK_STREAM = 1, /* Sequenced, reliable, connection-based
+ byte streams. */
+#define SOCK_STREAM SOCK_STREAM
+ SOCK_DGRAM = 2, /* Connectionless, unreliable datagrams
+ of fixed maximum length. */
+#define SOCK_DGRAM SOCK_DGRAM
+ SOCK_RAW = 3, /* Raw protocol interface. */
+#define SOCK_RAW SOCK_RAW
+ SOCK_RDM = 4, /* Reliably-delivered messages. */
+#define SOCK_RDM SOCK_RDM
+ SOCK_SEQPACKET = 5 /* Sequenced, reliable, connection-based,
+ datagrams of fixed maximum length. */
+#define SOCK_SEQPACKET SOCK_SEQPACKET
+};
+
+/* Protocol families. */
+#define PF_UNSPEC 0 /* Unspecified. */
+#define PF_LOCAL 1 /* Local to host (pipes and file-domain). */
+#define PF_UNIX PF_LOCAL /* Old BSD name for PF_LOCAL. */
+#define PF_FILE PF_LOCAL /* POSIX name for PF_LOCAL. */
+#define PF_INET 2 /* IP protocol family. */
+#define PF_IMPLINK 3 /* ARPAnet IMP protocol. */
+#define PF_PUP 4 /* PUP protocols. */
+#define PF_CHAOS 5 /* MIT Chaos protocols. */
+#define PF_NS 6 /* Xerox NS protocols. */
+#define PF_ISO 7 /* ISO protocols. */
+#define PF_OSI PF_ISO
+#define PF_ECMA 8 /* ECMA protocols. */
+#define PF_DATAKIT 9 /* AT&T Datakit protocols. */
+#define PF_CCITT 10 /* CCITT protocols (X.25 et al). */
+#define PF_SNA 11 /* IBM SNA protocol. */
+#define PF_DECnet 12 /* DECnet protocols. */
+#define PF_DLI 13 /* Direct data link interface. */
+#define PF_LAT 14 /* DEC Local Area Transport protocol. */
+#define PF_HYLINK 15 /* NSC Hyperchannel protocol. */
+#define PF_APPLETALK 16 /* Don't use this. */
+#define PF_ROUTE 17 /* Internal Routing Protocol. */
+#define PF_LINK 18 /* Link layer interface. */
+#define PF_XTP 19 /* eXpress Transfer Protocol (no AF). */
+#define PF_COIP 20 /* Connection-oriented IP, aka ST II. */
+#define PF_CNT 21 /* Computer Network Technology. */
+#define PF_RTIP 22 /* Help Identify RTIP packets. **/
+#define PF_IPX 23 /* Novell Internet Protocol. */
+#define PF_SIP 24 /* Simple Internet Protocol. */
+#define PF_PIP 25 /* Help Identify PIP packets. */
+#define PF_INET6 26 /* IP version 6. */
+#define PF_MAX 27
+
+/* Address families. */
+#define AF_UNSPEC PF_UNSPEC
+#define AF_LOCAL PF_LOCAL
+#define AF_UNIX PF_UNIX
+#define AF_FILE PF_FILE
+#define AF_INET PF_INET
+#define AF_IMPLINK PF_IMPLINK
+#define AF_PUP PF_PUP
+#define AF_CHAOS PF_CHAOS
+#define AF_NS PF_NS
+#define AF_ISO PF_ISO
+#define AF_OSI PF_OSI
+#define AF_ECMA PF_ECMA
+#define AF_DATAKIT PF_DATAKIT
+#define AF_CCITT PF_CCITT
+#define AF_SNA PF_SNA
+#define AF_DECnet PF_DECnet
+#define AF_DLI PF_DLI
+#define AF_LAT PF_LAT
+#define AF_HYLINK PF_HYLINK
+#define AF_APPLETALK PF_APPLETALK
+#define AF_ROUTE PF_ROUTE
+#define AF_LINK PF_LINK
+#define pseudo_AF_XTP PF_XTP
+#define AF_COIP PF_COIP
+#define AF_CNT PF_CNT
+#define pseudo_AF_RTIP PF_RTIP
+#define AF_IPX PF_IPX
+#define AF_SIP PF_SIP
+#define pseudo_AF_PIP PF_PIP
+#define AF_INET6 PF_INET6
+#define AF_MAX PF_MAX
+
+/* Maximum queue length specifiable by listen. */
+#define SOMAXCONN 128 /* 5 on the origional 4.4 BSD. */
+
+/* Get the definition of the macro to define the common sockaddr members. */
+#include <bits/sockaddr.h>
+
+/* Structure describing a generic socket address. */
+struct sockaddr
+ {
+ __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
+ char sa_data[14]; /* Address data. */
+ };
+
+
+/* Structure large enough to hold any socket address (with the historical
+ exception of AF_UNIX). We reserve 128 bytes. */
+#if ULONG_MAX > 0xffffffff
+# define __ss_aligntype __uint64_t
+#else
+# define __ss_aligntype __uint32_t
+#endif
+#define _SS_SIZE 128
+#define _SS_PADSIZE (_SS_SIZE - (2 * sizeof (__ss_aligntype)))
+
+struct sockaddr_storage
+ {
+ __SOCKADDR_COMMON (ss_); /* Address family, etc. */
+ __ss_aligntype __ss_align; /* Force desired alignment. */
+ char __ss_padding[_SS_PADSIZE];
+ };
+
+
+/* Bits in the FLAGS argument to `send', `recv', et al. */
+enum
+ {
+ MSG_OOB = 0x01, /* Process out-of-band data. */
+#define MSG_OOB MSG_OOB
+ MSG_PEEK = 0x02, /* Peek at incoming messages. */
+#define MSG_PEEK MSG_PEEK
+ MSG_DONTROUTE = 0x04, /* Don't use local routing. */
+#define MSG_DONTROUTE MSG_DONTROUTE
+ MSG_EOR = 0x08, /* Data completes record. */
+#define MSG_EOR MSG_EOR
+ MSG_TRUNC = 0x10, /* Data discarded before delivery. */
+#define MSG_TRUNC MSG_TRUNC
+ MSG_CTRUNC = 0x20, /* Control data lost before delivery. */
+#define MSG_CTRUNC MSG_CTRUNC
+ MSG_WAITALL = 0x40, /* Wait for full request or error. */
+#define MSG_WAITALL MSG_WAITALL
+ MSG_DONTWAIT = 0x80 /* This message should be nonblocking. */
+#define MSG_DONTWAIT MSG_DONTWAIT
+ };
+
+
+/* Structure describing messages sent by
+ `sendmsg' and received by `recvmsg'. */
+struct msghdr
+ {
+ void *msg_name; /* Address to send to/receive from. */
+ socklen_t msg_namelen; /* Length of address data. */
+
+ struct iovec *msg_iov; /* Vector of data to send/receive into. */
+ int msg_iovlen; /* Number of elements in the vector. */
+
+ void *msg_control; /* Ancillary data (eg BSD filedesc passing). */
+ socklen_t msg_controllen; /* Ancillary data buffer length. */
+
+ int msg_flags; /* Flags in received message. */
+ };
+
+/* Structure used for storage of ancillary data object information. */
+struct cmsghdr
+ {
+ socklen_t cmsg_len; /* Length of data in cmsg_data plus length
+ of cmsghdr structure. */
+ int cmsg_level; /* Originating protocol. */
+ int cmsg_type; /* Protocol specific type. */
+#if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L
+ __extension__ unsigned char __cmsg_data __flexarr; /* Ancillary data. */
+#endif
+ };
+
+/* Ancillary data object manipulation macros. */
+#if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L
+# define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data)
+#else
+# define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1))
+#endif
+
+#define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg)
+
+#define CMSG_FIRSTHDR(mhdr) \
+ ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
+ ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
+
+#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) \
+ & (size_t) ~(sizeof (size_t) - 1))
+#define CMSG_SPACE(len) (CMSG_ALIGN (len) \
+ + CMSG_ALIGN (sizeof (struct cmsghdr)))
+#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
+
+extern struct cmsghdr *__cmsg_nxthdr (struct msghdr *__mhdr,
+ struct cmsghdr *__cmsg) __THROW;
+#ifdef __USE_EXTERN_INLINES
+# ifndef _EXTERN_INLINE
+# define _EXTERN_INLINE extern __inline
+# endif
+_EXTERN_INLINE struct cmsghdr *
+__NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg))
+{
+ if ((size_t) __cmsg->cmsg_len < sizeof (struct cmsghdr))
+ /* The kernel header does this so there may be a reason. */
+ return 0;
+
+ __cmsg = (struct cmsghdr *) ((unsigned char *) __cmsg
+ + CMSG_ALIGN (__cmsg->cmsg_len));
+ if ((unsigned char *) (__cmsg + 1) > ((unsigned char *) __mhdr->msg_control
+ + __mhdr->msg_controllen)
+ || ((unsigned char *) __cmsg + CMSG_ALIGN (__cmsg->cmsg_len)
+ > ((unsigned char *) __mhdr->msg_control + __mhdr->msg_controllen)))
+ /* No more entries. */
+ return 0;
+ return __cmsg;
+}
+#endif /* Use `extern inline'. */
+
+/* Socket level message types. */
+enum
+ {
+ SCM_RIGHTS = 0x01, /* Access rights (array of int). */
+#define SCM_RIGHTS SCM_RIGHTS
+ SCM_TIMESTAMP = 0x02, /* Timestamp (struct timeval). */
+#define SCM_TIMESTAMP SCM_TIMESTAMP
+ SCM_CREDS = 0x03 /* Process creds (struct cmsgcred). */
+#define SCM_CREDS SCM_CREDS
+ };
+
+/* Unfortunately, BSD practice dictates this structure be of fixed size.
+ If there are more than CMGROUP_MAX groups, the list is truncated.
+ (On GNU systems, the `cmcred_euid' field is just the first in the
+ list of effective UIDs.) */
+#define CMGROUP_MAX 16
+
+/* Structure delivered by SCM_CREDS. This describes the identity of the
+ sender of the data simultaneously received on the socket. By BSD
+ convention, this is included only when a sender on a AF_LOCAL socket
+ sends cmsg data of this type and size; the sender's structure is
+ ignored, and the system fills in the various IDs of the sender process. */
+struct cmsgcred
+ {
+ __pid_t cmcred_pid;
+ __uid_t cmcred_uid;
+ __uid_t cmcred_euid;
+ __gid_t cmcred_gid;
+ int cmcred_ngroups;
+ __gid_t cmcred_groups[CMGROUP_MAX];
+ };
+
+/* Protocol number used to manipulate socket-level options
+ with `getsockopt' and `setsockopt'. */
+#define SOL_SOCKET 0xffff
+
+/* Socket-level options for `getsockopt' and `setsockopt'. */
+enum
+ {
+ SO_DEBUG = 0x0001, /* Record debugging information. */
+#define SO_DEBUG SO_DEBUG
+ SO_ACCEPTCONN = 0x0002, /* Accept connections on socket. */
+#define SO_ACCEPTCONN SO_ACCEPTCONN
+ SO_REUSEADDR = 0x0004, /* Allow reuse of local addresses. */
+#define SO_REUSEADDR SO_REUSEADDR
+ SO_KEEPALIVE = 0x0008, /* Keep connections alive and send
+ SIGPIPE when they die. */
+#define SO_KEEPALIVE SO_KEEPALIVE
+ SO_DONTROUTE = 0x0010, /* Don't do local routing. */
+#define SO_DONTROUTE SO_DONTROUTE
+ SO_BROADCAST = 0x0020, /* Allow transmission of
+ broadcast messages. */
+#define SO_BROADCAST SO_BROADCAST
+ SO_USELOOPBACK = 0x0040, /* Use the software loopback to avoid
+ hardware use when possible. */
+#define SO_USELOOPBACK SO_USELOOPBACK
+ SO_LINGER = 0x0080, /* Block on close of a reliable
+ socket to transmit pending data. */
+#define SO_LINGER SO_LINGER
+ SO_OOBINLINE = 0x0100, /* Receive out-of-band data in-band. */
+#define SO_OOBINLINE SO_OOBINLINE
+ SO_REUSEPORT = 0x0200, /* Allow local address and port reuse. */
+#define SO_REUSEPORT SO_REUSEPORT
+ SO_SNDBUF = 0x1001, /* Send buffer size. */
+#define SO_SNDBUF SO_SNDBUF
+ SO_RCVBUF = 0x1002, /* Receive buffer. */
+#define SO_RCVBUF SO_RCVBUF
+ SO_SNDLOWAT = 0x1003, /* Send low-water mark. */
+#define SO_SNDLOWAT SO_SNDLOWAT
+ SO_RCVLOWAT = 0x1004, /* Receive low-water mark. */
+#define SO_RCVLOWAT SO_RCVLOWAT
+ SO_SNDTIMEO = 0x1005, /* Send timeout. */
+#define SO_SNDTIMEO SO_SNDTIMEO
+ SO_RCVTIMEO = 0x1006, /* Receive timeout. */
+#define SO_RCVTIMEO SO_RCVTIMEO
+ SO_ERROR = 0x1007, /* Get and clear error status. */
+#define SO_ERROR SO_ERROR
+ SO_STYLE = 0x1008, /* Get socket connection style. */
+#define SO_STYLE SO_STYLE
+ SO_TYPE = SO_STYLE /* Compatible name for SO_STYLE. */
+#define SO_TYPE SO_TYPE
+ };
+
+/* Structure used to manipulate the SO_LINGER option. */
+struct linger
+ {
+ int l_onoff; /* Nonzero to linger on close. */
+ int l_linger; /* Time to linger. */
+ };
+
+#endif /* bits/socket.h */
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/cmsg_nxthdr.c b/libc/sysdeps/unix/bsd/bsd4.4/cmsg_nxthdr.c
new file mode 100644
index 000000000..1a542fa01
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/cmsg_nxthdr.c
@@ -0,0 +1,2 @@
+/* The Linux version is perfectly usable on 4.4 BSD. */
+#include <sysdeps/unix/sysv/linux/cmsg_nxthdr.c>
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/freebsd/bits/environments.h b/libc/sysdeps/unix/bsd/bsd4.4/freebsd/bits/environments.h
new file mode 100644
index 000000000..92112b554
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/freebsd/bits/environments.h
@@ -0,0 +1,72 @@
+/* Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _UNISTD_H
+# error "Never include this file directly. Use <unistd.h> instead"
+#endif
+
+#include <bits/wordsize.h>
+
+/* This header should define the following symbols under the described
+ situations. A value `1' means that the model is always supported,
+ `-1' means it is never supported. Undefined means it cannot be
+ statically decided.
+
+ _POSIX_V6_ILP32_OFF32 32bit int, long, pointers, and off_t type
+ _POSIX_V6_ILP32_OFFBIG 32bit int, long, and pointers and larger off_t type
+
+ _POSIX_V6_LP64_OFF32 64bit long and pointers and 32bit off_t type
+ _POSIX_V6_LPBIG_OFFBIG 64bit long and pointers and large off_t type
+
+ The macros _XBS5_ILP32_OFF32, _XBS5_ILP32_OFFBIG, _XBS5_LP64_OFF32, and
+ _XBS5_LPBIG_OFFBIG were used in previous versions of the Unix standard
+ and are available only for compatibility.
+*/
+
+#if __WORDSIZE == 64
+
+/* We can never provide environments with 32-bit wide pointers. */
+# define _POSIX_V6_ILP32_OFF32 -1
+# define _POSIX_V6_ILP32_OFFBIG -1
+# define _XBS5_ILP32_OFF32 -1
+# define _XBS5_ILP32_OFFBIG -1
+/* We also have no use (for now) for an environment with bigger pointers
+ and offsets. */
+# define _POSIX_V6_LPBIG_OFFBIG -1
+# define _XBS5_LPBIG_OFFBIG -1
+
+/* By default we have 64-bit wide `long int', pointers and `off_t'. */
+# define _POSIX_V6_LP64_OFF64 1
+# define _XBS5_LP64_OFF64 1
+
+#else /* __WORDSIZE == 32 */
+
+/* By default we have 32-bit wide `int', `long int', pointers
+ and 64-bit `off_t'. */
+# define _POSIX_V6_ILP32_OFF32 -1
+# define _POSIX_V6_ILP32_OFFBIG 1
+# define _XBS5_ILP32_OFF32 -1
+# define _XBS5_ILP32_OFFBIG 1
+
+/* We can never provide environments with 64-bit wide pointers. */
+# define _POSIX_V6_LP64_OFF64 -1
+# define _POSIX_V6_LPBIG_OFFBIG -1
+# define _XBS5_LP64_OFF64 -1
+# define _XBS5_LPBIG_OFFBIG -1
+
+#endif /* __WORDSIZE == 32 */
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/freebsd/bits/typesizes.h b/libc/sysdeps/unix/bsd/bsd4.4/freebsd/bits/typesizes.h
new file mode 100644
index 000000000..c0e267ff6
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/freebsd/bits/typesizes.h
@@ -0,0 +1,66 @@
+/* bits/typesizes.h -- underlying types for *_t. FreeBSD version.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _BITS_TYPES_H
+# error "Never include <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 __U32_TYPE
+#define __UID_T_TYPE __U32_TYPE
+#define __GID_T_TYPE __U32_TYPE
+#define __INO_T_TYPE __U32_TYPE
+#define __INO64_T_TYPE __UQUAD_TYPE
+#define __MODE_T_TYPE __U16_TYPE
+#define __NLINK_T_TYPE __U16_TYPE
+#define __OFF_T_TYPE __SQUAD_TYPE
+#define __OFF64_T_TYPE __SQUAD_TYPE
+#define __PID_T_TYPE __S32_TYPE
+#define __RLIM_T_TYPE __SQUAD_TYPE
+#define __RLIM64_T_TYPE __SQUAD_TYPE
+#define __BLKCNT_T_TYPE __SLONGWORD_TYPE
+#define __BLKCNT64_T_TYPE __SQUAD_TYPE
+#define __FSBLKCNT_T_TYPE __ULONGWORD_TYPE
+#define __FSBLKCNT64_T_TYPE __UQUAD_TYPE
+#define __FSFILCNT_T_TYPE __ULONGWORD_TYPE
+#define __FSFILCNT64_T_TYPE __UQUAD_TYPE
+#define __ID_T_TYPE __U32_TYPE
+#define __CLOCK_T_TYPE __S32_TYPE
+#define __TIME_T_TYPE __SLONGWORD_TYPE
+#define __USECONDS_T_TYPE __U32_TYPE
+#define __SUSECONDS_T_TYPE __SLONGWORD_TYPE
+#define __DADDR_T_TYPE __S32_TYPE
+#define __SWBLK_T_TYPE __S32_TYPE
+#define __KEY_T_TYPE __S32_TYPE
+#define __CLOCKID_T_TYPE __S32_TYPE
+#define __TIMER_T_TYPE __S32_TYPE
+#define __BLKSIZE_T_TYPE __U32_TYPE
+#define __FSID_T_TYPE struct { int __val[2]; }
+#define __SSIZE_T_TYPE __SWORD_TYPE
+
+/* Number of descriptors that can fit in an `fd_set'. */
+#define __FD_SETSIZE 1024
+
+
+#endif /* bits/typesizes.h */
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/freebsd/sys/sysmacros.h b/libc/sysdeps/unix/bsd/bsd4.4/freebsd/sys/sysmacros.h
new file mode 100644
index 000000000..6b5e07e08
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/freebsd/sys/sysmacros.h
@@ -0,0 +1,28 @@
+/* Definitions of macros to access `dev_t' values. FreeBSD version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SYSMACROS_H
+#define _SYS_SYSMACROS_H 1
+
+/* For compatibility we provide alternative names. */
+#define major(dev) ((int)(((unsigned int) (dev) >> 8) & 0xff))
+#define minor(dev) ((int)((dev) & 0xffff00ff))
+#define makedev(major, minor) (((major) << 8) | (minor))
+
+#endif /* sys/sysmacros.h */
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/isatty.c b/libc/sysdeps/unix/bsd/bsd4.4/isatty.c
new file mode 100644
index 000000000..473368c93
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/isatty.c
@@ -0,0 +1,3 @@
+/* In a 4.4-derived world, tcgetattr is just one ioctl. */
+
+#include <sysdeps/posix/isatty.c>
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/sigblock.c b/libc/sysdeps/unix/bsd/bsd4.4/sigblock.c
new file mode 100644
index 000000000..2647327db
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/sigblock.c
@@ -0,0 +1 @@
+#include <sysdeps/posix/sigblock.c>
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/sigsetmask.c b/libc/sysdeps/unix/bsd/bsd4.4/sigsetmask.c
new file mode 100644
index 000000000..47f1e36a7
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/sigsetmask.c
@@ -0,0 +1 @@
+#include <sysdeps/posix/sigsetmask.c>
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/sigvec.c b/libc/sysdeps/unix/bsd/bsd4.4/sigvec.c
new file mode 100644
index 000000000..d03d9bb3d
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/sigvec.c
@@ -0,0 +1 @@
+#include <sysdeps/posix/sigvec.c>
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/syscalls.list b/libc/sysdeps/unix/bsd/bsd4.4/syscalls.list
new file mode 100644
index 000000000..a4d354685
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/syscalls.list
@@ -0,0 +1,8 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+chflags - chflags 2 chflags
+fchflags - fchflags 2 fchflags
+revoke - revoke 1 revoke
+setlogin - setlogin 2 setlogin
+sigaltstack - sigaltstack 2 __sigaltstack sigaltstack
+wait4 - wait4 4 __wait4 wait4
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/system.c b/libc/sysdeps/unix/bsd/bsd4.4/system.c
new file mode 100644
index 000000000..9283f7455
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/system.c
@@ -0,0 +1,2 @@
+/* BSD 4.4 does have `waitpid'. Avoid unix/system.c, which says we don't. */
+#include <sysdeps/posix/system.c>
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/tcdrain.c b/libc/sysdeps/unix/bsd/bsd4.4/tcdrain.c
new file mode 100644
index 000000000..4eb5612f7
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/tcdrain.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1992, 1994, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <sys/ioctl.h>
+
+/* Wait for pending output to be written on FD. */
+int
+__libc_tcdrain (int fd)
+{
+ return __ioctl (fd, TIOCDRAIN);
+}
+weak_alias (__libc_tcdrain, tcdrain)
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/tcgetattr.c b/libc/sysdeps/unix/bsd/bsd4.4/tcgetattr.c
new file mode 100644
index 000000000..ac60752f1
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/tcgetattr.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 1991, 1992, 1994, 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <termios.h>
+
+/* These are defined both in <bits/termios.h> and in <bits/ioctls.h>.
+ They should have the same values, but perhaps not written the same way. */
+#undef ECHO
+#undef MDMBUF
+#undef TOSTOP
+#undef FLUSHO
+#undef PENDIN
+#undef NOFLSH
+#include <sys/ioctl.h>
+
+/* Put the state of FD into *TERMIOS_P. */
+int
+__tcgetattr (fd, termios_p)
+ int fd;
+ struct termios *termios_p;
+{
+ return __ioctl (fd, TIOCGETA, termios_p);
+}
+
+weak_alias (__tcgetattr, tcgetattr)
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/tcsetattr.c b/libc/sysdeps/unix/bsd/bsd4.4/tcsetattr.c
new file mode 100644
index 000000000..b3142f6a2
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/tcsetattr.c
@@ -0,0 +1,63 @@
+/* Copyright (C) 1992, 1994, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <termios.h>
+
+/* These are defined both in <bits/termios.h> and in <bits/ioctls.h>.
+ They should have the same values, but perhaps not written the same way. */
+#undef ECHO
+#undef MDMBUF
+#undef TOSTOP
+#undef FLUSHO
+#undef PENDIN
+#undef NOFLSH
+#include <sys/ioctl.h>
+
+
+/* Set the state of FD to *TERMIOS_P. */
+int
+tcsetattr (fd, optional_actions, termios_p)
+ int fd;
+ int optional_actions;
+ const struct termios *termios_p;
+{
+ struct termios myt;
+
+ if (optional_actions & TCSASOFT)
+ {
+ myt = *termios_p;
+ myt.c_cflag |= CIGNORE;
+ termios_p = &myt;
+ optional_actions &= ~TCSASOFT;
+ }
+
+ switch (optional_actions)
+ {
+ case TCSANOW:
+ return __ioctl (fd, TIOCSETA, termios_p);
+
+ case TCSADRAIN:
+ return __ioctl (fd, TIOCSETAW, termios_p);
+
+ default:
+ return __ioctl (fd, TIOCSETAF, termios_p);
+ }
+}
+libc_hidden_def (tcsetattr)
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/wait.c b/libc/sysdeps/unix/bsd/bsd4.4/wait.c
new file mode 100644
index 000000000..643dd7a39
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/wait.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/wait.h>
+#include <errno.h>
+#include <sys/resource.h>
+#include <stddef.h>
+
+/* Wait for a child to die. When one does, put its status in *STAT_LOC
+ and return its process ID. For errors, return (pid_t) -1. */
+__pid_t
+__libc_wait (__WAIT_STATUS_DEFN stat_loc)
+{
+ return __wait4 (WAIT_ANY, stat_loc, 0, (struct rusage *) NULL);
+}
+
+weak_alias (__libc_wait, __wait)
+weak_alias (__libc_wait, wait)
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/wait3.c b/libc/sysdeps/unix/bsd/bsd4.4/wait3.c
new file mode 100644
index 000000000..540dad6fb
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/wait3.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1991, 1992, 1993, 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+
+/* Wait for a child to exit. When one does, put its status in *STAT_LOC and
+ return its process ID. For errors return (pid_t) -1. If USAGE is not nil,
+ store information about the child's resource usage (as a `struct rusage')
+ there. If the WUNTRACED bit is set in OPTIONS, return status for stopped
+ children; otherwise don't. */
+pid_t
+__wait3 (stat_loc, options, usage)
+ __WAIT_STATUS stat_loc;
+ int options;
+ struct rusage *usage;
+{
+ return __wait4 (WAIT_ANY, stat_loc, options, usage);
+}
+
+weak_alias (__wait3, wait3)
diff --git a/libc/sysdeps/unix/bsd/bsd4.4/waitpid.c b/libc/sysdeps/unix/bsd/bsd4.4/waitpid.c
new file mode 100644
index 000000000..33b29d2c3
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsd4.4/waitpid.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 1991,95,96,97,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <stddef.h>
+
+/* Wait for a child matching PID to die.
+ If PID is greater than 0, match any process whose process ID is PID.
+ If PID is (pid_t) -1, match any process.
+ If PID is (pid_t) 0, match any process with the
+ same process group as the current process.
+ If PID is less than -1, match any process whose
+ process group is the absolute value of PID.
+ If the WNOHANG bit is set in OPTIONS, and that child
+ is not already dead, return (pid_t) 0. If successful,
+ return PID and store the dead child's status in STAT_LOC.
+ Return (pid_t) -1 for errors. If the WUNTRACED bit is set in OPTIONS,
+ return status for stopped children; otherwise don't. */
+pid_t
+__libc_waitpid (pid_t pid, int *stat_loc, int options)
+{
+ return __wait4 (pid, (union wait *) stat_loc, options, NULL);
+}
+
+weak_alias (__libc_waitpid, __waitpid)
+libc_hidden_weak (__waitpid)
+weak_alias (__libc_waitpid, waitpid)
diff --git a/libc/sysdeps/unix/bsd/bsdstat.h b/libc/sysdeps/unix/bsd/bsdstat.h
new file mode 100644
index 000000000..f1e38c015
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsdstat.h
@@ -0,0 +1,112 @@
+/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/types.h>
+
+/* This will make it not define major, minor, makedev, and S_IF*. */
+#undef __USE_BSD
+#undef __USE_MISC
+#include <sys/stat.h>
+
+#undef stat
+#undef fstat
+
+#undef S_IRWXU
+#undef S_IRUSR
+#undef S_IWUSR
+#undef S_IXUSR
+#undef S_IRWXG
+#undef S_IRGRP
+#undef S_IWGRP
+#undef S_IXGRP
+#undef S_IRWXO
+#undef S_IROTH
+#undef S_IWOTH
+#undef S_IXOTH
+#undef S_ISBLK
+#undef S_ISCHR
+#undef S_ISDIR
+#undef S_ISFIFO
+#undef S_ISREG
+#undef S_ISUID
+#undef S_ISGID
+#define stat system_stat
+#define fstat system_fstat
+#define KERNEL /* Try to avoid misc decls. */
+#include "/usr/include/sys/stat.h"
+#undef KERNEL
+#undef stat
+#undef fstat
+
+#define member_same(statbufp, sysbufp, member) \
+ (offsetof(struct __stat, member) == offsetof(struct system_stat, member) && \
+ sizeof((statbufp)->member) == sizeof((sysbufp)->member))
+#define need_stat_mapping(statbufp, sysbufp) \
+ (!(member_same(statbufp, sysbufp, st_dev) && \
+ member_same(statbufp, sysbufp, st_ino) && \
+ member_same(statbufp, sysbufp, st_mode) && \
+ member_same(statbufp, sysbufp, st_nlink) && \
+ member_same(statbufp, sysbufp, st_uid) && \
+ member_same(statbufp, sysbufp, st_gid) && \
+ member_same(statbufp, sysbufp, st_rdev) && \
+ member_same(statbufp, sysbufp, st_size) && \
+ member_same(statbufp, sysbufp, st_atime) && \
+ member_same(statbufp, sysbufp, st_mtime) && \
+ member_same(statbufp, sysbufp, st_ctime) && \
+ member_same(statbufp, sysbufp, st_blksize) && \
+ member_same(statbufp, sysbufp, st_blocks)))
+
+/* Map a system `struct stat' to our `struct stat'. */
+#ifdef __GNUC__
+inline
+#endif
+static int
+mapstat (sysbuf, statbuf)
+ const struct system_stat *sysbuf;
+ struct __stat *buf;
+{
+ if (buf == NULL)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (!need_stat_mapping(buf, sysbuf))
+ /* Hopefully this will be optimized out. */
+ *buf = *(struct __stat *) sysbuf;
+ else
+ {
+ buf->st_dev = (dev_t) sysbuf->st_dev;
+ buf->st_ino = (ino_t) sysbuf->st_ino;
+ buf->st_mode = (mode_t) sysbuf->st_mode;
+ buf->st_nlink = (nlink_t) sysbuf->st_nlink;
+ buf->st_uid = (uid_t) sysbuf->st_uid;
+ buf->st_gid = (gid_t) sysbuf->st_gid;
+ buf->st_rdev = (dev_t) sysbuf->st_rdev;
+ buf->st_size = (size_t) sysbuf->st_size;
+ buf->st_atime = (time_t) sysbuf->st_atime;
+ buf->st_mtime = (time_t) sysbuf->st_mtime;
+ buf->st_ctime = (time_t) sysbuf->st_ctime;
+ buf->st_blksize = (size_t) sysbuf->st_blksize;
+ buf->st_blocks = (size_t) sysbuf->st_blocks;
+ }
+
+ return 0;
+}
diff --git a/libc/sysdeps/unix/bsd/bsdtty.h b/libc/sysdeps/unix/bsd/bsdtty.h
new file mode 100644
index 000000000..a1da8d5cc
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/bsdtty.h
@@ -0,0 +1,218 @@
+#undef B0
+#undef B50
+#undef B75
+#undef B110
+#undef B134
+#undef B150
+#undef B200
+#undef B300
+#undef B600
+#undef B1200
+#undef B1800
+#undef B2400
+#undef B4800
+#undef B9600
+#undef B19200
+#undef B38400
+#undef EXTA
+#undef EXTB
+#undef ECHO
+#undef TOSTOP
+#undef NOFLSH
+#undef MDMBUF
+#undef FLUSHO
+#undef PENDIN
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+#undef CERASE
+#undef CKILL
+#undef CINTR
+#undef CQUIT
+#undef CSTART
+#undef CSTOP
+#undef CEOF
+#undef CEOT
+#undef CBRK
+#undef CSUSP
+#undef CDSUSP
+#undef CRPRNT
+#undef CFLUSH
+#undef CWERASE
+#undef CLNEXT
+#undef CSTATUS
+
+#include <sys/ioctl.h>
diff --git a/libc/sysdeps/unix/bsd/clock.c b/libc/sysdeps/unix/bsd/clock.c
new file mode 100644
index 000000000..4faae57dc
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/clock.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 1991, 1997, 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <time.h>
+
+#ifdef __GNUC__
+__inline
+#endif
+static clock_t
+timeval_to_clock_t (const struct timeval *tv)
+{
+ return (clock_t) ((tv->tv_sec * CLOCKS_PER_SEC) +
+ (tv->tv_usec * CLOCKS_PER_SEC / 1000000));
+}
+
+/* Return the time used by the program so far (user time + system time). */
+clock_t
+clock (void)
+{
+ struct rusage usage;
+
+ if (__getrusage (RUSAGE_SELF, &usage) < 0)
+ return (clock_t) -1;
+
+ return (timeval_to_clock_t (&usage.ru_stime) +
+ timeval_to_clock_t (&usage.ru_utime));
+}
diff --git a/libc/sysdeps/unix/bsd/confstr.h b/libc/sysdeps/unix/bsd/confstr.h
new file mode 100644
index 000000000..befefb652
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/confstr.h
@@ -0,0 +1 @@
+#define CS_PATH "/usr/ucb:/bin:/usr/bin"
diff --git a/libc/sysdeps/unix/bsd/ftime.c b/libc/sysdeps/unix/bsd/ftime.c
new file mode 100644
index 000000000..187c24c1d
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/ftime.c
@@ -0,0 +1,42 @@
+/* Copyright (C) 1994, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/timeb.h>
+#include <sys/time.h>
+
+int
+ftime (timebuf)
+ struct timeb *timebuf;
+{
+ struct timeval tv;
+ struct timezone tz;
+
+ if (__gettimeofday (&tv, &tz) < 0)
+ return -1;
+
+ timebuf->time = tv.tv_sec;
+ timebuf->millitm = (tv.tv_usec + 500) / 1000;
+ if (timebuf->millitm == 1000)
+ {
+ ++timebuf->time;
+ timebuf->millitm = 0;
+ }
+ timebuf->timezone = tz.tz_minuteswest;
+ timebuf->dstflag = tz.tz_dsttime;
+ return 0;
+}
diff --git a/libc/sysdeps/unix/bsd/getpt.c b/libc/sysdeps/unix/bsd/getpt.c
new file mode 100644
index 000000000..f4a6b17f0
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/getpt.c
@@ -0,0 +1,93 @@
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+
+
+/* Prefix for master pseudo terminal nodes. */
+#define _PATH_PTY "/dev/pty"
+
+
+/* Letters indicating a series of pseudo terminals. */
+#ifndef PTYNAME1
+#define PTYNAME1 "pqrsPQRS"
+#endif
+const char __libc_ptyname1[] attribute_hidden = PTYNAME1;
+
+/* Letters indicating the position within a series. */
+#ifndef PTYNAME2
+#define PTYNAME2 "0123456789abcdefghijklmnopqrstuv";
+#endif
+const char __libc_ptyname2[] attribute_hidden = PTYNAME2;
+
+
+/* Open a master pseudo terminal and return its file descriptor. */
+int
+__getpt (void)
+{
+ char buf[sizeof (_PATH_PTY) + 2];
+ const char *p, *q;
+ char *s;
+
+ s = __mempcpy (buf, _PATH_PTY, sizeof (_PATH_PTY) - 1);
+ /* s[0] and s[1] will be filled in the loop. */
+ s[2] = '\0';
+
+ for (p = __libc_ptyname1; *p != '\0'; ++p)
+ {
+ s[0] = *p;
+
+ for (q = __libc_ptyname2; *q != '\0'; ++q)
+ {
+ int fd;
+
+ s[1] = *q;
+
+ fd = __open (buf, O_RDWR);
+ if (fd != -1)
+ return fd;
+
+ if (errno == ENOENT)
+ return -1;
+ }
+ }
+
+ __set_errno (ENOENT);
+ return -1;
+}
+
+#undef __getpt
+weak_alias (__getpt, getpt)
+
+#ifndef HAVE_POSIX_OPENPT
+/* We cannot define posix_openpt in general for BSD systems. */
+int
+__posix_openpt (int oflag)
+{
+ __set_errno (ENOSYS);
+ return -1;
+}
+weak_alias (__posix_openpt, posix_openpt)
+
+stub_warning (posix_openpt)
+# include <stub-tag.h>
+#endif
diff --git a/libc/sysdeps/unix/bsd/gtty.c b/libc/sysdeps/unix/bsd/gtty.c
new file mode 100644
index 000000000..081ce25ae
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/gtty.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sgtty.h>
+
+/* Fill in *PARAMS with terminal parameters associated with FD. */
+int
+gtty (fd, params)
+ int fd;
+ struct sgttyb *params;
+{
+ return ioctl (fd, TIOCGETP, (void *) params);
+}
diff --git a/libc/sysdeps/unix/bsd/i386/vfork.S b/libc/sysdeps/unix/bsd/i386/vfork.S
new file mode 100644
index 000000000..a245f3e14
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/i386/vfork.S
@@ -0,0 +1,40 @@
+/* Copyright (C) 1993, 1994, 1995, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* Since vfork shares the address space between the parent and child,
+ we must take care to avoid the child unwinding the stack frame and
+ clobbering it for the parent. */
+
+.text
+ENTRY (__vfork)
+ popl scratch /* Save the return PC in a register. */
+ DO_CALL (vfork, 0) /* Do the system call. */
+ pushl scratch /* Put the return PC back on the stack. */
+ jb syscall_error /* Branch if error. */
+ /* R1 is now 0 for the parent and 1 for the child. Decrement it to
+ make it -1 (all bits set) for the parent, and 0 (no bits set)
+ for the child. Then AND it with R0, so the parent gets
+ R0&-1==R0, and the child gets R0&0==0. */
+ decl r1
+ andl r1, r0
+ ret
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/sysdeps/unix/bsd/i386/wait3.S b/libc/sysdeps/unix/bsd/i386/wait3.S
new file mode 100644
index 000000000..5988340cc
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/i386/wait3.S
@@ -0,0 +1,44 @@
+/* Copyright (C) 1991, 1992, 1993, 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* <sysdeps/unix/bsd/sequent/i386/sysdep.h> defines this to put the first
+ two arguments into registers. Since the arguments to wait3 are
+ transferred magically through the same registers, we want to disable this.
+ This allows us to avoid rewriting this file for that system. */
+
+#undef ARGS_2
+#define ARGS_2 /* Special-case no-op. */
+
+.text
+.globl syscall_error
+.align 4
+ENTRY (__wait3)
+ mov 8(%esp), %ecx /* Flags. */
+ mov 12(%esp), %edx /* rusage pointer. */
+ pushl $0xdf; popf /* Set all the condition codes. */
+ DO_CALL (wait, 2) /* Do the system call. */
+ je syscall_error /* Check for error. */
+ mov 4(%esp), scratch /* Status pointer. */
+ orl scratch, scratch /* Is it nil? */
+ je done /* Yup; return. */
+ mov r1, 0(scratch) /* Non-nil; store the status in it. */
+done: ret
+
+weak_alias (__wait3, wait3)
diff --git a/libc/sysdeps/unix/bsd/init-posix.c b/libc/sysdeps/unix/bsd/init-posix.c
new file mode 100644
index 000000000..b5ea8846f
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/init-posix.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991, 94, 95, 97, 98, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <time.h>
+
+/* This must be initialized data or its presence will not be sufficient to
+ merit linkage of this file, which is necessary for the real
+ initialization function below to be called. */
+time_t _posix_start_time = -1;
+
+void
+__init_posix (void)
+{
+ _posix_start_time = time ((time_t *) NULL);
+}
+
+text_set_element(__libc_subinit, __init_posix);
diff --git a/libc/sysdeps/unix/bsd/isatty.c b/libc/sysdeps/unix/bsd/isatty.c
new file mode 100644
index 000000000..996c4ed41
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/isatty.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1991,95,96,97,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
+/* Return 1 if FD is a terminal, 0 if not. */
+int
+__isatty (fd)
+ int fd;
+{
+ struct sgttyb term;
+
+ return __ioctl (fd, TIOCGETP, &term) == 0;
+}
+weak_alias (__isatty, isatty)
diff --git a/libc/sysdeps/unix/bsd/poll.c b/libc/sysdeps/unix/bsd/poll.c
new file mode 100644
index 000000000..0bddf0b27
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/poll.c
@@ -0,0 +1,199 @@
+/* Copyright (C) 1994,1996,1997,1998,1999,2001,2002
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <alloca.h>
+#include <sys/poll.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/param.h>
+#include <unistd.h>
+
+/* Poll the file descriptors described by the NFDS structures starting at
+ FDS. If TIMEOUT is nonzero and not -1, allow TIMEOUT milliseconds for
+ an event to occur; if TIMEOUT is -1, block until an event occurs.
+ Returns the number of file descriptors with events, zero if timed out,
+ or -1 for errors. */
+
+int
+__poll (fds, nfds, timeout)
+ struct pollfd *fds;
+ nfds_t nfds;
+ int timeout;
+{
+ static int max_fd_size;
+ struct timeval tv;
+ fd_set *rset, *wset, *xset;
+ struct pollfd *f;
+ int ready;
+ int maxfd = 0;
+ int bytes;
+
+ if (!max_fd_size)
+ max_fd_size = __getdtablesize ();
+
+ bytes = howmany (max_fd_size, __NFDBITS);
+ rset = alloca (bytes);
+ wset = alloca (bytes);
+ xset = alloca (bytes);
+
+ /* We can't call FD_ZERO, since FD_ZERO only works with sets
+ of exactly __FD_SETSIZE size. */
+ __bzero (rset, bytes);
+ __bzero (wset, bytes);
+ __bzero (xset, bytes);
+
+ for (f = fds; f < &fds[nfds]; ++f)
+ {
+ f->revents = 0;
+ if (f->fd >= 0)
+ {
+ if (f->fd >= max_fd_size)
+ {
+ /* The user provides a file descriptor number which is higher
+ than the maximum we got from the `getdtablesize' call.
+ Maybe this is ok so enlarge the arrays. */
+ fd_set *nrset, *nwset, *nxset;
+ int nbytes;
+
+ max_fd_size = roundup (f->fd, __NFDBITS);
+ nbytes = howmany (max_fd_size, __NFDBITS);
+
+ nrset = alloca (nbytes);
+ nwset = alloca (nbytes);
+ nxset = alloca (nbytes);
+
+ __bzero ((char *) nrset + bytes, nbytes - bytes);
+ __bzero ((char *) nwset + bytes, nbytes - bytes);
+ __bzero ((char *) nxset + bytes, nbytes - bytes);
+
+ rset = memcpy (nrset, rset, bytes);
+ wset = memcpy (nwset, wset, bytes);
+ xset = memcpy (nxset, xset, bytes);
+
+ bytes = nbytes;
+ }
+
+ if (f->events & POLLIN)
+ FD_SET (f->fd, rset);
+ if (f->events & POLLOUT)
+ FD_SET (f->fd, wset);
+ if (f->events & POLLPRI)
+ FD_SET (f->fd, xset);
+ if (f->fd > maxfd && (f->events & (POLLIN|POLLOUT|POLLPRI)))
+ maxfd = f->fd;
+ }
+ }
+
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+
+ while (1)
+ {
+ ready = __select (maxfd + 1, rset, wset, xset,
+ timeout == -1 ? NULL : &tv);
+
+ /* It might be that one or more of the file descriptors is invalid.
+ We now try to find and mark them and then try again. */
+ if (ready == -1 && errno == EBADF)
+ {
+ fd_set *sngl_rset = alloca (bytes);
+ fd_set *sngl_wset = alloca (bytes);
+ fd_set *sngl_xset = alloca (bytes);
+ struct timeval sngl_tv;
+
+ /* Clear the original set. */
+ __bzero (rset, bytes);
+ __bzero (wset, bytes);
+ __bzero (xset, bytes);
+
+ /* This means we don't wait for input. */
+ sngl_tv.tv_sec = 0;
+ sngl_tv.tv_usec = 0;
+
+ maxfd = -1;
+
+ /* Reset the return value. */
+ ready = 0;
+
+ for (f = fds; f < &fds[nfds]; ++f)
+ if (f->fd != -1 && (f->events & (POLLIN|POLLOUT|POLLPRI))
+ && (f->revents & POLLNVAL) == 0)
+ {
+ int n;
+
+ __bzero (sngl_rset, bytes);
+ __bzero (sngl_wset, bytes);
+ __bzero (sngl_xset, bytes);
+
+ if (f->events & POLLIN)
+ FD_SET (f->fd, sngl_rset);
+ if (f->events & POLLOUT)
+ FD_SET (f->fd, sngl_wset);
+ if (f->events & POLLPRI)
+ FD_SET (f->fd, sngl_xset);
+
+ n = __select (f->fd + 1, sngl_rset, sngl_wset, sngl_xset,
+ &sngl_tv);
+ if (n != -1)
+ {
+ /* This descriptor is ok. */
+ if (f->events & POLLIN)
+ FD_SET (f->fd, rset);
+ if (f->events & POLLOUT)
+ FD_SET (f->fd, wset);
+ if (f->events & POLLPRI)
+ FD_SET (f->fd, xset);
+ if (f->fd > maxfd)
+ maxfd = f->fd;
+ if (n > 0)
+ /* Count it as being available. */
+ ++ready;
+ }
+ else if (errno == EBADF)
+ f->revents |= POLLNVAL;
+ }
+ /* Try again. */
+ continue;
+ }
+
+ break;
+ }
+
+ if (ready > 0)
+ for (f = fds; f < &fds[nfds]; ++f)
+ {
+ if (f->fd >= 0)
+ {
+ if (FD_ISSET (f->fd, rset))
+ f->revents |= POLLIN;
+ if (FD_ISSET (f->fd, wset))
+ f->revents |= POLLOUT;
+ if (FD_ISSET (f->fd, xset))
+ f->revents |= POLLPRI;
+ }
+ }
+
+ return ready;
+}
+#ifndef __poll
+libc_hidden_def (__poll)
+weak_alias (__poll, poll)
+#endif
diff --git a/libc/sysdeps/unix/bsd/ptsname.c b/libc/sysdeps/unix/bsd/ptsname.c
new file mode 100644
index 000000000..fd446a4b6
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/ptsname.c
@@ -0,0 +1,76 @@
+/* Copyright (C) 1998,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <paths.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+/* Static buffer for `ptsname'. */
+static char buffer[sizeof (_PATH_TTY) + 2];
+
+
+/* Return the pathname of the pseudo terminal slave assoicated with
+ the master FD is open on, or NULL on errors.
+ The returned storage is good until the next call to this function. */
+char *
+ptsname (int fd)
+{
+ return __ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer;
+}
+
+
+/* Store at most BUFLEN characters of the pathname of the slave pseudo
+ terminal associated with the master FD is open on in BUF.
+ Return 0 on success, otherwise an error number. */
+int
+__ptsname_r (int fd, char *buf, size_t buflen)
+{
+ int save_errno = errno;
+ struct stat st;
+
+ if (buf == NULL)
+ {
+ __set_errno (EINVAL);
+ return EINVAL;
+ }
+
+ if (!__isatty (fd))
+ /* We rely on isatty to set errno properly (i.e. EBADF or ENOTTY). */
+ return errno;
+
+ if (buflen < strlen (_PATH_TTY) + 3)
+ {
+ __set_errno (ERANGE);
+ return ERANGE;
+ }
+
+ if (__ttyname_r (fd, buf, buflen) != 0)
+ return errno;
+
+ buf[sizeof (_PATH_DEV) - 1] = 't';
+
+ if (__stat (buf, &st) < 0)
+ return errno;
+
+ __set_errno (save_errno);
+ return 0;
+}
+weak_alias (__ptsname_r, ptsname_r)
diff --git a/libc/sysdeps/unix/bsd/seekdir.c b/libc/sysdeps/unix/bsd/seekdir.c
new file mode 100644
index 000000000..4d244f53b
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/seekdir.c
@@ -0,0 +1 @@
+/* Because they share a private data structure, seekdir is in telldir.c. */
diff --git a/libc/sysdeps/unix/bsd/setegid.c b/libc/sysdeps/unix/bsd/setegid.c
new file mode 100644
index 000000000..cc9f939ba
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/setegid.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+int
+setegid (gid)
+ gid_t gid;
+{
+ if (gid == (gid_t) ~0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return __setregid (-1, gid);
+}
+libc_hidden_def (setegid)
diff --git a/libc/sysdeps/unix/bsd/seteuid.c b/libc/sysdeps/unix/bsd/seteuid.c
new file mode 100644
index 000000000..056b6583c
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/seteuid.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+int
+seteuid (uid)
+ uid_t uid;
+{
+ if (uid == (uid_t) ~0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return __setreuid (-1, uid);
+}
+libc_hidden_def (seteuid)
diff --git a/libc/sysdeps/unix/bsd/setgid.c b/libc/sysdeps/unix/bsd/setgid.c
new file mode 100644
index 000000000..3d1fd3196
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/setgid.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1991, 1993, 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+/* Set the group ID of the calling process to GID.
+ If the calling process is the super-user, the real
+ and effective group IDs, and the saved set-group-ID to GID;
+ if not, the effective group ID is set to GID. */
+int
+__setgid (gid)
+ gid_t gid;
+{
+ return __setregid (gid, gid);
+}
+
+weak_alias (__setgid, setgid)
diff --git a/libc/sysdeps/unix/bsd/setrgid.c b/libc/sysdeps/unix/bsd/setrgid.c
new file mode 100644
index 000000000..9083afd13
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/setrgid.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <unistd.h>
+#include <sys/types.h>
+
+int
+setrgid (gid)
+ gid_t gid;
+{
+ return __setregid (gid, -1);
+}
diff --git a/libc/sysdeps/unix/bsd/setruid.c b/libc/sysdeps/unix/bsd/setruid.c
new file mode 100644
index 000000000..adaff4e48
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/setruid.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <unistd.h>
+#include <sys/types.h>
+
+int
+setruid (uid)
+ uid_t uid;
+{
+ return __setreuid (uid, -1);
+}
diff --git a/libc/sysdeps/unix/bsd/setsid.c b/libc/sysdeps/unix/bsd/setsid.c
new file mode 100644
index 000000000..b09ad3c5b
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/setsid.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+/* Create a new session with the calling process as its leader.
+ The process group IDs of the session and the calling process
+ are set to the process ID of the calling process, which is returned. */
+int
+__setsid ()
+{
+ pid_t pid = getpid ();
+ int tty;
+ int save = errno;
+
+ if (__getpgid (pid) == pid)
+ {
+ /* Already the leader. */
+ __set_errno (EPERM);
+ return -1;
+ }
+
+ if (setpgid (pid, pid) < 0)
+ return -1;
+
+ tty = open ("/dev/tty", 0);
+ if (tty < 0)
+ {
+ __set_errno (save);
+ return 0;
+ }
+ (void) __ioctl (tty, TIOCNOTTY, 0);
+ (void) __close (tty);
+
+ __set_errno (save);
+ return 0;
+}
+
+weak_alias (__setsid, setsid)
diff --git a/libc/sysdeps/unix/bsd/setuid.c b/libc/sysdeps/unix/bsd/setuid.c
new file mode 100644
index 000000000..5a37f5c85
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/setuid.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1991, 1993, 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+/* Set the user ID of the calling process to UID.
+ If the calling process is the super-user, the real
+ and effective user IDs, and the saved set-user-ID to UID;
+ if not, the effective user ID is set to UID. */
+int
+__setuid (uid)
+ uid_t uid;
+{
+ return __setreuid (uid, uid);
+}
+
+weak_alias (__setuid, setuid)
diff --git a/libc/sysdeps/unix/bsd/sigaction.c b/libc/sysdeps/unix/bsd/sigaction.c
new file mode 100644
index 000000000..ba73400af
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/sigaction.c
@@ -0,0 +1,63 @@
+/* Copyright (C) 1991,1995,1996,1997,2002,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <stddef.h>
+#include <signal.h>
+
+
+/* If ACT is not NULL, change the action for SIG to *ACT.
+ If OACT is not NULL, put the old action for SIG in *OACT. */
+int
+__sigaction (sig, act, oact)
+ int sig;
+ const struct sigaction *act;
+ struct sigaction *oact;
+{
+ struct sigvec vec, ovec;
+
+ if (sig <= 0 || sig >= NSIG)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (act != NULL)
+ {
+ vec.sv_mask = act->sa_mask;
+ vec.sv_handler = act->sa_handler;
+ vec.sv_flags = (((act->sa_flags & SA_ONSTACK) ? SV_ONSTACK : 0) |
+ (!(act->sa_flags & SA_RESTART) ? SV_INTERRUPT : 0));
+ }
+
+ if (__sigvec(sig, act != NULL ? &vec : (struct sigvec *) NULL, &ovec) < 0)
+ return -1;
+
+ if (oact != NULL)
+ {
+ oact->sa_handler = (void (*) (int)) ovec.sv_handler;
+ oact->sa_mask = ovec.sv_mask;
+ oact->sa_flags = (((ovec.sv_flags & SV_ONSTACK) ? SA_ONSTACK : 0) |
+ (!(ovec.sv_flags & SV_INTERRUPT) ? SA_RESTART : 0));
+ }
+
+ return 0;
+}
+libc_hidden_def (__sigaction)
+weak_alias (__sigaction, sigaction)
diff --git a/libc/sysdeps/unix/bsd/sigprocmask.c b/libc/sysdeps/unix/bsd/sigprocmask.c
new file mode 100644
index 000000000..5ad137e02
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/sigprocmask.c
@@ -0,0 +1,66 @@
+/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <signal.h>
+
+
+/* If SET is not NULL, modify the current set of blocked signals
+ according to HOW, which may be SIG_BLOCK, SIG_UNBLOCK or SIG_SETMASK.
+ If OSET is not NULL, store the old set of blocked signals in *OSET. */
+int
+__sigprocmask (how, set, oset)
+ int how;
+ const sigset_t *set;
+ sigset_t *oset;
+{
+ int mask;
+
+ if (set != NULL)
+ {
+ mask = *set;
+ switch (how)
+ {
+ case SIG_BLOCK:
+ mask = __sigblock (mask);
+ break;
+
+ case SIG_UNBLOCK:
+ mask = __sigblock (0) & ~mask;
+ /* Fall through. */
+
+ case SIG_SETMASK:
+ mask = __sigsetmask (mask);
+ break;
+
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+ else
+ mask = __sigblock (0);
+
+ if (oset != NULL)
+ *oset = mask;
+
+ return 0;
+}
+
+weak_alias (__sigprocmask, sigprocmask)
diff --git a/libc/sysdeps/unix/bsd/sigsuspend.c b/libc/sysdeps/unix/bsd/sigsuspend.c
new file mode 100644
index 000000000..0d62ce218
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/sigsuspend.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 1991, 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <stddef.h>
+#include <unistd.h>
+
+
+/* Change the set of blocked signals to SET,
+ wait until a signal arrives, and restore the set of blocked signals. */
+int
+__sigsuspend (set)
+ const sigset_t *set;
+{
+ int mask;
+ int sig;
+
+ if (set == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ mask = 0;
+ for (sig = 1; sig <= NSIG; ++sig)
+ if (__sigismember (set, sig))
+ mask |= sigmask (sig);
+
+ return __sigpause (mask, 0);
+}
+libc_hidden_def (__sigsuspend)
+weak_alias (__sigsuspend, sigsuspend)
diff --git a/libc/sysdeps/unix/bsd/stty.c b/libc/sysdeps/unix/bsd/stty.c
new file mode 100644
index 000000000..a995cd0db
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/stty.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sgtty.h>
+
+/* Set the terminal parameters associated with FD to *PARAMS. */
+int
+stty (fd, params)
+ int fd;
+ const struct sgttyb *params;
+{
+ return ioctl (fd, TIOCSETP, (void *) params);
+}
diff --git a/libc/sysdeps/unix/bsd/sys/reboot.h b/libc/sysdeps/unix/bsd/sys/reboot.h
new file mode 100644
index 000000000..76c2380b2
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/sys/reboot.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)reboot.h 8.1 (Berkeley) 6/2/93
+ */
+
+/*
+ * Arguments to reboot system call.
+ * These are passed to boot program in r11,
+ * and on to init.
+ */
+#define RB_AUTOBOOT 0 /* flags for system auto-booting itself */
+
+#define RB_ASKNAME 0x01 /* ask for file name to reboot from */
+#define RB_SINGLE 0x02 /* reboot to single user only */
+#define RB_NOSYNC 0x04 /* don't sync before reboot */
+#define RB_HALT 0x08 /* don't reboot, just halt */
+#define RB_INITNAME 0x10 /* name given for /etc/init (unused) */
+#define RB_DFLTROOT 0x20 /* use compiled-in rootdev */
+#define RB_KDB 0x40 /* give control to kernel debugger */
+#define RB_RDONLY 0x80 /* mount root fs read-only */
+#define RB_DUMP 0x100 /* dump kernel memory before reboot */
+#define RB_MINIROOT 0x200 /* mini-root present in memory at boot time */
+
+/*
+ * Constants for converting boot-style device number to type,
+ * adaptor (uba, mba, etc), unit number and partition number.
+ * Type (== major device number) is in the low byte
+ * for backward compatibility. Except for that of the "magic
+ * number", each mask applies to the shifted value.
+ * Format:
+ * (4) (4) (4) (4) (8) (8)
+ * --------------------------------
+ * |MA | AD| CT| UN| PART | TYPE |
+ * --------------------------------
+ */
+#define B_ADAPTORSHIFT 24
+#define B_ADAPTORMASK 0x0f
+#define B_ADAPTOR(val) (((val) >> B_ADAPTORSHIFT) & B_ADAPTORMASK)
+#define B_CONTROLLERSHIFT 20
+#define B_CONTROLLERMASK 0xf
+#define B_CONTROLLER(val) (((val)>>B_CONTROLLERSHIFT) & B_CONTROLLERMASK)
+#define B_UNITSHIFT 16
+#define B_UNITMASK 0xf
+#define B_UNIT(val) (((val) >> B_UNITSHIFT) & B_UNITMASK)
+#define B_PARTITIONSHIFT 8
+#define B_PARTITIONMASK 0xff
+#define B_PARTITION(val) (((val) >> B_PARTITIONSHIFT) & B_PARTITIONMASK)
+#define B_TYPESHIFT 0
+#define B_TYPEMASK 0xff
+#define B_TYPE(val) (((val) >> B_TYPESHIFT) & B_TYPEMASK)
+
+#define B_MAGICMASK ((u_long)0xf0000000)
+#define B_DEVMAGIC ((u_long)0xa0000000)
+
+#define MAKEBOOTDEV(type, adaptor, controller, unit, partition) \
+ (((type) << B_TYPESHIFT) | ((adaptor) << B_ADAPTORSHIFT) | \
+ ((controller) << B_CONTROLLERSHIFT) | ((unit) << B_UNITSHIFT) | \
+ ((partition) << B_PARTITIONSHIFT) | B_DEVMAGIC)
diff --git a/libc/sysdeps/unix/bsd/syscalls.list b/libc/sysdeps/unix/bsd/syscalls.list
new file mode 100644
index 000000000..e84819dc1
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/syscalls.list
@@ -0,0 +1,14 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+flock - flock 2 __flock flock
+getdents - getdirentries 4 __getdirentries getdirentries
+getdtsz - getdtablesize 0 __getdtablesize getdtablesize
+getpagesize - getpagesize 0 __getpagesize getpagesize
+killpg - killpg 2 killpg
+sigblock - sigblock 1 __sigblock sigblock
+sigpause - sigpause 1 __sigpause sigpause
+sigsetmask - sigsetmask 1 __sigsetmask sigsetmask
+sigstack - sigstack 2 sigstack
+sigvec - sigvec 3 __sigvec sigvec
+wait3 - wait3 3 __wait3 wait3
+waitpid - waitpid 3 __waitpid waitpid
diff --git a/libc/sysdeps/unix/bsd/tcdrain.c b/libc/sysdeps/unix/bsd/tcdrain.c
new file mode 100644
index 000000000..7dd60759e
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/tcdrain.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include "bsdtty.h"
+
+/* Wait for pending output to be written on FD. */
+int
+__libc_tcdrain (int fd)
+{
+ /* The TIOCSETP control waits for pending output to be written before
+ affecting its changes, so we use that without changing anything. */
+ struct sgttyb b;
+ if (__ioctl (fd, TIOCGETP, (void *) &b) < 0 ||
+ __ioctl (fd, TIOCSETP, (void *) &b) < 0)
+ return -1;
+ return 0;
+}
+weak_alias (__libc_tcdrain, tcdrain)
diff --git a/libc/sysdeps/unix/bsd/tcflow.c b/libc/sysdeps/unix/bsd/tcflow.c
new file mode 100644
index 000000000..b3b6f8e11
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/tcflow.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 1991, 1992, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include "bsdtty.h"
+
+/* Suspend or restart transmission on FD. */
+int
+tcflow (fd, action)
+ int fd;
+ int action;
+{
+ switch (action)
+ {
+ case TCOOFF:
+ return __ioctl (fd, TIOCSTOP, (void *) NULL);
+ case TCOON:
+ return __ioctl (fd, TIOCSTART, (void *) NULL);
+
+ case TCIOFF:
+ case TCION:
+ {
+ /* This just writes the START or STOP character with
+ `write'. Is there another way to do this? */
+ struct termios attr;
+ unsigned char c;
+ if (tcgetattr (fd, &attr) < 0)
+ return -1;
+ c = attr.c_cc[action == TCIOFF ? VSTOP : VSTART];
+ if (c != _POSIX_VDISABLE && write (fd, &c, 1) < 1)
+ return -1;
+ return 0;
+ }
+
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+}
diff --git a/libc/sysdeps/unix/bsd/tcflush.c b/libc/sysdeps/unix/bsd/tcflush.c
new file mode 100644
index 000000000..9b5d3445c
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/tcflush.c
@@ -0,0 +1,51 @@
+/* Copyright (C) 1991, 1992, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <termios.h>
+#include <unistd.h>
+#include "bsdtty.h"
+#include <sys/file.h>
+
+/* Flush pending data on FD. */
+int
+tcflush (fd, queue_selector)
+ int fd;
+ int queue_selector;
+{
+ int arg;
+
+ switch (queue_selector)
+ {
+ case TCIFLUSH:
+ arg = FREAD;
+ break;
+ case TCOFLUSH:
+ arg = FWRITE;
+ break;
+ case TCIOFLUSH:
+ arg = FREAD | FWRITE;
+ break;
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return __ioctl (fd, TIOCFLUSH, (void *) &arg);
+}
diff --git a/libc/sysdeps/unix/bsd/tcgetattr.c b/libc/sysdeps/unix/bsd/tcgetattr.c
new file mode 100644
index 000000000..5743ffa4b
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/tcgetattr.c
@@ -0,0 +1,130 @@
+/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <termios.h>
+
+#include "bsdtty.h"
+
+extern const speed_t __bsd_speeds[]; /* Defined in tcsetattr.c. */
+
+/* Put the state of FD into *TERMIOS_P. */
+int
+__tcgetattr (fd, termios_p)
+ int fd;
+ struct termios *termios_p;
+{
+ struct sgttyb buf;
+ struct tchars tchars;
+ struct ltchars ltchars;
+ int local;
+#ifdef TIOCGETX
+ int extra;
+#endif
+
+ if (termios_p == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (__ioctl(fd, TIOCGETP, &buf) < 0 ||
+ __ioctl(fd, TIOCGETC, &tchars) < 0 ||
+ __ioctl(fd, TIOCGLTC, &ltchars) < 0 ||
+#ifdef TIOCGETX
+ __ioctl(fd, TIOCGETX, &extra) < 0 ||
+#endif
+ __ioctl(fd, TIOCLGET, &local) < 0)
+ return -1;
+
+ termios_p->__ispeed = __bsd_speeds[(unsigned char) buf.sg_ispeed];
+ termios_p->__ospeed = __bsd_speeds[(unsigned char) buf.sg_ospeed];
+
+ termios_p->c_iflag = 0;
+ termios_p->c_oflag = 0;
+ termios_p->c_cflag = 0;
+ termios_p->c_lflag = 0;
+ termios_p->c_oflag |= CREAD | HUPCL;
+#ifdef LPASS8
+ if (local & LPASS8)
+ termios_p->c_oflag |= CS8;
+ else
+#endif
+ termios_p->c_oflag |= CS7;
+ if (!(buf.sg_flags & RAW))
+ {
+ termios_p->c_iflag |= IXON;
+ termios_p->c_cflag |= OPOST;
+#ifndef NOISIG
+ termios_p->c_lflag |= ISIG;
+#endif
+ }
+ if ((buf.sg_flags & (CBREAK|RAW)) == 0)
+ termios_p->c_lflag |= ICANON;
+ if (!(buf.sg_flags & RAW) && !(local & LLITOUT))
+ termios_p->c_oflag |= OPOST;
+ if (buf.sg_flags & CRMOD)
+ termios_p->c_iflag |= ICRNL;
+ if (buf.sg_flags & TANDEM)
+ termios_p->c_iflag |= IXOFF;
+#ifdef TIOCGETX
+ if (!(extra & NOISIG))
+ termios_p->c_lflag |= ISIG;
+ if (extra & STOPB)
+ termios_p->c_cflag |= CSTOPB;
+#endif
+
+ switch (buf.sg_flags & (EVENP|ODDP))
+ {
+ case EVENP|ODDP:
+ break;
+ case ODDP:
+ termios_p->c_cflag |= PARODD;
+ default:
+ termios_p->c_cflag |= PARENB;
+ termios_p->c_iflag |= IGNPAR | INPCK;
+ break;
+ }
+ if (buf.sg_flags & ECHO)
+ termios_p->c_lflag |= _ECHO;
+ if (local & LCRTERA)
+ termios_p->c_lflag |= ECHOE;
+ if (local & LCRTKIL)
+ termios_p->c_lflag |= ECHOK;
+ if (local & LTOSTOP)
+ termios_p->c_lflag |= _TOSTOP;
+ if (local & LNOFLSH)
+ termios_p->c_lflag |= _NOFLSH;
+
+ termios_p->c_cc[VEOF] = tchars.t_eofc;
+ termios_p->c_cc[VEOL] = '\n';
+ termios_p->c_cc[VERASE] = buf.sg_erase;
+ termios_p->c_cc[VKILL] = buf.sg_kill;
+ termios_p->c_cc[VINTR] = tchars.t_intrc;
+ termios_p->c_cc[VQUIT] = tchars.t_quitc;
+ termios_p->c_cc[VSTART] = tchars.t_startc;
+ termios_p->c_cc[VSTOP] = tchars.t_stopc;
+ termios_p->c_cc[VSUSP] = ltchars.t_suspc;
+ termios_p->c_cc[VMIN] = -1;
+ termios_p->c_cc[VTIME] = -1;
+
+ return 0;
+}
+
+weak_alias (__tcgetattr, tcgetattr)
diff --git a/libc/sysdeps/unix/bsd/tcgetpgrp.c b/libc/sysdeps/unix/bsd/tcgetpgrp.c
new file mode 100644
index 000000000..0ccadef87
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/tcgetpgrp.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1991, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+/* Return the foreground process group ID of FD. */
+pid_t
+tcgetpgrp (fd)
+ int fd;
+{
+ int pgrp;
+
+ if (__ioctl (fd, TIOCGPGRP, &pgrp) < 0)
+ return (pid_t) -1;
+ return (pid_t) pgrp;
+}
+libc_hidden_def (tcgetpgrp)
diff --git a/libc/sysdeps/unix/bsd/tcsendbrk.c b/libc/sysdeps/unix/bsd/tcsendbrk.c
new file mode 100644
index 000000000..e8583be53
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/tcsendbrk.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 1991, 1992, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <signal.h>
+#include <termios.h>
+#include <unistd.h>
+#include "bsdtty.h"
+#include <sys/file.h>
+#include <sys/time.h>
+#include <sys/types.h>
+
+/* Send zero bits on FD. */
+int
+tcsendbreak (fd, duration)
+ int fd;
+ int duration;
+{
+ struct timeval delay;
+
+ /* The break lasts 0.25 to 0.5 seconds if DURATION is zero,
+ and an implementation-defined period if DURATION is nonzero.
+ We define a positive DURATION to be number of microseconds to break. */
+ if (duration <= 0)
+ duration = 400000;
+
+ delay.tv_sec = 0;
+ delay.tv_usec = duration;
+
+ /* Starting sending break. */
+ if (__ioctl (fd, TIOCSBRK, (void *) NULL) < 0)
+ return -1;
+
+ /* Wait DURATION microseconds. */
+ (void) __select (0, (fd_set *) NULL, (fd_set *) NULL, (fd_set *) NULL,
+ &delay);
+
+ /* Turn off the break. */
+ return __ioctl (fd, TIOCCBRK, (void *) NULL);
+}
diff --git a/libc/sysdeps/unix/bsd/tcsetattr.c b/libc/sysdeps/unix/bsd/tcsetattr.c
new file mode 100644
index 000000000..fd390cd88
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/tcsetattr.c
@@ -0,0 +1,188 @@
+/* Copyright (C) 1991, 1993, 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <termios.h>
+
+#include "bsdtty.h"
+
+
+const speed_t __bsd_speeds[] =
+ {
+ 0,
+ 50,
+ 75,
+ 110,
+ 134,
+ 150,
+ 200,
+ 300,
+ 600,
+ 1200,
+ 1800,
+ 2400,
+ 4800,
+ 9600,
+ 19200,
+ 38400,
+ };
+
+
+/* Set the state of FD to *TERMIOS_P. */
+int
+tcsetattr (fd, optional_actions, termios_p)
+ int fd;
+ int optional_actions;
+ const struct termios *termios_p;
+{
+ struct sgttyb buf;
+ struct tchars tchars;
+ struct ltchars ltchars;
+ int local;
+#ifdef TIOCGETX
+ int extra;
+#endif
+ size_t i;
+
+ if (__ioctl (fd, TIOCGETP, &buf) < 0 ||
+ __ioctl (fd, TIOCGETC, &tchars) < 0 ||
+ __ioctl (fd, TIOCGLTC, &ltchars) < 0 ||
+#ifdef TIOCGETX
+ __ioctl (fd, TIOCGETX, &extra) < 0 ||
+#endif
+ __ioctl (fd, TIOCLGET, &local) < 0)
+ return -1;
+
+ if (termios_p == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ switch (optional_actions)
+ {
+ case TCSANOW:
+ break;
+ case TCSADRAIN:
+ if (tcdrain (fd) < 0)
+ return -1;
+ break;
+ case TCSAFLUSH:
+ if (tcflush (fd, TCIFLUSH) < 0)
+ return -1;
+ break;
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ buf.sg_ispeed = buf.sg_ospeed = -1;
+ for (i = 0; i <= sizeof (__bsd_speeds) / sizeof (__bsd_speeds[0]); ++i)
+ {
+ if (__bsd_speeds[i] == termios_p->__ispeed)
+ buf.sg_ispeed = i;
+ if (__bsd_speeds[i] == termios_p->__ospeed)
+ buf.sg_ospeed = i;
+ }
+ if (buf.sg_ispeed == -1 || buf.sg_ospeed == -1)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ buf.sg_flags &= ~(CBREAK|RAW);
+ if (!(termios_p->c_lflag & ICANON))
+ buf.sg_flags |= (termios_p->c_cflag & ISIG) ? CBREAK : RAW;
+#ifdef LPASS8
+ if (termios_p->c_oflag & CS8)
+ local |= LPASS8;
+ else
+ local &= ~LPASS8;
+#endif
+ if (termios_p->c_lflag & _NOFLSH)
+ local |= LNOFLSH;
+ else
+ local &= ~LNOFLSH;
+ if (termios_p->c_oflag & OPOST)
+ local &= ~LLITOUT;
+ else
+ local |= LLITOUT;
+#ifdef TIOCGETX
+ if (termios_p->c_lflag & ISIG)
+ extra &= ~NOISIG;
+ else
+ extra |= NOISIG;
+ if (termios_p->c_cflag & CSTOPB)
+ extra |= STOPB;
+ else
+ extra &= ~STOPB;
+#endif
+ if (termios_p->c_iflag & ICRNL)
+ buf.sg_flags |= CRMOD;
+ else
+ buf.sg_flags &= ~CRMOD;
+ if (termios_p->c_iflag & IXOFF)
+ buf.sg_flags |= TANDEM;
+ else
+ buf.sg_flags &= ~TANDEM;
+
+ buf.sg_flags &= ~(ODDP|EVENP);
+ if (!(termios_p->c_cflag & PARENB))
+ buf.sg_flags |= ODDP | EVENP;
+ else if (termios_p->c_cflag & PARODD)
+ buf.sg_flags |= ODDP;
+ else
+ buf.sg_flags |= EVENP;
+
+ if (termios_p->c_lflag & _ECHO)
+ buf.sg_flags |= ECHO;
+ else
+ buf.sg_flags &= ~ECHO;
+ if (termios_p->c_lflag & ECHOE)
+ local |= LCRTERA;
+ else
+ local &= ~LCRTERA;
+ if (termios_p->c_lflag & ECHOK)
+ local |= LCRTKIL;
+ else
+ local &= ~LCRTKIL;
+ if (termios_p->c_lflag & _TOSTOP)
+ local |= LTOSTOP;
+ else
+ local &= ~LTOSTOP;
+
+ buf.sg_erase = termios_p->c_cc[VERASE];
+ buf.sg_kill = termios_p->c_cc[VKILL];
+ tchars.t_eofc = termios_p->c_cc[VEOF];
+ tchars.t_intrc = termios_p->c_cc[VINTR];
+ tchars.t_quitc = termios_p->c_cc[VQUIT];
+ ltchars.t_suspc = termios_p->c_cc[VSUSP];
+ tchars.t_startc = termios_p->c_cc[VSTART];
+ tchars.t_stopc = termios_p->c_cc[VSTOP];
+
+ if (__ioctl (fd, TIOCSETP, &buf) < 0 ||
+ __ioctl (fd, TIOCSETC, &tchars) < 0 ||
+ __ioctl (fd, TIOCSLTC, &ltchars) < 0 ||
+#ifdef TIOCGETX
+ __ioctl (fd, TIOCSETX, &extra) < 0 ||
+#endif
+ __ioctl (fd, TIOCLSET, &local) < 0)
+ return -1;
+ return 0;
+}
+libc_hidden_def (tcsetattr)
diff --git a/libc/sysdeps/unix/bsd/tcsetpgrp.c b/libc/sysdeps/unix/bsd/tcsetpgrp.c
new file mode 100644
index 000000000..ea7e4cc72
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/tcsetpgrp.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <unistd.h>
+
+/* Set the foreground process group ID of FD set PGRP_ID. */
+int
+tcsetpgrp (fd, pgrp_id)
+ int fd;
+ pid_t pgrp_id;
+{
+ return __ioctl (fd, TIOCSPGRP, &pgrp_id);
+}
diff --git a/libc/sysdeps/unix/bsd/telldir.c b/libc/sysdeps/unix/bsd/telldir.c
new file mode 100644
index 000000000..3d625c65d
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/telldir.c
@@ -0,0 +1,116 @@
+/* Copyright (C) 1994, 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include "dirstream.h"
+
+/* Internal data structure for telldir and seekdir. */
+struct record
+ {
+ struct record *next; /* Link in chain. */
+ off_t cookie; /* Value returned by `telldir'. */
+ off_t pos;
+ size_t offset;
+ };
+#define NBUCKETS 32
+static struct record *records[32];
+static off_t lastpos;
+__libc_lock_define_initialized(static, lock) /* Locks above data. */
+
+
+/* Return the current position of DIRP. */
+long int
+telldir (dirp)
+ DIR *dirp;
+{
+ struct record *new;
+ long int pos;
+
+ new = malloc (sizeof *new);
+ if (new == NULL)
+ return -1l;
+
+ __libc_lock_lock (lock);
+
+ new->pos = dirp->filepos;
+ new->offset = dirp->offset;
+ new->cookie = ++lastpos;
+ new->next = records[new->cookie % NBUCKETS];
+ records[new->cookie % NBUCKETS] = new;
+
+ pos = new->cookie;
+
+ __libc_lock_unlock (lock);
+
+ return pos;
+}
+
+
+
+/* Seek to position POS in DIRP. */
+void
+seekdir (dirp, pos)
+ DIR *dirp;
+ long int pos;
+{
+ struct record *r, **prevr;
+
+ __libc_lock_lock (lock);
+
+ for (prevr = &records[pos % NBUCKETS], r = *prevr;
+ r != NULL;
+ prevr = &r->next, r = r->next)
+ if (r->cookie == pos)
+ {
+ __libc_lock_lock (dirp->__lock);
+ if (dirp->filepos != r->pos || dirp->offset != r->offset)
+ {
+ dirp->size = 0; /* Must read a fresh buffer. */
+ /* Move to the saved position. */
+ __lseek (dirp->fd, r->pos, SEEK_SET);
+ dirp->filepos = r->pos;
+ dirp->offset = 0;
+ /* Read entries until we reach the saved offset. */
+ while (dirp->offset < r->offset)
+ {
+ struct dirent *scan;
+ __libc_lock_unlock (dirp->__lock);
+ scan = readdir (dirp);
+ __libc_lock_lock (dirp->__lock);
+ if (! scan)
+ break;
+ }
+ }
+ __libc_lock_unlock (dirp->__lock);
+
+ /* To prevent leaking memory, cookies returned from telldir
+ can only be used once. So free this one's record now. */
+ *prevr = r->next;
+ free (r);
+ break;
+ }
+
+ __libc_lock_unlock (lock);
+
+ /* If we lost there is no way to indicate it. Oh well. */
+}
diff --git a/libc/sysdeps/unix/bsd/times.c b/libc/sysdeps/unix/bsd/times.c
new file mode 100644
index 000000000..d77438703
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/times.c
@@ -0,0 +1,72 @@
+/* Copyright (C) 1991,92,93,95,96,97,1998,2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/resource.h>
+#include <sys/times.h>
+#include <sys/time.h>
+#include <time.h>
+
+
+/* Time the program started. */
+extern time_t _posix_start_time;
+
+#ifdef __GNUC__
+__inline
+#endif
+static clock_t
+timeval_to_clock_t (const struct timeval *tv, clock_t clk_tck)
+{
+ return (clock_t) ((tv->tv_sec * clk_tck) +
+ (tv->tv_usec * clk_tck / 1000000L));
+}
+
+/* Store the CPU time used by this process and all its
+ dead children (and their dead children) in BUFFER.
+ Return the elapsed real time, or (clock_t) -1 for errors.
+ All times are in CLK_TCKths of a second. */
+clock_t
+__times (buffer)
+ struct tms *buffer;
+{
+ struct rusage usage;
+ clock_t clk_tck;
+
+ if (buffer == NULL)
+ {
+ __set_errno (EINVAL);
+ return (clock_t) -1;
+ }
+
+ clk_tck = __getclktck ();
+
+ if (__getrusage (RUSAGE_SELF, &usage) < 0)
+ return (clock_t) -1;
+ buffer->tms_utime = (clock_t) timeval_to_clock_t (&usage.ru_utime, clk_tck);
+ buffer->tms_stime = (clock_t) timeval_to_clock_t (&usage.ru_stime, clk_tck);
+
+ if (__getrusage (RUSAGE_CHILDREN, &usage) < 0)
+ return (clock_t) -1;
+ buffer->tms_cutime = (clock_t) timeval_to_clock_t (&usage.ru_utime, clk_tck);
+ buffer->tms_cstime = (clock_t) timeval_to_clock_t (&usage.ru_stime, clk_tck);
+
+ return (time ((time_t *) NULL) - _posix_start_time) * clk_tck;
+}
+
+weak_alias (__times, times)
diff --git a/libc/sysdeps/unix/bsd/ualarm.c b/libc/sysdeps/unix/bsd/ualarm.c
new file mode 100644
index 000000000..939ca6be2
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/ualarm.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 1991, 1997, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/time.h>
+#include <unistd.h>
+
+/* Set an alarm to go off (generating a SIGALRM signal) in VALUE microseconds.
+ If INTERVAL is nonzero, when the alarm goes off, the timer is reset to go
+ off every INTERVAL microseconds thereafter.
+
+ Returns the number of microseconds remaining before the alarm. */
+useconds_t
+ualarm (value, interval)
+ useconds_t value;
+ useconds_t interval;
+{
+ struct itimerval timer, otimer;
+
+ timer.it_value.tv_sec = 0;
+ timer.it_value.tv_usec = value;
+ timer.it_interval.tv_sec = 0;
+ timer.it_interval.tv_usec = interval;
+
+ if (__setitimer (ITIMER_REAL, &timer, &otimer) < 0)
+ return -1;
+
+ return (otimer.it_value.tv_sec * 1000000) + otimer.it_value.tv_usec;
+}
diff --git a/libc/sysdeps/unix/bsd/ulimit.c b/libc/sysdeps/unix/bsd/ulimit.c
new file mode 100644
index 000000000..963d156e2
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/ulimit.c
@@ -0,0 +1,92 @@
+/* Copyright (C) 1991,1992,1994-1998,2001,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <sysdep.h>
+#include <ulimit.h>
+#include <unistd.h>
+#include <sys/resource.h>
+
+
+extern int _etext;
+
+/* Function depends on CMD:
+ 1 = Return the limit on the size of a file, in units of 512 bytes.
+ 2 = Set the limit on the size of a file to NEWLIMIT. Only the
+ super-user can increase the limit.
+ 3 = Return the maximum possible address of the data segment.
+ 4 = Return the maximum number of files that the calling process
+ can open.
+ Returns -1 on errors. */
+long int
+ulimit (int cmd, ...)
+{
+ struct rlimit limit;
+ va_list va;
+ long int result = -1;
+
+ va_start (va, cmd);
+
+ switch (cmd)
+ {
+ case UL_GETFSIZE:
+ /* Get limit on file size. */
+ if (getrlimit (RLIMIT_FSIZE, &limit) == 0)
+ /* Convert from bytes to 512 byte units. */
+ result = limit.rlim_cur / 512;
+ break;
+
+ case UL_SETFSIZE:
+ /* Set limit on file size. */
+ {
+ long int newlimit = va_arg (va, long int);
+
+ if ((rlim_t) newlimit > RLIM_INFINITY / 512)
+ {
+ limit.rlim_cur = RLIM_INFINITY;
+ limit.rlim_max = RLIM_INFINITY;
+ }
+ else
+ {
+ limit.rlim_cur = newlimit * 512;
+ limit.rlim_max = newlimit * 512;
+ }
+
+ result = setrlimit (RLIMIT_FSIZE, &limit);
+ }
+ break;
+
+ case __UL_GETMAXBRK:
+ /* Get maximum address for `brk'. */
+ if (getrlimit (RLIMIT_DATA, &limit) == 0)
+ result = ((long int) &_etext) + limit.rlim_cur;
+ break;
+
+ case __UL_GETOPENMAX:
+ result = sysconf (_SC_OPEN_MAX);
+ break;
+
+ default:
+ __set_errno (EINVAL);
+ }
+
+ va_end (va);
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/bsd/unlockpt.c b/libc/sysdeps/unix/bsd/unlockpt.c
new file mode 100644
index 000000000..59fc7392e
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/unlockpt.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <paths.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+/* Unlock the slave pseudo terminal associated with the master pseudo
+ terminal specified by FD. */
+int
+unlockpt (int fd)
+{
+ char buf[sizeof (_PATH_TTY) + 2];
+
+ /* BSD doesn't have a lock, but it does have `revoke'. */
+ if (__ptsname_r (fd, buf, sizeof (buf)))
+ return -1;
+ return revoke (buf);
+}
diff --git a/libc/sysdeps/unix/bsd/usleep.c b/libc/sysdeps/unix/bsd/usleep.c
new file mode 100644
index 000000000..9c1049c10
--- /dev/null
+++ b/libc/sysdeps/unix/bsd/usleep.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1992, 1996, 1999, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+/* Sleep USECONDS microseconds, or until a previously set timer goes off. */
+int
+usleep (useconds)
+ useconds_t useconds;
+{
+ struct timeval delay;
+
+ delay.tv_sec = 0;
+ delay.tv_usec = useconds;
+
+ return __select (0, (fd_set *) NULL, (fd_set *) NULL, (fd_set *) NULL,
+ &delay);
+}
diff --git a/libc/sysdeps/unix/clock_gettime.c b/libc/sysdeps/unix/clock_gettime.c
new file mode 100644
index 000000000..f698f0151
--- /dev/null
+++ b/libc/sysdeps/unix/clock_gettime.c
@@ -0,0 +1,134 @@
+/* clock_gettime -- Get the current time from a POSIX clockid_t. Unix version.
+ Copyright (C) 1999-2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdint.h>
+#include <time.h>
+#include <sys/time.h>
+#include <libc-internal.h>
+#include <ldsodefs.h>
+
+
+#if HP_TIMING_AVAIL
+/* Clock frequency of the processor. We make it a 64-bit variable
+ because some jokers are already playing with processors with more
+ than 4GHz. */
+static hp_timing_t freq;
+
+
+/* This function is defined in the thread library. */
+extern int __pthread_clock_gettime (clockid_t clock_id, hp_timing_t freq,
+ struct timespec *tp)
+ __attribute__ ((__weak__));
+
+static int
+hp_timing_gettime (clockid_t clock_id, struct timespec *tp)
+{
+ hp_timing_t tsc;
+
+ if (__builtin_expect (freq == 0, 0))
+ {
+ /* This can only happen if we haven't initialized the `freq'
+ variable yet. Do this now. We don't have to protect this
+ code against multiple execution since all of them should
+ lead to the same result. */
+ freq = __get_clockfreq ();
+ if (__builtin_expect (freq == 0, 0))
+ /* Something went wrong. */
+ return -1;
+ }
+
+ if (clock_id != CLOCK_PROCESS_CPUTIME_ID
+ && __pthread_clock_gettime != NULL)
+ return __pthread_clock_gettime (clock_id, freq, tp);
+
+ /* Get the current counter. */
+ HP_TIMING_NOW (tsc);
+
+ /* Compute the offset since the start time of the process. */
+ tsc -= GL(dl_cpuclock_offset);
+
+ /* Compute the seconds. */
+ tp->tv_sec = tsc / freq;
+
+ /* And the nanoseconds. This computation should be stable until
+ we get machines with about 16GHz frequency. */
+ tp->tv_nsec = ((tsc % freq) * UINT64_C (1000000000)) / freq;
+
+ return 0;
+}
+#endif
+
+
+static inline int
+realtime_gettime (struct timespec *tp)
+{
+ struct timeval tv;
+ int retval = gettimeofday (&tv, NULL);
+ if (retval == 0)
+ /* Convert into `timespec'. */
+ TIMEVAL_TO_TIMESPEC (&tv, tp);
+ return retval;
+}
+
+
+/* Get current value of CLOCK and store it in TP. */
+int
+clock_gettime (clockid_t clock_id, struct timespec *tp)
+{
+ int retval = -1;
+ struct timeval tv;
+
+ switch (clock_id)
+ {
+#ifdef SYSDEP_GETTIME
+ SYSDEP_GETTIME;
+#endif
+
+#ifndef HANDLED_REALTIME
+ case CLOCK_REALTIME:
+ retval = gettimeofday (&tv, NULL);
+ if (retval == 0)
+ TIMEVAL_TO_TIMESPEC (&tv, tp);
+ break;
+#endif
+
+ default:
+#ifdef SYSDEP_GETTIME_CPU
+ SYSDEP_GETTIME_CPU;
+#endif
+#if HP_TIMING_AVAIL
+ if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
+ == CLOCK_THREAD_CPUTIME_ID)
+ retval = hp_timing_gettime (clock_id, tp);
+ else
+#endif
+ __set_errno (EINVAL);
+ break;
+
+#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
+ case CLOCK_PROCESS_CPUTIME_ID:
+ retval = hp_timing_gettime (clock_id, tp);
+ break;
+#endif
+ }
+
+ return retval;
+}
+librt_hidden_def (clock_gettime)
diff --git a/libc/sysdeps/unix/clock_nanosleep.c b/libc/sysdeps/unix/clock_nanosleep.c
new file mode 100644
index 000000000..248bfe1c9
--- /dev/null
+++ b/libc/sysdeps/unix/clock_nanosleep.c
@@ -0,0 +1,101 @@
+/* High-resolution sleep with the specified clock.
+ Copyright (C) 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <time.h>
+#include <hp-timing.h>
+#include <sysdep-cancel.h>
+
+#if HP_TIMING_AVAIL
+# define CPUCLOCK_P(clock) \
+ ((clock) == CLOCK_PROCESS_CPUTIME_ID \
+ || ((clock) & ((1 << CLOCK_IDFIELD_SIZE) - 1)) == CLOCK_THREAD_CPUTIME_ID)
+#else
+# define CPUCLOCK_P(clock) 0
+#endif
+
+#ifndef INVALID_CLOCK_P
+# define INVALID_CLOCK_P(cl) \
+ ((cl) < CLOCK_REALTIME || (cl) > CLOCK_THREAD_CPUTIME_ID)
+#endif
+
+
+/* This implementation assumes that these is only a `nanosleep' system
+ call. So we have to remap all other activities. */
+int
+clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
+ struct timespec *rem)
+{
+ struct timespec now;
+
+ if (__builtin_expect (req->tv_nsec, 0) < 0
+ || __builtin_expect (req->tv_nsec, 0) >= 1000000000)
+ return EINVAL;
+
+ if (clock_id == CLOCK_THREAD_CPUTIME_ID)
+ return EINVAL; /* POSIX specifies EINVAL for this case. */
+
+#ifdef SYSDEP_NANOSLEEP
+ SYSDEP_NANOSLEEP;
+#endif
+
+ if (CPUCLOCK_P (clock_id))
+ return ENOTSUP;
+
+ if (INVALID_CLOCK_P (clock_id))
+ return EINVAL;
+
+ /* If we got an absolute time, remap it. */
+ if (flags == TIMER_ABSTIME)
+ {
+ long int nsec;
+ long int sec;
+
+ /* Make sure we use safe data types. */
+ assert (sizeof (sec) >= sizeof (now.tv_sec));
+
+ /* Get the current time for this clock. */
+ if (__builtin_expect (clock_gettime (clock_id, &now), 0) != 0)
+ return errno;
+
+ /* Compute the difference. */
+ nsec = req->tv_nsec - now.tv_nsec;
+ sec = req->tv_sec - now.tv_sec - (nsec < 0);
+ if (sec < 0)
+ /* The time has already elapsed. */
+ return 0;
+
+ now.tv_sec = sec;
+ now.tv_nsec = nsec + (nsec < 0 ? 1000000000 : 0);
+
+ /* From now on this is our time. */
+ req = &now;
+
+ /* Make sure we are not modifying the struct pointed to by REM. */
+ rem = NULL;
+ }
+ else if (__builtin_expect (flags, 0) != 0)
+ return EINVAL;
+ else if (clock_id != CLOCK_REALTIME)
+ /* Not supported. */
+ return ENOTSUP;
+
+ return __builtin_expect (nanosleep (req, rem), 0) ? errno : 0;
+}
diff --git a/libc/sysdeps/unix/clock_settime.c b/libc/sysdeps/unix/clock_settime.c
new file mode 100644
index 000000000..a93be6349
--- /dev/null
+++ b/libc/sysdeps/unix/clock_settime.c
@@ -0,0 +1,129 @@
+/* Copyright (C) 1999-2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+#include <libc-internal.h>
+#include <ldsodefs.h>
+
+
+#if HP_TIMING_AVAIL
+/* Clock frequency of the processor. We make it a 64-bit variable
+ because some jokers are already playing with processors with more
+ than 4GHz. */
+static hp_timing_t freq;
+
+
+/* This function is defined in the thread library. */
+extern void __pthread_clock_settime (clockid_t clock_id, hp_timing_t offset)
+ __attribute__ ((__weak__));
+#endif
+
+
+#if HP_TIMING_AVAIL
+static int
+hp_timing_settime (clockid_t clock_id, const struct timespec *tp)
+{
+ hp_timing_t tsc;
+ hp_timing_t usertime;
+
+ /* First thing is to get the current time. */
+ HP_TIMING_NOW (tsc);
+
+ if (__builtin_expect (freq == 0, 0))
+ {
+ /* This can only happen if we haven't initialized the `freq'
+ variable yet. Do this now. We don't have to protect this
+ code against multiple execution since all of them should lead
+ to the same result. */
+ freq = __get_clockfreq ();
+ if (__builtin_expect (freq == 0, 0))
+ /* Something went wrong. */
+ return -1;
+ }
+
+ /* Convert the user-provided time into CPU ticks. */
+ usertime = tp->tv_sec * freq + (tp->tv_nsec * freq) / 1000000000ull;
+
+ /* Determine the offset and use it as the new base value. */
+ if (clock_id == CLOCK_PROCESS_CPUTIME_ID
+ || __pthread_clock_settime == NULL)
+ GL(dl_cpuclock_offset) = tsc - usertime;
+ else
+ __pthread_clock_settime (clock_id, tsc - usertime);
+
+ return 0;
+}
+#endif
+
+
+/* Set CLOCK to value TP. */
+int
+clock_settime (clockid_t clock_id, const struct timespec *tp)
+{
+ int retval;
+
+ /* Make sure the time cvalue is OK. */
+ if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ switch (clock_id)
+ {
+#define HANDLE_REALTIME \
+ do { \
+ struct timeval tv; \
+ TIMESPEC_TO_TIMEVAL (&tv, tp); \
+ \
+ retval = settimeofday (&tv, NULL); \
+ } while (0)
+
+#ifdef SYSDEP_SETTIME
+ SYSDEP_SETTIME;
+#endif
+
+#ifndef HANDLED_REALTIME
+ case CLOCK_REALTIME:
+ HANDLE_REALTIME;
+ break;
+#endif
+
+ default:
+#ifdef SYSDEP_SETTIME_CPU
+ SYSDEP_SETTIME_CPU;
+#endif
+#ifndef HANDLED_CPUTIME
+# if HP_TIMING_AVAIL
+ if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID
+ || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID)
+ retval = hp_timing_settime (clock_id, tp);
+ else
+# endif
+ {
+ __set_errno (EINVAL);
+ retval = -1;
+ }
+#endif
+ break;
+ }
+
+ return retval;
+}
diff --git a/libc/sysdeps/unix/closedir.c b/libc/sysdeps/unix/closedir.c
new file mode 100644
index 000000000..09deee7e8
--- /dev/null
+++ b/libc/sysdeps/unix/closedir.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 1991,1993,1995,1996,1998,2002,2003
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <dirstream.h>
+#include <not-cancel.h>
+
+
+/* Close the directory stream DIRP.
+ Return 0 if successful, -1 if not. */
+int
+__closedir (DIR *dirp)
+{
+ int fd;
+
+ if (dirp == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* We do not try to synchronize access here. If some other thread
+ still uses this handle it is a big mistake and that thread
+ deserves all the bad data it gets. */
+
+ fd = dirp->fd;
+
+ __libc_lock_fini (dirp->lock);
+
+ free ((void *) dirp);
+
+ return close_not_cancel (fd);
+}
+weak_alias (__closedir, closedir)
diff --git a/libc/sysdeps/unix/common/.cvsignore b/libc/sysdeps/unix/common/.cvsignore
new file mode 100644
index 000000000..1f69fd919
--- /dev/null
+++ b/libc/sysdeps/unix/common/.cvsignore
@@ -0,0 +1,4 @@
+*.gz *.Z *.tar *.tgz
+=*
+TODO COPYING* AUTHORS copyr-* copying.*
+glibc-*
diff --git a/libc/sysdeps/unix/common/bits/dirent.h b/libc/sysdeps/unix/common/bits/dirent.h
new file mode 100644
index 000000000..666a89fe1
--- /dev/null
+++ b/libc/sysdeps/unix/common/bits/dirent.h
@@ -0,0 +1,33 @@
+/* Directory entry structure `struct dirent'. SVR4 version.
+ Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _DIRENT_H
+# error "Never use <bits/dirent.h> directly; include <dirent.h> instead."
+#endif
+
+struct dirent
+ {
+ unsigned int d_fileno;
+ int d_off; /* Position in directory of following entry. */
+ unsigned short int d_reclen;
+ char d_name[1]; /* Variable length. */
+ };
+
+#define _DIRENT_HAVE_D_RECLEN 1
+#define _DIRENT_HAVE_D_OFF 1
diff --git a/libc/sysdeps/unix/common/bits/fcntl.h b/libc/sysdeps/unix/common/bits/fcntl.h
new file mode 100644
index 000000000..5bf6791b5
--- /dev/null
+++ b/libc/sysdeps/unix/common/bits/fcntl.h
@@ -0,0 +1,120 @@
+/* O_*, F_*, FD_* bit values for general Unix system.
+ Copyright (C) 1991, 1992, 1995, 1997, 2000, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+
+/* File access modes for `open' and `fcntl'. */
+#define O_RDONLY 0 /* Open read-only. */
+#define O_WRONLY 1 /* Open write-only. */
+#define O_RDWR 2 /* Open read/write. */
+
+
+/* Bits OR'd into the second argument to open. */
+#define O_CREAT 0x0100 /* Create file if it doesn't exist. */
+#define O_EXCL 0x0400 /* Fail if file already exists. */
+#define O_TRUNC 0x0200 /* Truncate file to zero length. */
+#define O_NOCTTY 0x0800 /* Don't assign a controlling terminal. */
+#ifdef __USE_MISC
+# define O_ASYNC 0x0040 /* Send SIGIO to owner when data is ready. */
+# define O_FSYNC 0x0010 /* Synchronous writes. */
+# define O_SYNC O_FSYNC
+#endif
+
+/* File status flags for `open' and `fcntl'. */
+#define O_APPEND 0x0008 /* Writes append to the file. */
+#define O_NONBLOCK 0x0080 /* Non-blocking I/O. */
+
+#ifdef __USE_MISC
+# define O_NDELAY 0x0004
+#endif
+
+#ifdef __USE_MISC
+/* Bits in the file status flags returned by F_GETFL.
+ These are all the O_* flags, plus FREAD and FWRITE, which are
+ independent bits set by which of O_RDONLY, O_WRONLY, and O_RDWR, was
+ given to `open'. */
+# define FREAD 1
+# define FWRITE 2
+
+/* Traditional Unix names the O_* bits. */
+# define FASYNC O_ASYNC
+# define FCREAT O_CREAT
+# define FEXCL O_EXCL
+# define FTRUNC O_TRUNC
+# define FNOCTTY O_NOCTTY
+# define FFSYNC O_FSYNC
+# define FSYNC O_SYNC
+# define FAPPEND O_APPEND
+# define FNONBLOCK O_NONBLOCK
+# define FNONBIO O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif
+
+/* Mask for file access modes. This is system-dependent in case
+ some system ever wants to define some other flavor of access. */
+#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#if defined __USE_BSD || defined __USE_UNIX98
+# define F_GETOWN 23 /* Get owner (receiver of SIGIO). */
+# define F_SETOWN 24 /* Set owner (receiver of SIGIO). */
+#endif
+#define F_GETLK 14 /* Get record locking info. */
+#define F_SETLK 6 /* Set record locking info (non-blocking). */
+#define F_SETLKW 7 /* Set record locking info (blocking). */
+#ifdef __USE_SVID
+# define F_ALLOCSP 10 /* Allocate space in the file. */
+# define F_FREESP 11 /* Free space in the file. */
+# define F_RGETLK 20 /* Get remote record locking info. */
+# define F_RSETLK 21 /* Set remote locking info (non-blocking). */
+# define F_RSETLKW 22 /* Set remote locking info (blocking). */
+#endif
+
+/* File descriptor flags used with F_GETFD and F_SETFD. */
+#define FD_CLOEXEC 1 /* Close on exec. */
+
+
+#include <bits/types.h>
+
+/* The structure describing an advisory lock. This is the type of the third
+ argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests. */
+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'). */
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+ long int l_sysid; /* System ID where locking process resides. */
+ __pid_t l_pid; /* Process holding the lock. */
+ long int pad[4]; /* Reserved for future use. */
+ };
+
+/* Values for the `l_type' field of a `struct flock'. */
+#define F_RDLCK 1 /* Read lock. */
+#define F_WRLCK 2 /* Write lock. */
+#define F_UNLCK 3 /* Remove lock. */
diff --git a/libc/sysdeps/unix/common/lxstat.c b/libc/sysdeps/unix/common/lxstat.c
new file mode 100644
index 000000000..88cc87120
--- /dev/null
+++ b/libc/sysdeps/unix/common/lxstat.c
@@ -0,0 +1,39 @@
+/* lxstat using old-style Unix lstat system call.
+ Copyright (C) 1991,1995,1996,1997,2000,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <bp-checks.h>
+
+extern int __syscall_lstat (const char *__unbounded, struct stat *__unbounded);
+
+int
+__lxstat (int vers, const char *file, struct stat *buf)
+{
+ if (vers != _STAT_VER)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return __syscall_lstat (CHECK_STRING (file), CHECK_1 (buf));
+}
+hidden_def (__lxstat)
+weak_alias (__lxstat, _lxstat)
diff --git a/libc/sysdeps/unix/common/syscalls.list b/libc/sysdeps/unix/common/syscalls.list
new file mode 100644
index 000000000..baec92f78
--- /dev/null
+++ b/libc/sysdeps/unix/common/syscalls.list
@@ -0,0 +1,16 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+adjtime - adjtime i:pp __adjtime adjtime
+fchmod - fchmod i:ii __fchmod fchmod
+fchown - fchown i:iii __fchown fchown
+ftruncate - ftruncate i:ii __ftruncate ftruncate
+getrusage - getrusage i:ip __getrusage getrusage
+gettimeofday - gettimeofday i:PP __gettimeofday gettimeofday __gettimeofday_internal
+settimeofday - settimeofday i:PP __settimeofday settimeofday
+setpgid - setpgrp i:ii __setpgid setpgid
+setregid - setregid i:ii __setregid setregid
+setreuid - setreuid i:ii __setreuid setreuid
+sigaction - sigaction i:ipp __sigaction sigaction
+sys_lstat lxstat lstat i:sp __syscall_lstat
+truncate - truncate i:si __truncate truncate
+vhangup - vhangup i:i vhangup
diff --git a/libc/sysdeps/unix/common/tcsendbrk.c b/libc/sysdeps/unix/common/tcsendbrk.c
new file mode 100644
index 000000000..16736e925
--- /dev/null
+++ b/libc/sysdeps/unix/common/tcsendbrk.c
@@ -0,0 +1,46 @@
+/* Send break to terminal.
+ Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+
+/* Send zero bits on FD. */
+int
+tcsendbreak (int fd, int duration)
+{
+ /* The break lasts 0.25 to 0.5 seconds if DURATION is zero,
+ and an implementation-defined period if DURATION is nonzero.
+ We define a positive DURATION to be number of milliseconds to break. */
+ if (duration <= 0)
+ return __ioctl (fd, TCSBRK, 0);
+
+#ifdef TCSBRKP
+ /* Probably Linux-specific: a positive third TCSBRKP ioctl argument is
+ defined to be the number of 100ms units to break. */
+ return __ioctl (fd, TCSBRKP, (duration + 99) / 100);
+#else
+ /* ioctl can't send a break of any other duration for us.
+ This could be changed to use trickery (e.g. lower speed and
+ send a '\0') to send the break, but for now just return an error. */
+ __set_errno (EINVAL);
+ return -1;
+#endif
+}
diff --git a/libc/sysdeps/unix/confstr.h b/libc/sysdeps/unix/confstr.h
new file mode 100644
index 000000000..15859c3b2
--- /dev/null
+++ b/libc/sysdeps/unix/confstr.h
@@ -0,0 +1 @@
+#define CS_PATH "/bin:/usr/bin"
diff --git a/libc/sysdeps/unix/dirfd.c b/libc/sysdeps/unix/dirfd.c
new file mode 100644
index 000000000..9a43246fe
--- /dev/null
+++ b/libc/sysdeps/unix/dirfd.c
@@ -0,0 +1,30 @@
+/* Return the file descriptor used by a DIR stream. Unix version.
+ Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <dirent.h>
+#include <dirstream.h>
+
+#undef dirfd
+
+int
+dirfd (dirp)
+ DIR *dirp;
+{
+ return dirp->fd;
+}
diff --git a/libc/sysdeps/unix/dirstream.h b/libc/sysdeps/unix/dirstream.h
new file mode 100644
index 000000000..a1f74473c
--- /dev/null
+++ b/libc/sysdeps/unix/dirstream.h
@@ -0,0 +1,48 @@
+/* Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _DIRSTREAM_H
+
+#define _DIRSTREAM_H 1
+
+#include <sys/types.h>
+
+#include <bits/libc-lock.h>
+
+/* Directory stream type.
+
+ The miscellaneous Unix `readdir' implementations read directory data
+ into a buffer and return `struct dirent *' pointers into it. */
+
+struct __dirstream
+ {
+ int fd; /* File descriptor. */
+
+ char *data; /* Directory block. */
+ size_t allocation; /* Space allocated for the block. */
+ size_t size; /* Total valid data in the block. */
+ size_t offset; /* Current offset into the block. */
+
+ off_t filepos; /* Position of next entry to read. */
+
+ __libc_lock_define (, lock) /* Mutex lock for this structure. */
+ };
+
+#define _DIR_dirfd(dirp) ((dirp)->fd)
+
+#endif /* dirstream.h */
diff --git a/libc/sysdeps/unix/errnos-tmpl.c b/libc/sysdeps/unix/errnos-tmpl.c
new file mode 100644
index 000000000..25d7ec5db
--- /dev/null
+++ b/libc/sysdeps/unix/errnos-tmpl.c
@@ -0,0 +1,99 @@
+/* Copyright (C) 1991, 1993, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+
+static char iferrno[] = "#ifdef _ERRNO_H";
+static char endiferrno[] = "#endif /* <errno.h> included. */";
+static char ifEmath[] = "#if !defined(__Emath_defined) && \
+ (defined(_ERRNO_H) || defined(__need_Emath))";
+static char endifEmath[] = "#endif /* Emath not defined and <errno.h> \
+included or need Emath. */";
+
+static int biggest_value = 0;
+static int done_ENOSYS = 0;
+static int done_ERANGE = 0, done_EDOM = 0;
+
+static void
+DO(name, value)
+ char *name;
+ int value;
+{
+ int is_ERANGE = !done_ERANGE && !strcmp(name, "ERANGE");
+ int is_EDOM = !done_EDOM && !strcmp(name, "EDOM");
+ int is_Emath = is_ERANGE || is_EDOM;
+
+ if (is_Emath)
+ {
+ puts(endiferrno);
+ puts(ifEmath);
+ }
+
+ if (!strcmp (name, "EWOULDBLOCK"))
+ {
+ puts ("#define EWOULDBLOCK EAGAIN /* Translated in glibc. */");
+ name = "EWOULDBLOCK_sys /* Value actually returned by kernel. */";
+ }
+
+ printf ("#define %s %d\n", name, value);
+
+ if (is_Emath)
+ {
+ puts(endifEmath);
+ puts(iferrno);
+ }
+
+ if (value > biggest_value)
+ biggest_value = value;
+
+ if (is_ERANGE)
+ done_ERANGE = 1;
+ else if (is_EDOM)
+ done_EDOM = 1;
+ else if (!done_ENOSYS && !strcmp(name, "ENOSYS"))
+ done_ENOSYS = 1;
+}
+
+int
+main()
+{
+ puts(iferrno);
+
+ ERRNOS;
+
+ if (!done_EDOM || !done_ERANGE)
+ {
+ puts(endiferrno);
+ puts(ifEmath);
+ if (!done_EDOM)
+ printf("#define EDOM %d\n", ++biggest_value);
+ if (!done_ERANGE)
+ printf("#define ERANGE %d\n", ++biggest_value);
+ puts(endifEmath);
+ }
+
+ if (!done_ENOSYS)
+ printf("#define ENOSYS %d\n", ++biggest_value);
+
+ puts(endiferrno);
+
+ puts("#undef __need_Emath");
+ puts("#ifndef __Emath_defined\n#define __Emath_defined 1\n#endif");
+
+ exit(0);
+}
diff --git a/libc/sysdeps/unix/errnos.awk b/libc/sysdeps/unix/errnos.awk
new file mode 100644
index 000000000..8648f41fb
--- /dev/null
+++ b/libc/sysdeps/unix/errnos.awk
@@ -0,0 +1,12 @@
+BEGIN { special = 0 }
+
+/ERRNOS/ { nerrnos = split(errnos, errs)
+ for (i = 1; i <= nerrnos; ++i)
+ # Some systems define errno codes inside undefined #ifdefs,
+ # and then never actually use them.
+ printf "#ifdef %s\n DO(\"%s\", %s);\n#endif\n", \
+ errs[i], errs[i], errs[i]
+ special = 1 }
+
+
+{ if (special == 0) print $0; special = 0 }
diff --git a/libc/sysdeps/unix/execve.S b/libc/sysdeps/unix/execve.S
new file mode 100644
index 000000000..de125d3f9
--- /dev/null
+++ b/libc/sysdeps/unix/execve.S
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991, 92, 93, 95, 96 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* Some systems misname the system call number macro for this. */
+#if !defined (SYS_execve) && defined (SYS_exece)
+#define SYS_execve SYS_exece
+#endif
+#if !defined (SYS_execve) && defined (SYS_exec)
+#define SYS_execve SYS_exec
+#endif
+
+SYSCALL__ (execve, 3)
+ ret
+PSEUDO_END(__execve)
+
+weak_alias (__execve, execve)
diff --git a/libc/sysdeps/unix/fdopendir.c b/libc/sysdeps/unix/fdopendir.c
new file mode 100644
index 000000000..565ce1ed7
--- /dev/null
+++ b/libc/sysdeps/unix/fdopendir.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#include <not-cancel.h>
+
+
+DIR *
+__fdopendir (int fd)
+{
+ struct stat64 statbuf;
+
+ if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &statbuf), 0) < 0)
+ return NULL;
+ if (__builtin_expect (! S_ISDIR (statbuf.st_mode), 0))
+ {
+ __set_errno (ENOTDIR);
+ return NULL;
+ }
+
+ /* Make sure the descriptor allows for reading. */
+ int flags = __fcntl (fd, F_GETFL);
+ if (__builtin_expect (flags == -1, 0))
+ return NULL;
+ if (__builtin_expect ((flags & O_ACCMODE) == O_WRONLY, 0))
+ {
+ __set_errno (EINVAL);
+ return NULL;
+ }
+
+ return __alloc_dir (fd, false, &statbuf);
+}
+weak_alias (__fdopendir, fdopendir)
diff --git a/libc/sysdeps/unix/fork.S b/libc/sysdeps/unix/fork.S
new file mode 100644
index 000000000..8717d513b
--- /dev/null
+++ b/libc/sysdeps/unix/fork.S
@@ -0,0 +1,34 @@
+/* Copyright (C) 1991,92,94,95,97,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* This code works for at least m68k. */
+
+SYSCALL__ (fork, 0)
+ /* R1 is now 0 for the parent and 1 for the child. Decrement it to
+ make it -1 (all bits set) for the parent, and 0 (no bits set)
+ for the child. Then AND it with R0, so the parent gets
+ R0&-1==R0, and the child gets R0&0==0. */
+ subl #1, r1
+ andl r1, r0
+ ret
+PSEUDO_END (__fork)
+libc_hidden_def (__fork)
+
+weak_alias (__fork, fork)
diff --git a/libc/sysdeps/unix/fxstat.c b/libc/sysdeps/unix/fxstat.c
new file mode 100644
index 000000000..687ce9aba
--- /dev/null
+++ b/libc/sysdeps/unix/fxstat.c
@@ -0,0 +1,40 @@
+/* fxstat using old-style Unix fstat system call.
+ Copyright (C) 1991,1995,1996,1997,2000,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <bp-checks.h>
+
+extern int __syscall_fstat (int, struct stat *__unbounded);
+
+/* Get information about the file descriptor FD in BUF. */
+int
+__fxstat (int vers, int fd, struct stat *buf)
+{
+ if (vers != _STAT_VER)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return __syscall_fstat (fd, CHECK_1 (buf));
+}
+hidden_def (__fxstat)
+weak_alias (__fxstat, _fxstat)
diff --git a/libc/sysdeps/unix/get_child_max.c b/libc/sysdeps/unix/get_child_max.c
new file mode 100644
index 000000000..c59e4d895
--- /dev/null
+++ b/libc/sysdeps/unix/get_child_max.c
@@ -0,0 +1,37 @@
+/* Get POSIX {CHILD_MAX} run-time limit value. Unix version.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <limits.h>
+#include <sys/sysinfo.h>
+#include <sys/resource.h>
+
+#ifndef CHILD_MAX
+long int
+__get_child_max (void)
+{
+# ifdef RLIMIT_NPROC
+ struct rlimit limit;
+ if (__getrlimit (RLIMIT_NPROC, &limit) == 0
+ && limit.rlim_cur != RLIM_INFINITY)
+ return limit.rlim_cur;
+# endif
+
+ return -1;
+}
+#endif
diff --git a/libc/sysdeps/unix/getdents.c b/libc/sysdeps/unix/getdents.c
new file mode 100644
index 000000000..54a76d9d8
--- /dev/null
+++ b/libc/sysdeps/unix/getdents.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+ssize_t
+__getdirentries (fd, buf, nbytes, basep)
+ int fd;
+ char *buf;
+ size_t nbytes;
+ off_t *basep;
+{
+ if (basep)
+ *basep = __lseek (fd, (off_t) 0, SEEK_CUR);
+
+ return (ssize_t) __read (fd, buf, nbytes);
+}
+
+weak_alias (__getdirentries, getdirentries)
diff --git a/libc/sysdeps/unix/getegid.S b/libc/sysdeps/unix/getegid.S
new file mode 100644
index 000000000..95ebd9262
--- /dev/null
+++ b/libc/sysdeps/unix/getegid.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991, 1992, 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#ifdef SYS_getegid
+SYSCALL__ (getegid, 0)
+#else
+PSEUDO (__getegid, getgid, 0)
+ MOVE(r1, r0)
+#endif
+ ret
+PSEUDO_END(__getegid)
+
+weak_alias (__getegid, getegid)
diff --git a/libc/sysdeps/unix/geteuid.S b/libc/sysdeps/unix/geteuid.S
new file mode 100644
index 000000000..2a8910529
--- /dev/null
+++ b/libc/sysdeps/unix/geteuid.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991, 1992, 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#ifdef SYS_geteuid
+SYSCALL__ (geteuid, 0)
+#else
+PSEUDO (__geteuid, getuid, 0)
+ MOVE(r1, r0)
+#endif
+ ret
+PSEUDO_END(__geteuid)
+
+weak_alias (__geteuid, geteuid)
diff --git a/libc/sysdeps/unix/getlogin.c b/libc/sysdeps/unix/getlogin.c
new file mode 100644
index 000000000..4752685f8
--- /dev/null
+++ b/libc/sysdeps/unix/getlogin.c
@@ -0,0 +1,73 @@
+/* Copyright (C) 1991, 1992, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <limits.h>
+#include <fcntl.h>
+
+#include <utmp.h>
+
+/* Return the login name of the user, or NULL if it can't be determined.
+ The returned pointer, if not NULL, is good only until the next call. */
+
+char *
+getlogin (void)
+{
+ char tty_pathname[2 + 2 * NAME_MAX];
+ char *real_tty_path = tty_pathname;
+ char *result = NULL;
+ static char name[UT_NAMESIZE + 1];
+ struct utmp *ut, line, buffer;
+
+ /* Get name of tty connected to fd 0. Return NULL if not a tty or
+ if fd 0 isn't open. Note that a lot of documentation says that
+ getlogin() is based on the controlling terminal---what they
+ really mean is "the terminal connected to standard input". The
+ getlogin() implementation of DEC Unix, SunOS, Solaris, HP-UX all
+ return NULL if fd 0 has been closed, so this is the compatible
+ thing to do. Note that ttyname(open("/dev/tty")) on those
+ systems returns /dev/tty, so that is not a possible solution for
+ getlogin(). */
+ if (__ttyname_r (0, real_tty_path, sizeof (tty_pathname)) != 0)
+ return NULL;
+
+ real_tty_path += 5; /* Remove "/dev/". */
+
+ __setutent ();
+ strncpy (line.ut_line, real_tty_path, sizeof line.ut_line);
+ if (__getutline_r (&line, &buffer, &ut) < 0)
+ {
+ if (errno == ESRCH)
+ /* The caller expects ENOENT if nothing is found. */
+ __set_errno (ENOENT);
+ result = NULL;
+ }
+ else
+ {
+ strncpy (name, ut->ut_user, UT_NAMESIZE);
+ name[UT_NAMESIZE] = '\0';
+ result = name;
+ }
+
+ __endutent ();
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/getlogin_r.c b/libc/sysdeps/unix/getlogin_r.c
new file mode 100644
index 000000000..ba7badd05
--- /dev/null
+++ b/libc/sysdeps/unix/getlogin_r.c
@@ -0,0 +1,99 @@
+/* Reentrant function to return the current login name. Unix version.
+ Copyright (C) 1991,92,96,97,98,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <limits.h>
+#include <fcntl.h>
+
+#include <utmp.h>
+#include "../login/utmp-private.h"
+
+/* Return at most NAME_LEN characters of the login name of the user in NAME.
+ If it cannot be determined or some other error occurred, return the error
+ code. Otherwise return 0. */
+
+int
+getlogin_r (name, name_len)
+ char *name;
+ size_t name_len;
+{
+ char tty_pathname[2 + 2 * NAME_MAX];
+ char *real_tty_path = tty_pathname;
+ int result;
+ struct utmp *ut, line, buffer;
+
+ /* Get name of tty connected to fd 0. Return if not a tty or
+ if fd 0 isn't open. Note that a lot of documentation says that
+ getlogin() is based on the controlling terminal---what they
+ really mean is "the terminal connected to standard input". The
+ getlogin() implementation of DEC Unix, SunOS, Solaris, HP-UX all
+ return NULL if fd 0 has been closed, so this is the compatible
+ thing to do. Note that ttyname(open("/dev/tty")) on those
+ systems returns /dev/tty, so that is not a possible solution for
+ getlogin(). */
+
+ result = __ttyname_r (0, real_tty_path, sizeof (tty_pathname));
+
+ if (result != 0)
+ return result;
+
+ real_tty_path += 5; /* Remove "/dev/". */
+ strncpy (line.ut_line, real_tty_path, sizeof line.ut_line);
+
+ /* We don't use the normal entry points __setutent et al, because we
+ want setutent + getutline_r + endutent all to happen with the lock
+ held so that our search is thread-safe. */
+
+ __libc_lock_lock (__libc_utmp_lock);
+ (*__libc_utmp_jump_table->setutent) ();
+ result = (*__libc_utmp_jump_table->getutline_r) (&line, &buffer, &ut);
+ if (result < 0)
+ {
+ if (errno == ESRCH)
+ /* The caller expects ENOENT if nothing is found. */
+ result = ENOENT;
+ else
+ result = errno;
+ }
+ (*__libc_utmp_jump_table->endutent) ();
+ __libc_utmp_jump_table = &__libc_utmp_unknown_functions;
+ __libc_lock_unlock (__libc_utmp_lock);
+
+ if (result == 0)
+ {
+ size_t needed = strlen (ut->ut_user) + 1;
+
+ if (needed > name_len)
+ {
+ __set_errno (ERANGE);
+ result = ERANGE;
+ }
+ else
+ {
+ memcpy (name, ut->ut_user, needed);
+ result = 0;
+ }
+ }
+
+ return result;
+}
+libc_hidden_def (getlogin_r)
diff --git a/libc/sysdeps/unix/getpagesize.c b/libc/sysdeps/unix/getpagesize.c
new file mode 100644
index 000000000..6e62101ab
--- /dev/null
+++ b/libc/sysdeps/unix/getpagesize.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 1991,1992,1995,1996,1997,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <unistd.h>
+#include <sys/param.h>
+
+/* Return the system page size. */
+int
+__getpagesize ()
+{
+#ifdef EXEC_PAGESIZE
+ return EXEC_PAGESIZE;
+#else /* No EXEC_PAGESIZE. */
+#ifdef NBPG
+#ifndef CLSIZE
+#define CLSIZE 1
+#endif /* No CLSIZE. */
+ return NBPG * CLSIZE;
+#else /* No NBPG. */
+ return NBPC;
+#endif /* NBPG. */
+#endif /* EXEC_PAGESIZE. */
+}
+libc_hidden_def (__getpagesize)
+weak_alias (__getpagesize, getpagesize)
diff --git a/libc/sysdeps/unix/getppid.S b/libc/sysdeps/unix/getppid.S
new file mode 100644
index 000000000..a1821686a
--- /dev/null
+++ b/libc/sysdeps/unix/getppid.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991, 1992, 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#ifdef SYS_getppid
+SYSCALL__ (getppid, 0)
+#else
+PSEUDO (__getppid, getpid, 0)
+ MOVE(r1, r0)
+#endif
+ ret
+PSEUDO_END(__getppid)
+
+weak_alias (__getppid, getppid)
diff --git a/libc/sysdeps/unix/grantpt.c b/libc/sysdeps/unix/grantpt.c
new file mode 100644
index 000000000..bdedbacec
--- /dev/null
+++ b/libc/sysdeps/unix/grantpt.c
@@ -0,0 +1,216 @@
+/* Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <grp.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include "pty-private.h"
+
+
+/* Return the result of ptsname_r in the buffer pointed to by PTS,
+ which should be of length BUF_LEN. If it is too long to fit in
+ this buffer, a sufficiently long buffer is allocated using malloc,
+ and returned in PTS. 0 is returned upon success, -1 otherwise. */
+static int
+pts_name (int fd, char **pts, size_t buf_len)
+{
+ int rv;
+ char *buf = *pts;
+
+ for (;;)
+ {
+ char *new_buf;
+
+ if (buf_len)
+ {
+ rv = __ptsname_r (fd, buf, buf_len);
+ if (rv != 0)
+ {
+ if (rv == ENOTTY)
+ /* ptsname_r returns with ENOTTY to indicate
+ a descriptor not referring to a pty master.
+ For this condition, grantpt must return EINVAL. */
+ rv = EINVAL;
+ errno = rv; /* Not necessarily set by __ptsname_r. */
+ break;
+ }
+
+ if (memchr (buf, '\0', buf_len))
+ /* We succeeded and the returned name fit in the buffer. */
+ break;
+
+ /* Try again with a longer buffer. */
+ buf_len += buf_len; /* Double it */
+ }
+ else
+ /* No initial buffer; start out by mallocing one. */
+ buf_len = 128; /* First time guess. */
+
+ if (buf != *pts)
+ /* We've already malloced another buffer at least once. */
+ new_buf = (char *) realloc (buf, buf_len);
+ else
+ new_buf = (char *) malloc (buf_len);
+ if (! new_buf)
+ {
+ rv = -1;
+ __set_errno (ENOMEM);
+ break;
+ }
+ buf = new_buf;
+ }
+
+ if (rv == 0)
+ *pts = buf; /* Return buffer to the user. */
+ else if (buf != *pts)
+ free (buf); /* Free what we malloced when returning an error. */
+
+ return rv;
+}
+
+/* Change the ownership and access permission of the slave pseudo
+ terminal associated with the master pseudo terminal specified
+ by FD. */
+int
+grantpt (int fd)
+{
+ int retval = -1;
+#ifdef PATH_MAX
+ char _buf[PATH_MAX];
+#else
+ char _buf[512];
+#endif
+ char *buf = _buf;
+ struct stat64 st;
+ char *grtmpbuf;
+ struct group grbuf;
+ size_t grbuflen = __sysconf (_SC_GETGR_R_SIZE_MAX);
+ struct group *p;
+ uid_t uid;
+ gid_t gid;
+ pid_t pid;
+
+ if (pts_name (fd, &buf, sizeof (_buf)))
+ return -1;
+
+ if (__xstat64 (_STAT_VER, buf, &st) < 0)
+ goto cleanup;
+
+ /* Make sure that we own the device. */
+ uid = __getuid ();
+ if (st.st_uid != uid)
+ {
+ if (__chown (buf, uid, st.st_gid) < 0)
+ goto helper;
+ }
+
+ /* Get the group ID of the special `tty' group. */
+ if (grbuflen == (size_t) -1L)
+ /* `sysconf' does not support _SC_GETGR_R_SIZE_MAX.
+ Try a moderate value. */
+ grbuflen = 1024;
+ grtmpbuf = (char *) __alloca (grbuflen);
+ __getgrnam_r (TTY_GROUP, &grbuf, grtmpbuf, grbuflen, &p);
+ gid = p ? p->gr_gid : __getgid ();
+
+ /* Make sure the group of the device is that special group. */
+ if (st.st_gid != gid)
+ {
+ if (__chown (buf, uid, gid) < 0)
+ goto helper;
+ }
+
+ /* Make sure the permission mode is set to readable and writable by
+ the owner, and writable by the group. */
+ if ((st.st_mode & ACCESSPERMS) != (S_IRUSR|S_IWUSR|S_IWGRP))
+ {
+ if (__chmod (buf, S_IRUSR|S_IWUSR|S_IWGRP) < 0)
+ goto helper;
+ }
+
+ retval = 0;
+ goto cleanup;
+
+ /* We have to use the helper program. */
+ helper:
+
+ pid = __fork ();
+ if (pid == -1)
+ goto cleanup;
+ else if (pid == 0)
+ {
+ /* Disable core dumps. */
+ struct rlimit rl = { 0, 0 };
+ __setrlimit (RLIMIT_CORE, &rl);
+
+ /* We pass the master pseudo terminal as file descriptor PTY_FILENO. */
+ if (fd != PTY_FILENO)
+ if (__dup2 (fd, PTY_FILENO) < 0)
+ _exit (FAIL_EBADF);
+
+ execle (_PATH_PT_CHOWN, basename (_PATH_PT_CHOWN), NULL, NULL);
+ _exit (FAIL_EXEC);
+ }
+ else
+ {
+ int w;
+
+ if (__waitpid (pid, &w, 0) == -1)
+ goto cleanup;
+ if (!WIFEXITED (w))
+ __set_errno (ENOEXEC);
+ else
+ switch (WEXITSTATUS(w))
+ {
+ case 0:
+ retval = 0;
+ break;
+ case FAIL_EBADF:
+ __set_errno (EBADF);
+ break;
+ case FAIL_EINVAL:
+ __set_errno (EINVAL);
+ break;
+ case FAIL_EACCES:
+ __set_errno (EACCES);
+ break;
+ case FAIL_EXEC:
+ __set_errno (ENOEXEC);
+ break;
+
+ default:
+ assert(! "getpt: internal error: invalid exit code from pt_chown");
+ }
+ }
+
+ cleanup:
+ if (buf != _buf)
+ free (buf);
+
+ return retval;
+}
diff --git a/libc/sysdeps/unix/i386/brk.S b/libc/sysdeps/unix/i386/brk.S
new file mode 100644
index 000000000..d8dd96b4c
--- /dev/null
+++ b/libc/sysdeps/unix/i386/brk.S
@@ -0,0 +1,47 @@
+/* Copyright (C) 1991,92,93,95,97,2002,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#ifndef SYS_brk
+#define SYS_brk 17
+#endif
+
+.data
+.globl C_SYMBOL_NAME(__curbrk)
+C_LABEL(__curbrk)
+ .long C_SYMBOL_NAME(_end)
+
+.text
+SYSCALL__ (brk, 1)
+ movl 4(%esp), %eax
+#ifdef PIC
+ /* Standard PIC nonsense to store into `__curbrk' through the GOT. */
+ call L(here)
+L(here): popl %ecx
+ addl $_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ecx
+ movl C_SYMBOL_NAME(__curbrk@GOT)(%ecx), %ecx
+ movl %eax, (%ecx)
+#else
+ movl %eax, C_SYMBOL_NAME(__curbrk)
+#endif
+ xorl %eax, %eax
+ ret
+PSEUDO_END (__brk)
+
+weak_alias (__brk, brk)
diff --git a/libc/sysdeps/unix/i386/dl-brk.S b/libc/sysdeps/unix/i386/dl-brk.S
new file mode 100644
index 000000000..eeb96544e
--- /dev/null
+++ b/libc/sysdeps/unix/i386/dl-brk.S
@@ -0,0 +1 @@
+#include <brk.S>
diff --git a/libc/sysdeps/unix/i386/fork.S b/libc/sysdeps/unix/i386/fork.S
new file mode 100644
index 000000000..b729d47f7
--- /dev/null
+++ b/libc/sysdeps/unix/i386/fork.S
@@ -0,0 +1,32 @@
+/* Copyright (C) 1991,92,94,95,97,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+SYSCALL__ (fork, 0)
+ /* R1 is now 0 for the parent and 1 for the child. Decrement it to
+ make it -1 (all bits set) for the parent, and 0 (no bits set)
+ for the child. Then AND it with R0, so the parent gets
+ R0&-1==R0, and the child gets R0&0==0. */
+ decl r1
+ andl r1, r0
+ ret
+PSEUDO_END (__fork)
+libc_hidden_def (__fork)
+
+weak_alias (__fork, fork)
diff --git a/libc/sysdeps/unix/i386/pipe.S b/libc/sysdeps/unix/i386/pipe.S
new file mode 100644
index 000000000..1bdadc649
--- /dev/null
+++ b/libc/sysdeps/unix/i386/pipe.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991,92,93,95,97,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+SYSCALL__ (pipe, 1)
+ movl 4(%esp), scratch
+ movl %eax, (scratch)
+ movl r1, 4(scratch)
+ xorl %eax, %eax
+ ret
+PSEUDO_END (__pipe)
+
+libc_hidden_def (__pipe)
+weak_alias (__pipe, pipe)
diff --git a/libc/sysdeps/unix/i386/sigreturn.S b/libc/sysdeps/unix/i386/sigreturn.S
new file mode 100644
index 000000000..cf6f89e01
--- /dev/null
+++ b/libc/sysdeps/unix/i386/sigreturn.S
@@ -0,0 +1,27 @@
+/* Copyright (C) 1992, 1993, 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+.text
+ENTRY (__sigreturn)
+ addl $4, %esp /* Pop the return PC. */
+ DO_CALL (sigreturn, 0) /* Do the system call; it never returns. */
+ /* NOTREACHED */
+
+weak_alias (__sigreturn, sigreturn)
diff --git a/libc/sysdeps/unix/i386/start.c b/libc/sysdeps/unix/i386/start.c
new file mode 100644
index 000000000..e6c89ee3f
--- /dev/null
+++ b/libc/sysdeps/unix/i386/start.c
@@ -0,0 +1,2 @@
+#define DUMMIES dummy0
+#include <sysdeps/unix/start.c>
diff --git a/libc/sysdeps/unix/i386/syscall.S b/libc/sysdeps/unix/i386/syscall.S
new file mode 100644
index 000000000..b333c617c
--- /dev/null
+++ b/libc/sysdeps/unix/i386/syscall.S
@@ -0,0 +1,28 @@
+/* Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+.globl syscall_error
+ENTRY (syscall)
+ popl %ecx /* Pop return address into %ecx. */
+ popl %eax /* Pop syscall number into %eax. */
+ pushl %ecx /* Push back return address. */
+ .byte 0x9a, 0, 0, 0, 0, 7, 0 /* lcall $7, $0 -- gas bug */
+ jb JUMPTARGET(syscall_error)
+ ret
diff --git a/libc/sysdeps/unix/i386/sysdep.S b/libc/sysdeps/unix/i386/sysdep.S
new file mode 100644
index 000000000..3bc872add
--- /dev/null
+++ b/libc/sysdeps/unix/i386/sysdep.S
@@ -0,0 +1,106 @@
+/* Copyright (C) 1991,1992,1993,1994,1995,1996,1997,2000,2002,2004,2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H
+#include <bits/errno.h>
+#include <bp-asm.h>
+#include <bp-sym.h>
+
+#ifdef IS_IN_rtld
+# include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
+#endif
+
+.globl C_SYMBOL_NAME(errno)
+.globl syscall_error
+
+#undef syscall_error
+#ifdef NO_UNDERSCORES
+__syscall_error:
+#else
+syscall_error:
+#endif
+#if defined (EWOULDBLOCK_sys) && EWOULDBLOCK_sys != EAGAIN
+ /* We translate the system's EWOULDBLOCK error into EAGAIN.
+ The GNU C library always defines EWOULDBLOCK==EAGAIN.
+ EWOULDBLOCK_sys is the original number. */
+ cmpl $EWOULDBLOCK_sys, %eax /* Is it the old EWOULDBLOCK? */
+ jne notb /* Branch if not. */
+ movl $EAGAIN, %eax /* Yes; translate it to EAGAIN. */
+notb:
+#endif
+#ifndef PIC
+# if USE___THREAD
+# ifndef NO_TLS_DIRECT_SEG_REFS
+ movl %eax, %gs:C_SYMBOL_NAME(errno@NTPOFF)
+# else
+ movl %gs:0, %ecx
+ movl %eax, C_SYMBOL_NAME(errno@NTPOFF)(%ecx)
+# endif
+# elif !defined _LIBC_REENTRANT
+ movl %eax, C_SYMBOL_NAME(errno)
+# else
+ pushl %eax
+ PUSH_ERRNO_LOCATION_RETURN
+ call BP_SYM (__errno_location)
+ POP_ERRNO_LOCATION_RETURN
+ popl %ecx
+ movl %ecx, (%eax)
+# endif
+#else
+ /* The caller has pushed %ebx and then set it up to
+ point to the GOT before calling us through the PLT. */
+# if USE___THREAD
+ movl C_SYMBOL_NAME(errno@GOTNTPOFF)(%ebx), %ecx
+
+ /* Pop %ebx value saved before jumping here. */
+ popl %ebx
+# ifndef NO_TLS_DIRECT_SEG_REFS
+ addl %gs:0, %ecx
+ movl %eax, (%ecx)
+# else
+ movl %eax, %gs:0(%ecx)
+# endif
+# elif RTLD_PRIVATE_ERRNO
+ movl %eax, C_SYMBOL_NAME(rtld_errno@GOTOFF)(%ebx)
+
+ /* Pop %ebx value saved before jumping here. */
+ popl %ebx
+# elif !defined _LIBC_REENTRANT
+ movl C_SYMBOL_NAME(errno@GOT)(%ebx), %ecx
+
+ /* Pop %ebx value saved before jumping here. */
+ popl %ebx
+ movl %eax, (%ecx)
+# else
+ pushl %eax
+ PUSH_ERRNO_LOCATION_RETURN
+ call C_SYMBOL_NAME (BP_SYM (__errno_location)@PLT)
+ POP_ERRNO_LOCATION_RETURN
+ popl %ecx
+ /* Pop %ebx value saved before jumping here. */
+ popl %ebx
+ movl %ecx, (%eax)
+# endif
+#endif
+ movl $-1, %eax
+ ret
+
+#undef __syscall_error
+END (__syscall_error)
diff --git a/libc/sysdeps/unix/i386/sysdep.h b/libc/sysdeps/unix/i386/sysdep.h
new file mode 100644
index 000000000..d6b496223
--- /dev/null
+++ b/libc/sysdeps/unix/i386/sysdep.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 1991, 92, 93, 95, 96, 97 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/unix/sysdep.h>
+#include <sysdeps/i386/sysdep.h>
+
+#ifdef __ASSEMBLER__
+
+/* This is defined as a separate macro so that other sysdep.h files
+ can include this one and then redefine DO_CALL. */
+
+#define DO_CALL(syscall_name, args) \
+ lea SYS_ify (syscall_name), %eax; \
+ lcall $7, $0
+
+#define r0 %eax /* Normal return-value register. */
+#define r1 %edx /* Secondary return-value register. */
+#define scratch %ecx /* Call-clobbered register for random use. */
+#define MOVE(x,y) movl x, y
+
+#endif /* __ASSEMBLER__ */
diff --git a/libc/sysdeps/unix/i386/vfork.S b/libc/sysdeps/unix/i386/vfork.S
new file mode 100644
index 000000000..81d714878
--- /dev/null
+++ b/libc/sysdeps/unix/i386/vfork.S
@@ -0,0 +1,24 @@
+/* Copyright (C) 1994, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* Go directly into __vfork, don't do anything with the stack ptr. */
+
+ENTRY(vfork)
+ jmp __vfork
diff --git a/libc/sysdeps/unix/i386/wait.S b/libc/sysdeps/unix/i386/wait.S
new file mode 100644
index 000000000..49195a229
--- /dev/null
+++ b/libc/sysdeps/unix/i386/wait.S
@@ -0,0 +1,29 @@
+/* Copyright (C) 1991,92,93,95,97,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+SYSCALL__ (wait, 1)
+ movl 4(%esp), scratch /* Put status pointer in scratch register. */
+ testl scratch, scratch /* Is it non-nil? */
+ je null
+ movl r1, (scratch) /* Yes; store the status there. */
+null: ret
+PSEUDO_END (__wait)
+
+weak_alias (__wait, wait)
diff --git a/libc/sysdeps/unix/inet/Subdirs b/libc/sysdeps/unix/inet/Subdirs
new file mode 100644
index 000000000..4a191e299
--- /dev/null
+++ b/libc/sysdeps/unix/inet/Subdirs
@@ -0,0 +1,7 @@
+inet
+resolv
+hesiod
+sunrpc
+nis
+nscd
+streams
diff --git a/libc/sysdeps/unix/inet/syscalls.list b/libc/sysdeps/unix/inet/syscalls.list
new file mode 100644
index 000000000..df2f34eea
--- /dev/null
+++ b/libc/sysdeps/unix/inet/syscalls.list
@@ -0,0 +1,23 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+accept - accept Ci:iBN __libc_accept accept
+bind - bind i:ipi __bind bind
+connect - connect Ci:ipi __libc_connect __connect __connect_internal connect
+gethostid - gethostid i: gethostid
+gethostname - gethostname i:bn __gethostname gethostname
+getpeername - getpeername i:ibN __getpeername getpeername
+getsockname - getsockname i:ibN __getsockname getsockname
+getsockopt - getsockopt i:iiiBN getsockopt
+listen - listen i:ii __listen listen
+recv - recv Ci:ibni __libc_recv recv
+recvfrom - recvfrom Ci:ibniBN __libc_recvfrom __recvfrom recvfrom
+recvmsg - recvmsg Ci:ipi __libc_recvmsg __recvmsg recvmsg
+send - send Ci:ibni __libc_send __send send
+sendmsg - sendmsg Ci:ipi __libc_sendmsg __sendmsg sendmsg
+sendto - sendto Ci:ibnibn __libc_sendto __sendto sendto
+sethostid - sethostid i:i sethostid
+sethostname - sethostname i:pi sethostname
+setsockopt - setsockopt i:iiibn setsockopt __setsockopt
+shutdown - shutdown i:ii shutdown
+socket - socket i:iii __socket socket
+socketpair - socketpair i:iiif socketpair
diff --git a/libc/sysdeps/unix/ioctls-tmpl.c b/libc/sysdeps/unix/ioctls-tmpl.c
new file mode 100644
index 000000000..1c973c945
--- /dev/null
+++ b/libc/sysdeps/unix/ioctls-tmpl.c
@@ -0,0 +1,134 @@
+/* On SVR4, this #define is necessary to make <sys/ioctl.h> define
+ many of the ioctls. */
+#define BSD_COMP
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+/* On SunOS 4.1, <sys/ioctl.h> and <sys/termios.h> define some symbols
+ with different values, but <sys/termios.h> defines some ioctl symbols
+ not in <sys/ioctl.h>, so we need it. Our <sys/ioctl.h> should define
+ them with the values from Sun's <sys/ioctl.h>, not <sys/termios.h>.
+ So we include <sys/termios.h> and let <sys/ioctl.h> redefine things.
+ This produces some spurious warnings. */
+
+#ifdef HAVE_sys_termios_h
+#include <sys/termios.h>
+#endif
+
+/* This causes <sys/ioctl.h> to define some necessary data structure. */
+#ifdef sony_news
+#define KANJI
+#endif
+
+#include <sys/ioctl.h>
+
+#ifdef SIOCGIFCONF
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <net/if.h>
+#include <net/route.h>
+#if defined(SIOCGARP) && !defined(ARPOP_REQUEST)
+#include <net/if_arp.h>
+#endif
+#ifdef SIOCGNIT
+#ifdef HAVE_net_nit_h
+#include <net/nit.h>
+#else /* No net/nit.h. */
+#undef SIOCGNIT
+#undef SIOCSNIT
+#endif /* net/nit.h. */
+#endif /* SIOCGNIT. */
+#endif /* SIOCGIFCONF. */
+
+/* These exist on Sequents. */
+#ifdef SMIOSTATS
+#include <sec/sec.h>
+#include <sec/sm.h>
+#endif
+#ifdef SMIOGETREBOOT0
+#include <i386/cfg.h>
+#endif
+#ifdef ZIOCBCMD
+#include <zdc/zdc.h>
+#endif
+
+/* These exist under Ultrix, but I figured there may be others. */
+#ifdef DIOCGETPT
+#include <ufs/fs.h> /* for DIOC* */
+#endif
+#ifdef DEVGETGEOM
+#include <sys/devio.h>
+#endif
+
+#ifdef ultrix
+/* Ultrix has a conditional include that brings these in; we have to force
+ their inclusion when we actually compile them. */
+#undef TCGETA
+#undef TCSETA
+#undef TCSETAW
+#undef TCSETAF
+#undef TCGETP
+#undef TCSANOW
+#undef TCSADRAIN
+#undef TCSAFLUSH
+#ifdef ELSETPID
+#include <sys/un.h> /* get sockaddr_un for elcsd.h */
+#include <elcsd.h>
+#endif
+#ifdef DKIOCDOP
+#include <sys/dkio.h>
+#endif
+/* Couldn't find the header where the structures used by these are
+ defined; it looks like an unbundled LAT package or something. */
+#undef LIOCSOL
+#undef LIOCRES
+#undef LIOCCMD
+#undef LIOCINI
+#undef LIOCTTYI
+#undef LIOCCONN
+/* struct mtop hasn't been in sys/mtio.h since 4.1 */
+#undef MTIOCTOP
+#undef MTIOCGET
+#endif
+
+#if defined(__osf__) && defined(__alpha__)
+#include <sys/ioctl_compat.h> /* To get TIOCGETP, etc. */
+#include <alpha/pt.h> /* for DIOC* */
+#include <sys/mtio.h> /* for MTIOC* */
+/* The binlog_getstatus structure doesn't seem to be defined. */
+#undef BINLOG_GETSTATUS
+/* Can't find `struct ifdata' anywhere. */
+#undef SIOCMANREQ
+#undef SIOCGETEVENTS
+/* OSF/1 smells an awful lot like Ultrix. */
+#undef TCGETA
+#undef TCSETA
+#undef TCSETAF
+#undef TCSETAW
+/* This macro looks screwed in sys/devio.h. */
+#undef DEV_DISKPART
+/* This is in sys/dkio.h, but we don't need it. */
+#undef DKIOCACC
+#undef DKIOCDOP
+#undef DKIOCEXCL
+#undef DKIOCGET
+#undef DKIOCHDR
+/* Introduced by OSF/1 2.0. */
+#undef FIOPIPESTAT
+#undef SIOCSRREQR
+#undef SIOCSRREQW
+#undef SRVC_REQUEST
+#endif
+
+#define DEFINE(name, value) \
+ printf("#define %s 0x%.8x\n", (name), (value))
+
+int
+main()
+{
+ REQUESTS
+
+ exit(0);
+ return 0;
+}
diff --git a/libc/sysdeps/unix/ioctls.awk b/libc/sysdeps/unix/ioctls.awk
new file mode 100644
index 000000000..b05140af7
--- /dev/null
+++ b/libc/sysdeps/unix/ioctls.awk
@@ -0,0 +1,10 @@
+BEGIN { special = 0 }
+
+/REQUESTS/ { nreqs = split(requests, reqs)
+ for (i = 1; i <= nreqs; ++i)
+ printf "#ifdef\t%s\n DEFINE(\"%s\", %s);\n#endif\n", \
+ reqs[i], reqs[i], reqs[i]
+ special = 1 }
+
+
+{ if (special == 0) print $0; special = 0 }
diff --git a/libc/sysdeps/unix/make-syscalls.sh b/libc/sysdeps/unix/make-syscalls.sh
new file mode 100644
index 000000000..0ec8b28fd
--- /dev/null
+++ b/libc/sysdeps/unix/make-syscalls.sh
@@ -0,0 +1,342 @@
+#! /bin/sh
+
+# Usage: make-syscalls.sh ../sysdeps/unix/common
+# Expects $sysdirs in environment.
+
+##############################################################################
+
+# Syscall Signature Key Letters for BP Thunks:
+#
+# a: unchecked address (e.g., 1st arg to mmap)
+# b: non-NULL buffer (e.g., 2nd arg to read; return value from mmap)
+# B: optionally-NULL buffer (e.g., 4th arg to getsockopt)
+# f: buffer of 2 ints (e.g., 4th arg to socketpair)
+# F: 3rd arg to fcntl
+# i: scalar (any signedness & size: int, long, long long, enum, whatever)
+# I: 3rd arg to ioctl
+# n: scalar buffer length (e.g., 3rd arg to read)
+# N: pointer to value/return scalar buffer length (e.g., 6th arg to recvfrom)
+# p: non-NULL pointer to typed object (e.g., any non-void* arg)
+# P: optionally-NULL pointer to typed object (e.g., 2nd argument to gettimeofday)
+# s: non-NULL string (e.g., 1st arg to open)
+# S: optionally-NULL string (e.g., 1st arg to acct)
+# v: vararg scalar (e.g., optional 3rd arg to open)
+# V: byte-per-page vector (3rd arg to mincore)
+# W: wait status, optionally-NULL pointer to int (e.g., 2nd arg of wait4)
+
+ptr='[abBfFINpPsSWV]' # all pointer keyletters
+int='[inv]' # all scalar keyletters
+typ='[ifnNpP]' # typed-arg keyletters: we capture type for use in thunk
+
+##############################################################################
+
+thisdir=$1; shift
+
+echo ''
+echo \#### DIRECTORY = $thisdir
+# Check each sysdep dir with higher priority than this one,
+# and remove from $calls all the functions found in other dirs.
+# Punt when we reach the directory defining these syscalls.
+sysdirs=`for dir in $sysdirs; do
+ test $dir = $thisdir && break; echo $dir; done`
+echo \#### SYSDIRS = $sysdirs
+
+# Get the list of system calls for this directory.
+calls=`sed 's/#.*$//
+/^[ ]*$/d' $thisdir/syscalls.list`
+
+calls=`echo "$calls" |
+while read file caller rest; do
+ # Remove each syscall that is implemented by a file in $dir.
+ # If a syscall specified a "caller", then only compile that syscall
+ # if the caller function is also implemented in this directory.
+ srcfile=-;
+ for dir in $sysdirs; do
+ { test -f $dir/$file.c && srcfile=$dir/$file.c; } ||
+ { test -f $dir/$file.S && srcfile=$dir/$file.S; } ||
+ { test -f $dir/$file.s && srcfile=$dir/$file.s; } ||
+ { test x$caller != x- &&
+ { { test -f $dir/$caller.c && srcfile=$dir/$caller.c; } ||
+ { test -f $dir/$caller.S && srcfile=$dir/$caller.S; } ||
+ { test -f $dir/$caller.s && srcfile=$dir/$caller.s; }; }; } && break;
+ done;
+ echo $file $srcfile $caller $rest;
+done`
+
+# Any calls left?
+test -n "$calls" || exit 0
+
+# Emit rules to compile the syscalls remaining in $calls.
+echo "$calls" |
+while read file srcfile caller syscall args strong weak; do
+
+ case x"$syscall" in
+ x-) callnum=_ ;;
+ *)
+ # Figure out if $syscall is defined with a number in syscall.h.
+ callnum=-
+ eval `{ echo "#include <sysdep.h>";
+ echo "callnum=SYS_ify ($syscall)"; } |
+ $asm_CPP -D__OPTIMIZE__ - |
+ sed -n -e "/^callnum=.*$syscall/d" \
+ -e "/^\(callnum=\)[ ]*\(.*\)/s//\1'\2'/p"`
+ ;;
+ esac
+
+ cancellable=
+ noerrno=
+ case $args in
+ C*) cancellable=-cancel; args=`echo $args | sed 's/C:\?//'`;;
+ E*) noerrno=_NOERRNO; args=`echo $args | sed 's/E:\?//'`;;
+ V*) noerrno=_ERRVAL; args=`echo $args | sed 's/V:\?//'`;;
+ esac
+
+ # Derive the number of arguments from the argument signature
+ case $args in
+ [0-9]) nargs=$args;;
+ ?:) nargs=0;;
+ ?:?) nargs=1;;
+ ?:??) nargs=2;;
+ ?:???) nargs=3;;
+ ?:????) nargs=4;;
+ ?:?????) nargs=5;;
+ ?:??????) nargs=6;;
+ ?:???????) nargs=7;;
+ ?:????????) nargs=8;;
+ ?:?????????) nargs=9;;
+ esac
+
+ # Make sure only the first syscall rule is used, if multiple dirs
+ # define the same syscall.
+ echo ''
+ echo "#### CALL=$file NUMBER=$callnum ARGS=$args SOURCE=$srcfile"
+
+ case x$srcfile"$callnum" in
+ x--)
+ # Undefined callnum for an extra syscall.
+ if [ x$caller != x- ]; then
+ if [ x$noerrno != x ]; then
+ echo >&2 "$0: no number for $fileno, no-error syscall ($strong $weak)"
+ exit 2
+ fi
+ echo "unix-stub-syscalls += $strong $weak"
+ fi
+ ;;
+ x*-) ;; ### Do nothing for undefined callnum
+ x-*)
+ echo "ifeq (,\$(filter $file,\$(unix-syscalls)))"
+
+ case $weak in
+ *@*)
+ # The versioned symbols are only in the shared library.
+ echo "ifneq (,\$(filter .os,\$(object-suffixes)))"
+ ;;
+ esac
+ # Accumulate the list of syscall files for this directory.
+ echo "unix-syscalls += $file"
+ test x$caller = x- || echo "unix-extra-syscalls += $file"
+
+ # Emit a compilation rule for this syscall.
+ case $weak in
+ *@*)
+ # The versioned symbols are only in the shared library.
+ echo "\
+shared-only-routines += $file
+\$(objpfx)${file}.os: \\"
+ ;;
+ *)
+ echo "\
+\$(foreach o,\$(object-suffixes),\$(objpfx)$file\$o) \
+\$(foreach o,\$(object-suffixes),\$(objpfx)ptw-$file\$o) \
+\$(objpfx)rtld-$file.os: \\"
+ ;;
+ esac
+
+ echo " \$(common-objpfx)s-proto$cancellable.d"
+ case x"$callnum" in
+ x_)
+ echo "\
+ (echo '/* Dummy module requested by syscalls.list */'; \\"
+ ;;
+ x*)
+ echo "\
+ \$(make-target-directory)
+ (echo '#include <sysdep$cancellable.h>'; \\
+ echo 'PSEUDO$noerrno ($strong, $syscall, $nargs)'; \\
+ echo ' ret$noerrno'; \\
+ echo 'PSEUDO_END$noerrno($strong)'; \\
+ echo 'libc_hidden_def ($strong)'; \\"
+ ;;
+ esac
+
+ # Append any weak aliases or versions defined for this syscall function.
+
+ # A shortcoming in the current gas is that it will only allow one
+ # version-alias per symbol. So we create new strong aliases as needed.
+ vcount=""
+
+ for name in $weak; do
+ case $name in
+ *@@*)
+ base=`echo $name | sed 's/@@.*//'`
+ ver=`echo $name | sed 's/.*@@//'`
+ if test -z "$vcount" ; then
+ source=$strong
+ vcount=1
+ else
+ source="${strong}_${vcount}"
+ vcount=`expr $vcount + 1`
+ echo " echo 'strong_alias ($strong, $source)'; \\"
+ fi
+ echo " echo 'default_symbol_version($source, $base, $ver)'; \\"
+ ;;
+ *@*)
+ base=`echo $name | sed 's/@.*//'`
+ ver=`echo $name | sed 's/.*@//'`
+ if test -z "$vcount" ; then
+ source=$strong
+ vcount=1
+ else
+ source="${strong}_${vcount}"
+ vcount=`expr $vcount + 1`
+ echo " echo 'strong_alias ($strong, $source)'; \\"
+ fi
+ echo " echo 'symbol_version($source, $base, $ver)'; \\"
+ ;;
+ !*)
+ name=`echo $name | sed 's/.//'`
+ echo " echo 'strong_alias ($strong, $name)'; \\"
+ echo " echo 'libc_hidden_def ($name)'; \\"
+ ;;
+ *)
+ echo " echo 'weak_alias ($strong, $name)'; \\"
+ echo " echo 'libc_hidden_weak ($name)'; \\"
+ ;;
+ esac
+ done
+
+ # And finally, pipe this all into the compiler.
+ echo ' ) | $(compile-syscall)'
+
+ case $weak in
+ *@*)
+ # The versioned symbols are only in the shared library.
+ echo endif
+ ;;
+ esac
+
+ echo endif
+ ;;
+ esac
+
+ case x"$callnum",$srcfile,$args in
+ x[_-],-,* | x*,*.[sS],*V*) ;;
+ x*,-,*$ptr* | x*,*.[sS],*$ptr*)
+
+ nv_weak=`for name in $weak; do
+ case $name in
+ *@*) ;;
+ *) echo $name;;
+ esac; done`
+
+ # choose the name with the fewest leading underscores, preferably none
+ set `echo $strong $nv_weak |tr '@ \t' ' \n\n' |sort -r`
+ callname=$1
+
+ # convert signature string to individual numbered arg names
+ # e.g., i:ipbN -> i0 i1 p2 b3 N4
+ set `echo $args |
+ sed -e 's/^\(.\):\(.*\)/\2 <\10>/' \
+ -e 's/^\([^ ]\)\(.*\)/\2 <\11>/' \
+ -e 's/^\([^ ]\)\(.*\)/\2 <\12>/' \
+ -e 's/^\([^ ]\)\(.*\)/\2 <\13>/' \
+ -e 's/^\([^ ]\)\(.*\)/\2 <\14>/' \
+ -e 's/^\([^ ]\)\(.*\)/\2 <\15>/' \
+ -e 's/^\([^ ]\)\(.*\)/\2 <\16>/' \
+ -e 's/^\([^ ]\)\(.*\)/\2 <\17>/' \
+ -e 's/^\([^ ]\)\(.*\)/\2 <\18>/' \
+ -e 's/^\([^ ]\)\(.*\)/\2 <\19>/'`
+ rtn=$1; shift
+ args=$*
+ arglist=`echo $* |sed 's/ /, /g'`
+
+ # The best way to understand what's going on here is to examine
+ # the output in BUILDDIR/sysd-syscalls.
+
+ # generate makefile envelope & rule head
+ echo "ifeq (,\$(filter $file,\$(bp-thunks)))"
+ echo "bp-thunks += $file"
+ echo "\$(objpfx)\$(bppfx)$file.ob: \$(common-objpfx)s-proto-bp.d"
+
+ # generate macro head
+ echo " (echo '#define $callname(`echo $arglist | \
+ sed -e 's/[<>]//g'`) `echo $rtn | \
+ sed -e 's/<\('$typ'0\)>/\1v;/g' \
+ -e 's/<\(b0\)>/x0; extern char \1v;/g'` \\'; \\"
+
+ # generate extern decls of dummy variables for each arg
+ echo " echo '`echo $args | \
+ sed -e 's/<\('$typ'[1-9]\)>/extern \1, \1v;/g' \
+ -e 's/<\([abBFIsSV][1-9]\)>/extern char \1v;/g' \
+ -e 's/<\([Wv][1-9]\)>/extern int \1v;/g'` \\'; \\"
+
+ # generate bounded-pointer thunk declarator
+ echo " echo '`echo $rtn | \
+ sed -e 's/<\('$ptr'0\)>/__typeof (\1v) *__bounded/g' \
+ -e 's/<\('$int'0\)>/__typeof (\1v)/g'` BP_SYM ($strong) (`echo $arglist | \
+ sed -e 's/<\('$ptr'[1-9]\)>/__typeof (\1v) *__bounded \1a/g' \
+ -e 's/<\('$int'[1-9]\)>/__typeof (\1v) \1a/g'`) { \\'; \\"
+
+ # generate extern primitive syscall declaration
+ echo " echo ' extern `echo $rtn | \
+ sed -e 's/<\('$ptr'0\)>/__typeof (\1v) *__unbounded/g' \
+ -e 's/<\('$int'0\)>/__typeof (\1v)/g'` ($callname) (`echo $arglist | \
+ sed -e 's/<\('$ptr'[1-9]\)>/__typeof (\1v) *__unbounded/g' \
+ -e 's/<\('$int'[1-9]\)>/__typeof (\1v)/g'`); \\'; \\"
+
+ # generate call the primtive system call, optionally wrapping bounds
+ # around the result if the signature's return keyletter is `b'.
+ echo " echo ' return `echo $rtn |
+ sed -e 's/<b0>/BOUNDED_N (/' \
+ -e 's/<.0>//'`($callname) (`echo $arglist | \
+ sed -e 's/<\(a[1-9]\)>/__ptrvalue (\1a)/g' \
+ -e 's/<\(n[1-9]\)>, <\(V[1-9]\)>/\1a, CHECK_N_PAGES (\2a, \1a)/g' \
+ -e 's/<\(b[1-9]\)>, <\(n[1-9]\)>/CHECK_N (\1a, \2a), \2a/g' \
+ -e 's/<\(b[1-9]\)>, <\(N[1-9]\)>/CHECK_N (\1a, *CHECK_1 (\2a)), __ptrvalue (\2a)/g' \
+ -e 's/<\(B[1-9]\)>, <\(n[1-9]\)>/CHECK_N_NULL_OK (\1a, \2a), \2a/g' \
+ -e 's/<\(B[1-9]\)>, <\(N[1-9]\)>/CHECK_N_NULL_OK (\1a, *CHECK_1 (\2a)), __ptrvalue (\2a)/g' \
+ -e 's/<\(f[1-9]\)>/CHECK_N (\1a, 2)/g' \
+ -e 's/<\(i[1-9]\)>, <\(F[1-9]\)>/\1a, CHECK_FCNTL (\2a, \1a)/g' \
+ -e 's/<\(i[1-9]\)>, <\(I[1-9]\)>/\1a, CHECK_IOCTL (\2a, \1a)/g' \
+ -e 's/<\(p[1-9]\)>/CHECK_1 (\1a)/g' \
+ -e 's/<\([PW][1-9]\)>/CHECK_1_NULL_OK (\1a)/g' \
+ -e 's/<\(s[1-9]\)>/CHECK_STRING (\1a)/g' \
+ -e 's/<\(S[1-9]\)>/CHECK_STRING_NULL_OK (\1a)/g' \
+ -e 's/<\([ivn][1-9]\)>/\1a/g'`)`echo $rtn $args |
+ sed -e 's/<b0>.*<\(n[1-9]\)>.*/, \1a)/' \
+ -e 's/<.0>.*//'`; \\'; \\"
+
+ echo " echo '} \\'; \\"
+
+ echo " echo 'libc_hidden_def (BP_SYM ($strong)) \\'; \\"
+
+ # generate thunk aliases
+ for name in $nv_weak; do
+ echo " echo 'weak_alias (BP_SYM ($strong), BP_SYM ($name)) \\'; \\"
+ echo " echo 'libc_hidden_weak (BP_SYM ($name)) \\'; \\"
+ done
+
+ # wrap up
+ echo "\
+ echo ''; \\
+ echo '#include <bp-thunks.h>'; \\
+ ) | \$(COMPILE.c) -x c -o \$@ -"
+### Use this for debugging intermediate output:
+### ) >\$(@:.ob=.c)
+### \$(subst -c,-E,\$(COMPILE.c)) -o \$(@:.ob=.ib) \$(@:.ob=.c)
+### \$(COMPILE.c) -x cpp-output -o \$@ \$(@:.ob=.ib)"
+ echo endif
+ ;;
+ esac
+
+done
diff --git a/libc/sysdeps/unix/mk-local_lim.c b/libc/sysdeps/unix/mk-local_lim.c
new file mode 100644
index 000000000..5db0214cc
--- /dev/null
+++ b/libc/sysdeps/unix/mk-local_lim.c
@@ -0,0 +1,126 @@
+/* Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdio.h>
+#include <sys/types.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+
+#ifdef HAVE_SYS_LIMITS_H
+#include <sys/limits.h>
+#endif
+
+/* Generate bits/local_lim.h from the values defined in the system's
+ headers. */
+
+struct param
+ {
+ char *name;
+ int value;
+ };
+
+static struct param params[] =
+ {
+
+#if !defined (ARG_MAX) && defined (NCARGS)
+#define ARG_MAX NCARGS
+#endif
+#ifdef ARG_MAX
+ { "ARG_MAX", ARG_MAX },
+#endif
+
+#if !defined (CHILD_MAX) && defined (MAXUPRC)
+#define CHILD_MAX MAXUPRC
+#endif
+#ifdef CHILD_MAX
+ { "CHILD_MAX", CHILD_MAX },
+#endif
+
+#if !defined (LINK_MAX) && defined (MAXLINK)
+#define LINK_MAX MAXLINK
+#endif
+#ifdef LINK_MAX
+ { "LINK_MAX", LINK_MAX },
+#endif
+
+#if !defined (OPEN_MAX) && defined (NOFILE)
+#define OPEN_MAX NOFILE
+#endif
+#ifdef OPEN_MAX
+ { "OPEN_MAX", OPEN_MAX },
+#endif
+
+#if !defined (MAX_CANON) && defined (CANBSIZ)
+#define MAX_CANON CANBSIZ
+#endif
+#ifdef MAX_CANON
+ { "MAX_CANON", MAX_CANON },
+#endif
+
+#if !defined (NAME_MAX) && defined (MAXNAMLEN)
+#define NAME_MAX MAXNAMLEN
+#endif
+#ifndef NAME_MAX
+#define NAME_MAX 255 /* XXX ? */
+#endif
+ { "NAME_MAX", NAME_MAX },
+
+#if !defined (PATH_MAX) && defined (MAXPATHLEN)
+#define PATH_MAX MAXPATHLEN
+#endif
+#ifdef PATH_MAX
+ { "PATH_MAX", PATH_MAX },
+#endif
+
+#if !defined (SYMLOOP_MAX) && defined (MAXSYMLINKS)
+#define SYMLOOP_MAX MAXSYMLINKS
+#endif
+#ifdef SYMLOOP_MAX
+ { "SYMLOOP_MAX", SYMLOOP_MAX },
+#endif
+
+ { NULL, 0 }
+ };
+
+int
+main()
+{
+ extern char *ctime ();
+ extern time_t time ();
+ time_t now = time ((time_t *) NULL);
+ register struct param *p;
+
+ if (! params[0].name)
+ /* We have no information to give, so let the caller know. */
+ exit (1);
+
+ printf ("\
+/* Implementation-specific limits.\n\
+ Generated at %.24s. */\n\n", ctime (&now));
+
+ for (p = params; p->name != NULL; ++p)
+ printf ("#define %s %d\n", p->name, p->value);
+
+ exit (0);
+}
diff --git a/libc/sysdeps/unix/mkdir.c b/libc/sysdeps/unix/mkdir.c
new file mode 100644
index 000000000..dac88acb1
--- /dev/null
+++ b/libc/sysdeps/unix/mkdir.c
@@ -0,0 +1,98 @@
+/* Copyright (C) 1992, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <string.h>
+
+/* Create a directory named PATH with protections MODE. */
+int
+__mkdir (path, mode)
+ const char *path;
+ mode_t mode;
+{
+ char *cmd = __alloca (80 + strlen (path));
+ char *p;
+ int status;
+ mode_t mask;
+ int save;
+ struct stat statbuf;
+
+ if (path == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* Check for some errors. */
+ if (__stat (path, &statbuf) < 0)
+ {
+ if (errno != ENOENT)
+ return -1;
+ /* There is no file by that name. Good. */
+ }
+ else
+ {
+ __set_errno (EEXIST);
+ return -1;
+ }
+
+ /* Race condition, but how else to do it? */
+ mask = __umask (0777);
+ (void) __umask (mask);
+
+ p = cmd;
+ *p++ = 'm';
+ *p++ = 'k';
+ *p++ = 'd';
+ *p++ = 'i';
+ *p++ = 'r';
+ *p++ = ' ';
+
+ mode &= ~mask;
+ *p++ = '-';
+ *p++ = 'm';
+ *p++ = ' ';
+ *p++ = ((mode & 07000) >> 9) + '0';
+ *p++ = ((mode & 0700) >> 6) + '0';
+ *p++ = ((mode & 070) >> 3) + '0';
+ *p++ = ((mode & 07)) + '0';
+ *p++ = ' ';
+
+ strcpy (p, path);
+
+ save = errno;
+ /* If system doesn't set errno, but the mkdir fails, we really
+ have no idea what went wrong. EIO is the vaguest error I
+ can think of, so I'll use that. */
+ __set_errno (EIO);
+ status = system (cmd);
+ if (WIFEXITED (status) && WEXITSTATUS (status) == 0)
+ {
+ __set_errno (save);
+ return 0;
+ }
+ else
+ return -1;
+}
+
+weak_alias (__mkdir, mkdir)
diff --git a/libc/sysdeps/unix/mkfifo.c b/libc/sysdeps/unix/mkfifo.c
new file mode 100644
index 000000000..40676897e
--- /dev/null
+++ b/libc/sysdeps/unix/mkfifo.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+/* Create a named pipe (FIFO) named PATH with protections MODE. */
+int
+mkfifo (const char *path, mode_t mode)
+{
+ dev_t dev = 0;
+ return __xmknod (_MKNOD_VER, path, mode | S_IFIFO, &dev);
+}
diff --git a/libc/sysdeps/unix/mkfifoat.c b/libc/sysdeps/unix/mkfifoat.c
new file mode 100644
index 000000000..5c4da2a98
--- /dev/null
+++ b/libc/sysdeps/unix/mkfifoat.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/stat.h>
+
+
+/* Create a new FIFO with permission bits MODE. But interpret
+ relative PATH names relative to the directory associated with FD. */
+int
+mkfifoat (fd, file, mode)
+ int fd;
+ const char *file;
+ mode_t mode;
+{
+ dev_t dev = 0;
+ return __xmknodat (_MKNOD_VER, fd, file, mode | S_IFIFO, &dev);
+}
diff --git a/libc/sysdeps/unix/mman/syscalls.list b/libc/sysdeps/unix/mman/syscalls.list
new file mode 100644
index 000000000..7db8eb772
--- /dev/null
+++ b/libc/sysdeps/unix/mman/syscalls.list
@@ -0,0 +1,11 @@
+# This interface desciption corresponds to the POSIX.1 description. The
+# 4.4BSD interface is slightly different since the `msync' function takes
+# only 2 arguments.
+
+# File name Caller Syscall name # args Strong name Weak names
+
+madvise - madvise i:pii madvise
+mmap - mmap b:aniiii __mmap mmap
+mprotect - mprotect i:aii __mprotect mprotect
+msync - msync Ci:aii __libc_msync msync
+munmap - munmap i:ai __munmap munmap
diff --git a/libc/sysdeps/unix/nice.c b/libc/sysdeps/unix/nice.c
new file mode 100644
index 000000000..eb26c43a6
--- /dev/null
+++ b/libc/sysdeps/unix/nice.c
@@ -0,0 +1,53 @@
+/* Copyright (C) 1992, 1996, 1997, 2001, 2002, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/resource.h>
+
+/* Increment the scheduling priority of the calling process by INCR.
+ The superuser may use a negative INCR to decrement the priority. */
+int
+nice (int incr)
+{
+ int save;
+ int prio;
+ int result;
+
+ /* -1 is a valid priority, so we use errno to check for an error. */
+ save = errno;
+ __set_errno (0);
+ prio = getpriority (PRIO_PROCESS, 0);
+ if (prio == -1)
+ {
+ if (errno != 0)
+ return -1;
+ else
+ __set_errno (save);
+ }
+
+ result = setpriority (PRIO_PROCESS, 0, prio + incr);
+ if (result == -1)
+ {
+ if (errno == EACCES)
+ errno = EPERM;
+ return -1;
+ }
+ return getpriority (PRIO_PROCESS, 0);
+}
diff --git a/libc/sysdeps/unix/opendir.c b/libc/sysdeps/unix/opendir.c
new file mode 100644
index 000000000..6aa738fb6
--- /dev/null
+++ b/libc/sysdeps/unix/opendir.c
@@ -0,0 +1,179 @@
+/* Copyright (C) 1991-1996,98,2000-2003,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <limits.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <dirstream.h>
+#include <not-cancel.h>
+
+
+/* opendir() must not accidentally open something other than a directory.
+ Some OS's have kernel support for that, some don't. In the worst
+ case we have to stat() before the open() AND fstat() after.
+
+ We have to test at runtime for kernel support since libc may have
+ been compiled with different headers to the kernel it's running on.
+ This test can't be done reliably in the general case. We'll use
+ /dev/null, which if it's not a device lots of stuff will break, as
+ a guinea pig. It may be missing in chroot environments, so we
+ make sure to fail safe. */
+#ifdef O_DIRECTORY
+# ifdef O_DIRECTORY_WORKS
+# define o_directory_works 1
+# define tryopen_o_directory() while (1) /* This must not be called. */
+# else
+static int o_directory_works;
+
+static void
+tryopen_o_directory (void)
+{
+ int serrno = errno;
+ int x = open_not_cancel_2 ("/dev/null", O_RDONLY|O_NDELAY|O_DIRECTORY);
+
+ if (x >= 0)
+ {
+ close_not_cancel_no_status (x);
+ o_directory_works = -1;
+ }
+ else if (errno != ENOTDIR)
+ o_directory_works = -1;
+ else
+ o_directory_works = 1;
+
+ __set_errno (serrno);
+}
+# endif
+# define EXTRA_FLAGS O_DIRECTORY
+#else
+# define EXTRA_FLAGS 0
+#endif
+
+
+/* Open a directory stream on NAME. */
+DIR *
+__opendir (const char *name)
+{
+ struct stat64 statbuf;
+
+ if (__builtin_expect (name[0], '\1') == '\0')
+ {
+ /* POSIX.1-1990 says an empty name gets ENOENT;
+ but `open' might like it fine. */
+ __set_errno (ENOENT);
+ return NULL;
+ }
+
+#ifdef O_DIRECTORY
+ /* Test whether O_DIRECTORY works. */
+ if (o_directory_works == 0)
+ tryopen_o_directory ();
+
+ /* We can skip the expensive `stat' call if O_DIRECTORY works. */
+ if (o_directory_works < 0)
+#endif
+ {
+ /* We first have to check whether the name is for a directory. We
+ cannot do this after the open() call since the open/close operation
+ performed on, say, a tape device might have undesirable effects. */
+ if (__builtin_expect (__xstat64 (_STAT_VER, name, &statbuf), 0) < 0)
+ return NULL;
+ if (__builtin_expect (! S_ISDIR (statbuf.st_mode), 0))
+ {
+ __set_errno (ENOTDIR);
+ return NULL;
+ }
+ }
+
+ int fd = open_not_cancel_2 (name, O_RDONLY|O_NDELAY|EXTRA_FLAGS|O_LARGEFILE);
+ if (__builtin_expect (fd, 0) < 0)
+ return NULL;
+
+ /* Now make sure this really is a directory and nothing changed since
+ the `stat' call. We do not have to perform the test for the
+ descriptor being associated with a directory if we know the
+ O_DIRECTORY flag is honored by the kernel. */
+ if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &statbuf), 0) < 0)
+ goto lose;
+#ifdef O_DIRECTORY
+ if (o_directory_works <= 0)
+#endif
+ {
+ if (__builtin_expect (! S_ISDIR (statbuf.st_mode), 0))
+ {
+ __set_errno (ENOTDIR);
+ lose:
+ close_not_cancel_no_status (fd);
+ return NULL;
+ }
+ }
+
+ return __alloc_dir (fd, true, &statbuf);
+}
+weak_alias (__opendir, opendir)
+
+
+DIR *
+internal_function
+__alloc_dir (int fd, bool close_fd, const struct stat64 *statp)
+{
+ if (__builtin_expect (__fcntl (fd, F_SETFD, FD_CLOEXEC), 0) < 0)
+ goto lose;
+
+ size_t allocation;
+#ifdef _STATBUF_ST_BLKSIZE
+ if (__builtin_expect ((size_t) statp->st_blksize >= sizeof (struct dirent64),
+ 1))
+ allocation = statp->st_blksize;
+ else
+#endif
+ allocation = (BUFSIZ < sizeof (struct dirent64)
+ ? sizeof (struct dirent64) : BUFSIZ);
+
+ const int pad = -sizeof (DIR) % __alignof__ (struct dirent64);
+
+ DIR *dirp = (DIR *) malloc (sizeof (DIR) + allocation + pad);
+ if (dirp == NULL)
+ lose:
+ {
+ if (close_fd)
+ {
+ int save_errno = errno;
+ close_not_cancel_no_status (fd);
+ __set_errno (save_errno);
+ }
+ return NULL;
+ }
+ memset (dirp, '\0', sizeof (DIR));
+ dirp->data = (char *) (dirp + 1) + pad;
+ dirp->allocation = allocation;
+ dirp->fd = fd;
+
+ __libc_lock_init (dirp->lock);
+
+ return dirp;
+}
diff --git a/libc/sysdeps/unix/powerpc/sysdep.h b/libc/sysdeps/unix/powerpc/sysdep.h
new file mode 100644
index 000000000..90c1e49e8
--- /dev/null
+++ b/libc/sysdeps/unix/powerpc/sysdep.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 1991, 92, 93, 95, 96, 97, 1999, 2002
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/unix/sysdep.h>
+#include <bits/wordsize.h>
+#if __WORDSIZE == 64
+#include <sysdeps/powerpc/powerpc64/sysdep.h>
+#else
+#include <sysdeps/powerpc/powerpc32/sysdep.h>
+#endif
diff --git a/libc/sysdeps/unix/readdir.c b/libc/sysdeps/unix/readdir.c
new file mode 100644
index 000000000..4a0f0890e
--- /dev/null
+++ b/libc/sysdeps/unix/readdir.c
@@ -0,0 +1,120 @@
+/* Copyright (C) 1991,92,93,94,95,96,97,99,2000,02
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <limits.h>
+#include <stddef.h>
+#include <string.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <assert.h>
+
+#include <dirstream.h>
+
+#ifndef __READDIR
+# define __READDIR __readdir
+# define __GETDENTS __getdents
+# define DIRENT_TYPE struct dirent
+# define __READDIR_ALIAS
+#endif
+
+/* Read a directory entry from DIRP. */
+DIRENT_TYPE *
+__READDIR (DIR *dirp)
+{
+ DIRENT_TYPE *dp;
+ int saved_errno = errno;
+
+ __libc_lock_lock (dirp->lock);
+
+ do
+ {
+ size_t reclen;
+
+ if (dirp->offset >= dirp->size)
+ {
+ /* We've emptied out our buffer. Refill it. */
+
+ size_t maxread;
+ ssize_t bytes;
+
+#ifndef _DIRENT_HAVE_D_RECLEN
+ /* Fixed-size struct; must read one at a time (see below). */
+ maxread = sizeof *dp;
+#else
+ maxread = dirp->allocation;
+#endif
+
+ bytes = __GETDENTS (dirp->fd, dirp->data, maxread);
+ if (bytes <= 0)
+ {
+ /* On some systems getdents fails with ENOENT when the
+ open directory has been rmdir'd already. POSIX.1
+ requires that we treat this condition like normal EOF. */
+ if (bytes < 0 && errno == ENOENT)
+ bytes = 0;
+
+ /* Don't modifiy errno when reaching EOF. */
+ if (bytes == 0)
+ __set_errno (saved_errno);
+ dp = NULL;
+ break;
+ }
+ dirp->size = (size_t) bytes;
+
+ /* Reset the offset into the buffer. */
+ dirp->offset = 0;
+ }
+
+ dp = (DIRENT_TYPE *) &dirp->data[dirp->offset];
+
+#ifdef _DIRENT_HAVE_D_RECLEN
+ reclen = dp->d_reclen;
+#else
+ /* The only version of `struct dirent*' that lacks `d_reclen'
+ is fixed-size. */
+ assert (sizeof dp->d_name > 1);
+ reclen = sizeof *dp;
+ /* The name is not terminated if it is the largest possible size.
+ Clobber the following byte to ensure proper null termination. We
+ read jst one entry at a time above so we know that byte will not
+ be used later. */
+ dp->d_name[sizeof dp->d_name] = '\0';
+#endif
+
+ dirp->offset += reclen;
+
+#ifdef _DIRENT_HAVE_D_OFF
+ dirp->filepos = dp->d_off;
+#else
+ dirp->filepos += reclen;
+#endif
+
+ /* Skip deleted files. */
+ } while (dp->d_ino == 0);
+
+ __libc_lock_unlock (dirp->lock);
+
+ return dp;
+}
+
+#ifdef __READDIR_ALIAS
+weak_alias (__readdir, readdir)
+#endif
diff --git a/libc/sysdeps/unix/readdir_r.c b/libc/sysdeps/unix/readdir_r.c
new file mode 100644
index 000000000..f84709e73
--- /dev/null
+++ b/libc/sysdeps/unix/readdir_r.c
@@ -0,0 +1,127 @@
+/* Copyright (C) 1991,92,93,94,95,96,97,98,99,2000,02
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <limits.h>
+#include <stddef.h>
+#include <string.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <assert.h>
+
+#include <dirstream.h>
+
+#ifndef __READDIR_R
+# define __READDIR_R __readdir_r
+# define __GETDENTS __getdents
+# define DIRENT_TYPE struct dirent
+# define __READDIR_R_ALIAS
+#endif
+
+/* Read a directory entry from DIRP. */
+int
+__READDIR_R (DIR *dirp, DIRENT_TYPE *entry, DIRENT_TYPE **result)
+{
+ DIRENT_TYPE *dp;
+ size_t reclen;
+ const int saved_errno = errno;
+
+ __libc_lock_lock (dirp->lock);
+
+ do
+ {
+ if (dirp->offset >= dirp->size)
+ {
+ /* We've emptied out our buffer. Refill it. */
+
+ size_t maxread;
+ ssize_t bytes;
+
+#ifndef _DIRENT_HAVE_D_RECLEN
+ /* Fixed-size struct; must read one at a time (see below). */
+ maxread = sizeof *dp;
+#else
+ maxread = dirp->allocation;
+#endif
+
+ bytes = __GETDENTS (dirp->fd, dirp->data, maxread);
+ if (bytes <= 0)
+ {
+ /* On some systems getdents fails with ENOENT when the
+ open directory has been rmdir'd already. POSIX.1
+ requires that we treat this condition like normal EOF. */
+ if (bytes < 0 && errno == ENOENT)
+ {
+ bytes = 0;
+ __set_errno (saved_errno);
+ }
+
+ dp = NULL;
+ /* Reclen != 0 signals that an error occurred. */
+ reclen = bytes != 0;
+ break;
+ }
+ dirp->size = (size_t) bytes;
+
+ /* Reset the offset into the buffer. */
+ dirp->offset = 0;
+ }
+
+ dp = (DIRENT_TYPE *) &dirp->data[dirp->offset];
+
+#ifdef _DIRENT_HAVE_D_RECLEN
+ reclen = dp->d_reclen;
+#else
+ /* The only version of `struct dirent*' that lacks `d_reclen'
+ is fixed-size. */
+ assert (sizeof dp->d_name > 1);
+ reclen = sizeof *dp;
+ /* The name is not terminated if it is the largest possible size.
+ Clobber the following byte to ensure proper null termination. We
+ read just one entry at a time above so we know that byte will not
+ be used later. */
+ dp->d_name[sizeof dp->d_name] = '\0';
+#endif
+
+ dirp->offset += reclen;
+
+#ifdef _DIRENT_HAVE_D_OFF
+ dirp->filepos = dp->d_off;
+#else
+ dirp->filepos += reclen;
+#endif
+
+ /* Skip deleted files. */
+ }
+ while (dp->d_ino == 0);
+
+ if (dp != NULL)
+ *result = memcpy (entry, dp, reclen);
+ else
+ *result = NULL;
+
+ __libc_lock_unlock (dirp->lock);
+
+ return dp != NULL ? 0 : reclen ? errno : 0;
+}
+
+#ifdef __READDIR_R_ALIAS
+weak_alias (__readdir_r, readdir_r)
+#endif
diff --git a/libc/sysdeps/unix/rewinddir.c b/libc/sysdeps/unix/rewinddir.c
new file mode 100644
index 000000000..051e93595
--- /dev/null
+++ b/libc/sysdeps/unix/rewinddir.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1991, 1995-1998, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <dirstream.h>
+
+/* Rewind DIRP to the beginning of the directory. */
+/* XXX should be __rewinddir ? */
+void
+rewinddir (dirp)
+ DIR *dirp;
+{
+ __libc_lock_lock (dirp->lock);
+ (void) __lseek (dirp->fd, (off_t) 0, SEEK_SET);
+ dirp->filepos = 0;
+ dirp->offset = 0;
+ dirp->size = 0;
+ __libc_lock_unlock (dirp->lock);
+}
diff --git a/libc/sysdeps/unix/rmdir.c b/libc/sysdeps/unix/rmdir.c
new file mode 100644
index 000000000..ac68d280c
--- /dev/null
+++ b/libc/sysdeps/unix/rmdir.c
@@ -0,0 +1,78 @@
+/* Copyright (C) 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <string.h>
+
+/* Create a directory named PATH with protections MODE. */
+int
+__rmdir (path)
+ const char *path;
+{
+ char *cmd = __alloca (80 + strlen (path));
+ char *p;
+ int status;
+ int save;
+ struct stat statbuf;
+
+ if (path == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* Check for some errors. */
+ if (__stat (path, &statbuf) < 0)
+ return -1;
+ if (!S_ISDIR (statbuf.st_mode))
+ {
+ __set_errno (ENOTDIR);
+ return -1;
+ }
+
+ p = cmd;
+ *p++ = 'r';
+ *p++ = 'm';
+ *p++ = 'd';
+ *p++ = 'i';
+ *p++ = 'r';
+ *p++ = ' ';
+
+ strcpy (p, path);
+
+ save = errno;
+ /* If system doesn't set errno, but the rmdir fails, we really
+ have no idea what went wrong. EIO is the vaguest error I
+ can think of, so I'll use that. */
+ __set_errno (EIO);
+ status = system (cmd);
+ if (WIFEXITED (status) && WEXITSTATUS (status) == 0)
+ {
+ return 0;
+ __set_errno (save);
+ }
+ else
+ return -1;
+}
+
+weak_alias (__rmdir, rmdir)
diff --git a/libc/sysdeps/unix/s-proto-bp.S b/libc/sysdeps/unix/s-proto-bp.S
new file mode 100644
index 000000000..ba0363e16
--- /dev/null
+++ b/libc/sysdeps/unix/s-proto-bp.S
@@ -0,0 +1,4 @@
+/* This file exists just to have its dependencies determined.
+ Those dependencies are then used for the bp thunk objects. */
+
+#include <bp-thunks.h>
diff --git a/libc/sysdeps/unix/s-proto-cancel.S b/libc/sysdeps/unix/s-proto-cancel.S
new file mode 100644
index 000000000..042be3c8d
--- /dev/null
+++ b/libc/sysdeps/unix/s-proto-cancel.S
@@ -0,0 +1,5 @@
+/* This file exists just to have its dependencies determined.
+ Those dependencies are then used for the objects of the cancellable
+ system calls. */
+
+#include <sysdep-cancel.h>
diff --git a/libc/sysdeps/unix/s-proto.S b/libc/sysdeps/unix/s-proto.S
new file mode 100644
index 000000000..52a197036
--- /dev/null
+++ b/libc/sysdeps/unix/s-proto.S
@@ -0,0 +1,4 @@
+/* This file exists just to have its dependencies determined.
+ Those dependencies are then used for the simple system call objects. */
+
+#include <sysdep.h>
diff --git a/libc/sysdeps/unix/seekdir.c b/libc/sysdeps/unix/seekdir.c
new file mode 100644
index 000000000..1790e6237
--- /dev/null
+++ b/libc/sysdeps/unix/seekdir.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 1991,1995,1996,1997,1999,2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <dirstream.h>
+
+/* Seek to position POS in DIRP. */
+/* XXX should be __seekdir ? */
+void
+seekdir (dirp, pos)
+ DIR *dirp;
+ long int pos;
+{
+ __libc_lock_lock (dirp->lock);
+ (void) __lseek (dirp->fd, pos, SEEK_SET);
+ dirp->size = 0;
+ dirp->offset = 0;
+ dirp->filepos = pos;
+ __libc_lock_unlock (dirp->lock);
+}
diff --git a/libc/sysdeps/unix/setxid.h b/libc/sysdeps/unix/setxid.h
new file mode 100644
index 000000000..c18e2d4a6
--- /dev/null
+++ b/libc/sysdeps/unix/setxid.h
@@ -0,0 +1,4 @@
+#include <sysdep.h>
+
+#define INLINE_SETXID_SYSCALL(name, nr, args...) \
+ INLINE_SYSCALL (name, nr, args)
diff --git a/libc/sysdeps/unix/sh/sysdep.S b/libc/sysdeps/unix/sh/sysdep.S
new file mode 100644
index 000000000..802d51f3b
--- /dev/null
+++ b/libc/sysdeps/unix/sh/sysdep.S
@@ -0,0 +1,110 @@
+/* Copyright (C) 1999, 2000, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H
+#include <bits/errno.h>
+
+ENTRY(__syscall_error)
+#if defined (EWOULDBLOCK_sys) && EWOULDBLOCK_sys != EAGAIN
+ /* We translate the system's EWOULDBLOCK error into EAGAIN.
+ The GNU C library always defines EWOULDBLOCK==EAGAIN.
+ EWOULDBLOCK_sys is the original number. */
+ mov.l .L1, r1
+ cmp/eq r1, r0
+ bf skip
+ nop
+ mov.l .L2, r0
+skip:
+#endif
+ /* Store it in errno... */
+#ifndef SHARED
+#ifndef _LIBC_REENTRANT
+ mov.l .L3, r1
+ mov.l r0, @r1
+#else
+ mov.l .L3, r1
+ sts.l pr, @-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (pr, 0)
+ jsr @r1
+ mov.l r0, @-r15
+ cfi_adjust_cfa_offset (4)
+ mov.l @r15+, r1
+ cfi_adjust_cfa_offset (-4)
+ lds.l @r15+, pr
+ cfi_adjust_cfa_offset (-4)
+ mov.l r1, @r0
+#endif
+#else
+ mov.l r12, @-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (r12, 0)
+#ifndef _LIBC_REENTRANT
+ mov r0, r2
+ mov.l 0f, r12
+ mova 0f, r0
+ add r0, r12
+ mov.l .L3, r0
+ mov.l @(r0,r12), r1
+ mov.l r2, @r1
+#else
+ mov.l r0, @-r15
+ cfi_adjust_cfa_offset (4)
+ sts.l pr, @-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (pr, 0)
+ mov.l 0f, r12
+ mova 0f, r0
+ add r0, r12
+ mov.l .L3, r1
+ mova .L3, r0
+ add r0, r1
+ jsr @r1
+ nop
+ lds.l @r15+, pr
+ mov.l @r15+, r1
+ mov.l r1, @r0
+#endif
+ mov.l @r15+, r12
+#endif
+ /* And just kick back a -1. */
+ rts
+ mov #-1, r0
+
+ .align 2
+#if defined (EWOULDBLOCK_sys) && EWOULDBLOCK_sys != EAGAIN
+.L1: .long EWOULDBLOCK_sys
+.L2: .long EAGAIN
+#endif
+#ifndef SHARED
+#ifndef _LIBC_REENTRANT
+.L3: .long C_SYMBOL_NAME(errno)
+#else
+.L3: .long C_SYMBOL_NAME(__errno_location)
+#endif
+#else
+0:
+ .long _GLOBAL_OFFSET_TABLE_
+#ifndef _LIBC_REENTRANT
+.L3: .long C_SYMBOL_NAME(errno@GOT)
+#else
+.L3: .long C_SYMBOL_NAME(__errno_location@PLT)
+#endif
+#endif
+END(__syscall_error)
diff --git a/libc/sysdeps/unix/sh/sysdep.h b/libc/sysdeps/unix/sh/sysdep.h
new file mode 100644
index 000000000..bf1ac0fd4
--- /dev/null
+++ b/libc/sysdeps/unix/sh/sysdep.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/unix/sysdep.h>
+#include <sysdeps/sh/sysdep.h>
+
+#ifdef __ASSEMBLER__
+
+#define ret rts ; nop
+
+/* The sh move insn is s, d. */
+#define MOVE(x,y) mov x , y
+
+#endif
diff --git a/libc/sysdeps/unix/siglist.c b/libc/sysdeps/unix/siglist.c
new file mode 100644
index 000000000..821a2b048
--- /dev/null
+++ b/libc/sysdeps/unix/siglist.c
@@ -0,0 +1,62 @@
+/* Copyright (C) 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <libintl.h>
+
+/* This is a list of all known signal numbers. */
+
+const char *const _sys_siglist[] =
+ {
+ N_("Signal 0"),
+ N_("Hangup"),
+ N_("Interrupt"),
+ N_("Quit"),
+ N_("Illegal instruction"),
+ N_("Trace/breakpoint trap"),
+ N_("IOT trap"),
+ N_("EMT trap"),
+ N_("Floating point exception"),
+ N_("Killed"),
+ N_("Bus error"),
+ N_("Segmentation fault"),
+ N_("Bad system call"),
+ N_("Broken pipe"),
+ N_("Alarm clock"),
+ N_("Terminated"),
+ N_("Urgent I/O condition"),
+ N_("Stopped (signal)"),
+ N_("Stopped"),
+ N_("Continued"),
+ N_("Child exited"),
+ N_("Stopped (tty input)"),
+ N_("Stopped (tty output)"),
+ N_("I/O possible"),
+ N_("CPU time limit exceeded"),
+ N_("File size limit exceeded"),
+ N_("Virtual timer expired"),
+ N_("Profiling timer expired"),
+ N_("Window changed"),
+ N_("Resource lost"),
+ N_("User defined signal 1"),
+ N_("User defined signal 2"),
+ NULL
+ };
+strong_alias (_sys_siglist, _sys_siglist_internal)
+
+weak_alias (_sys_siglist, sys_siglist)
diff --git a/libc/sysdeps/unix/snarf-ioctls b/libc/sysdeps/unix/snarf-ioctls
new file mode 100755
index 000000000..e6352bea7
--- /dev/null
+++ b/libc/sysdeps/unix/snarf-ioctls
@@ -0,0 +1,49 @@
+#!/bin/sh
+# Copyright (C) 1991, 1992, 1995, 1997 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, write to the Free
+# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307 USA.
+
+sysincludedir=${sysincludedir-/usr/include}
+
+if [ ! "$snarfexclude" ]; then
+ # Filter out some headers which cause trouble.
+ # Reportedly a bug in sunos4.1.2's sed makes this lose if
+ # the two cmds are in a single sed invocation.
+ snarfexclude="`echo !${sysincludedir}/sys/param.h! \
+ !${sysincludedir}/sys/time.h! \
+ !${sysincludedir}/sys/types.h! \
+ | sed 's,/,\\\\/,g' \
+ | sed 's,!\\([^!]*\\)!,-e /\\1/d,g'`"
+fi
+
+for file in $*; do
+ sed -n 's/^#define[ ]*\([A-Z][A-Z0-9_]*\)[ ][ ]*[^ ].*$/\1/p' \
+ < $file
+
+ snarfexclude="$snarfexclude \
+ `echo $file | sed -e 's,/,\\\\/,g' -e 's,^.*$,-e /&/d,'`"
+ export snarfexclude
+
+ included="`sed -n < $file \
+ -e 's,^#include[ ]*<\(.*\)>.*$,'${sysincludedir}'/\1,p'\
+ | sed $snarfexclude`"
+ if [ "$included" ]; then
+ $0 $included
+ fi
+done
+
+exit 0
diff --git a/libc/sysdeps/unix/sockatmark.c b/libc/sysdeps/unix/sockatmark.c
new file mode 100644
index 000000000..a2476415a
--- /dev/null
+++ b/libc/sysdeps/unix/sockatmark.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2001, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+/* Determine wheter socket is at a out-of-band mark. */
+int
+sockatmark (fd)
+ int fd;
+{
+ int answ;
+
+ return __ioctl (fd, SIOCATMARK, &answ) == -1 ? -1 : answ;
+}
diff --git a/libc/sysdeps/unix/sparc/brk.S b/libc/sysdeps/unix/sparc/brk.S
new file mode 100644
index 000000000..29255fc68
--- /dev/null
+++ b/libc/sysdeps/unix/sparc/brk.S
@@ -0,0 +1,51 @@
+/* Copyright (C) 1993, 1995, 1997, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#ifndef SYS_brk
+#define SYS_brk 17
+#endif
+
+#ifndef C_SYMBOL_NAME
+#define C_SYMBOL_NAME(name) _##name
+#endif
+
+.data
+.global C_SYMBOL_NAME(__curbrk)
+C_LABEL(__curbrk)
+ .long C_SYMBOL_NAME(_end)
+
+.text
+ENTRY (__brk)
+ add %o0, 7, %o0
+ andn %o0, 7, %o0
+ mov SYS_brk, %g1
+ mov %o0, %o1 /* Save rounded value. */
+ ta %g0
+ bcs error
+ sethi %hi(C_SYMBOL_NAME(__curbrk)), %g1
+ st %o1, [%g1 + %lo(C_SYMBOL_NAME(__curbrk))]
+ ret
+error: sethi %hi(C_SYMBOL_NAME(errno)), %g1
+ st %o0, [%g1 + %lo(C_SYMBOL_NAME(errno))]
+ sub %g0, 1, %o0
+ retl
+ nop /* Fill the delay slot. */
+
+weak_alias (__brk, brk)
diff --git a/libc/sysdeps/unix/sparc/dl-brk.S b/libc/sysdeps/unix/sparc/dl-brk.S
new file mode 100644
index 000000000..eeb96544e
--- /dev/null
+++ b/libc/sysdeps/unix/sparc/dl-brk.S
@@ -0,0 +1 @@
+#include <brk.S>
diff --git a/libc/sysdeps/unix/sparc/fork.S b/libc/sysdeps/unix/sparc/fork.S
new file mode 100644
index 000000000..ae594ec8e
--- /dev/null
+++ b/libc/sysdeps/unix/sparc/fork.S
@@ -0,0 +1,31 @@
+/* Copyright (C) 1991, 92, 94, 95, 97, 99, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+SYSCALL__ (fork, 0)
+ /* %o1 is now 0 for the parent and 1 for the child. Decrement it to
+ make it -1 (all bits set) for the parent, and 0 (no bits set)
+ for the child. Then AND it with %o0, so the parent gets
+ %o0&-1==pid, and the child gets %o0&0==0. */
+ sub %o1, 1, %o1
+ retl
+ and %o0, %o1, %o0
+libc_hidden_def (__fork)
+
+weak_alias (__fork, fork)
diff --git a/libc/sysdeps/unix/sparc/pipe.S b/libc/sysdeps/unix/sparc/pipe.S
new file mode 100644
index 000000000..43981c895
--- /dev/null
+++ b/libc/sysdeps/unix/sparc/pipe.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991, 1992, 1995, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+ENTRY (__pipe)
+ mov %o0, %o2 /* Save PIPEDES. */
+PSEUDO (__Spipe, pipe, 1)
+ st %o0, [%o2] /* PIPEDES[0] = %o0; */
+ st %o1, [%o2 + 4] /* PIPEDES[1] = %o1; */
+ retl /* return 0; */
+ clr %o0
+
+libc_hidden_def (__pipe)
+weak_alias (__pipe, pipe)
diff --git a/libc/sysdeps/unix/sparc/start.c b/libc/sysdeps/unix/sparc/start.c
new file mode 100644
index 000000000..a664189bb
--- /dev/null
+++ b/libc/sysdeps/unix/sparc/start.c
@@ -0,0 +1,189 @@
+/* Copyright (C) 1991,92,93,94,95,96,97,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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.
+
+ In addition to the permissions in the GNU Lesser General Public
+ License, the Free Software Foundation gives you unlimited
+ permission to link the compiled version of this file with other
+ programs, and to distribute those programs without any restriction
+ coming from the use of this file. (The GNU Lesser General Public
+ License restrictions do apply in other respects; for example, they
+ cover modification of the file, and distribution when not linked
+ into another program.)
+
+ Note that people who make modified versions of this file are not
+ obligated to grant this special exception for their modified
+ versions; it is their choice whether to do so. The GNU Lesser
+ General Public License gives permission to release a modified
+ version without this exception; this exception also makes it
+ possible to release a modified version which carries forward this
+ exception.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#ifndef NO_SHLIB
+#include <sys/exec.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <link.h>
+#include <syscall.h>
+#endif
+
+#if !defined (__GNUC__) || __GNUC__ < 2
+ #error This file uses GNU C extensions; you must compile with GCC version 2.
+#endif
+
+/* The first piece of initialized data. */
+int __data_start = 0;
+#ifdef HAVE_WEAK_SYMBOLS
+weak_alias (__data_start, data_start)
+#endif
+
+extern void __libc_init (int argc, char **argv, char **envp) __THROW;
+extern int main (int argc, char **argv, char **envp) __THROW;
+
+register long int sp asm("%sp"), fp asm("%fp");
+
+#ifndef NO_SHLIB
+static void init_shlib (void) __THROW;
+#endif
+
+#ifndef NO_EXPLICIT_START
+/* Declare _start with an explicit assembly symbol name of `start'
+ (note no leading underscore). This is the name Sun's crt0.o uses,
+ and programs are often linked with `ld -e start'. */
+void _start (void) asm ("start");
+#endif
+
+void
+_start (void)
+{
+ /* It is important that these be declared `register'.
+ Otherwise, when compiled without optimization, they are put on the
+ stack, which loses completely after we zero the FP. */
+ register int argc;
+ register char **argv, **envp;
+
+ /* Unwind the frame built when we entered the function. */
+ asm("restore");
+
+ /* And clear the frame pointer. */
+ fp = 0;
+
+ /* The argument info starts after one register
+ window (64 bytes) past the SP. */
+ argc = ((int *) sp)[16];
+ argv = (char **) &((int *) sp)[17];
+ envp = &argv[argc + 1];
+ __environ = envp;
+
+#ifndef NO_SHLIB
+ init_shlib ();
+#endif
+
+ /* Allocate 24 bytes of stack space for the register save area. */
+ sp -= 24;
+ __libc_init (argc, argv, envp);
+
+ exit (main (argc, argv, envp));
+}
+
+#ifndef NO_SHLIB
+
+/* System calls for use by the bootstrap routine.
+ These are defined here since the usual calls may be dynamically linked. */
+
+int syscall (int sysno, ...) asm ("init_syscall");
+asm ("init_syscall:\n"
+ " clr %g1\n"
+ " ta 0\n"
+ " bcc 1f\n"
+ " sethi %hi(_errno), %g1\n"
+ " st %o0, [%g1 + %lo(_errno)]\n"
+ " sub %g0, 1, %o0\n"
+ "1:retl\n"
+ " nop");
+
+static void
+init_shlib ()
+{
+ extern struct link_dynamic _DYNAMIC;
+ int so, zf;
+ caddr_t somap;
+ caddr_t sodmap;
+ caddr_t sobssmap;
+ void (*ldstart) (int, int);
+ struct exec soexec;
+ struct
+ {
+ caddr_t crt_ba;
+ int crt_dzfd;
+ int crt_ldfd;
+ struct link_dynamic *crt_dp;
+ char **crt_ep;
+ caddr_t crt_bp;
+ } soarg;
+
+ /* If not dynamically linked, do nothing. */
+ if (&_DYNAMIC == 0)
+ return;
+
+ /* Map in the dynamic linker. */
+ so = syscall (SYS_open, "/usr/lib/ld.so", O_RDONLY);
+ if (syscall (SYS_read, so, &soexec, sizeof (soexec)) != sizeof (soexec)
+ || soexec.a_magic != ZMAGIC)
+ {
+ static const char emsg[] = "crt0: no /usr/lib/ld.so\n";
+
+ syscall (SYS_write, 2, emsg, sizeof (emsg) - 1);
+ syscall (SYS_exit, 127);
+ }
+ somap = (caddr_t) syscall (SYS_mmap, 0,
+ soexec.a_text + soexec.a_data + soexec.a_bss,
+ PROT_READ | PROT_EXEC, _MAP_NEW | MAP_PRIVATE,
+ so, 0);
+ sodmap = (caddr_t) syscall (SYS_mmap, somap + soexec.a_text, soexec.a_data,
+ PROT_READ | PROT_WRITE | PROT_EXEC,
+ _MAP_NEW | MAP_FIXED | MAP_PRIVATE,
+ so, soexec.a_text);
+ zf = syscall (SYS_open, "/dev/zero", O_RDONLY);
+ if (soexec.a_bss != 0)
+ sobssmap = (caddr_t) syscall (SYS_mmap,
+ somap + soexec.a_text + soexec.a_data,
+ soexec.a_bss,
+ PROT_READ | PROT_WRITE | PROT_EXEC,
+ _MAP_NEW | MAP_FIXED | MAP_PRIVATE,
+ zf, 0);
+
+ /* Call the entry point of the dynamic linker. */
+ soarg.crt_ba = somap;
+ soarg.crt_dzfd = zf;
+ soarg.crt_ldfd = so;
+ soarg.crt_dp = &_DYNAMIC;
+ soarg.crt_ep = __environ;
+ soarg.crt_bp = (caddr_t) &&retaddr;
+
+ ldstart = (__typeof (ldstart)) (somap + soexec.a_entry);
+ (*ldstart) (1, (char *) &soarg - (char *) sp);
+
+ retaddr:
+}
+
+#endif
diff --git a/libc/sysdeps/unix/sparc/sysdep.S b/libc/sysdeps/unix/sparc/sysdep.S
new file mode 100644
index 000000000..7e2e4d4e8
--- /dev/null
+++ b/libc/sysdeps/unix/sparc/sysdep.S
@@ -0,0 +1,47 @@
+/* Copyright (C) 1994, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H
+#include <bits/errno.h>
+
+.global C_SYMBOL_NAME(errno)
+.global syscall_error
+
+.text
+.align 2
+#undef syscall_error
+#ifdef NO_UNDERSCORES
+__syscall_error:
+#else
+syscall_error:
+#endif
+#if defined (EWOULDBLOCK_sys) && EWOULDBLOCK_sys != EAGAIN
+ /* We translate the system's EWOULDBLOCK error into EAGAIN.
+ The GNU C library always defines EWOULDBLOCK==EAGAIN.
+ EWOULDBLOCK_sys is the original number. */
+ cmp %o0, EWOULDBLOCK_sys
+ be,a notblock
+ mov EAGAIN, %o0
+#endif
+notblock: /* Store the error code in `errno'. */
+ sethi %hi(C_SYMBOL_NAME(errno)), %g1
+ st %o0, [%g1 + %lo(C_SYMBOL_NAME(errno))]
+ /* And return -1. */
+ retl
+ mov -1, %o0
diff --git a/libc/sysdeps/unix/sparc/sysdep.h b/libc/sysdeps/unix/sparc/sysdep.h
new file mode 100644
index 000000000..24225d962
--- /dev/null
+++ b/libc/sysdeps/unix/sparc/sysdep.h
@@ -0,0 +1,74 @@
+/* Copyright (C) 1993, 1994, 1995, 1997, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/unix/sysdep.h>
+
+#ifdef __ASSEMBLER__
+
+#ifdef NO_UNDERSCORES
+/* Since C identifiers are not normally prefixed with an underscore
+ on this system, the asm identifier `syscall_error' intrudes on the
+ C name space. Make sure we use an innocuous name. */
+#define syscall_error C_SYMBOL_NAME(__syscall_error)
+#endif
+
+#ifdef HAVE_ELF
+#define ENTRY(name) \
+ .global C_SYMBOL_NAME(name); \
+ .type name,@function; \
+ .align 4; \
+ C_LABEL(name)
+
+#else
+#define ENTRY(name) \
+ .global C_SYMBOL_NAME(name); \
+ .align 4; \
+ C_LABEL(name)
+
+#endif /* HAVE_ELF */
+
+#define PSEUDO(name, syscall_name, args) \
+ .global syscall_error; \
+ ENTRY (name) \
+ mov SYS_ify(syscall_name), %g1; \
+ ta 0; \
+ bcc 1f; \
+ sethi %hi(syscall_error), %g1; \
+ jmp %g1 + %lo(syscall_error); nop; \
+1:
+
+#define PSEUDO_NOERRNO(name, syscall_name, args) \
+ .global syscall_error; \
+ ENTRY (name) \
+ mov SYS_ify(syscall_name), %g1; \
+ ta 0
+
+#define PSEUDO_ERRVAL(name, syscall_name, args) \
+ .global syscall_error; \
+ ENTRY (name) \
+ mov SYS_ify(syscall_name), %g1; \
+ ta 0
+
+#define ret retl; nop
+#define ret_NOERRNO retl; nop
+#define ret_ERRVAL retl; nop
+#define r0 %o0
+#define r1 %o1
+#define MOVE(x,y) mov x, y
+
+#endif /* __ASSEMBLER__ */
diff --git a/libc/sysdeps/unix/sparc/vfork.S b/libc/sysdeps/unix/sparc/vfork.S
new file mode 100644
index 000000000..5d48b090d
--- /dev/null
+++ b/libc/sysdeps/unix/sparc/vfork.S
@@ -0,0 +1,35 @@
+/* Copyright (C) 1991, 92, 94, 95, 97, 99, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#ifndef SYS_vfork
+#define SYS_vfork 66
+#endif
+
+SYSCALL__ (vfork, 0)
+ /* %o1 is now 0 for the parent and 1 for the child. Decrement it to
+ make it -1 (all bits set) for the parent, and 0 (no bits set)
+ for the child. Then AND it with %o0, so the parent gets
+ %o0&-1==pid, and the child gets %o0&0==0. */
+ sub %o1, 1, %o1
+ retl
+ and %o0, %o1, %o0
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/sysdeps/unix/start.c b/libc/sysdeps/unix/start.c
new file mode 100644
index 000000000..2474fc2e7
--- /dev/null
+++ b/libc/sysdeps/unix/start.c
@@ -0,0 +1,105 @@
+/* Copyright (C) 1991, 93, 1995-1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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.
+
+ In addition to the permissions in the GNU Lesser General Public
+ License, the Free Software Foundation gives you unlimited
+ permission to link the compiled version of this file with other
+ programs, and to distribute those programs without any restriction
+ coming from the use of this file. (The GNU Lesser General Public
+ License restrictions do apply in other respects; for example, they
+ cover modification of the file, and distribution when not linked
+ into another program.)
+
+ Note that people who make modified versions of this file are not
+ obligated to grant this special exception for their modified
+ versions; it is their choice whether to do so. The GNU Lesser
+ General Public License gives permission to release a modified
+ version without this exception; this exception also makes it
+ possible to release a modified version which carries forward this
+ exception.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sysdep.h> /* In case it wants to define anything. */
+
+/* The first piece of initialized data. */
+int __data_start = 0;
+#ifdef HAVE_WEAK_SYMBOLS
+weak_alias (__data_start, data_start)
+#endif
+
+#ifdef DUMMIES
+#define ARG_DUMMIES DUMMIES,
+#define DECL_DUMMIES int DUMMIES;
+#else
+#define ARG_DUMMIES
+#define DECL_DUMMIES
+#endif
+
+extern void __libc_init (int argc, char **argv, char **envp);
+extern int main (int argc, char **argv, char **envp);
+
+
+/* Not a prototype because it gets called strangely. */
+static void start1();
+
+#ifndef HAVE__start
+
+/* N.B.: It is important that this be the first function.
+ This file is the first thing in the text section. */
+void
+_start ()
+{
+ start1 ();
+}
+
+#ifndef NO_UNDERSCORES
+/* Make an alias called `start' (no leading underscore, so it can't
+ conflict with C symbols) for `_start'. This is the name vendor crt0.o's
+ tend to use, and thus the name most linkers expect. */
+asm (".set start, __start");
+#endif
+
+#endif
+
+/* ARGSUSED */
+static void
+start1 (ARG_DUMMIES argc, argp)
+ DECL_DUMMIES
+ int argc;
+ char *argp;
+{
+ char **argv = &argp;
+
+ /* The environment starts just after ARGV. */
+ __environ = &argv[argc + 1];
+
+ /* If the first thing after ARGV is the arguments
+ themselves, there is no environment. */
+ if ((char *) __environ == *argv)
+ /* The environment is empty. Make __environ
+ point at ARGV[ARGC], which is NULL. */
+ --__environ;
+
+ /* Do C library initializations. */
+ __libc_init (argc, argv, __environ);
+
+ /* Call the user program. */
+ exit (main (argc, argv, __environ));
+}
diff --git a/libc/sysdeps/unix/stime.c b/libc/sysdeps/unix/stime.c
new file mode 100644
index 000000000..c4dfdcf93
--- /dev/null
+++ b/libc/sysdeps/unix/stime.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 1992, 1996, 1997, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h> /* For NULL. */
+#include <sys/time.h>
+#include <time.h>
+
+/* Set the system clock to *WHEN. */
+
+int
+stime (when)
+ const time_t *when;
+{
+ struct timeval tv;
+
+ if (when == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ tv.tv_sec = *when;
+ tv.tv_usec = 0;
+ return __settimeofday (&tv, (struct timezone *) 0);
+}
diff --git a/libc/sysdeps/unix/syscall.S b/libc/sysdeps/unix/syscall.S
new file mode 100644
index 000000000..8b685cf30
--- /dev/null
+++ b/libc/sysdeps/unix/syscall.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#ifndef SYS_syscall
+#define SYS_syscall 0
+#endif
+
+/* This works if the kernel does an "indirect system call" for system call 0,
+ taking the first argument word off the stack as the system call number. */
+
+SYSCALL (syscall, 1)
+ ret
+PSEUDO_END(syscall)
diff --git a/libc/sysdeps/unix/syscalls.list b/libc/sysdeps/unix/syscalls.list
new file mode 100644
index 000000000..4c963abe5
--- /dev/null
+++ b/libc/sysdeps/unix/syscalls.list
@@ -0,0 +1,65 @@
+# File name Caller Syscall name Args Strong name Weak names
+
+access - access i:si __access access
+acct - acct i:S acct
+chdir - chdir i:s __chdir chdir
+chmod - chmod i:si __chmod chmod
+chown - chown i:sii __chown __chown_internal chown
+chroot - chroot i:s chroot
+close - close Ci:i __libc_close __close close
+dup - dup i:i __dup dup
+dup2 - dup2 i:ii __dup2 dup2
+fchdir - fchdir i:i __fchdir fchdir
+fcntl - fcntl Ci:iiF __libc_fcntl __fcntl __fcntl_internal fcntl
+fstatfs - fstatfs i:ip __fstatfs fstatfs
+fsync - fsync Ci:i __libc_fsync fsync
+getdomain - getdomainname i:si getdomainname
+getgid - getgid Ei: __getgid getgid
+getgroups - getgroups i:ip __getgroups getgroups
+getitimer - getitimer i:ip __getitimer getitimer
+getpid - getpid Ei: __getpid getpid
+getpriority - getpriority i:ii getpriority
+getrlimit - getrlimit i:ip __getrlimit getrlimit
+getuid - getuid Ei: __getuid getuid
+ioctl - ioctl i:iiI __ioctl ioctl
+kill - kill i:ii __kill kill
+link - link i:ss __link link
+lseek - lseek i:iii __libc_lseek __lseek lseek
+mkdir - mkdir i:si __mkdir mkdir
+open - open Ci:siv __libc_open __open open
+profil - profil i:piii __profil profil
+ptrace - ptrace i:iiii ptrace
+read - read Ci:ibn __libc_read __read read
+readlink - readlink i:spi __readlink readlink
+readv - readv Ci:ipi __readv readv
+reboot - reboot i:i reboot
+rename - rename i:ss rename
+rmdir - rmdir i:s __rmdir rmdir
+select - select Ci:iPPPP __select __libc_select select
+setdomain - setdomainname i:si setdomainname
+setegid - setegid i:i __setegid setegid
+seteuid - seteuid i:i __seteuid seteuid
+setgid - setgid i:i __setgid setgid
+setgroups - setgroups i:ip setgroups
+setitimer - setitimer i:ipp __setitimer setitimer
+setpriority - setpriority i:iii setpriority
+setrlimit - setrlimit i:ip __setrlimit setrlimit
+setsid - setsid i: __setsid setsid
+settimeofday - settimeofday i:PP __settimeofday settimeofday
+setuid - setuid i:i __setuid setuid
+sigsuspend - sigsuspend Ci:p sigsuspend
+sstk - sstk b:i sstk
+statfs - statfs i:sp __statfs statfs
+swapoff - swapoff i:s swapoff
+swapon - swapon i:s swapon
+symlink - symlink i:ss __symlink symlink
+sync - sync i: sync
+sys_fstat fxstat fstat i:ip __syscall_fstat
+sys_mknod xmknod mknod i:sii __syscall_mknod
+sys_stat xstat stat i:sp __syscall_stat
+umask - umask Ei:i __umask umask
+uname - uname i:p __uname uname
+unlink - unlink i:s __unlink unlink
+utimes - utimes i:sp __utimes utimes
+write - write Ci:ibn __libc_write __write write
+writev - writev Ci:ipi __writev writev
diff --git a/libc/sysdeps/unix/sysdep.h b/libc/sysdeps/unix/sysdep.h
new file mode 100644
index 000000000..11e5317df
--- /dev/null
+++ b/libc/sysdeps/unix/sysdep.h
@@ -0,0 +1,59 @@
+/* Copyright (C) 1991, 92, 93, 96, 98, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/generic/sysdep.h>
+
+#include <sys/syscall.h>
+#define HAVE_SYSCALLS
+
+/* Note that using a `PASTE' macro loses. */
+#ifdef __STDC__
+#define SYSCALL__(name, args) PSEUDO (__##name, name, args)
+#else
+#define SYSCALL__(name, args) PSEUDO (__/**/name, name, args)
+#endif
+#define SYSCALL(name, args) PSEUDO (name, name, args)
+
+/* Machine-dependent sysdep.h files are expected to define the macro
+ PSEUDO (function_name, syscall_name) to emit assembly code to define the
+ C-callable function FUNCTION_NAME to do system call SYSCALL_NAME.
+ r0 and r1 are the system call outputs. MOVE(x, y) should be defined as
+ an instruction such that "MOVE(r1, r0)" works. ret should be defined
+ as the return instruction. */
+
+#ifdef __STDC__
+#define SYS_ify(syscall_name) SYS_##syscall_name
+#else
+#define SYS_ify(syscall_name) SYS_/**/syscall_name
+#endif
+
+/* Terminate a system call named SYM. This is used on some platforms
+ to generate correct debugging information. */
+#ifndef PSEUDO_END
+#define PSEUDO_END(sym)
+#endif
+#ifndef PSEUDO_END_NOERRNO
+#define PSEUDO_END_NOERRNO(sym) PSEUDO_END(sym)
+#endif
+#ifndef PSEUDO_END_ERRVAL
+#define PSEUDO_END_ERRVAL(sym) PSEUDO_END(sym)
+#endif
+
+/* Wrappers around system calls should normally inline the system call code.
+ But sometimes it is not possible or implemented and we use this code. */
+#define INLINE_SYSCALL(name, nr, args...) __syscall_##name (args)
diff --git a/libc/sysdeps/unix/system.c b/libc/sysdeps/unix/system.c
new file mode 100644
index 000000000..2c52ec81d
--- /dev/null
+++ b/libc/sysdeps/unix/system.c
@@ -0,0 +1,2 @@
+#define NO_WAITPID
+#include <sysdeps/posix/system.c>
diff --git a/libc/sysdeps/unix/sysv/Makefile b/libc/sysdeps/unix/sysv/Makefile
new file mode 100644
index 000000000..10f3e792f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/Makefile
@@ -0,0 +1,42 @@
+# Copyright (C) 1992, 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, write to the Free
+# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307 USA.
+
+ifeq ($(subdir),termios)
+
+ifeq (,$(filter termio.h,$(sysdep_headers)))
+
+sysdep_headers := $(sysdep_headers) termio.h
+generated := $(generated) termio.h
+
+# termio.h is just like sysv_termio.h except it uses the same names for
+# everything that System V termio does. sysv_termio.h is necessary to
+# include in __tcgetatr.c et al, because some of the names in termio.h
+# conflict with termios.h. The C library doesn't actually use termio.h,
+# but we generate it for those application programs which use it.
+$(objpfx)termio.h: $(..)sysdeps/unix/sysv/sysv_termio.h
+ sed < $< > $@-tmp \
+ -e 's/_SYSV_//' \
+ -e 's/^#define[ ]*_T/#define T/'\
+ -e 's/__sysv_termio/termio/'
+ mv $@-tmp $@
+
+endif
+endif
+
+# In SYSV style archives the symbol table member has an empty name.
+ar-symtab-name =
diff --git a/libc/sysdeps/unix/sysv/Versions b/libc/sysdeps/unix/sysv/Versions
new file mode 100644
index 000000000..bdb8ba836
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/Versions
@@ -0,0 +1,5 @@
+libc {
+ GLIBC_2.0 {
+ sysinfo;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/bits/dirent.h b/libc/sysdeps/unix/sysv/bits/dirent.h
new file mode 100644
index 000000000..3a5246a78
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/bits/dirent.h
@@ -0,0 +1,28 @@
+/* Directory entry structure `struct dirent'. Old System V version.
+ Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _DIRENT_H
+# error "Never use <bits/dirent.h> directly; include <dirent.h> instead."
+#endif
+
+struct dirent
+ {
+ unsigned short int d_fileno;
+ char d_name[14];
+ };
diff --git a/libc/sysdeps/unix/sysv/bits/fcntl.h b/libc/sysdeps/unix/sysv/bits/fcntl.h
new file mode 100644
index 000000000..0eb81aa6e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/bits/fcntl.h
@@ -0,0 +1,94 @@
+/* O_*, F_*, FD_* bit values for System V.
+ Copyright (C) 1991, 1992, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+#error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+
+/* File access modes for `open' and `fcntl'. */
+#define O_RDONLY 0 /* Open read-only. */
+#define O_WRONLY 1 /* Open write-only. */
+#define O_RDWR 2 /* Open read/write. */
+
+
+/* Bits OR'd into the second argument to open. */
+#define O_CREAT 00400 /* Create file if it doesn't exist. */
+#define O_EXCL 02000 /* Fail if file already exists. */
+#define O_TRUNC 01000 /* Truncate file to zero length. */
+#if defined __USE_BSD || defined __USE_SVID
+#define O_SYNC 00020 /* Synchronous writes. */
+#define O_FSYNC O_SYNC
+#endif
+
+/* File status flags for `open' and `fcntl'. */
+#define O_APPEND 000010 /* Writes append to the file. */
+#define O_NONBLOCK 000004 /* Non-blocking I/O. */
+
+#ifdef __USE_BSD
+/* System V doesn't support POSIX.1 O_NONBLOCK, but O_NDELAY is close. */
+#define O_NDELAY O_NONBLOCK
+#endif
+
+/* Mask for file access modes. This is system-dependent in case
+ some system ever wants to define some other flavor of access. */
+#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#define F_GETLK 5 /* Get record locking info. */
+#define F_SETLK 6 /* Set record locking info. */
+#define F_SETLKW 7 /* Set record locking info, wait. */
+
+/* File descriptor flags used with F_GETFD and F_SETFD. */
+#define FD_CLOEXEC 1 /* Close on exec. */
+
+
+#include <bits/types.h>
+
+/* The structure describing an advisory lock. This is the type of the third
+ argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests. */
+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'). */
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+ short int l_sysid; /* System ID where locking process resides. */
+ short int l_pid; /* Process holding the lock. */
+ };
+
+/* Values for the `l_type' field of a `struct flock'. */
+#define F_RDLCK 1 /* Read lock. */
+#define F_WRLCK 2 /* Write lock. */
+#define F_UNLCK 3 /* Remove lock. */
+
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+#define FAPPEND O_APPEND
+#define FFSYNC O_FSYNC
+#define FNONBLOCK O_NONBLOCK
+#define FNDELAY O_NDELAY
+#endif /* Use BSD. */
diff --git a/libc/sysdeps/unix/sysv/bits/local_lim.h b/libc/sysdeps/unix/sysv/bits/local_lim.h
new file mode 100644
index 000000000..d9fa98809
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/bits/local_lim.h
@@ -0,0 +1,32 @@
+/* Copyright (C) 1992, 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define NGROUPS_MAX 0 /* No supplementary groups. */
+#define ARG_MAX 5120
+#define CHILD_MAX 25
+#define OPEN_MAX 60
+#define LINK_MAX 1000
+#define MAX_CANON 256
+
+/* For SVR3, this is 14. For SVR4, it is 255, at least on ufs
+ file systems, even though the System V limits.h incorrectly
+ defines it as 14. Giving it a value which is too large
+ is harmless (it is a maximum). */
+#define NAME_MAX 255
+
+#define PATH_MAX 1024
diff --git a/libc/sysdeps/unix/sysv/bits/signum.h b/libc/sysdeps/unix/sysv/bits/signum.h
new file mode 100644
index 000000000..d0fc7f469
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/bits/signum.h
@@ -0,0 +1,56 @@
+/* Signal number definitions. System V version.
+ Copyright (C) 1991, 1992, 1993, 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifdef _SIGNAL_H
+
+/* This file defines the fake signal functions and signal
+ number constants for System V release 3. */
+
+/* Fake signal functions. */
+#define SIG_ERR ((__sighandler_t) -1) /* Error return. */
+#define SIG_DFL ((__sighandler_t) 0) /* Default action. */
+#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */
+
+
+/* Signals. */
+#define SIGHUP 1 /* Hangup (POSIX). */
+#define SIGINT 2 /* Interrupt (ANSI). */
+#define SIGQUIT 3 /* Quit (POSIX). */
+#define SIGILL 4 /* Illegal instruction (ANSI). */
+#define SIGABRT SIGIOT /* Abort (ANSI). */
+#define SIGTRAP 5 /* Trace trap (POSIX). */
+#define SIGIOT 6 /* IOT trap (4.2 BSD). */
+#define SIGEMT 7 /* EMT trap (4.2 BSD). */
+#define SIGFPE 8 /* Floating-point exception (ANSI). */
+#define SIGKILL 9 /* Kill, unblockable (POSIX). */
+#define SIGBUS 10 /* Bus error (4.2 BSD). */
+#define SIGSEGV 11 /* Segmentation violation (ANSI). */
+#define SIGSYS 12 /* Bad argument to system call (4.2 BSD)*/
+#define SIGPIPE 13 /* Broken pipe (POSIX). */
+#define SIGALRM 14 /* Alarm clock (POSIX). */
+#define SIGTERM 15 /* Termination (ANSI). */
+#define SIGUSR1 16 /* User-defined signal 1 (POSIX). */
+#define SIGUSR2 17 /* User-defined signal 2 (POSIX). */
+#define SIGCHLD 18 /* Child status has changed (POSIX). */
+#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */
+#define SIGPWR 19 /* Power failure restart (System V). */
+
+#endif /* <signal.h> included. */
+
+#define _NSIG 20 /* Biggest signal number + 1. */
diff --git a/libc/sysdeps/unix/sysv/bits/stat.h b/libc/sysdeps/unix/sysv/bits/stat.h
new file mode 100644
index 000000000..f9a9e614d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/bits/stat.h
@@ -0,0 +1,65 @@
+/* Copyright (C) 1992, 1996, 1997, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STAT_H
+# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
+#endif
+
+struct stat
+ {
+ short int st_dev;
+ unsigned short int st_ino;
+ unsigned short int st_mode;
+ short int st_nlink;
+ unsigned short int st_uid;
+ unsigned short int st_gid;
+ short int st_rdev;
+ long int st_size;
+ long int st_atime;
+ long int st_mtime;
+ long int st_ctime;
+ };
+
+/* 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. */
+
+/* These don't actually exist on System V, but having them doesn't hurt. */
+#define __S_IFLNK 0120000 /* Symbolic link. */
+#define __S_IFSOCK 0140000 /* Socket. */
+
+/* POSIX.1b objects. */
+#define __S_TYPEISMQ(buf) (0)
+#define __S_TYPEISSEM(buf) (0)
+#define __S_TYPEISSHM(buf) (0)
+
+/* 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. */
diff --git a/libc/sysdeps/unix/sysv/bits/utmp.h b/libc/sysdeps/unix/sysv/bits/utmp.h
new file mode 100644
index 000000000..b5353b662
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/bits/utmp.h
@@ -0,0 +1,54 @@
+/* The `struct utmp' type, describing entries in the utmp file. System V.
+ Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _UTMP_H
+# error "Never include <bits/utmp.h> directly; use <utmp.h> instead."
+#endif
+
+
+#include <time.h>
+
+#define _PATH_UTMP "/var/adm/utmp"
+#define _PATH_WTMP "/var/adm/wtmp"
+#define _PATH_LASTLOG "/var/adm/lastlog"
+
+
+struct utmp
+ {
+#define ut_name ut_user
+ char ut_user[8];
+ char ut_id[4];
+ char ut_line[12];
+ short int ut_pid;
+ short int ut_type;
+ struct exit_status
+ {
+ short int e_termination;
+ short int e_exit;
+ } ut_exit;
+ __time_t ut_time;
+ };
+
+
+/* Tell the user that we have a modern system with UT_HOST, UT_TYPE, UT_ID
+ and UT_TV fields. */
+#define _HAVE_UT_TYPE 1
+#define _HAVE_UT_ID 1
+#define _HAVE_UT_TV 1
+#define _HAVE_UT_HOST 1
diff --git a/libc/sysdeps/unix/sysv/bits/utsname.h b/libc/sysdeps/unix/sysv/bits/utsname.h
new file mode 100644
index 000000000..0b2949b17
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/bits/utsname.h
@@ -0,0 +1,23 @@
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_UTSNAME_H
+# error "Never include <bits/utsname.h> directly; use <sys/utsname.h> instead."
+#endif
+
+#define _UTSNAME_LENGTH 9
diff --git a/libc/sysdeps/unix/sysv/direct.h b/libc/sysdeps/unix/sysv/direct.h
new file mode 100644
index 000000000..dc1d77bee
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/direct.h
@@ -0,0 +1,10 @@
+struct direct
+ {
+ unsigned short int d_fileno;
+ char d_name[14];
+ };
+
+#define D_NAMLEN(d) \
+ ((d)->d_name[13] == '\0' ? strlen ((d)->d_name) : 14)
+
+#define D_RECLEN(d) (sizeof (*(d)))
diff --git a/libc/sysdeps/unix/sysv/getdents.c b/libc/sysdeps/unix/sysv/getdents.c
new file mode 100644
index 000000000..5f8fd8f6b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/getdents.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 1993, 1995, 1997, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+extern ssize_t __getdents (int fd, char *buf, size_t nbytes);
+
+ssize_t
+__getdirentries (fd, buf, nbytes, basep)
+ int fd;
+ char *buf;
+ size_t nbytes;
+ off_t *basep;
+{
+ if (basep)
+ *basep = __lseek (fd, (off_t) 0, SEEK_CUR);
+
+ return __getdents (fd, buf, nbytes);
+}
+
+weak_alias (__getdirentries, getdirentries)
diff --git a/libc/sysdeps/unix/sysv/gethostname.c b/libc/sysdeps/unix/sysv/gethostname.c
new file mode 100644
index 000000000..330770c8b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/gethostname.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 1992, 1995, 1997, 2000, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/utsname.h>
+
+/* Put the name of the current host in no more than LEN bytes of NAME.
+ The result is null-terminated if LEN is large enough for the full
+ name and the terminator. */
+int
+__gethostname (name, len)
+ char *name;
+ size_t len;
+{
+ struct utsname buf;
+ size_t node_len;
+
+ if (uname (&buf))
+ return -1;
+
+ node_len = strlen (buf.nodename) + 1;
+ memcpy (name, buf.nodename, len < node_len ? len : node_len);
+
+ if (node_len > len)
+ {
+ __set_errno (ENAMETOOLONG);
+ return -1;
+ }
+ return 0;
+}
+
+weak_alias (__gethostname, gethostname)
diff --git a/libc/sysdeps/unix/sysv/i386/sysdep.h b/libc/sysdeps/unix/sysv/i386/sysdep.h
new file mode 100644
index 000000000..fedd5ea82
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/i386/sysdep.h
@@ -0,0 +1,4 @@
+/* System V does not precede the asm names of C symbols with a `_'. */
+#define NO_UNDERSCORES
+
+#include <sysdeps/unix/i386/sysdep.h>
diff --git a/libc/sysdeps/unix/sysv/i386/time.S b/libc/sysdeps/unix/sysv/i386/time.S
new file mode 100644
index 000000000..83b8d1fd6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/i386/time.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991,92,96,97,2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <asm-syntax.h>
+
+PSEUDO_NOERRNO (time, time, 1)
+ movl 4(%esp), %edx /* Put passed pointer in %edx. */
+ testl %edx, %edx /* Is it non-nil? */
+ je L(null)
+ movl %eax, (%edx) /* Yes; store the time there. */
+L(null):
+ ret
+PSEUDO_END_NOERRNO (time)
+libc_hidden_def (time)
diff --git a/libc/sysdeps/unix/sysv/linux/Implies b/libc/sysdeps/unix/sysv/linux/Implies
new file mode 100644
index 000000000..4deb1c624
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/Implies
@@ -0,0 +1,14 @@
+# The gnu subdirectory exists for things common to both Linux-based and
+# Hurd-based GNU systems.
+gnu
+
+# Linux shares most of the syscalls which are also common to BSD and SVR4.
+unix/common
+
+# Linux as of version 1.3.29 has all functions of the mmap family
+# which are described in POSIX.4. Missing is only madvise() so
+# we define a stub here.
+unix/mman
+
+# Linux has network support in the kernel.
+unix/inet
diff --git a/libc/sysdeps/unix/sysv/linux/Makefile b/libc/sysdeps/unix/sysv/linux/Makefile
new file mode 100644
index 000000000..8bec6cdb8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/Makefile
@@ -0,0 +1,159 @@
+ifeq ($(subdir),csu)
+sysdep_routines += errno-loc
+endif
+
+ifeq ($(subdir),assert)
+CFLAGS-assert.c += -DFATAL_PREPARE_INCLUDE='<fatal-prepare.h>'
+CFLAGS-assert-perr.c += -DFATAL_PREPARE_INCLUDE='<fatal-prepare.h>'
+endif
+
+ifeq ($(subdir),malloc)
+CFLAGS-malloc.c += -DMORECORE_CLEARS=2
+endif
+
+ifeq ($(subdir),misc)
+sysdep_routines += sysctl clone llseek umount umount2 readahead \
+ setfsuid setfsgid makedev
+
+CFLAGS-gethostid.c = -fexceptions
+
+sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \
+ sys/klog.h sys/kdaemon.h \
+ sys/user.h sys/procfs.h sys/prctl.h \
+ sys/kd.h sys/soundcard.h sys/vt.h \
+ sys/quota.h sys/fsuid.h \
+ scsi/sg.h scsi/scsi.h scsi/scsi_ioctl.h sys/pci.h \
+ sys/ultrasound.h sys/raw.h sys/personality.h sys/epoll.h \
+ bits/a.out.h sys/inotify.h
+
+install-others += $(inst_includedir)/bits/syscall.h
+
+tests += tst-clone
+
+# Generate the list of SYS_* macros for the system calls (__NR_* macros).
+# For bi-arch platforms, the CPU/Makefile defines {32,64}bit-predefine and
+# we generate a file that uses <bits/wordsize.h>.
+$(objpfx)syscall-%.h $(objpfx)syscall-%.d: ../sysdeps/unix/sysv/linux/sys/syscall.h
+ $(make-target-directory)
+ { \
+ echo '/* Generated at libc build time from kernel syscall list. */';\
+ echo ''; \
+ echo '#ifndef _SYSCALL_H'; \
+ echo '# error "Never use <bits/syscall.h> directly; include <sys/syscall.h> instead."'; \
+ echo '#endif'; \
+ echo ''; \
+ $(CC) -E -MD -MP -MF $(@:.h=.d)-t1 -MT '$(@:.d=.h) $(@:.h=.d)' \
+ -x c $(sysincludes) $< $(addprefix -U,$(64bit-predefine)) \
+ $(addprefix -D,$(32bit-predefine)) -D_LIBC -dM | \
+ sed -n 's@^#define __NR_\([^ ]*\) .*$$@#define SYS_\1 __NR_\1@p' | \
+ LC_ALL=C sort > $(@:.d=.h).new32; \
+ $(CC) -E -MD -MP -MF $(@:.h=.d)-t2 -MT '$(@:.d=.h) $(@:.h=.d)' \
+ -x c $(sysincludes) $< $(addprefix -U,$(32bit-predefine)) \
+ $(addprefix -D,$(64bit-predefine)) -D_LIBC -dM | \
+ sed -n 's@^#define __NR_\([^ ]*\) .*$$@#define SYS_\1 __NR_\1@p' | \
+ LC_ALL=C sort > $(@:.d=.h).new64; \
+ if cmp -s $(@:.d=.h).new32 $(@:.d=.h).new64; then \
+ cat $(@:.d=.h).new32; \
+ else \
+ echo '#include <bits/wordsize.h>'; \
+ echo ''; \
+ LC_ALL=C comm -12 $(@:.d=.h).new32 $(@:.d=.h).new64; \
+ echo '#if __WORDSIZE == 64'; \
+ LC_ALL=C comm -13 $(@:.d=.h).new32 $(@:.d=.h).new64; \
+ echo '#else'; \
+ LC_ALL=C comm -23 $(@:.d=.h).new32 $(@:.d=.h).new64; \
+ echo '#endif'; \
+ fi; \
+ rm -f $(@:.d=.h).new32 $(@:.d=.h).new64; \
+ } > $(@:.d=.h).new
+ mv -f $(@:.d=.h).new $(@:.d=.h)
+ifneq (,$(objpfx))
+ sed $(sed-remove-objpfx) $(@:.h=.d)-t1 $(@:.h=.d)-t2 > $(@:.h=.d)-t3
+else
+ cat $(@:.h=.d)-t1 $(@:.h=.d)-t2 > $(@:.h=.d)-t3
+endif
+ rm -f $(@:.h=.d)-t1 $(@:.h=.d)-t2
+ mv -f $(@:.h=.d)-t3 $(@:.h=.d)
+
+$(inst_includedir)/bits/syscall.h: $(objpfx)syscall-list.h $(+force)
+ $(make-target-directory)
+ if test -r $@ && cmp -s $< $@; \
+ then echo 'bits/syscall.h unchanged'; \
+ else $(INSTALL_DATA) $< $@; fi
+
+ifndef no_deps
+# Get the generated list of dependencies (probably /usr/include/asm/unistd.h).
+-include $(objpfx)syscall-list.d
+endif
+generated += syscall-list.h syscall-list.d
+endif
+
+ifeq ($(subdir),time)
+sysdep_headers += sys/timex.h
+
+sysdep_routines += ntp_gettime
+endif
+
+ifeq ($(subdir),socket)
+sysdep_headers += net/if_ppp.h net/ppp-comp.h \
+ net/ppp_defs.h net/if_arp.h net/route.h net/ethernet.h \
+ net/if_slip.h net/if_packet.h net/if_shaper.h
+sysdep_routines += cmsg_nxthdr sa_len
+endif
+
+ifeq ($(subdir),sunrpc)
+sysdep_headers += nfs/nfs.h
+endif
+
+ifeq ($(subdir),termios)
+sysdep_headers += termio.h
+endif
+
+ifeq ($(subdir),posix)
+sysdep_headers += bits/initspin.h
+
+sysdep_routines += exit-thread
+endif
+
+ifeq ($(subdir),inet)
+sysdep_headers += netinet/if_fddi.h netinet/if_tr.h \
+ netipx/ipx.h netash/ash.h netax25/ax25.h netatalk/at.h \
+ netrom/netrom.h netpacket/packet.h netrose/rose.h \
+ neteconet/ec.h
+endif
+
+# Don't compile the ctype glue code, since there is no old non-GNU C library.
+inhibit-glue = yes
+
+ifeq ($(subdir),dirent)
+sysdep_routines += getdirentries getdirentries64
+endif
+
+ifeq ($(subdir),nis)
+CFLAGS-ypclnt.c = -DUSE_BINDINGDIR=1
+endif
+
+ifeq ($(subdir),io)
+sysdep_routines += xstatconv internal_statvfs internal_statvfs64
+endif
+
+ifeq ($(subdir),elf)
+sysdep-rtld-routines += dl-brk dl-sbrk
+
+CPPFLAGS-lddlibc4 += -DNOT_IN_libc
+endif
+
+ifeq ($(subdir),rt)
+CFLAGS-mq_send.c += -fexceptions
+CFLAGS-mq_receive.c += -fexceptions
+endif
+
+ifeq ($(subdir),nscd)
+CFLAGS-connections.c += -DHAVE_EPOLL -DHAVE_SENDFILE
+CFLAGS-pwdcache.c += -DHAVE_SENDFILE
+CFLAGS-grpcache.c += -DHAVE_SENDFILE
+CFLAGS-hstcache.c += -DHAVE_SENDFILE
+CFLAGS-aicache.c += -DHAVE_SENDFILE
+CFLAGS-initgrcache.c += -DHAVE_SENDFILE
+CFLAGS-gai.c += -DNEED_NETLINK
+endif
diff --git a/libc/sysdeps/unix/sysv/linux/Versions b/libc/sysdeps/unix/sysv/linux/Versions
new file mode 100644
index 000000000..7c015b1d6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/Versions
@@ -0,0 +1,133 @@
+libc {
+ # The comment lines with "#errlist-compat" are magic; see errlist-compat.awk.
+ # When you get an error from errlist-compat.awk, you need to add a new
+ # version here. Don't do this blindly, since this means changing the ABI
+ # for all GNU/Linux configurations.
+
+ GLIBC_2.0 {
+ # functions used in inline functions or macros
+ __cmsg_nxthdr;
+
+ # functions used in other libraries
+ __clone;
+
+ # helper functions
+ __errno_location;
+
+ # b*
+ bdflush;
+
+ # c*
+ clone; create_module;
+
+ # d*
+ delete_module;
+
+ # g*
+ get_kernel_syms; getresgid; getresuid;
+
+ # i*
+ init_module;
+
+ # k*
+ klogctl;
+
+ # l*
+ llseek;
+
+ # m*
+ mremap;
+
+ # n*
+ nfsservctl;
+
+ # p*
+ personality; prctl;
+
+ # q*
+ query_module; quotactl;
+
+ # s*
+ setfsgid; setfsuid;
+
+ # s*
+ setresgid; setresuid; swapoff; swapon; sysctl;
+
+ # u*
+ umount; uselib;
+
+ #errlist-compat 123
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+ }
+ GLIBC_2.1 {
+ # functions used in inline functions or macros
+ __libc_sa_len;
+
+ # Since we have new signals this structure changed.
+ _sys_siglist; sys_siglist; sys_sigabbrev;
+
+ # New errlist.
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+
+ # chown interface change.
+ chown;
+
+ # Change in pthread_attr_t.
+ pthread_attr_init;
+
+ # c*
+ capget; capset;
+
+ # n*
+ ntp_adjtime; ntp_gettime;
+
+ # u*
+ umount2;
+
+ #errlist-compat 125
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+ }
+ GLIBC_2.2 {
+ # needed in other libraries.
+ __endmntent; __getmntent_r; __setmntent; __statfs; __sysctl;
+
+ # ipc ctl interface change.
+ semctl; shmctl; msgctl;
+ }
+ GLIBC_2.2.1 {
+ # p*
+ pivot_root;
+ }
+ GLIBC_2.3 {
+ # r*
+ readahead;
+
+ #errlist-compat 126
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+ }
+ GLIBC_2.3.2 {
+ # New kernel interfaces.
+ epoll_create; epoll_ctl; epoll_wait;
+ }
+ GLIBC_2.3.3 {
+ gnu_dev_major; gnu_dev_minor; gnu_dev_makedev;
+ }
+ GLIBC_2.3.4 {
+ sched_getaffinity; sched_setaffinity;
+ }
+ GLIBC_2.4 {
+ inotify_init; inotify_add_watch; inotify_rm_watch;
+
+ unshare;
+
+ #errlist-compat 132
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+ }
+ GLIBC_2.5 {
+ splice; sync_file_range; tee; vmsplice;
+ }
+ GLIBC_PRIVATE {
+ # functions used in other libraries
+ __syscall_rt_sigqueueinfo;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/_exit.c b/libc/sysdeps/unix/sysv/linux/_exit.c
new file mode 100644
index 000000000..1477bd80f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/_exit.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sysdep.h>
+#include <abort-instr.h>
+
+
+void
+_exit (status)
+ int status;
+{
+ while (1)
+ {
+#ifdef __NR_exit_group
+ INLINE_SYSCALL (exit_group, 1, status);
+#endif
+ INLINE_SYSCALL (exit, 1, status);
+
+#ifdef ABORT_INSTRUCTION
+ ABORT_INSTRUCTION;
+#endif
+ }
+}
+libc_hidden_def (_exit)
+weak_alias (_exit, _Exit)
diff --git a/libc/sysdeps/unix/sysv/linux/a.out.h b/libc/sysdeps/unix/sysv/linux/a.out.h
new file mode 100644
index 000000000..f0514c93a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/a.out.h
@@ -0,0 +1,138 @@
+#ifndef __A_OUT_GNU_H__
+#define __A_OUT_GNU_H__
+
+#include <bits/a.out.h>
+
+#define __GNU_EXEC_MACROS__
+
+struct exec
+{
+ unsigned long a_info; /* Use macros N_MAGIC, etc for access. */
+ unsigned int a_text; /* Length of text, in bytes. */
+ unsigned int a_data; /* Length of data, in bytes. */
+ unsigned int a_bss; /* Length of uninitialized data area for file, in bytes. */
+ unsigned int a_syms; /* Length of symbol table data in file, in bytes. */
+ unsigned int a_entry; /* Start address. */
+ unsigned int a_trsize;/* Length of relocation info for text, in bytes. */
+ unsigned int a_drsize;/* Length of relocation info for data, in bytes. */
+};
+
+enum machine_type
+{
+ M_OLDSUN2 = 0,
+ M_68010 = 1,
+ M_68020 = 2,
+ M_SPARC = 3,
+ M_386 = 100,
+ M_MIPS1 = 151,
+ M_MIPS2 = 152
+};
+
+#define N_MAGIC(exec) ((exec).a_info & 0xffff)
+#define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
+#define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
+#define N_SET_INFO(exec, magic, type, flags) \
+ ((exec).a_info = ((magic) & 0xffff) \
+ | (((int)(type) & 0xff) << 16) \
+ | (((flags) & 0xff) << 24))
+#define N_SET_MAGIC(exec, magic) \
+ ((exec).a_info = ((exec).a_info & 0xffff0000) | ((magic) & 0xffff))
+#define N_SET_MACHTYPE(exec, machtype) \
+ ((exec).a_info = \
+ ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
+#define N_SET_FLAGS(exec, flags) \
+ ((exec).a_info = \
+ ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
+
+/* Code indicating object file or impure executable. */
+#define OMAGIC 0407
+/* Code indicating pure executable. */
+#define NMAGIC 0410
+/* Code indicating demand-paged executable. */
+#define ZMAGIC 0413
+/* This indicates a demand-paged executable with the header in the text.
+ The first page is unmapped to help trap NULL pointer references. */
+#define QMAGIC 0314
+/* Code indicating core file. */
+#define CMAGIC 0421
+
+#define N_TRSIZE(a) ((a).a_trsize)
+#define N_DRSIZE(a) ((a).a_drsize)
+#define N_SYMSIZE(a) ((a).a_syms)
+#define N_BADMAG(x) \
+ (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \
+ && N_MAGIC(x) != ZMAGIC && N_MAGIC(x) != QMAGIC)
+#define _N_HDROFF(x) (1024 - sizeof (struct exec))
+#define N_TXTOFF(x) \
+ (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : \
+ (N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec)))
+#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
+#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
+#define N_DRELOFF(x) (N_TRELOFF(x) + N_TRSIZE(x))
+#define N_SYMOFF(x) (N_DRELOFF(x) + N_DRSIZE(x))
+#define N_STROFF(x) (N_SYMOFF(x) + N_SYMSIZE(x))
+
+/* Address of text segment in memory after it is loaded. */
+#define N_TXTADDR(x) (N_MAGIC(x) == QMAGIC ? 4096 : 0)
+
+/* Address of data segment in memory after it is loaded. */
+#define SEGMENT_SIZE 1024
+
+#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
+#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
+
+#define N_DATADDR(x) \
+ (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
+ : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
+#define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
+
+#if !defined (N_NLIST_DECLARED)
+struct nlist
+{
+ union
+ {
+ char *n_name;
+ struct nlist *n_next;
+ long n_strx;
+ } n_un;
+ unsigned char n_type;
+ char n_other;
+ short n_desc;
+ unsigned long n_value;
+};
+#endif /* no N_NLIST_DECLARED. */
+
+#define N_UNDF 0
+#define N_ABS 2
+#define N_TEXT 4
+#define N_DATA 6
+#define N_BSS 8
+#define N_FN 15
+#define N_EXT 1
+#define N_TYPE 036
+#define N_STAB 0340
+#define N_INDR 0xa
+#define N_SETA 0x14 /* Absolute set element symbol. */
+#define N_SETT 0x16 /* Text set element symbol. */
+#define N_SETD 0x18 /* Data set element symbol. */
+#define N_SETB 0x1A /* Bss set element symbol. */
+#define N_SETV 0x1C /* Pointer to set vector in data area. */
+
+#if !defined (N_RELOCATION_INFO_DECLARED)
+/* This structure describes a single relocation to be performed.
+ The text-relocation section of the file is a vector of these structures,
+ all of which apply to the text section.
+ Likewise, the data-relocation section applies to the data section. */
+
+struct relocation_info
+{
+ int r_address;
+ unsigned int r_symbolnum:24;
+ unsigned int r_pcrel:1;
+ unsigned int r_length:2;
+ unsigned int r_extern:1;
+ unsigned int r_pad:4;
+};
+#endif /* no N_RELOCATION_INFO_DECLARED. */
+
+#endif /* __A_OUT_GNU_H__ */
diff --git a/libc/sysdeps/unix/sysv/linux/accept.S b/libc/sysdeps/unix/sysv/linux/accept.S
new file mode 100644
index 000000000..491ebe2ab
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/accept.S
@@ -0,0 +1,6 @@
+#define socket accept
+#define __socket __libc_accept
+#define NARGS 3
+#define NEED_CANCELLATION
+#include <socket.S>
+libc_hidden_def (accept)
diff --git a/libc/sysdeps/unix/sysv/linux/adjtime.c b/libc/sysdeps/unix/sysv/linux/adjtime.c
new file mode 100644
index 000000000..38ef805cd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/adjtime.c
@@ -0,0 +1,98 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2002, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <limits.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+
+#define MAX_SEC (INT_MAX / 1000000L - 2)
+#define MIN_SEC (INT_MIN / 1000000L + 2)
+
+#ifndef MOD_OFFSET
+#define modes mode
+#endif
+
+#ifndef TIMEVAL
+#define TIMEVAL timeval
+#endif
+
+#ifndef TIMEX
+#define TIMEX timex
+#endif
+
+#ifndef ADJTIME
+#define ADJTIME __adjtime
+#endif
+
+#ifndef ADJTIMEX
+#define NO_LOCAL_ADJTIME
+#define ADJTIMEX(x) INTUSE(__adjtimex) (x)
+extern int INTUSE(__adjtimex) (struct timex *__ntx);
+#endif
+
+#ifndef LINKAGE
+#define LINKAGE
+#endif
+
+LINKAGE int
+ADJTIME (const struct TIMEVAL *itv, struct TIMEVAL *otv)
+{
+ struct TIMEX tntx;
+
+ if (itv)
+ {
+ struct TIMEVAL tmp;
+
+ /* We will do some check here. */
+ tmp.tv_sec = itv->tv_sec + itv->tv_usec / 1000000L;
+ tmp.tv_usec = itv->tv_usec % 1000000L;
+ if (tmp.tv_sec > MAX_SEC || tmp.tv_sec < MIN_SEC)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ tntx.offset = tmp.tv_usec + tmp.tv_sec * 1000000L;
+ tntx.modes = ADJ_OFFSET_SINGLESHOT;
+ }
+ else
+ tntx.modes = 0;
+
+ if (ADJTIMEX (&tntx) < 0)
+ return -1;
+
+ if (otv)
+ {
+ if (tntx.offset < 0)
+ {
+ otv->tv_usec = -(-tntx.offset % 1000000);
+ otv->tv_sec = -(-tntx.offset / 1000000);
+ }
+ else
+ {
+ otv->tv_usec = tntx.offset % 1000000;
+ otv->tv_sec = tntx.offset / 1000000;
+ }
+ }
+ return 0;
+}
+
+#ifdef NO_LOCAL_ADJTIME
+weak_alias (__adjtime, adjtime)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/aio_sigqueue.c b/libc/sysdeps/unix/sysv/linux/aio_sigqueue.c
new file mode 100644
index 000000000..30e9fbf7e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/aio_sigqueue.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 1997,1998,1999,2000,2003,2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <aio.h>
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include <aio_misc.h>
+
+#ifdef __NR_rt_sigqueueinfo
+
+/* Return any pending signal or wait for one for the given time. */
+int
+__aio_sigqueue (sig, val, caller_pid)
+ int sig;
+ const union sigval val;
+ pid_t caller_pid;
+{
+ siginfo_t info;
+
+ /* First, clear the siginfo_t structure, so that we don't pass our
+ stack content to other tasks. */
+ memset (&info, 0, sizeof (siginfo_t));
+ /* We must pass the information about the data in a siginfo_t value. */
+ info.si_signo = sig;
+ info.si_code = SI_ASYNCIO;
+ info.si_pid = caller_pid;
+ info.si_uid = getuid ();
+ info.si_value = val;
+
+ return INLINE_SYSCALL (rt_sigqueueinfo, 3, info.si_pid,
+ sig, __ptrvalue (&info));
+}
+#else
+# include <rt/aio_sigqueue.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/Implies b/libc/sysdeps/unix/sysv/linux/alpha/Implies
new file mode 100644
index 000000000..1616efecb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/Implies
@@ -0,0 +1,4 @@
+unix/sysv/linux/wordsize-64
+# These supply the ABI compatibility for when long double was double.
+ieee754/ldbl-64-128
+ieee754/ldbl-opt
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/Makefile b/libc/sysdeps/unix/sysv/linux/alpha/Makefile
new file mode 100644
index 000000000..f64f23fd7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/Makefile
@@ -0,0 +1,38 @@
+ifeq ($(subdir),posix)
+sysdep_routines += oldglob
+endif
+
+ifeq ($(subdir),stdlib)
+gen-as-const-headers += ucontext-offsets.sym
+endif
+
+ifeq ($(subdir),misc)
+sysdep_headers += alpha/ptrace.h alpha/regdef.h sys/io.h
+
+sysdep_routines += ieee_get_fp_control ieee_set_fp_control \
+ ioperm llseek
+
+# Support old timeval32 entry points
+sysdep_routines += osf_select osf_gettimeofday osf_settimeofday \
+ osf_getitimer osf_setitimer osf_utimes \
+ osf_getrusage osf_wait4
+
+# Support old ipc control
+sysdep_routines += oldmsgctl oldsemctl oldshmctl
+
+CFLAGS-ioperm.c = -Wa,-mev6
+endif
+
+ifeq ($(subdir),signal)
+sysdep_routines += rt_sigaction
+endif
+
+ifeq ($(subdir),math)
+# These 2 routines are normally in libgcc{.a,_s.so.1}.
+# However, alpha -mlong-double-128 libgcc relies on
+# glibc providing _Ots* routines and without these files
+# glibc relies on __multc3/__divtc3 only provided
+# by libgcc if configured with -mlong-double-128.
+# Provide these routines here as well.
+libm-routines += multc3 divtc3
+endif # math
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/Versions b/libc/sysdeps/unix/sysv/linux/alpha/Versions
new file mode 100644
index 000000000..8709dd2a3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/Versions
@@ -0,0 +1,94 @@
+libc {
+ # The comment lines with "#errlist-compat" are magic; see
+ # sysdeps/gnu/errlist-compat.awk.
+ # When you get an error from errlist-compat.awk, you need to add a new
+ # version here. Don't do this blindly, since this means changing the ABI
+ # for all GNU/Linux configurations.
+
+ GLIBC_2.0 {
+ #errlist-compat 131
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+
+ # Unfortunately in wider use.
+ _inb; _inw; _inl; _outb; _outw; _outl; _bus_base; _bus_base_sparse;
+ _hae_shift;
+
+ # Exception handling support functions from libgcc
+ __register_frame; __register_frame_table; __deregister_frame;
+ __frame_state_for; __register_frame_info_table;
+
+ # b*
+ bus_base; bus_base_sparse;
+
+ # h*
+ hae_shift;
+
+ # i*
+ inb; inl; inw; ioperm; iopl;
+
+ # o*
+ outb; outl; outw;
+
+ # p*
+ pciconfig_read; pciconfig_write; sethae;
+ }
+ GLIBC_2.1 {
+ #errlist-compat 131
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+
+ # Linux/Alpha 64-bit timeval functions.
+ __select; select;
+ adjtime; adjtimex; __adjtimex;
+ __gettimeofday;
+
+ # glob interface change
+ glob; globfree;
+
+ # limit type change
+ getrusage;
+
+ # time type change
+ gettimeofday; getitimer;
+
+ # i*
+ ieee_get_fp_control; ieee_set_fp_control;
+
+ # s*
+ setitimer; settimeofday;
+
+ # u*
+ utimes;
+
+ # w*
+ wait4;
+ }
+ GLIBC_2.1.4 {
+ pciconfig_iobase;
+ }
+ GLIBC_2.2.2 {
+ # w*
+ wordexp;
+ }
+ GLIBC_2.3 {
+ #errlist-compat 132
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+ }
+ GLIBC_2.4 {
+ #errlist-compat 138
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+ }
+ GLIBC_PRIVATE {
+ __libc_alpha_cache_shape;
+ }
+}
+ld {
+ GLIBC_PRIVATE {
+ __libc_alpha_cache_shape;
+ }
+}
+librt {
+ GLIBC_2.3 {
+ # AIO functions.
+ aio_cancel; aio_cancel64;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/a.out.h b/libc/sysdeps/unix/sysv/linux/alpha/a.out.h
new file mode 100644
index 000000000..a7699f0fe
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/a.out.h
@@ -0,0 +1,197 @@
+#ifndef __A_OUT_GNU_H__
+#define __A_OUT_GNU_H__
+
+#include <bits/a.out.h>
+
+#define __GNU_EXEC_MACROS__
+
+/*
+ * OSF/1 ECOFF header structs. ECOFF files consist of:
+ * - a file header (struct filehdr),
+ * - an a.out header (struct aouthdr),
+ * - one or more section headers (struct scnhdr).
+ * The filhdr's "f_nscns" field contains the
+ * number of section headers.
+ */
+
+struct filehdr
+{
+ /* OSF/1 "file" header */
+ unsigned short f_magic, f_nscns;
+ unsigned int f_timdat;
+ unsigned long f_symptr;
+ unsigned int f_nsyms;
+ unsigned short f_opthdr, f_flags;
+};
+
+struct aouthdr
+{
+ unsigned long info; /* After that it looks quite normal.. */
+ unsigned long tsize;
+ unsigned long dsize;
+ unsigned long bsize;
+ unsigned long entry;
+ unsigned long text_start; /* With a few additions that actually make sense. */
+ unsigned long data_start;
+ unsigned long bss_start;
+ unsigned int gprmask, fprmask; /* Bitmask of general & floating point regs used in binary. */
+ unsigned long gpvalue;
+};
+
+struct scnhdr
+{
+ char s_name[8];
+ unsigned long s_paddr;
+ unsigned long s_vaddr;
+ unsigned long s_size;
+ unsigned long s_scnptr;
+ unsigned long s_relptr;
+ unsigned long s_lnnoptr;
+ unsigned short s_nreloc;
+ unsigned short s_nlnno;
+ unsigned int s_flags;
+};
+
+struct exec
+{
+ /* OSF/1 "file" header */
+ struct filehdr fh;
+ struct aouthdr ah;
+};
+
+#define a_info ah.info
+#define a_text ah.tsize
+#define a_data ah.dsize
+#define a_bss ah.bsize
+#define a_entry ah.entry
+#define a_textstart ah.text_start
+#define a_datastart ah.data_start
+#define a_bssstart ah.bss_start
+#define a_gprmask ah.gprmask
+#define a_fprmask ah.fprmask
+#define a_gpvalue ah.gpvalue
+
+
+#define AOUTHSZ sizeof(struct aouthdr)
+#define SCNHSZ sizeof(struct scnhdr)
+#define SCNROUND 16
+
+enum machine_type
+{
+ M_OLDSUN2 = 0,
+ M_68010 = 1,
+ M_68020 = 2,
+ M_SPARC = 3,
+ M_386 = 100,
+ M_MIPS1 = 151,
+ M_MIPS2 = 152
+};
+
+#define N_MAGIC(exec) ((exec).a_info & 0xffff)
+#define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
+#define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
+#define N_SET_INFO(exec, magic, type, flags) \
+ ((exec).a_info = ((magic) & 0xffff) \
+ | (((int)(type) & 0xff) << 16) \
+ | (((flags) & 0xff) << 24))
+#define N_SET_MAGIC(exec, magic) \
+ ((exec).a_info = ((exec).a_info & 0xffff0000) | ((magic) & 0xffff))
+#define N_SET_MACHTYPE(exec, machtype) \
+ ((exec).a_info = \
+ ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
+#define N_SET_FLAGS(exec, flags) \
+ ((exec).a_info = \
+ ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
+
+/* Code indicating object file or impure executable. */
+#define OMAGIC 0407
+/* Code indicating pure executable. */
+#define NMAGIC 0410
+/* Code indicating demand-paged executable. */
+#define ZMAGIC 0413
+/* This indicates a demand-paged executable with the header in the text.
+ The first page is unmapped to help trap NULL pointer references. */
+#define QMAGIC 0314
+/* Code indicating core file. */
+#define CMAGIC 0421
+
+#define N_TRSIZE(x) 0
+#define N_DRSIZE(x) 0
+#define N_SYMSIZE(x) 0
+#define N_BADMAG(x) \
+ (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \
+ && N_MAGIC(x) != ZMAGIC && N_MAGIC(x) != QMAGIC)
+#define _N_HDROFF(x) (1024 - sizeof (struct exec))
+#define N_TXTOFF(x) \
+ ((long) N_MAGIC(x) == ZMAGIC ? 0 : \
+ (sizeof (struct exec) + (x).fh.f_nscns * SCNHSZ + SCNROUND - 1) \
+ & ~(SCNROUND - 1))
+
+#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
+#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
+#define N_DRELOFF(x) (N_TRELOFF(x) + N_TRSIZE(x))
+#define N_SYMOFF(x) (N_DRELOFF(x) + N_DRSIZE(x))
+#define N_STROFF(x) (N_SYMOFF(x) + N_SYMSIZE(x))
+
+/* Address of text segment in memory after it is loaded. */
+#define N_TXTADDR(x) ((x).a_textstart)
+
+/* Address of data segment in memory after it is loaded. */
+#define SEGMENT_SIZE 1024
+
+#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
+#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
+
+#define N_DATADDR(x) ((x).a_datastart)
+#define N_BSSADDR(x) ((x).a_bssstart)
+
+#if !defined (N_NLIST_DECLARED)
+struct nlist
+{
+ union
+ {
+ char *n_name;
+ struct nlist *n_next;
+ long n_strx;
+ } n_un;
+ unsigned char n_type;
+ char n_other;
+ short n_desc;
+ unsigned long n_value;
+};
+#endif /* no N_NLIST_DECLARED. */
+
+#define N_UNDF 0
+#define N_ABS 2
+#define N_TEXT 4
+#define N_DATA 6
+#define N_BSS 8
+#define N_FN 15
+#define N_EXT 1
+#define N_TYPE 036
+#define N_STAB 0340
+#define N_INDR 0xa
+#define N_SETA 0x14 /* Absolute set element symbol. */
+#define N_SETT 0x16 /* Text set element symbol. */
+#define N_SETD 0x18 /* Data set element symbol. */
+#define N_SETB 0x1A /* Bss set element symbol. */
+#define N_SETV 0x1C /* Pointer to set vector in data area. */
+
+#if !defined (N_RELOCATION_INFO_DECLARED)
+/* This structure describes a single relocation to be performed.
+ The text-relocation section of the file is a vector of these structures,
+ all of which apply to the text section.
+ Likewise, the data-relocation section applies to the data section. */
+
+struct relocation_info
+{
+ int r_address;
+ unsigned int r_symbolnum:24;
+ unsigned int r_pcrel:1;
+ unsigned int r_length:2;
+ unsigned int r_extern:1;
+ unsigned int r_pad:4;
+};
+#endif /* no N_RELOCATION_INFO_DECLARED. */
+
+#endif /* __A_OUT_GNU_H__ */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/adjtime.c b/libc/sysdeps/unix/sysv/linux/alpha/adjtime.c
new file mode 100644
index 000000000..1700524d3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/adjtime.c
@@ -0,0 +1,220 @@
+/* Copyright (C) 1998,2000,2002,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <shlib-compat.h>
+#include <sysdep.h>
+#include <sys/time.h>
+#include <kernel-features.h>
+
+#if !defined __ASSUME_TIMEVAL64 || SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+struct timeval32
+{
+ int tv_sec, tv_usec;
+};
+
+struct timex32 {
+ unsigned int modes; /* mode selector */
+ long offset; /* time offset (usec) */
+ long freq; /* frequency offset (scaled ppm) */
+ long maxerror; /* maximum error (usec) */
+ long esterror; /* estimated error (usec) */
+ int status; /* clock command/status */
+ long constant; /* pll time constant */
+ long precision; /* clock precision (usec) (read only) */
+ long tolerance; /* clock frequency tolerance (ppm)
+ * (read only)
+ */
+ struct timeval32 time; /* (read only) */
+ long tick; /* (modified) usecs between clock ticks */
+
+ long ppsfreq; /* pps frequency (scaled ppm) (ro) */
+ long jitter; /* pps jitter (us) (ro) */
+ int shift; /* interval duration (s) (shift) (ro) */
+ long stabil; /* pps stability (scaled ppm) (ro) */
+ long jitcnt; /* jitter limit exceeded (ro) */
+ long calcnt; /* calibration intervals (ro) */
+ long errcnt; /* calibration errors (ro) */
+ long stbcnt; /* stability limit exceeded (ro) */
+
+ int :32; int :32; int :32; int :32;
+ int :32; int :32; int :32; int :32;
+ int :32; int :32; int :32; int :32;
+};
+
+#define TIMEVAL timeval32
+#define TIMEX timex32
+#define ADJTIME attribute_compat_text_section __adjtime_tv32
+#define ADJTIMEX(x) INLINE_SYSCALL (old_adjtimex, 1, x)
+#define ADJTIMEX32(x) INLINE_SYSCALL (old_adjtimex, 1, x)
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+#define LINKAGE
+#else
+#define LINKAGE static
+#endif
+
+LINKAGE int ADJTIME (const struct TIMEVAL *itv, struct TIMEVAL *otv);
+
+#include <sysdeps/unix/sysv/linux/adjtime.c>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+int
+attribute_compat_text_section
+__adjtimex_tv32 (struct timex32 *tx) { return ADJTIMEX (tx); }
+strong_alias (__adjtimex_tv32, __adjtimex_tv32_1);
+strong_alias (__adjtimex_tv32, __adjtimex_tv32_2);
+compat_symbol (libc, __adjtimex_tv32_1, __adjtimex, GLIBC_2_0);
+compat_symbol (libc, __adjtimex_tv32_2, adjtimex, GLIBC_2_0);
+compat_symbol (libc, __adjtime_tv32, adjtime, GLIBC_2_0);
+#endif
+#endif /* !__ASSUME_TIMEVAL64 || SHLIB_COMPAT */
+
+#undef TIMEVAL
+#define TIMEVAL timeval
+#undef TIMEX
+#define TIMEX timex
+#undef ADJTIMEX
+#define ADJTIMEX(x) INLINE_SYSCALL (adjtimex, 1, x)
+
+#undef LINKAGE
+#undef ADJTIME
+#if !defined __ASSUME_TIMEVAL64
+#define LINKAGE static
+#define ADJTIME __adjtime_tv64
+#endif
+
+#include <sysdeps/unix/sysv/linux/adjtime.c>
+#include <stdbool.h>
+
+#if !defined __ASSUME_TIMEVAL64
+static bool missing_adjtimex;
+
+int
+__adjtime (itv, otv)
+ const struct timeval *itv;
+ struct timeval *otv;
+{
+ struct timeval32 itv32, otv32;
+ int ret;
+
+ switch (missing_adjtimex)
+ {
+ case false:
+ ret = __adjtime_tv64 (itv, otv);
+ if (ret && errno == ENOSYS)
+ missing_adjtimex = 1;
+ else
+ break;
+
+ /* FALLTHRU */
+
+ default:
+ itv32.tv_sec = itv->tv_sec;
+ itv32.tv_usec = itv->tv_usec;
+ ret = __adjtime_tv32 (&itv32, &otv32);
+ if (ret == 0)
+ {
+ otv->tv_sec = otv32.tv_sec;
+ otv->tv_usec = otv32.tv_usec;
+ }
+ break;
+ }
+
+ return ret;
+}
+#endif
+
+versioned_symbol (libc, __adjtime, adjtime, GLIBC_2_1);
+
+int
+__adjtimex_tv64 (struct timex *tx)
+{
+#if defined __ASSUME_TIMEVAL64
+ return ADJTIMEX (tx);
+#else
+ struct timex32 tx32;
+ int ret;
+
+ switch (missing_adjtimex)
+ {
+ case false:
+ ret = ADJTIMEX (tx);
+ if (ret && errno == ENOSYS)
+ missing_adjtimex = 1;
+ else
+ break;
+
+ /* FALLTHRU */
+
+ default:
+ tx32.modes = tx->modes;
+ tx32.offset = tx->offset;
+ tx32.freq = tx->freq;
+ tx32.maxerror = tx->maxerror;
+ tx32.esterror = tx->esterror;
+ tx32.status = tx->status;
+ tx32.constant = tx->constant;
+ tx32.precision = tx->precision;
+ tx32.tolerance = tx->tolerance;
+ tx32.time.tv_sec = tx->time.tv_sec;
+ tx32.time.tv_sec = tx->time.tv_usec;
+ tx32.tick = tx->tick;
+ tx32.ppsfreq = tx->ppsfreq;
+ tx32.jitter = tx->jitter;
+ tx32.shift = tx->shift;
+ tx32.stabil = tx->stabil;
+ tx32.jitcnt = tx->jitcnt;
+ tx32.calcnt = tx->calcnt;
+ tx32.errcnt = tx->errcnt;
+ tx32.stbcnt = tx->stbcnt;
+
+ ret = ADJTIMEX32 (&tx32);
+ if (ret == 0)
+ {
+ tx->modes = tx32.modes;
+ tx->offset = tx32.offset;
+ tx->freq = tx32.freq;
+ tx->maxerror = tx32.maxerror;
+ tx->esterror = tx32.esterror;
+ tx->status = tx32.status;
+ tx->constant = tx32.constant;
+ tx->precision = tx32.precision;
+ tx->tolerance = tx32.tolerance;
+ tx->time.tv_sec = tx32.time.tv_sec;
+ tx->time.tv_usec = tx32.time.tv_sec;
+ tx->tick = tx32.tick;
+ tx->ppsfreq = tx32.ppsfreq;
+ tx->jitter = tx32.jitter;
+ tx->shift = tx32.shift;
+ tx->stabil = tx32.stabil;
+ tx->jitcnt = tx32.jitcnt;
+ tx->calcnt = tx32.calcnt;
+ tx->errcnt = tx32.errcnt;
+ tx->stbcnt = tx32.stbcnt;
+ }
+ break;
+ }
+
+ return ret;
+#endif
+}
+
+strong_alias (__adjtimex_tv64, __adjtimex_internal);
+strong_alias (__adjtimex_tv64, __adjtimex_tv64p);
+weak_alias (__adjtimex_tv64, ntp_adjtime);
+versioned_symbol (libc, __adjtimex_tv64, __adjtimex, GLIBC_2_1);
+versioned_symbol (libc, __adjtimex_tv64p, adjtimex, GLIBC_2_1);
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/alpha/ptrace.h b/libc/sysdeps/unix/sysv/linux/alpha/alpha/ptrace.h
new file mode 100644
index 000000000..57b96d64d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/alpha/ptrace.h
@@ -0,0 +1,18 @@
+#ifndef __alpha_ptrace_h__
+#define __alpha_ptrace_h__
+
+/*
+ * Mostly for OSF/1 compatibility.
+ */
+
+#define REG_BASE 0
+#define NGP_REGS 32
+#define NFP_REGS 32
+
+#define GPR_BASE REG_BASE
+#define FPR_BASE (GPR_BASE+NGP_REGS)
+#define PC (FPR_BASE+NFP_REGS)
+#define SPR_PS (PC+1)
+#define NPTRC_REGS (SPR_PS+1)
+
+#endif /* __alpha_ptrace_h__ */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/alpha/regdef.h b/libc/sysdeps/unix/sysv/linux/alpha/alpha/regdef.h
new file mode 100644
index 000000000..142df9c4f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/alpha/regdef.h
@@ -0,0 +1,44 @@
+#ifndef __alpha_regdef_h__
+#define __alpha_regdef_h__
+
+#define v0 $0 /* function return value */
+
+#define t0 $1 /* temporary registers (caller-saved) */
+#define t1 $2
+#define t2 $3
+#define t3 $4
+#define t4 $5
+#define t5 $6
+#define t6 $7
+#define t7 $8
+
+#define s0 $9 /* saved-registers (callee-saved registers) */
+#define s1 $10
+#define s2 $11
+#define s3 $12
+#define s4 $13
+#define s5 $14
+#define s6 $15
+#define fp s6 /* frame-pointer (s6 in frame-less procedures) */
+
+#define a0 $16 /* argument registers (caller-saved) */
+#define a1 $17
+#define a2 $18
+#define a3 $19
+#define a4 $20
+#define a5 $21
+
+#define t8 $22 /* more temps (caller-saved) */
+#define t9 $23
+#define t10 $24
+#define t11 $25
+#define ra $26 /* return address register */
+#define t12 $27
+
+#define pv t12 /* procedure-variable register */
+#define AT $at /* assembler temporary */
+#define gp $29 /* global pointer */
+#define sp $30 /* stack pointer */
+#define zero $31 /* reads as zero, writes are noops */
+
+#endif /* __alpha_regdef_h__ */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/a.out.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/a.out.h
new file mode 100644
index 000000000..82a3dd4c0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/a.out.h
@@ -0,0 +1,9 @@
+#ifndef __A_OUT_GNU_H__
+# error "Never use <bits/a.out.h> directly; include <a.out.h> instead."
+#endif
+#ifndef __A_OUT_GNU_H__
+# error "Never use <bits/a.out.h> directly; include <a.out.h> instead."
+#endif
+#ifndef __A_OUT_GNU_H__
+# error "Never use <bits/a.out.h> directly; include <a.out.h> instead."
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/dirent.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/dirent.h
new file mode 100644
index 000000000..6ed74783a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/dirent.h
@@ -0,0 +1,55 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _BITS_DIRENT_H
+#define _BITS_DIRENT_H 1
+
+struct dirent
+ {
+#ifdef __USE_FILE_OFFSET64
+ __ino64_t d_ino;
+#else
+ __ino_t d_ino;
+ int __pad;
+#endif
+ __off_t d_off;
+ unsigned short int d_reclen;
+ unsigned char d_type;
+ char d_name[256]; /* We must not include limits.h! */
+ };
+
+#ifdef __USE_LARGEFILE64
+/* Note dirent64 is the same as dirent. */
+struct dirent64
+ {
+ __ino64_t d_ino;
+ __off64_t d_off;
+ unsigned short int d_reclen;
+ unsigned char d_type;
+ char d_name[256]; /* We must not include limits.h! */
+ };
+#endif
+
+#define d_fileno d_ino /* Backwards compatibility. */
+
+#undef _DIRENT_HAVE_D_NAMLEN
+#define _DIRENT_HAVE_D_RECLEN
+#define _DIRENT_HAVE_D_OFF
+#define _DIRENT_HAVE_D_TYPE
+
+#endif /* bits/dirent.h */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/elfclass.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/elfclass.h
new file mode 100644
index 000000000..e5aa4a0fb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/elfclass.h
@@ -0,0 +1,14 @@
+/* This file specifies the native word size of the machine, which indicates
+ the ELF file class used for executables and shared objects on this
+ machine. */
+
+#ifndef _LINK_H
+# error "Never use <bits/elfclass.h> directly; include <link.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#define __ELF_NATIVE_CLASS __WORDSIZE
+
+/* Linux/Alpha is exceptional as it has .hash section with 64 bit entries. */
+typedef uint64_t Elf_Symndx;
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/errno.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/errno.h
new file mode 100644
index 000000000..8b2f152a1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/errno.h
@@ -0,0 +1,58 @@
+/* Error constants. Linux/Alpha specific version.
+ Copyright (C) 1996,1997,1998,1999,2002,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifdef _ERRNO_H
+
+# undef EDOM
+# undef EILSEQ
+# undef ERANGE
+# include <linux/errno.h>
+
+/* Linux has no ENOTSUP error code. */
+# define ENOTSUP EOPNOTSUPP
+
+# ifndef ECANCELED
+# define ECANCELED 131
+# endif
+
+/* Support for error codes to support robust mutexes was added later, too. */
+# ifndef EOWNERDEAD
+# define EOWNERDEAD 136
+# define ENOTRECOVERABLE 137
+# endif
+
+# ifndef __ASSEMBLER__
+/* Function to get address of global `errno' variable. */
+extern int *__errno_location (void) __THROW __attribute__ ((__const__));
+
+# if !defined _LIBC || defined _LIBC_REENTRANT
+/* When using threads, errno is a per-thread value. */
+# define errno (*__errno_location ())
+# endif
+# endif /* !__ASSEMBLER__ */
+#endif /* _ERRNO_H */
+
+#if !defined _ERRNO_H && defined __need_Emath
+/* This is ugly but the kernel header is not clean enough. We must
+ define only the values EDOM, EILSEQ and ERANGE in case __need_Emath is
+ defined. */
+# define EDOM 33 /* Math argument out of domain of function. */
+# define EILSEQ 116 /* Illegal byte sequence. */
+# define ERANGE 34 /* Math result not representable. */
+#endif /* !_ERRNO_H && __need_Emath */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h
new file mode 100644
index 000000000..6084c38c9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h
@@ -0,0 +1,228 @@
+/* O_*, F_*, FD_* bit values for Linux.
+ Copyright (C) 1995-2000, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <sys/types.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+
+
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on an ext2 file system */
+#define O_ACCMODE 0003
+#define O_RDONLY 00
+#define O_WRONLY 01
+#define O_RDWR 02
+#define O_CREAT 01000 /* not fcntl */
+#define O_TRUNC 02000 /* not fcntl */
+#define O_EXCL 04000 /* not fcntl */
+#define O_NOCTTY 010000 /* not fcntl */
+
+#define O_NONBLOCK 00004
+#define O_APPEND 00010
+#define O_NDELAY O_NONBLOCK
+#define O_SYNC 040000
+#define O_FSYNC O_SYNC
+#define O_ASYNC 020000 /* fcntl, for BSD compatibility */
+
+#ifdef __USE_GNU
+# define O_DIRECTORY 0100000 /* Must be a directory. */
+# define O_NOFOLLOW 0200000 /* Do not follow links. */
+# define O_DIRECT 02000000 /* Direct disk access. */
+# define O_NOATIME 04000000 /* Do not set atime. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+/* Not necessary, files are always with 64bit off_t. */
+# define O_LARGEFILE 0
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#define F_GETLK 7 /* Get record locking info. */
+#define F_SETLK 8 /* Set record locking info (non-blocking). */
+#define F_SETLKW 9 /* Set record locking info (blocking). */
+#define F_GETLK64 F_GETLK /* Get record locking info. */
+#define F_SETLK64 F_SETLK /* Set record locking info (non-blocking). */
+#define F_SETLKW64 F_SETLKW /* Set record locking info (blocking). */
+
+#if defined __USE_BSD || defined __USE_UNIX98
+# define F_SETOWN 5 /* Get owner of socket (receiver of SIGIO). */
+# define F_GETOWN 6 /* Set owner of socket (receiver of SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+#endif
+
+/* for F_[GET|SET]FD */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf() */
+#define F_RDLCK 1 /* Read lock. */
+#define F_WRLCK 2 /* Write lock. */
+#define F_UNLCK 8 /* Remove lock. */
+
+/* for old implementation of bsd flock () */
+#define F_EXLCK 16 /* or 3 */
+#define F_SHLCK 32 /* or 4 */
+
+/* Operations for bsd flock(), also used by the kernel implementation */
+#ifdef __USE_BSD
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#endif
+
+/* We don't need to support __USE_FILE_OFFSET64. */
+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'). */
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+ __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
+
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+#endif
+
+
+#ifdef __USE_GNU
+/* Flags for SYNC_FILE_RANGE. */
+# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
+ in the range before performing the
+ write. */
+# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
+ dirty pages in the range which are
+ not presently under writeback. */
+# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
+ the range after performing the
+ write. */
+
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+#endif
+
+__BEGIN_DECLS
+
+#ifdef __USE_GNU
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+
+/* Selective file content synch'ing. */
+extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
+ unsigned int __flags);
+
+
+/* Splice address range into a pipe. */
+extern int vmsplice (int __fdout, const struct iovec *__iov, size_t __count,
+ unsigned int __flags);
+
+/* Splice two files together. */
+extern int splice (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+/* In-kernel implementation of tee for pipe buffers. */
+extern int tee (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+#endif
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/ioctls.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/ioctls.h
new file mode 100644
index 000000000..c525046e5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/ioctls.h
@@ -0,0 +1,37 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IOCTL_H
+# error "Never use <bits/ioctls.h> directly; include <sys/ioctl.h> instead."
+#endif
+
+/* Use the definitions from the kernel header files. */
+#include <asm/ioctls.h>
+
+/* Oh well, this is necessary since the kernel data structure is
+ different from the user-level version. */
+#undef TCGETS
+#undef TCSETS
+#undef TCSETSW
+#undef TCSETSF
+#define TCGETS _IOR ('t', 19, char[44])
+#define TCSETS _IOW ('t', 20, char[44])
+#define TCSETSW _IOW ('t', 21, char[44])
+#define TCSETSF _IOW ('t', 22, char[44])
+
+#include <linux/sockios.h>
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/ipc.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/ipc.h
new file mode 100644
index 000000000..77f3c938d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/ipc.h
@@ -0,0 +1,55 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IPC_H
+# error "Never use <bits/ipc.h> directly; include <sys/ipc.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Mode bits for `msgget', `semget', and `shmget'. */
+#define IPC_CREAT 01000 /* Create key if key does not exist. */
+#define IPC_EXCL 02000 /* Fail if key exists. */
+#define IPC_NOWAIT 04000 /* Return error on wait. */
+
+/* Control commands for `msgctl', `semctl', and `shmctl'. */
+#define IPC_RMID 0 /* Remove identifier. */
+#define IPC_SET 1 /* Set `ipc_perm' options. */
+#define IPC_STAT 2 /* Get `ipc_perm' options. */
+#ifdef __USE_GNU
+# define IPC_INFO 3 /* See ipcs. */
+#endif
+
+/* Special key values. */
+#define IPC_PRIVATE ((__key_t) 0) /* Private key. */
+
+
+/* Data structure used to pass permission information to IPC operations. */
+struct ipc_perm
+ {
+ __key_t __key; /* Key. */
+ unsigned int uid; /* Owner's user ID. */
+ unsigned int gid; /* Owner's group ID. */
+ unsigned int cuid; /* Creator's user ID. */
+ unsigned int cgid; /* Creator's group ID. */
+ unsigned int mode; /* Read/write permission. */
+ unsigned short int __seq; /* Sequence number. */
+ unsigned short int __pad1;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ };
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/mman.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/mman.h
new file mode 100644
index 000000000..2f0e56491
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/mman.h
@@ -0,0 +1,118 @@
+/* Definitions for POSIX memory map interface. Linux/Alpha version.
+ Copyright (C) 1997, 1998, 2000, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MMAN_H
+# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead."
+#endif
+
+/* The following definitions basically come from the kernel headers.
+ But the kernel header is not namespace clean. */
+
+
+/* Protections are chosen from these bits, OR'd together. The
+ implementation does not necessarily support PROT_EXEC or PROT_WRITE
+ without PROT_READ. The only guarantees are that no writing will be
+ allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
+
+#define PROT_READ 0x1 /* Page can be read. */
+#define PROT_WRITE 0x2 /* Page can be written. */
+#define PROT_EXEC 0x4 /* Page can be executed. */
+#define PROT_NONE 0x0 /* Page can not be accessed. */
+#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
+ growsdown vma (mprotect only). */
+#define PROT_GROWSUP 0x02000000 /* Extend change to start of
+ growsup vma (mprotect only). */
+
+/* Sharing types (must choose one and only one of these). */
+#define MAP_SHARED 0x01 /* Share changes. */
+#define MAP_PRIVATE 0x02 /* Changes are private. */
+#ifdef __USE_MISC
+# define MAP_TYPE 0x0f /* Mask for type of mapping. */
+#endif
+
+/* Other flags. */
+#define MAP_FIXED 0x100 /* Interpret addr exactly. */
+#ifdef __USE_MISC
+# define MAP_FILE 0
+# define MAP_ANONYMOUS 0x10 /* Don't use a file. */
+# define MAP_ANON MAP_ANONYMOUS
+#endif
+
+/* Not used by Linux, but here to make sure we don't clash with
+ OSF/1 defines. */
+#if 0 && defined __USE_BSD
+# define MAP_HASSEMAPHORE 0x0200
+# define MAP_INHERIT 0x0400
+# define MAP_UNALIGNED 0x0800
+#endif
+
+/* These are Linux-specific. */
+#ifdef __USE_MISC
+# define MAP_GROWSDOWN 0x01000 /* Stack-like segment. */
+# define MAP_DENYWRITE 0x02000 /* ETXTBSY */
+# define MAP_EXECUTABLE 0x04000 /* Mark it as an executable. */
+# define MAP_LOCKED 0x08000 /* Lock the mapping. */
+# define MAP_NORESERVE 0x10000 /* Don't check for reservations. */
+# define MAP_POPULATE 0x20000 /* Populate (prefault) pagetables. */
+# define MAP_NONBLOCK 0x40000 /* Do not block on IO. */
+#endif
+
+/* Flags to `msync'. */
+#define MS_ASYNC 1 /* Sync memory asynchronously. */
+#define MS_SYNC 2 /* Synchronous memory sync. */
+#define MS_INVALIDATE 4 /* Invalidate the caches. */
+
+/* Flags for `mlockall'. */
+#define MCL_CURRENT 8192 /* Lock all currently mapped pages. */
+#define MCL_FUTURE 16384 /* Lock all additions to address
+ space. */
+
+/* Flags for `mremap'. */
+#ifdef __USE_GNU
+# define MREMAP_MAYMOVE 1
+# define MREMAP_FIXED 2
+#endif
+
+/* Advice to `madvise'. */
+#ifdef __USE_BSD
+# define MADV_NORMAL 0 /* No further special treatment. */
+# define MADV_RANDOM 1 /* Expect random page references. */
+# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define MADV_WILLNEED 3 /* Will need these pages. */
+# define MADV_DONTNEED 6 /* Don't need these pages. */
+# define MADV_REMOVE 9 /* Remove these pages and resources. */
+# define MADV_DONTFORK 10 /* Do not inherit across fork. */
+# define MADV_DOFORK 11 /* Do inherit across fork. */
+#endif
+
+/* The POSIX people had to invent similar names for the same things. */
+#ifdef __USE_XOPEN2K
+# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_MADV_DONTNEED 6 /* Don't need these pages. */
+#endif
+
+/* Not used by Linux, but here to make sure we don't clash with
+ OSF/1 defines. */
+#if 0 && defined __USE_BSD
+# define MADV_DONTNEED_COMPAT 4 /* Old version? */
+# define MADV_SPACEAVAIL 5 /* Ensure resources are available. */
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/msq.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/msq.h
new file mode 100644
index 000000000..ab251eaf7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/msq.h
@@ -0,0 +1,74 @@
+/* Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MSG_H
+# error "Never use <bits/msq.h> directly; include <sys/msg.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Define options for message queue functions. */
+#define MSG_NOERROR 010000 /* no error if message is too big */
+#ifdef __USE_GNU
+# define MSG_EXCEPT 020000 /* recv any msg except of specified type */
+#endif
+
+/* Types used in the structure definition. */
+typedef unsigned long int msgqnum_t;
+typedef unsigned long int msglen_t;
+
+
+/* Structure of record for one message inside the kernel.
+ The type `struct msg' is opaque. */
+struct msqid_ds
+{
+ struct ipc_perm msg_perm; /* structure describing operation permission */
+ __time_t msg_stime; /* time of last msgsnd command */
+ __time_t msg_rtime; /* time of last msgrcv command */
+ __time_t msg_ctime; /* time of last change */
+ 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 __unused1;
+ unsigned long int __unused2;
+};
+
+#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/libc/sysdeps/unix/sysv/linux/alpha/bits/netdb.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/netdb.h
new file mode 100644
index 000000000..e3664fd29
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/netdb.h
@@ -0,0 +1,35 @@
+/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NETDB_H
+# error "Never include <bits/netdb.h> directly; use <netdb.h> instead."
+#endif
+
+
+/* Description of data base entry for a single network. NOTE: here a
+ poor assumption is made. The network number is expected to fit
+ into an unsigned long int variable. */
+struct netent
+{
+ char *n_name; /* Official name of network. */
+ char **n_aliases; /* Alias list. */
+ int n_addrtype; /* Net address type. */
+ /* XXX We should probably use uint32_t for the field and ensure
+ compatiblity by adding appropriate padding. */
+ unsigned long int n_net; /* Network number. */
+};
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/resource.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/resource.h
new file mode 100644
index 000000000..216374584
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/resource.h
@@ -0,0 +1,225 @@
+/* Bit values & structures for resource limits. Alpha/Linux version.
+ Copyright (C) 1994, 1996, 1997, 1998, 1999, 2000, 2004, 2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_RESOURCE_H
+# error "Never use <bits/resource.h> directly; include <sys/resource.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Transmute defines to enumerations. The macro re-definitions are
+ necessary because some programs want to test for operating system
+ features with #ifdef RUSAGE_SELF. In ISO C the reflexive
+ definition is a no-op. */
+
+/* Kinds of resource limit. */
+enum __rlimit_resource
+{
+ /* Per-process CPU limit, in seconds. */
+ RLIMIT_CPU = 0,
+#define RLIMIT_CPU RLIMIT_CPU
+
+ /* Largest file that can be created, in bytes. */
+ RLIMIT_FSIZE = 1,
+#define RLIMIT_FSIZE RLIMIT_FSIZE
+
+ /* Maximum size of data segment, in bytes. */
+ RLIMIT_DATA = 2,
+#define RLIMIT_DATA RLIMIT_DATA
+
+ /* Maximum size of stack segment, in bytes. */
+ RLIMIT_STACK = 3,
+#define RLIMIT_STACK RLIMIT_STACK
+
+ /* Largest core file that can be created, in bytes. */
+ RLIMIT_CORE = 4,
+#define RLIMIT_CORE RLIMIT_CORE
+
+ /* Largest resident set size, in bytes.
+ This affects swapping; processes that are exceeding their
+ resident set size will be more likely to have physical memory
+ taken from them. */
+ __RLIMIT_RSS = 5,
+#define RLIMIT_RSS __RLIMIT_RSS
+
+ /* Number of open files. */
+ RLIMIT_NOFILE = 6,
+ __RLIMIT_OFILE = RLIMIT_NOFILE, /* BSD name for same. */
+#define RLIMIT_NOFILE RLIMIT_NOFILE
+#define RLIMIT_OFILE __RLIMIT_OFILE
+
+ /* Address space limit (?) */
+ RLIMIT_AS = 7,
+#define RLIMIT_AS RLIMIT_AS
+
+ /* Number of processes. */
+ __RLIMIT_NPROC = 8,
+#define RLIMIT_NPROC __RLIMIT_NPROC
+
+ /* Locked-in-memory address space. */
+ __RLIMIT_MEMLOCK = 9,
+#define RLIMIT_MEMLOCK __RLIMIT_MEMLOCK
+
+ /* Maximum number of file locks. */
+ __RLIMIT_LOCKS = 10,
+#define RLIMIT_LOCKS __RLIMIT_LOCKS
+
+ /* Maximum number of pending signals. */
+ __RLIMIT_SIGPENDING = 11,
+#define RLIMIT_SIGPENDING __RLIMIT_SIGPENDING
+
+ /* Maximum bytes in POSIX message queues. */
+ __RLIMIT_MSGQUEUE = 12,
+#define RLIMIT_MSGQUEUE __RLIMIT_MSGQUEUE
+
+ /* Maximum nice priority allowed to raise to.
+ Nice levels 19 .. -20 correspond to 0 .. 39
+ values of this resource limit. */
+ __RLIMIT_NICE = 13,
+#define RLIMIT_NICE __RLIMIT_NICE
+
+ /* Maximum realtime priority allowed for non-priviledged
+ processes. */
+ __RLIMIT_RTPRIO = 14,
+#define RLIMIT_RTPRIO __RLIMIT_RTPRIO
+
+ __RLIMIT_NLIMITS = 15,
+ __RLIM_NLIMITS = __RLIMIT_NLIMITS
+#define RLIMIT_NLIMITS __RLIMIT_NLIMITS
+#define RLIM_NLIMITS __RLIM_NLIMITS
+};
+
+/* Value to indicate that there is no limit. */
+#ifndef __USE_FILE_OFFSET64
+# define RLIM_INFINITY ((long int)(~0UL >> 1))
+#else
+# define RLIM_INFINITY 0x7fffffffffffffffLL
+#endif
+
+#ifdef __USE_LARGEFILE64
+# define RLIM64_INFINITY 0x7fffffffffffffffLL
+#endif
+
+/* We can represent all limits. */
+#define RLIM_SAVED_MAX RLIM_INFINITY
+#define RLIM_SAVED_CUR RLIM_INFINITY
+
+
+/* Type for resource quantity measurement. */
+#ifndef __USE_FILE_OFFSET64
+typedef __rlim_t rlim_t;
+#else
+typedef __rlim64_t rlim_t;
+#endif
+#ifdef __USE_LARGEFILE64
+typedef __rlim64_t rlim64_t;
+#endif
+
+struct rlimit
+ {
+ /* The current (soft) limit. */
+ rlim_t rlim_cur;
+ /* The hard limit. */
+ rlim_t rlim_max;
+ };
+
+#ifdef __USE_LARGEFILE64
+struct rlimit64
+ {
+ /* The current (soft) limit. */
+ rlim64_t rlim_cur;
+ /* The hard limit. */
+ rlim64_t rlim_max;
+ };
+#endif
+
+/* Whose usage statistics do you want? */
+enum __rusage_who
+{
+ /* The calling process. */
+ RUSAGE_SELF = 0,
+#define RUSAGE_SELF RUSAGE_SELF
+
+ /* All of its terminated child processes. */
+ RUSAGE_CHILDREN = -1
+#define RUSAGE_CHILDREN RUSAGE_CHILDREN
+};
+
+#define __need_timeval
+#include <bits/time.h> /* For `struct timeval'. */
+
+/* Structure which says how much of each resource has been used. */
+struct rusage
+ {
+ /* Total amount of user time used. */
+ struct timeval ru_utime;
+ /* Total amount of system time used. */
+ struct timeval ru_stime;
+ /* Maximum resident set size (in kilobytes). */
+ long int ru_maxrss;
+ /* Amount of sharing of text segment memory
+ with other processes (kilobyte-seconds). */
+ long int ru_ixrss;
+ /* Amount of data segment memory used (kilobyte-seconds). */
+ long int ru_idrss;
+ /* Amount of stack memory used (kilobyte-seconds). */
+ long int ru_isrss;
+ /* Number of soft page faults (i.e. those serviced by reclaiming
+ a page from the list of pages awaiting reallocation. */
+ long int ru_minflt;
+ /* Number of hard page faults (i.e. those that required I/O). */
+ long int ru_majflt;
+ /* Number of times a process was swapped out of physical memory. */
+ long int ru_nswap;
+ /* Number of input operations via the file system. Note: This
+ and `ru_oublock' do not include operations with the cache. */
+ long int ru_inblock;
+ /* Number of output operations via the file system. */
+ long int ru_oublock;
+ /* Number of IPC messages sent. */
+ long int ru_msgsnd;
+ /* Number of IPC messages received. */
+ long int ru_msgrcv;
+ /* Number of signals delivered. */
+ long int ru_nsignals;
+ /* Number of voluntary context switches, i.e. because the process
+ gave up the process before it had to (usually to wait for some
+ resource to be available). */
+ long int ru_nvcsw;
+ /* Number of involuntary context switches, i.e. a higher priority process
+ became runnable or the current process used up its time slice. */
+ long int ru_nivcsw;
+ };
+
+/* Priority limits. */
+#define PRIO_MIN -20 /* Minimum priority a process can have. */
+#define PRIO_MAX 20 /* Maximum priority a process can have. */
+
+/* The type of the WHICH argument to `getpriority' and `setpriority',
+ indicating what flavor of entity the WHO argument specifies. */
+enum __priority_which
+{
+ PRIO_PROCESS = 0, /* WHO is a process ID. */
+#define PRIO_PROCESS PRIO_PROCESS
+ PRIO_PGRP = 1, /* WHO is a process group ID. */
+#define PRIO_PGRP PRIO_PGRP
+ PRIO_USER = 2 /* WHO is a user ID. */
+#define PRIO_USER PRIO_USER
+};
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/sem.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/sem.h
new file mode 100644
index 000000000..f63360b2b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/sem.h
@@ -0,0 +1,85 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SEM_H
+# error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
+#endif
+
+#include <sys/types.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 */
+ __time_t sem_ctime; /* last time changed by semctl() */
+ unsigned long int sem_nsems; /* number of semaphores in set */
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+};
+
+/* 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/libc/sysdeps/unix/sysv/linux/alpha/bits/shm.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/shm.h
new file mode 100644
index 000000000..35226c16c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/shm.h
@@ -0,0 +1,101 @@
+/* Copyright (C) 1995, 1996, 1997, 2000, 2002, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SHM_H
+# error "Never include <bits/shm.h> directly; use <sys/shm.h> instead."
+#endif
+
+#include <bits/types.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 */
+
+/* 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 set of semaphores. */
+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() */
+ __time_t shm_dtime; /* time of last shmdt() */
+ __time_t shm_ctime; /* time of last change by shmctl() */
+ __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 __unused1;
+ unsigned long int __unused2;
+ };
+
+#ifdef __USE_MISC
+
+/* ipcs ctl commands */
+# define SHM_STAT 13
+# define SHM_INFO 14
+
+/* shm_mode upper byte flags */
+# define SHM_DEST 01000 /* segment will be destroyed on last detach */
+# define SHM_LOCKED 02000 /* segment will not be swapped */
+# define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */
+# define SHM_NORESERVE 010000 /* don't check for reservations */
+
+struct shminfo
+ {
+ unsigned long int shmmax;
+ unsigned long int shmmin;
+ unsigned long int shmmni;
+ unsigned long int shmseg;
+ unsigned long int shmall;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+ };
+
+struct shm_info
+ {
+ int used_ids;
+ unsigned long int shm_tot; /* total allocated shm */
+ unsigned long int shm_rss; /* total resident shm */
+ unsigned long int shm_swp; /* total swapped shm */
+ unsigned long int swap_attempts;
+ unsigned long int swap_successes;
+ };
+
+#endif /* __USE_MISC */
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/sigaction.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/sigaction.h
new file mode 100644
index 000000000..80feb2fa2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/sigaction.h
@@ -0,0 +1,74 @@
+/* The proper definitions for Linux/Alpha sigaction.
+ Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIGNAL_H
+# error "Never include <bits/sigaction.h> directly; use <signal.h> instead."
+#endif
+
+/* Structure describing the action to be taken when a signal arrives. */
+struct sigaction
+ {
+ /* Signal handler. */
+#ifdef __USE_POSIX199309
+ union
+ {
+ /* Used if SA_SIGINFO is not set. */
+ __sighandler_t sa_handler;
+ /* Used if SA_SIGINFO is set. */
+ void (*sa_sigaction) (int, siginfo_t *, void *);
+ }
+ __sigaction_handler;
+# define sa_handler __sigaction_handler.sa_handler
+# define sa_sigaction __sigaction_handler.sa_sigaction
+#else
+ __sighandler_t sa_handler;
+#endif
+
+ /* Additional set of signals to be blocked. */
+ __sigset_t sa_mask;
+
+ /* Special flags. */
+ unsigned int sa_flags;
+ };
+
+/* Bits in `sa_flags'. */
+#define SA_NOCLDSTOP 0x00000004 /* Don't send SIGCHLD when children stop. */
+#define SA_NOCLDWAIT 0x00000020 /* Don't create zombie on child death. */
+#define SA_SIGINFO 0x00000040 /* Invoke signal-catching function with
+ three arguments instead of one. */
+#if defined __USE_UNIX98 || defined __USE_MISC
+# define SA_ONSTACK 0x00000001 /* Use signal stack by using `sa_restorer'. */
+# define SA_RESTART 0x00000002 /* Restart syscall on signal return. */
+# define SA_NODEFER 0x00000008 /* Don't automatically block the signal
+ when its handler is being executed. */
+# define SA_RESETHAND 0x00000010 /* Reset to SIG_DFL on entry to handler. */
+#endif
+#ifdef __USE_MISC
+# define SA_INTERRUPT 0x20000000 /* Historical no-op. */
+
+/* Some aliases for the SA_ constants. */
+# define SA_NOMASK SA_NODEFER
+# define SA_ONESHOT SA_RESETHAND
+# define SA_STACK SA_ONSTACK
+#endif
+
+/* Values for the HOW argument to `sigprocmask'. */
+#define SIG_BLOCK 1 /* Block signals. */
+#define SIG_UNBLOCK 2 /* Unblock signals. */
+#define SIG_SETMASK 3 /* Set the set of blocked signals. */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/siginfo.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/siginfo.h
new file mode 100644
index 000000000..a2aacc04b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/siginfo.h
@@ -0,0 +1,303 @@
+/* siginfo_t, sigevent and constants. Linux/Alpha version.
+ Copyright (C) 1997-2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#if !defined _SIGNAL_H && !defined __need_siginfo_t \
+ && !defined __need_sigevent_t
+# error "Never include this file directly. Use <signal.h> instead"
+#endif
+
+#if (!defined __have_sigval_t \
+ && (defined _SIGNAL_H || defined __need_siginfo_t \
+ || defined __need_sigevent_t))
+# define __have_sigval_t 1
+
+/* Type for data associated with a signal. */
+typedef union sigval
+ {
+ int sival_int;
+ void *sival_ptr;
+ } sigval_t;
+#endif
+
+#if (!defined __have_siginfo_t \
+ && (defined _SIGNAL_H || defined __need_siginfo_t))
+# define __have_siginfo_t 1
+
+# define __SI_MAX_SIZE 128
+# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 4)
+
+typedef struct siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_errno; /* If non-zero, an errno value associated with
+ this signal, as defined in <errno.h>. */
+ int si_code; /* Signal code. */
+
+ union
+ {
+ int _pad[__SI_PAD_SIZE];
+
+ /* kill(). */
+ struct
+ {
+ __pid_t si_pid; /* Sending process ID. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ } _kill;
+
+ /* POSIX.1b timers. */
+ struct
+ {
+ int si_tid; /* Timer ID. */
+ int si_overrun; /* Overrun count. */
+ sigval_t si_sigval; /* Signal value. */
+ } _timer;
+
+ /* POSIX.1b signals. */
+ struct
+ {
+ __pid_t si_pid; /* Sending process ID. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ sigval_t si_sigval; /* Signal value. */
+ } _rt;
+
+ /* SIGCHLD. */
+ struct
+ {
+ __pid_t si_pid; /* Which child. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ int si_status; /* Exit value or signal. */
+ __clock_t si_utime;
+ __clock_t si_stime;
+ } _sigchld;
+
+ /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
+ struct
+ {
+ void *si_addr; /* Faulting insn/memory ref. */
+ } _sigfault;
+
+ /* SIGPOLL. */
+ struct
+ {
+ int si_band; /* Band event for SIGPOLL. */
+ int si_fd;
+ } _sigpoll;
+ } _sifields;
+ } siginfo_t;
+
+
+/* X/Open requires some more fields with fixed names. */
+# define si_pid _sifields._kill.si_pid
+# define si_uid _sifields._kill.si_uid
+# define si_timerid _sifields._timer.si_tid
+# define si_overrun _sifields._timer.si_overrun
+# define si_status _sifields._sigchld.si_status
+# define si_utime _sifields._sigchld.si_utime
+# define si_stime _sifields._sigchld.si_stime
+# define si_value _sifields._rt.si_sigval
+# define si_int _sifields._rt.si_sigval.sival_int
+# define si_ptr _sifields._rt.si_sigval.sival_ptr
+# define si_addr _sifields._sigfault.si_addr
+# define si_band _sifields._sigpoll.si_band
+# define si_fd _sifields._sigpoll.si_fd
+
+
+/* Values for `si_code'. Positive values are reserved for kernel-generated
+ signals. */
+enum
+{
+ SI_ASYNCNL = -60, /* Sent by asynch name lookup completion. */
+# define SI_ASYNCNL SI_ASYNCNL
+ SI_TKILL = -6, /* Sent by tkill. */
+# define SI_TKILL SI_TKILL
+ SI_SIGIO, /* Sent by queued SIGIO. */
+# define SI_SIGIO SI_SIGIO
+ SI_ASYNCIO, /* Sent by AIO completion. */
+# define SI_ASYNCIO SI_ASYNCIO
+ SI_MESGQ, /* Sent by real time mesq state change. */
+# define SI_MESGQ SI_MESGQ
+ SI_TIMER, /* Sent by timer expiration. */
+# define SI_TIMER SI_TIMER
+ SI_QUEUE, /* Sent by sigqueue. */
+# define SI_QUEUE SI_QUEUE
+ SI_USER, /* Sent by kill, sigsend, raise. */
+# define SI_USER SI_USER
+ SI_KERNEL = 0x80 /* Send by kernel. */
+#define SI_KERNEL SI_KERNEL
+};
+
+
+/* `si_code' values for SIGILL signal. */
+enum
+{
+ ILL_ILLOPC = 1, /* Illegal opcode. */
+# define ILL_ILLOPC ILL_ILLOPC
+ ILL_ILLOPN, /* Illegal operand. */
+# define ILL_ILLOPN ILL_ILLOPN
+ ILL_ILLADR, /* Illegal addressing mode. */
+# define ILL_ILLADR ILL_ILLADR
+ ILL_ILLTRP, /* Illegal trap. */
+# define ILL_ILLTRP ILL_ILLTRP
+ ILL_PRVOPC, /* Privileged opcode. */
+# define ILL_PRVOPC ILL_PRVOPC
+ ILL_PRVREG, /* Privileged register. */
+# define ILL_PRVREG ILL_PRVREG
+ ILL_COPROC, /* Coprocessor error. */
+# define ILL_COPROC ILL_COPROC
+ ILL_BADSTK /* Internal stack error. */
+# define ILL_BADSTK ILL_BADSTK
+};
+
+/* `si_code' values for SIGFPE signal. */
+enum
+{
+ FPE_INTDIV = 1, /* Integer divide by zero. */
+# define FPE_INTDIV FPE_INTDIV
+ FPE_INTOVF, /* Integer overflow. */
+# define FPE_INTOVF FPE_INTOVF
+ FPE_FLTDIV, /* Floating point divide by zero. */
+# define FPE_FLTDIV FPE_FLTDIV
+ FPE_FLTOVF, /* Floating point overflow. */
+# define FPE_FLTOVF FPE_FLTOVF
+ FPE_FLTUND, /* Floating point underflow. */
+# define FPE_FLTUND FPE_FLTUND
+ FPE_FLTRES, /* Floating point inexact result. */
+# define FPE_FLTRES FPE_FLTRES
+ FPE_FLTINV, /* Floating point invalid operation. */
+# define FPE_FLTINV FPE_FLTINV
+ FPE_FLTSUB /* Subscript out of range. */
+# define FPE_FLTSUB FPE_FLTSUB
+};
+
+/* `si_code' values for SIGSEGV signal. */
+enum
+{
+ SEGV_MAPERR = 1, /* Address not mapped to object. */
+# define SEGV_MAPERR SEGV_MAPERR
+ SEGV_ACCERR /* Invalid permissions for mapped object. */
+# define SEGV_ACCERR SEGV_ACCERR
+};
+
+/* `si_code' values for SIGBUS signal. */
+enum
+{
+ BUS_ADRALN = 1, /* Invalid address alignment. */
+# define BUS_ADRALN BUS_ADRALN
+ BUS_ADRERR, /* Non-existant physical address. */
+# define BUS_ADRERR BUS_ADRERR
+ BUS_OBJERR /* Object specific hardware error. */
+# define BUS_OBJERR BUS_OBJERR
+};
+
+/* `si_code' values for SIGTRAP signal. */
+enum
+{
+ TRAP_BRKPT = 1, /* Process breakpoint. */
+# define TRAP_BRKPT TRAP_BRKPT
+ TRAP_TRACE /* Process trace trap. */
+# define TRAP_TRACE TRAP_TRACE
+};
+
+/* `si_code' values for SIGCHLD signal. */
+enum
+{
+ CLD_EXITED = 1, /* Child has exited. */
+# define CLD_EXITED CLD_EXITED
+ CLD_KILLED, /* Child was killed. */
+# define CLD_KILLED CLD_KILLED
+ CLD_DUMPED, /* Child terminated abnormally. */
+# define CLD_DUMPED CLD_DUMPED
+ CLD_TRAPPED, /* Traced child has trapped. */
+# define CLD_TRAPPED CLD_TRAPPED
+ CLD_STOPPED, /* Child has stopped. */
+# define CLD_STOPPED CLD_STOPPED
+ CLD_CONTINUED /* Stopped child has continued. */
+# define CLD_CONTINUED CLD_CONTINUED
+};
+
+/* `si_code' values for SIGPOLL signal. */
+enum
+{
+ POLL_IN = 1, /* Data input available. */
+# define POLL_IN POLL_IN
+ POLL_OUT, /* Output buffers available. */
+# define POLL_OUT POLL_OUT
+ POLL_MSG, /* Input message available. */
+# define POLL_MSG POLL_MSG
+ POLL_ERR, /* I/O error. */
+# define POLL_ERR POLL_ERR
+ POLL_PRI, /* High priority input available. */
+# define POLL_PRI POLL_PRI
+ POLL_HUP /* Device disconnected. */
+# define POLL_HUP POLL_HUP
+};
+
+# undef __need_siginfo_t
+#endif /* !have siginfo_t && (have _SIGNAL_H || need siginfo_t). */
+
+
+#if (defined _SIGNAL_H || defined __need_sigevent_t) \
+ && !defined __have_sigevent_t
+# define __have_sigevent_t 1
+
+/* Structure to transport application-defined values with signals. */
+# define __SIGEV_MAX_SIZE 64
+# define __SIGEV_PAD_SIZE ((__SIGEV_MAX_SIZE / sizeof (int)) - 4)
+
+typedef struct sigevent
+ {
+ sigval_t sigev_value;
+ int sigev_signo;
+ int sigev_notify;
+
+ union
+ {
+ int _pad[__SIGEV_PAD_SIZE];
+
+ /* When SIGEV_SIGNAL and SIGEV_THREAD_ID set, LWP ID of the
+ thread to receive the signal. */
+ __pid_t _tid;
+
+ struct
+ {
+ void (*_function) (sigval_t); /* Function to start. */
+ void *_attribute; /* Really pthread_attr_t. */
+ } _sigev_thread;
+ } _sigev_un;
+ } sigevent_t;
+
+/* POSIX names to access some of the members. */
+# define sigev_notify_function _sigev_un._sigev_thread._function
+# define sigev_notify_attributes _sigev_un._sigev_thread._attribute
+
+/* `sigev_notify' values. */
+enum
+{
+ SIGEV_SIGNAL = 0, /* Notify via signal. */
+# define SIGEV_SIGNAL SIGEV_SIGNAL
+ SIGEV_NONE, /* Other notification: meaningless. */
+# define SIGEV_NONE SIGEV_NONE
+ SIGEV_THREAD, /* Deliver via thread creation. */
+# define SIGEV_THREAD SIGEV_THREAD
+
+ SIGEV_THREAD_ID = 4 /* Send signal to specific thread. */
+#define SIGEV_THREAD_ID SIGEV_THREAD_ID
+};
+
+#endif /* have _SIGNAL_H. */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/signum.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/signum.h
new file mode 100644
index 000000000..477c13175
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/signum.h
@@ -0,0 +1,82 @@
+/* Signal number definitions. Linux/Alpha version.
+ Copyright (C) 1996, 1997, 1998, 1999, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifdef _SIGNAL_H
+
+/* Fake signal functions. */
+#define SIG_ERR ((__sighandler_t) -1) /* Error return. */
+#define SIG_DFL ((__sighandler_t) 0) /* Default action. */
+#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */
+
+#ifdef __USE_UNIX98
+# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */
+#endif
+
+/*
+ * Linux/AXP has different signal numbers that Linux/i386: I'm trying
+ * to make it OSF/1 binary compatible, at least for normal binaries.
+ */
+#define SIGHUP 1
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGILL 4
+#define SIGTRAP 5
+#define SIGABRT 6
+#define SIGEMT 7
+#define SIGFPE 8
+#define SIGKILL 9
+#define SIGBUS 10
+#define SIGSEGV 11
+#define SIGSYS 12
+#define SIGPIPE 13
+#define SIGALRM 14
+#define SIGTERM 15
+#define SIGURG 16
+#define SIGSTOP 17
+#define SIGTSTP 18
+#define SIGCONT 19
+#define SIGCHLD 20
+#define SIGCLD SIGCHLD
+#define SIGTTIN 21
+#define SIGTTOU 22
+#define SIGIO 23
+#define SIGXCPU 24
+#define SIGXFSZ 25
+#define SIGVTALRM 26
+#define SIGPROF 27
+#define SIGWINCH 28
+#define SIGINFO 29
+#define SIGUSR1 30
+#define SIGUSR2 31
+
+#define SIGPOLL SIGIO
+#define SIGPWR SIGINFO
+#define SIGIOT SIGABRT
+
+#define _NSIG 65 /* Biggest signal number + 1. */
+
+#define SIGRTMIN (__libc_current_sigrtmin ())
+#define SIGRTMAX (__libc_current_sigrtmax ())
+
+/* These are the hard limits of the kernel. These values should not be
+ used directly at user level. */
+#define __SIGRTMIN 32
+#define __SIGRTMAX (_NSIG - 1)
+
+#endif /* <signal.h> included. */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/sigstack.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/sigstack.h
new file mode 100644
index 000000000..7faaf98d5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/sigstack.h
@@ -0,0 +1,55 @@
+/* sigstack, sigaltstack definitions.
+ Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIGNAL_H
+# error "Never include this file directly. Use <signal.h> instead"
+#endif
+
+
+/* Structure describing a signal stack (obsolete). */
+struct sigstack
+ {
+ __ptr_t ss_sp; /* Signal stack pointer. */
+ int ss_onstack; /* Nonzero if executing on this stack. */
+ };
+
+
+/* Possible values for `ss_flags.'. */
+enum
+{
+ SS_ONSTACK = 1,
+#define SS_ONSTACK SS_ONSTACK
+ SS_DISABLE
+#define SS_DISABLE SS_DISABLE
+};
+
+/* Minimum stack size for a signal handler. */
+#define MINSIGSTKSZ 4096
+
+/* System default stack size. */
+#define SIGSTKSZ 16384
+
+
+/* Alternate, preferred interface. */
+typedef struct sigaltstack
+ {
+ __ptr_t ss_sp;
+ int ss_flags;
+ size_t ss_size;
+ } stack_t;
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/stat.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/stat.h
new file mode 100644
index 000000000..40b685343
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/stat.h
@@ -0,0 +1,151 @@
+/* Copyright (C) 1996,1997,1998,1999,2000,2001,2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STAT_H
+# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
+#endif
+
+/* Versions of the `struct stat' data structure. */
+#define _STAT_VER_KERNEL 0
+#define _STAT_VER_GLIBC2 1
+#define _STAT_VER_GLIBC2_1 2
+#define _STAT_VER_KERNEL64 3
+#define _STAT_VER_GLIBC2_3_4 3
+#define _STAT_VER _STAT_VER_GLIBC2_3_4
+
+/* Versions of the `xmknod' interface. */
+#define _MKNOD_VER_LINUX 0
+
+
+/* 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.
+
+ Use neat tidy anonymous unions and structures when possible. */
+
+#ifdef __USE_MISC
+# if __GNUC_PREREQ(3,3)
+# define __ST_TIME(X) \
+ __extension__ union { \
+ struct timespec st_##X##tim; \
+ struct { \
+ __time_t st_##X##time; \
+ unsigned long st_##X##timensec; \
+ }; \
+ }
+# else
+# define __ST_TIME(X) struct timespec st_##X##tim
+# define st_atime st_atim.tv_sec
+# define st_mtime st_mtim.tv_sec
+# define st_ctime st_ctim.tv_sec
+# endif
+#else
+# define __ST_TIME(X) \
+ __time_t st_##X##time; \
+ unsigned long st_##X##timensec
+#endif
+
+
+struct stat
+ {
+ __dev_t st_dev; /* Device. */
+#ifdef __USE_FILE_OFFSET64
+ __ino64_t st_ino; /* File serial number. */
+#else
+ __ino_t st_ino; /* File serial number. */
+ int __pad0; /* 64-bit st_ino. */
+#endif
+ __dev_t st_rdev; /* Device number, if device. */
+ __off_t st_size; /* Size of file, in bytes. */
+#ifdef __USE_FILE_OFFSET64
+ __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */
+#else
+ __blkcnt_t st_blocks; /* Nr. 512-byte blocks allocated. */
+ int __pad1; /* 64-bit st_blocks. */
+#endif
+ __mode_t st_mode; /* File mode. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ __nlink_t st_nlink; /* Link count. */
+ int __pad2; /* Real padding. */
+ __ST_TIME(a); /* Time of last access. */
+ __ST_TIME(m); /* Time of last modification. */
+ __ST_TIME(c); /* Time of last status change. */
+ long __unused[3];
+ };
+
+#ifdef __USE_LARGEFILE64
+/* Note stat64 is the same shape as stat. */
+struct stat64
+ {
+ __dev_t st_dev; /* Device. */
+ __ino64_t st_ino; /* File serial number. */
+ __dev_t st_rdev; /* Device number, if device. */
+ __off_t st_size; /* Size of file, in bytes. */
+ __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */
+ __mode_t st_mode; /* File mode. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ __nlink_t st_nlink; /* Link count. */
+ int __pad0; /* Real padding. */
+ __ST_TIME(a); /* Time of last access. */
+ __ST_TIME(m); /* Time of last modification. */
+ __ST_TIME(c); /* Time of last status change. */
+ long __unused[3];
+ };
+#endif
+
+#undef __ST_TIME
+
+/* Tell code we have these members. */
+#define _STATBUF_ST_BLKSIZE
+#define _STATBUF_ST_RDEV
+#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. */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/statfs.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/statfs.h
new file mode 100644
index 000000000..d838e6bf4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/statfs.h
@@ -0,0 +1,67 @@
+/* Copyright (C) 1997, 1998, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STATFS_H
+# error "Never include <bits/statfs.h> directly; use <sys/statfs.h> instead."
+#endif
+
+#include <bits/types.h> /* for __fsid_t and __fsblkcnt_t. */
+
+struct statfs
+ {
+ int f_type;
+ int f_bsize;
+#ifndef __USE_FILE_OFFSET64
+ __fsblkcnt_t f_blocks;
+ __fsblkcnt_t f_bfree;
+ __fsblkcnt_t f_bavail;
+ __fsfilcnt_t f_files;
+ __fsfilcnt_t f_ffree;
+#else
+ __fsblkcnt64_t f_blocks;
+ __fsblkcnt64_t f_bfree;
+ __fsblkcnt64_t f_bavail;
+ __fsfilcnt64_t f_files;
+ __fsfilcnt64_t f_ffree;
+#endif
+ __fsid_t f_fsid;
+ int f_namelen;
+ int f_frsize;
+ int f_spare[5];
+ };
+
+#ifdef __USE_LARGEFILE64
+struct statfs64
+ {
+ int f_type;
+ int 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;
+ int f_namelen;
+ int f_frsize;
+ int f_spare[5];
+ };
+#endif
+
+/* Tell code we have this member. */
+#define _STATFS_F_NAMELEN
+#define _STATFS_F_FRSIZE
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/termios.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/termios.h
new file mode 100644
index 000000000..966ccf94d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/termios.h
@@ -0,0 +1,226 @@
+/* termios type and macro definitions. Linux version.
+ Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2003, 2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _TERMIOS_H
+# error "Never include <bits/termios.h> directly; use <termios.h> instead."
+#endif
+
+typedef unsigned char cc_t;
+typedef unsigned int speed_t;
+typedef unsigned int tcflag_t;
+
+#define NCCS 32
+struct termios
+ {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_cc[NCCS]; /* control characters */
+ cc_t c_line; /* line discipline (== c_cc[33]) */
+ speed_t c_ispeed; /* input speed */
+ speed_t c_ospeed; /* output speed */
+#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
+#define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
+ };
+
+/* c_cc characters */
+#define VEOF 0
+#define VEOL 1
+#define VEOL2 2
+#define VERASE 3
+#define VWERASE 4
+#define VKILL 5
+#define VREPRINT 6
+#define VSWTC 7
+#define VINTR 8
+#define VQUIT 9
+#define VSUSP 10
+#define VSTART 12
+#define VSTOP 13
+#define VLNEXT 14
+#define VDISCARD 15
+#define VMIN 16
+#define VTIME 17
+
+/* c_iflag bits */
+#define IGNBRK 0000001
+#define BRKINT 0000002
+#define IGNPAR 0000004
+#define PARMRK 0000010
+#define INPCK 0000020
+#define ISTRIP 0000040
+#define INLCR 0000100
+#define IGNCR 0000200
+#define ICRNL 0000400
+#define IXON 0001000
+#define IXOFF 0002000
+#ifdef __USE_BSD
+ /* POSIX.1 doesn't want these... */
+# define IXANY 0004000
+# define IUCLC 0010000
+# define IMAXBEL 0020000
+# define IUTF8 0040000
+#endif
+
+/* c_oflag bits */
+#define OPOST 0000001
+#define ONLCR 0000002
+#define OLCUC 0000004
+
+#define OCRNL 0000010
+#define ONOCR 0000020
+#define ONLRET 0000040
+
+#define OFILL 00000100
+#define OFDEL 00000200
+#if defined __USE_MISC || defined __USE_XOPEN
+# define NLDLY 00001400
+# define NL0 00000000
+# define NL1 00000400
+# define NL2 00001000
+# define NL3 00001400
+# define TABDLY 00006000
+# define TAB0 00000000
+# define TAB1 00002000
+# define TAB2 00004000
+# define TAB3 00006000
+# define CRDLY 00030000
+# define CR0 00000000
+# define CR1 00010000
+# define CR2 00020000
+# define CR3 00030000
+# define FFDLY 00040000
+# define FF0 00000000
+# define FF1 00040000
+# define BSDLY 00100000
+# define BS0 00000000
+# define BS1 00100000
+#endif
+
+#define VTDLY 00200000
+#define VT0 00000000
+#define VT1 00200000
+
+#ifdef __USE_MISC
+# define XTABS 01000000 /* Hmm.. Linux/i386 considers this part of TABDLY.. */
+#endif
+
+/* c_cflag bit meaning */
+#ifdef __USE_MISC
+# define CBAUD 0000037
+#endif
+#define B0 0000000 /* hang up */
+#define B50 0000001
+#define B75 0000002
+#define B110 0000003
+#define B134 0000004
+#define B150 0000005
+#define B200 0000006
+#define B300 0000007
+#define B600 0000010
+#define B1200 0000011
+#define B1800 0000012
+#define B2400 0000013
+#define B4800 0000014
+#define B9600 0000015
+#define B19200 0000016
+#define B38400 0000017
+#ifdef __USE_MISC
+# define EXTA B19200
+# define EXTB B38400
+# define CBAUDEX 0000000
+#endif
+#define B57600 00020
+#define B115200 00021
+#define B230400 00022
+#define B460800 00023
+#define B500000 00024
+#define B576000 00025
+#define B921600 00026
+#define B1000000 00027
+#define B1152000 00030
+#define B1500000 00031
+#define B2000000 00032
+#define B2500000 00033
+#define B3000000 00034
+#define B3500000 00035
+#define B4000000 00036
+
+#define __MAX_BAUD B4000000
+
+#define CSIZE 00001400
+#define CS5 00000000
+#define CS6 00000400
+#define CS7 00001000
+#define CS8 00001400
+
+#define CSTOPB 00002000
+#define CREAD 00004000
+#define PARENB 00010000
+#define PARODD 00020000
+#define HUPCL 00040000
+
+#define CLOCAL 00100000
+#ifdef __USE_MISC
+# define CMSPAR 010000000000 /* mark or space (stick) parity */
+# define CRTSCTS 020000000000 /* flow control */
+#endif
+
+/* c_lflag bits */
+#define ISIG 0x00000080
+#define ICANON 0x00000100
+#if defined __USE_MISC || defined __USE_XOPEN
+# define XCASE 0x00004000
+#endif
+#define ECHO 0x00000008
+#define ECHOE 0x00000002
+#define ECHOK 0x00000004
+#define ECHONL 0x00000010
+#define NOFLSH 0x80000000
+#define TOSTOP 0x00400000
+#ifdef __USE_MISC
+# define ECHOCTL 0x00000040
+# define ECHOPRT 0x00000020
+# define ECHOKE 0x00000001
+# define FLUSHO 0x00800000
+# define PENDIN 0x20000000
+#endif
+#define IEXTEN 0x00000400
+
+/* Values for the ACTION argument to `tcflow'. */
+#define TCOOFF 0
+#define TCOON 1
+#define TCIOFF 2
+#define TCION 3
+
+/* Values for the QUEUE_SELECTOR argument to `tcflush'. */
+#define TCIFLUSH 0
+#define TCOFLUSH 1
+#define TCIOFLUSH 2
+
+/* Values for the OPTIONAL_ACTIONS argument to `tcsetattr'. */
+#define TCSANOW 0
+#define TCSADRAIN 1
+#define TCSAFLUSH 2
+
+
+#define _IOT_termios /* Hurd ioctl type field. */ \
+ _IOT (_IOTS (cflag_t), 4, _IOTS (cc_t), NCCS, _IOTS (speed_t), 2)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
new file mode 100644
index 000000000..201585af1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
@@ -0,0 +1,66 @@
+/* bits/typesizes.h -- underlying types for *_t. Linux/Alpha version.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _BITS_TYPES_H
+# error "Never include <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 __U64_TYPE
+#define __UID_T_TYPE __U32_TYPE
+#define __GID_T_TYPE __U32_TYPE
+#define __INO_T_TYPE __U32_TYPE
+#define __INO64_T_TYPE __U64_TYPE
+#define __MODE_T_TYPE __U32_TYPE
+#define __NLINK_T_TYPE __U32_TYPE
+#define __OFF_T_TYPE __SLONGWORD_TYPE
+#define __OFF64_T_TYPE __S64_TYPE
+#define __PID_T_TYPE __S32_TYPE
+#define __RLIM_T_TYPE __ULONGWORD_TYPE
+#define __RLIM64_T_TYPE __U64_TYPE
+#define __BLKCNT_T_TYPE __U32_TYPE
+#define __BLKCNT64_T_TYPE __U64_TYPE
+#define __FSBLKCNT_T_TYPE __S32_TYPE
+#define __FSBLKCNT64_T_TYPE __S64_TYPE
+#define __FSFILCNT_T_TYPE __U32_TYPE
+#define __FSFILCNT64_T_TYPE __U64_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 __S64_TYPE
+#define __DADDR_T_TYPE __S32_TYPE
+#define __SWBLK_T_TYPE __SLONGWORD_TYPE
+#define __KEY_T_TYPE __S32_TYPE
+#define __CLOCKID_T_TYPE __S32_TYPE
+#define __TIMER_T_TYPE void *
+#define __BLKSIZE_T_TYPE __U32_TYPE
+#define __FSID_T_TYPE struct { int __val[2]; }
+#define __SSIZE_T_TYPE __SWORD_TYPE
+
+/* Number of descriptors that can fit in an `fd_set'. */
+#define __FD_SETSIZE 1024
+
+
+#endif /* bits/typesizes.h */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h b/libc/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
new file mode 100644
index 000000000..22fc64109
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
@@ -0,0 +1,30 @@
+/* Copyright (C) 1999, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define __WORDSIZE 64
+
+#if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
+
+/* Signal that we didn't used to have a `long double'. The changes all
+ the `long double' function variants to be redirects to the double
+ functions. */
+# define __LONG_DOUBLE_MATH_OPTIONAL 1
+# ifndef __LONG_DOUBLE_128__
+# define __NO_LONG_DOUBLE_MATH 1
+# endif
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/brk.S b/libc/sysdeps/unix/sysv/linux/alpha/brk.S
new file mode 100644
index 000000000..e01abebe0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/brk.S
@@ -0,0 +1,81 @@
+/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Brendan Kehoe <brendan@zen.org>, 1993.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* __brk is a special syscall under Linux since it never returns an
+ error. Instead, the error condition is indicated by returning the old
+ break value (instead of the new, requested one). */
+
+#include <sysdep.h>
+#define _ERRNO_H
+#include <bits/errno.h>
+
+#ifdef PIC
+.section .bss
+ .align 3
+ .globl __curbrk
+__curbrk: .skip 8
+ .type __curbrk,@object
+ .size __curbrk,8
+#else
+.comm __curbrk, 8
+#endif
+
+ .text
+LEAF(__brk, 8)
+ ldgp gp, 0(t12)
+ subq sp, 8, sp
+#ifdef PROF
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+#endif
+ .prologue 1
+
+ /* Save the requested brk across the system call. */
+ stq a0, 0(sp)
+
+ ldiq v0, __NR_brk
+ call_pal PAL_callsys
+
+ ldq a0, 0(sp)
+
+ /* Be prepared for an OSF-style brk. */
+ bne a3, $err1
+ beq v0, $ok
+
+ /* Correctly handle the brk(0) query case. */
+ cmoveq a0, v0, a0
+ xor a0, v0, t0
+ bne t0, $err0
+
+ /* Update __curbrk and return cleanly. */
+ mov zero, v0
+$ok: stq a0, __curbrk
+ addq sp, 8, sp
+ ret
+
+ /* What a horrible way to die. */
+$err0: ldi v0, ENOMEM
+$err1: addq sp, 8, sp
+ SYSCALL_ERROR_HANDLER
+
+ END(__brk)
+
+weak_alias (__brk, brk)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/clone.S b/libc/sysdeps/unix/sysv/linux/alpha/clone.S
new file mode 100644
index 000000000..5e0b21ea1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/clone.S
@@ -0,0 +1,149 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson <rth@tamu.edu>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* clone() is even more special than fork() as it mucks with stacks
+ and invokes a function in the right context after its all over. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+#define CLONE_VM 0x00000100
+#define CLONE_THREAD 0x00010000
+
+/* int clone(int (*fn)(void *arg), void *child_stack, int flags,
+ void *arg, pid_t *ptid, void *tls, pid_t *ctid);
+
+ Note that everything past ARG is technically optional, based
+ on FLAGS, and that CTID is arg 7, and thus is on the stack.
+ However, since a load from top-of-stack better be legal always,
+ we don't bother checking FLAGS. */
+
+ .text
+ENTRY(__clone)
+#ifdef PROF
+ ldgp gp,0(pv)
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+ .prologue 1
+#else
+ .prologue 0
+#endif
+
+ /* Sanity check arguments. */
+ ldiq v0,EINVAL
+ beq a0,$error /* no NULL function pointers */
+ beq a1,$error /* no NULL stack pointers */
+
+ /* Save the fn ptr and arg on the new stack. */
+ subq a1,32,a1
+ stq a0,0(a1)
+ stq a3,8(a1)
+#ifdef RESET_PID
+ stq a2,16(a1)
+#endif
+
+ /* The syscall is of the form clone(flags, usp, ptid, ctid, tls).
+ Shift the flags, ptid, ctid, tls arguments into place; the
+ child_stack argument is already correct. */
+ mov a2,a0
+ mov a4,a2
+ ldq a3,0(sp)
+ mov a5,a4
+
+ /* Do the system call. */
+ ldiq v0,__NR_clone
+ call_pal PAL_callsys
+
+ bne a3,$error
+ beq v0,thread_start
+
+ /* Successful return from the parent. */
+ ret
+
+ /* Something bad happened -- no child created. */
+$error:
+#ifndef PROF
+ br gp,1f
+1: ldgp gp,0(gp)
+#endif
+ SYSCALL_ERROR_HANDLER
+
+ END(__clone)
+
+/* Load up the arguments to the function. Put this block of code in
+ its own function so that we can terminate the stack trace with our
+ debug info. */
+
+ .ent thread_start
+thread_start:
+ .frame fp,0,fp,0
+ mov 0, fp
+ .prologue 0
+
+#ifdef RESET_PID
+ /* Check and see if we need to reset the PID. */
+ ldq t0,16(sp)
+ lda t1,CLONE_THREAD
+ and t0,t1,t2
+ beq t2,2f
+1:
+#endif
+
+ /* Load up the arguments. */
+ ldq pv,0(sp)
+ ldq a0,8(sp)
+ addq sp,32,sp
+
+ /* Call the user's function. */
+ jsr ra,(pv)
+ ldgp gp,0(ra)
+
+ /* Call _exit rather than doing it inline for breakpoint purposes. */
+ mov v0,a0
+#ifdef PIC
+ bsr ra, HIDDEN_JUMPTARGET(_exit) !samegp
+#else
+ jsr ra, HIDDEN_JUMPTARGET(_exit)
+#endif
+
+ /* Die horribly. */
+ halt
+
+#ifdef RESET_PID
+2:
+ rduniq
+ lda t1, CLONE_VM
+ mov v0, s0
+ lda v0, -1
+ and t0, t1, t2
+ bne t2, 3f
+ lda v0, __NR_getxpid
+ callsys
+3:
+ stl v0, PID_OFFSET(s0)
+ stl v0, TID_OFFSET(s0)
+ br 1b
+#endif
+
+ .end thread_start
+
+weak_alias (__clone, clone)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/dl-brk.S b/libc/sysdeps/unix/sysv/linux/alpha/dl-brk.S
new file mode 100644
index 000000000..eeb96544e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/dl-brk.S
@@ -0,0 +1 @@
+#include <brk.S>
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/dl-sysdep.c b/libc/sysdeps/unix/sysv/linux/alpha/dl-sysdep.c
new file mode 100644
index 000000000..d95e46f6f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/dl-sysdep.c
@@ -0,0 +1,59 @@
+/* Operating system support for run-time dynamic linker. Linux/Alpha version.
+ Copyright (C) 1997, 1998, 2001, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <config.h>
+#include <kernel-features.h>
+#include <ldsodefs.h>
+
+extern long __libc_alpha_cache_shape[4];
+weak_extern (__libc_alpha_cache_shape);
+
+
+/* Scan the Aux Vector for the cache shape entries. */
+#define DL_PLATFORM_AUXV \
+ case AT_L1I_CACHESHAPE: \
+ { \
+ long *cls = __libc_alpha_cache_shape; \
+ if (cls != NULL) \
+ cls[0] = av->a_un.a_val; \
+ break; \
+ } \
+ case AT_L1D_CACHESHAPE: \
+ { \
+ long *cls = __libc_alpha_cache_shape; \
+ if (cls != NULL) \
+ cls[1] = av->a_un.a_val; \
+ break; \
+ } \
+ case AT_L2_CACHESHAPE: \
+ { \
+ long *cls = __libc_alpha_cache_shape; \
+ if (cls != NULL) \
+ cls[2] = av->a_un.a_val; \
+ break; \
+ } \
+ case AT_L3_CACHESHAPE: \
+ { \
+ long *cls = __libc_alpha_cache_shape; \
+ if (cls != NULL) \
+ cls[3] = av->a_un.a_val; \
+ break; \
+ }
+
+#include <sysdeps/unix/sysv/linux/dl-sysdep.c>
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/fraiseexcpt.c b/libc/sysdeps/unix/sysv/linux/alpha/fraiseexcpt.c
new file mode 100644
index 000000000..5e63be5cc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/fraiseexcpt.c
@@ -0,0 +1,92 @@
+/* Copyright (C) 2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <fenv_libc.h>
+#include <sysdep.h>
+#include <float.h>
+#include <kernel-features.h>
+#include "kernel_sysinfo.h"
+
+
+int
+__feraiseexcept (int excepts)
+{
+ INTERNAL_SYSCALL_DECL (err);
+ unsigned long t = excepts;
+ long r;
+
+ r = INTERNAL_SYSCALL (osf_setsysinfo, err, 2, SSI_IEEE_RAISE_EXCEPTION, &t);
+
+#ifndef __ASSUME_IEEE_RAISE_EXCEPTION
+ if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+ return 0;
+
+ double d;
+
+ /* If we got an error from SSI_IEEE_RAISE_EXCEPTION, assume it means that
+ the system call isn't actually implemented. Do the best we can. */
+
+ /* Invalid implemented with 0 / 0 -> NaN. */
+ if (excepts & FE_INVALID)
+ __asm__ __volatile__ ("divs/su $f31,$f31,%0; trapb" : "=f"(d) : );
+
+ /* Division By Zero implemented with 1 / 0 -> NaN. */
+ if (excepts & FE_DIVBYZERO)
+ __asm__ __volatile__ ("divs/su %1,$f31,%0; trapb" : "=&f"(d) : "f"(1.0f));
+
+ /* Overflow and underflow cannot be had all by themselves. We can
+ generate them with arithmetic, but we always get INEXACT raised
+ at the same time. Prepare to undo. */
+ if ((excepts & (FE_OVERFLOW | FE_UNDERFLOW)) && !(excepts & FE_INEXACT))
+ INTERNAL_SYSCALL (osf_getsysinfo, err, 2, GSI_IEEE_FP_CONTROL, &t);
+
+ /* Overflow implemented with FLT_MAX + FLT_MAX -> Inf. */
+ if (excepts & FE_OVERFLOW)
+ __asm__ __volatile__ ("adds/sui %1,%1,%0; trapb"
+ : "=&f"(d) : "f"(FLT_MAX));
+
+ /* Underflow implemented with FLT_MIN * FLT_MIN -> 0. */
+ if (excepts & FE_UNDERFLOW)
+ __asm__ __volatile__ ("muls/sui %1,%1,%0; trapb"
+ : "=&f"(d) : "f"(FLT_MIN));
+
+ /* Inexact implemented with (long)0.5 -> 0. */
+ if ((excepts & (FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)) == FE_INEXACT)
+ __asm__ __volatile__ ("cvttq/svi %1,%0; trapb" : "=&f"(d) : "f"(0.5f));
+
+ /* If we raised inexact when not asked, and inexact was not previously
+ raised, then clear that exception. */
+ if ((excepts & (FE_OVERFLOW | FE_UNDERFLOW))
+ && !((excepts | t) & FE_INEXACT))
+ {
+ t |= excepts & SWCR_STATUS_MASK;
+ INTERNAL_SYSCALL (osf_setsysinfo, err, 2, SSI_IEEE_FP_CONTROL, &t);
+ }
+#endif /* !__ASSUME_IEEE_RAISE_EXCEPTION */
+
+ return 0;
+}
+
+#include <shlib-compat.h>
+#if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
+strong_alias (__feraiseexcept, __old_feraiseexcept)
+compat_symbol (libm, __old_feraiseexcept, feraiseexcept, GLIBC_2_1);
+#endif
+
+libm_hidden_ver (__feraiseexcept, feraiseexcept)
+versioned_symbol (libm, __feraiseexcept, feraiseexcept, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/fxstat.c b/libc/sysdeps/unix/sysv/linux/alpha/fxstat.c
new file mode 100644
index 000000000..40e08fd86
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/fxstat.c
@@ -0,0 +1,64 @@
+/* fxstat using old-style Unix stat system call.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define __fxstat64 __fxstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <xstatconv.h>
+
+#undef __fxstat64
+
+
+/* Get information about the file NAME in BUF. */
+int
+__fxstat (int vers, int fd, struct stat *buf)
+{
+ INTERNAL_SYSCALL_DECL (err);
+ int result, errno_out;
+ struct kernel_stat kbuf;
+
+ if (vers == _STAT_VER_KERNEL64 && !__libc_missing_axp_stat64)
+ {
+ result = INTERNAL_SYSCALL (fstat64, err, 2, fd, buf);
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return result;
+ errno_out = INTERNAL_SYSCALL_ERRNO (result, err);
+ if (errno_out != ENOSYS)
+ goto fail;
+ __libc_missing_axp_stat64 = 1;
+ }
+
+ result = INTERNAL_SYSCALL (fstat, err, 2, fd, &kbuf);
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return __xstat_conv (vers, &kbuf, buf);
+ errno_out = INTERNAL_SYSCALL_ERRNO (result, err);
+
+ fail:
+ __set_errno (errno_out);
+ return -1;
+}
+hidden_def (__fxstat)
+weak_alias (__fxstat, _fxstat);
+strong_alias (__fxstat, __fxstat64);
+hidden_ver (__fxstat, __fxstat64)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/fxstatat.c b/libc/sysdeps/unix/sysv/linux/alpha/fxstatat.c
new file mode 100644
index 000000000..497694619
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/fxstatat.c
@@ -0,0 +1,99 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define __fxstatat64 __fxstatat64_disable
+
+#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 <xstatconv.h>
+
+#undef __fxstatat64
+
+
+/* Get information about the file NAME in BUF. */
+int
+__fxstatat (int vers, int fd, const char *file, struct stat *st, int flag)
+{
+ if (flag & ~AT_SYMLINK_NOFOLLOW)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+ int result, errno_out;
+ struct kernel_stat kst;
+
+ if (vers == _STAT_VER_KERNEL64 && !__libc_missing_axp_stat64)
+ {
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lstat64, err, 2, file, st);
+ else
+ result = INTERNAL_SYSCALL (stat64, err, 2, file, st);
+
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return result;
+ errno_out = INTERNAL_SYSCALL_ERRNO (result, err);
+ if (errno_out != ENOSYS)
+ goto fail;
+ __libc_missing_axp_stat64 = 1;
+ }
+
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lstat, err, 2, file, &kst);
+ else
+ result = INTERNAL_SYSCALL (stat, err, 2, file, &kst);
+
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return __xstat_conv (vers, &kst, st);
+ errno_out = INTERNAL_SYSCALL_ERRNO (result, err);
+
+ fail:
+ __atfct_seterrno (errno_out, fd, buf);
+
+ return -1;
+}
+libc_hidden_def (__fxstatat)
+strong_alias (__fxstatat, __fxstatat64);
+libc_hidden_ver(__fxstatat, __fxstatat64);
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/getclktck.c b/libc/sysdeps/unix/sysv/linux/alpha/getclktck.c
new file mode 100644
index 000000000..6636bbe68
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/getclktck.c
@@ -0,0 +1,2 @@
+#define SYSTEM_CLK_TCK 1024
+#include <sysdeps/unix/sysv/linux/getclktck.c>
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/getcontext.S b/libc/sysdeps/unix/sysv/linux/alpha/getcontext.S
new file mode 100644
index 000000000..f010f337e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/getcontext.S
@@ -0,0 +1,188 @@
+/* Save current context.
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <ucontext-offsets.h>
+
+/* ??? Should be a better place for this that's asm friendly. */
+#define SIG_BLOCK 1
+
+
+ENTRY (__getcontext)
+#ifdef PROF
+ ldgp gp, 0(pv)
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+ .prologue 1
+#else
+ .prologue 0
+#endif
+
+ bsr $0, __getcontext_x
+ mov $31, $0
+ ret
+
+END(__getcontext)
+weak_alias (__getcontext, getcontext)
+
+
+/* An internal routine used by getcontext and setcontext.
+ The incomming return address register is $0. */
+
+ .align 4
+ .globl __getcontext_x
+ .hidden __getcontext_x
+ .usepv __getcontext_x, no
+
+ cfi_startproc
+ cfi_return_column (64)
+__getcontext_x:
+ cfi_register (64, 0)
+
+ .set noat
+
+ /* Return value of getcontext. $0 is the only register
+ whose value is not preserved. */
+ stq $31, UC_SIGCTX+SC_REGS($16)
+
+ /* Store all registers into the context. */
+ stq $1, UC_SIGCTX+SC_REGS+1*8($16)
+ stq $2, UC_SIGCTX+SC_REGS+2*8($16)
+ stq $3, UC_SIGCTX+SC_REGS+3*8($16)
+ stq $4, UC_SIGCTX+SC_REGS+4*8($16)
+ stq $5, UC_SIGCTX+SC_REGS+5*8($16)
+ stq $6, UC_SIGCTX+SC_REGS+6*8($16)
+ stq $7, UC_SIGCTX+SC_REGS+7*8($16)
+ stq $8, UC_SIGCTX+SC_REGS+8*8($16)
+ stq $9, UC_SIGCTX+SC_REGS+9*8($16)
+ stq $10, UC_SIGCTX+SC_REGS+10*8($16)
+ stq $11, UC_SIGCTX+SC_REGS+11*8($16)
+ stq $12, UC_SIGCTX+SC_REGS+12*8($16)
+ stq $13, UC_SIGCTX+SC_REGS+13*8($16)
+ stq $14, UC_SIGCTX+SC_REGS+14*8($16)
+ stq $15, UC_SIGCTX+SC_REGS+15*8($16)
+ stq $16, UC_SIGCTX+SC_REGS+16*8($16)
+ stq $17, UC_SIGCTX+SC_REGS+17*8($16)
+ stq $18, UC_SIGCTX+SC_REGS+18*8($16)
+ stq $19, UC_SIGCTX+SC_REGS+19*8($16)
+ stq $20, UC_SIGCTX+SC_REGS+20*8($16)
+ stq $21, UC_SIGCTX+SC_REGS+21*8($16)
+ stq $22, UC_SIGCTX+SC_REGS+22*8($16)
+ stq $23, UC_SIGCTX+SC_REGS+23*8($16)
+ stq $24, UC_SIGCTX+SC_REGS+24*8($16)
+ stq $25, UC_SIGCTX+SC_REGS+25*8($16)
+ stq $26, UC_SIGCTX+SC_REGS+26*8($16)
+ stq $27, UC_SIGCTX+SC_REGS+27*8($16)
+ stq $28, UC_SIGCTX+SC_REGS+28*8($16)
+ stq $29, UC_SIGCTX+SC_REGS+29*8($16)
+ stq $30, UC_SIGCTX+SC_REGS+30*8($16)
+ stq $31, UC_SIGCTX+SC_REGS+31*8($16)
+
+ stt $f0, UC_SIGCTX+SC_FPREGS+0*8($16)
+ stt $f1, UC_SIGCTX+SC_FPREGS+1*8($16)
+ stt $f2, UC_SIGCTX+SC_FPREGS+2*8($16)
+ stt $f3, UC_SIGCTX+SC_FPREGS+3*8($16)
+ stt $f4, UC_SIGCTX+SC_FPREGS+4*8($16)
+ stt $f5, UC_SIGCTX+SC_FPREGS+5*8($16)
+ stt $f6, UC_SIGCTX+SC_FPREGS+6*8($16)
+ stt $f7, UC_SIGCTX+SC_FPREGS+7*8($16)
+ stt $f8, UC_SIGCTX+SC_FPREGS+8*8($16)
+ stt $f9, UC_SIGCTX+SC_FPREGS+9*8($16)
+ stt $f10, UC_SIGCTX+SC_FPREGS+10*8($16)
+ stt $f11, UC_SIGCTX+SC_FPREGS+11*8($16)
+ stt $f12, UC_SIGCTX+SC_FPREGS+12*8($16)
+ stt $f13, UC_SIGCTX+SC_FPREGS+13*8($16)
+ stt $f14, UC_SIGCTX+SC_FPREGS+14*8($16)
+ stt $f15, UC_SIGCTX+SC_FPREGS+15*8($16)
+ stt $f16, UC_SIGCTX+SC_FPREGS+16*8($16)
+ stt $f17, UC_SIGCTX+SC_FPREGS+17*8($16)
+ stt $f18, UC_SIGCTX+SC_FPREGS+18*8($16)
+ stt $f19, UC_SIGCTX+SC_FPREGS+19*8($16)
+ stt $f20, UC_SIGCTX+SC_FPREGS+20*8($16)
+ stt $f21, UC_SIGCTX+SC_FPREGS+21*8($16)
+ stt $f22, UC_SIGCTX+SC_FPREGS+22*8($16)
+ stt $f23, UC_SIGCTX+SC_FPREGS+23*8($16)
+ stt $f24, UC_SIGCTX+SC_FPREGS+24*8($16)
+ stt $f25, UC_SIGCTX+SC_FPREGS+25*8($16)
+ stt $f26, UC_SIGCTX+SC_FPREGS+26*8($16)
+ stt $f27, UC_SIGCTX+SC_FPREGS+27*8($16)
+ stt $f28, UC_SIGCTX+SC_FPREGS+28*8($16)
+ stt $f29, UC_SIGCTX+SC_FPREGS+29*8($16)
+ stt $f30, UC_SIGCTX+SC_FPREGS+30*8($16)
+ stt $f31, UC_SIGCTX+SC_FPREGS+31*8($16)
+
+ mf_fpcr $f0
+ lda $1, 8
+ stt $f0, UC_SIGCTX+SC_FPCR($16)
+
+ /* The return address of getcontext is the restart pc. */
+ stq $26, UC_SIGCTX+SC_PC($16)
+
+ /* Userlevel always has a processor status word of 8. */
+ stq $1, UC_SIGCTX+SC_PS($16)
+
+ /* Save registers around the syscall. We preserve $17
+ for the benefit of swapcontext. */
+ subq $30, 4*8, $30
+ cfi_adjust_cfa_offset(4*8)
+ stq $0, 0($30)
+ cfi_rel_offset(64, 0)
+ stq $16, 8($30)
+ stq $17, 16($30)
+
+ /* Save the current signal mask. Whee, there are three
+ copies of this in the alpha ucontext_t. */
+ lda $16, SIG_BLOCK
+ lda $17, 0
+ lda $0, __NR_osf_sigprocmask
+ callsys
+
+ ldq $16, 8($30)
+ ldq $17, 16($30)
+
+ stq $0, UC_OSF_SIGMASK($16)
+ stq $0, UC_SIGCTX+SC_MASK($16)
+ stq $0, UC_SIGMASK($16)
+ stq $31, UC_SIGMASK + 1*8($16)
+ stq $31, UC_SIGMASK + 2*8($16)
+ stq $31, UC_SIGMASK + 3*8($16)
+ stq $31, UC_SIGMASK + 4*8($16)
+ stq $31, UC_SIGMASK + 5*8($16)
+ stq $31, UC_SIGMASK + 6*8($16)
+ stq $31, UC_SIGMASK + 7*8($16)
+ stq $31, UC_SIGMASK + 8*8($16)
+ stq $31, UC_SIGMASK + 9*8($16)
+ stq $31, UC_SIGMASK +10*8($16)
+ stq $31, UC_SIGMASK +11*8($16)
+ stq $31, UC_SIGMASK +12*8($16)
+ stq $31, UC_SIGMASK +13*8($16)
+ stq $31, UC_SIGMASK +14*8($16)
+ stq $31, UC_SIGMASK +15*8($16)
+
+ ldq $0, 0($30)
+ addq $30, 4*8, $30
+ cfi_register (64, 0)
+ cfi_adjust_cfa_offset(-4*8)
+ ret $31, ($0), 1
+
+ cfi_endproc
+ .size __getcontext_x, .-__getcontext_x
+ .type __getcontext_x, @function
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/getdents.c b/libc/sysdeps/unix/sysv/linux/alpha/getdents.c
new file mode 100644
index 000000000..dfecfef92
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/getdents.c
@@ -0,0 +1,3 @@
+#define DIRENT_SET_DP_INO(dp, value) \
+ do { (dp)->d_ino = (value); (dp)->__pad = 0; } while (0)
+#include <sysdeps/unix/sysv/linux/getdents.c>
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/getdents64.c b/libc/sysdeps/unix/sysv/linux/alpha/getdents64.c
new file mode 100644
index 000000000..e53570c03
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/getdents64.c
@@ -0,0 +1 @@
+#include "../getdents64.c"
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/gethostname.c b/libc/sysdeps/unix/sysv/linux/alpha/gethostname.c
new file mode 100644
index 000000000..4e15ee43e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/gethostname.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+int
+__gethostname (char *name, size_t len)
+{
+ int result;
+
+ result = INLINE_SYSCALL (gethostname, 2, CHECK_N (name, len), len);
+
+ if (result == 0
+ /* See whether the string is terminated. If not we will return
+ an error. */
+ && memchr (name, '\0', len) == NULL)
+ {
+ __set_errno (EOVERFLOW);
+ result = -1;
+ }
+
+ return result;
+}
+
+weak_alias (__gethostname, gethostname)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/getitimer.S b/libc/sysdeps/unix/sysv/linux/alpha/getitimer.S
new file mode 100644
index 000000000..6644a5c36
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/getitimer.S
@@ -0,0 +1,113 @@
+/* Copyright (C) 1998, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+
+.text
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+#define GETITIMER __getitimer_tv64
+#else
+#define GETITIMER getitimer
+#endif
+
+#if defined __ASSUME_TIMEVAL64
+PSEUDO(GETITIMER, getitimer, 2)
+ ret
+PSEUDO_END(GETITIMER)
+#else
+/* The problem here is that initially we made struct timeval compatible with
+ OSF/1, using int32. But we defined time_t with uint64, and later found
+ that POSIX requires tv_sec to be time_t.
+
+ So now we have to do compatibility stuff. */
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. */
+.comm __libc_missing_axp_tv64, 4
+
+LEAF(GETITIMER, 16)
+ ldgp gp, 0(pv)
+ subq sp, 16, sp
+#ifdef PROF
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+#endif
+ .prologue 1
+
+ ldl t0, __libc_missing_axp_tv64
+
+ /* Save arguments in case we do need to fall back. */
+ stq a0, 0(sp)
+ stq a1, 8(sp)
+
+ bne t0, $do32
+
+ ldi v0, SYS_ify(getitimer)
+ callsys
+ bne a3, $err64
+
+ /* Everything ok. */
+ addq sp, 16, sp
+ ret
+
+ /* If we didn't get ENOSYS, it is a real error. */
+ .align 3
+$err64: cmpeq v0, ENOSYS, t0
+ beq t0, $error
+ stl t0, __libc_missing_axp_tv64
+
+ /* Recover the saved arguments. */
+ ldq a1, 8(sp)
+ ldq a0, 0(sp)
+
+ .align 3
+$do32: ldi v0, SYS_ify(osf_getitimer)
+ callsys
+ bne a3, $error
+
+ /* Copy back to proper format. */
+ ldq a1, 8(sp)
+ ldl t0, 0(a1)
+ ldl t1, 4(a1)
+ ldl t2, 8(a1)
+ ldl t3, 12(a1)
+ stq t0, 0(a1)
+ stq t1, 8(a1)
+ stq t2, 16(a1)
+ stq t3, 24(a1)
+
+ addq sp, 16, sp
+ ret
+
+ .align 3
+$error:
+ addq sp, 16, sp
+ SYSCALL_ERROR_HANDLER
+
+END(GETITIMER)
+#endif /* __ASSUME_TIMEVAL64 */
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+default_symbol_version (__getitimer_tv64, getitimer, GLIBC_2.1)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/getrusage.S b/libc/sysdeps/unix/sysv/linux/alpha/getrusage.S
new file mode 100644
index 000000000..0bca4b5f2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/getrusage.S
@@ -0,0 +1,149 @@
+/* Copyright (C) 1998, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+
+.text
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+#define GETRUSAGE __getrusage_tv64
+#else
+#define GETRUSAGE __getrusage
+#endif
+
+#if defined __ASSUME_TIMEVAL64
+PSEUDO(GETRUSAGE, getrusage, 2)
+ ret
+PSEUDO_END(GETRUSAGE)
+#else
+/* The problem here is that initially we made struct timeval compatible with
+ OSF/1, using int32. But we defined time_t with uint64, and later found
+ that POSIX requires tv_sec to be time_t.
+
+ So now we have to do compatibility stuff. */
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. */
+.comm __libc_missing_axp_tv64, 4
+
+LEAF(GETRUSAGE, 16)
+ ldgp gp, 0(pv)
+ subq sp, 16, sp
+#ifdef PROF
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+#endif
+ .prologue 1
+
+ ldl t0, __libc_missing_axp_tv64
+
+ /* Save arguments in case we do need to fall back. */
+ stq a0, 0(sp)
+ stq a1, 8(sp)
+
+ bne t0, $do32
+
+ ldi v0, SYS_ify(getrusage)
+ callsys
+ bne a3, $err64
+
+ /* Everything ok. */
+ addq sp, 16, sp
+ ret
+
+ /* If we didn't get ENOSYS, it is a real error. */
+ .align 3
+$err64: cmpeq v0, ENOSYS, t0
+ beq t0, $error
+ stl t0, __libc_missing_axp_tv64
+
+ /* Recover the saved arguments. */
+ ldq a1, 8(sp)
+ ldq a0, 0(sp)
+
+ .align 3
+$do32: ldi v0, SYS_ify(osf_getrusage)
+ callsys
+ bne a3, $error
+
+ /* Copy back to proper format. */
+ ldq a1, 8(sp)
+ ldl t0, 0(a1) # ru_utime.tv_sec
+ ldl t1, 4(a1) # ru_utime.tv_usec
+ ldl t2, 8(a1) # ru_stime.tv_sec
+ ldl t3, 12(a1) # ru_stime.tv_usec
+ ldt $f15, 16(a1) # ru_maxrss
+ ldt $f16, 24(a1) # ru_ixrss
+ ldt $f17, 32(a1) # ru_idrss
+ ldt $f18, 40(a1) # ru_isrss
+ ldt $f19, 48(a1) # ru_minflt
+ ldt $f20, 56(a1) # ru_majflt
+ ldt $f21, 64(a1) # ru_nswap
+ ldt $f22, 72(a1) # ru_inblock
+ ldt $f23, 80(a1) # ru_oublock
+ ldt $f24, 88(a1) # ru_msgsend
+ ldt $f25, 96(a1) # ru_msgrcv
+ ldt $f26, 104(a1) # ru_nsignals
+ ldt $f27, 112(a1) # ru_nvcsw
+ .set noat
+ ldt $f28, 120(a1) # ru_nivcsw
+ .set at
+ stq t0, 0(a1)
+ stq t1, 8(a1)
+ stq t2, 16(a1)
+ stq t3, 24(a1)
+ stt $f15, 32(a1)
+ stt $f16, 40(a1)
+ stt $f17, 48(a1)
+ stt $f18, 56(a1)
+ stt $f19, 64(a1)
+ stt $f20, 72(a1)
+ stt $f21, 80(a1)
+ stt $f22, 88(a1)
+ stt $f23, 96(a1)
+ stt $f24, 104(a1)
+ stt $f25, 112(a1)
+ stt $f26, 120(a1)
+ stt $f27, 128(a1)
+ .set noat
+ stt $f28, 136(a1)
+ .set at
+
+ addq sp, 16, sp
+ ret
+
+ .align 3
+$error:
+ addq sp, 16, sp
+ SYSCALL_ERROR_HANDLER
+
+END(GETRUSAGE)
+#endif /* __ASSUME_TIMEVAL64 */
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+strong_alias(__getrusage_tv64, ____getrusage_tv64)
+default_symbol_version (____getrusage_tv64, __getrusage, GLIBC_2.1)
+default_symbol_version (__getrusage_tv64, getrusage, GLIBC_2.1)
+#else
+weak_alias (__getrusage, getrusage)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/getsysstats.c b/libc/sysdeps/unix/sysv/linux/alpha/getsysstats.c
new file mode 100644
index 000000000..0e49a8452
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/getsysstats.c
@@ -0,0 +1,57 @@
+/* Determine various system internal values, Linux/Alpha version.
+ Copyright (C) 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Schwab <schwab@suse.de>
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+/* We need to define a special parser for /proc/cpuinfo. */
+#define GET_NPROCS_PARSER(FP, BUFFER, RESULT) \
+ do \
+ { \
+ /* Find the line that contains the information about the number of \
+ active cpus. We don't have to fear extremely long lines since \
+ the kernel will not generate them. 8192 bytes are really enough. \
+ If there is no "CPUs ..." line then we are on a UP system. */ \
+ (RESULT) = 1; \
+ while (fgets_unlocked (BUFFER, sizeof (BUFFER), FP) != NULL) \
+ if ((sscanf (BUFFER, "cpus active : %d", &(RESULT)) == 1) \
+ || (sscanf (BUFFER, "CPUs probed %*d active %d", \
+ &(RESULT)) == 1)) \
+ break; \
+ } \
+ while (0)
+
+
+/* On the Alpha we can distinguish between the number of configured and
+ active cpus. */
+#define GET_NPROCS_CONF_PARSER(FP, BUFFER, RESULT) \
+ do \
+ { \
+ /* Find the line that contains the information about the number of \
+ probed cpus. We don't have to fear extremely long lines since \
+ the kernel will not generate them. 8192 bytes are really enough. \
+ If there is no "CPUs ..." line then we are on a UP system. */ \
+ (RESULT) = 1; \
+ while (fgets_unlocked ((BUFFER), sizeof (BUFFER), (FP)) != NULL) \
+ if ((sscanf (buffer, "cpus detected : %d", &(RESULT)) == 1) \
+ || (sscanf (buffer, "CPUs probed %d", &(RESULT)) == 1)) \
+ break; \
+ } \
+ while (0)
+
+#include <sysdeps/unix/sysv/linux/getsysstats.c>
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/gettimeofday.S b/libc/sysdeps/unix/sysv/linux/alpha/gettimeofday.S
new file mode 100644
index 000000000..7c9183a4f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/gettimeofday.S
@@ -0,0 +1,120 @@
+/* Copyright (C) 1998, 2002, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+
+.text
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+#define GETTIMEOFDAY __gettimeofday_tv64
+#else
+#define GETTIMEOFDAY __gettimeofday
+#endif
+
+#if defined __ASSUME_TIMEVAL64
+PSEUDO(GETTIMEOFDAY, gettimeofday, 2)
+ ret
+PSEUDO_END(GETTIMEOFDAY)
+#else
+
+/* The problem here is that initially we made struct timeval compatible with
+ OSF/1, using int32. But we defined time_t with uint64, and later found
+ that POSIX requires tv_sec to be time_t.
+
+ So now we have to do compatibility stuff. */
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. */
+.comm __libc_missing_axp_tv64, 4
+
+LEAF(GETTIMEOFDAY, 16)
+ ldgp gp, 0(pv)
+ subq sp, 16, sp
+#ifdef PROF
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+#endif
+ .prologue 1
+
+ ldl t0, __libc_missing_axp_tv64
+
+ /* Save arguments in case we do need to fall back. */
+ stq a0, 0(sp)
+ stq a1, 8(sp)
+
+ bne t0, $do32
+
+ ldi v0, SYS_ify(gettimeofday)
+ callsys
+ bne a3, $err64
+
+ /* Everything ok. */
+ addq sp, 16, sp
+ ret
+
+ /* If we didn't get ENOSYS, it is a real error. */
+ .align 3
+$err64: cmpeq v0, ENOSYS, t0
+ beq t0, $error
+ stl t0, __libc_missing_axp_tv64
+
+ /* Recover the saved arguments. */
+ ldq a1, 8(sp)
+ ldq a0, 0(sp)
+
+ .align 3
+$do32: ldi v0, SYS_ify(osf_gettimeofday)
+ callsys
+ bne a3, $error
+
+ /* Copy back to proper format. */
+ ldq a0, 0(sp)
+ beq a0, 2f
+ ldl t0, 0(a0)
+ ldl t1, 4(a0)
+ stq t0, 0(a0)
+ stq t1, 8(a0)
+
+2: addq sp, 16, sp
+ ret
+
+ .align 3
+$error:
+ addq sp, 16, sp
+ SYSCALL_ERROR_HANDLER
+
+END(GETTIMEOFDAY)
+#endif /* __ASSUME_TIMEVAL64 */
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+default_symbol_version (__gettimeofday_tv64, __gettimeofday, GLIBC_2.1)
+
+/* It seems to me to be a misfeature of the assembler that we can only
+ have one version-alias per symbol. So create an alias ourselves.
+ The 'p' is for 'public'. *Shrug* */
+strong_alias (__gettimeofday_tv64, __gettimeofday_tv64p)
+default_symbol_version (__gettimeofday_tv64p, gettimeofday, GLIBC_2.1)
+#else
+weak_alias (__gettimeofday, gettimeofday)
+#endif
+strong_alias(GETTIMEOFDAY, __gettimeofday_internal)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/glob.c b/libc/sysdeps/unix/sysv/linux/alpha/glob.c
new file mode 100644
index 000000000..84573899d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/glob.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 1998, 2000, 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define glob64 __no_glob64_decl
+#define globfree64 __no_globfree64_decl
+
+#include <sys/types.h>
+#include <glob.h>
+#include <shlib-compat.h>
+
+/* For Linux/Alpha we have to make the glob symbols versioned. */
+#define glob(pattern, flags, errfunc, pglob) \
+ __new_glob (pattern, flags, errfunc, pglob)
+#define globfree(pglob) \
+ __new_globfree (pglob)
+
+/* We need prototypes for these new names. */
+extern int __new_glob (const char *__pattern, int __flags,
+ int (*__errfunc) (const char *, int),
+ glob_t *__pglob);
+extern void __new_globfree (glob_t *__pglob);
+
+#include <posix/glob.c>
+
+#undef glob
+#undef globfree
+#undef glob64
+#undef globfree64
+
+versioned_symbol (libc, __new_glob, glob, GLIBC_2_1);
+versioned_symbol (libc, __new_globfree, globfree, GLIBC_2_1);
+libc_hidden_ver (__new_glob, glob)
+libc_hidden_ver (__new_globfree, globfree)
+
+weak_alias (__new_glob, glob64)
+weak_alias (__new_globfree, globfree64)
+libc_hidden_ver (__new_globfree, globfree64)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/ieee_get_fp_control.S b/libc/sysdeps/unix/sysv/linux/alpha/ieee_get_fp_control.S
new file mode 100644
index 000000000..4779f175e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/ieee_get_fp_control.S
@@ -0,0 +1,61 @@
+/* Copyright (C) 1993, 1995, 1996, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger <davidm@azstarnet.com>, 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include "kernel_sysinfo.h"
+
+
+ .text
+
+LEAF(__ieee_get_fp_control, 16)
+#ifdef PROF
+ ldgp gp, 0(pv)
+ lda sp, -16(sp)
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+ .prologue 1
+#elif defined PIC
+ lda sp, -16(sp)
+ .prologue 0
+#else
+ ldgp gp, 0(pv)
+ lda sp, -16(sp)
+ .prologue 1
+#endif
+
+ mov sp, a1
+ ldi a0, GSI_IEEE_FP_CONTROL
+ ldi v0, __NR_osf_getsysinfo
+ call_pal PAL_callsys
+ bne a3, $error
+
+ ldq v0, 0(sp)
+ lda sp, 16(sp)
+ ret
+
+$error:
+ lda sp, 16(sp)
+ SYSCALL_ERROR_HANDLER
+
+ END(__ieee_get_fp_control)
+
+libc_hidden_def(__ieee_get_fp_control)
+weak_alias (__ieee_get_fp_control, ieee_get_fp_control)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/ieee_set_fp_control.S b/libc/sysdeps/unix/sysv/linux/alpha/ieee_set_fp_control.S
new file mode 100644
index 000000000..a9c0891aa
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/ieee_set_fp_control.S
@@ -0,0 +1,61 @@
+/* Copyright (C) 1993, 1995, 1996, 1997, 2003, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger <davidm@azstarnet.com>, 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include "kernel_sysinfo.h"
+
+
+LEAF(__ieee_set_fp_control, 16)
+#ifdef PROF
+ ldgp gp, 0(pv)
+ lda sp, -16(sp)
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+ .prologue 1
+#elif defined PIC
+ lda sp, -16(sp)
+ .prologue 0
+#else
+ ldgp gp, 0(pv)
+ lda sp, -16(sp)
+ .prologue 1
+#endif
+
+ stq a0, 0(sp)
+ mov sp, a1
+ ldi a0, SSI_IEEE_FP_CONTROL
+ ldi v0, __NR_osf_setsysinfo
+ call_pal PAL_callsys
+
+ bne a3, $error
+
+ lda sp, 16(sp)
+ ret
+
+$error:
+ lda sp, 16(sp)
+ SYSCALL_ERROR_HANDLER
+
+ END(__ieee_set_fp_control)
+
+libc_hidden_def(__ieee_set_fp_control)
+weak_alias (__ieee_set_fp_control, ieee_set_fp_control)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/ioperm.c b/libc/sysdeps/unix/sysv/linux/alpha/ioperm.c
new file mode 100644
index 000000000..6c4115d1c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/ioperm.c
@@ -0,0 +1,878 @@
+/* Copyright (C) 1992, 1996-1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* I/O access is restricted to ISA port space (ports 0..65535).
+ Modern devices hopefully are sane enough not to put any performance
+ critical registers in i/o space.
+
+ On the first call to ioperm, the entire (E)ISA port space is mapped
+ into the virtual address space at address io.base. mprotect calls
+ are then used to enable/disable access to ports. Per page, there
+ are PAGE_SIZE>>IO_SHIFT I/O ports (e.g., 256 ports on a Low Cost Alpha
+ based system using 8KB pages).
+
+ Keep in mind that this code should be able to run in a 32bit address
+ space. It is therefore unreasonable to expect mmap'ing the entire
+ sparse address space would work (e.g., the Low Cost Alpha chip has an
+ I/O address space that's 512MB large!). */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/io.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#define PATH_ALPHA_SYSTYPE "/etc/alpha_systype"
+#define PATH_CPUINFO "/proc/cpuinfo"
+
+#define MAX_PORT 0x10000
+#define vip volatile int *
+#define vuip volatile unsigned int *
+#define vusp volatile unsigned short *
+#define vucp volatile unsigned char *
+
+#define JENSEN_IO_BASE (0x300000000UL)
+#define JENSEN_SPARSE_MEM (0x200000000UL)
+
+/* With respect to the I/O architecture, APECS and LCA are identical,
+ so the following defines apply to LCA as well. */
+#define APECS_IO_BASE (0x1c0000000UL)
+#define APECS_SPARSE_MEM (0x200000000UL)
+#define APECS_DENSE_MEM (0x300000000UL)
+
+/* The same holds for CIA and PYXIS, except for PYXIS we prefer BWX. */
+#define CIA_IO_BASE (0x8580000000UL)
+#define CIA_SPARSE_MEM (0x8000000000UL)
+#define CIA_DENSE_MEM (0x8600000000UL)
+
+#define PYXIS_IO_BASE (0x8900000000UL)
+#define PYXIS_DENSE_MEM (0x8800000000UL)
+
+/* SABLE is EV4, GAMMA is EV5 */
+#define T2_IO_BASE (0x3a0000000UL)
+#define T2_SPARSE_MEM (0x200000000UL)
+#define T2_DENSE_MEM (0x3c0000000UL)
+
+#define GAMMA_IO_BASE (0x83a0000000UL)
+#define GAMMA_SPARSE_MEM (0x8200000000UL)
+#define GAMMA_DENSE_MEM (0x83c0000000UL)
+
+/* NOTE: these are hardwired to PCI bus 0 addresses!!! */
+#define MCPCIA_IO_BASE (0xf980000000UL)
+#define MCPCIA_SPARSE_MEM (0xf800000000UL)
+#define MCPCIA_DENSE_MEM (0xf900000000UL)
+
+/* Tsunami and Irongate use the same offsets, at least for hose 0. */
+#define TSUNAMI_IO_BASE (0x801fc000000UL)
+#define TSUNAMI_DENSE_MEM (0x80000000000UL)
+
+/* Polaris has SPARSE space, but we prefer to use only DENSE
+ because of some idiosyncracies in actually using SPARSE. */
+#define POLARIS_IO_BASE (0xf9fc000000UL)
+#define POLARIS_DENSE_MEM (0xf900000000UL)
+
+typedef enum {
+ IOSYS_UNKNOWN, IOSYS_JENSEN, IOSYS_APECS, IOSYS_CIA, IOSYS_PYXIS, IOSYS_T2,
+ IOSYS_TSUNAMI, IOSYS_MCPCIA, IOSYS_GAMMA, IOSYS_POLARIS,
+ IOSYS_CPUDEP, IOSYS_PCIDEP
+} iosys_t;
+
+typedef enum {
+ IOSWIZZLE_JENSEN, IOSWIZZLE_SPARSE, IOSWIZZLE_DENSE
+} ioswizzle_t;
+
+static struct io_system {
+ unsigned long int bus_memory_base;
+ unsigned long int sparse_bus_mem_base;
+ unsigned long int bus_io_base;
+} io_system[] = { /* NOTE! must match iosys_t enumeration */
+/* UNKNOWN */ {0, 0, 0},
+/* JENSEN */ {0, JENSEN_SPARSE_MEM, JENSEN_IO_BASE},
+/* APECS */ {APECS_DENSE_MEM, APECS_SPARSE_MEM, APECS_IO_BASE},
+/* CIA */ {CIA_DENSE_MEM, CIA_SPARSE_MEM, CIA_IO_BASE},
+/* PYXIS */ {PYXIS_DENSE_MEM, 0, PYXIS_IO_BASE},
+/* T2 */ {T2_DENSE_MEM, T2_SPARSE_MEM, T2_IO_BASE},
+/* TSUNAMI */ {TSUNAMI_DENSE_MEM, 0, TSUNAMI_IO_BASE},
+/* MCPCIA */ {MCPCIA_DENSE_MEM, MCPCIA_SPARSE_MEM, MCPCIA_IO_BASE},
+/* GAMMA */ {GAMMA_DENSE_MEM, GAMMA_SPARSE_MEM, GAMMA_IO_BASE},
+/* POLARIS */ {POLARIS_DENSE_MEM, 0, POLARIS_IO_BASE},
+/* CPUDEP */ {0, 0, 0}, /* for platforms dependent on CPU type */
+/* PCIDEP */ {0, 0, 0}, /* for platforms dependent on core logic */
+};
+
+static struct platform {
+ const char *name;
+ iosys_t io_sys;
+} platform[] = {
+ {"Alcor", IOSYS_CIA},
+ {"Avanti", IOSYS_APECS},
+ {"Cabriolet", IOSYS_APECS},
+ {"EB164", IOSYS_PCIDEP},
+ {"EB64+", IOSYS_APECS},
+ {"EB66", IOSYS_APECS},
+ {"EB66P", IOSYS_APECS},
+ {"Jensen", IOSYS_JENSEN},
+ {"Miata", IOSYS_PYXIS},
+ {"Mikasa", IOSYS_CPUDEP},
+ {"Nautilus", IOSYS_TSUNAMI},
+ {"Noname", IOSYS_APECS},
+ {"Noritake", IOSYS_CPUDEP},
+ {"Rawhide", IOSYS_MCPCIA},
+ {"Ruffian", IOSYS_PYXIS},
+ {"Sable", IOSYS_CPUDEP},
+ {"Takara", IOSYS_CIA},
+ {"Tsunami", IOSYS_TSUNAMI},
+ {"XL", IOSYS_APECS},
+};
+
+struct ioswtch {
+ void (*sethae)(unsigned long int addr);
+ void (*outb)(unsigned char b, unsigned long int port);
+ void (*outw)(unsigned short b, unsigned long int port);
+ void (*outl)(unsigned int b, unsigned long int port);
+ unsigned int (*inb)(unsigned long int port);
+ unsigned int (*inw)(unsigned long int port);
+ unsigned int (*inl)(unsigned long int port);
+};
+
+static struct {
+ unsigned long int hae_cache;
+ unsigned long int base;
+ struct ioswtch * swp;
+ unsigned long int bus_memory_base;
+ unsigned long int sparse_bus_memory_base;
+ unsigned long int io_base;
+ ioswizzle_t swiz;
+} io;
+
+static inline void
+stb_mb(unsigned char val, unsigned long addr)
+{
+ __asm__("stb %1,%0; mb" : "=m"(*(vucp)addr) : "r"(val));
+}
+
+static inline void
+stw_mb(unsigned short val, unsigned long addr)
+{
+ __asm__("stw %1,%0; mb" : "=m"(*(vusp)addr) : "r"(val));
+}
+
+static inline void
+stl_mb(unsigned int val, unsigned long addr)
+{
+ __asm__("stl %1,%0; mb" : "=m"(*(vip)addr) : "r"(val));
+}
+
+/* No need to examine error -- sethae never fails. */
+static inline void
+__sethae(unsigned long value)
+{
+ register unsigned long r16 __asm__("$16") = value;
+ register unsigned long r0 __asm__("$0") = __NR_sethae;
+ __asm__ __volatile__ ("callsys"
+ : "=r"(r0)
+ : "0"(r0), "r" (r16)
+ : inline_syscall_clobbers, "$19");
+}
+
+extern long __pciconfig_iobase(enum __pciconfig_iobase_which __which,
+ unsigned long int __bus,
+ unsigned long int __dfn);
+
+static inline unsigned long int
+port_to_cpu_addr (unsigned long int port, ioswizzle_t ioswiz, int size)
+{
+ if (ioswiz == IOSWIZZLE_SPARSE)
+ return io.base + (port << 5) + ((size - 1) << 3);
+ else if (ioswiz == IOSWIZZLE_DENSE)
+ return port + io.base;
+ else
+ return io.base + (port << 7) + ((size - 1) << 5);
+}
+
+static inline void
+inline_sethae (unsigned long int addr, ioswizzle_t ioswiz)
+{
+ if (ioswiz == IOSWIZZLE_SPARSE)
+ {
+ unsigned long int msb;
+
+ /* no need to set hae if msb is 0: */
+ msb = addr & 0xf8000000;
+ if (msb && msb != io.hae_cache)
+ {
+ io.hae_cache = msb;
+ __sethae (msb);
+ }
+ }
+ else if (ioswiz == IOSWIZZLE_JENSEN)
+ {
+ /* HAE on the Jensen is bits 31:25 shifted right. */
+ addr >>= 25;
+ if (addr != io.hae_cache)
+ {
+ io.hae_cache = addr;
+ __sethae (addr);
+ }
+ }
+}
+
+static inline void
+inline_outb (unsigned char b, unsigned long int port, ioswizzle_t ioswiz)
+{
+ unsigned int w;
+ unsigned long int addr = port_to_cpu_addr (port, ioswiz, 1);
+
+ asm ("insbl %2,%1,%0" : "=r" (w) : "ri" (port & 0x3), "r" (b));
+ stl_mb(w, addr);
+}
+
+
+static inline void
+inline_outw (unsigned short int b, unsigned long int port, ioswizzle_t ioswiz)
+{
+ unsigned long w;
+ unsigned long int addr = port_to_cpu_addr (port, ioswiz, 2);
+
+ asm ("inswl %2,%1,%0" : "=r" (w) : "ri" (port & 0x3), "r" (b));
+ stl_mb(w, addr);
+}
+
+
+static inline void
+inline_outl (unsigned int b, unsigned long int port, ioswizzle_t ioswiz)
+{
+ unsigned long int addr = port_to_cpu_addr (port, ioswiz, 4);
+
+ stl_mb(b, addr);
+}
+
+
+static inline unsigned int
+inline_inb (unsigned long int port, ioswizzle_t ioswiz)
+{
+ unsigned long int addr = port_to_cpu_addr (port, ioswiz, 1);
+ int result;
+
+ result = *(vip) addr;
+ result >>= (port & 3) * 8;
+ return 0xffUL & result;
+}
+
+
+static inline unsigned int
+inline_inw (unsigned long int port, ioswizzle_t ioswiz)
+{
+ unsigned long int addr = port_to_cpu_addr (port, ioswiz, 2);
+ int result;
+
+ result = *(vip) addr;
+ result >>= (port & 3) * 8;
+ return 0xffffUL & result;
+}
+
+
+static inline unsigned int
+inline_inl (unsigned long int port, ioswizzle_t ioswiz)
+{
+ unsigned long int addr = port_to_cpu_addr (port, ioswiz, 4);
+
+ return *(vuip) addr;
+}
+
+/*
+ * Now define the inline functions for CPUs supporting byte/word insns,
+ * and whose core logic supports I/O space accesses utilizing them.
+ *
+ * These routines could be used by MIATA, for example, because it has
+ * and EV56 plus PYXIS, but it currently uses SPARSE anyway. This is
+ * also true of RX164 which used POLARIS, but we will choose to use
+ * these routines in that case instead of SPARSE.
+ *
+ * These routines are necessary for TSUNAMI/TYPHOON based platforms,
+ * which will have (at least) EV6.
+ */
+
+static inline unsigned long int
+dense_port_to_cpu_addr (unsigned long int port)
+{
+ return port + io.base;
+}
+
+static inline void
+inline_bwx_outb (unsigned char b, unsigned long int port)
+{
+ unsigned long int addr = dense_port_to_cpu_addr (port);
+ stb_mb (b, addr);
+}
+
+static inline void
+inline_bwx_outw (unsigned short int b, unsigned long int port)
+{
+ unsigned long int addr = dense_port_to_cpu_addr (port);
+ stw_mb (b, addr);
+}
+
+static inline void
+inline_bwx_outl (unsigned int b, unsigned long int port)
+{
+ unsigned long int addr = dense_port_to_cpu_addr (port);
+ stl_mb (b, addr);
+}
+
+static inline unsigned int
+inline_bwx_inb (unsigned long int port)
+{
+ unsigned long int addr = dense_port_to_cpu_addr (port);
+ unsigned char r;
+
+ __asm__ ("ldbu %0,%1" : "=r"(r) : "m"(*(vucp)addr));
+ return r;
+}
+
+static inline unsigned int
+inline_bwx_inw (unsigned long int port)
+{
+ unsigned long int addr = dense_port_to_cpu_addr (port);
+ unsigned short r;
+
+ __asm__ ("ldwu %0,%1" : "=r"(r) : "m"(*(vusp)addr));
+ return r;
+}
+
+static inline unsigned int
+inline_bwx_inl (unsigned long int port)
+{
+ unsigned long int addr = dense_port_to_cpu_addr (port);
+
+ return *(vuip) addr;
+}
+
+/* macros to define routines with appropriate names and functions */
+
+/* these do either SPARSE or JENSEN swizzle */
+
+#define DCL_SETHAE(name, ioswiz) \
+static void \
+name##_sethae (unsigned long int addr) \
+{ \
+ inline_sethae (addr, IOSWIZZLE_##ioswiz); \
+}
+
+#define DCL_OUT(name, func, type, ioswiz) \
+static void \
+name##_##func (unsigned type b, unsigned long int addr) \
+{ \
+ inline_##func (b, addr, IOSWIZZLE_##ioswiz); \
+}
+
+#define DCL_IN(name, func, ioswiz) \
+static unsigned int \
+name##_##func (unsigned long int addr) \
+{ \
+ return inline_##func (addr, IOSWIZZLE_##ioswiz); \
+}
+
+/* these do DENSE, so no swizzle is needed */
+
+#define DCL_OUT_BWX(name, func, type) \
+static void \
+name##_##func (unsigned type b, unsigned long int addr) \
+{ \
+ inline_bwx_##func (b, addr); \
+}
+
+#define DCL_IN_BWX(name, func) \
+static unsigned int \
+name##_##func (unsigned long int addr) \
+{ \
+ return inline_bwx_##func (addr); \
+}
+
+/* now declare/define the necessary routines */
+
+DCL_SETHAE(jensen, JENSEN)
+DCL_OUT(jensen, outb, char, JENSEN)
+DCL_OUT(jensen, outw, short int, JENSEN)
+DCL_OUT(jensen, outl, int, JENSEN)
+DCL_IN(jensen, inb, JENSEN)
+DCL_IN(jensen, inw, JENSEN)
+DCL_IN(jensen, inl, JENSEN)
+
+DCL_SETHAE(sparse, SPARSE)
+DCL_OUT(sparse, outb, char, SPARSE)
+DCL_OUT(sparse, outw, short int, SPARSE)
+DCL_OUT(sparse, outl, int, SPARSE)
+DCL_IN(sparse, inb, SPARSE)
+DCL_IN(sparse, inw, SPARSE)
+DCL_IN(sparse, inl, SPARSE)
+
+DCL_SETHAE(dense, DENSE)
+DCL_OUT_BWX(dense, outb, char)
+DCL_OUT_BWX(dense, outw, short int)
+DCL_OUT_BWX(dense, outl, int)
+DCL_IN_BWX(dense, inb)
+DCL_IN_BWX(dense, inw)
+DCL_IN_BWX(dense, inl)
+
+/* define the "swizzle" switch */
+static struct ioswtch ioswtch[] = {
+ {
+ jensen_sethae,
+ jensen_outb, jensen_outw, jensen_outl,
+ jensen_inb, jensen_inw, jensen_inl
+ },
+ {
+ sparse_sethae,
+ sparse_outb, sparse_outw, sparse_outl,
+ sparse_inb, sparse_inw, sparse_inl
+ },
+ {
+ dense_sethae,
+ dense_outb, dense_outw, dense_outl,
+ dense_inb, dense_inw, dense_inl
+ }
+};
+
+#undef DEBUG_IOPERM
+
+/* Routine to process the /proc/cpuinfo information into the fields
+ that are required for correctly determining the platform parameters. */
+
+struct cpuinfo_data
+{
+ char systype[256]; /* system type field */
+ char sysvari[256]; /* system variation field */
+ char cpumodel[256]; /* cpu model field */
+};
+
+static inline int
+process_cpuinfo(struct cpuinfo_data *data)
+{
+ int got_type, got_vari, got_model;
+ char dummy[256];
+ FILE * fp;
+ int n;
+
+ data->systype[0] = 0;
+ data->sysvari[0] = 0;
+ data->cpumodel[0] = 0;
+
+ /* If there's an /etc/alpha_systype link, we're intending to override
+ whatever's in /proc/cpuinfo. */
+ n = __readlink (PATH_ALPHA_SYSTYPE, data->systype, 256 - 1);
+ if (n > 0)
+ {
+ data->systype[n] = '\0';
+ return 1;
+ }
+
+ fp = fopen (PATH_CPUINFO, "r");
+ if (!fp)
+ return 0;
+
+ got_type = got_vari = got_model = 0;
+
+ while (1)
+ {
+ if (fgets (dummy, 256, fp) == NULL)
+ break;
+ if (!got_type &&
+ sscanf (dummy, "system type : %256[^\n]\n", data->systype) == 1)
+ got_type = 1;
+ if (!got_vari &&
+ sscanf (dummy, "system variation : %256[^\n]\n", data->sysvari) == 1)
+ got_vari = 1;
+ if (!got_model &&
+ sscanf (dummy, "cpu model : %256[^\n]\n", data->cpumodel) == 1)
+ got_model = 1;
+ }
+
+ fclose (fp);
+
+#ifdef DEBUG_IOPERM
+ fprintf(stderr, "system type: `%s'\n", data->systype);
+ fprintf(stderr, "system vari: `%s'\n", data->sysvari);
+ fprintf(stderr, "cpu model: `%s'\n", data->cpumodel);
+#endif
+
+ return got_type + got_vari + got_model;
+}
+
+
+/*
+ * Initialize I/O system.
+ */
+static int
+init_iosys (void)
+{
+ long addr;
+ int i, olderrno = errno;
+ struct cpuinfo_data data;
+
+ /* First try the pciconfig_iobase syscall added to 2.2.15 and 2.3.99. */
+
+#ifdef __NR_pciconfig_iobase
+ addr = __pciconfig_iobase (IOBASE_DENSE_MEM, 0, 0);
+ if (addr != -1)
+ {
+ ioswizzle_t io_swiz;
+
+ if (addr == 0)
+ {
+ /* Only Jensen doesn't have dense mem space. */
+ io.sparse_bus_memory_base
+ = io_system[IOSYS_JENSEN].sparse_bus_mem_base;
+ io.io_base = io_system[IOSYS_JENSEN].bus_io_base;
+ io_swiz = IOSWIZZLE_JENSEN;
+ }
+ else
+ {
+ io.bus_memory_base = addr;
+
+ addr = __pciconfig_iobase (IOBASE_DENSE_IO, 0, 0);
+ if (addr != 0)
+ {
+ /* The X server uses _bus_base_sparse == 0 to know that
+ BWX access are supported to dense mem space. This is
+ true of every system that supports dense io space, so
+ never fill in io.sparse_bus_memory_base in this case. */
+ io_swiz = IOSWIZZLE_DENSE;
+ io.io_base = addr;
+ }
+ else
+ {
+ io.sparse_bus_memory_base
+ = __pciconfig_iobase (IOBASE_SPARSE_MEM, 0, 0);
+ io.io_base = __pciconfig_iobase (IOBASE_SPARSE_IO, 0, 0);
+ io_swiz = IOSWIZZLE_SPARSE;
+ }
+ }
+
+ io.swiz = io_swiz;
+ io.swp = &ioswtch[io_swiz];
+
+ return 0;
+ }
+#endif
+
+ /* Second, collect the contents of /etc/alpha_systype or /proc/cpuinfo. */
+
+ if (process_cpuinfo(&data) == 0)
+ {
+ /* This can happen if the format of /proc/cpuinfo changes. */
+ fprintf (stderr,
+ "ioperm.init_iosys: Unable to determine system type.\n"
+ "\t(May need " PATH_ALPHA_SYSTYPE " symlink?)\n");
+ __set_errno (ENODEV);
+ return -1;
+ }
+
+ /* Translate systype name into i/o system. */
+ for (i = 0; i < sizeof (platform) / sizeof (platform[0]); ++i)
+ {
+ if (strcmp (platform[i].name, data.systype) == 0)
+ {
+ iosys_t io_sys = platform[i].io_sys;
+
+ /* Some platforms can have either EV4 or EV5 CPUs. */
+ if (io_sys == IOSYS_CPUDEP)
+ {
+ /* SABLE or MIKASA or NORITAKE so far. */
+ if (strcmp (platform[i].name, "Sable") == 0)
+ {
+ if (strncmp (data.cpumodel, "EV4", 3) == 0)
+ io_sys = IOSYS_T2;
+ else if (strncmp (data.cpumodel, "EV5", 3) == 0)
+ io_sys = IOSYS_GAMMA;
+ }
+ else
+ {
+ /* This covers MIKASA/NORITAKE. */
+ if (strncmp (data.cpumodel, "EV4", 3) == 0)
+ io_sys = IOSYS_APECS;
+ else if (strncmp (data.cpumodel, "EV5", 3) == 0)
+ io_sys = IOSYS_CIA;
+ }
+ if (io_sys == IOSYS_CPUDEP)
+ {
+ /* This can happen if the format of /proc/cpuinfo changes.*/
+ fprintf (stderr, "ioperm.init_iosys: Unable to determine"
+ " CPU model.\n");
+ __set_errno (ENODEV);
+ return -1;
+ }
+ }
+ /* Some platforms can have different core logic chipsets */
+ if (io_sys == IOSYS_PCIDEP)
+ {
+ /* EB164 so far */
+ if (strcmp (data.systype, "EB164") == 0)
+ {
+ if (strncmp (data.sysvari, "RX164", 5) == 0)
+ io_sys = IOSYS_POLARIS;
+ else if (strncmp (data.sysvari, "LX164", 5) == 0
+ || strncmp (data.sysvari, "SX164", 5) == 0)
+ io_sys = IOSYS_PYXIS;
+ else
+ io_sys = IOSYS_CIA;
+ }
+ if (io_sys == IOSYS_PCIDEP)
+ {
+ /* This can happen if the format of /proc/cpuinfo changes.*/
+ fprintf (stderr, "ioperm.init_iosys: Unable to determine"
+ " core logic chipset.\n");
+ __set_errno (ENODEV);
+ return -1;
+ }
+ }
+ io.bus_memory_base = io_system[io_sys].bus_memory_base;
+ io.sparse_bus_memory_base = io_system[io_sys].sparse_bus_mem_base;
+ io.io_base = io_system[io_sys].bus_io_base;
+
+ if (io_sys == IOSYS_JENSEN)
+ io.swiz = IOSWIZZLE_JENSEN;
+ else if (io_sys == IOSYS_TSUNAMI
+ || io_sys == IOSYS_POLARIS
+ || io_sys == IOSYS_PYXIS)
+ io.swiz = IOSWIZZLE_DENSE;
+ else
+ io.swiz = IOSWIZZLE_SPARSE;
+ io.swp = &ioswtch[io.swiz];
+
+ __set_errno (olderrno);
+ return 0;
+ }
+ }
+
+ __set_errno (ENODEV);
+ fprintf(stderr, "ioperm.init_iosys: Platform not recognized.\n"
+ "\t(May need " PATH_ALPHA_SYSTYPE " symlink?)\n");
+ return -1;
+}
+
+
+int
+_ioperm (unsigned long int from, unsigned long int num, int turn_on)
+{
+ unsigned long int addr, len, pagesize = __getpagesize();
+ int prot;
+
+ if (!io.swp && init_iosys() < 0)
+ {
+#ifdef DEBUG_IOPERM
+ fprintf(stderr, "ioperm: init_iosys() failed (%m)\n");
+#endif
+ return -1;
+ }
+
+ /* This test isn't as silly as it may look like; consider overflows! */
+ if (from >= MAX_PORT || from + num > MAX_PORT)
+ {
+ __set_errno (EINVAL);
+#ifdef DEBUG_IOPERM
+ fprintf(stderr, "ioperm: from/num out of range\n");
+#endif
+ return -1;
+ }
+
+#ifdef DEBUG_IOPERM
+ fprintf(stderr, "ioperm: turn_on %d io.base %ld\n", turn_on, io.base);
+#endif
+
+ if (turn_on)
+ {
+ if (!io.base)
+ {
+ int fd;
+
+ io.hae_cache = 0;
+ if (io.swiz != IOSWIZZLE_DENSE)
+ {
+ /* Synchronize with hw. */
+ __sethae (0);
+ }
+
+ fd = __open ("/dev/mem", O_RDWR);
+ if (fd < 0)
+ {
+#ifdef DEBUG_IOPERM
+ fprintf(stderr, "ioperm: /dev/mem open failed (%m)\n");
+#endif
+ return -1;
+ }
+
+ addr = port_to_cpu_addr (0, io.swiz, 1);
+ len = port_to_cpu_addr (MAX_PORT, io.swiz, 1) - addr;
+ io.base =
+ (unsigned long int) __mmap (0, len, PROT_NONE, MAP_SHARED,
+ fd, io.io_base);
+ __close (fd);
+#ifdef DEBUG_IOPERM
+ fprintf(stderr, "ioperm: mmap of len 0x%lx returned 0x%lx\n",
+ len, io.base);
+#endif
+ if ((long) io.base == -1)
+ return -1;
+ }
+ prot = PROT_READ | PROT_WRITE;
+ }
+ else
+ {
+ if (!io.base)
+ return 0; /* never was turned on... */
+
+ /* turnoff access to relevant pages: */
+ prot = PROT_NONE;
+ }
+ addr = port_to_cpu_addr (from, io.swiz, 1);
+ addr &= ~(pagesize - 1);
+ len = port_to_cpu_addr (from + num, io.swiz, 1) - addr;
+ return __mprotect ((void *) addr, len, prot);
+}
+
+
+int
+_iopl (int level)
+{
+ switch (level)
+ {
+ case 0:
+ return 0;
+
+ case 1: case 2: case 3:
+ return _ioperm (0, MAX_PORT, 1);
+
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+}
+
+
+void
+_sethae (unsigned long int addr)
+{
+ if (!io.swp && init_iosys () < 0)
+ return;
+
+ io.swp->sethae (addr);
+}
+
+
+void
+_outb (unsigned char b, unsigned long int port)
+{
+ if (port >= MAX_PORT)
+ return;
+
+ io.swp->outb (b, port);
+}
+
+
+void
+_outw (unsigned short b, unsigned long int port)
+{
+ if (port >= MAX_PORT)
+ return;
+
+ io.swp->outw (b, port);
+}
+
+
+void
+_outl (unsigned int b, unsigned long int port)
+{
+ if (port >= MAX_PORT)
+ return;
+
+ io.swp->outl (b, port);
+}
+
+
+unsigned int
+_inb (unsigned long int port)
+{
+ return io.swp->inb (port);
+}
+
+
+unsigned int
+_inw (unsigned long int port)
+{
+ return io.swp->inw (port);
+}
+
+
+unsigned int
+_inl (unsigned long int port)
+{
+ return io.swp->inl (port);
+}
+
+
+unsigned long int
+_bus_base(void)
+{
+ if (!io.swp && init_iosys () < 0)
+ return -1;
+ return io.bus_memory_base;
+}
+
+unsigned long int
+_bus_base_sparse(void)
+{
+ if (!io.swp && init_iosys () < 0)
+ return -1;
+ return io.sparse_bus_memory_base;
+}
+
+int
+_hae_shift(void)
+{
+ if (!io.swp && init_iosys () < 0)
+ return -1;
+ if (io.swiz == IOSWIZZLE_JENSEN)
+ return 7;
+ if (io.swiz == IOSWIZZLE_SPARSE)
+ return 5;
+ return 0;
+}
+
+weak_alias (_sethae, sethae);
+weak_alias (_ioperm, ioperm);
+weak_alias (_iopl, iopl);
+weak_alias (_inb, inb);
+weak_alias (_inw, inw);
+weak_alias (_inl, inl);
+weak_alias (_outb, outb);
+weak_alias (_outw, outw);
+weak_alias (_outl, outl);
+weak_alias (_bus_base, bus_base);
+weak_alias (_bus_base_sparse, bus_base_sparse);
+weak_alias (_hae_shift, hae_shift);
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/ipc_priv.h b/libc/sysdeps/unix/sysv/linux/alpha/ipc_priv.h
new file mode 100644
index 000000000..0328dc08e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/ipc_priv.h
@@ -0,0 +1,47 @@
+/* Copyright (C) 1995-1999, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/ipc.h>
+
+#define __IPC_64 0x100
+
+struct __old_ipc_perm
+{
+ __key_t __key; /* Key. */
+ unsigned int uid; /* Owner's user ID. */
+ unsigned int gid; /* Owner's group ID. */
+ unsigned int cuid; /* Creator's user ID. */
+ unsigned int cgid; /* Creator's group ID. */
+ unsigned int mode; /* Read/write permission. */
+ unsigned short int __seq; /* Sequence number. */
+};
+
+
+/* The codes for the functions to use the ipc syscall multiplexer. */
+#define IPCOP_semop 1
+#define IPCOP_semget 2
+#define IPCOP_semctl 3
+#define IPCOP_semtimedop 4
+#define IPCOP_msgsnd 11
+#define IPCOP_msgrcv 12
+#define IPCOP_msgget 13
+#define IPCOP_msgctl 14
+#define IPCOP_shmat 21
+#define IPCOP_shmdt 22
+#define IPCOP_shmget 23
+#define IPCOP_shmctl 24
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/kernel_sigaction.h b/libc/sysdeps/unix/sysv/linux/alpha/kernel_sigaction.h
new file mode 100644
index 000000000..4c35d969c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/kernel_sigaction.h
@@ -0,0 +1,15 @@
+/* This is the sigaction struction from the Linux 2.1.20 kernel. */
+
+struct old_kernel_sigaction {
+ __sighandler_t k_sa_handler;
+ unsigned long sa_mask;
+ unsigned int sa_flags;
+};
+
+/* This is the sigaction structure from the Linux 2.1.68 kernel. */
+
+struct kernel_sigaction {
+ __sighandler_t k_sa_handler;
+ unsigned int sa_flags;
+ sigset_t sa_mask;
+};
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/kernel_stat.h b/libc/sysdeps/unix/sysv/linux/alpha/kernel_stat.h
new file mode 100644
index 000000000..a1d012ab0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/kernel_stat.h
@@ -0,0 +1,88 @@
+/* Definition of `struct stat' used in the kernel. */
+struct kernel_stat
+ {
+ unsigned int st_dev;
+ unsigned int st_ino;
+ unsigned int st_mode;
+ unsigned int st_nlink;
+ unsigned int st_uid;
+ unsigned int st_gid;
+ unsigned int st_rdev;
+ long int st_size;
+ unsigned long int st_atime;
+ unsigned long int st_mtime;
+ unsigned long int st_ctime;
+ unsigned int st_blksize;
+ int st_blocks;
+ unsigned int st_flags;
+ unsigned int st_gen;
+ };
+
+/* Definition of `struct stat64' used in the kernel. */
+struct kernel_stat64
+ {
+ unsigned long st_dev;
+ unsigned long st_ino;
+ unsigned long st_rdev;
+ long st_size;
+ unsigned long st_blocks;
+
+ unsigned int st_mode;
+ unsigned int st_uid;
+ unsigned int st_gid;
+ unsigned int st_blksize;
+ unsigned int st_nlink;
+ unsigned int __pad0;
+
+ unsigned long st_atime;
+ unsigned long st_atimensec;
+ unsigned long st_mtime;
+ unsigned long st_mtimensec;
+ unsigned long st_ctime;
+ unsigned long st_ctimensec;
+ long __unused[3];
+ };
+
+/* Definition of `struct stat' used by glibc 2.0. */
+struct glibc2_stat
+ {
+ __dev_t st_dev;
+ __ino_t st_ino;
+ __mode_t st_mode;
+ __nlink_t st_nlink;
+ __uid_t st_uid;
+ __gid_t st_gid;
+ __dev_t st_rdev;
+ __off_t st_size;
+ __time_t st_atime;
+ __time_t st_mtime;
+ __time_t st_ctime;
+ unsigned int st_blksize;
+ int st_blocks;
+ unsigned int st_flags;
+ unsigned int st_gen;
+ };
+
+/* Definition of `struct stat' used by glibc 2.1. */
+struct glibc21_stat
+ {
+ __dev_t st_dev;
+ __ino64_t st_ino;
+ __mode_t st_mode;
+ __nlink_t st_nlink;
+ __uid_t st_uid;
+ __gid_t st_gid;
+ __dev_t st_rdev;
+ __off_t st_size;
+ __time_t st_atime;
+ __time_t st_mtime;
+ __time_t st_ctime;
+ __blkcnt64_t st_blocks;
+ __blksize_t st_blksize;
+ unsigned int st_flags;
+ unsigned int st_gen;
+ int __pad3;
+ long __unused[4];
+ };
+
+#define XSTAT_IS_XSTAT64 1
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/kernel_sysinfo.h b/libc/sysdeps/unix/sysv/linux/alpha/kernel_sysinfo.h
new file mode 100644
index 000000000..a3edec226
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/kernel_sysinfo.h
@@ -0,0 +1,6 @@
+/* A copy of the couple of bits we need from <asm/sysinfo.h>. */
+
+#define GSI_IEEE_FP_CONTROL 45
+
+#define SSI_IEEE_FP_CONTROL 14
+#define SSI_IEEE_RAISE_EXCEPTION 1001
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/kernel_termios.h b/libc/sysdeps/unix/sysv/linux/alpha/kernel_termios.h
new file mode 100644
index 000000000..c38f1fac1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/kernel_termios.h
@@ -0,0 +1,44 @@
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _KERNEL_TERMIOS_H
+#define _KERNEL_TERMIOS_H 1
+
+/* The following corresponds to the values from the Linux 2.1.20 kernel. */
+
+/* We need the definition of tcflag_t, cc_t, and speed_t. */
+#include <termios.h>
+
+#define __KERNEL_NCCS 19
+
+struct __kernel_termios
+ {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_cc[__KERNEL_NCCS]; /* control characters */
+ cc_t c_line; /* line discipline */
+ speed_t c_ispeed; /* input speed */
+ speed_t c_ospeed; /* output speed */
+ };
+
+#define _HAVE_C_ISPEED 1
+#define _HAVE_C_OSPEED 1
+
+#endif /* kernel_termios.h */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/lxstat.c b/libc/sysdeps/unix/sysv/linux/alpha/lxstat.c
new file mode 100644
index 000000000..38fac2e2b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/lxstat.c
@@ -0,0 +1,64 @@
+/* lxstat using old-style Unix stat system call.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define __lxstat64 __lxstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <xstatconv.h>
+
+#undef __lxstat64
+
+
+/* Get information about the file NAME in BUF. */
+int
+__lxstat (int vers, const char *name, struct stat *buf)
+{
+ INTERNAL_SYSCALL_DECL (err);
+ int result, errno_out;
+ struct kernel_stat kbuf;
+
+ if (vers == _STAT_VER_KERNEL64 && !__libc_missing_axp_stat64)
+ {
+ result = INTERNAL_SYSCALL (lstat64, err, 2, name, buf);
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return result;
+ errno_out = INTERNAL_SYSCALL_ERRNO (result, err);
+ if (errno_out != ENOSYS)
+ goto fail;
+ __libc_missing_axp_stat64 = 1;
+ }
+
+ result = INTERNAL_SYSCALL (lstat, err, 2, name, &kbuf);
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return __xstat_conv (vers, &kbuf, buf);
+ errno_out = INTERNAL_SYSCALL_ERRNO (result, err);
+
+ fail:
+ __set_errno (errno_out);
+ return -1;
+}
+hidden_def (__lxstat)
+weak_alias (__lxstat, _lxstat);
+strong_alias (__lxstat, __lxstat64);
+hidden_ver (__lxstat, __lxstat64)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/makecontext.S b/libc/sysdeps/unix/sysv/linux/alpha/makecontext.S
new file mode 100644
index 000000000..223117e26
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/makecontext.S
@@ -0,0 +1,164 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <ucontext-offsets.h>
+
+
+ENTRY(__makecontext)
+ ldgp $29, 0($27)
+#ifdef PROF
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+#endif
+ .prologue 1
+
+ /* Compute top of stack, including arguments. */
+ ldq $1, UC_STACK+SS_SP($16)
+ ldq $2, UC_STACK+SS_SIZE($16)
+ addq $1, $2, $8
+ subq $18, 6, $1
+ cmovlt $1, 0, $1
+ s8addq $1, 0, $2
+ subq $8, $2, $8
+
+ /* Copy all parameters. Switch statement header here. */
+ ldah $3, $jumptable($29) !gprelhigh
+ cmple $18, 6, $1
+ mov $18, $2
+ cmoveq $1, 7, $2
+ s4addq $2, $3, $3
+ ldl $4, $jumptable($3) !gprellow
+ addq $4, $29, $4
+ jmp $31, ($4), $args1
+
+ .section .rodata
+ .align 2
+$jumptable:
+ .gprel32 $args0
+ .gprel32 $args1
+ .gprel32 $args2
+ .gprel32 $args3
+ .gprel32 $args4
+ .gprel32 $args5
+ .gprel32 $args6
+ .gprel32 $argsN
+ .text
+
+ /* Here we process arguments 7 through N. This is a straight
+ stack-to-stack copy. */
+ .align 4
+$argsN:
+ subq $18, 6, $1
+ lda $2, 0($8)
+ lda $3, 3*8($30)
+ .align 4
+1:
+ ldq $0, 0($3)
+ subq $1, 1, $1
+ lda $3, 8($3)
+ stq $0, 0($2)
+ lda $2, 8($2)
+ bne $1, 1b
+
+ /* Here we process arguments 6 through 0. This involves
+ copying into the register save areas of the ucontext. */
+ .align 4
+$args6:
+ ldq $0, 2*8($30)
+ stq $0, UC_SIGCTX+SC_REGS+21*8($16)
+ unop
+ stq $0, UC_SIGCTX+SC_FPREGS+21*8($16)
+$args5:
+ ldq $0, 1*8($30)
+ stq $0, UC_SIGCTX+SC_REGS+20*8($16)
+ unop
+ stq $0, UC_SIGCTX+SC_FPREGS+20*8($16)
+$args4:
+ ldq $0, 0*8($30)
+ stq $0, UC_SIGCTX+SC_REGS+19*8($16)
+ unop
+ stq $0, UC_SIGCTX+SC_FPREGS+19*8($16)
+$args3:
+ unop
+ stq $21, UC_SIGCTX+SC_REGS+18*8($16)
+ unop
+ stt $f21, UC_SIGCTX+SC_FPREGS+18*8($16)
+$args2:
+ unop
+ stq $20, UC_SIGCTX+SC_REGS+17*8($16)
+ unop
+ stt $f20, UC_SIGCTX+SC_FPREGS+17*8($16)
+$args1:
+ unop
+ stq $19, UC_SIGCTX+SC_REGS+16*8($16)
+ unop
+ stt $f19, UC_SIGCTX+SC_FPREGS+16*8($16)
+$args0:
+
+ /* Set up the registers ready to invoke __startcontext.
+ We seed $27 with the target function address, and $9
+ with the link from ucp. */
+ ldah $0, __startcontext($29) !gprelhigh
+ ldq $1, UC_LINK($16)
+ lda $0, __startcontext($0) !gprellow
+ stq $17, UC_SIGCTX+SC_REGS+27*8($16)
+ stq $8, UC_SIGCTX+SC_REGS+30*8($16)
+ stq $0, UC_SIGCTX+SC_PC($16)
+ stq $1, UC_SIGCTX+SC_REGS+9*8($16)
+
+ /* No return value from makecontext. */
+ ret
+
+END(__makecontext)
+weak_alias (__makecontext, makecontext)
+
+/* This function is where a new makecontext "thread" begins life.
+ We have already set up $27 for calling the target function, and
+ we've set $9 to the UC_LINK of the parent context.
+
+ If the function returns, we either jump to the linked context
+ (if non-null) or exit. */
+
+ .align 4
+ .ent __startcontext
+__startcontext:
+ .frame $31, 0, $31, 0
+ .prologue 0
+
+ jsr $26, ($27), 0
+ ldgp $29, 0($26)
+ mov $9, $16
+ beq $9, 1f
+
+#ifdef PIC
+ bsr $26, __setcontext !samegp
+1: mov $31, $16
+ bsr $26, HIDDEN_JUMPTARGET(exit) !samegp
+#else
+ jsr $26, __setcontext
+ ldgp $29, 0($26)
+1: mov $31, $16
+ jsr $26, HIDDEN_JUMPTARGET(exit)
+#endif
+
+ halt
+
+ .end __startcontext
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/msgctl.c b/libc/sysdeps/unix/sysv/linux/alpha/msgctl.c
new file mode 100644
index 000000000..a59911fe4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/msgctl.c
@@ -0,0 +1,121 @@
+/* Copyright (C) 1995,1997,1998,2000,2003,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/msg.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <string.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+struct __old_msqid_ds
+{
+ struct __old_ipc_perm msg_perm; /* structure describing operation permission */
+ struct msg *__unbounded __msg_first; /* pointer to first message on queue */
+ struct msg *__unbounded __msg_last; /* pointer to last message on queue */
+ __time_t msg_stime; /* time of last msgsnd command */
+ __time_t msg_rtime; /* time of last msgrcv command */
+ __time_t msg_ctime; /* time of last change */
+ struct wait_queue *__unbounded __wwait; /* ??? */
+ struct wait_queue *__unbounded __rwait; /* ??? */
+ unsigned short int __msg_cbytes; /* current number of bytes on queue */
+ unsigned short int msg_qnum; /* number of messages currently on queue */
+ unsigned short int msg_qbytes; /* max number of bytes allowed on queue */
+ __ipc_pid_t msg_lspid; /* pid of last msgsnd() */
+ __ipc_pid_t msg_lrpid; /* pid of last msgrcv() */
+};
+
+/* Allows to control internal state and destruction of message queue
+ objects. */
+int __new_msgctl (int, int, struct msqid_ds *);
+
+int
+__new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
+{
+ /* This is a misnomer -- Alpha had 32-bit uids at the beginning
+ of time. However, msg_qnum and msg_qbytes changed size at
+ the same time the size of uid changed elsewhere. */
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (msgctl, 3, msqid, cmd | __IPC_64, CHECK_1 (buf));
+#else
+ switch (cmd) {
+ case MSG_STAT:
+ case IPC_STAT:
+ case IPC_SET:
+ break;
+ default:
+ return INLINE_SYSCALL (msgctl, 3, msqid, cmd, CHECK_1 (buf));
+ }
+
+ {
+ int save_errno = errno, result;
+ struct __old_msqid_ds old;
+
+ /* Unfortunately there is no way how to find out for sure whether
+ we should use old or new msgctl. */
+ result = INLINE_SYSCALL (msgctl, 3, msqid, cmd | __IPC_64, CHECK_1 (buf));
+ if (result != -1 || errno != EINVAL)
+ return result;
+
+ __set_errno(save_errno);
+ if (cmd == IPC_SET)
+ {
+ old.msg_perm.uid = buf->msg_perm.uid;
+ old.msg_perm.gid = buf->msg_perm.gid;
+ old.msg_perm.mode = buf->msg_perm.mode;
+ old.msg_qbytes = buf->msg_qbytes;
+ if (old.msg_perm.uid != buf->msg_perm.uid ||
+ old.msg_perm.gid != buf->msg_perm.gid ||
+ old.msg_qbytes != buf->msg_qbytes)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+ result = INLINE_SYSCALL (msgctl, 3, msqid, cmd, __ptrvalue (&old));
+ if (result != -1 && cmd != IPC_SET)
+ {
+ memset(buf, 0, sizeof(*buf));
+ buf->msg_perm.__key = old.msg_perm.__key;
+ buf->msg_perm.uid = old.msg_perm.uid;
+ buf->msg_perm.gid = old.msg_perm.gid;
+ buf->msg_perm.cuid = old.msg_perm.cuid;
+ buf->msg_perm.cgid = old.msg_perm.cgid;
+ buf->msg_perm.mode = old.msg_perm.mode;
+ buf->msg_perm.__seq = old.msg_perm.__seq;
+ buf->msg_stime = old.msg_stime;
+ buf->msg_rtime = old.msg_rtime;
+ buf->msg_ctime = old.msg_ctime;
+ buf->__msg_cbytes = old.__msg_cbytes;
+ buf->msg_qnum = old.msg_qnum;
+ buf->msg_qbytes = old.msg_qbytes;
+ buf->msg_lspid = old.msg_lspid;
+ buf->msg_lrpid = old.msg_lrpid;
+ }
+ return result;
+ }
+#endif
+}
+
+#include <shlib-compat.h>
+versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/nldbl-abi.h b/libc/sysdeps/unix/sysv/linux/alpha/nldbl-abi.h
new file mode 100644
index 000000000..bd985cc59
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/nldbl-abi.h
@@ -0,0 +1,8 @@
+/* ABI version for long double switch.
+ This is used by the Versions and math_ldbl_opt.h files in
+ sysdeps/ieee754/ldbl-opt/. It gives the ABI version where
+ long double == double was replaced with proper long double
+ for libm *l functions and libc functions using long double. */
+
+#define NLDBL_VERSION GLIBC_2.4
+#define LONG_DOUBLE_COMPAT_VERSION GLIBC_2_4
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/oldglob.c b/libc/sysdeps/unix/sysv/linux/alpha/oldglob.c
new file mode 100644
index 000000000..6d9b79f2c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/oldglob.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 1998, 2000, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This file contains only wrappers around the real glob functions. It
+ became necessary since the glob_t structure changed. */
+#include <sys/types.h>
+#include <glob.h>
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+
+/* This is the old structure. The difference is that the gl_pathc and
+ gl_offs elements have type `int'. */
+typedef struct
+ {
+ int gl_pathc; /* Count of paths matched by the pattern. */
+ char **gl_pathv; /* List of matched pathnames. */
+ int gl_offs; /* Slots to reserve in `gl_pathv'. */
+ int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
+
+ /* If the GLOB_ALTDIRFUNC flag is set, the following functions
+ are used instead of the normal file access functions. */
+ void (*gl_closedir) (void *);
+ struct dirent *(*gl_readdir) (void *);
+ __ptr_t (*gl_opendir) (__const char *);
+ int (*gl_lstat) (__const char *, struct stat *);
+ int (*gl_stat) (__const char *, struct stat *);
+ } old_glob_t;
+
+
+int
+attribute_compat_text_section
+__old_glob (const char *pattern, int flags,
+ int (*errfunc) (const char *, int),
+ old_glob_t *pglob)
+{
+ glob_t correct;
+ int result;
+
+ /* Construct an object of correct type. */
+ correct.gl_pathc = pglob->gl_pathc;
+ correct.gl_pathv = pglob->gl_pathv;
+ correct.gl_offs = pglob->gl_offs;
+ correct.gl_flags = pglob->gl_flags;
+ correct.gl_closedir = pglob->gl_closedir;
+ correct.gl_readdir = pglob->gl_readdir;
+ correct.gl_opendir = pglob->gl_opendir;
+ correct.gl_lstat = pglob->gl_lstat;
+ correct.gl_stat = pglob->gl_stat;
+
+ result = glob (pattern, flags, errfunc, &correct);
+
+ /* And convert it back. */
+ pglob->gl_pathc = correct.gl_pathc;
+ pglob->gl_pathv = correct.gl_pathv;
+ pglob->gl_offs = correct.gl_offs;
+ pglob->gl_flags = correct.gl_flags;
+ pglob->gl_closedir = correct.gl_closedir;
+ pglob->gl_readdir = correct.gl_readdir;
+ pglob->gl_opendir = correct.gl_opendir;
+ pglob->gl_lstat = correct.gl_lstat;
+ pglob->gl_stat = correct.gl_stat;
+
+ return result;
+}
+compat_symbol (libc, __old_glob, glob, GLIBC_2_0);
+
+
+/* Free storage allocated in PGLOB by a previous `glob' call. */
+void
+attribute_compat_text_section
+__old_globfree (old_glob_t *pglob)
+{
+ glob_t correct;
+
+ /* We only need these two symbols. */
+ correct.gl_pathc = pglob->gl_pathc;
+ correct.gl_pathv = pglob->gl_pathv;
+ correct.gl_offs = pglob->gl_offs;
+
+ globfree (&correct);
+}
+compat_symbol (libc, __old_globfree, globfree, GLIBC_2_0);
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/pipe.S b/libc/sysdeps/unix/sysv/linux/alpha/pipe.S
new file mode 100644
index 000000000..1e7ec1c19
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/pipe.S
@@ -0,0 +1 @@
+#include <sysdeps/unix/alpha/pipe.S>
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/register-dump.h b/libc/sysdeps/unix/sysv/linux/alpha/register-dump.h
new file mode 100644
index 000000000..77f962952
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/register-dump.h
@@ -0,0 +1,157 @@
+/* Dump registers.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <string.h>
+
+/* We will print the register dump in this format:
+
+ V0: XXXXXXXXXXXXXXXX T0: XXXXXXXXXXXXXXXX T1: XXXXXXXXXXXXXXXX
+ T2: XXXXXXXXXXXXXXXX T3: XXXXXXXXXXXXXXXX T4: XXXXXXXXXXXXXXXX
+ T5: XXXXXXXXXXXXXXXX T6: XXXXXXXXXXXXXXXX T7: XXXXXXXXXXXXXXXX
+ S0: XXXXXXXXXXXXXXXX S1: XXXXXXXXXXXXXXXX S2: XXXXXXXXXXXXXXXX
+ S3: XXXXXXXXXXXXXXXX S4: XXXXXXXXXXXXXXXX S5: XXXXXXXXXXXXXXXX
+ S6: XXXXXXXXXXXXXXXX A0: XXXXXXXXXXXXXXXX A1: XXXXXXXXXXXXXXXX
+ A2: XXXXXXXXXXXXXXXX A3: XXXXXXXXXXXXXXXX A4: XXXXXXXXXXXXXXXX
+ A5: XXXXXXXXXXXXXXXX T8: XXXXXXXXXXXXXXXX T9: XXXXXXXXXXXXXXXX
+ T10: XXXXXXXXXXXXXXXX T11: XXXXXXXXXXXXXXXX RA: XXXXXXXXXXXXXXXX
+ T12: XXXXXXXXXXXXXXXX AT: XXXXXXXXXXXXXXXX GP: XXXXXXXXXXXXXXXX
+ SP: XXXXXXXXXXXXXXXX PC: XXXXXXXXXXXXXXXX
+
+ FP0: XXXXXXXXXXXXXXXX FP1: XXXXXXXXXXXXXXXX FP2: XXXXXXXXXXXXXXXX
+ FP3: XXXXXXXXXXXXXXXX FP4: XXXXXXXXXXXXXXXX FP5: XXXXXXXXXXXXXXXX
+ FP6: XXXXXXXXXXXXXXXX FP7: XXXXXXXXXXXXXXXX FP8: XXXXXXXXXXXXXXXX
+ FP9: XXXXXXXXXXXXXXXX FP10: XXXXXXXXXXXXXXXX FP11: XXXXXXXXXXXXXXXX
+ FP12: XXXXXXXXXXXXXXXX FP13: XXXXXXXXXXXXXXXX FP14: XXXXXXXXXXXXXXXX
+ FP15: XXXXXXXXXXXXXXXX FP16: XXXXXXXXXXXXXXXX FP17: XXXXXXXXXXXXXXXX
+ FP18: XXXXXXXXXXXXXXXX FP19: XXXXXXXXXXXXXXXX FP20: XXXXXXXXXXXXXXXX
+ FP21: XXXXXXXXXXXXXXXX FP22: XXXXXXXXXXXXXXXX FP23: XXXXXXXXXXXXXXXX
+ FP24: XXXXXXXXXXXXXXXX FP25: XXXXXXXXXXXXXXXX FP26: XXXXXXXXXXXXXXXX
+ FP27: XXXXXXXXXXXXXXXX FP28: XXXXXXXXXXXXXXXX FP29: XXXXXXXXXXXXXXXX
+ FP30: XXXXXXXXXXXXXXXX FPCR: XXXXXXXXXXXXXXXX
+
+ TA0: XXXXXXXXXXXXXXXX TA1: XXXXXXXXXXXXXXXX TA2: XXXXXXXXXXXXXXXX
+*/
+
+#define NREGS (32+32+3)
+
+static const char __attribute__((aligned(8))) regnames[NREGS][8] =
+{
+ " V0: ", " T0: ", " T1: ",
+ " T2: ", " T3: ", " T4: ",
+ " T5: ", " T6: ", " T7: ",
+ " S0: ", " S1: ", " S2: ",
+ " S3: ", " S4: ", " S5: ",
+ " S6: ", " A0: ", " A1: ",
+ " A2: ", " A3: ", " A4: ",
+ " A5: ", " T8: ", " T9: ",
+ " T10: ", " T11: ", " RA: ",
+ " T12: ", " AT: ", " GP: ",
+ " SP: ", " PC: ",
+
+ " FP0: ", " FP1: ", " FP2: ",
+ " FP3: ", " FP4: ", " FP5: ",
+ " FP6: ", " FP7: ", " FP8: ",
+ " FP9: ", " FP10: ", " FP11: ",
+ " FP12: ", " FP13: ", " FP14: ",
+ " FP15: ", " FP16: ", " FP17: ",
+ " FP18: ", " FP19: ", " FP20: ",
+ " FP21: ", " FP22: ", " FP23: ",
+ " FP24: ", " FP25: ", " FP26: ",
+ " FP27: ", " FP28: ", " FP29: ",
+ " FP30: ", " FPCR: ",
+
+ " TA0: ", " TA1: ", " TA2: "
+};
+
+#define O(FIELD, LF) offsetof(struct sigcontext, FIELD) + LF
+
+static const int offsets[NREGS] =
+{
+ O(sc_regs[0], 0), O(sc_regs[1], 0), O(sc_regs[2], 1),
+ O(sc_regs[3], 0), O(sc_regs[4], 0), O(sc_regs[5], 1),
+ O(sc_regs[6], 0), O(sc_regs[7], 0), O(sc_regs[8], 1),
+ O(sc_regs[9], 0), O(sc_regs[10], 0), O(sc_regs[11], 1),
+ O(sc_regs[12], 0), O(sc_regs[13], 0), O(sc_regs[14], 1),
+ O(sc_regs[15], 0), O(sc_regs[16], 0), O(sc_regs[17], 1),
+ O(sc_regs[18], 0), O(sc_regs[19], 0), O(sc_regs[20], 1),
+ O(sc_regs[21], 0), O(sc_regs[22], 0), O(sc_regs[23], 1),
+ O(sc_regs[24], 0), O(sc_regs[25], 0), O(sc_regs[26], 1),
+ O(sc_regs[27], 0), O(sc_regs[28], 0), O(sc_regs[29], 1),
+ O(sc_regs[30], 0), O(sc_pc, 2),
+
+ O(sc_fpregs[0], 0), O(sc_fpregs[1], 0), O(sc_fpregs[2], 1),
+ O(sc_fpregs[3], 0), O(sc_fpregs[4], 0), O(sc_fpregs[5], 1),
+ O(sc_fpregs[6], 0), O(sc_fpregs[7], 0), O(sc_fpregs[8], 1),
+ O(sc_fpregs[9], 0), O(sc_fpregs[10], 0), O(sc_fpregs[11], 1),
+ O(sc_fpregs[12], 0), O(sc_fpregs[13], 0), O(sc_fpregs[14], 1),
+ O(sc_fpregs[15], 0), O(sc_fpregs[16], 0), O(sc_fpregs[17], 1),
+ O(sc_fpregs[18], 0), O(sc_fpregs[19], 0), O(sc_fpregs[20], 1),
+ O(sc_fpregs[21], 0), O(sc_fpregs[22], 0), O(sc_fpregs[23], 1),
+ O(sc_fpregs[24], 0), O(sc_fpregs[25], 0), O(sc_fpregs[26], 1),
+ O(sc_fpregs[27], 0), O(sc_fpregs[28], 0), O(sc_fpregs[29], 1),
+ O(sc_fpregs[30], 0), O(sc_fpcr, 2),
+
+ O(sc_traparg_a0, 0), O(sc_traparg_a1, 0), O(sc_traparg_a2, 1)
+};
+
+#undef O
+
+static void
+register_dump (int fd, struct sigcontext *ctx)
+{
+ char buf[NREGS*(8+16) + 25 + 80];
+ char *p = buf;
+ size_t i;
+
+ p = stpcpy (p, "Register dump:\n\n");
+
+ for (i = 0; i < NREGS; ++i)
+ {
+ int this_offset, this_lf;
+ unsigned long val;
+ signed long j;
+
+ this_offset = offsets[i];
+ this_lf = this_offset & 7;
+
+ val = *(unsigned long *)(((size_t)ctx + this_offset) & -8);
+
+ memcpy (p, regnames[i], 8);
+ p += 8;
+
+ for (j = 60; j >= 0; j -= 4)
+ {
+ unsigned long x = (val >> j) & 15;
+ x += x < 10 ? '0' : 'a' - 10;
+ *p++ = x;
+ }
+
+ if (this_lf > 0)
+ {
+ if (this_lf > 1)
+ *p++ = '\n';
+ *p++ = '\n';
+ }
+ }
+
+ write (fd, buf, p - buf);
+}
+
+#define REGISTER_DUMP register_dump (fd, ctx)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/rt_sigaction.S b/libc/sysdeps/unix/sysv/linux/alpha/rt_sigaction.S
new file mode 100644
index 000000000..e27949fef
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/rt_sigaction.S
@@ -0,0 +1,120 @@
+/* Copyright (C) 1998, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson <rth@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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* On Alpha we desparately want to avoid having to issue an imb. Ordinarily
+ the kernel would have to issue one after setting up the signal return
+ stack, but the Linux rt_sigaction syscall is prepared to accept a pointer
+ to the sigreturn syscall, instead of inlining it on the stack.
+
+ This just about halves signal delivery time. */
+
+ .text
+
+ENTRY(__syscall_rt_sigaction)
+ .frame sp,0,ra,0
+ ldgp gp,0(pv)
+#ifdef PROF
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+#endif
+ .prologue 1
+
+ beq a1, 0f
+ ldl t0, 8(a1) # sa_flags
+
+ /* The unwinder will subtract one from the return address when
+ attempting to find the call instruction that led us here.
+ Since we didn't get here via a normal call, if we do nothing
+ we would pick up the wrong symbol and the wrong FDE. Account
+ for this by adding a nop to the start of the function and
+ then skipping it here by adding 4. */
+ ldah a4, __syscall_sigreturn+4(gp) !gprelhigh
+ ldah t1, __syscall_rt_sigreturn+4(gp) !gprelhigh
+ lda a4, __syscall_sigreturn+4(a4) !gprellow
+ lda t1, __syscall_rt_sigreturn+4(t1) !gprellow
+ and t0, 0x40, t0 # SA_SIGINFO
+ cmovne t0, t1, a4
+
+0: ldi v0, __NR_rt_sigaction
+ callsys
+ bne a3, SYSCALL_ERROR_LABEL
+ ret
+
+PSEUDO_END(__syscall_rt_sigaction)
+
+/* To enable unwinding through the signal frame without special hackery
+ elsewhere, describe the entire struct sigcontext with unwind info.
+
+ In order to minimize the size of the encoding, we set the CFA to the
+ end of the sigcontext, which makes all of the registers have small
+ negative offsets from that. */
+
+ .macro SIGCONTEXT_REGS_I base, from=0
+ cfi_offset (\from, \base + (4 + \from) * 8)
+ .if 30-\from
+ SIGCONTEXT_REGS_I \base, "(\from+1)"
+ .endif
+ .endm
+
+ .macro SIGCONTEXT_REGS_F base, from=32
+ cfi_offset (\from, \base + (4 + 1 + \from) * 8)
+ .if 62-\from
+ SIGCONTEXT_REGS_F \base, "(\from+1)"
+ .endif
+ .endm
+
+ .macro SIGCONTEXT_REGS base
+ SIGCONTEXT_REGS_I \base
+ SIGCONTEXT_REGS_F \base
+ cfi_offset (63, \base + (4 + 32 + 1 + 32) * 8)
+ cfi_offset (64, \base + 2 * 8)
+ .endm
+
+ .align 4
+ nop
+ nop
+ nop
+
+ cfi_startproc
+ cfi_return_column (64)
+ SIGCONTEXT_REGS -648
+
+ cfi_def_cfa_offset (648)
+__syscall_sigreturn:
+ nop
+ mov sp, a0
+ ldi v0, __NR_sigreturn
+ callsys
+ .size __syscall_sigreturn, .-__syscall_sigreturn
+ .type __syscall_sigreturn, @function
+
+ cfi_def_cfa_offset (176 + 648)
+__syscall_rt_sigreturn:
+ nop
+ mov sp,a0
+ ldi v0,__NR_rt_sigreturn
+ callsys
+ .size __syscall_rt_sigreturn, .-__syscall_rt_sigreturn
+ .type __syscall_rt_sigreturn, @function
+
+ cfi_endproc
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/select.S b/libc/sysdeps/unix/sysv/linux/alpha/select.S
new file mode 100644
index 000000000..35a81e949
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/select.S
@@ -0,0 +1,241 @@
+/* Copyright (C) 1998,2002,2003,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep-cancel.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+
+.text
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+#define SELECT __select_tv64
+#else
+#define SELECT __select
+#endif
+
+#if defined __ASSUME_TIMEVAL64
+PSEUDO(SELECT, select, 5)
+ ret
+PSEUDO_END(SELECT)
+#else
+/* The problem here is that initially we made struct timeval compatible with
+ OSF/1, using int32. But we defined time_t with uint64, and later found
+ that POSIX requires tv_sec to be time_t.
+
+ So now we have to do compatibility stuff. */
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. */
+.comm __libc_missing_axp_tv64, 4
+
+LEAF(SELECT, 64)
+ ldgp gp, 0(pv)
+ subq sp, 64, sp
+#ifdef PROF
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+#endif
+ stq ra, 40(sp)
+ .mask 0x4000000, 40-64
+ .prologue 1
+
+#ifdef CENABLE
+ SINGLE_THREAD_P (t1)
+#else
+ ldl t0, __libc_missing_axp_tv64
+#endif
+
+ /* Save timeout early, since we'll need to recover this after
+ the system call. */
+ stq a4, 48(sp)
+
+#ifdef CENABLE
+ bne t1, $do_cancel
+#endif
+
+ bne t0, $do32
+
+ /* Save arguments in case we do need to fall back. */
+ stq a0, 8(sp)
+ stq a1, 16(sp)
+ stq a2, 24(sp)
+ stq a3, 32(sp)
+
+ ldi v0, SYS_ify(select)
+ callsys
+ bne a3, $err64
+
+ /* Everything ok. */
+ addq sp, 64, sp
+ ret
+
+ /* If we didn't get ENOSYS, it is a real error. */
+ .align 3
+$err64: cmpeq v0, ENOSYS, t0
+ beq t0, $error
+ stl t0, __libc_missing_axp_tv64
+
+ /* Recover the saved arguments. */
+ ldq a4, 48(sp)
+ ldq a3, 32(sp)
+ ldq a2, 24(sp)
+ ldq a1, 16(sp)
+ ldq a0, 8(sp)
+
+ .align 3
+$do32:
+ /* If the timeout argument is present bounce to the smaller fmt. */
+ beq a4, 1f
+ ldq t0, 0(a4)
+ ldq t1, 8(a4)
+ stl t0, 0(sp)
+ stl t1, 4(sp)
+ mov sp, a4
+
+1: ldi v0, SYS_ify(osf_select)
+ callsys
+ bne a3, $error
+
+ /* ... and bounce the remaining timeout back. */
+ ldq a4, 48(sp)
+ beq a4, 2f
+ ldl t0, 0(sp)
+ ldl t1, 4(sp)
+ stq t0, 0(a4)
+ stq t1, 8(a4)
+
+2: addq sp, 64, sp
+ ret
+
+#ifdef CENABLE
+ .align 3
+$do_cancel:
+ /* Save arguments. */
+ stq a0, 8(sp)
+ stq a1, 16(sp)
+ stq a2, 24(sp)
+ stq a3, 32(sp)
+
+ CENABLE
+ mov v0, ra
+
+ ldl t0, __libc_missing_axp_tv64
+ bne t0, $do_cancel32
+
+ /* Recover the saved arguments. */
+ ldq a4, 48(sp)
+ ldq a3, 32(sp)
+ ldq a2, 24(sp)
+ ldq a1, 16(sp)
+ ldq a0, 8(sp)
+
+ ldi v0, SYS_ify(select)
+ callsys
+
+ mov ra, a0
+ bne a3, $cancel_err64
+
+ stq v0, 8(sp)
+ CDISABLE
+ ldq v0, 8(sp)
+ ldq ra, 40(sp)
+
+ /* Everything ok. */
+ addq sp, 64, sp
+ ret
+
+ /* If we didn't get ENOSYS, it is a real error. */
+ .align 3
+$cancel_err64:
+ cmpeq v0, ENOSYS, t0
+ beq t0, $cancel_error
+ stl t0, __libc_missing_axp_tv64
+
+ /* Recover the saved arguments. */
+ .align 3
+$do_cancel32:
+ ldq a4, 48(sp)
+ ldq a3, 32(sp)
+ ldq a2, 24(sp)
+ ldq a1, 16(sp)
+ ldq a0, 8(sp)
+
+ /* If the timeout argument is present bounce to the smaller fmt. */
+ beq a4, 1f
+ ldq t0, 0(a4)
+ ldq t1, 8(a4)
+ stl t0, 0(sp)
+ stl t1, 4(sp)
+ mov sp, a4
+
+1: ldi v0, SYS_ify(osf_select)
+ callsys
+
+ mov ra, a0
+ bne a3, $cancel_error
+
+ /* ... and bounce the remaining timeout back. */
+ ldq a4, 48(sp)
+ beq a4, 2f
+ ldl t0, 0(sp)
+ ldl t1, 4(sp)
+ stq t0, 0(a4)
+ stq t1, 8(a4)
+
+2: stq v0, 8(sp)
+ CDISABLE
+ ldq v0, 8(sp)
+ ldq ra, 40(sp)
+
+ addq sp, 64, sp
+ ret
+
+ .align 3
+$cancel_error:
+ stq v0, 8(sp)
+ CDISABLE
+ ldq v0, 8(sp)
+ ldq ra, 40(sp)
+#endif
+
+ .align 3
+$error:
+ addq sp, 64, sp
+ SYSCALL_ERROR_HANDLER
+
+END(SELECT)
+#endif /* __ASSUME_TIMEVAL64 */
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+default_symbol_version (__select_tv64, __select, GLIBC_2.1)
+
+/* It seems to me to be a misfeature of the assembler that we can only
+ have one version-alias per symbol. So create an alias ourselves.
+ The 'p' is for 'public'. *Shrug* */
+strong_alias (__select_tv64, __select_tv64p)
+default_symbol_version (__select_tv64p, select, GLIBC_2.1)
+libc_hidden_ver (__select_tv64, __select)
+strong_alias (__select_tv64, __libc_select)
+#else
+strong_alias (__select, __libc_select)
+weak_alias (__select, select)
+libc_hidden_def (__select)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/semctl.c b/libc/sysdeps/unix/sysv/linux/alpha/semctl.c
new file mode 100644
index 000000000..9957f983b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/semctl.c
@@ -0,0 +1,136 @@
+/* Copyright (C) 1995,1997,1998,2000,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <sys/sem.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <string.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+struct __old_semid_ds
+{
+ struct __old_ipc_perm sem_perm; /* operation permission struct */
+ __time_t sem_otime; /* last semop() time */
+ __time_t sem_ctime; /* last time changed by semctl() */
+ struct sem *__sembase; /* ptr to first semaphore in array */
+ struct sem_queue *__sem_pending; /* pending operations */
+ struct sem_queue *__sem_pending_last; /* last pending operation */
+ struct sem_undo *__undo; /* ondo requests on this array */
+ unsigned short int sem_nsems; /* number of semaphores in set */
+};
+
+/* Define a `union semun' suitable for Linux here. */
+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 */
+};
+
+#include <bp-checks.h>
+#include <bp-semctl.h> /* definition of CHECK_SEMCTL needs union semum */
+
+/* Return identifier for array of NSEMS semaphores associated with
+ KEY. */
+int __new_semctl (int semid, int semnum, int cmd, ...);
+
+int
+__new_semctl (int semid, int semnum, int cmd, ...)
+{
+ union semun arg;
+ va_list ap;
+
+ va_start (ap, cmd);
+
+ /* Get the argument. */
+ arg = va_arg (ap, union semun);
+
+ va_end (ap);
+
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (semctl, 4, semid, semnum, cmd | __IPC_64,
+ CHECK_SEMCTL (&arg, semid, cmd | __IPC_64)->array);
+#else
+ switch (cmd) {
+ case SEM_STAT:
+ case IPC_STAT:
+ case IPC_SET:
+ break;
+ default:
+ return INLINE_SYSCALL (semctl, 4, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd)->array);
+ }
+
+ {
+ int save_errno = errno, result;
+ struct __old_semid_ds old;
+ struct semid_ds *buf;
+
+ /* Unfortunately there is no way how to find out for sure whether
+ we should use old or new semctl. */
+ result = INLINE_SYSCALL (semctl, 4, semid, semnum, cmd | __IPC_64,
+ CHECK_SEMCTL (&arg, semid, cmd | __IPC_64)->array);
+ if (result != -1 || errno != EINVAL)
+ return result;
+
+ __set_errno(save_errno);
+ buf = arg.buf;
+ arg.buf = (void *)&old;
+ if (cmd == IPC_SET)
+ {
+ old.sem_perm.uid = buf->sem_perm.uid;
+ old.sem_perm.gid = buf->sem_perm.gid;
+ old.sem_perm.mode = buf->sem_perm.mode;
+ if (old.sem_perm.uid != buf->sem_perm.uid ||
+ old.sem_perm.gid != buf->sem_perm.gid)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+ result = INLINE_SYSCALL (semctl, 4, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd)->array);
+ if (result != -1 && cmd != IPC_SET)
+ {
+ memset(buf, 0, sizeof(*buf));
+ buf->sem_perm.__key = old.sem_perm.__key;
+ buf->sem_perm.uid = old.sem_perm.uid;
+ buf->sem_perm.gid = old.sem_perm.gid;
+ buf->sem_perm.cuid = old.sem_perm.cuid;
+ buf->sem_perm.cgid = old.sem_perm.cgid;
+ buf->sem_perm.mode = old.sem_perm.mode;
+ buf->sem_perm.__seq = old.sem_perm.__seq;
+ buf->sem_otime = old.sem_otime;
+ buf->sem_ctime = old.sem_ctime;
+ buf->sem_nsems = old.sem_nsems;
+ }
+ return result;
+ }
+#endif
+}
+
+#include <shlib-compat.h>
+versioned_symbol (libc, __new_semctl, semctl, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/setcontext.S b/libc/sysdeps/unix/sysv/linux/alpha/setcontext.S
new file mode 100644
index 000000000..27abfd0c1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/setcontext.S
@@ -0,0 +1,35 @@
+/* Install given context.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <ucontext-offsets.h>
+
+
+/* In case the user fiddled it, copy the "official" signal mask
+ from the ucontext_t into the sigcontext structure. */
+#undef PSEUDO_PREPARE_ARGS
+#define PSEUDO_PREPARE_ARGS \
+ ldq $0, UC_SIGMASK($16); \
+ stq $0, UC_SIGCTX+SC_MASK($16); \
+ lda $16, UC_SIGCTX($16);
+
+PSEUDO(__setcontext, sigreturn, 1)
+ ret
+PSEUDO_END(__setcontext)
+weak_alias (__setcontext, setcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/setfpucw.c b/libc/sysdeps/unix/sysv/linux/alpha/setfpucw.c
new file mode 100644
index 000000000..a7e3a5581
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/setfpucw.c
@@ -0,0 +1,80 @@
+/* Set FP exception mask and rounding mode.
+ Copyright (C) 1996, 1997, 1998, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <fpu_control.h>
+#include <asm/fpu.h>
+
+extern void __ieee_set_fp_control (unsigned long);
+libc_hidden_proto(__ieee_set_fp_control)
+
+extern unsigned long __ieee_get_fp_control (void);
+libc_hidden_proto(__ieee_get_fp_control)
+
+static inline unsigned long
+rdfpcr (void)
+{
+ unsigned long fpcr;
+ asm ("excb; mf_fpcr %0" : "=f"(fpcr));
+ return fpcr;
+}
+
+
+static inline void
+wrfpcr (unsigned long fpcr)
+{
+ asm volatile ("mt_fpcr %0; excb" : : "f"(fpcr));
+}
+
+
+void
+__setfpucw (fpu_control_t fpu_control)
+{
+ unsigned long fpcr = 0, fpcw = 0;
+
+ if (!fpu_control)
+ fpu_control = _FPU_DEFAULT;
+
+ /* first, set dynamic rounding mode: */
+
+ fpcr = rdfpcr();
+ fpcr &= ~FPCR_DYN_MASK;
+ switch (fpu_control & 0xc00)
+ {
+ case _FPU_RC_NEAREST: fpcr |= FPCR_DYN_NORMAL; break;
+ case _FPU_RC_DOWN: fpcr |= FPCR_DYN_MINUS; break;
+ case _FPU_RC_UP: fpcr |= FPCR_DYN_PLUS; break;
+ case _FPU_RC_ZERO: fpcr |= FPCR_DYN_CHOPPED; break;
+ }
+ wrfpcr(fpcr);
+
+ /* now tell kernel about traps that we like to hear about: */
+
+ fpcw = __ieee_get_fp_control();
+ fpcw &= ~IEEE_TRAP_ENABLE_MASK;
+
+ if (!(fpu_control & _FPU_MASK_IM)) fpcw |= IEEE_TRAP_ENABLE_INV;
+ if (!(fpu_control & _FPU_MASK_DM)) fpcw |= IEEE_TRAP_ENABLE_UNF;
+ if (!(fpu_control & _FPU_MASK_ZM)) fpcw |= IEEE_TRAP_ENABLE_DZE;
+ if (!(fpu_control & _FPU_MASK_OM)) fpcw |= IEEE_TRAP_ENABLE_OVF;
+ if (!(fpu_control & _FPU_MASK_PM)) fpcw |= IEEE_TRAP_ENABLE_INE;
+
+ __fpu_control = fpu_control; /* update global copy */
+
+ __ieee_set_fp_control(fpcw);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/setitimer.S b/libc/sysdeps/unix/sysv/linux/alpha/setitimer.S
new file mode 100644
index 000000000..59caeac68
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/setitimer.S
@@ -0,0 +1,137 @@
+/* Copyright (C) 1998, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+
+.text
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+#define SETITIMER __setitimer_tv64
+#else
+#define SETITIMER __setitimer
+#endif
+
+#if defined __ASSUME_TIMEVAL64
+PSEUDO(SETITIMER, setitimer, 3)
+ ret
+PSEUDO_END(SETITIMER)
+#else
+/* The problem here is that initially we made struct timeval compatible with
+ OSF/1, using int32. But we defined time_t with uint64, and later found
+ that POSIX requires tv_sec to be time_t.
+
+ So now we have to do compatibility stuff. */
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. */
+.comm __libc_missing_axp_tv64, 4
+
+LEAF(SETITIMER, 48)
+ ldgp gp, 0(pv)
+ subq sp, 48, sp
+#ifdef PROF
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+#endif
+ .prologue 1
+
+ ldl t0, __libc_missing_axp_tv64
+
+ /* Save arguments in case we do need to fall back. */
+ stq a0, 0(sp)
+ stq a1, 8(sp)
+ stq a2, 16(sp)
+
+ bne t0, $do32
+
+ ldi v0, SYS_ify(setitimer)
+ callsys
+ bne a3, $err64
+
+ /* Everything ok. */
+ addq sp, 48, sp
+ ret
+
+ /* If we didn't get ENOSYS, it is a real error. */
+ .align 3
+$err64: cmpeq v0, ENOSYS, t0
+ beq t0, $error
+ stl t0, __libc_missing_axp_tv64
+
+ /* Recover the saved arguments. */
+ ldq a2, 16(sp)
+ ldq a1, 8(sp)
+ ldq a0, 0(sp)
+
+ .align 3
+$do32:
+ /* Conditionally bounce new value down. */
+ beq a1, 1f
+ ldq t0, 0(a1)
+ ldq t1, 8(a1)
+ ldq t2, 16(a1)
+ ldq t3, 24(a1)
+ stl t0, 32(sp)
+ stl t1, 36(sp)
+ stl t2, 40(sp)
+ stl t3, 44(sp)
+ addq sp, 32, a1
+
+1: ldi v0, SYS_ify(osf_setitimer)
+ callsys
+ bne a3, $error
+
+ /* Conditionaly bounce old value up. */
+ ldq a2, 16(sp)
+ bne a2, 2f
+ ldl t0, 0(a2)
+ ldl t1, 4(a2)
+ ldl t2, 8(a2)
+ ldl t3, 12(a2)
+ stq t0, 0(a2)
+ stq t1, 8(a2)
+ stq t2, 48(a2)
+ stq t3, 24(a2)
+
+2: addq sp, 48, sp
+ ret
+
+ .align 3
+$error:
+ addq sp, 48, sp
+ SYSCALL_ERROR_HANDLER
+
+END(SETITIMER)
+#endif /* __ASSUME_TIMEVAL64 */
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+default_symbol_version (__setitimer_tv64, __setitimer, GLIBC_2.1)
+
+/* It seems to me to be a misfeature of the assembler that we can only
+ have one version-alias per symbol. So create an alias ourselves.
+ The 'p' is for 'public'. *Shrug* */
+strong_alias (__setitimer_tv64, __setitimer_tv64p)
+default_symbol_version (__setitimer_tv64p, setitimer, GLIBC_2.1)
+#else
+weak_alias (__setitimer, setitimer)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/setregid.c b/libc/sysdeps/unix/sysv/linux/alpha/setregid.c
new file mode 100644
index 000000000..0973fe4ac
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/setregid.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+
+
+int
+__setregid (gid_t rgid, gid_t egid)
+{
+ return INLINE_SETXID_SYSCALL (setregid, 2, (int) rgid, (int) egid);
+}
+#ifndef __setregid
+weak_alias (__setregid, setregid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/setresgid.c b/libc/sysdeps/unix/sysv/linux/alpha/setresgid.c
new file mode 100644
index 000000000..50e29e3c7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/setresgid.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+
+
+int
+__setresgid (gid_t rgid, gid_t egid, gid_t sgid)
+{
+ return INLINE_SETXID_SYSCALL (setresgid, 3, (int) rgid,
+ (int) egid, (int) sgid);
+}
+libc_hidden_def (__setresgid)
+#ifndef __setresgid
+weak_alias (__setresgid, setresgid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/setresuid.c b/libc/sysdeps/unix/sysv/linux/alpha/setresuid.c
new file mode 100644
index 000000000..e76413bf6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/setresuid.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+
+
+int
+__setresuid (uid_t ruid, uid_t euid, uid_t suid)
+{
+ return INLINE_SETXID_SYSCALL (setresuid, 3, (int) ruid,
+ (int) euid, (int) suid);
+}
+libc_hidden_def (__setresuid)
+#ifndef __setresuid
+weak_alias (__setresuid, setresuid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/setreuid.c b/libc/sysdeps/unix/sysv/linux/alpha/setreuid.c
new file mode 100644
index 000000000..a23a34792
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/setreuid.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+
+
+int
+__setreuid (uid_t ruid, uid_t euid)
+{
+ return INLINE_SETXID_SYSCALL (setreuid, 2, (int) ruid, (int) euid);
+}
+#ifndef __setreuid
+weak_alias (__setreuid, setreuid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/settimeofday.S b/libc/sysdeps/unix/sysv/linux/alpha/settimeofday.S
new file mode 100644
index 000000000..e39eadc20
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/settimeofday.S
@@ -0,0 +1,118 @@
+/* Copyright (C) 1998, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+
+.text
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+#define SETTIMEOFDAY __settimeofday_tv64
+#else
+#define SETTIMEOFDAY __settimeofday
+#endif
+
+#if defined __ASSUME_TIMEVAL64
+PSEUDO(SETTIMEOFDAY, settimeofday, 2)
+ ret
+PSEUDO_END(SETTIMEOFDAY)
+#else
+/* The problem here is that initially we made struct timeval compatible with
+ OSF/1, using int32. But we defined time_t with uint64, and later found
+ that POSIX requires tv_sec to be time_t.
+
+ So now we have to do compatibility stuff. */
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. */
+.comm __libc_missing_axp_tv64, 4
+
+LEAF(SETTIMEOFDAY, 16)
+ ldgp gp, 0(pv)
+ subq sp, 16, sp
+#ifdef PROF
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+#endif
+ .prologue 1
+
+ ldl t0, __libc_missing_axp_tv64
+ bne t0, $do32
+
+ /* Save arguments in case we do need to fall back. */
+ stq a0, 0(sp)
+ stq a1, 8(sp)
+
+ ldi v0, SYS_ify(settimeofday)
+ callsys
+ bne a3, $err64
+
+ /* Everything ok. */
+ addq sp, 16, sp
+ ret
+
+ /* If we didn't get ENOSYS, it is a real error. */
+ .align 3
+$err64: cmpeq v0, ENOSYS, t0
+ beq t0, $error
+ stl t0, __libc_missing_axp_tv64
+
+ /* Recover the saved arguments. */
+ ldq a1, 8(sp)
+ ldq a0, 0(sp)
+
+ .align 3
+$do32:
+ /* Conditionally bounce the timeval down. */
+ beq a0, 1f
+ ldq t0, 0(a0)
+ ldq t1, 8(a0)
+ stl t0, 0(sp)
+ stl t1, 4(sp)
+ mov sp, a0
+
+1: ldi v0, SYS_ify(osf_settimeofday)
+ callsys
+ bne a3, $error
+
+ addq sp, 16, sp
+ ret
+
+ .align 3
+$error:
+ addq sp, 16, sp
+ SYSCALL_ERROR_HANDLER
+
+END(SETTIMEOFDAY)
+#endif /* __ASSUME_TIMEVAL64 */
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+default_symbol_version (__settimeofday_tv64, __settimeofday, GLIBC_2.1)
+
+/* It seems to me to be a misfeature of the assembler that we can only
+ have one version-alias per symbol. So create an alias ourselves.
+ The 'p' is for 'public'. *Shrug* */
+strong_alias (__settimeofday_tv64, __settimeofday_tv64p)
+default_symbol_version (__settimeofday_tv64p, settimeofday, GLIBC_2.1)
+#else
+weak_alias (__settimeofday, settimeofday)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/shmctl.c b/libc/sysdeps/unix/sysv/linux/alpha/shmctl.c
new file mode 100644
index 000000000..e63211fa0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/shmctl.c
@@ -0,0 +1,135 @@
+/* Copyright (C) 1995,1997,1998,2000,2003,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/shm.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <string.h>
+#include <sys/syscall.h>
+#include <bits/wordsize.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+struct __old_shmid_ds
+{
+ struct __old_ipc_perm shm_perm; /* operation permission struct */
+ int shm_segsz; /* size of segment in bytes */
+ __time_t shm_atime; /* time of last shmat() */
+ __time_t shm_dtime; /* time of last shmdt() */
+ __time_t shm_ctime; /* time of last change by shmctl() */
+ __ipc_pid_t shm_cpid; /* pid of creator */
+ __ipc_pid_t shm_lpid; /* pid of last shmop */
+ unsigned short int shm_nattch; /* number of current attaches */
+ unsigned short int __shm_npages; /* size of segment (pages) */
+ unsigned long int *__unbounded __shm_pages; /* array of ptrs to frames -> SHMMAX */
+ struct vm_area_struct *__unbounded __attaches; /* descriptors for attaches */
+};
+
+struct __old_shminfo
+{
+ int shmmax;
+ int shmmin;
+ int shmmni;
+ int shmseg;
+ int shmall;
+};
+
+/* Provide operations to control over shared memory segments. */
+int __new_shmctl (int, int, struct shmid_ds *);
+
+int
+__new_shmctl (int shmid, int cmd, struct shmid_ds *buf)
+{
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (shmctl, 3, shmid, cmd | __IPC_64, CHECK_1 (buf));
+#else
+ switch (cmd) {
+ case SHM_STAT:
+ case IPC_STAT:
+ case IPC_SET:
+ case IPC_INFO:
+ break;
+ default:
+ return INLINE_SYSCALL (shmctl, 3, shmid, cmd, CHECK_1 (buf));
+ }
+
+ {
+ int save_errno = errno, result;
+ struct __old_shmid_ds old;
+
+ /* Unfortunately there is no way how to find out for sure whether
+ we should use old or new shmctl. */
+ result = INLINE_SYSCALL (shmctl, 3, shmid, cmd | __IPC_64, CHECK_1 (buf));
+ if (result != -1 || errno != EINVAL)
+ return result;
+
+ __set_errno(save_errno);
+ if (cmd == IPC_SET)
+ {
+ old.shm_perm.uid = buf->shm_perm.uid;
+ old.shm_perm.gid = buf->shm_perm.gid;
+ old.shm_perm.mode = buf->shm_perm.mode;
+ if (old.shm_perm.uid != buf->shm_perm.uid ||
+ old.shm_perm.gid != buf->shm_perm.gid)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+ result = INLINE_SYSCALL (shmctl, 3, shmid, cmd, __ptrvalue (&old));
+ if (result != -1 && (cmd == SHM_STAT || cmd == IPC_STAT))
+ {
+ memset(buf, 0, sizeof(*buf));
+ buf->shm_perm.__key = old.shm_perm.__key;
+ buf->shm_perm.uid = old.shm_perm.uid;
+ buf->shm_perm.gid = old.shm_perm.gid;
+ buf->shm_perm.cuid = old.shm_perm.cuid;
+ buf->shm_perm.cgid = old.shm_perm.cgid;
+ buf->shm_perm.mode = old.shm_perm.mode;
+ buf->shm_perm.__seq = old.shm_perm.__seq;
+ buf->shm_atime = old.shm_atime;
+ buf->shm_dtime = old.shm_dtime;
+ buf->shm_ctime = old.shm_ctime;
+ buf->shm_segsz = old.shm_segsz;
+ buf->shm_nattch = old.shm_nattch;
+ buf->shm_cpid = old.shm_cpid;
+ buf->shm_lpid = old.shm_lpid;
+ }
+ else if (result != -1 && cmd == IPC_INFO)
+ {
+ struct __old_shminfo *oldi = (void *)&old;
+ struct shminfo *i = (struct shminfo *)buf;
+
+ memset(i, 0, sizeof(*i));
+ i->shmmax = oldi->shmmax;
+ i->shmmin = oldi->shmmin;
+ i->shmmni = oldi->shmmni;
+ i->shmseg = oldi->shmseg;
+ i->shmall = oldi->shmall;
+ }
+ return result;
+ }
+#endif
+}
+
+#include <shlib-compat.h>
+versioned_symbol (libc, __new_shmctl, shmctl, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sigaction.c b/libc/sysdeps/unix/sysv/linux/alpha/sigaction.c
new file mode 100644
index 000000000..26b081d9a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sigaction.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <sys/cdefs.h>
+#include <stddef.h>
+
+/*
+ * In order to get the hidden arguments for rt_sigaction set up
+ * properly, we need to call the assembly version. Detect this in the
+ * INLINE_SYSCALL macro, and fail to expand inline in that case.
+ */
+
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...) \
+ (__NR_##name == __NR_rt_sigaction \
+ ? __syscall_rt_sigaction(args) \
+ : INLINE_SYSCALL1(name, nr, args))
+
+struct kernel_sigaction;
+extern int __syscall_rt_sigaction (int, const struct kernel_sigaction *__unbounded,
+ struct kernel_sigaction *__unbounded, size_t);
+
+#include <sysdeps/unix/sysv/linux/sigaction.c>
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h b/libc/sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h
new file mode 100644
index 000000000..16c5dcbc5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h
@@ -0,0 +1,25 @@
+/* Copyright (C) 1999, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define SIGCONTEXT int _code, struct sigcontext *
+#define SIGCONTEXT_EXTRA_ARGS _code,
+#define GET_PC(ctx) ((void *) (ctx)->sc_pc)
+#define GET_FRAME(ctx) ((void *) (ctx)->sc_regs[15])
+#define GET_STACK(ctx) ((void *) (ctx)->sc_regs[30])
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sigprocmask.c b/libc/sysdeps/unix/sysv/linux/alpha/sigprocmask.c
new file mode 100644
index 000000000..1916111a2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sigprocmask.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 1993, 1995, 1997, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger (davidm@azstarnet.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sysdep.h>
+#include <signal.h>
+
+/* When there is kernel support for more than 64 signals, we'll have to
+ switch to a new system call convention here. */
+
+int
+__sigprocmask (int how, const sigset_t *set, sigset_t *oset)
+{
+ unsigned long int setval;
+ long result;
+
+ if (set)
+ setval = set->__val[0];
+ else
+ {
+ setval = 0;
+ how = SIG_BLOCK; /* ensure blocked mask doesn't get changed */
+ }
+
+ result = INLINE_SYSCALL (osf_sigprocmask, 2, how, setval);
+ if (result == -1)
+ /* If there are ever more than 63 signals, we need to recode this
+ in assembler since we wouldn't be able to distinguish a mask of
+ all 1s from -1, but for now, we're doing just fine... */
+ return result;
+
+ if (oset)
+ {
+ oset->__val[0] = result;
+ result = _SIGSET_NWORDS;
+ while (--result > 0)
+ oset->__val[result] = 0;
+ }
+ return 0;
+}
+
+weak_alias (__sigprocmask, sigprocmask);
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sigsuspend.S b/libc/sysdeps/unix/sysv/linux/alpha/sigsuspend.S
new file mode 100644
index 000000000..48c3f271c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sigsuspend.S
@@ -0,0 +1,33 @@
+/* Copyright (C) 1993,1995,1996,1997,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger <davidm@cs.arizona.edu>, 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* sigsuspend is a special syscall since it needs to dereference the
+ sigset. This will have to change when we have more than 64 signals. */
+
+#include <sysdep-cancel.h>
+
+#undef PSEUDO_PREPARE_ARGS
+#define PSEUDO_PREPARE_ARGS ldq a0, 0(a0);
+
+PSEUDO(__sigsuspend, sigsuspend, 1)
+ ret
+PSEUDO_END(__sigsuspend)
+libc_hidden_def (__sigsuspend)
+weak_alias (__sigsuspend, sigsuspend)
+strong_alias (__sigsuspend, __libc_sigsuspend)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sizes.h b/libc/sysdeps/unix/sysv/linux/alpha/sizes.h
new file mode 100644
index 000000000..0c7f4d5d2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sizes.h
@@ -0,0 +1,24 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIZES_H
+#define _SIZES_H 1
+
+#define PTR_SIZE_STR "8"
+
+#endif /* sizes.h */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/swapcontext.S b/libc/sysdeps/unix/sysv/linux/alpha/swapcontext.S
new file mode 100644
index 000000000..1221f67f7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/swapcontext.S
@@ -0,0 +1,51 @@
+/* Save current context and install the given one.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <ucontext-offsets.h>
+
+ENTRY(__swapcontext)
+
+#ifdef PROF
+ ldgp $29, 0($27)
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+ .prologue 1
+#elif defined PIC
+ .prologue 0
+#else
+ ldgp $29, 0($27)
+ .prologue 1
+#endif
+
+#ifdef PIC
+ unop
+ bsr $0, __getcontext_x !samegp
+ mov $17, $16
+ br $31, __setcontext !samegp
+#else
+ jsr $0, __getcontext_x
+ mov $17, $16
+ jmp $31, __setcontext
+#endif
+
+END(__swapcontext)
+weak_alias (__swapcontext, swapcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sys/acct.h b/libc/sysdeps/unix/sysv/linux/alpha/sys/acct.h
new file mode 100644
index 000000000..1e00006ef
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sys/acct.h
@@ -0,0 +1,66 @@
+/* Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_ACCT_H
+
+#define _SYS_ACCT_H 1
+#include <features.h>
+
+#define __need_time_t
+#include <time.h>
+
+
+__BEGIN_DECLS
+
+#define ACCT_COMM 16
+
+struct acct
+ {
+ char ac_comm[ACCT_COMM]; /* Accounting command name. */
+ time_t ac_utime; /* Accounting user time. */
+ time_t ac_stime; /* Accounting system time. */
+ time_t ac_etime; /* Accounting elapsed time. */
+ time_t ac_btime; /* Beginning time. */
+ unsigned int ac_uid; /* Accounting user ID. */
+ unsigned int ac_gid; /* Accounting group ID. */
+ unsigned int ac_tty; /* Controlling tty. */
+ /* Please note that the value of the `ac_tty' field, a device number,
+ is encoded differently in the kernel and for the libc dev_t type. */
+ char ac_flag; /* Accounting flag. */
+ long int ac_minflt; /* Accounting minor pagefaults. */
+ long int ac_majflt; /* Accounting major pagefaults. */
+ long int ac_exitcode; /* Accounting process exitcode. */
+ };
+
+enum
+ {
+ AFORK = 0001, /* Has executed fork, but no exec. */
+ ASU = 0002, /* Used super-user privileges. */
+ ACORE = 0004, /* Dumped core. */
+ AXSIG = 0010 /* Killed by a signal. */
+ };
+
+#define AHZ 100
+
+
+/* Switch process accounting on and off. */
+extern int acct (__const char *__filename) __THROW;
+
+__END_DECLS
+
+#endif /* sys/acct.h */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sys/io.h b/libc/sysdeps/unix/sysv/linux/alpha/sys/io.h
new file mode 100644
index 000000000..4334c6392
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sys/io.h
@@ -0,0 +1,95 @@
+/* Copyright (C) 1996, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IO_H
+
+#define _SYS_IO_H 1
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* If TURN_ON is TRUE, request for permission to do direct i/o on the
+ port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
+ permission off for that range. This call requires root privileges.
+
+ Portability note: not all Linux platforms support this call. Most
+ platforms based on the PC I/O architecture probably will, however.
+ E.g., Linux/Alpha for Alpha PCs supports this. */
+extern int ioperm (unsigned long int __from, unsigned long int __num,
+ int __turn_on) __THROW;
+
+/* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
+ access any I/O port is granted. This call requires root
+ privileges. */
+extern int iopl (int __level) __THROW;
+
+/* Return the physical address of the DENSE I/O memory or NULL if none
+ is available (e.g. on a jensen). */
+extern unsigned long int _bus_base (void) __THROW __attribute__ ((const));
+extern unsigned long int bus_base (void) __THROW __attribute__ ((const));
+
+/* Return the physical address of the SPARSE I/O memory. */
+extern unsigned long _bus_base_sparse (void) __THROW __attribute__ ((const));
+extern unsigned long bus_base_sparse (void) __THROW __attribute__ ((const));
+
+/* Return the HAE shift used by the SPARSE I/O memory. */
+extern int _hae_shift (void) __THROW __attribute__ ((const));
+extern int hae_shift (void) __THROW __attribute__ ((const));
+
+/* Previous three are deprecated in favour of the following, which
+ knows about multiple PCI "hoses". Provide the PCI bus and dfn
+ numbers just as to pciconfig_read/write. */
+
+enum __pciconfig_iobase_which
+{
+ IOBASE_HOSE = 0, /* Return hose index. */
+ IOBASE_SPARSE_MEM = 1, /* Return physical memory addresses. */
+ IOBASE_DENSE_MEM = 2,
+ IOBASE_SPARSE_IO = 3,
+ IOBASE_DENSE_IO = 4
+};
+
+extern long pciconfig_iobase(enum __pciconfig_iobase_which __which,
+ unsigned long int __bus,
+ unsigned long int __dfn)
+ __THROW __attribute__ ((const));
+
+/* Access PCI space protected from machine checks. */
+extern int pciconfig_read (unsigned long int __bus,
+ unsigned long int __dfn,
+ unsigned long int __off,
+ unsigned long int __len,
+ unsigned char *__buf) __THROW;
+
+extern int pciconfig_write (unsigned long int __bus,
+ unsigned long int __dfn,
+ unsigned long int __off,
+ unsigned long int __len,
+ unsigned char *__buf) __THROW;
+
+/* Userspace declarations. */
+extern unsigned int inb (unsigned long __port) __THROW;
+extern unsigned int inw (unsigned long __port) __THROW;
+extern unsigned int inl (unsigned long __port) __THROW;
+extern void outb (unsigned char __b, unsigned long __port) __THROW;
+extern void outw (unsigned short __w, unsigned long __port) __THROW;
+extern void outl (unsigned int __l, unsigned long __port) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_IO_H */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sys/procfs.h b/libc/sysdeps/unix/sysv/linux/alpha/sys/procfs.h
new file mode 100644
index 000000000..bee51f94e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sys/procfs.h
@@ -0,0 +1,115 @@
+/* Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H 1
+
+/* This is somehow modelled after the file of the same name on SysVr4
+ systems. It provides a definition of the core file format for ELF
+ used on Linux. */
+
+#include <features.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/ucontext.h>
+#include <sys/user.h>
+#include <asm/elf.h>
+
+__BEGIN_DECLS
+
+struct elf_siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_code; /* Extra code. */
+ int si_errno; /* Errno. */
+ };
+
+/* Definitions to generate Intel SVR4-like core files. These mostly
+ have the same names as the SVR4 types with "elf_" tacked on the
+ front to prevent clashes with linux definitions, and the typedef
+ forms have been avoided. This is mostly like the SVR4 structure,
+ but more Linuxy, with things that Linux does not support and which
+ gdb doesn't really use excluded. Fields present but not used are
+ marked with "XXX". */
+struct elf_prstatus
+ {
+#if 0
+ long int pr_flags; /* XXX Process flags. */
+ short int pr_why; /* XXX Reason for process halt. */
+ short int pr_what; /* XXX More detailed reason. */
+#endif
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned long int pr_sigpend; /* Set of pending signals. */
+ unsigned long int pr_sighold; /* Set of held signals. */
+#if 0
+ struct sigaltstack pr_altstack; /* Alternate stack info. */
+ struct sigaction pr_action; /* Signal action for current sig. */
+#endif
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct timeval pr_utime; /* User time. */
+ struct timeval pr_stime; /* System time. */
+ struct timeval pr_cutime; /* Cumulative user time. */
+ struct timeval pr_cstime; /* Cumulative system time. */
+#if 0
+ long int pr_instr; /* Current instruction. */
+#endif
+ elf_gregset_t pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+
+#define ELF_PRARGSZ (80) /* Number of chars for args */
+
+struct elf_prpsinfo
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned long int pr_flag; /* Flags. */
+ unsigned int pr_uid;
+ unsigned int pr_gid;
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+/* Addresses. */
+typedef void *psaddr_t;
+
+/* Register sets. Linux has different names. */
+typedef gregset_t prgregset_t;
+typedef fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+ therefore habe only ine PID type. */
+typedef __pid_t lwpid_t;
+
+
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+__END_DECLS
+
+#endif /* sys/procfs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sys/ucontext.h b/libc/sysdeps/unix/sysv/linux/alpha/sys/ucontext.h
new file mode 100644
index 000000000..438293c62
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sys/ucontext.h
@@ -0,0 +1,61 @@
+/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+
+#include <features.h>
+#include <signal.h>
+
+#include <bits/sigcontext.h>
+
+
+/* Type for general register. */
+typedef long int greg_t;
+
+/* Number of general registers. */
+#define NGREG 33
+
+/* Container for all general registers. */
+typedef greg_t gregset_t[NGREG];
+
+/* Type for floating-point register. */
+typedef long int fpreg_t;
+
+/* Number of general registers. */
+#define NFPREG 32
+
+/* Container for all general registers. */
+typedef fpreg_t fpregset_t[NFPREG];
+
+
+/* A machine context is exactly a sigcontext. */
+typedef struct sigcontext mcontext_t;
+
+/* Userlevel context. */
+typedef struct ucontext
+ {
+ unsigned long int uc_flags;
+ struct ucontext *uc_link;
+ unsigned long __uc_osf_sigmask;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ __sigset_t uc_sigmask;
+ } ucontext_t;
+
+#endif /* sys/ucontext.h */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sys/user.h b/libc/sysdeps/unix/sysv/linux/alpha/sys/user.h
new file mode 100644
index 000000000..4cd29d2ff
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sys/user.h
@@ -0,0 +1,50 @@
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_USER_H
+#define _SYS_USER_H 1
+
+/* The whole purpose of this file is for gdb/strace and gdb/strace
+ only. Don't read too much into it. Don't use it for anything other
+ than gdb/strace unless you know what you are doing. */
+
+#include <asm/page.h>
+#include <asm/reg.h>
+
+struct user
+{
+ unsigned long int regs[EF_SIZE / 8 + 32]; /* integer and fp regs */
+ size_t u_tsize; /* text size (pages) */
+ size_t u_dsize; /* data size (pages) */
+ size_t u_ssize; /* stack size (pages) */
+ unsigned long int start_code; /* text starting address */
+ unsigned long int start_data; /* data starting address */
+ unsigned long int start_stack; /* stack starting address */
+ long int signal; /* signal causing core dump */
+ struct regs *u_ar0; /* help gdb find registers */
+ unsigned long int magic; /* identifies a core file */
+ char u_comm[32]; /* user command name */
+};
+
+#define NBPG PAGE_SIZE
+#define UPAGES 1
+#define HOST_TEXT_START_ADDR (u.start_code)
+#define HOST_DATA_START_ADDR (u.start_data)
+#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
+
+#endif /* sys/user.h */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/syscall.S b/libc/sysdeps/unix/sysv/linux/alpha/syscall.S
new file mode 100644
index 000000000..0c4081363
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/syscall.S
@@ -0,0 +1,77 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger <davidm@azstarnet.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/*
+ * This is for COMPATIBILITY with Linux/x86 only. Linux/Alpha system
+ * calls return an error indication in a3. This allows arbitrary 64bit
+ * values to be returned in v0 (because negative values are not
+ * mistaken as error numbers). However, C allows only one value to
+ * be returned, so the interface below folds the error indication passed in
+ * a3 back into v0: it sets v0 to -errno if an error occurs. Thus,
+ * no negative 64bit numbers can be returned. To avoid this problem,
+ * use assembly stubs wherever possible/convenient.
+ *
+ * Usage:
+ *
+ * long syscall(syscall_number, arg1, arg2, arg3, arg4, arg5)
+ *
+ * syscall_number = the index of the system call we're invoking
+ * arg1-arg5 = up to 5 integer arguments to the system call
+ *
+ * We need to do some arg shifting: the kernel expects the
+ * syscall number in v0 and the first five args in a0-a4.
+ *
+ */
+
+
+LEAF(__syscall, 0)
+#ifdef PROF
+ ldgp gp, 0(pv)
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+ .prologue 1
+#else
+ .prologue 0
+#endif
+
+ mov a0, v0 /* Syscall number -> v0 */
+ mov a1, a0 /* arg1-arg5 -> a0-a4 */
+ mov a2, a1
+ mov a3, a2
+ mov a4, a3
+ mov a5, a4
+
+ call_pal PAL_callsys /* Invoke system call */
+ bne a3, $error
+ ret
+
+$error:
+#ifndef PROF
+ br gp, 2f
+2: ldgp gp, 0(gp)
+#endif
+ SYSCALL_ERROR_HANDLER
+
+END(__syscall)
+
+weak_alias (__syscall, syscall)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/syscalls.list b/libc/sysdeps/unix/sysv/linux/alpha/syscalls.list
new file mode 100644
index 000000000..7b3f23356
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/syscalls.list
@@ -0,0 +1,57 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+oldmsgctl EXTRA msgctl i:iip __old_msgctl msgctl@GLIBC_2.0
+msgget - msgget i:ii __msgget msgget
+msgrcv - msgrcv Ci:ibnii __msgrcv msgrcv
+msgsnd - msgsnd Ci:ibni __msgsnd msgsnd
+shmat - osf_shmat i:ipi __shmat shmat
+oldshmctl EXTRA shmctl i:iip __old_shmctl shmctl@GLIBC_2.0
+shmdt - shmdt i:s __shmdt shmdt
+shmget - shmget i:iii __shmget shmget
+semop - semop i:ipi __semop semop
+semtimedop - semtimedop i:ipip semtimedop
+semget - semget i:iii __semget semget
+oldsemctl EXTRA semctl i:iiii __old_semctl semctl@GLIBC_2.0
+
+sigstack - sigstack 2 sigstack
+vfork - vfork 0 __vfork vfork
+
+getpriority - getpriority i:ii __getpriority getpriority
+open - open Ci:siv __libc_open __open open !__libc_open64 __open64 open64
+open64 open -
+
+# proper socket implementations:
+accept - accept Ci:iBN __libc_accept __accept accept
+bind - bind i:ipi __bind bind
+connect - connect Ci:ipi __libc_connect __connect_internal __connect connect
+getpeername - getpeername i:ipp __getpeername getpeername
+getsockname - getsockname i:ipp __getsockname getsockname
+getsockopt - getsockopt i:iiiBN __getsockopt getsockopt
+listen - listen i:ii __listen listen
+recv - recv Ci:ibni __libc_recv __recv recv
+recvfrom - recvfrom Ci:ibniBN __libc_recvfrom __recvfrom recvfrom
+recvmsg - recvmsg Ci:ipi __libc_recvmsg __recvmsg recvmsg
+send - send Ci:ibni __libc_send __send send
+sendmsg - sendmsg Ci:ipi __libc_sendmsg __sendmsg sendmsg
+sendto - sendto Ci:ibnibn __libc_sendto __sendto sendto
+setsockopt - setsockopt i:iiibn __setsockopt setsockopt
+shutdown - shutdown i:ii __shutdown shutdown
+socket - socket i:iii __socket socket
+socketpair - socketpair i:iiif __socketpair socketpair
+
+ptrace - ptrace 4 __ptrace ptrace
+
+# access pci space protected from machine checks:
+pciconfig_read EXTRA pciconfig_read 5 pciconfig_read
+pciconfig_write EXTRA pciconfig_write 5 pciconfig_write
+pciconfig_iobase EXTRA pciconfig_iobase 3 __pciconfig_iobase pciconfig_iobase
+
+# support old timeval32 entry points
+osf_select - osf_select C:5 __select_tv32 __select@GLIBC_2.0 select@GLIBC_2.0
+osf_gettimeofday - osf_gettimeofday 2 __gettimeofday_tv32 __gettimeofday@GLIBC_2.0 gettimeofday@GLIBC_2.0
+osf_settimeofday - osf_settimeofday 2 __settimeofday_tv32 settimeofday@GLIBC_2.0
+osf_getitimer - osf_getitimer 2 __getitimer_tv32 getitimer@GLIBC_2.0
+osf_setitimer - osf_setitimer 3 __setitimer_tv32 setitimer@GLIBC_2.0
+osf_utimes - osf_utimes 2 __utimes_tv32 utimes@GLIBC_2.0
+osf_getrusage - osf_getrusage 2 __getrusage_tv32 getrusage@GLIBC_2.0
+osf_wait4 - osf_wait4 2 __wait4_tv32 wait4@GLIBC_2.0
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sysconf.c b/libc/sysdeps/unix/sysv/linux/alpha/sysconf.c
new file mode 100644
index 000000000..2bbaf1f36
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sysconf.c
@@ -0,0 +1,152 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static long int linux_sysconf (int name);
+
+#define CSHAPE(totalsize, linesize, assoc) \
+ ((totalsize & ~0xff) | (linesize << 4) | assoc)
+
+long __libc_alpha_cache_shape[4] = { -2, -2, -2, -2 };
+
+static inline unsigned long
+implver (void)
+{
+ unsigned long i;
+#if __GNUC_PREREQ(3,3)
+ i = __builtin_alpha_implver ();
+#else
+ asm ("implver %0" : "=r" (i));
+#endif
+ return i;
+}
+
+static inline unsigned long
+amask (unsigned long x)
+{
+ unsigned long r;
+#if __GNUC_PREREQ(3,3)
+ r = __builtin_alpha_amask (x);
+#else
+ asm ("amask %1,%0" : "=r"(r) : "Ir"(x));
+#endif
+ return r;
+}
+
+/* Get the value of the system variable NAME. */
+long int
+__sysconf (int name)
+{
+ long shape, index;
+
+ /* We only handle the cache information here (for now). */
+ if (name < _SC_LEVEL1_ICACHE_SIZE || name > _SC_LEVEL4_CACHE_LINESIZE)
+ return linux_sysconf (name);
+
+ /* No Alpha has L4 caches. */
+ if (name >= _SC_LEVEL4_CACHE_SIZE)
+ return -1;
+
+ index = (name - _SC_LEVEL1_ICACHE_SIZE) / 3;
+ shape = __libc_alpha_cache_shape[index];
+ if (shape == -2)
+ {
+ long shape_l1i, shape_l1d, shape_l2, shape_l3 = -1;
+
+ /* ??? In the cases below for which we do not know L1 cache sizes,
+ we could do timings to measure sizes. But for the Bcache, it's
+ generally big enough that (without additional help) TLB effects
+ get in the way. We'd either need to be able to allocate large
+ pages or have the kernel do the timings from KSEG. Fortunately,
+ kernels beginning with 2.6.5 will pass us this info in auxvec. */
+
+ switch (implver())
+ {
+ case 0: /* EV4 */
+ /* EV4/LCA45 had 8k L1 caches; EV45 had 16k L1 caches. */
+ /* EV4/EV45 had 128k to 16M 32-byte direct Bcache. LCA45
+ had 64k to 8M 8-byte direct Bcache. Can't tell. */
+ shape_l1i = shape_l1d = shape_l2 = CSHAPE (0, 5, 1);
+ break;
+
+ case 1: /* EV5 */
+ if (amask (1 << 8))
+ {
+ /* MAX insns not present; either EV5 or EV56. */
+ shape_l1i = shape_l1d = CSHAPE(8*1024, 5, 1);
+ /* ??? L2 and L3 *can* be configured as 32-byte line. */
+ shape_l2 = CSHAPE (96*1024, 6, 3);
+ /* EV5/EV56 has 1M to 16M Bcache. */
+ shape_l3 = CSHAPE (0, 6, 1);
+ }
+ else
+ {
+ /* MAX insns present; either PCA56 or PCA57. */
+ /* PCA56 had 16k 64-byte cache; PCA57 had 32k Icache. */
+ /* PCA56 had 8k 64-byte cache; PCA57 had 16k Dcache. */
+ /* PCA5[67] had 512k to 4M Bcache. */
+ shape_l1i = shape_l1d = shape_l2 = CSHAPE (0, 6, 1);
+ }
+ break;
+
+ case 2: /* EV6 */
+ shape_l1i = shape_l1d = CSHAPE(64*1024, 6, 2);
+ /* EV6/EV67/EV68* had 1M to 16M Bcache. */
+ shape_l2 = CSHAPE (0, 6, 1);
+ break;
+
+ case 3: /* EV7 */
+ shape_l1i = shape_l1d = CSHAPE(64*1024, 6, 2);
+ shape_l2 = CSHAPE(7*1024*1024/4, 6, 7);
+ break;
+
+ default:
+ shape_l1i = shape_l1d = shape_l2 = 0;
+ break;
+ }
+
+ __libc_alpha_cache_shape[0] = shape_l1i;
+ __libc_alpha_cache_shape[1] = shape_l1d;
+ __libc_alpha_cache_shape[2] = shape_l2;
+ __libc_alpha_cache_shape[3] = shape_l3;
+ shape = __libc_alpha_cache_shape[index];
+ }
+
+ if (shape <= 0)
+ return shape;
+
+ switch (name % 3)
+ {
+ case 0: /* total size */
+ return shape & -0x100;
+ case 1: /* associativity */
+ return shape & 0xf;
+ default: /* line size */
+ return 1L << ((shape >> 4) & 0xf);
+ }
+}
+
+/* Now the generic Linux version. */
+#undef __sysconf
+#define __sysconf static linux_sysconf
+#include "../sysconf.c"
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/sysdep.h b/libc/sysdeps/unix/sysv/linux/alpha/sysdep.h
new file mode 100644
index 000000000..a22da71d6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/sysdep.h
@@ -0,0 +1,99 @@
+/* Copyright (C) 1992, 1993, 1995, 1996, 1997, 2002, 2003, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_ALPHA_SYSDEP_H
+#define _LINUX_ALPHA_SYSDEP_H 1
+
+#ifdef __ASSEMBLER__
+#include <asm/pal.h>
+#include <alpha/regdef.h>
+#endif
+
+/* There is some commonality. */
+#include <sysdeps/unix/alpha/sysdep.h>
+
+/* For Linux we can use the system call table in the header file
+ /usr/include/asm/unistd.h
+ of the kernel. But these symbols do not follow the SYS_* syntax
+ so we have to redefine the `SYS_ify' macro here. */
+#undef SYS_ify
+#ifdef __STDC__
+# define SYS_ify(syscall_name) __NR_##syscall_name
+#else
+# define SYS_ify(syscall_name) __NR_/**/syscall_name
+#endif
+
+/* Define some aliases to make automatic syscall generation work
+ properly. The SYS_* variants are for the benefit of the files in
+ sysdeps/unix. */
+#define __NR_getpid __NR_getxpid
+#define __NR_getuid __NR_getxuid
+#define __NR_getgid __NR_getxgid
+#define SYS_getpid __NR_getxpid
+#define SYS_getuid __NR_getxuid
+#define SYS_getgid __NR_getxgid
+
+/*
+ * Some syscalls no Linux program should know about:
+ */
+#define __NR_osf_sigprocmask 48
+#define __NR_osf_shmat 209
+#define __NR_osf_getsysinfo 256
+#define __NR_osf_setsysinfo 257
+
+/* Help old kernel headers where particular syscalls are not available. */
+#ifndef __NR_semtimedop
+# define __NR_semtimedop 423
+#endif
+
+/* This is a kludge to make syscalls.list find these under the names
+ pread and pwrite, since some kernel headers define those names
+ and some define the *64 names for the same system calls. */
+#if !defined __NR_pread && defined __NR_pread64
+# define __NR_pread __NR_pread64
+#endif
+#if !defined __NR_pwrite && defined __NR_pwrite64
+# define __NR_pwrite __NR_pwrite64
+#endif
+
+/*
+ * In order to get the hidden arguments for rt_sigaction set up
+ * properly, we need to call the assembly version. This shouldn't
+ * happen except for inside sigaction.c, where we handle this
+ * specially. Catch other uses and error.
+ */
+
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...) \
+({ \
+ extern char ChEcK[__NR_##name == __NR_rt_sigaction ? -1 : 1] \
+ __attribute__((unused)); \
+ INLINE_SYSCALL1(name, nr, args); \
+})
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, err_out, nr, args...) \
+({ \
+ extern char ChEcK[__NR_##name == __NR_rt_sigaction ? -1 : 1] \
+ __attribute__((unused)); \
+ INTERNAL_SYSCALL1(name, err_out, nr, args); \
+})
+
+#endif /* _LINUX_ALPHA_SYSDEP_H */
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/ucontext-offsets.sym b/libc/sysdeps/unix/sysv/linux/alpha/ucontext-offsets.sym
new file mode 100644
index 000000000..f95ff7563
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/ucontext-offsets.sym
@@ -0,0 +1,18 @@
+#include <stddef.h>
+#include <sys/ucontext.h>
+
+--
+UC_LINK offsetof (ucontext_t, uc_link)
+UC_OSF_SIGMASK offsetof (ucontext_t, __uc_osf_sigmask)
+UC_STACK offsetof (ucontext_t, uc_stack)
+UC_SIGCTX offsetof (ucontext_t, uc_mcontext)
+UC_SIGMASK offsetof (ucontext_t, uc_sigmask)
+SC_REGS offsetof (struct sigcontext, sc_regs)
+SC_FPREGS offsetof (struct sigcontext, sc_fpregs)
+SC_PC offsetof (struct sigcontext, sc_pc)
+SC_PS offsetof (struct sigcontext, sc_ps)
+SC_FPCRS offsetof (struct sigcontext, sc_fpcr)
+SC_MASK offsetof (struct sigcontext, sc_mask)
+SC_FPCR offsetof (struct sigcontext, sc_fpcr)
+SS_SP offsetof (stack_t, ss_sp)
+SS_SIZE offsetof (stack_t, ss_size)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/utimes.S b/libc/sysdeps/unix/sysv/linux/alpha/utimes.S
new file mode 100644
index 000000000..0dd0a9372
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/utimes.S
@@ -0,0 +1,123 @@
+/* Copyright (C) 1998, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+
+.text
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+#define UTIMES __utimes_tv64
+#else
+#define UTIMES __utimes
+#endif
+
+#if defined __ASSUME_TIMEVAL64
+PSEUDO(UTIMES, utimes, 2)
+ ret
+PSEUDO_END(UTIMES)
+#else
+/* The problem here is that initially we made struct timeval compatible with
+ OSF/1, using int32. But we defined time_t with uint64, and later found
+ that POSIX requires tv_sec to be time_t.
+
+ So now we have to do compatibility stuff. */
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. */
+.comm __libc_missing_axp_tv64, 4
+
+LEAF(UTIMES, 16)
+ ldgp gp, 0(pv)
+ subq sp, 16, sp
+#ifdef PROF
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+#endif
+ .prologue 1
+
+ ldl t0, __libc_missing_axp_tv64
+
+ /* Save arguments in case we do need to fall back. */
+ stq a0, 0(sp)
+ stq a1, 8(sp)
+
+ bne t0, $do32
+
+ ldi v0, SYS_ify(utimes)
+ callsys
+ bne a3, $err64
+
+ /* Everything ok. */
+ addq sp, 16, sp
+ ret
+
+ /* If we didn't get ENOSYS, it is a real error. */
+ .align 3
+$err64: cmpeq v0, ENOSYS, t0
+ beq t0, $error
+ stl t0, __libc_missing_axp_tv64
+
+ /* Recover the saved arguments. */
+ ldq a1, 8(sp)
+ ldq a0, 0(sp)
+
+ .align 3
+$do32:
+ /* Conditionally bounce values down. */
+ beq a1, 1f
+ ldq t0, 0(a1)
+ ldq t1, 8(a1)
+ ldq t2, 16(a1)
+ ldq t3, 24(a1)
+ stl t0, 0(sp)
+ stl t1, 4(sp)
+ stl t2, 8(sp)
+ stl t3, 12(sp)
+ mov sp, a1
+
+1: ldi v0, SYS_ify(osf_utimes)
+ callsys
+ bne a3, $error
+
+ addq sp, 16, sp
+ ret
+
+ .align 3
+$error:
+ addq sp, 16, sp
+ SYSCALL_ERROR_HANDLER
+
+END(UTIMES)
+#endif /* __ASSUME_TIMEVAL64 */
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+default_symbol_version (__utimes_tv64, __utimes, GLIBC_2.1)
+
+/* It seems to me to be a misfeature of the assembler that we can only
+ have one version-alias per symbol. So create an alias ourselves.
+ The 'p' is for 'public'. *Shrug* */
+strong_alias (__utimes_tv64, __utimes_tv64p)
+default_symbol_version (__utimes_tv64p, utimes, GLIBC_2.1)
+#else
+weak_alias (__utimes, utimes)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/wait4.S b/libc/sysdeps/unix/sysv/linux/alpha/wait4.S
new file mode 100644
index 000000000..634993deb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/wait4.S
@@ -0,0 +1,156 @@
+/* Copyright (C) 1998, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+
+.text
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+#define WAIT4 __wait4_tv64
+#else
+#define WAIT4 __wait4
+#endif
+
+#if defined __ASSUME_TIMEVAL64
+PSEUDO(WAIT4, wait4, 4)
+ ret
+PSEUDO_END(WAIT4)
+#else
+/* The problem here is that initially we made struct timeval compatible with
+ OSF/1, using int32. But we defined time_t with uint64, and later found
+ that POSIX requires tv_sec to be time_t.
+
+ So now we have to do compatibility stuff. */
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. */
+.comm __libc_missing_axp_tv64, 4
+
+LEAF(WAIT4, 32)
+ ldgp gp, 0(pv)
+ subq sp, 32, sp
+#ifdef PROF
+ .set noat
+ lda AT, _mcount
+ jsr AT, (AT), _mcount
+ .set at
+#endif
+ .prologue 1
+
+ ldl t0, __libc_missing_axp_tv64
+
+ /* Save arguments in case we do need to fall back. */
+ stq a0, 0(sp)
+ stq a1, 8(sp)
+ stq a2, 16(sp)
+ stq a3, 24(sp)
+
+ bne t0, $do32
+
+ ldi v0, SYS_ify(wait4)
+ callsys
+ bne a3, $err64
+
+ /* Everything ok. */
+ addq sp, 32, sp
+ ret
+
+ /* If we didn't get ENOSYS, it is a real error. */
+ .align 3
+$err64: cmpeq v0, ENOSYS, t0
+ beq t0, $error
+ stl t0, __libc_missing_axp_tv64
+
+ /* Recover the saved arguments. */
+ ldq a3, 24(sp)
+ ldq a2, 16(sp)
+ ldq a1, 8(sp)
+ ldq a0, 0(sp)
+
+ .align 3
+$do32: ldi v0, SYS_ify(osf_wait4)
+ callsys
+ bne a3, $error
+
+ /* Copy back to proper format. */
+ ldq a3, 24(sp)
+ beq a3, 2f
+ ldl t0, 0(a3) # ru_utime.tv_sec
+ ldl t1, 4(a3) # ru_utime.tv_usec
+ ldl t2, 8(a3) # ru_stime.tv_sec
+ ldl t3, 12(a3) # ru_stime.tv_usec
+ ldt $f15, 16(a3) # ru_maxrss
+ ldt $f16, 24(a3) # ru_ixrss
+ ldt $f17, 32(a3) # ru_idrss
+ ldt $f18, 40(a3) # ru_isrss
+ ldt $f19, 48(a3) # ru_minflt
+ ldt $f20, 56(a3) # ru_majflt
+ ldt $f21, 64(a3) # ru_nswap
+ ldt $f22, 72(a3) # ru_inblock
+ ldt $f23, 80(a3) # ru_oublock
+ ldt $f24, 88(a3) # ru_msgsend
+ ldt $f25, 96(a3) # ru_msgrcv
+ ldt $f26, 104(a3) # ru_nsignals
+ ldt $f27, 112(a3) # ru_nvcsw
+ .set noat
+ ldt $f28, 120(a3) # ru_nivcsw
+ stq t0, 0(a3)
+ stq t1, 8(a3)
+ stq t2, 16(a3)
+ stq t3, 24(a3)
+ stt $f15, 32(a3)
+ stt $f16, 40(a3)
+ stt $f17, 48(a3)
+ stt $f18, 56(a3)
+ stt $f19, 64(a3)
+ stt $f20, 72(a3)
+ stt $f21, 80(a3)
+ stt $f22, 88(a3)
+ stt $f23, 96(a3)
+ stt $f24, 104(a3)
+ stt $f25, 112(a3)
+ stt $f26, 120(a3)
+ stt $f27, 128(a3)
+ stt $f28, 136(a3)
+ .set at
+
+2: addq sp, 32, sp
+ ret
+
+ .align 3
+$error:
+ addq sp, 32, sp
+ SYSCALL_ERROR_HANDLER
+
+END(WAIT4)
+#endif /* __ASSUME_TIMEVAL64 */
+
+#if defined HAVE_ELF && defined PIC && defined DO_VERSIONING
+default_symbol_version (__wait4_tv64, __wait4, GLIBC_2.1)
+
+/* It seems to me to be a misfeature of the assembler that we can only
+ have one version-alias per symbol. So create an alias ourselves.
+ The 'p' is for 'public'. *Shrug* */
+strong_alias (__wait4_tv64, __wait4_tv64p)
+default_symbol_version (__wait4_tv64p, wait4, GLIBC_2.1)
+#else
+weak_alias (__wait4, wait4)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/wordexp.c b/libc/sysdeps/unix/sysv/linux/alpha/wordexp.c
new file mode 100644
index 000000000..c2972e40c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/wordexp.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <shlib-compat.h>
+
+/* For Linux/Alpha we have to make the wordexp symbols versioned. */
+#define wordexp(words, pwordexp, flags) \
+ __new_wordexp (words, pwordexp, flags)
+
+#include <posix/wordexp.c>
+
+versioned_symbol (libc, __new_wordexp, wordexp, GLIBC_2_2_2);
+
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2_2)
+/* The old, incorrect wordexp_t definition. */
+typedef struct
+ {
+ int we_wordc; /* Count of words matched. */
+ char **we_wordv; /* List of expanded words. */
+ int we_offs; /* Slots to reserve in `we_wordv'. */
+ } old_wordexp_t;
+
+
+int
+attribute_compat_text_section
+__old_wordexp (const char *words, old_wordexp_t *pwordexp, int flags)
+{
+ wordexp_t we;
+ int result;
+
+ we.we_wordc = pwordexp->we_wordc;
+ we.we_wordv = pwordexp->we_wordv;
+ we.we_offs = pwordexp->we_offs;
+
+ result = __new_wordexp (words, &we, flags);
+
+ pwordexp->we_wordc = we.we_wordc;
+ pwordexp->we_wordv = we.we_wordv;
+ pwordexp->we_offs = we.we_offs;
+
+ return result;
+}
+compat_symbol (libc, __old_wordexp, wordexp, GLIBC_2_1);
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/xstat.c b/libc/sysdeps/unix/sysv/linux/alpha/xstat.c
new file mode 100644
index 000000000..b7488e425
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/xstat.c
@@ -0,0 +1,64 @@
+/* xstat using old-style Unix stat system call.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define __xstat64 __xstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <xstatconv.h>
+
+#undef __xstat64
+
+
+/* Get information about the file NAME in BUF. */
+int
+__xstat (int vers, const char *name, struct stat *buf)
+{
+ INTERNAL_SYSCALL_DECL (err);
+ int result, errno_out;
+ struct kernel_stat kbuf;
+
+ if (vers == _STAT_VER_KERNEL64 && !__libc_missing_axp_stat64)
+ {
+ result = INTERNAL_SYSCALL (stat64, err, 2, name, buf);
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return result;
+ errno_out = INTERNAL_SYSCALL_ERRNO (result, err);
+ if (errno_out != ENOSYS)
+ goto fail;
+ __libc_missing_axp_stat64 = 1;
+ }
+
+ result = INTERNAL_SYSCALL (stat, err, 2, name, &kbuf);
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return __xstat_conv (vers, &kbuf, buf);
+ errno_out = INTERNAL_SYSCALL_ERRNO (result, err);
+
+ fail:
+ __set_errno (errno_out);
+ return -1;
+}
+hidden_def (__xstat)
+weak_alias (__xstat, _xstat);
+strong_alias (__xstat, __xstat64);
+hidden_ver (__xstat, __xstat64)
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/xstatconv.c b/libc/sysdeps/unix/sysv/linux/alpha/xstatconv.c
new file mode 100644
index 000000000..a193b62ad
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/xstatconv.c
@@ -0,0 +1,123 @@
+/* Convert between the kernel's `struct stat' format, and libc's.
+ Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+#include <xstatconv.h>
+
+
+int __libc_missing_axp_stat64;
+
+int
+__xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
+{
+ switch (vers)
+ {
+ case _STAT_VER_KERNEL:
+ *(struct kernel_stat *) ubuf = *kbuf;
+ break;
+
+ case _STAT_VER_GLIBC2:
+ {
+ struct glibc2_stat *buf = ubuf;
+
+ buf->st_dev = kbuf->st_dev;
+ buf->st_ino = kbuf->st_ino;
+ buf->st_mode = kbuf->st_mode;
+ buf->st_nlink = kbuf->st_nlink;
+ buf->st_uid = kbuf->st_uid;
+ buf->st_gid = kbuf->st_gid;
+ buf->st_rdev = kbuf->st_rdev;
+ buf->st_size = kbuf->st_size;
+ buf->st_atime = kbuf->st_atime;
+ buf->st_mtime = kbuf->st_mtime;
+ buf->st_ctime = kbuf->st_ctime;
+ buf->st_blksize = kbuf->st_blksize;
+ buf->st_blocks = kbuf->st_blocks;
+ buf->st_flags = kbuf->st_flags;
+ buf->st_gen = kbuf->st_gen;
+ }
+ break;
+
+ case _STAT_VER_GLIBC2_1:
+ {
+ struct glibc21_stat *buf = ubuf;
+
+ buf->st_dev = kbuf->st_dev;
+ buf->st_ino = kbuf->st_ino;
+ buf->st_mode = kbuf->st_mode;
+ buf->st_nlink = kbuf->st_nlink;
+ buf->st_uid = kbuf->st_uid;
+ buf->st_gid = kbuf->st_gid;
+ buf->st_rdev = kbuf->st_rdev;
+ buf->st_size = kbuf->st_size;
+ buf->st_atime = kbuf->st_atime;
+ buf->st_mtime = kbuf->st_mtime;
+ buf->st_ctime = kbuf->st_ctime;
+ buf->st_blocks = kbuf->st_blocks;
+ buf->st_blksize = kbuf->st_blksize;
+ buf->st_flags = kbuf->st_flags;
+ buf->st_gen = kbuf->st_gen;
+ buf->__pad3 = 0;
+ buf->__unused[0] = 0;
+ buf->__unused[1] = 0;
+ buf->__unused[2] = 0;
+ buf->__unused[3] = 0;
+ }
+ break;
+
+ case _STAT_VER_GLIBC2_3_4:
+ {
+ struct stat64 *buf = ubuf;
+
+ buf->st_dev = kbuf->st_dev;
+ buf->st_ino = kbuf->st_ino;
+ buf->st_rdev = kbuf->st_rdev;
+ buf->st_size = kbuf->st_size;
+ buf->st_blocks = kbuf->st_blocks;
+
+ buf->st_mode = kbuf->st_mode;
+ buf->st_uid = kbuf->st_uid;
+ buf->st_gid = kbuf->st_gid;
+ buf->st_blksize = kbuf->st_blksize;
+ buf->st_nlink = kbuf->st_nlink;
+ buf->__pad0 = 0;
+
+ buf->st_atime = kbuf->st_atime;
+ buf->st_atimensec = 0;
+ buf->st_mtime = kbuf->st_mtime;
+ buf->st_mtimensec = 0;
+ buf->st_ctime = kbuf->st_ctime;
+ buf->st_ctimensec = 0;
+
+ buf->__unused[0] = 0;
+ buf->__unused[1] = 0;
+ buf->__unused[2] = 0;
+ }
+ break;
+
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/alpha/xstatconv.h b/libc/sysdeps/unix/sysv/linux/alpha/xstatconv.h
new file mode 100644
index 000000000..094d11e5c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/alpha/xstatconv.h
@@ -0,0 +1,24 @@
+/* Convert between the kernel's `struct stat' format, and libc's.
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <kernel-features.h>
+
+extern int __libc_missing_axp_stat64 attribute_hidden;
+extern int __xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
+ attribute_hidden;
diff --git a/libc/sysdeps/unix/sysv/linux/bind.S b/libc/sysdeps/unix/sysv/linux/bind.S
new file mode 100644
index 000000000..7719ad0be
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bind.S
@@ -0,0 +1,5 @@
+#define socket bind
+#define NARGS 3
+#define NO_WEAK_ALIAS 1
+#include <socket.S>
+weak_alias (bind, __bind)
diff --git a/libc/sysdeps/unix/sysv/linux/bits/a.out.h b/libc/sysdeps/unix/sysv/linux/bits/a.out.h
new file mode 100644
index 000000000..0e7fb030f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/a.out.h
@@ -0,0 +1,7 @@
+#ifndef __A_OUT_GNU_H__
+# error "Never use <bits/a.out.h> directly; include <a.out.h> instead."
+#endif
+
+/* Signal to users of this header that this architecture really doesn't
+ support a.out binary format. */
+#define __NO_A_OUT_SUPPORT 1
diff --git a/libc/sysdeps/unix/sysv/linux/bits/dirent.h b/libc/sysdeps/unix/sysv/linux/bits/dirent.h
new file mode 100644
index 000000000..76794b08d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/dirent.h
@@ -0,0 +1,53 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _DIRENT_H
+# error "Never use <bits/dirent.h> directly; include <dirent.h> instead."
+#endif
+
+struct dirent
+ {
+#ifndef __USE_FILE_OFFSET64
+ __ino_t d_ino;
+ __off_t d_off;
+#else
+ __ino64_t d_ino;
+ __off64_t d_off;
+#endif
+ unsigned short int d_reclen;
+ unsigned char d_type;
+ char d_name[256]; /* We must not include limits.h! */
+ };
+
+#ifdef __USE_LARGEFILE64
+struct dirent64
+ {
+ __ino64_t d_ino;
+ __off64_t d_off;
+ unsigned short int d_reclen;
+ unsigned char d_type;
+ char d_name[256]; /* We must not include limits.h! */
+ };
+#endif
+
+#define d_fileno d_ino /* Backwards compatibility. */
+
+#undef _DIRENT_HAVE_D_NAMLEN
+#define _DIRENT_HAVE_D_RECLEN
+#define _DIRENT_HAVE_D_OFF
+#define _DIRENT_HAVE_D_TYPE
diff --git a/libc/sysdeps/unix/sysv/linux/bits/errno.h b/libc/sysdeps/unix/sysv/linux/bits/errno.h
new file mode 100644
index 000000000..4de8cbba5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/errno.h
@@ -0,0 +1,59 @@
+/* Error constants. Linux specific version.
+ Copyright (C) 1996, 1997, 1998, 1999, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifdef _ERRNO_H
+
+# undef EDOM
+# undef EILSEQ
+# undef ERANGE
+# include <linux/errno.h>
+
+/* Linux has no ENOTSUP error code. */
+# define ENOTSUP EOPNOTSUPP
+
+/* Older Linux versions also had no ECANCELED error code. */
+# ifndef ECANCELED
+# define ECANCELED 125
+# endif
+
+/* Support for error codes to support robust mutexes was added later, too. */
+# ifndef EOWNERDEAD
+# define EOWNERDEAD 130
+# define ENOTRECOVERABLE 131
+# endif
+
+# ifndef __ASSEMBLER__
+/* Function to get address of global `errno' variable. */
+extern int *__errno_location (void) __THROW __attribute__ ((__const__));
+
+# if !defined _LIBC || defined _LIBC_REENTRANT
+/* When using threads, errno is a per-thread value. */
+# define errno (*__errno_location ())
+# endif
+# endif /* !__ASSEMBLER__ */
+#endif /* _ERRNO_H */
+
+#if !defined _ERRNO_H && defined __need_Emath
+/* This is ugly but the kernel header is not clean enough. We must
+ define only the values EDOM, EILSEQ and ERANGE in case __need_Emath is
+ defined. */
+# define EDOM 33 /* Math argument out of domain of function. */
+# define EILSEQ 84 /* Illegal byte sequence. */
+# define ERANGE 34 /* Math result not representable. */
+#endif /* !_ERRNO_H && __need_Emath */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/fcntl.h b/libc/sysdeps/unix/sysv/linux/bits/fcntl.h
new file mode 100644
index 000000000..be40350e8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/fcntl.h
@@ -0,0 +1,3 @@
+/* bits/fcntl.h is architecture specific. */
+#error "This file must be supplied by every Linux architecture."
+
diff --git a/libc/sysdeps/unix/sysv/linux/bits/in.h b/libc/sysdeps/unix/sysv/linux/bits/in.h
new file mode 100644
index 000000000..6880a2e63
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/in.h
@@ -0,0 +1,170 @@
+/* Copyright (C) 1991-1999, 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Linux version. */
+
+#ifndef _NETINET_IN_H
+# error "Never use <bits/in.h> directly; include <netinet/in.h> instead."
+#endif
+
+/* Options for use with `getsockopt' and `setsockopt' at the IP level.
+ The first word in the comment at the right is the data type used;
+ "bool" means a boolean value stored in an `int'. */
+#define IP_OPTIONS 4 /* ip_opts; IP per-packet options. */
+#define IP_HDRINCL 3 /* int; Header is included with data. */
+#define IP_TOS 1 /* int; IP type of service and precedence. */
+#define IP_TTL 2 /* int; IP time to live. */
+#define IP_RECVOPTS 6 /* bool; Receive all IP options w/datagram. */
+/* For BSD compatibility. */
+#define IP_RECVRETOPTS IP_RETOPTS /* bool; Receive IP options for response. */
+#define IP_RETOPTS 7 /* ip_opts; Set/get IP per-packet options. */
+#define IP_MULTICAST_IF 32 /* in_addr; set/get IP multicast i/f */
+#define IP_MULTICAST_TTL 33 /* u_char; set/get IP multicast ttl */
+#define IP_MULTICAST_LOOP 34 /* i_char; set/get IP multicast loopback */
+#define IP_ADD_MEMBERSHIP 35 /* ip_mreq; add an IP group membership */
+#define IP_DROP_MEMBERSHIP 36 /* ip_mreq; drop an IP group membership */
+#define IP_UNBLOCK_SOURCE 37 /* ip_mreq_source: unblock data from source */
+#define IP_BLOCK_SOURCE 38 /* ip_mreq_source: block data from source */
+#define IP_ADD_SOURCE_MEMBERSHIP 39 /* ip_mreq_source: join source group */
+#define IP_DROP_SOURCE_MEMBERSHIP 40 /* ip_mreq_source: leave source group */
+#define IP_MSFILTER 41
+#define MCAST_JOIN_GROUP 42 /* group_req: join any-source group */
+#define MCAST_BLOCK_SOURCE 43 /* group_source_req: block from given group */
+#define MCAST_UNBLOCK_SOURCE 44 /* group_source_req: unblock from given group*/
+#define MCAST_LEAVE_GROUP 45 /* group_req: leave any-source group */
+#define MCAST_JOIN_SOURCE_GROUP 46 /* group_source_req: join source-spec gr */
+#define MCAST_LEAVE_SOURCE_GROUP 47 /* group_source_req: leave source-spec gr*/
+#define MCAST_MSFILTER 48
+
+#define MCAST_EXCLUDE 0
+#define MCAST_INCLUDE 1
+
+#define IP_ROUTER_ALERT 5 /* bool */
+#define IP_PKTINFO 8 /* bool */
+#define IP_PKTOPTIONS 9
+#define IP_PMTUDISC 10 /* obsolete name? */
+#define IP_MTU_DISCOVER 10 /* int; see below */
+#define IP_RECVERR 11 /* bool */
+#define IP_RECVTTL 12 /* bool */
+#define IP_RECVTOS 13 /* bool */
+
+
+/* IP_MTU_DISCOVER arguments. */
+#define IP_PMTUDISC_DONT 0 /* Never send DF frames. */
+#define IP_PMTUDISC_WANT 1 /* Use per route hints. */
+#define IP_PMTUDISC_DO 2 /* Always DF. */
+
+/* To select the IP level. */
+#define SOL_IP 0
+
+#define IP_DEFAULT_MULTICAST_TTL 1
+#define IP_DEFAULT_MULTICAST_LOOP 1
+#define IP_MAX_MEMBERSHIPS 20
+
+/* Structure used to describe IP options for IP_OPTIONS and IP_RETOPTS.
+ The `ip_dst' field is used for the first-hop gateway when using a
+ source route (this gets put into the header proper). */
+struct ip_opts
+ {
+ struct in_addr ip_dst; /* First hop; zero without source route. */
+ char ip_opts[40]; /* Actually variable in size. */
+ };
+
+/* Like `struct ip_mreq' but including interface specification by index. */
+struct ip_mreqn
+ {
+ struct in_addr imr_multiaddr; /* IP multicast address of group */
+ struct in_addr imr_address; /* local IP address of interface */
+ int imr_ifindex; /* Interface index */
+ };
+
+/* Structure used for IP_PKTINFO. */
+struct in_pktinfo
+ {
+ int ipi_ifindex; /* Interface index */
+ struct in_addr ipi_spec_dst; /* Routing destination address */
+ struct in_addr ipi_addr; /* Header destination address */
+ };
+
+/* Options for use with `getsockopt' and `setsockopt' at the IPv6 level.
+ The first word in the comment at the right is the data type used;
+ "bool" means a boolean value stored in an `int'. */
+#define IPV6_ADDRFORM 1
+#define IPV6_2292PKTINFO 2
+#define IPV6_2292HOPOPTS 3
+#define IPV6_2292DSTOPTS 4
+#define IPV6_2292RTHDR 5
+#define IPV6_2292PKTOPTIONS 6
+#define IPV6_CHECKSUM 7
+#define IPV6_2292HOPLIMIT 8
+
+#define SCM_SRCRT IPV6_RXSRCRT
+
+#define IPV6_NEXTHOP 9
+#define IPV6_AUTHHDR 10
+#define IPV6_UNICAST_HOPS 16
+#define IPV6_MULTICAST_IF 17
+#define IPV6_MULTICAST_HOPS 18
+#define IPV6_MULTICAST_LOOP 19
+#define IPV6_JOIN_GROUP 20
+#define IPV6_LEAVE_GROUP 21
+#define IPV6_ROUTER_ALERT 22
+#define IPV6_MTU_DISCOVER 23
+#define IPV6_MTU 24
+#define IPV6_RECVERR 25
+#define IPV6_V6ONLY 26
+#define IPV6_JOIN_ANYCAST 27
+#define IPV6_LEAVE_ANYCAST 28
+#define IPV6_IPSEC_POLICY 34
+#define IPV6_XFRM_POLICY 35
+
+#define IPV6_RECVPKTINFO 49
+#define IPV6_PKTINFO 50
+#define IPV6_RECVHOPLIMIT 51
+#define IPV6_HOPLIMIT 52
+#define IPV6_RECVHOPOPTS 53
+#define IPV6_HOPOPTS 54
+#define IPV6_RTHDRDSTOPTS 55
+#define IPV6_RECVRTHDR 56
+#define IPV6_RTHDR 57
+#define IPV6_RECVDSTOPTS 58
+#define IPV6_DSTOPTS 59
+
+#define IPV6_RECVTCLASS 66
+#define IPV6_TCLASS 67
+
+/* Obsolete synonyms for the above. */
+#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
+#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
+#define IPV6_RXHOPOPTS IPV6_HOPOPTS
+#define IPV6_RXDSTOPTS IPV6_DSTOPTS
+
+/* IPV6_MTU_DISCOVER values. */
+#define IPV6_PMTUDISC_DONT 0 /* Never send DF frames. */
+#define IPV6_PMTUDISC_WANT 1 /* Use per route hints. */
+#define IPV6_PMTUDISC_DO 2 /* Always DF. */
+
+/* Socket level values for IPv6. */
+#define SOL_IPV6 41
+#define SOL_ICMPV6 58
+
+/* Routing header options for IPv6. */
+#define IPV6_RTHDR_LOOSE 0 /* Hop doesn't need to be neighbour. */
+#define IPV6_RTHDR_STRICT 1 /* Hop must be a neighbour. */
+
+#define IPV6_RTHDR_TYPE_0 0 /* IPv6 Routing header type 0. */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/initspin.h b/libc/sysdeps/unix/sysv/linux/bits/initspin.h
new file mode 100644
index 000000000..936f17849
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/initspin.h
@@ -0,0 +1 @@
+/* No thread support. */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/ioctl-types.h b/libc/sysdeps/unix/sysv/linux/bits/ioctl-types.h
new file mode 100644
index 000000000..e856a04b4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/ioctl-types.h
@@ -0,0 +1,78 @@
+/* Structure types for pre-termios terminal ioctls. Linux version.
+ Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IOCTL_H
+# error "Never use <bits/ioctl-types.h> directly; include <sys/ioctl.h> instead."
+#endif
+
+/* Get definition of constants for use with `ioctl'. */
+#include <asm/ioctls.h>
+
+
+struct winsize
+ {
+ unsigned short int ws_row;
+ unsigned short int ws_col;
+ unsigned short int ws_xpixel;
+ unsigned short int ws_ypixel;
+ };
+
+#define NCC 8
+struct termio
+ {
+ unsigned short int c_iflag; /* input mode flags */
+ unsigned short int c_oflag; /* output mode flags */
+ unsigned short int c_cflag; /* control mode flags */
+ unsigned short int c_lflag; /* local mode flags */
+ unsigned char c_line; /* line discipline */
+ unsigned char c_cc[NCC]; /* control characters */
+};
+
+/* modem lines */
+#define TIOCM_LE 0x001
+#define TIOCM_DTR 0x002
+#define TIOCM_RTS 0x004
+#define TIOCM_ST 0x008
+#define TIOCM_SR 0x010
+#define TIOCM_CTS 0x020
+#define TIOCM_CAR 0x040
+#define TIOCM_RNG 0x080
+#define TIOCM_DSR 0x100
+#define TIOCM_CD TIOCM_CAR
+#define TIOCM_RI TIOCM_RNG
+
+/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
+
+/* line disciplines */
+#define N_TTY 0
+#define N_SLIP 1
+#define N_MOUSE 2
+#define N_PPP 3
+#define N_STRIP 4
+#define N_AX25 5
+#define N_X25 6 /* X.25 async */
+#define N_6PACK 7
+#define N_MASC 8 /* Mobitex module */
+#define N_R3964 9 /* Simatic R3964 module */
+#define N_PROFIBUS_FDL 10 /* Profibus */
+#define N_IRDA 11 /* Linux IR */
+#define N_SMSBLOCK 12 /* SMS block mode */
+#define N_HDLC 13 /* synchronous HDLC */
+#define N_SYNC_PPP 14 /* synchronous PPP */
+#define N_HCI 15 /* Bluetooth HCI UART */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/ioctls.h b/libc/sysdeps/unix/sysv/linux/bits/ioctls.h
new file mode 100644
index 000000000..11bb4c485
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/ioctls.h
@@ -0,0 +1,109 @@
+/* Copyright (C) 1996, 1997, 1998, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IOCTL_H
+# error "Never use <bits/ioctls.h> directly; include <sys/ioctl.h> instead."
+#endif
+
+/* Use the definitions from the kernel header files. */
+#include <asm/ioctls.h>
+
+/* Routing table calls. */
+#define SIOCADDRT 0x890B /* add routing table entry */
+#define SIOCDELRT 0x890C /* delete routing table entry */
+#define SIOCRTMSG 0x890D /* call to routing system */
+
+/* Socket configuration controls. */
+#define SIOCGIFNAME 0x8910 /* get iface name */
+#define SIOCSIFLINK 0x8911 /* set iface channel */
+#define SIOCGIFCONF 0x8912 /* get iface list */
+#define SIOCGIFFLAGS 0x8913 /* get flags */
+#define SIOCSIFFLAGS 0x8914 /* set flags */
+#define SIOCGIFADDR 0x8915 /* get PA address */
+#define SIOCSIFADDR 0x8916 /* set PA address */
+#define SIOCGIFDSTADDR 0x8917 /* get remote PA address */
+#define SIOCSIFDSTADDR 0x8918 /* set remote PA address */
+#define SIOCGIFBRDADDR 0x8919 /* get broadcast PA address */
+#define SIOCSIFBRDADDR 0x891a /* set broadcast PA address */
+#define SIOCGIFNETMASK 0x891b /* get network PA mask */
+#define SIOCSIFNETMASK 0x891c /* set network PA mask */
+#define SIOCGIFMETRIC 0x891d /* get metric */
+#define SIOCSIFMETRIC 0x891e /* set metric */
+#define SIOCGIFMEM 0x891f /* get memory address (BSD) */
+#define SIOCSIFMEM 0x8920 /* set memory address (BSD) */
+#define SIOCGIFMTU 0x8921 /* get MTU size */
+#define SIOCSIFMTU 0x8922 /* set MTU size */
+#define SIOCSIFNAME 0x8923 /* set interface name */
+#define SIOCSIFHWADDR 0x8924 /* set hardware address */
+#define SIOCGIFENCAP 0x8925 /* get/set encapsulations */
+#define SIOCSIFENCAP 0x8926
+#define SIOCGIFHWADDR 0x8927 /* Get hardware address */
+#define SIOCGIFSLAVE 0x8929 /* Driver slaving support */
+#define SIOCSIFSLAVE 0x8930
+#define SIOCADDMULTI 0x8931 /* Multicast address lists */
+#define SIOCDELMULTI 0x8932
+#define SIOCGIFINDEX 0x8933 /* name -> if_index mapping */
+#define SIOGIFINDEX SIOCGIFINDEX /* misprint compatibility :-) */
+#define SIOCSIFPFLAGS 0x8934 /* set/get extended flags set */
+#define SIOCGIFPFLAGS 0x8935
+#define SIOCDIFADDR 0x8936 /* delete PA address */
+#define SIOCSIFHWBROADCAST 0x8937 /* set hardware broadcast addr */
+#define SIOCGIFCOUNT 0x8938 /* get number of devices */
+
+#define SIOCGIFBR 0x8940 /* Bridging support */
+#define SIOCSIFBR 0x8941 /* Set bridging options */
+
+#define SIOCGIFTXQLEN 0x8942 /* Get the tx queue length */
+#define SIOCSIFTXQLEN 0x8943 /* Set the tx queue length */
+
+
+/* ARP cache control calls. */
+ /* 0x8950 - 0x8952 * obsolete calls, don't re-use */
+#define SIOCDARP 0x8953 /* delete ARP table entry */
+#define SIOCGARP 0x8954 /* get ARP table entry */
+#define SIOCSARP 0x8955 /* set ARP table entry */
+
+/* RARP cache control calls. */
+#define SIOCDRARP 0x8960 /* delete RARP table entry */
+#define SIOCGRARP 0x8961 /* get RARP table entry */
+#define SIOCSRARP 0x8962 /* set RARP table entry */
+
+/* Driver configuration calls */
+
+#define SIOCGIFMAP 0x8970 /* Get device parameters */
+#define SIOCSIFMAP 0x8971 /* Set device parameters */
+
+/* DLCI configuration calls */
+
+#define SIOCADDDLCI 0x8980 /* Create new DLCI device */
+#define SIOCDELDLCI 0x8981 /* Delete DLCI device */
+
+/* Device private ioctl calls. */
+
+/* These 16 ioctls are available to devices via the do_ioctl() device
+ vector. Each device should include this file and redefine these
+ names as their own. Because these are device dependent it is a good
+ idea _NOT_ to issue them to random objects and hope. */
+
+#define SIOCDEVPRIVATE 0x89F0 /* to 89FF */
+
+/*
+ * These 16 ioctl calls are protocol private
+ */
+
+#define SIOCPROTOPRIVATE 0x89E0 /* to 89EF */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/ipc.h b/libc/sysdeps/unix/sysv/linux/bits/ipc.h
new file mode 100644
index 000000000..f1a043fe5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/ipc.h
@@ -0,0 +1,56 @@
+/* Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IPC_H
+# error "Never use <bits/ipc.h> directly; include <sys/ipc.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Mode bits for `msgget', `semget', and `shmget'. */
+#define IPC_CREAT 01000 /* Create key if key does not exist. */
+#define IPC_EXCL 02000 /* Fail if key exists. */
+#define IPC_NOWAIT 04000 /* Return error on wait. */
+
+/* Control commands for `msgctl', `semctl', and `shmctl'. */
+#define IPC_RMID 0 /* Remove identifier. */
+#define IPC_SET 1 /* Set `ipc_perm' options. */
+#define IPC_STAT 2 /* Get `ipc_perm' options. */
+#ifdef __USE_GNU
+# define IPC_INFO 3 /* See ipcs. */
+#endif
+
+/* Special key values. */
+#define IPC_PRIVATE ((__key_t) 0) /* Private key. */
+
+
+/* Data structure used to pass permission information to IPC operations. */
+struct ipc_perm
+ {
+ __key_t __key; /* Key. */
+ __uid_t uid; /* Owner's user ID. */
+ __gid_t gid; /* Owner's group ID. */
+ __uid_t cuid; /* Creator's user ID. */
+ __gid_t cgid; /* Creator's group ID. */
+ unsigned short int mode; /* Read/write permission. */
+ unsigned short int __pad1;
+ unsigned short int __seq; /* Sequence number. */
+ unsigned short int __pad2;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ };
diff --git a/libc/sysdeps/unix/sysv/linux/bits/local_lim.h b/libc/sysdeps/unix/sysv/linux/bits/local_lim.h
new file mode 100644
index 000000000..54a51ee76
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/local_lim.h
@@ -0,0 +1,68 @@
+/* Minimum guaranteed maximum values for system limits. Linux version.
+ Copyright (C) 1993-1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* The kernel header pollutes the namespace with the NR_OPEN symbol
+ and defines LINK_MAX although filesystems have different maxima. A
+ similar thing is true for OPEN_MAX: the limit can be changed at
+ runtime and therefore the macro must not be defined. Remove this
+ after including the header if necessary. */
+#ifndef NR_OPEN
+# define __undef_NR_OPEN
+#endif
+#ifndef LINK_MAX
+# define __undef_LINK_MAX
+#endif
+#ifndef OPEN_MAX
+# define __undef_OPEN_MAX
+#endif
+
+/* The kernel sources contain a file with all the needed information. */
+#include <linux/limits.h>
+
+/* Have to remove NR_OPEN? */
+#ifdef __undef_NR_OPEN
+# undef NR_OPEN
+# undef __undef_NR_OPEN
+#endif
+/* Have to remove LINK_MAX? */
+#ifdef __undef_LINK_MAX
+# undef LINK_MAX
+# undef __undef_LINK_MAX
+#endif
+/* Have to remove OPEN_MAX? */
+#ifdef __undef_OPEN_MAX
+# undef OPEN_MAX
+# undef __undef_OPEN_MAX
+#endif
+
+/* Maximum amount by which a process can descrease its asynchronous I/O
+ priority level. */
+#define AIO_PRIO_DELTA_MAX 20
+
+/* Maximum tty name length. */
+#define TTY_NAME_MAX 32
+
+/* Maximum login name length. This is arbitrary. */
+#define LOGIN_NAME_MAX 256
+
+/* Maximum host name length. */
+#define HOST_NAME_MAX 64
+
+/* Maximum message queue priority level. */
+#define MQ_PRIO_MAX 32768
diff --git a/libc/sysdeps/unix/sysv/linux/bits/mqueue.h b/libc/sysdeps/unix/sysv/linux/bits/mqueue.h
new file mode 100644
index 000000000..df528f876
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/mqueue.h
@@ -0,0 +1,32 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _MQUEUE_H
+# error "Never use <bits/mqueue.h> directly; include <mqueue.h> instead."
+#endif
+
+typedef int mqd_t;
+
+struct mq_attr
+{
+ long int mq_flags; /* Message queue flags. */
+ long int mq_maxmsg; /* Maximum number of messages. */
+ long int mq_msgsize; /* Maximum message size. */
+ long int mq_curmsgs; /* Number of messages currently queued. */
+ long int __pad[4];
+};
diff --git a/libc/sysdeps/unix/sysv/linux/bits/msq.h b/libc/sysdeps/unix/sysv/linux/bits/msq.h
new file mode 100644
index 000000000..32a49b592
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/msq.h
@@ -0,0 +1,77 @@
+/* Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MSG_H
+# error "Never use <bits/msq.h> directly; include <sys/msg.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Define options for message queue functions. */
+#define MSG_NOERROR 010000 /* no error if message is too big */
+#ifdef __USE_GNU
+# define MSG_EXCEPT 020000 /* recv any msg except of specified type */
+#endif
+
+/* Types used in the structure definition. */
+typedef unsigned long int msgqnum_t;
+typedef unsigned long int msglen_t;
+
+
+/* Structure of record for one message inside the kernel.
+ The type `struct msg' is opaque. */
+struct msqid_ds
+{
+ struct ipc_perm msg_perm; /* structure describing operation permission */
+ __time_t msg_stime; /* time of last msgsnd command */
+ unsigned long int __unused1;
+ __time_t msg_rtime; /* time of last msgrcv command */
+ unsigned long int __unused2;
+ __time_t msg_ctime; /* time of last change */
+ unsigned long int __unused3;
+ unsigned long int __msg_cbytes; /* current number of bytes on queue */
+ msgqnum_t msg_qnum; /* number of messages currently on queue */
+ msglen_t msg_qbytes; /* max number of bytes allowed on queue */
+ __pid_t msg_lspid; /* pid of last msgsnd() */
+ __pid_t msg_lrpid; /* pid of last msgrcv() */
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+};
+
+#ifdef __USE_MISC
+
+# define msg_cbytes __msg_cbytes
+
+/* ipcs ctl commands */
+# define MSG_STAT 11
+# define MSG_INFO 12
+
+/* buffer for msgctl calls IPC_INFO, MSG_INFO */
+struct msginfo
+ {
+ int msgpool;
+ int msgmap;
+ int msgmax;
+ int msgmnb;
+ int msgmni;
+ int msgssz;
+ int msgtql;
+ unsigned short int msgseg;
+ };
+
+#endif /* __USE_MISC */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/poll.h b/libc/sysdeps/unix/sysv/linux/bits/poll.h
new file mode 100644
index 000000000..d7996b46c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/poll.h
@@ -0,0 +1,50 @@
+/* Copyright (C) 1997, 2001, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_POLL_H
+# error "Never use <bits/poll.h> directly; include <sys/poll.h> instead."
+#endif
+
+/* Event types that can be polled for. These bits may be set in `events'
+ to indicate the interesting event types; they will appear in `revents'
+ to indicate the status of the file descriptor. */
+#define POLLIN 0x001 /* There is data to read. */
+#define POLLPRI 0x002 /* There is urgent data to read. */
+#define POLLOUT 0x004 /* Writing now will not block. */
+
+#ifdef __USE_XOPEN
+/* These values are defined in XPG4.2. */
+# define POLLRDNORM 0x040 /* Normal data may be read. */
+# define POLLRDBAND 0x080 /* Priority data may be read. */
+# define POLLWRNORM 0x100 /* Writing now will not block. */
+# define POLLWRBAND 0x200 /* Priority data may be written. */
+#endif
+
+#ifdef __USE_GNU
+/* These are extensions for Linux. */
+# define POLLMSG 0x400
+# define POLLREMOVE 0x1000
+# define POLLRDHUP 0x2000
+#endif
+
+/* Event types always implicitly polled for. These bits need not be set in
+ `events', but they will appear in `revents' to indicate the status of
+ the file descriptor. */
+#define POLLERR 0x008 /* Error condition. */
+#define POLLHUP 0x010 /* Hung up. */
+#define POLLNVAL 0x020 /* Invalid polling request. */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/posix_opt.h b/libc/sysdeps/unix/sysv/linux/bits/posix_opt.h
new file mode 100644
index 000000000..1a96db298
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/posix_opt.h
@@ -0,0 +1,96 @@
+/* Define POSIX options for Linux.
+ Copyright (C) 1996,1997,1999,2000,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/*
+ * Never include this file directly; use <unistd.h> instead.
+ */
+
+#ifndef _BITS_POSIX_OPT_H
+#define _BITS_POSIX_OPT_H 1
+
+/* Job control is supported. */
+#define _POSIX_JOB_CONTROL 1
+
+/* Processes have a saved set-user-ID and a saved set-group-ID. */
+#define _POSIX_SAVED_IDS 1
+
+/* Priority scheduling is supported. */
+#define _POSIX_PRIORITY_SCHEDULING 200112L
+
+/* Synchronizing file data is supported. */
+#define _POSIX_SYNCHRONIZED_IO 200112L
+
+/* The fsync function is present. */
+#define _POSIX_FSYNC 200112L
+
+/* Mapping of files to memory is supported. */
+#define _POSIX_MAPPED_FILES 200112L
+
+/* Locking of all memory is supported. */
+#define _POSIX_MEMLOCK 200112L
+
+/* Locking of ranges of memory is supported. */
+#define _POSIX_MEMLOCK_RANGE 200112L
+
+/* Setting of memory protections is supported. */
+#define _POSIX_MEMORY_PROTECTION 200112L
+
+/* Only root can change owner of file. */
+#define _POSIX_CHOWN_RESTRICTED 1
+
+/* `c_cc' member of 'struct termios' structure can be disabled by
+ using the value _POSIX_VDISABLE. */
+#define _POSIX_VDISABLE '\0'
+
+/* Filenames are not silently truncated. */
+#define _POSIX_NO_TRUNC 1
+
+/* X/Open realtime support is available. */
+#define _XOPEN_REALTIME 1
+
+/* XPG4.2 shared memory is supported. */
+#define _XOPEN_SHM 1
+
+/* Real-time signals are supported. */
+#define _POSIX_REALTIME_SIGNALS 200112L
+
+/* The LFS interface is available, except for the asynchronous I/O. */
+#define _LFS_LARGEFILE 1
+#define _LFS64_LARGEFILE 1
+#define _LFS64_STDIO 1
+
+/* POSIX timers are available. */
+#define _POSIX_TIMERS 200112L
+
+/* POSIX shared memory objects are implemented. */
+#define _POSIX_SHARED_MEMORY_OBJECTS 200112L
+
+/* GNU libc provides regular expression handling. */
+#define _POSIX_REGEXP 1
+
+/* We have a POSIX shell. */
+#define _POSIX_SHELL 1
+
+/* The `spawn' function family is supported. */
+#define _POSIX_SPAWN 200112L
+
+/* The monotonic clock might be available. */
+#define _POSIX_MONOTONIC_CLOCK 0
+
+#endif /* bits/posix_opt.h */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/resource.h b/libc/sysdeps/unix/sysv/linux/bits/resource.h
new file mode 100644
index 000000000..526cdaf53
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/resource.h
@@ -0,0 +1,225 @@
+/* Bit values & structures for resource limits. Linux version.
+ Copyright (C) 1994, 1996, 1997, 1998, 1999, 2000, 2004, 2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_RESOURCE_H
+# error "Never use <bits/resource.h> directly; include <sys/resource.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Transmute defines to enumerations. The macro re-definitions are
+ necessary because some programs want to test for operating system
+ features with #ifdef RUSAGE_SELF. In ISO C the reflexive
+ definition is a no-op. */
+
+/* Kinds of resource limit. */
+enum __rlimit_resource
+{
+ /* Per-process CPU limit, in seconds. */
+ RLIMIT_CPU = 0,
+#define RLIMIT_CPU RLIMIT_CPU
+
+ /* Largest file that can be created, in bytes. */
+ RLIMIT_FSIZE = 1,
+#define RLIMIT_FSIZE RLIMIT_FSIZE
+
+ /* Maximum size of data segment, in bytes. */
+ RLIMIT_DATA = 2,
+#define RLIMIT_DATA RLIMIT_DATA
+
+ /* Maximum size of stack segment, in bytes. */
+ RLIMIT_STACK = 3,
+#define RLIMIT_STACK RLIMIT_STACK
+
+ /* Largest core file that can be created, in bytes. */
+ RLIMIT_CORE = 4,
+#define RLIMIT_CORE RLIMIT_CORE
+
+ /* Largest resident set size, in bytes.
+ This affects swapping; processes that are exceeding their
+ resident set size will be more likely to have physical memory
+ taken from them. */
+ __RLIMIT_RSS = 5,
+#define RLIMIT_RSS __RLIMIT_RSS
+
+ /* Number of open files. */
+ RLIMIT_NOFILE = 7,
+ __RLIMIT_OFILE = RLIMIT_NOFILE, /* BSD name for same. */
+#define RLIMIT_NOFILE RLIMIT_NOFILE
+#define RLIMIT_OFILE __RLIMIT_OFILE
+
+ /* Address space limit. */
+ RLIMIT_AS = 9,
+#define RLIMIT_AS RLIMIT_AS
+
+ /* Number of processes. */
+ __RLIMIT_NPROC = 6,
+#define RLIMIT_NPROC __RLIMIT_NPROC
+
+ /* Locked-in-memory address space. */
+ __RLIMIT_MEMLOCK = 8,
+#define RLIMIT_MEMLOCK __RLIMIT_MEMLOCK
+
+ /* Maximum number of file locks. */
+ __RLIMIT_LOCKS = 10,
+#define RLIMIT_LOCKS __RLIMIT_LOCKS
+
+ /* Maximum number of pending signals. */
+ __RLIMIT_SIGPENDING = 11,
+#define RLIMIT_SIGPENDING __RLIMIT_SIGPENDING
+
+ /* Maximum bytes in POSIX message queues. */
+ __RLIMIT_MSGQUEUE = 12,
+#define RLIMIT_MSGQUEUE __RLIMIT_MSGQUEUE
+
+ /* Maximum nice priority allowed to raise to.
+ Nice levels 19 .. -20 correspond to 0 .. 39
+ values of this resource limit. */
+ __RLIMIT_NICE = 13,
+#define RLIMIT_NICE __RLIMIT_NICE
+
+ /* Maximum realtime priority allowed for non-priviledged
+ processes. */
+ __RLIMIT_RTPRIO = 14,
+#define RLIMIT_RTPRIO __RLIMIT_RTPRIO
+
+ __RLIMIT_NLIMITS = 15,
+ __RLIM_NLIMITS = __RLIMIT_NLIMITS
+#define RLIMIT_NLIMITS __RLIMIT_NLIMITS
+#define RLIM_NLIMITS __RLIM_NLIMITS
+};
+
+/* Value to indicate that there is no limit. */
+#ifndef __USE_FILE_OFFSET64
+# define RLIM_INFINITY ((unsigned long int)(~0UL))
+#else
+# define RLIM_INFINITY 0xffffffffffffffffuLL
+#endif
+
+#ifdef __USE_LARGEFILE64
+# define RLIM64_INFINITY 0xffffffffffffffffuLL
+#endif
+
+/* We can represent all limits. */
+#define RLIM_SAVED_MAX RLIM_INFINITY
+#define RLIM_SAVED_CUR RLIM_INFINITY
+
+
+/* Type for resource quantity measurement. */
+#ifndef __USE_FILE_OFFSET64
+typedef __rlim_t rlim_t;
+#else
+typedef __rlim64_t rlim_t;
+#endif
+#ifdef __USE_LARGEFILE64
+typedef __rlim64_t rlim64_t;
+#endif
+
+struct rlimit
+ {
+ /* The current (soft) limit. */
+ rlim_t rlim_cur;
+ /* The hard limit. */
+ rlim_t rlim_max;
+ };
+
+#ifdef __USE_LARGEFILE64
+struct rlimit64
+ {
+ /* The current (soft) limit. */
+ rlim64_t rlim_cur;
+ /* The hard limit. */
+ rlim64_t rlim_max;
+ };
+#endif
+
+/* Whose usage statistics do you want? */
+enum __rusage_who
+{
+ /* The calling process. */
+ RUSAGE_SELF = 0,
+#define RUSAGE_SELF RUSAGE_SELF
+
+ /* All of its terminated child processes. */
+ RUSAGE_CHILDREN = -1
+#define RUSAGE_CHILDREN RUSAGE_CHILDREN
+};
+
+#define __need_timeval
+#include <bits/time.h> /* For `struct timeval'. */
+
+/* Structure which says how much of each resource has been used. */
+struct rusage
+ {
+ /* Total amount of user time used. */
+ struct timeval ru_utime;
+ /* Total amount of system time used. */
+ struct timeval ru_stime;
+ /* Maximum resident set size (in kilobytes). */
+ long int ru_maxrss;
+ /* Amount of sharing of text segment memory
+ with other processes (kilobyte-seconds). */
+ long int ru_ixrss;
+ /* Amount of data segment memory used (kilobyte-seconds). */
+ long int ru_idrss;
+ /* Amount of stack memory used (kilobyte-seconds). */
+ long int ru_isrss;
+ /* Number of soft page faults (i.e. those serviced by reclaiming
+ a page from the list of pages awaiting reallocation. */
+ long int ru_minflt;
+ /* Number of hard page faults (i.e. those that required I/O). */
+ long int ru_majflt;
+ /* Number of times a process was swapped out of physical memory. */
+ long int ru_nswap;
+ /* Number of input operations via the file system. Note: This
+ and `ru_oublock' do not include operations with the cache. */
+ long int ru_inblock;
+ /* Number of output operations via the file system. */
+ long int ru_oublock;
+ /* Number of IPC messages sent. */
+ long int ru_msgsnd;
+ /* Number of IPC messages received. */
+ long int ru_msgrcv;
+ /* Number of signals delivered. */
+ long int ru_nsignals;
+ /* Number of voluntary context switches, i.e. because the process
+ gave up the process before it had to (usually to wait for some
+ resource to be available). */
+ long int ru_nvcsw;
+ /* Number of involuntary context switches, i.e. a higher priority process
+ became runnable or the current process used up its time slice. */
+ long int ru_nivcsw;
+ };
+
+/* Priority limits. */
+#define PRIO_MIN -20 /* Minimum priority a process can have. */
+#define PRIO_MAX 20 /* Maximum priority a process can have. */
+
+/* The type of the WHICH argument to `getpriority' and `setpriority',
+ indicating what flavor of entity the WHO argument specifies. */
+enum __priority_which
+{
+ PRIO_PROCESS = 0, /* WHO is a process ID. */
+#define PRIO_PROCESS PRIO_PROCESS
+ PRIO_PGRP = 1, /* WHO is a process group ID. */
+#define PRIO_PGRP PRIO_PGRP
+ PRIO_USER = 2 /* WHO is a user ID. */
+#define PRIO_USER PRIO_USER
+};
diff --git a/libc/sysdeps/unix/sysv/linux/bits/sched.h b/libc/sysdeps/unix/sysv/linux/bits/sched.h
new file mode 100644
index 000000000..4a95a263f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/sched.h
@@ -0,0 +1,130 @@
+/* Definitions of constants and data structure for POSIX 1003.1b-1993
+ scheduling interface.
+ Copyright (C) 1996-1999,2001-2003,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef __need_schedparam
+
+#ifndef _SCHED_H
+# error "Never include <bits/sched.h> directly; use <sched.h> instead."
+#endif
+
+
+/* Scheduling algorithms. */
+#define SCHED_OTHER 0
+#define SCHED_FIFO 1
+#define SCHED_RR 2
+#ifdef __USE_GNU
+# define SCHED_BATCH 3
+#endif
+
+#ifdef __USE_MISC
+/* Cloning flags. */
+# define CSIGNAL 0x000000ff /* Signal mask to be sent at exit. */
+# define CLONE_VM 0x00000100 /* Set if VM shared between processes. */
+# define CLONE_FS 0x00000200 /* Set if fs info shared between processes. */
+# define CLONE_FILES 0x00000400 /* Set if open files shared between processes. */
+# define CLONE_SIGHAND 0x00000800 /* Set if signal handlers shared. */
+# define CLONE_PTRACE 0x00002000 /* Set if tracing continues on the child. */
+# define CLONE_VFORK 0x00004000 /* Set if the parent wants the child to
+ wake it up on mm_release. */
+# define CLONE_PARENT 0x00008000 /* Set if we want to have the same
+ parent as the cloner. */
+# define CLONE_THREAD 0x00010000 /* Set to add to same thread group. */
+# define CLONE_NEWNS 0x00020000 /* Set to create new namespace. */
+# define CLONE_SYSVSEM 0x00040000 /* Set to shared SVID SEM_UNDO semantics. */
+# define CLONE_SETTLS 0x00080000 /* Set TLS info. */
+# define CLONE_PARENT_SETTID 0x00100000 /* Store TID in userlevel buffer
+ before MM copy. */
+# define CLONE_CHILD_CLEARTID 0x00200000 /* Register exit futex and memory
+ location to clear. */
+# define CLONE_DETACHED 0x00400000 /* Create clone detached. */
+# define CLONE_UNTRACED 0x00800000 /* Set if the tracing process can't
+ force CLONE_PTRACE on this clone. */
+# define CLONE_CHILD_SETTID 0x01000000 /* Store TID in userlevel buffer in
+ the child. */
+# define CLONE_STOPPED 0x02000000 /* Start in stopped state. */
+#endif
+
+/* The official definition. */
+struct sched_param
+ {
+ int __sched_priority;
+ };
+
+__BEGIN_DECLS
+
+#ifdef __USE_MISC
+/* Clone current process. */
+extern int clone (int (*__fn) (void *__arg), void *__child_stack,
+ int __flags, void *__arg, ...) __THROW;
+
+/* Unshare the specified resources. */
+extern int unshare (int __flags) __THROW;
+#endif
+
+__END_DECLS
+
+#endif /* need schedparam */
+
+#if !defined __defined_schedparam \
+ && (defined __need_schedparam || defined _SCHED_H)
+# define __defined_schedparam 1
+/* Data structure to describe a process' schedulability. */
+struct __sched_param
+ {
+ int __sched_priority;
+ };
+# undef __need_schedparam
+#endif
+
+
+#if defined _SCHED_H && !defined __cpu_set_t_defined
+# define __cpu_set_t_defined
+/* Size definition for CPU sets. */
+# define __CPU_SETSIZE 1024
+# define __NCPUBITS (8 * sizeof (__cpu_mask))
+
+/* Type for array elements in 'cpu_set'. */
+typedef unsigned long int __cpu_mask;
+
+/* Basic access functions. */
+# define __CPUELT(cpu) ((cpu) / __NCPUBITS)
+# define __CPUMASK(cpu) ((__cpu_mask) 1 << ((cpu) % __NCPUBITS))
+
+/* Data structure to describe CPU mask. */
+typedef struct
+{
+ __cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
+} cpu_set_t;
+
+/* Access functions for CPU masks. */
+# define __CPU_ZERO(cpusetp) \
+ do { \
+ unsigned int __i; \
+ cpu_set_t *__arr = (cpusetp); \
+ for (__i = 0; __i < sizeof (cpu_set_t) / sizeof (__cpu_mask); ++__i) \
+ __arr->__bits[__i] = 0; \
+ } while (0)
+# define __CPU_SET(cpu, cpusetp) \
+ ((cpusetp)->__bits[__CPUELT (cpu)] |= __CPUMASK (cpu))
+# define __CPU_CLR(cpu, cpusetp) \
+ ((cpusetp)->__bits[__CPUELT (cpu)] &= ~__CPUMASK (cpu))
+# define __CPU_ISSET(cpu, cpusetp) \
+ (((cpusetp)->__bits[__CPUELT (cpu)] & __CPUMASK (cpu)) != 0)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/bits/sem.h b/libc/sysdeps/unix/sysv/linux/bits/sem.h
new file mode 100644
index 000000000..6193501e2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/sem.h
@@ -0,0 +1,87 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SEM_H
+# error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
+#endif
+
+#include <sys/types.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 */
+ unsigned long int __unused1;
+ __time_t sem_ctime; /* last time changed by semctl() */
+ unsigned long int __unused2;
+ unsigned long int sem_nsems; /* number of semaphores in set */
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+};
+
+/* The user should define a union like the following to use it for arguments
+ for `semctl'.
+
+ union semun
+ {
+ int val; <= value for SETVAL
+ struct semid_ds *buf; <= buffer for IPC_STAT & IPC_SET
+ unsigned short int *array; <= array for GETALL & SETALL
+ struct seminfo *__buf; <= buffer for IPC_INFO
+ };
+
+ Previous versions of this file used to define this union but this is
+ incorrect. One can test the macro _SEM_SEMUN_UNDEFINED to see whether
+ one must define the union or not. */
+#define _SEM_SEMUN_UNDEFINED 1
+
+#ifdef __USE_MISC
+
+/* ipcs ctl cmds */
+# define SEM_STAT 18
+# define SEM_INFO 19
+
+struct seminfo
+{
+ int semmap;
+ int semmni;
+ int semmns;
+ int semmnu;
+ int semmsl;
+ int semopm;
+ int semume;
+ int semusz;
+ int semvmx;
+ int semaem;
+};
+
+#endif /* __USE_MISC */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/shm.h b/libc/sysdeps/unix/sysv/linux/bits/shm.h
new file mode 100644
index 000000000..318d601ae
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/shm.h
@@ -0,0 +1,103 @@
+/* Copyright (C) 1995,1996,1997,2000,2002,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SHM_H
+# error "Never include <bits/shm.h> directly; use <sys/shm.h> instead."
+#endif
+
+#include <bits/types.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 */
+
+/* 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 set of semaphores. */
+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() */
+ unsigned long int __unused1;
+ __time_t shm_dtime; /* time of last shmdt() */
+ unsigned long int __unused2;
+ __time_t shm_ctime; /* time of last change by shmctl() */
+ unsigned long int __unused3;
+ __pid_t shm_cpid; /* pid of creator */
+ __pid_t shm_lpid; /* pid of last shmop */
+ shmatt_t shm_nattch; /* number of current attaches */
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+ };
+
+#ifdef __USE_MISC
+
+/* ipcs ctl commands */
+# define SHM_STAT 13
+# define SHM_INFO 14
+
+/* shm_mode upper byte flags */
+# define SHM_DEST 01000 /* segment will be destroyed on last detach */
+# define SHM_LOCKED 02000 /* segment will not be swapped */
+# define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */
+# define SHM_NORESERVE 010000 /* don't check for reservations */
+
+struct shminfo
+ {
+ unsigned long int shmmax;
+ unsigned long int shmmin;
+ unsigned long int shmmni;
+ unsigned long int shmseg;
+ unsigned long int shmall;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+ };
+
+struct shm_info
+ {
+ int used_ids;
+ unsigned long int shm_tot; /* total allocated shm */
+ unsigned long int shm_rss; /* total resident shm */
+ unsigned long int shm_swp; /* total swapped shm */
+ unsigned long int swap_attempts;
+ unsigned long int swap_successes;
+ };
+
+#endif /* __USE_MISC */
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/bits/sigaction.h b/libc/sysdeps/unix/sysv/linux/bits/sigaction.h
new file mode 100644
index 000000000..48cc5312f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/sigaction.h
@@ -0,0 +1,77 @@
+/* The proper definitions for Linux's sigaction.
+ Copyright (C) 1993-1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIGNAL_H
+# error "Never include <bits/sigaction.h> directly; use <signal.h> instead."
+#endif
+
+/* Structure describing the action to be taken when a signal arrives. */
+struct sigaction
+ {
+ /* Signal handler. */
+#ifdef __USE_POSIX199309
+ union
+ {
+ /* Used if SA_SIGINFO is not set. */
+ __sighandler_t sa_handler;
+ /* Used if SA_SIGINFO is set. */
+ void (*sa_sigaction) (int, siginfo_t *, void *);
+ }
+ __sigaction_handler;
+# define sa_handler __sigaction_handler.sa_handler
+# define sa_sigaction __sigaction_handler.sa_sigaction
+#else
+ __sighandler_t sa_handler;
+#endif
+
+ /* Additional set of signals to be blocked. */
+ __sigset_t sa_mask;
+
+ /* Special flags. */
+ int sa_flags;
+
+ /* Restore handler. */
+ void (*sa_restorer) (void);
+ };
+
+/* Bits in `sa_flags'. */
+#define SA_NOCLDSTOP 1 /* Don't send SIGCHLD when children stop. */
+#define SA_NOCLDWAIT 2 /* Don't create zombie on child death. */
+#define SA_SIGINFO 4 /* Invoke signal-catching function with
+ three arguments instead of one. */
+#if defined __USE_UNIX98 || defined __USE_MISC
+# define SA_ONSTACK 0x08000000 /* Use signal stack by using `sa_restorer'. */
+# define SA_RESTART 0x10000000 /* Restart syscall on signal return. */
+# define SA_NODEFER 0x40000000 /* Don't automatically block the signal when
+ its handler is being executed. */
+# define SA_RESETHAND 0x80000000 /* Reset to SIG_DFL on entry to handler. */
+#endif
+#ifdef __USE_MISC
+# define SA_INTERRUPT 0x20000000 /* Historical no-op. */
+
+/* Some aliases for the SA_ constants. */
+# define SA_NOMASK SA_NODEFER
+# define SA_ONESHOT SA_RESETHAND
+# define SA_STACK SA_ONSTACK
+#endif
+
+/* Values for the HOW argument to `sigprocmask'. */
+#define SIG_BLOCK 0 /* Block signals. */
+#define SIG_UNBLOCK 1 /* Unblock signals. */
+#define SIG_SETMASK 2 /* Set the set of blocked signals. */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/sigcontext.h b/libc/sysdeps/unix/sysv/linux/bits/sigcontext.h
new file mode 100644
index 000000000..67dcf9498
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/sigcontext.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#if !defined _SIGNAL_H && !defined _SYS_UCONTEXT_H
+# error "Never use <bits/sigcontext.h> directly; include <signal.h> instead."
+#endif
+
+#ifndef sigcontext_struct
+/* Kernel headers before 2.1.1 define a struct sigcontext_struct, but
+ we need sigcontext. */
+# define sigcontext_struct sigcontext
+
+# include <asm/sigcontext.h>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/bits/siginfo.h b/libc/sysdeps/unix/sysv/linux/bits/siginfo.h
new file mode 100644
index 000000000..4ce319dc9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/siginfo.h
@@ -0,0 +1,313 @@
+/* siginfo_t, sigevent and constants. Linux version.
+ Copyright (C) 1997-2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#if !defined _SIGNAL_H && !defined __need_siginfo_t \
+ && !defined __need_sigevent_t
+# error "Never include this file directly. Use <signal.h> instead"
+#endif
+
+#include <bits/wordsize.h>
+
+#if (!defined __have_sigval_t \
+ && (defined _SIGNAL_H || defined __need_siginfo_t \
+ || defined __need_sigevent_t))
+# define __have_sigval_t 1
+
+/* Type for data associated with a signal. */
+typedef union sigval
+ {
+ int sival_int;
+ void *sival_ptr;
+ } sigval_t;
+#endif
+
+#if (!defined __have_siginfo_t \
+ && (defined _SIGNAL_H || defined __need_siginfo_t))
+# define __have_siginfo_t 1
+
+# define __SI_MAX_SIZE 128
+# if __WORDSIZE == 64
+# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 4)
+# else
+# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
+# endif
+
+typedef struct siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_errno; /* If non-zero, an errno value associated with
+ this signal, as defined in <errno.h>. */
+ int si_code; /* Signal code. */
+
+ union
+ {
+ int _pad[__SI_PAD_SIZE];
+
+ /* kill(). */
+ struct
+ {
+ __pid_t si_pid; /* Sending process ID. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ } _kill;
+
+ /* POSIX.1b timers. */
+ struct
+ {
+ int si_tid; /* Timer ID. */
+ int si_overrun; /* Overrun count. */
+ sigval_t si_sigval; /* Signal value. */
+ } _timer;
+
+ /* POSIX.1b signals. */
+ struct
+ {
+ __pid_t si_pid; /* Sending process ID. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ sigval_t si_sigval; /* Signal value. */
+ } _rt;
+
+ /* SIGCHLD. */
+ struct
+ {
+ __pid_t si_pid; /* Which child. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ int si_status; /* Exit value or signal. */
+ __clock_t si_utime;
+ __clock_t si_stime;
+ } _sigchld;
+
+ /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
+ struct
+ {
+ void *si_addr; /* Faulting insn/memory ref. */
+ } _sigfault;
+
+ /* SIGPOLL. */
+ struct
+ {
+ long int si_band; /* Band event for SIGPOLL. */
+ int si_fd;
+ } _sigpoll;
+ } _sifields;
+ } siginfo_t;
+
+
+/* X/Open requires some more fields with fixed names. */
+# define si_pid _sifields._kill.si_pid
+# define si_uid _sifields._kill.si_uid
+# define si_timerid _sifields._timer.si_tid
+# define si_overrun _sifields._timer.si_overrun
+# define si_status _sifields._sigchld.si_status
+# define si_utime _sifields._sigchld.si_utime
+# define si_stime _sifields._sigchld.si_stime
+# define si_value _sifields._rt.si_sigval
+# define si_int _sifields._rt.si_sigval.sival_int
+# define si_ptr _sifields._rt.si_sigval.sival_ptr
+# define si_addr _sifields._sigfault.si_addr
+# define si_band _sifields._sigpoll.si_band
+# define si_fd _sifields._sigpoll.si_fd
+
+
+/* Values for `si_code'. Positive values are reserved for kernel-generated
+ signals. */
+enum
+{
+ SI_ASYNCNL = -60, /* Sent by asynch name lookup completion. */
+# define SI_ASYNCNL SI_ASYNCNL
+ SI_TKILL = -6, /* Sent by tkill. */
+# define SI_TKILL SI_TKILL
+ SI_SIGIO, /* Sent by queued SIGIO. */
+# define SI_SIGIO SI_SIGIO
+ SI_ASYNCIO, /* Sent by AIO completion. */
+# define SI_ASYNCIO SI_ASYNCIO
+ SI_MESGQ, /* Sent by real time mesq state change. */
+# define SI_MESGQ SI_MESGQ
+ SI_TIMER, /* Sent by timer expiration. */
+# define SI_TIMER SI_TIMER
+ SI_QUEUE, /* Sent by sigqueue. */
+# define SI_QUEUE SI_QUEUE
+ SI_USER, /* Sent by kill, sigsend, raise. */
+# define SI_USER SI_USER
+ SI_KERNEL = 0x80 /* Send by kernel. */
+#define SI_KERNEL SI_KERNEL
+};
+
+
+/* `si_code' values for SIGILL signal. */
+enum
+{
+ ILL_ILLOPC = 1, /* Illegal opcode. */
+# define ILL_ILLOPC ILL_ILLOPC
+ ILL_ILLOPN, /* Illegal operand. */
+# define ILL_ILLOPN ILL_ILLOPN
+ ILL_ILLADR, /* Illegal addressing mode. */
+# define ILL_ILLADR ILL_ILLADR
+ ILL_ILLTRP, /* Illegal trap. */
+# define ILL_ILLTRP ILL_ILLTRP
+ ILL_PRVOPC, /* Privileged opcode. */
+# define ILL_PRVOPC ILL_PRVOPC
+ ILL_PRVREG, /* Privileged register. */
+# define ILL_PRVREG ILL_PRVREG
+ ILL_COPROC, /* Coprocessor error. */
+# define ILL_COPROC ILL_COPROC
+ ILL_BADSTK /* Internal stack error. */
+# define ILL_BADSTK ILL_BADSTK
+};
+
+/* `si_code' values for SIGFPE signal. */
+enum
+{
+ FPE_INTDIV = 1, /* Integer divide by zero. */
+# define FPE_INTDIV FPE_INTDIV
+ FPE_INTOVF, /* Integer overflow. */
+# define FPE_INTOVF FPE_INTOVF
+ FPE_FLTDIV, /* Floating point divide by zero. */
+# define FPE_FLTDIV FPE_FLTDIV
+ FPE_FLTOVF, /* Floating point overflow. */
+# define FPE_FLTOVF FPE_FLTOVF
+ FPE_FLTUND, /* Floating point underflow. */
+# define FPE_FLTUND FPE_FLTUND
+ FPE_FLTRES, /* Floating point inexact result. */
+# define FPE_FLTRES FPE_FLTRES
+ FPE_FLTINV, /* Floating point invalid operation. */
+# define FPE_FLTINV FPE_FLTINV
+ FPE_FLTSUB /* Subscript out of range. */
+# define FPE_FLTSUB FPE_FLTSUB
+};
+
+/* `si_code' values for SIGSEGV signal. */
+enum
+{
+ SEGV_MAPERR = 1, /* Address not mapped to object. */
+# define SEGV_MAPERR SEGV_MAPERR
+ SEGV_ACCERR /* Invalid permissions for mapped object. */
+# define SEGV_ACCERR SEGV_ACCERR
+};
+
+/* `si_code' values for SIGBUS signal. */
+enum
+{
+ BUS_ADRALN = 1, /* Invalid address alignment. */
+# define BUS_ADRALN BUS_ADRALN
+ BUS_ADRERR, /* Non-existant physical address. */
+# define BUS_ADRERR BUS_ADRERR
+ BUS_OBJERR /* Object specific hardware error. */
+# define BUS_OBJERR BUS_OBJERR
+};
+
+/* `si_code' values for SIGTRAP signal. */
+enum
+{
+ TRAP_BRKPT = 1, /* Process breakpoint. */
+# define TRAP_BRKPT TRAP_BRKPT
+ TRAP_TRACE /* Process trace trap. */
+# define TRAP_TRACE TRAP_TRACE
+};
+
+/* `si_code' values for SIGCHLD signal. */
+enum
+{
+ CLD_EXITED = 1, /* Child has exited. */
+# define CLD_EXITED CLD_EXITED
+ CLD_KILLED, /* Child was killed. */
+# define CLD_KILLED CLD_KILLED
+ CLD_DUMPED, /* Child terminated abnormally. */
+# define CLD_DUMPED CLD_DUMPED
+ CLD_TRAPPED, /* Traced child has trapped. */
+# define CLD_TRAPPED CLD_TRAPPED
+ CLD_STOPPED, /* Child has stopped. */
+# define CLD_STOPPED CLD_STOPPED
+ CLD_CONTINUED /* Stopped child has continued. */
+# define CLD_CONTINUED CLD_CONTINUED
+};
+
+/* `si_code' values for SIGPOLL signal. */
+enum
+{
+ POLL_IN = 1, /* Data input available. */
+# define POLL_IN POLL_IN
+ POLL_OUT, /* Output buffers available. */
+# define POLL_OUT POLL_OUT
+ POLL_MSG, /* Input message available. */
+# define POLL_MSG POLL_MSG
+ POLL_ERR, /* I/O error. */
+# define POLL_ERR POLL_ERR
+ POLL_PRI, /* High priority input available. */
+# define POLL_PRI POLL_PRI
+ POLL_HUP /* Device disconnected. */
+# define POLL_HUP POLL_HUP
+};
+
+# undef __need_siginfo_t
+#endif /* !have siginfo_t && (have _SIGNAL_H || need siginfo_t). */
+
+
+#if (defined _SIGNAL_H || defined __need_sigevent_t) \
+ && !defined __have_sigevent_t
+# define __have_sigevent_t 1
+
+/* Structure to transport application-defined values with signals. */
+# define __SIGEV_MAX_SIZE 64
+# if __WORDSIZE == 64
+# define __SIGEV_PAD_SIZE ((__SIGEV_MAX_SIZE / sizeof (int)) - 4)
+# else
+# define __SIGEV_PAD_SIZE ((__SIGEV_MAX_SIZE / sizeof (int)) - 3)
+# endif
+
+typedef struct sigevent
+ {
+ sigval_t sigev_value;
+ int sigev_signo;
+ int sigev_notify;
+
+ union
+ {
+ int _pad[__SIGEV_PAD_SIZE];
+
+ /* When SIGEV_SIGNAL and SIGEV_THREAD_ID set, LWP ID of the
+ thread to receive the signal. */
+ __pid_t _tid;
+
+ struct
+ {
+ void (*_function) (sigval_t); /* Function to start. */
+ void *_attribute; /* Really pthread_attr_t. */
+ } _sigev_thread;
+ } _sigev_un;
+ } sigevent_t;
+
+/* POSIX names to access some of the members. */
+# define sigev_notify_function _sigev_un._sigev_thread._function
+# define sigev_notify_attributes _sigev_un._sigev_thread._attribute
+
+/* `sigev_notify' values. */
+enum
+{
+ SIGEV_SIGNAL = 0, /* Notify via signal. */
+# define SIGEV_SIGNAL SIGEV_SIGNAL
+ SIGEV_NONE, /* Other notification: meaningless. */
+# define SIGEV_NONE SIGEV_NONE
+ SIGEV_THREAD, /* Deliver via thread creation. */
+# define SIGEV_THREAD SIGEV_THREAD
+
+ SIGEV_THREAD_ID = 4 /* Send signal to specific thread. */
+#define SIGEV_THREAD_ID SIGEV_THREAD_ID
+};
+
+#endif /* have _SIGNAL_H. */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/signum.h b/libc/sysdeps/unix/sysv/linux/bits/signum.h
new file mode 100644
index 000000000..a18ac113a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/signum.h
@@ -0,0 +1,80 @@
+/* Signal number definitions. Linux version.
+ Copyright (C) 1995,1996,1997,1998,1999,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifdef _SIGNAL_H
+
+/* Fake signal functions. */
+#define SIG_ERR ((__sighandler_t) -1) /* Error return. */
+#define SIG_DFL ((__sighandler_t) 0) /* Default action. */
+#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */
+
+#ifdef __USE_UNIX98
+# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */
+#endif
+
+
+/* Signals. */
+#define SIGHUP 1 /* Hangup (POSIX). */
+#define SIGINT 2 /* Interrupt (ANSI). */
+#define SIGQUIT 3 /* Quit (POSIX). */
+#define SIGILL 4 /* Illegal instruction (ANSI). */
+#define SIGTRAP 5 /* Trace trap (POSIX). */
+#define SIGABRT 6 /* Abort (ANSI). */
+#define SIGIOT 6 /* IOT trap (4.2 BSD). */
+#define SIGBUS 7 /* BUS error (4.2 BSD). */
+#define SIGFPE 8 /* Floating-point exception (ANSI). */
+#define SIGKILL 9 /* Kill, unblockable (POSIX). */
+#define SIGUSR1 10 /* User-defined signal 1 (POSIX). */
+#define SIGSEGV 11 /* Segmentation violation (ANSI). */
+#define SIGUSR2 12 /* User-defined signal 2 (POSIX). */
+#define SIGPIPE 13 /* Broken pipe (POSIX). */
+#define SIGALRM 14 /* Alarm clock (POSIX). */
+#define SIGTERM 15 /* Termination (ANSI). */
+#define SIGSTKFLT 16 /* Stack fault. */
+#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */
+#define SIGCHLD 17 /* Child status has changed (POSIX). */
+#define SIGCONT 18 /* Continue (POSIX). */
+#define SIGSTOP 19 /* Stop, unblockable (POSIX). */
+#define SIGTSTP 20 /* Keyboard stop (POSIX). */
+#define SIGTTIN 21 /* Background read from tty (POSIX). */
+#define SIGTTOU 22 /* Background write to tty (POSIX). */
+#define SIGURG 23 /* Urgent condition on socket (4.2 BSD). */
+#define SIGXCPU 24 /* CPU limit exceeded (4.2 BSD). */
+#define SIGXFSZ 25 /* File size limit exceeded (4.2 BSD). */
+#define SIGVTALRM 26 /* Virtual alarm clock (4.2 BSD). */
+#define SIGPROF 27 /* Profiling alarm clock (4.2 BSD). */
+#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */
+#define SIGPOLL SIGIO /* Pollable event occurred (System V). */
+#define SIGIO 29 /* I/O now possible (4.2 BSD). */
+#define SIGPWR 30 /* Power failure restart (System V). */
+#define SIGSYS 31 /* Bad system call. */
+#define SIGUNUSED 31
+
+#define _NSIG 65 /* Biggest signal number + 1
+ (including real-time signals). */
+
+#define SIGRTMIN (__libc_current_sigrtmin ())
+#define SIGRTMAX (__libc_current_sigrtmax ())
+
+/* These are the hard limits of the kernel. These values should not be
+ used directly at user level. */
+#define __SIGRTMIN 32
+#define __SIGRTMAX (_NSIG - 1)
+
+#endif /* <signal.h> included. */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/sigset.h b/libc/sysdeps/unix/sysv/linux/bits/sigset.h
new file mode 100644
index 000000000..7ccadda45
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/sigset.h
@@ -0,0 +1,125 @@
+/* __sig_atomic_t, __sigset_t, and related definitions. Linux version.
+ Copyright (C) 1991, 1992, 1994, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIGSET_H_types
+# define _SIGSET_H_types 1
+
+typedef int __sig_atomic_t;
+
+/* A `sigset_t' has a bit for each signal. */
+
+# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
+typedef struct
+ {
+ unsigned long int __val[_SIGSET_NWORDS];
+ } __sigset_t;
+
+#endif
+
+
+/* We only want to define these functions if <signal.h> was actually
+ included; otherwise we were included just to define the types. Since we
+ are namespace-clean, it wouldn't hurt to define extra macros. But
+ trouble can be caused by functions being defined (e.g., any global
+ register vars declared later will cause compilation errors). */
+
+#if !defined _SIGSET_H_fns && defined _SIGNAL_H
+# define _SIGSET_H_fns 1
+
+# ifndef _EXTERN_INLINE
+# define _EXTERN_INLINE extern __inline
+# endif
+
+/* Return a mask that includes the bit for SIG only. */
+# define __sigmask(sig) \
+ (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
+
+/* Return the word index for SIG. */
+# define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int)))
+
+# if defined __GNUC__ && __GNUC__ >= 2
+# define __sigemptyset(set) \
+ (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
+ sigset_t *__set = (set); \
+ while (--__cnt >= 0) __set->__val[__cnt] = 0; \
+ 0; }))
+# define __sigfillset(set) \
+ (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
+ sigset_t *__set = (set); \
+ while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
+ 0; }))
+
+# ifdef __USE_GNU
+/* The POSIX does not specify for handling the whole signal set in one
+ command. This is often wanted and so we define three more functions
+ here. */
+# define __sigisemptyset(set) \
+ (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
+ const sigset_t *__set = (set); \
+ int __ret = __set->__val[--__cnt]; \
+ while (!__ret && --__cnt >= 0) \
+ __ret = __set->__val[__cnt]; \
+ __ret == 0; }))
+# define __sigandset(dest, left, right) \
+ (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
+ sigset_t *__dest = (dest); \
+ const sigset_t *__left = (left); \
+ const sigset_t *__right = (right); \
+ while (--__cnt >= 0) \
+ __dest->__val[__cnt] = (__left->__val[__cnt] \
+ & __right->__val[__cnt]); \
+ 0; }))
+# define __sigorset(dest, left, right) \
+ (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
+ sigset_t *__dest = (dest); \
+ const sigset_t *__left = (left); \
+ const sigset_t *__right = (right); \
+ while (--__cnt >= 0) \
+ __dest->__val[__cnt] = (__left->__val[__cnt] \
+ | __right->__val[__cnt]); \
+ 0; }))
+# endif
+# endif
+
+/* These functions needn't check for a bogus signal number -- error
+ checking is done in the non __ versions. */
+
+extern int __sigismember (__const __sigset_t *, int);
+extern int __sigaddset (__sigset_t *, int);
+extern int __sigdelset (__sigset_t *, int);
+
+# ifdef __USE_EXTERN_INLINES
+# define __SIGSETFN(NAME, BODY, CONST) \
+ _EXTERN_INLINE int \
+ NAME (CONST __sigset_t *__set, int __sig) \
+ { \
+ unsigned long int __mask = __sigmask (__sig); \
+ unsigned long int __word = __sigword (__sig); \
+ return BODY; \
+ }
+
+__SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
+__SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
+__SIGSETFN (__sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
+
+# undef __SIGSETFN
+# endif
+
+
+#endif /* ! _SIGSET_H_fns. */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/sigstack.h b/libc/sysdeps/unix/sysv/linux/bits/sigstack.h
new file mode 100644
index 000000000..7f260367b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/sigstack.h
@@ -0,0 +1,55 @@
+/* sigstack, sigaltstack definitions.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIGNAL_H
+# error "Never include this file directly. Use <signal.h> instead"
+#endif
+
+
+/* Structure describing a signal stack (obsolete). */
+struct sigstack
+ {
+ void *ss_sp; /* Signal stack pointer. */
+ int ss_onstack; /* Nonzero if executing on this stack. */
+ };
+
+
+/* Possible values for `ss_flags.'. */
+enum
+{
+ SS_ONSTACK = 1,
+#define SS_ONSTACK SS_ONSTACK
+ SS_DISABLE
+#define SS_DISABLE SS_DISABLE
+};
+
+/* Minimum stack size for a signal handler. */
+#define MINSIGSTKSZ 2048
+
+/* System default stack size. */
+#define SIGSTKSZ 8192
+
+
+/* Alternate, preferred interface. */
+typedef struct sigaltstack
+ {
+ void *ss_sp;
+ int ss_flags;
+ size_t ss_size;
+ } stack_t;
diff --git a/libc/sysdeps/unix/sysv/linux/bits/socket.h b/libc/sysdeps/unix/sysv/linux/bits/socket.h
new file mode 100644
index 000000000..356a2ece7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/socket.h
@@ -0,0 +1,320 @@
+/* System-specific socket constants and types. Linux version.
+ Copyright (C) 1991,1992,1994-2001,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef __BITS_SOCKET_H
+#define __BITS_SOCKET_H
+
+#if !defined _SYS_SOCKET_H && !defined _NETINET_IN_H
+# error "Never include <bits/socket.h> directly; use <sys/socket.h> instead."
+#endif
+
+#define __need_size_t
+#define __need_NULL
+#include <stddef.h>
+
+#include <limits.h>
+#include <sys/types.h>
+
+/* Type for length arguments in socket calls. */
+#ifndef __socklen_t_defined
+typedef __socklen_t socklen_t;
+# define __socklen_t_defined
+#endif
+
+/* Types of sockets. */
+enum __socket_type
+{
+ SOCK_STREAM = 1, /* Sequenced, reliable, connection-based
+ byte streams. */
+#define SOCK_STREAM SOCK_STREAM
+ SOCK_DGRAM = 2, /* Connectionless, unreliable datagrams
+ of fixed maximum length. */
+#define SOCK_DGRAM SOCK_DGRAM
+ SOCK_RAW = 3, /* Raw protocol interface. */
+#define SOCK_RAW SOCK_RAW
+ SOCK_RDM = 4, /* Reliably-delivered messages. */
+#define SOCK_RDM SOCK_RDM
+ SOCK_SEQPACKET = 5, /* Sequenced, reliable, connection-based,
+ datagrams of fixed maximum length. */
+#define SOCK_SEQPACKET SOCK_SEQPACKET
+ SOCK_PACKET = 10 /* Linux specific way of getting packets
+ at the dev level. For writing rarp and
+ other similar things on the user level. */
+#define SOCK_PACKET SOCK_PACKET
+};
+
+/* Protocol families. */
+#define PF_UNSPEC 0 /* Unspecified. */
+#define PF_LOCAL 1 /* Local to host (pipes and file-domain). */
+#define PF_UNIX PF_LOCAL /* Old BSD name for PF_LOCAL. */
+#define PF_FILE PF_LOCAL /* Another non-standard name for PF_LOCAL. */
+#define PF_INET 2 /* IP protocol family. */
+#define PF_AX25 3 /* Amateur Radio AX.25. */
+#define PF_IPX 4 /* Novell Internet Protocol. */
+#define PF_APPLETALK 5 /* Appletalk DDP. */
+#define PF_NETROM 6 /* Amateur radio NetROM. */
+#define PF_BRIDGE 7 /* Multiprotocol bridge. */
+#define PF_ATMPVC 8 /* ATM PVCs. */
+#define PF_X25 9 /* Reserved for X.25 project. */
+#define PF_INET6 10 /* IP version 6. */
+#define PF_ROSE 11 /* Amateur Radio X.25 PLP. */
+#define PF_DECnet 12 /* Reserved for DECnet project. */
+#define PF_NETBEUI 13 /* Reserved for 802.2LLC project. */
+#define PF_SECURITY 14 /* Security callback pseudo AF. */
+#define PF_KEY 15 /* PF_KEY key management API. */
+#define PF_NETLINK 16
+#define PF_ROUTE PF_NETLINK /* Alias to emulate 4.4BSD. */
+#define PF_PACKET 17 /* Packet family. */
+#define PF_ASH 18 /* Ash. */
+#define PF_ECONET 19 /* Acorn Econet. */
+#define PF_ATMSVC 20 /* ATM SVCs. */
+#define PF_SNA 22 /* Linux SNA Project */
+#define PF_IRDA 23 /* IRDA sockets. */
+#define PF_PPPOX 24 /* PPPoX sockets. */
+#define PF_WANPIPE 25 /* Wanpipe API sockets. */
+#define PF_BLUETOOTH 31 /* Bluetooth sockets. */
+#define PF_MAX 32 /* For now.. */
+
+/* Address families. */
+#define AF_UNSPEC PF_UNSPEC
+#define AF_LOCAL PF_LOCAL
+#define AF_UNIX PF_UNIX
+#define AF_FILE PF_FILE
+#define AF_INET PF_INET
+#define AF_AX25 PF_AX25
+#define AF_IPX PF_IPX
+#define AF_APPLETALK PF_APPLETALK
+#define AF_NETROM PF_NETROM
+#define AF_BRIDGE PF_BRIDGE
+#define AF_ATMPVC PF_ATMPVC
+#define AF_X25 PF_X25
+#define AF_INET6 PF_INET6
+#define AF_ROSE PF_ROSE
+#define AF_DECnet PF_DECnet
+#define AF_NETBEUI PF_NETBEUI
+#define AF_SECURITY PF_SECURITY
+#define AF_KEY PF_KEY
+#define AF_NETLINK PF_NETLINK
+#define AF_ROUTE PF_ROUTE
+#define AF_PACKET PF_PACKET
+#define AF_ASH PF_ASH
+#define AF_ECONET PF_ECONET
+#define AF_ATMSVC PF_ATMSVC
+#define AF_SNA PF_SNA
+#define AF_IRDA PF_IRDA
+#define AF_PPPOX PF_PPPOX
+#define AF_WANPIPE PF_WANPIPE
+#define AF_BLUETOOTH PF_BLUETOOTH
+#define AF_MAX PF_MAX
+
+/* Socket level values. Others are defined in the appropriate headers.
+
+ XXX These definitions also should go into the appropriate headers as
+ far as they are available. */
+#define SOL_RAW 255
+#define SOL_DECNET 261
+#define SOL_X25 262
+#define SOL_PACKET 263
+#define SOL_ATM 264 /* ATM layer (cell level). */
+#define SOL_AAL 265 /* ATM Adaption Layer (packet level). */
+#define SOL_IRDA 266
+
+/* Maximum queue length specifiable by listen. */
+#define SOMAXCONN 128
+
+/* Get the definition of the macro to define the common sockaddr members. */
+#include <bits/sockaddr.h>
+
+/* Structure describing a generic socket address. */
+struct sockaddr
+ {
+ __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
+ char sa_data[14]; /* Address data. */
+ };
+
+
+/* Structure large enough to hold any socket address (with the historical
+ exception of AF_UNIX). We reserve 128 bytes. */
+#if ULONG_MAX > 0xffffffff
+# define __ss_aligntype __uint64_t
+#else
+# define __ss_aligntype __uint32_t
+#endif
+#define _SS_SIZE 128
+#define _SS_PADSIZE (_SS_SIZE - (2 * sizeof (__ss_aligntype)))
+
+struct sockaddr_storage
+ {
+ __SOCKADDR_COMMON (ss_); /* Address family, etc. */
+ __ss_aligntype __ss_align; /* Force desired alignment. */
+ char __ss_padding[_SS_PADSIZE];
+ };
+
+
+/* Bits in the FLAGS argument to `send', `recv', et al. */
+enum
+ {
+ MSG_OOB = 0x01, /* Process out-of-band data. */
+#define MSG_OOB MSG_OOB
+ MSG_PEEK = 0x02, /* Peek at incoming messages. */
+#define MSG_PEEK MSG_PEEK
+ MSG_DONTROUTE = 0x04, /* Don't use local routing. */
+#define MSG_DONTROUTE MSG_DONTROUTE
+#ifdef __USE_GNU
+ /* DECnet uses a different name. */
+ MSG_TRYHARD = MSG_DONTROUTE,
+# define MSG_TRYHARD MSG_DONTROUTE
+#endif
+ MSG_CTRUNC = 0x08, /* Control data lost before delivery. */
+#define MSG_CTRUNC MSG_CTRUNC
+ MSG_PROXY = 0x10, /* Supply or ask second address. */
+#define MSG_PROXY MSG_PROXY
+ MSG_TRUNC = 0x20,
+#define MSG_TRUNC MSG_TRUNC
+ MSG_DONTWAIT = 0x40, /* Nonblocking IO. */
+#define MSG_DONTWAIT MSG_DONTWAIT
+ MSG_EOR = 0x80, /* End of record. */
+#define MSG_EOR MSG_EOR
+ MSG_WAITALL = 0x100, /* Wait for a full request. */
+#define MSG_WAITALL MSG_WAITALL
+ MSG_FIN = 0x200,
+#define MSG_FIN MSG_FIN
+ MSG_SYN = 0x400,
+#define MSG_SYN MSG_SYN
+ MSG_CONFIRM = 0x800, /* Confirm path validity. */
+#define MSG_CONFIRM MSG_CONFIRM
+ MSG_RST = 0x1000,
+#define MSG_RST MSG_RST
+ MSG_ERRQUEUE = 0x2000, /* Fetch message from error queue. */
+#define MSG_ERRQUEUE MSG_ERRQUEUE
+ MSG_NOSIGNAL = 0x4000, /* Do not generate SIGPIPE. */
+#define MSG_NOSIGNAL MSG_NOSIGNAL
+ MSG_MORE = 0x8000 /* Sender will send more. */
+#define MSG_MORE MSG_MORE
+ };
+
+
+/* Structure describing messages sent by
+ `sendmsg' and received by `recvmsg'. */
+struct msghdr
+ {
+ void *msg_name; /* Address to send to/receive from. */
+ socklen_t msg_namelen; /* Length of address data. */
+
+ struct iovec *msg_iov; /* Vector of data to send/receive into. */
+ size_t msg_iovlen; /* Number of elements in the vector. */
+
+ void *msg_control; /* Ancillary data (eg BSD filedesc passing). */
+ size_t msg_controllen; /* Ancillary data buffer length.
+ !! The type should be socklen_t but the
+ definition of the kernel is incompatible
+ with this. */
+
+ int msg_flags; /* Flags on received message. */
+ };
+
+/* Structure used for storage of ancillary data object information. */
+struct cmsghdr
+ {
+ size_t cmsg_len; /* Length of data in cmsg_data plus length
+ of cmsghdr structure.
+ !! The type should be socklen_t but the
+ definition of the kernel is incompatible
+ with this. */
+ int cmsg_level; /* Originating protocol. */
+ int cmsg_type; /* Protocol specific type. */
+#if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L
+ __extension__ unsigned char __cmsg_data __flexarr; /* Ancillary data. */
+#endif
+ };
+
+/* Ancillary data object manipulation macros. */
+#if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L
+# define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data)
+#else
+# define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1))
+#endif
+#define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg)
+#define CMSG_FIRSTHDR(mhdr) \
+ ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
+ ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
+#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) \
+ & (size_t) ~(sizeof (size_t) - 1))
+#define CMSG_SPACE(len) (CMSG_ALIGN (len) \
+ + CMSG_ALIGN (sizeof (struct cmsghdr)))
+#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
+
+extern struct cmsghdr *__cmsg_nxthdr (struct msghdr *__mhdr,
+ struct cmsghdr *__cmsg) __THROW;
+#ifdef __USE_EXTERN_INLINES
+# ifndef _EXTERN_INLINE
+# define _EXTERN_INLINE extern __inline
+# endif
+_EXTERN_INLINE struct cmsghdr *
+__NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg))
+{
+ if ((size_t) __cmsg->cmsg_len < sizeof (struct cmsghdr))
+ /* The kernel header does this so there may be a reason. */
+ return 0;
+
+ __cmsg = (struct cmsghdr *) ((unsigned char *) __cmsg
+ + CMSG_ALIGN (__cmsg->cmsg_len));
+ if ((unsigned char *) (__cmsg + 1) > ((unsigned char *) __mhdr->msg_control
+ + __mhdr->msg_controllen)
+ || ((unsigned char *) __cmsg + CMSG_ALIGN (__cmsg->cmsg_len)
+ > ((unsigned char *) __mhdr->msg_control + __mhdr->msg_controllen)))
+ /* No more entries. */
+ return 0;
+ return __cmsg;
+}
+#endif /* Use `extern inline'. */
+
+/* Socket level message types. This must match the definitions in
+ <linux/socket.h>. */
+enum
+ {
+ SCM_RIGHTS = 0x01 /* Transfer file descriptors. */
+#define SCM_RIGHTS SCM_RIGHTS
+#ifdef __USE_BSD
+ , SCM_CREDENTIALS = 0x02 /* Credentials passing. */
+# define SCM_CREDENTIALS SCM_CREDENTIALS
+#endif
+ };
+
+/* User visible structure for SCM_CREDENTIALS message */
+
+struct ucred
+{
+ pid_t pid; /* PID of sending process. */
+ uid_t uid; /* UID of sending process. */
+ gid_t gid; /* GID of sending process. */
+};
+
+/* Get socket manipulation related informations from kernel headers. */
+#include <asm/socket.h>
+
+
+/* Structure used to manipulate the SO_LINGER option. */
+struct linger
+ {
+ int l_onoff; /* Nonzero to linger on close. */
+ int l_linger; /* Time to linger. */
+ };
+
+#endif /* bits/socket.h */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/stat.h b/libc/sysdeps/unix/sysv/linux/bits/stat.h
new file mode 100644
index 000000000..e08899c9a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/stat.h
@@ -0,0 +1,163 @@
+/* Copyright (C) 1992, 1995-2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STAT_H
+# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
+#endif
+
+/* Versions of the `struct stat' data structure. */
+#define _STAT_VER_LINUX_OLD 1
+#define _STAT_VER_KERNEL 1
+#define _STAT_VER_SVR4 2
+#define _STAT_VER_LINUX 3
+#define _STAT_VER _STAT_VER_LINUX /* The one defined below. */
+
+/* Versions of the `xmknod' interface. */
+#define _MKNOD_VER_LINUX 1
+#define _MKNOD_VER_SVR4 2
+#define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
+
+
+struct stat
+ {
+ __dev_t st_dev; /* Device. */
+ unsigned short int __pad1;
+#ifndef __USE_FILE_OFFSET64
+ __ino_t st_ino; /* File serial number. */
+#else
+ __ino_t __st_ino; /* 32bit file serial number. */
+#endif
+ __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. */
+ unsigned short int __pad2;
+#ifndef __USE_FILE_OFFSET64
+ __off_t st_size; /* Size of file, in bytes. */
+#else
+ __off64_t st_size; /* Size of file, in bytes. */
+#endif
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+#ifndef __USE_FILE_OFFSET64
+ __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
+#else
+ __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
+#endif
+#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
+#ifndef __USE_FILE_OFFSET64
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+#else
+ __ino64_t st_ino; /* File serial number. */
+#endif
+ };
+
+#ifdef __USE_LARGEFILE64
+struct stat64
+ {
+ __dev_t st_dev; /* Device. */
+ unsigned int __pad1;
+
+ __ino_t __st_ino; /* 32bit 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. */
+ unsigned int __pad2;
+ __off64_t st_size; /* Size of file, in bytes. */
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+ __blkcnt64_t st_blocks; /* Number 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
+ __ino64_t st_ino; /* File serial number. */
+ };
+#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. */
diff --git a/libc/sysdeps/unix/sysv/linux/bits/statfs.h b/libc/sysdeps/unix/sysv/linux/bits/statfs.h
new file mode 100644
index 000000000..0e27865e8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/statfs.h
@@ -0,0 +1,67 @@
+/* Copyright (C) 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STATFS_H
+# error "Never include <bits/statfs.h> directly; use <sys/statfs.h> instead."
+#endif
+
+#include <bits/types.h>
+
+struct statfs
+ {
+ __SWORD_TYPE f_type;
+ __SWORD_TYPE f_bsize;
+#ifndef __USE_FILE_OFFSET64
+ __fsblkcnt_t f_blocks;
+ __fsblkcnt_t f_bfree;
+ __fsblkcnt_t f_bavail;
+ __fsfilcnt_t f_files;
+ __fsfilcnt_t f_ffree;
+#else
+ __fsblkcnt64_t f_blocks;
+ __fsblkcnt64_t f_bfree;
+ __fsblkcnt64_t f_bavail;
+ __fsfilcnt64_t f_files;
+ __fsfilcnt64_t f_ffree;
+#endif
+ __fsid_t f_fsid;
+ __SWORD_TYPE f_namelen;
+ __SWORD_TYPE f_frsize;
+ __SWORD_TYPE f_spare[5];
+ };
+
+#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_spare[5];
+ };
+#endif
+
+/* Tell code we have these members. */
+#define _STATFS_F_NAMELEN
+#define _STATFS_F_FRSIZE
diff --git a/libc/sysdeps/unix/sysv/linux/bits/statvfs.h b/libc/sysdeps/unix/sysv/linux/bits/statvfs.h
new file mode 100644
index 000000000..cca0871ac
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/statvfs.h
@@ -0,0 +1,107 @@
+/* Copyright (C) 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STATVFS_H
+# error "Never include <bits/statvfs.h> directly; use <sys/statvfs.h> instead."
+#endif
+
+#include <bits/types.h> /* For __fsblkcnt_t and __fsfilcnt_t. */
+
+#if __WORDSIZE == 32
+#define _STATVFSBUF_F_UNUSED
+#endif
+
+struct statvfs
+ {
+ unsigned long int f_bsize;
+ unsigned long int f_frsize;
+#ifndef __USE_FILE_OFFSET64
+ __fsblkcnt_t f_blocks;
+ __fsblkcnt_t f_bfree;
+ __fsblkcnt_t f_bavail;
+ __fsfilcnt_t f_files;
+ __fsfilcnt_t f_ffree;
+ __fsfilcnt_t f_favail;
+#else
+ __fsblkcnt64_t f_blocks;
+ __fsblkcnt64_t f_bfree;
+ __fsblkcnt64_t f_bavail;
+ __fsfilcnt64_t f_files;
+ __fsfilcnt64_t f_ffree;
+ __fsfilcnt64_t f_favail;
+#endif
+ unsigned long int f_fsid;
+#ifdef _STATVFSBUF_F_UNUSED
+ int __f_unused;
+#endif
+ unsigned long int f_flag;
+ unsigned long int f_namemax;
+ int __f_spare[6];
+ };
+
+#ifdef __USE_LARGEFILE64
+struct statvfs64
+ {
+ unsigned long int f_bsize;
+ unsigned long int f_frsize;
+ __fsblkcnt64_t f_blocks;
+ __fsblkcnt64_t f_bfree;
+ __fsblkcnt64_t f_bavail;
+ __fsfilcnt64_t f_files;
+ __fsfilcnt64_t f_ffree;
+ __fsfilcnt64_t f_favail;
+ unsigned long int f_fsid;
+#ifdef _STATVFSBUF_F_UNUSED
+ int __f_unused;
+#endif
+ unsigned long int f_flag;
+ unsigned long int f_namemax;
+ int __f_spare[6];
+ };
+#endif
+
+/* Definitions for the flag in `f_flag'. These definitions should be
+ kept in sync with the definitions in <sys/mount.h>. */
+enum
+{
+ ST_RDONLY = 1, /* Mount read-only. */
+#define ST_RDONLY ST_RDONLY
+ ST_NOSUID = 2 /* Ignore suid and sgid bits. */
+#define ST_NOSUID ST_NOSUID
+#ifdef __USE_GNU
+ ,
+ ST_NODEV = 4, /* Disallow access to device special files. */
+# define ST_NODEV ST_NODEV
+ ST_NOEXEC = 8, /* Disallow program execution. */
+# define ST_NOEXEC ST_NOEXEC
+ ST_SYNCHRONOUS = 16, /* Writes are synced at once. */
+# define ST_SYNCHRONOUS ST_SYNCHRONOUS
+ ST_MANDLOCK = 64, /* Allow mandatory locks on an FS. */
+# define ST_MANDLOCK ST_MANDLOCK
+ ST_WRITE = 128, /* Write on file/directory/symlink. */
+# define ST_WRITE ST_WRITE
+ ST_APPEND = 256, /* Append-only file. */
+# define ST_APPEND ST_APPEND
+ ST_IMMUTABLE = 512, /* Immutable file. */
+# define ST_IMMUTABLE ST_IMMUTABLE
+ ST_NOATIME = 1024, /* Do not update access times. */
+# define ST_NOATIME ST_NOATIME
+ ST_NODIRATIME = 2048 /* Do not update directory access times. */
+# define ST_NODIRATIME ST_NODIRATIME
+#endif /* Use GNU. */
+};
diff --git a/libc/sysdeps/unix/sysv/linux/bits/sys_errlist.h b/libc/sysdeps/unix/sysv/linux/bits/sys_errlist.h
new file mode 100644
index 000000000..ee556e8ec
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/sys_errlist.h
@@ -0,0 +1,33 @@
+/* Declare sys_errlist and sys_nerr, or don't. Compatibility (do) version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _STDIO_H
+# error "Never include <bits/sys_errlist.h> directly; use <stdio.h> instead."
+#endif
+
+/* sys_errlist and sys_nerr are deprecated. Use strerror instead. */
+
+#ifdef __USE_BSD
+extern int sys_nerr;
+extern __const char *__const sys_errlist[];
+#endif
+#ifdef __USE_GNU
+extern int _sys_nerr;
+extern __const char *__const _sys_errlist[];
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/bits/termios.h b/libc/sysdeps/unix/sysv/linux/bits/termios.h
new file mode 100644
index 000000000..c71e4ad1f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/termios.h
@@ -0,0 +1,218 @@
+/* termios type and macro definitions. Linux version.
+ Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2003, 2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _TERMIOS_H
+# error "Never include <bits/termios.h> directly; use <termios.h> instead."
+#endif
+
+typedef unsigned char cc_t;
+typedef unsigned int speed_t;
+typedef unsigned int tcflag_t;
+
+#define NCCS 32
+struct termios
+ {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_line; /* line discipline */
+ cc_t c_cc[NCCS]; /* control characters */
+ speed_t c_ispeed; /* input speed */
+ speed_t c_ospeed; /* output speed */
+#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
+#define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
+ };
+
+/* c_cc characters */
+#define VINTR 0
+#define VQUIT 1
+#define VERASE 2
+#define VKILL 3
+#define VEOF 4
+#define VTIME 5
+#define VMIN 6
+#define VSWTC 7
+#define VSTART 8
+#define VSTOP 9
+#define VSUSP 10
+#define VEOL 11
+#define VREPRINT 12
+#define VDISCARD 13
+#define VWERASE 14
+#define VLNEXT 15
+#define VEOL2 16
+
+/* c_iflag bits */
+#define IGNBRK 0000001
+#define BRKINT 0000002
+#define IGNPAR 0000004
+#define PARMRK 0000010
+#define INPCK 0000020
+#define ISTRIP 0000040
+#define INLCR 0000100
+#define IGNCR 0000200
+#define ICRNL 0000400
+#define IUCLC 0001000
+#define IXON 0002000
+#define IXANY 0004000
+#define IXOFF 0010000
+#define IMAXBEL 0020000
+#define IUTF8 0040000
+
+/* c_oflag bits */
+#define OPOST 0000001
+#define OLCUC 0000002
+#define ONLCR 0000004
+#define OCRNL 0000010
+#define ONOCR 0000020
+#define ONLRET 0000040
+#define OFILL 0000100
+#define OFDEL 0000200
+#if defined __USE_MISC || defined __USE_XOPEN
+# define NLDLY 0000400
+# define NL0 0000000
+# define NL1 0000400
+# define CRDLY 0003000
+# define CR0 0000000
+# define CR1 0001000
+# define CR2 0002000
+# define CR3 0003000
+# define TABDLY 0014000
+# define TAB0 0000000
+# define TAB1 0004000
+# define TAB2 0010000
+# define TAB3 0014000
+# define BSDLY 0020000
+# define BS0 0000000
+# define BS1 0020000
+# define FFDLY 0100000
+# define FF0 0000000
+# define FF1 0100000
+#endif
+
+#define VTDLY 0040000
+#define VT0 0000000
+#define VT1 0040000
+
+#ifdef __USE_MISC
+# define XTABS 0014000
+#endif
+
+/* c_cflag bit meaning */
+#ifdef __USE_MISC
+# define CBAUD 0010017
+#endif
+#define B0 0000000 /* hang up */
+#define B50 0000001
+#define B75 0000002
+#define B110 0000003
+#define B134 0000004
+#define B150 0000005
+#define B200 0000006
+#define B300 0000007
+#define B600 0000010
+#define B1200 0000011
+#define B1800 0000012
+#define B2400 0000013
+#define B4800 0000014
+#define B9600 0000015
+#define B19200 0000016
+#define B38400 0000017
+#ifdef __USE_MISC
+# define EXTA B19200
+# define EXTB B38400
+#endif
+#define CSIZE 0000060
+#define CS5 0000000
+#define CS6 0000020
+#define CS7 0000040
+#define CS8 0000060
+#define CSTOPB 0000100
+#define CREAD 0000200
+#define PARENB 0000400
+#define PARODD 0001000
+#define HUPCL 0002000
+#define CLOCAL 0004000
+#ifdef __USE_MISC
+# define CBAUDEX 0010000
+#endif
+#define B57600 0010001
+#define B115200 0010002
+#define B230400 0010003
+#define B460800 0010004
+#define B500000 0010005
+#define B576000 0010006
+#define B921600 0010007
+#define B1000000 0010010
+#define B1152000 0010011
+#define B1500000 0010012
+#define B2000000 0010013
+#define B2500000 0010014
+#define B3000000 0010015
+#define B3500000 0010016
+#define B4000000 0010017
+#define __MAX_BAUD B4000000
+#ifdef __USE_MISC
+# define CIBAUD 002003600000 /* input baud rate (not used) */
+# define CMSPAR 010000000000 /* mark or space (stick) parity */
+# define CRTSCTS 020000000000 /* flow control */
+#endif
+
+/* c_lflag bits */
+#define ISIG 0000001
+#define ICANON 0000002
+#if defined __USE_MISC || defined __USE_XOPEN
+# define XCASE 0000004
+#endif
+#define ECHO 0000010
+#define ECHOE 0000020
+#define ECHOK 0000040
+#define ECHONL 0000100
+#define NOFLSH 0000200
+#define TOSTOP 0000400
+#ifdef __USE_MISC
+# define ECHOCTL 0001000
+# define ECHOPRT 0002000
+# define ECHOKE 0004000
+# define FLUSHO 0010000
+# define PENDIN 0040000
+#endif
+#define IEXTEN 0100000
+
+/* tcflow() and TCXONC use these */
+#define TCOOFF 0
+#define TCOON 1
+#define TCIOFF 2
+#define TCION 3
+
+/* tcflush() and TCFLSH use these */
+#define TCIFLUSH 0
+#define TCOFLUSH 1
+#define TCIOFLUSH 2
+
+/* tcsetattr uses these */
+#define TCSANOW 0
+#define TCSADRAIN 1
+#define TCSAFLUSH 2
+
+
+#define _IOT_termios /* Hurd ioctl type field. */ \
+ _IOT (_IOTS (cflag_t), 4, _IOTS (cc_t), NCCS, _IOTS (speed_t), 2)
diff --git a/libc/sysdeps/unix/sysv/linux/bits/uio.h b/libc/sysdeps/unix/sysv/linux/bits/uio.h
new file mode 100644
index 000000000..6a283ed77
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/uio.h
@@ -0,0 +1,50 @@
+/* Copyright (C) 1996, 1997, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#if !defined _SYS_UIO_H && !defined _FCNTL_H
+# error "Never include <bits/uio.h> directly; use <sys/uio.h> instead."
+#endif
+
+#ifndef _BITS_UIO_H
+#define _BITS_UIO_H 1
+
+#include <sys/types.h>
+
+
+/* We should normally use the Linux kernel header file to define this
+ type and macros but this calls for trouble because of the header
+ includes other kernel headers. */
+
+/* Size of object which can be written atomically.
+
+ This macro has different values in different kernel versions. The
+ latest versions of the kernel use 1024 and this is good choice. Since
+ the C library implementation of readv/writev is able to emulate the
+ functionality even if the currently running kernel does not support
+ this large value the readv/writev call will not fail because of this. */
+#define UIO_MAXIOV 1024
+
+
+/* Structure for scatter/gather I/O. */
+struct iovec
+ {
+ void *iov_base; /* Pointer to data. */
+ size_t iov_len; /* Length of data. */
+ };
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/bits/utsname.h b/libc/sysdeps/unix/sysv/linux/bits/utsname.h
new file mode 100644
index 000000000..35e71e3ba
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/utsname.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_UTSNAME_H
+# error "Never include <bits/utsname.h> directly; use <sys/utsname.h> instead."
+#endif
+
+/* Length of the entries in `struct utsname' is 65. */
+#define _UTSNAME_LENGTH 65
+
+/* Linux provides as additional information in the `struct utsname'
+ the name of the current domain. Define _UTSNAME_DOMAIN_LENGTH
+ to a value != 0 to activate this entry. */
+#define _UTSNAME_DOMAIN_LENGTH _UTSNAME_LENGTH
diff --git a/libc/sysdeps/unix/sysv/linux/bits/waitflags.h b/libc/sysdeps/unix/sysv/linux/bits/waitflags.h
new file mode 100644
index 000000000..464cedb1f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/bits/waitflags.h
@@ -0,0 +1,38 @@
+/* Definitions of flag bits for `waitpid' et al.
+ Copyright (C) 1992,1996,1997,2000,2004,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#if !defined _SYS_WAIT_H && !defined _STDLIB_H
+# error "Never include <bits/waitflags.h> directly; use <sys/wait.h> instead."
+#endif
+
+
+/* Bits in the third argument to `waitpid'. */
+#define WNOHANG 1 /* Don't block waiting. */
+#define WUNTRACED 2 /* Report status of stopped children. */
+
+/* Bits in the fourth argument to `waitid'. */
+#define WSTOPPED 2 /* Report stopped child (same as WUNTRACED). */
+#define WEXITED 4 /* Report dead child. */
+#define WCONTINUED 8 /* Report continued child. */
+#define WNOWAIT 0x01000000 /* Don't reap, just poll status. */
+
+#define __WNOTHREAD 0x20000000 /* Don't wait on children of other threads
+ in this group */
+#define __WALL 0x40000000 /* Wait for any child. */
+#define __WCLONE 0x80000000 /* Wait for cloned process. */
diff --git a/libc/sysdeps/unix/sysv/linux/check_pf.c b/libc/sysdeps/unix/sysv/linux/check_pf.c
new file mode 100644
index 000000000..7fbb7543d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/check_pf.c
@@ -0,0 +1,268 @@
+/* Determine protocol families for which interfaces exist. Linux version.
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <ifaddrs.h>
+#include <netdb.h>
+#include <stddef.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/socket.h>
+
+#include <asm/types.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
+#include <not-cancel.h>
+#include <kernel-features.h>
+
+
+#ifndef IFA_F_TEMPORARY
+# define IFA_F_TEMPORARY IFA_F_SECONDARY
+#endif
+
+
+static int
+make_request (int fd, pid_t pid, bool *seen_ipv4, bool *seen_ipv6,
+ struct in6addrinfo **in6ai, size_t *in6ailen)
+{
+ struct req
+ {
+ struct nlmsghdr nlh;
+ struct rtgenmsg g;
+ /* struct rtgenmsg consists of a single byte. This means there
+ are three bytes of padding included in the REQ definition.
+ We make them explicit here. */
+ char pad[3];
+ } req;
+ struct sockaddr_nl nladdr;
+
+ req.nlh.nlmsg_len = sizeof (req);
+ req.nlh.nlmsg_type = RTM_GETADDR;
+ req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
+ req.nlh.nlmsg_pid = 0;
+ req.nlh.nlmsg_seq = time (NULL);
+ req.g.rtgen_family = AF_UNSPEC;
+
+ assert (sizeof (req) - offsetof (struct req, pad) == 3);
+ memset (req.pad, '\0', sizeof (req.pad));
+
+ memset (&nladdr, '\0', sizeof (nladdr));
+ nladdr.nl_family = AF_NETLINK;
+
+ if (TEMP_FAILURE_RETRY (__sendto (fd, (void *) &req, sizeof (req), 0,
+ (struct sockaddr *) &nladdr,
+ sizeof (nladdr))) < 0)
+ return -1;
+
+ *seen_ipv4 = false;
+ *seen_ipv6 = false;
+
+ bool done = false;
+ char buf[4096];
+ struct iovec iov = { buf, sizeof (buf) };
+ struct in6ailist
+ {
+ struct in6addrinfo info;
+ struct in6ailist *next;
+ } *in6ailist = NULL;
+ size_t in6ailistlen = 0;
+
+ do
+ {
+ struct msghdr msg =
+ {
+ (void *) &nladdr, sizeof (nladdr),
+ &iov, 1,
+ NULL, 0,
+ 0
+ };
+
+ ssize_t read_len = TEMP_FAILURE_RETRY (__recvmsg (fd, &msg, 0));
+ if (read_len < 0)
+ return -1;
+
+ if (msg.msg_flags & MSG_TRUNC)
+ return -1;
+
+ struct nlmsghdr *nlmh;
+ for (nlmh = (struct nlmsghdr *) buf;
+ NLMSG_OK (nlmh, (size_t) read_len);
+ nlmh = (struct nlmsghdr *) NLMSG_NEXT (nlmh, read_len))
+ {
+ if (nladdr.nl_pid != 0 || (pid_t) nlmh->nlmsg_pid != pid
+ || nlmh->nlmsg_seq != req.nlh.nlmsg_seq)
+ continue;
+
+ if (nlmh->nlmsg_type == RTM_NEWADDR)
+ {
+ struct ifaddrmsg *ifam = (struct ifaddrmsg *) NLMSG_DATA (nlmh);
+
+ switch (ifam->ifa_family)
+ {
+ case AF_INET:
+ *seen_ipv4 = true;
+ break;
+ case AF_INET6:
+ *seen_ipv6 = true;
+
+ if (ifam->ifa_flags & (IFA_F_DEPRECATED | IFA_F_TEMPORARY))
+ {
+ struct rtattr *rta = IFA_RTA (ifam);
+ size_t len = (nlmh->nlmsg_len
+ - NLMSG_LENGTH (sizeof (*ifam)));
+ void *local = NULL;
+ void *address = NULL;
+ while (RTA_OK (rta, len))
+ {
+ switch (rta->rta_type)
+ {
+ case IFA_LOCAL:
+ local = RTA_DATA (rta);
+ break;
+
+ case IFA_ADDRESS:
+ address = RTA_DATA (rta);
+ break;
+ }
+
+ rta = RTA_NEXT (rta, len);
+ }
+
+ struct in6ailist *newp = alloca (sizeof (*newp));
+ newp->info.flags = (((ifam->ifa_flags & IFA_F_DEPRECATED)
+ ? in6ai_deprecated : 0)
+ | ((ifam->ifa_flags
+ & IFA_F_TEMPORARY)
+ ? in6ai_temporary : 0));
+ memcpy (newp->info.addr, address ?: local,
+ sizeof (newp->info.addr));
+ newp->next = in6ailist;
+ in6ailist = newp;
+ ++in6ailistlen;
+ }
+ break;
+ default:
+ /* Ignore. */
+ break;
+ }
+ }
+ else if (nlmh->nlmsg_type == NLMSG_DONE)
+ /* We found the end, leave the loop. */
+ done = true;
+ }
+ }
+ while (! done);
+
+ close_not_cancel_no_status (fd);
+
+ if (in6ailist != NULL)
+ {
+ *in6ai = malloc (in6ailistlen * sizeof (**in6ai));
+ if (*in6ai == NULL)
+ return -1;
+
+ *in6ailen = in6ailistlen;
+
+ do
+ {
+ (*in6ai)[--in6ailistlen] = in6ailist->info;
+ in6ailist = in6ailist->next;
+ }
+ while (in6ailist != NULL);
+ }
+
+ return 0;
+}
+
+
+/* We don't know if we have NETLINK support compiled in in our
+ Kernel. */
+#if __ASSUME_NETLINK_SUPPORT == 0
+/* Define in ifaddrs.h. */
+extern int __no_netlink_support attribute_hidden;
+#else
+# define __no_netlink_support 0
+#endif
+
+
+void
+attribute_hidden
+__check_pf (bool *seen_ipv4, bool *seen_ipv6,
+ struct in6addrinfo **in6ai, size_t *in6ailen)
+{
+ *in6ai = NULL;
+ *in6ailen = 0;
+
+ if (! __no_netlink_support)
+ {
+ int fd = __socket (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+
+ struct sockaddr_nl nladdr;
+ memset (&nladdr, '\0', sizeof (nladdr));
+ nladdr.nl_family = AF_NETLINK;
+
+ socklen_t addr_len = sizeof (nladdr);
+
+ if (fd >= 0
+ && __bind (fd, (struct sockaddr *) &nladdr, sizeof (nladdr)) == 0
+ && __getsockname (fd, (struct sockaddr *) &nladdr, &addr_len) == 0
+ && make_request (fd, nladdr.nl_pid, seen_ipv4, seen_ipv6,
+ in6ai, in6ailen) == 0)
+ /* It worked. */
+ return;
+
+ if (fd >= 0)
+ __close (fd);
+
+#if __ASSUME_NETLINK_SUPPORT == 0
+ /* Remember that there is no netlink support. */
+ __no_netlink_support = 1;
+#else
+ /* We cannot determine what interfaces are available. Be
+ pessimistic. */
+ *seen_ipv4 = true;
+ *seen_ipv6 = true;
+#endif
+ }
+
+#if __ASSUME_NETLINK_SUPPORT == 0
+ /* No netlink. Get the interface list via getifaddrs. */
+ struct ifaddrs *ifa = NULL;
+ if (getifaddrs (&ifa) != 0)
+ {
+ /* We cannot determine what interfaces are available. Be
+ pessimistic. */
+ *seen_ipv4 = true;
+ *seen_ipv6 = true;
+ return;
+ }
+
+ struct ifaddrs *runp;
+ for (runp = ifa; runp != NULL; runp = runp->ifa_next)
+ if (runp->ifa_addr->sa_family == PF_INET)
+ *seen_ipv4 = true;
+ else if (runp->ifa_addr->sa_family == PF_INET6)
+ *seen_ipv6 = true;
+
+ (void) freeifaddrs (ifa);
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/clock.c b/libc/sysdeps/unix/sysv/linux/clock.c
new file mode 100644
index 000000000..e9d408d91
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/clock.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 1991, 1992, 1996, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/times.h>
+#include <time.h>
+#include <unistd.h>
+
+/* Return the time used by the program so far (user time + system time). */
+clock_t
+clock (void)
+{
+ struct tms buf;
+ long clk_tck = __sysconf (_SC_CLK_TCK);
+
+ /* We don't check for errors here. The only error the kernel
+ returns is EFAULT if the value cannot be written to the struct we
+ pass a pointer to. Otherwise the kernel returns an `unsigned
+ long' value which is the number of jiffies since system start.
+ But this number can be negative (when read as `long') when the
+ system is up for some time. Ignoring errors should therefore
+ have no negative impacts but solve the problem. */
+ __times (&buf);
+
+ return
+ (clk_tck <= CLOCKS_PER_SEC)
+ ? ((unsigned long) buf.tms_utime + buf.tms_stime) * (CLOCKS_PER_SEC
+ / clk_tck)
+ : ((unsigned long) buf.tms_utime + buf.tms_stime) / (clk_tck
+ / CLOCKS_PER_SEC);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/clock_getcpuclockid.c b/libc/sysdeps/unix/sysv/linux/clock_getcpuclockid.c
new file mode 100644
index 000000000..04bf49e45
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/clock_getcpuclockid.c
@@ -0,0 +1,103 @@
+/* clock_getcpuclockid -- Get a clockid_t for process CPU time. Linux version.
+ Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+#include <kernel-features.h>
+#include "kernel-posix-cpu-timers.h"
+
+#ifndef HAS_CPUCLOCK
+# define HAS_CPUCLOCK 1
+#endif
+
+int
+clock_getcpuclockid (pid_t pid, clockid_t *clock_id)
+{
+#ifdef __NR_clock_getres
+ /* The clockid_t value is a simple computation from the PID.
+ But we do a clock_getres call to validate it. */
+
+ const clockid_t pidclock = MAKE_PROCESS_CPUCLOCK (pid, CPUCLOCK_SCHED);
+
+# if !(__ASSUME_POSIX_CPU_TIMERS > 0)
+ extern int __libc_missing_posix_cpu_timers attribute_hidden;
+# if !(__ASSUME_POSIX_TIMERS > 0)
+ extern int __libc_missing_posix_timers attribute_hidden;
+ if (__libc_missing_posix_timers && !__libc_missing_posix_cpu_timers)
+ __libc_missing_posix_cpu_timers = 1;
+# endif
+ if (!__libc_missing_posix_cpu_timers)
+# endif
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ int r = INTERNAL_SYSCALL (clock_getres, err, 2, pidclock, NULL);
+ if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+ {
+ *clock_id = pidclock;
+ return 0;
+ }
+
+# if !(__ASSUME_POSIX_TIMERS > 0)
+ if (INTERNAL_SYSCALL_ERRNO (r, err) == ENOSYS)
+ {
+ /* The kernel doesn't support these calls at all. */
+ __libc_missing_posix_timers = 1;
+ __libc_missing_posix_cpu_timers = 1;
+ }
+ else
+# endif
+ if (INTERNAL_SYSCALL_ERRNO (r, err) == EINVAL)
+ {
+# if !(__ASSUME_POSIX_CPU_TIMERS > 0)
+ if (pidclock == MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED)
+ || INTERNAL_SYSCALL_ERROR_P (INTERNAL_SYSCALL
+ (clock_getres, err, 2,
+ MAKE_PROCESS_CPUCLOCK
+ (0, CPUCLOCK_SCHED), NULL),
+ err))
+ /* The kernel doesn't support these clocks at all. */
+ __libc_missing_posix_cpu_timers = 1;
+ else
+# endif
+ /* The clock_getres system call checked the PID for us. */
+ return ESRCH;
+ }
+ else
+ return INTERNAL_SYSCALL_ERRNO (r, err);
+ }
+#endif
+
+ /* We don't allow any process ID but our own. */
+ if (pid != 0 && pid != getpid ())
+ return EPERM;
+
+#ifdef CLOCK_PROCESS_CPUTIME_ID
+ if (HAS_CPUCLOCK)
+ {
+ /* Store the number. */
+ *clock_id = CLOCK_PROCESS_CPUTIME_ID;
+
+ return 0;
+ }
+#endif
+
+ /* We don't have a timer for that. */
+ return ENOENT;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/clock_getres.c b/libc/sysdeps/unix/sysv/linux/clock_getres.c
new file mode 100644
index 000000000..813d3ebbf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/clock_getres.c
@@ -0,0 +1,193 @@
+/* clock_getres -- Get the resolution of a POSIX clockid_t. Linux version.
+ Copyright (C) 2003,2004,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <time.h>
+#include "kernel-posix-cpu-timers.h"
+#include <kernel-features.h>
+
+#ifndef HAVE_CLOCK_GETRES_VSYSCALL
+# undef INTERNAL_VSYSCALL
+# define INTERNAL_VSYSCALL INTERNAL_SYSCALL
+# undef INLINE_VSYSCALL
+# define INLINE_VSYSCALL INLINE_SYSCALL
+#else
+# include <bits/libc-vdso.h>
+#endif
+
+#define SYSCALL_GETRES \
+ retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, res); \
+ break
+
+#ifdef __ASSUME_POSIX_TIMERS
+
+/* This means the REALTIME and MONOTONIC clock are definitely
+ supported in the kernel. */
+# define SYSDEP_GETRES \
+ SYSDEP_GETRES_CPUTIME \
+ case CLOCK_REALTIME: \
+ case CLOCK_MONOTONIC: \
+ SYSCALL_GETRES
+
+# define __libc_missing_posix_timers 0
+#elif defined __NR_clock_getres
+/* Is the syscall known to exist? */
+extern int __libc_missing_posix_timers attribute_hidden;
+
+static inline int
+maybe_syscall_getres (clockid_t clock_id, struct timespec *res)
+{
+ int e = EINVAL;
+
+ if (!__libc_missing_posix_timers)
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ int r = INTERNAL_VSYSCALL (clock_getres, err, 2, clock_id, res);
+ if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+ return 0;
+
+ e = INTERNAL_SYSCALL_ERRNO (r, err);
+ if (e == ENOSYS)
+ {
+ __libc_missing_posix_timers = 1;
+ e = EINVAL;
+ }
+ }
+
+ return e;
+}
+
+/* The REALTIME and MONOTONIC clock might be available. Try the
+ syscall first. */
+# define SYSDEP_GETRES \
+ SYSDEP_GETRES_CPUTIME \
+ case CLOCK_REALTIME: \
+ case CLOCK_MONOTONIC: \
+ retval = maybe_syscall_getres (clock_id, res); \
+ if (retval == 0) \
+ break; \
+ /* Fallback code. */ \
+ if (retval == EINVAL && clock_id == CLOCK_REALTIME) \
+ retval = realtime_getres (res); \
+ else \
+ { \
+ __set_errno (retval); \
+ retval = -1; \
+ } \
+ break;
+#endif
+
+#ifdef __NR_clock_getres
+/* We handled the REALTIME clock here. */
+# define HANDLED_REALTIME 1
+# define HANDLED_CPUTIME 1
+
+# if __ASSUME_POSIX_CPU_TIMERS > 0
+
+# define SYSDEP_GETRES_CPU SYSCALL_GETRES
+# define SYSDEP_GETRES_CPUTIME /* Default catches them too. */
+
+# else
+
+extern int __libc_missing_posix_cpu_timers attribute_hidden;
+
+static int
+maybe_syscall_getres_cpu (clockid_t clock_id, struct timespec *res)
+{
+ int e = EINVAL;
+
+ if (!__libc_missing_posix_cpu_timers)
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ int r = INTERNAL_VSYSCALL (clock_getres, err, 2, clock_id, res);
+ if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+ return 0;
+
+ e = INTERNAL_SYSCALL_ERRNO (r, err);
+# ifndef __ASSUME_POSIX_TIMERS
+ if (e == ENOSYS)
+ {
+ __libc_missing_posix_timers = 1;
+ __libc_missing_posix_cpu_timers = 1;
+ e = EINVAL;
+ }
+ else
+# endif
+ {
+ if (e == EINVAL)
+ {
+ /* Check whether the kernel supports CPU clocks at all.
+ If not, record it for the future. */
+ r = INTERNAL_VSYSCALL (clock_getres, err, 2,
+ MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+ NULL);
+ if (INTERNAL_SYSCALL_ERROR_P (r, err))
+ __libc_missing_posix_cpu_timers = 1;
+ }
+ }
+ }
+
+ return e;
+}
+
+# define SYSDEP_GETRES_CPU \
+ retval = maybe_syscall_getres_cpu (clock_id, res); \
+ if (retval == 0) \
+ break; \
+ if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \
+ { \
+ __set_errno (retval); \
+ retval = -1; \
+ break; \
+ } \
+ retval = -1 /* Otherwise continue on to the HP_TIMING version. */;
+
+static inline int
+maybe_syscall_getres_cputime (clockid_t clock_id, struct timespec *res)
+{
+ return maybe_syscall_getres_cpu
+ (clock_id == CLOCK_THREAD_CPUTIME_ID
+ ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED)
+ : MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+ res);
+}
+
+# define SYSDEP_GETRES_CPUTIME \
+ case CLOCK_PROCESS_CPUTIME_ID: \
+ case CLOCK_THREAD_CPUTIME_ID: \
+ retval = maybe_syscall_getres_cputime (clock_id, res); \
+ if (retval == 0) \
+ break; \
+ if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \
+ { \
+ __set_errno (retval); \
+ retval = -1; \
+ break; \
+ } \
+ retval = hp_timing_getres (res); \
+ break;
+# if !HP_TIMING_AVAIL
+# define hp_timing_getres(res) (__set_errno (EINVAL), -1)
+# endif
+
+# endif
+#endif
+
+#include <sysdeps/posix/clock_getres.c>
diff --git a/libc/sysdeps/unix/sysv/linux/clock_gettime.c b/libc/sysdeps/unix/sysv/linux/clock_gettime.c
new file mode 100644
index 000000000..5afe20feb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -0,0 +1,193 @@
+/* clock_gettime -- Get current time from a POSIX clockid_t. Linux version.
+ Copyright (C) 2003,2004,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <time.h>
+#include "kernel-posix-cpu-timers.h"
+#include <kernel-features.h>
+
+#ifndef HAVE_CLOCK_GETTIME_VSYSCALL
+# undef INTERNAL_VSYSCALL
+# define INTERNAL_VSYSCALL INTERNAL_SYSCALL
+# undef INLINE_VSYSCALL
+# define INLINE_VSYSCALL INLINE_SYSCALL
+#else
+# include <bits/libc-vdso.h>
+#endif
+
+#define SYSCALL_GETTIME \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+ break
+
+#ifdef __ASSUME_POSIX_TIMERS
+
+/* This means the REALTIME and MONOTONIC clock are definitely
+ supported in the kernel. */
+# define SYSDEP_GETTIME \
+ SYSDEP_GETTIME_CPUTIME \
+ case CLOCK_REALTIME: \
+ case CLOCK_MONOTONIC: \
+ SYSCALL_GETTIME
+
+# define __libc_missing_posix_timers 0
+#elif defined __NR_clock_gettime
+/* Is the syscall known to exist? */
+int __libc_missing_posix_timers attribute_hidden;
+
+static inline int
+maybe_syscall_gettime (clockid_t clock_id, struct timespec *tp)
+{
+ int e = EINVAL;
+
+ if (!__libc_missing_posix_timers)
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ int r = INTERNAL_VSYSCALL (clock_gettime, err, 2, clock_id, tp);
+ if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+ return 0;
+
+ e = INTERNAL_SYSCALL_ERRNO (r, err);
+ if (e == ENOSYS)
+ {
+ __libc_missing_posix_timers = 1;
+ e = EINVAL;
+ }
+ }
+
+ return e;
+}
+
+/* The REALTIME and MONOTONIC clock might be available. Try the
+ syscall first. */
+# define SYSDEP_GETTIME \
+ SYSDEP_GETTIME_CPUTIME \
+ case CLOCK_REALTIME: \
+ case CLOCK_MONOTONIC: \
+ retval = maybe_syscall_gettime (clock_id, tp); \
+ if (retval == 0) \
+ break; \
+ /* Fallback code. */ \
+ if (retval == EINVAL && clock_id == CLOCK_REALTIME) \
+ retval = realtime_gettime (tp); \
+ else \
+ { \
+ __set_errno (retval); \
+ retval = -1; \
+ } \
+ break;
+#endif
+
+#ifdef __NR_clock_gettime
+/* We handled the REALTIME clock here. */
+# define HANDLED_REALTIME 1
+# define HANDLED_CPUTIME 1
+
+# if __ASSUME_POSIX_CPU_TIMERS > 0
+
+# define SYSDEP_GETTIME_CPU SYSCALL_GETTIME
+# define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */
+
+# else
+
+int __libc_missing_posix_cpu_timers attribute_hidden;
+
+static int
+maybe_syscall_gettime_cpu (clockid_t clock_id, struct timespec *tp)
+{
+ int e = EINVAL;
+
+ if (!__libc_missing_posix_cpu_timers)
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ int r = INTERNAL_VSYSCALL (clock_gettime, err, 2, clock_id, tp);
+ if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+ return 0;
+
+ e = INTERNAL_SYSCALL_ERRNO (r, err);
+# ifndef __ASSUME_POSIX_TIMERS
+ if (e == ENOSYS)
+ {
+ __libc_missing_posix_timers = 1;
+ __libc_missing_posix_cpu_timers = 1;
+ e = EINVAL;
+ }
+ else
+# endif
+ {
+ if (e == EINVAL)
+ {
+ /* Check whether the kernel supports CPU clocks at all.
+ If not, record it for the future. */
+ r = INTERNAL_VSYSCALL (clock_getres, err, 2,
+ MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+ NULL);
+ if (INTERNAL_SYSCALL_ERROR_P (r, err))
+ __libc_missing_posix_cpu_timers = 1;
+ }
+ }
+ }
+
+ return e;
+}
+
+# define SYSDEP_GETTIME_CPU \
+ retval = maybe_syscall_gettime_cpu (clock_id, tp); \
+ if (retval == 0) \
+ break; \
+ if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \
+ { \
+ __set_errno (retval); \
+ retval = -1; \
+ break; \
+ } \
+ retval = -1 /* Otherwise continue on to the HP_TIMING version. */;
+
+static inline int
+maybe_syscall_gettime_cputime (clockid_t clock_id, struct timespec *tp)
+{
+ return maybe_syscall_gettime_cpu
+ (clock_id == CLOCK_THREAD_CPUTIME_ID
+ ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED)
+ : MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+ tp);
+}
+
+# define SYSDEP_GETTIME_CPUTIME \
+ case CLOCK_PROCESS_CPUTIME_ID: \
+ case CLOCK_THREAD_CPUTIME_ID: \
+ retval = maybe_syscall_gettime_cputime (clock_id, tp); \
+ if (retval == 0) \
+ break; \
+ if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \
+ { \
+ __set_errno (retval); \
+ retval = -1; \
+ break; \
+ } \
+ retval = hp_timing_gettime (clock_id, tp); \
+ break;
+# if !HP_TIMING_AVAIL
+# define hp_timing_gettime(clock_id, tp) (__set_errno (EINVAL), -1)
+# endif
+
+# endif
+#endif
+
+#include <sysdeps/unix/clock_gettime.c>
diff --git a/libc/sysdeps/unix/sysv/linux/clock_nanosleep.c b/libc/sysdeps/unix/sysv/linux/clock_nanosleep.c
new file mode 100644
index 000000000..7645262ce
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/clock_nanosleep.c
@@ -0,0 +1,96 @@
+/* Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <time.h>
+#include <errno.h>
+
+#include <sysdep-cancel.h>
+#include <kernel-features.h>
+#include "kernel-posix-cpu-timers.h"
+
+
+#ifdef __ASSUME_POSIX_TIMERS
+/* We can simply use the syscall. The CPU clocks are not supported
+ with this function. */
+int
+clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
+ struct timespec *rem)
+{
+ INTERNAL_SYSCALL_DECL (err);
+ int r;
+
+ if (clock_id == CLOCK_THREAD_CPUTIME_ID)
+ return EINVAL;
+ if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
+ clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED);
+
+ if (SINGLE_THREAD_P)
+ r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, rem);
+ else
+ {
+ int oldstate = LIBC_CANCEL_ASYNC ();
+
+ r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req,
+ rem);
+
+ LIBC_CANCEL_RESET (oldstate);
+ }
+
+ return (INTERNAL_SYSCALL_ERROR_P (r, err)
+ ? INTERNAL_SYSCALL_ERRNO (r, err) : 0);
+}
+
+#else
+# ifdef __NR_clock_nanosleep
+/* Is the syscall known to exist? */
+extern int __libc_missing_posix_timers attribute_hidden;
+
+/* The REALTIME and MONOTONIC clock might be available. Try the
+ syscall first. */
+# define SYSDEP_NANOSLEEP \
+ if (!__libc_missing_posix_timers) \
+ { \
+ clockid_t syscall_clockid; \
+ INTERNAL_SYSCALL_DECL (err); \
+ \
+ if (clock_id == CLOCK_THREAD_CPUTIME_ID) \
+ return EINVAL; \
+ if (clock_id == CLOCK_PROCESS_CPUTIME_ID) \
+ syscall_clockid = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED); \
+ else \
+ syscall_clockid = clock_id; \
+ \
+ int oldstate = LIBC_CANCEL_ASYNC (); \
+ \
+ int r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, \
+ syscall_clockid, flags, req, rem); \
+ \
+ LIBC_CANCEL_RESET (oldstate); \
+ \
+ if (!INTERNAL_SYSCALL_ERROR_P (r, err)) \
+ return 0; \
+ \
+ if (INTERNAL_SYSCALL_ERRNO (r, err) != ENOSYS) \
+ return INTERNAL_SYSCALL_ERRNO (r, err); \
+ \
+ __libc_missing_posix_timers = 1; \
+ }
+# endif
+
+# include <sysdeps/unix/clock_nanosleep.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/clock_settime.c b/libc/sysdeps/unix/sysv/linux/clock_settime.c
new file mode 100644
index 000000000..217ae3f29
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/clock_settime.c
@@ -0,0 +1,149 @@
+/* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sysdep.h>
+
+#include "kernel-posix-cpu-timers.h"
+#include <kernel-features.h>
+
+#ifndef HAVE_CLOCK_GETRES_VSYSCALL
+# undef INTERNAL_VSYSCALL
+# define INTERNAL_VSYSCALL INTERNAL_SYSCALL
+# undef INLINE_VSYSCALL
+# define INLINE_VSYSCALL INLINE_SYSCALL
+#else
+# include <bits/libc-vdso.h>
+#endif
+
+#if __ASSUME_POSIX_CPU_TIMERS <= 0 && defined __NR_clock_settime
+extern int __libc_missing_posix_timers attribute_hidden;
+extern int __libc_missing_posix_cpu_timers attribute_hidden;
+
+static int
+maybe_syscall_settime_cpu (clockid_t clock_id, const struct timespec *tp)
+{
+ int e = EINVAL;
+
+ if (!__libc_missing_posix_cpu_timers)
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ int r = INTERNAL_SYSCALL (clock_settime, err, 2, clock_id, tp);
+ if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+ return 0;
+
+ e = INTERNAL_SYSCALL_ERRNO (r, err);
+# ifndef __ASSUME_POSIX_TIMERS
+ if (e == ENOSYS)
+ {
+ __libc_missing_posix_timers = 1;
+ __libc_missing_posix_cpu_timers = 1;
+ e = EINVAL;
+ }
+ else
+# endif
+ {
+ if (e == EINVAL)
+ {
+ /* Check whether the kernel supports CPU clocks at all.
+ If not, record it for the future. */
+ r = INTERNAL_VSYSCALL (clock_getres, err, 2,
+ MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+ NULL);
+ if (INTERNAL_SYSCALL_ERROR_P (r, err))
+ __libc_missing_posix_cpu_timers = 1;
+ }
+ }
+ }
+
+ return e;
+}
+#endif
+
+
+#ifdef __ASSUME_POSIX_TIMERS
+/* This means the REALTIME clock is definitely supported in the
+ kernel. */
+# define SYSDEP_SETTIME \
+ case CLOCK_REALTIME: \
+ retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp); \
+ break
+#elif defined __NR_clock_settime
+/* Is the syscall known to exist? */
+extern int __libc_missing_posix_timers attribute_hidden;
+
+/* The REALTIME clock might be available. Try the syscall first. */
+# define SYSDEP_SETTIME \
+ case CLOCK_REALTIME: \
+ { \
+ int e = EINVAL; \
+ \
+ if (!__libc_missing_posix_timers) \
+ { \
+ INTERNAL_SYSCALL_DECL (err); \
+ int r = INTERNAL_SYSCALL (clock_settime, err, 2, clock_id, tp); \
+ if (!INTERNAL_SYSCALL_ERROR_P (r, err)) \
+ { \
+ retval = 0; \
+ break; \
+ } \
+ \
+ e = INTERNAL_SYSCALL_ERRNO (r, err); \
+ if (e == ENOSYS) \
+ { \
+ __libc_missing_posix_timers = 1; \
+ e = EINVAL; \
+ } \
+ } \
+ \
+ /* Fallback code. */ \
+ if (e == EINVAL && clock_id == CLOCK_REALTIME) \
+ HANDLE_REALTIME; \
+ else \
+ { \
+ __set_errno (e); \
+ retval = -1; \
+ } \
+ } \
+ break
+#endif
+
+#ifdef __NR_clock_settime
+/* We handled the REALTIME clock here. */
+# define HANDLED_REALTIME 1
+#endif
+
+#if __ASSUME_POSIX_CPU_TIMERS > 0
+# define HANDLED_CPUTIME 1
+# define SYSDEP_SETTIME_CPU \
+ retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp)
+#elif defined __NR_clock_settime
+# define SYSDEP_SETTIME_CPU \
+ retval = maybe_syscall_settime_cpu (clock_id, tp); \
+ if (retval == 0) \
+ break; \
+ if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \
+ { \
+ __set_errno (retval); \
+ retval = -1; \
+ break; \
+ } \
+ do { } while (0)
+#endif
+
+#include <sysdeps/unix/clock_settime.c>
diff --git a/libc/sysdeps/unix/sysv/linux/cmsg_nxthdr.c b/libc/sysdeps/unix/sysv/linux/cmsg_nxthdr.c
new file mode 100644
index 000000000..b7de285e3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/cmsg_nxthdr.c
@@ -0,0 +1,39 @@
+/* Return point to next ancillary data entry in message header.
+ Copyright (C) 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/socket.h>
+
+
+struct cmsghdr *
+__cmsg_nxthdr (struct msghdr *mhdr, struct cmsghdr *cmsg)
+{
+ if ((size_t) cmsg->cmsg_len < sizeof (struct cmsghdr))
+ /* The kernel header does this so there may be a reason. */
+ return NULL;
+
+ cmsg = (struct cmsghdr *) ((unsigned char *) cmsg
+ + CMSG_ALIGN (cmsg->cmsg_len));
+ if ((unsigned char *) (cmsg + 1) > ((unsigned char *) mhdr->msg_control
+ + mhdr->msg_controllen)
+ || ((unsigned char *) cmsg + CMSG_ALIGN (cmsg->cmsg_len)
+ > ((unsigned char *) mhdr->msg_control + mhdr->msg_controllen)))
+ /* No more entries. */
+ return NULL;
+ return cmsg;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/configure b/libc/sysdeps/unix/sysv/linux/configure
new file mode 100644
index 000000000..a8a9cc470
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/configure
@@ -0,0 +1,367 @@
+# This file is generated from configure.in by Autoconf. DO NOT EDIT!
+ # Local configure fragment for sysdeps/unix/sysv/linux.
+
+# The Linux kernel headers can be found in
+# /lib/modules/$(uname -r)/build/include
+# Check whether this directory is available.
+if test -z "$sysheaders" &&
+ test "x$cross_compiling" = xno &&
+ test -d /lib/modules/`uname -r`/build/include; then
+ sysheaders="/lib/modules/`uname -r`/build/include"
+ ccheaders=`$CC -print-file-name=include`
+ SYSINCLUDES="-I $sysheaders"
+fi
+
+# Don't bother trying to generate any glue code to be compatible with the
+# existing system library, because we are the only system library.
+inhibit_glue=yes
+
+if test -n "$sysheaders"; then
+ OLD_CPPFLAGS=$CPPFLAGS
+ CPPFLAGS="$CPPFLAGS $SYSINCLUDES"
+fi
+
+
+echo "$as_me:$LINENO: checking for egrep" >&5
+echo $ECHO_N "checking for egrep... $ECHO_C" >&6
+if test "${ac_cv_prog_egrep+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if echo a | (grep -E '(a|b)') >/dev/null 2>&1
+ then ac_cv_prog_egrep='grep -E'
+ else ac_cv_prog_egrep='egrep'
+ fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_egrep" >&5
+echo "${ECHO_T}$ac_cv_prog_egrep" >&6
+ EGREP=$ac_cv_prog_egrep
+
+
+echo "$as_me:$LINENO: checking installed Linux kernel header files" >&5
+echo $ECHO_N "checking installed Linux kernel header files... $ECHO_C" >&6
+if test "${libc_cv_linux2010+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <linux/version.h>
+#if !defined LINUX_VERSION_CODE || LINUX_VERSION_CODE < (2 *65536+ 0 *256+ 10) /* 2.0.10 */
+eat flaming death
+#endif
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "eat flaming death" >/dev/null 2>&1; then
+ libc_cv_linux2010='TOO OLD!'
+else
+ libc_cv_linux2010='2.0.10 or later'
+fi
+rm -f conftest*
+
+fi
+echo "$as_me:$LINENO: result: $libc_cv_linux2010" >&5
+echo "${ECHO_T}$libc_cv_linux2010" >&6
+if test "$libc_cv_linux2010" != '2.0.10 or later'; then
+ { { echo "$as_me:$LINENO: error: GNU libc requires kernel header files from
+Linux 2.0.10 or later to be installed before configuring.
+The kernel header files are found usually in /usr/include/asm and
+/usr/include/linux; make sure these directories use files from
+Linux 2.0.10 or later. This check uses <linux/version.h>, so
+make sure that file was built correctly when installing the kernel header
+files. To use kernel headers not from /usr/include/linux, use the
+configure option --with-headers." >&5
+echo "$as_me: error: GNU libc requires kernel header files from
+Linux 2.0.10 or later to be installed before configuring.
+The kernel header files are found usually in /usr/include/asm and
+/usr/include/linux; make sure these directories use files from
+Linux 2.0.10 or later. This check uses <linux/version.h>, so
+make sure that file was built correctly when installing the kernel header
+files. To use kernel headers not from /usr/include/linux, use the
+configure option --with-headers." >&2;}
+ { (exit 1); exit 1; }; }
+fi
+
+# If the user gave a minimal version number test whether the available
+# kernel headers are young enough. Additionally we have minimal
+# kernel versions for some architectures. If a previous configure fragment
+# set arch_minimum_kernel already, let that override our defaults here.
+# Note that we presume such a fragment has set libc_cv_gcc_unwind_find_fde
+# if appropriate too.
+test -n "$arch_minimum_kernel" ||
+case "$machine" in
+ alpha*)
+ arch_minimum_kernel=2.1.100
+ libc_cv_gcc_unwind_find_fde=yes
+ ;;
+ arm*)
+ arch_minimum_kernel=2.0.10
+ libc_cv_gcc_unwind_find_fde=yes
+ ;;
+ i386*)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.0.10
+ ;;
+ ia64*)
+ arch_minimum_kernel=2.4.0
+ ;;
+ hppa*)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.4.19
+ ;;
+ m68k*)
+ arch_minimum_kernel=2.0.10
+ libc_cv_gcc_unwind_find_fde=yes
+ ;;
+ powerpc/powerpc32)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.0.10
+ ;;
+ powerpc/powerpc64)
+ arch_minimum_kernel=2.4.19
+ ;;
+ s390/s390-32)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.2.10
+ ;;
+ s390/s390-64)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.4.0
+ ;;
+ sh*)
+ arch_minimum_kernel=2.3.99
+ libc_cv_gcc_unwind_find_fde=yes
+ ;;
+ sparc/sparc64*)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.4.21
+ ;;
+ sparc*)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.0.10
+ ;;
+ x86_64*)
+ arch_minimum_kernel=2.4.0
+ ;;
+ *)
+ arch_minimum_kernel=2.0.10
+ ;;
+esac
+if test -n "$minimum_kernel"; then
+
+ user_version=$((`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \* 65536 + \2 \* 256 + \3/'`))
+ arch_version=$((`echo "$arch_minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \* 65536 + \2 \* 256 + \3/'`))
+
+ if test $user_version -lt $arch_version; then
+ { echo "$as_me:$LINENO: WARNING: minimum kernel version reset to $arch_minimum_kernel" >&5
+echo "$as_me: WARNING: minimum kernel version reset to $arch_minimum_kernel" >&2;}
+ minimum_kernel=$arch_minimum_kernel
+ fi
+else
+ if test $arch_minimum_kernel != '2.0.10'; then
+ minimum_kernel=$arch_minimum_kernel
+ fi
+fi
+
+if test -n "$minimum_kernel"; then
+ echo "$as_me:$LINENO: checking for kernel header at least $minimum_kernel" >&5
+echo $ECHO_N "checking for kernel header at least $minimum_kernel... $ECHO_C" >&6
+ decnum=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/(\1 * 65536 + \2 * 256 + \3)/'`;
+ abinum=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1,\2,\3/'`;
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <linux/version.h>
+#if LINUX_VERSION_CODE < $decnum
+eat flaming death
+#endif
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP "eat flaming death" >/dev/null 2>&1; then
+ libc_minimum_kernel='too old!'
+else
+ libc_minimum_kernel=ok
+fi
+rm -f conftest*
+
+ echo "$as_me:$LINENO: result: $libc_minimum_kernel" >&5
+echo "${ECHO_T}$libc_minimum_kernel" >&6
+ if test "$libc_minimum_kernel" = ok; then
+ cat >>confdefs.h <<_ACEOF
+#define __LINUX_KERNEL_VERSION $decnum
+_ACEOF
+
+ cat >>confdefs.h <<_ACEOF
+#define __ABI_TAG_VERSION $abinum
+_ACEOF
+
+ else
+ { { echo "$as_me:$LINENO: error: *** The available kernel headers are older than the requested
+*** compatible kernel version" >&5
+echo "$as_me: error: *** The available kernel headers are older than the requested
+*** compatible kernel version" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+fi
+
+# The result of the above test for the use of the FDE code is invalid if
+# the user overrides the decision about the minimum ABI.
+if test "$oldest_abi" != default && test "2.2.4" \< "$oldest_abi"; then
+ libc_cv_gcc_unwind_find_fde=no
+fi
+
+if test -n "$sysheaders"; then
+ CPPFLAGS=$OLD_CPPFLAGS
+fi
+# The Linux filesystem standard prescribes where to place "essential"
+# files. I.e., when the installation prefix is "/usr" we have to place
+# shared library objects and the configuration files on the root partition
+# in /lib and /etc.
+case "$prefix" in
+/usr | /usr/)
+ # 64-bit libraries on bi-arch platforms go in /lib64 instead of /lib.
+ # Allow earlier configure scripts to handle libc_cv_slibdir, libdir,
+ # and libc_cv_localedir.
+ test -n "$libc_cv_slibdir" || \
+ case $machine in
+ sparc/sparc64 | x86_64 | powerpc/powerpc64 | s390/s390-64)
+ libc_cv_slibdir="/lib64"
+ if test "$libdir" = '${exec_prefix}/lib'; then
+ libdir='${exec_prefix}/lib64';
+ # Locale data can be shared between 32bit and 64bit libraries
+ libc_cv_localedir='${exec_prefix}/lib/locale'
+ fi
+ ;;
+ *)
+ libc_cv_slibdir="/lib"
+ ;;
+ esac
+ # Allow the user to override the path with --sysconfdir
+ if test $sysconfdir = '${prefix}/etc'; then
+ libc_cv_sysconfdir=/etc
+ else
+ libc_cv_sysconfdir=$sysconfdir
+ fi
+ libc_cv_rootsbindir="/sbin"
+ ;;
+esac
+
+# Under Linux the NPTL add-on should be available.
+case $add_ons in
+ # It is available. Good.
+ *nptl*)
+ nptl_missing=
+ ;;
+ *)
+ nptl_missing=yes
+ ;;
+esac
+
+if test "$nptl_missing"; then
+ if test $enable_sanity = yes; then
+ echo "\
+*** On GNU/Linux systems it is normal to compile GNU libc with the
+*** \`nptl' add-on. Without that, the library will be
+*** incompatible with normal GNU/Linux systems.
+*** If you really mean to not use this add-on, run configure again
+*** using the extra parameter \`--disable-sanity-checks'."
+ exit 1
+ else
+ echo "\
+*** WARNING: Are you sure you do not want to use the \`nptl'
+*** add-on?"
+ fi
+fi
+
+if test "$prefix" = "/usr/local" -o "$prefix" = "/usr/local/" -o "$prefix" = "NONE"; then
+ if test $enable_sanity = yes; then
+ echo "\
+*** On GNU/Linux systems the GNU C Library should not be installed into
+*** /usr/local since this might make your system totally unusable.
+*** We strongly advise to use a different prefix. For details read the FAQ.
+*** If you really mean to do this, run configure again using the extra
+*** parameter \`--disable-sanity-checks'."
+ exit 1
+ else
+ echo "\
+*** WARNING: Do you really want to install the GNU C Library into /usr/local?
+*** This might make your system totally unusable, for details read the FAQ."
+ fi
+fi
+
+
+# One Linux we use ldconfig.
+use_ldconfig=yes
+
+# We need some extensions to the `ldd' script.
+
+case "$machine" in
+ i[3456]86* | m68*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/ldd-rewrite.sed
+ ;;
+ ia64*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/ia64/ldd-rewrite.sed
+ ;;
+ s390*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/s390/ldd-rewrite.sed
+ ;;
+ sparc*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/sparc/ldd-rewrite.sed
+ ;;
+ x86_64*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/x86_64/ldd-rewrite.sed
+ ;;
+ powerpc*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/powerpc/ldd-rewrite.sed
+ ;;
+ *)
+ ;;
+esac
+
+
+if test $host = $build; then
+ # If $prefix/include/{net,scsi} are symlinks, make install will
+ # clobber what they're linked to (probably a kernel tree).
+ # test -L ought to work on all Linux boxes.
+ if test "x$prefix" != xNONE; then
+ ac_prefix=$prefix
+ else
+ ac_prefix=$ac_default_prefix
+ fi
+ echo "$as_me:$LINENO: checking for symlinks in ${ac_prefix}/include" >&5
+echo $ECHO_N "checking for symlinks in ${ac_prefix}/include... $ECHO_C" >&6
+ ac_message=
+ if test -L ${ac_prefix}/include/net; then
+ ac_message="$ac_message
+ ${ac_prefix}/include/net is a symlink"
+ fi
+ if test -L ${ac_prefix}/include/scsi; then
+ ac_message="$ac_message
+ ${ac_prefix}/include/scsi is a symlink"
+ fi
+ if test -n "$ac_message"; then
+ { { echo "$as_me:$LINENO: error: $ac_message
+\`make install' will destroy the target of the link(s).
+Delete the links and re-run configure, or better still, move the entire
+${ac_prefix}/include directory out of the way." >&5
+echo "$as_me: error: $ac_message
+\`make install' will destroy the target of the link(s).
+Delete the links and re-run configure, or better still, move the entire
+${ac_prefix}/include directory out of the way." >&2;}
+ { (exit 1); exit 1; }; }
+ else
+ echo "$as_me:$LINENO: result: ok" >&5
+echo "${ECHO_T}ok" >&6
+ fi
+fi
+
+# We have inlined syscalls.
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_INLINED_SYSCALLS 1
+_ACEOF
+
diff --git a/libc/sysdeps/unix/sysv/linux/configure.in b/libc/sysdeps/unix/sysv/linux/configure.in
new file mode 100644
index 000000000..43681f325
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/configure.in
@@ -0,0 +1,292 @@
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/unix/sysv/linux.
+
+# The Linux kernel headers can be found in
+# /lib/modules/$(uname -r)/build/include
+# Check whether this directory is available.
+if test -z "$sysheaders" &&
+ test "x$cross_compiling" = xno &&
+ test -d /lib/modules/`uname -r`/build/include; then
+ sysheaders="/lib/modules/`uname -r`/build/include"
+ ccheaders=`$CC -print-file-name=include`
+ dnl We don't have to use -nostdinc. We just want one more directory
+ dnl to be used.
+ SYSINCLUDES="-I $sysheaders"
+fi
+
+# Don't bother trying to generate any glue code to be compatible with the
+# existing system library, because we are the only system library.
+inhibit_glue=yes
+
+define([LIBC_LINUX_VERSION],[2.0.10])dnl
+if test -n "$sysheaders"; then
+ OLD_CPPFLAGS=$CPPFLAGS
+ CPPFLAGS="$CPPFLAGS $SYSINCLUDES"
+fi
+define([libc_cv_linuxVER], [libc_cv_linux]patsubst(LIBC_LINUX_VERSION,[\.]))dnl
+AC_CACHE_CHECK(installed Linux kernel header files, libc_cv_linuxVER, [dnl
+AC_EGREP_CPP([eat flaming death], [#include <linux/version.h>
+#if !defined LINUX_VERSION_CODE || LINUX_VERSION_CODE < ]dnl
+patsubst(LIBC_LINUX_VERSION,[^\([^.]*\)\.\([^.]*\)\.\([^.]*\)$],dnl
+[ (\1 *65536+ \2 *256+ \3) /* \1.\2.\3 */])[
+eat flaming death
+#endif],
+ libc_cv_linuxVER='TOO OLD!',
+ libc_cv_linuxVER='LIBC_LINUX_VERSION or later')])
+if test "$libc_cv_linuxVER" != 'LIBC_LINUX_VERSION or later'; then
+ AC_MSG_ERROR([GNU libc requires kernel header files from
+Linux LIBC_LINUX_VERSION or later to be installed before configuring.
+The kernel header files are found usually in /usr/include/asm and
+/usr/include/linux; make sure these directories use files from
+Linux LIBC_LINUX_VERSION or later. This check uses <linux/version.h>, so
+make sure that file was built correctly when installing the kernel header
+files. To use kernel headers not from /usr/include/linux, use the
+configure option --with-headers.])
+fi
+
+# If the user gave a minimal version number test whether the available
+# kernel headers are young enough. Additionally we have minimal
+# kernel versions for some architectures. If a previous configure fragment
+# set arch_minimum_kernel already, let that override our defaults here.
+# Note that we presume such a fragment has set libc_cv_gcc_unwind_find_fde
+# if appropriate too.
+test -n "$arch_minimum_kernel" ||
+case "$machine" in
+ alpha*)
+ arch_minimum_kernel=2.1.100
+ libc_cv_gcc_unwind_find_fde=yes
+ ;;
+ arm*)
+ arch_minimum_kernel=2.0.10
+ libc_cv_gcc_unwind_find_fde=yes
+ ;;
+ i386*)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.0.10
+ ;;
+ ia64*)
+ arch_minimum_kernel=2.4.0
+ ;;
+ hppa*)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.4.19
+ ;;
+ m68k*)
+ arch_minimum_kernel=2.0.10
+ libc_cv_gcc_unwind_find_fde=yes
+ ;;
+ powerpc/powerpc32)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.0.10
+ ;;
+ powerpc/powerpc64)
+ arch_minimum_kernel=2.4.19
+ ;;
+ s390/s390-32)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.2.10
+ ;;
+ s390/s390-64)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.4.0
+ ;;
+ sh*)
+ arch_minimum_kernel=2.3.99
+ libc_cv_gcc_unwind_find_fde=yes
+ ;;
+ sparc/sparc64*)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.4.21
+ ;;
+ sparc*)
+ libc_cv_gcc_unwind_find_fde=yes
+ arch_minimum_kernel=2.0.10
+ ;;
+ x86_64*)
+ arch_minimum_kernel=2.4.0
+ ;;
+ *)
+ arch_minimum_kernel=2.0.10
+ ;;
+esac
+if test -n "$minimum_kernel"; then
+ changequote(,)
+ user_version=$((`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \* 65536 + \2 \* 256 + \3/'`))
+ arch_version=$((`echo "$arch_minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \* 65536 + \2 \* 256 + \3/'`))
+ changequote([,])
+ if test $user_version -lt $arch_version; then
+ AC_MSG_WARN([minimum kernel version reset to $arch_minimum_kernel])
+ minimum_kernel=$arch_minimum_kernel
+ fi
+else
+ if test $arch_minimum_kernel != '2.0.10'; then
+ minimum_kernel=$arch_minimum_kernel
+ fi
+fi
+
+if test -n "$minimum_kernel"; then
+ AC_MSG_CHECKING(for kernel header at least $minimum_kernel)
+changequote(,)dnl
+ decnum=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/(\1 * 65536 + \2 * 256 + \3)/'`;
+ abinum=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1,\2,\3/'`;
+changequote([,])dnl
+ AC_EGREP_CPP([eat flaming death], [#include <linux/version.h>
+#if LINUX_VERSION_CODE < $decnum
+eat flaming death
+#endif], libc_minimum_kernel='too old!', libc_minimum_kernel=ok)
+ AC_MSG_RESULT($libc_minimum_kernel)
+ if test "$libc_minimum_kernel" = ok; then
+ AC_DEFINE_UNQUOTED(__LINUX_KERNEL_VERSION, $decnum)
+ AC_DEFINE_UNQUOTED(__ABI_TAG_VERSION, $abinum)
+ else
+ AC_MSG_ERROR([*** The available kernel headers are older than the requested
+*** compatible kernel version])
+ fi
+fi
+
+# The result of the above test for the use of the FDE code is invalid if
+# the user overrides the decision about the minimum ABI.
+if test "$oldest_abi" != default && test "2.2.4" \< "$oldest_abi"; then
+ libc_cv_gcc_unwind_find_fde=no
+fi
+
+if test -n "$sysheaders"; then
+ CPPFLAGS=$OLD_CPPFLAGS
+fi
+# The Linux filesystem standard prescribes where to place "essential"
+# files. I.e., when the installation prefix is "/usr" we have to place
+# shared library objects and the configuration files on the root partition
+# in /lib and /etc.
+case "$prefix" in
+/usr | /usr/)
+ # 64-bit libraries on bi-arch platforms go in /lib64 instead of /lib.
+ # Allow earlier configure scripts to handle libc_cv_slibdir, libdir,
+ # and libc_cv_localedir.
+ test -n "$libc_cv_slibdir" || \
+ case $machine in
+ sparc/sparc64 | x86_64 | powerpc/powerpc64 | s390/s390-64)
+ libc_cv_slibdir="/lib64"
+ if test "$libdir" = '${exec_prefix}/lib'; then
+ libdir='${exec_prefix}/lib64';
+ # Locale data can be shared between 32bit and 64bit libraries
+ libc_cv_localedir='${exec_prefix}/lib/locale'
+ fi
+ ;;
+ *)
+ libc_cv_slibdir="/lib"
+ ;;
+ esac
+ # Allow the user to override the path with --sysconfdir
+ if test $sysconfdir = '${prefix}/etc'; then
+ libc_cv_sysconfdir=/etc
+ else
+ libc_cv_sysconfdir=$sysconfdir
+ fi
+ libc_cv_rootsbindir="/sbin"
+ ;;
+esac
+
+# Under Linux the NPTL add-on should be available.
+case $add_ons in
+ # It is available. Good.
+ *nptl*)
+ nptl_missing=
+ ;;
+ *)
+ nptl_missing=yes
+ ;;
+esac
+
+if test "$nptl_missing"; then
+ if test $enable_sanity = yes; then
+ echo "\
+*** On GNU/Linux systems it is normal to compile GNU libc with the
+*** \`nptl' add-on. Without that, the library will be
+*** incompatible with normal GNU/Linux systems.
+*** If you really mean to not use this add-on, run configure again
+*** using the extra parameter \`--disable-sanity-checks'."
+ exit 1
+ else
+ echo "\
+*** WARNING: Are you sure you do not want to use the \`nptl'
+*** add-on?"
+ fi
+fi
+
+if test "$prefix" = "/usr/local" -o "$prefix" = "/usr/local/" -o "$prefix" = "NONE"; then
+ if test $enable_sanity = yes; then
+ echo "\
+*** On GNU/Linux systems the GNU C Library should not be installed into
+*** /usr/local since this might make your system totally unusable.
+*** We strongly advise to use a different prefix. For details read the FAQ.
+*** If you really mean to do this, run configure again using the extra
+*** parameter \`--disable-sanity-checks'."
+ exit 1
+ else
+ echo "\
+*** WARNING: Do you really want to install the GNU C Library into /usr/local?
+*** This might make your system totally unusable, for details read the FAQ."
+ fi
+fi
+
+
+# One Linux we use ldconfig.
+use_ldconfig=yes
+
+# We need some extensions to the `ldd' script.
+changequote(,)
+case "$machine" in
+ i[3456]86* | m68*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/ldd-rewrite.sed
+ ;;
+ ia64*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/ia64/ldd-rewrite.sed
+ ;;
+ s390*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/s390/ldd-rewrite.sed
+ ;;
+ sparc*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/sparc/ldd-rewrite.sed
+ ;;
+ x86_64*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/x86_64/ldd-rewrite.sed
+ ;;
+ powerpc*)
+ ldd_rewrite_script=../sysdeps/unix/sysv/linux/powerpc/ldd-rewrite.sed
+ ;;
+ *)
+ ;;
+esac
+changequote([,])
+
+if test $host = $build; then
+ # If $prefix/include/{net,scsi} are symlinks, make install will
+ # clobber what they're linked to (probably a kernel tree).
+ # test -L ought to work on all Linux boxes.
+ if test "x$prefix" != xNONE; then
+ ac_prefix=$prefix
+ else
+ ac_prefix=$ac_default_prefix
+ fi
+ AC_MSG_CHECKING([for symlinks in ${ac_prefix}/include])
+ ac_message=
+ if test -L ${ac_prefix}/include/net; then
+ ac_message="$ac_message
+ ${ac_prefix}/include/net is a symlink"
+ fi
+ if test -L ${ac_prefix}/include/scsi; then
+ ac_message="$ac_message
+ ${ac_prefix}/include/scsi is a symlink"
+ fi
+ if test -n "$ac_message"; then
+ AC_MSG_ERROR([$ac_message
+\`make install' will destroy the target of the link(s).
+Delete the links and re-run configure, or better still, move the entire
+${ac_prefix}/include directory out of the way.])
+ else
+ AC_MSG_RESULT(ok)
+ fi
+fi
+
+# We have inlined syscalls.
+AC_DEFINE(HAVE_INLINED_SYSCALLS)
diff --git a/libc/sysdeps/unix/sysv/linux/connect.S b/libc/sysdeps/unix/sysv/linux/connect.S
new file mode 100644
index 000000000..7d1fa12b3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/connect.S
@@ -0,0 +1,7 @@
+#define socket connect
+#define __socket __libc_connect
+#define NARGS 3
+#define NEED_CANCELLATION
+#include <socket.S>
+strong_alias (__libc_connect, __connect_internal)
+weak_alias (__libc_connect, __connect)
diff --git a/libc/sysdeps/unix/sysv/linux/device-nrs.h b/libc/sysdeps/unix/sysv/linux/device-nrs.h
new file mode 100644
index 000000000..b30c1dbed
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/device-nrs.h
@@ -0,0 +1,46 @@
+/* Device numbers of devices used in the implementation. Linux version.
+ Copyright (C) 2000, 2001, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _DEVICE_NRS_H
+#define _DEVICE_NRS_H 1
+
+#include <sys/sysmacros.h>
+
+/* /dev/null is (1,3). */
+#define DEV_NULL_MAJOR 1
+#define DEV_NULL_MINOR 3
+
+/* /dev/full is (1,7). */
+#define DEV_FULL_MAJOR 1
+#define DEV_FULL_MINOR 7
+
+/* Pseudo tty slaves. For Linux we use the Unix98 ttys. We could
+ also include the old BSD-style tty buts they should not be used and
+ the extra test would only slow down correctly set up systems. If a
+ system still uses those device the slower tests performed (using
+ isatty) will catch it. */
+#define DEV_TTY_LOW_MAJOR 136
+#define DEV_TTY_HIGH_MAJOR 143
+
+/* Test whether given device is a tty. */
+#define DEV_TTY_P(statp) \
+ ({ int __dev_major = major ((statp)->st_rdev); \
+ __dev_major >= DEV_TTY_LOW_MAJOR && __dev_major <= DEV_TTY_HIGH_MAJOR; })
+
+#endif /* device-nrs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/dl-brk.c b/libc/sysdeps/unix/sysv/linux/dl-brk.c
new file mode 100644
index 000000000..c37cdfec3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/dl-brk.c
@@ -0,0 +1,5 @@
+/* We can use the normal code but we also know the __curbrk is not exported
+ from ld.so. */
+extern void *__curbrk attribute_hidden;
+
+#include <brk.c>
diff --git a/libc/sysdeps/unix/sysv/linux/dl-execstack.c b/libc/sysdeps/unix/sysv/linux/dl-execstack.c
new file mode 100644
index 000000000..fcac5ae24
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/dl-execstack.c
@@ -0,0 +1,154 @@
+/* Stack executability handling for GNU dynamic linker. Linux version.
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ldsodefs.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <libintl.h>
+#include <stdbool.h>
+#include <stackinfo.h>
+#include <caller.h>
+#include <sysdep.h>
+
+#include <kernel-features.h>
+
+
+extern int __stack_prot attribute_relro attribute_hidden;
+
+
+int
+internal_function
+_dl_make_stack_executable (void **stack_endp)
+{
+ /* This gives us the highest/lowest page that needs to be changed. */
+ uintptr_t page = ((uintptr_t) *stack_endp
+ & -(intptr_t) GLRO(dl_pagesize));
+ int result = 0;
+
+ /* Challenge the caller. */
+ if (__builtin_expect (__check_caller (RETURN_ADDRESS (0),
+ allow_ldso|allow_libpthread) != 0, 0)
+ || __builtin_expect (*stack_endp != __libc_stack_end, 0))
+ return EPERM;
+
+ /* Newer Linux kernels support a flag to make our job easy. */
+#if defined PROT_GROWSDOWN || defined PROT_GROWSUP
+# if __ASSUME_PROT_GROWSUPDOWN == 0
+ static bool no_growsupdown;
+ if (! no_growsupdown)
+# endif
+ {
+ if (__builtin_expect (__mprotect ((void *) page, GLRO(dl_pagesize),
+ __stack_prot) == 0, 1))
+ goto return_success;
+# if __ASSUME_PROT_GROWSUPDOWN == 0
+ if (errno == EINVAL)
+ no_growsupdown = true;
+ else
+# endif
+ {
+ result = errno;
+ goto out;
+ }
+ }
+#endif
+
+ /* There is always a hole in the address space below the bottom of the
+ stack. So when we make an mprotect call that starts below the bottom
+ of the stack, it will include the hole and fail with ENOMEM.
+
+ We start with a random guess at how deep the stack might have gotten
+ so as to have extended the GROWSDOWN mapping to lower pages. */
+
+#if __ASSUME_PROT_GROWSUPDOWN == 0
+ size_t size = GLRO(dl_pagesize) * 8;
+
+# if _STACK_GROWS_DOWN
+ page = page + GLRO(dl_pagesize) - size;
+ while (1)
+ {
+ if (__mprotect ((void *) page, size,
+ __stack_prot & ~PROT_GROWSDOWN) == 0)
+ /* We got this chunk changed; loop to do another chunk below. */
+ page -= size;
+ else
+ {
+ if (errno != ENOMEM) /* Unexpected failure mode. */
+ {
+ result = errno;
+ goto out;
+ }
+
+ if (size == GLRO(dl_pagesize))
+ /* We just tried to mprotect the top hole page and failed.
+ We are done. */
+ break;
+
+ /* Our mprotect call failed because it started below the lowest
+ stack page. Try again on just the top half of that region. */
+ size /= 2;
+ page += size;
+ }
+ }
+
+# elif _STACK_GROWS_UP
+ while (1)
+ {
+ if (__mprotect ((void *) page, size, __stack_prot & ~PROT_GROWSUP) == 0)
+ /* We got this chunk changed; loop to do another chunk below. */
+ page += size;
+ else
+ {
+ if (errno != ENOMEM) /* Unexpected failure mode. */
+ {
+ result = errno;
+ goto out;
+ }
+
+ if (size == GLRO(dl_pagesize))
+ /* We just tried to mprotect the lowest hole page and failed.
+ We are done. */
+ break;
+
+ /* Our mprotect call failed because it extended past the highest
+ stack page. Try again on just the bottom half of that region. */
+ size /= 2;
+ }
+ }
+
+# else
+# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
+# endif
+#endif
+
+ return_success:
+ /* Clear the address. */
+ *stack_endp = NULL;
+
+ /* Remember that we changed the permission. */
+ GL(dl_stack_flags) |= PF_X;
+
+ out:
+#ifdef check_consistency
+ check_consistency ();
+#endif
+
+ return result;
+}
+rtld_hidden_def (_dl_make_stack_executable)
diff --git a/libc/sysdeps/unix/sysv/linux/dl-librecon.h b/libc/sysdeps/unix/sysv/linux/dl-librecon.h
new file mode 100644
index 000000000..db46b98fb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/dl-librecon.h
@@ -0,0 +1,61 @@
+/* Optional code to distinguish library flavours.
+ Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2001.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _DL_LIBRECON_H
+#define _DL_LIBRECON_H 1
+
+static inline void __attribute__ ((unused, always_inline))
+_dl_osversion_init (char *assume_kernel)
+{
+ unsigned long int i, j, osversion = 0;
+ char *p = assume_kernel, *q;
+
+ for (i = 0; i < 3; i++, p = q + 1)
+ {
+ j = __strtoul_internal (p, &q, 0, 0);
+ if (j >= 255 || p == q || (i < 2 && *q && *q != '.'))
+ {
+ osversion = 0;
+ break;
+ }
+ osversion |= j << (16 - 8 * i);
+ if (!*q)
+ break;
+ }
+ if (osversion)
+ GLRO(dl_osversion) = osversion;
+}
+
+/* Recognizing extra environment variables. */
+#define EXTRA_LD_ENVVARS_13 \
+ if (memcmp (envline, "ASSUME_KERNEL", 13) == 0) \
+ { \
+ _dl_osversion_init (&envline[14]); \
+ break; \
+ }
+
+#define DL_OSVERSION_INIT \
+ do { \
+ char *assume_kernel = getenv ("LD_ASSUME_KERNEL"); \
+ if (assume_kernel) \
+ _dl_osversion_init (assume_kernel); \
+ } while (0)
+
+#endif /* dl-librecon.h */
diff --git a/libc/sysdeps/unix/sysv/linux/dl-origin.c b/libc/sysdeps/unix/sysv/linux/dl-origin.c
new file mode 100644
index 000000000..a7fa53ea1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/dl-origin.c
@@ -0,0 +1,81 @@
+/* Find path of executable.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.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 (readlink, err, 3, "/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/libc/sysdeps/unix/sysv/linux/dl-osinfo.h b/libc/sysdeps/unix/sysv/linux/dl-osinfo.h
new file mode 100644
index 000000000..0738501a5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/dl-osinfo.h
@@ -0,0 +1,180 @@
+/* Operating system specific code for generic dynamic loader functions. Linux.
+ Copyright (C) 2000,2001,2002,2004,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <string.h>
+#include <fcntl.h>
+#include <sys/utsname.h>
+#include <kernel-features.h>
+#include <dl-sysdep.h>
+#include <stdint.h>
+
+#ifndef MIN
+# define MIN(a,b) (((a)<(b))?(a):(b))
+#endif
+
+#ifdef SHARED
+/* This is the function used in the dynamic linker to print the fatal error
+ message. */
+static inline void
+__attribute__ ((__noreturn__))
+dl_fatal (const char *str)
+{
+ _dl_dprintf (2, str);
+ _exit (1);
+}
+#endif
+
+static inline int __attribute__ ((always_inline))
+_dl_discover_osversion (void)
+{
+#if (defined NEED_DL_SYSINFO || defined NEED_DL_SYSINFO_DSO) && defined SHARED
+ if (GLRO(dl_sysinfo_map) != NULL)
+ {
+ /* If the kernel-supplied DSO contains a note indicating the kernel's
+ version, we don't need to call uname or parse any strings. */
+
+ static const struct
+ {
+ ElfW(Word) vendorlen;
+ ElfW(Word) datalen;
+ ElfW(Word) type;
+ char vendor[8];
+ } expected_note = { sizeof "Linux", sizeof (ElfW(Word)), 0, "Linux" };
+ const ElfW(Phdr) *const phdr = GLRO(dl_sysinfo_map)->l_phdr;
+ const ElfW(Word) phnum = GLRO(dl_sysinfo_map)->l_phnum;
+ for (uint_fast16_t i = 0; i < phnum; ++i)
+ if (phdr[i].p_type == PT_NOTE)
+ {
+ const ElfW(Addr) start = (phdr[i].p_vaddr
+ + GLRO(dl_sysinfo_map)->l_addr);
+ const struct
+ {
+ ElfW(Word) vendorlen;
+ ElfW(Word) datalen;
+ ElfW(Word) type;
+ } *note = (const void *) start;
+ while ((ElfW(Addr)) (note + 1) - start < phdr[i].p_memsz)
+ {
+ if (!memcmp (note, &expected_note, sizeof expected_note))
+ return *(const ElfW(Word) *) ((const void *) note
+ + sizeof expected_note);
+#define ROUND(len) (((len) + sizeof (ElfW(Word)) - 1) & -sizeof (ElfW(Word)))
+ note = ((const void *) (note + 1)
+ + ROUND (note->vendorlen) + ROUND (note->datalen));
+ }
+ }
+ }
+#endif
+
+ char bufmem[64];
+ char *buf = bufmem;
+ unsigned int version;
+ int parts;
+ char *cp;
+ struct utsname uts;
+
+ /* Try the uname system call. */
+ if (__uname (&uts))
+ {
+ /* This was not successful. Now try reading the /proc filesystem. */
+ int fd = __open ("/proc/sys/kernel/osrelease", O_RDONLY);
+ if (fd < 0)
+ return -1;
+ ssize_t reslen = __read (fd, bufmem, sizeof (bufmem));
+ __close (fd);
+ if (reslen <= 0)
+ /* This also didn't work. We give up since we cannot
+ make sure the library can actually work. */
+ return -1;
+ buf[MIN (reslen, (ssize_t) sizeof (bufmem) - 1)] = '\0';
+ }
+ else
+ buf = uts.release;
+
+ /* Now convert it into a number. The string consists of at most
+ three parts. */
+ version = 0;
+ parts = 0;
+ cp = buf;
+ while ((*cp >= '0') && (*cp <= '9'))
+ {
+ unsigned int here = *cp++ - '0';
+
+ while ((*cp >= '0') && (*cp <= '9'))
+ {
+ here *= 10;
+ here += *cp++ - '0';
+ }
+
+ ++parts;
+ version <<= 8;
+ version |= here;
+
+ if (*cp++ != '.')
+ /* Another part following? */
+ break;
+ }
+
+ if (parts < 3)
+ version <<= 8 * (3 - parts);
+
+ return version;
+}
+
+#define DL_SYSDEP_OSCHECK(FATAL) \
+ do { \
+ /* Test whether the kernel is new enough. This test is only performed \
+ if the library is not compiled to run on all kernels. */ \
+ \
+ int version = _dl_discover_osversion (); \
+ if (__builtin_expect (version >= 0, 1)) \
+ { \
+ if (__builtin_expect (GLRO(dl_osversion) == 0, 1) \
+ || GLRO(dl_osversion) > version) \
+ GLRO(dl_osversion) = version; \
+ \
+ /* Now we can test with the required version. */ \
+ if (__LINUX_KERNEL_VERSION > 0 && version < __LINUX_KERNEL_VERSION) \
+ /* Not sufficent. */ \
+ FATAL ("FATAL: kernel too old\n"); \
+ } \
+ else if (__LINUX_KERNEL_VERSION > 0) \
+ FATAL ("FATAL: cannot determine kernel version\n"); \
+ } while (0)
+
+static inline uintptr_t __attribute__ ((always_inline))
+_dl_setup_stack_chk_guard (void)
+{
+ uintptr_t ret;
+#ifdef ENABLE_STACKGUARD_RANDOMIZE
+ int fd = __open ("/dev/urandom", O_RDONLY);
+ if (fd >= 0)
+ {
+ ssize_t reslen = __read (fd, &ret, sizeof (ret));
+ __close (fd);
+ if (reslen == (ssize_t) sizeof (ret))
+ return ret;
+ }
+#endif
+ ret = 0;
+ unsigned char *p = (unsigned char *) &ret;
+ p[sizeof (ret) - 1] = 255;
+ p[sizeof (ret) - 2] = '\n';
+ return ret;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/dl-sbrk.c b/libc/sysdeps/unix/sysv/linux/dl-sbrk.c
new file mode 100644
index 000000000..1ce5cb188
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/dl-sbrk.c
@@ -0,0 +1,5 @@
+/* We can use the normal code but we also know the __curbrk is not exported
+ from ld.so. */
+extern void *__curbrk attribute_hidden;
+
+#include <misc/sbrk.c>
diff --git a/libc/sysdeps/unix/sysv/linux/dl-sysdep.c b/libc/sysdeps/unix/sysv/linux/dl-sysdep.c
new file mode 100644
index 000000000..42aec77e8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/dl-sysdep.c
@@ -0,0 +1,56 @@
+/* Dynamic linker system dependencies for Linux.
+ Copyright (C) 1995,1997,2001,2004,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Linux needs some special initialization, but otherwise uses
+ the generic dynamic linker system interface code. */
+
+#include <unistd.h>
+#include <ldsodefs.h>
+#include <kernel-features.h>
+
+#define DL_SYSDEP_INIT frob_brk ()
+
+static inline void
+frob_brk (void)
+{
+ __brk (0); /* Initialize the break. */
+
+#if ! __ASSUME_BRK_PAGE_ROUNDED
+ /* If the dynamic linker was executed as a program, then the break may
+ start immediately after our data segment. However, dl-minimal.c has
+ already stolen the remainder of the page for internal allocations.
+ If we don't adjust the break location recorded by the kernel, the
+ normal program startup will inquire, find the value at our &_end,
+ and start allocating its own data there, clobbering dynamic linker
+ data structures allocated there during startup.
+
+ Later Linux kernels have changed this behavior so that the initial
+ break value is rounded up to the page boundary before we start. */
+
+ extern void *__curbrk attribute_hidden;
+ extern void _end attribute_hidden;
+ void *const endpage = (void *) 0 + (((__curbrk - (void *) 0)
+ + GLRO(dl_pagesize) - 1)
+ & -GLRO(dl_pagesize));
+ if (__builtin_expect (__curbrk >= &_end && __curbrk < endpage, 0))
+ __brk (endpage);
+#endif
+}
+
+#include <elf/dl-sysdep.c>
diff --git a/libc/sysdeps/unix/sysv/linux/dl-sysdep.h b/libc/sysdeps/unix/sysv/linux/dl-sysdep.h
new file mode 100644
index 000000000..becfc8df3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/dl-sysdep.h
@@ -0,0 +1,27 @@
+/* System-specific settings for dynamic linker code. Linux version.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include_next <dl-sysdep.h>
+
+/* On many architectures the kernel provides a virtual DSO and gives
+ AT_SYSINFO_EHDR to point us to it. As this is introduced for new
+ machines, we should look at it for unwind information even if
+ we aren't making direct use of it. So enable this across the board. */
+
+#define NEED_DL_SYSINFO_DSO 1
diff --git a/libc/sysdeps/unix/sysv/linux/errqueue.h b/libc/sysdeps/unix/sysv/linux/errqueue.h
new file mode 100644
index 000000000..9ed6dc62b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/errqueue.h
@@ -0,0 +1,46 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Linux version. */
+
+#ifndef _BITS_ERRQUEUE_H
+#define _BITS_ERRQUEUE_H 1
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+struct sock_extended_err
+ {
+ u_int32_t ee_errno;
+ u_int8_t ee_origin;
+ u_int8_t ee_type;
+ u_int8_t ee_code;
+ u_int8_t ee_pad;
+ u_int32_t ee_info;
+ u_int32_t ee_data;
+ };
+
+#define SO_EE_ORIGIN_NONE 0
+#define SO_EE_ORIGIN_LOCAL 1
+#define SO_EE_ORIGIN_ICMP 2
+#define SO_EE_ORIGIN_ICMP6 3
+
+#define SO_EE_OFFENDER(see) \
+ ((struct sockaddr *)(((struct sock_extended_err)(see))+1))
+
+#endif /* bits/errqueue.h */
diff --git a/libc/sysdeps/unix/sysv/linux/execve.c b/libc/sysdeps/unix/sysv/linux/execve.c
new file mode 100644
index 000000000..41dc0e75b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/execve.c
@@ -0,0 +1,63 @@
+/* Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <alloca.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+int
+__execve (file, argv, envp)
+ const char *file;
+ char *const argv[];
+ char *const envp[];
+{
+#if __BOUNDED_POINTERS__
+ {
+ char *const *v;
+ int i;
+ char *__unbounded *__unbounded ubp_argv;
+ char *__unbounded *__unbounded ubp_envp;
+ char *__unbounded *__unbounded ubp_v;
+
+ for (v = argv; *v; v++)
+ ;
+ i = v - argv + 1;
+ ubp_argv = (char *__unbounded *__unbounded) alloca (sizeof (*ubp_argv) * i);
+ for (v = argv, ubp_v = ubp_argv; --i; v++, ubp_v++)
+ *ubp_v = CHECK_STRING (*v);
+ *ubp_v = 0;
+
+ for (v = envp; *v; v++)
+ ;
+ i = v - envp + 1;
+ ubp_envp = (char *__unbounded *__unbounded) alloca (sizeof (*ubp_envp) * i);
+ for (v = envp, ubp_v = ubp_envp; --i; v++, ubp_v++)
+ *ubp_v = CHECK_STRING (*v);
+ *ubp_v = 0;
+
+ return INLINE_SYSCALL (execve, 3, CHECK_STRING (file), ubp_argv, ubp_envp);
+ }
+#else
+ return INLINE_SYSCALL (execve, 3, file, argv, envp);
+#endif
+}
+weak_alias (__execve, execve)
diff --git a/libc/sysdeps/unix/sysv/linux/exit-thread.S b/libc/sysdeps/unix/sysv/linux/exit-thread.S
new file mode 100644
index 000000000..bb996fecf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/exit-thread.S
@@ -0,0 +1,23 @@
+/* Copyright (C) 1991,92,97,99,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+PSEUDO (__exit_thread, exit, 1)
+ /* Shouldn't get here. */
+PSEUDO_END(__exit_thread)
diff --git a/libc/sysdeps/unix/sysv/linux/faccessat.c b/libc/sysdeps/unix/sysv/linux/faccessat.c
new file mode 100644
index 000000000..10b903d07
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/faccessat.c
@@ -0,0 +1,143 @@
+/* Test for access to file, relative to open directory. Linux version.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <alloca.h>
+#include <kernel-features.h>
+#include <sysdep.h>
+
+
+int
+faccessat (fd, file, mode, flag)
+ int fd;
+ const char *file;
+ int mode;
+ int flag;
+{
+ if (flag & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+#ifdef __NR_faccessat
+ if ((flag == 0 || ((flag & ~AT_EACCESS) == 0 && ! __libc_enable_secure))
+# ifndef __ASSUME_ATFCTS
+ && __have_atfcts >= 0
+# endif
+ )
+ {
+ int result = INLINE_SYSCALL (faccessat, 3, fd, file, mode);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ if ((!(flag & AT_EACCESS) || ! __libc_enable_secure)
+# ifndef __NR_laccess /* Linux so far has no laccess syscall. */
+ && !(flag & AT_SYMLINK_NOFOLLOW)
+# endif
+ )
+ {
+ /* If we are not set-uid or set-gid, access does the same. */
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ int result;
+ INTERNAL_SYSCALL_DECL (err);
+
+# ifdef __NR_laccess
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (laccess, err, 2, file, mode);
+ else
+# endif
+ result = INTERNAL_SYSCALL (access, err, 2, file, mode);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+ result = -1;
+ }
+
+ return result;
+ }
+#endif
+
+ struct stat64 stats;
+ if (fstatat64 (fd, file, &stats, flag & AT_SYMLINK_NOFOLLOW))
+ return -1;
+
+ mode &= (X_OK | W_OK | R_OK); /* Clear any bogus bits. */
+#if R_OK != S_IROTH || W_OK != S_IWOTH || X_OK != S_IXOTH
+# error Oops, portability assumptions incorrect.
+#endif
+
+ if (mode == F_OK)
+ return 0; /* The file exists. */
+
+ uid_t uid = (flag & AT_EACCESS) ? __geteuid () : __getuid ();
+
+ /* The super-user can read and write any file, and execute any file
+ that anyone can execute. */
+ if (uid == 0 && ((mode & X_OK) == 0
+ || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))))
+ return 0;
+
+ int granted = (uid == stats.st_uid
+ ? (unsigned int) (stats.st_mode & (mode << 6)) >> 6
+ : (stats.st_gid == ((flag & AT_EACCESS)
+ ? __getegid () : __getgid ())
+ || __group_member (stats.st_gid))
+ ? (unsigned int) (stats.st_mode & (mode << 3)) >> 3
+ : (stats.st_mode & mode));
+
+ if (granted == mode)
+ return 0;
+
+ __set_errno (EACCES);
+ return -1;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/fatal-prepare.h b/libc/sysdeps/unix/sysv/linux/fatal-prepare.h
new file mode 100644
index 000000000..d48ae625e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fatal-prepare.h
@@ -0,0 +1,39 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <pthread.h>
+
+/* We have to completely disable cancellation. assert() must not be a
+ cancellation point but the implementation uses write() etc. */
+#ifdef SHARED
+# include <pthread-functions.h>
+# define FATAL_PREPARE \
+ { \
+ int (*fp) (int, int *); \
+ fp = __libc_pthread_functions.ptr_pthread_setcancelstate; \
+ if (fp != NULL) \
+ fp (PTHREAD_CANCEL_DISABLE, NULL); \
+ }
+#else
+# pragma weak pthread_setcancelstate
+# define FATAL_PREPARE \
+ { \
+ if (pthread_setcancelstate != NULL) \
+ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); \
+ }
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/fchmodat.c b/libc/sysdeps/unix/sysv/linux/fchmodat.c
new file mode 100644
index 000000000..8b420153f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fchmodat.c
@@ -0,0 +1,106 @@
+/* Change the protections of file relative to open directory. Linux version.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <alloca.h>
+#include <kernel-features.h>
+#include <sysdep.h>
+
+int
+fchmodat (fd, file, mode, flag)
+ int fd;
+ const char *file;
+ mode_t mode;
+ int flag;
+{
+ if (flag & ~AT_SYMLINK_NOFOLLOW)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+#ifndef __NR_lchmod /* Linux so far has no lchmod syscall. */
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ {
+ __set_errno (ENOTSUP);
+ return -1;
+ }
+#endif
+
+ int result;
+
+#ifdef __NR_fchmodat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INLINE_SYSCALL (fchmodat, 3, fd, file, mode);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+# ifdef __NR_lchmod
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lchmod, err, 2, file, mode);
+ else
+# endif
+ result = INTERNAL_SYSCALL (chmod, err, 2, file, mode);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+ result = -1;
+ }
+
+ return result;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/fchownat.c b/libc/sysdeps/unix/sysv/linux/fchownat.c
new file mode 100644
index 000000000..0f731775b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fchownat.c
@@ -0,0 +1,99 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <alloca.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+
+
+/* Change the owner and group of FILE. */
+int
+fchownat (fd, file, owner, group, flag)
+ int fd;
+ const char *file;
+ uid_t owner;
+ gid_t group;
+ int flag;
+{
+ int result;
+
+#ifdef __NR_fchownat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INLINE_SYSCALL (fchownat, 5, fd, file, owner, group, flag);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ if (flag & ~AT_SYMLINK_NOFOLLOW)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lchown, err, 3, file, owner, group);
+ else
+ result = INTERNAL_SYSCALL (chown, err, 3, file, owner, group);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+ result = -1;
+ }
+
+ return result;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/fcntl.c b/libc/sysdeps/unix/sysv/linux/fcntl.c
new file mode 100644
index 000000000..1f5aca14a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fcntl.c
@@ -0,0 +1,69 @@
+/* Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <sysdep-cancel.h> /* Must come before <fcntl.h>. */
+#include <fcntl.h>
+#include <stdarg.h>
+
+#include <sys/syscall.h>
+
+
+#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 INLINE_SYSCALL (fcntl, 3, 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 INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = INLINE_SYSCALL (fcntl, 3, 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/libc/sysdeps/unix/sysv/linux/fd_to_filename.h b/libc/sysdeps/unix/sysv/linux/fd_to_filename.h
new file mode 100644
index 000000000..dc1bdcc92
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fd_to_filename.h
@@ -0,0 +1,46 @@
+/* Query filename corresponding to an open FD. Linux version.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <stdio-common/_itoa.h>
+
+static inline const char *
+fd_to_filename (int fd)
+{
+ char *ret = malloc (30);
+
+ if (ret != NULL)
+ {
+ struct stat64 st;
+
+ *_fitoa_word (fd, __stpcpy (ret, "/proc/self/fd/"), 10, 0) = '\0';
+
+ /* We must make sure the file exists. */
+ if (__lxstat64 (_STAT_VER, ret, &st) < 0)
+ {
+ /* /proc is not mounted or something else happened. Don't
+ return the file name. */
+ free (ret);
+ ret = NULL;
+ }
+ }
+ return ret;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/fexecve.c b/libc/sysdeps/unix/sysv/linux/fexecve.c
new file mode 100644
index 000000000..50d2d779b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fexecve.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 1994, 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+
+/* Execute the file FD refers to, overlaying the running program image.
+ ARGV and ENVP are passed to the new program, as for `execve'. */
+int
+fexecve (fd, argv, envp)
+ int fd;
+ char *const argv[];
+ char *const envp[];
+{
+ if (fd < 0 || argv == NULL || envp == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* We use the /proc filesystem to get the information. If it is not
+ mounted we fail. */
+ char buf[sizeof "/proc/self/fd/" + sizeof (int) * 3];
+ __snprintf (buf, sizeof (buf), "/proc/self/fd/%d", fd);
+
+ /* We do not need the return value. */
+ __execve (buf, argv, envp);
+
+ int save = errno;
+
+ /* We come here only if the 'execve' call fails. Determine whether
+ /proc is mounted. If not we return ENOSYS. */
+ struct stat st;
+ if (stat ("/proc/self/fd", &st) != 0 && errno == ENOENT)
+ save = ENOSYS;
+
+ __set_errno (save);
+
+ return -1;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/fpathconf.c b/libc/sysdeps/unix/sysv/linux/fpathconf.c
new file mode 100644
index 000000000..c1cdb1b89
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fpathconf.c
@@ -0,0 +1,51 @@
+/* Get file-specific information about descriptor FD. Linux version.
+ Copyright (C) 1991,1995,1996,1998-2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include "pathconf.h"
+
+static long int posix_fpathconf (int fd, int name);
+
+/* Define this first, so it can be inlined. */
+#define __fpathconf static posix_fpathconf
+#include <sysdeps/posix/fpathconf.c>
+
+
+/* Get file-specific information about descriptor FD. */
+long int
+__fpathconf (fd, name)
+ int fd;
+ int name;
+{
+ struct statfs fsbuf;
+
+ switch (name)
+ {
+ case _PC_LINK_MAX:
+ return __statfs_link_max (__fstatfs (fd, &fsbuf), &fsbuf);
+
+ case _PC_FILESIZEBITS:
+ return __statfs_filesize_max (__fstatfs (fd, &fsbuf), &fsbuf);
+
+ case _PC_2_SYMLINKS:
+ return __statfs_symlinks (__fstatfs (fd, &fsbuf), &fsbuf);
+
+ default:
+ return posix_fpathconf (fd, name);
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/fstatfs64.c b/libc/sysdeps/unix/sysv/linux/fstatfs64.c
new file mode 100644
index 000000000..48afd1f4d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fstatfs64.c
@@ -0,0 +1,72 @@
+/* Return information about the filesystem on which FD resides.
+ Copyright (C) 1996,1997,1998,1999,2000,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <string.h>
+#include <sys/statfs.h>
+#include <stddef.h>
+#include <sysdep.h>
+
+/* Defined in statfs64.c. */
+extern int __no_statfs64 attribute_hidden;
+
+/* Return information about the filesystem on which FD resides. */
+int
+__fstatfs64 (int fd, struct statfs64 *buf)
+{
+#ifdef __NR_fstatfs64
+# if __ASSUME_STATFS64 == 0
+ if (! __no_statfs64)
+# endif
+ {
+ int result = INLINE_SYSCALL (fstatfs64, 3, fd, sizeof (*buf), buf);
+
+# if __ASSUME_STATFS64 == 0
+ if (result == 0 || errno != ENOSYS)
+# endif
+ return result;
+
+# if __ASSUME_STATFS64 == 0
+ __no_statfs64 = 1;
+# endif
+ }
+#endif
+
+#if __ASSUME_STATFS64 == 0
+ struct statfs buf32;
+
+ if (__fstatfs (fd, &buf32) < 0)
+ return -1;
+
+ buf->f_type = buf32.f_type;
+ buf->f_bsize = buf32.f_bsize;
+ buf->f_blocks = buf32.f_blocks;
+ buf->f_bfree = buf32.f_bfree;
+ buf->f_bavail = buf32.f_bavail;
+ buf->f_files = buf32.f_files;
+ buf->f_ffree = buf32.f_ffree;
+ buf->f_fsid = buf32.f_fsid;
+ buf->f_namelen = buf32.f_namelen;
+ buf->f_frsize = buf32.f_frsize;
+ memcpy (buf->f_spare, buf32.f_spare, sizeof (buf32.f_spare));
+
+ return 0;
+#endif
+}
+weak_alias (__fstatfs64, fstatfs64)
diff --git a/libc/sysdeps/unix/sysv/linux/fstatvfs.c b/libc/sysdeps/unix/sysv/linux/fstatvfs.c
new file mode 100644
index 000000000..0dd56c104
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fstatvfs.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 1998, 1999, 2000, 2002, 2003 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <sys/stat.h>
+#include <sys/statfs.h>
+#include <sys/statvfs.h>
+
+extern void __internal_statvfs (const char *name, struct statvfs *buf,
+ struct statfs *fsbuf, struct stat64 *st);
+
+
+int
+fstatvfs (int fd, struct statvfs *buf)
+{
+ struct statfs fsbuf;
+ struct stat64 st;
+
+ /* Get as much information as possible from the system. */
+ if (__fstatfs (fd, &fsbuf) < 0)
+ return -1;
+
+ /* Convert the result. */
+ __internal_statvfs (NULL, buf, &fsbuf, fstat64 (fd, &st) == -1 ? NULL : &st);
+
+ /* We signal success if the statfs call succeeded. */
+ return 0;
+}
+libc_hidden_def (fstatvfs)
diff --git a/libc/sysdeps/unix/sysv/linux/fstatvfs64.c b/libc/sysdeps/unix/sysv/linux/fstatvfs64.c
new file mode 100644
index 000000000..24c0a8fed
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fstatvfs64.c
@@ -0,0 +1,74 @@
+/* Return information about the filesystem on which FD resides.
+ Copyright (C) 1996,1997,1998,2000,2001,2004,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/statfs.h>
+#include <sys/statvfs.h>
+#include <kernel-features.h>
+
+
+extern void __internal_statvfs64 (const char *name, struct statvfs64 *buf,
+ struct statfs64 *fsbuf, struct stat64 *st);
+
+
+/* Return information about the filesystem on which FD resides. */
+int
+__fstatvfs64 (int fd, struct statvfs64 *buf)
+{
+ struct statfs64 fsbuf;
+ int res = __fstatfs64 (fd, &fsbuf);
+
+#ifndef __ASSUME_STATFS64
+ if (res < 0 && errno == ENOSYS)
+ {
+ struct statvfs buf32;
+
+ res = fstatvfs (fd, &buf32);
+ if (res == 0)
+ {
+ buf->f_bsize = buf32.f_bsize;
+ buf->f_frsize = buf32.f_frsize;
+ buf->f_blocks = buf32.f_blocks;
+ buf->f_bfree = buf32.f_bfree;
+ buf->f_bavail = buf32.f_bavail;
+ buf->f_files = buf32.f_files;
+ buf->f_ffree = buf32.f_ffree;
+ buf->f_favail = buf32.f_favail;
+ buf->f_fsid = buf32.f_fsid;
+ buf->f_flag = buf32.f_flag;
+ buf->f_namemax = buf32.f_namemax;
+ memcpy (buf->__f_spare, buf32.__f_spare, sizeof (buf32.__f_spare));
+ }
+ }
+#endif
+
+ if (res == 0)
+ {
+ /* Convert the result. */
+ struct stat64 st;
+ __internal_statvfs64 (NULL, buf, &fsbuf,
+ fstat64 (fd, &st) == -1 ? NULL : &st);
+ }
+
+ return res;
+}
+weak_alias (__fstatvfs64, fstatvfs64)
diff --git a/libc/sysdeps/unix/sysv/linux/ftime.c b/libc/sysdeps/unix/sysv/linux/ftime.c
new file mode 100644
index 000000000..5a5949f60
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ftime.c
@@ -0,0 +1,3 @@
+/* Linux defines the ftime system call but doesn't actually implement
+ it. Use the BSD implementation. */
+#include <sysdeps/unix/bsd/ftime.c>
diff --git a/libc/sysdeps/unix/sysv/linux/ftruncate64.c b/libc/sysdeps/unix/sysv/linux/ftruncate64.c
new file mode 100644
index 000000000..60e7ae0ac
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ftruncate64.c
@@ -0,0 +1,77 @@
+/* Copyright (C) 1997,1998,1999,2000,2001,2003,2005,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_ftruncate64
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+/* The variable is shared between all wrappers around *truncate64 calls. */
+extern int __have_no_truncate64;
+#endif
+
+
+/* Truncate the file FD refers to to LENGTH bytes. */
+int
+__ftruncate64 (int fd, off64_t length)
+{
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if (! __have_no_truncate64)
+#endif
+ {
+ unsigned int low = length & 0xffffffff;
+ unsigned int high = length >> 32;
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ int saved_errno = errno;
+#endif
+ int result = INLINE_SYSCALL (ftruncate64, 3, fd,
+ __LONG_LONG_PAIR (high, low));
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if (result != -1 || errno != ENOSYS)
+#endif
+ return result;
+
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ __set_errno (saved_errno);
+ __have_no_truncate64 = 1;
+#endif
+ }
+
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if ((off_t) length != length)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ return __ftruncate (fd, (off_t) length);
+#endif
+}
+weak_alias (__ftruncate64, ftruncate64)
+
+#else
+/* Use the generic implementation. */
+# include <misc/ftruncate64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/futimes.c b/libc/sysdeps/unix/sysv/linux/futimes.c
new file mode 100644
index 000000000..b307c3ff6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/futimes.c
@@ -0,0 +1,101 @@
+/* futimes -- change access and modification times of open file. Linux version.
+ Copyright (C) 2002,2003,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sysdep.h>
+#include <string.h>
+#include <utime.h>
+#include <sys/time.h>
+#include <stdio-common/_itoa.h>
+#include <fcntl.h>
+
+#include <kernel-features.h>
+
+/* Change the access time of FILE to TVP[0] and
+ the modification time of FILE to TVP[1], but do not follow symlinks.
+
+ The Linux kernel has no futimes() syscall so we use the /proc
+ filesystem. */
+int
+__futimes (int fd, const struct timeval tvp[2])
+{
+ static const char selffd[] = "/proc/self/fd/";
+ char fname[sizeof (selffd) + 3 * sizeof (int)];
+ fname[sizeof (fname) - 1] = '\0';
+ char *cp = _itoa_word ((unsigned int) fd, fname + sizeof (fname) - 1, 10, 0);
+ cp = memcpy (cp - sizeof (selffd) + 1, selffd, sizeof (selffd) - 1);
+
+ int result;
+#ifdef __NR_utimes
+ result = INLINE_SYSCALL (utimes, 2, cp, tvp);
+# ifndef __ASSUME_UTIMES
+ if (result == -1 && errno == ENOSYS)
+# endif
+#endif
+ {
+ /* The utimes() syscall does not exist or is not available in the
+ used kernel. Use utime(). For this we have to convert to the
+ data format utime() expects. */
+#ifndef __ASSUME_UTIMES
+ struct utimbuf buf;
+ struct utimbuf *times;
+
+ if (tvp != NULL)
+ {
+ times = &buf;
+ buf.actime = tvp[0].tv_sec + (tvp[0].tv_usec + 500000) / 1000000;
+ buf.modtime = tvp[1].tv_sec + (tvp[1].tv_usec + 500000) / 1000000;
+ }
+ else
+ times = NULL;
+
+ result = INLINE_SYSCALL (utime, 2, cp, times);
+#endif
+ }
+
+ if (result == -1)
+ /* Check for errors that result from failing to find /proc.
+ This means we can't do futimes at all, so return ENOSYS
+ rather than some confusing error. */
+ switch (errno)
+ {
+ case EACCES:
+ if (tvp == NULL) /* Could be a path problem or a file problem. */
+ break;
+ /*FALLTHROUGH*/
+ case ELOOP:
+ case ENAMETOOLONG:
+ case ENOTDIR:
+ __set_errno (ENOSYS);
+ break;
+
+ case ENOENT:
+ /* Validate the file descriptor by letting fcntl set errno to
+ EBADF if it's bogus. Otherwise it's a /proc issue. */
+#if !defined __NR_fcntl && defined __NR_fcntl64
+# define __NR_fcntl __NR_fcntl64
+#endif
+ if (INLINE_SYSCALL (fcntl, 3, fd, F_GETFD, 0) != -1)
+ __set_errno (ENOSYS);
+ break;
+ }
+
+ return result;
+}
+weak_alias (__futimes, futimes)
diff --git a/libc/sysdeps/unix/sysv/linux/futimesat.c b/libc/sysdeps/unix/sysv/linux/futimesat.c
new file mode 100644
index 000000000..7c96b7804
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/futimesat.c
@@ -0,0 +1,134 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <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 (fd, file, tvp)
+ int fd;
+ const char *file;
+ const struct timeval tvp[2];
+{
+ int result;
+
+#ifdef __NR_futimesat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ if (file == NULL)
+ return __futimes (fd, tvp);
+
+ result = INLINE_SYSCALL (futimesat, 3, fd, file, tvp);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ char *buf = NULL;
+
+ if (file == NULL)
+ {
+ static const char procfd[] = "/proc/self/fd/%d";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd);
+ file = buf;
+ }
+ else if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+# ifdef __NR_utimes
+ result = INTERNAL_SYSCALL (utimes, err, 2, file, tvp);
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return result;
+
+# ifndef __ASSUME_UTIMES
+ if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ goto fail;
+# endif
+# endif
+
+ /* The utimes() syscall does not exist or is not available in the
+ used kernel. Use utime(). For this we have to convert to the
+ data format utime() expects. */
+# ifndef __ASSUME_UTIMES
+ struct utimbuf tmp;
+ struct utimbuf *times;
+
+ if (tvp != NULL)
+ {
+ times = &tmp;
+ tmp.actime = tvp[0].tv_sec + tvp[0].tv_usec / 1000000;
+ tmp.modtime = tvp[1].tv_sec + tvp[1].tv_usec / 1000000;
+ }
+ else
+ times = NULL;
+
+ result = INTERNAL_SYSCALL (utime, err, 2, file, times);
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return result;
+
+ fail:
+# endif
+
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+
+ return -1;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/fxstat.c b/libc/sysdeps/unix/sysv/linux/fxstat.c
new file mode 100644
index 000000000..47c98158b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fxstat.c
@@ -0,0 +1,64 @@
+/* fxstat using old-style Unix fstat system call.
+ Copyright (C) 1991,1995-1998,2000,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, if xstat == xstat64 we must get rid of the prototype or gcc
+ will complain since they don't strictly match. */
+#define __fxstat64 __fxstat64_disable
+
+#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 <bp-checks.h>
+
+#include <xstatconv.h>
+
+/* Get information about the file FD in BUF. */
+int
+__fxstat (int vers, int fd, struct stat *buf)
+{
+ if (vers == _STAT_VER_KERNEL)
+ return INLINE_SYSCALL (fstat, 2, fd, CHECK_1 ((struct kernel_stat *) buf));
+
+#ifdef STAT_IS_KERNEL_STAT
+ errno = EINVAL;
+ return -1;
+#else
+ struct kernel_stat kbuf;
+ int result;
+
+ result = INLINE_SYSCALL (fstat, 2, fd, __ptrvalue (&kbuf));
+ if (result == 0)
+ result = __xstat_conv (vers, &kbuf, buf);
+
+ return result;
+#endif
+}
+
+hidden_def (__fxstat)
+weak_alias (__fxstat, _fxstat);
+#ifdef XSTAT_IS_XSTAT64
+#undef __fxstat64
+strong_alias (__fxstat, __fxstat64);
+hidden_ver (__fxstat, __fxstat64)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/fxstat64.c b/libc/sysdeps/unix/sysv/linux/fxstat64.c
new file mode 100644
index 000000000..6bc560152
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fxstat64.c
@@ -0,0 +1,94 @@
+/* fxstat64 using old-style Unix fstat system call.
+ Copyright (C) 1997-2002, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if __ASSUME_STAT64_SYSCALL == 0
+# include <xstatconv.h>
+#endif
+
+#ifdef __NR_fstat64
+# if __ASSUME_STAT64_SYSCALL == 0
+/* The variable is shared between all wrappers around *stat64 calls. */
+extern int __have_no_stat64;
+# endif
+#endif
+
+/* Get information about the file FD in BUF. */
+
+int
+___fxstat64 (int vers, int fd, struct stat64 *buf)
+{
+ int result;
+#if __ASSUME_STAT64_SYSCALL > 0
+ result = INLINE_SYSCALL (fstat64, 2, fd, CHECK_1 (buf));
+# if defined _HAVE_STAT64___ST_INO && __ASSUME_ST_INO_64_BIT == 0
+ if (__builtin_expect (!result, 1) && buf->__st_ino != (__ino_t) buf->st_ino)
+ buf->st_ino = buf->__st_ino;
+# endif
+ return result;
+#else
+ struct kernel_stat kbuf;
+# if defined __NR_fstat64
+ if (! __have_no_stat64)
+ {
+ int saved_errno = errno;
+ result = INLINE_SYSCALL (fstat64, 2, fd, CHECK_1 (buf));
+
+ if (result != -1 || errno != ENOSYS)
+ {
+# if defined _HAVE_STAT64___ST_INO && __ASSUME_ST_INO_64_BIT == 0
+ if (!result && buf->__st_ino != (__ino_t)buf->st_ino)
+ buf->st_ino = buf->__st_ino;
+# endif
+ return result;
+ }
+
+ __set_errno (saved_errno);
+ __have_no_stat64 = 1;
+ }
+# endif
+ result = INLINE_SYSCALL (fstat, 2, fd, __ptrvalue (&kbuf));
+ if (result == 0)
+ result = __xstat64_conv (vers, &kbuf, buf);
+
+ return result;
+#endif
+}
+
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+versioned_symbol (libc, ___fxstat64, __fxstat64, GLIBC_2_2);
+strong_alias (___fxstat64, __old__fxstat64)
+compat_symbol (libc, __old__fxstat64, __fxstat64, GLIBC_2_1);
+hidden_ver (___fxstat64, __fxstat64)
+#else
+strong_alias (___fxstat64, __fxstat64)
+hidden_def (__fxstat64)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/fxstatat.c b/libc/sysdeps/unix/sysv/linux/fxstatat.c
new file mode 100644
index 000000000..c1c416abd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fxstatat.c
@@ -0,0 +1,141 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, if fxstatat == fxstatat64 we must get rid of the prototype or gcc
+ will complain since they don't strictly match. */
+#define __fxstatat64 __fxstatat64_disable
+
+#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 <bp-checks.h>
+
+#include <xstatconv.h>
+
+/* Get information about the file NAME in BUF. */
+int
+__fxstatat (int vers, int fd, const char *file, struct stat *st, int flag)
+{
+ int result;
+ INTERNAL_SYSCALL_DECL (err);
+#ifdef STAT_IS_KERNEL_STAT
+# define kst (*st)
+#else
+ struct kernel_stat kst;
+#endif
+
+#ifdef __NR_newfstatat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INTERNAL_SYSCALL (newfstatat, err, 4, fd, file, &kst, flag);
+# ifndef __ASSUME_ATFCTS
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1)
+ && INTERNAL_SYSCALL_ERRNO (result, err) == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ if (!__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ {
+#ifdef STAT_IS_KERNEL_STAT
+ return 0;
+#else
+ return __xstat_conv (vers, &kst, st);
+#endif
+ }
+ else
+ {
+ __set_errno (INTERNAL_SYSCALL_ERRNO (result, err));
+ return -1;
+ }
+ }
+#endif
+
+ if (flag & ~AT_SYMLINK_NOFOLLOW)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ if (vers == _STAT_VER_KERNEL)
+ {
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lstat, err, 2, CHECK_STRING (file),
+ CHECK_1 ((struct kernel_stat *) st));
+ else
+ result = INTERNAL_SYSCALL (stat, err, 2, CHECK_STRING (file),
+ CHECK_1 ((struct kernel_stat *) st));
+
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return result;
+ }
+#ifdef STAT_IS_KERNEL_STAT
+ else
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+#else
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lstat, err, 2, CHECK_STRING (file),
+ __ptrvalue (&kst));
+ else
+ result = INTERNAL_SYSCALL (stat, err, 2, CHECK_STRING (file),
+ __ptrvalue (&kst));
+
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return __xstat_conv (vers, &kst, st);
+#endif
+
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+
+ return -1;
+}
+libc_hidden_def (__fxstatat)
+#ifdef XSTAT_IS_XSTAT64
+# undef __fxstatat64
+strong_alias (__fxstatat, __fxstatat64);
+libc_hidden_def (__fxstatat64)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/fxstatat64.c b/libc/sysdeps/unix/sysv/linux/fxstatat64.c
new file mode 100644
index 000000000..cb932b8e5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/fxstatat64.c
@@ -0,0 +1,167 @@
+/* Copyright (C) 2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if __ASSUME_STAT64_SYSCALL == 0
+# include <xstatconv.h>
+#endif
+
+#ifdef __NR_stat64
+# if __ASSUME_STAT64_SYSCALL == 0
+/* The variable is shared between all wrappers around *stat64 calls.
+ This is the definition. */
+extern int __have_no_stat64;
+# endif
+#endif
+
+/* Get information about the file NAME in BUF. */
+
+int
+__fxstatat64 (int vers, int fd, const char *file, struct stat64 *st, int flag)
+{
+ if (__builtin_expect (vers != _STAT_VER_LINUX, 0))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ int result;
+ INTERNAL_SYSCALL_DECL (err);
+
+#ifdef __NR_fstatat64
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INTERNAL_SYSCALL (fstatat64, err, 4, fd, file, st, flag);
+# ifndef __ASSUME_ATFCTS
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1)
+ && INTERNAL_SYSCALL_ERRNO (result, err) == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ if (!__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return 0;
+ else
+ {
+ __set_errno (INTERNAL_SYSCALL_ERRNO (result, err));
+ return -1;
+ }
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ if (flag & ~AT_SYMLINK_NOFOLLOW)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+# if __ASSUME_STAT64_SYSCALL > 0
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lstat64, err, 2, CHECK_STRING (file),
+ CHECK_1 (st));
+ else
+ result = INTERNAL_SYSCALL (stat64, err, 2, CHECK_STRING (file),
+ CHECK_1 (st));
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ {
+# if defined _HAVE_STAT64___ST_INO && __ASSUME_ST_INO_64_BIT == 0
+ if (st->__st_ino != (__ino_t) st->st_ino)
+ st->st_ino = st->__st_ino;
+# endif
+ return result;
+ }
+# else
+ struct kernel_stat kst;
+# ifdef __NR_stat64
+ if (! __have_no_stat64)
+ {
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lstat64, err, 2, CHECK_STRING (file),
+ CHECK_1 (st));
+ else
+ result = INTERNAL_SYSCALL (stat64, err, 2, CHECK_STRING (file),
+ CHECK_1 (st));
+
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ {
+# if defined _HAVE_STAT64___ST_INO && __ASSUME_ST_INO_64_BIT == 0
+ if (st->__st_ino != (__ino_t) st->st_ino)
+ st->st_ino = st->__st_ino;
+# endif
+ return result;
+ }
+ if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ goto fail;
+
+ __have_no_stat64 = 1;
+ }
+# endif
+
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lstat, err, 2, CHECK_STRING (file),
+ __ptrvalue (&kst));
+ else
+ result = INTERNAL_SYSCALL (stat, err, 2, CHECK_STRING (file),
+ __ptrvalue (&kst));
+
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return __xstat64_conv (vers, &kst, st);
+
+ fail:
+# endif
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+
+ return -1;
+#endif
+}
+libc_hidden_def (__fxstatat64)
diff --git a/libc/sysdeps/unix/sysv/linux/gai_sigqueue.c b/libc/sysdeps/unix/sysv/linux/gai_sigqueue.c
new file mode 100644
index 000000000..0c6654a38
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/gai_sigqueue.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <netdb.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include "gai_misc.h"
+
+#ifdef __NR_rt_sigqueueinfo
+
+/* Return any pending signal or wait for one for the given time. */
+int
+__gai_sigqueue (sig, val, caller_pid)
+ int sig;
+ const union sigval val;
+ pid_t caller_pid;
+{
+ siginfo_t info;
+
+ /* First, clear the siginfo_t structure, so that we don't pass our
+ stack content to other tasks. */
+ memset (&info, 0, sizeof (siginfo_t));
+ /* We must pass the information about the data in a siginfo_t value. */
+ info.si_signo = sig;
+ info.si_code = SI_ASYNCNL;
+ info.si_pid = caller_pid;
+ info.si_uid = __getuid ();
+ info.si_value = val;
+
+ return INLINE_SYSCALL (rt_sigqueueinfo, 3, info.si_pid,
+ sig, __ptrvalue (&info));
+}
+#else
+# include <resolv/gai_sigqueue.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/getclktck.c b/libc/sysdeps/unix/sysv/linux/getclktck.c
new file mode 100644
index 000000000..f9fece32f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getclktck.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <time.h>
+
+#include <ldsodefs.h>
+
+#ifndef SYSTEM_CLK_TCK
+# define SYSTEM_CLK_TCK 100
+#endif
+
+/* Return frequency of times(). */
+int
+__getclktck ()
+{
+ return GLRO(dl_clktck) ?: SYSTEM_CLK_TCK;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/getcwd.c b/libc/sysdeps/unix/sysv/linux/getcwd.c
new file mode 100644
index 000000000..911d85f43
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getcwd.c
@@ -0,0 +1,222 @@
+/* Determine current working directory. Linux version.
+ Copyright (C) 1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+
+/* If we compile the file for use in ld.so we don't need the feature
+ that getcwd() allocates the buffers itself. */
+#ifdef IS_IN_rtld
+# define NO_ALLOCATION 1
+#endif
+
+
+#if __ASSUME_GETCWD_SYSCALL > 0
+/* Kernel 2.1.92 introduced a third way to get the current working
+ directory: a syscall. We've got to be careful that even when
+ compiling under 2.1.92+ the libc still runs under older kernels. */
+# define no_syscall_getcwd 0
+# define have_new_dcache 1
+/* This is a trick since we don't define generic_getcwd. */
+# define generic_getcwd getcwd
+#else
+/* The "proc" filesystem provides an easy method to retrieve the value.
+ For each process, the corresponding directory contains a symbolic link
+ named `cwd'. Reading the content of this link immediate gives us the
+ information. But we have to take care for systems which do not have
+ the proc filesystem mounted. Use the POSIX implementation in this case. */
+static char *generic_getcwd (char *buf, size_t size) internal_function;
+
+# if __NR_getcwd
+/* Kernel 2.1.92 introduced a third way to get the current working
+ directory: a syscall. We've got to be careful that even when
+ compiling under 2.1.92+ the libc still runs under older kernels. */
+static int no_syscall_getcwd;
+static int have_new_dcache;
+# else
+# define no_syscall_getcwd 1
+static int have_new_dcache = 1;
+# endif
+#endif
+
+char *
+__getcwd (char *buf, size_t size)
+{
+ char *path;
+ int n;
+ char *result;
+
+ if (no_syscall_getcwd && !have_new_dcache)
+ return generic_getcwd (buf, size);
+
+#ifndef NO_ALLOCATION
+ size_t alloc_size = size;
+ if (size == 0)
+ {
+ if (buf != NULL)
+ {
+ __set_errno (EINVAL);
+ return NULL;
+ }
+
+ alloc_size = MAX (PATH_MAX, __getpagesize ());
+ }
+
+ if (buf == NULL)
+ {
+ path = malloc (alloc_size);
+ if (path == NULL)
+ return NULL;
+ }
+ else
+#else
+# define alloc_size size
+#endif
+ path = buf;
+
+#if defined __NR_getcwd || __LINUX_GETCWD_SYSCALL > 0
+ if (!no_syscall_getcwd)
+ {
+ int retval;
+
+ retval = INLINE_SYSCALL (getcwd, 2, CHECK_STRING (path), alloc_size);
+ if (retval >= 0)
+ {
+# ifndef NO_ALLOCATION
+ if (buf == NULL && size == 0)
+ /* Ensure that the buffer is only as large as necessary. */
+ buf = realloc (path, (size_t) retval);
+
+ if (buf == NULL)
+ /* Either buf was NULL all along, or `realloc' failed but
+ we still have the original string. */
+ buf = path;
+# endif
+
+ return buf;
+ }
+
+# if __ASSUME_GETCWD_SYSCALL
+ /* It should never happen that the `getcwd' syscall failed because
+ the buffer is too small if we allocated the buffer ourselves
+ large enough. */
+ assert (errno != ERANGE || buf != NULL || size != 0);
+
+# ifndef NO_ALLOCATION
+ if (buf == NULL)
+ free (path);
+# endif
+
+ return NULL;
+# else
+ if (errno == ENOSYS)
+ {
+ no_syscall_getcwd = 1;
+ have_new_dcache = 1; /* Now we will try the /proc method. */
+ }
+ else if (errno != ERANGE || buf != NULL)
+ {
+# ifndef NO_ALLOCATION
+ if (buf == NULL)
+ free (path);
+# endif
+ return NULL;
+ }
+# endif
+ }
+#endif
+
+ n = __readlink ("/proc/self/cwd", path, alloc_size - 1);
+ if (n != -1)
+ {
+ if (path[0] == '/')
+ {
+ if ((size_t) n >= alloc_size - 1)
+ {
+#ifndef NO_ALLOCATION
+ if (buf == NULL)
+ free (path);
+#endif
+ return NULL;
+ }
+
+ path[n] = '\0';
+#ifndef NO_ALLOCATION
+ if (buf == NULL && size == 0)
+ /* Ensure that the buffer is only as large as necessary. */
+ buf = realloc (path, (size_t) n + 1);
+ if (buf == NULL)
+ /* Either buf was NULL all along, or `realloc' failed but
+ we still have the original string. */
+ buf = path;
+#endif
+
+ return buf;
+ }
+#ifndef have_new_dcache
+ else
+ have_new_dcache = 0;
+#endif
+ }
+
+#if __ASSUME_GETCWD_SYSCALL == 0
+ /* Set to have_new_dcache only if error indicates that proc doesn't
+ exist. */
+ if (errno != EACCES && errno != ENAMETOOLONG)
+ have_new_dcache = 0;
+#endif
+
+#ifndef NO_ALLOCATION
+ /* Don't put restrictions on the length of the path unless the user does. */
+ if (size == 0)
+ {
+ free (path);
+ path = NULL;
+ }
+#endif
+
+ result = generic_getcwd (path, size);
+
+#ifndef NO_ALLOCATION
+ if (result == NULL && buf == NULL && size != 0)
+ free (path);
+#endif
+
+ return result;
+}
+weak_alias (__getcwd, getcwd)
+
+#if __ASSUME_GETCWD_SYSCALL == 0
+/* Get the code for the generic version. */
+# define GETCWD_RETURN_TYPE static char * internal_function
+# define __getcwd generic_getcwd
+# include <sysdeps/posix/getcwd.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/getdents.c b/libc/sysdeps/unix/sysv/linux/getdents.c
new file mode 100644
index 000000000..836cbf392
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getdents.c
@@ -0,0 +1,299 @@
+/* Copyright (C) 1993, 1995-2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <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>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_getdents64
+# ifndef __ASSUME_GETDENTS64_SYSCALL
+# ifndef __GETDENTS
+/* The variable is shared between all *getdents* calls. */
+int __have_no_getdents64 attribute_hidden;
+# else
+extern int __have_no_getdents64 attribute_hidden;
+# endif
+# define have_no_getdents64_defined 1
+# endif
+#endif
+#ifndef have_no_getdents64_defined
+# define __have_no_getdents64 0
+#endif
+
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+
+/* For Linux we need a special version of this file since the
+ definition of `struct dirent' is not the same for the kernel and
+ the libc. There is one additional field which might be introduced
+ in the kernel structure in the future.
+
+ Here is the kernel definition of `struct dirent' as of 2.1.20: */
+
+struct kernel_dirent
+ {
+ long int d_ino;
+ __kernel_off_t d_off;
+ unsigned short int d_reclen;
+ char d_name[256];
+ };
+
+struct kernel_dirent64
+ {
+ uint64_t d_ino;
+ int64_t d_off;
+ unsigned short int d_reclen;
+ unsigned char d_type;
+ char d_name[256];
+ };
+
+#ifndef __GETDENTS
+# define __GETDENTS __getdents
+#endif
+#ifndef DIRENT_TYPE
+# define DIRENT_TYPE struct dirent
+#endif
+#ifndef DIRENT_SET_DP_INO
+# define DIRENT_SET_DP_INO(dp, value) (dp)->d_ino = (value)
+#endif
+
+/* The problem here is that we cannot simply read the next NBYTES
+ bytes. We need to take the additional field into account. We use
+ some heuristic. Assuming the directory contains names with 14
+ characters on average we can compute an estimated number of entries
+ which fit in the buffer. Taking this number allows us to specify a
+ reasonable number of bytes to read. If we should be wrong, we can
+ reset the file descriptor. In practice the kernel is limiting the
+ amount of data returned much more then the reduced buffer size. */
+ssize_t
+internal_function
+__GETDENTS (int fd, char *buf, size_t nbytes)
+{
+ ssize_t retval;
+
+#ifdef __ASSUME_GETDENTS32_D_TYPE
+ if (sizeof (DIRENT_TYPE) == sizeof (struct dirent))
+ {
+ retval = INLINE_SYSCALL (getdents, 3, fd, CHECK_N(buf, nbytes), nbytes);
+
+ /* The kernel added the d_type value after the name. Change
+ this now. */
+ if (retval != -1)
+ {
+ union
+ {
+ struct kernel_dirent k;
+ struct dirent u;
+ } *kbuf = (void *) buf;
+
+ while ((char *) kbuf < buf + retval)
+ {
+ char d_type = *((char *) kbuf + kbuf->k.d_reclen - 1);
+ memmove (kbuf->u.d_name, kbuf->k.d_name,
+ strlen (kbuf->k.d_name) + 1);
+ kbuf->u.d_type = d_type;
+
+ kbuf = (void *) ((char *) kbuf + kbuf->k.d_reclen);
+ }
+ }
+
+ return retval;
+ }
+#endif
+
+ off64_t last_offset = -1;
+
+#ifdef __NR_getdents64
+ if (!__have_no_getdents64)
+ {
+# ifndef __ASSUME_GETDENTS64_SYSCALL
+ int saved_errno = errno;
+# endif
+ union
+ {
+ struct kernel_dirent64 k;
+ DIRENT_TYPE u;
+ char b[1];
+ } *kbuf = (void *) buf, *outp, *inp;
+ size_t kbytes = nbytes;
+ if (offsetof (DIRENT_TYPE, d_name)
+ < offsetof (struct kernel_dirent64, d_name)
+ && nbytes <= sizeof (DIRENT_TYPE))
+ {
+ kbytes = nbytes + offsetof (struct kernel_dirent64, d_name)
+ - offsetof (DIRENT_TYPE, d_name);
+ kbuf = __alloca(kbytes);
+ }
+ retval = INLINE_SYSCALL (getdents64, 3, fd, CHECK_N(kbuf, kbytes),
+ kbytes);
+# ifndef __ASSUME_GETDENTS64_SYSCALL
+ if (retval != -1 || (errno != EINVAL && errno != ENOSYS))
+# endif
+ {
+ const size_t size_diff = (offsetof (struct kernel_dirent64, d_name)
+ - offsetof (DIRENT_TYPE, d_name));
+
+ /* Return the error if encountered. */
+ if (retval == -1)
+ return -1;
+
+ /* If the structure returned by the kernel is identical to what we
+ need, don't do any conversions. */
+ if (offsetof (DIRENT_TYPE, d_name)
+ == offsetof (struct kernel_dirent64, d_name)
+ && sizeof (outp->u.d_ino) == sizeof (inp->k.d_ino)
+ && sizeof (outp->u.d_off) == sizeof (inp->k.d_off))
+ return retval;
+
+ /* 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__ (DIRENT_TYPE);
+ /* 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 kernel_dirent64, d_name));
+
+ /* Now we have copied the data from INP and access only OUTP. */
+
+ DIRENT_SET_DP_INO (&outp->u, 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;
+ }
+
+# ifndef __ASSUME_GETDENTS64_SYSCALL
+ __set_errno (saved_errno);
+ __have_no_getdents64 = 1;
+# endif
+ }
+#endif
+ {
+ size_t red_nbytes;
+ struct kernel_dirent *skdp, *kdp;
+ const size_t size_diff = (offsetof (DIRENT_TYPE, d_name)
+ - offsetof (struct kernel_dirent, d_name));
+
+ red_nbytes = MIN (nbytes
+ - ((nbytes / (offsetof (DIRENT_TYPE, d_name) + 14))
+ * size_diff),
+ nbytes - size_diff);
+
+ skdp = kdp = __alloca (red_nbytes);
+
+ retval = INLINE_SYSCALL (getdents, 3, fd,
+ CHECK_N ((char *) kdp, red_nbytes), red_nbytes);
+
+ if (retval == -1)
+ return -1;
+
+ DIRENT_TYPE *dp = (DIRENT_TYPE *) buf;
+ while ((char *) kdp < (char *) skdp + retval)
+ {
+ const size_t alignment = __alignof__ (DIRENT_TYPE);
+ /* Since kdp->d_reclen is already aligned for the kernel structure
+ this may compute a value that is bigger than necessary. */
+ size_t new_reclen = ((kdp->d_reclen + size_diff + alignment - 1)
+ & ~(alignment - 1));
+ if ((char *) dp + new_reclen > buf + nbytes)
+ {
+ /* Our heuristic failed. We read too many entries. Reset
+ the stream. */
+ assert (last_offset != -1);
+ __lseek64 (fd, last_offset, SEEK_SET);
+
+ if ((char *) dp == buf)
+ {
+ /* The buffer the user passed in is too small to hold even
+ one entry. */
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ break;
+ }
+
+ last_offset = kdp->d_off;
+ DIRENT_SET_DP_INO(dp, kdp->d_ino);
+ dp->d_off = kdp->d_off;
+ dp->d_reclen = new_reclen;
+ dp->d_type = DT_UNKNOWN;
+ memcpy (dp->d_name, kdp->d_name,
+ kdp->d_reclen - offsetof (struct kernel_dirent, d_name));
+
+ dp = (DIRENT_TYPE *) ((char *) dp + new_reclen);
+ kdp = (struct kernel_dirent *) (((char *) kdp) + kdp->d_reclen);
+ }
+
+ return (char *) dp - buf;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/getdents64.c b/libc/sysdeps/unix/sysv/linux/getdents64.c
new file mode 100644
index 000000000..805917e27
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getdents64.c
@@ -0,0 +1,3 @@
+#define __GETDENTS __getdents64
+#define DIRENT_TYPE struct dirent64
+#include <sysdeps/unix/sysv/linux/getdents.c>
diff --git a/libc/sysdeps/unix/sysv/linux/getdirentries.c b/libc/sysdeps/unix/sysv/linux/getdirentries.c
new file mode 100644
index 000000000..73dabdb19
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getdirentries.c
@@ -0,0 +1,42 @@
+/* Copyright (C) 1993, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <dirent.h>
+#include <unistd.h>
+
+#ifndef GETDIRENTRIES
+# define GETDIRENTRIES getdirentries
+# define __GETDENTS __getdents
+#else
+# define off_t off64_t
+# define __lseek __lseek64
+#endif
+
+ssize_t
+GETDIRENTRIES (int fd, char *buf, size_t nbytes, off_t *basep)
+{
+ off_t base = __lseek (fd, (off_t) 0, SEEK_CUR);
+ ssize_t result;
+
+ result = __GETDENTS (fd, buf, nbytes);
+
+ if (result != -1)
+ *basep = base;
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/getdirentries64.c b/libc/sysdeps/unix/sysv/linux/getdirentries64.c
new file mode 100644
index 000000000..e486a36a1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getdirentries64.c
@@ -0,0 +1,3 @@
+#define GETDIRENTRIES getdirentries64
+#define __GETDENTS __getdents64
+#include "getdirentries.c"
diff --git a/libc/sysdeps/unix/sysv/linux/getdtsz.c b/libc/sysdeps/unix/sysv/linux/getdtsz.c
new file mode 100644
index 000000000..1dcfa6dde
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getdtsz.c
@@ -0,0 +1,22 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This comes from the Linux kernel header. */
+#define OPEN_MAX 256
+
+#include <sysdeps/posix/getdtsz.c>
diff --git a/libc/sysdeps/unix/sysv/linux/gethostid.c b/libc/sysdeps/unix/sysv/linux/gethostid.c
new file mode 100644
index 000000000..de98fb3d7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/gethostid.c
@@ -0,0 +1,121 @@
+/* Copyright (C) 1995,1996,1998-2001,2003,2004,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <alloca.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <netdb.h>
+#include <not-cancel.h>
+
+#define HOSTIDFILE "/etc/hostid"
+
+#ifdef SET_PROCEDURE
+int
+sethostid (id)
+ long int id;
+{
+ int fd;
+ ssize_t written;
+ int32_t id32 = id;
+
+ /* Test for appropriate rights to set host ID. */
+ if (__libc_enable_secure)
+ {
+ __set_errno (EPERM);
+ return -1;
+ }
+
+ /* Make sure the ID is not too large. Needed for bi-arch support. */
+ if (id32 != id)
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+
+ /* Open file for writing. Everybody is allowed to read this file. */
+ fd = open_not_cancel (HOSTIDFILE, O_CREAT|O_WRONLY|O_TRUNC, 0644);
+ if (fd < 0)
+ return -1;
+
+ written = write_not_cancel (fd, &id32, sizeof (id32));
+
+ close_not_cancel_no_status (fd);
+
+ return written != sizeof (id32) ? -1 : 0;
+}
+
+#else
+# include <string.h>
+# include <sys/param.h>
+# include <resolv/netdb.h>
+# include <netinet/in.h>
+
+long int
+gethostid ()
+{
+ char hostname[MAXHOSTNAMELEN + 1];
+ size_t buflen;
+ char *buffer;
+ struct hostent hostbuf, *hp;
+ int32_t id;
+ struct in_addr in;
+ int herr;
+ int fd;
+
+ /* First try to get the ID from a former invocation of sethostid. */
+ fd = open_not_cancel (HOSTIDFILE, O_RDONLY|O_LARGEFILE, 0);
+ if (fd >= 0)
+ {
+ ssize_t n = read_not_cancel (fd, &id, sizeof (id));
+
+ close_not_cancel_no_status (fd);
+
+ if (n == sizeof (id))
+ return id;
+ }
+
+ /* Getting from the file was not successful. An intelligent guess for
+ a unique number of a host is its IP address. Return this. */
+ if (__gethostname (hostname, MAXHOSTNAMELEN) < 0 || hostname[0] == '\0')
+ /* This also fails. Return and arbitrary value. */
+ return 0;
+
+ buflen = 1024;
+ buffer = __alloca (buflen);
+
+ /* To get the IP address we need to know the host name. */
+ while (__gethostbyname_r (hostname, &hostbuf, buffer, buflen, &hp, &herr)
+ != 0
+ || hp == NULL)
+ if (herr != NETDB_INTERNAL || errno != ERANGE)
+ return 0;
+ else
+ /* Enlarge buffer. */
+ buffer = extend_alloca (buffer, buflen, 2 * buflen);
+
+ in.s_addr = 0;
+ memcpy (&in, hp->h_addr,
+ (int) sizeof (in) < hp->h_length ? (int) sizeof (in) : hp->h_length);
+
+ /* For the return value to be not exactly the IP address we do some
+ bit fiddling. */
+ return (int32_t) (in.s_addr << 16 | in.s_addr >> 16);
+}
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/getipv4sourcefilter.c b/libc/sysdeps/unix/sysv/linux/getipv4sourcefilter.c
new file mode 100644
index 000000000..1a4e16cdb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getipv4sourcefilter.c
@@ -0,0 +1,73 @@
+/* Get IPv4 source filter. Linux version.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <alloca.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+
+
+int
+getipv4sourcefilter (int s, struct in_addr interface, struct in_addr group,
+ uint32_t *fmode, uint32_t *numsrc, struct in_addr *slist)
+{
+ /* We have to create an struct ip_msfilter object which we can pass
+ to the kernel. */
+ socklen_t needed = IP_MSFILTER_SIZE (*numsrc);
+ int use_alloca = __libc_use_alloca (needed);
+
+ struct ip_msfilter *imsf;
+ if (use_alloca)
+ imsf = (struct ip_msfilter *) alloca (needed);
+ else
+ {
+ imsf = (struct ip_msfilter *) malloc (needed);
+ if (imsf == NULL)
+ return -1;
+ }
+
+ imsf->imsf_multiaddr = group;
+ imsf->imsf_interface = interface;
+ imsf->imsf_numsrc = *numsrc;
+
+ int result = __getsockopt (s, SOL_IP, IP_MSFILTER, imsf, &needed);
+
+ /* If successful, copy the results to the places the caller wants
+ them in. */
+ if (result == 0)
+ {
+ *fmode = imsf->imsf_fmode;
+ memcpy (slist, imsf->imsf_slist,
+ MIN (*numsrc, imsf->imsf_numsrc) * sizeof (struct in_addr));
+ *numsrc = imsf->imsf_numsrc;
+ }
+
+ if (! use_alloca)
+ {
+ int save_errno = errno;
+ free (imsf);
+ __set_errno (save_errno);
+ }
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/getloadavg.c b/libc/sysdeps/unix/sysv/linux/getloadavg.c
new file mode 100644
index 000000000..81a1c0dd5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getloadavg.c
@@ -0,0 +1,69 @@
+/* Get system load averages. Linux (/proc/loadavg) version.
+ Copyright (C) 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <locale.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <not-cancel.h>
+
+/* Put the 1 minute, 5 minute and 15 minute load averages
+ into the first NELEM elements of LOADAVG.
+ Return the number written (never more than 3, but may be less than NELEM),
+ or -1 if an error occurred. */
+
+int
+getloadavg (double loadavg[], int nelem)
+{
+ int fd;
+
+ fd = open_not_cancel_2 ("/proc/loadavg", O_RDONLY);
+ if (fd < 0)
+ return -1;
+ else
+ {
+ char buf[65], *p;
+ ssize_t nread;
+ int i;
+
+ nread = read_not_cancel (fd, buf, sizeof buf - 1);
+ close_not_cancel_no_status (fd);
+ if (nread <= 0)
+ return -1;
+ buf[nread - 1] = '\0';
+
+ if (nelem > 3)
+ nelem = 3;
+ p = buf;
+ for (i = 0; i < nelem; ++i)
+ {
+ char *endp;
+ loadavg[i] = __strtod_l (p, &endp, _nl_C_locobj_ptr);
+ if (endp == p)
+ /* This should not happen. The format of /proc/loadavg
+ must have changed. Don't return with what we have,
+ signal an error. */
+ return -1;
+ p = endp;
+ }
+
+ return i;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/getpagesize.c b/libc/sysdeps/unix/sysv/linux/getpagesize.c
new file mode 100644
index 000000000..6d03b3bbf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getpagesize.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 1991,1992,1995-1997,2000,2002,2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <unistd.h>
+#include <sys/param.h>
+
+#include <ldsodefs.h>
+
+/* Return the system page size. */
+int
+__getpagesize ()
+{
+ if (GLRO(dl_pagesize) != 0)
+ return GLRO(dl_pagesize);
+
+#ifdef EXEC_PAGESIZE
+ return EXEC_PAGESIZE;
+#else /* No EXEC_PAGESIZE. */
+#ifdef NBPG
+#ifndef CLSIZE
+#define CLSIZE 1
+#endif /* No CLSIZE. */
+ return NBPG * CLSIZE;
+#else /* No NBPG. */
+ return NBPC;
+#endif /* NBPG. */
+#endif /* EXEC_PAGESIZE. */
+}
+libc_hidden_def (__getpagesize)
+weak_alias (__getpagesize, getpagesize)
diff --git a/libc/sysdeps/unix/sysv/linux/getpeername.S b/libc/sysdeps/unix/sysv/linux/getpeername.S
new file mode 100644
index 000000000..a6d8e86d4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getpeername.S
@@ -0,0 +1,3 @@
+#define socket getpeername
+#define NARGS 3
+#include <socket.S>
diff --git a/libc/sysdeps/unix/sysv/linux/getpriority.c b/libc/sysdeps/unix/sysv/linux/getpriority.c
new file mode 100644
index 000000000..23da8495f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getpriority.c
@@ -0,0 +1,45 @@
+/* getpriority for Linux.
+ Copyright (C) 1996,98,2000,02,03 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/resource.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* The return value of getpriority syscall is biased by this value
+ to avoid returning negative values. */
+#define PZERO 20
+
+/* Return the highest priority of any process specified by WHICH and WHO
+ (see above); if WHO is zero, the current process, process group, or user
+ (as specified by WHO) is used. A lower priority number means higher
+ priority. Priorities range from PRIO_MIN to PRIO_MAX. */
+
+int
+getpriority (enum __priority_which which, id_t who)
+{
+ int res;
+
+ res = INLINE_SYSCALL (getpriority, 2, (int) which, who);
+ if (res >= 0)
+ res = PZERO - res;
+ return res;
+}
+libc_hidden_def (getpriority)
diff --git a/libc/sysdeps/unix/sysv/linux/getpt.c b/libc/sysdeps/unix/sysv/linux/getpt.c
new file mode 100644
index 000000000..bb1ea4764
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getpt.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <paths.h>
+#include <sys/statfs.h>
+
+#include "linux_fsinfo.h"
+
+/* Path to the master pseudo terminal cloning device. */
+#define _PATH_DEVPTMX _PATH_DEV "ptmx"
+/* Directory containing the UNIX98 pseudo terminals. */
+#define _PATH_DEVPTS _PATH_DEV "pts"
+
+/* Prototype for function that opens BSD-style master pseudo-terminals. */
+int __bsd_getpt (void);
+
+/* Open a master pseudo terminal and return its file descriptor. */
+int
+__posix_openpt (oflag)
+ int oflag;
+{
+ static int have_no_dev_ptmx;
+ int fd;
+
+ if (!have_no_dev_ptmx)
+ {
+ fd = __open (_PATH_DEVPTMX, oflag);
+ if (fd != -1)
+ {
+ struct statfs fsbuf;
+ static int devpts_mounted;
+
+ /* Check that the /dev/pts filesystem is mounted
+ or if /dev is a devfs filesystem (this implies /dev/pts). */
+ if (devpts_mounted
+ || (__statfs (_PATH_DEVPTS, &fsbuf) == 0
+ && fsbuf.f_type == DEVPTS_SUPER_MAGIC)
+ || (__statfs (_PATH_DEV, &fsbuf) == 0
+ && fsbuf.f_type == DEVFS_SUPER_MAGIC))
+ {
+ /* Everything is ok. */
+ devpts_mounted = 1;
+ return fd;
+ }
+
+ /* If /dev/pts is not mounted then the UNIX98 pseudo terminals
+ are not usable. */
+ __close (fd);
+ have_no_dev_ptmx = 1;
+ }
+ else
+ {
+ if (errno == ENOENT || errno == ENODEV)
+ have_no_dev_ptmx = 1;
+ else
+ return -1;
+ }
+ }
+
+ return -1;
+}
+weak_alias (__posix_openpt, posix_openpt)
+
+
+int
+__getpt (void)
+{
+ int fd = __posix_openpt (O_RDWR);
+ if (fd == -1)
+ fd = __bsd_getpt ();
+ return fd;
+}
+
+
+#define PTYNAME1 "pqrstuvwxyzabcde";
+#define PTYNAME2 "0123456789abcdef";
+
+#define __getpt __bsd_getpt
+#define HAVE_POSIX_OPENPT
+#include <sysdeps/unix/bsd/getpt.c>
diff --git a/libc/sysdeps/unix/sysv/linux/getsockname.S b/libc/sysdeps/unix/sysv/linux/getsockname.S
new file mode 100644
index 000000000..9ea371ff6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getsockname.S
@@ -0,0 +1,5 @@
+#define socket getsockname
+#define NARGS 3
+#define NO_WEAK_ALIAS 1
+#include <socket.S>
+weak_alias (getsockname, __getsockname)
diff --git a/libc/sysdeps/unix/sysv/linux/getsockopt.S b/libc/sysdeps/unix/sysv/linux/getsockopt.S
new file mode 100644
index 000000000..6f982082a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getsockopt.S
@@ -0,0 +1,3 @@
+#define socket getsockopt
+#define NARGS 5
+#include <socket.S>
diff --git a/libc/sysdeps/unix/sysv/linux/getsourcefilter.c b/libc/sysdeps/unix/sysv/linux/getsourcefilter.c
new file mode 100644
index 000000000..a6f89a3cc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getsourcefilter.c
@@ -0,0 +1,146 @@
+/* Get source filter. Linux version.
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <alloca.h>
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netatalk/at.h>
+#include <netax25/ax25.h>
+#include <netinet/in.h>
+#include <netipx/ipx.h>
+#include <netpacket/packet.h>
+#include <netrose/rose.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+
+
+static const struct
+{
+ int sol;
+ int af;
+ socklen_t size;
+} sol_map[] =
+ {
+ /* Sort the array according to importance of the protocols. Add
+ more protocols when they become available. */
+ { SOL_IP, AF_INET, sizeof (struct sockaddr_in) },
+ { SOL_IPV6, AF_INET6, sizeof (struct sockaddr_in6) },
+ { SOL_AX25, AF_AX25, sizeof (struct sockaddr_ax25) },
+ { SOL_IPX, AF_IPX, sizeof (struct sockaddr_ipx) },
+ { SOL_ATALK, AF_APPLETALK, sizeof (struct sockaddr_at) },
+ { SOL_ROSE, AF_ROSE, sizeof (struct sockaddr_rose) },
+ { SOL_PACKET, AF_PACKET, sizeof (struct sockaddr_ll) }
+ };
+#define NSOL_MAP (sizeof (sol_map) / sizeof (sol_map[0]))
+
+
+/* Try to determine the socket level value. Ideally both side and
+ family are set. But sometimes only the size is correct and the
+ family value might be bogus. Loop over the array entries and look
+ for a perfect match or the first match based on size. */
+int
+__get_sol (int af, socklen_t len)
+{
+ int first_size_sol = -1;
+
+ for (size_t cnt = 0; cnt < NSOL_MAP; ++cnt)
+ {
+ /* Just a test so that we make sure the special value used to
+ signal the "we have so far no socket level value" is OK. */
+ assert (sol_map[cnt].sol != -1);
+
+ if (len == sol_map[cnt].size)
+ {
+ /* The size matches, which is a requirement. If the family
+ matches, too, we have a winner. Otherwise we remember the
+ socket level value for this protocol if it is the first
+ match. */
+ if (af == sol_map[cnt].af)
+ /* Bingo! */
+ return sol_map[cnt].sol;
+
+ if (first_size_sol == -1)
+ first_size_sol = sol_map[cnt].sol;
+ }
+ }
+
+ return first_size_sol;
+}
+
+
+int
+getsourcefilter (int s, uint32_t interface, const struct sockaddr *group,
+ socklen_t grouplen, uint32_t *fmode, uint32_t *numsrc,
+ struct sockaddr_storage *slist)
+{
+ /* We have to create an struct ip_msfilter object which we can pass
+ to the kernel. */
+ socklen_t needed = GROUP_FILTER_SIZE (*numsrc);
+ int use_alloca = __libc_use_alloca (needed);
+
+ struct group_filter *gf;
+ if (use_alloca)
+ gf = (struct group_filter *) alloca (needed);
+ else
+ {
+ gf = (struct group_filter *) malloc (needed);
+ if (gf == NULL)
+ return -1;
+ }
+
+ gf->gf_interface = interface;
+ memcpy (&gf->gf_group, group, grouplen);
+ gf->gf_numsrc = *numsrc;
+
+ /* We need to provide the appropriate socket level value. */
+ int result;
+ int sol = __get_sol (group->sa_family, grouplen);
+ if (sol == -1)
+ {
+ __set_errno (EINVAL);
+ result = -1;
+ }
+ else
+ {
+ result = __getsockopt (s, sol, MCAST_MSFILTER, gf, &needed);
+
+ /* If successful, copy the results to the places the caller wants
+ them in. */
+ if (result == 0)
+ {
+ *fmode = gf->gf_fmode;
+ memcpy (slist, gf->gf_slist,
+ MIN (*numsrc, gf->gf_numsrc)
+ * sizeof (struct sockaddr_storage));
+ *numsrc = gf->gf_numsrc;
+ }
+ }
+
+ if (! use_alloca)
+ {
+ int save_errno = errno;
+ free (gf);
+ __set_errno (save_errno);
+ }
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/getsysstats.c b/libc/sysdeps/unix/sysv/linux/getsysstats.c
new file mode 100644
index 000000000..d655ba3b2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/getsysstats.c
@@ -0,0 +1,214 @@
+/* Determine various system internal values, Linux version.
+ Copyright (C) 1996-2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <alloca.h>
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <mntent.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/sysinfo.h>
+
+#include <atomic.h>
+
+
+/* How we can determine the number of available processors depends on
+ the configuration. There is currently (as of version 2.0.21) no
+ system call to determine the number. It is planned for the 2.1.x
+ series to add this, though.
+
+ One possibility to implement it for systems using Linux 2.0 is to
+ examine the pseudo file /proc/cpuinfo. Here we have one entry for
+ each processor.
+
+ But not all systems have support for the /proc filesystem. If it
+ is not available we simply return 1 since there is no way. */
+
+/* Other architectures use different formats for /proc/cpuinfo. This
+ provides a hook for alternative parsers. */
+#ifndef GET_NPROCS_PARSER
+# define GET_NPROCS_PARSER(FP, BUFFER, RESULT) \
+ do \
+ { \
+ (RESULT) = 0; \
+ /* Read all lines and count the lines starting with the string \
+ "processor". We don't have to fear extremely long lines since \
+ the kernel will not generate them. 8192 bytes are really \
+ enough. */ \
+ while (fgets_unlocked (BUFFER, sizeof (BUFFER), FP) != NULL) \
+ if (strncmp (BUFFER, "processor", 9) == 0) \
+ ++(RESULT); \
+ } \
+ while (0)
+#endif
+
+int
+__get_nprocs ()
+{
+ char buffer[8192];
+ int result = 1;
+
+ /* XXX Here will come a test for the new system call. */
+
+ /* The /proc/stat format is more uniform, use it by default. */
+ FILE *fp = fopen ("/proc/stat", "rc");
+ if (fp != NULL)
+ {
+ /* No threads use this stream. */
+ __fsetlocking (fp, FSETLOCKING_BYCALLER);
+
+ result = 0;
+ while (fgets_unlocked (buffer, sizeof (buffer), fp) != NULL)
+ if (strncmp (buffer, "cpu", 3) == 0 && isdigit (buffer[3]))
+ ++result;
+
+ fclose (fp);
+ }
+ else
+ {
+ fp = fopen ("/proc/cpuinfo", "rc");
+ if (fp != NULL)
+ {
+ /* No threads use this stream. */
+ __fsetlocking (fp, FSETLOCKING_BYCALLER);
+ GET_NPROCS_PARSER (fp, buffer, result);
+ fclose (fp);
+ }
+ }
+
+ return result;
+}
+weak_alias (__get_nprocs, get_nprocs)
+
+
+#ifdef GET_NPROCS_CONF_PARSER
+/* On some architectures it is possible to distinguish between configured
+ and active cpus. */
+int
+__get_nprocs_conf ()
+{
+ char buffer[8192];
+ int result = 1;
+
+ /* XXX Here will come a test for the new system call. */
+
+ /* If we haven't found an appropriate entry return 1. */
+ FILE *fp = fopen ("/proc/cpuinfo", "rc");
+ if (fp != NULL)
+ {
+ /* No threads use this stream. */
+ __fsetlocking (fp, FSETLOCKING_BYCALLER);
+ GET_NPROCS_CONF_PARSER (fp, buffer, result);
+ fclose (fp);
+ }
+
+ return result;
+}
+#else
+/* As far as I know Linux has no separate numbers for configured and
+ available processors. So make the `get_nprocs_conf' function an
+ alias. */
+strong_alias (__get_nprocs, __get_nprocs_conf)
+#endif
+weak_alias (__get_nprocs_conf, get_nprocs_conf)
+
+/* General function to get information about memory status from proc
+ filesystem. */
+static long int
+internal_function
+phys_pages_info (const char *format)
+{
+ char buffer[8192];
+ long int result = -1;
+
+ /* If we haven't found an appropriate entry return 1. */
+ FILE *fp = fopen ("/proc/meminfo", "rc");
+ if (fp != NULL)
+ {
+ /* No threads use this stream. */
+ __fsetlocking (fp, FSETLOCKING_BYCALLER);
+
+ result = 0;
+ /* Read all lines and count the lines starting with the
+ string "processor". We don't have to fear extremely long
+ lines since the kernel will not generate them. 8192
+ bytes are really enough. */
+ while (fgets_unlocked (buffer, sizeof buffer, fp) != NULL)
+ if (sscanf (buffer, format, &result) == 1)
+ {
+ result /= (__getpagesize () / 1024);
+ break;
+ }
+
+ fclose (fp);
+ }
+
+ if (result == -1)
+ /* We cannot get the needed value: signal an error. */
+ __set_errno (ENOSYS);
+
+ return result;
+}
+
+
+/* Return the number of pages of physical memory in the system. There
+ is currently (as of version 2.0.21) no system call to determine the
+ number. It is planned for the 2.1.x series to add this, though.
+
+ One possibility to implement it for systems using Linux 2.0 is to
+ examine the pseudo file /proc/cpuinfo. Here we have one entry for
+ each processor.
+
+ But not all systems have support for the /proc filesystem. If it
+ is not available we return -1 as an error signal. */
+long int
+__get_phys_pages ()
+{
+ /* XXX Here will come a test for the new system call. */
+
+ return phys_pages_info ("MemTotal: %ld kB");
+}
+weak_alias (__get_phys_pages, get_phys_pages)
+
+
+/* Return the number of available pages of physical memory in the
+ system. There is currently (as of version 2.0.21) no system call
+ to determine the number. It is planned for the 2.1.x series to add
+ this, though.
+
+ One possibility to implement it for systems using Linux 2.0 is to
+ examine the pseudo file /proc/cpuinfo. Here we have one entry for
+ each processor.
+
+ But not all systems have support for the /proc filesystem. If it
+ is not available we return -1 as an error signal. */
+long int
+__get_avphys_pages ()
+{
+ /* XXX Here will come a test for the new system call. */
+
+ return phys_pages_info ("MemFree: %ld kB");
+}
+weak_alias (__get_avphys_pages, get_avphys_pages)
diff --git a/libc/sysdeps/unix/sysv/linux/grantpt.c b/libc/sysdeps/unix/sysv/linux/grantpt.c
new file mode 100644
index 000000000..b894b8b63
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/grantpt.c
@@ -0,0 +1,81 @@
+/* Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <sys/statfs.h>
+
+#include "linux_fsinfo.h"
+
+/* Prototype for function that changes ownership and access permission
+ for slave pseudo terminals that do not live on a `devpts'
+ filesystem. */
+static int __unix_grantpt (int fd);
+
+/* Prototype for private function that gets the name of the slave
+ pseudo terminal in a safe way. */
+static int pts_name (int fd, char **pts, size_t buf_len);
+
+/* Change the ownership and access permission of the slave pseudo
+ terminal associated with the master pseudo terminal specified
+ by FD. */
+int
+grantpt (int fd)
+{
+ struct statfs fsbuf;
+#ifdef PATH_MAX
+ char _buf[PATH_MAX];
+#else
+ char _buf[512];
+#endif
+ char *buf = _buf;
+
+ if (__builtin_expect (pts_name (fd, &buf, sizeof (_buf)), 0))
+ {
+ int save_errno = errno;
+
+ /* Check, if the file descriptor is valid. pts_name returns the
+ wrong errno number, so we cannot use that. */
+ if (__libc_fcntl (fd, F_GETFD) == -1 && errno == EBADF)
+ return -1;
+
+ /* If the filedescriptor is no TTY, grantpt has to set errno
+ to EINVAL. */
+ if (save_errno == ENOTTY)
+ __set_errno (EINVAL);
+ else
+ __set_errno (save_errno);
+
+ return -1;
+ }
+
+ if (__statfs (buf, &fsbuf) < 0)
+ return -1;
+
+ /* If the slave pseudo terminal lives on a `devpts' filesystem, the
+ ownership and access permission are already set. */
+ if (fsbuf.f_type == DEVPTS_SUPER_MAGIC || fsbuf.f_type == DEVFS_SUPER_MAGIC)
+ return 0;
+
+ return __unix_grantpt (fd);
+}
+
+#define grantpt static __unix_grantpt
+#include <sysdeps/unix/grantpt.c>
diff --git a/libc/sysdeps/unix/sysv/linux/i386/Makefile b/libc/sysdeps/unix/sysv/linux/i386/Makefile
new file mode 100644
index 000000000..9e8497563
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/Makefile
@@ -0,0 +1,18 @@
+ifeq ($(subdir),misc)
+sysdep_routines += ioperm iopl vm86 call_pselect6
+sysdep_headers += sys/elf.h sys/perm.h sys/reg.h sys/vm86.h sys/debugreg.h sys/io.h
+endif
+
+ifeq ($(subdir),elf)
+sysdep-others += lddlibc4
+install-bin += lddlibc4
+
+endif
+
+ifeq ($(subdir),resource)
+sysdep_routines += oldgetrlimit64
+endif
+
+ifeq ($(subdir),stdlib)
+gen-as-const-headers += ucontext_i.sym
+endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/Versions b/libc/sysdeps/unix/sysv/linux/i386/Versions
new file mode 100644
index 000000000..abd1d152d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/Versions
@@ -0,0 +1,47 @@
+libc {
+ GLIBC_2.0 {
+ # Exception handling support functions from libgcc
+ __register_frame; __register_frame_table; __deregister_frame;
+ __frame_state_for; __register_frame_info_table;
+
+ ioperm; iopl;
+
+ vm86;
+ }
+ GLIBC_2.1 {
+ modify_ldt;
+ }
+ GLIBC_2.2 {
+ # functions used in other libraries
+ __xstat64; __fxstat64; __lxstat64;
+
+ # a*
+ alphasort64;
+
+ # g*
+ glob64;
+
+ # New rlimit interface
+ getrlimit; setrlimit; getrlimit64;
+
+ # r*
+ readdir64; readdir64_r;
+
+ # s*
+ scandir64;
+
+ # v*
+ versionsort64;
+ }
+ GLIBC_2.3.3 {
+ # p*
+ posix_fadvise64; posix_fallocate64;
+ }
+ GLIBC_2.3.4 {
+ # v*
+ vm86;
+ }
+ GLIBC_PRIVATE {
+ __modify_ldt;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/i386/_exit.S b/libc/sysdeps/unix/sysv/linux/i386/_exit.S
new file mode 100644
index 000000000..5c2e58840
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/_exit.S
@@ -0,0 +1,44 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+ .text
+ .type _exit,@function
+ .global _exit
+_exit:
+ movl 4(%esp), %ebx
+
+ /* Try the new syscall first. */
+#ifdef __NR_exit_group
+ movl $__NR_exit_group, %eax
+ ENTER_KERNEL
+#endif
+
+ /* Not available. Now the old one. */
+ movl $__NR_exit, %eax
+ /* Don't bother using ENTER_KERNEL here. If the exit_group
+ syscall is not available AT_SYSINFO isn't either. */
+ int $0x80
+
+ /* This must not fail. Be sure we don't return. */
+ hlt
+ .size _exit,.-_exit
+
+libc_hidden_def (_exit)
+weak_alias (_exit, _Exit)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/alphasort64.c b/libc/sysdeps/unix/sysv/linux/i386/alphasort64.c
new file mode 100644
index 000000000..221aedc16
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/alphasort64.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 1992, 1997, 1998, 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <dirent.h>
+#include <string.h>
+
+int
+__alphasort64 (const void *a, const void *b)
+{
+ return strcoll ((*(const struct dirent64 **) a)->d_name,
+ (*(const struct dirent64 **) b)->d_name);
+}
+
+#include <shlib-compat.h>
+
+versioned_symbol (libc, __alphasort64, alphasort64, GLIBC_2_2);
+
+#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+
+#include <sysdeps/unix/sysv/linux/i386/olddirent.h>
+
+int
+__old_alphasort64 (const void *a, const void *b);
+
+int
+attribute_compat_text_section
+__old_alphasort64 (const void *a, const void *b)
+{
+ return strcoll ((*(const struct __old_dirent64 **) a)->d_name,
+ (*(const struct __old_dirent64 **) b)->d_name);
+}
+
+compat_symbol (libc, __old_alphasort64, alphasort64, GLIBC_2_1);
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/bits/a.out.h b/libc/sysdeps/unix/sysv/linux/i386/bits/a.out.h
new file mode 100644
index 000000000..0fb52c381
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/bits/a.out.h
@@ -0,0 +1,3 @@
+#ifndef __A_OUT_GNU_H__
+# error "Never use <bits/a.out.h> directly; include <a.out.h> instead."
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/bits/environments.h b/libc/sysdeps/unix/sysv/linux/i386/bits/environments.h
new file mode 100644
index 000000000..16f7732aa
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/bits/environments.h
@@ -0,0 +1,62 @@
+/* Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _UNISTD_H
+# error "Never include this file directly. Use <unistd.h> instead"
+#endif
+
+/* This header should define the following symbols under the described
+ situations. A value `1' means that the model is always supported,
+ `-1' means it is never supported. Undefined means it cannot be
+ statically decided.
+
+ _POSIX_V6_ILP32_OFF32 32bit int, long, pointers, and off_t type
+ _POSIX_V6_ILP32_OFFBIG 32bit int, long, and pointers and larger off_t type
+
+ _POSIX_V6_LP64_OFF32 64bit long and pointers and 32bit off_t type
+ _POSIX_V6_LPBIG_OFFBIG 64bit long and pointers and large off_t type
+
+ The macros _XBS5_ILP32_OFF32, _XBS5_ILP32_OFFBIG, _XBS5_LP64_OFF32, and
+ _XBS5_LPBIG_OFFBIG were used in previous versions of the Unix standard
+ and are available only for compatibility.
+*/
+
+/* By default we have 32-bit wide `int', `long int', pointers and `off_t'
+ and all platforms support LFS. */
+#define _POSIX_V6_ILP32_OFF32 1
+#define _POSIX_V6_ILP32_OFFBIG 1
+#define _XBS5_ILP32_OFF32 1
+#define _XBS5_ILP32_OFFBIG 1
+
+/* We optionally provide an environment with the above size but an 64-bit
+ side `off_t'. Therefore we don't define _XBS5_ILP32_OFFBIG. */
+
+/* Environments with 64-bit wide pointers can be provided,
+ so these macros aren't defined:
+ # undef _POSIX_V6_LP64_OFF64
+ # undef _POSIX_V6_LPBIG_OFFBIG
+ # undef _XBS5_LP64_OFF64
+ # undef _XBS5_LPBIG_OFFBIG
+ and sysconf tests for it at runtime. */
+
+#define __ILP32_OFF32_CFLAGS "-m32"
+#define __ILP32_OFFBIG_CFLAGS "-m32 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+#define __ILP32_OFF32_LDFLAGS "-m32"
+#define __ILP32_OFFBIG_LDFLAGS "-m32"
+#define __LP64_OFF64_CFLAGS "-m64"
+#define __LP64_OFF64_LDFLAGS "-m64"
diff --git a/libc/sysdeps/unix/sysv/linux/i386/bits/fcntl.h b/libc/sysdeps/unix/sysv/linux/i386/bits/fcntl.h
new file mode 100644
index 000000000..1f7ac0f25
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/bits/fcntl.h
@@ -0,0 +1,236 @@
+/* O_*, F_*, FD_* bit values for Linux.
+ Copyright (C) 1995, 1996, 1997, 1998, 2000, 2004, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <sys/types.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+
+
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on an ext2 file system */
+#define O_ACCMODE 0003
+#define O_RDONLY 00
+#define O_WRONLY 01
+#define O_RDWR 02
+#define O_CREAT 0100 /* not fcntl */
+#define O_EXCL 0200 /* not fcntl */
+#define O_NOCTTY 0400 /* not fcntl */
+#define O_TRUNC 01000 /* not fcntl */
+#define O_APPEND 02000
+#define O_NONBLOCK 04000
+#define O_NDELAY O_NONBLOCK
+#define O_SYNC 010000
+#define O_FSYNC O_SYNC
+#define O_ASYNC 020000
+
+#ifdef __USE_GNU
+# define O_DIRECT 040000 /* Direct disk access. */
+# define O_DIRECTORY 0200000 /* Must be a directory. */
+# define O_NOFOLLOW 0400000 /* Do not follow links. */
+# define O_NOATIME 01000000 /* Do not set atime. */
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+# define O_LARGEFILE 0100000
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#ifndef __USE_FILE_OFFSET64
+# define F_GETLK 5 /* Get record locking info. */
+# define F_SETLK 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW 7 /* Set record locking info (blocking). */
+#else
+# define F_GETLK F_GETLK64 /* Get record locking info. */
+# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
+# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
+#endif
+#define F_GETLK64 12 /* Get record locking info. */
+#define F_SETLK64 13 /* Set record locking info (non-blocking). */
+#define F_SETLKW64 14 /* Set record locking info (blocking). */
+
+#if defined __USE_BSD || defined __USE_UNIX98
+# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */
+# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+#endif
+
+/* For F_[GET|SET]FD. */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
+#define F_RDLCK 0 /* Read lock. */
+#define F_WRLCK 1 /* Write lock. */
+#define F_UNLCK 2 /* Remove lock. */
+
+/* For old implementation of bsd flock(). */
+#define F_EXLCK 4 /* or 3 */
+#define F_SHLCK 8 /* or 4 */
+
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation. */
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#endif
+
+struct flock
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+#ifndef __USE_FILE_OFFSET64
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+#else
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+#endif
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+
+#ifdef __USE_LARGEFILE64
+struct flock64
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+#endif
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+#endif
+
+
+#ifdef __USE_GNU
+/* Flags for SYNC_FILE_RANGE. */
+# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
+ in the range before performing the
+ write. */
+# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
+ dirty pages in the range which are
+ not presently under writeback. */
+# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
+ the range after performing the
+ write. */
+
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+#endif
+
+__BEGIN_DECLS
+
+#ifdef __USE_GNU
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+
+/* Selective file content synch'ing. */
+extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
+ unsigned int __flags);
+
+
+/* Splice address range into a pipe. */
+extern int vmsplice (int __fdout, const struct iovec *__iov, size_t __count,
+ unsigned int __flags);
+
+/* Splice two files together. */
+extern int splice (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+/* In-kernel implementation of tee for pipe buffers. */
+extern int tee (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+#endif
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/i386/bits/mman.h b/libc/sysdeps/unix/sysv/linux/i386/bits/mman.h
new file mode 100644
index 000000000..00cb98239
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/bits/mman.h
@@ -0,0 +1,103 @@
+/* Definitions for POSIX memory map interface. Linux/i386 version.
+ Copyright (C) 1997, 2000, 2003, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MMAN_H
+# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead."
+#endif
+
+/* The following definitions basically come from the kernel headers.
+ But the kernel header is not namespace clean. */
+
+
+/* Protections are chosen from these bits, OR'd together. The
+ implementation does not necessarily support PROT_EXEC or PROT_WRITE
+ without PROT_READ. The only guarantees are that no writing will be
+ allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
+
+#define PROT_READ 0x1 /* Page can be read. */
+#define PROT_WRITE 0x2 /* Page can be written. */
+#define PROT_EXEC 0x4 /* Page can be executed. */
+#define PROT_NONE 0x0 /* Page can not be accessed. */
+#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
+ growsdown vma (mprotect only). */
+#define PROT_GROWSUP 0x02000000 /* Extend change to start of
+ growsup vma (mprotect only). */
+
+/* Sharing types (must choose one and only one of these). */
+#define MAP_SHARED 0x01 /* Share changes. */
+#define MAP_PRIVATE 0x02 /* Changes are private. */
+#ifdef __USE_MISC
+# define MAP_TYPE 0x0f /* Mask for type of mapping. */
+#endif
+
+/* Other flags. */
+#define MAP_FIXED 0x10 /* Interpret addr exactly. */
+#ifdef __USE_MISC
+# define MAP_FILE 0
+# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
+# define MAP_ANON MAP_ANONYMOUS
+#endif
+
+/* These are Linux-specific. */
+#ifdef __USE_MISC
+# define MAP_GROWSDOWN 0x00100 /* Stack-like segment. */
+# define MAP_DENYWRITE 0x00800 /* ETXTBSY */
+# define MAP_EXECUTABLE 0x01000 /* Mark it as an executable. */
+# define MAP_LOCKED 0x02000 /* Lock the mapping. */
+# define MAP_NORESERVE 0x04000 /* Don't check for reservations. */
+# define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */
+# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
+#endif
+
+/* Flags to `msync'. */
+#define MS_ASYNC 1 /* Sync memory asynchronously. */
+#define MS_SYNC 4 /* Synchronous memory sync. */
+#define MS_INVALIDATE 2 /* Invalidate the caches. */
+
+/* Flags for `mlockall'. */
+#define MCL_CURRENT 1 /* Lock all currently mapped pages. */
+#define MCL_FUTURE 2 /* Lock all additions to address
+ space. */
+
+/* Flags for `mremap'. */
+#ifdef __USE_GNU
+# define MREMAP_MAYMOVE 1
+# define MREMAP_FIXED 2
+#endif
+
+/* Advice to `madvise'. */
+#ifdef __USE_BSD
+# define MADV_NORMAL 0 /* No further special treatment. */
+# define MADV_RANDOM 1 /* Expect random page references. */
+# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define MADV_WILLNEED 3 /* Will need these pages. */
+# define MADV_DONTNEED 4 /* Don't need these pages. */
+# define MADV_REMOVE 9 /* Remove these pages and resources. */
+# define MADV_DONTFORK 10 /* Do not inherit across fork. */
+# define MADV_DOFORK 11 /* Do inherit across fork. */
+#endif
+
+/* The POSIX people had to invent similar names for the same things. */
+#ifdef __USE_XOPEN2K
+# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/bits/wchar.h b/libc/sysdeps/unix/sysv/linux/i386/bits/wchar.h
new file mode 100644
index 000000000..442a4621e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/bits/wchar.h
@@ -0,0 +1,26 @@
+/* wchar_t type related definitions.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _BITS_WCHAR_H
+#define _BITS_WCHAR_H 1
+
+#define __WCHAR_MIN (-2147483647l - 1l)
+#define __WCHAR_MAX (2147483647l)
+
+#endif /* bits/wchar.h */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/bp-thunks.h b/libc/sysdeps/unix/sysv/linux/i386/bp-thunks.h
new file mode 100644
index 000000000..59a42ddef
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/bp-thunks.h
@@ -0,0 +1,4 @@
+#ifndef __ASSEMBLER__
+# include <sysdeps/generic/bp-thunks.h>
+# include <sys/vm86.h>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/brk.c b/libc/sysdeps/unix/sysv/linux/i386/brk.c
new file mode 100644
index 000000000..1d26439ed
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/brk.c
@@ -0,0 +1,53 @@
+/* brk system call for Linux/i386.
+ Copyright (C) 1995, 1996, 2000, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sysdep.h>
+
+#include <bp-checks.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)
+{
+ void *__unbounded newbrk;
+
+ INTERNAL_SYSCALL_DECL (err);
+ newbrk = (void *__unbounded) INTERNAL_SYSCALL (brk, err, 1,
+ __ptrvalue (addr));
+
+ __curbrk = newbrk;
+
+ if (newbrk < addr)
+ {
+ __set_errno (ENOMEM);
+ return -1;
+ }
+
+ return 0;
+}
+weak_alias (__brk, brk)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/call_pselect6.S b/libc/sysdeps/unix/sysv/linux/i386/call_pselect6.S
new file mode 100644
index 000000000..a356f1dfa
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/call_pselect6.S
@@ -0,0 +1,65 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2006.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#ifdef __NR_pselect6
+ .text
+ENTRY(__call_pselect6)
+ .hidden __call_pselect6
+ pushl %ebx
+ cfi_adjust_cfa_offset (4)
+ pushl %esi
+ cfi_adjust_cfa_offset (4)
+ pushl %edi
+ cfi_adjust_cfa_offset (4)
+ pushl %ebp
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (ebp, 0)
+ cfi_rel_offset (edi, 4)
+ cfi_rel_offset (esi, 8)
+ cfi_rel_offset (ebx, 12)
+
+ movl $__NR_pselect6, %eax
+ movl 20(%esp), %ebx
+ movl 24(%esp), %ecx
+ movl 28(%esp), %edx
+ movl 32(%esp), %esi
+ movl 36(%esp), %edi
+ movl 40(%esp), %ebp
+
+ /* The syscall handling cannot handle 6 parameters. Yet. */
+ int $0x80
+
+ popl %ebp
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebp)
+ popl %edi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (edi)
+ popl %esi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (esi)
+ popl %ebx
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebx)
+
+ ret
+END(__call_pselect6)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/chown.c b/libc/sysdeps/unix/sysv/linux/i386/chown.c
new file mode 100644
index 000000000..fc6a9c95a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/chown.c
@@ -0,0 +1,159 @@
+/* Copyright (C) 1998,1999,2000,2002,2003,2004,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <shlib-compat.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+/*
+ In Linux 2.1.x the chown functions have been changed. A new function lchown
+ was introduced. The new chown now follows symlinks - the old chown and the
+ new lchown do not follow symlinks.
+ The new lchown function has the same number as the old chown had and the
+ new chown has a new number. When compiling with headers from Linux > 2.1.8x
+ it's impossible to run this libc with older kernels. In these cases libc
+ has therefore to route calls to chown to the old chown function.
+*/
+
+extern int __chown_is_lchown (const char *__file, uid_t __owner,
+ gid_t __group);
+extern int __real_chown (const char *__file, uid_t __owner, gid_t __group);
+
+
+#if defined __NR_lchown || __ASSUME_LCHOWN_SYSCALL > 0
+/* Running under Linux > 2.1.80. */
+
+# ifdef __NR_chown32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+# endif /* __NR_chown32 */
+
+int
+__real_chown (const char *file, uid_t owner, gid_t group)
+{
+# if __ASSUME_LCHOWN_SYSCALL == 0
+ static int __libc_old_chown;
+ int result;
+
+ if (!__libc_old_chown)
+ {
+ int saved_errno = errno;
+# ifdef __NR_chown32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+ int saved_errno = errno;
+
+ result = INLINE_SYSCALL (chown32, 3, CHECK_STRING (file), owner, group);
+ if (result == 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_chown32 */
+ if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ result = INLINE_SYSCALL (chown, 3, CHECK_STRING (file), owner, group);
+
+ if (result >= 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_old_chown = 1;
+ }
+
+ return __lchown (file, owner, group);
+# elif __ASSUME_32BITUIDS
+ /* This implies __ASSUME_LCHOWN_SYSCALL. */
+ return INLINE_SYSCALL (chown32, 3, CHECK_STRING (file), owner, group);
+# else
+ /* !__ASSUME_32BITUIDS && ASSUME_LCHOWN_SYSCALL */
+# ifdef __NR_chown32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+ int saved_errno = errno;
+
+ result = INLINE_SYSCALL (chown32, 3, CHECK_STRING (file), owner, group);
+ if (result == 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_chown32 */
+ if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return INLINE_SYSCALL (chown, 3, CHECK_STRING (file), owner, group);
+# endif
+}
+#endif
+
+
+#if !defined __NR_lchown && __ASSUME_LCHOWN_SYSCALL == 0
+/* Compiling under older kernels. */
+int
+__chown_is_lchown (const char *file, uid_t owner, gid_t group)
+{
+ return INLINE_SYSCALL (chown, 3, CHECK_STRING (file), owner, group);
+}
+#elif SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+/* Compiling for compatibiity. */
+int
+attribute_compat_text_section
+__chown_is_lchown (const char *file, uid_t owner, gid_t group)
+{
+ return __lchown (file, owner, group);
+}
+#endif
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+compat_symbol (libc, __chown_is_lchown, chown, GLIBC_2_0);
+#endif
+
+#ifdef __NR_lchown
+versioned_symbol (libc, __real_chown, chown, GLIBC_2_1);
+strong_alias (__real_chown, __chown)
+#else
+strong_alias (__chown_is_lchown, __chown_is_lchown21)
+versioned_symbol (libc, __chown_is_lchown21, chown, GLIBC_2_1);
+strong_alias (__chown_is_lchown, __chown)
+#endif
+libc_hidden_def (__chown)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/clone.S b/libc/sysdeps/unix/sysv/linux/i386/clone.S
new file mode 100644
index 000000000..54524ec12
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/clone.S
@@ -0,0 +1,159 @@
+/* Copyright (C) 1996-2000,02,03,04,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson (rth@tamu.edu)
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* clone() is even more special than fork() as it mucks with stacks
+ and invokes a function in the right context after its all over. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <asm-syntax.h>
+#include <bp-sym.h>
+#include <bp-asm.h>
+
+/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
+ pid_t *ptid, struct user_desc *tls, pid_t *ctid); */
+
+#define PARMS LINKAGE /* no space for saved regs */
+#define FUNC PARMS
+#define STACK FUNC+4
+#define FLAGS STACK+PTR_SIZE
+#define ARG FLAGS+4
+#define PTID ARG+PTR_SIZE
+#define TLS PTID+PTR_SIZE
+#define CTID TLS+PTR_SIZE
+
+#define __NR_clone 120
+#define SYS_clone 120
+
+#define CLONE_VM 0x00000100
+#define CLONE_THREAD 0x00010000
+
+ .text
+ENTRY (BP_SYM (__clone))
+ /* Sanity check arguments. */
+ movl $-EINVAL,%eax
+ movl FUNC(%esp),%ecx /* no NULL function pointers */
+#ifdef PIC
+ jecxz SYSCALL_ERROR_LABEL
+#else
+ testl %ecx,%ecx
+ jz SYSCALL_ERROR_LABEL
+#endif
+ movl STACK(%esp),%ecx /* no NULL stack pointers */
+#ifdef PIC
+ jecxz SYSCALL_ERROR_LABEL
+#else
+ testl %ecx,%ecx
+ jz SYSCALL_ERROR_LABEL
+#endif
+
+ /* Insert the argument onto the new stack. Make sure the new
+ thread is started with an alignment of (mod 16). */
+ andl $0xfffffff0, %ecx
+ subl $28,%ecx
+ movl ARG(%esp),%eax /* no negative argument counts */
+ movl %eax,12(%ecx)
+
+ /* Save the function pointer as the zeroth argument.
+ It will be popped off in the child in the ebx frobbing below. */
+ movl FUNC(%esp),%eax
+ movl %eax,8(%ecx)
+ /* Don't leak any information. */
+ movl $0,4(%ecx)
+#ifndef RESET_PID
+ movl $0,(%ecx)
+#endif
+
+ /* Do the system call */
+ pushl %ebx
+ cfi_adjust_cfa_offset (4)
+ pushl %esi
+ cfi_adjust_cfa_offset (4)
+ pushl %edi
+ cfi_adjust_cfa_offset (4)
+
+ movl TLS+12(%esp),%esi
+ cfi_rel_offset (esi, 4)
+ movl PTID+12(%esp),%edx
+ movl FLAGS+12(%esp),%ebx
+ cfi_rel_offset (ebx, 8)
+ movl CTID+12(%esp),%edi
+ cfi_rel_offset (edi, 0)
+ movl $SYS_ify(clone),%eax
+
+#ifdef RESET_PID
+ /* Remember the flag value. */
+ movl %ebx, (%ecx)
+#endif
+
+ /* End FDE now, because in the child the unwind info will be
+ wrong. */
+ cfi_endproc
+
+ int $0x80
+ popl %edi
+ popl %esi
+ popl %ebx
+
+ test %eax,%eax
+ jl SYSCALL_ERROR_LABEL
+ jz L(thread_start)
+
+L(pseudo_end):
+ ret
+
+L(thread_start):
+ /* Note: %esi is zero. */
+ movl %esi,%ebp /* terminate the stack frame */
+#ifdef RESET_PID
+ testl $CLONE_THREAD, %edi
+ je L(newpid)
+L(haspid):
+#endif
+ call *%ebx
+#ifdef PIC
+ call L(here)
+L(here):
+ popl %ebx
+ addl $_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ebx
+#endif
+ movl %eax, %ebx
+ movl $SYS_ify(exit), %eax
+ ENTER_KERNEL
+
+#ifdef RESET_PID
+ .subsection 2
+L(newpid):
+ testl $CLONE_VM, %edi
+ movl $-1, %eax
+ jne L(nomoregetpid)
+ movl $SYS_ify(getpid), %eax
+ ENTER_KERNEL
+L(nomoregetpid):
+ movl %eax, %gs:PID
+ movl %eax, %gs:TID
+ jmp L(haspid)
+ .previous
+#endif
+
+ cfi_startproc
+PSEUDO_END (BP_SYM (__clone))
+
+weak_alias (BP_SYM (__clone), BP_SYM (clone))
diff --git a/libc/sysdeps/unix/sysv/linux/i386/dl-librecon.h b/libc/sysdeps/unix/sysv/linux/i386/dl-librecon.h
new file mode 100644
index 000000000..9f5203151
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/dl-librecon.h
@@ -0,0 +1,63 @@
+/* Optional code to distinguish library flavours.
+ Copyright (C) 1998, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _DL_LIBRECON_H
+
+#include <sysdeps/unix/sysv/linux/dl-librecon.h>
+
+#define DISTINGUISH_LIB_VERSIONS \
+ do \
+ { \
+ /* We have to find out whether the binary is linked against \
+ libc 5 or glibc. We do this by looking at all the DT_NEEDED \
+ entries. If one is libc.so.5 this is a libc 5 linked binary. */ \
+ if (main_map->l_info[DT_NEEDED]) \
+ { \
+ /* We have dependencies. */ \
+ const ElfW(Dyn) *d; \
+ const char *strtab; \
+ \
+ strtab = (const char *) D_PTR (main_map, l_info[DT_STRTAB]); \
+ \
+ for (d = main_map->l_ld; d->d_tag != DT_NULL; ++d) \
+ if (d->d_tag == DT_NEEDED \
+ && strcmp (strtab + d->d_un.d_val, "libc.so.5") == 0) \
+ break; \
+ \
+ /* We print a `5' or `6' depending on the outcome. */ \
+ _dl_printf (d->d_tag != DT_NULL ? "5\n" : "6\n"); \
+ } \
+ } \
+ while (0)
+
+/* Recognizing extra environment variables. */
+#define EXTRA_LD_ENVVARS \
+ case 15: \
+ if (memcmp (envline, "LIBRARY_VERSION", 15) == 0) \
+ GLRO(dl_correct_cache_id) = envline[16] == '5' ? 2 : 3; \
+ break; \
+
+/* Extra unsecure variables. The names are all stuffed in a single
+ string which means they have to be terminated with a '\0' explicitly. */
+#define EXTRA_UNSECURE_ENVVARS \
+ "LD_AOUT_LIBRARY_PATH\0" \
+ "LD_AOUT_PRELOAD\0"
+
+#endif /* dl-librecon.h */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/dl-procinfo.h b/libc/sysdeps/unix/sysv/linux/i386/dl-procinfo.h
new file mode 100644
index 000000000..d92a3b235
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/dl-procinfo.h
@@ -0,0 +1,43 @@
+/* Linux/i386 version of processor capability information handling macros.
+ Copyright (C) 1998-2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/i386/dl-procinfo.h>
+#include <ldsodefs.h>
+
+
+#undef _dl_procinfo
+static inline int
+__attribute__ ((unused))
+_dl_procinfo (int word)
+{
+ /* This table should match the information from arch/i386/kernel/setup.c
+ in the kernel sources. */
+ int i;
+
+ _dl_printf ("AT_HWCAP: ");
+
+ for (i = 0; i < _DL_HWCAP_COUNT; ++i)
+ if (word & (1 << i))
+ _dl_printf (" %s", GLRO(dl_x86_cap_flags)[i]);
+
+ _dl_printf ("\n");
+
+ return 0;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/i386/fchown.c b/libc/sysdeps/unix/sysv/linux/i386/fchown.c
new file mode 100644
index 000000000..30299c960
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/fchown.c
@@ -0,0 +1,68 @@
+/* Copyright (C) 2000, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+#ifdef __NR_fchown32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_fchown32 */
+
+int
+__fchown (int fd, uid_t owner, gid_t group)
+{
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (fchown32, 3, fd, owner, group);
+#else
+# ifdef __NR_fchown32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+ int saved_errno = errno;
+
+ result = INLINE_SYSCALL (fchown32, 3, fd, owner, group);
+ if (result == 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_fchown32 */
+
+ if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return INLINE_SYSCALL (fchown, 3, fd, owner, group);
+#endif
+}
+
+weak_alias (__fchown, fchown)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/fchownat.c b/libc/sysdeps/unix/sysv/linux/i386/fchownat.c
new file mode 100644
index 000000000..db5481705
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/fchownat.c
@@ -0,0 +1,196 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <shlib-compat.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+/*
+ In Linux 2.1.x the chown functions have been changed. A new function lchown
+ was introduced. The new chown now follows symlinks - the old chown and the
+ new lchown do not follow symlinks.
+ The new lchown function has the same number as the old chown had and the
+ new chown has a new number. When compiling with headers from Linux > 2.1.8x
+ it's impossible to run this libc with older kernels. In these cases libc
+ has therefore to route calls to chown to the old chown function.
+*/
+
+extern int __chown_is_lchown (const char *__file, uid_t __owner,
+ gid_t __group);
+extern int __real_chown (const char *__file, uid_t __owner, gid_t __group);
+
+
+#if defined __NR_lchown || __ASSUME_LCHOWN_SYSCALL > 0
+/* Running under Linux > 2.1.80. */
+
+# ifdef __NR_chown32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+# endif /* __NR_chown32 */
+#endif
+
+
+int
+fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
+{
+ int result;
+
+#ifdef __NR_fchownat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INLINE_SYSCALL (fchownat, 5, fd, file, owner, group, flag);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ if (flag & ~AT_SYMLINK_NOFOLLOW)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+# if defined __NR_lchown || __ASSUME_LCHOWN_SYSCALL > 0
+# if __ASSUME_LCHOWN_SYSCALL == 0
+ static int __libc_old_chown;
+
+# ifdef __NR_chown32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lchown32, err, 3, CHECK_STRING (file),
+ owner, group);
+ else
+ result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file),
+ owner, group);
+
+ if (!INTERNAL_SYSCALL_ERROR_P (result, err))
+ return result;
+ if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ goto fail;
+
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_chown32 */
+
+ if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (!__libc_old_chown && (flag & AT_SYMLINK_NOFOLLOW) == 0)
+ {
+ result = INTERNAL_SYSCALL (chown, err, 3, CHECK_STRING (file), owner,
+ group);
+
+ if (!INTERNAL_SYSCALL_ERROR_P (result, err))
+ return result;
+ if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ goto fail;
+
+ __libc_old_chown = 1;
+ }
+
+ result = INTERNAL_SYSCALL (lchown, err, 3, CHECK_STRING (file), owner,
+ group);
+# elif __ASSUME_32BITUIDS
+ /* This implies __ASSUME_LCHOWN_SYSCALL. */
+ result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file), owner,
+ group);
+# else
+ /* !__ASSUME_32BITUIDS && ASSUME_LCHOWN_SYSCALL */
+# ifdef __NR_chown32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file), owner,
+ group);
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return result;
+ if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ goto fail;
+
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_chown32 */
+ if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ result = INTERNAL_SYSCALL (chown, err, 3, CHECK_STRING (file), owner, group);
+# endif
+# else
+ result = INTERNAL_SYSCALL (chown, err, 3, CHECK_STRING (file), owner, group);
+# endif
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ goto fail;
+
+ return result;
+
+ fail:
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+ return -1;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/i386/fcntl.c b/libc/sysdeps/unix/sysv/linux/i386/fcntl.c
new file mode 100644
index 000000000..b27373d24
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/fcntl.c
@@ -0,0 +1,169 @@
+/* Copyright (C) 2000,2002,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <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>
+
+#if __ASSUME_FCNTL64 == 0
+/* This variable is shared with all files that check for fcntl64. */
+int __have_no_fcntl64;
+#endif
+
+#if defined NO_CANCELLATION && __ASSUME_FCNTL64 == 0
+# define __fcntl_nocancel __libc_fcntl
+#endif
+
+#if !defined NO_CANCELLATION || __ASSUME_FCNTL64 == 0
+int
+__fcntl_nocancel (int fd, int cmd, ...)
+{
+ va_list ap;
+ void *arg;
+
+ va_start (ap, cmd);
+ arg = va_arg (ap, void *);
+ va_end (ap);
+
+#if __ASSUME_FCNTL64 == 0
+# ifdef __NR_fcntl64
+ if (! __have_no_fcntl64)
+ {
+ int result = INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
+ if (result >= 0 || errno != ENOSYS)
+ return result;
+
+ __have_no_fcntl64 = 1;
+ }
+# endif
+ switch (cmd)
+ {
+ case F_GETLK64:
+ /* Convert arg from flock64 to flock and back. */
+ {
+ struct flock fl;
+ struct flock64 *fl64 = arg;
+ int res;
+
+ fl.l_start = (off_t)fl64->l_start;
+ /* Check if we can represent the values with the smaller type. */
+ if ((off64_t) fl.l_start != fl64->l_start)
+ {
+ eoverflow:
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+ fl.l_len = (off_t) fl64->l_len;
+ /* Check if we can represent the values with the smaller type. */
+ if ((off64_t) fl.l_len != fl64->l_len)
+ goto eoverflow;
+
+ fl.l_type = fl64->l_type;
+ fl.l_whence = fl64->l_whence;
+ fl.l_pid = fl64->l_pid;
+
+ res = INLINE_SYSCALL (fcntl, 3, fd, F_GETLK, &fl);
+ if (res != 0)
+ return res;
+ /* Everything ok, convert back. */
+ fl64->l_type = fl.l_type;
+ fl64->l_whence = fl.l_whence;
+ fl64->l_start = fl.l_start;
+ fl64->l_len = fl.l_len;
+ fl64->l_pid = fl.l_pid;
+
+ return 0;
+ }
+ case F_SETLK64:
+ case F_SETLKW64:
+ /* Try to convert arg from flock64 to flock. */
+ {
+ struct flock fl;
+ struct flock64 *fl64 = arg;
+
+ fl.l_start = (off_t) fl64->l_start;
+ /* Check if we can represent the values with the smaller type. */
+ if ((off64_t) fl.l_start != fl64->l_start)
+ goto eoverflow;
+
+ fl.l_len = (off_t)fl64->l_len;
+ /* Check if we can represent the values with the smaller type. */
+ if ((off64_t) fl.l_len != fl64->l_len)
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+ fl.l_type = fl64->l_type;
+ fl.l_whence = fl64->l_whence;
+ fl.l_pid = fl64->l_pid;
+ assert (F_SETLK - F_SETLKW == F_SETLK64 - F_SETLKW64);
+ return INLINE_SYSCALL (fcntl, 3, fd, cmd + F_SETLK - F_SETLK64, &fl);
+ }
+ default:
+ return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
+ }
+ return -1;
+#else
+ return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
+#endif /* !__ASSUME_FCNTL64 */
+}
+#endif /* NO_CANCELLATION || !__ASSUME_FCNTL64 */
+
+
+#ifndef __fcntl_nocancel
+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 __ASSUME_FCNTL64 > 0
+ if (SINGLE_THREAD_P || (cmd != F_SETLKW && cmd != F_SETLKW64))
+ return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
+#else
+ if (SINGLE_THREAD_P || (cmd != F_SETLKW && cmd != F_SETLKW64))
+ return __fcntl_nocancel (fd, cmd, arg);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = __fcntl_nocancel (fd, cmd, arg);
+#endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+#endif
+libc_hidden_def (__libc_fcntl)
+
+weak_alias (__libc_fcntl, __fcntl)
+libc_hidden_weak (__fcntl)
+weak_alias (__libc_fcntl, fcntl)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/fxstat.c b/libc/sysdeps/unix/sysv/linux/i386/fxstat.c
new file mode 100644
index 000000000..281839f96
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/fxstat.c
@@ -0,0 +1,101 @@
+/* fxstat using old-style Unix fstat system call.
+ Copyright (C) 1991,1995-1998,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, if xstat == xstat64 we must get rid of the prototype or gcc
+ will complain since they don't strictly match. */
+#define __fxstat64 __fxstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#include <xstatconv.h>
+
+#ifdef __NR_stat64
+# if __ASSUME_STAT64_SYSCALL == 0
+/* The variable is shared between all wrappers around *stat64 calls. */
+extern int __have_no_stat64;
+# endif
+#endif
+
+/* Get information about the file FD in BUF. */
+int
+__fxstat (int vers, int fd, struct stat *buf)
+{
+#if __ASSUME_STAT64_SYSCALL == 0
+ struct kernel_stat kbuf;
+#endif
+ int result;
+
+ if (vers == _STAT_VER_KERNEL)
+ return INLINE_SYSCALL (fstat, 2, fd, CHECK_1 ((struct kernel_stat *) buf));
+
+#if __ASSUME_STAT64_SYSCALL > 0
+ {
+ struct stat64 buf64;
+
+ result = INLINE_SYSCALL (fstat64, 2, fd, __ptrvalue (&buf64));
+ if (result == 0)
+ result = __xstat32_conv (vers, &buf64, buf);
+ return result;
+ }
+#else
+
+# if defined __NR_stat64
+ /* To support 32 bit UIDs, we have to use stat64. The normal stat call only returns
+ 16 bit UIDs. */
+ if (! __have_no_stat64)
+ {
+ struct stat64 buf64;
+
+ result = INLINE_SYSCALL (fstat64, 2, fd, __ptrvalue (&buf64));
+
+ if (result == 0)
+ result = __xstat32_conv (vers, &buf64, buf);
+
+ if (result != -1 || errno != ENOSYS)
+ return result;
+
+ __have_no_stat64 = 1;
+ }
+# endif
+
+ result = INLINE_SYSCALL (fstat, 2, fd, __ptrvalue (&kbuf));
+ if (result == 0)
+ result = __xstat_conv (vers, &kbuf, buf);
+
+ return result;
+#endif /* __ASSUME_STAT64_SYSCALL */
+}
+
+hidden_def (__fxstat)
+weak_alias (__fxstat, _fxstat);
+#ifdef XSTAT_IS_XSTAT64
+#undef __fxstat64
+strong_alias (__fxstat, __fxstat64);
+hidden_ver (__fxstat, __fxstat64)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/fxstatat.c b/libc/sysdeps/unix/sysv/linux/i386/fxstatat.c
new file mode 100644
index 000000000..94f6e8118
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/fxstatat.c
@@ -0,0 +1,176 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, if fxstatat == fxstatat64 we must get rid of the prototype or gcc
+ will complain since they don't strictly match. */
+#define __fxstatat64 __fxstatat64_disable
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#include <xstatconv.h>
+
+#ifdef __NR_stat64
+# if __ASSUME_STAT64_SYSCALL == 0
+/* The variable is shared between all wrappers around *stat64 calls. */
+extern int __have_no_stat64;
+# endif
+#endif
+
+
+/* Get information about the file NAME relative to FD in ST. */
+int
+__fxstatat (int vers, int fd, const char *file, struct stat *st, int flag)
+{
+ int result;
+ INTERNAL_SYSCALL_DECL (err);
+ struct stat64 st64;
+
+#ifdef __NR_fstatat64
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INTERNAL_SYSCALL (fstatat64, err, 4, fd, file, &st64, flag);
+# ifndef __ASSUME_ATFCTS
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1)
+ && INTERNAL_SYSCALL_ERRNO (result, err) == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ if (!__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return __xstat32_conv (vers, &st64, st);
+ else
+ {
+ __set_errno (INTERNAL_SYSCALL_ERRNO (result, err));
+ return -1;
+ }
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ if (__builtin_expect (flag & ~AT_SYMLINK_NOFOLLOW, 0))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+# if __ASSUME_STAT64_SYSCALL == 0
+ struct kernel_stat kst;
+# endif
+ if (vers == _STAT_VER_KERNEL)
+ {
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lstat, err, 2, CHECK_STRING (file),
+ CHECK_1 ((struct kernel_stat *) st));
+ else
+ result = INTERNAL_SYSCALL (stat, err, 2, CHECK_STRING (file),
+ CHECK_1 ((struct kernel_stat *) st));
+ goto out;
+ }
+
+# if __ASSUME_STAT64_SYSCALL > 0
+
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lstat64, err, 2, CHECK_STRING (file),
+ __ptrvalue (&st64));
+ else
+ result = INTERNAL_SYSCALL (stat64, err, 2, CHECK_STRING (file),
+ __ptrvalue (&st64));
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return __xstat32_conv (vers, &st64, st);
+# else
+# if defined __NR_stat64
+ /* To support 32 bit UIDs, we have to use stat64. The normal stat
+ call only returns 16 bit UIDs. */
+ if (! __have_no_stat64)
+ {
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lstat64, err, 2, CHECK_STRING (file),
+ __ptrvalue (&st64));
+ else
+ result = INTERNAL_SYSCALL (stat64, err, 2, CHECK_STRING (file),
+ __ptrvalue (&st64));
+
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ result = __xstat32_conv (vers, &st64, st);
+
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1)
+ || INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ goto out;
+
+ __have_no_stat64 = 1;
+ }
+# endif
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lstat, err, 2, CHECK_STRING (file),
+ __ptrvalue (&kst));
+ else
+ result = INTERNAL_SYSCALL (stat, err, 2, CHECK_STRING (file),
+ __ptrvalue (&kst));
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return __xstat_conv (vers, &kst, st);
+# endif /* __ASSUME_STAT64_SYSCALL */
+
+ out:
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+ result = -1;
+ }
+
+ return result;
+#endif
+}
+libc_hidden_def (__fxstatat)
+#ifdef XSTAT_IS_XSTAT64
+# undef __fxstatat64
+strong_alias (__fxstatat, __fxstatat64);
+libc_hidden_ver (__fxstatat, __fxstatat64)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/get_clockfreq.c b/libc/sysdeps/unix/sysv/linux/i386/get_clockfreq.c
new file mode 100644
index 000000000..3e2b18392
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/get_clockfreq.c
@@ -0,0 +1,91 @@
+/* Get frequency of the system processor. i386/Linux version.
+ Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <libc-internal.h>
+
+
+hp_timing_t
+__get_clockfreq (void)
+{
+ /* We read the information from the /proc filesystem. It contains at
+ least one line like
+ cpu MHz : 497.840237
+ or also
+ cpu MHz : 497.841
+ We search for this line and convert the number in an integer. */
+ static hp_timing_t result;
+ int fd;
+
+ /* If this function was called before, we know the result. */
+ if (result != 0)
+ return result;
+
+ fd = open ("/proc/cpuinfo", O_RDONLY);
+ if (__builtin_expect (fd != -1, 1))
+ {
+ /* XXX AFAIK the /proc filesystem can generate "files" only up
+ to a size of 4096 bytes. */
+ char buf[4096];
+ ssize_t n;
+
+ n = read (fd, buf, sizeof buf);
+ if (__builtin_expect (n, 1) > 0)
+ {
+ char *mhz = memmem (buf, n, "cpu MHz", 7);
+
+ if (__builtin_expect (mhz != NULL, 1))
+ {
+ char *endp = buf + n;
+ int seen_decpoint = 0;
+ int ndigits = 0;
+
+ /* Search for the beginning of the string. */
+ while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
+ ++mhz;
+
+ while (mhz < endp && *mhz != '\n')
+ {
+ if (*mhz >= '0' && *mhz <= '9')
+ {
+ result *= 10;
+ result += *mhz - '0';
+ if (seen_decpoint)
+ ++ndigits;
+ }
+ else if (*mhz == '.')
+ seen_decpoint = 1;
+
+ ++mhz;
+ }
+
+ /* Compensate for missing digits at the end. */
+ while (ndigits++ < 6)
+ result *= 10;
+ }
+ }
+
+ close (fd);
+ }
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/i386/getcontext.S b/libc/sysdeps/unix/sysv/linux/i386/getcontext.S
new file mode 100644
index 000000000..fe28f1e0e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/getcontext.S
@@ -0,0 +1,85 @@
+/* Save current context.
+ Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__getcontext)
+ /* Load address of the context data structure. */
+ movl 4(%esp), %eax
+
+ /* Return value of getcontext. EAX is the only register whose
+ value is not preserved. */
+ movl $0, oEAX(%eax)
+
+ /* Save the 32-bit register values and the return address. */
+ movl %ecx, oECX(%eax)
+ movl %edx, oEDX(%eax)
+ movl %edi, oEDI(%eax)
+ movl %esi, oESI(%eax)
+ movl %ebp, oEBP(%eax)
+ movl (%esp), %ecx
+ movl %ecx, oEIP(%eax)
+ leal 4(%esp), %ecx /* Exclude the return address. */
+ movl %ecx, oESP(%eax)
+ movl %ebx, oEBX(%eax)
+
+ /* Save the FS segment register. We don't touch the GS register
+ since it is used for threads. */
+ xorl %edx, %edx
+ movw %fs, %dx
+ movl %edx, oFS(%eax)
+
+ /* We have separate floating-point register content memory on the
+ stack. We use the __fpregs_mem block in the context. Set the
+ links up correctly. */
+ leal oFPREGSMEM(%eax), %ecx
+ movl %ecx, oFPREGS(%eax)
+ /* Save the floating-point context. */
+ fnstenv (%ecx)
+ /* And load it right back since the processor changes the mask.
+ Intel thought this opcode to be used in interrupt handlers which
+ would block all exceptions. */
+ fldenv (%ecx)
+
+ /* Save the current signal mask. */
+ pushl %ebx
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (ebx, 0)
+ leal oSIGMASK(%eax), %edx
+ xorl %ecx, %ecx
+ movl $SIG_BLOCK, %ebx
+ movl $__NR_sigprocmask, %eax
+ ENTER_KERNEL
+ popl %ebx
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebx)
+ cmpl $-4095, %eax /* Check %eax for error. */
+ jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
+
+ /* All done, return 0 for success. */
+ xorl %eax, %eax
+L(pseudo_end):
+ ret
+PSEUDO_END(__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/getdents64.c b/libc/sysdeps/unix/sysv/linux/i386/getdents64.c
new file mode 100644
index 000000000..e6fcf68ad
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/getdents64.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define __GETDENTS __getdents64
+#define DIRENT_TYPE struct dirent64
+
+#include <sysdeps/unix/sysv/linux/getdents.c>
+
+#include <shlib-compat.h>
+
+#undef __READDIR
+#undef __GETDENTS
+#undef DIRENT_TYPE
+
+#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+
+#include <sysdeps/unix/sysv/linux/i386/olddirent.h>
+
+#define __GETDENTS __old_getdents64
+#define DIRENT_TYPE struct __old_dirent64
+#define kernel_dirent old_kernel_dirent
+#define kernel_dirent64 old_kernel_dirent64
+
+#include <sysdeps/unix/sysv/linux/getdents.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/getegid.c b/libc/sysdeps/unix/sysv/linux/i386/getegid.c
new file mode 100644
index 000000000..31c10cc32
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/getegid.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 2000, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <kernel-features.h>
+
+#ifdef __NR_getegid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids attribute_hidden;
+# endif
+#endif /* __NR_getegid32 */
+
+gid_t
+__getegid (void)
+{
+ INTERNAL_SYSCALL_DECL (err);
+#if __ASSUME_32BITUIDS > 0
+ /* No error checking. */
+ return INTERNAL_SYSCALL (getegid32, err, 0);
+#else
+# ifdef __NR_getegid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+
+ result = INTERNAL_SYSCALL (getegid32, err, 0);
+ if (! INTERNAL_SYSCALL_ERROR_P (result, err)
+ || INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ return result;
+
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_getegid32 */
+
+ /* No error checking. */
+ return INTERNAL_SYSCALL (getegid, err, 0);
+#endif
+}
+
+weak_alias (__getegid, getegid)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/geteuid.c b/libc/sysdeps/unix/sysv/linux/i386/geteuid.c
new file mode 100644
index 000000000..53f52687a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/geteuid.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 2000, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <kernel-features.h>
+
+#ifdef __NR_geteuid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids attribute_hidden;
+# endif
+#endif /* __NR_geteuid32 */
+
+uid_t
+__geteuid (void)
+{
+ INTERNAL_SYSCALL_DECL (err);
+#if __ASSUME_32BITUIDS > 0
+ /* No error checking. */
+ return INTERNAL_SYSCALL (geteuid32, err, 0);
+#else
+# ifdef __NR_geteuid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+
+ result = INTERNAL_SYSCALL (geteuid32, err, 0);
+ if (! INTERNAL_SYSCALL_ERROR_P (result, err)
+ || INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ return result;
+
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_geteuid32 */
+
+ /* No error checking. */
+ return INTERNAL_SYSCALL (geteuid, err, 0);
+#endif
+}
+
+weak_alias (__geteuid, geteuid)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/getgid.c b/libc/sysdeps/unix/sysv/linux/i386/getgid.c
new file mode 100644
index 000000000..7a7e38d9c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/getgid.c
@@ -0,0 +1,62 @@
+/* Copyright (C) 2000, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_getgid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids attribute_hidden;
+# endif
+#endif /* __NR_getgid32 */
+
+gid_t
+__getgid (void)
+{
+ INTERNAL_SYSCALL_DECL (err);
+#if __ASSUME_32BITUIDS > 0
+ /* No error checking. */
+ return INTERNAL_SYSCALL (getgid32, err, 0);
+#else
+# ifdef __NR_getgid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+
+ result = INTERNAL_SYSCALL (getgid32, err, 0);
+ if (! INTERNAL_SYSCALL_ERROR_P (result, err)
+ || INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ return result;
+
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_getgid32 */
+
+ /* No error checking. */
+ return INTERNAL_SYSCALL (getgid, err, 0);
+#endif
+}
+
+weak_alias (__getgid, getgid)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/getgroups.c b/libc/sysdeps/unix/sysv/linux/i386/getgroups.c
new file mode 100644
index 000000000..b7a0a4efd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/getgroups.c
@@ -0,0 +1,81 @@
+/* Copyright (C) 1997, 1998, 2000, 2001, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+
+#ifdef __NR_getgroups32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids attribute_hidden;
+# endif
+#endif /* __NR_getgroups32 */
+
+/* For Linux we must convert the array of groups from the format that the
+ kernel returns. */
+int
+__getgroups (int n, gid_t *groups)
+{
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (getgroups32, 2, n, CHECK_N (groups, n));
+#else
+ if (__builtin_expect (n, 1) < 0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ else
+ {
+ int i, ngids;
+ __kernel_gid_t kernel_groups[n = MIN (n, __sysconf (_SC_NGROUPS_MAX))];
+# ifdef __NR_getgroups32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+ int saved_errno = errno;
+
+ result = INLINE_SYSCALL (getgroups32, 2, n, CHECK_N (groups, n));
+ if (result != -1 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_getgroups32 */
+
+ ngids = INLINE_SYSCALL (getgroups, 2, n, CHECK_N (kernel_groups, n));
+ if (n != 0 && ngids > 0)
+ for (i = 0; i < ngids; i++)
+ (__ptrvalue (groups))[i] = kernel_groups[i];
+ return ngids;
+ }
+#endif
+}
+
+weak_alias (__getgroups, getgroups)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/getmsg.c b/libc/sysdeps/unix/sysv/linux/i386/getmsg.c
new file mode 100644
index 000000000..c0efd5636
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/getmsg.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 1998, 1999, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <stropts.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#ifdef __NR_getpmsg
+int
+getmsg (fildes, ctlptr, dataptr, flagsp)
+ int fildes;
+ struct strbuf *ctlptr;
+ struct strbuf *dataptr;
+ int *flagsp;
+{
+ return INLINE_SYSCALL (getpmsg, 5, fildes, ctlptr, dataptr, NULL, flagsp);
+}
+#else
+# include <streams/getmsg.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/getresgid.c b/libc/sysdeps/unix/sysv/linux/i386/getresgid.c
new file mode 100644
index 000000000..393195619
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/getresgid.c
@@ -0,0 +1,85 @@
+/* Copyright (C) 1998,2000,2002,2003,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <linux/posix_types.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_getresgid
+
+# ifdef __NR_getresgid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+# endif /* __NR_getresgid32 */
+
+
+int
+__getresgid (gid_t *rgid, gid_t *egid, gid_t *sgid)
+{
+# if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (getresgid32, 3, CHECK_1 (rgid),
+ CHECK_1 (egid), CHECK_1 (sgid));
+# else
+ __kernel_gid_t k_rgid, k_egid, k_sgid;
+ int result;
+# ifdef __NR_getresgid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int r;
+ int saved_errno = errno;
+
+ r = INLINE_SYSCALL (getresgid32, 3, CHECK_1 (rgid),
+ CHECK_1 (egid), CHECK_1 (sgid));
+ if (r == 0 || errno != ENOSYS)
+ return r;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_getresgid32 */
+
+ result = INLINE_SYSCALL (getresgid, 3, __ptrvalue (&k_rgid),
+ __ptrvalue (&k_egid), __ptrvalue (&k_sgid));
+
+ if (result == 0)
+ {
+ *rgid = (gid_t) k_rgid;
+ *egid = (gid_t) k_egid;
+ *sgid = (gid_t) k_sgid;
+ }
+
+ return result;
+# endif
+}
+libc_hidden_def (__getresgid)
+weak_alias (__getresgid, getresgid)
+
+#else
+# include <posix/getresgid.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/getresuid.c b/libc/sysdeps/unix/sysv/linux/i386/getresuid.c
new file mode 100644
index 000000000..ddd25341b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/getresuid.c
@@ -0,0 +1,84 @@
+/* Copyright (C) 1998,2000,2002,2003,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <linux/posix_types.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_getresuid
+
+# ifdef __NR_getresuid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+# endif /* __NR_getresuid32 */
+
+int
+__getresuid (uid_t *ruid, uid_t *euid, uid_t *suid)
+{
+# if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (getresuid32, 3, CHECK_1 (ruid),
+ CHECK_1 (euid), CHECK_1 (suid));
+# else
+ __kernel_uid_t k_ruid, k_euid, k_suid;
+ int result;
+# ifdef __NR_getresuid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int r;
+ int saved_errno = errno;
+
+ r = INLINE_SYSCALL (getresuid32, 3, CHECK_1 (ruid),
+ CHECK_1 (euid), CHECK_1 (suid));
+ if (r == 0 || errno != ENOSYS)
+ return r;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_getresuid32 */
+
+ result = INLINE_SYSCALL (getresuid, 3, __ptrvalue (&k_ruid),
+ __ptrvalue (&k_euid), __ptrvalue (&k_suid));
+
+ if (result == 0)
+ {
+ *ruid = (uid_t) k_ruid;
+ *euid = (uid_t) k_euid;
+ *suid = (uid_t) k_suid;
+ }
+
+ return result;
+# endif
+}
+libc_hidden_def (__getresuid)
+weak_alias (__getresuid, getresuid)
+
+#else
+# include <posix/getresuid.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/getrlimit.c b/libc/sysdeps/unix/sysv/linux/i386/getrlimit.c
new file mode 100644
index 000000000..59951ac10
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/getrlimit.c
@@ -0,0 +1,82 @@
+/* Copyright (C) 1999, 2000, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/resource.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <shlib-compat.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+extern int __new_getrlimit (enum __rlimit_resource resource,
+ struct rlimit *__unbounded rlimits);
+
+
+/* Linux 2.3.25 introduced a new system call since the types used for
+ the limits are now unsigned. */
+#if defined __NR_ugetrlimit && !defined __ASSUME_NEW_GETRLIMIT_SYSCALL
+int __have_no_new_getrlimit;
+#endif
+
+int
+__new_getrlimit (enum __rlimit_resource resource, struct rlimit *rlimits)
+{
+#ifdef __ASSUME_NEW_GETRLIMIT_SYSCALL
+ return INLINE_SYSCALL (ugetrlimit, 2, resource, CHECK_1 (rlimits));
+#else
+ int result;
+
+# ifdef __NR_ugetrlimit
+ if (__have_no_new_getrlimit <= 0)
+ {
+ result = INLINE_SYSCALL (ugetrlimit, 2, resource, CHECK_1 (rlimits));
+
+ /* If the system call is available remember this fact and return. */
+ if (result != -1 || errno != ENOSYS)
+ {
+ __have_no_new_getrlimit = -1;
+ return result;
+ }
+
+ /* Remember that the system call is not available. */
+ __have_no_new_getrlimit = 1;
+ }
+# endif
+
+ /* Fall back to the old system call. */
+ result = INLINE_SYSCALL (getrlimit, 2, resource, CHECK_1 (rlimits));
+
+ if (result == -1)
+ return result;
+
+ /* We might have to correct the limits values. Since the old values
+ were signed the infinity value is too small. */
+ if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
+ rlimits->rlim_cur = RLIM_INFINITY;
+ if (rlimits->rlim_max == RLIM_INFINITY >> 1)
+ rlimits->rlim_max = RLIM_INFINITY;
+
+ return result;
+#endif
+}
+
+weak_alias (__new_getrlimit, __getrlimit);
+versioned_symbol (libc, __new_getrlimit, getrlimit, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/i386/getrlimit64.c b/libc/sysdeps/unix/sysv/linux/i386/getrlimit64.c
new file mode 100644
index 000000000..2ff175393
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/getrlimit64.c
@@ -0,0 +1,25 @@
+/* Copyright (C) 1999, 2000, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define getrlimit64 __new_getrlimit64
+
+#include <resource/getrlimit64.c>
+
+#undef getrlimit64
+#include <shlib-compat.h>
+versioned_symbol (libc, __new_getrlimit64, getrlimit64, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/i386/getuid.c b/libc/sysdeps/unix/sysv/linux/i386/getuid.c
new file mode 100644
index 000000000..d7be0c3cd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/getuid.c
@@ -0,0 +1,65 @@
+/* Copyright (C) 2000, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_getuid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. This is the definition.
+ -1 if libc does not know yet whether kernel has 32bit uids or not.
+ 0 if it does have them.
+ 1 if it does not have them. */
+int __libc_missing_32bit_uids attribute_hidden = -1;
+# endif
+#endif /* __NR_getuid32 */
+
+uid_t
+__getuid (void)
+{
+ INTERNAL_SYSCALL_DECL (err);
+#if __ASSUME_32BITUIDS > 0
+ /* No error checking. */
+ return INTERNAL_SYSCALL (getuid32, err, 0);
+#else
+# ifdef __NR_getuid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+
+ result = INTERNAL_SYSCALL (getuid32, err, 0);
+ if (! INTERNAL_SYSCALL_ERROR_P (result, err)
+ || INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ return result;
+
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_getuid32 */
+
+ /* No error checking. */
+ return INTERNAL_SYSCALL (getuid, err, 0);
+#endif
+}
+
+weak_alias (__getuid, getuid)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/glob64.c b/libc/sysdeps/unix/sysv/linux/i386/glob64.c
new file mode 100644
index 000000000..18b7f21ae
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/glob64.c
@@ -0,0 +1,54 @@
+#include <dirent.h>
+#include <glob.h>
+#include <sys/stat.h>
+
+#define dirent dirent64
+#define __readdir(dirp) __readdir64 (dirp)
+
+#define glob_t glob64_t
+#define glob(pattern, flags, errfunc, pglob) \
+ __glob64 (pattern, flags, errfunc, pglob)
+#define globfree(pglob) globfree64 (pglob)
+
+#undef stat
+#define stat stat64
+#undef __stat
+#define __stat(file, buf) __xstat64 (_STAT_VER, file, buf)
+
+#define NO_GLOB_PATTERN_P 1
+
+#define COMPILE_GLOB64 1
+
+#include <posix/glob.c>
+
+#include "shlib-compat.h"
+
+libc_hidden_def (globfree64)
+
+versioned_symbol (libc, __glob64, glob64, GLIBC_2_2);
+libc_hidden_ver (__glob64, glob64)
+
+#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+
+#include <sysdeps/unix/sysv/linux/i386/olddirent.h>
+
+int __old_glob64 (__const char *__pattern, int __flags,
+ int (*__errfunc) (__const char *, int),
+ glob64_t *__pglob);
+
+#undef dirent
+#define dirent __old_dirent64
+#undef __readdir
+#define __readdir(dirp) __old_readdir64 (dirp)
+#undef glob
+#define glob(pattern, flags, errfunc, pglob) \
+ __old_glob64 (pattern, flags, errfunc, pglob)
+#define glob_in_dir __old_glob_in_dir
+#define GLOB_ATTRIBUTE attribute_compat_text_section
+
+#define GLOB_ONLY_P 1
+
+#include <posix/glob.c>
+
+compat_symbol (libc, __old_glob64, glob64, GLIBC_2_1);
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/lchown.c b/libc/sysdeps/unix/sysv/linux/i386/lchown.c
new file mode 100644
index 000000000..fbba0bf1d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/lchown.c
@@ -0,0 +1,74 @@
+/* Copyright (C) 2000,2003,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+#ifdef __NR_lchown
+# ifdef __NR_lchown32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+# endif /* __NR_lchown32 */
+
+int
+__lchown (const char *file, uid_t owner, gid_t group)
+{
+# if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (lchown32, 3, CHECK_STRING (file), owner, group);
+# else
+# ifdef __NR_lchown32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+ int saved_errno = errno;
+
+ result = INLINE_SYSCALL (lchown32, 3, CHECK_STRING (file), owner, group);
+ if (result == 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_lchown32 */
+
+ if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return INLINE_SYSCALL (lchown, 3, CHECK_STRING (file), owner, group);
+# endif
+}
+
+weak_alias (__lchown, lchown)
+
+#else
+# include <io/lchown.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/ldconfig.h b/libc/sysdeps/unix/sysv/linux/i386/ldconfig.h
new file mode 100644
index 000000000..671ec69be
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/ldconfig.h
@@ -0,0 +1,25 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/generic/ldconfig.h>
+
+#define SYSDEP_KNOWN_INTERPRETER_NAMES \
+ { "/lib/ld-linux.so.1", FLAG_ELF_LIBC5 },
+#define SYSDEP_KNOWN_LIBRARY_NAMES \
+ { "libc.so.5", FLAG_ELF_LIBC5 }, \
+ { "libm.so.5", FLAG_ELF_LIBC5 },
diff --git a/libc/sysdeps/unix/sysv/linux/i386/lockf64.c b/libc/sysdeps/unix/sysv/linux/i386/lockf64.c
new file mode 100644
index 000000000..8b568ff4a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/lockf64.c
@@ -0,0 +1,194 @@
+/* Copyright (C) 1994,1996,1997,1998,1999,2000,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <sysdep.h>
+
+#include <kernel-features.h>
+
+/* lockf is a simplified interface to fcntl's locking facilities. */
+
+#ifdef __NR_fcntl64
+# if __ASSUME_FCNTL64 == 0
+/* This variable is shared with all files that check for fcntl64. The
+ declaration is in fcntl.c. */
+extern int __have_no_fcntl64;
+# endif
+#endif
+
+int
+lockf64 (int fd, int cmd, off64_t len64)
+{
+#if __ASSUME_FCNTL64 == 0
+ struct flock fl;
+ off_t len = (off_t) len64;
+#endif
+#ifdef __NR_fcntl64
+ struct flock64 fl64;
+ int cmd64;
+#endif
+
+#if __ASSUME_FCNTL64 == 0
+ memset ((char *) &fl, '\0', sizeof (fl));
+
+ /* lockf is always relative to the current file position. */
+ fl.l_whence = SEEK_CUR;
+ fl.l_start = 0;
+ fl.l_len = len;
+#endif
+#ifdef __NR_fcntl64
+# if __ASSUME_FCNTL64 == 0
+ if (!__have_no_fcntl64)
+ {
+# endif
+ memset ((char *) &fl64, '\0', sizeof (fl64));
+ fl64.l_whence = SEEK_CUR;
+ fl64.l_start = 0;
+ fl64.l_len = len64;
+# if __ASSUME_FCNTL64 == 0
+ }
+# endif
+#endif
+
+#if __ASSUME_FCNTL64 == 0 && !defined __NR_fcntl64
+ if (len64 != (off64_t) len)
+ {
+ /* We can't represent the length. */
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+#endif
+ switch (cmd)
+ {
+ case F_TEST:
+ /* Test the lock: return 0 if FD is unlocked or locked by this process;
+ return -1, set errno to EACCES, if another process holds the lock. */
+#if __ASSUME_FCNTL64 > 0
+ fl64.l_type = F_RDLCK;
+ if (INLINE_SYSCALL (fcntl64, 3, fd, F_GETLK64, &fl64) < 0)
+ return -1;
+ if (fl64.l_type == F_UNLCK || fl64.l_pid == __getpid ())
+ return 0;
+ __set_errno (EACCES);
+ return -1;
+#else
+# ifdef __NR_fcntl64
+ if (!__have_no_fcntl64)
+ {
+ int res;
+
+ fl64.l_type = F_RDLCK;
+ res = INLINE_SYSCALL (fcntl64, 3, fd, F_GETLK64, &fl64);
+ /* If errno == ENOSYS try the 32bit interface if len64 can
+ be represented with 32 bits. */
+
+ if (res == 0)
+ {
+ if (fl64.l_type == F_UNLCK || fl64.l_pid == __getpid ())
+ return 0;
+ __set_errno (EACCES);
+ return -1;
+ }
+ else if (errno == ENOSYS)
+ __have_no_fcntl64 = 1;
+ else
+ /* res < 0 && errno != ENOSYS. */
+ return -1;
+ if (len64 != (off64_t) len)
+ {
+ /* We can't represent the length. */
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+ }
+# endif
+ fl.l_type = F_RDLCK;
+ if (__fcntl (fd, F_GETLK, &fl) < 0)
+ return -1;
+ if (fl.l_type == F_UNLCK || fl.l_pid == __getpid ())
+ return 0;
+ __set_errno (EACCES);
+ return -1;
+#endif
+ case F_ULOCK:
+#if __ASSUME_FCNTL64 == 0
+ fl.l_type = F_UNLCK;
+ cmd = F_SETLK;
+#endif
+#ifdef __NR_fcntl64
+ fl64.l_type = F_UNLCK;
+ cmd64 = F_SETLK64;
+#endif
+ break;
+ case F_LOCK:
+#if __ASSUME_FCNTL64 == 0
+ fl.l_type = F_WRLCK;
+ cmd = F_SETLKW;
+#endif
+#ifdef __NR_fcntl64
+ fl64.l_type = F_WRLCK;
+ cmd64 = F_SETLKW64;
+#endif
+ break;
+ case F_TLOCK:
+#if __ASSUME_FCNTL64 == 0
+ fl.l_type = F_WRLCK;
+ cmd = F_SETLK;
+#endif
+#ifdef __NR_fcntl64
+ fl64.l_type = F_WRLCK;
+ cmd64 = F_SETLK64;
+#endif
+ break;
+
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+#if __ASSUME_FCNTL64 > 0
+ return INLINE_SYSCALL (fcntl64, 3, fd, cmd64, &fl64);
+#else
+# ifdef __NR_fcntl64
+
+ if (!__have_no_fcntl64)
+ {
+ int res = INLINE_SYSCALL (fcntl64, 3, fd, cmd64, &fl64);
+
+ /* If errno == ENOSYS try the 32bit interface if len64 can
+ be represented with 32 bits. */
+ if (res == 0 || errno != ENOSYS)
+ return res;
+
+ __have_no_fcntl64 = 1;
+
+ if (len64 != (off64_t) len)
+ {
+ /* We can't represent the length. */
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+ }
+# endif
+ return __fcntl (fd, cmd, &fl);
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/i386/lxstat.c b/libc/sysdeps/unix/sysv/linux/i386/lxstat.c
new file mode 100644
index 000000000..5cc96127b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/lxstat.c
@@ -0,0 +1,101 @@
+/* lxstat using old-style Unix lstat system call.
+ Copyright (C) 1991,1995,1996,1997,1998,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, if xstat == xstat64 we must get rid of the prototype or gcc
+ will complain since they don't strictly match. */
+#define __lxstat64 __lxstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#include <xstatconv.h>
+
+#ifdef __NR_stat64
+# if __ASSUME_STAT64_SYSCALL == 0
+/* The variable is shared between all wrappers around *stat64 calls. */
+extern int __have_no_stat64;
+# endif
+#endif
+
+
+/* Get information about the file NAME in BUF. */
+int
+__lxstat (int vers, const char *name, struct stat *buf)
+{
+#if __ASSUME_STAT64_SYSCALL == 0
+ struct kernel_stat kbuf;
+#endif
+ int result;
+
+ if (vers == _STAT_VER_KERNEL)
+ return INLINE_SYSCALL (lstat, 2, CHECK_STRING (name), CHECK_1 ((struct kernel_stat *) buf));
+
+#if __ASSUME_STAT64_SYSCALL > 0
+ {
+ struct stat64 buf64;
+
+ result = INLINE_SYSCALL (lstat64, 2, CHECK_STRING (name), __ptrvalue (&buf64));
+ if (result == 0)
+ result = __xstat32_conv (vers, &buf64, buf);
+ return result;
+ }
+#else
+
+# if defined __NR_stat64
+ /* To support 32 bit UIDs, we have to use stat64. The normal stat call only returns
+ 16 bit UIDs. */
+ if (! __have_no_stat64)
+ {
+ struct stat64 buf64;
+ result = INLINE_SYSCALL (lstat64, 2, CHECK_STRING (name), __ptrvalue (&buf64));
+
+ if (result == 0)
+ result = __xstat32_conv (vers, &buf64, buf);
+
+ if (result != -1 || errno != ENOSYS)
+ return result;
+
+ __have_no_stat64 = 1;
+ }
+# endif
+
+ result = INLINE_SYSCALL (lstat, 2, CHECK_STRING (name), __ptrvalue (&kbuf));
+ if (result == 0)
+ result = __xstat_conv (vers, &kbuf, buf);
+
+ return result;
+#endif
+}
+
+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/libc/sysdeps/unix/sysv/linux/i386/makecontext.S b/libc/sysdeps/unix/sysv/linux/i386/makecontext.S
new file mode 100644
index 000000000..12ba4e2d6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/makecontext.S
@@ -0,0 +1,117 @@
+/* Create new context.
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__makecontext)
+ movl 4(%esp), %eax
+
+ /* Load the address of the function we are supposed to run. */
+ movl 8(%esp), %ecx
+
+ /* Compute the address of the stack. The information comes from
+ to us_stack element. */
+ movl oSS_SP(%eax), %edx
+ movl %ecx, oEIP(%eax)
+ addl oSS_SIZE(%eax), %edx
+
+ /* Put the next context on the new stack (from the uc_link
+ element). */
+ movl oLINK(%eax), %ecx
+ movl %ecx, -4(%edx)
+
+ /* Remember the number of parameters for the exit handler since
+ it has to remove them. We store the number in the EBX register
+ which the function we will call must preserve. */
+ movl 12(%esp), %ecx
+ movl %ecx, oEBX(%eax)
+
+ /* Make room on the new stack for the parameters. */
+ negl %ecx
+ leal -8(%edx,%ecx,4), %edx
+ negl %ecx
+ /* Store the future stack pointer. */
+ movl %edx, oESP(%eax)
+
+ /* Copy all the parameters. */
+ jecxz 2f
+1: movl 12(%esp,%ecx,4), %eax
+ movl %eax, (%edx,%ecx,4)
+ decl %ecx
+ jnz 1b
+2:
+
+ /* If the function we call returns we must continue with the
+ context which is given in the uc_link element. To do this
+ set the return address for the function the user provides
+ to a little bit of helper code which does the magic (see
+ below). */
+#ifdef PIC
+ call 1f
+ cfi_adjust_cfa_offset (4)
+1: popl %ecx
+ cfi_adjust_cfa_offset (-4)
+ addl $L(exitcode)-1b, %ecx
+ movl %ecx, (%edx)
+#else
+ movl $L(exitcode), (%edx)
+#endif
+ /* 'makecontext' returns no value. */
+ ret
+
+ /* This is the helper code which gets called if a function which
+ is registered with 'makecontext' returns. In this case we
+ have to install the context listed in the uc_link element of
+ the context 'makecontext' manipulated at the time of the
+ 'makecontext' call. If the pointer is NULL the process must
+ terminate. */
+ cfi_endproc
+L(exitcode):
+ /* This removes the parameters passed to the function given to
+ 'makecontext' from the stack. EBX contains the number of
+ parameters (see above). */
+ leal (%esp,%ebx,4), %esp
+
+#ifdef PIC
+ call 1f
+1: popl %ebx
+ addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
+#endif
+ popl %eax /* This is the next context. */
+ testl %eax, %eax
+ je 2f /* If it is zero exit. */
+
+ pushl %eax
+ call JUMPTARGET(__setcontext)
+ /* If this returns (which can happen if the syscall fails) we'll
+ exit the program with the return error value (-1). */
+
+2: pushl %eax
+ call HIDDEN_JUMPTARGET(exit)
+ /* The 'exit' call should never return. In case it does cause
+ the process to terminate. */
+ hlt
+ cfi_startproc
+END(__makecontext)
+
+weak_alias (__makecontext, makecontext)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/mmap.S b/libc/sysdeps/unix/sysv/linux/i386/mmap.S
new file mode 100644
index 000000000..a1481feeb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/mmap.S
@@ -0,0 +1,107 @@
+/* Copyright (C) 1995,96,97,98,99,2000,2002,2005,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include <kernel-features.h>
+
+#define EINVAL 22
+
+ .text
+
+ENTRY (__mmap)
+
+/* I don't think it is worthwhile trying to use mmap2 whenever it
+ is available. Only use it when we are sure the syscall exists. */
+#ifdef __ASSUME_MMAP2_SYSCALL
+
+ /* Save registers. */
+ pushl %ebp
+ cfi_adjust_cfa_offset (4)
+ pushl %ebx
+ cfi_adjust_cfa_offset (4)
+ pushl %esi
+ cfi_adjust_cfa_offset (4)
+ pushl %edi
+ cfi_adjust_cfa_offset (4)
+
+ movl 20(%esp), %ebx
+ cfi_rel_offset (ebx, 8)
+ movl 24(%esp), %ecx
+ movl 28(%esp), %edx
+ movl 32(%esp), %esi
+ cfi_rel_offset (esi, 4)
+ movl 36(%esp), %edi
+ cfi_rel_offset (edi, 0)
+ movl 40(%esp), %ebp
+ cfi_rel_offset (ebp, 12)
+ testl $0xfff, %ebp
+ movl $-EINVAL, %eax
+ jne L(skip)
+ shrl $12, %ebp /* mmap2 takes the offset in pages. */
+
+ movl $SYS_ify(mmap2), %eax /* System call number in %eax. */
+
+ /* Do the system call trap. */
+ ENTER_KERNEL
+L(skip):
+ /* Restore registers. */
+ popl %edi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (edi)
+ popl %esi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (esi)
+ popl %ebx
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebx)
+ popl %ebp
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebp)
+
+#else
+
+ /* Save registers. */
+ movl %ebx, %edx
+ cfi_register (ebx, edx)
+
+ movl $SYS_ify(mmap), %eax /* System call number in %eax. */
+
+ lea 4(%esp), %ebx /* Address of args is 1st arg. */
+
+ /* Do the system call trap. */
+ int $0x80
+
+ /* Restore registers. */
+ movl %edx, %ebx
+ cfi_restore (ebx)
+
+#endif
+
+ /* If 0 > %eax > -4096 there was an error. */
+ cmpl $-4096, %eax
+ ja SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+L(pseudo_end):
+ ret
+
+PSEUDO_END (__mmap)
+
+weak_alias (__mmap, mmap)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/mmap64.S b/libc/sysdeps/unix/sysv/linux/i386/mmap64.S
new file mode 100644
index 000000000..f53e6e8c6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/mmap64.S
@@ -0,0 +1,170 @@
+/* Copyright (C) 1995,96,97,98,99,2000,2002,2005,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <bp-sym.h>
+#include <bp-asm.h>
+
+#include <kernel-features.h>
+
+#define EINVAL 22
+#define ENOSYS 38
+
+#define SVRSP 16 /* saved register space */
+#define PARMS LINKAGE+SVRSP /* space for 4 saved regs */
+#define ADDR PARMS
+#define LEN ADDR+PTR_SIZE
+#define PROT LEN+4
+#define FLAGS PROT+4
+#define FD FLAGS+4
+#define OFFLO FD+4
+#define OFFHI OFFLO+4
+
+ .text
+ENTRY (BP_SYM (__mmap64))
+
+#ifdef __NR_mmap2
+
+ /* Save registers. */
+ pushl %ebp
+ cfi_adjust_cfa_offset (4)
+ pushl %ebx
+ cfi_adjust_cfa_offset (4)
+ pushl %esi
+ cfi_adjust_cfa_offset (4)
+ pushl %edi
+ cfi_adjust_cfa_offset (4)
+
+ movl OFFLO(%esp), %edx
+ movl OFFHI(%esp), %ecx
+ testl $0xfff, %edx
+ jne L(einval)
+ shrdl $12, %ecx, %edx /* mmap2 takes the offset in pages. */
+ shrl $12, %ecx
+ jne L(einval)
+ movl %edx, %ebp
+ cfi_rel_offset (ebp, 12)
+
+ movl ADDR(%esp), %ebx
+ cfi_rel_offset (ebx, 8)
+ movl LEN(%esp), %ecx
+ movl PROT(%esp), %edx
+ movl FLAGS(%esp), %esi
+ cfi_rel_offset (esi, 4)
+ movl FD(%esp), %edi
+ cfi_rel_offset (edi, 0)
+
+ movl $SYS_ify(mmap2), %eax /* System call number in %eax. */
+
+ /* Do the system call trap. */
+L(do_syscall):
+ ENTER_KERNEL
+
+ /* Restore registers. */
+ popl %edi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (edi)
+ popl %esi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (esi)
+ popl %ebx
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebx)
+ popl %ebp
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebp)
+
+#ifndef __ASSUME_MMAP2_SYSCALL
+2:
+ cmp $-ENOSYS, %eax
+ je 3f
+#endif
+
+ /* If 0 > %eax > -4096 there was an error. */
+ cmpl $-4096, %eax
+ ja SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+L(pseudo_end):
+ ret
+
+ cfi_adjust_cfa_offset (16)
+ cfi_rel_offset (ebp, 12)
+ cfi_rel_offset (ebx, 8)
+ cfi_rel_offset (esi, 4)
+ cfi_rel_offset (edi, 0)
+ /* This means the offset value is too large. */
+L(einval):
+ popl %edi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (edi)
+ popl %esi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (esi)
+ popl %ebx
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebx)
+ popl %ebp
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebp)
+ movl $-EINVAL, %eax
+ jmp SYSCALL_ERROR_LABEL
+#endif
+
+#if !defined __ASSUME_MMAP2_SYSCALL || !defined __NR_mmap2
+3:
+ /* Save registers. */
+ movl %ebx, %edx
+ cfi_register (ebx, edx)
+
+ cmpl $0, OFFHI-SVRSP(%esp)
+ jne L(einval2)
+
+ movl $SYS_ify(mmap), %eax /* System call number in %eax. */
+
+ lea ADDR-SVRSP(%esp), %ebx /* Address of args is 1st arg. */
+
+ /* Do the system call trap. */
+ ENTER_KERNEL
+
+ /* Restore registers. */
+ movl %edx, %ebx
+ cfi_restore (ebx)
+
+ /* If 0 > %eax > -4096 there was an error. */
+ cmpl $-4096, %eax
+ ja SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+#ifndef __NR_mmap2
+L(pseudo_end):
+#endif
+ ret
+
+ cfi_register (ebx, edx)
+L(einval2):
+ movl %edx, %ebx
+ cfi_restore (ebx)
+ movl $-EINVAL, %eax
+ jmp SYSCALL_ERROR_LABEL
+#endif
+
+PSEUDO_END (BP_SYM (__mmap64))
+
+weak_alias (BP_SYM (__mmap64), BP_SYM (mmap64))
diff --git a/libc/sysdeps/unix/sysv/linux/i386/msgctl.c b/libc/sysdeps/unix/sysv/linux/i386/msgctl.c
new file mode 100644
index 000000000..afecc49dd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/msgctl.c
@@ -0,0 +1,159 @@
+/* Copyright (C) 1995,1997,1998,2000,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/msg.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <string.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+#include <shlib-compat.h>
+
+struct __old_msqid_ds
+{
+ struct __old_ipc_perm msg_perm; /* structure describing operation permission */
+ struct msg *__unbounded __msg_first; /* pointer to first message on queue */
+ struct msg *__unbounded __msg_last; /* pointer to last message on queue */
+ __time_t msg_stime; /* time of last msgsnd command */
+ __time_t msg_rtime; /* time of last msgrcv command */
+ __time_t msg_ctime; /* time of last change */
+ struct wait_queue *__unbounded __wwait; /* ??? */
+ struct wait_queue *__unbounded __rwait; /* ??? */
+ unsigned short int __msg_cbytes; /* current number of bytes on queue */
+ unsigned short int msg_qnum; /* number of messages currently on queue */
+ unsigned short int msg_qbytes; /* max number of bytes allowed on queue */
+ __ipc_pid_t msg_lspid; /* pid of last msgsnd() */
+ __ipc_pid_t msg_lrpid; /* pid of last msgrcv() */
+};
+
+/* Allows to control internal state and destruction of message queue
+ objects. */
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int __old_msgctl (int, int, struct __old_msqid_ds *);
+#endif
+int __new_msgctl (int, int, struct msqid_ds *);
+
+#ifdef __NR_getuid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int
+attribute_compat_text_section
+__old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
+ msqid, cmd, 0, CHECK_1 (buf));
+}
+compat_symbol (libc, __old_msgctl, msgctl, GLIBC_2_0);
+#endif
+
+int
+__new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
+{
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
+ msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
+#else
+ switch (cmd) {
+ case MSG_STAT:
+ case IPC_STAT:
+ case IPC_SET:
+ break;
+ default:
+ return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
+ msqid, cmd, 0, CHECK_1 (buf));
+ }
+
+ {
+ int result;
+ struct __old_msqid_ds old;
+
+#ifdef __NR_getuid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ if (__libc_missing_32bit_uids < 0)
+ {
+ int save_errno = errno;
+
+ /* Test presence of new IPC by testing for getuid32 syscall. */
+ result = INLINE_SYSCALL (getuid32, 0);
+ if (result == -1 && errno == ENOSYS)
+ __libc_missing_32bit_uids = 1;
+ else
+ __libc_missing_32bit_uids = 0;
+ __set_errno(save_errno);
+ }
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
+ msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
+ return result;
+ }
+ }
+#endif
+ if (cmd == IPC_SET)
+ {
+ old.msg_perm.uid = buf->msg_perm.uid;
+ old.msg_perm.gid = buf->msg_perm.gid;
+ old.msg_perm.mode = buf->msg_perm.mode;
+ old.msg_qbytes = buf->msg_qbytes;
+ if (old.msg_perm.uid != buf->msg_perm.uid ||
+ old.msg_perm.gid != buf->msg_perm.gid ||
+ old.msg_qbytes != buf->msg_qbytes)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
+ msqid, cmd, 0, __ptrvalue (&old));
+ if (result != -1 && cmd != IPC_SET)
+ {
+ memset(buf, 0, sizeof(*buf));
+ buf->msg_perm.__key = old.msg_perm.__key;
+ buf->msg_perm.uid = old.msg_perm.uid;
+ buf->msg_perm.gid = old.msg_perm.gid;
+ buf->msg_perm.cuid = old.msg_perm.cuid;
+ buf->msg_perm.cgid = old.msg_perm.cgid;
+ buf->msg_perm.mode = old.msg_perm.mode;
+ buf->msg_perm.__seq = old.msg_perm.__seq;
+ buf->msg_stime = old.msg_stime;
+ buf->msg_rtime = old.msg_rtime;
+ buf->msg_ctime = old.msg_ctime;
+ buf->__msg_cbytes = old.__msg_cbytes;
+ buf->msg_qnum = old.msg_qnum;
+ buf->msg_qbytes = old.msg_qbytes;
+ buf->msg_lspid = old.msg_lspid;
+ buf->msg_lrpid = old.msg_lrpid;
+ }
+ return result;
+ }
+#endif
+}
+
+versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/i386/olddirent.h b/libc/sysdeps/unix/sysv/linux/i386/olddirent.h
new file mode 100644
index 000000000..f9a79b235
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/olddirent.h
@@ -0,0 +1,44 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef __OLD_DIRENT_H
+#define __OLD_DIRENT_H 1
+
+#include <dirent.h>
+
+struct __old_dirent64
+ {
+ __ino_t d_ino;
+ __off64_t d_off;
+ unsigned short int d_reclen;
+ unsigned char d_type;
+ char d_name[256]; /* We must not include limits.h! */
+ };
+
+/* Now define the internal interfaces. */
+extern struct __old_dirent64 *__old_readdir64 (DIR *__dirp);
+extern int __old_readdir64_r (DIR *__dirp, struct __old_dirent64 *__entry,
+ struct __old_dirent64 **__result);
+extern __ssize_t __old_getdents64 (int __fd, char *__buf, size_t __nbytes)
+ internal_function;
+int __old_scandir64 (__const char * __dir,
+ struct __old_dirent64 *** __namelist,
+ int (*__selector) (__const struct __old_dirent64 *),
+ int (*__cmp) (__const void *, __const void *));
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c b/libc/sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c
new file mode 100644
index 000000000..3947e5988
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 1991, 1995-1999, 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This is a compatibility file. If we don't build the libc with
+ versioning don't compile this file. */
+#include <shlib-compat.h>
+#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
+
+#include <errno.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+
+extern int __new_getrlimit (enum __rlimit_resource, struct rlimit *);
+extern int __old_getrlimit64 (enum __rlimit_resource resource,
+ struct rlimit64 *rlimits);
+
+
+/* Put the soft and hard limits for RESOURCE in *RLIMITS.
+ Returns 0 if successful, -1 if not (and sets errno). */
+int
+attribute_compat_text_section
+__old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
+{
+ struct rlimit rlimits32;
+
+ if (__new_getrlimit (resource, &rlimits32) < 0)
+ return -1;
+
+ if (rlimits32.rlim_cur == RLIM_INFINITY)
+ rlimits->rlim_cur = RLIM64_INFINITY >> 1;
+ else
+ rlimits->rlim_cur = rlimits32.rlim_cur;
+ if (rlimits32.rlim_max == RLIM_INFINITY)
+ rlimits->rlim_max = RLIM64_INFINITY >> 1;
+ else
+ rlimits->rlim_max = rlimits32.rlim_max;
+
+ return 0;
+}
+
+compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
+
+#endif /* SHLIB_COMPAT */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/posix_fadvise64.S b/libc/sysdeps/unix/sysv/linux/i386/posix_fadvise64.S
new file mode 100644
index 000000000..092a3bfb9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/posix_fadvise64.S
@@ -0,0 +1,162 @@
+/* Copyright (C) 1995-2000,2002,2003,2004,2005,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <bp-sym.h>
+#include <bp-asm.h>
+
+#include <kernel-features.h>
+
+#define EINVAL 22
+#define ENOSYS 38
+#define EOVERFLOW 75
+
+#define SVRSP 16 /* saved register space */
+#define PARMS LINKAGE+SVRSP /* space for 4 saved regs */
+#define FD PARMS
+#define OFFLO FD+4
+#define OFFHI OFFLO+4
+#define LENLO OFFHI+4
+#define LENHI LENLO+4
+#define FLAGS LENHI+4
+
+ .text
+ENTRY (BP_SYM (__posix_fadvise64_l64))
+
+#ifdef __NR_fadvise64_64
+
+ /* Save registers. */
+ pushl %ebp
+ cfi_adjust_cfa_offset (4)
+ pushl %ebx
+ cfi_adjust_cfa_offset (4)
+ pushl %esi
+ cfi_adjust_cfa_offset (4)
+ pushl %edi
+ cfi_adjust_cfa_offset (4)
+
+ movl FD(%esp), %ebx
+ cfi_rel_offset (ebx, 8)
+ movl OFFLO(%esp), %ecx
+ movl OFFHI(%esp), %edx
+ movl LENLO(%esp), %esi
+ cfi_rel_offset (esi, 4)
+ movl LENHI(%esp), %edi
+ cfi_rel_offset (edi, 0)
+ movl FLAGS(%esp), %ebp
+ cfi_rel_offset (ebp, 12)
+
+ movl $SYS_ify(fadvise64_64), %eax
+ ENTER_KERNEL
+
+ /* Restore registers. */
+ popl %edi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (edi)
+ popl %esi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (esi)
+ popl %ebx
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebx)
+ popl %ebp
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebp)
+
+#ifndef __ASSUME_FADVISE64_64_SYSCALL
+ cmpl $-ENOSYS, %eax
+ je 1f
+#endif
+
+ /* The function returns zero, or the error number. So all we
+ have to do is negate the value passed back from the kernel. */
+ /* If 0 > %eax > -4096 there was an error. */
+ negl %eax
+
+ /* Successful; return the syscall's value. */
+ ret
+#endif
+
+#if defined __NR_fadvise64 \
+ && (!defined __ASSUME_FADVISE64_64_SYSCALL || !defined __NR_fadvise64_64)
+1: /* Save registers. */
+ pushl %ebx
+ cfi_adjust_cfa_offset (4)
+ pushl %esi
+ cfi_adjust_cfa_offset (4)
+ pushl %edi
+ cfi_adjust_cfa_offset (4)
+
+ /* Overflow check. */
+ cmpl $0, LENHI(%esp)
+ movl $-EOVERFLOW, %eax
+ jne L(overflow)
+
+ movl FD(%esp), %ebx
+ cfi_rel_offset (ebx, 8)
+ movl OFFLO(%esp), %ecx
+ movl OFFHI(%esp), %edx
+ movl LENLO(%esp), %esi
+ cfi_rel_offset (esi, 4)
+ movl FLAGS(%esp), %edi
+ cfi_rel_offset (edi, 0)
+
+ movl $SYS_ify(fadvise64), %eax
+ ENTER_KERNEL
+
+ /* Restore registers. */
+L(overflow):
+ popl %edi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (edi)
+ popl %esi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (esi)
+ popl %ebx
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebx)
+
+ /* If 0 > %eax > -4096 there was an error. */
+ negl %eax
+
+ /* Successful; return the syscall's value. */
+ ret
+#else
+ movl $ENOSYS, %eax
+ ret
+#endif
+
+END (BP_SYM (__posix_fadvise64_l64))
+
+#ifdef __NR_fadvise64
+ .section .text.compat, "ax"
+ENTRY (__posix_fadvise64_l32)
+ DO_CALL (fadvise64, 5)
+ negl %eax
+ ret
+PSEUDO_END_ERRVAL (__posix_fadvise64_l32)
+#else
+ENTRY (BP_SYM (__posix_fadvise64_l32))
+ movl $ENOSYS, %eax
+ ret
+END (BP_SYM (__posix_fadvise64_l32))
+#endif
+
+default_symbol_version (__posix_fadvise64_l64, posix_fadvise64, GLIBC_2.3.3)
+symbol_version (__posix_fadvise64_l32, posix_fadvise64, GLIBC_2.2)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/profil-counter.h b/libc/sysdeps/unix/sysv/linux/i386/profil-counter.h
new file mode 100644
index 000000000..d592a7bd6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/profil-counter.h
@@ -0,0 +1,32 @@
+/* Low-level statistical profiling support function. Linux/i386 version.
+ Copyright (C) 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <signal.h>
+#include <sigcontextinfo.h>
+
+static void
+profil_counter (int signo, const SIGCONTEXT scp)
+{
+ profil_count ((void *) GET_PC (scp));
+
+ /* This is a hack to prevent the compiler from implementing the
+ above function call as a sibcall. The sibcall would overwrite
+ the signal context. */
+ asm volatile ("");
+}
diff --git a/libc/sysdeps/unix/sysv/linux/i386/pselect.c b/libc/sysdeps/unix/sysv/linux/i386/pselect.c
new file mode 100644
index 000000000..264660878
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/pselect.c
@@ -0,0 +1,18 @@
+#include <sys/select.h>
+
+extern int __call_pselect6 (int nfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, const struct timespec *timeout,
+ void *data) attribute_hidden;
+
+
+#define CALL_PSELECT6(nfds, readfds, writefds, exceptfds, timeout, data) \
+ ({ int r = __call_pselect6 (nfds, readfds, writefds, exceptfds, timeout, \
+ data); \
+ if (r < 0 && r > -4096) \
+ { \
+ __set_errno (-r); \
+ r = -1; \
+ } \
+ r; })
+
+#include "../pselect.c"
diff --git a/libc/sysdeps/unix/sysv/linux/i386/putmsg.c b/libc/sysdeps/unix/sysv/linux/i386/putmsg.c
new file mode 100644
index 000000000..04fd159b7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/putmsg.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 1998, 1999, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <stropts.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#ifdef __NR_putpmsg
+int
+putmsg (fildes, ctlptr, dataptr, flags)
+ int fildes;
+ const struct strbuf *ctlptr;
+ const struct strbuf *dataptr;
+ int flags;
+{
+ return INLINE_SYSCALL (putpmsg, 5, fildes, ctlptr, dataptr, -1, flags);
+}
+#else
+# include <streams/putmsg.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/readdir64.c b/libc/sysdeps/unix/sysv/linux/i386/readdir64.c
new file mode 100644
index 000000000..8d3908869
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/readdir64.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define __READDIR __readdir64
+#define __GETDENTS __getdents64
+#define DIRENT_TYPE struct dirent64
+
+#include <sysdeps/unix/readdir.c>
+
+#include <shlib-compat.h>
+
+#undef __READDIR
+#undef __GETDENTS
+#undef DIRENT_TYPE
+
+versioned_symbol (libc, __readdir64, readdir64, GLIBC_2_2);
+
+#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+
+#include <sysdeps/unix/sysv/linux/i386/olddirent.h>
+
+#define __READDIR attribute_compat_text_section __old_readdir64
+#define __GETDENTS __old_getdents64
+#define DIRENT_TYPE struct __old_dirent64
+
+#include <sysdeps/unix/readdir.c>
+
+compat_symbol (libc, __old_readdir64, readdir64, GLIBC_2_1);
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/readdir64_r.c b/libc/sysdeps/unix/sysv/linux/i386/readdir64_r.c
new file mode 100644
index 000000000..c6da57b75
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/readdir64_r.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define __READDIR_R __readdir64_r
+#define __GETDENTS __getdents64
+#define DIRENT_TYPE struct dirent64
+
+#include <sysdeps/unix/readdir_r.c>
+
+#undef __READDIR_R
+#undef __GETDENTS
+#undef DIRENT_TYPE
+
+#include <shlib-compat.h>
+
+versioned_symbol (libc, __readdir64_r, readdir64_r, GLIBC_2_2);
+
+#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+
+#include <sysdeps/unix/sysv/linux/i386/olddirent.h>
+
+#define __READDIR_R attribute_compat_text_section __old_readdir64_r
+#define __GETDENTS __old_getdents64
+#define DIRENT_TYPE struct __old_dirent64
+
+#include <sysdeps/unix/readdir_r.c>
+
+compat_symbol (libc, __old_readdir64_r, readdir64_r, GLIBC_2_1);
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/readelflib.c b/libc/sysdeps/unix/sysv/linux/i386/readelflib.c
new file mode 100644
index 000000000..a6374e61d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/readelflib.c
@@ -0,0 +1,82 @@
+/* Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Jaeger <aj@suse.de>, 1999 and
+ Jakub Jelinek <jakub@redhat.com>, 2000.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+int process_elf32_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+int process_elf64_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+
+/* Returns 0 if everything is ok, != 0 in case of error. */
+int
+process_elf_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname, void *file_contents,
+ size_t file_length)
+{
+ ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
+ int ret;
+
+ if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
+ return process_elf32_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ else
+ {
+ switch (elf_header->e_machine)
+ {
+ case EM_IA_64:
+ case EM_X86_64:
+ break;
+ default:
+ error (0, 0, _("%s is for unknown machine %d.\n"),
+ file_name, elf_header->e_machine);
+ return 1;
+ }
+
+ ret = process_elf64_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ /* IA64/X86-64 64bit libraries are always libc.so.6+. */
+ if (!ret)
+ switch (elf_header->e_machine)
+ {
+ case EM_IA_64:
+ *flag = FLAG_IA64_LIB64|FLAG_ELF_LIBC6;
+ break;
+ case EM_X86_64:
+ *flag = FLAG_X8664_LIB64|FLAG_ELF_LIBC6;
+ break;
+ }
+
+ return ret;
+ }
+}
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf32_file
+#define __ELF_NATIVE_CLASS 32
+#include "elf/readelflib.c"
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf64_file
+#define __ELF_NATIVE_CLASS 64
+#include "elf/readelflib.c"
diff --git a/libc/sysdeps/unix/sysv/linux/i386/register-dump.h b/libc/sysdeps/unix/sysv/linux/i386/register-dump.h
new file mode 100644
index 000000000..05f295ecb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/register-dump.h
@@ -0,0 +1,256 @@
+/* Dump registers.
+ Copyright (C) 1998 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/uio.h>
+#include <stdio-common/_itoa.h>
+
+/* We will print the register dump in this format:
+
+ EAX: XXXXXXXX EBX: XXXXXXXX ECX: XXXXXXXX EDX: XXXXXXXX
+ ESI: XXXXXXXX EDI: XXXXXXXX EBP: XXXXXXXX ESP: XXXXXXXX
+
+ EIP: XXXXXXXX EFLAGS: XXXXXXXX
+
+ CS: XXXX DS: XXXX ES: XXXX FS: XXXX GS: XXXX SS: XXXX
+
+ Trap: XXXXXXXX Error: XXXXXXXX OldMask: XXXXXXXX
+ ESP/SIGNAL: XXXXXXXX CR2: XXXXXXXX
+
+ FPUCW: XXXXXXXX FPUSW: XXXXXXXX TAG: XXXXXXXX
+ IPOFF: XXXXXXXX CSSEL: XXXX DATAOFF: XXXXXXXX DATASEL: XXXX
+
+ ST(0) XXXX XXXXXXXXXXXXXXXX ST(1) XXXX XXXXXXXXXXXXXXXX
+ ST(2) XXXX XXXXXXXXXXXXXXXX ST(3) XXXX XXXXXXXXXXXXXXXX
+ ST(4) XXXX XXXXXXXXXXXXXXXX ST(5) XXXX XXXXXXXXXXXXXXXX
+ ST(6) XXXX XXXXXXXXXXXXXXXX ST(7) XXXX XXXXXXXXXXXXXXXX
+
+ */
+
+static void
+hexvalue (unsigned long int value, char *buf, size_t len)
+{
+ char *cp = _itoa_word (value, buf + len, 16, 0);
+ while (cp > buf)
+ *--cp = '0';
+}
+
+static void
+register_dump (int fd, struct sigcontext *ctx)
+{
+ char regs[21][8];
+ char fpregs[31][8];
+ struct iovec iov[97];
+ size_t nr = 0;
+
+#define ADD_STRING(str) \
+ iov[nr].iov_base = (char *) str; \
+ iov[nr].iov_len = strlen (str); \
+ ++nr
+#define ADD_MEM(str, len) \
+ iov[nr].iov_base = str; \
+ iov[nr].iov_len = len; \
+ ++nr
+
+ /* Generate strings of register contents. */
+ hexvalue (ctx->eax, regs[0], 8);
+ hexvalue (ctx->ebx, regs[1], 8);
+ hexvalue (ctx->ecx, regs[2], 8);
+ hexvalue (ctx->edx, regs[3], 8);
+ hexvalue (ctx->esi, regs[4], 8);
+ hexvalue (ctx->edi, regs[5], 8);
+ hexvalue (ctx->ebp, regs[6], 8);
+ hexvalue (ctx->esp, regs[7], 8);
+ hexvalue (ctx->eip, regs[8], 8);
+ hexvalue (ctx->eflags, regs[9], 8);
+ hexvalue (ctx->cs, regs[10], 4);
+ hexvalue (ctx->ds, regs[11], 4);
+ hexvalue (ctx->es, regs[12], 4);
+ hexvalue (ctx->fs, regs[13], 4);
+ hexvalue (ctx->gs, regs[14], 4);
+ hexvalue (ctx->ss, regs[15], 4);
+ hexvalue (ctx->trapno, regs[16], 8);
+ hexvalue (ctx->err, regs[17], 8);
+ hexvalue (ctx->oldmask, regs[18], 8);
+ hexvalue (ctx->esp_at_signal, regs[19], 8);
+ hexvalue (ctx->cr2, regs[20], 8);
+
+ /* Generate the output. */
+ ADD_STRING ("Register dump:\n\n EAX: ");
+ ADD_MEM (regs[0], 8);
+ ADD_STRING (" EBX: ");
+ ADD_MEM (regs[1], 8);
+ ADD_STRING (" ECX: ");
+ ADD_MEM (regs[2], 8);
+ ADD_STRING (" EDX: ");
+ ADD_MEM (regs[3], 8);
+ ADD_STRING ("\n ESI: ");
+ ADD_MEM (regs[4], 8);
+ ADD_STRING (" EDI: ");
+ ADD_MEM (regs[5], 8);
+ ADD_STRING (" EBP: ");
+ ADD_MEM (regs[6], 8);
+ ADD_STRING (" ESP: ");
+ ADD_MEM (regs[7], 8);
+ ADD_STRING ("\n\n EIP: ");
+ ADD_MEM (regs[8], 8);
+ ADD_STRING (" EFLAGS: ");
+ ADD_MEM (regs[9], 8);
+ ADD_STRING ("\n\n CS: ");
+ ADD_MEM (regs[10], 4);
+ ADD_STRING (" DS: ");
+ ADD_MEM (regs[11], 4);
+ ADD_STRING (" ES: ");
+ ADD_MEM (regs[12], 4);
+ ADD_STRING (" FS: ");
+ ADD_MEM (regs[13], 4);
+ ADD_STRING (" GS: ");
+ ADD_MEM (regs[14], 4);
+ ADD_STRING (" SS: ");
+ ADD_MEM (regs[15], 4);
+ ADD_STRING ("\n\n Trap: ");
+ ADD_MEM (regs[16], 8);
+ ADD_STRING (" Error: ");
+ ADD_MEM (regs[17], 8);
+ ADD_STRING (" OldMask: ");
+ ADD_MEM (regs[18], 8);
+ ADD_STRING ("\n ESP/signal: ");
+ ADD_MEM (regs[19], 8);
+ ADD_STRING (" CR2: ");
+ ADD_MEM (regs[20], 8);
+
+ if (ctx->fpstate != NULL)
+ {
+
+ /* Generate output for the FPU control/status registers. */
+ hexvalue (ctx->fpstate->cw, fpregs[0], 8);
+ hexvalue (ctx->fpstate->sw, fpregs[1], 8);
+ hexvalue (ctx->fpstate->tag, fpregs[2], 8);
+ hexvalue (ctx->fpstate->ipoff, fpregs[3], 8);
+ hexvalue (ctx->fpstate->cssel, fpregs[4], 4);
+ hexvalue (ctx->fpstate->dataoff, fpregs[5], 8);
+ hexvalue (ctx->fpstate->datasel, fpregs[6], 4);
+
+ ADD_STRING ("\n\n FPUCW: ");
+ ADD_MEM (fpregs[0], 8);
+ ADD_STRING (" FPUSW: ");
+ ADD_MEM (fpregs[1], 8);
+ ADD_STRING (" TAG: ");
+ ADD_MEM (fpregs[2], 8);
+ ADD_STRING ("\n IPOFF: ");
+ ADD_MEM (fpregs[3], 8);
+ ADD_STRING (" CSSEL: ");
+ ADD_MEM (fpregs[4], 4);
+ ADD_STRING (" DATAOFF: ");
+ ADD_MEM (fpregs[5], 8);
+ ADD_STRING (" DATASEL: ");
+ ADD_MEM (fpregs[6], 4);
+
+ /* Now the real FPU registers. */
+ hexvalue (ctx->fpstate->_st[0].exponent, fpregs[7], 8);
+ hexvalue (ctx->fpstate->_st[0].significand[3] << 16
+ | ctx->fpstate->_st[0].significand[2], fpregs[8], 8);
+ hexvalue (ctx->fpstate->_st[0].significand[1] << 16
+ | ctx->fpstate->_st[0].significand[0], fpregs[9], 8);
+ hexvalue (ctx->fpstate->_st[1].exponent, fpregs[10], 8);
+ hexvalue (ctx->fpstate->_st[1].significand[3] << 16
+ | ctx->fpstate->_st[1].significand[2], fpregs[11], 8);
+ hexvalue (ctx->fpstate->_st[1].significand[1] << 16
+ | ctx->fpstate->_st[1].significand[0], fpregs[12], 8);
+ hexvalue (ctx->fpstate->_st[2].exponent, fpregs[13], 8);
+ hexvalue (ctx->fpstate->_st[2].significand[3] << 16
+ | ctx->fpstate->_st[2].significand[2], fpregs[14], 8);
+ hexvalue (ctx->fpstate->_st[2].significand[1] << 16
+ | ctx->fpstate->_st[2].significand[0], fpregs[15], 8);
+ hexvalue (ctx->fpstate->_st[3].exponent, fpregs[16], 8);
+ hexvalue (ctx->fpstate->_st[3].significand[3] << 16
+ | ctx->fpstate->_st[3].significand[2], fpregs[17], 8);
+ hexvalue (ctx->fpstate->_st[3].significand[1] << 16
+ | ctx->fpstate->_st[3].significand[0], fpregs[18], 8);
+ hexvalue (ctx->fpstate->_st[4].exponent, fpregs[19], 8);
+ hexvalue (ctx->fpstate->_st[4].significand[3] << 16
+ | ctx->fpstate->_st[4].significand[2], fpregs[20], 8);
+ hexvalue (ctx->fpstate->_st[4].significand[1] << 16
+ | ctx->fpstate->_st[4].significand[0], fpregs[21], 8);
+ hexvalue (ctx->fpstate->_st[5].exponent, fpregs[22], 8);
+ hexvalue (ctx->fpstate->_st[5].significand[3] << 16
+ | ctx->fpstate->_st[5].significand[2], fpregs[23], 8);
+ hexvalue (ctx->fpstate->_st[5].significand[1] << 16
+ | ctx->fpstate->_st[5].significand[0], fpregs[24], 8);
+ hexvalue (ctx->fpstate->_st[6].exponent, fpregs[25], 8);
+ hexvalue (ctx->fpstate->_st[6].significand[3] << 16
+ | ctx->fpstate->_st[6].significand[2], fpregs[26], 8);
+ hexvalue (ctx->fpstate->_st[6].significand[1] << 16
+ | ctx->fpstate->_st[6].significand[0], fpregs[27], 8);
+ hexvalue (ctx->fpstate->_st[7].exponent, fpregs[28], 8);
+ hexvalue (ctx->fpstate->_st[7].significand[3] << 16
+ | ctx->fpstate->_st[7].significand[2], fpregs[29], 8);
+ hexvalue (ctx->fpstate->_st[7].significand[1] << 16
+ | ctx->fpstate->_st[7].significand[0], fpregs[30], 8);
+
+ ADD_STRING ("\n\n ST(0) ");
+ ADD_MEM (fpregs[7], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[8], 8);
+ ADD_MEM (fpregs[9], 8);
+ ADD_STRING (" ST(1) ");
+ ADD_MEM (fpregs[10], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[11], 8);
+ ADD_MEM (fpregs[12], 8);
+ ADD_STRING ("\n ST(2) ");
+ ADD_MEM (fpregs[13], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[14], 8);
+ ADD_MEM (fpregs[15], 8);
+ ADD_STRING (" ST(3) ");
+ ADD_MEM (fpregs[16], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[17], 8);
+ ADD_MEM (fpregs[18], 8);
+ ADD_STRING ("\n ST(4) ");
+ ADD_MEM (fpregs[19], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[20], 8);
+ ADD_MEM (fpregs[21], 8);
+ ADD_STRING (" ST(5) ");
+ ADD_MEM (fpregs[22], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[23], 8);
+ ADD_MEM (fpregs[24], 8);
+ ADD_STRING ("\n ST(6) ");
+ ADD_MEM (fpregs[25], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[26], 8);
+ ADD_MEM (fpregs[27], 8);
+ ADD_STRING (" ST(7) ");
+ ADD_MEM (fpregs[28], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[29], 8);
+ ADD_MEM (fpregs[30], 8);
+ }
+
+ ADD_STRING ("\n");
+
+ /* Write the stuff out. */
+ writev (fd, iov, nr);
+}
+
+
+#define REGISTER_DUMP register_dump (fd, &ctx)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/scandir64.c b/libc/sysdeps/unix/sysv/linux/i386/scandir64.c
new file mode 100644
index 000000000..690be813b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/scandir64.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <dirent.h>
+
+#define SCANDIR __scandir64
+#define READDIR __readdir64
+#define DIRENT_TYPE struct dirent64
+
+#include <dirent/scandir.c>
+
+#undef SCANDIR
+#undef READDIR
+#undef DIRENT_TYPE
+
+#include <shlib-compat.h>
+
+versioned_symbol (libc, __scandir64, scandir64, GLIBC_2_2);
+
+#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+
+#include <sysdeps/unix/sysv/linux/i386/olddirent.h>
+
+#define SCANDIR attribute_compat_text_section __old_scandir64
+#define READDIR __old_readdir64
+#define DIRENT_TYPE struct __old_dirent64
+
+#include <dirent/scandir.c>
+
+compat_symbol (libc, __old_scandir64, scandir64, GLIBC_2_1);
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/semctl.c b/libc/sysdeps/unix/sysv/linux/i386/semctl.c
new file mode 100644
index 000000000..1693cd47c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/semctl.c
@@ -0,0 +1,185 @@
+/* Copyright (C) 1995,1997,1998,2000,2003,2004,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <sys/sem.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <string.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+#include <shlib-compat.h>
+
+struct __old_semid_ds
+{
+ struct __old_ipc_perm sem_perm; /* operation permission struct */
+ __time_t sem_otime; /* last semop() time */
+ __time_t sem_ctime; /* last time changed by semctl() */
+ struct sem *__sembase; /* ptr to first semaphore in array */
+ struct sem_queue *__sem_pending; /* pending operations */
+ struct sem_queue *__sem_pending_last; /* last pending operation */
+ struct sem_undo *__undo; /* ondo requests on this array */
+ unsigned short int sem_nsems; /* number of semaphores in set */
+};
+
+/* Define a `union semun' suitable for Linux here. */
+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 */
+ struct __old_semid_ds *__old_buf;
+};
+
+#include <bp-checks.h>
+#include <bp-semctl.h> /* definition of CHECK_SEMCTL needs union semum */
+
+#ifdef __NR_getuid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif
+
+/* Return identifier for array of NSEMS semaphores associated with
+ KEY. */
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int __old_semctl (int semid, int semnum, int cmd, ...);
+#endif
+int __new_semctl (int semid, int semnum, int cmd, ...);
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int
+attribute_compat_text_section
+__old_semctl (int semid, int semnum, int cmd, ...)
+{
+ union semun arg;
+ va_list ap;
+
+ va_start (ap, cmd);
+
+ /* Get the argument. */
+ arg = va_arg (ap, union semun);
+
+ va_end (ap);
+
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd));
+}
+compat_symbol (libc, __old_semctl, semctl, GLIBC_2_0);
+#endif
+
+int
+__new_semctl (int semid, int semnum, int cmd, ...)
+{
+ union semun arg;
+ va_list ap;
+
+ va_start (ap, cmd);
+
+ /* Get the argument. */
+ arg = va_arg (ap, union semun);
+
+ va_end (ap);
+
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd | __IPC_64,
+ CHECK_SEMCTL (&arg, semid, cmd | __IPC_64));
+#else
+ switch (cmd) {
+ case SEM_STAT:
+ case IPC_STAT:
+ case IPC_SET:
+ break;
+ default:
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd));
+ }
+
+ {
+ int result;
+ struct __old_semid_ds old;
+ struct semid_ds *buf;
+
+#ifdef __NR_getuid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ if (__libc_missing_32bit_uids < 0)
+ {
+ int save_errno = errno;
+
+ /* Test presence of new IPC by testing for getuid32 syscall. */
+ result = INLINE_SYSCALL (getuid32, 0);
+ if (result == -1 && errno == ENOSYS)
+ __libc_missing_32bit_uids = 1;
+ else
+ __libc_missing_32bit_uids = 0;
+ __set_errno(save_errno);
+ }
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd | __IPC_64,
+ CHECK_SEMCTL (&arg, semid, cmd | __IPC_64));
+ return result;
+ }
+ }
+#endif
+
+ buf = arg.buf;
+ arg.__old_buf = &old;
+ if (cmd == IPC_SET)
+ {
+ old.sem_perm.uid = buf->sem_perm.uid;
+ old.sem_perm.gid = buf->sem_perm.gid;
+ old.sem_perm.mode = buf->sem_perm.mode;
+ if (old.sem_perm.uid != buf->sem_perm.uid ||
+ old.sem_perm.gid != buf->sem_perm.gid)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd));
+ if (result != -1 && cmd != IPC_SET)
+ {
+ memset(buf, 0, sizeof(*buf));
+ buf->sem_perm.__key = old.sem_perm.__key;
+ buf->sem_perm.uid = old.sem_perm.uid;
+ buf->sem_perm.gid = old.sem_perm.gid;
+ buf->sem_perm.cuid = old.sem_perm.cuid;
+ buf->sem_perm.cgid = old.sem_perm.cgid;
+ buf->sem_perm.mode = old.sem_perm.mode;
+ buf->sem_perm.__seq = old.sem_perm.__seq;
+ buf->sem_otime = old.sem_otime;
+ buf->sem_ctime = old.sem_ctime;
+ buf->sem_nsems = old.sem_nsems;
+ }
+ return result;
+ }
+#endif
+}
+
+versioned_symbol (libc, __new_semctl, semctl, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/i386/semtimedop.S b/libc/sysdeps/unix/sysv/linux/i386/semtimedop.S
new file mode 100644
index 000000000..0893c6a65
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/semtimedop.S
@@ -0,0 +1,75 @@
+/* Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#define SYSOP_semtimedop 4
+
+#define SVRSP 12 /* saved register space */
+#define PARMS LINKAGE+SVRSP /* space for 3 saved regs */
+#define SEMID PARMS
+#define SOPS SEMID+4
+#define NSOPS SOPS+PTR_SIZE
+#define TIMEOUT NSOPS+4
+
+ .text
+ENTRY (BP_SYM (semtimedop))
+
+ pushl %ebp
+ cfi_adjust_cfa_offset (4)
+ pushl %ebx
+ cfi_adjust_cfa_offset (4)
+ pushl %edi
+ cfi_adjust_cfa_offset (4)
+
+ movl $SYSOP_semtimedop, %ebx
+ cfi_rel_offset (ebx, 4)
+ movl SEMID(%esp), %ecx
+ movl NSOPS(%esp), %edx
+ movl SOPS(%esp), %edi
+ cfi_rel_offset (edi, 0)
+ movl TIMEOUT(%esp), %ebp
+ cfi_rel_offset (ebp, 8)
+ movl $__NR_ipc, %eax
+
+ ENTER_KERNEL
+
+ /* Restore registers. */
+ popl %edi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (edi)
+ popl %ebx
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebx)
+ popl %ebp
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebp)
+
+ /* If 0 > %eax > -4096 there was an error. */
+ cmpl $-4096, %eax
+ ja SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+L(pseudo_end):
+ ret
+
+#ifdef PIC
+ .align 4
+#endif
+PSEUDO_END (BP_SYM (semtimedop))
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setcontext.S b/libc/sysdeps/unix/sysv/linux/i386/setcontext.S
new file mode 100644
index 000000000..bf2d7d2ba
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setcontext.S
@@ -0,0 +1,97 @@
+/* Install given context.
+ Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__setcontext)
+ /* Load address of the context data structure. */
+ movl 4(%esp), %eax
+
+ /* Get the current signal mask. Note that we preserve EBX in case
+ the system call fails and we return from the function with an
+ error. */
+ pushl %ebx
+ cfi_adjust_cfa_offset (4)
+ xorl %edx, %edx
+ leal oSIGMASK(%eax), %ecx
+ movl $SIG_SETMASK, %ebx
+ cfi_rel_offset (ebx, 0)
+ movl $__NR_sigprocmask, %eax
+ ENTER_KERNEL
+ popl %ebx
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebx)
+ cmpl $-4095, %eax /* Check %eax for error. */
+ jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
+
+ /* EAX was modified, reload it. */
+ movl 4(%esp), %eax
+
+ /* Restore the floating-point context. Not the registers, only the
+ rest. */
+ movl oFPREGS(%eax), %ecx
+ fldenv (%ecx)
+
+ /* Restore the FS segment register. We don't touch the GS register
+ since it is used for threads. */
+ movl oFS(%eax), %ecx
+ movw %cx, %fs
+
+ /* Fetch the address to return to. */
+ movl oEIP(%eax), %ecx
+
+ /* Load the new stack pointer. */
+ cfi_def_cfa (eax, 0)
+ cfi_offset (edi, oEDI)
+ cfi_offset (esi, oESI)
+ cfi_offset (ebp, oEBP)
+ cfi_offset (ebx, oEBX)
+ cfi_offset (edx, oEDX)
+ cfi_offset (ecx, oECX)
+ movl oESP(%eax), %esp
+
+ /* Push the return address on the new stack so we can return there. */
+ pushl %ecx
+
+ /* Load the values of all the 32-bit registers (except ESP).
+ Since we are loading from EAX, it must be last. */
+ movl oEDI(%eax), %edi
+ movl oESI(%eax), %esi
+ movl oEBP(%eax), %ebp
+ movl oEBX(%eax), %ebx
+ movl oEDX(%eax), %edx
+ movl oECX(%eax), %ecx
+ movl oEAX(%eax), %eax
+
+ /* End FDE here, we fall into another context. */
+ cfi_endproc
+ cfi_startproc
+
+ /* The following 'ret' will pop the address of the code and jump
+ to it. */
+
+L(pseudo_end):
+ ret
+PSEUDO_END(__setcontext)
+
+weak_alias (__setcontext, setcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setegid.c b/libc/sysdeps/unix/sysv/linux/i386/setegid.c
new file mode 100644
index 000000000..755bc360a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setegid.c
@@ -0,0 +1,62 @@
+/* Copyright (C) 1995-1998,2000,2002,2003,2004,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+#include <kernel-features.h>
+
+
+#ifdef __NR_setresgid
+extern int __setresgid (uid_t rgid, uid_t egid, uid_t sgid);
+#endif
+
+int
+setegid (gid)
+ gid_t gid;
+{
+ int result;
+
+ if (gid == (gid_t) ~0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+#if __ASSUME_32BITUIDS > 0
+ result = INLINE_SETXID_SYSCALL (setresgid32, 3, -1, gid, -1);
+#else
+ /* First try the syscall. */
+# ifdef __NR_setresgid
+ result = __setresgid (-1, gid, -1);
+# if __ASSUME_SETRESGID_SYSCALL > 0
+ if (0)
+# else
+ if (result == -1 && errno == ENOSYS)
+# endif
+ /* No system call available. Use emulation. This may not work
+ since `setregid' also sets the saved user ID when GID is not
+ equal to the real user ID, making it impossible to switch back. */
+# endif
+ result = __setregid (-1, gid);
+#endif
+
+ return result;
+}
+libc_hidden_def (setegid)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/seteuid.c b/libc/sysdeps/unix/sysv/linux/i386/seteuid.c
new file mode 100644
index 000000000..6de173521
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/seteuid.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 1998,2000,2002,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+#include <kernel-features.h>
+
+
+#ifdef __NR_setresuid
+extern int __setresuid (uid_t ruid, uid_t euid, uid_t suid);
+#endif
+
+int
+seteuid (uid_t uid)
+{
+ int result;
+
+ if (uid == (uid_t) ~0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+#if __ASSUME_32BITUIDS > 0
+ result = INLINE_SETXID_SYSCALL (setresuid32, 3, -1, uid, -1);
+#else
+ /* First try the syscall. */
+# ifdef __NR_setresuid
+ result = __setresuid (-1, uid, -1);
+# if __ASSUME_SETRESUID_SYSCALL > 0
+ if (0)
+# else
+ if (result == -1 && errno == ENOSYS)
+# endif
+ /* No system call available. Use emulation. This may not work
+ since `setreuid' also sets the saved user ID when UID is not
+ equal to the real user ID, making it impossible to switch back. */
+# endif
+ result = __setreuid (-1, uid);
+#endif
+
+ return result;
+}
+libc_hidden_def (seteuid)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setfsgid.c b/libc/sysdeps/unix/sysv/linux/i386/setfsgid.c
new file mode 100644
index 000000000..7296d433c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setfsgid.c
@@ -0,0 +1,70 @@
+/* Copyright (C) 1998, 2000, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/fsuid.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+
+#ifdef __NR_setfsgid
+
+# ifdef __NR_setfsgid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids attribute_hidden;
+# endif
+# endif /* __NR_setfsgid32 */
+
+int
+setfsgid (gid_t gid)
+{
+ INTERNAL_SYSCALL_DECL (err);
+# if __ASSUME_32BITUIDS > 0
+ /* No error checking. */
+ return INTERNAL_SYSCALL (setfsgid32, err, 1, gid);
+# else
+# ifdef __NR_setfsgid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+
+ result = INTERNAL_SYSCALL (setfsgid32, err, 1, gid);
+ if (! INTERNAL_SYSCALL_ERROR_P (result, err)
+ || INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ return result;
+
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_setfsgid32 */
+ if (gid != (gid_t) ((__kernel_gid_t) gid))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* No error checking. */
+ return INTERNAL_SYSCALL (setfsgid, err, 1, gid);
+# endif
+}
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setfsuid.c b/libc/sysdeps/unix/sysv/linux/i386/setfsuid.c
new file mode 100644
index 000000000..65ed35348
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setfsuid.c
@@ -0,0 +1,71 @@
+/* Copyright (C) 1998, 2000, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/fsuid.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+#ifdef __NR_setfsuid
+
+# ifdef __NR_setfsuid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids attribute_hidden;
+# endif
+# endif /* __NR_setfsuid32 */
+
+int
+setfsuid (uid_t uid)
+{
+ INTERNAL_SYSCALL_DECL (err);
+# if __ASSUME_32BITUIDS > 0
+ /* No error checking. */
+ return INTERNAL_SYSCALL (setfsuid32, err, 1, uid);
+# else
+# ifdef __NR_setfsuid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+
+ result = INTERNAL_SYSCALL (setfsuid32, err, 1, uid);
+ if (! INTERNAL_SYSCALL_ERROR_P (result, err)
+ || INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ return result;
+
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_setfsuid32 */
+
+ if (uid != (uid_t) ((__kernel_uid_t) uid))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* No error checking. */
+ return INTERNAL_SYSCALL (setfsuid, err, 1, uid);
+# endif
+}
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setgid.c b/libc/sysdeps/unix/sysv/linux/i386/setgid.c
new file mode 100644
index 000000000..208ef25d0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setgid.c
@@ -0,0 +1,76 @@
+/* Copyright (C) 1998, 2000, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+
+#ifdef __NR_setgid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_setgid32 */
+
+int
+__setgid (gid_t gid)
+{
+ int result;
+
+#if __ASSUME_32BITUIDS > 0
+ result = INLINE_SETXID_SYSCALL (setgid32, 1, gid);
+#else
+# ifdef __NR_setgid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int saved_errno = errno;
+
+ result = INLINE_SETXID_SYSCALL (setgid32, 1, gid);
+
+ if (result == 0)
+ goto out;
+ if (errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_setgid32 */
+
+ if (gid == (gid_t) ~0
+ || gid != (gid_t) ((__kernel_gid_t) gid))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ result = INLINE_SETXID_SYSCALL (setgid, 1, gid);
+# ifdef __NR_setgid32
+ out:
+# endif
+#endif
+
+ return result;
+}
+#ifndef __setgid
+weak_alias (__setgid, setgid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setgroups.c b/libc/sysdeps/unix/sysv/linux/i386/setgroups.c
new file mode 100644
index 000000000..10f5b7c91
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setgroups.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 1997,1998,2000,2002,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <grp.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+
+#ifdef __NR_setgroups32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_setgroups32 */
+
+/* Set the group set for the current user to GROUPS (N of them). For
+ Linux we must convert the array of groups into the format that the
+ kernel expects. */
+int
+setgroups (size_t n, const gid_t *groups)
+{
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (setgroups32, 2, n, CHECK_N (groups, n));
+#else
+ if (n > (size_t) __sysconf (_SC_NGROUPS_MAX))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ else
+ {
+ size_t i;
+ __kernel_gid_t kernel_groups[n];
+
+# ifdef __NR_setgroups32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+ int saved_errno = errno;
+
+ result = INLINE_SYSCALL (setgroups32, 2, n, CHECK_N (groups, n));
+ if (result == 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_setgroups32 */
+ for (i = 0; i < n; i++)
+ {
+ kernel_groups[i] = (__ptrvalue (groups))[i];
+ if (groups[i] != (gid_t) ((__kernel_gid_t) groups[i]))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+
+ return INLINE_SYSCALL (setgroups, 2, n, CHECK_N (kernel_groups, n));
+ }
+#endif
+}
+libc_hidden_def (setgroups)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setregid.c b/libc/sysdeps/unix/sysv/linux/i386/setregid.c
new file mode 100644
index 000000000..05e448c6c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setregid.c
@@ -0,0 +1,75 @@
+/* Copyright (C) 1998,2000,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+
+#ifdef __NR_setregid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_setregid32 */
+
+int
+__setregid (gid_t rgid, gid_t egid)
+{
+ int result;
+
+#if __ASSUME_32BITUIDS > 0
+ result = INLINE_SETXID_SYSCALL (setregid32, 2, rgid, egid);
+#else
+# ifdef __NR_setregid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int saved_errno = errno;
+
+ result = INLINE_SETXID_SYSCALL (setregid32, 2, rgid, egid);
+
+ if (result == 0)
+ goto out;
+ if (errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_setregid32 */
+ if (((rgid + 1) > (gid_t) ((__kernel_gid_t) -1U))
+ || ((egid + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ result = INLINE_SETXID_SYSCALL (setregid, 2, rgid, egid);
+# ifdef __NR_setregid32
+ out:
+# endif
+#endif
+
+ return result;
+}
+#ifndef __setregid
+weak_alias (__setregid, setregid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setresgid.c b/libc/sysdeps/unix/sysv/linux/i386/setresgid.c
new file mode 100644
index 000000000..d0750bb20
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setresgid.c
@@ -0,0 +1,86 @@
+/* Copyright (C) 1998,2000,2002,2003,2004,2005,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+
+#if defined __NR_setresgid || defined __NR_setresgid32
+
+# ifdef __NR_setresgid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+# endif /* __NR_setresgid32 */
+
+int
+__setresgid (gid_t rgid, gid_t egid, gid_t sgid)
+{
+ int result;
+
+# if __ASSUME_32BITUIDS > 0 || !defined __NR_setresgid
+ result = INLINE_SETXID_SYSCALL (setresgid32, 3, rgid, egid, sgid);
+# else
+# ifdef __NR_setresgid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int saved_errno = errno;
+
+ result = INLINE_SETXID_SYSCALL (setresgid32, 3, rgid, egid, sgid);
+ if (result == 0)
+ goto out;
+ if (errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_setresgid32 */
+
+ if (((rgid + 1) > (gid_t) ((__kernel_gid_t) -1U))
+ || ((egid + 1) > (gid_t) ((__kernel_gid_t) -1U))
+ || ((sgid + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ result = INLINE_SETXID_SYSCALL (setresgid, 3, rgid, egid, sgid);
+# ifdef __NR_setresgid32
+ out:
+# endif
+# endif
+
+ return result;
+}
+libc_hidden_def (__setresgid)
+#ifndef __setresgid
+weak_alias (__setresgid, setresgid)
+#endif
+
+#else
+
+#include <posix/setresgid.c>
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setresuid.c b/libc/sysdeps/unix/sysv/linux/i386/setresuid.c
new file mode 100644
index 000000000..0a676e53a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setresuid.c
@@ -0,0 +1,86 @@
+/* Copyright (C) 1998,2000,2002,2003,2004,2005,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+
+#if defined __NR_setresuid || defined __NR_setresuid32
+
+# ifdef __NR_setresuid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+# endif /* __NR_setresuid32 */
+
+int
+__setresuid (uid_t ruid, uid_t euid, uid_t suid)
+{
+ int result;
+
+# if __ASSUME_32BITUIDS > 0 || !defined __NR_setresuid
+ result = INLINE_SETXID_SYSCALL (setresuid32, 3, ruid, euid, suid);
+# else
+# ifdef __NR_setresuid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int saved_errno = errno;
+
+ result = INLINE_SETXID_SYSCALL (setresuid32, 3, ruid, euid, suid);
+ if (result == 0)
+ goto out;
+ if (errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_setresuid32 */
+
+ if (((ruid + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((euid + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((suid + 1) > (uid_t) ((__kernel_uid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ result = INLINE_SETXID_SYSCALL (setresuid, 3, ruid, euid, suid);
+# ifdef __NR_setresuid32
+ out:
+# endif
+# endif
+
+ return result;
+}
+libc_hidden_def (__setresuid)
+#ifndef __setresuid
+weak_alias (__setresuid, setresuid)
+#endif
+
+#else
+
+#include <posix/setresuid.c>
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setreuid.c b/libc/sysdeps/unix/sysv/linux/i386/setreuid.c
new file mode 100644
index 000000000..1ea449616
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setreuid.c
@@ -0,0 +1,75 @@
+/* Copyright (C) 1998,2000,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+
+#ifdef __NR_setreuid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_setreuid32 */
+
+int
+__setreuid (uid_t ruid, uid_t euid)
+{
+ int result;
+
+#if __ASSUME_32BITUIDS > 0
+ result = INLINE_SETXID_SYSCALL (setreuid32, 2, ruid, euid);
+#else
+# ifdef __NR_setreuid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int saved_errno = errno;
+
+ result = INLINE_SETXID_SYSCALL (setreuid32, 2, ruid, euid);
+
+ if (result == 0)
+ goto out;
+ if (errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_setreuid32 */
+ if (((ruid + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((euid + 1) > (uid_t) ((__kernel_uid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ result = INLINE_SETXID_SYSCALL (setreuid, 2, ruid, euid);
+# ifdef __NR_setreuid32
+ out:
+# endif
+#endif
+
+ return result;
+}
+#ifndef __setreuid
+weak_alias (__setreuid, setreuid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setrlimit.c b/libc/sysdeps/unix/sysv/linux/i386/setrlimit.c
new file mode 100644
index 000000000..e7e517d91
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setrlimit.c
@@ -0,0 +1,78 @@
+/* Copyright (C) 1999, 2000, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/param.h>
+#include <sys/resource.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <shlib-compat.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+extern int __new_setrlimit (enum __rlimit_resource resource,
+ const struct rlimit *__unboundedrlimits);
+
+/* Linux 2.3.25 introduced a new system call since the types used for
+ the limits are now unsigned. */
+#if defined __NR_ugetrlimit && !defined __ASSUME_NEW_GETRLIMIT_SYSCALL
+extern int __have_no_new_getrlimit; /* from getrlimit.c */
+#endif
+
+int
+__new_setrlimit (enum __rlimit_resource resource, const struct rlimit *rlimits)
+{
+#ifdef __ASSUME_NEW_GETRLIMIT_SYSCALL
+ return INLINE_SYSCALL (setrlimit, 2, resource, CHECK_1 (rlimits));
+#else
+ struct rlimit rlimits_small;
+
+# ifdef __NR_ugetrlimit
+ if (__have_no_new_getrlimit == 0)
+ {
+ /* Check if the new ugetrlimit syscall exists. We must do this
+ first because older kernels don't reject negative rlimit
+ values in setrlimit. */
+ int result = INLINE_SYSCALL (ugetrlimit, 2, resource, __ptrvalue (&rlimits_small));
+ if (result != -1 || errno != ENOSYS)
+ /* The syscall exists. */
+ __have_no_new_getrlimit = -1;
+ else
+ /* The syscall does not exist. */
+ __have_no_new_getrlimit = 1;
+ }
+ if (__have_no_new_getrlimit < 0)
+ return INLINE_SYSCALL (setrlimit, 2, resource, CHECK_1 (rlimits));
+# endif
+
+ /* We might have to correct the limits values. Since the old values
+ were signed the new values might be too large. */
+ rlimits_small.rlim_cur = MIN ((unsigned long int) rlimits->rlim_cur,
+ RLIM_INFINITY >> 1);
+ rlimits_small.rlim_max = MIN ((unsigned long int) rlimits->rlim_max,
+ RLIM_INFINITY >> 1);
+
+ /* Use the adjusted values. */
+ return INLINE_SYSCALL (setrlimit, 2, resource, __ptrvalue (&rlimits_small));
+#endif
+}
+
+weak_alias (__new_setrlimit, __setrlimit);
+versioned_symbol (libc, __new_setrlimit, setrlimit, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/i386/setuid.c b/libc/sysdeps/unix/sysv/linux/i386/setuid.c
new file mode 100644
index 000000000..21c5bcd61
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/setuid.c
@@ -0,0 +1,75 @@
+/* Copyright (C) 1998,2000,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+
+#ifdef __NR_setuid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_setuid32 */
+
+int
+__setuid (uid_t uid)
+{
+ int result;
+
+#if __ASSUME_32BITUIDS > 0 && defined __NR_setuid32
+ result = INLINE_SETXID_SYSCALL (setuid32, 1, uid);
+#else
+# ifdef __NR_setuid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int saved_errno = errno;
+
+ result = INLINE_SETXID_SYSCALL (setuid32, 1, uid);
+ if (result == 0)
+ goto out;
+ if (errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_setuid32 */
+
+ if (uid == (uid_t) ~0
+ || uid != (uid_t) ((__kernel_uid_t) uid))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ result = INLINE_SETXID_SYSCALL (setuid, 1, uid);
+# ifdef __NR_setuid32
+ out:
+# endif
+#endif
+
+ return result;
+}
+#ifndef __setuid
+weak_alias (__setuid, setuid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/shmctl.c b/libc/sysdeps/unix/sysv/linux/i386/shmctl.c
new file mode 100644
index 000000000..2cc039996
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/shmctl.c
@@ -0,0 +1,178 @@
+/* Copyright (C) 1995,1997,1998,2000,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/shm.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <string.h>
+#include <sys/syscall.h>
+#include <bits/wordsize.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+#include <shlib-compat.h>
+
+struct __old_shmid_ds
+{
+ struct __old_ipc_perm shm_perm; /* operation permission struct */
+ int shm_segsz; /* size of segment in bytes */
+ __time_t shm_atime; /* time of last shmat() */
+ __time_t shm_dtime; /* time of last shmdt() */
+ __time_t shm_ctime; /* time of last change by shmctl() */
+ __ipc_pid_t shm_cpid; /* pid of creator */
+ __ipc_pid_t shm_lpid; /* pid of last shmop */
+ unsigned short int shm_nattch; /* number of current attaches */
+ unsigned short int __shm_npages; /* size of segment (pages) */
+ unsigned long int *__unbounded __shm_pages; /* array of ptrs to frames -> SHMMAX */
+ struct vm_area_struct *__unbounded __attaches; /* descriptors for attaches */
+};
+
+struct __old_shminfo
+{
+ int shmmax;
+ int shmmin;
+ int shmmni;
+ int shmseg;
+ int shmall;
+};
+
+#ifdef __NR_getuid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif
+
+/* Provide operations to control over shared memory segments. */
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int __old_shmctl (int, int, struct __old_shmid_ds *);
+#endif
+int __new_shmctl (int, int, struct shmid_ds *);
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int
+attribute_compat_text_section
+__old_shmctl (int shmid, int cmd, struct __old_shmid_ds *buf)
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_shmctl,
+ shmid, cmd, 0, CHECK_1 (buf));
+}
+compat_symbol (libc, __old_shmctl, shmctl, GLIBC_2_0);
+#endif
+
+int
+__new_shmctl (int shmid, int cmd, struct shmid_ds *buf)
+{
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (ipc, 5, IPCOP_shmctl,
+ shmid, cmd | __IPC_64, 0, CHECK_1 (buf));
+#else
+ switch (cmd) {
+ case SHM_STAT:
+ case IPC_STAT:
+ case IPC_SET:
+# if __WORDSIZE != 32
+ case IPC_INFO:
+# endif
+ break;
+ default:
+ return INLINE_SYSCALL (ipc, 5, IPCOP_shmctl,
+ shmid, cmd, 0, CHECK_1 (buf));
+ }
+
+ {
+ struct __old_shmid_ds old;
+ int result;
+
+# ifdef __NR_getuid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ if (__libc_missing_32bit_uids < 0)
+ {
+ int save_errno = errno;
+
+ /* Test presence of new IPC by testing for getuid32 syscall. */
+ result = INLINE_SYSCALL (getuid32, 0);
+ if (result == -1 && errno == ENOSYS)
+ __libc_missing_32bit_uids = 1;
+ else
+ __libc_missing_32bit_uids = 0;
+ __set_errno(save_errno);
+ }
+ if (__libc_missing_32bit_uids <= 0)
+ return INLINE_SYSCALL (ipc, 5, IPCOP_shmctl,
+ shmid, cmd | __IPC_64, 0, CHECK_1 (buf));
+ }
+# endif
+
+ if (cmd == IPC_SET)
+ {
+ old.shm_perm.uid = buf->shm_perm.uid;
+ old.shm_perm.gid = buf->shm_perm.gid;
+ old.shm_perm.mode = buf->shm_perm.mode;
+ if (old.shm_perm.uid != buf->shm_perm.uid ||
+ old.shm_perm.gid != buf->shm_perm.gid)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_shmctl,
+ shmid, cmd, 0, __ptrvalue (&old));
+ if (result != -1 && (cmd == SHM_STAT || cmd == IPC_STAT))
+ {
+ memset(buf, 0, sizeof(*buf));
+ buf->shm_perm.__key = old.shm_perm.__key;
+ buf->shm_perm.uid = old.shm_perm.uid;
+ buf->shm_perm.gid = old.shm_perm.gid;
+ buf->shm_perm.cuid = old.shm_perm.cuid;
+ buf->shm_perm.cgid = old.shm_perm.cgid;
+ buf->shm_perm.mode = old.shm_perm.mode;
+ buf->shm_perm.__seq = old.shm_perm.__seq;
+ buf->shm_atime = old.shm_atime;
+ buf->shm_dtime = old.shm_dtime;
+ buf->shm_ctime = old.shm_ctime;
+ buf->shm_segsz = old.shm_segsz;
+ buf->shm_nattch = old.shm_nattch;
+ buf->shm_cpid = old.shm_cpid;
+ buf->shm_lpid = old.shm_lpid;
+ }
+# if __WORDSIZE != 32
+ else if (result != -1 && cmd == IPC_INFO)
+ {
+ struct __old_shminfo *oldi = (struct __old_shminfo *)&old;
+ struct shminfo *i = (struct shminfo *)buf;
+
+ memset(i, 0, sizeof(*i));
+ i->shmmax = oldi->shmmax;
+ i->shmmin = oldi->shmmin;
+ i->shmmni = oldi->shmmni;
+ i->shmseg = oldi->shmseg;
+ i->shmall = oldi->shmall;
+ }
+# endif
+ return result;
+ }
+#endif
+}
+
+versioned_symbol (libc, __new_shmctl, shmctl, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sigaction.c b/libc/sysdeps/unix/sysv/linux/i386/sigaction.c
new file mode 100644
index 000000000..299574dac
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sigaction.c
@@ -0,0 +1,204 @@
+/* POSIX.1 `sigaction' call for Linux/i386.
+ Copyright (C) 1991,1995-2000,2002-2004,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <stddef.h>
+#include <signal.h>
+#include <string.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <ldsodefs.h>
+
+#include <kernel-features.h>
+
+/* The difference here is that the sigaction structure used in the
+ kernel is not the same as we use in the libc. Therefore we must
+ translate it here. */
+#include <kernel_sigaction.h>
+
+/* We do not globally define the SA_RESTORER flag so do it here. */
+#define SA_RESTORER 0x04000000
+
+
+#if __ASSUME_REALTIME_SIGNALS == 0
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. */
+int __libc_missing_rt_sigs;
+#endif
+
+/* Using the hidden attribute here does not change the code but it
+ helps to avoid warnings. */
+#if defined HAVE_HIDDEN && defined HAVE_VISIBILITY_ATTRIBUTE \
+ && !defined HAVE_BROKEN_VISIBILITY_ATTRIBUTE
+# ifdef __NR_rt_sigaction
+extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
+# endif
+extern void restore (void) asm ("__restore") attribute_hidden;
+#else
+# ifdef __NR_rt_sigaction
+static void restore_rt (void) asm ("__restore_rt");
+# endif
+static void restore (void) asm ("__restore");
+#endif
+
+
+/* If ACT is not NULL, change the action for SIG to *ACT.
+ If OACT is not NULL, put the old action for SIG in *OACT. */
+int
+__libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
+{
+#if __ASSUME_REALTIME_SIGNALS == 0
+ struct old_kernel_sigaction k_newact, k_oldact;
+#endif
+ int result;
+
+#ifdef __NR_rt_sigaction
+
+ /* First try the RT signals. */
+# if __ASSUME_REALTIME_SIGNALS == 0
+ if (!__libc_missing_rt_sigs)
+# endif
+ {
+ struct kernel_sigaction kact, koact;
+# if __ASSUME_REALTIME_SIGNALS == 0
+ int saved_errno = errno;
+# endif
+
+ if (act)
+ {
+ kact.k_sa_handler = act->sa_handler;
+ kact.sa_flags = act->sa_flags;
+ memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
+
+ if (GLRO(dl_sysinfo_dso) == NULL)
+ {
+ kact.sa_flags |= SA_RESTORER;
+
+ kact.sa_restorer = ((act->sa_flags & SA_SIGINFO)
+ ? &restore_rt : &restore);
+ }
+ }
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ result = INLINE_SYSCALL (rt_sigaction, 4,
+ sig, act ? __ptrvalue (&kact) : NULL,
+ oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
+
+# if __ASSUME_REALTIME_SIGNALS == 0
+ if (result >= 0 || errno != ENOSYS)
+# endif
+ {
+ if (oact && result >= 0)
+ {
+ oact->sa_handler = koact.k_sa_handler;
+ memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
+ oact->sa_flags = koact.sa_flags;
+ oact->sa_restorer = koact.sa_restorer;
+ }
+ return result;
+ }
+
+# if __ASSUME_REALTIME_SIGNALS == 0
+ __set_errno (saved_errno);
+ __libc_missing_rt_sigs = 1;
+# endif
+ }
+#endif
+
+#if __ASSUME_REALTIME_SIGNALS == 0
+ if (act)
+ {
+ k_newact.k_sa_handler = act->sa_handler;
+ k_newact.sa_mask = act->sa_mask.__val[0];
+ k_newact.sa_flags = act->sa_flags | SA_RESTORER;
+
+ k_newact.sa_restorer = &restore;
+ }
+
+ result = INLINE_SYSCALL (sigaction, 3, sig,
+ act ? __ptrvalue (&k_newact) : 0,
+ oact ? __ptrvalue (&k_oldact) : 0);
+
+ if (result < 0)
+ return -1;
+
+ if (oact)
+ {
+ oact->sa_handler = k_oldact.k_sa_handler;
+ oact->sa_mask.__val[0] = k_oldact.sa_mask;
+ oact->sa_flags = k_oldact.sa_flags;
+ oact->sa_restorer = k_oldact.sa_restorer;
+ }
+
+ return 0;
+#endif
+}
+libc_hidden_def (__libc_sigaction)
+
+#ifdef WRAPPER_INCLUDE
+# include WRAPPER_INCLUDE
+#endif
+
+#ifndef LIBC_SIGACTION
+weak_alias (__libc_sigaction, __sigaction)
+libc_hidden_weak (__sigaction)
+weak_alias (__libc_sigaction, sigaction)
+#endif
+
+/* NOTE: Please think twice before making any changes to the bits of
+ code below. GDB needs some intimate knowledge about it to
+ recognize them as signal trampolines, and make backtraces through
+ signal handlers work right. Important are both the names
+ (__restore and __restore_rt) and the exact instruction sequence.
+ If you ever feel the need to make any changes, please notify the
+ appropriate GDB maintainer. */
+
+#define RESTORE(name, syscall) RESTORE2 (name, syscall)
+#define RESTORE2(name, syscall) \
+asm \
+ ( \
+ ".text\n" \
+ " .align 16\n" \
+ "__" #name ":\n" \
+ " movl $" #syscall ", %eax\n" \
+ " int $0x80" \
+ );
+
+#ifdef __NR_rt_sigaction
+/* The return code for realtime-signals. */
+RESTORE (restore_rt, __NR_rt_sigreturn)
+#endif
+
+/* For the boring old signals. */
+#undef RESTORE2
+#define RESTORE2(name, syscall) \
+asm \
+ ( \
+ ".text\n" \
+ " .align 8\n" \
+ "__" #name ":\n" \
+ " popl %eax\n" \
+ " movl $" #syscall ", %eax\n" \
+ " int $0x80" \
+ );
+
+RESTORE (restore, __NR_sigreturn)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sigcontextinfo.h b/libc/sysdeps/unix/sysv/linux/i386/sigcontextinfo.h
new file mode 100644
index 000000000..6530ba6f3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sigcontextinfo.h
@@ -0,0 +1,51 @@
+/* Copyright (C) 1998, 1999, 2001 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define SIGCONTEXT struct sigcontext
+#define SIGCONTEXT_EXTRA_ARGS
+#define GET_PC(ctx) ((void *) ctx.eip)
+#define GET_FRAME(ctx) ((void *) ctx.ebp)
+#define GET_STACK(ctx) ((void *) ctx.esp_at_signal)
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+do { \
+ int __tmp1, __tmp2, __tmp3, __tmp4; \
+ __asm __volatile ("movl\t%%esp, %%edi\n\t" \
+ "andl\t$-16, %%esp\n\t" \
+ "subl\t%8, %%esp\n\t" \
+ "movl\t%%edi, %c8-4(%%esp)\n\t" \
+ "movl\t%1, 0(%%esp)\n\t" \
+ "leal\t4(%%esp), %%edi\n\t" \
+ "cld\n\t" \
+ "rep\tmovsl\n\t" \
+ "call\t*%0\n\t" \
+ "cld\n\t" \
+ "movl\t%9, %%ecx\n\t" \
+ "subl\t%%edi, %%esi\n\t" \
+ "leal\t4(%%esp,%%esi,1), %%edi\n\t" \
+ "leal\t4(%%esp), %%esi\n\t" \
+ "rep\tmovsl\n\t" \
+ "movl\t%c8-4(%%esp), %%esp\n\t" \
+ : "=a" (__tmp1), "=d" (__tmp2), "=S" (__tmp3), \
+ "=c" (__tmp4) \
+ : "0" (handler), "1" (signo), "2" (&ctx), \
+ "3" (sizeof (struct sigcontext) / 4), \
+ "n" ((sizeof (struct sigcontext) + 19) & ~15), \
+ "i" (sizeof (struct sigcontext) / 4) \
+ : "cc", "edi"); \
+} while (0)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/socket.S b/libc/sysdeps/unix/sysv/linux/i386/socket.S
new file mode 100644
index 000000000..7c8ac29b8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/socket.S
@@ -0,0 +1,124 @@
+/* Copyright (C) 1995-1998,2002,2003,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+#include <tls.h>
+
+#define P(a, b) P2(a, b)
+#define P2(a, b) a##b
+
+ .text
+/* The socket-oriented system calls are handled unusally in Linux.
+ They are all gated through the single `socketcall' system call number.
+ `socketcall' takes two arguments: the first is the subcode, specifying
+ which socket function is being called; and the second is a pointer to
+ the arguments to the specific function.
+
+ The .S files for the other calls just #define socket and #include this. */
+
+#ifndef __socket
+# ifndef NO_WEAK_ALIAS
+# define __socket P(__,socket)
+# else
+# define __socket socket
+# endif
+#endif
+
+.globl __socket
+ENTRY (__socket)
+#if defined NEED_CANCELLATION && defined CENABLE
+ SINGLE_THREAD_P
+ jne 1f
+#endif
+
+ /* Save registers. */
+ movl %ebx, %edx
+ cfi_register (3, 2)
+
+ movl $SYS_ify(socketcall), %eax /* System call number in %eax. */
+
+ /* Use ## so `socket' is a separate token that might be #define'd. */
+ movl $P(SOCKOP_,socket), %ebx /* Subcode is first arg to syscall. */
+ lea 4(%esp), %ecx /* Address of args is 2nd arg. */
+
+ /* Do the system call trap. */
+ ENTER_KERNEL
+
+ /* Restore registers. */
+ movl %edx, %ebx
+ cfi_restore (3)
+
+ /* %eax is < 0 if there was an error. */
+ cmpl $-125, %eax
+ jae SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+L(pseudo_end):
+ ret
+
+
+#if defined NEED_CANCELLATION && defined CENABLE
+ /* We need one more register. */
+1: pushl %esi
+ cfi_adjust_cfa_offset(4)
+
+ /* Enable asynchronous cancellation. */
+ CENABLE
+ movl %eax, %esi
+ cfi_offset(6, -8) /* %esi */
+
+ /* Save registers. */
+ movl %ebx, %edx
+ cfi_register (3, 2)
+
+ movl $SYS_ify(socketcall), %eax /* System call number in %eax. */
+
+ /* Use ## so `socket' is a separate token that might be #define'd. */
+ movl $P(SOCKOP_,socket), %ebx /* Subcode is first arg to syscall. */
+ lea 8(%esp), %ecx /* Address of args is 2nd arg. */
+
+ /* Do the system call trap. */
+ ENTER_KERNEL
+
+ /* Restore registers. */
+ movl %edx, %ebx
+ cfi_restore (3)
+
+ /* Restore the cancellation. */
+ xchgl %esi, %eax
+ CDISABLE
+
+ /* Restore registers. */
+ movl %esi, %eax
+ popl %esi
+ cfi_restore (6)
+ cfi_adjust_cfa_offset(-4)
+
+ /* %eax is < 0 if there was an error. */
+ cmpl $-125, %eax
+ jae SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+ ret
+#endif
+PSEUDO_END (__socket)
+
+#ifndef NO_WEAK_ALIAS
+weak_alias (__socket, socket)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/swapcontext.S b/libc/sysdeps/unix/sysv/linux/i386/swapcontext.S
new file mode 100644
index 000000000..27c16200b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/swapcontext.S
@@ -0,0 +1,112 @@
+/* Save current context and install the given one.
+ Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__swapcontext)
+ /* Load address of the context data structure we save in. */
+ movl 4(%esp), %eax
+
+ /* Return value of swapcontext. EAX is the only register whose
+ value is not preserved. */
+ movl $0, oEAX(%eax)
+
+ /* Save the 32-bit register values and the return address. */
+ movl %ecx, oECX(%eax)
+ movl %edx, oEDX(%eax)
+ movl %edi, oEDI(%eax)
+ movl %esi, oESI(%eax)
+ movl %ebp, oEBP(%eax)
+ movl (%esp), %ecx
+ movl %ecx, oEIP(%eax)
+ leal 4(%esp), %ecx
+ movl %ecx, oESP(%eax)
+ movl %ebx, oEBX(%eax)
+
+ /* Save the FS segment register. */
+ xorl %edx, %edx
+ movw %fs, %dx
+ movl %edx, oFS(%eax)
+
+ /* We have separate floating-point register content memory on the
+ stack. We use the __fpregs_mem block in the context. Set the
+ links up correctly. */
+ leal oFPREGSMEM(%eax), %ecx
+ movl %ecx, oFPREGS(%eax)
+ /* Save the floating-point context. */
+ fnstenv (%ecx)
+
+ /* Load address of the context data structure we have to load. */
+ movl 8(%esp), %ecx
+
+ /* Save the current signal mask and install the new one. */
+ pushl %ebx
+ leal oSIGMASK(%eax), %edx
+ leal oSIGMASK(%ecx), %ecx
+ movl $SIG_SETMASK, %ebx
+ movl $__NR_sigprocmask, %eax
+ ENTER_KERNEL
+ popl %ebx
+ cmpl $-4095, %eax /* Check %eax for error. */
+ jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
+
+ /* EAX was modified, reload it. */
+ movl 8(%esp), %eax
+
+ /* Restore the floating-point context. Not the registers, only the
+ rest. */
+ movl oFPREGS(%eax), %ecx
+ fldenv (%ecx)
+
+ /* Restore the FS segment register. We don't touch the GS register
+ since it is used for threads. */
+ movl oFS(%eax), %edx
+ movw %dx, %fs
+
+ /* Fetch the address to return to. */
+ movl oEIP(%eax), %ecx
+
+ /* Load the new stack pointer. */
+ movl oESP(%eax), %esp
+
+ /* Push the return address on the new stack so we can return there. */
+ pushl %ecx
+
+ /* Load the values of all the 32-bit registers (except ESP).
+ Since we are loading from EAX, it must be last. */
+ movl oEDI(%eax), %edi
+ movl oESI(%eax), %esi
+ movl oEBP(%eax), %ebp
+ movl oEBX(%eax), %ebx
+ movl oEDX(%eax), %edx
+ movl oECX(%eax), %ecx
+ movl oEAX(%eax), %eax
+
+ /* The following 'ret' will pop the address of the code and jump
+ to it. */
+
+L(pseudo_end):
+ ret
+PSEUDO_END(__swapcontext)
+
+weak_alias (__swapcontext, swapcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sync_file_range.S b/libc/sysdeps/unix/sysv/linux/i386/sync_file_range.S
new file mode 100644
index 000000000..f39e8a00d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sync_file_range.S
@@ -0,0 +1,72 @@
+/* Selective file content synch'ing.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+
+ .text
+ENTRY (sync_file_range)
+#ifdef __NR_sync_file_range
+ pushl %ebx
+ cfi_adjust_cfa_offset (4)
+ pushl %esi
+ cfi_adjust_cfa_offset (4)
+ pushl %edi
+ cfi_adjust_cfa_offset (4)
+ pushl %ebp
+ cfi_adjust_cfa_offset (4)
+
+ movl 20(%esp), %ebx
+ cfi_rel_offset (ebx, 12)
+ movl 24(%esp), %ecx
+ movl 28(%esp), %edx
+ movl 32(%esp), %esi
+ cfi_rel_offset (esi, 8)
+ movl 36(%esp), %edi
+ cfi_rel_offset (edi, 4)
+ movl 40(%esp), %ebp
+ cfi_rel_offset (ebp, 0)
+
+ movl $SYS_ify(sync_file_range), %eax
+ ENTER_KERNEL
+
+ popl %ebp
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebp)
+ popl %edi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (edi)
+ popl %esi
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (esi)
+ popl %ebx
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebx)
+
+ cmpl $-4095, %eax
+ jae SYSCALL_ERROR_LABEL
+L(pseudo_end):
+ ret
+#else
+ movl $-ENOSYS, %eax
+ jmp SYSCALL_ERROR_LABEL
+#endif
+PSEUDO_END (sync_file_range)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sys/debugreg.h b/libc/sysdeps/unix/sysv/linux/i386/sys/debugreg.h
new file mode 100644
index 000000000..c99c94359
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sys/debugreg.h
@@ -0,0 +1,91 @@
+/* Copyright (C) 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_DEBUGREG_H
+#define _SYS_DEBUGREG_H 1
+
+/* Indicate the register numbers for a number of the specific
+ debug registers. Registers 0-3 contain the addresses we wish to trap on */
+#define DR_FIRSTADDR 0 /* u_debugreg[DR_FIRSTADDR] */
+#define DR_LASTADDR 3 /* u_debugreg[DR_LASTADDR] */
+
+#define DR_STATUS 6 /* u_debugreg[DR_STATUS] */
+#define DR_CONTROL 7 /* u_debugreg[DR_CONTROL] */
+
+/* Define a few things for the status register. We can use this to determine
+ which debugging register was responsible for the trap. The other bits
+ are either reserved or not of interest to us. */
+
+#define DR_TRAP0 (0x1) /* db0 */
+#define DR_TRAP1 (0x2) /* db1 */
+#define DR_TRAP2 (0x4) /* db2 */
+#define DR_TRAP3 (0x8) /* db3 */
+
+#define DR_STEP (0x4000) /* single-step */
+#define DR_SWITCH (0x8000) /* task switch */
+
+/* Now define a bunch of things for manipulating the control register.
+ The top two bytes of the control register consist of 4 fields of 4
+ bits - each field corresponds to one of the four debug registers,
+ and indicates what types of access we trap on, and how large the data
+ field is that we are looking at */
+
+#define DR_CONTROL_SHIFT 16 /* Skip this many bits in ctl register */
+#define DR_CONTROL_SIZE 4 /* 4 control bits per register */
+
+#define DR_RW_EXECUTE (0x0) /* Settings for the access types to trap on */
+#define DR_RW_WRITE (0x1)
+#define DR_RW_READ (0x3)
+
+#define DR_LEN_1 (0x0) /* Settings for data length to trap on */
+#define DR_LEN_2 (0x4)
+#define DR_LEN_4 (0xC)
+
+/* The low byte to the control register determine which registers are
+ enabled. There are 4 fields of two bits. One bit is "local", meaning
+ that the processor will reset the bit after a task switch and the other
+ is global meaning that we have to explicitly reset the bit. With linux,
+ you can use either one, since we explicitly zero the register when we enter
+ kernel mode. */
+
+#define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit */
+#define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit */
+#define DR_ENABLE_SIZE 2 /* 2 enable bits per register */
+
+#define DR_LOCAL_ENABLE_MASK (0x55) /* Set local bits for all 4 regs */
+#define DR_GLOBAL_ENABLE_MASK (0xAA) /* Set global bits for all 4 regs */
+
+/* The second byte to the control register has a few special things.
+
+ On the i386, you should set the DR_LOCAL_SLOWDOWN or
+ DR_GLOBAL_SLOWDOWN bits if you want to know exactly which
+ instruction triggered the watchpoint. Setting these bits causes
+ the processor to run more slowly, but leaving them clear makes it
+ treat watchpoint hits as imprecise exceptions, so you can't
+ reliably determine which instruction caused the hit.
+
+ The i486 and all later IA-32 processors ignore DR_LOCAL_SLOWDOWN
+ and DR_GLOBAL_SLOWDOWN. They always report the exception
+ precisely, except in some rare cases, which the user can't do
+ anything about. */
+
+#define DR_CONTROL_RESERVED (0xFC00) /* Reserved by Intel */
+#define DR_LOCAL_SLOWDOWN (0x100) /* Local slow the pipeline */
+#define DR_GLOBAL_SLOWDOWN (0x200) /* Global slow the pipeline */
+
+#endif /* sys/debugreg.h */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sys/elf.h b/libc/sysdeps/unix/sysv/linux/i386/sys/elf.h
new file mode 100644
index 000000000..d959cdca1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sys/elf.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_ELF_H
+#define _SYS_ELF_H 1
+
+#warning "This header is obsolete; use <sys/procfs.h> instead."
+
+#include <sys/procfs.h>
+
+#endif /* _SYS_ELF_H */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sys/io.h b/libc/sysdeps/unix/sysv/linux/i386/sys/io.h
new file mode 100644
index 000000000..39a7877f7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sys/io.h
@@ -0,0 +1,181 @@
+/* Copyright (C) 1996, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IO_H
+#define _SYS_IO_H 1
+
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* If TURN_ON is TRUE, request for permission to do direct i/o on the
+ port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
+ permission off for that range. This call requires root privileges.
+
+ Portability note: not all Linux platforms support this call. Most
+ platforms based on the PC I/O architecture probably will, however.
+ E.g., Linux/Alpha for Alpha PCs supports this. */
+extern int ioperm (unsigned long int __from, unsigned long int __num,
+ int __turn_on) __THROW;
+
+/* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
+ access any I/O port is granted. This call requires root
+ privileges. */
+extern int iopl (int __level) __THROW;
+
+#if defined __GNUC__ && __GNUC__ >= 2
+
+static __inline unsigned char
+inb (unsigned short int port)
+{
+ unsigned char _v;
+
+ __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned char
+inb_p (unsigned short int port)
+{
+ unsigned char _v;
+
+ __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned short int
+inw (unsigned short int port)
+{
+ unsigned short _v;
+
+ __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned short int
+inw_p (unsigned short int port)
+{
+ unsigned short int _v;
+
+ __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned int
+inl (unsigned short int port)
+{
+ unsigned int _v;
+
+ __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned int
+inl_p (unsigned short int port)
+{
+ unsigned int _v;
+ __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline void
+outb (unsigned char value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
+}
+
+static __inline void
+outb_p (unsigned char value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
+ "Nd" (port));
+}
+
+static __inline void
+outw (unsigned short int value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
+
+}
+
+static __inline void
+outw_p (unsigned short int value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
+ "Nd" (port));
+}
+
+static __inline void
+outl (unsigned int value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
+}
+
+static __inline void
+outl_p (unsigned int value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
+ "Nd" (port));
+}
+
+static __inline void
+insb (unsigned short int port, void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+static __inline void
+insw (unsigned short int port, void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+static __inline void
+insl (unsigned short int port, void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+static __inline void
+outsb (unsigned short int port, const void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+static __inline void
+outsw (unsigned short int port, const void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+static __inline void
+outsl (unsigned short int port, const void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+#endif /* GNU C */
+
+__END_DECLS
+#endif /* _SYS_IO_H */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sys/perm.h b/libc/sysdeps/unix/sysv/linux/i386/sys/perm.h
new file mode 100644
index 000000000..e389e6679
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sys/perm.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 1996, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PERM_H
+
+#define _SYS_PERM_H 1
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* Set port input/output permissions. */
+extern int ioperm (unsigned long int __from, unsigned long int __num,
+ int __turn_on) __THROW;
+
+
+/* Change I/O privilege level. */
+extern int iopl (int __level) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_PERM_H */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sys/procfs.h b/libc/sysdeps/unix/sysv/linux/i386/sys/procfs.h
new file mode 100644
index 000000000..f0be43309
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sys/procfs.h
@@ -0,0 +1,131 @@
+/* Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H 1
+
+/* This is somewhat modelled after the file of the same name on SVR4
+ systems. It provides a definition of the core file format for ELF
+ used on Linux. It doesn't have anything to do with the /proc file
+ system, even though Linux has one.
+
+ Anyway, the whole purpose of this file is for GDB and GDB only.
+ Don't read too much into it. Don't use it for anything other than
+ GDB unless you know what you are doing. */
+
+#include <features.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/user.h>
+
+__BEGIN_DECLS
+
+/* Type for a general-purpose register. */
+typedef unsigned long elf_greg_t;
+
+/* And the whole bunch of them. We could have used `struct
+ user_regs_struct' directly in the typedef, but tradition says that
+ the register set is an array, which does have some peculiar
+ semantics, so leave it that way. */
+#define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof(elf_greg_t))
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+/* Register set for the floating-point registers. */
+typedef struct user_fpregs_struct elf_fpregset_t;
+
+/* Register set for the extended floating-point registers. Includes
+ the Pentium III SSE registers in addition to the classic
+ floating-point stuff. */
+typedef struct user_fpxregs_struct elf_fpxregset_t;
+
+
+/* Signal info. */
+struct elf_siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_code; /* Extra code. */
+ int si_errno; /* Errno. */
+ };
+
+
+/* Definitions to generate Intel SVR4-like core files. These mostly
+ have the same names as the SVR4 types with "elf_" tacked on the
+ front to prevent clashes with Linux definitions, and the typedef
+ forms have been avoided. This is mostly like the SVR4 structure,
+ but more Linuxy, with things that Linux does not support and which
+ GDB doesn't really use excluded. */
+
+struct elf_prstatus
+ {
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned long int pr_sigpend; /* Set of pending signals. */
+ unsigned long int pr_sighold; /* Set of held signals. */
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct timeval pr_utime; /* User time. */
+ struct timeval pr_stime; /* System time. */
+ struct timeval pr_cutime; /* Cumulative user time. */
+ struct timeval pr_cstime; /* Cumulative system time. */
+ elf_gregset_t pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+
+#define ELF_PRARGSZ (80) /* Number of chars for args. */
+
+struct elf_prpsinfo
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned long int pr_flag; /* Flags. */
+ unsigned short int pr_uid;
+ unsigned short int pr_gid;
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+
+/* The rest of this file provides the types for emulation of the
+ Solaris <proc_service.h> interfaces that should be implemented by
+ users of libthread_db. */
+
+/* Addresses. */
+typedef void *psaddr_t;
+
+/* Register sets. Linux has different names. */
+typedef elf_gregset_t prgregset_t;
+typedef elf_fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+ therefore have only one PID type. */
+typedef __pid_t lwpid_t;
+
+/* Process status and info. In the end we do provide typedefs for them. */
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+__END_DECLS
+
+#endif /* sys/procfs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sys/reg.h b/libc/sysdeps/unix/sysv/linux/i386/sys/reg.h
new file mode 100644
index 000000000..39003c45b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sys/reg.h
@@ -0,0 +1,43 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_REG_H
+#define _SYS_REG_H 1
+
+/* Index into an array of 4 byte integers returned from ptrace for
+ * location of the users' stored general purpose registers. */
+
+#define EBX 0
+#define ECX 1
+#define EDX 2
+#define ESI 3
+#define EDI 4
+#define EBP 5
+#define EAX 6
+#define DS 7
+#define ES 8
+#define FS 9
+#define GS 10
+#define ORIG_EAX 11
+#define EIP 12
+#define CS 13
+#define EFL 14
+#define UESP 15
+#define SS 16
+
+#endif /* _SYS_REG_H */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sys/ucontext.h b/libc/sysdeps/unix/sysv/linux/i386/sys/ucontext.h
new file mode 100644
index 000000000..d6474c722
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sys/ucontext.h
@@ -0,0 +1,129 @@
+/* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+
+#include <features.h>
+#include <signal.h>
+
+/* We need the signal context definitions even if they are not used
+ included in <signal.h>. */
+#include <bits/sigcontext.h>
+
+
+/* Type for general register. */
+typedef int greg_t;
+
+/* Number of general registers. */
+#define NGREG 19
+
+/* Container for all general registers. */
+typedef greg_t gregset_t[NGREG];
+
+#ifdef __USE_GNU
+/* Number of each register is the `gregset_t' array. */
+enum
+{
+ REG_GS = 0,
+# define REG_GS REG_GS
+ REG_FS,
+# define REG_FS REG_FS
+ REG_ES,
+# define REG_ES REG_ES
+ REG_DS,
+# define REG_DS REG_DS
+ REG_EDI,
+# define REG_EDI REG_EDI
+ REG_ESI,
+# define REG_ESI REG_ESI
+ REG_EBP,
+# define REG_EBP REG_EBP
+ REG_ESP,
+# define REG_ESP REG_ESP
+ REG_EBX,
+# define REG_EBX REG_EBX
+ REG_EDX,
+# define REG_EDX REG_EDX
+ REG_ECX,
+# define REG_ECX REG_ECX
+ REG_EAX,
+# define REG_EAX REG_EAX
+ REG_TRAPNO,
+# define REG_TRAPNO REG_TRAPNO
+ REG_ERR,
+# define REG_ERR REG_ERR
+ REG_EIP,
+# define REG_EIP REG_EIP
+ REG_CS,
+# define REG_CS REG_CS
+ REG_EFL,
+# define REG_EFL REG_EFL
+ REG_UESP,
+# define REG_UESP REG_UESP
+ REG_SS
+# define REG_SS REG_SS
+};
+#endif
+
+/* Definitions taken from the kernel headers. */
+struct _libc_fpreg
+{
+ unsigned short int significand[4];
+ unsigned short int exponent;
+};
+
+struct _libc_fpstate
+{
+ unsigned long int cw;
+ unsigned long int sw;
+ unsigned long int tag;
+ unsigned long int ipoff;
+ unsigned long int cssel;
+ unsigned long int dataoff;
+ unsigned long int datasel;
+ struct _libc_fpreg _st[8];
+ unsigned long int status;
+};
+
+/* Structure to describe FPU registers. */
+typedef struct _libc_fpstate *fpregset_t;
+
+/* Context to describe whole processor state. */
+typedef struct
+ {
+ gregset_t gregs;
+ /* Due to Linux's history we have to use a pointer here. The SysV/i386
+ ABI requires a struct with the values. */
+ fpregset_t fpregs;
+ unsigned long int oldmask;
+ unsigned long int cr2;
+ } mcontext_t;
+
+/* Userlevel context. */
+typedef struct ucontext
+ {
+ unsigned long int uc_flags;
+ struct ucontext *uc_link;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ __sigset_t uc_sigmask;
+ struct _libc_fpstate __fpregs_mem;
+ } ucontext_t;
+
+#endif /* sys/ucontext.h */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sys/user.h b/libc/sysdeps/unix/sysv/linux/i386/sys/user.h
new file mode 100644
index 000000000..aca46e7d3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sys/user.h
@@ -0,0 +1,103 @@
+/* Copyright (C) 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_USER_H
+#define _SYS_USER_H 1
+
+/* The whole purpose of this file is for GDB and GDB only. Don't read
+ too much into it. Don't use it for anything other than GDB unless
+ you know what you are doing. */
+
+struct user_fpregs_struct
+{
+ long int cwd;
+ long int swd;
+ long int twd;
+ long int fip;
+ long int fcs;
+ long int foo;
+ long int fos;
+ long int st_space [20];
+};
+
+struct user_fpxregs_struct
+{
+ unsigned short int cwd;
+ unsigned short int swd;
+ unsigned short int twd;
+ unsigned short int fop;
+ long int fip;
+ long int fcs;
+ long int foo;
+ long int fos;
+ long int mxcsr;
+ long int reserved;
+ long int st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
+ long int xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
+ long int padding[56];
+};
+
+struct user_regs_struct
+{
+ long int ebx;
+ long int ecx;
+ long int edx;
+ long int esi;
+ long int edi;
+ long int ebp;
+ long int eax;
+ long int xds;
+ long int xes;
+ long int xfs;
+ long int xgs;
+ long int orig_eax;
+ long int eip;
+ long int xcs;
+ long int eflags;
+ long int esp;
+ long int xss;
+};
+
+struct user
+{
+ struct user_regs_struct regs;
+ int u_fpvalid;
+ struct user_fpregs_struct i387;
+ unsigned long int u_tsize;
+ unsigned long int u_dsize;
+ unsigned long int u_ssize;
+ unsigned long start_code;
+ unsigned long start_stack;
+ long int signal;
+ int reserved;
+ struct user_regs_struct* u_ar0;
+ struct user_fpregs_struct* u_fpstate;
+ unsigned long int magic;
+ char u_comm [32];
+ int u_debugreg [8];
+};
+
+#define PAGE_SHIFT 12
+#define PAGE_SIZE (1UL << PAGE_SHIFT)
+#define PAGE_MASK (~(PAGE_SIZE-1))
+#define NBPG PAGE_SIZE
+#define UPAGES 1
+#define HOST_TEXT_START_ADDR (u.start_code)
+#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
+
+#endif /* _SYS_USER_H */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sys/vm86.h b/libc/sysdeps/unix/sysv/linux/i386/sys/vm86.h
new file mode 100644
index 000000000..4c5152c2e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sys/vm86.h
@@ -0,0 +1,35 @@
+/* Copyright (C) 1996, 1999, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_VM86_H
+
+#define _SYS_VM86_H 1
+#include <features.h>
+
+/* Get constants and data types from kernel header file. */
+#include <asm/vm86.h>
+
+__BEGIN_DECLS
+
+/* Enter virtual 8086 mode. */
+extern int vm86 (unsigned long int __subfunction,
+ struct vm86plus_struct *__info) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_VM86_H */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/syscall.S b/libc/sysdeps/unix/sysv/linux/i386/syscall.S
new file mode 100644
index 000000000..b569650b2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/syscall.S
@@ -0,0 +1,37 @@
+/* Copyright (C) 1995, 1996, 1998, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* Please consult the file sysdeps/unix/sysv/linux/i386/sysdep.h for
+ more information about the value -4095 used below.*/
+
+ .text
+ENTRY (syscall)
+
+ PUSHARGS_6 /* Save register contents. */
+ _DOARGS_6(44) /* Load arguments. */
+ movl 20(%esp), %eax /* Load syscall number into %eax. */
+ ENTER_KERNEL /* Do the system call. */
+ POPARGS_6 /* Restore register contents. */
+ cmpl $-4095, %eax /* Check %eax for error. */
+ jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
+L(pseudo_end):
+ ret /* Return to caller. */
+
+PSEUDO_END (syscall)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/syscalls.list b/libc/sysdeps/unix/sysv/linux/i386/syscalls.list
new file mode 100644
index 000000000..3ff3a73aa
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/syscalls.list
@@ -0,0 +1,8 @@
+# File name Caller Syscall name Args Strong name Weak names
+
+modify_ldt EXTRA modify_ldt i:ipi __modify_ldt modify_ldt
+vm86old EXTRA vm86old i:p __vm86old vm86@GLIBC_2.0
+vm86 - vm86 i:ip __vm86 vm86@@GLIBC_2.3.4
+oldgetrlimit EXTRA getrlimit i:ip __old_getrlimit getrlimit@GLIBC_2.0
+oldsetrlimit EXTRA setrlimit i:ip __old_setrlimit setrlimit@GLIBC_2.0
+waitpid - waitpid Ci:ipi __waitpid waitpid __libc_waitpid
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sysconf.c b/libc/sysdeps/unix/sysv/linux/i386/sysconf.c
new file mode 100644
index 000000000..25b9ba734
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sysconf.c
@@ -0,0 +1,410 @@
+/* Get file-specific information about a file. Linux version.
+ Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <hp-timing.h>
+
+static long int linux_sysconf (int name);
+
+
+static long int __attribute__ ((noinline))
+handle_i486 (int name)
+{
+ /* The processor only has a unified level 1 cache of 8k. */
+ switch (name)
+ {
+ case _SC_LEVEL1_ICACHE_SIZE:
+ case _SC_LEVEL1_DCACHE_SIZE:
+ return 8 * 1024;
+
+ case _SC_LEVEL1_ICACHE_ASSOC:
+ case _SC_LEVEL1_DCACHE_ASSOC:
+ // XXX Anybody know this?
+ return 0;
+
+ case _SC_LEVEL1_ICACHE_LINESIZE:
+ case _SC_LEVEL1_DCACHE_LINESIZE:
+ // XXX Anybody know for sure?
+ return 16;
+
+ case _SC_LEVEL2_CACHE_SIZE:
+ case _SC_LEVEL2_CACHE_ASSOC:
+ case _SC_LEVEL2_CACHE_LINESIZE:
+ case _SC_LEVEL3_CACHE_SIZE:
+ case _SC_LEVEL3_CACHE_ASSOC:
+ case _SC_LEVEL3_CACHE_LINESIZE:
+ case _SC_LEVEL4_CACHE_SIZE:
+ case _SC_LEVEL4_CACHE_ASSOC:
+ /* Not available. */
+ break;
+
+ default:
+ assert (! "cannot happen");
+ }
+
+ return -1;
+}
+
+
+static const struct intel_02_cache_info
+{
+ unsigned int idx;
+ int name;
+ long int size;
+ long int assoc;
+ long int linesize;
+} intel_02_known[] =
+ {
+ { 0x06, _SC_LEVEL1_ICACHE_SIZE, 8192, 4, 32 },
+ { 0x08, _SC_LEVEL1_ICACHE_SIZE, 16384, 4, 32 },
+ { 0x0a, _SC_LEVEL1_DCACHE_SIZE, 8192, 2, 32 },
+ { 0x0c, _SC_LEVEL1_DCACHE_SIZE, 16384, 4, 32 },
+ { 0x22, _SC_LEVEL3_CACHE_SIZE, 524288, 4, 64 },
+ { 0x23, _SC_LEVEL3_CACHE_SIZE, 1048576, 8, 64 },
+ { 0x25, _SC_LEVEL3_CACHE_SIZE, 2097152, 8, 64 },
+ { 0x29, _SC_LEVEL3_CACHE_SIZE, 4194304, 8, 64 },
+ { 0x2c, _SC_LEVEL1_DCACHE_SIZE, 32768, 8, 64 },
+ { 0x30, _SC_LEVEL1_ICACHE_SIZE, 32768, 8, 64 },
+ { 0x39, _SC_LEVEL2_CACHE_SIZE, 131072, 4, 64 },
+ { 0x3a, _SC_LEVEL2_CACHE_SIZE, 196608, 6, 64 },
+ { 0x3b, _SC_LEVEL2_CACHE_SIZE, 131072, 2, 64 },
+ { 0x3c, _SC_LEVEL2_CACHE_SIZE, 262144, 4, 64 },
+ { 0x3d, _SC_LEVEL2_CACHE_SIZE, 393216, 6, 64 },
+ { 0x3e, _SC_LEVEL2_CACHE_SIZE, 524288, 4, 64 },
+ { 0x41, _SC_LEVEL2_CACHE_SIZE, 131072, 4, 32 },
+ { 0x42, _SC_LEVEL2_CACHE_SIZE, 262144, 4, 32 },
+ { 0x43, _SC_LEVEL2_CACHE_SIZE, 524288, 4, 32 },
+ { 0x44, _SC_LEVEL2_CACHE_SIZE, 1048576, 4, 32 },
+ { 0x45, _SC_LEVEL2_CACHE_SIZE, 2097152, 4, 32 },
+ { 0x46, _SC_LEVEL3_CACHE_SIZE, 4194304, 4, 64 },
+ { 0x47, _SC_LEVEL3_CACHE_SIZE, 8388608, 8, 64 },
+ { 0x49, _SC_LEVEL3_CACHE_SIZE, 4194304, 16, 64 },
+ { 0x4a, _SC_LEVEL3_CACHE_SIZE, 6291456, 12, 64 },
+ { 0x4b, _SC_LEVEL3_CACHE_SIZE, 8388608, 16, 64 },
+ { 0x4c, _SC_LEVEL3_CACHE_SIZE, 12582912, 12, 64 },
+ { 0x4d, _SC_LEVEL3_CACHE_SIZE, 16777216, 16, 64 },
+ { 0x60, _SC_LEVEL1_DCACHE_SIZE, 16384, 8, 64 },
+ { 0x66, _SC_LEVEL1_DCACHE_SIZE, 8192, 4, 64 },
+ { 0x67, _SC_LEVEL1_DCACHE_SIZE, 16384, 4, 64 },
+ { 0x68, _SC_LEVEL1_DCACHE_SIZE, 32768, 4, 64 },
+ { 0x78, _SC_LEVEL2_CACHE_SIZE, 1048576, 8, 64 },
+ { 0x79, _SC_LEVEL2_CACHE_SIZE, 131072, 8, 64 },
+ { 0x7a, _SC_LEVEL2_CACHE_SIZE, 262144, 8, 64 },
+ { 0x7b, _SC_LEVEL2_CACHE_SIZE, 524288, 8, 64 },
+ { 0x7c, _SC_LEVEL2_CACHE_SIZE, 1048576, 8, 64 },
+ { 0x7d, _SC_LEVEL2_CACHE_SIZE, 2097152, 8, 64 },
+ { 0x7f, _SC_LEVEL2_CACHE_SIZE, 524288, 2, 64 },
+ { 0x82, _SC_LEVEL2_CACHE_SIZE, 262144, 8, 32 },
+ { 0x83, _SC_LEVEL2_CACHE_SIZE, 524288, 8, 32 },
+ { 0x84, _SC_LEVEL2_CACHE_SIZE, 1048576, 8, 32 },
+ { 0x85, _SC_LEVEL2_CACHE_SIZE, 2097152, 8, 32 },
+ { 0x86, _SC_LEVEL2_CACHE_SIZE, 524288, 4, 64 },
+ { 0x87, _SC_LEVEL2_CACHE_SIZE, 1048576, 8, 64 },
+ };
+#define nintel_02_known (sizeof (intel_02_known) / sizeof (intel_02_known[0]))
+
+
+static int
+intel_02_known_compare (const void *p1, const void *p2)
+{
+ const struct intel_02_cache_info *i1;
+ const struct intel_02_cache_info *i2;
+
+ i1 = (const struct intel_02_cache_info *) p1;
+ i2 = (const struct intel_02_cache_info *) p2;
+
+ if (i1->idx == i2->idx)
+ return 0;
+
+ return i1->idx < i2->idx ? -1 : 1;
+}
+
+
+static long int
+intel_check_word (int name, unsigned int value, bool *has_level_2,
+ bool *no_level_2_or_3)
+{
+ if ((value & 0x80000000) != 0)
+ /* The register value is reserved. */
+ return 0;
+
+ /* Fold the name. The _SC_ constants are always in the order SIZE,
+ ASSOC, LINESIZE. */
+ int folded_name = (_SC_LEVEL1_ICACHE_SIZE
+ + ((name - _SC_LEVEL1_ICACHE_SIZE) / 3) * 3);
+
+ while (value != 0)
+ {
+ unsigned int byte = value & 0xff;
+
+ if (byte == 0x40)
+ {
+ *no_level_2_or_3 = true;
+
+ if (folded_name == _SC_LEVEL3_CACHE_SIZE)
+ /* No need to look further. */
+ break;
+ }
+ else
+ {
+ struct intel_02_cache_info *found;
+ struct intel_02_cache_info search;
+
+ search.idx = byte;
+ found = bsearch (&search, intel_02_known, nintel_02_known,
+ sizeof (intel_02_known[0]), intel_02_known_compare);
+ if (found != NULL)
+ {
+ if (found->name == folded_name)
+ {
+ unsigned int offset = name - folded_name;
+
+ if (offset == 0)
+ /* Cache size. */
+ return found->size;
+ if (offset == 1)
+ return found->assoc;
+
+ assert (offset == 2);
+ return found->linesize;
+ }
+
+ if (found->name == _SC_LEVEL2_CACHE_SIZE)
+ *has_level_2 = true;
+ }
+ }
+
+ /* Next byte for the next round. */
+ value >>= 8;
+ }
+
+ /* Nothing found. */
+ return 0;
+}
+
+
+static long int __attribute__ ((noinline))
+handle_intel (int name, unsigned int maxidx)
+{
+ if (maxidx < 2)
+ {
+ // XXX Do such processors exist? When we know we can fill in some
+ // values.
+ return 0;
+ }
+
+ /* OK, we can use the CPUID instruction to get all info about the
+ caches. */
+ unsigned int cnt = 0;
+ unsigned int max = 1;
+ long int result = 0;
+ bool no_level_2_or_3 = false;
+ bool has_level_2 = false;
+ while (cnt++ < max)
+ {
+ unsigned int eax;
+ unsigned int ebx;
+ unsigned int ecx;
+ unsigned int edx;
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
+ : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
+ : "0" (2));
+
+ /* The low byte of EAX in the first round contain the number of
+ rounds we have to make. At least one, the one we are already
+ doing. */
+ if (cnt == 1)
+ {
+ max = eax & 0xff;
+ eax &= 0xffffff00;
+ }
+
+ /* Process the individual registers' value. */
+ result = intel_check_word (name, eax, &has_level_2, &no_level_2_or_3);
+ if (result != 0)
+ return result;
+
+ result = intel_check_word (name, ebx, &has_level_2, &no_level_2_or_3);
+ if (result != 0)
+ return result;
+
+ result = intel_check_word (name, ecx, &has_level_2, &no_level_2_or_3);
+ if (result != 0)
+ return result;
+
+ result = intel_check_word (name, edx, &has_level_2, &no_level_2_or_3);
+ if (result != 0)
+ return result;
+ }
+
+ if (name >= _SC_LEVEL2_CACHE_SIZE && name <= _SC_LEVEL3_CACHE_LINESIZE
+ && no_level_2_or_3)
+ return -1;
+
+ return 0;
+}
+
+
+static long int __attribute__ ((noinline))
+handle_amd (int name)
+{
+ unsigned int eax;
+ unsigned int ebx;
+ unsigned int ecx;
+ unsigned int edx;
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
+ : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
+ : "0" (0x80000000));
+
+ if (name >= _SC_LEVEL3_CACHE_SIZE)
+ return 0;
+
+ unsigned int fn = 0x80000005 + (name >= _SC_LEVEL2_CACHE_SIZE);
+ if (eax < fn)
+ return 0;
+
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
+ : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
+ : "0" (fn));
+
+ if (name < _SC_LEVEL1_DCACHE_SIZE)
+ {
+ name += _SC_LEVEL1_DCACHE_SIZE - _SC_LEVEL1_ICACHE_SIZE;
+ ecx = edx;
+ }
+
+ switch (name)
+ {
+ case _SC_LEVEL1_DCACHE_SIZE:
+ return (ecx >> 14) & 0x3fc00;
+ case _SC_LEVEL1_DCACHE_ASSOC:
+ ecx >>= 16;
+ if ((ecx & 0xff) == 0xff)
+ /* Fully associative. */
+ return (ecx << 2) & 0x3fc00;
+ return ecx & 0xff;
+ case _SC_LEVEL1_DCACHE_LINESIZE:
+ return ecx & 0xff;
+ case _SC_LEVEL2_CACHE_SIZE:
+ return (ecx & 0xf000) == 0 ? 0 : (ecx >> 6) & 0x3fffc00;
+ case _SC_LEVEL2_CACHE_ASSOC:
+ ecx >>= 12;
+ switch (ecx & 0xf)
+ {
+ case 0:
+ case 1:
+ case 2:
+ case 4:
+ return ecx & 0xf;
+ case 6:
+ return 8;
+ case 8:
+ return 16;
+ case 0xf:
+ return (ecx << 6) & 0x3fffc00;
+ default:
+ return 0;
+ }
+ case _SC_LEVEL2_CACHE_LINESIZE:
+ return (ecx & 0xf000) == 0 ? 0 : ecx & 0xff;
+ default:
+ assert (! "cannot happen");
+ }
+ return -1;
+}
+
+
+static int
+i386_i486_test (void)
+{
+ int eflags;
+ int ac;
+ asm volatile ("pushfl;\n\t"
+ "popl %0;\n\t"
+ "movl $0x240000, %1;\n\t"
+ "xorl %0, %1;\n\t"
+ "pushl %1;\n\t"
+ "popfl;\n\t"
+ "pushfl;\n\t"
+ "popl %1;\n\t"
+ "xorl %0, %1;\n\t"
+ "pushl %0;\n\t"
+ "popfl"
+ : "=r" (eflags), "=r" (ac));
+
+ return ac;
+}
+
+
+/* Get the value of the system variable NAME. */
+long int
+__sysconf (int name)
+{
+ /* All the remainder, except the cache information, is handled in
+ the generic code. */
+ if (name < _SC_LEVEL1_ICACHE_SIZE || name > _SC_LEVEL4_CACHE_LINESIZE)
+ return linux_sysconf (name);
+
+ /* Recognize i386 and compatible. These don't have any cache on
+ board. */
+ int ac = i386_i486_test ();
+
+ if (ac == 0)
+ /* This is an i386. */
+ // XXX Is this true for all brands?
+ return -1;
+
+ /* Detect i486, the last Intel processor without CPUID. */
+ if ((ac & (1 << 21)) == 0)
+ {
+ /* No CPUID. */
+ // XXX Fill in info about other brands. For now only Intel.
+ return handle_i486 (name);
+ }
+
+ /* Find out what brand of processor. */
+ unsigned int eax;
+ unsigned int ebx;
+ unsigned int ecx;
+ unsigned int edx;
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
+ : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
+ : "0" (0));
+
+ /* This spells out "GenuineIntel". */
+ if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69)
+ return handle_intel (name, eax);
+
+ /* This spells out "AuthenticAMD". */
+ if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
+ return handle_amd (name);
+
+ // XXX Fill in more vendors.
+
+ /* CPU not known, we have no information. */
+ return 0;
+}
+
+/* Now the generic Linux version. */
+#undef __sysconf
+#define __sysconf static linux_sysconf
+#include "../sysconf.c"
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sysdep.S b/libc/sysdeps/unix/sysv/linux/i386/sysdep.S
new file mode 100644
index 000000000..b8df43cd7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sysdep.S
@@ -0,0 +1,41 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* The following code is only used in the shared library when we
+ compile the reentrant version. Otherwise each system call defines
+ each own version. */
+
+#ifndef PIC
+
+/* The syscall stubs jump here when they detect an error.
+ The code for Linux is almost identical to the canonical Unix/i386
+ code, except that the error number in %eax is negated. */
+
+#undef CALL_MCOUNT
+#define CALL_MCOUNT /* Don't insert the profiling call, it clobbers %eax. */
+
+ .text
+ENTRY (__syscall_error)
+ negl %eax
+
+#define __syscall_error __syscall_error_1
+#include <sysdeps/unix/i386/sysdep.S>
+
+#endif /* !PIC */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/sysdep.h b/libc/sysdeps/unix/sysv/linux/i386/sysdep.h
new file mode 100644
index 000000000..90423d843
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/sysdep.h
@@ -0,0 +1,581 @@
+/* Copyright (C) 1992,1993,1995-2000,2002-2005,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper, <drepper@gnu.org>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_I386_SYSDEP_H
+#define _LINUX_I386_SYSDEP_H 1
+
+/* There is some commonality. */
+#include <sysdeps/unix/i386/sysdep.h>
+#include <bp-sym.h>
+#include <bp-asm.h>
+/* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */
+#include <dl-sysdep.h>
+#include <tls.h>
+
+
+/* For Linux we can use the system call table in the header file
+ /usr/include/asm/unistd.h
+ of the kernel. But these symbols do not follow the SYS_* syntax
+ so we have to redefine the `SYS_ify' macro here. */
+#undef SYS_ify
+#define SYS_ify(syscall_name) __NR_##syscall_name
+
+#if defined USE_DL_SYSINFO \
+ && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define I386_USE_SYSENTER 1
+#else
+# undef I386_USE_SYSENTER
+#endif
+
+#ifdef __ASSEMBLER__
+
+/* Linux uses a negative return value to indicate syscall errors,
+ unlike most Unices, which use the condition codes' carry flag.
+
+ Since version 2.1 the return value of a system call might be
+ negative even if the call succeeded. E.g., the `lseek' system call
+ might return a large offset. Therefore we must not anymore test
+ for < 0, but test for a real error by making sure the value in %eax
+ is a real error number. Linus said he will make sure the no syscall
+ returns a value in -1 .. -4095 as a valid result so we can savely
+ test with -4095. */
+
+/* We don't want the label for the error handle to be global when we define
+ it here. */
+#ifdef PIC
+# define SYSCALL_ERROR_LABEL 0f
+#else
+# define SYSCALL_ERROR_LABEL syscall_error
+#endif
+
+#undef PSEUDO
+#define PSEUDO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args); \
+ cmpl $-4095, %eax; \
+ jae SYSCALL_ERROR_LABEL; \
+ L(pseudo_end):
+
+#undef PSEUDO_END
+#define PSEUDO_END(name) \
+ SYSCALL_ERROR_HANDLER \
+ END (name)
+
+#undef PSEUDO_NOERRNO
+#define PSEUDO_NOERRNO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args)
+
+#undef PSEUDO_END_NOERRNO
+#define PSEUDO_END_NOERRNO(name) \
+ END (name)
+
+#define ret_NOERRNO ret
+
+/* The function has to return the error code. */
+#undef PSEUDO_ERRVAL
+#define PSEUDO_ERRVAL(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args); \
+ negl %eax
+
+#undef PSEUDO_END_ERRVAL
+#define PSEUDO_END_ERRVAL(name) \
+ END (name)
+
+#define ret_ERRVAL ret
+
+#ifndef PIC
+# define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
+#else
+
+# if RTLD_PRIVATE_ERRNO
+# define SYSCALL_ERROR_HANDLER \
+0:SETUP_PIC_REG(cx); \
+ addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
+ xorl %edx, %edx; \
+ subl %eax, %edx; \
+ movl %edx, rtld_errno@GOTOFF(%ecx); \
+ orl $-1, %eax; \
+ jmp L(pseudo_end);
+
+# elif defined _LIBC_REENTRANT
+
+# if USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+# define SYSCALL_ERROR_ERRNO errno
+# endif
+# define SYSCALL_ERROR_HANDLER \
+0:SETUP_PIC_REG (cx); \
+ addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
+ movl SYSCALL_ERROR_ERRNO@GOTNTPOFF(%ecx), %ecx; \
+ xorl %edx, %edx; \
+ subl %eax, %edx; \
+ SYSCALL_ERROR_HANDLER_TLS_STORE (%edx, %ecx); \
+ orl $-1, %eax; \
+ jmp L(pseudo_end);
+# ifndef NO_TLS_DIRECT_SEG_REFS
+# define SYSCALL_ERROR_HANDLER_TLS_STORE(src, destoff) \
+ movl src, %gs:(destoff)
+# else
+# define SYSCALL_ERROR_HANDLER_TLS_STORE(src, destoff) \
+ addl %gs:0, destoff; \
+ movl src, (destoff)
+# endif
+# else
+# define SYSCALL_ERROR_HANDLER \
+0:pushl %ebx; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (ebx, 0); \
+ SETUP_PIC_REG (bx); \
+ addl $_GLOBAL_OFFSET_TABLE_, %ebx; \
+ xorl %edx, %edx; \
+ subl %eax, %edx; \
+ pushl %edx; \
+ cfi_adjust_cfa_offset (4); \
+ PUSH_ERRNO_LOCATION_RETURN; \
+ call BP_SYM (__errno_location)@PLT; \
+ POP_ERRNO_LOCATION_RETURN; \
+ popl %ecx; \
+ cfi_adjust_cfa_offset (-4); \
+ popl %ebx; \
+ cfi_adjust_cfa_offset (-4); \
+ cfi_restore (ebx); \
+ movl %ecx, (%eax); \
+ orl $-1, %eax; \
+ jmp L(pseudo_end);
+/* A quick note: it is assumed that the call to `__errno_location' does
+ not modify the stack! */
+# endif
+# else
+/* Store (- %eax) into errno through the GOT. */
+# define SYSCALL_ERROR_HANDLER \
+0:SETUP_PIC_REG(cx); \
+ addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
+ xorl %edx, %edx; \
+ subl %eax, %edx; \
+ movl errno@GOT(%ecx), %ecx; \
+ movl %edx, (%ecx); \
+ orl $-1, %eax; \
+ jmp L(pseudo_end);
+# endif /* _LIBC_REENTRANT */
+#endif /* PIC */
+
+
+/* The original calling convention for system calls on Linux/i386 is
+ to use int $0x80. */
+#ifdef I386_USE_SYSENTER
+# ifdef SHARED
+# define ENTER_KERNEL call *%gs:SYSINFO_OFFSET
+# else
+# define ENTER_KERNEL call *_dl_sysinfo
+# endif
+#else
+# define ENTER_KERNEL int $0x80
+#endif
+
+/* Linux takes system call arguments in registers:
+
+ syscall number %eax call-clobbered
+ arg 1 %ebx call-saved
+ arg 2 %ecx call-clobbered
+ arg 3 %edx call-clobbered
+ arg 4 %esi call-saved
+ arg 5 %edi call-saved
+
+ The stack layout upon entering the function is:
+
+ 20(%esp) Arg# 5
+ 16(%esp) Arg# 4
+ 12(%esp) Arg# 3
+ 8(%esp) Arg# 2
+ 4(%esp) Arg# 1
+ (%esp) Return address
+
+ (Of course a function with say 3 arguments does not have entries for
+ arguments 4 and 5.)
+
+ The following code tries hard to be optimal. A general assumption
+ (which is true according to the data books I have) is that
+
+ 2 * xchg is more expensive than pushl + movl + popl
+
+ Beside this a neat trick is used. The calling conventions for Linux
+ tell that among the registers used for parameters %ecx and %edx need
+ not be saved. Beside this we may clobber this registers even when
+ they are not used for parameter passing.
+
+ As a result one can see below that we save the content of the %ebx
+ register in the %edx register when we have less than 3 arguments
+ (2 * movl is less expensive than pushl + popl).
+
+ Second unlike for the other registers we don't save the content of
+ %ecx and %edx when we have more than 1 and 2 registers resp.
+
+ The code below might look a bit long but we have to take care for
+ the pipelined processors (i586). Here the `pushl' and `popl'
+ instructions are marked as NP (not pairable) but the exception is
+ two consecutive of these instruction. This gives no penalty on
+ other processors though. */
+
+#undef DO_CALL
+#define DO_CALL(syscall_name, args) \
+ PUSHARGS_##args \
+ DOARGS_##args \
+ movl $SYS_ify (syscall_name), %eax; \
+ ENTER_KERNEL \
+ POPARGS_##args
+
+#define PUSHARGS_0 /* No arguments to push. */
+#define DOARGS_0 /* No arguments to frob. */
+#define POPARGS_0 /* No arguments to pop. */
+#define _PUSHARGS_0 /* No arguments to push. */
+#define _DOARGS_0(n) /* No arguments to frob. */
+#define _POPARGS_0 /* No arguments to pop. */
+
+#define PUSHARGS_1 movl %ebx, %edx; L(SAVEBX1): PUSHARGS_0
+#define DOARGS_1 _DOARGS_1 (4)
+#define POPARGS_1 POPARGS_0; movl %edx, %ebx; L(RESTBX1):
+#define _PUSHARGS_1 pushl %ebx; cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (ebx, 0); L(PUSHBX1): _PUSHARGS_0
+#define _DOARGS_1(n) movl n(%esp), %ebx; _DOARGS_0(n-4)
+#define _POPARGS_1 _POPARGS_0; popl %ebx; cfi_adjust_cfa_offset (-4); \
+ cfi_restore (ebx); L(POPBX1):
+
+#define PUSHARGS_2 PUSHARGS_1
+#define DOARGS_2 _DOARGS_2 (8)
+#define POPARGS_2 POPARGS_1
+#define _PUSHARGS_2 _PUSHARGS_1
+#define _DOARGS_2(n) movl n(%esp), %ecx; _DOARGS_1 (n-4)
+#define _POPARGS_2 _POPARGS_1
+
+#define PUSHARGS_3 _PUSHARGS_2
+#define DOARGS_3 _DOARGS_3 (16)
+#define POPARGS_3 _POPARGS_3
+#define _PUSHARGS_3 _PUSHARGS_2
+#define _DOARGS_3(n) movl n(%esp), %edx; _DOARGS_2 (n-4)
+#define _POPARGS_3 _POPARGS_2
+
+#define PUSHARGS_4 _PUSHARGS_4
+#define DOARGS_4 _DOARGS_4 (24)
+#define POPARGS_4 _POPARGS_4
+#define _PUSHARGS_4 pushl %esi; cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (esi, 0); L(PUSHSI1): _PUSHARGS_3
+#define _DOARGS_4(n) movl n(%esp), %esi; _DOARGS_3 (n-4)
+#define _POPARGS_4 _POPARGS_3; popl %esi; cfi_adjust_cfa_offset (-4); \
+ cfi_restore (esi); L(POPSI1):
+
+#define PUSHARGS_5 _PUSHARGS_5
+#define DOARGS_5 _DOARGS_5 (32)
+#define POPARGS_5 _POPARGS_5
+#define _PUSHARGS_5 pushl %edi; cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (edi, 0); L(PUSHDI1): _PUSHARGS_4
+#define _DOARGS_5(n) movl n(%esp), %edi; _DOARGS_4 (n-4)
+#define _POPARGS_5 _POPARGS_4; popl %edi; cfi_adjust_cfa_offset (-4); \
+ cfi_restore (edi); L(POPDI1):
+
+#define PUSHARGS_6 _PUSHARGS_6
+#define DOARGS_6 _DOARGS_6 (36)
+#define POPARGS_6 _POPARGS_6
+#define _PUSHARGS_6 pushl %ebp; cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (ebp, 0); L(PUSHBP1): _PUSHARGS_5
+#define _DOARGS_6(n) movl n(%esp), %ebp; _DOARGS_5 (n-4)
+#define _POPARGS_6 _POPARGS_5; popl %ebp; cfi_adjust_cfa_offset (-4); \
+ cfi_restore (ebp); L(POPBP1):
+
+#else /* !__ASSEMBLER__ */
+
+/* We need some help from the assembler to generate optimal code. We
+ define some macros here which later will be used. */
+asm (".L__X'%ebx = 1\n\t"
+ ".L__X'%ecx = 2\n\t"
+ ".L__X'%edx = 2\n\t"
+ ".L__X'%eax = 3\n\t"
+ ".L__X'%esi = 3\n\t"
+ ".L__X'%edi = 3\n\t"
+ ".L__X'%ebp = 3\n\t"
+ ".L__X'%esp = 3\n\t"
+ ".macro bpushl name reg\n\t"
+ ".if 1 - \\name\n\t"
+ ".if 2 - \\name\n\t"
+ "error\n\t"
+ ".else\n\t"
+ "xchgl \\reg, %ebx\n\t"
+ ".endif\n\t"
+ ".endif\n\t"
+ ".endm\n\t"
+ ".macro bpopl name reg\n\t"
+ ".if 1 - \\name\n\t"
+ ".if 2 - \\name\n\t"
+ "error\n\t"
+ ".else\n\t"
+ "xchgl \\reg, %ebx\n\t"
+ ".endif\n\t"
+ ".endif\n\t"
+ ".endm\n\t");
+
+/* Define a macro which expands inline into the wrapper code for a system
+ call. */
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...) \
+ ({ \
+ unsigned int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
+ resultvar = 0xffffffff; \
+ } \
+ (int) resultvar; })
+
+/* Define a macro which expands inline into the wrapper code for a system
+ call. This use is for internal calls that do not need to handle errors
+ normally. It will never touch errno. This returns just what the kernel
+ gave back.
+
+ The _NCS variant allows non-constant syscall numbers but it is not
+ possible to use more than four parameters. */
+#undef INTERNAL_SYSCALL
+#ifdef I386_USE_SYSENTER
+# ifdef SHARED
+# define INTERNAL_SYSCALL(name, err, nr, args...) \
+ ({ \
+ register unsigned int resultvar; \
+ EXTRAVAR_##nr \
+ asm volatile ( \
+ LOADARGS_##nr \
+ "movl %1, %%eax\n\t" \
+ "call *%%gs:%P2\n\t" \
+ RESTOREARGS_##nr \
+ : "=a" (resultvar) \
+ : "i" (__NR_##name), "i" (offsetof (tcbhead_t, sysinfo)) \
+ ASMFMT_##nr(args) : "memory", "cc"); \
+ (int) resultvar; })
+# define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({ \
+ register unsigned int resultvar; \
+ EXTRAVAR_##nr \
+ asm volatile ( \
+ LOADARGS_##nr \
+ "call *%%gs:%P2\n\t" \
+ RESTOREARGS_##nr \
+ : "=a" (resultvar) \
+ : "0" (name), "i" (offsetof (tcbhead_t, sysinfo)) \
+ ASMFMT_##nr(args) : "memory", "cc"); \
+ (int) resultvar; })
+# else
+# define INTERNAL_SYSCALL(name, err, nr, args...) \
+ ({ \
+ register unsigned int resultvar; \
+ EXTRAVAR_##nr \
+ asm volatile ( \
+ LOADARGS_##nr \
+ "movl %1, %%eax\n\t" \
+ "call *_dl_sysinfo\n\t" \
+ RESTOREARGS_##nr \
+ : "=a" (resultvar) \
+ : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
+ (int) resultvar; })
+# define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({ \
+ register unsigned int resultvar; \
+ EXTRAVAR_##nr \
+ asm volatile ( \
+ LOADARGS_##nr \
+ "call *_dl_sysinfo\n\t" \
+ RESTOREARGS_##nr \
+ : "=a" (resultvar) \
+ : "0" (name) ASMFMT_##nr(args) : "memory", "cc"); \
+ (int) resultvar; })
+# endif
+#else
+# define INTERNAL_SYSCALL(name, err, nr, args...) \
+ ({ \
+ register unsigned int resultvar; \
+ EXTRAVAR_##nr \
+ asm volatile ( \
+ LOADARGS_##nr \
+ "movl %1, %%eax\n\t" \
+ "int $0x80\n\t" \
+ RESTOREARGS_##nr \
+ : "=a" (resultvar) \
+ : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
+ (int) resultvar; })
+# define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({ \
+ register unsigned int resultvar; \
+ EXTRAVAR_##nr \
+ asm volatile ( \
+ LOADARGS_##nr \
+ "int $0x80\n\t" \
+ RESTOREARGS_##nr \
+ : "=a" (resultvar) \
+ : "0" (name) ASMFMT_##nr(args) : "memory", "cc"); \
+ (int) resultvar; })
+#endif
+
+#undef INTERNAL_SYSCALL_DECL
+#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
+
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+ ((unsigned int) (val) >= 0xfffff001u)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
+
+#define LOADARGS_0
+#ifdef __PIC__
+# if defined I386_USE_SYSENTER && defined SHARED
+# define LOADARGS_1 \
+ "bpushl .L__X'%k3, %k3\n\t"
+# define LOADARGS_5 \
+ "movl %%ebx, %4\n\t" \
+ "movl %3, %%ebx\n\t"
+# else
+# define LOADARGS_1 \
+ "bpushl .L__X'%k2, %k2\n\t"
+# define LOADARGS_5 \
+ "movl %%ebx, %3\n\t" \
+ "movl %2, %%ebx\n\t"
+# endif
+# define LOADARGS_2 LOADARGS_1
+# define LOADARGS_3 \
+ "xchgl %%ebx, %%edi\n\t"
+# define LOADARGS_4 LOADARGS_3
+#else
+# define LOADARGS_1
+# define LOADARGS_2
+# define LOADARGS_3
+# define LOADARGS_4
+# define LOADARGS_5
+#endif
+
+#define RESTOREARGS_0
+#ifdef __PIC__
+# if defined I386_USE_SYSENTER && defined SHARED
+# define RESTOREARGS_1 \
+ "bpopl .L__X'%k3, %k3\n\t"
+# define RESTOREARGS_5 \
+ "movl %4, %%ebx"
+# else
+# define RESTOREARGS_1 \
+ "bpopl .L__X'%k2, %k2\n\t"
+# define RESTOREARGS_5 \
+ "movl %3, %%ebx"
+# endif
+# define RESTOREARGS_2 RESTOREARGS_1
+# define RESTOREARGS_3 \
+ "xchgl %%edi, %%ebx\n\t"
+# define RESTOREARGS_4 RESTOREARGS_3
+#else
+# define RESTOREARGS_1
+# define RESTOREARGS_2
+# define RESTOREARGS_3
+# define RESTOREARGS_4
+# define RESTOREARGS_5
+#endif
+
+#define ASMFMT_0()
+#ifdef __PIC__
+# define ASMFMT_1(arg1) \
+ , "cd" (arg1)
+# define ASMFMT_2(arg1, arg2) \
+ , "d" (arg1), "c" (arg2)
+# define ASMFMT_3(arg1, arg2, arg3) \
+ , "D" (arg1), "c" (arg2), "d" (arg3)
+# define ASMFMT_4(arg1, arg2, arg3, arg4) \
+ , "D" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
+# define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
+ , "0" (arg1), "m" (_xv), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
+#else
+# define ASMFMT_1(arg1) \
+ , "b" (arg1)
+# define ASMFMT_2(arg1, arg2) \
+ , "b" (arg1), "c" (arg2)
+# define ASMFMT_3(arg1, arg2, arg3) \
+ , "b" (arg1), "c" (arg2), "d" (arg3)
+# define ASMFMT_4(arg1, arg2, arg3, arg4) \
+ , "b" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
+# define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
+ , "b" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
+#endif
+
+#define EXTRAVAR_0
+#define EXTRAVAR_1
+#define EXTRAVAR_2
+#define EXTRAVAR_3
+#define EXTRAVAR_4
+#ifdef __PIC__
+# define EXTRAVAR_5 int _xv;
+#else
+# define EXTRAVAR_5
+#endif
+
+/* Consistency check for position-independent code. */
+#ifdef __PIC__
+# define check_consistency() \
+ ({ int __res; \
+ __asm__ __volatile__ \
+ ("call __i686.get_pc_thunk.cx;" \
+ "addl $_GLOBAL_OFFSET_TABLE_, %%ecx;" \
+ "subl %%ebx, %%ecx;" \
+ "je 1f;" \
+ "ud2;" \
+ "1:\n" \
+ ".section .gnu.linkonce.t.__i686.get_pc_thunk.cx,\"ax\",@progbits;" \
+ ".globl __i686.get_pc_thunk.cx;" \
+ ".hidden __i686.get_pc_thunk.cx;" \
+ ".type __i686.get_pc_thunk.cx,@function;" \
+ "__i686.get_pc_thunk.cx:" \
+ "movl (%%esp), %%ecx;" \
+ "ret;" \
+ ".previous" \
+ : "=c" (__res)); \
+ __res; })
+#endif
+
+#endif /* __ASSEMBLER__ */
+
+
+/* Pointer mangling support. */
+#if defined NOT_IN_libc && defined IS_IN_rtld
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+ earlier than the descriptor is initialized. Using a global variable
+ is too complicated here since we have no PC-relative addressing mode. */
+#else
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(reg) xorl %gs:POINTER_GUARD, reg
+# define PTR_DEMANGLE(reg) PTR_MANGLE (reg)
+# else
+# define PTR_MANGLE(var) asm ("xorl %%gs:%c2, %0" \
+ : "=r" (var) \
+ : "0" (var), \
+ "i" (offsetof (tcbhead_t, \
+ pointer_guard)))
+# define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* linux/i386/sysdep.h */
diff --git a/libc/sysdeps/unix/sysv/linux/i386/ucontext_i.sym b/libc/sysdeps/unix/sysv/linux/i386/ucontext_i.sym
new file mode 100644
index 000000000..b11a5509c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/ucontext_i.sym
@@ -0,0 +1,30 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+--
+
+SIG_BLOCK
+SIG_SETMASK
+
+#define ucontext(member) offsetof (ucontext_t, member)
+#define mcontext(member) ucontext (uc_mcontext.member)
+#define mreg(reg) mcontext (gregs[REG_##reg])
+
+oLINK ucontext (uc_link)
+oSS_SP ucontext (uc_stack.ss_sp)
+oSS_SIZE ucontext (uc_stack.ss_size)
+oGS mreg (GS)
+oFS mreg (FS)
+oEDI mreg (EDI)
+oESI mreg (ESI)
+oEBP mreg (EBP)
+oESP mreg (ESP)
+oEBX mreg (EBX)
+oEDX mreg (EDX)
+oECX mreg (ECX)
+oEAX mreg (EAX)
+oEIP mreg (EIP)
+oFPREGS mcontext (fpregs)
+oSIGMASK ucontext (uc_sigmask)
+oFPREGSMEM ucontext (__fpregs_mem)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/versionsort64.c b/libc/sysdeps/unix/sysv/linux/i386/versionsort64.c
new file mode 100644
index 000000000..3efce692f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/versionsort64.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 1992, 1997, 1998, 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <dirent.h>
+#include <string.h>
+
+int
+__versionsort64 (const void *a, const void *b)
+{
+ return __strverscmp ((*(const struct dirent64 **) a)->d_name,
+ (*(const struct dirent64 **) b)->d_name);
+}
+
+#include <shlib-compat.h>
+
+versioned_symbol (libc, __versionsort64, versionsort64, GLIBC_2_2);
+
+#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+
+#include <sysdeps/unix/sysv/linux/i386/olddirent.h>
+
+int
+__old_versionsort64 (const void *a, const void *b);
+
+int
+attribute_compat_text_section
+__old_versionsort64 (const void *a, const void *b)
+{
+ return __strverscmp ((*(const struct __old_dirent64 **) a)->d_name,
+ (*(const struct __old_dirent64 **) b)->d_name);
+}
+
+compat_symbol (libc, __old_versionsort64, versionsort64, GLIBC_2_1);
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/i386/vfork.S b/libc/sysdeps/unix/sysv/linux/i386/vfork.S
new file mode 100644
index 000000000..eefd4b49c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/vfork.S
@@ -0,0 +1,88 @@
+/* Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Schwab <schwab@gnu.org>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+
+#ifdef __NR_vfork
+
+ /* Pop the return PC value into ECX. */
+ popl %ecx
+ cfi_adjust_cfa_offset (-4)
+
+#ifdef SAVE_PID
+ SAVE_PID
+#endif
+
+ /* Stuff the syscall number in EAX and enter into the kernel. */
+ movl $SYS_ify (vfork), %eax
+ int $0x80
+
+ /* Jump to the return PC. Don't jump directly since this
+ disturbs the branch target cache. Instead push the return
+ address back on the stack. */
+ pushl %ecx
+ cfi_adjust_cfa_offset (4)
+
+#ifdef RESTORE_PID
+ RESTORE_PID
+#endif
+
+ cmpl $-4095, %eax
+ /* Branch forward if it failed. */
+# ifdef __ASSUME_VFORK_SYSCALL
+ jae SYSCALL_ERROR_LABEL
+.Lpseudo_end:
+# else
+ jae .Lerror
+# endif
+
+ ret
+
+# ifndef __ASSUME_VFORK_SYSCALL
+.Lerror:
+ /* Check if vfork syscall is known at all. */
+ cmpl $-ENOSYS, %eax
+ jne SYSCALL_ERROR_LABEL
+# endif
+#endif
+
+#ifndef __ASSUME_VFORK_SYSCALL
+ /* If we don't have vfork, fork is close enough. */
+
+ movl $SYS_ify (fork), %eax
+ int $0x80
+ cmpl $-4095, %eax
+ jae SYSCALL_ERROR_LABEL
+.Lpseudo_end:
+ ret
+#endif
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/sysdeps/unix/sysv/linux/i386/xstat.c b/libc/sysdeps/unix/sysv/linux/i386/xstat.c
new file mode 100644
index 000000000..d27ecd312
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/i386/xstat.c
@@ -0,0 +1,99 @@
+/* xstat using old-style Unix stat system call.
+ Copyright (C) 1991,95,96,97,98,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, if xstat == xstat64 we must get rid of the prototype or gcc
+ will complain since they don't strictly match. */
+#define __xstat64 __xstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#include <xstatconv.h>
+
+#ifdef __NR_stat64
+# if __ASSUME_STAT64_SYSCALL == 0
+/* The variable is shared between all wrappers around *stat64 calls. */
+extern int __have_no_stat64;
+# endif
+#endif
+
+
+/* Get information about the file NAME in BUF. */
+int
+__xstat (int vers, const char *name, struct stat *buf)
+{
+#if __ASSUME_STAT64_SYSCALL == 0
+ struct kernel_stat kbuf;
+#endif
+ int result;
+
+ if (vers == _STAT_VER_KERNEL)
+ return INLINE_SYSCALL (stat, 2, CHECK_STRING (name), CHECK_1 ((struct kernel_stat *) buf));
+
+#if __ASSUME_STAT64_SYSCALL > 0
+ {
+ struct stat64 buf64;
+
+ result = INLINE_SYSCALL (stat64, 2, CHECK_STRING (name), __ptrvalue (&buf64));
+ if (result == 0)
+ result = __xstat32_conv (vers, &buf64, buf);
+ return result;
+ }
+#else
+# if defined __NR_stat64
+ /* To support 32 bit UIDs, we have to use stat64. The normal stat call only returns
+ 16 bit UIDs. */
+ if (! __have_no_stat64)
+ {
+ struct stat64 buf64;
+
+ result = INLINE_SYSCALL (stat64, 2, CHECK_STRING (name), __ptrvalue (&buf64));
+
+ if (result == 0)
+ result = __xstat32_conv (vers, &buf64, buf);
+
+ if (result != -1 || errno != ENOSYS)
+ return result;
+
+ __have_no_stat64 = 1;
+ }
+# endif
+ result = INLINE_SYSCALL (stat, 2, CHECK_STRING (name), __ptrvalue (&kbuf));
+ if (result == 0)
+ result = __xstat_conv (vers, &kbuf, buf);
+
+ return result;
+#endif /* __ASSUME_STAT64_SYSCALL */
+}
+hidden_def (__xstat)
+weak_alias (__xstat, _xstat);
+#ifdef XSTAT_IS_XSTAT64
+# undef __xstat64
+strong_alias (__xstat, __xstat64);
+hidden_ver (__xstat, __xstat64)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/Implies b/libc/sysdeps/unix/sysv/linux/ia64/Implies
new file mode 100644
index 000000000..8d91c8009
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/Implies
@@ -0,0 +1 @@
+unix/sysv/linux/wordsize-64
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/Makefile b/libc/sysdeps/unix/sysv/linux/ia64/Makefile
new file mode 100644
index 000000000..d9a35a7c6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/Makefile
@@ -0,0 +1,27 @@
+ifeq ($(subdir),misc)
+sysdep_headers += sys/rse.h
+endif
+
+ifeq ($(subdir),stdlib)
+sysdep_routines += __start_context
+gen-as-const-headers += sigcontext-offsets.sym
+endif
+
+ifeq ($(subdir),misc)
+sysdep_headers += sys/io.h
+sysdep_routines += ioperm clone2
+endif
+
+ifeq ($(subdir),elf)
+sysdep-dl-routines += dl-static
+sysdep_routines += $(sysdep-dl-routines)
+sysdep-rtld-routines += $(sysdep-dl-routines)
+endif
+
+ifeq ($(subdir),rt)
+librt-routines += rt-sysdep
+endif
+
+# This is a crude attempt to silence the compiler which complains about
+# then 'current' definition in the kernel headers.
+CPPFLAGS += -D_ASM_IA64_CURRENT_H
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/Versions b/libc/sysdeps/unix/sysv/linux/ia64/Versions
new file mode 100644
index 000000000..13d710a07
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/Versions
@@ -0,0 +1,25 @@
+ld {
+ GLIBC_PRIVATE {
+ _dl_var_init;
+ }
+}
+libc {
+ GLIBC_2.2 {
+ ioperm; iopl;
+ inb; inw; inl;
+ _inb; _inw; _inl;
+ outb; outw; _outl;
+ _outb; _outw; _outl;
+ pciconfig_read; pciconfig_write;
+
+ # linuxthreads
+ __clone2;
+ }
+ GLIBC_2.2.2 {
+ # w*
+ wordexp;
+ }
+ GLIBC_2.2.6 {
+ getunwind;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/__longjmp.S b/libc/sysdeps/unix/sysv/linux/ia64/__longjmp.S
new file mode 100644
index 000000000..aa18fadf9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/__longjmp.S
@@ -0,0 +1,163 @@
+/* Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA.
+
+ Note that __sigsetjmp() did NOT flush the register stack. Instead,
+ we do it here since __longjmp() is usually much less frequently
+ invoked than __sigsetjmp(). The only difficulty is that __sigsetjmp()
+ didn't (and wouldn't be able to) save ar.rnat either. This is a problem
+ because if we're not careful, we could end up loading random NaT bits.
+ There are two cases:
+
+ (i) ar.bsp < ia64_rse_rnat_addr(jmpbuf.ar_bsp)
+ ar.rnat contains the desired bits---preserve ar.rnat
+ across loadrs and write to ar.bspstore
+
+ (ii) ar.bsp >= ia64_rse_rnat_addr(jmpbuf.ar_bsp)
+ The desired ar.rnat is stored in
+ ia64_rse_rnat_addr(jmpbuf.ar_bsp). Load those
+ bits into ar.rnat after setting ar.bspstore. */
+
+#include <sysdep.h>
+#include <features.h>
+
+# define pPos p6 /* is rotate count positive? */
+# define pNeg p7 /* is rotate count negative? */
+
+
+ /* __longjmp(__jmp_buf buf, int val) */
+
+LEAF(__longjmp)
+ alloc r8=ar.pfs,2,1,0,0
+ mov r27=ar.rsc
+ add r2=0x98,in0 // r2 <- &jmpbuf.orig_jmp_buf_addr
+ ;;
+ ld8 r8=[r2],-16 // r8 <- orig_jmp_buf_addr
+ mov r10=ar.bsp
+ and r11=~0x3,r27 // clear ar.rsc.mode
+ ;;
+ flushrs // flush dirty regs to backing store (must be first in insn grp)
+ ld8 r23=[r2],8 // r23 <- jmpbuf.ar_bsp
+ sub r8=r8,in0 // r8 <- &orig_jmpbuf - &jmpbuf
+ ;;
+ ld8 r25=[r2] // r25 <- jmpbuf.ar_unat
+ extr.u r8=r8,3,6 // r8 <- (&orig_jmpbuf - &jmpbuf)/8 & 0x3f
+ ;;
+ cmp.lt pNeg,pPos=r8,r0
+ mov r2=in0
+ ;;
+(pPos) mov r16=r8
+(pNeg) add r16=64,r8
+(pPos) sub r17=64,r8
+(pNeg) sub r17=r0,r8
+ ;;
+ mov ar.rsc=r11 // put RSE in enforced lazy mode
+ shr.u r8=r25,r16
+ add r3=8,in0 // r3 <- &jmpbuf.r1
+ shl r9=r25,r17
+ ;;
+ or r25=r8,r9
+ ;;
+ mov r26=ar.rnat
+ mov ar.unat=r25 // setup ar.unat (NaT bits for r1, r4-r7, and r12)
+ ;;
+ ld8.fill.nta sp=[r2],16 // r12 (sp)
+ ld8.fill.nta gp=[r3],16 // r1 (gp)
+ dep r11=-1,r23,3,6 // r11 <- ia64_rse_rnat_addr(jmpbuf.ar_bsp)
+ ;;
+ ld8.nta r16=[r2],16 // caller's unat
+ ld8.nta r17=[r3],16 // fpsr
+ ;;
+ ld8.fill.nta r4=[r2],16 // r4
+ ld8.fill.nta r5=[r3],16 // r5 (gp)
+ cmp.geu p8,p0=r10,r11 // p8 <- (ar.bsp >= jmpbuf.ar_bsp)
+ ;;
+ ld8.fill.nta r6=[r2],16 // r6
+ ld8.fill.nta r7=[r3],16 // r7
+ ;;
+ mov ar.unat=r16 // restore caller's unat
+ mov ar.fpsr=r17 // restore fpsr
+ ;;
+ ld8.nta r16=[r2],16 // b0
+ ld8.nta r17=[r3],16 // b1
+ ;;
+(p8) ld8 r26=[r11] // r26 <- *ia64_rse_rnat_addr(jmpbuf.ar_bsp)
+ mov ar.bspstore=r23 // restore ar.bspstore
+ ;;
+ ld8.nta r18=[r2],16 // b2
+ ld8.nta r19=[r3],16 // b3
+ ;;
+#ifdef PTR_DEMANGLE
+ PTR_DEMANGLE (r16, r24)
+#endif
+ ld8.nta r20=[r2],16 // b4
+ ld8.nta r21=[r3],16 // b5
+ ;;
+ ld8.nta r11=[r2],16 // ar.pfs
+ ld8.nta r22=[r3],56 // ar.lc
+ ;;
+ ld8.nta r24=[r2],32 // pr
+ mov b0=r16
+ ;;
+ ldf.fill.nta f2=[r2],32
+ ldf.fill.nta f3=[r3],32
+ mov b1=r17
+ ;;
+ ldf.fill.nta f4=[r2],32
+ ldf.fill.nta f5=[r3],32
+ mov b2=r18
+ ;;
+ ldf.fill.nta f16=[r2],32
+ ldf.fill.nta f17=[r3],32
+ mov b3=r19
+ ;;
+ ldf.fill.nta f18=[r2],32
+ ldf.fill.nta f19=[r3],32
+ mov b4=r20
+ ;;
+ ldf.fill.nta f20=[r2],32
+ ldf.fill.nta f21=[r3],32
+ mov b5=r21
+ ;;
+ ldf.fill.nta f22=[r2],32
+ ldf.fill.nta f23=[r3],32
+ mov ar.lc=r22
+ ;;
+ ldf.fill.nta f24=[r2],32
+ ldf.fill.nta f25=[r3],32
+ cmp.eq p8,p9=0,in1
+ ;;
+ ldf.fill.nta f26=[r2],32
+ ldf.fill.nta f27=[r3],32
+ mov ar.pfs=r11
+ ;;
+ ldf.fill.nta f28=[r2],32
+ ldf.fill.nta f29=[r3],32
+ ;;
+ ldf.fill.nta f30=[r2]
+ ldf.fill.nta f31=[r3]
+(p8) mov r8=1
+
+ mov ar.rnat=r26 // restore ar.rnat
+ ;;
+ mov ar.rsc=r27 // restore ar.rsc
+(p9) mov r8=in1
+
+ invala // virt. -> phys. regnum mapping may change
+ mov pr=r24,-1
+ ret
+END(__longjmp)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/__start_context.S b/libc/sysdeps/unix/sysv/linux/ia64/__start_context.S
new file mode 100644
index 000000000..519bd252b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/__start_context.S
@@ -0,0 +1,52 @@
+/* Copyright (C) 2001, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <features.h>
+
+/* When a context set up by __makecontext() is activated, control
+ transfers to __start_context. When we get here:
+
+ b1 = entry point of function to call
+ in0 = address of UCP to resume after function returns
+ in1 = global pointer for __start_context
+ out0 .. outN = arguments for function */
+
+ENTRY(__start_context)
+ .prologue
+ alloc r2 = ar.pfs, 2, 0, 8, 0
+
+ .save rp, r4 // terminate call chain with a NULL rp
+ mov r4 = r0
+ ;;
+
+ .body
+ br.call.sptk rp = b1
+1:
+ mov gp = in1 // restore gp
+ cmp.ne p6,p0 = in0, r0 // uc_link != 0 ?
+ ;;
+(p6) mov out0 = in0
+(p6) br.call.sptk rp = __setcontext
+.Lexit:
+ mov out0 = 0
+ br.call.sptk rp = HIDDEN_JUMPTARGET(exit)
+
+1: br.cond.sptk .Lexit
+END(__start_context)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bits/endian.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/endian.h
new file mode 100644
index 000000000..98a5e2399
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/endian.h
@@ -0,0 +1,7 @@
+/* Linux/ia64 is little-endian. */
+
+#ifndef _ENDIAN_H
+# error "Never use <bits/endian.h> directly; include <endian.h> instead."
+#endif
+
+#define __BYTE_ORDER __LITTLE_ENDIAN
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bits/fcntl.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/fcntl.h
new file mode 100644
index 000000000..ef66d465d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/fcntl.h
@@ -0,0 +1,230 @@
+/* O_*, F_*, FD_* bit values for Linux/IA64.
+ Copyright (C) 1999, 2000, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+
+#include <sys/types.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on an ext2 file system */
+#define O_ACCMODE 0003
+#define O_RDONLY 00
+#define O_WRONLY 01
+#define O_RDWR 02
+#define O_CREAT 0100 /* not fcntl */
+#define O_EXCL 0200 /* not fcntl */
+#define O_NOCTTY 0400 /* not fcntl */
+#define O_TRUNC 01000 /* not fcntl */
+#define O_APPEND 02000
+#define O_NONBLOCK 04000
+#define O_NDELAY O_NONBLOCK
+#define O_SYNC 010000
+#define O_FSYNC O_SYNC
+#define O_ASYNC 020000
+
+#ifdef __USE_GNU
+# define O_DIRECT 040000
+# define O_DIRECTORY 0200000 /* must be a directory */
+# define O_NOFOLLOW 0400000 /* don't follow links */
+# define O_NOATIME 01000000 /* Do not set atime. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+/* Not necessary, files are always with 64bit off_t. */
+# define O_LARGEFILE 0
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#define F_GETLK 5 /* Get record locking info. */
+#define F_SETLK 6 /* Set record locking info (non-blocking). */
+#define F_SETLKW 7 /* Set record locking info (blocking). */
+
+/* Not necessary, we always have 64-bit offsets. */
+#define F_GETLK64 5 /* Get record locking info. */
+#define F_SETLK64 6 /* Set record locking info (non-blocking). */
+#define F_SETLKW64 7 /* Set record locking info (blocking). */
+
+#if defined __USE_BSD || defined __USE_UNIX98
+# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */
+# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+#endif
+
+/* For F_[GET|SET]FD. */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
+#define F_RDLCK 0 /* Read lock. */
+#define F_WRLCK 1 /* Write lock. */
+#define F_UNLCK 2 /* Remove lock. */
+
+/* for old implementation of bsd flock () */
+#define F_EXLCK 4 /* or 3 */
+#define F_SHLCK 8 /* or 4 */
+
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation */
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#endif
+
+/* We don't need to support __USE_FILE_OFFSET64. */
+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'). */
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+ __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
+
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+#endif
+
+
+#ifdef __USE_GNU
+/* Flags for SYNC_FILE_RANGE. */
+# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
+ in the range before performing the
+ write. */
+# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
+ dirty pages in the range which are
+ not presently under writeback. */
+# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
+ the range after performing the
+ write. */
+
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+#endif
+
+__BEGIN_DECLS
+
+#ifdef __USE_GNU
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+
+/* Selective file content synch'ing. */
+extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
+ unsigned int __flags);
+
+
+/* Splice address range into a pipe. */
+extern int vmsplice (int __fdout, const struct iovec *__iov, size_t __count,
+ unsigned int __flags);
+
+/* Splice two files together. */
+extern int splice (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+/* In-kernel implementation of tee for pipe buffers. */
+extern int tee (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+#endif
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bits/ipc.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/ipc.h
new file mode 100644
index 000000000..858c332f1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/ipc.h
@@ -0,0 +1,54 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IPC_H
+# error "Never use <bits/ipc.h> directly; include <sys/ipc.h> instead."
+#endif
+
+#include <sys/types.h>
+
+/* Mode bits for `msgget', `semget', and `shmget'. */
+#define IPC_CREAT 01000 /* Create key if key does not exist. */
+#define IPC_EXCL 02000 /* Fail if key exists. */
+#define IPC_NOWAIT 04000 /* Return error on wait. */
+
+/* Control commands for `msgctl', `semctl', and `shmctl'. */
+#define IPC_RMID 0 /* Remove identifier. */
+#define IPC_SET 1 /* Set `ipc_perm' options. */
+#define IPC_STAT 2 /* Get `ipc_perm' options. */
+#define IPC_INFO 3 /* See ipcs. */
+
+/* Special key values. */
+#define IPC_PRIVATE ((__key_t) 0) /* Private key. */
+
+
+/* Data structure used to pass permission information to IPC operations. */
+struct ipc_perm
+ {
+ __key_t __key; /* Key. */
+ __uid_t uid; /* Owner's user ID. */
+ __gid_t gid; /* Owner's group ID. */
+ __uid_t cuid; /* Creator's user ID. */
+ __gid_t cgid; /* Creator's group ID. */
+ __mode_t mode; /* Read/write permission. */
+ unsigned short int __seq; /* Sequence number. */
+ unsigned short int __pad1;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ };
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bits/mman.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/mman.h
new file mode 100644
index 000000000..a27a30fc0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/mman.h
@@ -0,0 +1,104 @@
+/* Definitions for POSIX memory map interface. Linux/ia64 version.
+ Copyright (C) 1997,1998,2000,2003,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MMAN_H
+# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead."
+#endif
+
+/* The following definitions basically come from the kernel headers.
+ But the kernel header is not namespace clean. */
+
+
+/* Protections are chosen from these bits, OR'd together. The
+ implementation does not necessarily support PROT_EXEC or PROT_WRITE
+ without PROT_READ. The only guarantees are that no writing will be
+ allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
+
+#define PROT_READ 0x1 /* Page can be read. */
+#define PROT_WRITE 0x2 /* Page can be written. */
+#define PROT_EXEC 0x4 /* Page can be executed. */
+#define PROT_NONE 0x0 /* Page can not be accessed. */
+#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
+ growsdown vma (mprotect only). */
+#define PROT_GROWSUP 0x02000000 /* Extend change to start of
+ growsup vma (mprotect only). */
+
+/* Sharing types (must choose one and only one of these). */
+#define MAP_SHARED 0x01 /* Share changes. */
+#define MAP_PRIVATE 0x02 /* Changes are private. */
+#ifdef __USE_MISC
+# define MAP_TYPE 0x0f /* Mask for type of mapping. */
+#endif
+
+/* Other flags. */
+#define MAP_FIXED 0x10 /* Interpret addr exactly. */
+#ifdef __USE_MISC
+# define MAP_FILE 0
+# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
+# define MAP_ANON MAP_ANONYMOUS
+#endif
+
+/* These are Linux-specific. */
+#ifdef __USE_MISC
+# define MAP_GROWSDOWN 0x00100 /* Stack-like segment. */
+# define MAP_GROWSUP 0x00200 /* Register stack-like segment */
+# define MAP_DENYWRITE 0x00800 /* ETXTBSY */
+# define MAP_EXECUTABLE 0x01000 /* Mark it as an executable. */
+# define MAP_LOCKED 0x02000 /* Lock the mapping. */
+# define MAP_NORESERVE 0x04000 /* Don't check for reservations. */
+# define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */
+# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
+#endif
+
+/* Flags to `msync'. */
+#define MS_ASYNC 0x1 /* Sync memory asynchronously. */
+#define MS_INVALIDATE 0x2 /* Invalidate the caches. */
+#define MS_SYNC 0x4 /* Synchronous memory sync. */
+
+/* Flags for `mlockall'. */
+#define MCL_CURRENT 0x1 /* Lock all currently mapped pages. */
+#define MCL_FUTURE 0x2 /* Lock all additions to address
+ space. */
+
+/* Flags for `mremap'. */
+#ifdef __USE_GNU
+# define MREMAP_MAYMOVE 1
+# define MREMAP_FIXED 2
+#endif
+
+/* Advice to `madvise'. */
+#ifdef __USE_BSD
+# define MADV_NORMAL 0 /* No further special treatment. */
+# define MADV_RANDOM 1 /* Expect random page references. */
+# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define MADV_WILLNEED 3 /* Will need these pages. */
+# define MADV_DONTNEED 4 /* Don't need these pages. */
+# define MADV_REMOVE 9 /* Remove these pages and resources. */
+# define MADV_DONTFORK 10 /* Do not inherit across fork. */
+# define MADV_DOFORK 11 /* Do inherit across fork. */
+#endif
+
+/* The POSIX people had to invent similar names for the same things. */
+#ifdef __USE_XOPEN2K
+# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bits/msq.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/msq.h
new file mode 100644
index 000000000..cd268eea3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/msq.h
@@ -0,0 +1,69 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contribute by David Mosberger-Tang <davidm@hpl.hp.com>
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MSG_H
+#error "Never use <bits/msq.h> directly; include <sys/msg.h> instead."
+#endif
+
+#include <sys/types.h>
+
+/* Define options for message queue functions. */
+#define MSG_NOERROR 010000 /* no error if message is too big */
+#define MSG_EXCEPT 020000 /* recv any msg except of specified type */
+
+
+/* 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 */
+ __time_t msg_rtime; /* time of last msgrcv command */
+ __time_t msg_ctime; /* time of last change */
+ unsigned long int __msg_cbytes; /* current number of bytes on queue */
+ unsigned long int msg_qnum; /* number of messages currently on queue */
+ unsigned long int 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 __unused1;
+ unsigned long int __unused2;
+};
+
+#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/libc/sysdeps/unix/sysv/linux/ia64/bits/sem.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/sem.h
new file mode 100644
index 000000000..449f1ecc4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/sem.h
@@ -0,0 +1,87 @@
+/* Copyright (C) 2000
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SEM_H
+# error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
+#endif
+
+#include <sys/types.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 */
+ __time_t sem_ctime; /* last time changed by semctl() */
+ unsigned long int sem_nsems; /* number of semaphores in set */
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+};
+
+/* 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/libc/sysdeps/unix/sysv/linux/ia64/bits/setjmp.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/setjmp.h
new file mode 100644
index 000000000..8bd675e4e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/setjmp.h
@@ -0,0 +1,35 @@
+/* Define the machine-dependent type `jmp_buf'. Linux/IA-64 version.
+ Copyright (C) 1999,2000,2003,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _BITS_SETJMP_H
+#define _BITS_SETJMP_H 1
+
+#if !defined _SETJMP_H && !defined _PTHREAD_H
+# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
+#endif
+
+/* User code must not depend on the internal representation of jmp_buf. */
+
+#define _JBLEN 70
+
+/* the __jmp_buf element type should be __float80 per ABI... */
+typedef long __jmp_buf[_JBLEN] __attribute__ ((aligned (16))); /* guarantees 128-bit alignment! */
+
+#endif /* bits/setjmp.h */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bits/shm.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/shm.h
new file mode 100644
index 000000000..7f38f2dd7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/shm.h
@@ -0,0 +1,94 @@
+/* Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SHM_H
+# error "Never include <bits/shm.h> directly; use <sys/shm.h> instead."
+#endif
+
+#include <sys/types.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 */
+
+/* Commands for `shmctl'. */
+#define SHM_LOCK 11 /* lock segment (root only) */
+#define SHM_UNLOCK 12 /* unlock segment (root only) */
+
+/* Segment low boundary address multiple. */
+#define SHMLBA (1024 * 1024)
+
+/* Type to count number of attaches. */
+typedef unsigned long int shmatt_t;
+
+/* Data structure describing a set of semaphores. */
+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() */
+ __time_t shm_dtime; /* time of last shmdt() */
+ __time_t shm_ctime; /* time of last change by shmctl() */
+ __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 __unused1;
+ unsigned long int __unused2;
+ };
+
+#ifdef __USE_MISC
+
+/* ipcs ctl commands */
+# define SHM_STAT 13
+# define SHM_INFO 14
+
+/* shm_mode upper byte flags */
+# define SHM_DEST 01000 /* segment will be destroyed on last detach */
+# define SHM_LOCKED 02000 /* segment will not be swapped */
+# define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */
+# define SHM_NORESERVE 010000 /* don't check for reservations */
+
+struct shminfo
+ {
+ unsigned long int shmmax;
+ unsigned long int shmmin;
+ unsigned long int shmmni;
+ unsigned long int shmseg;
+ unsigned long int shmall;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+ };
+
+struct shm_info
+ {
+ int used_ids;
+ unsigned long int shm_tot; /* total allocated shm */
+ unsigned long int shm_rss; /* total resident shm */
+ unsigned long int shm_swp; /* total swapped shm */
+ unsigned long int swap_attempts;
+ unsigned long int swap_successes;
+ };
+
+#endif /* __USE_MISC */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bits/sigaction.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/sigaction.h
new file mode 100644
index 000000000..11599d520
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/sigaction.h
@@ -0,0 +1,73 @@
+/* Definitions for Linux/ia64 sigaction.
+ Copyright (C) 1996, 1997, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIGNAL_H
+# error "Never include <bits/sigaction.h> directly; use <signal.h> instead."
+#endif
+
+/* Structure describing the action to be taken when a signal arrives. */
+struct sigaction
+ {
+ /* Signal handler. */
+#ifdef __USE_POSIX199309
+ union
+ {
+ /* Used if SA_SIGINFO is not set. */
+ __sighandler_t sa_handler;
+ /* Used if SA_SIGINFO is set. */
+ void (*sa_sigaction) (int, siginfo_t *, void *);
+ }
+ __sigaction_handler;
+# define sa_handler __sigaction_handler.sa_handler
+# define sa_sigaction __sigaction_handler.sa_sigaction
+#else
+ __sighandler_t sa_handler;
+#endif
+
+ /* Special flags. */
+ unsigned long int sa_flags;
+
+ /* Additional set of signals to be blocked. */
+ __sigset_t sa_mask;
+ };
+
+/* Bits in `sa_flags'. */
+#define SA_NOCLDSTOP 0x00000001 /* Don't send SIGCHLD when children stop. */
+#define SA_NOCLDWAIT 0x00000002 /* Don't create zombie on child death. */
+#define SA_SIGINFO 0x00000004
+#if defined __USE_UNIX98 || defined __USE_MISC
+# define SA_ONSTACK 0x08000000 /* Use signal stack by using `sa_restorer'. */
+# define SA_RESTART 0x10000000 /* Restart syscall on signal return. */
+# define SA_NODEFER 0x40000000 /* Don't automatically block the signal
+ when its handler is being executed. */
+# define SA_RESETHAND 0x80000000 /* Reset to SIG_DFL on entry to handler. */
+#endif
+#ifdef __USE_MISC
+# define SA_INTERRUPT 0x20000000 /* Historic no-op. */
+
+/* Some aliases for the SA_ constants. */
+# define SA_NOMASK SA_NODEFER
+# define SA_ONESHOT SA_RESETHAND
+# define SA_STACK SA_ONSTACK
+#endif
+
+/* Values for the HOW argument to `sigprocmask'. */
+#define SIG_BLOCK 0 /* for blocking signals */
+#define SIG_UNBLOCK 1 /* for unblocking signals */
+#define SIG_SETMASK 2 /* for setting the signal mask */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
new file mode 100644
index 000000000..72c60ec24
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
@@ -0,0 +1,79 @@
+/* Copyright (C) 1996, 1997, 1998, 2000, 2001, 2003, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jes Sorensen <jes@linuxcare.com>, July 2000
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#if !defined _SIGNAL_H && !defined _SYS_UCONTEXT_H
+# error "Never use <bits/sigcontext.h> directly; include <signal.h> instead."
+#endif
+
+#ifndef _BITS_SIGCONTEXT_H
+#define _BITS_SIGCONTEXT_H 1
+
+#include <bits/sigstack.h>
+
+struct ia64_fpreg
+ {
+ union
+ {
+ unsigned long bits[2];
+ } u;
+ } __attribute__ ((aligned (16)));
+
+struct sigcontext
+{
+ unsigned long int sc_flags; /* see manifest constants below */
+ unsigned long int sc_nat; /* bit i == 1 iff scratch reg gr[i] is a NaT */
+ stack_t sc_stack; /* previously active stack */
+
+ unsigned long int sc_ip; /* instruction pointer */
+ unsigned long int sc_cfm; /* current frame marker */
+ unsigned long int sc_um; /* user mask bits */
+ unsigned long int sc_ar_rsc; /* register stack configuration register */
+ unsigned long int sc_ar_bsp; /* backing store pointer */
+ unsigned long int sc_ar_rnat; /* RSE NaT collection register */
+ unsigned long int sc_ar_ccv; /* compare & exchange compare value register */
+ unsigned long int sc_ar_unat; /* ar.unat of interrupted context */
+ unsigned long int sc_ar_fpsr; /* floating-point status register */
+ unsigned long int sc_ar_pfs; /* previous function state */
+ unsigned long int sc_ar_lc; /* loop count register */
+ unsigned long int sc_pr; /* predicate registers */
+ unsigned long int sc_br[8]; /* branch registers */
+ unsigned long int sc_gr[32]; /* general registers (static partition) */
+ struct ia64_fpreg sc_fr[128]; /* floating-point registers */
+ unsigned long int sc_rbs_base;/* NULL or new base of sighandler's rbs */
+ unsigned long int sc_loadrs; /* see description above */
+ unsigned long int sc_ar25; /* cmp8xchg16 uses this */
+ unsigned long int sc_ar26; /* rsvd for scratch use */
+ unsigned long int sc_rsvd[12];/* reserved for future use */
+
+ /* sc_mask is actually an sigset_t but we don't want to
+ * include the kernel headers here. */
+ unsigned long int sc_mask; /* signal mask to restore after handler returns */
+};
+
+/* sc_flag bit definitions. */
+#define IA64_SC_FLAG_ONSTACK_BIT 0 /* is handler running on signal stack? */
+#define IA64_SC_FLAG_IN_SYSCALL_BIT 1 /* did signal interrupt a syscall? */
+#define IA64_SC_FLAG_FPH_VALID_BIT 2 /* is state in f[32]-f[127] valid? */
+
+#define IA64_SC_FLAG_ONSTACK (1 << IA64_SC_FLAG_ONSTACK_BIT)
+#define IA64_SC_FLAG_IN_SYSCALL (1 << IA64_SC_FLAG_IN_SYSCALL_BIT)
+#define IA64_SC_FLAG_FPH_VALID (1 << IA64_SC_FLAG_FPH_VALID_BIT)
+
+#endif /* _BITS_SIGCONTEXT_H */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bits/siginfo.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/siginfo.h
new file mode 100644
index 000000000..66310c65b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/siginfo.h
@@ -0,0 +1,339 @@
+/* siginfo_t, sigevent and constants. Linux/ia64 version.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#if !defined _SIGNAL_H && !defined __need_siginfo_t \
+ && !defined __need_sigevent_t
+# error "Never include this file directly. Use <signal.h> instead"
+#endif
+
+#if (!defined __have_sigval_t \
+ && (defined _SIGNAL_H || defined __need_siginfo_t \
+ || defined __need_sigevent_t))
+# define __have_sigval_t 1
+
+/* Type for data associated with a signal. */
+typedef union sigval
+ {
+ int sival_int;
+ void *sival_ptr;
+ } sigval_t;
+#endif
+
+#if (!defined __have_siginfo_t \
+ && (defined _SIGNAL_H || defined __need_siginfo_t))
+# define __have_siginfo_t 1
+
+# define __SI_MAX_SIZE 128
+# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 4)
+
+typedef struct siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_errno; /* If non-zero, an errno value associated with
+ this signal, as defined in <errno.h>. */
+ int si_code; /* Signal code. */
+ int __pad0; /* Explicit padding. */
+
+ union
+ {
+ int _pad[__SI_PAD_SIZE];
+
+ /* kill(). */
+ struct
+ {
+ __pid_t si_pid; /* Sending process ID. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ } _kill;
+
+ /* POSIX.1b timers. */
+ struct
+ {
+ int si_tid; /* Timer ID. */
+ int si_overrun; /* Overrun count. */
+ sigval_t si_sigval; /* Signal value. */
+ } _timer;
+
+ /* POSIX.1b signals. */
+ struct
+ {
+ __pid_t si_pid; /* Sending process ID. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ sigval_t si_sigval; /* Signal value. */
+ } _rt;
+
+ /* SIGCHLD. */
+ struct
+ {
+ __pid_t si_pid; /* Which child. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ int si_status; /* Exit value or signal. */
+ __clock_t si_utime;
+ __clock_t si_stime;
+ } _sigchld;
+
+ /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
+ struct
+ {
+ void *si_addr; /* Faulting insn/memory ref. */
+ int _si_imm;
+ unsigned int _si_flags;
+ unsigned long int _si_isr;
+ } _sigfault;
+
+ /* SIGPOLL. */
+ struct
+ {
+ long int si_band; /* Band event for SIGPOLL. */
+ int si_fd;
+ } _sigpoll;
+ } _sifields;
+ } siginfo_t;
+
+
+/* X/Open requires some more fields with fixed names. */
+# define si_pid _sifields._kill.si_pid
+# define si_uid _sifields._kill.si_uid
+# define si_timerid _sifields._timer.si_tid
+# define si_overrun _sifields._timer.si_overrun
+# define si_status _sifields._sigchld.si_status
+# define si_utime _sifields._sigchld.si_utime
+# define si_stime _sifields._sigchld.si_stime
+# define si_value _sifields._rt.si_sigval
+# define si_int _sifields._rt.si_sigval.sival_int
+# define si_ptr _sifields._rt.si_sigval.sival_ptr
+# define si_addr _sifields._sigfault.si_addr
+# define si_band _sifields._sigpoll.si_band
+# define si_fd _sifields._sigpoll.si_fd
+
+# ifdef __USE_GNU
+# define si_imm _sifields._sigfault._si_imm
+# define si_segvflags _sifields._sigfault._si_flags
+# define si_isr _sifields._sigfault._si_isr
+# endif
+
+/* Values for `si_code'. Positive values are reserved for kernel-generated
+ signals. */
+enum
+{
+ SI_ASYNCNL = -60, /* Sent by asynch name lookup completion. */
+# define SI_ASYNCNL SI_ASYNCNL
+ SI_TKILL = -6, /* Sent by tkill. */
+# define SI_TKILL SI_TKILL
+ SI_SIGIO, /* Sent by queued SIGIO. */
+# define SI_SIGIO SI_SIGIO
+ SI_ASYNCIO, /* Sent by AIO completion. */
+# define SI_ASYNCIO SI_ASYNCIO
+ SI_MESGQ, /* Sent by real time mesq state change. */
+# define SI_MESGQ SI_MESGQ
+ SI_TIMER, /* Sent by timer expiration. */
+# define SI_TIMER SI_TIMER
+ SI_QUEUE, /* Sent by sigqueue. */
+# define SI_QUEUE SI_QUEUE
+ SI_USER, /* Sent by kill, sigsend, raise. */
+# define SI_USER SI_USER
+ SI_KERNEL = 0x80 /* Send by kernel. */
+#define SI_KERNEL SI_KERNEL
+};
+
+
+/* `si_code' values for SIGILL signal. */
+enum
+{
+ ILL_ILLOPC = 1, /* Illegal opcode. */
+# define ILL_ILLOPC ILL_ILLOPC
+ ILL_ILLOPN, /* Illegal operand. */
+# define ILL_ILLOPN ILL_ILLOPN
+ ILL_ILLADR, /* Illegal addressing mode. */
+# define ILL_ILLADR ILL_ILLADR
+ ILL_ILLTRP, /* Illegal trap. */
+# define ILL_ILLTRP ILL_ILLTRP
+ ILL_PRVOPC, /* Privileged opcode. */
+# define ILL_PRVOPC ILL_PRVOPC
+ ILL_PRVREG, /* Privileged register. */
+# define ILL_PRVREG ILL_PRVREG
+ ILL_COPROC, /* Coprocessor error. */
+# define ILL_COPROC ILL_COPROC
+ ILL_BADSTK, /* Internal stack error. */
+# define ILL_BADSTK ILL_BADSTK
+ ILL_BADIADDR /* Unimplemented instruction address. */
+# define ILL_BADIADDR ILL_BADIADDR
+
+# ifdef __USE_GNU
+ , ILL_BREAK
+# define ILL_BREAK ILL_BREAK
+# endif
+};
+
+/* `si_code' values for SIGFPE signal. */
+enum
+{
+ FPE_INTDIV = 1, /* Integer divide by zero. */
+# define FPE_INTDIV FPE_INTDIV
+ FPE_INTOVF, /* Integer overflow. */
+# define FPE_INTOVF FPE_INTOVF
+ FPE_FLTDIV, /* Floating point divide by zero. */
+# define FPE_FLTDIV FPE_FLTDIV
+ FPE_FLTOVF, /* Floating point overflow. */
+# define FPE_FLTOVF FPE_FLTOVF
+ FPE_FLTUND, /* Floating point underflow. */
+# define FPE_FLTUND FPE_FLTUND
+ FPE_FLTRES, /* Floating point inexact result. */
+# define FPE_FLTRES FPE_FLTRES
+ FPE_FLTINV, /* Floating point invalid operation. */
+# define FPE_FLTINV FPE_FLTINV
+ FPE_FLTSUB /* Subscript out of range. */
+# define FPE_FLTSUB FPE_FLTSUB
+# ifdef __USE_GNU
+ , FPE_DECOVF
+# define FPE_DECOVF FPE_DECOVF
+ , FPE_DECDIV
+# define FPE_DECDIV FPE_DECDIV
+ , FPE_DECERR
+# define FPE_DECERR FPE_DECERR
+ , FPE_INVASC
+# define FPE_INVASC FPE_INVASC
+ , FPE_INVDEC
+# define FPE_INVDEC FPE_INVDEC
+# endif
+};
+
+/* `si_code' values for SIGSEGV signal. */
+enum
+{
+ SEGV_MAPERR = 1, /* Address not mapped to object. */
+# define SEGV_MAPERR SEGV_MAPERR
+ SEGV_ACCERR /* Invalid permissions for mapped object. */
+# define SEGV_ACCERR SEGV_ACCERR
+# ifdef __USE_GNU
+ , SEGV_PSTKOVF /* Paragraph stack overflow. */
+# define SEGV_PSTKOVF SEGV_PSTKOVF
+# endif
+};
+
+/* `si_code' values for SIGBUS signal. */
+enum
+{
+ BUS_ADRALN = 1, /* Invalid address alignment. */
+# define BUS_ADRALN BUS_ADRALN
+ BUS_ADRERR, /* Non-existant physical address. */
+# define BUS_ADRERR BUS_ADRERR
+ BUS_OBJERR /* Object specific hardware error. */
+# define BUS_OBJERR BUS_OBJERR
+};
+
+/* `si_code' values for SIGTRAP signal. */
+enum
+{
+ TRAP_BRKPT = 1, /* Process breakpoint. */
+# define TRAP_BRKPT TRAP_BRKPT
+ TRAP_TRACE /* Process trace trap. */
+# define TRAP_TRACE TRAP_TRACE
+
+# ifdef __USE_GNU
+ , TRAP_BRANCH
+# define TRAP_BRANCH TRAP_BRANCH
+ , TRAP_HWBKPT
+# define TRAP_HWBKPT TRAP_HWBKPT
+# endif
+};
+
+/* `si_code' values for SIGCHLD signal. */
+enum
+{
+ CLD_EXITED = 1, /* Child has exited. */
+# define CLD_EXITED CLD_EXITED
+ CLD_KILLED, /* Child was killed. */
+# define CLD_KILLED CLD_KILLED
+ CLD_DUMPED, /* Child terminated abnormally. */
+# define CLD_DUMPED CLD_DUMPED
+ CLD_TRAPPED, /* Traced child has trapped. */
+# define CLD_TRAPPED CLD_TRAPPED
+ CLD_STOPPED, /* Child has stopped. */
+# define CLD_STOPPED CLD_STOPPED
+ CLD_CONTINUED /* Stopped child has continued. */
+# define CLD_CONTINUED CLD_CONTINUED
+};
+
+/* `si_code' values for SIGPOLL signal. */
+enum
+{
+ POLL_IN = 1, /* Data input available. */
+# define POLL_IN POLL_IN
+ POLL_OUT, /* Output buffers available. */
+# define POLL_OUT POLL_OUT
+ POLL_MSG, /* Input message available. */
+# define POLL_MSG POLL_MSG
+ POLL_ERR, /* I/O error. */
+# define POLL_ERR POLL_ERR
+ POLL_PRI, /* High priority input available. */
+# define POLL_PRI POLL_PRI
+ POLL_HUP /* Device disconnected. */
+# define POLL_HUP POLL_HUP
+};
+
+# undef __need_siginfo_t
+#endif /* !have siginfo_t && (have _SIGNAL_H || need siginfo_t). */
+
+
+#if (defined _SIGNAL_H || defined __need_sigevent_t) \
+ && !defined __have_sigevent_t
+# define __have_sigevent_t 1
+
+/* Structure to transport application-defined values with signals. */
+# define __SIGEV_MAX_SIZE 64
+# define __SIGEV_PAD_SIZE ((__SIGEV_MAX_SIZE / sizeof (int)) - 4)
+
+typedef struct sigevent
+ {
+ sigval_t sigev_value;
+ int sigev_signo;
+ int sigev_notify;
+
+ union
+ {
+ int _pad[__SIGEV_PAD_SIZE];
+
+ struct
+ {
+ void (*_function) (sigval_t); /* Function to start. */
+ void *_attribute; /* Really pthread_attr_t. */
+ } _sigev_thread;
+ } _sigev_un;
+ } sigevent_t;
+
+/* POSIX names to access some of the members. */
+# define sigev_notify_function _sigev_un._sigev_thread._function
+# define sigev_notify_attributes _sigev_un._sigev_thread._attribute
+
+/* `sigev_notify' values. */
+enum
+{
+ SIGEV_SIGNAL = 0, /* Notify via signal. */
+# define SIGEV_SIGNAL SIGEV_SIGNAL
+ SIGEV_NONE, /* Other notification: meaningless. */
+# define SIGEV_NONE SIGEV_NONE
+ SIGEV_THREAD, /* Deliver via thread creation. */
+# define SIGEV_THREAD SIGEV_THREAD
+
+ SIGEV_THREAD_ID = 4 /* Send signal to specific thread. */
+#define SIGEV_THREAD_ID SIGEV_THREAD_ID
+};
+
+#endif /* have _SIGNAL_H. */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bits/sigstack.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/sigstack.h
new file mode 100644
index 000000000..c9c9d2fed
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/sigstack.h
@@ -0,0 +1,63 @@
+/* sigstack, sigaltstack definitions.
+ Copyright (C) 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIGNAL_H
+# error "Never include this file directly. Use <signal.h> instead"
+#endif
+
+#ifndef _SIGSTACK_H
+#define _SIGSTACK_H 1
+
+/* Structure describing a signal stack (obsolete). */
+struct sigstack
+ {
+ __ptr_t ss_sp; /* Signal stack pointer. */
+ int ss_onstack; /* Nonzero if executing on this stack. */
+ };
+
+
+/* Possible values for `ss_flags.'. */
+enum
+{
+ SS_ONSTACK = 1,
+#define SS_ONSTACK SS_ONSTACK
+ SS_DISABLE
+#define SS_DISABLE SS_DISABLE
+};
+
+/* Minimum stack size for a signal handler.
+
+ Yes, this should be 131072 but the constant got defined incorrectly
+ in the kernel and we have to live with it. Users should in any case
+ use SIGSTKSZ as the size user-supplied buffers should have. */
+#define MINSIGSTKSZ 131027
+
+/* System default stack size. */
+#define SIGSTKSZ 262144
+
+
+/* Alternate, preferred interface. */
+typedef struct sigaltstack
+ {
+ __ptr_t ss_sp;
+ int ss_flags;
+ size_t ss_size;
+ } stack_t;
+
+#endif /* bits/sigstack.h */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bits/stat.h b/libc/sysdeps/unix/sysv/linux/ia64/bits/stat.h
new file mode 100644
index 000000000..f6b6671c0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bits/stat.h
@@ -0,0 +1,140 @@
+/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STAT_H
+# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
+#endif
+
+/* Versions of the `struct stat' data structure. */
+#define _STAT_VER_KERNEL 0
+#define _STAT_VER_LINUX 1
+#define _STAT_VER _STAT_VER_LINUX
+
+/* Versions of the `xmknod' interface. */
+#define _MKNOD_VER_LINUX 0
+
+struct stat
+ {
+ __dev_t st_dev; /* Device. */
+ __ino_t st_ino; /* File serial number. */
+ __nlink_t st_nlink; /* Link count. */
+ __mode_t st_mode; /* File mode. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ int pad0;
+ __dev_t st_rdev; /* Device number, if device. */
+ __off_t st_size; /* Size of file, in bytes. */
+#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
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ __blkcnt_t st_blocks; /* Nr. 512-byte blocks allocated. */
+ long int __unused[3];
+ };
+
+#ifdef __USE_LARGEFILE64
+/* Note stat64 is the same shape as stat. */
+struct stat64
+ {
+ __dev_t st_dev; /* Device. */
+ __ino64_t st_ino; /* File serial number. */
+ __nlink_t st_nlink; /* Link count. */
+ __mode_t st_mode; /* File mode. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ int pad0;
+ __dev_t st_rdev; /* Device number, if device. */
+ __off_t st_size; /* Size of file, in bytes. */
+#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
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */
+ long int __unused[3];
+ };
+#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. */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/brk.S b/libc/sysdeps/unix/sysv/linux/ia64/brk.S
new file mode 100644
index 000000000..0e4114a33
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/brk.S
@@ -0,0 +1,52 @@
+/* brk system call for Linux/ia64
+ Copyright (C) 1999,2000,2001,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Stephane Eranian <eranian@hpl.hp.com> and
+ Jes Sorensen, <Jes.Sorensen@cern.ch>, April 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include <asm/unistd.h>
+#include <asm/errno.h>
+
+ .global __curbrk
+ .type __curbrk,@object
+ .size __curbrk,8
+ .data
+ .align 8
+__curbrk:
+ data8 0
+
+weak_alias (__curbrk, ___brk_addr)
+
+LEAF(__brk)
+ .regstk 1, 0, 0, 0
+ DO_CALL(__NR_brk)
+ cmp.ltu p6, p0 = ret0, in0
+ addl r9 = @ltoff(__curbrk), gp
+ ;;
+ ld8 r9 = [r9]
+(p6) mov ret0 = ENOMEM
+(p6) br.cond.spnt.few __syscall_error
+ ;;
+ st8 [r9] = ret0
+ mov ret0 = 0
+ ret
+END(__brk)
+
+weak_alias (__brk, brk)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bsd-_setjmp.S b/libc/sysdeps/unix/sysv/linux/ia64/bsd-_setjmp.S
new file mode 100644
index 000000000..4e6a2da56
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bsd-_setjmp.S
@@ -0,0 +1 @@
+/* _setjmp is in setjmp.S */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/bsd-setjmp.S b/libc/sysdeps/unix/sysv/linux/ia64/bsd-setjmp.S
new file mode 100644
index 000000000..1da848d2f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/bsd-setjmp.S
@@ -0,0 +1 @@
+/* setjmp is in setjmp.S */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/clock_getcpuclockid.c b/libc/sysdeps/unix/sysv/linux/ia64/clock_getcpuclockid.c
new file mode 100644
index 000000000..2f3985153
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/clock_getcpuclockid.c
@@ -0,0 +1,32 @@
+/* clock_getcpuclockid -- Get a clockid_t for process CPU time. Linux/IA64
+ Copyright (C) 2000,2001,2003,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+
+#include "has_cpuclock.c"
+
+#define HAS_CPUCLOCK (has_cpuclock () > 0)
+
+#include <sysdeps/unix/sysv/linux/clock_getcpuclockid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/clone.S b/libc/sysdeps/unix/sysv/linux/ia64/clone.S
new file mode 100644
index 000000000..0cfaeab64
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/clone.S
@@ -0,0 +1 @@
+/* clone is not supported under Linux/ia64, use clone2. */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/clone2.S b/libc/sysdeps/unix/sysv/linux/ia64/clone2.S
new file mode 100644
index 000000000..d38eb201a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/clone2.S
@@ -0,0 +1,106 @@
+/* Copyright (C) 2000, 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+#include <sysdep.h>
+#include <asm/errno.h>
+
+
+/* int __clone2(int (*fn) (void *arg), void *child_stack_base, */
+/* size_t child_stack_size, int flags, void *arg, */
+/* pid_t *parent_tid, void *tls, pid_t *child_tid) */
+
+#define CHILD p8
+#define PARENT p9
+
+ENTRY(__clone2)
+ .prologue
+ alloc r2=ar.pfs,8,1,6,0
+ cmp.eq p6,p0=0,in0
+ cmp.eq p7,p0=0,in1
+ mov r8=EINVAL
+ mov out0=in3 /* Flags are first syscall argument. */
+ mov out1=in1 /* Stack address. */
+(p6) br.cond.spnt.many __syscall_error /* no NULL function pointers */
+(p7) br.cond.spnt.many __syscall_error /* no NULL stack pointers */
+ ;;
+ mov out2=in2 /* Stack size. */
+ mov out3=in5 /* Parent TID Pointer */
+ mov out4=in7 /* Child TID Pointer */
+ mov out5=in6 /* TLS pointer */
+ /*
+ * clone2() is special: the child cannot execute br.ret right
+ * after the system call returns, because it starts out
+ * executing on an empty stack. Because of this, we can't use
+ * the new (lightweight) syscall convention here. Instead, we
+ * just fall back on always using "break".
+ *
+ * Furthermore, since the child starts with an empty stack, we
+ * need to avoid unwinding past invalid memory. To that end,
+ * we'll pretend now that __clone2() is the end of the
+ * call-chain. This is wrong for the parent, but only until
+ * it returns from clone2() but it's better than the
+ * alternative.
+ */
+ mov r15=SYS_ify (clone2)
+ .save rp, r0
+ break __BREAK_SYSCALL
+ .body
+ cmp.eq p6,p0=-1,r10
+ cmp.eq CHILD,PARENT=0,r8 /* Are we the child? */
+(p6) br.cond.spnt.many __syscall_error
+ ;;
+(CHILD) mov loc0=gp
+(PARENT) ret
+ ;;
+#ifdef RESET_PID
+ tbit.nz p6,p0=in3,16 /* CLONE_THREAD */
+ tbit.z p7,p10=in3,8 /* CLONE_VM */
+(p6) br.cond.dptk 1f
+ ;;
+ mov r15=SYS_ify (getpid)
+(p10) addl r8=-1,r0
+(p7) break __BREAK_SYSCALL
+ ;;
+ add r9=PID,r13
+ add r10=TID,r13
+ ;;
+ st4 [r9]=r8
+ st4 [r10]=r8
+ ;;
+#endif
+1: ld8 out1=[in0],8 /* Retrieve code pointer. */
+ mov out0=in4 /* Pass proper argument to fn */
+ ;;
+ ld8 gp=[in0] /* Load function gp. */
+ mov b6=out1
+ br.call.dptk.many rp=b6 /* Call fn(arg) in the child */
+ ;;
+ mov out0=r8 /* Argument to _exit */
+ mov gp=loc0
+ .globl HIDDEN_JUMPTARGET(_exit)
+ br.call.dpnt.many rp=HIDDEN_JUMPTARGET(_exit)
+ /* call _exit with result from fn. */
+ ret /* Not reached. */
+PSEUDO_END(__clone2)
+
+/* For now we leave __clone undefined. This is unlikely to be a */
+/* problem, since at least the i386 __clone in glibc always failed */
+/* with a 0 sp (eventhough the kernel explicitly handled it). */
+/* Thus all such calls needed to pass an explicit sp, and as a result, */
+/* would be unlikely to work on ia64. */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/dl-brk.S b/libc/sysdeps/unix/sysv/linux/ia64/dl-brk.S
new file mode 100644
index 000000000..eeb96544e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/dl-brk.S
@@ -0,0 +1 @@
+#include <brk.S>
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/dl-cache.h b/libc/sysdeps/unix/sysv/linux/ia64/dl-cache.h
new file mode 100644
index 000000000..b8e279058
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/dl-cache.h
@@ -0,0 +1,25 @@
+/* Support for reading /etc/ld.so.cache files written by Linux ldconfig.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define _DL_CACHE_DEFAULT_ID 0x203
+
+#define _dl_cache_check_flags(flags) \
+ ((flags) == _DL_CACHE_DEFAULT_ID)
+
+#include_next <dl-cache.h>
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/dl-static.c b/libc/sysdeps/unix/sysv/linux/ia64/dl-static.c
new file mode 100644
index 000000000..4efc07703
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/dl-static.c
@@ -0,0 +1,69 @@
+/* Variable initialization. IA-64 version.
+ Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ldsodefs.h>
+
+#ifdef SHARED
+
+void
+_dl_var_init (void *array[])
+{
+ /* It has to match "variables" below. */
+ enum
+ {
+ DL_PAGESIZE = 0,
+ DL_CLKTCK
+ };
+
+ GLRO(dl_pagesize) = *((size_t *) array[DL_PAGESIZE]);
+ GLRO(dl_clktck) = *((int *) array[DL_CLKTCK]);
+}
+
+#else
+#include <bits/libc-lock.h>
+
+__libc_lock_define_initialized_recursive (static, _dl_static_lock)
+
+static void *variables[] =
+{
+ &GLRO(dl_pagesize),
+ &GLRO(dl_clktck)
+};
+
+void
+_dl_static_init (struct link_map *map)
+{
+ const ElfW(Sym) *ref = NULL;
+ lookup_t loadbase;
+ void (*f) (void *[]);
+
+ __libc_lock_lock_recursive (_dl_static_lock);
+
+ loadbase = _dl_lookup_symbol_x ("_dl_var_init", map, &ref,
+ map->l_local_scope, NULL, 0, 1, NULL);
+ if (ref != NULL)
+ {
+ f = (void (*) (void *[])) DL_SYMBOL_ADDRESS (loadbase, ref);
+ f (variables);
+ }
+
+ __libc_lock_unlock_recursive (_dl_static_lock);
+}
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/fork.S b/libc/sysdeps/unix/sysv/linux/ia64/fork.S
new file mode 100644
index 000000000..0a57ab0d1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/fork.S
@@ -0,0 +1,41 @@
+/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+#include <sysdep.h>
+#define _SIGNAL_H
+#include <bits/signum.h>
+
+/* pid_t fork(void); */
+/* Implemented as a clone system call with parameters SIGCHLD and 0 */
+
+ENTRY(__libc_fork)
+ alloc r2=ar.pfs,0,0,2,0
+ mov out0=SIGCHLD /* Return SIGCHLD when child finishes */
+ /* no other clone flags; nothing shared */
+ mov out1=0 /* Standard sp value. */
+ ;;
+ DO_CALL (SYS_ify (clone))
+ cmp.eq p6,p0=-1,r10
+(p6) br.cond.spnt.few __syscall_error
+ ret
+PSEUDO_END(__libc_fork)
+
+weak_alias (__libc_fork, __fork)
+libc_hidden_def (__fork)
+weak_alias (__libc_fork, fork)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/get_clockfreq.c b/libc/sysdeps/unix/sysv/linux/ia64/get_clockfreq.c
new file mode 100644
index 000000000..48abfc13f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/get_clockfreq.c
@@ -0,0 +1,89 @@
+/* Get frequency of the system processor. IA-64/Linux version.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <libc-internal.h>
+
+
+hp_timing_t
+__get_clockfreq (void)
+{
+ /* We read the information from the /proc filesystem. It contains at
+ least one line like
+ itc MHz : 733.390988
+ We search for this line and convert the number in an integer. */
+ static hp_timing_t result;
+ int fd;
+
+ /* If this function was called before, we know the result. */
+ if (result != 0)
+ return result;
+
+ fd = open ("/proc/cpuinfo", O_RDONLY);
+ if (__builtin_expect (fd != -1, 1))
+ {
+ /* XXX AFAIK the /proc filesystem can generate "files" only up
+ to a size of 4096 bytes. */
+ char buf[4096];
+ ssize_t n;
+
+ n = read (fd, buf, sizeof buf);
+ if (__builtin_expect (n, 1) > 0)
+ {
+ char *mhz = memmem (buf, n, "itc MHz", 7);
+
+ if (__builtin_expect (mhz != NULL, 1))
+ {
+ char *endp = buf + n;
+ int seen_decpoint = 0;
+ int ndigits = 0;
+
+ /* Search for the beginning of the string. */
+ while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
+ ++mhz;
+
+ while (mhz < endp && *mhz != '\n')
+ {
+ if (*mhz >= '0' && *mhz <= '9')
+ {
+ result *= 10;
+ result += *mhz - '0';
+ if (seen_decpoint)
+ ++ndigits;
+ }
+ else if (*mhz == '.')
+ seen_decpoint = 1;
+
+ ++mhz;
+ }
+
+ /* Compensate for missing digits at the end. */
+ while (ndigits++ < 6)
+ result *= 10;
+ }
+ }
+
+ close (fd);
+ }
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/getclktck.c b/libc/sysdeps/unix/sysv/linux/ia64/getclktck.c
new file mode 100644
index 000000000..6636bbe68
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/getclktck.c
@@ -0,0 +1,2 @@
+#define SYSTEM_CLK_TCK 1024
+#include <sysdeps/unix/sysv/linux/getclktck.c>
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/getcontext.S b/libc/sysdeps/unix/sysv/linux/ia64/getcontext.S
new file mode 100644
index 000000000..4e18bace2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/getcontext.S
@@ -0,0 +1,158 @@
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <features.h>
+
+#include "ucontext_i.h"
+
+/* __getcontext (ucontext_t *ucp)
+
+ Saves the machine context in UCP such that when it is activated,
+ it appears as if __getcontext() returned again. The only difference
+ is that on a first return, r9 contains 1 and on a subsequent
+ return, it contains 0.
+
+ This implementation in intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to save anything
+ other than the PRESERVED state. */
+
+ENTRY(__getcontext)
+ .prologue
+ .body
+ alloc r11 = ar.pfs, 1, 0, 4, 0
+
+ // sigprocmask (SIG_BLOCK, NULL, &sc->sc_mask):
+
+ mov r3 = SC_MASK
+ mov out0 = SIG_BLOCK
+
+ flushrs // save dirty partition on rbs
+ mov out1 = 0
+ add out2 = r3, in0
+
+ mov out3 = 8 // sizeof kernel sigset_t
+ DO_CALL(__NR_rt_sigprocmask)
+
+ mov.m rFPSR = ar.fpsr
+ mov.m rRSC = ar.rsc
+ add r2 = SC_GR+1*8, r32
+ ;;
+ mov.m rBSP = ar.bsp
+ .prologue
+ .save ar.unat, rUNAT
+ mov.m rUNAT = ar.unat
+ .body
+ add r3 = SC_GR+4*8, r32
+ ;;
+
+.mem.offset 0,0; st8.spill [r2] = r1, (5*8 - 1*8)
+.mem.offset 8,0; st8.spill [r3] = r4, 16
+ mov rPFS = r11
+ ;;
+.mem.offset 0,0; st8.spill [r2] = r5, 16
+.mem.offset 8,0; st8.spill [r3] = r6, 48
+ and rTMP = ~0x3, rRSC
+ ;;
+.mem.offset 0,0; st8.spill [r2] = r7, (SC_FR+2*16-(SC_GR+7*8))
+.mem.offset 8,0; st8.spill [r3] = sp, (SC_FR+3*16-(SC_GR+12*8))
+ ;;
+ mov.m ar.rsc = rTMP // put RSE into enforced lazy mode
+ mov.m rNAT = ar.unat
+ mov.i rLC = ar.lc
+ ;;
+ mov.m rRNAT = ar.rnat
+ mov.m ar.rsc = rRSC // restore RSE mode
+ mov rPR = pr
+
+ /*
+ * Rotate NaT bits by rPOS positions to the right:
+ */
+ stf.spill [r2] = f2, 32
+ stf.spill [r3] = f3, 32
+ add rPOS = SC_GR, r32 // rPOS <- &sc_gr[0]
+ ;;
+ stf.spill [r2] = f4, (16*16-4*16)
+ stf.spill [r3] = f5, (17*16-5*16)
+ extr.u rPOS = rPOS, 3, 6 // get NaT bit number for r0
+ ;;
+ stf.spill [r2] = f16, 32
+ stf.spill [r3] = f17, 32
+ sub rCPOS = 64, rPOS
+ ;;
+ stf.spill [r2] = f18, 32
+ stf.spill [r3] = f19, 32
+ shr.u rTMP = rNAT, rPOS
+ ;;
+ stf.spill [r2] = f20, 32
+ stf.spill [r3] = f21, 32
+ shl rNAT = rNAT, rCPOS
+ ;;
+ stf.spill [r2] = f22, 32
+ stf.spill [r3] = f23, 32
+ or rNAT = rNAT, rTMP
+ ;;
+ stf.spill [r2] = f24, 32
+ stf.spill [r3] = f25, 32
+ mov r8 = 0
+ ;;
+ stf.spill [r2] = f26, 32
+ stf.spill [r3] = f27, 32
+ mov r9 = 1
+ ;;
+ stf.spill [r2] = f28, 32
+ stf.spill [r3] = f29, 32
+ mov rB0 = b0
+ ;;
+ stf.spill [r2] = f30, 32
+ stf.spill [r3] = f31, 32
+ mov rB1 = b1
+ ;;
+ mov ar.unat = rUNAT // we're done spilling integer regs; restore caller's UNaT
+ add r2 = SC_NAT, r32
+ add r3 = SC_BSP, r32
+ ;;
+ st8 [r2] = rNAT, (SC_RNAT-SC_NAT)
+ st8 [r3] = rBSP, (SC_UNAT-SC_BSP)
+ mov rB2 = b2
+ ;;
+ st8 [r2] = rRNAT, (SC_FPSR-SC_RNAT)
+ st8 [r3] = rUNAT, (SC_PFS-SC_UNAT)
+ mov rB3 = b3
+ ;;
+ st8 [r2] = rFPSR, (SC_LC-SC_FPSR)
+ st8 [r3] = rPFS, (SC_PR-SC_PFS)
+ mov rB4 = b4
+ ;;
+ st8 [r2] = rLC, (SC_BR+0*8-SC_LC)
+ st8 [r3] = rPR, (SC_BR+1*8-SC_PR)
+ mov rB5 = b5
+ ;;
+ st8 [r2] = rB0, 16
+ st8 [r3] = rB1, 16
+ ;;
+ st8 [r2] = rB2, 16
+ st8 [r3] = rB3, 16
+ ;;
+ st8 [r2] = rB4
+ st8 [r3] = rB5
+ ret
+END(__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/getpagesize.c b/libc/sysdeps/unix/sysv/linux/ia64/getpagesize.c
new file mode 100644
index 000000000..1155dfdad
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/getpagesize.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <unistd.h>
+#include <sys/param.h>
+
+#include <ldsodefs.h>
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Return the system page size. The return value will depend on how
+ the kernel is configured. A program must use this call to
+ determine the page size to ensure proper alignment for calls such
+ as mmap and friends. --davidm 99/11/30 */
+
+int
+__getpagesize ()
+{
+ assert (GLRO(dl_pagesize) != 0);
+ return GLRO(dl_pagesize);
+}
+libc_hidden_def (__getpagesize)
+weak_alias (__getpagesize, getpagesize)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c b/libc/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c
new file mode 100644
index 000000000..39511cd2c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <not-cancel.h>
+
+static int itc_usable;
+
+static int
+has_cpuclock (void)
+{
+ if (__builtin_expect (itc_usable == 0, 0))
+ {
+ int newval = 1;
+ int fd = open_not_cancel_2 ("/proc/sal/itc_drift", O_RDONLY);
+ if (__builtin_expect (fd != -1, 1))
+ {
+ char buf[16];
+ /* We expect the file to contain a single digit followed by
+ a newline. If the format changes we better not rely on
+ the file content. */
+ if (read_not_cancel (fd, buf, sizeof buf) != 2
+ || buf[0] != '0' || buf[1] != '\n')
+ newval = -1;
+
+ close_not_cancel_no_status (fd);
+ }
+
+ itc_usable = newval;
+ }
+
+ return itc_usable;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/ioperm.c b/libc/sysdeps/unix/sysv/linux/ia64/ioperm.c
new file mode 100644
index 000000000..89a0a36d3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/ioperm.c
@@ -0,0 +1,217 @@
+/* Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* I/O access is restricted to ISA port space (ports 0..65535).
+ Modern devices hopefully are sane enough not to put any performance
+ critical registers in i/o space.
+
+ On the first call to ioperm() or iopl(), the entire (E)ISA port
+ space is mapped into the virtual address space at address io.base.
+ mprotect() calls are then used to enable/disable access to ports.
+ Per 4KB page, there are 4 I/O ports. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#define MAX_PORT 0x10000
+
+/*
+ * Memory fence w/accept. This should never be used in code that is
+ * not IA-64 specific.
+ */
+#define __ia64_mf_a() __asm__ __volatile__ ("mf.a" ::: "memory")
+
+static struct
+ {
+ unsigned long int base;
+ unsigned long int page_mask;
+ }
+io;
+
+__inline__ unsigned long int
+io_offset (unsigned long int port)
+{
+ return ((port >> 2) << 12) | (port & 0xfff);
+}
+
+int
+_ioperm (unsigned long int from, unsigned long int num, int turn_on)
+{
+#if 0
+ unsigned long int addr, len, base;
+#endif
+ unsigned long int base;
+ int prot;
+
+ /* this test isn't as silly as it may look like; consider overflows! */
+ if (from >= MAX_PORT || from + num > MAX_PORT)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (turn_on)
+ {
+ if (!io.base)
+ {
+ unsigned long phys_io_base, len;
+ int fd;
+
+ io.page_mask = ~(__getpagesize() - 1);
+
+ /* get I/O base physical address from ar.k0 as per PRM: */
+ __asm__ ("mov %0=ar.k0" : "=r"(phys_io_base));
+
+ /* The O_SYNC flag tells the /dev/mem driver to map the
+ memory uncached: */
+ fd = __open ("/dev/mem", O_RDWR | O_SYNC);
+ if (fd < 0)
+ return -1;
+
+ len = io_offset (MAX_PORT);
+#if 1
+ /* see comment below */
+ base = (unsigned long int) __mmap (0, len, PROT_READ | PROT_WRITE, MAP_SHARED,
+ fd, phys_io_base);
+#else
+ base = (unsigned long int) __mmap (0, len, PROT_NONE, MAP_SHARED,
+ fd, phys_io_base);
+#endif
+ __close (fd);
+
+ if ((long) base == -1)
+ return -1;
+
+ io.base = base;
+ }
+ prot = PROT_READ | PROT_WRITE;
+ }
+ else
+ {
+ if (!io.base)
+ return 0; /* never was turned on... */
+
+ prot = PROT_NONE;
+ }
+#if 0
+ /* We can't do mprotect because that would cause us to lose the
+ uncached flag that the /dev/mem driver turned on. A MAP_UNCACHED
+ flag seems so much cleaner... */
+ addr = (io.base + io_offset (from)) & io.page_mask;
+ len = io.base + io_offset (from + num) - addr;
+ return mprotect ((void *) addr, len, prot);
+#else
+ return 0;
+#endif
+}
+
+int
+_iopl (unsigned int level)
+{
+ if (level > 3)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ if (level)
+ {
+ int retval = _ioperm (0, MAX_PORT, 1);
+ /* Match the documented error returns of the x86 version. */
+ if (retval < 0 && errno == EACCES)
+ __set_errno (EPERM);
+ return retval;
+ }
+ return 0;
+}
+
+unsigned int
+_inb (unsigned long int port)
+{
+ volatile unsigned char *addr = (void *) io.base + io_offset (port);
+ unsigned char ret;
+
+ ret = *addr;
+ __ia64_mf_a();
+ return ret;
+}
+
+unsigned int
+_inw (unsigned long int port)
+{
+ volatile unsigned short *addr = (void *) io.base + io_offset (port);
+ unsigned short ret;
+
+ ret = *addr;
+ __ia64_mf_a();
+ return ret;
+}
+
+unsigned int
+_inl (unsigned long int port)
+{
+ volatile unsigned int *addr = (void *) io.base + io_offset (port);
+ unsigned int ret;
+
+ ret = *addr;
+ __ia64_mf_a();
+ return ret;
+}
+
+void
+_outb (unsigned char val, unsigned long int port)
+{
+ volatile unsigned char *addr = (void *) io.base + io_offset (port);
+
+ *addr = val;
+ __ia64_mf_a();
+}
+
+void
+_outw (unsigned short val, unsigned long int port)
+{
+ volatile unsigned short *addr = (void *) io.base + io_offset (port);
+
+ *addr = val;
+ __ia64_mf_a();
+}
+
+void
+_outl (unsigned int val, unsigned long int port)
+{
+ volatile unsigned int *addr = (void *) io.base + io_offset (port);
+
+ *addr = val;
+ __ia64_mf_a();
+}
+
+weak_alias (_ioperm, ioperm);
+weak_alias (_iopl, iopl);
+weak_alias (_inb, inb);
+weak_alias (_inw, inw);
+weak_alias (_inl, inl);
+weak_alias (_outb, outb);
+weak_alias (_outw, outw);
+weak_alias (_outl, outl);
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/kernel_stat.h b/libc/sysdeps/unix/sysv/linux/ia64/kernel_stat.h
new file mode 100644
index 000000000..ef11dc94d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/kernel_stat.h
@@ -0,0 +1,21 @@
+/* Definition of `struct stat' used in the kernel.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define STAT_IS_KERNEL_STAT 1
+#define XSTAT_IS_XSTAT64 1
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/ldconfig.h b/libc/sysdeps/unix/sysv/linux/ia64/ldconfig.h
new file mode 100644
index 000000000..af194898b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/ldconfig.h
@@ -0,0 +1,25 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/generic/ldconfig.h>
+
+#define SYSDEP_KNOWN_INTERPRETER_NAMES \
+ { "/lib/ld-linux.so.2", FLAG_ELF_LIBC6 },
+#define SYSDEP_KNOWN_LIBRARY_NAMES \
+ { "libc.so.6", FLAG_ELF_LIBC6 }, \
+ { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/ldd-rewrite.sed b/libc/sysdeps/unix/sysv/linux/ia64/ldd-rewrite.sed
new file mode 100644
index 000000000..535d1671e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/ldd-rewrite.sed
@@ -0,0 +1 @@
+s_^\(RTLDLIST=\)\([^ ]*\)-ia64\(\.so\.[0-9.]*\)[ ]*$_\1"\2-ia64\3 \2\3"_
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/ldsodefs.h b/libc/sysdeps/unix/sysv/linux/ia64/ldsodefs.h
new file mode 100644
index 000000000..31af62491
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/ldsodefs.h
@@ -0,0 +1,33 @@
+/* Run-time dynamic linker data structures for loaded ELF shared objects. IA64.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LDSODEFS_H
+
+/* Get the real definitions. */
+#include_next <ldsodefs.h>
+
+/* Now define our stuff. */
+
+/* We need special support to initialize DSO loaded for statically linked
+ binaries. */
+extern void _dl_static_init (struct link_map *map);
+#undef DL_STATIC_INIT
+#define DL_STATIC_INIT(map) _dl_static_init (map)
+
+#endif /* ldsodefs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/makecontext.c b/libc/sysdeps/unix/sysv/linux/ia64/makecontext.c
new file mode 100644
index 000000000..d7a2a9f15
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/makecontext.c
@@ -0,0 +1,93 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <libintl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ucontext.h>
+#include <sys/rse.h>
+
+
+struct fdesc
+ {
+ unsigned long ip;
+ unsigned long gp;
+ };
+
+#define PUSH(val) \
+do { \
+ if (ia64_rse_is_rnat_slot (rbs)) \
+ *rbs++ = 0; \
+ *rbs++ = (val); \
+} while (0)
+
+
+/* This implementation can handle an ARGC value of at most 8 and
+ values can be passed only in integer registers (r32-r39). */
+
+void
+__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
+{
+ struct sigcontext *sc = &ucp->uc_mcontext;
+ extern void __start_context (ucontext_t *link, long gp, ...);
+ unsigned long stack_start, stack_end;
+ va_list ap;
+ long *rbs;
+ int i;
+
+ stack_start = (long) sc->sc_stack.ss_sp;
+ stack_end = (long) sc->sc_stack.ss_sp + sc->sc_stack.ss_size;
+
+ stack_start = (stack_start + 7) & -8;
+ stack_end = stack_end & -16;
+
+ if (argc > 8)
+ {
+ fprintf (stderr, _("\
+makecontext: does not know how to handle more than 8 arguments\n"));
+ exit (-1);
+ }
+
+ /* set the entry point and global pointer: */
+ sc->sc_br[0] = ((struct fdesc *) &__start_context)->ip;
+ sc->sc_br[1] = ((struct fdesc *) func)->ip;
+ sc->sc_gr[1] = ((struct fdesc *) func)->gp;
+
+ /* set up the call frame: */
+ sc->sc_ar_pfs = ((sc->sc_ar_pfs & ~0x3fffffffffUL)
+ | (argc + 2) | ((argc + 2) << 7));
+ rbs = (long *) stack_start;
+ PUSH((long) ucp->uc_link);
+ PUSH(((struct fdesc *) &__start_context)->gp);
+ va_start (ap, argc);
+ for (i = 0; i < argc; ++i)
+ PUSH(va_arg (ap, long));
+ va_end (ap);
+
+ /* set the memory and register stack pointers: */
+ sc->sc_ar_bsp = (long) rbs;
+ sc->sc_gr[12] = stack_end - 16;
+
+ /* clear the NaT bits for r1 and r12: */
+ sc->sc_nat &= ~((1 << 1) | (1 << 12));
+ sc->sc_ar_rnat = 0;
+}
+
+weak_alias (__makecontext, makecontext)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/pipe.S b/libc/sysdeps/unix/sysv/linux/ia64/pipe.S
new file mode 100644
index 000000000..60624df3c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/pipe.S
@@ -0,0 +1,38 @@
+/* Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger <davidm@hpl.hp.com>
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* __pipe is a special syscall since it returns two values. */
+
+#include <sysdep.h>
+
+ENTRY(__pipe)
+ .regstk 1,0,0,0
+ DO_CALL (SYS_ify (pipe))
+ cmp.ne p6,p0=-1,r10
+ ;;
+(p6) st4 [in0]=r8,4
+(p6) mov ret0=0
+ ;;
+(p6) st4 [in0]=r9
+(p6) ret
+ br.cond.spnt.few __syscall_error
+PSEUDO_END(__pipe)
+
+libc_hidden_def (__pipe)
+weak_alias (__pipe, pipe)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/profil-counter.h b/libc/sysdeps/unix/sysv/linux/ia64/profil-counter.h
new file mode 100644
index 000000000..bc9a8433f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/profil-counter.h
@@ -0,0 +1,32 @@
+/* Machine-dependent SIGPROF signal handler. IA-64 version.
+ Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* In many Unix systems signal handlers are called like this
+ and the interrupted PC is easily findable in the `struct sigcontext'. */
+
+static void
+profil_counter (int signr, siginfo_t *si, struct sigcontext *scp)
+{
+ unsigned long ip = scp->sc_ip & ~0X3ULL, slot = scp->sc_ip & 0x3ull;
+
+ /* Note: Linux/ia64 encodes the slot number in bits 0 and 1. We
+ want to multiply the slot number by four so we can use bins of
+ width 4 to get accurate instruction-level profiling. */
+ profil_count ((void *) (ip + 4*slot));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/readelflib.c b/libc/sysdeps/unix/sysv/linux/ia64/readelflib.c
new file mode 100644
index 000000000..7a10d23c9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/readelflib.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 2000, 2001, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+int process_elf32_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+int process_elf64_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+
+/* Returns 0 if everything is ok, != 0 in case of error. */
+int
+process_elf_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length)
+{
+ ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
+ int ret;
+
+ if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
+ return process_elf32_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ else
+ {
+ ret = process_elf64_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ /* Intel 64bit libraries are always libc.so.6+. */
+ if (!ret)
+ *flag = FLAG_IA64_LIB64|FLAG_ELF_LIBC6;
+ return ret;
+ }
+}
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf32_file
+#define __ELF_NATIVE_CLASS 32
+#include "elf/readelflib.c"
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf64_file
+#define __ELF_NATIVE_CLASS 64
+#include "elf/readelflib.c"
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/register-dump.h b/libc/sysdeps/unix/sysv/linux/ia64/register-dump.h
new file mode 100644
index 000000000..513db974f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/register-dump.h
@@ -0,0 +1,182 @@
+/* Dump registers.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <string.h>
+#include <sys/uio.h>
+#include <stdio-common/_itoa.h>
+
+/* We will print the register dump in this format:
+
+ GP: XXXXXXXXXXXXXXXX R2: XXXXXXXXXXXXXXXX R3: XXXXXXXXXXXXXXXX
+ R8: XXXXXXXXXXXXXXXX R9: XXXXXXXXXXXXXXXX R10: XXXXXXXXXXXXXXXX
+ R11: XXXXXXXXXXXXXXXX SP: XXXXXXXXXXXXXXXX TP: XXXXXXXXXXXXXXXX
+ R14: XXXXXXXXXXXXXXXX R15: XXXXXXXXXXXXXXXX R16: XXXXXXXXXXXXXXXX
+ R17: XXXXXXXXXXXXXXXX R18: XXXXXXXXXXXXXXXX R19: XXXXXXXXXXXXXXXX
+ R20: XXXXXXXXXXXXXXXX R21: XXXXXXXXXXXXXXXX R22: XXXXXXXXXXXXXXXX
+ R23: XXXXXXXXXXXXXXXX R24: XXXXXXXXXXXXXXXX R25: XXXXXXXXXXXXXXXX
+ R26: XXXXXXXXXXXXXXXX R27: XXXXXXXXXXXXXXXX R28: XXXXXXXXXXXXXXXX
+ R29: XXXXXXXXXXXXXXXX R30: XXXXXXXXXXXXXXXX R31: XXXXXXXXXXXXXXXX
+
+ RP: XXXXXXXXXXXXXXXX B6: XXXXXXXXXXXXXXXX B7: XXXXXXXXXXXXXXXX
+
+ IP: XXXXXXXXXXXXXXXX RSC: XXXXXXXXXXXXXXXX PR: XXXXXXXXXXXXXXXX
+ PFS: XXXXXXXXXXXXXXXX UNAT: XXXXXXXXXXXXXXXX CFM: XXXXXXXXXXXXXXXX
+ CCV: XXXXXXXXXXXXXXXX FPSR: XXXXXXXXXXXXXXXX
+
+ F32: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX F33: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ F34: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX F35: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+...
+ F124: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX F125: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ F126: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX F127: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ */
+
+static void
+hexvalue (unsigned long int value, char *buf, size_t len)
+{
+ char *cp = _itoa_word (value, buf + len, 16, 0);
+ while (cp > buf)
+ *--cp = '0';
+}
+
+static void
+regvalue (unsigned long int *value, char letter, int regno, char *buf)
+{
+ int n = regno >= 100 ? 3 : regno >= 10 ? 2 : 1;
+ buf[0] = ' ';
+ buf[1] = letter;
+ _itoa_word (regno, buf + 2 + n, 10, 0);
+ buf[2 + n] = ':';
+ for (++n; n <= 4; ++n)
+ buf[2 + n] = ' ';
+ hexvalue (value[0], buf + 7, 16);
+ if (letter == 'F')
+ {
+ hexvalue (value[1], buf + 7 + 16, 16);
+ buf[7 + 32] = '\n';
+ }
+ else
+ buf[7 + 16] = '\n';
+}
+
+static void
+register_dump (int fd, struct sigcontext *ctx)
+{
+ char gpregs[32 - 5][8 + 16];
+ char fpregs[128 - 32][8 + 32];
+ char bpregs[3][8 + 16];
+ char spregs[8][16];
+ struct iovec iov[146];
+ size_t nr = 0;
+ int i;
+
+#define ADD_STRING(str) \
+ do \
+ { \
+ iov[nr].iov_base = (char *) str; \
+ iov[nr].iov_len = strlen (str); \
+ ++nr; \
+ } \
+ while (0)
+#define ADD_MEM(str, len) \
+ do \
+ { \
+ iov[nr].iov_base = str; \
+ iov[nr].iov_len = len; \
+ ++nr; \
+ } \
+ while (0)
+
+ /* Generate strings of register contents. */
+ for (i = 1; i < 4; ++i)
+ {
+ regvalue (&ctx->sc_gr[i], 'R', i, gpregs[i - 1]);
+ if (ctx->sc_nat & (1L << i))
+ memcpy (gpregs[i - 1] + 7, "NaT ", 16);
+ }
+ for (i = 8; i < 32; ++i)
+ {
+ regvalue (&ctx->sc_gr[i], 'R', i, gpregs[i - 5]);
+ if (ctx->sc_nat & (1L << i))
+ memcpy (gpregs[i - 1] + 7, "NaT ", 16);
+ }
+ memcpy (gpregs[0] + 1, "GP:", 3);
+ memcpy (gpregs[7] + 1, "SP: ", 4);
+ memcpy (gpregs[8] + 1, "TP: ", 4);
+
+ regvalue (&ctx->sc_br[0], 'B', 0, bpregs[0]);
+ regvalue (&ctx->sc_br[6], 'B', 6, bpregs[1]);
+ regvalue (&ctx->sc_br[7], 'B', 7, bpregs[2]);
+ memcpy (bpregs[0] + 1, "RP:", 3);
+
+ if (ctx->sc_flags & IA64_SC_FLAG_FPH_VALID)
+ for (i = 32; i < 128; ++i)
+ regvalue (&ctx->sc_fr[i].u.bits[0], 'F', i, fpregs[i - 32]);
+
+ hexvalue (ctx->sc_ip, spregs[0], sizeof (spregs[0]));
+ hexvalue (ctx->sc_ar_rsc, spregs[1], sizeof (spregs[1]));
+ hexvalue (ctx->sc_pr, spregs[2], sizeof (spregs[2]));
+ hexvalue (ctx->sc_ar_pfs, spregs[3], sizeof (spregs[3]));
+ hexvalue (ctx->sc_ar_unat, spregs[4], sizeof (spregs[4]));
+ hexvalue (ctx->sc_cfm, spregs[5], sizeof (spregs[5]));
+ hexvalue (ctx->sc_ar_ccv, spregs[6], sizeof (spregs[6]));
+ hexvalue (ctx->sc_ar_fpsr, spregs[7], sizeof (spregs[7]));
+
+ /* Generate the output. */
+ ADD_STRING ("Register dump:\n\n");
+
+ for (i = 0; i < 32 - 5; ++i)
+ ADD_MEM (gpregs[i], sizeof (gpregs[0]) - 1 + ((i % 3) == 2));
+ ADD_STRING ("\n");
+
+ for (i = 0; i < 3; ++i)
+ ADD_MEM (bpregs[i], sizeof (bpregs[0]) - 1);
+
+ ADD_STRING ("\n\n IP: ");
+ ADD_MEM (spregs[0], sizeof (spregs[0]));
+ ADD_STRING (" RSC: ");
+ ADD_MEM (spregs[1], sizeof (spregs[0]));
+ ADD_STRING (" PR: ");
+ ADD_MEM (spregs[2], sizeof (spregs[0]));
+ ADD_STRING ("\n PFS: ");
+ ADD_MEM (spregs[3], sizeof (spregs[0]));
+ ADD_STRING (" UNAT: ");
+ ADD_MEM (spregs[4], sizeof (spregs[0]));
+ ADD_STRING (" CFM: ");
+ ADD_MEM (spregs[5], sizeof (spregs[0]));
+ ADD_STRING ("\n CCV: ");
+ ADD_MEM (spregs[6], sizeof (spregs[0]));
+ ADD_STRING (" FPSR: ");
+ ADD_MEM (spregs[7], sizeof (spregs[0]));
+ ADD_STRING ("\n");
+
+ if (ctx->sc_flags & IA64_SC_FLAG_FPH_VALID)
+ {
+ ADD_STRING ("\n");
+
+ for (i = 0; i < 128 - 32; ++i)
+ ADD_MEM (fpregs[i], sizeof (fpregs[0]) - 1 + (i & 1));
+ }
+
+ /* Write the stuff out. */
+ writev (fd, iov, nr);
+}
+
+
+#define REGISTER_DUMP register_dump (fd, ctx)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/rt-sysdep.S b/libc/sysdeps/unix/sysv/linux/ia64/rt-sysdep.S
new file mode 100644
index 000000000..f966bf1e5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/rt-sysdep.S
@@ -0,0 +1 @@
+#include <sysdep.S>
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/setcontext.S b/libc/sysdeps/unix/sysv/linux/ia64/setcontext.S
new file mode 100644
index 000000000..ef0a93c0c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/setcontext.S
@@ -0,0 +1,153 @@
+/* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <features.h>
+
+#include "ucontext_i.h"
+
+/* __setcontext (const ucontext_t *ucp)
+
+ Restores the machine context in UCP and thereby resumes execution
+ in that context.
+
+ This implementation in intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to restore anything
+ other than the PRESERVED state. */
+
+ENTRY(__setcontext)
+ .prologue
+ .body
+ alloc r11 = ar.pfs, 1, 0, 4, 0
+
+ // sigprocmask (SIG_SETMASK, &sc->sc_mask, NULL):
+
+ mov r3 = SC_MASK
+ mov out0 = SIG_SETMASK
+ ;;
+ add out1 = r3, in0
+ mov out2 = 0
+ mov out3 = 8 // sizeof kernel sigset_t
+
+ invala
+ DO_CALL(__NR_rt_sigprocmask)
+ add r2 = SC_NAT, r32
+
+ add r3 = SC_RNAT, r32 // r3 <- &sc_ar_rnat
+ add rPOS = SC_GR, r32 // rPOS <- &sc_gr[0]
+ ;;
+ ld8 rNAT = [r2], (SC_BSP-SC_NAT)
+ extr.u rPOS = rPOS, 3, 6 // get NaT bit number for r0
+ ;;
+ ld8 rBSP = [r2], (SC_UNAT-SC_BSP)
+ ld8 rRNAT = [r3], (SC_FPSR-SC_RNAT)
+ /*
+ * Rotate NaT bits by rPOS positions to the left:
+ */
+ sub rCPOS = 64, rPOS
+ ;;
+ ld8 rUNAT = [r2], (SC_PFS-SC_UNAT)
+ ld8 rFPSR = [r3], (SC_LC-SC_FPSR)
+ shl rTMP = rNAT, rPOS
+ ;;
+ ld8 rPFS = [r2], (SC_PR-SC_PFS)
+ ld8 rLC = [r3], (SC_BR+0*8-SC_LC)
+ shr.u rNAT = rNAT, rCPOS
+ ;;
+ ld8 rPR = [r2], (SC_BR+1*8-SC_PR)
+ ld8 rB0 = [r3], 16
+ or rNAT = rNAT, rTMP
+ ;;
+ ld8 rB1 = [r2], 16
+ ld8 rB2 = [r3], 16
+ ;;
+ mov.m ar.unat = rNAT
+ mov.m rRSC = ar.rsc
+ ;;
+ ld8 rB3 = [r2], 16
+ ld8 rB4 = [r3], (SC_GR+1*8-(SC_BR+4*8))
+ ;;
+ ld8 rB5 = [r2], (SC_GR+4*8-(SC_BR+5*8))
+ ld8.fill r1 = [r3], (5*8 - 1*8)
+ ;;
+ ld8.fill r4 = [r2], 16
+ ld8.fill r5 = [r3], 16
+ mov b0 = rB0
+ ;;
+ ld8.fill r6 = [r2], 48
+ ld8.fill r7 = [r3], (SC_FR+2*16-(SC_GR+7*8))
+ ;;
+ ld8.fill sp = [r2], (SC_FR+3*16-(SC_GR+12*8))
+ mov.m ar.fpsr = rFPSR
+ mov.i ar.pfs = rPFS
+ ;;
+ ldf.fill f3 = [r2], 16
+ ldf.fill f2 = [r3], 48
+ mov b1 = rB1
+ ;;
+ ldf.fill f4 = [r2], (16*16-4*16)
+ ldf.fill f5 = [r3], (17*16-5*16)
+ mov b2 = rB2
+ ;;
+ ldf.fill f16 = [r2], 32
+ ldf.fill f17 = [r3], 32
+ mov b3 = rB3
+ ;;
+ ldf.fill f18 = [r2], 32
+ ldf.fill f19 = [r3], 32
+ mov b4 = rB4
+ ;;
+ ldf.fill f20 = [r2], 32
+ ldf.fill f21 = [r3], 32
+ mov b5 = rB5
+ ;;
+ ldf.fill f22 = [r2], 32
+ ldf.fill f23 = [r3], 32
+ mov r8 = 0
+ ;;
+ ldf.fill f24 = [r2], 32
+ ldf.fill f25 = [r3], 32
+ mov r9 = 0
+ ;;
+ ldf.fill f26 = [r2], 32
+ ldf.fill f27 = [r3], 32
+ dep rTMP = 0, rRSC, 16, 14 // clear ar.rsc.loadrs
+ ;;
+ ldf.fill f28 = [r2], 32
+ ldf.fill f29 = [r3], 32
+ and rTMP = ~0x3, rTMP // clear ar.rsc.mode
+ ;;
+ ldf.fill f30 = [r2], 32
+ ldf.fill f31 = [r3], 32
+ mov pr = rPR, -1
+ ;;
+ mov.m ar.rsc = rTMP // put RSE into enforced lazy mode
+ ;;
+ loadrs // drop dirty partition
+ ;;
+ mov.m ar.bspstore = rBSP
+ mov.m ar.unat = rUNAT
+ mov.i ar.lc = rLC
+ ;;
+ mov.m ar.rnat = rRNAT
+ mov.m ar.rsc = rRSC
+ ret
+END(__setcontext)
+
+weak_alias (__setcontext, setcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/setjmp.S b/libc/sysdeps/unix/sysv/linux/ia64/setjmp.S
new file mode 100644
index 000000000..53f80d203
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/setjmp.S
@@ -0,0 +1,199 @@
+/* Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005
+ Free Software Foundation, Inc.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA.
+
+ The layout of the jmp_buf is as follows. This is subject to change
+ and user-code should never depend on the particular layout of
+ jmp_buf!
+
+
+ offset: description:
+ ------- ------------
+ 0x000 stack pointer (r12) ; unchangeable (see _JMPBUF_UNWINDS)
+ 0x008 r1 (gp)
+ 0x010 caller's unat
+ 0x018 fpsr
+ 0x020 r4
+ 0x028 r5
+ 0x030 r6
+ 0x038 r7
+ 0x040 rp (b0)
+ 0x048 b1
+ 0x050 b2
+ 0x058 b3
+ 0x060 b4
+ 0x068 b5
+ 0x070 ar.pfs
+ 0x078 ar.lc
+ 0x080 pr
+ 0x088 ar.bsp ; unchangeable (see __longjmp.S)
+ 0x090 ar.unat
+ 0x098 &__jmp_buf ; address of the jmpbuf (needed to locate NaT bits in unat)
+ 0x0a0 f2
+ 0x0b0 f3
+ 0x0c0 f4
+ 0x0d0 f5
+ 0x0e0 f16
+ 0x0f0 f17
+ 0x100 f18
+ 0x110 f19
+ 0x120 f20
+ 0x130 f21
+ 0x130 f22
+ 0x140 f23
+ 0x150 f24
+ 0x160 f25
+ 0x170 f26
+ 0x180 f27
+ 0x190 f28
+ 0x1a0 f29
+ 0x1b0 f30
+ 0x1c0 f31 */
+
+#include <sysdep.h>
+#include <features.h>
+
+ /* The following two entry points are the traditional entry points: */
+
+LEAF(setjmp)
+ alloc r8=ar.pfs,2,0,0,0
+ mov in1=1
+ br.cond.sptk.many _GI___sigsetjmp
+END(setjmp)
+
+LEAF(_setjmp)
+ alloc r8=ar.pfs,2,0,0,0
+ mov in1=0
+ br.cond.sptk.many _GI___sigsetjmp
+END(_setjmp)
+libc_hidden_def (_setjmp)
+
+ /* __sigsetjmp(__jmp_buf buf, int savemask) */
+
+ENTRY(__sigsetjmp)
+ .prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(2)
+ alloc loc1=ar.pfs,2,5,2,0
+ .save ar.unat, loc2
+ mov loc2=ar.unat
+ ;;
+ mov r17=ar.fpsr
+ mov r2=in0
+ add r3=8,in0
+ ;;
+.mem.offset 8,0; st8.spill.nta [r2]=sp,16 // r12 (sp)
+.mem.offset 0,0; st8.spill.nta [r3]=gp,16 // r1 (gp)
+ ;;
+ st8.nta [r2]=loc2,16 // save caller's unat
+ st8.nta [r3]=r17,16 // save fpsr
+ add r8=0xa0,in0
+ ;;
+.mem.offset 8,0; st8.spill.nta [r2]=r4,16 // r4
+.mem.offset 0,0; st8.spill.nta [r3]=r5,16 // r5
+ add r9=0xb0,in0
+ ;;
+ stf.spill.nta [r8]=f2,32
+ stf.spill.nta [r9]=f3,32
+ mov loc0=rp
+ .body
+ ;;
+ stf.spill.nta [r8]=f4,32
+ stf.spill.nta [r9]=f5,32
+ mov r17=b1
+ ;;
+ stf.spill.nta [r8]=f16,32
+ stf.spill.nta [r9]=f17,32
+ mov r18=b2
+ ;;
+ stf.spill.nta [r8]=f18,32
+ stf.spill.nta [r9]=f19,32
+ mov r19=b3
+ ;;
+ stf.spill.nta [r8]=f20,32
+ stf.spill.nta [r9]=f21,32
+ mov r20=b4
+ ;;
+ stf.spill.nta [r8]=f22,32
+ stf.spill.nta [r9]=f23,32
+ mov r21=b5
+ ;;
+ stf.spill.nta [r8]=f24,32
+ stf.spill.nta [r9]=f25,32
+ mov r22=ar.lc
+ ;;
+ stf.spill.nta [r8]=f26,32
+ stf.spill.nta [r9]=f27,32
+ mov r24=pr
+ ;;
+ stf.spill.nta [r8]=f28,32
+ stf.spill.nta [r9]=f29,32
+#ifdef PTR_MANGLE
+ mov loc3=loc0
+ ;;
+ PTR_MANGLE (loc3, loc4)
+#else
+ ;;
+#endif
+ stf.spill.nta [r8]=f30
+ stf.spill.nta [r9]=f31
+
+.mem.offset 8,0; st8.spill.nta [r2]=r6,16 // r6
+.mem.offset 0,0; st8.spill.nta [r3]=r7,16 // r7
+ ;;
+ mov r23=ar.bsp
+ mov r25=ar.unat
+ mov out0=in0
+
+#ifdef PTR_MANGLE
+ st8.nta [r2]=loc3,16 // b0
+#else
+ st8.nta [r2]=loc0,16 // b0
+#endif
+ st8.nta [r3]=r17,16 // b1
+ mov out1=in1
+ ;;
+ st8.nta [r2]=r18,16 // b2
+ st8.nta [r3]=r19,16 // b3
+ ;;
+ st8.nta [r2]=r20,16 // b4
+ st8.nta [r3]=r21,16 // b5
+ ;;
+ st8.nta [r2]=loc1,16 // ar.pfs
+ st8.nta [r3]=r22,16 // ar.lc
+ ;;
+ st8.nta [r2]=r24,16 // pr
+ st8.nta [r3]=r23,16 // ar.bsp
+ ;;
+ st8.nta [r2]=r25 // ar.unat
+ st8.nta [r3]=in0 // &__jmp_buf
+#if defined NOT_IN_libc && defined IS_IN_rtld
+ /* In ld.so we never save the signal mask. */
+ ;;
+#else
+ br.call.dpnt.few rp=__sigjmp_save
+#endif
+.ret0: // force a new bundle ::q
+ mov.m ar.unat=loc2 // restore caller's unat
+ mov rp=loc0
+ mov ar.pfs=loc1
+ mov r8=0
+ ret
+END(__sigsetjmp)
+strong_alias(__sigsetjmp, _GI___sigsetjmp)
+
+weak_extern(_setjmp)
+weak_extern(setjmp)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sigaction.c b/libc/sysdeps/unix/sysv/linux/ia64/sigaction.c
new file mode 100644
index 000000000..fdbc93f0e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sigaction.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 1997-2000,2002,2003,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Linux/IA64 specific sigaction
+ Written by Jes Sorensen, <Jes.Sorensen@cern.ch>, April 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Linux/ia64 only has rt signals, thus we do not even want to try falling
+ back to the old style signals as the default Linux handler does. */
+
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. This is the definition. */
+
+
+/* If ACT is not NULL, change the action for SIG to *ACT.
+ If OACT is not NULL, put the old action for SIG in *OACT. */
+int
+__libc_sigaction (sig, act, oact)
+ int sig;
+ const struct sigaction *act;
+ struct sigaction *oact;
+{
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ return INLINE_SYSCALL (rt_sigaction, 4, sig,
+ CHECK_1_NULL_OK (act), CHECK_1_NULL_OK (oact), _NSIG / 8);
+}
+libc_hidden_def (__libc_sigaction)
+
+#ifdef WRAPPER_INCLUDE
+# include WRAPPER_INCLUDE
+#endif
+
+#ifndef LIBC_SIGACTION
+weak_alias (__libc_sigaction, __sigaction)
+libc_hidden_def (__sigaction)
+weak_alias (__libc_sigaction, sigaction)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sigcontext-offsets.sym b/libc/sysdeps/unix/sysv/linux/ia64/sigcontext-offsets.sym
new file mode 100644
index 000000000..943e68a66
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sigcontext-offsets.sym
@@ -0,0 +1,16 @@
+#include <stddef.h>
+#include <sys/ucontext.h>
+
+--
+SC_NAT offsetof (struct sigcontext, sc_nat)
+SC_BSP offsetof (struct sigcontext, sc_ar_bsp)
+SC_RNAT offsetof (struct sigcontext, sc_ar_rnat)
+SC_UNAT offsetof (struct sigcontext, sc_ar_unat)
+SC_FPSR offsetof (struct sigcontext, sc_ar_fpsr)
+SC_PFS offsetof (struct sigcontext, sc_ar_pfs)
+SC_LC offsetof (struct sigcontext, sc_ar_lc)
+SC_PR offsetof (struct sigcontext, sc_pr)
+SC_BR offsetof (struct sigcontext, sc_br)
+SC_GR offsetof (struct sigcontext, sc_gr)
+SC_FR offsetof (struct sigcontext, sc_fr)
+SC_MASK offsetof (struct sigcontext, sc_mask)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h b/libc/sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h
new file mode 100644
index 000000000..51c11e6b4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define SIGCONTEXT siginfo_t *_si, struct sigcontext *
+#define SIGCONTEXT_EXTRA_ARGS _si,
+#define GET_PC(ctx) ((ctx)->sc_ip)
+#define GET_FRAME(ctx) ((void *) 0)
+#define GET_STACK(ctx) ((void *) 0)
+
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sigpending.c b/libc/sysdeps/unix/sysv/linux/ia64/sigpending.c
new file mode 100644
index 000000000..ae75a5516
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sigpending.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Linux/ia64 only has rt signals, thus we do not even want to try falling
+ back to the old style signals as the default Linux handler does. */
+
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Change the set of blocked signals to SET,
+ wait until a signal arrives, and restore the set of blocked signals. */
+int
+sigpending (set)
+ sigset_t *set;
+{
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ return INLINE_SYSCALL (rt_sigpending, 2, CHECK_SIGSET (set), _NSIG / 8);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sigprocmask.c b/libc/sysdeps/unix/sysv/linux/ia64/sigprocmask.c
new file mode 100644
index 000000000..ba8b05386
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sigprocmask.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Linux/IA64 specific sigprocmask
+ Written by Jes Sorensen, <Jes.Sorensen@cern.ch>, April 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Linux/ia64 only has rt signals, thus we do not even want to try falling
+ back to the old style signals as the default Linux handler does. */
+
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Get and/or change the set of blocked signals. */
+int
+__sigprocmask (how, set, oset)
+ int how;
+ const sigset_t *set;
+ sigset_t *oset;
+{
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ return INLINE_SYSCALL (rt_sigprocmask, 4, how, CHECK_SIGSET (set),
+ CHECK_SIGSET_NULL_OK (oset), _NSIG / 8);
+}
+weak_alias (__sigprocmask, sigprocmask)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/swapcontext.c b/libc/sysdeps/unix/sysv/linux/ia64/swapcontext.c
new file mode 100644
index 000000000..1b9fbdb6a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/swapcontext.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ucontext.h>
+
+struct rv
+ {
+ long retval;
+ long first_return;
+ };
+
+extern struct rv __getcontext (ucontext_t *__ucp) __THROW;
+extern int __setcontext (__const ucontext_t *__ucp) __THROW;
+
+int
+__swapcontext (ucontext_t *oucp, const ucontext_t *ucp)
+{
+ struct rv rv = __getcontext (oucp);
+ if (rv.first_return)
+ __setcontext (ucp);
+ return 0;
+}
+
+weak_alias (__swapcontext, swapcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sys/io.h b/libc/sysdeps/unix/sysv/linux/ia64/sys/io.h
new file mode 100644
index 000000000..14736ff1c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sys/io.h
@@ -0,0 +1,68 @@
+/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IO_H
+#define _SYS_IO_H 1
+
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* If TURN_ON is TRUE, request for permission to do direct i/o on the
+ port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
+ permission off for that range. This call requires root privileges.
+
+ Portability note: not all Linux platforms support this call. Most
+ platforms based on the PC I/O architecture probably will, however.
+ E.g., Linux/Alpha for Alpha PCs supports this. */
+extern int ioperm (unsigned long int __from, unsigned long int __num,
+ int __turn_on);
+
+/* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
+ access any I/O port is granted. This call requires root
+ privileges. */
+extern int iopl (int __level);
+
+extern unsigned int _inb (unsigned long int __port);
+extern unsigned int _inb (unsigned long int __port);
+extern unsigned int _inw (unsigned long int __port);
+extern unsigned int _inl (unsigned long int __port);
+extern void _outb (unsigned char __val, unsigned long int __port);
+extern void _outw (unsigned short __val, unsigned long int __port);
+extern void _outl (unsigned int __val, unsigned long int __port);
+
+#define inb _inb
+#define inw _inw
+#define inl _inl
+#define outb _outb
+#define outw _outw
+#define outl _outl
+
+/* Access PCI space protected from machine checks. */
+extern int pciconfig_read (unsigned long int __bus, unsigned long int __dfn,
+ unsigned long int __off, unsigned long int __len,
+ unsigned char *__buf);
+
+extern int pciconfig_write (unsigned long int __bus, unsigned long int __dfn,
+ unsigned long int __off, unsigned long int __len,
+ unsigned char *__buf);
+
+__END_DECLS
+
+#endif /* _SYS_IO_H */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sys/procfs.h b/libc/sysdeps/unix/sysv/linux/ia64/sys/procfs.h
new file mode 100644
index 000000000..b5196b997
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sys/procfs.h
@@ -0,0 +1,130 @@
+/* Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H 1
+
+/* This is somehow modelled after the file of the same name on SysVr4
+ systems. It provides a definition of the core file format for ELF
+ used on Linux. */
+
+#include <features.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/ucontext.h>
+#include <sys/user.h>
+
+__BEGIN_DECLS
+
+struct elf_siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_code; /* Extra code. */
+ int si_errno; /* Errno. */
+ };
+
+/* We really need just 72 but let's leave some headroom... */
+#define ELF_NGREG 128
+/* f0 and f1 could be omitted, but so what... */
+#define ELF_NFPREG 128
+
+typedef unsigned long elf_greg_t;
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+typedef struct ia64_fpreg elf_fpreg_t;
+typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
+
+typedef elf_greg_t greg_t;
+typedef elf_gregset_t gregset_t;
+typedef elf_fpregset_t fpregset_t;
+#define NGREG ELF_NGREG
+
+/* Definitions to generate Intel SVR4-like core files. These mostly
+ have the same names as the SVR4 types with "elf_" tacked on the
+ front to prevent clashes with linux definitions, and the typedef
+ forms have been avoided. This is mostly like the SVR4 structure,
+ but more Linuxy, with things that Linux does not support and which
+ gdb doesn't really use excluded. Fields present but not used are
+ marked with "XXX". */
+struct elf_prstatus
+ {
+#if 0
+ long int pr_flags; /* XXX Process flags. */
+ short int pr_why; /* XXX Reason for process halt. */
+ short int pr_what; /* XXX More detailed reason. */
+#endif
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned long int pr_sigpend; /* Set of pending signals. */
+ unsigned long int pr_sighold; /* Set of held signals. */
+#if 0
+ struct sigaltstack pr_altstack; /* Alternate stack info. */
+ struct sigaction pr_action; /* Signal action for current sig. */
+#endif
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct timeval pr_utime; /* User time. */
+ struct timeval pr_stime; /* System time. */
+ struct timeval pr_cutime; /* Cumulative user time. */
+ struct timeval pr_cstime; /* Cumulative system time. */
+#if 0
+ long int pr_instr; /* Current instruction. */
+#endif
+ elf_gregset_t pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+
+#define ELF_PRARGSZ (80) /* Number of chars for args */
+
+struct elf_prpsinfo
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned long int pr_flag; /* Flags. */
+ unsigned int pr_uid;
+ unsigned int pr_gid;
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+/* Addresses. */
+typedef void *psaddr_t;
+
+/* Register sets. Linux has different names. */
+typedef gregset_t prgregset_t;
+typedef fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+ therefore habe only ine PID type. */
+typedef __pid_t lwpid_t;
+
+
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+__END_DECLS
+
+#endif /* sys/procfs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h b/libc/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h
new file mode 100644
index 000000000..986c4b2d3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h
@@ -0,0 +1,135 @@
+/* `ptrace' debugger support interface. Linux/ia64 version.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PTRACE_H
+#define _SYS_PTRACE_H 1
+
+#include <features.h>
+#include <sys/ucontext.h>
+
+__BEGIN_DECLS
+
+/* Type of the REQUEST argument to `ptrace.' */
+enum __ptrace_request
+{
+ /* Indicate that the process making this request should be traced.
+ All signals received by this process can be intercepted by its
+ parent, and its parent can use the other `ptrace' requests. */
+ PTRACE_TRACEME = 0,
+#define PT_TRACE_ME PTRACE_TRACEME
+
+ /* Return the word in the process's text space at address ADDR. */
+ PTRACE_PEEKTEXT = 1,
+#define PT_READ_I PTRACE_PEEKTEXT
+
+ /* Return the word in the process's data space at address ADDR. */
+ PTRACE_PEEKDATA = 2,
+#define PT_READ_D PTRACE_PEEKDATA
+
+ /* Return the word in the process's user area at offset ADDR. */
+ PTRACE_PEEKUSER = 3,
+#define PT_READ_U PTRACE_PEEKUSER
+
+ /* Write the word DATA into the process's text space at address ADDR. */
+ PTRACE_POKETEXT = 4,
+#define PT_WRITE_I PTRACE_POKETEXT
+
+ /* Write the word DATA into the process's data space at address ADDR. */
+ PTRACE_POKEDATA = 5,
+#define PT_WRITE_D PTRACE_POKEDATA
+
+ /* Write the word DATA into the process's user area at offset ADDR. */
+ PTRACE_POKEUSER = 6,
+#define PT_WRITE_U PTRACE_POKEUSER
+
+ /* Continue the process. */
+ PTRACE_CONT = 7,
+#define PT_CONTINUE PTRACE_CONT
+
+ /* Kill the process. */
+ PTRACE_KILL = 8,
+#define PT_KILL PTRACE_KILL
+
+ /* Single step the process.
+ This is not supported on all machines. */
+ PTRACE_SINGLESTEP = 9,
+#define PT_STEP PTRACE_SINGLESTEP
+
+ /* Execute process until next taken branch. */
+ PTRACE_SINGLEBLOCK = 12,
+#define PT_STEPBLOCK PTRACE_SINGLEBLOCK
+
+ /* Get siginfo for process. */
+ PTRACE_GETSIGINFO = 13,
+#define PT_GETSIGINFO PTRACE_GETSIGINFO
+
+ /* Set new siginfo for process. */
+ PTRACE_SETSIGINFO = 14,
+#define PT_GETSIGINFO PTRACE_GETSIGINFO
+
+ /* Attach to a process that is already running. */
+ PTRACE_ATTACH = 16,
+#define PT_ATTACH PTRACE_ATTACH
+
+ /* Detach from a process attached to with PTRACE_ATTACH. */
+ PTRACE_DETACH = 17,
+#define PT_DETACH PTRACE_DETACH
+
+ /* Get all registers (pt_all_user_regs) in one shot */
+ PTRACE_GETREGS = 18,
+#define PT_GETREGS PTRACE_GETREGS
+
+ /* Set all registers (pt_all_user_regs) in one shot */
+ PTRACE_SETREGS = 19,
+#define PT_SETREGS PTRACE_SETREGS
+
+ /* Continue and stop at the next (return from) syscall. */
+ PTRACE_SYSCALL = 24
+#define PT_SYSCALL PTRACE_SYSCALL
+};
+
+/* pt_all_user_regs is used for PTRACE_GETREGS/PTRACE_SETREGS. */
+struct pt_all_user_regs
+ {
+ unsigned long nat;
+ unsigned long cr_iip;
+ unsigned long cfm;
+ unsigned long cr_ipsr;
+ unsigned long pr;
+
+ unsigned long gr[32];
+ unsigned long br[8];
+ unsigned long ar[128];
+ struct ia64_fpreg fr[128];
+ };
+
+/* Perform process tracing functions. REQUEST is one of the values
+ above, and determines the action to be taken.
+ For all requests except PTRACE_TRACEME, PID specifies the process to be
+ traced.
+
+ PID and the other arguments described above for the various requests should
+ appear (those that are used for the particular request) as:
+ pid_t PID, void *ADDR, int DATA, void *ADDR2
+ after REQUEST. */
+extern long int ptrace (enum __ptrace_request __request, ...) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_PTRACE_H */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sys/rse.h b/libc/sysdeps/unix/sysv/linux/ia64/sys/rse.h
new file mode 100644
index 000000000..1d1c803d3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sys/rse.h
@@ -0,0 +1,78 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _ia64_rse_h
+#define _ia64_rse_h
+
+#include <features.h>
+
+/* Register stack engine related helper functions. This file may be
+ used in applications, so be careful about the name-space and give
+ some consideration to non-GNU C compilers (though __inline is
+ fine). */
+
+static __inline unsigned long
+ia64_rse_slot_num (unsigned long *addr)
+{
+ return (((unsigned long) addr) >> 3) & 0x3f;
+}
+
+/* Return TRUE if ADDR is the address of an RNAT slot. */
+
+static __inline unsigned long
+ia64_rse_is_rnat_slot (unsigned long *addr)
+{
+ return ia64_rse_slot_num (addr) == 0x3f;
+}
+
+/* Returns the address of the RNAT slot that covers the slot at
+ address SLOT_ADDR. */
+
+static __inline unsigned long *
+ia64_rse_rnat_addr (unsigned long *slot_addr)
+{
+ return (unsigned long *) ((unsigned long) slot_addr | (0x3f << 3));
+}
+
+/* Calcuate the number of registers in the dirty partition starting at
+ BSPSTORE with a size of DIRTY bytes. This isn't simply DIRTY
+ divided by eight because the 64th slot is used to store ar.rnat. */
+
+static __inline unsigned long
+ia64_rse_num_regs (unsigned long *bspstore, unsigned long *bsp)
+{
+ unsigned long slots = (bsp - bspstore);
+
+ return slots - (ia64_rse_slot_num(bspstore) + slots)/0x40;
+}
+
+/* The inverse of the above: given bspstore and the number of
+ registers, calculate ar.bsp. */
+
+static __inline unsigned long *
+ia64_rse_skip_regs (unsigned long *addr, long num_regs)
+{
+ long delta = ia64_rse_slot_num(addr) + num_regs;
+
+ if (num_regs < 0)
+ delta -= 0x3e;
+ return addr + num_regs + delta/0x3f;
+}
+
+#endif /* _ia64_rse_h */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sys/ucontext.h b/libc/sysdeps/unix/sysv/linux/ia64/sys/ucontext.h
new file mode 100644
index 000000000..17dc85f99
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sys/ucontext.h
@@ -0,0 +1,66 @@
+/* Copyright (C) 1998, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+
+#include <features.h>
+#include <signal.h>
+
+#include <bits/sigcontext.h>
+
+/*
+ * These are here mostly for backwards compatibility with older Unices.
+ * IA-64 Linux does not distinguish between "struct sigcontext" and
+ * "ucontext_t" as all the necessary info is inside the former.
+ */
+
+typedef struct sigcontext mcontext_t;
+
+#if defined __cplusplus && __GNUC_PREREQ (3, 5)
+# define _SC_GR0_OFFSET \
+ __builtin_offsetof (struct sigcontext, sc_gr[0])
+#elif defined __GNUC__
+# define _SC_GR0_OFFSET \
+ (((char *) &((struct sigcontext *) 0)->sc_gr[0]) - (char *) 0)
+#else
+# define _SC_GR0_OFFSET 0xc8 /* pray that this is correct... */
+#endif
+
+typedef struct ucontext
+ {
+ union
+ {
+ mcontext_t _mc;
+ struct
+ {
+ unsigned long _pad[_SC_GR0_OFFSET/8];
+ struct ucontext *_link; /* this should overlay sc_gr[0] */
+ }
+ _uc;
+ }
+ _u;
+ }
+ucontext_t;
+
+#define uc_mcontext _u._mc
+#define uc_sigmask _u._mc.sc_mask
+#define uc_stack _u._mc.sc_stack
+#define uc_link _u._uc._link
+
+#endif /* sys/ucontext.h */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sys/user.h b/libc/sysdeps/unix/sysv/linux/ia64/sys/user.h
new file mode 100644
index 000000000..039218761
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sys/user.h
@@ -0,0 +1,54 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_USER_H
+#define _SYS_USER_H 1
+
+#include <features.h>
+#include <sys/types.h>
+
+/* This definition comes directly from the kernel headers. If
+ anything changes in them this header has to be changed, too. */
+
+
+/* The definition in the kernel has the comment "XXX fix me". */
+#define EF_SIZE 3072
+
+
+struct user
+{
+ unsigned long int regs[EF_SIZE / 8 + 32]; /* Integer and fp regs. */
+ size_t u_tsize; /* Text size (pages). */
+ size_t u_dsize; /* Data size (pages). */
+ size_t u_ssize; /* Stack size (pages). */
+ unsigned long int start_code; /* Text starting address. */
+ unsigned long int start_data; /* Data starting address. */
+ unsigned long int start_stack; /* Stack starting address. */
+ long int signal; /* Signal causing core dump. */
+ struct regs *u_ar0; /* Help gdb find registers. */
+ unsigned long int magic; /* Identifies a core file. */
+ char u_comm[32]; /* User command name. */
+};
+
+#define NBPG PAGE_SIZE
+#define UPAGES 1
+#define HOST_TEXT_START_ADDR (u.start_code)
+#define HOST_DATA_START_ADDR (u.start_data)
+#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
+
+#endif /* sys/user.h */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/syscall.S b/libc/sysdeps/unix/sysv/linux/ia64/syscall.S
new file mode 100644
index 000000000..c638cc865
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/syscall.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jes Sorensen <Jes.Sorensen@cern.ch>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+ENTRY(syscall)
+ alloc r2=ar.pfs,1,0,8,0
+ mov r15=r32 /* syscall number */
+ break __BREAK_SYSCALL
+ ;;
+ cmp.ne p6,p0=-1,r10 /* r10 = -1 on error */
+(p6) ret
+ br.cond.spnt.few __syscall_error
+PSEUDO_END(syscall)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/syscalls.list b/libc/sysdeps/unix/sysv/linux/ia64/syscalls.list
new file mode 100644
index 000000000..c55c70ef5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/syscalls.list
@@ -0,0 +1,50 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+umount2 - umount 2 __umount2 umount2
+
+getpriority - getpriority i:ii __getpriority getpriority
+
+# semaphore and shm system calls
+msgctl - msgctl i:iip __msgctl msgctl
+msgget - msgget i:ii __msgget msgget
+msgrcv - msgrcv Ci:ibnii __msgrcv msgrcv
+msgsnd - msgsnd Ci:ibni __msgsnd msgsnd
+shmat - shmat i:ipi __shmat shmat
+shmctl - shmctl i:iip __shmctl shmctl
+shmdt - shmdt i:s __shmdt shmdt
+shmget - shmget i:iii __shmget shmget
+semop - semop i:ipi __semop semop
+semtimedop - semtimedop i:ipip semtimedop
+semget - semget i:iii __semget semget
+semctl - semctl i:iiii __semctl semctl
+
+# proper socket implementations:
+accept - accept Ci:iBN __libc_accept __accept accept
+bind - bind i:ipi __bind bind
+connect - connect Ci:ipi __libc_connect __connect_internal __connect connect
+getpeername - getpeername i:ipp __getpeername getpeername
+getsockname - getsockname i:ipp __getsockname getsockname
+getsockopt - getsockopt i:iiiBN __getsockopt getsockopt
+listen - listen i:ii __listen listen
+recv - recv Ci:ibni __libc_recv __recv recv
+recvfrom - recvfrom Ci:ibniBN __libc_recvfrom __recvfrom recvfrom
+recvmsg - recvmsg Ci:ipi __libc_recvmsg __recvmsg recvmsg
+send - send Ci:ibni __libc_send __send send
+sendmsg - sendmsg Ci:ipi __libc_sendmsg __sendmsg sendmsg
+sendto - sendto Ci:ibnibn __libc_sendto __sendto sendto
+setsockopt - setsockopt i:iiibn __setsockopt setsockopt
+shutdown - shutdown i:ii __shutdown shutdown
+socket - socket i:iii __socket socket
+socketpair - socketpair i:iiif __socketpair socketpair
+
+# DIG-compliant access to PCI configuration space:
+pciconfig_read EXTRA pciconfig_read 5 pciconfig_read
+pciconfig_write EXTRA pciconfig_write 5 pciconfig_write
+
+ptrace - ptrace 4 __ptrace ptrace
+
+
+# System calls with wrappers.
+
+# IA-64 specific
+getunwind EXTRA getunwind i:pi getunwind
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sysconf.c b/libc/sysdeps/unix/sysv/linux/ia64/sysconf.c
new file mode 100644
index 000000000..4b5d1ce2c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sysconf.c
@@ -0,0 +1,45 @@
+/* Get file-specific information about a file. Linux version.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+#include "has_cpuclock.c"
+
+static long int linux_sysconf (int name);
+
+
+/* Get the value of the system variable NAME. */
+long int
+__sysconf (int name)
+{
+ if (name == _SC_CPUTIME || name == _SC_THREAD_CPUTIME)
+ return has_cpuclock () ? 200112L : -1;
+
+ /* Everything else is handled by the more general code. */
+ return linux_sysconf (name);
+}
+
+/* Now the generic Linux version. */
+#undef __sysconf
+#define __sysconf static linux_sysconf
+#include "../sysconf.c"
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sysdep.S b/libc/sysdeps/unix/sysv/linux/ia64/sysdep.S
new file mode 100644
index 000000000..3633dd4b7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sysdep.S
@@ -0,0 +1,89 @@
+/* Copyright (C) 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <features.h>
+#include <tls.h>
+
+ENTRY(__syscall_error)
+#if RTLD_PRIVATE_ERRNO
+ /*
+ * Note that the gp has to be set properly for this to work.
+ * As long as all syscalls are in the same load unit
+ * (executable or shared library) as this routine, we should
+ * be fine. Otherwise, we would have to first load the global
+ * pointer register from __gp.
+ */
+ addl r2=@gprel(rtld_errno),gp
+ ;;
+ st4 [r2]=r8
+ mov r8=-1
+#elif USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+# define SYSCALL_ERROR_ERRNO errno
+# endif
+ addl r2=@ltoff(@tprel(SYSCALL_ERROR_ERRNO)), gp;;
+ ld8 r2=[r2]
+ mov r3=r8;;
+ mov r8=-1
+ add r2=r2,r13;;
+ st4 [r2]=r3
+#elif defined _LIBC_REENTRANT
+ .prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(0)
+ alloc r33=ar.pfs, 0, 4, 0, 0
+ mov r32=rp
+ .body
+ mov r35=r8
+ mov r34=r1
+ ;;
+ br.call.sptk.many b0 = __errno_location
+.Lret0: /* force new bundle */
+ st4 [r8]=r35
+ mov r1=r34
+ mov rp=r32
+ mov r8=-1
+ mov ar.pfs=r33
+#else /* _LIBC_REENTRANT */
+ /*
+ * Note that the gp has to be set properly for this to work.
+ * As long as all syscalls are in the same load unit
+ * (executable or shared library) as this routine, we should
+ * be fine. Otherwise, we would have to first load the global
+ * pointer register from __gp.
+ */
+ addl r2=@ltoff(errno),gp
+ ;;
+ ld8 r2=[r2]
+ mov r3=r8
+ mov r8=-1
+ ;;
+ st4 [r2]=r3
+#endif /* _LIBC_REENTRANT */
+ ret // ret is #define'd in syscall.h!
+END(__syscall_error)
+
+ENTRY(__ia64_syscall)
+ mov r15=r37 /* syscall number */
+ break __BREAK_SYSCALL
+ cmp.eq p6,p0=-1,r10 /* r10 = -1 on error */
+(p6) br.cond.spnt.few __syscall_error
+ ret
+PSEUDO_END(__ia64_syscall)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/sysdep.h b/libc/sysdeps/unix/sysv/linux/ia64/sysdep.h
new file mode 100644
index 000000000..dd7a5b1b1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/sysdep.h
@@ -0,0 +1,384 @@
+/* Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Jes Sorensen, <Jes.Sorensen@cern.ch>, April 1999.
+ Based on code originally written by David Mosberger-Tang
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_IA64_SYSDEP_H
+#define _LINUX_IA64_SYSDEP_H 1
+
+#include <sysdeps/unix/sysdep.h>
+#include <sysdeps/ia64/sysdep.h>
+#include <dl-sysdep.h>
+#include <tls.h>
+
+/* As of GAS v2.4.90.0.7, including a ".align" directive inside a
+ function will cause bad unwind info to be emitted (GAS doesn't know
+ how to account for the padding introduced by the .align directive).
+ Turning on this macro will work around this bug by introducing the
+ necessary padding explicitly. */
+#define GAS_ALIGN_BREAKS_UNWIND_INFO
+
+/* For Linux we can use the system call table in the header file
+ /usr/include/asm/unistd.h
+ of the kernel. But these symbols do not follow the SYS_* syntax
+ so we have to redefine the `SYS_ify' macro here. */
+#undef SYS_ify
+#ifdef __STDC__
+# define SYS_ify(syscall_name) __NR_##syscall_name
+#else
+# define SYS_ify(syscall_name) __NR_/**/syscall_name
+#endif
+
+/* This is a kludge to make syscalls.list find these under the names
+ pread and pwrite, since some kernel headers define those names
+ and some define the *64 names for the same system calls. */
+#if !defined __NR_pread && defined __NR_pread64
+# define __NR_pread __NR_pread64
+#endif
+#if !defined __NR_pwrite && defined __NR_pwrite64
+# define __NR_pwrite __NR_pwrite64
+#endif
+
+/* This is to help the old kernel headers where __NR_semtimedop is not
+ available. */
+#ifndef __NR_semtimedop
+# define __NR_semtimedop 1247
+#endif
+
+#if defined USE_DL_SYSINFO \
+ && (!defined NOT_IN_libc \
+ || defined IS_IN_libpthread || defined IS_IN_librt)
+# define IA64_USE_NEW_STUB
+#else
+# undef IA64_USE_NEW_STUB
+#endif
+
+#ifdef __ASSEMBLER__
+
+#undef CALL_MCOUNT
+#ifdef PROF
+# define CALL_MCOUNT \
+ .data; \
+1: data8 0; /* XXX fixme: use .xdata8 once labels work */ \
+ .previous; \
+ .prologue; \
+ .save ar.pfs, r40; \
+ alloc out0 = ar.pfs, 8, 0, 4, 0; \
+ mov out1 = gp; \
+ .save rp, out2; \
+ mov out2 = rp; \
+ .body; \
+ ;; \
+ addl out3 = @ltoff(1b), gp; \
+ br.call.sptk.many rp = _mcount \
+ ;;
+#else
+# define CALL_MCOUNT /* Do nothing. */
+#endif
+
+/* Linux uses a negative return value to indicate syscall errors, unlike
+ most Unices, which use the condition codes' carry flag.
+
+ Since version 2.1 the return value of a system call might be negative
+ even if the call succeeded. E.g., the `lseek' system call might return
+ a large offset. Therefore we must not anymore test for < 0, but test
+ for a real error by making sure the value in %d0 is a real error
+ number. Linus said he will make sure the no syscall returns a value
+ in -1 .. -4095 as a valid result so we can savely test with -4095. */
+
+/* We don't want the label for the error handler to be visible in the symbol
+ table when we define it here. */
+#define SYSCALL_ERROR_LABEL __syscall_error
+
+#undef PSEUDO
+#define PSEUDO(name, syscall_name, args) \
+ ENTRY(name) \
+ DO_CALL (SYS_ify(syscall_name)); \
+ cmp.eq p6,p0=-1,r10; \
+(p6) br.cond.spnt.few __syscall_error;
+
+#define DO_CALL_VIA_BREAK(num) \
+ mov r15=num; \
+ break __BREAK_SYSCALL
+
+#ifdef IA64_USE_NEW_STUB
+# ifdef SHARED
+# define DO_CALL(num) \
+ .prologue; \
+ adds r2 = SYSINFO_OFFSET, r13;; \
+ ld8 r2 = [r2]; \
+ .save ar.pfs, r11; \
+ mov r11 = ar.pfs;; \
+ .body; \
+ mov r15 = num; \
+ mov b7 = r2; \
+ br.call.sptk.many b6 = b7;; \
+ .restore sp; \
+ mov ar.pfs = r11; \
+ .prologue; \
+ .body
+# else /* !SHARED */
+# define DO_CALL(num) \
+ .prologue; \
+ mov r15 = num; \
+ movl r2 = _dl_sysinfo;; \
+ ld8 r2 = [r2]; \
+ .save ar.pfs, r11; \
+ mov r11 = ar.pfs;; \
+ .body; \
+ mov b7 = r2; \
+ br.call.sptk.many b6 = b7;; \
+ .restore sp; \
+ mov ar.pfs = r11; \
+ .prologue; \
+ .body
+# endif
+#else
+# define DO_CALL(num) DO_CALL_VIA_BREAK(num)
+#endif
+
+#undef PSEUDO_END
+#define PSEUDO_END(name) .endp C_SYMBOL_NAME(name);
+
+#undef PSEUDO_NOERRNO
+#define PSEUDO_NOERRNO(name, syscall_name, args) \
+ ENTRY(name) \
+ DO_CALL (SYS_ify(syscall_name));
+
+#undef PSEUDO_END_NOERRNO
+#define PSEUDO_END_NOERRNO(name) .endp C_SYMBOL_NAME(name);
+
+#undef PSEUDO_ERRVAL
+#define PSEUDO_ERRVAL(name, syscall_name, args) \
+ ENTRY(name) \
+ DO_CALL (SYS_ify(syscall_name)); \
+ cmp.eq p6,p0=-1,r10; \
+(p6) mov r10=r8;
+
+
+#undef PSEUDO_END_ERRVAL
+#define PSEUDO_END_ERRVAL(name) .endp C_SYMBOL_NAME(name);
+
+#undef END
+#define END(name) \
+ .size C_SYMBOL_NAME(name), . - C_SYMBOL_NAME(name) ; \
+ .endp C_SYMBOL_NAME(name)
+
+#define ret br.ret.sptk.few b0
+#define ret_NOERRNO ret
+#define ret_ERRVAL ret
+
+#else /* not __ASSEMBLER__ */
+
+#define BREAK_INSN_1(num) "break " #num ";;\n\t"
+#define BREAK_INSN(num) BREAK_INSN_1(num)
+
+/* On IA-64 we have stacked registers for passing arguments. The
+ "out" registers end up being the called function's "in"
+ registers.
+
+ Also, since we have plenty of registers we have two return values
+ from a syscall. r10 is set to -1 on error, whilst r8 contains the
+ (non-negative) errno on error or the return value on success.
+ */
+
+#ifdef IA64_USE_NEW_STUB
+
+# define DO_INLINE_SYSCALL_NCS(name, nr, args...) \
+ LOAD_ARGS_##nr (args) \
+ register long _r8 __asm ("r8"); \
+ register long _r10 __asm ("r10"); \
+ register long _r15 __asm ("r15") = name; \
+ register void *_b7 __asm ("b7") = ((tcbhead_t *)__thread_self)->__private;\
+ long _retval; \
+ LOAD_REGS_##nr \
+ /* \
+ * Don't specify any unwind info here. We mark ar.pfs as \
+ * clobbered. This will force the compiler to save ar.pfs \
+ * somewhere and emit appropriate unwind info for that save. \
+ */ \
+ __asm __volatile ("br.call.sptk.many b6=%0;;\n" \
+ : "=b"(_b7), "=r" (_r8), "=r" (_r10), "=r" (_r15) \
+ ASM_OUTARGS_##nr \
+ : "0" (_b7), "3" (_r15) ASM_ARGS_##nr \
+ : "memory", "ar.pfs" ASM_CLOBBERS_##nr); \
+ _retval = _r8;
+
+#else /* !IA64_USE_NEW_STUB */
+
+# define DO_INLINE_SYSCALL_NCS(name, nr, args...) \
+ LOAD_ARGS_##nr (args) \
+ register long _r8 asm ("r8"); \
+ register long _r10 asm ("r10"); \
+ register long _r15 asm ("r15") = name; \
+ long _retval; \
+ LOAD_REGS_##nr \
+ __asm __volatile (BREAK_INSN (__BREAK_SYSCALL) \
+ : "=r" (_r8), "=r" (_r10), "=r" (_r15) \
+ ASM_OUTARGS_##nr \
+ : "2" (_r15) ASM_ARGS_##nr \
+ : "memory" ASM_CLOBBERS_##nr); \
+ _retval = _r8;
+
+#endif /* !IA64_USE_NEW_STUB */
+
+#define DO_INLINE_SYSCALL(name, nr, args...) \
+ DO_INLINE_SYSCALL_NCS (__NR_##name, nr, ##args)
+
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...) \
+ ({ \
+ DO_INLINE_SYSCALL_NCS (__NR_##name, nr, args) \
+ if (_r10 == -1) \
+ { \
+ __set_errno (_retval); \
+ _retval = -1; \
+ } \
+ _retval; })
+
+#undef INTERNAL_SYSCALL_DECL
+#define INTERNAL_SYSCALL_DECL(err) long int err
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({ \
+ DO_INLINE_SYSCALL_NCS (name, nr, args) \
+ err = _r10; \
+ _retval; })
+#define INTERNAL_SYSCALL(name, err, nr, args...) \
+ INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
+
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val, err) (err == -1)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val, err) (val)
+
+#define LOAD_ARGS_0()
+#define LOAD_REGS_0
+#define LOAD_ARGS_1(a1) \
+ long _arg1 = (long) (a1); \
+ LOAD_ARGS_0 ()
+#define LOAD_REGS_1 \
+ register long _out0 asm ("out0") = _arg1; \
+ LOAD_REGS_0
+#define LOAD_ARGS_2(a1, a2) \
+ long _arg2 = (long) (a2); \
+ LOAD_ARGS_1 (a1)
+#define LOAD_REGS_2 \
+ register long _out1 asm ("out1") = _arg2; \
+ LOAD_REGS_1
+#define LOAD_ARGS_3(a1, a2, a3) \
+ long _arg3 = (long) (a3); \
+ LOAD_ARGS_2 (a1, a2)
+#define LOAD_REGS_3 \
+ register long _out2 asm ("out2") = _arg3; \
+ LOAD_REGS_2
+#define LOAD_ARGS_4(a1, a2, a3, a4) \
+ long _arg4 = (long) (a4); \
+ LOAD_ARGS_3 (a1, a2, a3)
+#define LOAD_REGS_4 \
+ register long _out3 asm ("out3") = _arg4; \
+ LOAD_REGS_3
+#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
+ long _arg5 = (long) (a5); \
+ LOAD_ARGS_4 (a1, a2, a3, a4)
+#define LOAD_REGS_5 \
+ register long _out4 asm ("out4") = _arg5; \
+ LOAD_REGS_4
+#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
+ long _arg6 = (long) (a6); \
+ LOAD_ARGS_5 (a1, a2, a3, a4, a5)
+#define LOAD_REGS_6 \
+ register long _out5 asm ("out5") = _arg6; \
+ LOAD_REGS_5
+
+#define ASM_OUTARGS_0
+#define ASM_OUTARGS_1 ASM_OUTARGS_0, "=r" (_out0)
+#define ASM_OUTARGS_2 ASM_OUTARGS_1, "=r" (_out1)
+#define ASM_OUTARGS_3 ASM_OUTARGS_2, "=r" (_out2)
+#define ASM_OUTARGS_4 ASM_OUTARGS_3, "=r" (_out3)
+#define ASM_OUTARGS_5 ASM_OUTARGS_4, "=r" (_out4)
+#define ASM_OUTARGS_6 ASM_OUTARGS_5, "=r" (_out5)
+
+#ifdef IA64_USE_NEW_STUB
+#define ASM_ARGS_0
+#define ASM_ARGS_1 ASM_ARGS_0, "4" (_out0)
+#define ASM_ARGS_2 ASM_ARGS_1, "5" (_out1)
+#define ASM_ARGS_3 ASM_ARGS_2, "6" (_out2)
+#define ASM_ARGS_4 ASM_ARGS_3, "7" (_out3)
+#define ASM_ARGS_5 ASM_ARGS_4, "8" (_out4)
+#define ASM_ARGS_6 ASM_ARGS_5, "9" (_out5)
+#else
+#define ASM_ARGS_0
+#define ASM_ARGS_1 ASM_ARGS_0, "3" (_out0)
+#define ASM_ARGS_2 ASM_ARGS_1, "4" (_out1)
+#define ASM_ARGS_3 ASM_ARGS_2, "5" (_out2)
+#define ASM_ARGS_4 ASM_ARGS_3, "6" (_out3)
+#define ASM_ARGS_5 ASM_ARGS_4, "7" (_out4)
+#define ASM_ARGS_6 ASM_ARGS_5, "8" (_out5)
+#endif
+
+#define ASM_CLOBBERS_0 ASM_CLOBBERS_1, "out0"
+#define ASM_CLOBBERS_1 ASM_CLOBBERS_2, "out1"
+#define ASM_CLOBBERS_2 ASM_CLOBBERS_3, "out2"
+#define ASM_CLOBBERS_3 ASM_CLOBBERS_4, "out3"
+#define ASM_CLOBBERS_4 ASM_CLOBBERS_5, "out4"
+#define ASM_CLOBBERS_5 ASM_CLOBBERS_6, "out5"
+#define ASM_CLOBBERS_6_COMMON , "out6", "out7", \
+ /* Non-stacked integer registers, minus r8, r10, r15. */ \
+ "r2", "r3", "r9", "r11", "r12", "r13", "r14", "r16", "r17", "r18", \
+ "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", \
+ "r28", "r29", "r30", "r31", \
+ /* Predicate registers. */ \
+ "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
+ /* Non-rotating fp registers. */ \
+ "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
+ /* Branch registers. */ \
+ "b6"
+
+#ifdef IA64_USE_NEW_STUB
+# define ASM_CLOBBERS_6 ASM_CLOBBERS_6_COMMON
+#else
+# define ASM_CLOBBERS_6 ASM_CLOBBERS_6_COMMON , "b7"
+#endif
+
+#endif /* not __ASSEMBLER__ */
+
+/* Pointer mangling support. */
+#if defined NOT_IN_libc && defined IS_IN_rtld
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+ earlier than the descriptor is initialized. */
+#else
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(reg, tmpreg) \
+ add tmpreg=-16,r13 \
+ ;; \
+ ld8 tmpreg=[tmpreg] \
+ ;; \
+ xor reg=reg, tmpreg
+# define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
+# else
+# define PTR_MANGLE(var) \
+ (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+# define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* linux/ia64/sysdep.h */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/system.c b/libc/sysdeps/unix/sysv/linux/ia64/system.c
new file mode 100644
index 000000000..413ff27b3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/system.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <kernel-features.h>
+
+/* We have to and actually can handle cancelable system(). The big
+ problem: we have to kill the child process if necessary. To do
+ this a cleanup handler has to be registered and is has to be able
+ to find the PID of the child. The main problem is to reliable have
+ the PID when needed. It is not necessary for the parent thread to
+ return. It might still be in the kernel when the cancellation
+ request comes. Therefore we have to use the clone() calls ability
+ to have the kernel write the PID into the user-level variable. */
+#ifdef __ASSUME_CLONE_THREAD_FLAGS
+# define FORK() \
+ INLINE_SYSCALL (clone2, 6, CLONE_PARENT_SETTID | SIGCHLD, NULL, 0, \
+ &pid, NULL, NULL)
+#endif
+
+#include "../system.c"
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/ucontext_i.h b/libc/sysdeps/unix/sysv/linux/ia64/ucontext_i.h
new file mode 100644
index 000000000..e2a4d3c2b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/ucontext_i.h
@@ -0,0 +1,47 @@
+/* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Constants shared between setcontext() and getcontext(). Don't
+ install this header file. */
+
+#define SIG_BLOCK 0
+#define SIG_UNBLOCK 1
+#define SIG_SETMASK 2
+
+#include <sigcontext-offsets.h>
+
+#define rTMP r16
+#define rPOS r16
+#define rCPOS r17
+#define rNAT r18
+
+#define rB5 r18
+#define rB4 r19
+#define rB3 r20
+#define rB2 r21
+#define rB1 r22
+#define rB0 r23
+#define rRSC r24
+#define rBSP r25
+#define rRNAT r26
+#define rUNAT r27
+#define rFPSR r28
+#define rPFS r29
+#define rLC r30
+#define rPR r31
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/umount.c b/libc/sysdeps/unix/sysv/linux/ia64/umount.c
new file mode 100644
index 000000000..462ace325
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/umount.c
@@ -0,0 +1,31 @@
+/* umount system call for Linux/ia64.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/mount.h>
+#include <errno.h>
+
+#include <sysdep.h>
+#include <bp-checks.h>
+
+/* Unmount a filesystem. */
+int
+umount (const char *special_file)
+{
+ return INLINE_SYSCALL (umount, 2, CHECK_STRING (special_file), 0);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/unwind-dw2-fde.c b/libc/sysdeps/unix/sysv/linux/ia64/unwind-dw2-fde.c
new file mode 100644
index 000000000..15d12abfc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/unwind-dw2-fde.c
@@ -0,0 +1 @@
+/* Linux/ia64 does not need unwind table registry. */
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/vfork.S b/libc/sysdeps/unix/sysv/linux/ia64/vfork.S
new file mode 100644
index 000000000..086fce938
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/vfork.S
@@ -0,0 +1,44 @@
+/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+#include <sysdep.h>
+#define _SIGNAL_H
+#include <bits/signum.h>
+
+/* The following are defined in linux/sched.h, which unfortunately */
+/* is not safe for inclusion in an assembly file. */
+#define CLONE_VM 0x00000100 /* set if VM shared between processes */
+#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
+
+/* pid_t vfork(void); */
+/* Implemented as __clone_syscall(CLONE_VFORK | CLONE_VM | SIGCHLD, 0) */
+
+ENTRY(__vfork)
+ alloc r2=ar.pfs,0,0,2,0
+ mov out0=CLONE_VM+CLONE_VFORK+SIGCHLD
+ mov out1=0 /* Standard sp value. */
+ ;;
+ DO_CALL_VIA_BREAK (SYS_ify (clone))
+ cmp.eq p6,p0=-1,r10
+(p6) br.cond.spnt.few __syscall_error
+ ret
+PSEUDO_END(__vfork)
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/sysdeps/unix/sysv/linux/ia64/wordexp.c b/libc/sysdeps/unix/sysv/linux/ia64/wordexp.c
new file mode 100644
index 000000000..2e3d5bc2e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ia64/wordexp.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/alpha/wordexp.c>
diff --git a/libc/sysdeps/unix/sysv/linux/if_index.c b/libc/sysdeps/unix/sysv/linux/if_index.c
new file mode 100644
index 000000000..66f0ac131
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/if_index.c
@@ -0,0 +1,474 @@
+/* Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <alloca.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <bits/libc-lock.h>
+#include <not-cancel.h>
+
+#include "netlinkaccess.h"
+
+
+/* Variable to signal whether SIOCGIFCONF is not available. */
+# if __ASSUME_SIOCGIFNAME == 0
+static int old_siocgifconf;
+#else
+# define old_siocgifconf 0
+#endif
+
+
+unsigned int
+if_nametoindex (const char *ifname)
+{
+#ifndef SIOCGIFINDEX
+ __set_errno (ENOSYS);
+ return 0;
+#else
+ struct ifreq ifr;
+ int fd = __opensock ();
+
+ if (fd < 0)
+ return 0;
+
+ strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
+ if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0)
+ {
+ int saved_errno = errno;
+ close_not_cancel_no_status (fd);
+ if (saved_errno == EINVAL)
+ __set_errno (ENOSYS);
+ return 0;
+ }
+ close_not_cancel_no_status (fd);
+ return ifr.ifr_ifindex;
+#endif
+}
+libc_hidden_def (if_nametoindex)
+
+
+void
+if_freenameindex (struct if_nameindex *ifn)
+{
+ struct if_nameindex *ptr = ifn;
+ while (ptr->if_name || ptr->if_index)
+ {
+ free (ptr->if_name);
+ ++ptr;
+ }
+ free (ifn);
+}
+libc_hidden_def (if_freenameindex)
+
+
+#if __ASSUME_NETLINK_SUPPORT == 0
+static struct if_nameindex *
+if_nameindex_ioctl (void)
+{
+ int fd = __opensock ();
+ struct ifconf ifc;
+ unsigned int nifs, i;
+ int rq_len;
+ struct if_nameindex *idx = NULL;
+# define RQ_IFS 4
+
+ if (fd < 0)
+ return NULL;
+
+ ifc.ifc_buf = NULL;
+
+ /* We may be able to get the needed buffer size directly, rather than
+ guessing. */
+ if (! old_siocgifconf)
+ {
+ ifc.ifc_buf = NULL;
+ ifc.ifc_len = 0;
+ if (__ioctl (fd, SIOCGIFCONF, &ifc) < 0 || ifc.ifc_len == 0)
+ {
+# if __ASSUME_SIOCGIFNAME == 0
+ old_siocgifconf = 1;
+# endif
+ rq_len = RQ_IFS * sizeof (struct ifreq);
+ }
+ else
+ rq_len = ifc.ifc_len;
+ }
+ else
+ rq_len = RQ_IFS * sizeof (struct ifreq);
+
+ /* Read all the interfaces out of the kernel. */
+ ifc.ifc_buf = alloca (rq_len);
+ ifc.ifc_len = rq_len;
+ while (1)
+ {
+ if (__ioctl (fd, SIOCGIFCONF, &ifc) < 0)
+ {
+ close_not_cancel_no_status (fd);
+ return NULL;
+ }
+ if (ifc.ifc_len < rq_len || ! old_siocgifconf)
+ break;
+
+ ifc.ifc_buf = extend_alloca (ifc.ifc_buf, rq_len, 2 * rq_len);
+ ifc.ifc_len = rq_len;
+ }
+
+ nifs = ifc.ifc_len / sizeof (struct ifreq);
+
+ idx = malloc ((nifs + 1) * sizeof (struct if_nameindex));
+ if (idx == NULL)
+ {
+ close_not_cancel_no_status (fd);
+ __set_errno (ENOBUFS);
+ return NULL;
+ }
+
+ for (i = 0; i < nifs; ++i)
+ {
+ struct ifreq *ifr = &ifc.ifc_req[i];
+ idx[i].if_name = __strdup (ifr->ifr_name);
+ if (idx[i].if_name == NULL
+ || __ioctl (fd, SIOCGIFINDEX, ifr) < 0)
+ {
+ int saved_errno = errno;
+ unsigned int j;
+
+ for (j = 0; j < i; ++j)
+ free (idx[j].if_name);
+ free (idx);
+ close_not_cancel_no_status (fd);
+ if (saved_errno == EINVAL)
+ saved_errno = ENOSYS;
+ else if (saved_errno == ENOMEM)
+ saved_errno = ENOBUFS;
+ __set_errno (saved_errno);
+ return NULL;
+ }
+ idx[i].if_index = ifr->ifr_ifindex;
+ }
+
+ idx[i].if_index = 0;
+ idx[i].if_name = NULL;
+
+ close_not_cancel_no_status (fd);
+ return idx;
+}
+#endif
+
+
+static struct if_nameindex *
+if_nameindex_netlink (void)
+{
+ struct netlink_handle nh = { 0, 0, 0, NULL, NULL };
+ struct if_nameindex *idx = NULL;
+
+ if (__no_netlink_support || __netlink_open (&nh) < 0)
+ return NULL;
+
+
+ /* Tell the kernel that we wish to get a list of all
+ active interfaces. Collect all data for every interface. */
+ if (__netlink_request (&nh, RTM_GETLINK) < 0)
+ goto exit_free;
+
+ /* Count the interfaces. */
+ unsigned int nifs = 0;
+ for (struct netlink_res *nlp = nh.nlm_list; nlp; nlp = nlp->next)
+ {
+ struct nlmsghdr *nlh;
+ size_t size = nlp->size;
+
+ if (nlp->nlh == NULL)
+ continue;
+
+ /* Walk through all entries we got from the kernel and look, which
+ message type they contain. */
+ for (nlh = nlp->nlh; NLMSG_OK (nlh, size); nlh = NLMSG_NEXT (nlh, size))
+ {
+ /* Check if the message is what we want. */
+ if ((pid_t) nlh->nlmsg_pid != nh.pid || nlh->nlmsg_seq != nlp->seq)
+ continue;
+
+ if (nlh->nlmsg_type == NLMSG_DONE)
+ break; /* ok */
+
+ if (nlh->nlmsg_type == RTM_NEWLINK)
+ ++nifs;
+ }
+ }
+
+ idx = malloc ((nifs + 1) * sizeof (struct if_nameindex));
+ if (idx == NULL)
+ {
+ nomem:
+ __set_errno (ENOBUFS);
+ goto exit_free;
+ }
+
+ /* Add the interfaces. */
+ nifs = 0;
+ for (struct netlink_res *nlp = nh.nlm_list; nlp; nlp = nlp->next)
+ {
+ struct nlmsghdr *nlh;
+ size_t size = nlp->size;
+
+ if (nlp->nlh == NULL)
+ continue;
+
+ /* Walk through all entries we got from the kernel and look, which
+ message type they contain. */
+ for (nlh = nlp->nlh; NLMSG_OK (nlh, size); nlh = NLMSG_NEXT (nlh, size))
+ {
+ /* Check if the message is what we want. */
+ if ((pid_t) nlh->nlmsg_pid != nh.pid || nlh->nlmsg_seq != nlp->seq)
+ continue;
+
+ if (nlh->nlmsg_type == NLMSG_DONE)
+ break; /* ok */
+
+ if (nlh->nlmsg_type == RTM_NEWLINK)
+ {
+ struct ifinfomsg *ifim = (struct ifinfomsg *) NLMSG_DATA (nlh);
+ struct rtattr *rta = IFLA_RTA (ifim);
+ size_t rtasize = IFLA_PAYLOAD (nlh);
+
+ idx[nifs].if_index = ifim->ifi_index;
+
+ while (RTA_OK (rta, rtasize))
+ {
+ char *rta_data = RTA_DATA (rta);
+ size_t rta_payload = RTA_PAYLOAD (rta);
+
+ if (rta->rta_type == IFLA_IFNAME)
+ {
+ idx[nifs].if_name = __strndup (rta_data, rta_payload);
+ if (idx[nifs].if_name == NULL)
+ {
+ idx[nifs].if_index = 0;
+ if_freenameindex (idx);
+ idx = NULL;
+ goto nomem;
+ }
+ break;
+ }
+
+ rta = RTA_NEXT (rta, rtasize);
+ }
+
+ ++nifs;
+ }
+ }
+ }
+
+ idx[nifs].if_index = 0;
+ idx[nifs].if_name = NULL;
+
+ exit_free:
+ __netlink_free_handle (&nh);
+ __netlink_close (&nh);
+
+ return idx;
+}
+
+
+struct if_nameindex *
+if_nameindex (void)
+{
+#ifndef SIOCGIFINDEX
+ __set_errno (ENOSYS);
+ return NULL;
+#else
+ struct if_nameindex *result = if_nameindex_netlink ();
+# if __ASSUME_NETLINK_SUPPORT == 0
+ if (__no_netlink_support)
+ result = if_nameindex_ioctl ();
+# endif
+ return result;
+#endif
+}
+libc_hidden_def (if_nameindex)
+
+
+char *
+if_indextoname (unsigned int ifindex, char *ifname)
+{
+#if !defined SIOCGIFINDEX && __ASSUME_SIOCGIFNAME == 0
+ __set_errno (ENOSYS);
+ return NULL;
+#else
+# if __ASSUME_SIOCGIFNAME == 0
+ struct if_nameindex *idx;
+ struct if_nameindex *p;
+ char *result = NULL;
+# endif
+
+# if defined SIOCGIFNAME || __ASSUME_SIOCGIFNAME > 0
+ /* We may be able to do the conversion directly, rather than searching a
+ list. This ioctl is not present in kernels before version 2.1.50. */
+ struct ifreq ifr;
+ int fd;
+# if __ASSUME_SIOCGIFNAME == 0
+ static int siocgifname_works_not;
+
+ if (!siocgifname_works_not)
+# endif
+ {
+# if __ASSUME_SIOCGIFNAME == 0
+ int serrno = errno;
+# endif
+ int status;
+
+ fd = __opensock ();
+
+ if (fd < 0)
+ return NULL;
+
+ ifr.ifr_ifindex = ifindex;
+ status = __ioctl (fd, SIOCGIFNAME, &ifr);
+
+ close_not_cancel_no_status (fd);
+
+ if (status < 0)
+ {
+# if __ASSUME_SIOCGIFNAME == 0
+ if (errno == EINVAL)
+ siocgifname_works_not = 1; /* Don't make the same mistake twice. */
+ else
+# endif
+ {
+ if (errno == ENODEV)
+ /* POSIX requires ENXIO. */
+ __set_errno (ENXIO);
+
+ return NULL;
+ }
+ }
+ else
+ return strncpy (ifname, ifr.ifr_name, IFNAMSIZ);
+
+# if __ASSUME_SIOCGIFNAME == 0
+ __set_errno (serrno);
+# endif
+ }
+# endif
+
+# if __ASSUME_SIOCGIFNAME == 0
+ idx = if_nameindex ();
+
+ if (idx != NULL)
+ {
+ for (p = idx; p->if_index || p->if_name; ++p)
+ if (p->if_index == ifindex)
+ {
+ result = strncpy (ifname, p->if_name, IFNAMSIZ);
+ break;
+ }
+
+ if_freenameindex (idx);
+
+ if (result == NULL)
+ __set_errno (ENXIO);
+ }
+ return result;
+# endif
+#endif
+}
+libc_hidden_def (if_indextoname)
+
+
+#if 0
+void
+internal_function
+__protocol_available (int *have_inet, int *have_inet6)
+{
+ int fd = __opensock ();
+ unsigned int nifs;
+ int rq_len;
+ struct ifconf ifc;
+# define RQ_IFS 4
+
+ /* Wirst case assumption. */
+ *have_inet = 0;
+ *have_inet6 = 0;
+
+ if (fd < 0)
+ /* We cannot open the socket. No networking at all? */
+ return;
+
+ /* We may be able to get the needed buffer size directly, rather than
+ guessing. */
+ if (! old_siocgifconf)
+ {
+ ifc.ifc_buf = NULL;
+ ifc.ifc_len = 0;
+ if (__ioctl (fd, SIOCGIFCONF, &ifc) < 0 || ifc.ifc_len == 0)
+ {
+# if __ASSUME_SIOCGIFNAME == 0
+ old_siocgifconf = 1;
+# endif
+ rq_len = RQ_IFS * sizeof (struct ifreq);
+ }
+ else
+ rq_len = ifc.ifc_len;
+ }
+ else
+ rq_len = RQ_IFS * sizeof (struct ifreq);
+
+ /* Read all the interfaces out of the kernel. */
+ do
+ {
+ ifc.ifc_buf = alloca (ifc.ifc_len = rq_len);
+ if (__ioctl (fd, SIOCGIFCONF, &ifc) < 0)
+ {
+ close_not_cancel_no_status (fd);
+ return;
+ }
+ rq_len *= 2;
+ }
+ while (ifc.ifc_len == rq_len && old_siocgifconf);
+
+ nifs = ifc.ifc_len / sizeof (struct ifreq);
+
+ /* Go through all the interfaces and get the address. */
+ while (nifs-- > 0)
+ if (__ioctl (fd, SIOCGIFADDR, &ifc.ifc_req[nifs]) >= 0)
+ {
+ /* We successfully got information about this interface. Now
+ test whether it is an IPv4 or IPv6 address. */
+ if (ifc.ifc_req[nifs].ifr_addr.sa_family == AF_INET)
+ *have_inet = 1;
+ else if (ifc.ifc_req[nifs].ifr_addr.sa_family == AF_INET6)
+ *have_inet6 = 1;
+
+ /* Note, this is & not &&. It works since the values are always
+ 0 or 1. */
+ if (*have_inet & *have_inet6)
+ /* We can stop early. */
+ break;
+ }
+
+ close_not_cancel_no_status (fd);
+}
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/ifaddrs.c b/libc/sysdeps/unix/sysv/linux/ifaddrs.c
new file mode 100644
index 000000000..82495de03
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ifaddrs.c
@@ -0,0 +1,863 @@
+/* getifaddrs -- get names and addresses of all network interfaces
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <alloca.h>
+#include <assert.h>
+#include <errno.h>
+#include <ifaddrs.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netpacket/packet.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sysdep.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "netlinkaccess.h"
+
+
+/* We don't know if we have NETLINK support compiled in in our
+ Kernel, so include the old implementation as fallback. */
+#if __ASSUME_NETLINK_SUPPORT == 0
+int __no_netlink_support attribute_hidden;
+
+# define getifaddrs fallback_getifaddrs
+# include "sysdeps/gnu/ifaddrs.c"
+# undef getifaddrs
+#endif
+
+
+/* struct to hold the data for one ifaddrs entry, so we can allocate
+ everything at once. */
+struct ifaddrs_storage
+{
+ struct ifaddrs ifa;
+ union
+ {
+ /* Save space for the biggest of the four used sockaddr types and
+ avoid a lot of casts. */
+ struct sockaddr sa;
+ struct sockaddr_ll sl;
+ struct sockaddr_in s4;
+ struct sockaddr_in6 s6;
+ } addr, netmask, broadaddr;
+ char name[IF_NAMESIZE + 1];
+};
+
+
+void
+__netlink_free_handle (struct netlink_handle *h)
+{
+ struct netlink_res *ptr;
+ int saved_errno = errno;
+
+ ptr = h->nlm_list;
+ while (ptr != NULL)
+ {
+ struct netlink_res *tmpptr;
+
+ tmpptr = ptr->next;
+ free (ptr);
+ ptr = tmpptr;
+ }
+
+ __set_errno (saved_errno);
+}
+
+
+static int
+__netlink_sendreq (struct netlink_handle *h, int type)
+{
+ struct req
+ {
+ struct nlmsghdr nlh;
+ struct rtgenmsg g;
+ char pad[0];
+ } req;
+ struct sockaddr_nl nladdr;
+
+ if (h->seq == 0)
+ h->seq = time (NULL);
+
+ req.nlh.nlmsg_len = sizeof (req);
+ req.nlh.nlmsg_type = type;
+ req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
+ req.nlh.nlmsg_pid = 0;
+ req.nlh.nlmsg_seq = h->seq;
+ req.g.rtgen_family = AF_UNSPEC;
+ if (sizeof (req) != offsetof (struct req, pad))
+ memset (req.pad, '\0', sizeof (req) - offsetof (struct req, pad));
+
+ memset (&nladdr, '\0', sizeof (nladdr));
+ nladdr.nl_family = AF_NETLINK;
+
+ return TEMP_FAILURE_RETRY (__sendto (h->fd, (void *) &req, sizeof (req), 0,
+ (struct sockaddr *) &nladdr,
+ sizeof (nladdr)));
+}
+
+
+int
+__netlink_request (struct netlink_handle *h, int type)
+{
+ struct netlink_res *nlm_next;
+ struct netlink_res **new_nlm_list;
+ static volatile size_t buf_size = 4096;
+ char *buf;
+ struct sockaddr_nl nladdr;
+ struct nlmsghdr *nlmh;
+ ssize_t read_len;
+ bool done = false;
+ bool use_malloc = false;
+
+ if (__netlink_sendreq (h, type) < 0)
+ return -1;
+
+ size_t this_buf_size = buf_size;
+ if (__libc_use_alloca (this_buf_size))
+ buf = alloca (this_buf_size);
+ else
+ {
+ buf = malloc (this_buf_size);
+ if (buf != NULL)
+ use_malloc = true;
+ else
+ goto out_fail;
+ }
+
+ struct iovec iov = { buf, this_buf_size };
+
+ if (h->nlm_list != NULL)
+ new_nlm_list = &h->end_ptr->next;
+ else
+ new_nlm_list = &h->nlm_list;
+
+ while (! done)
+ {
+ struct msghdr msg =
+ {
+ (void *) &nladdr, sizeof (nladdr),
+ &iov, 1,
+ NULL, 0,
+ 0
+ };
+
+ read_len = TEMP_FAILURE_RETRY (__recvmsg (h->fd, &msg, 0));
+ if (read_len < 0)
+ goto out_fail;
+
+ if (nladdr.nl_pid != 0)
+ continue;
+
+ if (__builtin_expect (msg.msg_flags & MSG_TRUNC, 0))
+ {
+ if (this_buf_size >= SIZE_MAX / 2)
+ goto out_fail;
+
+ nlm_next = *new_nlm_list;
+ while (nlm_next != NULL)
+ {
+ struct netlink_res *tmpptr;
+
+ tmpptr = nlm_next->next;
+ free (nlm_next);
+ nlm_next = tmpptr;
+ }
+ *new_nlm_list = NULL;
+
+ if (__libc_use_alloca (2 * this_buf_size))
+ buf = extend_alloca (buf, this_buf_size, 2 * this_buf_size);
+ else
+ {
+ this_buf_size *= 2;
+
+ char *new_buf = realloc (use_malloc ? buf : NULL, this_buf_size);
+ if (new_buf == NULL)
+ goto out_fail;
+ new_buf = buf;
+
+ use_malloc = true;
+ }
+ buf_size = this_buf_size;
+
+ iov.iov_base = buf;
+ iov.iov_len = this_buf_size;
+
+ /* Increase sequence number, so that we can distinguish
+ between old and new request messages. */
+ h->seq++;
+
+ if (__netlink_sendreq (h, type) < 0)
+ goto out_fail;
+
+ continue;
+ }
+
+ size_t count = 0;
+ size_t remaining_len = read_len;
+ for (nlmh = (struct nlmsghdr *) buf;
+ NLMSG_OK (nlmh, remaining_len);
+ nlmh = (struct nlmsghdr *) NLMSG_NEXT (nlmh, remaining_len))
+ {
+ if ((pid_t) nlmh->nlmsg_pid != h->pid
+ || nlmh->nlmsg_seq != h->seq)
+ continue;
+
+ ++count;
+ if (nlmh->nlmsg_type == NLMSG_DONE)
+ {
+ /* We found the end, leave the loop. */
+ done = true;
+ break;
+ }
+ if (nlmh->nlmsg_type == NLMSG_ERROR)
+ {
+ struct nlmsgerr *nlerr = (struct nlmsgerr *) NLMSG_DATA (nlmh);
+ if (nlmh->nlmsg_len < NLMSG_LENGTH (sizeof (struct nlmsgerr)))
+ errno = EIO;
+ else
+ errno = -nlerr->error;
+ goto out_fail;
+ }
+ }
+
+ /* If there was nothing with the expected nlmsg_pid and nlmsg_seq,
+ there is no point to record it. */
+ if (count == 0)
+ continue;
+
+ nlm_next = (struct netlink_res *) malloc (sizeof (struct netlink_res)
+ + read_len);
+ if (nlm_next == NULL)
+ goto out_fail;
+ nlm_next->next = NULL;
+ nlm_next->nlh = memcpy (nlm_next + 1, buf, read_len);
+ nlm_next->size = read_len;
+ nlm_next->seq = h->seq;
+ if (h->nlm_list == NULL)
+ h->nlm_list = nlm_next;
+ else
+ h->end_ptr->next = nlm_next;
+ h->end_ptr = nlm_next;
+ }
+
+ if (use_malloc)
+ free (buf);
+ return 0;
+
+out_fail:
+ if (use_malloc)
+ free (buf);
+ return -1;
+}
+
+
+void
+__netlink_close (struct netlink_handle *h)
+{
+ /* Don't modify errno. */
+ INTERNAL_SYSCALL_DECL (err);
+ (void) INTERNAL_SYSCALL (close, err, 1, h->fd);
+}
+
+
+/* Open a NETLINK socket. */
+int
+__netlink_open (struct netlink_handle *h)
+{
+ struct sockaddr_nl nladdr;
+
+ h->fd = __socket (PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ if (h->fd < 0)
+ goto out;
+
+ memset (&nladdr, '\0', sizeof (nladdr));
+ nladdr.nl_family = AF_NETLINK;
+ if (__bind (h->fd, (struct sockaddr *) &nladdr, sizeof (nladdr)) < 0)
+ {
+ close_and_out:
+ __netlink_close (h);
+ out:
+#if __ASSUME_NETLINK_SUPPORT == 0
+ __no_netlink_support = 1;
+#endif
+ return -1;
+ }
+ /* Determine the ID the kernel assigned for this netlink connection.
+ It is not necessarily the PID if there is more than one socket
+ open. */
+ socklen_t addr_len = sizeof (nladdr);
+ if (__getsockname (h->fd, (struct sockaddr *) &nladdr, &addr_len) < 0)
+ goto close_and_out;
+ h->pid = nladdr.nl_pid;
+ return 0;
+}
+
+
+/* We know the number of RTM_NEWLINK entries, so we reserve the first
+ # of entries for this type. All RTM_NEWADDR entries have an index
+ pointer to the RTM_NEWLINK entry. To find the entry, create
+ a table to map kernel index entries to our index numbers.
+ Since we get at first all RTM_NEWLINK entries, it can never happen
+ that a RTM_NEWADDR index is not known to this map. */
+static int
+internal_function
+map_newlink (int index, struct ifaddrs_storage *ifas, int *map, int max)
+{
+ int i;
+
+ for (i = 0; i < max; i++)
+ {
+ if (map[i] == -1)
+ {
+ map[i] = index;
+ if (i > 0)
+ ifas[i - 1].ifa.ifa_next = &ifas[i].ifa;
+ return i;
+ }
+ else if (map[i] == index)
+ return i;
+ }
+ /* This should never be reached. If this will be reached, we have
+ a very big problem. */
+ abort ();
+}
+
+
+/* Create a linked list of `struct ifaddrs' structures, one for each
+ network interface on the host machine. If successful, store the
+ list in *IFAP and return 0. On errors, return -1 and set `errno'. */
+int
+getifaddrs (struct ifaddrs **ifap)
+{
+ struct netlink_handle nh = { 0, 0, 0, NULL, NULL };
+ struct netlink_res *nlp;
+ struct ifaddrs_storage *ifas;
+ unsigned int i, newlink, newaddr, newaddr_idx;
+ int *map_newlink_data;
+ size_t ifa_data_size = 0; /* Size to allocate for all ifa_data. */
+ char *ifa_data_ptr; /* Pointer to the unused part of memory for
+ ifa_data. */
+ int result = 0;
+
+ *ifap = NULL;
+
+ if (! __no_netlink_support && __netlink_open (&nh) < 0)
+ {
+#if __ASSUME_NETLINK_SUPPORT != 0
+ return -1;
+#endif
+ }
+
+#if __ASSUME_NETLINK_SUPPORT == 0
+ if (__no_netlink_support)
+ return fallback_getifaddrs (ifap);
+#endif
+
+ /* Tell the kernel that we wish to get a list of all
+ active interfaces, collect all data for every interface. */
+ if (__netlink_request (&nh, RTM_GETLINK) < 0)
+ {
+ result = -1;
+ goto exit_free;
+ }
+
+ /* Now ask the kernel for all addresses which are assigned
+ to an interface and collect all data for every interface.
+ Since we store the addresses after the interfaces in the
+ list, we will later always find the interface before the
+ corresponding addresses. */
+ ++nh.seq;
+ if (__netlink_request (&nh, RTM_GETADDR) < 0)
+ {
+ result = -1;
+ goto exit_free;
+ }
+
+ /* Count all RTM_NEWLINK and RTM_NEWADDR entries to allocate
+ enough memory. */
+ newlink = newaddr = 0;
+ for (nlp = nh.nlm_list; nlp; nlp = nlp->next)
+ {
+ struct nlmsghdr *nlh;
+ size_t size = nlp->size;
+
+ if (nlp->nlh == NULL)
+ continue;
+
+ /* Walk through all entries we got from the kernel and look, which
+ message type they contain. */
+ for (nlh = nlp->nlh; NLMSG_OK (nlh, size); nlh = NLMSG_NEXT (nlh, size))
+ {
+ /* Check if the message is what we want. */
+ if ((pid_t) nlh->nlmsg_pid != nh.pid || nlh->nlmsg_seq != nlp->seq)
+ continue;
+
+ if (nlh->nlmsg_type == NLMSG_DONE)
+ break; /* ok */
+
+ if (nlh->nlmsg_type == RTM_NEWLINK)
+ {
+ /* A RTM_NEWLINK message can have IFLA_STATS data. We need to
+ know the size before creating the list to allocate enough
+ memory. */
+ struct ifinfomsg *ifim = (struct ifinfomsg *) NLMSG_DATA (nlh);
+ struct rtattr *rta = IFLA_RTA (ifim);
+ size_t rtasize = IFLA_PAYLOAD (nlh);
+
+ while (RTA_OK (rta, rtasize))
+ {
+ size_t rta_payload = RTA_PAYLOAD (rta);
+
+ if (rta->rta_type == IFLA_STATS)
+ {
+ ifa_data_size += rta_payload;
+ break;
+ }
+ else
+ rta = RTA_NEXT (rta, rtasize);
+ }
+ ++newlink;
+ }
+ else if (nlh->nlmsg_type == RTM_NEWADDR)
+ ++newaddr;
+ }
+ }
+
+ /* Return if no interface is up. */
+ if ((newlink + newaddr) == 0)
+ goto exit_free;
+
+ /* Allocate memory for all entries we have and initialize next
+ pointer. */
+ ifas = (struct ifaddrs_storage *) calloc (1,
+ (newlink + newaddr)
+ * sizeof (struct ifaddrs_storage)
+ + ifa_data_size);
+ if (ifas == NULL)
+ {
+ result = -1;
+ goto exit_free;
+ }
+
+ /* Table for mapping kernel index to entry in our list. */
+ map_newlink_data = alloca (newlink * sizeof (int));
+ memset (map_newlink_data, '\xff', newlink * sizeof (int));
+
+ ifa_data_ptr = (char *) &ifas[newlink + newaddr];
+ newaddr_idx = 0; /* Counter for newaddr index. */
+
+ /* Walk through the list of data we got from the kernel. */
+ for (nlp = nh.nlm_list; nlp; nlp = nlp->next)
+ {
+ struct nlmsghdr *nlh;
+ size_t size = nlp->size;
+
+ if (nlp->nlh == NULL)
+ continue;
+
+ /* Walk through one message and look at the type: If it is our
+ message, we need RTM_NEWLINK/RTM_NEWADDR and stop if we reach
+ the end or we find the end marker (in this case we ignore the
+ following data. */
+ for (nlh = nlp->nlh; NLMSG_OK (nlh, size); nlh = NLMSG_NEXT (nlh, size))
+ {
+ int ifa_index = 0;
+
+ /* Check if the message is the one we want */
+ if ((pid_t) nlh->nlmsg_pid != nh.pid || nlh->nlmsg_seq != nlp->seq)
+ continue;
+
+ if (nlh->nlmsg_type == NLMSG_DONE)
+ break; /* ok */
+
+ if (nlh->nlmsg_type == RTM_NEWLINK)
+ {
+ /* We found a new interface. Now extract everything from the
+ interface data we got and need. */
+ struct ifinfomsg *ifim = (struct ifinfomsg *) NLMSG_DATA (nlh);
+ struct rtattr *rta = IFLA_RTA (ifim);
+ size_t rtasize = IFLA_PAYLOAD (nlh);
+
+ /* Interfaces are stored in the first "newlink" entries
+ of our list, starting in the order as we got from the
+ kernel. */
+ ifa_index = map_newlink (ifim->ifi_index - 1, ifas,
+ map_newlink_data, newlink);
+ ifas[ifa_index].ifa.ifa_flags = ifim->ifi_flags;
+
+ while (RTA_OK (rta, rtasize))
+ {
+ char *rta_data = RTA_DATA (rta);
+ size_t rta_payload = RTA_PAYLOAD (rta);
+
+ switch (rta->rta_type)
+ {
+ case IFLA_ADDRESS:
+ if (rta_payload <= sizeof (ifas[ifa_index].addr))
+ {
+ ifas[ifa_index].addr.sl.sll_family = AF_PACKET;
+ memcpy (ifas[ifa_index].addr.sl.sll_addr,
+ (char *) rta_data, rta_payload);
+ ifas[ifa_index].addr.sl.sll_halen = rta_payload;
+ ifas[ifa_index].addr.sl.sll_ifindex
+ = ifim->ifi_index;
+ ifas[ifa_index].addr.sl.sll_hatype = ifim->ifi_type;
+
+ ifas[ifa_index].ifa.ifa_addr
+ = &ifas[ifa_index].addr.sa;
+ }
+ break;
+
+ case IFLA_BROADCAST:
+ if (rta_payload <= sizeof (ifas[ifa_index].broadaddr))
+ {
+ ifas[ifa_index].broadaddr.sl.sll_family = AF_PACKET;
+ memcpy (ifas[ifa_index].broadaddr.sl.sll_addr,
+ (char *) rta_data, rta_payload);
+ ifas[ifa_index].broadaddr.sl.sll_halen = rta_payload;
+ ifas[ifa_index].broadaddr.sl.sll_ifindex
+ = ifim->ifi_index;
+ ifas[ifa_index].broadaddr.sl.sll_hatype
+ = ifim->ifi_type;
+
+ ifas[ifa_index].ifa.ifa_broadaddr
+ = &ifas[ifa_index].broadaddr.sa;
+ }
+ break;
+
+ case IFLA_IFNAME: /* Name of Interface */
+ if ((rta_payload + 1) <= sizeof (ifas[ifa_index].name))
+ {
+ ifas[ifa_index].ifa.ifa_name = ifas[ifa_index].name;
+ *(char *) __mempcpy (ifas[ifa_index].name, rta_data,
+ rta_payload) = '\0';
+ }
+ break;
+
+ case IFLA_STATS: /* Statistics of Interface */
+ ifas[ifa_index].ifa.ifa_data = ifa_data_ptr;
+ ifa_data_ptr += rta_payload;
+ memcpy (ifas[ifa_index].ifa.ifa_data, rta_data,
+ rta_payload);
+ break;
+
+ case IFLA_UNSPEC:
+ break;
+ case IFLA_MTU:
+ break;
+ case IFLA_LINK:
+ break;
+ case IFLA_QDISC:
+ break;
+ default:
+ break;
+ }
+
+ rta = RTA_NEXT (rta, rtasize);
+ }
+ }
+ else if (nlh->nlmsg_type == RTM_NEWADDR)
+ {
+ struct ifaddrmsg *ifam = (struct ifaddrmsg *) NLMSG_DATA (nlh);
+ struct rtattr *rta = IFA_RTA (ifam);
+ size_t rtasize = IFA_PAYLOAD (nlh);
+
+ /* New Addresses are stored in the order we got them from
+ the kernel after the interfaces. Theoretically it is possible
+ that we have holes in the interface part of the list,
+ but we always have already the interface for this address. */
+ ifa_index = newlink + newaddr_idx;
+ ifas[ifa_index].ifa.ifa_flags
+ = ifas[map_newlink (ifam->ifa_index - 1, ifas,
+ map_newlink_data, newlink)].ifa.ifa_flags;
+ if (ifa_index > 0)
+ ifas[ifa_index - 1].ifa.ifa_next = &ifas[ifa_index].ifa;
+ ++newaddr_idx;
+
+ while (RTA_OK (rta, rtasize))
+ {
+ char *rta_data = RTA_DATA (rta);
+ size_t rta_payload = RTA_PAYLOAD (rta);
+
+ switch (rta->rta_type)
+ {
+ case IFA_ADDRESS:
+ {
+ struct sockaddr *sa;
+
+ if (ifas[ifa_index].ifa.ifa_addr != NULL)
+ {
+ /* In a point-to-poing network IFA_ADDRESS
+ contains the destination address, local
+ address is supplied in IFA_LOCAL attribute.
+ destination address and broadcast address
+ are stored in an union, so it doesn't matter
+ which name we use. */
+ ifas[ifa_index].ifa.ifa_broadaddr
+ = &ifas[ifa_index].broadaddr.sa;
+ sa = &ifas[ifa_index].broadaddr.sa;
+ }
+ else
+ {
+ ifas[ifa_index].ifa.ifa_addr
+ = &ifas[ifa_index].addr.sa;
+ sa = &ifas[ifa_index].addr.sa;
+ }
+
+ sa->sa_family = ifam->ifa_family;
+
+ switch (ifam->ifa_family)
+ {
+ case AF_INET:
+ /* Size must match that of an address for IPv4. */
+ if (rta_payload == 4)
+ memcpy (&((struct sockaddr_in *) sa)->sin_addr,
+ rta_data, rta_payload);
+ break;
+
+ case AF_INET6:
+ /* Size must match that of an address for IPv6. */
+ if (rta_payload == 16)
+ {
+ memcpy (&((struct sockaddr_in6 *) sa)->sin6_addr,
+ rta_data, rta_payload);
+ if (IN6_IS_ADDR_LINKLOCAL (rta_data)
+ || IN6_IS_ADDR_MC_LINKLOCAL (rta_data))
+ ((struct sockaddr_in6 *) sa)->sin6_scope_id
+ = ifam->ifa_index;
+ }
+ break;
+
+ default:
+ if (rta_payload <= sizeof (ifas[ifa_index].addr))
+ memcpy (sa->sa_data, rta_data, rta_payload);
+ break;
+ }
+ }
+ break;
+
+ case IFA_LOCAL:
+ if (ifas[ifa_index].ifa.ifa_addr != NULL)
+ {
+ /* If ifa_addr is set and we get IFA_LOCAL,
+ assume we have a point-to-point network.
+ Move address to correct field. */
+ ifas[ifa_index].broadaddr = ifas[ifa_index].addr;
+ ifas[ifa_index].ifa.ifa_broadaddr
+ = &ifas[ifa_index].broadaddr.sa;
+ memset (&ifas[ifa_index].addr, '\0',
+ sizeof (ifas[ifa_index].addr));
+ }
+
+ ifas[ifa_index].ifa.ifa_addr = &ifas[ifa_index].addr.sa;
+ ifas[ifa_index].ifa.ifa_addr->sa_family
+ = ifam->ifa_family;
+
+ switch (ifam->ifa_family)
+ {
+ case AF_INET:
+ /* Size must match that of an address for IPv4. */
+ if (rta_payload == 4)
+ memcpy (&ifas[ifa_index].addr.s4.sin_addr,
+ rta_data, rta_payload);
+ break;
+
+ case AF_INET6:
+ /* Size must match that of an address for IPv6. */
+ if (rta_payload == 16)
+ {
+ memcpy (&ifas[ifa_index].addr.s6.sin6_addr,
+ rta_data, rta_payload);
+ if (IN6_IS_ADDR_LINKLOCAL (rta_data)
+ || IN6_IS_ADDR_MC_LINKLOCAL (rta_data))
+ ifas[ifa_index].addr.s6.sin6_scope_id =
+ ifam->ifa_index;
+ }
+ break;
+
+ default:
+ if (rta_payload <= sizeof (ifas[ifa_index].addr))
+ memcpy (ifas[ifa_index].addr.sa.sa_data,
+ rta_data, rta_payload);
+ break;
+ }
+ break;
+
+ case IFA_BROADCAST:
+ /* We get IFA_BROADCAST, so IFA_LOCAL was too much. */
+ if (ifas[ifa_index].ifa.ifa_broadaddr != NULL)
+ memset (&ifas[ifa_index].broadaddr, '\0',
+ sizeof (ifas[ifa_index].broadaddr));
+
+ ifas[ifa_index].ifa.ifa_broadaddr
+ = &ifas[ifa_index].broadaddr.sa;
+ ifas[ifa_index].ifa.ifa_broadaddr->sa_family
+ = ifam->ifa_family;
+
+ switch (ifam->ifa_family)
+ {
+ case AF_INET:
+ /* Size must match that of an address for IPv4. */
+ if (rta_payload == 4)
+ memcpy (&ifas[ifa_index].broadaddr.s4.sin_addr,
+ rta_data, rta_payload);
+ break;
+
+ case AF_INET6:
+ /* Size must match that of an address for IPv6. */
+ if (rta_payload == 16)
+ {
+ memcpy (&ifas[ifa_index].broadaddr.s6.sin6_addr,
+ rta_data, rta_payload);
+ if (IN6_IS_ADDR_LINKLOCAL (rta_data)
+ || IN6_IS_ADDR_MC_LINKLOCAL (rta_data))
+ ifas[ifa_index].broadaddr.s6.sin6_scope_id
+ = ifam->ifa_index;
+ }
+ break;
+
+ default:
+ if (rta_payload <= sizeof (ifas[ifa_index].addr))
+ memcpy (&ifas[ifa_index].broadaddr.sa.sa_data,
+ rta_data, rta_payload);
+ break;
+ }
+ break;
+
+ case IFA_LABEL:
+ if (rta_payload + 1 <= sizeof (ifas[ifa_index].name))
+ {
+ ifas[ifa_index].ifa.ifa_name = ifas[ifa_index].name;
+ *(char *) __mempcpy (ifas[ifa_index].name, rta_data,
+ rta_payload) = '\0';
+ }
+ else
+ abort ();
+ break;
+
+ case IFA_UNSPEC:
+ break;
+ case IFA_CACHEINFO:
+ break;
+ default:
+ break;
+ }
+
+ rta = RTA_NEXT (rta, rtasize);
+ }
+
+ /* If we didn't get the interface name with the
+ address, use the name from the interface entry. */
+ if (ifas[ifa_index].ifa.ifa_name == NULL)
+ ifas[ifa_index].ifa.ifa_name
+ = ifas[map_newlink (ifam->ifa_index - 1, ifas,
+ map_newlink_data, newlink)].ifa.ifa_name;
+
+ /* Calculate the netmask. */
+ if (ifas[ifa_index].ifa.ifa_addr
+ && ifas[ifa_index].ifa.ifa_addr->sa_family != AF_UNSPEC
+ && ifas[ifa_index].ifa.ifa_addr->sa_family != AF_PACKET)
+ {
+ uint32_t max_prefixlen = 0;
+ char *cp = NULL;
+
+ ifas[ifa_index].ifa.ifa_netmask
+ = &ifas[ifa_index].netmask.sa;
+
+ switch (ifas[ifa_index].ifa.ifa_addr->sa_family)
+ {
+ case AF_INET:
+ cp = (char *) &ifas[ifa_index].netmask.s4.sin_addr;
+ max_prefixlen = 32;
+ break;
+
+ case AF_INET6:
+ cp = (char *) &ifas[ifa_index].netmask.s6.sin6_addr;
+ max_prefixlen = 128;
+ break;
+ }
+
+ ifas[ifa_index].ifa.ifa_netmask->sa_family
+ = ifas[ifa_index].ifa.ifa_addr->sa_family;
+
+ if (cp != NULL)
+ {
+ char c;
+ unsigned int preflen;
+
+ if ((max_prefixlen > 0) &&
+ (ifam->ifa_prefixlen > max_prefixlen))
+ preflen = max_prefixlen;
+ else
+ preflen = ifam->ifa_prefixlen;
+
+ for (i = 0; i < (preflen / 8); i++)
+ *cp++ = 0xff;
+ c = 0xff;
+ c <<= (8 - (preflen % 8));
+ *cp = c;
+ }
+ }
+ }
+ }
+ }
+
+ assert (ifa_data_ptr <= (char *) &ifas[newlink + newaddr] + ifa_data_size);
+
+ if (newaddr_idx > 0)
+ {
+ for (i = 0; i < newlink; ++i)
+ if (map_newlink_data[i] == -1)
+ {
+ /* We have fewer links then we anticipated. Adjust the
+ forward pointer to the first address entry. */
+ ifas[i - 1].ifa.ifa_next = &ifas[newlink].ifa;
+ }
+
+ if (i == 0 && newlink > 0)
+ /* No valid link, but we allocated memory. We have to
+ populate the first entry. */
+ memmove (ifas, &ifas[newlink], sizeof (struct ifaddrs_storage));
+ }
+
+ *ifap = &ifas[0].ifa;
+
+ exit_free:
+ __netlink_free_handle (&nh);
+ __netlink_close (&nh);
+
+ return result;
+}
+libc_hidden_def (getifaddrs)
+
+
+#if __ASSUME_NETLINK_SUPPORT != 0
+void
+freeifaddrs (struct ifaddrs *ifa)
+{
+ free (ifa);
+}
+libc_hidden_def (freeifaddrs)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/ifreq.c b/libc/sysdeps/unix/sysv/linux/ifreq.c
new file mode 100644
index 000000000..d7e442c27
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ifreq.c
@@ -0,0 +1,101 @@
+/* Copyright (C) 1999,2002,2003,2004,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Jaeger <aj@suse.de>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include "ifreq.h"
+#include <kernel-features.h>
+
+/* Variable to signal whether SIOCGIFCONF is not available. */
+#if __ASSUME_SIOCGIFNAME == 0 || 1
+static int old_siocgifconf;
+#else
+# define old_siocgifconf 0
+#endif
+
+
+void
+__ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd)
+{
+ int fd = sockfd;
+ struct ifconf ifc;
+ int rq_len;
+ int nifs;
+# define RQ_IFS 4
+
+ if (fd < 0)
+ fd = __opensock ();
+ if (fd < 0)
+ {
+ *num_ifs = 0;
+ *ifreqs = NULL;
+ return;
+ }
+
+ ifc.ifc_buf = NULL;
+
+ /* We may be able to get the needed buffer size directly, rather than
+ guessing. */
+ if (! old_siocgifconf)
+ {
+ ifc.ifc_buf = NULL;
+ ifc.ifc_len = 0;
+ if (__ioctl (fd, SIOCGIFCONF, &ifc) < 0 || ifc.ifc_len == 0)
+ {
+# if __ASSUME_SIOCGIFNAME == 0
+ old_siocgifconf = 1;
+# endif
+ rq_len = RQ_IFS * sizeof (struct ifreq);
+ }
+ else
+ rq_len = ifc.ifc_len;
+ }
+ else
+ rq_len = RQ_IFS * sizeof (struct ifreq);
+
+ /* Read all the interfaces out of the kernel. */
+ while (1)
+ {
+ ifc.ifc_len = rq_len;
+ void *newp = realloc (ifc.ifc_buf, ifc.ifc_len);
+ if (newp == NULL
+ || (ifc.ifc_buf = newp, __ioctl (fd, SIOCGIFCONF, &ifc)) < 0)
+ {
+ free (ifc.ifc_buf);
+
+ if (fd != sockfd)
+ __close (fd);
+
+ *num_ifs = 0;
+ *ifreqs = NULL;
+ return;
+ }
+
+ if (!old_siocgifconf || ifc.ifc_len < rq_len)
+ break;
+
+ rq_len *= 2;
+ }
+
+ nifs = ifc.ifc_len / sizeof (struct ifreq);
+
+ if (fd != sockfd)
+ __close (fd);
+
+ *num_ifs = nifs;
+ *ifreqs = realloc (ifc.ifc_buf, nifs * sizeof (struct ifreq));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/init-first.c b/libc/sysdeps/unix/sysv/linux/init-first.c
new file mode 100644
index 000000000..b061a848c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/init-first.c
@@ -0,0 +1,109 @@
+/* Initialization code run first thing by the ELF startup code. Linux version.
+ Copyright (C) 1995-2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sysdep.h>
+#include <fpu_control.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <libc-internal.h>
+
+#include <ldsodefs.h>
+
+/* Set nonzero if we have to be prepared for more then one libc being
+ used in the process. Safe assumption if initializer never runs. */
+int __libc_multiple_libcs attribute_hidden = 1;
+
+/* Remember the command line argument and enviroment contents for
+ later calls of initializers for dynamic libraries. */
+int __libc_argc attribute_hidden;
+char **__libc_argv attribute_hidden;
+
+
+void
+__libc_init_first (int argc, char **argv, char **envp)
+{
+#ifdef SHARED
+ /* For DSOs we do not need __libc_init_first but instead _init. */
+}
+
+void
+attribute_hidden
+_init (int argc, char **argv, char **envp)
+{
+#endif
+#ifdef USE_NONOPTION_FLAGS
+ extern void __getopt_clean_environment (char **);
+#endif
+
+ __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
+
+ /* Make sure we don't initialize twice. */
+ if (!__libc_multiple_libcs)
+ {
+ /* Set the FPU control word to the proper default value if the
+ kernel would use a different value. (In a static program we
+ don't have this information.) */
+#ifdef SHARED
+ if (__fpu_control != GLRO(dl_fpu_control))
+#endif
+ __setfpucw (__fpu_control);
+ }
+
+ /* Save the command-line arguments. */
+ __libc_argc = argc;
+ __libc_argv = argv;
+ __environ = envp;
+
+#ifndef SHARED
+ __libc_init_secure ();
+
+ /* First the initialization which normally would be done by the
+ dynamic linker. */
+ _dl_non_dynamic_init ();
+#endif
+
+ __init_misc (argc, argv, envp);
+
+#ifdef USE_NONOPTION_FLAGS
+ /* This is a hack to make the special getopt in GNU libc working. */
+ __getopt_clean_environment (envp);
+#endif
+
+#ifdef SHARED
+ __libc_global_ctors ();
+#endif
+}
+
+
+/* This function is defined here so that if this file ever gets into
+ ld.so we will get a link error. Having this file silently included
+ in ld.so causes disaster, because the _init definition above will
+ cause ld.so to gain an init function, which is not a cool thing. */
+
+extern void _dl_start (void) __attribute__ ((noreturn));
+
+void
+_dl_start (void)
+{
+ abort ();
+}
diff --git a/libc/sysdeps/unix/sysv/linux/internal_statvfs.c b/libc/sysdeps/unix/sysv/linux/internal_statvfs.c
new file mode 100644
index 000000000..73317ecaf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/internal_statvfs.c
@@ -0,0 +1,239 @@
+/* Copyright (C) 1998-2003, 2004, 2005 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <mntent.h>
+#include <paths.h>
+#include <stdbool.h>
+#include <stdio_ext.h>
+#include <string.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/statfs.h>
+#include <sys/statvfs.h>
+#include "linux_fsinfo.h"
+
+
+#ifndef STATFS
+# define STATFS statfs
+# define STATVFS statvfs
+# define INTERNAL_STATVFS __internal_statvfs
+
+
+int
+__statvfs_getflags (const char *name, int fstype, struct stat64 *st)
+{
+ if (st == NULL)
+ return 0;
+
+ const char *fsname = NULL;
+ const char *fsname2 = NULL;
+
+ /* Map the filesystem type we got from the statfs call to a string. */
+ switch (fstype)
+ {
+ case EXT2_SUPER_MAGIC:
+ fsname = "ext3";
+ fsname2 = "ext2";
+ break;
+ case DEVPTS_SUPER_MAGIC:
+ fsname= "devpts";
+ break;
+ case SHMFS_SUPER_MAGIC:
+ fsname = "tmpfs";
+ break;
+ case PROC_SUPER_MAGIC:
+ fsname = "proc";
+ break;
+ case USBDEVFS_SUPER_MAGIC:
+ fsname = "usbdevfs";
+ break;
+ case AUTOFS_SUPER_MAGIC:
+ fsname = "autofs";
+ break;
+ case NFS_SUPER_MAGIC:
+ fsname = "nfs";
+ break;
+ case SYSFS_MAGIC:
+ fsname = "sysfs";
+ break;
+ case REISERFS_SUPER_MAGIC:
+ fsname = "reiserfs";
+ break;
+ case XFS_SUPER_MAGIC:
+ fsname = "xfs";
+ break;
+ case JFS_SUPER_MAGIC:
+ fsname = "jfs";
+ break;
+ case HPFS_SUPER_MAGIC:
+ fsname = "hpfs";
+ break;
+ case DEVFS_SUPER_MAGIC:
+ fsname = "devfs";
+ break;
+ case ISOFS_SUPER_MAGIC:
+ fsname = "iso9660";
+ break;
+ case MSDOS_SUPER_MAGIC:
+ fsname = "msdos";
+ break;
+ case NTFS_SUPER_MAGIC:
+ fsname = "ntfs";
+ break;
+ }
+
+ FILE *mtab = __setmntent ("/proc/mounts", "r");
+ if (mtab == NULL)
+ mtab = __setmntent (_PATH_MOUNTED, "r");
+
+ int result = 0;
+ if (mtab != NULL)
+ {
+ bool success = false;
+ struct mntent mntbuf;
+ char tmpbuf[1024];
+
+ /* No locking needed. */
+ (void) __fsetlocking (mtab, FSETLOCKING_BYCALLER);
+
+ again:
+ while (__getmntent_r (mtab, &mntbuf, tmpbuf, sizeof (tmpbuf)))
+ {
+ /* In a first round we look for a given mount point, if
+ we have a name. */
+ if (name != NULL && strcmp (name, mntbuf.mnt_dir) != 0)
+ continue;
+ /* We need to look at the entry only if the filesystem
+ name matches. If we have a filesystem name. */
+ else if (fsname != NULL
+ && strcmp (fsname, mntbuf.mnt_type) != 0
+ && (fsname2 == NULL
+ || strcmp (fsname2, mntbuf.mnt_type) != 0))
+ continue;
+
+ /* Find out about the device the current entry is for. */
+ struct stat64 fsst;
+ if (stat64 (mntbuf.mnt_dir, &fsst) >= 0
+ && st->st_dev == fsst.st_dev)
+ {
+ /* Bingo, we found the entry for the device FD is on.
+ Now interpret the option string. */
+ char *cp = mntbuf.mnt_opts;
+ char *opt;
+
+ while ((opt = strsep (&cp, ",")) != NULL)
+ if (strcmp (opt, "ro") == 0)
+ result |= ST_RDONLY;
+ else if (strcmp (opt, "nosuid") == 0)
+ result |= ST_NOSUID;
+ else if (strcmp (opt, "noexec") == 0)
+ result |= ST_NOEXEC;
+ else if (strcmp (opt, "nodev") == 0)
+ result |= ST_NODEV;
+ else if (strcmp (opt, "sync") == 0)
+ result |= ST_SYNCHRONOUS;
+ else if (strcmp (opt, "mand") == 0)
+ result |= ST_MANDLOCK;
+ else if (strcmp (opt, "noatime") == 0)
+ result |= ST_NOATIME;
+ else if (strcmp (opt, "nodiratime") == 0)
+ result |= ST_NODIRATIME;
+
+ /* We can stop looking for more entries. */
+ success = true;
+ break;
+ }
+ }
+ /* Maybe the kernel names for the filesystems changed or the
+ statvfs call got a name which was not the mount point. Check
+ again, this time without checking for name matches first. */
+ if (! success && (name != NULL || fsname != NULL))
+ {
+ if (name != NULL)
+ /* Try without a mount point name. */
+ name = NULL;
+ else
+ {
+ /* Try without a filesystem name. */
+ assert (fsname != NULL);
+ fsname = fsname2 = NULL;
+ }
+
+ /* It is not strictly allowed to use rewind here. But
+ this code is part of the implementation so it is
+ acceptable. */
+ rewind (mtab);
+
+ goto again;
+ }
+
+ /* Close the file. */
+ __endmntent (mtab);
+ }
+
+ return result;
+}
+#else
+extern int __statvfs_getflags (const char *name, int fstype,
+ struct stat64 *st);
+#endif
+
+
+void
+INTERNAL_STATVFS (const char *name, struct STATVFS *buf,
+ struct STATFS *fsbuf, struct stat64 *st)
+{
+ /* Now fill in the fields we have information for. */
+ buf->f_bsize = fsbuf->f_bsize;
+ /* Linux has the f_frsize size only in later version of the kernel.
+ If the value is not filled in use f_bsize. */
+ buf->f_frsize = fsbuf->f_frsize ?: fsbuf->f_bsize;
+ buf->f_blocks = fsbuf->f_blocks;
+ buf->f_bfree = fsbuf->f_bfree;
+ buf->f_bavail = fsbuf->f_bavail;
+ buf->f_files = fsbuf->f_files;
+ buf->f_ffree = fsbuf->f_ffree;
+ if (sizeof (buf->f_fsid) == sizeof (fsbuf->f_fsid))
+ buf->f_fsid = (fsbuf->f_fsid.__val[0]
+ | ((unsigned long int) fsbuf->f_fsid.__val[1]
+ << (8 * (sizeof (buf->f_fsid)
+ - sizeof (fsbuf->f_fsid.__val[0])))));
+ else
+ /* We cannot help here. The statvfs element is not large enough to
+ contain both words of the statfs f_fsid field. */
+ buf->f_fsid = fsbuf->f_fsid.__val[0];
+#ifdef _STATVFSBUF_F_UNUSED
+ buf->__f_unused = 0;
+#endif
+ buf->f_namemax = fsbuf->f_namelen;
+ memset (buf->__f_spare, '\0', sizeof (buf->__f_spare));
+
+ /* What remains to do is to fill the fields f_favail and f_flag. */
+
+ /* XXX I have no idea how to compute f_favail. Any idea??? */
+ buf->f_favail = buf->f_ffree;
+
+ /* Determining the flags is tricky. We have to read /proc/mounts or
+ the /etc/mtab file and search for the entry which matches the given
+ file. The way we can test for matching filesystem is using the
+ device number. */
+ buf->f_flag = __statvfs_getflags (name, fsbuf->f_type, st);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/internal_statvfs64.c b/libc/sysdeps/unix/sysv/linux/internal_statvfs64.c
new file mode 100644
index 000000000..49e7689f8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/internal_statvfs64.c
@@ -0,0 +1,4 @@
+#define STATFS statfs64
+#define STATVFS statvfs64
+#define INTERNAL_STATVFS __internal_statvfs64
+#include "internal_statvfs.c"
diff --git a/libc/sysdeps/unix/sysv/linux/ipc_priv.h b/libc/sysdeps/unix/sysv/linux/ipc_priv.h
new file mode 100644
index 000000000..20ba1a206
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ipc_priv.h
@@ -0,0 +1,47 @@
+/* Copyright (C) 1995-1999, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/ipc.h>
+
+#define __IPC_64 0x100
+
+struct __old_ipc_perm
+{
+ __key_t __key; /* Key. */
+ unsigned short int uid; /* Owner's user ID. */
+ unsigned short int gid; /* Owner's group ID. */
+ unsigned short int cuid; /* Creator's user ID. */
+ unsigned short int cgid; /* Creator's group ID. */
+ unsigned short int mode; /* Read/write permission. */
+ unsigned short int __seq; /* Sequence number. */
+};
+
+
+/* The codes for the functions to use the ipc syscall multiplexer. */
+#define IPCOP_semop 1
+#define IPCOP_semget 2
+#define IPCOP_semctl 3
+#define IPCOP_semtimedop 4
+#define IPCOP_msgsnd 11
+#define IPCOP_msgrcv 12
+#define IPCOP_msgget 13
+#define IPCOP_msgctl 14
+#define IPCOP_shmat 21
+#define IPCOP_shmdt 22
+#define IPCOP_shmget 23
+#define IPCOP_shmctl 24
diff --git a/libc/sysdeps/unix/sysv/linux/kernel-features.h b/libc/sysdeps/unix/sysv/linux/kernel-features.h
new file mode 100644
index 000000000..e54f675db
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/kernel-features.h
@@ -0,0 +1,460 @@
+/* Set flags signalling availability of kernel features based on given
+ kernel version number.
+ Copyright (C) 1999-2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This file must not contain any C code. At least it must be protected
+ to allow using the file also in assembler files. */
+
+#ifndef __LINUX_KERNEL_VERSION
+/* We assume the worst; all kernels should be supported. */
+# define __LINUX_KERNEL_VERSION 0
+#endif
+
+/* We assume for __LINUX_KERNEL_VERSION the same encoding used in
+ linux/version.h. I.e., the major, minor, and subminor all get a
+ byte with the major number being in the highest byte. This means
+ we can do numeric comparisons.
+
+ In the following we will define certain symbols depending on
+ whether the describes kernel feature is available in the kernel
+ version given by __LINUX_KERNEL_VERSION. We are not always exactly
+ recording the correct versions in which the features were
+ introduced. If somebody cares these values can afterwards be
+ corrected. Most of the numbers here are set corresponding to
+ 2.2.0. */
+
+/* `getcwd' system call. */
+#if __LINUX_KERNEL_VERSION >= 131584
+# define __ASSUME_GETCWD_SYSCALL 1
+#endif
+
+/* Real-time signal became usable in 2.1.70. */
+#if __LINUX_KERNEL_VERSION >= 131398
+# define __ASSUME_REALTIME_SIGNALS 1
+#endif
+
+/* When were the `pread'/`pwrite' syscalls introduced? */
+#if __LINUX_KERNEL_VERSION >= 131584
+# define __ASSUME_PREAD_SYSCALL 1
+# define __ASSUME_PWRITE_SYSCALL 1
+#endif
+
+/* When was `poll' introduced? */
+#if __LINUX_KERNEL_VERSION >= 131584
+# define __ASSUME_POLL_SYSCALL 1
+#endif
+
+/* The `lchown' syscall was introduced in 2.1.80. */
+#if __LINUX_KERNEL_VERSION >= 131408
+# define __ASSUME_LCHOWN_SYSCALL 1
+#endif
+
+/* When did the `setresuid' sysall became available? */
+#if __LINUX_KERNEL_VERSION >= 131584 && !defined __sparc__
+# define __ASSUME_SETRESUID_SYSCALL 1
+#endif
+
+/* The SIOCGIFNAME ioctl is available starting with 2.1.50. */
+#if __LINUX_KERNEL_VERSION >= 131408
+# define __ASSUME_SIOCGIFNAME 1
+#endif
+
+/* MSG_NOSIGNAL was at least available with Linux 2.2.0. */
+#if __LINUX_KERNEL_VERSION >= 131584
+# define __ASSUME_MSG_NOSIGNAL 1
+#endif
+
+/* The sendfile syscall was introduced in 2.2.0. */
+#if __LINUX_KERNEL_VERSION >= 131584
+# define __ASSUME_SENDFILE 1
+#endif
+
+/* Only very old kernels had no real symlinks for terminal descriptors
+ in /proc/self/fd. */
+#if __LINUX_KERNEL_VERSION >= 131584
+# define __ASSUME_PROC_SELF_FD_SYMLINK 1
+#endif
+
+/* On x86 another `getrlimit' syscall was added in 2.3.25. */
+#if __LINUX_KERNEL_VERSION >= 131865 && defined __i386__
+# define __ASSUME_NEW_GETRLIMIT_SYSCALL 1
+#endif
+
+/* On x86 the truncate64/ftruncate64 syscalls were introduced in 2.3.31. */
+#if __LINUX_KERNEL_VERSION >= 131871 && defined __i386__
+# define __ASSUME_TRUNCATE64_SYSCALL 1
+#endif
+
+/* On x86 the mmap2 syscall was introduced in 2.3.31. */
+#if __LINUX_KERNEL_VERSION >= 131871 && defined __i386__
+# define __ASSUME_MMAP2_SYSCALL 1
+#endif
+
+/* On x86 the stat64/lstat64/fstat64 syscalls were introduced in 2.3.34. */
+#if __LINUX_KERNEL_VERSION >= 131874 && defined __i386__
+# define __ASSUME_STAT64_SYSCALL 1
+#endif
+
+/* On sparc the truncate64/ftruncate64/mmap2/stat64/lstat64/fstat64
+ syscalls were introduced in 2.3.35. */
+#if __LINUX_KERNEL_VERSION >= 131875 \
+ && (defined __sparc__ && !defined __arch64__)
+# define __ASSUME_TRUNCATE64_SYSCALL 1
+# define __ASSUME_MMAP2_SYSCALL 1
+# define __ASSUME_STAT64_SYSCALL 1
+#endif
+
+/* I know for sure that getrlimit are in 2.3.35 on powerpc. */
+#if __LINUX_KERNEL_VERSION >= 131875 && defined __powerpc__
+# define __ASSUME_NEW_GETRLIMIT_SYSCALL 1
+#endif
+
+/* I know for sure that these are in 2.3.35 on powerpc. But PowerPC64 does not
+ support separate 64-bit syscalls, already 64-bit */
+#if __LINUX_KERNEL_VERSION >= 131875 && defined __powerpc__ \
+ && !defined __powerpc64__
+# define __ASSUME_TRUNCATE64_SYSCALL 1
+# define __ASSUME_STAT64_SYSCALL 1
+#endif
+
+/* Linux 2.3.39 introduced 32bit UID/GIDs. Some platforms had 32
+ bit type all along. */
+#if __LINUX_KERNEL_VERSION >= 131879 || defined __powerpc__
+# define __ASSUME_32BITUIDS 1
+#endif
+
+/* Linux 2.3.39 sparc added setresuid. */
+#if __LINUX_KERNEL_VERSION >= 131879 && defined __sparc__
+# define __ASSUME_SETRESUID_SYSCALL 1
+#endif
+
+#if __LINUX_KERNEL_VERSION >= 131879
+# define __ASSUME_SETRESGID_SYSCALL 1
+#endif
+
+/* Linux 2.3.39 introduced IPC64. Except for powerpc. */
+#if __LINUX_KERNEL_VERSION >= 131879 && !defined __powerpc__
+# define __ASSUME_IPC64 1
+#endif
+
+/* We can use the LDTs for threading with Linux 2.3.99 and newer. */
+#if __LINUX_KERNEL_VERSION >= 131939
+# define __ASSUME_LDT_WORKS 1
+#endif
+
+/* Linux 2.4.0 on PPC introduced a correct IPC64. But PowerPC64 does not
+ support a separate 64-bit sys call, already 64-bit */
+#if __LINUX_KERNEL_VERSION >= 132096 && defined __powerpc__ \
+ && !defined __powerpc64__
+# define __ASSUME_IPC64 1
+#endif
+
+/* SH kernels got stat64, mmap2, and truncate64 during 2.4.0-test. */
+#if __LINUX_KERNEL_VERSION >= 132096 && defined __sh__
+# define __ASSUME_TRUNCATE64_SYSCALL 1
+# define __ASSUME_MMAP2_SYSCALL 1
+# define __ASSUME_STAT64_SYSCALL 1
+#endif
+
+/* The changed st_ino field appeared in 2.4.0-test6. But we cannot
+ distinguish this version from other 2.4.0 releases. Therefore play
+ save and assume it available is for 2.4.1 and up. However, SH is lame,
+ and still does not have a 64-bit inode field. */
+#if __LINUX_KERNEL_VERSION >= 132097 && !defined __alpha__ && !defined __sh__
+# define __ASSUME_ST_INO_64_BIT 1
+#endif
+
+/* To support locking of large files a new fcntl() syscall was introduced
+ in 2.4.0-test7. We test for 2.4.1 for the earliest version we know
+ the syscall is available. */
+#if __LINUX_KERNEL_VERSION >= 132097 && (defined __i386__ || defined __sparc__)
+# define __ASSUME_FCNTL64 1
+#endif
+
+/* The AT_CLKTCK auxiliary vector entry was introduction in the 2.4.0
+ series. */
+#if __LINUX_KERNEL_VERSION >= 132097
+# define __ASSUME_AT_CLKTCK 1
+#endif
+
+/* Arm got fcntl64 in 2.4.4, PowerPC and SH have it also in 2.4.4 (I
+ don't know when it got introduced). But PowerPC64 does not support
+ separate FCNTL64 call, FCNTL is already 64-bit */
+#if __LINUX_KERNEL_VERSION >= 132100 \
+ && (defined __powerpc__ || defined __sh__) \
+ && !defined __powerpc64__
+# define __ASSUME_FCNTL64 1
+#endif
+
+/* The getdents64 syscall was introduced in 2.4.0-test7. We test for
+ 2.4.1 for the earliest version we know the syscall is available. */
+#if __LINUX_KERNEL_VERSION >= 132097
+# define __ASSUME_GETDENTS64_SYSCALL 1
+#endif
+
+/* When did O_DIRECTORY became available? Early in 2.3 but when?
+ Be safe, use 2.3.99. */
+#if __LINUX_KERNEL_VERSION >= 131939
+# define __ASSUME_O_DIRECTORY 1
+#endif
+
+/* Starting with one of the 2.4.0 pre-releases the Linux kernel passes
+ up the page size information. */
+#if __LINUX_KERNEL_VERSION >= 132097
+# define __ASSUME_AT_PAGESIZE 1
+#endif
+
+/* Starting with at least 2.4.0 the kernel passes the uid/gid unconditionally
+ up to the child. */
+#if __LINUX_KERNEL_VERSION >= 132097
+# define __ASSUME_AT_XID 1
+#endif
+
+/* Starting with 2.4.5 kernels PPC passes the AUXV in the standard way
+ and the vfork syscall made it into the official kernel. */
+#if __LINUX_KERNEL_VERSION >= (132096+5) && defined __powerpc__
+# define __ASSUME_STD_AUXV 1
+# define __ASSUME_VFORK_SYSCALL 1
+#endif
+
+/* Starting with 2.4.5 kernels the mmap2 syscall made it into the official
+ kernel. But PowerPC64 does not support a separate MMAP2 call. */
+#if __LINUX_KERNEL_VERSION >= (132096+5) && defined __powerpc__ \
+ && !defined __powerpc64__
+# define __ASSUME_MMAP2_SYSCALL 1
+#endif
+
+/* Starting with 2.4.21 PowerPC implements the new prctl syscall.
+ This allows applications to get/set the Floating Point Exception Mode. */
+#if __LINUX_KERNEL_VERSION >= (132096+21) && defined __powerpc__
+# define __ASSUME_NEW_PRCTL_SYSCALL 1
+#endif
+
+/* Starting with 2.4.21 the PowerPC32 clone syscall works as expected. */
+#if __LINUX_KERNEL_VERSION >= (132096+21) && defined __powerpc__ \
+ && !defined __powerpc64__
+# define __ASSUME_FIXED_CLONE_SYSCALL 1
+#endif
+
+/* Starting with 2.4.21 PowerPC64 implements the new rt_sigreturn syscall.
+ The new rt_sigreturn takes an ucontext pointer allowing rt_sigreturn
+ to be used in the set/swapcontext implementation. */
+#if __LINUX_KERNEL_VERSION >= (132096+21) && defined __powerpc64__
+# define __ASSUME_NEW_RT_SIGRETURN_SYSCALL 1
+#endif
+
+/* On x86, the set_thread_area syscall was introduced in 2.5.29, but its
+ semantics was changed in 2.5.30, and again after 2.5.31. */
+#if __LINUX_KERNEL_VERSION >= 132384 && defined __i386__
+# define __ASSUME_SET_THREAD_AREA_SYSCALL 1
+#endif
+
+/* The vfork syscall on x86 and arm was definitely available in 2.4. */
+#if __LINUX_KERNEL_VERSION >= 132097 && defined __i386__
+# define __ASSUME_VFORK_SYSCALL 1
+#endif
+
+/* Alpha switched to a 64-bit timeval sometime before 2.2.0. */
+#if __LINUX_KERNEL_VERSION >= 131584 && defined __alpha__
+# define __ASSUME_TIMEVAL64 1
+#endif
+
+/* The late 2.5 kernels saw a lot of new CLONE_* flags. Summarize
+ their availability with one define. The changes were made first
+ for i386 and the have to be done separately for the other archs.
+ For i386 we pick 2.5.50 as the first version with support.
+ For ia64, s390*, PPC, x86-64, and SH we pick 2.5.64 as the first
+ version with support. */
+#if ((__LINUX_KERNEL_VERSION >= 132402 && defined __i386__) \
+ || (__LINUX_KERNEL_VERSION >= 132416 \
+ && (defined __ia64__ || defined __s390__ \
+ || defined __powerpc__ || defined __x86_64__ || defined __sh__)))
+# define __ASSUME_CLONE_THREAD_FLAGS 1
+#endif
+
+/* Beginning with 2.5.63 support for realtime and monotonic clocks and
+ timers based on them is available. */
+#if __LINUX_KERNEL_VERSION >= 132415
+# define __ASSUME_POSIX_TIMERS 1
+#endif
+
+/* Beginning with 2.6.12 the clock and timer supports CPU clocks. */
+#if __LINUX_KERNEL_VERSION >= 0x2060c
+# define __ASSUME_POSIX_CPU_TIMERS 1
+#endif
+
+/* With kernel 2.4.17 we always have netlink support. */
+#if __LINUX_KERNEL_VERSION >= (132096+17)
+# define __ASSUME_NETLINK_SUPPORT 1
+#endif
+
+/* The requeue futex functionality was introduced in 2.5.70. */
+#if __LINUX_KERNEL_VERSION >= 132422
+# define __ASSUME_FUTEX_REQUEUE 1
+#endif
+
+/* The statfs64 syscalls are available in 2.5.74. */
+#if __LINUX_KERNEL_VERSION >= 132426
+# define __ASSUME_STATFS64 1
+#endif
+
+/* Starting with at least 2.5.74 the kernel passes the setuid-like exec
+ flag unconditionally up to the child. */
+#if __LINUX_KERNEL_VERSION >= 132426
+# define __ASSUME_AT_SECURE 1
+#endif
+
+/* Starting with the 2.5.75 kernel the kernel fills in the correct value
+ in the si_pid field passed as part of the siginfo_t struct to signal
+ handlers. */
+#if __LINUX_KERNEL_VERSION >= 132427
+# define __ASSUME_CORRECT_SI_PID 1
+#endif
+
+/* The tgkill syscall was instroduced for i386 in 2.5.75. For Alpha
+ it was introduced in 2.6.0-test1 which unfortunately cannot be
+ distinguished from 2.6.0. On x86-64, ppc, and ppc64 it was
+ introduced in 2.6.0-test3. */
+#if (__LINUX_KERNEL_VERSION >= 132427 && defined __i386__) \
+ || (__LINUX_KERNEL_VERSION >= 132609 && defined __alpha__) \
+ || (__LINUX_KERNEL_VERSION >= 132609 && defined __x86_64__) \
+ || (__LINUX_KERNEL_VERSION >= 132609 && defined __powerpc__) \
+ || (__LINUX_KERNEL_VERSION >= 132609 && defined __sh__)
+# define __ASSUME_TGKILL 1
+#endif
+
+/* The utimes syscall has been available for some architectures
+ forever. For x86 it was introduced after 2.5.75, for x86-64,
+ ppc, and ppc64 it was introduced in 2.6.0-test3. */
+#if defined __alpha__ || defined __ia64__ \
+ || defined __sparc__ \
+ || (__LINUX_KERNEL_VERSION > 132427 && defined __i386__) \
+ || (__LINUX_KERNEL_VERSION > 132609 && defined __x86_64__) \
+ || (__LINUX_KERNEL_VERSION >= 132609 && defined __powerpc__) \
+ || (__LINUX_KERNEL_VERSION >= 132609 && defined __sh__)
+# define __ASSUME_UTIMES 1
+#endif
+
+// XXX Disabled for now since the semantics we want is not achieved.
+#if 0
+/* The CLONE_STOPPED flag was introduced in the 2.6.0-test1 series. */
+#if __LINUX_KERNEL_VERSION >= 132609
+# define __ASSUME_CLONE_STOPPED 1
+#endif
+#endif
+
+/* The fixed version of the posix_fadvise64 syscall appeared in
+ 2.6.0-test3. At least for x86. Powerpc support appeared in
+ 2.6.2, but for 32-bit userspace only. */
+#if (__LINUX_KERNEL_VERSION >= 132609 && defined __i386__) \
+ || (__LINUX_KERNEL_VERSION >= 132610 && defined __powerpc__ \
+ && !defined __powerpc64__)
+# define __ASSUME_FADVISE64_64_SYSCALL 1
+#endif
+
+/* The PROT_GROWSDOWN/PROT_GROWSUP flags were introduced in the 2.6.0-test
+ series. */
+#if __LINUX_KERNEL_VERSION >= 132609
+# define __ASSUME_PROT_GROWSUPDOWN 1
+#endif
+
+/* Starting with 2.6.0 PowerPC adds signal/swapcontext support for Vector
+ SIMD (AKA Altivec, VMX) instructions and register state. This changes
+ the overall size of the sigcontext and adds the swapcontext syscall. */
+#if __LINUX_KERNEL_VERSION >= 132608 && defined __powerpc__
+# define __ASSUME_SWAPCONTEXT_SYSCALL 1
+#endif
+
+/* The CLONE_DETACHED flag is not necessary in 2.6.2 kernels, it is
+ implied. */
+#if __LINUX_KERNEL_VERSION >= 132610
+# define __ASSUME_NO_CLONE_DETACHED 1
+#endif
+
+/* Starting with version 2.6.4-rc1 the getdents syscall returns d_type
+ information as well and in between 2.6.5 and 2.6.8 most compat wrappers
+ were fixed too. Except s390{,x} which was fixed in 2.6.11. */
+#if (__LINUX_KERNEL_VERSION >= 0x020608 && !defined __s390__) \
+ || (__LINUX_KERNEL_VERSION >= 0x02060b && defined __s390__)
+# define __ASSUME_GETDENTS32_D_TYPE 1
+#endif
+
+/* Starting with version 2.5.3, the initial location returned by `brk'
+ after exec is always rounded up to the next page. */
+#if __LINUX_KERNEL_VERSION >= 132355
+# define __ASSUME_BRK_PAGE_ROUNDED 1
+#endif
+
+/* Starting with version 2.6.9, the waitid system call is available.
+ Except for powerpc{,64} and s390{,x}, where it is available in 2.6.12. */
+#if (__LINUX_KERNEL_VERSION >= 0x020609 \
+ && !defined __powerpc__ && !defined __s390__) \
+ || (__LINUX_KERNEL_VERSION >= 0x02060c \
+ && (defined __powerpc__ || defined __s390__))
+# define __ASSUME_WAITID_SYSCALL 1
+#endif
+
+/* Starting with version 2.6.9, SSI_IEEE_RAISE_EXCEPTION exists. */
+#if __LINUX_KERNEL_VERSION >= 0x020609 && defined __alpha__
+#define __ASSUME_IEEE_RAISE_EXCEPTION 1
+#endif
+
+/* On sparc64 stat64/lstat64/fstat64 syscalls were introduced in 2.6.12. */
+#if __LINUX_KERNEL_VERSION >= 0x02060c && defined __sparc__ \
+ && defined __arch64__
+# define __ASSUME_STAT64_SYSCALL 1
+#endif
+
+/* Early kernel used "shm" as the filesystem name for the filesystem used
+ for shm_open etc. Later it is "tmpfs". 2.4.20 is a safe bet for the
+ cutover. */
+#if __LINUX_KERNEL_VERSION >= 0x02041a
+# define __ASSUME_TMPFS_NAME 1
+#endif
+
+/* pselect was introduced just after 2.6.16-rc1. Due to the way the
+ kernel versions are advertised we can only rely on 2.6.17 to have
+ the code. */
+#if __LINUX_KERNEL_VERSION >= 0x020611 && !defined __x86_64__
+# define __ASSUME_PSELECT 1
+#endif
+
+/* ppoll was introduced just after 2.6.16-rc1. Due to the way the
+ kernel versions are advertised we can only rely on 2.6.17 to have
+ the code. */
+#if __LINUX_KERNEL_VERSION >= 0x020611 && !defined __x86_64__
+# define __ASSUME_PPOLL 1
+#endif
+
+/* The *at syscalls were introduced just after 2.6.16-rc1. Due to the way the
+ kernel versions are advertised we can only rely on 2.6.17 to have
+ the code. */
+#if __LINUX_KERNEL_VERSION >= 0x020611
+# define __ASSUME_ATFCTS 1
+#endif
+
+/* Support for inter-process robust mutexes was added in 2.6.17. */
+#if __LINUX_KERNEL_VERSION >= 0x020611
+# define __ASSUME_SET_ROBUST_LIST 1
+#endif
+
+/* Support for PI futexes was added in 2.6.18. */
+#if __LINUX_KERNEL_VERSION >= 0x020612
+# define __ASSUME_FUTEX_LOCK_PI 1
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h b/libc/sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h
new file mode 100644
index 000000000..164a90dde
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h
@@ -0,0 +1,18 @@
+/* Parameters for the Linux kernel ABI for CPU clocks. */
+
+#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
+#define CPUCLOCK_PERTHREAD(clock) \
+ (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
+#define CPUCLOCK_PID_MASK 7
+#define CPUCLOCK_PERTHREAD_MASK 4
+#define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
+#define CPUCLOCK_CLOCK_MASK 3
+#define CPUCLOCK_PROF 0
+#define CPUCLOCK_VIRT 1
+#define CPUCLOCK_SCHED 2
+#define CPUCLOCK_MAX 3
+
+#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
+ ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
+#define MAKE_THREAD_CPUCLOCK(tid, clock) \
+ MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
diff --git a/libc/sysdeps/unix/sysv/linux/kernel_sigaction.h b/libc/sysdeps/unix/sysv/linux/kernel_sigaction.h
new file mode 100644
index 000000000..d005cbce9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/kernel_sigaction.h
@@ -0,0 +1,19 @@
+/* This is the sigaction structure from the Linux 2.1.20 kernel. */
+
+#define HAVE_SA_RESTORER
+
+struct old_kernel_sigaction {
+ __sighandler_t k_sa_handler;
+ unsigned long sa_mask;
+ unsigned long sa_flags;
+ void (*sa_restorer) (void);
+};
+
+/* This is the sigaction structure from the Linux 2.1.68 kernel. */
+
+struct kernel_sigaction {
+ __sighandler_t k_sa_handler;
+ unsigned long sa_flags;
+ void (*sa_restorer) (void);
+ sigset_t sa_mask;
+};
diff --git a/libc/sysdeps/unix/sysv/linux/kernel_stat.h b/libc/sysdeps/unix/sysv/linux/kernel_stat.h
new file mode 100644
index 000000000..9f8434caa
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/kernel_stat.h
@@ -0,0 +1,35 @@
+/* Definition of `struct stat' used in the kernel.. */
+struct kernel_stat
+ {
+ unsigned short int st_dev;
+ unsigned short int __pad1;
+#define _HAVE___PAD1
+ unsigned long int st_ino;
+ unsigned short int st_mode;
+ unsigned short int st_nlink;
+ unsigned short int st_uid;
+ unsigned short int st_gid;
+ unsigned short int st_rdev;
+ unsigned short int __pad2;
+#define _HAVE___PAD2
+ unsigned long int st_size;
+ unsigned long int st_blksize;
+ unsigned long int st_blocks;
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ unsigned long int __unused4;
+#define _HAVE___UNUSED4
+ unsigned long int __unused5;
+#define _HAVE___UNUSED5
+ };
+
+#define _HAVE_STAT___UNUSED4
+#define _HAVE_STAT___UNUSED5
+#define _HAVE_STAT___PAD1
+#define _HAVE_STAT___PAD2
+#define _HAVE_STAT_NSEC
+#define _HAVE_STAT64___PAD1
+#define _HAVE_STAT64___PAD2
+#define _HAVE_STAT64___ST_INO
+#define _HAVE_STAT64_NSEC
diff --git a/libc/sysdeps/unix/sysv/linux/kernel_termios.h b/libc/sysdeps/unix/sysv/linux/kernel_termios.h
new file mode 100644
index 000000000..872ee36b9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/kernel_termios.h
@@ -0,0 +1,35 @@
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _KERNEL_TERMIOS_H
+#define _KERNEL_TERMIOS_H 1
+/* The following corresponds to the values from the Linux 2.1.20 kernel. */
+
+#define __KERNEL_NCCS 19
+
+struct __kernel_termios
+ {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_line; /* line discipline */
+ cc_t c_cc[__KERNEL_NCCS]; /* control characters */
+ };
+
+#endif /* kernel_termios.h */
diff --git a/libc/sysdeps/unix/sysv/linux/ldd-rewrite.sed b/libc/sysdeps/unix/sysv/linux/ldd-rewrite.sed
new file mode 100644
index 000000000..7b8b6bdee
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ldd-rewrite.sed
@@ -0,0 +1,11 @@
+/Maybe extra code for non-ELF binaries/a\
+ file=$1\
+ # Run the ldd stub.\
+ lddlibc4 "$file"\
+ # Test the result.\
+ if test $? -lt 3; then\
+ return 0;\
+ fi\
+ # In case of an error punt.
+/LD_TRACE_LOADED_OBJECTS=1/a\
+add_env="$add_env LD_LIBRARY_VERSION=\\$verify_out"
diff --git a/libc/sysdeps/unix/sysv/linux/lddlibc4.c b/libc/sysdeps/unix/sysv/linux/lddlibc4.c
new file mode 100644
index 000000000..7683ec2ef
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/lddlibc4.c
@@ -0,0 +1,88 @@
+/* Stub for ldd script to print Linux libc4 dependencies.
+ Copyright (C) 1998, 2005 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This code is based on the `ldd' program code from the Linux ld.so
+ package. */
+
+#include <a.out.h>
+#include <errno.h>
+#include <error.h>
+#include <libintl.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/* Get libc version number. */
+#include "../version.h"
+
+#define PACKAGE _libc_intl_domainname
+
+
+int
+main (int argc, char *argv[])
+{
+ const char *filename;
+ size_t filename_len;
+ struct exec exec;
+ char *buf;
+ FILE *fp;
+
+ /* Set locale via LC_ALL. */
+ setlocale (LC_ALL, "");
+
+ /* Set the text message domain. */
+ textdomain (PACKAGE);
+
+ /* We expect exactly one argument. */
+ if (argc != 2)
+ return 1;
+
+ filename = argv[1];
+
+ /* First see whether this is really an a.out binary. */
+ fp = fopen (filename, "rb");
+ if (fp == NULL)
+ error (2, errno, gettext ("cannot open `%s'"), filename);
+
+ /* Read the program header. */
+ if (fread (&exec, sizeof exec, 1, fp) < 1)
+ error (2, errno, gettext ("cannot read header from `%s'"), filename);
+
+ /* Test for the magic numbers. */
+ if (N_MAGIC (exec) != ZMAGIC && N_MAGIC (exec) != QMAGIC
+ && N_MAGIC (exec) != OMAGIC)
+ exit (3);
+
+ /* We don't need the file open anymore. */
+ fclose (fp);
+
+ /* We must put `__LDD_ARGV0=<program-name>' in the environment. */
+ filename_len = strlen (filename);
+ buf = (char *) alloca (sizeof "__LDD_ARGV0=" + filename_len);
+ mempcpy (mempcpy (buf, "__LDD_ARGV0=", sizeof "__LDD_ARGV0=" - 1),
+ filename, filename_len + 1);
+ /* ...and put the value in the environment. */
+ putenv (buf);
+
+ /* Now we can execute the binary. */
+ return execv (filename, &argv[argc]) ? 4 : 0;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ldsodefs.h b/libc/sysdeps/unix/sysv/linux/ldsodefs.h
new file mode 100644
index 000000000..0bdca3c3f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ldsodefs.h
@@ -0,0 +1,56 @@
+/* Run-time dynamic linker data structures for loaded ELF shared objects.
+ Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LDSODEFS_H
+
+#include <kernel-features.h>
+
+/* Get the real definitions. */
+#include_next <ldsodefs.h>
+
+/* Now define our stuff. */
+
+/* We have the auxiliary vector. */
+#define HAVE_AUX_VECTOR
+
+/* Used by static binaries to check the auxiliary vector. */
+extern void _dl_aux_init (ElfW(auxv_t) *av) internal_function;
+
+/* Initialization which is normally done by the dynamic linker. */
+extern void _dl_non_dynamic_init (void) internal_function;
+
+/* We can assume that the kernel always provides the AT_UID, AT_EUID,
+ AT_GID, and AT_EGID values in the auxiliary vector from 2.4.0 or so on. */
+#if __ASSUME_AT_XID
+# define HAVE_AUX_XID
+#endif
+
+/* We can assume that the kernel always provides the AT_SECURE value
+ in the auxiliary vector from 2.5.74 or so on. */
+#if __ASSUME_AT_SECURE
+# define HAVE_AUX_SECURE
+#endif
+
+/* Starting with one of the 2.4.0 pre-releases the Linux kernel passes
+ up the page size information. */
+#if __ASSUME_AT_PAGESIZE
+# define HAVE_AUX_PAGESIZE
+#endif
+
+#endif /* ldsodefs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/libc_fatal.c b/libc/sysdeps/unix/sysv/linux/libc_fatal.c
new file mode 100644
index 000000000..c7fac6ab5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/libc_fatal.c
@@ -0,0 +1,183 @@
+/* Copyright (C) 1993-1995,1997,2000,2002-2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysdep.h>
+#include <unistd.h>
+#include <sys/syslog.h>
+#include <execinfo.h>
+
+/* Abort with an error message. */
+#include <not-cancel.h>
+
+#ifdef FATAL_PREPARE_INCLUDE
+#include FATAL_PREPARE_INCLUDE
+#endif
+
+struct str_list
+{
+ const char *str;
+ size_t len;
+ struct str_list *next;
+};
+
+
+/* Abort with an error message. */
+void
+__libc_message (int do_abort, const char *fmt, ...)
+{
+ va_list ap;
+ va_list ap_copy;
+ int fd = -1;
+
+ va_start (ap, fmt);
+ va_copy (ap_copy, ap);
+
+#ifdef FATAL_PREPARE
+ FATAL_PREPARE;
+#endif
+
+ /* Open a descriptor for /dev/tty unless the user explicitly
+ requests errors on standard error. */
+ const char *on_2 = __secure_getenv ("LIBC_FATAL_STDERR_");
+ if (on_2 == NULL || *on_2 == '\0')
+ fd = open_not_cancel_2 (_PATH_TTY, O_RDWR | O_NOCTTY | O_NDELAY);
+
+ if (fd == -1)
+ fd = STDERR_FILENO;
+
+ struct str_list *list = NULL;
+ int nlist = 0;
+
+ const char *cp = fmt;
+ while (*cp != '\0')
+ {
+ /* Find the next "%s" or the end of the string. */
+ const char *next = cp;
+ while (next[0] != '%' || next[1] != 's')
+ {
+ next = __strchrnul (next + 1, '%');
+
+ if (next[0] == '\0')
+ break;
+ }
+
+ /* Determine what to print. */
+ const char *str;
+ size_t len;
+ if (cp[0] == '%' && cp[1] == 's')
+ {
+ str = va_arg (ap, const char *);
+ len = strlen (str);
+ cp += 2;
+ }
+ else
+ {
+ str = cp;
+ len = next - cp;
+ cp = next;
+ }
+
+ struct str_list *newp = alloca (sizeof (struct str_list));
+ newp->str = str;
+ newp->len = len;
+ newp->next = list;
+ list = newp;
+ ++nlist;
+ }
+
+ bool written = false;
+ if (nlist > 0)
+ {
+ struct iovec *iov = alloca (nlist * sizeof (struct iovec));
+ ssize_t total = 0;
+
+ for (int cnt = nlist - 1; cnt >= 0; --cnt)
+ {
+ iov[cnt].iov_base = (void *) list->str;
+ iov[cnt].iov_len = list->len;
+ total += list->len;
+ list = list->next;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+ ssize_t cnt;
+ do
+ cnt = INTERNAL_SYSCALL (writev, err, 3, fd, iov, nlist);
+ while (INTERNAL_SYSCALL_ERROR_P (cnt, err)
+ && INTERNAL_SYSCALL_ERRNO (cnt, err) == EINTR);
+
+ if (cnt == total)
+ written = true;
+ }
+
+ va_end (ap);
+
+ /* If we had no success writing the message, use syslog. */
+ if (! written)
+ vsyslog (LOG_ERR, fmt, ap_copy);
+
+ va_end (ap_copy);
+
+ if (do_abort)
+ {
+ if (do_abort > 1 && written)
+ {
+ void *addrs[64];
+#define naddrs (sizeof (addrs) / sizeof (addrs[0]))
+ int n = __backtrace (addrs, naddrs);
+ if (n > 2)
+ {
+#define strnsize(str) str, strlen (str)
+#define writestr(str) write_not_cancel (fd, str)
+ writestr (strnsize ("======= Backtrace: =========\n"));
+ __backtrace_symbols_fd (addrs + 1, n - 1, fd);
+
+ writestr (strnsize ("======= Memory map: ========\n"));
+ int fd2 = open_not_cancel_2 ("/proc/self/maps", O_RDONLY);
+ char buf[1024];
+ ssize_t n2;
+ while ((n2 = read_not_cancel (fd2, buf, sizeof (buf))) > 0)
+ if (write_not_cancel (fd, buf, n2) != n2)
+ break;
+ close_not_cancel_no_status (fd2);
+ }
+ }
+
+ /* Terminate the process. */
+ abort ();
+ }
+}
+
+
+void
+__libc_fatal (message)
+ const char *message;
+{
+ /* The loop is added only to keep gcc happy. */
+ while (1)
+ __libc_message (1, "%s", message);
+}
+libc_hidden_def (__libc_fatal)
diff --git a/libc/sysdeps/unix/sysv/linux/linkat.c b/libc/sysdeps/unix/sysv/linux/linkat.c
new file mode 100644
index 000000000..cfd0e1822
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/linkat.c
@@ -0,0 +1,115 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+#include <sysdep.h>
+#include <unistd.h>
+#include <kernel-features.h>
+
+
+/* Make a link to FROM named TO but relative paths in TO and FROM are
+ interpreted relative to FROMFD and TOFD respectively. */
+int
+linkat (fromfd, from, tofd, to, flags)
+ int fromfd;
+ const char *from;
+ int tofd;
+ const char *to;
+ int flags;
+{
+ int result;
+
+#ifdef __NR_linkat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INLINE_SYSCALL (linkat, 5, fromfd, from, tofd, to, flags);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ /* Without kernel support we cannot handle AT_SYMLINK_FOLLOW. */
+ if (flags != 0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ char *buffrom = NULL;
+
+ if (fromfd != AT_FDCWD && from[0] != '/')
+ {
+ size_t filelen = strlen (from);
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buffrom = alloca (buflen);
+
+ __snprintf (buffrom, buflen, procfd, fromfd, from);
+ from = buffrom;
+ }
+
+ char *bufto = NULL;
+
+ if (tofd != AT_FDCWD && to[0] != '/')
+ {
+ size_t filelen = strlen (to);
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ bufto = alloca (buflen);
+
+ __snprintf (bufto, buflen, procfd, tofd, to);
+ to = bufto;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+ result = INTERNAL_SYSCALL (link, err, 2, from, to);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+ __atfct_seterrno_2 (INTERNAL_SYSCALL_ERRNO (result, err), tofd, bufto,
+ fromfd, buffrom);
+ result = -1;
+ }
+
+ return result;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/linux_fsinfo.h b/libc/sysdeps/unix/sysv/linux/linux_fsinfo.h
new file mode 100644
index 000000000..8c6591ada
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/linux_fsinfo.h
@@ -0,0 +1,156 @@
+/* Constants from kernel header for various FSes.
+ Copyright (C) 1998,1999,2000,2001,2002,2003,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_FSINFO_H
+#define _LINUX_FSINFO_H 1
+
+/* These definitions come from the kernel headers. But we cannot
+ include the headers here because of type clashes. If new
+ filesystem types will become available we have to add the
+ appropriate definitions here.*/
+
+/* Constants that identify the `adfs' filesystem. */
+#define ADFS_SUPER_MAGIC 0xadf5
+
+/* Constants that identify the `affs' filesystem. */
+#define AFFS_SUPER_MAGIC 0xadff
+
+/* Constants that identify the `autofs' filesystem. */
+#define AUTOFS_SUPER_MAGIC 0x187
+
+/* Constants that identify the `bfs' filesystem. */
+#define BFS_MAGIC 0x1BADFACE
+
+/* Constants that identify the `coda' filesystem. */
+#define CODA_SUPER_MAGIC 0x73757245
+
+/* Constants that identify the `coherent' filesystem. */
+#define COH_SUPER_MAGIC 0x012ff7b7
+
+/* Constant that identifies the `ramfs' filesystem. */
+#define CRAMFS_MAGIC 0x28cd3d45
+
+/* Constant that identifies the `devfs' filesystem. */
+#define DEVFS_SUPER_MAGIC 0x1373
+
+/* Constant that identifies the `devpts' filesystem. */
+#define DEVPTS_SUPER_MAGIC 0x1cd1
+
+/* Constant that identifies the `efs' filesystem. */
+#define EFS_SUPER_MAGIC 0x414A53
+#define EFS_MAGIC 0x072959
+
+/* Constant that identifies the `ext2' and `ext3' filesystems. */
+#define EXT2_SUPER_MAGIC 0xef53
+
+/* Constant that identifies the `hpfs' filesystem. */
+#define HPFS_SUPER_MAGIC 0xf995e849
+
+/* Constant that identifies the `iso9660' filesystem. */
+#define ISOFS_SUPER_MAGIC 0x9660
+
+/* Constant that identifies the `jffs' filesystem. */
+#define JFFS_SUPER_MAGIC 0x07c0
+
+/* Constant that identifies the `jffs2' filesystem. */
+#define JFFS2_SUPER_MAGIC 0x72b6
+
+/* Constant that identifies the `jfs' filesystem. */
+#define JFS_SUPER_MAGIC 0x3153464a
+
+/* Constants that identify the `minix2' filesystem. */
+#define MINIX2_SUPER_MAGIC 0x2468
+#define MINIX2_SUPER_MAGIC2 0x2478
+
+/* Constants that identify the `minix' filesystem. */
+#define MINIX_SUPER_MAGIC 0x137f
+#define MINIX_SUPER_MAGIC2 0x138F
+
+/* Constants that identify the `msdos' filesystem. */
+#define MSDOS_SUPER_MAGIC 0x4d44
+
+/* Constants that identify the `ncp' filesystem. */
+#define NCP_SUPER_MAGIC 0x564c
+
+/* Constants that identify the `nfs' filesystem. */
+#define NFS_SUPER_MAGIC 0x6969
+
+/* Constants that identify the `ntfs' filesystem. */
+#define NTFS_SUPER_MAGIC 0x5346544e
+
+/* Constants that identify the `proc' filesystem. */
+#define PROC_SUPER_MAGIC 0x9fa0
+
+/* Constant that identifies the `usbdevfs' filesystem. */
+#define USBDEVFS_SUPER_MAGIC 0x9fa2
+
+/* Constants that identify the `qnx4' filesystem. */
+#define QNX4_SUPER_MAGIC 0x002f
+
+/* Constants that identify the `reiser' filesystem. */
+#define REISERFS_SUPER_MAGIC 0x52654973
+
+/* Constant that identifies the `romfs' filesystem. */
+#define ROMFS_SUPER_MAGIC 0x7275
+
+/* Constants that identify the `smb' filesystem. */
+#define SMB_SUPER_MAGIC 0x517b
+
+/* Constants that identify the `sysV' filesystem. */
+#define SYSV2_SUPER_MAGIC 0x012ff7b6
+#define SYSV4_SUPER_MAGIC 0x012ff7b5
+
+/* Constants that identify the `udf' filesystem. */
+#define UDF_SUPER_MAGIC 0x15013346
+
+/* Constants that identify the `ufs' filesystem. */
+#define UFS_MAGIC 0x00011954
+#define UFS_CIGAM 0x54190100 /* byteswapped MAGIC */
+
+/* Constants that identify the `xenix' filesystem. */
+#define XENIX_SUPER_MAGIC 0x012ff7b4
+
+/* Constant that identifies the `shm' filesystem. */
+#define SHMFS_SUPER_MAGIC 0x01021994
+
+/* Constants that identify the `xfs' filesystem. */
+#define XFS_SUPER_MAGIC 0x58465342
+
+/* Constants that identify the `vxfs' filesystem. */
+#define VXFS_SUPER_MAGIC 0xa501fcf5
+
+/* Constants that identify the `sysfs´ filesystem. */
+#define SYSFS_MAGIC 0x62656572
+
+/* Maximum link counts. */
+#define COH_LINK_MAX 10000
+#define EXT2_LINK_MAX 32000
+#define MINIX2_LINK_MAX 65530
+#define MINIX_LINK_MAX 250
+#define REISERFS_LINK_MAX 64535
+#define SYSV_LINK_MAX 126 /* 127? 251? */
+#define UFS_LINK_MAX EXT2_LINK_MAX
+#define XENIX_LINK_MAX 126 /* ?? */
+#define XFS_LINK_MAX 2147483647
+
+/* The Linux kernel header mentioned this as a kind of generic value. */
+#define LINUX_LINK_MAX 127
+
+
+#endif /* linux_fsinfo.h */
diff --git a/libc/sysdeps/unix/sysv/linux/listen.S b/libc/sysdeps/unix/sysv/linux/listen.S
new file mode 100644
index 000000000..bed6a05f2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/listen.S
@@ -0,0 +1,5 @@
+#define socket listen
+#define NARGS 2
+#define NO_WEAK_ALIAS 1
+#include <socket.S>
+weak_alias (listen, __listen)
diff --git a/libc/sysdeps/unix/sysv/linux/llseek.c b/libc/sysdeps/unix/sysv/linux/llseek.c
new file mode 100644
index 000000000..25c7bf2b5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/llseek.c
@@ -0,0 +1,47 @@
+/* Long-long seek operation.
+ Copyright (C) 1996-2000,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <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),
+ __ptrvalue (&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/libc/sysdeps/unix/sysv/linux/local-setxid.h b/libc/sysdeps/unix/sysv/linux/local-setxid.h
new file mode 100644
index 000000000..057968798
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/local-setxid.h
@@ -0,0 +1,23 @@
+/* SETxID functions which only have to change the local thread and
+ none of the possible other threads. */
+#include <kernel-features.h>
+#include <sysdep.h>
+
+/* If we can use the syscall directly, use it. */
+#if __ASSUME_32BITUIDS > 0 && defined __NR_setresuid32
+# define local_seteuid(id) INLINE_SYSCALL (setresuid32, 3, -1, id, -1)
+#elif __ASSUME_SETRESUID_SYSCALL > 0
+# define local_seteuid(id) INLINE_SYSCALL (setresuid, 3, -1, id, -1)
+#else
+# define local_seteuid(id) seteuid (id)
+#endif
+
+
+/* If we can use the syscall directly, use it. */
+#if __ASSUME_32BITUIDS > 0 && defined __NR_setresgid32
+# define local_setegid(id) INLINE_SYSCALL (setresgid32, 3, -1, id, -1)
+#elif __ASSUME_SETRESGID_SYSCALL > 0
+# define local_setegid(id) INLINE_SYSCALL (setresgid, 3, -1, id, -1)
+#else
+# define local_setegid(id) setegid (id)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/lseek64.c b/libc/sysdeps/unix/sysv/linux/lseek64.c
new file mode 100644
index 000000000..d81e98fb5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/lseek64.c
@@ -0,0 +1 @@
+/* We don't need a definition since the llseek function is what we need. */
diff --git a/libc/sysdeps/unix/sysv/linux/lxstat.c b/libc/sysdeps/unix/sysv/linux/lxstat.c
new file mode 100644
index 000000000..f49c25236
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/lxstat.c
@@ -0,0 +1,64 @@
+/* lxstat using old-style Unix lstat system call.
+ Copyright (C) 1991,1995-1998,2000,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, if xstat == xstat64 we must get rid of the prototype or gcc
+ will complain since they don't strictly match. */
+#define __lxstat64 __lxstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <xstatconv.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 (lstat, 2, CHECK_STRING (name),
+ CHECK_1 ((struct kernel_stat *) buf));
+
+#ifdef STAT_IS_KERNEL_STAT
+ errno = EINVAL;
+ return -1;
+#else
+ struct kernel_stat kbuf;
+ int result;
+
+ result = INLINE_SYSCALL (lstat, 2, CHECK_STRING (name), __ptrvalue (&kbuf));
+ if (result == 0)
+ result = __xstat_conv (vers, &kbuf, buf);
+
+ return result;
+#endif
+}
+
+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/libc/sysdeps/unix/sysv/linux/lxstat64.c b/libc/sysdeps/unix/sysv/linux/lxstat64.c
new file mode 100644
index 000000000..7444dfe0d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/lxstat64.c
@@ -0,0 +1,93 @@
+/* lxstat64 using old-style Unix lstat system call.
+ Copyright (C) 1997-2002,2003,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if __ASSUME_STAT64_SYSCALL == 0
+# include <xstatconv.h>
+#endif
+
+#ifdef __NR_lstat64
+# if __ASSUME_STAT64_SYSCALL == 0
+/* The variable is shared between all wrappers around *stat64 calls. */
+extern int __have_no_stat64;
+# endif
+#endif
+
+/* Get information about the file NAME in BUF. */
+int
+___lxstat64 (int vers, const char *name, struct stat64 *buf)
+{
+ int result;
+#ifdef __ASSUME_STAT64_SYSCALL
+ result = INLINE_SYSCALL (lstat64, 2, CHECK_STRING (name), CHECK_1 (buf));
+# if defined _HAVE_STAT64___ST_INO && __ASSUME_ST_INO_64_BIT == 0
+ if (__builtin_expect (!result, 1) && buf->__st_ino != (__ino_t) buf->st_ino)
+ buf->st_ino = buf->__st_ino;
+# endif
+ return result;
+#else
+ struct kernel_stat kbuf;
+# ifdef __NR_lstat64
+ if (! __have_no_stat64)
+ {
+ int saved_errno = errno;
+ result = INLINE_SYSCALL (lstat64, 2, CHECK_STRING (name), CHECK_1 (buf));
+
+ if (result != -1 || errno != ENOSYS)
+ {
+# if defined _HAVE_STAT64___ST_INO && __ASSUME_ST_INO_64_BIT == 0
+ if (!result && buf->__st_ino != (__ino_t) buf->st_ino)
+ buf->st_ino = buf->__st_ino;
+# endif
+ return result;
+ }
+
+ __set_errno (saved_errno);
+ __have_no_stat64 = 1;
+ }
+# endif
+ result = INLINE_SYSCALL (lstat, 2, CHECK_STRING (name), __ptrvalue (&kbuf));
+ if (result == 0)
+ result = __xstat64_conv (vers, &kbuf, buf);
+
+ return result;
+#endif
+}
+
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+versioned_symbol (libc, ___lxstat64, __lxstat64, GLIBC_2_2);
+strong_alias (___lxstat64, __old__lxstat64)
+compat_symbol (libc, __old__lxstat64, __lxstat64, GLIBC_2_1);
+hidden_ver (___lxstat64, __lxstat64)
+#else
+strong_alias (___lxstat64, __lxstat64);
+hidden_def (__lxstat64)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/makedev.c b/libc/sysdeps/unix/sysv/linux/makedev.c
new file mode 100644
index 000000000..93b7012da
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/makedev.c
@@ -0,0 +1,41 @@
+/* Definitions of functions to access `dev_t' values.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <endian.h>
+#include <sys/sysmacros.h>
+
+unsigned int
+gnu_dev_major (unsigned long long int dev)
+{
+ return ((dev >> 8) & 0xfff) | ((unsigned int) (dev >> 32) & ~0xfff);
+}
+
+unsigned int
+gnu_dev_minor (unsigned long long int dev)
+{
+ return (dev & 0xff) | ((unsigned int) (dev >> 12) & ~0xff);
+}
+
+unsigned long long int
+gnu_dev_makedev (unsigned int major, unsigned int minor)
+{
+ return ((minor & 0xff) | ((major & 0xfff) << 8)
+ | (((unsigned long long int) (minor & ~0xff)) << 12)
+ | (((unsigned long long int) (major & ~0xfff)) << 32));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/mkdirat.c b/libc/sysdeps/unix/sysv/linux/mkdirat.c
new file mode 100644
index 000000000..3c190085c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/mkdirat.c
@@ -0,0 +1,86 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <kernel-features.h>
+#include <sysdep-cancel.h>
+
+
+/* Create a new directory with permission bits MODE. But interpret
+ relative PATH names relative to the directory associated with FD. */
+int
+mkdirat (fd, file, mode)
+ int fd;
+ const char *file;
+ mode_t mode;
+{
+ int res;
+
+#ifdef __NR_mkdirat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ res = INLINE_SYSCALL (mkdirat, 3, fd, file, mode);
+# ifndef __ASSUME_ATFCTS
+ if (res == -1 && res == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return res;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+ res = INTERNAL_SYSCALL (mkdir, err, 2, file, mode);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (res, err), 0))
+ {
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (res, err), fd, buf);
+ res = -1;
+ }
+
+ return res;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/mmap64.c b/libc/sysdeps/unix/sysv/linux/mmap64.c
new file mode 100644
index 000000000..d3c68cd10
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/mmap64.c
@@ -0,0 +1,89 @@
+/* Copyright (C) 1999,2000,2001,2002,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_mmap2
+
+/* This is always 12, even on architectures where PAGE_SHIFT != 12. */
+# ifndef MMAP2_PAGE_SHIFT
+# define MMAP2_PAGE_SHIFT 12
+# endif
+
+# ifndef __ASSUME_MMAP2_SYSCALL
+static int have_no_mmap2;
+# endif
+#endif
+
+
+void *
+__mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
+{
+#ifdef __NR_mmap2
+ if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
+ {
+ __set_errno (EINVAL);
+ return MAP_FAILED;
+ }
+# ifndef __ASSUME_MMAP2_SYSCALL
+ if (! have_no_mmap2)
+# endif
+ {
+# ifndef __ASSUME_MMAP2_SYSCALL
+ int saved_errno = errno;
+# endif
+ void *result;
+ __ptrvalue (result) = (void *__unbounded)
+ INLINE_SYSCALL (mmap2, 6, __ptrvalue (addr),
+ len, prot, flags, fd,
+ (off_t) (offset >> MMAP2_PAGE_SHIFT));
+# if __BOUNDED_POINTERS__
+ __ptrlow (result) = __ptrvalue (result);
+ __ptrhigh (result) = __ptrvalue (result) + len;
+# endif
+# ifndef __ASSUME_MMAP2_SYSCALL
+ if (result != MAP_FAILED || errno != ENOSYS)
+# endif
+ return result;
+
+# ifndef __ASSUME_MMAP2_SYSCALL
+ __set_errno (saved_errno);
+ have_no_mmap2 = 1;
+# endif
+ }
+#endif
+#ifndef __ASSUME_MMAP2_SYSCALL
+ if (offset != (off_t) offset || (offset + len) != (off_t) (offset + len))
+ {
+ __set_errno (EINVAL);
+ return MAP_FAILED;
+ }
+
+ return __mmap (addr, len, prot, flags, fd, (off_t) offset);
+#endif
+}
+weak_alias (__mmap64, mmap64)
diff --git a/libc/sysdeps/unix/sysv/linux/mq_close.c b/libc/sysdeps/unix/sysv/linux/mq_close.c
new file mode 100644
index 000000000..008e8eeb9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/mq_close.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <mqueue.h>
+#include <sysdep.h>
+
+#ifdef __NR_mq_open
+
+/* Removes the association between message queue descriptor MQDES and its
+ message queue. */
+int
+mq_close (mqd_t mqdes)
+{
+ return INLINE_SYSCALL (close, 1, mqdes);
+}
+
+#else
+# include <rt/mq_close.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/mq_getattr.c b/libc/sysdeps/unix/sysv/linux/mq_getattr.c
new file mode 100644
index 000000000..d25df7bcf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/mq_getattr.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <mqueue.h>
+#include <stddef.h>
+#include <sysdep.h>
+
+#ifdef __NR_mq_getsetattr
+
+/* Query status and attributes of message queue MQDES. */
+int
+mq_getattr (mqd_t mqdes, struct mq_attr *mqstat)
+{
+ return mq_setattr (mqdes, NULL, mqstat);
+}
+
+#else
+# include <rt/mq_getattr.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/mq_notify.c b/libc/sysdeps/unix/sysv/linux/mq_notify.c
new file mode 100644
index 000000000..4eba28a30
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/mq_notify.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <mqueue.h>
+#include <stddef.h>
+#include <sysdep.h>
+
+#ifdef __NR_mq_notify
+
+/* Register notification upon message arrival to an empty message queue
+ MQDES. */
+int
+mq_notify (mqd_t mqdes, const struct sigevent *notification)
+{
+ /* mq_notify which handles SIGEV_THREAD is included in the thread
+ add-on. */
+ if (notification != NULL
+ && notification->sigev_notify == SIGEV_THREAD)
+ {
+ __set_errno (ENOSYS);
+ return -1;
+ }
+ return INLINE_SYSCALL (mq_notify, 2, mqdes, notification);
+}
+
+#else
+# include <rt/mq_notify.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/mq_open.c b/libc/sysdeps/unix/sysv/linux/mq_open.c
new file mode 100644
index 000000000..eac6e0123
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/mq_open.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <mqueue.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <sysdep.h>
+
+#ifdef __NR_mq_open
+
+/* Establish connection between a process and a message queue NAME and
+ return message queue descriptor or (mqd_t) -1 on error. OFLAG determines
+ the type of access used. If O_CREAT is on OFLAG, the third argument is
+ taken as a `mode_t', the mode of the created message queue, and the fourth
+ argument is taken as `struct mq_attr *', pointer to message queue
+ attributes. If the fourth argument is NULL, default attributes are
+ used. */
+mqd_t
+mq_open (const char *name, int oflag, ...)
+{
+ if (name[0] != '/')
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ mode_t mode = 0;
+ struct mq_attr *attr = NULL;
+ if (oflag & O_CREAT)
+ {
+ va_list ap;
+
+ va_start (ap, oflag);
+ mode = va_arg (ap, mode_t);
+ attr = va_arg (ap, struct mq_attr *);
+ va_end (ap);
+ }
+
+ return INLINE_SYSCALL (mq_open, 4, name + 1, oflag, mode, attr);
+}
+
+#else
+# include <rt/mq_open.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/mq_receive.c b/libc/sysdeps/unix/sysv/linux/mq_receive.c
new file mode 100644
index 000000000..218650802
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/mq_receive.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <mqueue.h>
+#include <stddef.h>
+#include <sysdep.h>
+
+#ifdef __NR_mq_timedreceive
+
+/* Receive the oldest from highest priority messages in message queue
+ MQDES. */
+ssize_t
+mq_receive (mqd_t mqdes, char *msg_ptr, size_t msg_len,
+ unsigned int *msg_prio)
+{
+ return mq_timedreceive (mqdes, msg_ptr, msg_len, msg_prio, NULL);
+}
+
+#else
+# include <rt/mq_receive.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/mq_send.c b/libc/sysdeps/unix/sysv/linux/mq_send.c
new file mode 100644
index 000000000..83b9f8df4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/mq_send.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <mqueue.h>
+#include <stddef.h>
+#include <sysdep.h>
+
+#ifdef __NR_mq_timedsend
+
+/* Add message pointed by MSG_PTR to message queue MQDES. */
+int
+mq_send (mqd_t mqdes, const char *msg_ptr, size_t msg_len,
+ unsigned int msg_prio)
+{
+ return mq_timedsend (mqdes, msg_ptr, msg_len, msg_prio, NULL);
+}
+
+#else
+# include <rt/mq_send.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/mq_unlink.c b/libc/sysdeps/unix/sysv/linux/mq_unlink.c
new file mode 100644
index 000000000..bef39a4ae
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/mq_unlink.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <mqueue.h>
+#include <sysdep.h>
+
+#ifdef __NR_mq_unlink
+
+/* Remove message queue named NAME. */
+int
+mq_unlink (const char *name)
+{
+ if (name[0] != '/')
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+ int ret = INTERNAL_SYSCALL (mq_unlink, err, 1, name + 1);
+
+ /* While unlink can return either EPERM or EACCES, mq_unlink should
+ return just EACCES. */
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (ret, err), 0))
+ {
+ ret = INTERNAL_SYSCALL_ERRNO (ret, err);
+ if (ret == EPERM)
+ ret = EACCES;
+ __set_errno (ret);
+ ret = -1;
+ }
+
+ return ret;
+}
+
+#else
+# include <rt/mq_unlink.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/msgctl.c b/libc/sysdeps/unix/sysv/linux/msgctl.c
new file mode 100644
index 000000000..86fd34cf8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/msgctl.c
@@ -0,0 +1,135 @@
+/* Copyright (C) 1995,1997,1998,2000,2002,2004,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/msg.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <string.h>
+#include <sys/syscall.h>
+#include <shlib-compat.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+struct __old_msqid_ds
+{
+ struct __old_ipc_perm msg_perm; /* structure describing operation permission */
+ struct msg *__unbounded __msg_first; /* pointer to first message on queue */
+ struct msg *__unbounded __msg_last; /* pointer to last message on queue */
+ __time_t msg_stime; /* time of last msgsnd command */
+ __time_t msg_rtime; /* time of last msgrcv command */
+ __time_t msg_ctime; /* time of last change */
+ struct wait_queue *__unbounded __wwait; /* ??? */
+ struct wait_queue *__unbounded __rwait; /* ??? */
+ unsigned short int __msg_cbytes; /* current number of bytes on queue */
+ unsigned short int msg_qnum; /* number of messages currently on queue */
+ unsigned short int msg_qbytes; /* max number of bytes allowed on queue */
+ __ipc_pid_t msg_lspid; /* pid of last msgsnd() */
+ __ipc_pid_t msg_lrpid; /* pid of last msgrcv() */
+};
+
+/* Allows to control internal state and destruction of message queue
+ objects. */
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int __old_msgctl (int, int, struct __old_msqid_ds *);
+#endif
+int __new_msgctl (int, int, struct msqid_ds *);
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int
+attribute_compat_text_section
+__old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd, 0, CHECK_1 (buf));
+}
+compat_symbol (libc, __old_msgctl, msgctl, GLIBC_2_0);
+#endif
+
+int
+__new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
+{
+#if __ASSUME_IPC64 > 0
+ return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
+ msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
+#else
+ switch (cmd) {
+ case MSG_STAT:
+ case IPC_STAT:
+ case IPC_SET:
+ break;
+ default:
+ return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
+ msqid, cmd, 0, CHECK_1 (buf));
+ }
+
+ {
+ int result;
+ struct __old_msqid_ds old;
+
+ /* Unfortunately there is no way how to find out for sure whether
+ we should use old or new msgctl. */
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
+ msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
+ if (result != -1 || errno != EINVAL)
+ return result;
+
+ if (cmd == IPC_SET)
+ {
+ old.msg_perm.uid = buf->msg_perm.uid;
+ old.msg_perm.gid = buf->msg_perm.gid;
+ old.msg_perm.mode = buf->msg_perm.mode;
+ old.msg_qbytes = buf->msg_qbytes;
+ if (old.msg_perm.uid != buf->msg_perm.uid ||
+ old.msg_perm.gid != buf->msg_perm.gid ||
+ old.msg_qbytes != buf->msg_qbytes)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
+ msqid, cmd, 0, __ptrvalue (&old));
+ if (result != -1 && cmd != IPC_SET)
+ {
+ memset(buf, 0, sizeof(*buf));
+ buf->msg_perm.__key = old.msg_perm.__key;
+ buf->msg_perm.uid = old.msg_perm.uid;
+ buf->msg_perm.gid = old.msg_perm.gid;
+ buf->msg_perm.cuid = old.msg_perm.cuid;
+ buf->msg_perm.cgid = old.msg_perm.cgid;
+ buf->msg_perm.mode = old.msg_perm.mode;
+ buf->msg_perm.__seq = old.msg_perm.__seq;
+ buf->msg_stime = old.msg_stime;
+ buf->msg_rtime = old.msg_rtime;
+ buf->msg_ctime = old.msg_ctime;
+ buf->__msg_cbytes = old.__msg_cbytes;
+ buf->msg_qnum = old.msg_qnum;
+ buf->msg_qbytes = old.msg_qbytes;
+ buf->msg_lspid = old.msg_lspid;
+ buf->msg_lrpid = old.msg_lrpid;
+ }
+ return result;
+ }
+#endif
+}
+
+versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/msgget.c b/libc/sysdeps/unix/sysv/linux/msgget.c
new file mode 100644
index 000000000..a4a8290b7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/msgget.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1995, 1997, 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/msg.h>
+#include <ipc_priv.h>
+#include <stdlib.h> /* for definition of NULL */
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Return descriptor for message queue associated with KEY. The MSGFLG
+ parameter describes how to proceed with clashing of key values. */
+
+int
+msgget (key, msgflg)
+ key_t key;
+ int msgflg;
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_msgget, key, msgflg, 0, NULL);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/msgrcv.c b/libc/sysdeps/unix/sysv/linux/msgrcv.c
new file mode 100644
index 000000000..71e7c7aea
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/msgrcv.c
@@ -0,0 +1,66 @@
+/* Copyright (C) 1995,1997,1998,2000,2002,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/msg.h>
+#include <ipc_priv.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+
+#include <bp-checks.h>
+
+/* Kludge to work around Linux' restriction of only up to five
+ arguments to a system call. */
+struct ipc_kludge
+ {
+ void *__unbounded msgp;
+ long int msgtyp;
+ };
+
+
+ssize_t
+__libc_msgrcv (msqid, msgp, msgsz, msgtyp, msgflg)
+ int msqid;
+ void *msgp;
+ size_t msgsz;
+ long int msgtyp;
+ int msgflg;
+{
+ /* The problem here is that Linux' calling convention only allows up to
+ fives parameters to a system call. */
+ struct ipc_kludge tmp;
+
+ tmp.msgp = CHECK_N (msgp, msgsz);
+ tmp.msgtyp = msgtyp;
+
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (ipc, 5, IPCOP_msgrcv, msqid, msgsz, msgflg,
+ __ptrvalue (&tmp));
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = INLINE_SYSCALL (ipc, 5, IPCOP_msgrcv, msqid, msgsz, msgflg,
+ __ptrvalue (&tmp));
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+weak_alias (__libc_msgrcv, msgrcv)
diff --git a/libc/sysdeps/unix/sysv/linux/msgsnd.c b/libc/sysdeps/unix/sysv/linux/msgsnd.c
new file mode 100644
index 000000000..c2031be71
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/msgsnd.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 1995,1997,1998,1999,2000,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/msg.h>
+#include <ipc_priv.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+
+#include <bp-checks.h>
+
+int
+__libc_msgsnd (msqid, msgp, msgsz, msgflg)
+ int msqid;
+ const void *msgp;
+ size_t msgsz;
+ int msgflg;
+{
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (ipc, 5, IPCOP_msgsnd, msqid, msgsz,
+ msgflg, (void *) CHECK_N (msgp, msgsz));
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = INLINE_SYSCALL (ipc, 5, IPCOP_msgsnd, msqid, msgsz,
+ msgflg, (void *) CHECK_N (msgp, msgsz));
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+weak_alias (__libc_msgsnd, msgsnd)
diff --git a/libc/sysdeps/unix/sysv/linux/net/ethernet.h b/libc/sysdeps/unix/sysv/linux/net/ethernet.h
new file mode 100644
index 000000000..7ca8e8348
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/net/ethernet.h
@@ -0,0 +1,76 @@
+/* Copyright (C) 1997, 1999, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Based on the FreeBSD version of this file. Curiously, that file
+ lacks a copyright in the header. */
+
+#ifndef __NET_ETHERNET_H
+#define __NET_ETHERNET_H 1
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <linux/if_ether.h> /* IEEE 802.3 Ethernet constants */
+
+__BEGIN_DECLS
+
+/* This is a name for the 48 bit ethernet address available on many
+ systems. */
+struct ether_addr
+{
+ u_int8_t ether_addr_octet[ETH_ALEN];
+} __attribute__ ((__packed__));
+
+/* 10Mb/s ethernet header */
+struct ether_header
+{
+ u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */
+ u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */
+ u_int16_t ether_type; /* packet type ID field */
+} __attribute__ ((__packed__));
+
+/* Ethernet protocol ID's */
+#define ETHERTYPE_PUP 0x0200 /* Xerox PUP */
+#define ETHERTYPE_IP 0x0800 /* IP */
+#define ETHERTYPE_ARP 0x0806 /* Address resolution */
+#define ETHERTYPE_REVARP 0x8035 /* Reverse ARP */
+
+#define ETHER_ADDR_LEN ETH_ALEN /* size of ethernet addr */
+#define ETHER_TYPE_LEN 2 /* bytes in type field */
+#define ETHER_CRC_LEN 4 /* bytes in CRC field */
+#define ETHER_HDR_LEN ETH_HLEN /* total octets in header */
+#define ETHER_MIN_LEN (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */
+#define ETHER_MAX_LEN (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */
+
+/* make sure ethenet length is valid */
+#define ETHER_IS_VALID_LEN(foo) \
+ ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
+
+/*
+ * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
+ * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
+ * by an ETHER type (as given above) and then the (variable-length) header.
+ */
+#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
+#define ETHERTYPE_NTRAILER 16
+
+#define ETHERMTU ETH_DATA_LEN
+#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
+
+__END_DECLS
+
+#endif /* net/ethernet.h */
diff --git a/libc/sysdeps/unix/sysv/linux/net/if_arp.h b/libc/sysdeps/unix/sysv/linux/net/if_arp.h
new file mode 100644
index 000000000..9608652ee
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/net/if_arp.h
@@ -0,0 +1,182 @@
+/* Definitions for Address Resolution Protocol.
+ Copyright (C) 1997,1999,2001,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Based on the 4.4BSD and Linux version of this file. */
+
+#ifndef _NET_IF_ARP_H
+
+#define _NET_IF_ARP_H 1
+#include <sys/cdefs.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+__BEGIN_DECLS
+
+/* Some internals from deep down in the kernel. */
+#define MAX_ADDR_LEN 7
+
+
+/* This structure defines an ethernet arp header. */
+
+/* ARP protocol opcodes. */
+#define ARPOP_REQUEST 1 /* ARP request. */
+#define ARPOP_REPLY 2 /* ARP reply. */
+#define ARPOP_RREQUEST 3 /* RARP request. */
+#define ARPOP_RREPLY 4 /* RARP reply. */
+#define ARPOP_InREQUEST 8 /* InARP request. */
+#define ARPOP_InREPLY 9 /* InARP reply. */
+#define ARPOP_NAK 10 /* (ATM)ARP NAK. */
+
+/* See RFC 826 for protocol description. ARP packets are variable
+ in size; the arphdr structure defines the fixed-length portion.
+ Protocol type values are the same as those for 10 Mb/s Ethernet.
+ It is followed by the variable-sized fields ar_sha, arp_spa,
+ arp_tha and arp_tpa in that order, according to the lengths
+ specified. Field names used correspond to RFC 826. */
+
+struct arphdr
+ {
+ unsigned short int ar_hrd; /* Format of hardware address. */
+ unsigned short int ar_pro; /* Format of protocol address. */
+ unsigned char ar_hln; /* Length of hardware address. */
+ unsigned char ar_pln; /* Length of protocol address. */
+ unsigned short int ar_op; /* ARP opcode (command). */
+#if 0
+ /* Ethernet looks like this : This bit is variable sized
+ however... */
+ unsigned char __ar_sha[ETH_ALEN]; /* Sender hardware address. */
+ unsigned char __ar_sip[4]; /* Sender IP address. */
+ unsigned char __ar_tha[ETH_ALEN]; /* Target hardware address. */
+ unsigned char __ar_tip[4]; /* Target IP address. */
+#endif
+ };
+
+
+/* ARP protocol HARDWARE identifiers. */
+#define ARPHRD_NETROM 0 /* From KA9Q: NET/ROM pseudo. */
+#define ARPHRD_ETHER 1 /* Ethernet 10/100Mbps. */
+#define ARPHRD_EETHER 2 /* Experimental Ethernet. */
+#define ARPHRD_AX25 3 /* AX.25 Level 2. */
+#define ARPHRD_PRONET 4 /* PROnet token ring. */
+#define ARPHRD_CHAOS 5 /* Chaosnet. */
+#define ARPHRD_IEEE802 6 /* IEEE 802.2 Ethernet/TR/TB. */
+#define ARPHRD_ARCNET 7 /* ARCnet. */
+#define ARPHRD_APPLETLK 8 /* APPLEtalk. */
+#define ARPHRD_DLCI 15 /* Frame Relay DLCI. */
+#define ARPHRD_ATM 19 /* ATM. */
+#define ARPHRD_METRICOM 23 /* Metricom STRIP (new IANA id). */
+#define ARPHRD_IEEE1394 24 /* IEEE 1394 IPv4 - RFC 2734. */
+#define ARPHRD_EUI64 27 /* EUI-64. */
+#define ARPHRD_INFINIBAND 32 /* InfiniBand. */
+
+/* Dummy types for non ARP hardware */
+#define ARPHRD_SLIP 256
+#define ARPHRD_CSLIP 257
+#define ARPHRD_SLIP6 258
+#define ARPHRD_CSLIP6 259
+#define ARPHRD_RSRVD 260 /* Notional KISS type. */
+#define ARPHRD_ADAPT 264
+#define ARPHRD_ROSE 270
+#define ARPHRD_X25 271 /* CCITT X.25. */
+#define ARPHRD_HWX25 272 /* Boards with X.25 in firmware. */
+#define ARPHRD_PPP 512
+#define ARPHRD_CISCO 513 /* Cisco HDLC. */
+#define ARPHRD_HDLC ARPHRD_CISCO
+#define ARPHRD_LAPB 516 /* LAPB. */
+#define ARPHRD_DDCMP 517 /* Digital's DDCMP. */
+#define ARPHRD_RAWHDLC 518 /* Raw HDLC. */
+
+#define ARPHRD_TUNNEL 768 /* IPIP tunnel. */
+#define ARPHRD_TUNNEL6 769 /* IPIP6 tunnel. */
+#define ARPHRD_FRAD 770 /* Frame Relay Access Device. */
+#define ARPHRD_SKIP 771 /* SKIP vif. */
+#define ARPHRD_LOOPBACK 772 /* Loopback device. */
+#define ARPHRD_LOCALTLK 773 /* Localtalk device. */
+#define ARPHRD_FDDI 774 /* Fiber Distributed Data Interface. */
+#define ARPHRD_BIF 775 /* AP1000 BIF. */
+#define ARPHRD_SIT 776 /* sit0 device - IPv6-in-IPv4. */
+#define ARPHRD_IPDDP 777 /* IP-in-DDP tunnel. */
+#define ARPHRD_IPGRE 778 /* GRE over IP. */
+#define ARPHRD_PIMREG 779 /* PIMSM register interface. */
+#define ARPHRD_HIPPI 780 /* High Performance Parallel I'face. */
+#define ARPHRD_ASH 781 /* (Nexus Electronics) Ash. */
+#define ARPHRD_ECONET 782 /* Acorn Econet. */
+#define ARPHRD_IRDA 783 /* Linux-IrDA. */
+#define ARPHRD_FCPP 784 /* Point to point fibrechanel. */
+#define ARPHRD_FCAL 785 /* Fibrechanel arbitrated loop. */
+#define ARPHRD_FCPL 786 /* Fibrechanel public loop. */
+#define ARPHRD_FCFABRIC 787 /* Fibrechanel fabric. */
+#define ARPHRD_IEEE802_TR 800 /* Magic type ident for TR. */
+#define ARPHRD_IEEE80211 801 /* IEEE 802.11. */
+#define ARPHRD_IEEE80211_PRISM 802 /* IEEE 802.11 + Prism2 header. */
+#define ARPHRD_IEEE80211_RADIOTAP 803 /* IEEE 802.11 + radiotap header. */
+
+#define ARPHRD_VOID 0xFFFF /* Void type, nothing is known. */
+#define ARPHRD_NONE 0xFFFE /* Zero header length. */
+
+
+/* ARP ioctl request. */
+struct arpreq
+ {
+ struct sockaddr arp_pa; /* Protocol address. */
+ struct sockaddr arp_ha; /* Hardware address. */
+ int arp_flags; /* Flags. */
+ struct sockaddr arp_netmask; /* Netmask (only for proxy arps). */
+ char arp_dev[16];
+ };
+
+struct arpreq_old
+ {
+ struct sockaddr arp_pa; /* Protocol address. */
+ struct sockaddr arp_ha; /* Hardware address. */
+ int arp_flags; /* Flags. */
+ struct sockaddr arp_netmask; /* Netmask (only for proxy arps). */
+ };
+
+/* ARP Flag values. */
+#define ATF_COM 0x02 /* Completed entry (ha valid). */
+#define ATF_PERM 0x04 /* Permanent entry. */
+#define ATF_PUBL 0x08 /* Publish entry. */
+#define ATF_USETRAILERS 0x10 /* Has requested trailers. */
+#define ATF_NETMASK 0x20 /* Want to use a netmask (only
+ for proxy entries). */
+#define ATF_DONTPUB 0x40 /* Don't answer this addresses. */
+#define ATF_MAGIC 0x80 /* Automatically added entry. */
+
+
+/* Support for the user space arp daemon, arpd. */
+#define ARPD_UPDATE 0x01
+#define ARPD_LOOKUP 0x02
+#define ARPD_FLUSH 0x03
+
+struct arpd_request
+ {
+ unsigned short int req; /* Request type. */
+ u_int32_t ip; /* IP address of entry. */
+ unsigned long int dev; /* Device entry is tied to. */
+ unsigned long int stamp;
+ unsigned long int updated;
+ unsigned char ha[MAX_ADDR_LEN]; /* Hardware address. */
+ };
+
+__END_DECLS
+
+#endif /* net/if_arp.h */
diff --git a/libc/sysdeps/unix/sysv/linux/net/if_packet.h b/libc/sysdeps/unix/sysv/linux/net/if_packet.h
new file mode 100644
index 000000000..e5184e7f1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/net/if_packet.h
@@ -0,0 +1,37 @@
+/* Definitions for use with Linux SOCK_PACKET sockets.
+ Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef __IF_PACKET_H
+#define __IF_PACKET_H
+
+#include <features.h>
+#include <bits/sockaddr.h>
+
+/* This is the SOCK_PACKET address structure as used in Linux 2.0.
+ From Linux 2.1 the AF_PACKET interface is preferred and you should
+ consider using it in place of this one. */
+
+struct sockaddr_pkt
+ {
+ __SOCKADDR_COMMON (spkt_);
+ unsigned char spkt_device[14];
+ unsigned short spkt_protocol;
+ };
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/net/if_ppp.h b/libc/sysdeps/unix/sysv/linux/net/if_ppp.h
new file mode 100644
index 000000000..bf5ec8387
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/net/if_ppp.h
@@ -0,0 +1,169 @@
+/* From: if_ppp.h,v 1.3 1995/06/12 11:36:50 paulus Exp */
+
+/*
+ * if_ppp.h - Point-to-Point Protocol definitions.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * ==FILEVERSION 960926==
+ *
+ * NOTE TO MAINTAINERS:
+ * If you modify this file at all, please set the above date.
+ * if_ppp.h is shipped with a PPP distribution as well as with the kernel;
+ * if everyone increases the FILEVERSION number above, then scripts
+ * can do the right thing when deciding whether to install a new if_ppp.h
+ * file. Don't change the format of that line otherwise, so the
+ * installation script can recognize it.
+ */
+
+
+#ifndef __NET_IF_PPP_H
+#define __NET_IF_PPP_H 1
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <net/ppp_defs.h>
+
+__BEGIN_DECLS
+
+/*
+ * Packet sizes
+ */
+
+#define PPP_MTU 1500 /* Default MTU (size of Info field) */
+#define PPP_MAXMRU 65000 /* Largest MRU we allow */
+#define PPP_VERSION "2.2.0"
+#define PPP_MAGIC 0x5002 /* Magic value for the ppp structure */
+#define PROTO_IPX 0x002b /* protocol numbers */
+#define PROTO_DNA_RT 0x0027 /* DNA Routing */
+
+
+/*
+ * Bit definitions for flags.
+ */
+
+#define SC_COMP_PROT 0x00000001 /* protocol compression (output) */
+#define SC_COMP_AC 0x00000002 /* header compression (output) */
+#define SC_COMP_TCP 0x00000004 /* TCP (VJ) compression (output) */
+#define SC_NO_TCP_CCID 0x00000008 /* disable VJ connection-id comp. */
+#define SC_REJ_COMP_AC 0x00000010 /* reject adrs/ctrl comp. on input */
+#define SC_REJ_COMP_TCP 0x00000020 /* reject TCP (VJ) comp. on input */
+#define SC_CCP_OPEN 0x00000040 /* Look at CCP packets */
+#define SC_CCP_UP 0x00000080 /* May send/recv compressed packets */
+#define SC_ENABLE_IP 0x00000100 /* IP packets may be exchanged */
+#define SC_COMP_RUN 0x00001000 /* compressor has been inited */
+#define SC_DECOMP_RUN 0x00002000 /* decompressor has been inited */
+#define SC_DEBUG 0x00010000 /* enable debug messages */
+#define SC_LOG_INPKT 0x00020000 /* log contents of good pkts recvd */
+#define SC_LOG_OUTPKT 0x00040000 /* log contents of pkts sent */
+#define SC_LOG_RAWIN 0x00080000 /* log all chars received */
+#define SC_LOG_FLUSH 0x00100000 /* log all chars flushed */
+#define SC_MASK 0x0fE0ffff /* bits that user can change */
+
+/* state bits */
+#define SC_ESCAPED 0x80000000 /* saw a PPP_ESCAPE */
+#define SC_FLUSH 0x40000000 /* flush input until next PPP_FLAG */
+#define SC_VJ_RESET 0x20000000 /* Need to reset the VJ decompressor */
+#define SC_XMIT_BUSY 0x10000000 /* ppp_write_wakeup is active */
+#define SC_RCV_ODDP 0x08000000 /* have rcvd char with odd parity */
+#define SC_RCV_EVNP 0x04000000 /* have rcvd char with even parity */
+#define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 1 */
+#define SC_RCV_B7_0 0x01000000 /* have rcvd char with bit 7 = 0 */
+#define SC_DC_FERROR 0x00800000 /* fatal decomp error detected */
+#define SC_DC_ERROR 0x00400000 /* non-fatal decomp error detected */
+
+/*
+ * Ioctl definitions.
+ */
+
+struct npioctl {
+ int protocol; /* PPP protocol, e.g. PPP_IP */
+ enum NPmode mode;
+};
+
+/* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
+struct ppp_option_data {
+ u_int8_t *ptr;
+ u_int32_t length;
+ int transmit;
+};
+
+struct ifpppstatsreq {
+ struct ifreq b;
+ struct ppp_stats stats; /* statistic information */
+};
+
+struct ifpppcstatsreq {
+ struct ifreq b;
+ struct ppp_comp_stats stats;
+};
+
+#define ifr__name b.ifr_ifrn.ifrn_name
+#define stats_ptr b.ifr_ifru.ifru_data
+
+/*
+ * Ioctl definitions.
+ */
+
+#define PPPIOCGFLAGS _IOR('t', 90, int) /* get configuration flags */
+#define PPPIOCSFLAGS _IOW('t', 89, int) /* set configuration flags */
+#define PPPIOCGASYNCMAP _IOR('t', 88, int) /* get async map */
+#define PPPIOCSASYNCMAP _IOW('t', 87, int) /* set async map */
+#define PPPIOCGUNIT _IOR('t', 86, int) /* get ppp unit number */
+#define PPPIOCGRASYNCMAP _IOR('t', 85, int) /* get receive async map */
+#define PPPIOCSRASYNCMAP _IOW('t', 84, int) /* set receive async map */
+#define PPPIOCGMRU _IOR('t', 83, int) /* get max receive unit */
+#define PPPIOCSMRU _IOW('t', 82, int) /* set max receive unit */
+#define PPPIOCSMAXCID _IOW('t', 81, int) /* set VJ max slot ID */
+#define PPPIOCGXASYNCMAP _IOR('t', 80, ext_accm) /* get extended ACCM */
+#define PPPIOCSXASYNCMAP _IOW('t', 79, ext_accm) /* set extended ACCM */
+#define PPPIOCXFERUNIT _IO('t', 78) /* transfer PPP unit */
+#define PPPIOCSCOMPRESS _IOW('t', 77, struct ppp_option_data)
+#define PPPIOCGNPMODE _IOWR('t', 76, struct npioctl) /* get NP mode */
+#define PPPIOCSNPMODE _IOW('t', 75, struct npioctl) /* set NP mode */
+#define PPPIOCGDEBUG _IOR('t', 65, int) /* Read debug level */
+#define PPPIOCSDEBUG _IOW('t', 64, int) /* Set debug level */
+#define PPPIOCGIDLE _IOR('t', 63, struct ppp_idle) /* get idle time */
+
+#define SIOCGPPPSTATS (SIOCDEVPRIVATE + 0)
+#define SIOCGPPPVER (SIOCDEVPRIVATE + 1) /* NEVER change this!! */
+#define SIOCGPPPCSTATS (SIOCDEVPRIVATE + 2)
+
+#if !defined(ifr_mtu)
+#define ifr_mtu ifr_ifru.ifru_metric
+#endif
+
+__END_DECLS
+
+#endif /* net/if_ppp.h */
diff --git a/libc/sysdeps/unix/sysv/linux/net/if_shaper.h b/libc/sysdeps/unix/sysv/linux/net/if_shaper.h
new file mode 100644
index 000000000..7060af31e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/net/if_shaper.h
@@ -0,0 +1,59 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NET_IF_SHAPER_H
+#define _NET_IF_SHAPER_H 1
+
+#include <features.h>
+#include <sys/types.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+
+__BEGIN_DECLS
+
+#define SHAPER_QLEN 10
+/*
+ * This is a bit speed dependant (read it shouldnt be a constant!)
+ *
+ * 5 is about right for 28.8 upwards. Below that double for every
+ * halving of speed or so. - ie about 20 for 9600 baud.
+ */
+#define SHAPER_LATENCY (5 * HZ)
+#define SHAPER_MAXSLIP 2
+#define SHAPER_BURST (HZ / 50) /* Good for >128K then */
+
+#define SHAPER_SET_DEV 0x0001
+#define SHAPER_SET_SPEED 0x0002
+#define SHAPER_GET_DEV 0x0003
+#define SHAPER_GET_SPEED 0x0004
+
+struct shaperconf
+{
+ u_int16_t ss_cmd;
+ union
+ {
+ char ssu_name[14];
+ u_int32_t ssu_speed;
+ } ss_u;
+#define ss_speed ss_u.ssu_speed
+#define ss_name ss_u.ssu_name
+};
+
+__END_DECLS
+
+#endif /* net/if_shaper.h */
diff --git a/libc/sysdeps/unix/sysv/linux/net/if_slip.h b/libc/sysdeps/unix/sysv/linux/net/if_slip.h
new file mode 100644
index 000000000..66bd7f30a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/net/if_slip.h
@@ -0,0 +1,25 @@
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NET_IF_SLIP_H
+#define _NET_IF_SLIP_H 1
+
+/* We can use the kernel header. */
+#include <linux/if_slip.h>
+
+#endif /* net/if_slip.h. */
diff --git a/libc/sysdeps/unix/sysv/linux/net/ppp-comp.h b/libc/sysdeps/unix/sysv/linux/net/ppp-comp.h
new file mode 100644
index 000000000..4a992d542
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/net/ppp-comp.h
@@ -0,0 +1 @@
+#include <linux/ppp-comp.h>
diff --git a/libc/sysdeps/unix/sysv/linux/net/ppp_defs.h b/libc/sysdeps/unix/sysv/linux/net/ppp_defs.h
new file mode 100644
index 000000000..f8924c4f2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/net/ppp_defs.h
@@ -0,0 +1,10 @@
+#ifndef _NET_PPP_DEFS_H
+#define _NET_PPP_DEFS_H 1
+
+#define __need_time_t
+#include <time.h>
+
+#include <asm/types.h>
+#include <linux/ppp_defs.h>
+
+#endif /* net/ppp_defs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/net/route.h b/libc/sysdeps/unix/sysv/linux/net/route.h
new file mode 100644
index 000000000..da5c810c7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/net/route.h
@@ -0,0 +1,145 @@
+/* Copyright (C) 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Based on the 4.4BSD and Linux version of this file. */
+
+#ifndef _NET_ROUTE_H
+#define _NET_ROUTE_H 1
+
+#include <features.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <bits/wordsize.h>
+
+
+/* This structure gets passed by the SIOCADDRT and SIOCDELRT calls. */
+struct rtentry
+ {
+ unsigned long int rt_pad1;
+ struct sockaddr rt_dst; /* Target address. */
+ struct sockaddr rt_gateway; /* Gateway addr (RTF_GATEWAY). */
+ struct sockaddr rt_genmask; /* Target network mask (IP). */
+ unsigned short int rt_flags;
+ short int rt_pad2;
+ unsigned long int rt_pad3;
+ unsigned char rt_tos;
+ unsigned char rt_class;
+#if __WORDSIZE == 64
+ short int rt_pad4[3];
+#else
+ short int rt_pad4;
+#endif
+ short int rt_metric; /* +1 for binary compatibility! */
+ char *rt_dev; /* Forcing the device at add. */
+ unsigned long int rt_mtu; /* Per route MTU/Window. */
+ unsigned long int rt_window; /* Window clamping. */
+ unsigned short int rt_irtt; /* Initial RTT. */
+ };
+/* Compatibility hack. */
+#define rt_mss rt_mtu
+
+
+struct in6_rtmsg
+ {
+ struct in6_addr rtmsg_dst;
+ struct in6_addr rtmsg_src;
+ struct in6_addr rtmsg_gateway;
+ u_int32_t rtmsg_type;
+ u_int16_t rtmsg_dst_len;
+ u_int16_t rtmsg_src_len;
+ u_int32_t rtmsg_metric;
+ unsigned long int rtmsg_info;
+ u_int32_t rtmsg_flags;
+ int rtmsg_ifindex;
+ };
+
+
+#define RTF_UP 0x0001 /* Route usable. */
+#define RTF_GATEWAY 0x0002 /* Destination is a gateway. */
+
+#define RTF_HOST 0x0004 /* Host entry (net otherwise). */
+#define RTF_REINSTATE 0x0008 /* Reinstate route after timeout. */
+#define RTF_DYNAMIC 0x0010 /* Created dyn. (by redirect). */
+#define RTF_MODIFIED 0x0020 /* Modified dyn. (by redirect). */
+#define RTF_MTU 0x0040 /* Specific MTU for this route. */
+#define RTF_MSS RTF_MTU /* Compatibility. */
+#define RTF_WINDOW 0x0080 /* Per route window clamping. */
+#define RTF_IRTT 0x0100 /* Initial round trip time. */
+#define RTF_REJECT 0x0200 /* Reject route. */
+#define RTF_STATIC 0x0400 /* Manually injected route. */
+#define RTF_XRESOLVE 0x0800 /* External resolver. */
+#define RTF_NOFORWARD 0x1000 /* Forwarding inhibited. */
+#define RTF_THROW 0x2000 /* Go to next class. */
+#define RTF_NOPMTUDISC 0x4000 /* Do not send packets with DF. */
+
+/* for IPv6 */
+#define RTF_DEFAULT 0x00010000 /* default - learned via ND */
+#define RTF_ALLONLINK 0x00020000 /* fallback, no routers on link */
+#define RTF_ADDRCONF 0x00040000 /* addrconf route - RA */
+
+#define RTF_LINKRT 0x00100000 /* link specific - device match */
+#define RTF_NONEXTHOP 0x00200000 /* route with no nexthop */
+
+#define RTF_CACHE 0x01000000 /* cache entry */
+#define RTF_FLOW 0x02000000 /* flow significant route */
+#define RTF_POLICY 0x04000000 /* policy route */
+
+#define RTCF_VALVE 0x00200000
+#define RTCF_MASQ 0x00400000
+#define RTCF_NAT 0x00800000
+#define RTCF_DOREDIRECT 0x01000000
+#define RTCF_LOG 0x02000000
+#define RTCF_DIRECTSRC 0x04000000
+
+#define RTF_LOCAL 0x80000000
+#define RTF_INTERFACE 0x40000000
+#define RTF_MULTICAST 0x20000000
+#define RTF_BROADCAST 0x10000000
+#define RTF_NAT 0x08000000
+
+#define RTF_ADDRCLASSMASK 0xF8000000
+#define RT_ADDRCLASS(flags) ((__u_int32_t) flags >> 23)
+
+#define RT_TOS(tos) ((tos) & IPTOS_TOS_MASK)
+
+#define RT_LOCALADDR(flags) ((flags & RTF_ADDRCLASSMASK) \
+ == (RTF_LOCAL|RTF_INTERFACE))
+
+#define RT_CLASS_UNSPEC 0
+#define RT_CLASS_DEFAULT 253
+
+#define RT_CLASS_MAIN 254
+#define RT_CLASS_LOCAL 255
+#define RT_CLASS_MAX 255
+
+
+#define RTMSG_ACK NLMSG_ACK
+#define RTMSG_OVERRUN NLMSG_OVERRUN
+
+#define RTMSG_NEWDEVICE 0x11
+#define RTMSG_DELDEVICE 0x12
+#define RTMSG_NEWROUTE 0x21
+#define RTMSG_DELROUTE 0x22
+#define RTMSG_NEWRULE 0x31
+#define RTMSG_DELRULE 0x32
+#define RTMSG_CONTROL 0x40
+
+#define RTMSG_AR_FAILED 0x51 /* Address Resolution failed. */
+
+#endif /* net/route.h */
diff --git a/libc/sysdeps/unix/sysv/linux/netash/ash.h b/libc/sysdeps/unix/sysv/linux/netash/ash.h
new file mode 100644
index 000000000..712c0aafd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/netash/ash.h
@@ -0,0 +1,40 @@
+/* Definitions for use with Linux AF_ASH sockets.
+ Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NETASH_ASH_H
+#define _NETASH_ASH_H 1
+
+#include <features.h>
+#include <bits/sockaddr.h>
+
+struct sockaddr_ash
+ {
+ __SOCKADDR_COMMON (sash_); /* Common data: address family etc. */
+ int sash_ifindex; /* Interface to use. */
+ unsigned char sash_channel; /* Realtime or control. */
+ unsigned int sash_plen;
+ unsigned char sash_prefix[16];
+ };
+
+/* Values for `channel' member. */
+#define ASH_CHANNEL_ANY 0
+#define ASH_CHANNEL_CONTROL 1
+#define ASH_CHANNEL_REALTIME 2
+
+#endif /* netash/ash.h */
diff --git a/libc/sysdeps/unix/sysv/linux/netatalk/at.h b/libc/sysdeps/unix/sysv/linux/netatalk/at.h
new file mode 100644
index 000000000..2668fc93b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/netatalk/at.h
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991, 1992, 1993, 1995, 1996, 1997, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NETATALK_AT_H
+#define _NETATALK_AT_H 1
+
+#include <asm/types.h>
+#include <bits/sockaddr.h>
+#include <linux/atalk.h>
+#include <sys/socket.h>
+
+#define SOL_ATALK 258 /* sockopt level for atalk */
+
+#endif /* netatalk/at.h */
diff --git a/libc/sysdeps/unix/sysv/linux/netax25/ax25.h b/libc/sysdeps/unix/sysv/linux/netax25/ax25.h
new file mode 100644
index 000000000..ce3c7abc9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/netax25/ax25.h
@@ -0,0 +1,171 @@
+/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NETAX25_AX25_H
+#define _NETAX25_AX25_H 1
+
+#include <features.h>
+#include <bits/sockaddr.h>
+
+/* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx. */
+#define SOL_AX25 257
+
+/* AX.25 flags: */
+#define AX25_WINDOW 1
+#define AX25_T1 2
+#define AX25_T2 5
+#define AX25_T3 4
+#define AX25_N2 3
+#define AX25_BACKOFF 6
+#define AX25_EXTSEQ 7
+#define AX25_PIDINCL 8
+#define AX25_IDLE 9
+#define AX25_PACLEN 10
+#define AX25_IPMAXQUEUE 11
+#define AX25_IAMDIGI 12
+#define AX25_KILL 99
+
+/* AX.25 socket ioctls: */
+#define SIOCAX25GETUID (SIOCPROTOPRIVATE)
+#define SIOCAX25ADDUID (SIOCPROTOPRIVATE+1)
+#define SIOCAX25DELUID (SIOCPROTOPRIVATE+2)
+#define SIOCAX25NOUID (SIOCPROTOPRIVATE+3)
+#define SIOCAX25BPQADDR (SIOCPROTOPRIVATE+4)
+#define SIOCAX25GETPARMS (SIOCPROTOPRIVATE+5)
+#define SIOCAX25SETPARMS (SIOCPROTOPRIVATE+6)
+#define SIOCAX25OPTRT (SIOCPROTOPRIVATE+7)
+#define SIOCAX25CTLCON (SIOCPROTOPRIVATE+8)
+#define SIOCAX25GETINFO (SIOCPROTOPRIVATE+9)
+#define SIOCAX25ADDFWD (SIOCPROTOPRIVATE+10)
+#define SIOCAX25DELFWD (SIOCPROTOPRIVATE+11)
+
+/* unknown: */
+#define AX25_NOUID_DEFAULT 0
+#define AX25_NOUID_BLOCK 1
+#define AX25_SET_RT_IPMODE 2
+
+/* Digipeating flags: */
+#define AX25_DIGI_INBAND 0x01 /* Allow digipeating within port */
+#define AX25_DIGI_XBAND 0x02 /* Allow digipeating across ports */
+
+/* Maximim number of digipeaters: */
+#define AX25_MAX_DIGIS 8
+
+
+typedef struct
+ {
+ char ax25_call[7]; /* 6 call + SSID (shifted ascii) */
+ }
+ax25_address;
+
+struct sockaddr_ax25
+ {
+ sa_family_t sax25_family;
+ ax25_address sax25_call;
+ int sax25_ndigis;
+ };
+
+/*
+ * The sockaddr struct with the digipeater adresses:
+ */
+struct full_sockaddr_ax25
+ {
+ struct sockaddr_ax25 fsa_ax25;
+ ax25_address fsa_digipeater[AX25_MAX_DIGIS];
+ };
+#define sax25_uid sax25_ndigis
+
+struct ax25_routes_struct
+ {
+ ax25_address port_addr;
+ ax25_address dest_addr;
+ unsigned char digi_count;
+ ax25_address digi_addr[AX25_MAX_DIGIS];
+ };
+
+/* The AX.25 ioctl structure: */
+struct ax25_ctl_struct
+ {
+ ax25_address port_addr;
+ ax25_address source_addr;
+ ax25_address dest_addr;
+ unsigned int cmd;
+ unsigned long arg;
+ unsigned char digi_count;
+ ax25_address digi_addr[AX25_MAX_DIGIS];
+ };
+
+struct ax25_info_struct
+ {
+ unsigned int n2, n2count;
+ unsigned int t1, t1timer;
+ unsigned int t2, t2timer;
+ unsigned int t3, t3timer;
+ unsigned int idle, idletimer;
+ unsigned int state;
+ unsigned int rcv_q, snd_q;
+ };
+
+struct ax25_fwd_struct
+ {
+ ax25_address port_from;
+ ax25_address port_to;
+ };
+
+/* AX.25 route structure: */
+struct ax25_route_opt_struct
+ {
+ ax25_address port_addr;
+ ax25_address dest_addr;
+ int cmd;
+ int arg;
+ };
+
+/* AX.25 BPQ stuff: */
+struct ax25_bpqaddr_struct
+ {
+ char dev[16];
+ ax25_address addr;
+ };
+
+/* Definitions for the AX.25 `values' fields: */
+#define AX25_VALUES_IPDEFMODE 0 /* 'D'=DG 'V'=VC */
+#define AX25_VALUES_AXDEFMODE 1 /* 8=Normal 128=Extended Seq Nos */
+#define AX25_VALUES_NETROM 2 /* Allow NET/ROM - 0=No 1=Yes */
+#define AX25_VALUES_TEXT 3 /* Allow PID=Text - 0=No 1=Yes */
+#define AX25_VALUES_BACKOFF 4 /* 'E'=Exponential 'L'=Linear */
+#define AX25_VALUES_CONMODE 5 /* Allow connected modes - 0=No 1=Yes */
+#define AX25_VALUES_WINDOW 6 /* Default window size for standard AX.25 */
+#define AX25_VALUES_EWINDOW 7 /* Default window size for extended AX.25 */
+#define AX25_VALUES_T1 8 /* Default T1 timeout value */
+#define AX25_VALUES_T2 9 /* Default T2 timeout value */
+#define AX25_VALUES_T3 10 /* Default T3 timeout value */
+#define AX25_VALUES_N2 11 /* Default N2 value */
+#define AX25_VALUES_DIGI 12 /* Digipeat mode */
+#define AX25_VALUES_IDLE 13 /* mode vc idle timer */
+#define AX25_VALUES_PACLEN 14 /* AX.25 MTU */
+#define AX25_VALUES_IPMAXQUEUE 15 /* Maximum number of buffers enqueued */
+#define AX25_MAX_VALUES 20
+
+struct ax25_parms_struct
+ {
+ ax25_address port_addr;
+ unsigned short values[AX25_MAX_VALUES];
+ };
+
+#endif /* netax25/ax25.h */
diff --git a/libc/sysdeps/unix/sysv/linux/neteconet/ec.h b/libc/sysdeps/unix/sysv/linux/neteconet/ec.h
new file mode 100644
index 000000000..f21601ca0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/neteconet/ec.h
@@ -0,0 +1,52 @@
+/* Definitions for use with Linux AF_ECONET sockets.
+ Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NETECONET_EC_H
+#define _NETECONET_EC_H 1
+
+#include <features.h>
+#include <bits/sockaddr.h>
+
+struct ec_addr
+ {
+ unsigned char station; /* Station number. */
+ unsigned char net; /* Network number. */
+ };
+
+struct sockaddr_ec
+ {
+ __SOCKADDR_COMMON (sec_);
+ unsigned char port; /* Port number. */
+ unsigned char cb; /* Control/flag byte. */
+ unsigned char type; /* Type of message. */
+ struct ec_addr addr;
+ unsigned long cookie;
+ };
+
+#define ECTYPE_PACKET_RECEIVED 0 /* Packet received */
+#define ECTYPE_TRANSMIT_STATUS 0x10 /* Transmit completed */
+
+#define ECTYPE_TRANSMIT_OK 1
+#define ECTYPE_TRANSMIT_NOT_LISTENING 2
+#define ECTYPE_TRANSMIT_NET_ERROR 3
+#define ECTYPE_TRANSMIT_NO_CLOCK 4
+#define ECTYPE_TRANSMIT_LINE_JAMMED 5
+#define ECTYPE_TRANSMIT_NOT_PRESENT 6
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/netinet/if_ether.h b/libc/sysdeps/unix/sysv/linux/netinet/if_ether.h
new file mode 100644
index 000000000..aadb59bea
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/netinet/if_ether.h
@@ -0,0 +1,105 @@
+/* Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef __NETINET_IF_ETHER_H
+
+#define __NETINET_IF_ETHER_H 1
+#include <features.h>
+#include <sys/types.h>
+
+/* Get definitions from kernel header file. */
+#include <linux/if_ether.h>
+
+#ifdef __USE_BSD
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_ether.h 8.3 (Berkeley) 5/2/95
+ * $FreeBSD$
+ */
+
+#include <net/ethernet.h>
+#include <net/if_arp.h>
+
+__BEGIN_DECLS
+/*
+ * Ethernet Address Resolution Protocol.
+ *
+ * See RFC 826 for protocol description. Structure below is adapted
+ * to resolving internet addresses. Field names used correspond to
+ * RFC 826.
+ */
+struct ether_arp {
+ struct arphdr ea_hdr; /* fixed-size header */
+ u_int8_t arp_sha[ETH_ALEN]; /* sender hardware address */
+ u_int8_t arp_spa[4]; /* sender protocol address */
+ u_int8_t arp_tha[ETH_ALEN]; /* target hardware address */
+ u_int8_t arp_tpa[4]; /* target protocol address */
+};
+#define arp_hrd ea_hdr.ar_hrd
+#define arp_pro ea_hdr.ar_pro
+#define arp_hln ea_hdr.ar_hln
+#define arp_pln ea_hdr.ar_pln
+#define arp_op ea_hdr.ar_op
+
+/*
+ * Macro to map an IP multicast address to an Ethernet multicast address.
+ * The high-order 25 bits of the Ethernet address are statically assigned,
+ * and the low-order 23 bits are taken from the low end of the IP address.
+ */
+#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
+ /* struct in_addr *ipaddr; */ \
+ /* u_char enaddr[ETH_ALEN]; */ \
+{ \
+ (enaddr)[0] = 0x01; \
+ (enaddr)[1] = 0x00; \
+ (enaddr)[2] = 0x5e; \
+ (enaddr)[3] = ((u_int8_t *)ipaddr)[1] & 0x7f; \
+ (enaddr)[4] = ((u_int8_t *)ipaddr)[2]; \
+ (enaddr)[5] = ((u_int8_t *)ipaddr)[3]; \
+}
+
+__END_DECLS
+#endif /* __USE_BSD */
+
+#endif /* netinet/if_ether.h */
diff --git a/libc/sysdeps/unix/sysv/linux/netinet/if_fddi.h b/libc/sysdeps/unix/sysv/linux/netinet/if_fddi.h
new file mode 100644
index 000000000..1a0ec927d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/netinet/if_fddi.h
@@ -0,0 +1,37 @@
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NETINET_IF_FDDI_H
+#define _NETINET_IF_FDDI_H 1
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <asm/types.h>
+
+#include <linux/if_fddi.h>
+
+#ifdef __USE_BSD
+
+struct fddi_header {
+ u_int8_t fddi_fc; /* Frame Control (FC) value */
+ u_int8_t fddi_dhost[FDDI_K_ALEN]; /* Destination host */
+ u_int8_t fddi_shost[FDDI_K_ALEN]; /* Source host */
+};
+#endif
+
+#endif /* netinet/if_fddi.h */
diff --git a/libc/sysdeps/unix/sysv/linux/netinet/if_tr.h b/libc/sysdeps/unix/sysv/linux/netinet/if_tr.h
new file mode 100644
index 000000000..45c39115f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/netinet/if_tr.h
@@ -0,0 +1,111 @@
+/* Copyright (C) 1997, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NETINET_IF_TR_H
+#define _NETINET_IF_TR_H 1
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+/* IEEE 802.5 Token-Ring magic constants. The frame sizes omit the preamble
+ and FCS/CRC (frame check sequence). */
+#define TR_ALEN 6 /* Octets in one token-ring addr */
+#define TR_HLEN (sizeof (struct trh_hdr) + sizeof (struct trllc))
+#define AC 0x10
+#define LLC_FRAME 0x40
+
+/* LLC and SNAP constants */
+#define EXTENDED_SAP 0xAA
+#define UI_CMD 0x03
+
+/* This is an Token-Ring frame header. */
+struct trh_hdr
+{
+ u_int8_t ac; /* access control field */
+ u_int8_t fc; /* frame control field */
+ u_int8_t daddr[TR_ALEN]; /* destination address */
+ u_int8_t saddr[TR_ALEN]; /* source address */
+ u_int16_t rcf; /* route control field */
+ u_int16_t rseg[8]; /* routing registers */
+};
+
+/* This is an Token-Ring LLC structure */
+struct trllc
+{
+ u_int8_t dsap; /* destination SAP */
+ u_int8_t ssap; /* source SAP */
+ u_int8_t llc; /* LLC control field */
+ u_int8_t protid[3]; /* protocol id */
+ u_int16_t ethertype; /* ether type field */
+};
+
+/* Token-Ring statistics collection data. */
+struct tr_statistics
+{
+ unsigned long rx_packets; /* total packets received */
+ unsigned long tx_packets; /* total packets transmitted */
+ unsigned long rx_bytes; /* total bytes received */
+ unsigned long tx_bytes; /* total bytes transmitted */
+ unsigned long rx_errors; /* bad packets received */
+ unsigned long tx_errors; /* packet transmit problems */
+ unsigned long rx_dropped; /* no space in linux buffers */
+ unsigned long tx_dropped; /* no space available in linux */
+ unsigned long multicast; /* multicast packets received */
+ unsigned long transmit_collision;
+
+ /* detailed Token-Ring errors. See IBM Token-Ring Network
+ Architecture for more info */
+
+ unsigned long line_errors;
+ unsigned long internal_errors;
+ unsigned long burst_errors;
+ unsigned long A_C_errors;
+ unsigned long abort_delimiters;
+ unsigned long lost_frames;
+ unsigned long recv_congest_count;
+ unsigned long frame_copied_errors;
+ unsigned long frequency_errors;
+ unsigned long token_errors;
+ unsigned long dummy1;
+};
+
+/* source routing stuff */
+#define TR_RII 0x80
+#define TR_RCF_DIR_BIT 0x80
+#define TR_RCF_LEN_MASK 0x1f00
+#define TR_RCF_BROADCAST 0x8000 /* all-routes broadcast */
+#define TR_RCF_LIMITED_BROADCAST 0xC000 /* single-route broadcast */
+#define TR_RCF_FRAME2K 0x20
+#define TR_RCF_BROADCAST_MASK 0xC000
+#define TR_MAXRIFLEN 18
+
+#ifdef __USE_BSD
+
+struct trn_hdr
+{
+ u_int8_t trn_ac; /* access control field */
+ u_int8_t trn_fc; /* field control field */
+ u_int8_t trn_dhost[TR_ALEN]; /* destination host */
+ u_int8_t trn_shost[TR_ALEN]; /* source host */
+ u_int16_t trn_rcf; /* route control field */
+ u_int16_t trn_rseg[8]; /* routing registers */
+};
+
+#endif
+
+#endif /* netinet/if_tr.h */
diff --git a/libc/sysdeps/unix/sysv/linux/netipx/ipx.h b/libc/sysdeps/unix/sysv/linux/netipx/ipx.h
new file mode 100644
index 000000000..7eb42ef55
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/netipx/ipx.h
@@ -0,0 +1,113 @@
+/* Copyright (C) 1991, 92, 93, 95, 96, 97, 98 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef __NETIPX_IPX_H
+#define __NETIPX_IPX_H 1
+
+#include <features.h>
+
+#include <sys/types.h>
+#include <bits/sockaddr.h>
+
+__BEGIN_DECLS
+
+#define SOL_IPX 256 /* sockopt level */
+
+#define IPX_TYPE 1
+#define IPX_NODE_LEN 6
+#define IPX_MTU 576
+
+struct sockaddr_ipx
+ {
+ sa_family_t sipx_family;
+ u_int16_t sipx_port;
+ u_int32_t sipx_network;
+ unsigned char sipx_node[IPX_NODE_LEN];
+ u_int8_t sipx_type;
+ unsigned char sipx_zero; /* 16 byte fill */
+ };
+
+/*
+ * So we can fit the extra info for SIOCSIFADDR into the address nicely
+ */
+
+#define sipx_special sipx_port
+#define sipx_action sipx_zero
+#define IPX_DLTITF 0
+#define IPX_CRTITF 1
+
+typedef struct ipx_route_definition
+ {
+ unsigned long ipx_network;
+ unsigned long ipx_router_network;
+ unsigned char ipx_router_node[IPX_NODE_LEN];
+ }
+ipx_route_definition;
+
+typedef struct ipx_interface_definition
+ {
+ unsigned long ipx_network;
+ unsigned char ipx_device[16];
+ unsigned char ipx_dlink_type;
+#define IPX_FRAME_NONE 0
+#define IPX_FRAME_SNAP 1
+#define IPX_FRAME_8022 2
+#define IPX_FRAME_ETHERII 3
+#define IPX_FRAME_8023 4
+#define IPX_FRAME_TR_8022 5
+ unsigned char ipx_special;
+#define IPX_SPECIAL_NONE 0
+#define IPX_PRIMARY 1
+#define IPX_INTERNAL 2
+ unsigned char ipx_node[IPX_NODE_LEN];
+ }
+ipx_interface_definition;
+
+typedef struct ipx_config_data
+ {
+ unsigned char ipxcfg_auto_select_primary;
+ unsigned char ipxcfg_auto_create_interfaces;
+ }
+ipx_config_data;
+
+/*
+ * OLD Route Definition for backward compatibility.
+ */
+
+struct ipx_route_def
+ {
+ unsigned long ipx_network;
+ unsigned long ipx_router_network;
+#define IPX_ROUTE_NO_ROUTER 0
+ unsigned char ipx_router_node[IPX_NODE_LEN];
+ unsigned char ipx_device[16];
+ unsigned short ipx_flags;
+#define IPX_RT_SNAP 8
+#define IPX_RT_8022 4
+#define IPX_RT_BLUEBOOK 2
+#define IPX_RT_ROUTED 1
+ };
+
+#define SIOCAIPXITFCRT (SIOCPROTOPRIVATE)
+#define SIOCAIPXPRISLT (SIOCPROTOPRIVATE + 1)
+#define SIOCIPXCFGDATA (SIOCPROTOPRIVATE + 2)
+#define SIOCIPXNCPCONN (SIOCPROTOPRIVATE + 3)
+
+__END_DECLS
+
+#endif /* netipx/ipx.h */
diff --git a/libc/sysdeps/unix/sysv/linux/netlinkaccess.h b/libc/sysdeps/unix/sysv/linux/netlinkaccess.h
new file mode 100644
index 000000000..92310b77d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/netlinkaccess.h
@@ -0,0 +1,61 @@
+/* Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NETLINKACCESS_H
+#define _NETLINKACCESS_H 1
+
+#include <asm/types.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
+#include <kernel-features.h>
+
+
+struct netlink_res
+{
+ struct netlink_res *next;
+ struct nlmsghdr *nlh;
+ size_t size; /* Size of response. */
+ uint32_t seq; /* sequential number we used. */
+};
+
+
+struct netlink_handle
+{
+ int fd; /* Netlink file descriptor. */
+ pid_t pid; /* Process ID. */
+ uint32_t seq; /* The sequence number we use currently. */
+ struct netlink_res *nlm_list; /* Pointer to list of responses. */
+ struct netlink_res *end_ptr; /* For faster append of new entries. */
+};
+
+
+#if __ASSUME_NETLINK_SUPPORT == 0
+extern int __no_netlink_support attribute_hidden;
+#else
+# define __no_netlink_support 0
+#endif
+
+
+extern int __netlink_open (struct netlink_handle *h);
+extern void __netlink_close (struct netlink_handle *h);
+extern void __netlink_free_handle (struct netlink_handle *h);
+extern int __netlink_request (struct netlink_handle *h, int type);
+
+
+#endif /* netlinkaccess.h */
diff --git a/libc/sysdeps/unix/sysv/linux/netpacket/packet.h b/libc/sysdeps/unix/sysv/linux/netpacket/packet.h
new file mode 100644
index 000000000..6c634282f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/netpacket/packet.h
@@ -0,0 +1,64 @@
+/* Definitions for use with Linux AF_PACKET sockets.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef __NETPACKET_PACKET_H
+#define __NETPACKET_PACKET_H 1
+
+struct sockaddr_ll
+ {
+ unsigned short int sll_family;
+ unsigned short int sll_protocol;
+ int sll_ifindex;
+ unsigned short int sll_hatype;
+ unsigned char sll_pkttype;
+ unsigned char sll_halen;
+ unsigned char sll_addr[8];
+ };
+
+/* Packet types. */
+
+#define PACKET_HOST 0 /* To us. */
+#define PACKET_BROADCAST 1 /* To all. */
+#define PACKET_MULTICAST 2 /* To group. */
+#define PACKET_OTHERHOST 3 /* To someone else. */
+#define PACKET_OUTGOING 4 /* Originated by us . */
+#define PACKET_LOOPBACK 5
+#define PACKET_FASTROUTE 6
+
+/* Packet socket options. */
+
+#define PACKET_ADD_MEMBERSHIP 1
+#define PACKET_DROP_MEMBERSHIP 2
+#define PACKET_RECV_OUTPUT 3
+#define PACKET_RX_RING 5
+#define PACKET_STATISTICS 6
+
+struct packet_mreq
+ {
+ int mr_ifindex;
+ unsigned short int mr_type;
+ unsigned short int mr_alen;
+ unsigned char mr_address[8];
+ };
+
+#define PACKET_MR_MULTICAST 0
+#define PACKET_MR_PROMISC 1
+#define PACKET_MR_ALLMULTI 2
+
+#endif /* netpacket/packet.h */
diff --git a/libc/sysdeps/unix/sysv/linux/netrom/netrom.h b/libc/sysdeps/unix/sysv/linux/netrom/netrom.h
new file mode 100644
index 000000000..4984772ad
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/netrom/netrom.h
@@ -0,0 +1,84 @@
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _NETROM_NETROM_H
+#define _NETROM_NETROM_H 1
+
+#include <netax25/ax25.h>
+
+/* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx. */
+#define SOL_NETROM 259
+
+/* NetRom control values: */
+#define NETROM_T1 1
+#define NETROM_T2 2
+#define NETROM_N2 3
+#define NETROM_PACLEN 5
+#define NETROM_T4 6
+#define NETROM_IDLE 7
+
+#define NETROM_KILL 99
+
+/* Type of route: */
+#define NETROM_NEIGH 0
+#define NETROM_NODE 1
+
+struct nr_route_struct
+ {
+ int type;
+ ax25_address callsign;
+ char device[16];
+ unsigned int quality;
+ char mnemonic[7];
+ ax25_address neighbour;
+ unsigned int obs_count;
+ unsigned int ndigis;
+ ax25_address digipeaters[AX25_MAX_DIGIS];
+ };
+
+/* NetRom socket ioctls: */
+#define SIOCNRGETPARMS (SIOCPROTOPRIVATE+0)
+#define SIOCNRSETPARMS (SIOCPROTOPRIVATE+1)
+#define SIOCNRDECOBS (SIOCPROTOPRIVATE+2)
+#define SIOCNRRTCTL (SIOCPROTOPRIVATE+3)
+#define SIOCNRCTLCON (SIOCPROTOPRIVATE+4)
+
+/* NetRom parameter structure: */
+struct nr_parms_struct
+ {
+ unsigned int quality;
+ unsigned int obs_count;
+ unsigned int ttl;
+ unsigned int timeout;
+ unsigned int ack_delay;
+ unsigned int busy_delay;
+ unsigned int tries;
+ unsigned int window;
+ unsigned int paclen;
+ };
+
+/* NetRom control structure: */
+struct nr_ctl_struct
+ {
+ unsigned char index;
+ unsigned char id;
+ unsigned int cmd;
+ unsigned long arg;
+ };
+
+#endif /* netrom/netrom.h */
diff --git a/libc/sysdeps/unix/sysv/linux/netrose/rose.h b/libc/sysdeps/unix/sysv/linux/netrose/rose.h
new file mode 100644
index 000000000..e4ba7d701
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/netrose/rose.h
@@ -0,0 +1,116 @@
+/* Definitions for Rose packet radio address family.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* What follows is copied from the 2.1.93 <linux/rose.h>. */
+
+#ifndef _NETROSE_ROSE_H
+#define _NETROSE_ROSE_H 1
+
+/* Socket level values. */
+#define SOL_ROSE 260
+
+
+/* These are the public elements of the Linux kernel Rose
+ implementation. For kernel AX.25 see the file ax25.h. This file
+ requires ax25.h for the definition of the ax25_address structure. */
+#define ROSE_MTU 251
+
+#define ROSE_MAX_DIGIS 6
+
+#define ROSE_DEFER 1
+#define ROSE_T1 2
+#define ROSE_T2 3
+#define ROSE_T3 4
+#define ROSE_IDLE 5
+#define ROSE_QBITINCL 6
+#define ROSE_HOLDBACK 7
+
+#define SIOCRSGCAUSE (SIOCPROTOPRIVATE + 0)
+#define SIOCRSSCAUSE (SIOCPROTOPRIVATE + 1)
+#define SIOCRSL2CALL (SIOCPROTOPRIVATE + 2)
+#define SIOCRSSL2CALL (SIOCPROTOPRIVATE + 2)
+#define SIOCRSACCEPT (SIOCPROTOPRIVATE + 3)
+#define SIOCRSCLRRT (SIOCPROTOPRIVATE + 4)
+#define SIOCRSGL2CALL (SIOCPROTOPRIVATE + 5)
+#define SIOCRSGFACILITIES (SIOCPROTOPRIVATE + 6)
+
+#define ROSE_DTE_ORIGINATED 0x00
+#define ROSE_NUMBER_BUSY 0x01
+#define ROSE_INVALID_FACILITY 0x03
+#define ROSE_NETWORK_CONGESTION 0x05
+#define ROSE_OUT_OF_ORDER 0x09
+#define ROSE_ACCESS_BARRED 0x0B
+#define ROSE_NOT_OBTAINABLE 0x0D
+#define ROSE_REMOTE_PROCEDURE 0x11
+#define ROSE_LOCAL_PROCEDURE 0x13
+#define ROSE_SHIP_ABSENT 0x39
+
+
+typedef struct
+{
+ char rose_addr[5];
+} rose_address;
+
+struct sockaddr_rose
+{
+ sa_family_t srose_family;
+ rose_address srose_addr;
+ ax25_address srose_call;
+ int srose_ndigis;
+ ax25_address srose_digi;
+};
+
+struct full_sockaddr_rose
+{
+ sa_family_t srose_family;
+ rose_address srose_addr;
+ ax25_address srose_call;
+ unsigned int srose_ndigis;
+ ax25_address srose_digis[ROSE_MAX_DIGIS];
+};
+
+struct rose_route_struct
+{
+ rose_address address;
+ unsigned short int mask;
+ ax25_address neighbour;
+ char device[16];
+ unsigned char ndigis;
+ ax25_address digipeaters[AX25_MAX_DIGIS];
+};
+
+struct rose_cause_struct
+{
+ unsigned char cause;
+ unsigned char diagnostic;
+};
+
+struct rose_facilities_struct
+{
+ rose_address source_addr, dest_addr;
+ ax25_address source_call, dest_call;
+ unsigned char source_ndigis, dest_ndigis;
+ ax25_address source_digis[ROSE_MAX_DIGIS];
+ ax25_address dest_digis[ROSE_MAX_DIGIS];
+ unsigned int rand;
+ rose_address fail_addr;
+ ax25_address fail_call;
+};
+
+#endif /* netrose/rose.h */
diff --git a/libc/sysdeps/unix/sysv/linux/nfs/nfs.h b/libc/sysdeps/unix/sysv/linux/nfs/nfs.h
new file mode 100644
index 000000000..61e4b656d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/nfs/nfs.h
@@ -0,0 +1 @@
+#include <linux/nfs.h>
diff --git a/libc/sysdeps/unix/sysv/linux/nice.c b/libc/sysdeps/unix/sysv/linux/nice.c
new file mode 100644
index 000000000..46a6da80c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/nice.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/nice.c>
diff --git a/libc/sysdeps/unix/sysv/linux/not-cancel.h b/libc/sysdeps/unix/sysv/linux/not-cancel.h
new file mode 100644
index 000000000..80d33be29
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/not-cancel.h
@@ -0,0 +1,105 @@
+/* Uncancelable versions of cancelable interfaces. Linux version.
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/types.h>
+#include <sysdep.h>
+
+/* Uncancelable open. */
+#define open_not_cancel(name, flags, mode) \
+ INLINE_SYSCALL (open, 3, (const char *) (name), (flags), (mode))
+#define open_not_cancel_2(name, flags) \
+ INLINE_SYSCALL (open, 2, (const char *) (name), (flags))
+
+/* Uncancelable openat. */
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+extern int __openat_nocancel (int fd, const char *fname, int oflag,
+ mode_t mode) attribute_hidden;
+extern int __openat64_nocancel (int fd, const char *fname, int oflag,
+ mode_t mode) attribute_hidden;
+#else
+# define __openat_nocancel(fd, fname, oflag, mode) \
+ openat (fd, fname, oflag, mode)
+# define __openat64_nocancel(fd, fname, oflag, mode) \
+ openat64 (fd, fname, oflag, mode)
+#endif
+
+#define openat_not_cancel(fd, fname, oflag, mode) \
+ __openat_nocancel (fd, fname, oflag, mode)
+#define openat_not_cancel_3(fd, fname, oflag) \
+ __openat_nocancel (fd, fname, oflag, 0)
+#define openat64_not_cancel(fd, fname, oflag, mode) \
+ __openat64_nocancel (fd, fname, oflag, mode)
+#define openat64_not_cancel_3(fd, fname, oflag) \
+ __openat64_nocancel (fd, fname, oflag, 0)
+
+/* Uncancelable close. */
+#define close_not_cancel(fd) \
+ INLINE_SYSCALL (close, 1, fd)
+#define close_not_cancel_no_status(fd) \
+ (void) ({ INTERNAL_SYSCALL_DECL (err); \
+ INTERNAL_SYSCALL (close, err, 1, (fd)); })
+
+/* Uncancelable read. */
+#define read_not_cancel(fd, buf, n) \
+ INLINE_SYSCALL (read, 3, (fd), (buf), (n))
+
+/* Uncancelable write. */
+#define write_not_cancel(fd, buf, n) \
+ INLINE_SYSCALL (write, 3, (fd), (buf), (n))
+
+/* Uncancelable writev. */
+#define writev_not_cancel_no_status(fd, iov, n) \
+ (void) ({ INTERNAL_SYSCALL_DECL (err); \
+ INTERNAL_SYSCALL (writev, err, 3, (fd), (iov), (n)); })
+
+/* Uncancelable fcntl. */
+#define fcntl_not_cancel(fd, cmd, val) \
+ __fcntl_nocancel (fd, cmd, val)
+
+/* Uncancelable waitpid. */
+#ifdef __NR_waitpid
+# define waitpid_not_cancel(pid, stat_loc, options) \
+ INLINE_SYSCALL (waitpid, 3, pid, stat_loc, options)
+#else
+# define waitpid_not_cancel(pid, stat_loc, options) \
+ INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL)
+#endif
+
+/* Uncancelable pause. */
+#ifdef __NR_pause
+# define pause_not_cancel() \
+ INLINE_SYSCALL (pause, 0)
+#else
+# define pause_not_cancel() \
+ __pause_nocancel ()
+#endif
+
+/* Uncancelable nanosleep. */
+#ifdef __NR_nanosleep
+# define nanosleep_not_cancel(requested_time, remaining) \
+ INLINE_SYSCALL (nanosleep, 2, requested_time, remaining)
+#else
+# define nanosleep_not_cancel(requested_time, remaining) \
+ __nanosleep_nocancel (requested_time, remaining)
+#endif
+
+/* Uncancelable sigsuspend. */
+#define sigsuspend_not_cancel(set) \
+ __sigsuspend_nocancel (set)
diff --git a/libc/sysdeps/unix/sysv/linux/nscd_setup_thread.c b/libc/sysdeps/unix/sysv/linux/nscd_setup_thread.c
new file mode 100644
index 000000000..1589c24ea
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/nscd_setup_thread.c
@@ -0,0 +1,47 @@
+/* Setup of nscd worker threads. Linux verison.
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include <string.h>
+#include <unistd.h>
+#include <nscd.h>
+#include <sysdep.h>
+
+
+void
+setup_thread (struct database_dyn *db)
+{
+#ifdef __NR_set_tid_address
+ /* Only supported when NPTL is used. */
+ char buf[100];
+ if (confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, sizeof (buf)) >= sizeof (buf)
+ || strncmp (buf, "NPTL", 4) != 0)
+ return;
+
+ /* Do not try this at home, kids. We play with the SETTID address
+ even thought the process is multi-threaded. This can only work
+ since none of the threads ever terminates. */
+ INTERNAL_SYSCALL_DECL (err);
+ int r = INTERNAL_SYSCALL (set_tid_address, err, 1,
+ &db->head->nscd_certainly_running);
+ if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+ /* We know the kernel can reset this field when nscd terminates.
+ So, set the field to a nonzero value which indicates that nscd
+ is certainly running and clients can skip the test. */
+ db->head->nscd_certainly_running = 1;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ntp_gettime.c b/libc/sysdeps/unix/sysv/linux/ntp_gettime.c
new file mode 100644
index 000000000..f78f1682f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ntp_gettime.c
@@ -0,0 +1,42 @@
+/* Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/timex.h>
+
+#ifndef MOD_OFFSET
+# define modes mode
+#endif
+
+
+extern int INTUSE(__adjtimex) (struct timex *__ntx);
+
+
+int
+ntp_gettime (ntv)
+ struct ntptimeval *ntv;
+{
+ struct timex tntx;
+ int result;
+
+ tntx.modes = 0;
+ result = INTUSE(__adjtimex) (&tntx);
+ ntv->time = tntx.time;
+ ntv->maxerror = tntx.maxerror;
+ ntv->esterror = tntx.esterror;
+ return result;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/open64.c b/libc/sysdeps/unix/sysv/linux/open64.c
new file mode 100644
index 000000000..5fb5363e1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/open64.c
@@ -0,0 +1,53 @@
+/* Copyright (C) 1991,1995-1997,1999,2000,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <bp-sym.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 (open, 3, file, oflag | O_LARGEFILE, mode);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = INLINE_SYSCALL (open, 3, file, oflag | O_LARGEFILE, mode);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+weak_alias (__libc_open64, BP_SYM (__open64))
+libc_hidden_weak (BP_SYM (__open64))
+weak_alias (__libc_open64, BP_SYM (open64))
diff --git a/libc/sysdeps/unix/sysv/linux/openat.c b/libc/sysdeps/unix/sysv/linux/openat.c
new file mode 100644
index 000000000..7dfe36742
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/openat.c
@@ -0,0 +1,173 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <kernel-features.h>
+#include <sysdep-cancel.h>
+#include <not-cancel.h>
+
+
+#if !defined OPENAT && !defined __ASSUME_ATFCTS
+# define OPENAT openat
+
+/* Set errno after a failed call. If BUF is not null,
+ it is a /proc/self/fd/ path name we just tried to use. */
+void
+attribute_hidden
+__atfct_seterrno (int errval, int fd, const char *buf)
+{
+ if (buf != NULL)
+ {
+ struct stat64 st;
+
+ if (errval == ENOTDIR || errval == ENOENT)
+ {
+ /* This can mean either the file descriptor is invalid or
+ /proc is not mounted. */
+ if (__fxstat64 (_STAT_VER, fd, &st) != 0)
+ /* errno is already set correctly. */
+ return;
+
+ /* If /proc is not mounted there is nothing we can do. */
+ if ((errval != ENOTDIR || S_ISDIR (st.st_mode))
+ && (__xstat64 (_STAT_VER, "/proc/self/fd", &st) != 0
+ || !S_ISDIR (st.st_mode)))
+ errval = ENOSYS;
+ }
+ }
+
+ __set_errno (errval);
+}
+
+int __have_atfcts;
+#endif
+
+
+#define OPENAT_NOT_CANCEL CONCAT (OPENAT)
+#define CONCAT(name) CONCAT2 (name)
+#define CONCAT2(name) __##name##_nocancel
+
+
+int
+OPENAT_NOT_CANCEL (fd, file, oflag, mode)
+ int fd;
+ const char *file;
+ int oflag;
+ mode_t mode;
+{
+
+ /* We have to add the O_LARGEFILE flag for openat64. */
+#ifdef MORE_OFLAGS
+ oflag |= MORE_OFLAGS;
+#endif
+
+ INTERNAL_SYSCALL_DECL (err);
+ int res;
+
+#ifdef __NR_openat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ res = INLINE_SYSCALL (openat, 4, fd, file, oflag, mode);
+
+# ifndef __ASSUME_ATFCTS
+ if (res == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return res;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ /* Note: snprintf cannot be canceled. */
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ res = INTERNAL_SYSCALL (open, err, 3, file, oflag, mode);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (res, err), 0))
+ {
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (res, err), fd, buf);
+ res = -1;
+ }
+
+ return res;
+#endif
+}
+
+#define UNDERIZE(name) UNDERIZE_1 (name)
+#define UNDERIZE_1(name) __##name
+#define __OPENAT UNDERIZE (OPENAT)
+
+
+/* Open FILE with access OFLAG. Interpret relative paths relative to
+ the directory associated with FD. If OFLAG includes O_CREAT, a
+ third argument is the file protection. */
+int
+__OPENAT (fd, file, oflag)
+ int fd;
+ const char *file;
+ int oflag;
+{
+ mode_t mode = 0;
+ if (oflag & O_CREAT)
+ {
+ va_list arg;
+ va_start (arg, oflag);
+ mode = va_arg (arg, mode_t);
+ va_end (arg);
+ }
+
+ if (SINGLE_THREAD_P)
+ return OPENAT_NOT_CANCEL (fd, file, oflag, mode);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int res = OPENAT_NOT_CANCEL (fd, file, oflag, mode);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return res;
+}
+libc_hidden_def (__OPENAT)
+weak_alias (__OPENAT, OPENAT)
diff --git a/libc/sysdeps/unix/sysv/linux/openat64.c b/libc/sysdeps/unix/sysv/linux/openat64.c
new file mode 100644
index 000000000..9e7a2b373
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/openat64.c
@@ -0,0 +1,4 @@
+#define OPENAT openat64
+#define MORE_OFLAGS O_LARGEFILE
+
+#include "openat.c"
diff --git a/libc/sysdeps/unix/sysv/linux/opendir.c b/libc/sysdeps/unix/sysv/linux/opendir.c
new file mode 100644
index 000000000..c7671dc17
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/opendir.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 2000, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <kernel-features.h>
+
+
+#ifdef __ASSUME_O_DIRECTORY
+# define O_DIRECTORY_WORKS 1
+#endif
+
+#include <sysdeps/unix/opendir.c>
diff --git a/libc/sysdeps/unix/sysv/linux/opensock.c b/libc/sysdeps/unix/sysv/linux/opensock.c
new file mode 100644
index 000000000..225298078
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/opensock.c
@@ -0,0 +1,119 @@
+/* Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/socket.h>
+
+/* Return a socket of any type. The socket can be used in subsequent
+ ioctl calls to talk to the kernel. */
+int internal_function
+__opensock (void)
+{
+ static int last_family; /* Available socket family we will use. */
+ static int last_type;
+ static const struct
+ {
+ int family;
+ const char procname[15];
+ } afs[] =
+ {
+ /* The 2.2 kernels cannot handle ioctl(SIOCGIFCONF) on AF_UNIX sockets.
+ Give the kernel a chance to user inet sockets on old kernels. */
+#if __LINUX_KERNEL_VERSION < 132096
+ { AF_INET, "" },
+ { AF_UNIX, "net/unix" },
+#else
+ { AF_UNIX, "net/unix" },
+ { AF_INET, "" },
+#endif
+ { AF_INET6, "net/if_inet6" },
+ { AF_AX25, "net/ax25" },
+ { AF_NETROM, "net/nr" },
+ { AF_ROSE, "net/rose" },
+ { AF_IPX, "net/ipx" },
+ { AF_APPLETALK, "net/appletalk" },
+ { AF_ECONET, "sys/net/econet" },
+ { AF_ASH, "sys/net/ash" },
+ { AF_X25, "net/x25" }
+ };
+#define nafs (sizeof (afs) / sizeof (afs[0]))
+ char fname[sizeof "/proc/" + 14];
+ int result;
+ int has_proc;
+ size_t cnt;
+
+ /* We already know which family to use from the last call. Use it
+ again. */
+ if (last_family != 0)
+ {
+ assert (last_type != 0);
+
+ result = __socket (last_family, last_type, 0);
+ if (result != -1 || errno != EAFNOSUPPORT)
+ /* Maybe the socket type isn't supported anymore (module is
+ unloaded). In this case again try to find the type. */
+ return result;
+
+ /* Reset the values. They seem not valid anymore. */
+ last_family = 0;
+ last_type = 0;
+ }
+
+ /* Check whether the /proc filesystem is available. */
+ has_proc = __access ("/proc/net", R_OK) != -1;
+ strcpy (fname, "/proc/");
+
+ /* Iterate over the interface families and find one which is
+ available. */
+ for (cnt = 0; cnt < nafs; ++cnt)
+ {
+ int type = SOCK_DGRAM;
+
+ if (has_proc && afs[cnt].procname[0] != '\0')
+ {
+ strcpy (fname + 6, afs[cnt].procname);
+ if (__access (fname, R_OK) == -1)
+ /* The /proc entry is not available. I.e., we cannot
+ create a socket of this type (without loading the
+ module). Don't look for it since this might trigger
+ loading the module. */
+ continue;
+ }
+
+ if (afs[cnt].family == AF_NETROM || afs[cnt].family == AF_X25)
+ type = SOCK_SEQPACKET;
+
+ result = __socket (afs[cnt].family, type, 0);
+ if (result != -1)
+ {
+ /* Found an available family. */
+ last_type = type;
+ last_family = afs[cnt].family;
+ return result;
+ }
+ }
+
+ /* None of the protocol families is available. It is unclear what kind
+ of error is returned. ENOENT seems like a reasonable choice. */
+ __set_errno (ENOENT);
+ return -1;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/pathconf.c b/libc/sysdeps/unix/sysv/linux/pathconf.c
new file mode 100644
index 000000000..e12a08434
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/pathconf.c
@@ -0,0 +1,181 @@
+/* Get file-specific information about a file. Linux version.
+ Copyright (C) 1991,1995,1996,1998-2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <unistd.h>
+#include <errno.h>
+#include "pathconf.h"
+#include "linux_fsinfo.h"
+
+static long int posix_pathconf (const char *file, int name);
+
+/* Define this first, so it can be inlined. */
+#define __pathconf static posix_pathconf
+#include <sysdeps/posix/pathconf.c>
+
+
+/* Get file-specific information about FILE. */
+long int
+__pathconf (const char *file, int name)
+{
+ struct statfs fsbuf;
+
+ switch (name)
+ {
+ case _PC_LINK_MAX:
+ return __statfs_link_max (__statfs (file, &fsbuf), &fsbuf);
+
+ case _PC_FILESIZEBITS:
+ return __statfs_filesize_max (__statfs (file, &fsbuf), &fsbuf);
+
+ case _PC_2_SYMLINKS:
+ return __statfs_symlinks (__statfs (file, &fsbuf), &fsbuf);
+
+ default:
+ return posix_pathconf (file, name);
+ }
+}
+
+
+/* Used like: return statfs_link_max (__statfs (name, &buf), &buf); */
+long int
+__statfs_link_max (int result, const struct statfs *fsbuf)
+{
+ if (result < 0)
+ {
+ if (errno == ENOSYS)
+ /* Not possible, return the default value. */
+ return LINUX_LINK_MAX;
+
+ /* Some error occured. */
+ return -1;
+ }
+
+ switch (fsbuf->f_type)
+ {
+ case EXT2_SUPER_MAGIC:
+ return EXT2_LINK_MAX;
+
+ case MINIX_SUPER_MAGIC:
+ case MINIX_SUPER_MAGIC2:
+ return MINIX_LINK_MAX;
+
+ case MINIX2_SUPER_MAGIC:
+ case MINIX2_SUPER_MAGIC2:
+ return MINIX2_LINK_MAX;
+
+ case XENIX_SUPER_MAGIC:
+ return XENIX_LINK_MAX;
+
+ case SYSV4_SUPER_MAGIC:
+ case SYSV2_SUPER_MAGIC:
+ return SYSV_LINK_MAX;
+
+ case COH_SUPER_MAGIC:
+ return COH_LINK_MAX;
+
+ case UFS_MAGIC:
+ case UFS_CIGAM:
+ return UFS_LINK_MAX;
+
+ case REISERFS_SUPER_MAGIC:
+ return REISERFS_LINK_MAX;
+
+ case XFS_SUPER_MAGIC:
+ return XFS_LINK_MAX;
+
+ default:
+ return LINUX_LINK_MAX;
+ }
+}
+
+
+/* Used like: return statfs_filesize_max (__statfs (name, &buf), &buf); */
+long int
+__statfs_filesize_max (int result, const struct statfs *fsbuf)
+{
+ if (result < 0)
+ {
+ if (errno == ENOSYS)
+ /* Not possible, return the default value. */
+ return 32;
+
+ /* Some error occured. */
+ return -1;
+ }
+
+ switch (fsbuf->f_type)
+ {
+ case EXT2_SUPER_MAGIC:
+ case UFS_MAGIC:
+ case UFS_CIGAM:
+ case REISERFS_SUPER_MAGIC:
+ case XFS_SUPER_MAGIC:
+ case SMB_SUPER_MAGIC:
+ case NTFS_SUPER_MAGIC:
+ case UDF_SUPER_MAGIC:
+ case JFS_SUPER_MAGIC:
+ case VXFS_SUPER_MAGIC:
+ return 64;
+
+ case MSDOS_SUPER_MAGIC:
+ case JFFS_SUPER_MAGIC:
+ case JFFS2_SUPER_MAGIC:
+ case NCP_SUPER_MAGIC:
+ case ROMFS_SUPER_MAGIC:
+ return 32;
+
+ default:
+ return 32;
+ }
+}
+
+
+/* Used like: return statfs_link_max (__statfs (name, &buf), &buf); */
+long int
+__statfs_symlinks (int result, const struct statfs *fsbuf)
+{
+ if (result < 0)
+ {
+ if (errno == ENOSYS)
+ /* Not possible, return the default value. */
+ return 1;
+
+ /* Some error occured. */
+ return -1;
+ }
+
+ switch (fsbuf->f_type)
+ {
+ case ADFS_SUPER_MAGIC:
+ case BFS_MAGIC:
+ case CRAMFS_MAGIC:
+ case DEVPTS_SUPER_MAGIC:
+ case EFS_SUPER_MAGIC:
+ case EFS_MAGIC:
+ case MSDOS_SUPER_MAGIC:
+ case NTFS_SUPER_MAGIC:
+ case QNX4_SUPER_MAGIC:
+ case ROMFS_SUPER_MAGIC:
+ /* No symlink support. */
+ return 0;
+
+ default:
+ return 1;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/pathconf.h b/libc/sysdeps/unix/sysv/linux/pathconf.h
new file mode 100644
index 000000000..20e23685e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/pathconf.h
@@ -0,0 +1,34 @@
+/* Common parts of Linux implementation of pathconf and fpathconf.
+ Copyright (C) 1991,1995,1996,1998-2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/statfs.h>
+
+
+/* Used like: return statfs_link_max (__statfs (name, &buf), &buf); */
+extern long int __statfs_link_max (int result, const struct statfs *fsbuf);
+
+
+/* Used like: return statfs_filesize_max (__statfs (name, &buf), &buf); */
+extern long int __statfs_filesize_max (int result, const struct statfs *fsbuf);
+
+
+/* Used like: return statfs_link_max (__statfs (name, &buf), &buf); */
+extern long int __statfs_symlinks (int result, const struct statfs *fsbuf);
diff --git a/libc/sysdeps/unix/sysv/linux/paths.h b/libc/sysdeps/unix/sysv/linux/paths.h
new file mode 100644
index 000000000..fb2c77e99
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/paths.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)paths.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _PATHS_H_
+#define _PATHS_H_
+
+/* Default search path. */
+#define _PATH_DEFPATH "/usr/bin:/bin"
+/* All standard utilities path. */
+#define _PATH_STDPATH \
+ "/usr/bin:/bin:/usr/sbin:/sbin"
+
+#define _PATH_BSHELL "/bin/sh"
+#define _PATH_CONSOLE "/dev/console"
+#define _PATH_CSHELL "/bin/csh"
+#define _PATH_DEVDB "/var/run/dev.db"
+#define _PATH_DEVNULL "/dev/null"
+#define _PATH_DRUM "/dev/drum"
+#define _PATH_KLOG "/proc/kmsg"
+#define _PATH_KMEM "/dev/kmem"
+#define _PATH_LASTLOG "/var/log/lastlog"
+#define _PATH_MAILDIR "/var/mail"
+#define _PATH_MAN "/usr/share/man"
+#define _PATH_MEM "/dev/mem"
+#define _PATH_MNTTAB "/etc/fstab"
+#define _PATH_MOUNTED "/etc/mtab"
+#define _PATH_NOLOGIN "/etc/nologin"
+#define _PATH_PRESERVE "/var/lib"
+#define _PATH_RWHODIR "/var/spool/rwho"
+#define _PATH_SENDMAIL "/usr/sbin/sendmail"
+#define _PATH_SHADOW "/etc/shadow"
+#define _PATH_SHELLS "/etc/shells"
+#define _PATH_TTY "/dev/tty"
+#define _PATH_UNIX "/boot/vmlinux"
+#define _PATH_UTMP "/var/run/utmp"
+#define _PATH_VI "/usr/bin/vi"
+#define _PATH_WTMP "/var/log/wtmp"
+
+/* Provide trailing slash, since mostly used for building pathnames. */
+#define _PATH_DEV "/dev/"
+#define _PATH_TMP "/tmp/"
+#define _PATH_VARDB "/var/db/"
+#define _PATH_VARRUN "/var/run/"
+#define _PATH_VARTMP "/var/tmp/"
+
+#endif /* !_PATHS_H_ */
diff --git a/libc/sysdeps/unix/sysv/linux/poll.c b/libc/sysdeps/unix/sysv/linux/poll.c
new file mode 100644
index 000000000..a745fbcbc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/poll.c
@@ -0,0 +1,105 @@
+/* Poll system call, with emulation if it is not available.
+ Copyright (C) 1997,1998,1999,2000,2001,2002,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/poll.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if defined __NR_poll || __ASSUME_POLL_SYSCALL > 0
+
+# if __ASSUME_POLL_SYSCALL == 0
+static int __emulate_poll (struct pollfd *fds, nfds_t nfds,
+ int timeout) internal_function;
+# endif
+
+
+# if __ASSUME_POLL_SYSCALL == 0
+/* For loser kernels. */
+static int
+loser_poll (struct pollfd *fds, nfds_t nfds, int timeout)
+{
+ static int must_emulate;
+
+ if (!must_emulate)
+ {
+ int errno_saved = errno;
+ int retval = INLINE_SYSCALL (poll, 3, CHECK_N (fds, nfds), nfds,
+ timeout);
+
+ if (retval >= 0 || errno != ENOSYS)
+ return retval;
+
+ __set_errno (errno_saved);
+ must_emulate = 1;
+ }
+
+ return __emulate_poll (fds, nfds, timeout);
+}
+# endif
+
+
+/* The real implementation. */
+int
+__poll (fds, nfds, timeout)
+ struct pollfd *fds;
+ nfds_t nfds;
+ int timeout;
+{
+# if __ASSUME_POLL_SYSCALL == 0
+ if (SINGLE_THREAD_P)
+ return loser_poll (CHECK_N (fds, nfds), nfds, timeout);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = loser_poll (CHECK_N (fds, nfds), nfds, timeout);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+# else
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (poll, 3, CHECK_N (fds, nfds), nfds, timeout);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = INLINE_SYSCALL (poll, 3, CHECK_N (fds, nfds), nfds, timeout);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+# endif
+}
+libc_hidden_def (__poll)
+weak_alias (__poll, poll)
+strong_alias (__poll, __libc_poll)
+
+/* Get the emulation code. */
+# define __poll(fds, nfds, timeout) \
+ static internal_function __emulate_poll (fds, nfds, timeout)
+#endif
+
+#if __ASSUME_POLL_SYSCALL == 0
+# include <sysdeps/unix/bsd/poll.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/posix_fadvise.c b/libc/sysdeps/unix/sysv/linux/posix_fadvise.c
new file mode 100644
index 000000000..30a6d9e5b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/posix_fadvise.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <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)
+{
+#ifdef __NR_fadvise64
+ INTERNAL_SYSCALL_DECL (err);
+ int ret = INTERNAL_SYSCALL (fadvise64, err, 5, fd,
+ __LONG_LONG_PAIR (offset >> 31, offset), len,
+ advise);
+ if (INTERNAL_SYSCALL_ERROR_P (ret, err))
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+ return 0;
+#else
+ return ENOSYS;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/posix_fadvise64.c b/libc/sysdeps/unix/sysv/linux/posix_fadvise64.c
new file mode 100644
index 000000000..3555ae835
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/posix_fadvise64.c
@@ -0,0 +1,82 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+
+int __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise);
+int __posix_fadvise64_l32 (int fd, off64_t offset, size_t len, int advise);
+
+/* Advice the system about the expected behaviour of the application with
+ respect to the file associated with FD. */
+
+int
+__posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
+{
+#ifdef __NR_fadvise64_64
+ INTERNAL_SYSCALL_DECL (err);
+ int ret = INTERNAL_SYSCALL (fadvise64_64, err, 6, fd,
+ __LONG_LONG_PAIR ((long) (offset >> 32),
+ (long) offset),
+ __LONG_LONG_PAIR ((long) (len >> 32),
+ (long) len),
+ advise);
+ if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
+ return 0;
+# ifndef __ASSUME_FADVISE64_64_SYSCALL
+ if (INTERNAL_SYSCALL_ERRNO (ret, err) != ENOSYS)
+# endif
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+#endif
+#ifndef __ASSUME_FADVISE64_64_SYSCALL
+# ifdef __NR_fadvise64
+ if (len != (off_t) len)
+ return EOVERFLOW;
+
+ INTERNAL_SYSCALL_DECL (err2);
+ int ret2 = INTERNAL_SYSCALL (fadvise64, err2, 5, fd,
+ __LONG_LONG_PAIR ((long) (offset >> 32),
+ (long) offset),
+ (off_t) len, advise);
+ if (!INTERNAL_SYSCALL_ERROR_P (ret2, err2))
+ return 0;
+ return INTERNAL_SYSCALL_ERRNO (ret2, err2);
+# else
+ return ENOSYS;
+# endif
+#endif
+}
+
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT(libc, GLIBC_2_2, GLIBC_2_3_3)
+
+int
+attribute_compat_text_section
+__posix_fadvise64_l32 (int fd, off64_t offset, size_t len, int advise)
+{
+ return __posix_fadvise64_l64 (fd, offset, len, advise);
+}
+
+versioned_symbol (libc, __posix_fadvise64_l64, posix_fadvise64, GLIBC_2_3_3);
+compat_symbol (libc, __posix_fadvise64_l32, posix_fadvise64, GLIBC_2_2);
+#else
+strong_alias (__posix_fadvise64_l64, posix_fadvise64);
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/Implies b/libc/sysdeps/unix/sysv/linux/powerpc/Implies
new file mode 100644
index 000000000..ff27cdb56
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/Implies
@@ -0,0 +1,4 @@
+# Make sure these routines come before ldbl-opt.
+ieee754/ldbl-128ibm
+# These supply the ABI compatibility for when long double was double.
+ieee754/ldbl-opt
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/Makefile b/libc/sysdeps/unix/sysv/linux/powerpc/Makefile
new file mode 100644
index 000000000..ecd805795
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/Makefile
@@ -0,0 +1,12 @@
+64bit-predefine = __powerpc64__
+ifeq ($(subdir),rt)
+librt-routines += rt-sysdep
+endif
+
+ifeq ($(subdir),stdlib)
+gen-as-const-headers += ucontext_i.sym
+endif
+
+ifeq ($(subdir),elf)
+routines += dl-vdso
+endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/Versions b/libc/sysdeps/unix/sysv/linux/powerpc/Versions
new file mode 100644
index 000000000..1ef53b9e9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/Versions
@@ -0,0 +1,7 @@
+libc {
+ GLIBC_PRIVATE {
+ __vdso_get_tbfreq;
+ __vdso_clock_gettime;
+ __vdso_clock_getres;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-dirent.h b/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-dirent.h
new file mode 100644
index 000000000..c18e9fa4b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-dirent.h
@@ -0,0 +1,19 @@
+#include "aix-types.h"
+
+struct aixdirent
+ {
+ aixino_t d_ino;
+ aixoff_t d_off;
+ unsigned short int d_reclen;
+ unsigned short int d_namlen;
+ char d_name[256]; /* We must not include limits.h! */
+ };
+
+struct aixdirent64
+ {
+ aixino64_t d_ino;
+ aixoff64_t d_off;
+ unsigned short int d_reclen;
+ unsigned short int d_namlen;
+ char d_name[256]; /* We must not include limits.h! */
+ };
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-errno.h b/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-errno.h
new file mode 100644
index 000000000..0df33d4e9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-errno.h
@@ -0,0 +1,125 @@
+/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define AIX_EPERM 1
+#define AIX_ENOENT 2
+#define AIX_ESRCH 3
+#define AIX_EINTR 4
+#define AIX_EIO 5
+#define AIX_ENXIO 6
+#define AIX_E2BIG 7
+#define AIX_ENOEXEC 8
+#define AIX_EBADF 9
+#define AIX_ECHILD 10
+#define AIX_EAGAIN 11
+#define AIX_ENOMEM 12
+#define AIX_EACCES 13
+#define AIX_EFAULT 14
+#define AIX_ENOTBLK 15
+#define AIX_EBUSY 16
+#define AIX_EEXIST 17
+#define AIX_EXDEV 18
+#define AIX_ENODEV 19
+#define AIX_ENOTDIR 20
+#define AIX_EISDIR 21
+#define AIX_EINVAL 22
+#define AIX_ENFILE 23
+#define AIX_EMFILE 24
+#define AIX_ENOTTY 25
+#define AIX_ETXTBSY 26
+#define AIX_EFBIG 27
+#define AIX_ENOSPC 28
+#define AIX_ESPIPE 29
+#define AIX_EROFS 30
+#define AIX_EMLINK 31
+#define AIX_EPIPE 32
+#define AIX_EDOM 33
+#define AIX_ERANGE 34
+#define AIX_ENOMSG 35
+#define AIX_EIDRM 36
+#define AIX_ECHRNG 37
+#define AIX_EL2NSYNC 38
+#define AIX_EL3HLT 39
+#define AIX_EL3RST 40
+#define AIX_ELNRNG 41
+#define AIX_EUNATCH 42
+#define AIX_ENOCSI 43
+#define AIX_EL2HLT 44
+#define AIX_EDEADLK 45
+#define AIX_ENOTREADY 46
+#define AIX_EWRPROTECT 47
+#define AIX_EFORMAT 48
+#define AIX_ENOLCK 49
+#define AIX_ENOCONNECT 50
+#define AIX_ESTALE 52
+#define AIX_EDIST 53
+#define AIX_EWOULDBLOCK 54
+#define AIX_EINPROGRESS 55
+#define AIX_EALREADY 56
+#define AIX_ENOTSOCK 57
+#define AIX_EDESTADDRREQ 58
+#define AIX_EMSGSIZE 59
+#define AIX_EPROTOTYPE 60
+#define AIX_ENOPROTOOPT 61
+#define AIX_EPROTONOSUPPORT 62
+#define AIX_ESOCKTNOSUPPORT 63
+#define AIX_EOPNOTSUPP 64
+#define AIX_EPFNOSUPPORT 65
+#define AIX_EAFNOSUPPORT 66
+#define AIX_EADDRINUSE 67
+#define AIX_EADDRNOTAVAIL 68
+#define AIX_ENETDOWN 69
+#define AIX_ENETUNREACH 70
+#define AIX_ENETRESET 71
+#define AIX_ECONNABORTED 72
+#define AIX_ECONNRESET 73
+#define AIX_ENOBUFS 74
+#define AIX_EISCONN 75
+#define AIX_ENOTCONN 76
+#define AIX_ESHUTDOWN 77
+#define AIX_ETIMEDOUT 78
+#define AIX_ECONNREFUSED 79
+#define AIX_EHOSTDOWN 80
+#define AIX_EHOSTUNREACH 81
+#define AIX_ERESTART 82
+#define AIX_EPROCLIM 83
+#define AIX_EUSERS 84
+#define AIX_ELOOP 85
+#define AIX_ENAMETOOLONG 86
+#define AIX_EDQUOT 88
+#define AIX_ECORRUPT 89
+#define AIX_EREMOTE 93
+#define AIX_ENOSYS 109
+#define AIX_EMEDIA 110
+#define AIX_ESOFT 111
+#define AIX_ENOATTR 112
+#define AIX_ESAD 113
+#define AIX_ENOTRUST 114
+#define AIX_ETOOMANYREFS 115
+#define AIX_EILSEQ 116
+#define AIX_ECANCELED 117
+#define AIX_ENOSR 118
+#define AIX_ETIME 119
+#define AIX_EBADMSG 120
+#define AIX_EPROTO 121
+#define AIX_ENODATA 122
+#define AIX_ENOSTR 123
+#define AIX_ENOTSUP 124
+#define AIX_EMULTIHOP 125
+#define AIX_ENOLINK 126
+#define AIX_EOVERFLOW 127
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-stat.h b/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-stat.h
new file mode 100644
index 000000000..dc5ad5f73
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-stat.h
@@ -0,0 +1,76 @@
+/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+struct aixstat
+ {
+ aixdev_t st_dev;
+ aixino_t st_ino;
+ aixmode_t st_mode;
+ aixnlink_t st_nlink;
+ unsigned short int st_flag;
+ aixuid_t st_uid;
+ aixgid_t st_gid;
+ aixdev_t st_rdev;
+ aixoff_t st_size;
+ aixtime_t st_atime;
+ unsigned long int __unused1;
+ aixtime_t st_mtime;
+ unsigned long int __unused2;
+ aixtime_t st_ctime;
+ unsigned long int __unused3;
+ aixblksize_t st_blksize;
+ aixblkcnt_t st_blocks;
+ int st_vfstype;
+ unsigned int st_vfs;
+ unsigned int st_type;
+ unsigned int st_gen;
+
+#define _STATBUF_RESERVED_SPACE 9
+ unsigned int st_reserved[_STATBUF_RESERVED_SPACE];
+ };
+
+struct aixstat64
+ {
+ aixdev_t st_dev;
+ aixino64_t st_ino;
+ aixmode_t st_mode;
+ aixnlink_t st_nlink;
+ unsigned short int st_flag;
+ aixuid_t st_uid;
+ aixgid_t st_gid;
+ aixdev_t st_rdev;
+ int st_ssize;
+ aixtime_t st_atime;
+ unsigned long int __unused1;
+ aixtime_t st_mtime;
+ unsigned long int __unused2;
+ aixtime_t st_ctime;
+ unsigned long int __unused3;
+ aixblksize_t st_blksize;
+ aixblkcnt64_t st_blocks;
+ int st_vfstype;
+ unsigned int st_vfs;
+ unsigned int st_type;
+ unsigned int st_gen;
+ unsigned int st_reserved[_STATBUF_RESERVED_SPACE];
+ unsigned int st_padto_ll;
+ aixoff64_t st_size;
+ };
+
+#define aix_major(x) (int) ((unsigned int) (x) >> 16)
+#define aix_minor(x) (int) ((x) & 0xFFFF)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-termios.h b/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-termios.h
new file mode 100644
index 000000000..5f3e953ab
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/aix/aix-termios.h
@@ -0,0 +1,85 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include "aix-types.h"
+
+#define AIX_NCCS 16
+struct aixtermios
+{
+ aixtcflag_t c_iflag;
+ aixtcflag_t c_oflag;
+ aixtcflag_t c_cflag;
+ aixtcflag_t c_lflag;
+ aixcc_t c_line;
+ aixcc_t c_cc[AIX_NCCS];
+ aixspeed_t c_ispeed;
+ aixspeed_t c_ospeed;
+};
+
+#define AIX_VINTR 0
+#define AIX_VQUIT 1
+#define AIX_VERASE 2
+#define AIX_VKILL 3
+#define AIX_VEOF 4
+#define AIX_VEOL 5
+#define AIX_VEOL2 6
+#define AIX_VSTART 7
+#define AIX_VSTOP 8
+#define AIX_VSUSP 9
+#define AIX_VDSUSP 10
+#define AIX_VREPRINT 11
+#define AIX_VDISCRD 12
+#define AIX_VWERSE 13
+#define AIX_VLNEXT 14
+
+#define AIX_IUCLC 0x00000800
+#define AIX_IXANY 0x00001000
+#define AIX_IMAXBE 0x00010000
+
+#define AIX_OLCUC 0x00000002
+#define AIX_ONLCR 0x00000004
+#define AIX_TABDLY 0x00000c00
+#define AIX_TAB0 0x00000000
+#define AIX_TAB1 0x00000400
+#define AIX_TAB2 0x00000800
+#define AIX_TAB3 0x00000c00
+#define AIX_BSDLY 0x00001000
+#define AIX_BS0 0x00000000
+#define AIX_BS1 0x00001000
+#define AIX_FFDLY 0x00002000
+#define AIX_FF0 0x00000000
+#define AIX_FF1 0x00002000
+#define AIX_NLDLY 0x00004000
+#define AIX_NL0 0x00000000
+#define AIX_NL1 0x00004000
+#define AIX_VTDLY 0x00008000
+#define AIX_VT0 0x00000000
+#define AIX_VT1 0x00008000
+
+#define AIX_CBAUD 0x0000000f
+#define AIX_CSIZE 0x00000030
+#define AIX_CS5 0x00000000
+#define AIX_CS6 0x00000010
+#define AIX_CS7 0x00000020
+#define AIX_CS8 0x00000030
+#define AIX_CSTOPB 0x00000040
+#define AIX_CREAD 0x00000080
+#define AIX_PARENB 0x00000100
+#define AIX_PARODD 0x00000200
+#define AIX_HUPCL 0x00000400
+#define AIX_CLOCAL 0x00000800
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/aix/direntconv.c b/libc/sysdeps/unix/sysv/linux/powerpc/aix/direntconv.c
new file mode 100644
index 000000000..ff4041b7e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/aix/direntconv.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <dirent.h>
+#include <string.h>
+#include "linux-dirent.h"
+
+#ifndef DT_UNKNOWN
+# define DT_UNKNOWN 0
+#endif
+
+
+void
+__dirent_aix_to_linux (const struct aixdirent *aixdir,
+ struct dirent *linuxdir)
+{
+ linuxdir->d_ino = aixdir->d_ino;
+ linuxdir->d_off = aixdir->d_off;
+ linuxdir->d_reclen = aixdir->d_reclen;
+ linuxdir->d_type = DT_UNKNOWN;
+ memcpy (linuxdir->d_name, aixdir->d_name, aixdir->d_namlen + 1);
+}
+
+
+void
+__dirent64_aix_to_linux (const struct aixdirent64 *aixdir,
+ struct dirent64 *linuxdir)
+{
+ linuxdir->d_ino = aixdir->d_ino;
+ linuxdir->d_off = aixdir->d_off;
+ linuxdir->d_reclen = aixdir->d_reclen;
+ linuxdir->d_type = DT_UNKNOWN;
+ memcpy (linuxdir->d_name, aixdir->d_name, aixdir->d_namlen + 1);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/aix/errnoconv.c b/libc/sysdeps/unix/sysv/linux/powerpc/aix/errnoconv.c
new file mode 100644
index 000000000..efa0df786
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/aix/errnoconv.c
@@ -0,0 +1,143 @@
+/* Convert the error number the AIX kernel returns to what the Linux
+ application expects.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include "linux-errno.h"
+
+
+static int mapping[] =
+{
+ [AIX_EPERM] = EPERM,
+ [AIX_ENOENT] = ENOENT,
+ [AIX_ESRCH] = ESRCH,
+ [AIX_EINTR] = EINTR,
+ [AIX_EIO] = EIO,
+ [AIX_ENXIO] = ENXIO,
+ [AIX_E2BIG] = E2BIG,
+ [AIX_ENOEXEC] = ENOEXEC,
+ [AIX_EBADF] = EBADF,
+ [AIX_ECHILD] = ECHILD,
+ [AIX_EAGAIN] = EAGAIN,
+ [AIX_ENOMEM] = ENOMEM,
+ [AIX_EACCES] = EACCES,
+ [AIX_EFAULT] = EFAULT,
+ [AIX_ENOTBLK] = ENOTBLK,
+ [AIX_EBUSY] = EBUSY,
+ [AIX_EEXIST] = EEXIST,
+ [AIX_EXDEV] = EXDEV,
+ [AIX_ENODEV] = ENODEV,
+ [AIX_ENOTDIR] = ENOTDIR,
+ [AIX_EISDIR] = EISDIR,
+ [AIX_EINVAL] = EINVAL,
+ [AIX_ENFILE] = ENFILE,
+ [AIX_EMFILE] = EMFILE,
+ [AIX_ENOTTY] = ENOTTY,
+ [AIX_ETXTBSY] = ETXTBSY,
+ [AIX_EFBIG] = EFBIG,
+ [AIX_ENOSPC] = ENOSPC,
+ [AIX_EIDRM] = EIDRM,
+ [AIX_ECHRNG] = ECHRNG,
+ [AIX_EL2NSYNC] = EL2NSYNC,
+ [AIX_EL3HLT] = EL3HLT,
+ [AIX_EL3RST] = EL3RST,
+ [AIX_ELNRNG] = ELNRNG,
+ [AIX_EUNATCH] = EUNATCH,
+ [AIX_ENOCSI] = ENOCSI,
+ [AIX_EL2HLT] = EL2HLT,
+ [AIX_EDEADLK] = EDEADLK,
+ [AIX_ENOTREADY] = ENOTREADY,
+ // EWPROTECT: no Linux equivalent
+ // EFORMAT: no Linux equivalent
+ [AIX_ENOLCK] = ENOLCK,
+ // ENOCONNECT: No Linux equivalent
+ [AIX_ESTALE] = ESTALE,
+ // EDIST: no Linux equivalent
+ [54] = EAGAIN, // EWOULDBLOCK
+ [AIX_EINPROGRESS] = EINPROGRESS,
+ [AIX_EALREADY] = EALREADY,
+ [AIX_ENOTSOCK] = ENOTSOCK,
+ [AIX_EDESTADDRREQ] = EDESTADDRREQ,
+ [AIX_EMSGSIZE] = EMSGSIZE,
+ [AIX_EPROTOTYPE] = EPROTOTYPE,
+ [AIX_ENOPROTOOPT] = ENOPROTOOPT,
+ [AIX_EPROTONOSUPPORT] = EPROTONOSUPPORT,
+ [AIX_ESOCKTNOSUPPORT] = ESOCKTNOSUPPORT,
+ [AIX_EOPNOTSUPP] = EOPNOTSUPP,
+ [AIX_EPFNOSUPPORT] = EPFNOSUPPORT,
+ [AIX_EAFNOSUPPORT] = EAFNOSUPPORT,
+ [AIX_EADDRINUSE] = EADDRINUSE,
+ [AIX_EADDRNOTAVAIL] = EADDRNOTAVAIL,
+ [AIX_ENETDOWN] = ENETDOWN,
+ [AIX_ENETUNREACH] = ENETUNREACH,
+ [AIX_ENETRESET] = ENETRESET,
+ [AIX_ECONNABORTED] = ECONNABORTED,
+ [AIX_ECONNRESET] = ECONNRESET,
+ [AIX_ENOBUFS] = ENOBUFS,
+ [AIX_EISCONN] = EISCONN,
+ [AIX_ENOTCONN] = ENOTCONN,
+ [AIX_ESHUTDOWN] = ESHUTDOWN,
+ [AIX_ETIMEDOUT] = ETIMEDOUT,
+ [AIX_ECONNREFUSED] = ECONNREFUSED,
+ [AIX_EHOSTDOWN] = EHOSTDOWN,
+ [AIX_EHOSTUNREACH] = EHOSTUNREACH,
+ [AIX_ERESTART] = ERESTART,
+ [AIX_EPROCLIM] = EPROCLIM,
+ [AIX_EUSERS] = EUSERS,
+ [AIX_ELOOP] = ELOOP,
+ [AIX_ENAMETOOLONG] = ENAMETOOLONG,
+ [87] = ENOTEMPTY, // ENOTEMPTY
+ [AIX_EDQUOT] = EDQUOT,
+ [AIX_ECORRUPT] = ECORRUPT,
+ [AIX_EREMOTE] = EREMOTE,
+ [AIX_ENOSYS] = ENOSYS,
+ [AIX_EMEDIA] = EMEDIA,
+ [AIX_ESOFT] = ESOFT,
+ [AIX_ENOATTR] = ENOATTR,
+ [AIX_ESAD] = ESAD,
+ // ENOTRUST: no Linux equivalent
+ [AIX_ETOOMANYREFS] = ETOOMANYREFS,
+ [AIX_EILSEQ] = EILSEQ,
+ [AIX_ECANCELED] = ECANCELED,
+ [AIX_ENOSR] = ENOSR,
+ [AIX_ETIME] = ETIME,
+ [AIX_EBADMSG] = EBADMSG,
+ [AIX_EPROTO] = EPROTO,
+ [AIX_ENODATA] = ENODATA,
+ [AIX_ENOSTR] = ENOSTR,
+ [AIX_ENOTSUP] = ENOTSUP,
+ [AIX_EMULTIHOP] = EMULTIHOP,
+ [AIX_ENOLINK] = ENOLINK,
+ [AIX_EOVERFLOW] = EOVERFLOW
+};
+
+
+int
+__errno_aix_to_linux (int err)
+{
+ int conv;
+
+ if (err >= 0 && err < (sizeof (mapping) / sizeof (mapping[0]))
+ && ((conv = mapping[err]) != 0 || err == 0))
+ return conv;
+
+ /* The error value is not known. Create a special value which can
+ be easily recognized as an invalid result. */
+ return 512 + err;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/aix/statconv.c b/libc/sysdeps/unix/sysv/linux/powerpc/aix/statconv.c
new file mode 100644
index 000000000..0d7b5f780
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/aix/statconv.c
@@ -0,0 +1,53 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+void
+__stat_aix_to_linux (const struct aixstat *aixstat, struct stat *linuxstat)
+{
+ linuxstat->st_dev = makedev (aix_major (aixstat->st_dev),
+ aix_minor (aixstat->st_dev));
+ linuxstat->st_ino = aixstat->st_ino;
+ /* The following assumes that the mode values are the same on AIX
+ and Linux which is true in the moment. */
+ linuxstat->st_mode = aixstat->st_mode;
+ linuxstat->st_nlink = aixstat->st_nlink;
+ /* There is no st_flag field in Linux. */
+ linuxstat->st_uid = aixstat->st_uid;
+ linuxstat->st_gid = aixstat->st_gid;
+ linuxstat->st_rdev = makedev (aix_major (aixstat->st_rdev),
+ aix_minor (aixstat->st_rdev));
+ linuxstat->st_size = aixstat->st_size;
+ linuxstat->st_atime = aixstat->st_atime;
+ linuxstat->st_mtime = aixstat->st_mtime;
+ linuxstat->st_ctime = aixstat->st_ctime;
+ linuxstat->st_blksize = aixstat->st_blksize;
+ linuxstat->st_blocks = aixstat->st_blocks;
+ /* There is no st_vfstype in Linux. */
+ /* There is no st_vfs in Linux. */
+ /* There is no st_type in Linux. */
+ /* There is no st_gen in Linux. */
+
+ /* File in the padding values with repeatable values. */
+ linuxstat->__pad1 = 0;
+ linuxstat->__pad2 = 0;
+ linuxstat->__unused1 = 0;
+ linuxstat->__unused2 = 0;
+ linuxstat->__unused3 = 0;
+ linuxstat->__unused4 = 0;
+ linuxstat->__unused5 = 0;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/aix/tcgetattr.c b/libc/sysdeps/unix/sysv/linux/powerpc/aix/tcgetattr.c
new file mode 100644
index 000000000..c095c7c85
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/aix/tcgetattr.c
@@ -0,0 +1,156 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <termios.h>
+#include "aix-termios.h"
+
+int
+tcgetattr (fd, linuxtermios_p)
+ int fd;
+ struct termios *linuxtermios_p;
+{
+ struct aixtermios aixtermios;
+ int result;
+
+ result = /* make syscall */;
+
+ if (result != -1)
+ {
+ /* Convert the result. */
+
+ linuxtermios_p->c_cc[VINTR] = aixtermios.c_cc[AIX_VINTR];
+ linuxtermios_p->c_cc[VQUIT] = aixtermios.c_cc[AIX_VQUIT];
+ linuxtermios_p->c_cc[VERASE] = aixtermios.c_cc[AIX_VERASE];
+ linuxtermios_p->c_cc[VKILL] = aixtermios.c_cc[AIX_VKILL];
+ linuxtermios_p->c_cc[VEOF] = aixtermios.c_cc[AIX_VEOF];
+ // XXX VMIN has the same value as VEOF !?
+ linuxtermios_p->c_cc[VEOL] = aixtermios.c_cc[AIX_VEOL];
+ // XXX VTIME has the same value as VEOL !?
+ linuxtermios_p->c_cc[VEOL2] = aixtermios.c_cc[AIX_VEOL2];
+ linuxtermios_p->c_cc[VSTART] = aixtermios.c_cc[AIX_VSTART];
+ linuxtermios_p->c_cc[VSTOP] = aixtermios.c_cc[AIX_VSTOP];
+ linuxtermios_p->c_cc[VSUSP] = aixtermios.c_cc[AIX_VSUSP];
+ // XXX No Linux equivalent for VDSUSP !?
+ linuxtermios_p->c_cc[VREPRINT] = aixtermios.c_cc[AIX_VREPRINT];
+ linuxtermios_p->c_cc[VDISCARD] = aixtermios.c_cc[AIX_VDISCARD];
+ linuxtermios_p->c_cc[VWERASE] = aixtermios.c_cc[AIX_VWERASE];
+ linuxtermios_p->c_cc[VLNEXT] = aixtermios.c_cc[AIX_VLNEXT];
+
+ linuxtermios_p->c_cflag = aixtermios.c_c_flag & AIX_CBAUD;
+
+ /* Only the IUCLC, IXANY, and IMAXBEL values are different in the
+ c_iflag member. */
+ linuxtermios_p->c_iflag = aixtermios.c_iflag & 0x7ff;
+ if (aixtermios.c_iflag & AIX_IXANY)
+ linuxtermios_p->c_iflag |= IXANY;
+ if (aixtermios.c_iflag & AIX_IUCLC)
+ linuxtermios_p->c_iflag |= IUCLC;
+ if (aixtermios.c_iflag & AIX_IMAXBEL)
+ linuxtermios_p->c_iflag |= IMAXBEL;
+
+ /* Many of the c_oflag files differ. Bummer. */
+ linuxtermios_p->c_oflag = (aixtermios.c_oflag
+ & (OPOST | OCRNL | ONOCR | ONLRET | OFILL
+ | OFDEL | TABDLY));
+ if (aixtermios.c_oflag & AIX_OLCUC)
+ linuxtermios_p->c_oflag |= OLCUC;
+ if (aixtermios.c_oflag & AIX_ONLCR)
+ linuxtermios_p->c_oflag |= ONLCR;
+ if (aixtermiosc_oflag & AIX_NLDLY)
+ linuxtermios_p->c_oflag |= NL1;
+
+ if (aixtermiosc_oflag.c_oflag & AIX_TABDLY)
+ {
+#define offset 2
+#if AIX_TAB1 << offset != TAB1 || AIX_TAB3 << offset != TAB3
+# error "Check the offset"
+#endif
+ linuxtermios_p->c_oflag |= (aixtermios.c_oflag >> offset) & TABDLY;
+#undef offset
+ }
+ if (aixtermios.c_oflag & AIX_FFDLY)
+ linuxtermios_p->c_oflag |= FF1;
+ if (aixtermios.c_oflag & AIX_BSDLY)
+ linuxtermios_p->c_oflag |= BS1;
+ if (aixtermios.c_oflag & AIX_VTDLY)
+ linuxtermios_p->c_oflag |= VT1;
+
+ /* A lot of the c_cflag member is also different. */
+ if (aixtermios.c_cflag & AIX_CSIZE)
+ {
+#define offset 4
+#if CSIZE >> offset != AIX_CSIZE
+# error "Check the offset"
+#endif
+ linuxtermios_p->c_cflag |= (aixtermios.c_cflag >> offset) & CSIZE;
+#undef offset
+ }
+
+ if (aixtermios.c_cflag & AIX_STOPB)
+ linuxtermios_p->c_cflag |= STOPB;
+ if (aixtermios.c_cflag & AIX_CREAD)
+ linuxtermios_p->c_cflag |= CREAD;
+ if (aixtermios.cflag & AIX_PARENB)
+ linuxtermios_p->c_cflag |= PARENB;
+ if (aixtermios.cflag & AIX_PARODD)
+ linuxtermios_p->c_cflag |= PARODD;
+ if (aixtermios.c_cflag & AIX_HUPCL)
+ linuxtermios_p->c_cflag |= HUPCL;
+ if (aixtermios.c_cflag & AIX_CLOCAL)
+ linuxtermios_p->c_cflag |= CLOCAL;
+
+ /* The c_lflag is information is also different. */
+ aixtermios.c_lflag = 0;
+ if (aixtermios.c_lflag & AIX_ISIG)
+ linuxtermios_p->c_lflag |= ISIG;
+ if (aixtermios.c_lflag & AIX_ICANON)
+ linuxtermios_p->c_lflag |= ICANON;
+ if (aixtermios.c_lflag & AIX_XCASE)
+ linuxtermios_p->c_lflag |= XCASE;
+ if (aixtermios.c_lflag & AIX_ECHO)
+ linuxtermios_p->c_lflag |= ECHO;
+ if (aixtermios.c_lflag & AIX_ECHOE)
+ linuxtermios_p->c_lflag |= ECHOE;
+ if (aixtermios.c_lflag & AIX_ECHOK)
+ linuxtermios_p->c_lflag |= ECHOK;
+ if (aixtermios.c_lflag & AIX_ECHONL)
+ linuxtermios_p->c_lflag |= ECHONL;
+ if (aixtermios.c_lflag & AIX_NOFLSH)
+ linuxtermios_p->c_lflag |= NOFLSH;
+ if (aixtermios.c_lflag & AIX_TOSTOP)
+ linuxtermios_p->c_lflag |= TOSTOP;
+ if (aixtermios.c_lflag & AIX_ECHOCTL)
+ linuxtermios_p->c_lflag |= ECHOCTL;
+ if (aixtermios.c_lflag & AIX_ECHOPRT)
+ linuxtermios_p->c_lflag |= ECHOPRT;
+ if (aixtermios.c_lflag & AIX_ECHOKE)
+ linuxtermios_p->c_lflag |= ECHOKE;
+ if (aixtermios.c_lflag & AIX_FLUSHO)
+ linuxtermios_p->c_lflag |= FLUSHO;
+ if (aixtermios.c_lflag & AIX_PENDIN)
+ linuxtermios_p->c_lflag |= PENDIN;
+ if (aixtermios->c_lflag & AIX_IEXTEN)
+ linuxtermios_p->c_lflag |= IEXTEN;
+ }
+ else
+ // Convert error here or in syscall.
+ ;
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/aix/tcsetattr.c b/libc/sysdeps/unix/sysv/linux/powerpc/aix/tcsetattr.c
new file mode 100644
index 000000000..3f9d29808
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/aix/tcsetattr.c
@@ -0,0 +1,171 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <termios.h>
+#include "aix-termios.h"
+
+int
+tcsetattr (fd, optional_actions, linuxtermios_p)
+ int fd;
+ int optional_actions;
+ const struct termios *linuxtermios_p;
+{
+ struct aixtermios aixtermios;
+ int result;
+
+ /* `optional_actions' does not have to be changed, AIX uses the
+ same values as Linux. */
+
+ aixtermios.c_cc[AIX_VINTR] = linuxtermios_p->c_cc[VINTR];
+ aixtermios.c_cc[AIX_VQUIT] = linuxtermios_p->c_cc[VQUIT];
+ aixtermios.c_cc[AIX_VERASE] = linuxtermios_p->c_cc[VERASE];
+ aixtermios.c_cc[AIX_VKILL] = linuxtermios_p->c_cc[VKILL];
+ aixtermios.c_cc[AIX_VEOF] = linuxtermios_p->c_cc[VEOF];
+ // XXX VMIN has the same value as VEOF !?
+ aixtermios.c_cc[AIX_VEOL] = linuxtermios_p->c_cc[VEOL];
+ // XXX VTIME has the same value as VEOL !?
+ aixtermios.c_cc[AIX_VEOL2] = linuxtermios_p->c_cc[VEOL2];
+ aixtermios.c_cc[AIX_VSTART] = linuxtermios_p->c_cc[VSTART];
+ aixtermios.c_cc[AIX_VSTOP] = linuxtermios_p->c_cc[VSTOP];
+ aixtermios.c_cc[AIX_VSUSP] = linuxtermios_p->c_cc[VSUSP];
+ aixtermios.c_cc[AIX_VDSUSP] = 0; // XXX No Linux equivalent !?
+ aixtermios.c_cc[AIX_VREPRINT] = linuxtermios_p->c_cc[VREPRINT];
+ aixtermios.c_cc[AIX_VDISCARD] = linuxtermios_p->c_cc[VDISCARD];
+ aixtermios.c_cc[AIX_VWERASE] = linuxtermios_p->c_cc[VWERASE];
+ aixtermios.c_cc[AIX_VLNEXT] = linuxtermios_p->c_cc[VLNEXT];
+
+ /* AIX has not all the speeds (the high one) Linux supports. The
+ symbol names and values used for the speeds are fortunately the
+ same. */
+ if ((linuxtermios_p->c_cflag & CBAUD) > B38400)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ aixtermios.c_c_flag = linuxtermios_p->c_cflag & CBAUD;
+
+ /* Only the IUCLC, IXANY, and IMAXBEL values are different in the
+ c_iflag member. */
+ aixtermios.c_iflag = linuxtermios_p->c_iflag & 0x7ff;
+ if (linuxtermios_p->c_iflag & IXANY)
+ aixtermios.c_iflag |= AIX_IXANY;
+ if (linuxtermios_p->c_iflag & IUCLC)
+ aixtermios.c_iflag |= AIX_IUCLC;
+ if (linuxtermios_p->c_iflag & IMAXBEL)
+ aixtermios.c_iflag |= AIX_IMAXBEL;
+
+ /* Many of the c_oflag files differ. Bummer. */
+ aixtermios.c_oflag = (linuxtermios_p->c_oflag
+ & (OPOST | OCRNL | ONOCR | ONLRET | OFILL
+ | OFDEL | TABDLY));
+ if (linuxtermios_p->c_oflag & OLCUC)
+ aixtermios.c_oflag |= AIX_OLCUC;
+ if (linuxtermios_p->c_oflag & ONLCR)
+ aixtermios.c_oflag |= AIX_ONLCR;
+ if (linuxtermios_p->c_oflag & NLDLY)
+ {
+ if ((linuxtermios_p->c_oflag & NLDLY) >= NL2)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (linuxtermios_p->c_oflag & NLDLY)
+ aixtermios.c_oflag |= AIX_NL1;
+ }
+ if (linuxtermios_p->c_oflag & TABDLY)
+ {
+#define offset 2
+#if TAB1 >> offset != AIX_TAB1 || TAB3 >> offset != AIX_TAB3
+# error "Check the offset"
+#endif
+ aixtermios.c_oflag |= (linuxtermios_p->c_oflag >> offset) & AIX_TABDLY;
+#undef offset
+ }
+ if (linuxtermios_p->c_oflag & FFDLY)
+ aixtermios.c_oflag |= AIX_FF1;
+ if (linuxtermios_p->c_oflag & BSDLY)
+ aixtermios.c_oflag |= AIX_BS1;
+ if (linuxtermios_p->c_oflag & VTDLY)
+ aixtermios.c_oflag |= AIX_VT1;
+
+ /* A lot of the c_cflag member is also different. */
+ if (linuxtermios_p->c_cflag & CSIZE)
+ {
+#define offset 4
+#if CSIZE >> offset != AIX_CSIZE
+# error "Check the offset"
+#endif
+ aixtermios.c_cflag |= (linuxtermios_p->c_cflag >> offset) & AIX_CSIZE;
+#undef offset
+ }
+
+ if (linuxtermios_p->c_cflag & STOPB)
+ aixtermios.c_cflag |= AIX_STOPB;
+ if (linuxtermios_p->c_cflag & CREAD)
+ aixtermios.c_cflag |= AIX_CREAD;
+ if (linuxtermios_p->c_cflag & PARENB)
+ aixtermios.c_cflag |= AIX_PARENB;
+ if (linuxtermios_p->c_cflag & PARODD)
+ aixtermios.c_cflag |= AIX_PARODD;
+ if (linuxtermios_p->c_cflag & HUPCL)
+ aixtermios.c_cflag |= AIX_HUPCL;
+ if (linuxtermios_p->c_cflag & CLOCAL)
+ aixtermios.c_cflag |= AIX_CLOCAL;
+
+ /* The c_lflag is information is also different. */
+ aixtermios.c_lflag = 0;
+ if (linuxtermios_p->c_lflag & ISIG)
+ aixtermios.c_lflag |= AIX_ISIG;
+ if (linuxtermios_p->c_lflag & ICANON)
+ aixtermios.c_lflag |= AIX_ICANON;
+ if (linuxtermios_p->c_lflag & XCASE)
+ aixtermios.c_lflag |= AIX_XCASE;
+ if (linuxtermios_p->c_lflag & ECHO)
+ aixtermios.c_lflag |= AIX_ECHO;
+ if (linuxtermios_p->c_lflag & ECHOE)
+ aixtermios.c_lflag |= AIX_ECHOE;
+ if (linuxtermios_p->c_lflag & ECHOK)
+ aixtermios.c_lflag |= AIX_ECHOK;
+ if (linuxtermios_p->c_lflag & ECHONL)
+ aixtermios.c_lflag |= AIX_ECHONL;
+ if (linuxtermios_p->c_lflag & NOFLSH)
+ aixtermios.c_lflag |= AIX_NOFLSH;
+ if (linuxtermios_p->c_lflag & TOSTOP)
+ aixtermios.c_lflag |= AIX_TOSTOP;
+ if (linuxtermios_p->c_lflag & ECHOCTL)
+ aixtermios.c_lflag |= AIX_ECHOCTL;
+ if (linuxtermios_p->c_lflag & ECHOPRT)
+ aixtermios.c_lflag |= AIX_ECHOPRT;
+ if (linuxtermios_p->c_lflag & ECHOKE)
+ aixtermios.c_lflag |= AIX_ECHOKE;
+ if (linuxtermios_p->c_lflag & FLUSHO)
+ aixtermios.c_lflag |= AIX_FLUSHO;
+ if (linuxtermios_p->c_lflag & PENDIN)
+ aixtermios.c_lflag |= AIX_PENDIN;
+ if (linuxtermios_p->c_lflag & IEXTEN)
+ aixtermios.c_lflag |= AIX_IEXTEN;
+
+ result = /* XXX syscall */;
+
+ // Convert error here or in syscall.
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/environments.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/environments.h
new file mode 100644
index 000000000..a51a564cb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/environments.h
@@ -0,0 +1,87 @@
+/* Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _UNISTD_H
+# error "Never include this file directly. Use <unistd.h> instead"
+#endif
+
+#include <bits/wordsize.h>
+
+/* This header should define the following symbols under the described
+ situations. A value `1' means that the model is always supported,
+ `-1' means it is never supported. Undefined means it cannot be
+ statically decided.
+
+ _POSIX_V6_ILP32_OFF32 32bit int, long, pointers, and off_t type
+ _POSIX_V6_ILP32_OFFBIG 32bit int, long, and pointers and larger off_t type
+
+ _POSIX_V6_LP64_OFF32 64bit long and pointers and 32bit off_t type
+ _POSIX_V6_LPBIG_OFFBIG 64bit long and pointers and large off_t type
+
+ The macros _XBS5_ILP32_OFF32, _XBS5_ILP32_OFFBIG, _XBS5_LP64_OFF32, and
+ _XBS5_LPBIG_OFFBIG were used in previous versions of the Unix standard
+ and are available only for compatibility.
+*/
+
+#if __WORDSIZE == 64
+
+/* Environments with 32-bit wide pointers are optionally provided.
+ Therefore following macros aren't defined:
+ # undef _POSIX_V6_ILP32_OFF32
+ # undef _POSIX_V6_ILP32_OFFBIG
+ # undef _XBS5_ILP32_OFF32
+ # undef _XBS5_ILP32_OFFBIG
+ and users need to check at runtime. */
+
+/* We also have no use (for now) for an environment with bigger pointers
+ and offsets. */
+# define _POSIX_V6_LPBIG_OFFBIG -1
+# define _XBS5_LPBIG_OFFBIG -1
+
+/* By default we have 64-bit wide `long int', pointers and `off_t'. */
+# define _POSIX_V6_LP64_OFF64 1
+# define _XBS5_LP64_OFF64 1
+
+#else /* __WORDSIZE == 32 */
+
+/* By default we have 32-bit wide `int', `long int', pointers and `off_t'
+ and all platforms support LFS. */
+# define _POSIX_V6_ILP32_OFF32 1
+# define _POSIX_V6_ILP32_OFFBIG 1
+# define _XBS5_ILP32_OFF32 1
+# define _XBS5_ILP32_OFFBIG 1
+
+/* We optionally provide an environment with the above size but an 64-bit
+ side `off_t'. Therefore we don't define _XBS5_ILP32_OFFBIG. */
+
+/* Environments with 64-bit wide pointers can be provided,
+ so these macros aren't defined:
+ # undef _POSIX_V6_LP64_OFF64
+ # undef _POSIX_V6_LPBIG_OFFBIG
+ # undef _XBS5_LP64_OFF64
+ # undef _XBS5_LPBIG_OFFBIG
+ and sysconf tests for it at runtime. */
+
+#endif /* __WORDSIZE == 32 */
+
+#define __ILP32_OFF32_CFLAGS "-m32"
+#define __ILP32_OFFBIG_CFLAGS "-m32 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+#define __ILP32_OFF32_LDFLAGS "-m32"
+#define __ILP32_OFFBIG_LDFLAGS "-m32"
+#define __LP64_OFF64_CFLAGS "-m64"
+#define __LP64_OFF64_LDFLAGS "-m64"
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/fcntl.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/fcntl.h
new file mode 100644
index 000000000..57fc7bd98
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/fcntl.h
@@ -0,0 +1,236 @@
+/* O_*, F_*, FD_* bit values for Linux/PowerPC.
+ Copyright (C) 1995, 1996, 1997, 1998, 2000, 2003, 2004, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <sys/types.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+
+
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on an ext2 file system */
+#define O_ACCMODE 0003
+#define O_RDONLY 00
+#define O_WRONLY 01
+#define O_RDWR 02
+#define O_CREAT 0100 /* not fcntl */
+#define O_EXCL 0200 /* not fcntl */
+#define O_NOCTTY 0400 /* not fcntl */
+#define O_TRUNC 01000 /* not fcntl */
+#define O_APPEND 02000
+#define O_NONBLOCK 04000
+#define O_NDELAY O_NONBLOCK
+#define O_SYNC 010000
+#define O_FSYNC O_SYNC
+#define O_ASYNC 020000
+
+#ifdef __USE_GNU
+# define O_DIRECT 0400000 /* Direct disk access. */
+# define O_DIRECTORY 040000 /* Must be a directory. */
+# define O_NOFOLLOW 0100000 /* Do not follow links. */
+# define O_NOATIME 01000000 /* Do not set atime. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+# define O_LARGEFILE 0200000
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#ifndef __USE_FILE_OFFSET64
+# define F_GETLK 5 /* Get record locking info. */
+# define F_SETLK 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW 7 /* Set record locking info (blocking). */
+#else
+# define F_GETLK F_GETLK64 /* Get record locking info. */
+# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
+# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
+#endif
+#define F_GETLK64 12 /* Get record locking info. */
+#define F_SETLK64 13 /* Set record locking info (non-blocking). */
+#define F_SETLKW64 14 /* Set record locking info (blocking). */
+
+#if defined __USE_BSD || defined __USE_UNIX98
+# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */
+# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+#endif
+
+/* For F_[GET|SET]FD. */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
+#define F_RDLCK 0 /* Read lock. */
+#define F_WRLCK 1 /* Write lock. */
+#define F_UNLCK 2 /* Remove lock. */
+
+/* For old implementation of bsd flock(). */
+#define F_EXLCK 4 /* or 3 */
+#define F_SHLCK 8 /* or 4 */
+
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation. */
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#endif
+
+struct flock
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+#ifndef __USE_FILE_OFFSET64
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+#else
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+#endif
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+
+#ifdef __USE_LARGEFILE64
+struct flock64
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+#endif
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+#endif
+
+
+#ifdef __USE_GNU
+/* Flags for SYNC_FILE_RANGE. */
+# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
+ in the range before performing the
+ write. */
+# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
+ dirty pages in the range which are
+ not presently under writeback. */
+# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
+ the range after performing the
+ write. */
+
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+#endif
+
+__BEGIN_DECLS
+
+#ifdef __USE_GNU
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+
+/* Selective file content synch'ing. */
+extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
+ unsigned int __flags);
+
+
+/* Splice address range into a pipe. */
+extern int vmsplice (int __fdout, const struct iovec *__iov, size_t __count,
+ unsigned int __flags);
+
+/* Splice two files together. */
+extern int splice (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+/* In-kernel implementation of tee for pipe buffers. */
+extern int tee (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+#endif
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/ioctl-types.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/ioctl-types.h
new file mode 100644
index 000000000..87b8265af
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/ioctl-types.h
@@ -0,0 +1,5 @@
+#ifndef _SYS_IOCTL_H
+# error "Never use <bits/ioctl-types.h> directly; include <sys/ioctl.h> instead."
+#endif
+
+#include <termios.h>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/ipc.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/ipc.h
new file mode 100644
index 000000000..1ba99347c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/ipc.h
@@ -0,0 +1,79 @@
+/* Copyright (C) 1995-1999, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IPC_H
+# error "Never use <bits/ipc.h> directly; include <sys/ipc.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Mode bits for `msgget', `semget', and `shmget'. */
+#define IPC_CREAT 01000 /* Create key if key does not exist. */
+#define IPC_EXCL 02000 /* Fail if key exists. */
+#define IPC_NOWAIT 04000 /* Return error on wait. */
+
+/* Control commands for `msgctl', `semctl', and `shmctl'. */
+#define IPC_RMID 0 /* Remove identifier. */
+#define IPC_SET 1 /* Set `ipc_perm' options. */
+#define IPC_STAT 2 /* Get `ipc_perm' options. */
+#ifdef __USE_GNU
+# define IPC_INFO 3 /* See ipcs. */
+#endif
+
+/* Special key values. */
+#define IPC_PRIVATE ((__key_t) 0) /* Private key. */
+
+
+/* Data structure used to pass permission information to IPC operations. */
+struct ipc_perm
+ {
+ __key_t __key; /* Key. */
+ __uid_t uid; /* Owner's user ID. */
+ __gid_t gid; /* Owner's group ID. */
+ __uid_t cuid; /* Creator's user ID. */
+ __gid_t cgid; /* Creator's group ID. */
+ __mode_t mode; /* Read/write permission. */
+ __uint32_t __seq; /* Sequence number. */
+ __uint32_t __pad1;
+ __uint64_t __unused1;
+ __uint64_t __unused2;
+ };
+
+
+__BEGIN_DECLS
+
+/* The actual system call: all functions are multiplexed by this. */
+extern int __ipc (int __call, int __first, int __second, int __third,
+ void *__ptr) __THROW;
+
+__END_DECLS
+
+#ifdef __USE_GNU
+/* The codes for the functions to use the multiplexer `__ipc'. */
+# define IPCOP_semop 1
+# define IPCOP_semget 2
+# define IPCOP_semctl 3
+# define IPCOP_msgsnd 11
+# define IPCOP_msgrcv 12
+# define IPCOP_msgget 13
+# define IPCOP_msgctl 14
+# define IPCOP_shmat 21
+# define IPCOP_shmdt 22
+# define IPCOP_shmget 23
+# define IPCOP_shmctl 24
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
new file mode 100644
index 000000000..f20a5a175
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
@@ -0,0 +1,36 @@
+/* Resolve function pointers to VDSO functions.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+#ifndef _LIBC_VDSO_H
+#define _LIBC_VDSO_H
+
+#ifdef SHARED
+
+extern void *__vdso_gettimeofday;
+
+extern void *__vdso_clock_gettime;
+
+extern void *__vdso_clock_getres;
+
+extern void *__vdso_get_tbfreq;
+
+#endif
+
+#endif /* _LIBC_VDSO_H */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/mman.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/mman.h
new file mode 100644
index 000000000..e03ab7ff8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/mman.h
@@ -0,0 +1,104 @@
+/* Definitions for POSIX memory map interface. Linux/PowerPC version.
+ Copyright (C) 1997, 2000, 2003, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MMAN_H
+# error "Never use <bits/mman.h> directly; iclude <sys/mman.h> instead."
+#endif
+
+/* The following definitions basically come from the kernel headers.
+ But the kernel header is not namespace clean. */
+
+
+/* Protections are chosen from these bits, OR'd together. The
+ implementation does not necessarily support PROT_EXEC or PROT_WRITE
+ without PROT_READ. The only guarantees are that no writing will be
+ allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
+
+#define PROT_READ 0x1 /* Page can be read. */
+#define PROT_WRITE 0x2 /* Page can be written. */
+#define PROT_EXEC 0x4 /* Page can be executed. */
+#define PROT_NONE 0x0 /* Page can not be accessed. */
+#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
+ growsdown vma (mprotect only). */
+#define PROT_GROWSUP 0x02000000 /* Extend change to start of
+ growsup vma (mprotect only). */
+
+/* Sharing types (must choose one and only one of these). */
+#define MAP_SHARED 0x001 /* Share changes. */
+#define MAP_PRIVATE 0x002 /* Changes are private. */
+#ifdef __USE_MISC
+# define MAP_TYPE 0x00f /* Mask for type of mapping. */
+#endif
+
+/* Other flags. */
+#define MAP_FIXED 0x010 /* Interpret addr exactly. */
+#ifdef __USE_MISC
+# define MAP_FILE 0x000
+# define MAP_ANONYMOUS 0x020 /* Don't use a file. */
+# define MAP_ANON MAP_ANONYMOUS
+#endif
+
+/* These are Linux-specific. */
+#ifdef __USE_MISC
+# define MAP_GROWSDOWN 0x00100 /* Stack-like segment. */
+# define MAP_DENYWRITE 0x00800 /* ETXTBSY */
+# define MAP_EXECUTABLE 0x01000 /* Mark it as an executable. */
+# define MAP_LOCKED 0x00080 /* Lock the mapping. */
+# define MAP_NORESERVE 0x00040 /* Don't check for reservations. */
+# define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */
+# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
+#endif
+
+/* Flags to `msync'. */
+#define MS_ASYNC 1 /* Sync memory asynchronously. */
+#define MS_SYNC 4 /* Synchronous memory sync. */
+#define MS_INVALIDATE 2 /* Invalidate the caches. */
+
+/* Flags for `mlockall'. */
+#define MCL_CURRENT 0x2000 /* Lock all currently mapped pages. */
+#define MCL_FUTURE 0x4000 /* Lock all additions to address
+ space. */
+
+
+/* Flags for `mremap'. */
+#ifdef __USE_GNU
+# define MREMAP_MAYMOVE 1
+# define MREMAP_FIXED 2
+#endif
+
+/* Advice to `madvise'. */
+#ifdef __USE_BSD
+# define MADV_NORMAL 0 /* No further special treatment. */
+# define MADV_RANDOM 1 /* Expect random page references. */
+# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define MADV_WILLNEED 3 /* Will need these pages. */
+# define MADV_DONTNEED 4 /* Don't need these pages. */
+# define MADV_REMOVE 9 /* Remove these pages and resources. */
+# define MADV_DONTFORK 10 /* Do not inherit across fork. */
+# define MADV_DOFORK 11 /* Do inherit across fork. */
+#endif
+
+/* The POSIX people had to invent similar names for the same things. */
+#ifdef __USE_XOPEN2K
+# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/msq.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/msq.h
new file mode 100644
index 000000000..f19884437
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/msq.h
@@ -0,0 +1,83 @@
+/* Copyright (C) 1995, 1996, 1997, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MSG_H
+# error "Never use <bits/msq.h> directly; include <sys/msg.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Define options for message queue functions. */
+#define MSG_NOERROR 010000 /* no error if message is too big */
+#ifdef __USE_GNU
+# define MSG_EXCEPT 020000 /* recv any msg except of specified type */
+#endif
+
+/* Types used in the structure definition. */
+typedef unsigned long int msgqnum_t;
+typedef unsigned long int msglen_t;
+
+
+/* Structure of record for one message inside the kernel.
+ The type `struct msg' is opaque. */
+struct msqid_ds
+{
+ struct ipc_perm msg_perm; /* structure describing operation permission */
+#if __WORDSIZE == 32
+ unsigned int __unused1;
+#endif
+ __time_t msg_stime; /* time of last msgsnd command */
+#if __WORDSIZE == 32
+ unsigned int __unused2;
+#endif
+ __time_t msg_rtime; /* time of last msgrcv command */
+#if __WORDSIZE == 32
+ unsigned int __unused3;
+#endif
+ __time_t msg_ctime; /* time of last change */
+ unsigned long __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 __unused4;
+ unsigned long __unused5;
+};
+
+#ifdef __USE_MISC
+
+# define msg_cbytes __msg_cbytes
+
+/* ipcs ctl commands */
+# define MSG_STAT 11
+# define MSG_INFO 12
+
+/* buffer for msgctl calls IPC_INFO, MSG_INFO */
+struct msginfo
+ {
+ int msgpool;
+ int msgmap;
+ int msgmax;
+ int msgmnb;
+ int msgmni;
+ int msgssz;
+ int msgtql;
+ unsigned short int msgseg;
+ };
+
+#endif /* __USE_MISC */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/sem.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/sem.h
new file mode 100644
index 000000000..1c648cd19
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/sem.h
@@ -0,0 +1,92 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SEM_H
+# error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
+#endif
+
+#include <sys/types.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 */
+#if __WORDSIZE == 32
+ unsigned int __unused1;
+#endif
+ __time_t sem_otime; /* last semop() time */
+#if __WORDSIZE == 32
+ unsigned int __unused2;
+#endif
+ __time_t sem_ctime; /* last time changed by semctl() */
+ unsigned long int sem_nsems; /* number of semaphores in set */
+ unsigned long __unused3;
+ unsigned long __unused4;
+};
+
+/* The user should define a union like the following to use it for arguments
+ for `semctl'.
+
+ union semun
+ {
+ int val; <= value for SETVAL
+ struct semid_ds *buf; <= buffer for IPC_STAT & IPC_SET
+ unsigned short int *array; <= array for GETALL & SETALL
+ struct seminfo *__buf; <= buffer for IPC_INFO
+ };
+
+ Previous versions of this file used to define this union but this is
+ incorrect. One can test the macro _SEM_SEMUN_UNDEFINED to see whether
+ one must define the union or not. */
+#define _SEM_SEMUN_UNDEFINED 1
+
+#ifdef __USE_MISC
+
+/* ipcs ctl cmds */
+# define SEM_STAT 18
+# define SEM_INFO 19
+
+struct seminfo
+{
+ int semmap;
+ int semmni;
+ int semmns;
+ int semmnu;
+ int semmsl;
+ int semopm;
+ int semume;
+ int semusz;
+ int semvmx;
+ int semaem;
+};
+
+#endif /* __USE_MISC */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/shm.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/shm.h
new file mode 100644
index 000000000..62560c0ca
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/shm.h
@@ -0,0 +1,113 @@
+/* Copyright (C) 1995, 1996, 1997, 2000, 2002, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SHM_H
+# error "Never include <bits/shm.h> directly; use <sys/shm.h> instead."
+#endif
+
+#include <bits/types.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 */
+
+/* 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 set of semaphores. */
+struct shmid_ds
+ {
+ struct ipc_perm shm_perm; /* operation permission struct */
+#if __WORDSIZE == 32
+ unsigned int __unused1;
+#endif
+ __time_t shm_atime; /* time of last shmat() */
+#if __WORDSIZE == 32
+ unsigned int __unused2;
+#endif
+ __time_t shm_dtime; /* time of last shmdt() */
+#if __WORDSIZE == 32
+ unsigned int __unused3;
+#endif
+ __time_t shm_ctime; /* time of last change by shmctl() */
+#if __WORDSIZE == 32
+ unsigned int __unused4;
+#endif
+ size_t shm_segsz; /* size of segment in bytes */
+ __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 __unused5;
+ unsigned long __unused6;
+ };
+
+#ifdef __USE_MISC
+
+/* ipcs ctl commands */
+# define SHM_STAT 13
+# define SHM_INFO 14
+
+/* shm_mode upper byte flags */
+# define SHM_DEST 01000 /* segment will be destroyed on last detach */
+# define SHM_LOCKED 02000 /* segment will not be swapped */
+# define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */
+# define SHM_NORESERVE 010000 /* don't check for reservations */
+
+struct shminfo
+ {
+ unsigned long int shmmax;
+ unsigned long int shmmin;
+ unsigned long int shmmni;
+ unsigned long int shmseg;
+ unsigned long int shmall;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+ };
+
+struct shm_info
+ {
+ int used_ids;
+ unsigned long int shm_tot; /* total allocated shm */
+ unsigned long int shm_rss; /* total resident shm */
+ unsigned long int shm_swp; /* total swapped shm */
+ unsigned long int swap_attempts;
+ unsigned long int swap_successes;
+ };
+
+#endif /* __USE_MISC */
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/stat.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/stat.h
new file mode 100644
index 000000000..b020504d0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/stat.h
@@ -0,0 +1,267 @@
+/* Copyright (C) 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STAT_H
+# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+/* Versions of the `struct stat' data structure. */
+#define _STAT_VER_LINUX_OLD 1
+#define _STAT_VER_KERNEL 1
+#define _STAT_VER_SVR4 2
+#define _STAT_VER_LINUX 3
+#if __WORDSIZE == 32
+# define _STAT_VER _STAT_VER_LINUX
+#else
+# define _STAT_VER _STAT_VER_KERNEL
+#endif
+
+/* Versions of the `xmknod' interface. */
+#define _MKNOD_VER_LINUX 1
+#define _MKNOD_VER_SVR4 2
+#define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
+
+
+#if __WORDSIZE == 32
+
+struct stat
+ {
+ __dev_t st_dev; /* Device. */
+# ifndef __USE_FILE_OFFSET64
+ unsigned short int __pad1;
+ __ino_t st_ino; /* File serial number. */
+# else
+ __ino64_t st_ino; /* File serial number. */
+# endif
+ __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. */
+ unsigned short int __pad2;
+# ifndef __USE_FILE_OFFSET64
+ __off_t st_size; /* Size of file, in bytes. */
+# else
+ __off64_t st_size; /* Size of file, in bytes. */
+# endif
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+# ifndef __USE_FILE_OFFSET64
+ __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
+# else
+ __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
+# endif
+#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
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+ };
+
+
+# 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. */
+ unsigned short int __pad2;
+ __off64_t st_size; /* Size of file, in bytes. */
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ __blkcnt64_t st_blocks; /* Number 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. */
+# 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
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+ };
+# endif /* __USE_LARGEFILE64 */
+
+#else /* __WORDSIZE == 32 */
+
+struct stat
+ {
+ __dev_t st_dev; /* Device. */
+# ifndef __USE_FILE_OFFSET64
+ __ino_t st_ino; /* File serial number. */
+# else
+ __ino64_t st_ino; /* File serial number. */
+# endif
+ __nlink_t st_nlink; /* Link count. */
+ __mode_t st_mode; /* File mode. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ int __pad2;
+ __dev_t st_rdev; /* Device number, if device. */
+# ifndef __USE_FILE_OFFSET64
+ __off_t st_size; /* Size of file, in bytes. */
+# else
+ __off64_t st_size; /* Size of file, in bytes. */
+# endif
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+# ifndef __USE_FILE_OFFSET64
+ __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
+# else
+ __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
+# endif
+#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
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+ unsigned long int __unused6;
+ };
+
+# ifdef __USE_LARGEFILE64
+struct stat64
+ {
+ __dev_t st_dev; /* Device. */
+ __ino64_t st_ino; /* File serial number. */
+ __nlink_t st_nlink; /* Link count. */
+ __mode_t st_mode; /* File mode. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ int __pad2;
+ __dev_t st_rdev; /* Device number, if device. */
+ __off64_t st_size; /* Size of file, in bytes. */
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ __blkcnt64_t st_blocks; /* Number 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. */
+# 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
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+ unsigned long int __unused6;
+ };
+# endif /* __USE_LARGEFILE64 */
+#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. */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/termios.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/termios.h
new file mode 100644
index 000000000..7aac02dc5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/termios.h
@@ -0,0 +1,319 @@
+/* Copyright (C) 1997,1999,2001,2003,2004,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _TERMIOS_H
+# error "Never include <bits/termios.h> directly; use <termios.h> instead."
+#endif
+
+typedef unsigned char cc_t;
+typedef unsigned int speed_t;
+typedef unsigned int tcflag_t;
+
+/*
+ * termios type and macro definitions. Be careful about adding stuff
+ * to this file since it's used in GNU libc and there are strict rules
+ * concerning namespace pollution.
+ */
+
+#define NCCS 32
+struct termios {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_line; /* line discipline (== c_cc[19]) */
+ cc_t c_cc[NCCS]; /* control characters */
+ speed_t c_ispeed; /* input speed */
+ speed_t c_ospeed; /* output speed */
+#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
+#define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
+};
+
+/* c_cc characters */
+#define VINTR 0
+#define VQUIT 1
+#define VERASE 2
+#define VKILL 3
+#define VEOF 4
+#define VMIN 5
+#define VEOL 6
+#define VTIME 7
+#define VEOL2 8
+#define VSWTC 9
+
+#define VWERASE 10
+#define VREPRINT 11
+#define VSUSP 12
+#define VSTART 13
+#define VSTOP 14
+#define VLNEXT 15
+#define VDISCARD 16
+
+/* c_iflag bits */
+#define IGNBRK 0000001
+#define BRKINT 0000002
+#define IGNPAR 0000004
+#define PARMRK 0000010
+#define INPCK 0000020
+#define ISTRIP 0000040
+#define INLCR 0000100
+#define IGNCR 0000200
+#define ICRNL 0000400
+#define IXON 0001000
+#define IXOFF 0002000
+#define IXANY 0004000
+#define IUCLC 0010000
+#define IMAXBEL 0020000
+#define IUTF8 0040000
+
+/* c_oflag bits */
+#define OPOST 0000001
+#define ONLCR 0000002
+#define OLCUC 0000004
+
+#define OCRNL 0000010
+#define ONOCR 0000020
+#define ONLRET 0000040
+
+#define OFILL 00000100
+#define OFDEL 00000200
+#if defined __USE_MISC || defined __USE_XOPEN
+# define NLDLY 00001400
+# define NL0 00000000
+# define NL1 00000400
+# define NL2 00001000
+# define NL3 00001400
+# define TABDLY 00006000
+# define TAB0 00000000
+# define TAB1 00002000
+# define TAB2 00004000
+# define TAB3 00006000
+# define CRDLY 00030000
+# define CR0 00000000
+# define CR1 00010000
+# define CR2 00020000
+# define CR3 00030000
+# define FFDLY 00040000
+# define FF0 00000000
+# define FF1 00040000
+# define BSDLY 00100000
+# define BS0 00000000
+# define BS1 00100000
+#endif
+#define VTDLY 00200000
+#define VT0 00000000
+#define VT1 00200000
+
+#ifdef __USE_MISC
+# define XTABS 00006000
+#endif
+
+/* c_cflag bit meaning */
+#ifdef __USE_MISC
+# define CBAUD 0000377
+#endif
+#define B0 0000000 /* hang up */
+#define B50 0000001
+#define B75 0000002
+#define B110 0000003
+#define B134 0000004
+#define B150 0000005
+#define B200 0000006
+#define B300 0000007
+#define B600 0000010
+#define B1200 0000011
+#define B1800 0000012
+#define B2400 0000013
+#define B4800 0000014
+#define B9600 0000015
+#define B19200 0000016
+#define B38400 0000017
+#ifdef __USE_MISC
+# define EXTA B19200
+# define EXTB B38400
+# define CBAUDEX 0000020
+#endif
+#define B57600 00020
+#define B115200 00021
+#define B230400 00022
+#define B460800 00023
+#define B500000 00024
+#define B576000 00025
+#define B921600 00026
+#define B1000000 00027
+#define B1152000 00030
+#define B1500000 00031
+#define B2000000 00032
+#define B2500000 00033
+#define B3000000 00034
+#define B3500000 00035
+#define B4000000 00036
+#define __MAX_BAUD B4000000
+
+#define CSIZE 00001400
+#define CS5 00000000
+#define CS6 00000400
+#define CS7 00001000
+#define CS8 00001400
+
+#define CSTOPB 00002000
+#define CREAD 00004000
+#define PARENB 00010000
+#define PARODD 00020000
+#define HUPCL 00040000
+
+#define CLOCAL 00100000
+#ifdef __USE_MISC
+# define CMSPAR 010000000000 /* mark or space (stick) parity */
+# define CRTSCTS 020000000000 /* flow control */
+#endif
+
+/* c_lflag bits */
+#define ISIG 0x00000080
+#define ICANON 0x00000100
+#if defined __USE_MISC || defined __USE_XOPEN
+# define XCASE 0x00004000
+#endif
+#define ECHO 0x00000008
+#define ECHOE 0x00000002
+#define ECHOK 0x00000004
+#define ECHONL 0x00000010
+#define NOFLSH 0x80000000
+#define TOSTOP 0x00400000
+#ifdef __USE_MISC
+# define ECHOCTL 0x00000040
+# define ECHOPRT 0x00000020
+# define ECHOKE 0x00000001
+# define FLUSHO 0x00800000
+# define PENDIN 0x20000000
+#endif
+#define IEXTEN 0x00000400
+
+/* Values for the ACTION argument to `tcflow'. */
+#define TCOOFF 0
+#define TCOON 1
+#define TCIOFF 2
+#define TCION 3
+
+/* Values for the QUEUE_SELECTOR argument to `tcflush'. */
+#define TCIFLUSH 0
+#define TCOFLUSH 1
+#define TCIOFLUSH 2
+
+/* Values for the OPTIONAL_ACTIONS argument to `tcsetattr'. */
+#define TCSANOW 0
+#define TCSADRAIN 1
+#define TCSAFLUSH 2
+
+struct sgttyb {
+ char sg_ispeed;
+ char sg_ospeed;
+ char sg_erase;
+ char sg_kill;
+ short sg_flags;
+};
+
+struct tchars {
+ char t_intrc;
+ char t_quitc;
+ char t_startc;
+ char t_stopc;
+ char t_eofc;
+ char t_brkc;
+};
+
+struct ltchars {
+ char t_suspc;
+ char t_dsuspc;
+ char t_rprntc;
+ char t_flushc;
+ char t_werasc;
+ char t_lnextc;
+};
+
+/* Used for packet mode */
+#define TIOCPKT_DATA 0
+#define TIOCPKT_FLUSHREAD 1
+#define TIOCPKT_FLUSHWRITE 2
+#define TIOCPKT_STOP 4
+#define TIOCPKT_START 8
+#define TIOCPKT_NOSTOP 16
+#define TIOCPKT_DOSTOP 32
+
+struct winsize {
+ unsigned short ws_row;
+ unsigned short ws_col;
+ unsigned short ws_xpixel;
+ unsigned short ws_ypixel;
+};
+
+#define NCC 10
+struct termio {
+ unsigned short c_iflag; /* input mode flags */
+ unsigned short c_oflag; /* output mode flags */
+ unsigned short c_cflag; /* control mode flags */
+ unsigned short c_lflag; /* local mode flags */
+ unsigned char c_line; /* line discipline */
+ unsigned char c_cc[NCC]; /* control characters */
+};
+
+/* c_cc characters */
+#define _VINTR 0
+#define _VQUIT 1
+#define _VERASE 2
+#define _VKILL 3
+#define _VEOF 4
+#define _VMIN 5
+#define _VEOL 6
+#define _VTIME 7
+#define _VEOL2 8
+#define _VSWTC 9
+
+/* modem lines */
+#define TIOCM_LE 0x001
+#define TIOCM_DTR 0x002
+#define TIOCM_RTS 0x004
+#define TIOCM_ST 0x008
+#define TIOCM_SR 0x010
+#define TIOCM_CTS 0x020
+#define TIOCM_CAR 0x040
+#define TIOCM_RNG 0x080
+#define TIOCM_DSR 0x100
+#define TIOCM_CD TIOCM_CAR
+#define TIOCM_RI TIOCM_RNG
+
+/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
+#define TIOCSER_TEMT 0x01 /* Transmitter physically empty */
+
+/* line disciplines */
+#define N_TTY 0
+#define N_SLIP 1
+#define N_MOUSE 2
+#define N_PPP 3
+#define N_STRIP 4
+#define N_AX25 5
+#define N_X25 6 /* X.25 async */
+#define N_6PACK 7
+#define N_MASC 8 /* Mobitex module */
+#define N_R3964 9 /* Simatic R3964 module */
+#define N_PROFIBUS_FDL 10 /* Profibus */
+#define N_IRDA 11 /* Linux IR */
+#define N_SMSBLOCK 12 /* SMS block mode */
+#define N_HDLC 13 /* synchronous HDLC */
+#define N_SYNC_PPP 14 /* synchronous PPP */
+#define N_HCI 15 /* Bluetooth HCI UART */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h b/libc/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
new file mode 100644
index 000000000..cf934234f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
@@ -0,0 +1,19 @@
+/* Determine the wordsize from the preprocessor defines. */
+
+#if defined __powerpc64__
+# define __WORDSIZE 64
+# define __WORDSIZE_COMPAT32 1
+#else
+# define __WORDSIZE 32
+#endif
+
+#if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
+
+/* Signal the glibc ABI didn't used to have a `long double'.
+ The changes all the `long double' function variants to be redirects
+ to the double functions. */
+# define __LONG_DOUBLE_MATH_OPTIONAL 1
+# ifndef __LONG_DOUBLE_128__
+# define __NO_LONG_DOUBLE_MATH 1
+# endif
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/chown.c b/libc/sysdeps/unix/sysv/linux/powerpc/chown.c
new file mode 100644
index 000000000..fdcbd3683
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/chown.c
@@ -0,0 +1,132 @@
+/* chown() compatibility.
+ Copyright (C) 1998, 2000, 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+#include <sysdep.h>
+#include <stdlib.h>
+
+#include <kernel-features.h>
+
+/*
+ In Linux 2.1.x the chown functions have been changed. A new function lchown
+ was introduced. The new chown now follows symlinks - the old chown and the
+ new lchown do not follow symlinks.
+ This file emulates chown() under the old kernels.
+*/
+
+int
+__chown (const char *file, uid_t owner, gid_t group)
+{
+#if __ASSUME_LCHOWN_SYSCALL
+ return INLINE_SYSCALL (chown, 3, file, owner, group);
+#else
+ int err;
+ int old_errno;
+ char link[PATH_MAX + 2];
+ char path[2 * PATH_MAX + 4];
+ int loopct;
+ size_t filelen;
+ static int libc_old_chown = 0 /* -1=old linux, 1=new linux, 0=unknown */;
+
+ if (libc_old_chown == 1)
+ return INLINE_SYSCALL (chown, 3, __ptrvalue (file), owner, group);
+
+ old_errno = errno;
+
+# ifdef __NR_lchown
+ if (libc_old_chown == 0)
+ {
+ err = INLINE_SYSCALL (chown, 3, __ptrvalue (file), owner, group);
+ if (err != -1 || errno != ENOSYS)
+ {
+ libc_old_chown = 1;
+ return err;
+ }
+ libc_old_chown = -1;
+ }
+# endif
+
+ err = __readlink (file, link, PATH_MAX + 1);
+ if (err == -1)
+ {
+ __set_errno (old_errno);
+ return __lchown (file, owner, group);
+ }
+
+ filelen = strlen (file) + 1;
+ if (filelen > sizeof (path))
+ {
+ __set_errno (ENAMETOOLONG);
+ return -1;
+ }
+ memcpy (path, file, filelen);
+
+ /* 'The system has an arbitrary limit...' In practise, we'll hit
+ ENAMETOOLONG before this, usually. */
+ for (loopct = 0; loopct < 128; ++loopct)
+ {
+ size_t linklen;
+
+ if (err >= PATH_MAX + 1)
+ {
+ __set_errno (ENAMETOOLONG);
+ return -1;
+ }
+
+ link[err] = 0; /* Null-terminate string, just-in-case. */
+
+ linklen = strlen (link) + 1;
+
+ if (link[0] == '/')
+ memcpy (path, link, linklen);
+ else
+ {
+ filelen = strlen (path);
+
+ while (filelen > 1 && path[filelen - 1] == '/')
+ --filelen;
+ while (filelen > 0 && path[filelen - 1] != '/')
+ --filelen;
+ if (filelen + linklen > sizeof (path))
+ {
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+ memcpy (path + filelen, link, linklen);
+ }
+
+ err = __readlink (path, link, PATH_MAX + 1);
+
+ if (err == -1)
+ {
+ __set_errno (old_errno);
+ return __lchown (path, owner, group);
+ }
+ }
+ __set_errno (ELOOP);
+ return -1;
+#endif
+}
+libc_hidden_def (__chown)
+
+#include <shlib-compat.h>
+versioned_symbol (libc, __chown, chown, GLIBC_2_1);
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/configure b/libc/sysdeps/unix/sysv/linux/powerpc/configure
new file mode 100644
index 000000000..070bf5cae
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/configure
@@ -0,0 +1,135 @@
+# This file is generated from configure.in by Autoconf. DO NOT EDIT!
+ # Local configure fragment for sysdeps/unix/sysv/linux/powerpc/.
+
+
+echo "$as_me:$LINENO: checking whether $CC $CFLAGS -mlong-double-128 uses IBM extended format" >&5
+echo $ECHO_N "checking whether $CC $CFLAGS -mlong-double-128 uses IBM extended format... $ECHO_C" >&6
+if test "${libc_cv_mlong_double_128ibm+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ save_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -mlong-double-128"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <float.h>
+int
+main ()
+{
+
+#if LDBL_MANT_DIG != 106
+# error "compiler doesn't implement IBM extended format of long double"
+#endif
+long double foobar (long double x) { return x; }
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ libc_cv_mlong_double_128ibm=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+libc_cv_mlong_double_128ibm=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+CFLAGS="$save_CFLAGS"
+fi
+echo "$as_me:$LINENO: result: $libc_cv_mlong_double_128ibm" >&5
+echo "${ECHO_T}$libc_cv_mlong_double_128ibm" >&6
+
+if test "$libc_cv_mlong_double_128ibm" = no; then
+ echo "$as_me:$LINENO: checking whether $CC $CFLAGS supports -mabi=ibmlongdouble" >&5
+echo $ECHO_N "checking whether $CC $CFLAGS supports -mabi=ibmlongdouble... $ECHO_C" >&6
+if test "${libc_cv_mabi_ibmlongdouble+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -mlong-double-128 -mabi=ibmlongdouble"
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <float.h>
+int
+main ()
+{
+
+#if LDBL_MANT_DIG != 106
+# error "compiler doesn't implement IBM extended format of long double"
+#endif
+long double foobar (long double x) { return x; }
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ libc_cv_mabi_ibmlongdouble=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+libc_cv_mabi_ibmlongdouble=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ CFLAGS="$save_CFLAGS"
+fi
+echo "$as_me:$LINENO: result: $libc_cv_mabi_ibmlongdouble" >&5
+echo "${ECHO_T}$libc_cv_mabi_ibmlongdouble" >&6
+
+ if test "$libc_cv_mabi_ibmlongdouble" = yes; then
+ CFLAGS="$CFLAGS -mabi=ibmlongdouble"
+ else
+ { { echo "$as_me:$LINENO: error: this configuration requires -mlong-double-128 IBM extended format support" >&5
+echo "$as_me: error: this configuration requires -mlong-double-128 IBM extended format support" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+fi
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/configure.in b/libc/sysdeps/unix/sysv/linux/powerpc/configure.in
new file mode 100644
index 000000000..1768ab1f9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/configure.in
@@ -0,0 +1,37 @@
+sinclude(./aclocal.m4)dnl Autoconf lossage
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/unix/sysv/linux/powerpc/.
+
+AC_CACHE_CHECK(whether $CC $CFLAGS -mlong-double-128 uses IBM extended format,
+ libc_cv_mlong_double_128ibm, [dnl
+save_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -mlong-double-128"
+AC_TRY_COMPILE([#include <float.h>], [
+#if LDBL_MANT_DIG != 106
+# error "compiler doesn't implement IBM extended format of long double"
+#endif
+long double foobar (long double x) { return x; }],
+ libc_cv_mlong_double_128ibm=yes,
+ libc_cv_mlong_double_128ibm=no)
+CFLAGS="$save_CFLAGS"])
+
+if test "$libc_cv_mlong_double_128ibm" = no; then
+ AC_CACHE_CHECK(whether $CC $CFLAGS supports -mabi=ibmlongdouble,
+ libc_cv_mabi_ibmlongdouble, [dnl
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -mlong-double-128 -mabi=ibmlongdouble"
+ AC_TRY_COMPILE([#include <float.h>], [
+#if LDBL_MANT_DIG != 106
+# error "compiler doesn't implement IBM extended format of long double"
+#endif
+long double foobar (long double x) { return x; }],
+ libc_cv_mabi_ibmlongdouble=yes,
+ libc_cv_mabi_ibmlongdouble=no)
+ CFLAGS="$save_CFLAGS"])
+
+ if test "$libc_cv_mabi_ibmlongdouble" = yes; then
+ CFLAGS="$CFLAGS -mabi=ibmlongdouble"
+ else
+ AC_MSG_ERROR([this configuration requires -mlong-double-128 IBM extended format support])
+ fi
+fi
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/dl-brk.S b/libc/sysdeps/unix/sysv/linux/powerpc/dl-brk.S
new file mode 100644
index 000000000..eeb96544e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/dl-brk.S
@@ -0,0 +1 @@
+#include <brk.S>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/dl-cache.h b/libc/sysdeps/unix/sysv/linux/powerpc/dl-cache.h
new file mode 100644
index 000000000..766bba426
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/dl-cache.h
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/sparc/dl-cache.h>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.c b/libc/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.c
new file mode 100644
index 000000000..7c02c6898
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.c
@@ -0,0 +1,71 @@
+/* Operating system support for run-time dynamic linker. Linux/PPC version.
+ Copyright (C) 1997, 1998, 2001, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <config.h>
+#include <kernel-features.h>
+#include <ldsodefs.h>
+
+extern int __cache_line_size;
+weak_extern (__cache_line_size)
+
+/* Scan the Aux Vector for the "Data Cache Block Size" entry. If found
+ verify that the static extern __cache_line_size is defined by checking
+ for not NULL. If it is defined then assign the cache block size
+ value to __cache_line_size. */
+#define DL_PLATFORM_AUXV \
+ case AT_DCACHEBSIZE: \
+ { \
+ int *cls = & __cache_line_size; \
+ if (cls != NULL) \
+ *cls = av->a_un.a_val; \
+ } \
+ break;
+
+#ifndef __ASSUME_STD_AUXV
+
+/* The PowerPC's auxiliary argument block gets aligned to a 16-byte
+ boundary. This is history and impossible to change compatibly. */
+
+#define DL_FIND_ARG_COMPONENTS(cookie, argc, argv, envp, auxp) \
+ do { \
+ char **_tmp; \
+ size_t _test; \
+ (argc) = *(long int *) cookie; \
+ (argv) = (char **) cookie + 1; \
+ (envp) = (argv) + (argc) + 1; \
+ for (_tmp = (envp); *_tmp; ++_tmp) \
+ continue; \
+ /* The following '++' is important! */ \
+ ++_tmp; \
+ \
+ _test = (size_t)_tmp; \
+ _test = (_test + 0xf) & ~0xf; \
+ /* Under some circumstances, MkLinux (up to at least DR3a5) \
+ omits the padding. To work around this, we make a \
+ basic sanity check of the argument vector. Of \
+ course, this means that in future, the argument \
+ vector will have to be laid out to allow for this \
+ test :-(. */ \
+ if (((ElfW(auxv_t) *)_test)->a_type <= 0x10) \
+ _tmp = (char **)_test; \
+ (auxp) = (ElfW(auxv_t) *) _tmp; \
+ } while (0)
+#endif
+
+#include <sysdeps/unix/sysv/linux/dl-sysdep.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c b/libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c
new file mode 100644
index 000000000..e1be09773
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c
@@ -0,0 +1,59 @@
+/* ELF symbol resolve functions for VDSO objects.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include "config.h"
+#include <dl-hash.h>
+#include <ldsodefs.h>
+
+
+void *
+internal_function
+_dl_vdso_vsym (const char *name, const char *version)
+{
+ struct link_map *map = GLRO (dl_sysinfo_map);
+ void *value = NULL;
+
+
+ if (map != NULL)
+ {
+ /* Use a WEAK REF so we don't error out if the symbol is not found. */
+ ElfW (Sym) wsym;
+ memset (&wsym, 0, sizeof (ElfW (Sym)));
+ wsym.st_info = (unsigned char) ELFW (ST_INFO (STB_WEAK, STT_NOTYPE));
+
+ /* Compute hash value to the version string. */
+ struct r_found_version vers;
+ vers.name = version;
+ vers.hidden = 1;
+ vers.hash = _dl_elf_hash (version);
+ /* We don't have a specific file where the symbol can be found. */
+ vers.filename = NULL;
+
+ /* Search the scope of the vdso map. */
+ const ElfW (Sym) *ref = &wsym;
+ lookup_t result = GLRO (dl_lookup_symbol_x) (name, map, &ref,
+ map->l_local_scope,
+ &vers, 0, 0, NULL);
+
+ if (ref != NULL)
+ value = DL_SYMBOL_ADDRESS (result, ref);
+ }
+
+ return value;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h b/libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h
new file mode 100644
index 000000000..a7dcb2e5f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h
@@ -0,0 +1,27 @@
+/* ELF symbol resolve functions for VDSO objects.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _DL_VDSO_H
+#define _DL_VDSO_H 1
+
+/* Functions for resolving symbols in the VDSO link map. */
+extern void *_dl_vdso_vsym (const char *name, const char *version)
+ internal_function attribute_hidden;
+
+#endif /* dl-vdso.h */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/fchownat.c b/libc/sysdeps/unix/sysv/linux/powerpc/fchownat.c
new file mode 100644
index 000000000..f1b9b4db4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/fchownat.c
@@ -0,0 +1,223 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+#include <sysdep.h>
+#include <stdlib.h>
+
+#include <kernel-features.h>
+
+/*
+ In Linux 2.1.x the chown functions have been changed. A new function lchown
+ was introduced. The new chown now follows symlinks - the old chown and the
+ new lchown do not follow symlinks.
+ This file emulates chown() under the old kernels.
+*/
+
+int
+fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
+{
+ int result;
+
+#ifdef __NR_fchownat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INLINE_SYSCALL (fchownat, 5, fd, file, owner, group, flag);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ if (flag & ~AT_SYMLINK_NOFOLLOW)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+# if __ASSUME_LCHOWN_SYSCALL
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lchown, err, 3, file, owner, group);
+ else
+ result = INTERNAL_SYSCALL (chown, err, 3, file, owner, group);
+# else
+ char link[PATH_MAX + 2];
+ char path[2 * PATH_MAX + 4];
+ int loopct;
+ size_t filelen;
+ static int libc_old_chown = 0 /* -1=old linux, 1=new linux, 0=unknown */;
+
+ if (libc_old_chown == 1)
+ {
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lchown, err, 3, __ptrvalue (file), owner,
+ group);
+ else
+ result = INTERNAL_SYSCALL (chown, err, 3, __ptrvalue (file), owner,
+ group);
+ goto out;
+ }
+
+# ifdef __NR_lchown
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ {
+ result = INTERNAL_SYSCALL (lchown, err, 3, __ptrvalue (file), owner,
+ group);
+ goto out;
+ }
+
+ if (libc_old_chown == 0)
+ {
+ result = INTERNAL_SYSCALL (chown, err, 3, __ptrvalue (file), owner,
+ group);
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return result;
+ if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ {
+ libc_old_chown = 1;
+ goto fail;
+ }
+ libc_old_chown = -1;
+ }
+# else
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ {
+ result = INTERNAL_SYSCALL (chown, err, 3, __ptrvalue (file), owner,
+ group);
+ goto out;
+ }
+# endif
+
+ result = __readlink (file, link, PATH_MAX + 1);
+ if (result == -1)
+ {
+# ifdef __NR_lchown
+ result = INTERNAL_SYSCALL (lchown, err, 3, __ptrvalue (file), owner,
+ group);
+# else
+ result = INTERNAL_SYSCALL (chown, err, 3, __ptrvalue (file), owner,
+ group);
+# endif
+ goto out;
+ }
+
+ filelen = strlen (file) + 1;
+ if (filelen > sizeof (path))
+ {
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+ memcpy (path, file, filelen);
+
+ /* 'The system has an arbitrary limit...' In practise, we'll hit
+ ENAMETOOLONG before this, usually. */
+ for (loopct = 0; loopct < 128; ++loopct)
+ {
+ size_t linklen;
+
+ if (result >= PATH_MAX + 1)
+ {
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+
+ link[result] = 0; /* Null-terminate string, just-in-case. */
+
+ linklen = strlen (link) + 1;
+
+ if (link[0] == '/')
+ memcpy (path, link, linklen);
+ else
+ {
+ filelen = strlen (path);
+
+ while (filelen > 1 && path[filelen - 1] == '/')
+ --filelen;
+ while (filelen > 0 && path[filelen - 1] != '/')
+ --filelen;
+ if (filelen + linklen > sizeof (path))
+ {
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+ memcpy (path + filelen, link, linklen);
+ }
+
+ result = __readlink (path, link, PATH_MAX + 1);
+
+ if (result == -1)
+ {
+# ifdef __NR_lchown
+ result = INTERNAL_SYSCALL (lchown, err, 3, path, owner, group);
+# else
+ result = INTERNAL_SYSCALL (chown, err, 3, path, owner, group);
+# endif
+ goto out;
+ }
+ }
+ __set_errno (ELOOP);
+ return -1;
+
+ out:
+# endif
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+# if !__ASSUME_LCHOWN_SYSCALL
+ fail:
+# endif
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+ result = -1;
+ }
+
+ return result;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c b/libc/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c
new file mode 100644
index 000000000..6d2e766aa
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c
@@ -0,0 +1,117 @@
+/* Get frequency of the system processor. powerpc/Linux version.
+ Copyright (C) 2000, 2001, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <libc-internal.h>
+#include <sysdep.h>
+#include <bits/libc-vdso.h>
+
+hp_timing_t
+__get_clockfreq (void)
+{
+ /* We read the information from the /proc filesystem. /proc/cpuinfo
+ contains at least one line like:
+ timebase : 33333333
+ We search for this line and convert the number into an integer. */
+ static hp_timing_t timebase_freq;
+ hp_timing_t result = 0L;
+
+ /* If this function was called before, we know the result. */
+ if (timebase_freq != 0)
+ return timebase_freq;
+
+ /* If we can use the vDSO to obtain the timebase even better. */
+#ifdef SHARED
+ INTERNAL_SYSCALL_DECL (err);
+ timebase_freq = INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK (get_tbfreq, err, 0);
+ if (INTERNAL_SYSCALL_ERROR_P (timebase_freq, err)
+ && INTERNAL_SYSCALL_ERRNO (timebase_freq, err) == ENOSYS)
+#endif
+ {
+ int fd = open ("/proc/cpuinfo", O_RDONLY);
+
+ if (__builtin_expect (fd != -1, 1))
+ {
+ /* The timebase will be in the 1st 1024 bytes for systems with up
+ to 8 processors. If the first read returns less then 1024
+ bytes read, we have the whole cpuinfo and can start the scan.
+ Otherwise we will have to read more to insure we have the
+ timebase value in the scan. */
+ char buf[1024];
+ ssize_t n;
+
+ n = read (fd, buf, sizeof (buf));
+ if (n == sizeof (buf))
+ {
+ /* We are here because the 1st read returned exactly sizeof
+ (buf) bytes. This implies that we are not at EOF and may
+ not have read the timebase value yet. So we need to read
+ more bytes until we know we have EOF. We copy the lower
+ half of buf to the upper half and read sizeof (buf)/2
+ bytes into the lower half of buf and repeat until we
+ reach EOF. We can assume that the timebase will be in
+ the last 512 bytes of cpuinfo, so two 512 byte half_bufs
+ will be sufficient to contain the timebase and will
+ handle the case where the timebase spans the half_buf
+ boundry. */
+ const ssize_t half_buf = sizeof (buf) / 2;
+ while (n >= half_buf)
+ {
+ memcpy (buf, buf + half_buf, half_buf);
+ n = read (fd, buf + half_buf, half_buf);
+ }
+ if (n >= 0)
+ n += half_buf;
+ }
+
+ if (__builtin_expect (n, 1) > 0)
+ {
+ char *mhz = memmem (buf, n, "timebase", 7);
+
+ if (__builtin_expect (mhz != NULL, 1))
+ {
+ char *endp = buf + n;
+
+ /* Search for the beginning of the string. */
+ while (mhz < endp && (*mhz < '0' || *mhz > '9')
+ && *mhz != '\n')
+ ++mhz;
+
+ while (mhz < endp && *mhz != '\n')
+ {
+ if (*mhz >= '0' && *mhz <= '9')
+ {
+ result *= 10;
+ result += *mhz - '0';
+ }
+
+ ++mhz;
+ }
+ }
+ timebase_freq = result;
+ }
+ close (fd);
+ }
+ }
+
+ return timebase_freq;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/getdents64.c b/libc/sysdeps/unix/sysv/linux/powerpc/getdents64.c
new file mode 100644
index 000000000..0c75fb5a0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/getdents64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getdents64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/getmsg.c b/libc/sysdeps/unix/sysv/linux/powerpc/getmsg.c
new file mode 100644
index 000000000..3a1fa0852
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/getmsg.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getmsg.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/getrlimit.c b/libc/sysdeps/unix/sysv/linux/powerpc/getrlimit.c
new file mode 100644
index 000000000..fc06dbd64
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/getrlimit.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getrlimit.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/getrlimit64.c b/libc/sysdeps/unix/sysv/linux/powerpc/getrlimit64.c
new file mode 100644
index 000000000..fef018f47
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/getrlimit64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getrlimit64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c b/libc/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
new file mode 100644
index 000000000..b381baa28
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
@@ -0,0 +1,42 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <bp-checks.h>
+#include <stddef.h>
+#include <sys/time.h>
+#include <time.h>
+#include <hp-timing.h>
+
+#undef __gettimeofday
+#include <bits/libc-vdso.h>
+
+/* Get the current time of day and timezone information,
+ putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled.
+ Returns 0 on success, -1 on errors. */
+
+int
+__gettimeofday (tv, tz)
+ struct timeval *tv;
+ struct timezone *tz;
+{
+ return INLINE_VSYSCALL (gettimeofday, 2, CHECK_1 (tv), CHECK_1 (tz));
+}
+
+INTDEF (__gettimeofday)
+weak_alias (__gettimeofday, gettimeofday)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/ioctl.c b/libc/sysdeps/unix/sysv/linux/powerpc/ioctl.c
new file mode 100644
index 000000000..88ea9ff08
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/ioctl.c
@@ -0,0 +1,65 @@
+/* Copyright (C) 1998, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdarg.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sysdep.h>
+
+/* The user-visible size of struct termios has changed. Catch ioctl calls
+ using the new-style struct termios, and translate them to old-style. */
+
+int
+__ioctl (int fd, unsigned long int request, ...)
+{
+ void *arg;
+ va_list ap;
+ int result;
+
+ va_start (ap, request);
+ arg = va_arg (ap, void *);
+
+ switch (request)
+ {
+ case TCGETS:
+ result = __tcgetattr (fd, (struct termios *) arg);
+ break;
+
+ case TCSETS:
+ result = tcsetattr (fd, TCSANOW, (struct termios *) arg);
+ break;
+
+ case TCSETSW:
+ result = tcsetattr (fd, TCSADRAIN, (struct termios *) arg);
+ break;
+
+ case TCSETSF:
+ result = tcsetattr (fd, TCSAFLUSH, (struct termios *) arg);
+ break;
+
+ default:
+ result = INLINE_SYSCALL (ioctl, 3, fd, request, arg);
+ break;
+ }
+
+ va_end (ap);
+
+ return result;
+}
+weak_alias (__ioctl, ioctl)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/ipc_priv.h b/libc/sysdeps/unix/sysv/linux/powerpc/ipc_priv.h
new file mode 100644
index 000000000..9b85386a7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/ipc_priv.h
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/alpha/ipc_priv.h>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/kernel_termios.h b/libc/sysdeps/unix/sysv/linux/powerpc/kernel_termios.h
new file mode 100644
index 000000000..4892cb56a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/kernel_termios.h
@@ -0,0 +1,54 @@
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _KERNEL_TERMIOS_H
+#define _KERNEL_TERMIOS_H 1
+
+/* We need the definition of tcflag_t, cc_t, and speed_t. */
+#include <termios.h>
+
+#define __KERNEL_NCCS 19
+
+struct __kernel_termios
+ {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_cc[__KERNEL_NCCS]; /* control characters */
+ cc_t c_line; /* line discipline */
+ speed_t c_ispeed; /* input speed */
+ speed_t c_ospeed; /* output speed */
+ };
+
+#define _HAVE_C_ISPEED 1
+#define _HAVE_C_OSPEED 1
+
+/* We have the kernel termios structure, so we can presume this code knows
+ what it's doing... */
+
+#undef TCGETS
+#undef TCSETS
+#undef TCSETSW
+#undef TCSETSF
+#define TCGETS _IOR ('t', 19, struct __kernel_termios)
+#define TCSETS _IOW ('t', 20, struct __kernel_termios)
+#define TCSETSW _IOW ('t', 21, struct __kernel_termios)
+#define TCSETSF _IOW ('t', 22, struct __kernel_termios)
+
+#endif /* kernel_termios.h */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/lchown.S b/libc/sysdeps/unix/sysv/linux/powerpc/lchown.S
new file mode 100644
index 000000000..78f892ee3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/lchown.S
@@ -0,0 +1,39 @@
+/* lchown system call.
+ Copyright (C) 1998, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Some old kernel headers call lchown() 'chown'. The number is
+ the same. */
+
+#include <sysdep.h>
+
+#ifdef __NR_lchown
+ PSEUDO (__lchown, lchown, 3)
+#else
+ PSEUDO (__lchown, chown, 3)
+#endif
+ ret
+ PSEUDO_END(__lchown)
+ weak_alias (__lchown, lchown)
+
+#ifdef SHARED
+#include <shlib-compat.h>
+# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+compat_symbol (libc, __lchown, chown, GLIBC_2_0)
+# endif
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/ldconfig.h b/libc/sysdeps/unix/sysv/linux/powerpc/ldconfig.h
new file mode 100644
index 000000000..ad67f3fcf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/ldconfig.h
@@ -0,0 +1,27 @@
+/* ldconfig default paths and libraries. Linux/PowerPC version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/generic/ldconfig.h>
+
+#define SYSDEP_KNOWN_INTERPRETER_NAMES \
+ { "/lib/ld.so.1", FLAG_ELF_LIBC6 }, \
+ { "/lib64/ld64.so.1", FLAG_ELF_LIBC6 },
+#define SYSDEP_KNOWN_LIBRARY_NAMES \
+ { "libc.so.6", FLAG_ELF_LIBC6 }, \
+ { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/ldd-rewrite.sed b/libc/sysdeps/unix/sysv/linux/powerpc/ldd-rewrite.sed
new file mode 100644
index 000000000..9039b6954
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/ldd-rewrite.sed
@@ -0,0 +1,15 @@
+/LD_TRACE_LOADED_OBJECTS=1/a\
+add_env="$add_env LD_LIBRARY_VERSION=\\$verify_out"
+
+# ldd is generated from elf/ldd.bash.in with the name
+# of ld.so as generated in Makeconfig
+
+# that name is replaced by a pair referring to both
+# the 32bit and 64bit dynamic linker.
+
+# /lib(64|)/*(64|).so* is replaced with /lib/*.so* and /lib64/*64.so*
+# this works for /lib64/ld64.so.x and /lib/ld.so.x as input
+s_lib64_lib_
+s_64\.so_\.so_
+s_^RTLDLIST=\(.*lib\)\(/[^/]*\)\(\.so\.[0-9.]*\)[[:blank:]]*$_RTLDLIST="\1\2\3 \164\264\3"_
+
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/libc-start.c b/libc/sysdeps/unix/sysv/linux/powerpc/libc-start.c
new file mode 100644
index 000000000..a8005c116
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/libc-start.c
@@ -0,0 +1,130 @@
+/* Copyright (C) 1998,2000,2001,2002,2003,2004,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <ldsodefs.h>
+#include <bp-start.h>
+#include <bp-sym.h>
+
+extern int __cache_line_size;
+weak_extern (__cache_line_size)
+/* The main work is done in the generic function. */
+#define LIBC_START_MAIN generic_start_main
+#define LIBC_START_DISABLE_INLINE
+#define LIBC_START_MAIN_AUXVEC_ARG
+#define MAIN_AUXVEC_ARG
+#define INIT_MAIN_ARGS
+#include <csu/libc-start.c>
+
+struct startup_info
+ {
+ void *__unbounded sda_base;
+ int (*main) (int, char **, char **, void *);
+ int (*init) (int, char **, char **, void *);
+ void (*fini) (void);
+ };
+
+
+#ifdef SHARED
+# include <sys/time.h>
+# include <dl-vdso.h>
+# undef __gettimeofday
+# undef __clock_gettime
+# undef __clock_getres
+# include <bits/libc-vdso.h>
+
+void *__vdso_gettimeofday;
+void *__vdso_clock_gettime;
+void *__vdso_clock_getres;
+void *__vdso_get_tbfreq;
+
+static inline void _libc_vdso_platform_setup (void)
+ {
+ __vdso_gettimeofday = _dl_vdso_vsym ("__kernel_gettimeofday",
+ "LINUX_2.6.15");
+
+ __vdso_clock_gettime = _dl_vdso_vsym ("__kernel_clock_gettime",
+ "LINUX_2.6.15");
+
+ __vdso_clock_getres = _dl_vdso_vsym ("__kernel_clock_getres",
+ "LINUX_2.6.15");
+
+ __vdso_get_tbfreq = _dl_vdso_vsym ("__kernel_vdso_get_tbfreq",
+ "LINUX_2.6.15");
+ }
+#endif
+
+int
+/* GKM FIXME: GCC: this should get __BP_ prefix by virtue of the
+ BPs in the arglist of startup_info.main and startup_info.init. */
+ BP_SYM (__libc_start_main) (int argc, char *__unbounded *__unbounded ubp_av,
+ char *__unbounded *__unbounded ubp_ev,
+ ElfW (auxv_t) * __unbounded auxvec,
+ void (*rtld_fini) (void),
+ struct startup_info *__unbounded stinfo,
+ char *__unbounded *__unbounded stack_on_entry)
+{
+#if __BOUNDED_POINTERS__
+ char **argv;
+#else
+# define argv ubp_av
+#endif
+
+ /* the PPC SVR4 ABI says that the top thing on the stack will
+ be a NULL pointer, so if not we assume that we're being called
+ as a statically-linked program by Linux... */
+ if (*stack_on_entry != NULL)
+ {
+ char *__unbounded * __unbounded temp;
+ /* ...in which case, we have argc as the top thing on the
+ stack, followed by argv (NULL-terminated), envp (likewise),
+ and the auxilary vector. */
+ /* 32/64-bit agnostic load from stack */
+ argc = *(long int *__unbounded) stack_on_entry;
+ ubp_av = stack_on_entry + 1;
+ ubp_ev = ubp_av + argc + 1;
+#ifdef HAVE_AUX_VECTOR
+ temp = ubp_ev;
+ while (*temp != NULL)
+ ++temp;
+ auxvec = (ElfW (auxv_t) *)++ temp;
+#endif
+ rtld_fini = NULL;
+ }
+
+ /* Initialize the __cache_line_size variable from the aux vector. */
+ for (ElfW (auxv_t) * av = auxvec; av->a_type != AT_NULL; ++av)
+ switch (av->a_type)
+ {
+ case AT_DCACHEBSIZE:
+ {
+ int *cls = &__cache_line_size;
+ if (cls != NULL)
+ *cls = av->a_un.a_val;
+ }
+ break;
+ }
+#ifdef SHARED
+ /* Resolve and initialize function pointers for VDSO functions. */
+ _libc_vdso_platform_setup ();
+#endif
+ return generic_start_main (stinfo->main, argc, ubp_av, auxvec,
+ stinfo->init, stinfo->fini, rtld_fini,
+ stack_on_entry);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/nldbl-abi.h b/libc/sysdeps/unix/sysv/linux/powerpc/nldbl-abi.h
new file mode 100644
index 000000000..bd985cc59
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/nldbl-abi.h
@@ -0,0 +1,8 @@
+/* ABI version for long double switch.
+ This is used by the Versions and math_ldbl_opt.h files in
+ sysdeps/ieee754/ldbl-opt/. It gives the ABI version where
+ long double == double was replaced with proper long double
+ for libm *l functions and libc functions using long double. */
+
+#define NLDBL_VERSION GLIBC_2.4
+#define LONG_DOUBLE_COMPAT_VERSION GLIBC_2_4
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/oldgetrlimit64.c b/libc/sysdeps/unix/sysv/linux/powerpc/oldgetrlimit64.c
new file mode 100644
index 000000000..4c27e957b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/oldgetrlimit64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
new file mode 100644
index 000000000..966a7689e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
@@ -0,0 +1,3 @@
+ifeq ($(subdir),resource)
+sysdep_routines += oldgetrlimit64
+endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/Versions b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/Versions
new file mode 100644
index 000000000..181d70150
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/Versions
@@ -0,0 +1,30 @@
+libc {
+ GLIBC_2.0 {
+ # Exception handling support functions from libgcc
+ __register_frame; __register_frame_table; __deregister_frame;
+ __frame_state_for; __register_frame_info_table;
+ }
+ GLIBC_2.2 {
+ # functions used in other libraries
+ __xstat64; __fxstat64; __lxstat64;
+
+ # g*
+ glob64;
+
+ # New rlimit interface
+ getrlimit; setrlimit; getrlimit64; setrlimit64;
+
+ # r*
+ readdir64; readdir64_r;
+
+ # s*
+ scandir64;
+ }
+ GLIBC_2.3.3 {
+ posix_fadvise64; posix_fallocate64;
+ setcontext; getcontext; swapcontext; makecontext;
+ }
+ GLIBC_2.3.4 {
+ setcontext; getcontext; swapcontext; makecontext;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S
new file mode 100644
index 000000000..e94583494
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S
@@ -0,0 +1,64 @@
+/* brk system call for Linux/ppc.
+ Copyright (C) 1995-97, 1999, 2000, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <bp-sym.h>
+#include <bp-asm.h>
+
+ .comm __curbrk,4,4
+ .section ".text"
+ENTRY (BP_SYM (__brk))
+ DISCARD_BOUNDS (r3) /* the bounds are meaningless, so toss 'em */
+ mflr r0
+ stwu r1,-16(r1)
+ cfi_adjust_cfa_offset (16)
+ stw r3,8(r1)
+ stw r0,20(r1)
+ cfi_offset (lr, 4)
+ DO_CALL(SYS_ify(brk))
+ lwz r6,8(r1)
+#ifdef PIC
+# ifdef HAVE_ASM_PPC_REL16
+ bcl 20,31,1f
+1: mflr r5
+ addis r5,r5,__curbrk-1b@ha
+ stw r3,__curbrk-1b@l(r5)
+# else
+ bl _GLOBAL_OFFSET_TABLE_@local-4
+ mflr r5
+ lwz r5,__curbrk@got(r5)
+ stw r3,0(r5)
+# endif
+#else
+ lis r4,__curbrk@ha
+ stw r3,__curbrk@l(r4)
+#endif
+ lwz r0,20(r1)
+ cmplw r6,r3
+ addi r1,r1,16
+ mtlr r0
+ li r3,0
+ blelr+
+ li r3,ENOMEM
+ b __syscall_error@local
+END (BP_SYM (__brk))
+
+weak_alias (BP_SYM (__brk), BP_SYM (brk))
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S
new file mode 100644
index 000000000..37b777799
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S
@@ -0,0 +1,149 @@
+/* Wrapper around clone system call.
+ Copyright (C) 1997,98,99,2000,02,04,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+#include <bp-sym.h>
+#include <bp-asm.h>
+
+#define CLONE_VM 0x00000100
+#define CLONE_THREAD 0x00010000
+
+
+/* This is the only really unusual system call in PPC linux, but not
+ because of any weirdness in the system call itself; because of
+ all the freaky stuff we have to do to make the call useful. */
+
+/* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
+ int flags [r5], void *arg [r6], void *parent_tid [r7],
+ void *tls [r8], void *child_tid [r9]); */
+
+ENTRY (BP_SYM (__clone))
+ /* GKM FIXME: add bounds checks, where sensible. */
+ DISCARD_BOUNDS (r4)
+ DISCARD_BOUNDS (r6)
+
+ /* Check for child_stack == NULL || fn == NULL. */
+ cmpwi cr0,r4,0
+ cmpwi cr1,r3,0
+ cror cr0*4+eq,cr1*4+eq,cr0*4+eq
+ beq- cr0,L(badargs)
+
+ /* Set up stack frame for parent. */
+ stwu r1,-32(r1)
+ cfi_adjust_cfa_offset (32)
+#ifdef RESET_PID
+ stmw r28,16(r1)
+#else
+# ifndef __ASSUME_FIXED_CLONE_SYSCALL
+ stmw r29,16(r1)
+# else
+ stmw r30,16(r1)
+# endif
+#endif
+
+ /* Set up stack frame for child. */
+ clrrwi r4,r4,4
+ li r0,0
+ stwu r0,-16(r4)
+
+ /* Save fn, args, stack across syscall. */
+ mr r30,r3 /* Function in r30. */
+#ifndef __ASSUME_FIXED_CLONE_SYSCALL
+ mr r29,r4 /* Stack pointer in r29. */
+#endif
+#ifdef RESET_PID
+ mr r28,r5
+#endif
+ mr r31,r6 /* Argument in r31. */
+
+ /* 'flags' argument is first parameter to clone syscall. (The other
+ argument is the stack pointer, already in r4.) */
+ mr r3,r5
+
+ /* Move the parent_tid, child_tid and tls arguments. */
+ mr r5,r7
+ mr r6,r8
+ mr r7,r9
+
+ /* End FDE now, because in the child the unwind info will be
+ wrong. */
+ cfi_endproc
+
+ /* Do the call. */
+ DO_CALL(SYS_ify(clone))
+
+ /* Check for child process. */
+ cmpwi cr1,r3,0
+ crandc cr1*4+eq,cr1*4+eq,cr0*4+so
+ bne- cr1,L(parent) /* The '-' is to minimise the race. */
+
+#ifndef __ASSUME_FIXED_CLONE_SYSCALL
+ /* On at least mklinux DR3a5, clone() doesn't actually change
+ the stack pointer. I'm pretty sure this is a bug, because
+ it adds a race condition if a signal is sent to a thread
+ just after it is created (in the previous three instructions). */
+ mr r1,r29
+#endif
+
+#ifdef RESET_PID
+ andis. r0,r28,CLONE_THREAD>>16
+ bne+ r0,L(oldpid)
+ andi. r0,r28,CLONE_VM
+ li r3,-1
+ bne- r0,L(nomoregetpid)
+ DO_CALL(SYS_ify(getpid))
+L(nomoregetpid):
+ stw r3,TID(r2)
+ stw r3,PID(r2)
+L(oldpid):
+#endif
+
+ /* Call procedure. */
+ mtctr r30
+ mr r3,r31
+ bctrl
+ /* Call _exit with result from procedure. */
+ b HIDDEN_JUMPTARGET(_exit)
+
+L(parent):
+ /* Parent. Restore registers & return. */
+#ifdef RESET_PID
+ lmw r28,16(r1)
+#else
+# ifndef __ASSUME_FIXED_CLONE_SYSCALL
+ lmw r29,16(r1)
+# else
+ lmw r30,16(r1)
+# endif
+#endif
+ addi r1,r1,32
+ bnslr+
+ b __syscall_error@local
+
+L(badargs):
+ li r3,EINVAL
+ b __syscall_error@local
+
+ cfi_startproc
+END (BP_SYM (__clone))
+
+weak_alias (BP_SYM (__clone), BP_SYM (clone))
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fcntl.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fcntl.c
new file mode 100644
index 000000000..ea951bc4f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fcntl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fe_nomask.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fe_nomask.c
new file mode 100644
index 000000000..8d3b9ad1f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fe_nomask.c
@@ -0,0 +1,68 @@
+/* Procedure definition for FE_NOMASK_ENV for Linux/ppc.
+ Copyright (C) 2000, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <fenv.h>
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sysdep.h>
+#include <sys/prctl.h>
+#include <kernel-features.h>
+
+#if __ASSUME_NEW_PRCTL_SYSCALL == 0
+/* This is rather fiddly under Linux. We don't have direct access,
+ and there is no system call, but we can change the bits
+ in a signal handler's context... */
+
+static struct sigaction oact;
+
+static void
+fe_nomask_handler (int signum, struct sigcontext *sc)
+{
+ sc->regs->msr |= 0x900ul; /* FE0 | FE1 */
+ sigaction (SIGUSR1, &oact, NULL);
+}
+#endif
+
+const fenv_t *
+__fe_nomask_env (void)
+{
+#if __ASSUME_NEW_PRCTL_SYSCALL == 0
+# if defined PR_SET_FPEXC && defined PR_FP_EXC_PRECISE
+ int result = INLINE_SYSCALL (prctl, 2, PR_SET_FPEXC, PR_FP_EXC_PRECISE);
+
+ if (result == -1 && errno == EINVAL)
+# endif
+ {
+ struct sigaction act;
+
+ act.sa_handler = (sighandler_t) fe_nomask_handler;
+ sigemptyset (&act.sa_mask);
+ act.sa_flags = 0;
+
+ sigaction (SIGUSR1, &act, &oact);
+ raise (SIGUSR1);
+ }
+#else
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (prctl, err, 2, PR_SET_FPEXC, PR_FP_EXC_PRECISE);
+#endif
+
+ return FE_ENABLED_ENV;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/Implies b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/Implies
new file mode 100644
index 000000000..9f70f795b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/Implies
@@ -0,0 +1,2 @@
+# Override ldbl-opt with powerpc32 specific routines.
+powerpc/powerpc32/fpu
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
new file mode 100644
index 000000000..e83f7f04b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c
@@ -0,0 +1,78 @@
+/* Copyright (C) 1997-2002,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_ftruncate64
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+/* The variable is shared between all wrappers around *truncate64 calls. */
+extern int __have_no_truncate64;
+#endif
+
+
+/* Truncate the file FD refers to to LENGTH bytes. */
+int
+__ftruncate64 (fd, length)
+ int fd;
+ off64_t length;
+{
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if (! __have_no_truncate64)
+#endif
+ {
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ int saved_errno = errno;
+#endif
+ /* On PPC32 64bit values are aligned in odd/even register pairs. */
+ int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
+ (long) (length >> 32),
+ (long) length);
+
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if (result != -1 || errno != ENOSYS)
+#endif
+ return result;
+
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ __set_errno (saved_errno);
+ __have_no_truncate64 = 1;
+#endif
+ }
+
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if ((off_t) length != length)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ return __ftruncate (fd, (off_t) length);
+#endif
+}
+weak_alias (__ftruncate64, ftruncate64)
+
+#else
+/* Use the generic implementation. */
+# include <misc/ftruncate64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstat.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstat.c
new file mode 100644
index 000000000..4f219f0b9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstatat.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstatat.c
new file mode 100644
index 000000000..0f8b3135d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstatat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstatat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext-common.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext-common.S
new file mode 100644
index 000000000..c28c34664
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext-common.S
@@ -0,0 +1,286 @@
+/* Save current context, powerpc32 common.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+/* This is the common implementation of getcontext for powerpc32.
+ It not complete in itself should be included in to a framework that
+ defines:
+ __CONTEXT_FUNC_NAME
+ and if appropriate:
+ __CONTEXT_ENABLE_FPRS
+ __CONTEXT_ENABLE_VRS
+ Any archecture that implements the Vector unit is assumed to also
+ implement the floating unit. */
+
+/* Stack frame offsets. */
+#define _FRAME_BACKCHAIN 0
+#define _FRAME_LR_SAVE 4
+#define _FRAME_PARM_SAVE1 8
+#define _FRAME_PARM_SAVE2 12
+#define _FRAME_PARM_SAVE3 16
+#define _FRAME_PARM_SAVE4 20
+
+#ifdef __CONTEXT_ENABLE_VRS
+ .machine "altivec"
+#endif
+ENTRY(__CONTEXT_FUNC_NAME)
+ stwu r1,-16(r1)
+ cfi_adjust_cfa_offset (16)
+/* Insure that the _UC_REGS start on a quadword boundary. */
+ stw r3,_FRAME_PARM_SAVE1(r1)
+ addi r3,r3,_UC_REG_SPACE+12
+ clrrwi r3,r3,4
+
+/* Save the general purpose registers */
+ stw r0,_UC_GREGS+(PT_R0*4)(r3)
+ mflr r0
+ stw r2,_UC_GREGS+(PT_R2*4)(r3)
+ stw r4,_UC_GREGS+(PT_R4*4)(r3)
+/* Set the callers LR_SAVE, and the ucontext LR and NIP to the callers
+ return address. */
+ stw r0,_UC_GREGS+(PT_LNK*4)(r3)
+ stw r0,_UC_GREGS+(PT_NIP*4)(r3)
+ stw r0,_FRAME_LR_SAVE+16(r1)
+ cfi_offset (lr, _FRAME_LR_SAVE)
+ stw r5,_UC_GREGS+(PT_R5*4)(r3)
+ stw r6,_UC_GREGS+(PT_R6*4)(r3)
+ stw r7,_UC_GREGS+(PT_R7*4)(r3)
+ stw r8,_UC_GREGS+(PT_R8*4)(r3)
+ stw r9,_UC_GREGS+(PT_R9*4)(r3)
+ stw r10,_UC_GREGS+(PT_R10*4)(r3)
+ stw r11,_UC_GREGS+(PT_R11*4)(r3)
+ stw r12,_UC_GREGS+(PT_R12*4)(r3)
+ stw r13,_UC_GREGS+(PT_R13*4)(r3)
+ stw r14,_UC_GREGS+(PT_R14*4)(r3)
+ stw r15,_UC_GREGS+(PT_R15*4)(r3)
+ stw r16,_UC_GREGS+(PT_R16*4)(r3)
+ stw r17,_UC_GREGS+(PT_R17*4)(r3)
+ stw r18,_UC_GREGS+(PT_R18*4)(r3)
+ stw r19,_UC_GREGS+(PT_R19*4)(r3)
+ stw r20,_UC_GREGS+(PT_R20*4)(r3)
+ stw r21,_UC_GREGS+(PT_R21*4)(r3)
+ stw r22,_UC_GREGS+(PT_R22*4)(r3)
+ stw r23,_UC_GREGS+(PT_R23*4)(r3)
+ stw r24,_UC_GREGS+(PT_R24*4)(r3)
+ stw r25,_UC_GREGS+(PT_R25*4)(r3)
+ stw r26,_UC_GREGS+(PT_R26*4)(r3)
+ stw r27,_UC_GREGS+(PT_R27*4)(r3)
+ stw r28,_UC_GREGS+(PT_R28*4)(r3)
+ stw r29,_UC_GREGS+(PT_R29*4)(r3)
+ stw r30,_UC_GREGS+(PT_R30*4)(r3)
+ stw r31,_UC_GREGS+(PT_R31*4)(r3)
+/* Save the value of R1. We had to push the stack before we
+ had the address of uc_reg_space. So compute the address of
+ the callers stack pointer and save it as R1. */
+ addi r8,r1,16
+ li r0,0
+/* Save the count, exception and condition registers. */
+ mfctr r11
+ mfxer r10
+ mfcr r9
+ stw r8,_UC_GREGS+(PT_R1*4)(r3)
+ stw r11,_UC_GREGS+(PT_CTR*4)(r3)
+ stw r10,_UC_GREGS+(PT_XER*4)(r3)
+ stw r9,_UC_GREGS+(PT_CCR*4)(r3)
+/* Set the return value of getcontext to "success". R3 is the only
+ register whose value is not preserved in the saved context. */
+ stw r0,_UC_GREGS+(PT_R3*4)(r3)
+
+/* Zero fill fields that can't be set in user state. */
+ stw r0,_UC_GREGS+(PT_MSR*4)(r3)
+ stw r0,_UC_GREGS+(PT_MQ*4)(r3)
+
+#ifdef __CONTEXT_ENABLE_FPRS
+/* Save the floating-point registers */
+ stfd fp0,_UC_FREGS+(0*8)(r3)
+ stfd fp1,_UC_FREGS+(1*8)(r3)
+ stfd fp2,_UC_FREGS+(2*8)(r3)
+ stfd fp3,_UC_FREGS+(3*8)(r3)
+ stfd fp4,_UC_FREGS+(4*8)(r3)
+ stfd fp5,_UC_FREGS+(5*8)(r3)
+ stfd fp6,_UC_FREGS+(6*8)(r3)
+ stfd fp7,_UC_FREGS+(7*8)(r3)
+ stfd fp8,_UC_FREGS+(8*8)(r3)
+ stfd fp9,_UC_FREGS+(9*8)(r3)
+ stfd fp10,_UC_FREGS+(10*8)(r3)
+ stfd fp11,_UC_FREGS+(11*8)(r3)
+ stfd fp12,_UC_FREGS+(12*8)(r3)
+ stfd fp13,_UC_FREGS+(13*8)(r3)
+ stfd fp14,_UC_FREGS+(14*8)(r3)
+ stfd fp15,_UC_FREGS+(15*8)(r3)
+ stfd fp16,_UC_FREGS+(16*8)(r3)
+ stfd fp17,_UC_FREGS+(17*8)(r3)
+ stfd fp18,_UC_FREGS+(18*8)(r3)
+ stfd fp19,_UC_FREGS+(19*8)(r3)
+ stfd fp20,_UC_FREGS+(20*8)(r3)
+ stfd fp21,_UC_FREGS+(21*8)(r3)
+ stfd fp22,_UC_FREGS+(22*8)(r3)
+ stfd fp23,_UC_FREGS+(23*8)(r3)
+ stfd fp24,_UC_FREGS+(24*8)(r3)
+ stfd fp25,_UC_FREGS+(25*8)(r3)
+ stfd fp26,_UC_FREGS+(26*8)(r3)
+ stfd fp27,_UC_FREGS+(27*8)(r3)
+ stfd fp28,_UC_FREGS+(28*8)(r3)
+ stfd fp29,_UC_FREGS+(29*8)(r3)
+ mffs fp0
+ stfd fp30,_UC_FREGS+(30*8)(r3)
+ stfd fp31,_UC_FREGS+(31*8)(r3)
+ stfd fp0,_UC_FREGS+(32*8)(r3)
+
+# ifdef __CONTEXT_ENABLE_VRS
+# ifdef PIC
+ mflr r8
+# ifdef HAVE_ASM_PPC_REL16
+ bcl 20,31,1f
+1: mflr r7
+ addis r7,r7,_GLOBAL_OFFSET_TABLE_-1b@ha
+ addi r7,r7,_GLOBAL_OFFSET_TABLE_-1b@l
+# else
+ bl _GLOBAL_OFFSET_TABLE_@local-4
+ mflr r7
+# endif
+# ifdef SHARED
+ lwz r7,_rtld_global_ro@got(r7)
+ mtlr r8
+ lwz r7,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r7)
+# else
+ lwz r7,_dl_hwcap@got(r7)
+ mtlr r8
+ lwz r7,0(r7)
+# endif
+# else
+ lis r7,_dl_hwcap@ha
+ lwz r7,_dl_hwcap@l(r7)
+# endif
+ andis. r7,r7,(PPC_FEATURE_HAS_ALTIVEC >> 16)
+
+ la r10,(_UC_VREGS)(r3)
+ la r9,(_UC_VREGS+16)(r3)
+
+ beq 2f /* L(no_vec) */
+/* address of the combined VSCR/VSAVE quadword. */
+ la r8,(_UC_VREGS+512)(r3)
+
+/* Save the vector registers */
+ stvx v0,0,r10
+ stvx v1,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+/* We need to get the Vector Status and Control Register early to avoid
+ store order problems later with the VSAVE register that shares the
+ same quadword. */
+ mfvscr v0
+
+ stvx v2,0,r10
+ stvx v3,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v0,0,r8
+
+ stvx v4,0,r10
+ stvx v5,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v6,0,r10
+ stvx v7,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v8,0,r10
+ stvx v9,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v10,0,r10
+ stvx v11,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v12,0,r10
+ stvx v13,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v14,0,r10
+ stvx v15,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v16,0,r10
+ stvx v17,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v18,0,r10
+ stvx v19,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v20,0,r10
+ stvx v21,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v22,0,r10
+ stvx v23,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v24,0,r10
+ stvx v25,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v26,0,r10
+ stvx v27,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v28,0,r10
+ stvx v29,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ mfspr r0,VRSAVE
+ stvx v30,0,r10
+ stvx v31,0,r9
+
+ stw r0,0(r8)
+
+2: /* L(no_vec): */
+# endif
+#endif
+/* We need to set up parms and call sigprocmask which will clobber
+ volatile registers. So before the call we need to retrieve the
+ original ucontext ptr (parm1) from stack and store the UC_REGS_PTR
+ (current R3). */
+ lwz r12,_FRAME_PARM_SAVE1(r1)
+ li r4,0
+ stw r3,_UC_REGS_PTR(r12)
+ addi r5,r12,_UC_SIGMASK
+ li r3,SIG_BLOCK
+ bl __sigprocmask@local
+
+ lwz r0,_FRAME_LR_SAVE+16(r1)
+ addi r1,r1,16
+ mtlr r0
+ blr
+END(__CONTEXT_FUNC_NAME)
+
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S
new file mode 100644
index 000000000..dad107403
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S
@@ -0,0 +1,84 @@
+/* Save current context.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#include <rtld-global-offsets.h>
+#include <shlib-compat.h>
+#include <kernel-features.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include "ucontext_i.h"
+
+#define __CONTEXT_FUNC_NAME __getcontext
+#define __CONTEXT_ENABLE_FPRS 1
+#define __CONTEXT_ENABLE_VRS 1
+
+/* Size of ucontext in GLIBC_2.3.4 and later. */
+#define _UC_SIZE_2_3_4 1184
+
+#ifdef __ASSUME_SWAPCONTEXT_SYSCALL
+ .section ".text";
+ENTRY (__getcontext)
+ li r4,0
+ li r5,_UC_SIZE_2_3_4;
+ DO_CALL (SYS_ify (swapcontext));
+ bso- cr0,1f
+/* the kernel does not set the return code for the success case */
+ li r3,0
+ blr
+1:
+ b __syscall_error@local
+END(__getcontext)
+#else
+# include "getcontext-common.S"
+#endif
+
+versioned_symbol (libc, __getcontext, getcontext, GLIBC_2_3_4)
+
+#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
+ compat_text_section
+
+# undef __CONTEXT_FUNC_NAME
+# define __CONTEXT_FUNC_NAME __novec_getcontext
+# undef __CONTEXT_ENABLE_VRS
+
+# clude "getcontext-common.S"
+
+ .previous
+
+compat_symbol (libc, __novec_getcontext, getcontext, GLIBC_2_3_3)
+
+#endif
+
+#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_3_3)
+
+# define _ERRNO_H 1
+# include <bits/errno.h>
+
+ compat_text_section
+ENTRY (__getcontext_stub)
+ li r3,ENOSYS
+ b __syscall_error@local
+END (__getcontext_stub)
+ .previous
+
+compat_symbol (libc, __getcontext_stub, getcontext, GLIBC_2_1)
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/glob64.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/glob64.c
new file mode 100644
index 000000000..82a9a296a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/glob64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/glob64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/kernel_stat.h b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/kernel_stat.h
new file mode 100644
index 000000000..65f3aa40e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/kernel_stat.h
@@ -0,0 +1,49 @@
+/* Definition of `struct stat' used in the kernel.
+ Copyright (C) 1997, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+struct kernel_stat
+ {
+ unsigned int st_dev;
+ unsigned int st_ino;
+ unsigned int st_mode;
+ unsigned short st_nlink;
+ unsigned int st_uid;
+ unsigned int st_gid;
+ unsigned int st_rdev;
+ unsigned long int st_size;
+ unsigned long int st_blksize;
+ unsigned long int st_blocks;
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ unsigned long int __unused4;
+#define _HAVE___UNUSED4
+ unsigned long int __unused5;
+#define _HAVE___UNUSED5
+ };
+
+#define _HAVE_STAT___UNUSED4
+#define _HAVE_STAT___UNUSED5
+#define _HAVE_STAT___PAD1
+#define _HAVE_STAT___PAD2
+#define _HAVE_STAT_NSEC
+#define _HAVE_STAT64___UNUSED4
+#define _HAVE_STAT64___UNUSED5
+#define _HAVE_STAT64___PAD2
+#define _HAVE_STAT64_NSEC
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/lockf64.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/lockf64.c
new file mode 100644
index 000000000..a88f5a784
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/lockf64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/lockf64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/lxstat.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/lxstat.c
new file mode 100644
index 000000000..2371cd971
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/lxstat.c
@@ -0,0 +1,2 @@
+#include <sysdeps/unix/sysv/linux/i386/lxstat.c>
+
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S
new file mode 100644
index 000000000..208a375ef
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S
@@ -0,0 +1,219 @@
+/* Set up a context to call a function.
+ Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#include <shlib-compat.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include "ucontext_i.h"
+
+ENTRY(__makecontext)
+ /* Set up the first 7 args to the function in its registers */
+ addi r11,r3,_UC_REG_SPACE+12
+ clrrwi r11,r11,4
+ stw r11,_UC_REGS_PTR(r3)
+ stw r6,_UC_GREGS+(PT_R3*4)(r11)
+ stw r7,_UC_GREGS+(PT_R4*4)(r11)
+ stw r8,_UC_GREGS+(PT_R5*4)(r11)
+ stw r9,_UC_GREGS+(PT_R6*4)(r11)
+ stw r10,_UC_GREGS+(PT_R7*4)(r11)
+ lwz r8,8(r1)
+ lwz r9,12(r1)
+ stw r8,_UC_GREGS+(PT_R8*4)(r11)
+ stw r9,_UC_GREGS+(PT_R9*4)(r11)
+
+ /* Set the NIP to the start of the function */
+ stw r4,_UC_GREGS+(PT_NIP*4)(r11)
+
+ /* Set the function's r31 to ucp->uc_link for the exitcode below. */
+ lwz r7,_UC_LINK(r3)
+ stw r7,_UC_GREGS+(PT_R31*4)(r11)
+
+ /* Set the function's LR to point to the exitcode below. */
+#ifdef PIC
+ mflr r0
+ cfi_register(lr,r0)
+ bl 1f
+1: mflr r6
+ addi r6,r6,L(exitcode)-1b
+ mtlr r0
+ cfi_same_value (lr)
+#else
+ lis r6,L(exitcode)@ha
+ addi r6,r6,L(exitcode)@l
+#endif
+ stw r6,_UC_GREGS+(PT_LNK*4)(r11)
+
+ /*
+ * Set up the stack frame for the function.
+ * If we have more than 5 args to the function (8 args to makecontext),
+ * there will be some arguments on the stack which have to end up
+ * in registers. If there are more than 8 args to the function,
+ * we have to copy (argc - 8) args from our stack to the functions'
+ * stack (and allow space for them in the frame).
+ */
+ lwz r4,_UC_STACK_SP(r3)
+ lwz r8,_UC_STACK_SIZE(r3)
+ add r4,r4,r8
+ rlwinm r4,r4,0,0,27 /* round down to 16-byte boundary */
+ addi r7,r4,-16 /* stack frame for fn's caller */
+ cmpwi r5,8
+ blt 2f /* less than 8 args is easy */
+ lwz r10,16(r1)
+ stw r10,_UC_GREGS+(PT_R10*4)(r11)
+ beq 2f /* if exactly 8 args */
+ subi r9,r5,3
+ subi r5,r5,8
+ rlwinm r9,r9,2,0,27
+ subf r7,r9,r4
+ mtctr r5 /* copy the 9th and following args */
+ addi r6,r1,16
+ addi r8,r7,4
+3: lwzu r10,4(r6)
+ stwu r10,4(r8)
+ bdnz 3b
+2: stw r7,_UC_GREGS+(PT_R1*4)(r11)
+ li r6,0
+ stw r6,0(r7)
+
+ blr
+
+/*
+ * If the function returns, it comes here. We put ucp->uc_link in
+ * r31, which is a callee-saved register. We have to continue with
+ * the context that r31 points to, or exit if it is 0.
+ */
+L(exitcode):
+ mr. r3,r31
+ beq 4f
+ bl __setcontext@local
+4: bl HIDDEN_JUMPTARGET(exit)
+ b 4b
+
+END(__makecontext)
+
+versioned_symbol (libc, __makecontext, makecontext, GLIBC_2_3_4)
+
+#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
+
+ compat_text_section
+ENTRY(__novec_makecontext)
+ /* Set up the first 7 args to the function in its registers */
+ addi r11,r3,_UC_REG_SPACE
+ stw r11,_UC_REGS_PTR(r3)
+ stw r6,_UC_GREGS+(PT_R3*4)(r11)
+ stw r7,_UC_GREGS+(PT_R4*4)(r11)
+ stw r8,_UC_GREGS+(PT_R5*4)(r11)
+ stw r9,_UC_GREGS+(PT_R6*4)(r11)
+ stw r10,_UC_GREGS+(PT_R7*4)(r11)
+ lwz r8,8(r1)
+ lwz r9,12(r1)
+ stw r8,_UC_GREGS+(PT_R8*4)(r11)
+ stw r9,_UC_GREGS+(PT_R9*4)(r11)
+
+ /* Set the NIP to the start of the function */
+ stw r4,_UC_GREGS+(PT_NIP*4)(r11)
+
+ /* Set the function's r31 to ucp->uc_link for the exitcode below. */
+ lwz r7,_UC_LINK(r3)
+ stw r7,_UC_GREGS+(PT_R31*4)(r11)
+
+ /* Set the function's LR to point to the exitcode below. */
+#ifdef PIC
+ mflr r0
+ cfi_register(lr,r0)
+ bl 1f
+1: mflr r6
+ addi r6,r6,L(novec_exitcode)-1b
+ mtlr r0
+ cfi_same_value (lr)
+#else
+ lis r6,L(novec_exitcode)@ha
+ addi r6,r6,L(novec_exitcode)@l
+#endif
+ stw r6,_UC_GREGS+(PT_LNK*4)(r11)
+
+ /*
+ * Set up the stack frame for the function.
+ * If we have more than 5 args to the function (8 args to makecontext),
+ * there will be some arguments on the stack which have to end up
+ * in registers. If there are more than 8 args to the function,
+ * we have to copy (argc - 8) args from our stack to the functions'
+ * stack (and allow space for them in the frame).
+ */
+ lwz r4,_UC_STACK_SP(r3)
+ lwz r8,_UC_STACK_SIZE(r3)
+ add r4,r4,r8
+ rlwinm r4,r4,0,0,27 /* round down to 16-byte boundary */
+ addi r7,r4,-16 /* stack frame for fn's caller */
+ cmpwi r5,8
+ blt 2f /* less than 8 args is easy */
+ lwz r10,16(r1)
+ stw r10,_UC_GREGS+(PT_R10*4)(r11)
+ beq 2f /* if exactly 8 args */
+ subi r9,r5,3
+ subi r5,r5,8
+ rlwinm r9,r9,2,0,27
+ subf r7,r9,r4
+ mtctr r5 /* copy the 9th and following args */
+ addi r6,r1,16
+ addi r8,r7,4
+3: lwzu r10,4(r6)
+ stwu r10,4(r8)
+ bdnz 3b
+2: stw r7,_UC_GREGS+(PT_R1*4)(r11)
+ li r6,0
+ stw r6,0(r7)
+
+ blr
+
+/*
+ * If the function returns, it comes here. We put ucp->uc_link in
+ * r31, which is a callee-saved register. We have to continue with
+ * the context that r31 points to, or exit if it is 0.
+ */
+L(novec_exitcode):
+ mr. r3,r31
+ beq 4f
+ bl __novec_setcontext@local
+4: bl HIDDEN_JUMPTARGET(exit)
+ b 4b
+
+END(__novec_makecontext)
+ .previous
+
+compat_symbol (libc, __novec_makecontext, makecontext, GLIBC_2_3_3)
+#endif
+
+#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_3_3)
+
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+ compat_text_section
+ENTRY (__makecontext_stub)
+ li r3,ENOSYS
+ b __syscall_error@local
+END (__makecontext_stub)
+ .previous
+
+compat_symbol (libc, __makecontext_stub, makecontext, GLIBC_2_1)
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/posix_fadvise.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/posix_fadvise.c
new file mode 100644
index 000000000..15b705402
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/posix_fadvise.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <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)
+{
+#ifdef __NR_fadvise64
+ INTERNAL_SYSCALL_DECL (err);
+ int ret = INTERNAL_SYSCALL (fadvise64, err, 6, fd, 0,
+ __LONG_LONG_PAIR (offset >> 31, offset), len,
+ advise);
+ if (INTERNAL_SYSCALL_ERROR_P (ret, err))
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+ return 0;
+#else
+ return ENOSYS;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/posix_fadvise64.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/posix_fadvise64.c
new file mode 100644
index 000000000..c97bbbe87
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/posix_fadvise64.c
@@ -0,0 +1,78 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+
+int __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise);
+int __posix_fadvise64_l32 (int fd, off64_t offset, size_t len, int advise);
+
+/* Advice the system about the expected behaviour of the application with
+ respect to the file associated with FD. */
+
+int
+__posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
+{
+#ifdef __NR_fadvise64_64
+ INTERNAL_SYSCALL_DECL (err);
+ int ret = INTERNAL_SYSCALL (fadvise64_64, err, 6, fd, advise,
+ __LONG_LONG_PAIR ((long)(offset >> 32), (long)offset),
+ __LONG_LONG_PAIR ((long)(len >> 32), (long)len));
+ if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
+ return 0;
+# ifndef __ASSUME_FADVISE64_64_SYSCALL
+ if (INTERNAL_SYSCALL_ERRNO (ret, err) != ENOSYS)
+# endif
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+#endif
+#ifndef __ASSUME_FADVISE64_64_SYSCALL
+# ifdef __NR_fadvise64
+ if (len != (off_t) len)
+ return EOVERFLOW;
+
+ INTERNAL_SYSCALL_DECL (err2);
+ int ret2 = INTERNAL_SYSCALL (fadvise64, err2, 6, fd, 0,
+ __LONG_LONG_PAIR ((long)(offset >> 32), (long)offset),
+ (off_t) len, advise);
+ if (!INTERNAL_SYSCALL_ERROR_P (ret2, err2))
+ return 0;
+ return INTERNAL_SYSCALL_ERRNO (ret2, err2);
+# else
+ return ENOSYS;
+# endif
+#endif
+}
+
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT(libc, GLIBC_2_2, GLIBC_2_3_3)
+
+int
+attribute_compat_text_section
+__posix_fadvise64_l32 (int fd, off64_t offset, size_t len, int advise)
+{
+ return __posix_fadvise64_l64 (fd, offset, len, advise);
+}
+
+versioned_symbol (libc, __posix_fadvise64_l64, posix_fadvise64, GLIBC_2_3_3);
+compat_symbol (libc, __posix_fadvise64_l32, posix_fadvise64, GLIBC_2_2);
+#else
+strong_alias (__posix_fadvise64_l64, posix_fadvise64);
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread.c
new file mode 100644
index 000000000..4d9fa263c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
+
+# if __ASSUME_PREAD_SYSCALL == 0
+static ssize_t __emulate_pread (int fd, void *buf, size_t count,
+ off_t offset) internal_function;
+# endif
+
+
+ssize_t
+__libc_pread (fd, buf, count, offset)
+ int fd;
+ void *buf;
+ size_t count;
+ off_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ /* On PPC32 64bit values are aligned in odd/even register pairs. */
+ result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count,
+ 0, offset >> 31, offset);
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread (fd, buf, count, offset);
+# endif
+
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* On PPC32 64bit values are aligned in odd/even register pairs. */
+ result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count,
+ 0, offset >> 31, offset);
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+strong_alias (__libc_pread, __pread)
+weak_alias (__libc_pread, pread)
+
+# define __libc_pread(fd, buf, count, offset) \
+ static internal_function __emulate_pread (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PREAD_SYSCALL == 0
+# include <sysdeps/posix/pread.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread64.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread64.c
new file mode 100644
index 000000000..9527554e9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread64.c
@@ -0,0 +1,88 @@
+/* Copyright (C) 1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
+
+# if __ASSUME_PREAD_SYSCALL == 0
+static ssize_t __emulate_pread64 (int fd, void *buf, size_t count,
+ off64_t offset) internal_function;
+# endif
+
+
+ssize_t
+__libc_pread64 (fd, buf, count, offset)
+ int fd;
+ void *buf;
+ size_t count;
+ off64_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ /* On PPC32 64bit values are aligned in odd/even register pairs. */
+ result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count,
+ 0, (long) (offset >> 32),
+ (long) offset);
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread64 (fd, buf, count, offset);
+# endif
+
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* On PPC32 64bit values are aligned in odd/even register pairs. */
+ result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count,
+ 0, (long) (offset >> 32),
+ (long) offset);
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread64 (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+weak_alias (__libc_pread64, __pread64)
+weak_alias (__libc_pread64, pread64)
+
+# define __libc_pread64(fd, buf, count, offset) \
+ static internal_function __emulate_pread64 (fd, buf, count, offset)
+#endif
+
+# if __ASSUME_PREAD_SYSCALL == 0
+# include <sysdeps/posix/pread64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite.c
new file mode 100644
index 000000000..32383f430
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
+
+# if __ASSUME_PWRITE_SYSCALL == 0
+static ssize_t __emulate_pwrite (int fd, const void *buf, size_t count,
+ off_t offset) internal_function;
+# endif
+
+
+ssize_t
+__libc_pwrite (fd, buf, count, offset)
+ int fd;
+ const void *buf;
+ size_t count;
+ off_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ /* On PPC32 64bit values are aligned in odd/even register pairs. */
+ result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count,
+ 0, offset >> 31, offset);
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite (fd, buf, count, offset);
+# endif
+
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* On PPC32 64bit values are aligned in odd/even register pairs. */
+ result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count,
+ 0, offset >> 31, offset);
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+strong_alias (__libc_pwrite, __pwrite)
+weak_alias (__libc_pwrite, pwrite)
+
+# define __libc_pwrite(fd, buf, count, offset) \
+ static internal_function __emulate_pwrite (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PWRITE_SYSCALL == 0
+# include <sysdeps/posix/pwrite.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite64.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite64.c
new file mode 100644
index 000000000..acc250a88
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite64.c
@@ -0,0 +1,89 @@
+/* Copyright (C) 1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
+
+# if __ASSUME_PWRITE_SYSCALL == 0
+static ssize_t __emulate_pwrite64 (int fd, const void *buf, size_t count,
+ off64_t offset) internal_function;
+# endif
+
+
+ssize_t
+__libc_pwrite64 (fd, buf, count, offset)
+ int fd;
+ const void *buf;
+ size_t count;
+ off64_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ /* On PPC32 64bit values are aligned in odd/even register pairs. */
+ result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count,
+ 0, (long) (offset >> 32),
+ (long) offset);
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite64 (fd, buf, count, offset);
+# endif
+
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* On PPC32 64bit values are aligned in odd/even register pairs. */
+ result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count,
+ 0, (long) (offset >> 32),
+ (long) offset);
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite64 (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+weak_alias (__libc_pwrite64, __pwrite64)
+libc_hidden_weak (__pwrite64)
+weak_alias (__libc_pwrite64, pwrite64)
+
+# define __libc_pwrite64(fd, buf, count, offset) \
+ static internal_function __emulate_pwrite64 (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PWRITE_SYSCALL == 0
+# include <sysdeps/posix/pwrite64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext-common.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext-common.S
new file mode 100644
index 000000000..40a7a24f1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext-common.S
@@ -0,0 +1,293 @@
+/* Jump to a new context powerpc32 common.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+/* This is the common implementation of setcontext for powerpc32.
+ It not complete in itself should be included in to a framework that
+ defines:
+ __CONTEXT_FUNC_NAME
+ and if appropriate:
+ __CONTEXT_ENABLE_FPRS
+ __CONTEXT_ENABLE_VRS
+ Any archecture that implements the Vector unit is assumed to also
+ implement the floating unit. */
+
+/* Stack frame offsets. */
+#define _FRAME_BACKCHAIN 0
+#define _FRAME_LR_SAVE 4
+#define _FRAME_PARM_SAVE1 8
+#define _FRAME_PARM_SAVE2 12
+#define _FRAME_PARM_SAVE3 16
+#define _FRAME_PARM_SAVE4 20
+
+#ifdef __CONTEXT_ENABLE_VRS
+ .machine "altivec"
+#endif
+ENTRY(__CONTEXT_FUNC_NAME)
+ mflr r0
+ stwu r1,-16(r1)
+ cfi_adjust_cfa_offset (16)
+ stw r0,20(r1)
+ cfi_offset (lr, _FRAME_LR_SAVE)
+ stw r31,12(r1)
+ cfi_offset(r31,-4)
+ lwz r31,_UC_REGS_PTR(r3)
+
+ /*
+ * If this ucontext refers to the point where we were interrupted
+ * by a signal, we have to use the rt_sigreturn system call to
+ * return to the context so we get both LR and CTR restored.
+ *
+ * Otherwise, the context we are restoring is either just after
+ * a procedure call (getcontext/swapcontext) or at the beginning
+ * of a procedure call (makecontext), so we don't need to restore
+ * r0, xer, ctr. We don't restore r2 since it will be used as
+ * the TLS pointer.
+ */
+ lwz r0,_UC_GREGS+(PT_MSR*4)(r31)
+ cmpwi r0,0
+ bne 4f /* L(do_sigret) */
+
+ /* Restore the signal mask */
+ li r5,0
+ addi r4,r3,_UC_SIGMASK
+ li r3,SIG_SETMASK
+ bl __sigprocmask@local
+ cmpwi r3,0
+ bne 3f /* L(error_exit) */
+
+#ifdef __CONTEXT_ENABLE_FPRS
+# ifdef __CONTEXT_ENABLE_VRS
+# ifdef PIC
+ mflr r8
+# ifdef HAVE_ASM_PPC_REL16
+ bcl 20,31,1f
+1: mflr r7
+ addis r7,r7,_GLOBAL_OFFSET_TABLE_-1b@ha
+ addi r7,r7,_GLOBAL_OFFSET_TABLE_-1b@l
+# else
+ bl _GLOBAL_OFFSET_TABLE_@local-4
+ mflr r7
+# endif
+# ifdef SHARED
+ lwz r7,_rtld_global_ro@got(r7)
+ mtlr r8
+ lwz r7,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r7)
+# else
+ lwz r7,_dl_hwcap@got(r7)
+ mtlr r8
+ lwz r7,0(r7)
+# endif
+# else
+ lis r7,_dl_hwcap@ha
+ lwz r7,_dl_hwcap@l(r7)
+# endif
+ andis. r7,r7,(PPC_FEATURE_HAS_ALTIVEC >> 16)
+ la r10,(_UC_VREGS)(r31)
+ beq 2f /* L(has_no_vec) */
+
+ lwz r0,(32*16)(r10)
+ li r9,(32*16)
+ cmpwi r0,0
+ mtspr VRSAVE,r0
+ beq 2f /* L(has_no_vec) */
+
+ lvx v19,r9,r10
+ la r9,(16)(r10)
+
+ lvx v0,0,r10
+ lvx v1,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ mtvscr v19
+ lvx v2,0,r10
+ lvx v3,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v4,0,r10
+ lvx v5,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v6,0,r10
+ lvx v7,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v8,0,r10
+ lvx v9,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v10,0,r10
+ lvx v11,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v12,0,r10
+ lvx v13,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v14,0,r10
+ lvx v15,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v16,0,r10
+ lvx v17,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v18,0,r10
+ lvx v19,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v20,0,r10
+ lvx v21,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v22,0,r10
+ lvx v23,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v24,0,r10
+ lvx v25,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v26,0,r10
+ lvx v27,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v28,0,r10
+ lvx v29,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v30,0,r10
+ lvx v31,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v10,0,r10
+ lvx v11,0,r9
+
+2: /* L(has_no_vec): */
+# endif /* __CONTEXT_ENABLE_VRS */
+ /* Restore the floating-point registers */
+ lfd fp31,_UC_FREGS+(32*8)(r31)
+ lfd fp0,_UC_FREGS+(0*8)(r31)
+ mtfsf 0xff,fp31
+ lfd fp1,_UC_FREGS+(1*8)(r31)
+ lfd fp2,_UC_FREGS+(2*8)(r31)
+ lfd fp3,_UC_FREGS+(3*8)(r31)
+ lfd fp4,_UC_FREGS+(4*8)(r31)
+ lfd fp5,_UC_FREGS+(5*8)(r31)
+ lfd fp6,_UC_FREGS+(6*8)(r31)
+ lfd fp7,_UC_FREGS+(7*8)(r31)
+ lfd fp8,_UC_FREGS+(8*8)(r31)
+ lfd fp9,_UC_FREGS+(9*8)(r31)
+ lfd fp10,_UC_FREGS+(10*8)(r31)
+ lfd fp11,_UC_FREGS+(11*8)(r31)
+ lfd fp12,_UC_FREGS+(12*8)(r31)
+ lfd fp13,_UC_FREGS+(13*8)(r31)
+ lfd fp14,_UC_FREGS+(14*8)(r31)
+ lfd fp15,_UC_FREGS+(15*8)(r31)
+ lfd fp16,_UC_FREGS+(16*8)(r31)
+ lfd fp17,_UC_FREGS+(17*8)(r31)
+ lfd fp18,_UC_FREGS+(18*8)(r31)
+ lfd fp19,_UC_FREGS+(19*8)(r31)
+ lfd fp20,_UC_FREGS+(20*8)(r31)
+ lfd fp21,_UC_FREGS+(21*8)(r31)
+ lfd fp22,_UC_FREGS+(22*8)(r31)
+ lfd fp23,_UC_FREGS+(23*8)(r31)
+ lfd fp24,_UC_FREGS+(24*8)(r31)
+ lfd fp25,_UC_FREGS+(25*8)(r31)
+ lfd fp26,_UC_FREGS+(26*8)(r31)
+ lfd fp27,_UC_FREGS+(27*8)(r31)
+ lfd fp28,_UC_FREGS+(28*8)(r31)
+ lfd fp29,_UC_FREGS+(29*8)(r31)
+ lfd fp30,_UC_FREGS+(30*8)(r31)
+ lfd fp31,_UC_FREGS+(31*8)(r31)
+#endif /* __CONTEXT_ENABLE_FPRS */
+
+ /* Restore LR and CCR, and set CTR to the NIP value */
+ lwz r3,_UC_GREGS+(PT_LNK*4)(r31)
+ lwz r4,_UC_GREGS+(PT_NIP*4)(r31)
+ lwz r5,_UC_GREGS+(PT_CCR*4)(r31)
+ mtlr r3
+ mtctr r4
+ mtcr r5
+
+ /* Restore the general registers */
+ lwz r1,_UC_GREGS+(PT_R1*4)(r31)
+ lwz r3,_UC_GREGS+(PT_R3*4)(r31)
+ lwz r4,_UC_GREGS+(PT_R4*4)(r31)
+ lwz r5,_UC_GREGS+(PT_R5*4)(r31)
+ lwz r6,_UC_GREGS+(PT_R6*4)(r31)
+ lwz r7,_UC_GREGS+(PT_R7*4)(r31)
+ lwz r8,_UC_GREGS+(PT_R8*4)(r31)
+ lwz r9,_UC_GREGS+(PT_R9*4)(r31)
+ lwz r10,_UC_GREGS+(PT_R10*4)(r31)
+ lwz r11,_UC_GREGS+(PT_R11*4)(r31)
+ lwz r12,_UC_GREGS+(PT_R12*4)(r31)
+ lwz r13,_UC_GREGS+(PT_R13*4)(r31)
+ lwz r14,_UC_GREGS+(PT_R14*4)(r31)
+ lwz r15,_UC_GREGS+(PT_R15*4)(r31)
+ lwz r16,_UC_GREGS+(PT_R16*4)(r31)
+ lwz r17,_UC_GREGS+(PT_R17*4)(r31)
+ lwz r18,_UC_GREGS+(PT_R18*4)(r31)
+ lwz r19,_UC_GREGS+(PT_R19*4)(r31)
+ lwz r20,_UC_GREGS+(PT_R20*4)(r31)
+ lwz r21,_UC_GREGS+(PT_R21*4)(r31)
+ lwz r22,_UC_GREGS+(PT_R22*4)(r31)
+ lwz r23,_UC_GREGS+(PT_R23*4)(r31)
+ lwz r24,_UC_GREGS+(PT_R24*4)(r31)
+ lwz r25,_UC_GREGS+(PT_R25*4)(r31)
+ lwz r26,_UC_GREGS+(PT_R26*4)(r31)
+ lwz r27,_UC_GREGS+(PT_R27*4)(r31)
+ lwz r28,_UC_GREGS+(PT_R28*4)(r31)
+ lwz r29,_UC_GREGS+(PT_R29*4)(r31)
+ lwz r30,_UC_GREGS+(PT_R30*4)(r31)
+ lwz r31,_UC_GREGS+(PT_R31*4)(r31)
+
+ bctr
+
+3: /* L(error_exit): */
+ lwz r31,12(r1)
+ lwz r0,20(r1)
+ addi r1,r1,16
+ mtlr r0
+ blr
+
+
+4: /* L(do_sigret): */
+ addi r1,r3,-0xd0
+ li r0,SYS_ify(rt_sigreturn)
+ sc
+ /* NOTREACHED */
+
+END (__CONTEXT_FUNC_NAME)
+
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S
new file mode 100644
index 000000000..7e9213c2d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S
@@ -0,0 +1,85 @@
+/* Jump to a new context.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#include <rtld-global-offsets.h>
+#include <shlib-compat.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include "ucontext_i.h"
+
+#define __CONTEXT_FUNC_NAME __setcontext
+#define __CONTEXT_ENABLE_FPRS 1
+#define __CONTEXT_ENABLE_VRS 1
+
+/* Size of ucontext in GLIBC_2.3.4 and later. */
+#define _UC_SIZE_2_3_4 1184
+
+#ifdef __ASSUME_SWAPCONTEXT_SYSCALL
+ .section ".text";
+ENTRY (__setcontext)
+ mr r4,r3
+ li r3,0
+ li r5,_UC_SIZE_2_3_4;
+ DO_CALL (SYS_ify (swapcontext));
+ bso- cr0,1f
+/* the kernel does not set the return code for the success case */
+ li r3,0
+ blr
+1:
+ b __syscall_error@local
+END(__setcontext)
+#else
+# include "setcontext-common.S"
+#endif
+
+versioned_symbol (libc, __setcontext, setcontext, GLIBC_2_3_4)
+
+#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
+
+ compat_text_section
+
+# undef __CONTEXT_FUNC_NAME
+# define __CONTEXT_FUNC_NAME __novec_setcontext
+# undef __CONTEXT_ENABLE_VRS
+
+# include "setcontext-common.S"
+
+ .previous
+
+compat_symbol (libc, __novec_setcontext, setcontext, GLIBC_2_3_3)
+
+#endif
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_3)
+
+# define _ERRNO_H 1
+# include <bits/errno.h>
+
+ compat_text_section
+ENTRY (__setcontext_stub)
+ li r3,ENOSYS
+ b __syscall_error@local
+END (__setcontext_stub)
+ .previous
+
+compat_symbol (libc, __setcontext_stub, setcontext, GLIBC_2_0)
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/socket.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/socket.S
new file mode 100644
index 000000000..0bb5bef78
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/socket.S
@@ -0,0 +1,121 @@
+/* Copyright (C) 1995,96,97,99, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+#define P(a, b) P2(a, b)
+#define P2(a, b) a##b
+
+/* The socket-oriented system calls are handled unusally in Linux.
+ They are all gated through the single `socketcall' system call number.
+ `socketcall' takes two arguments: the first is the subcode, specifying
+ which socket function is being called; and the second is a pointer to
+ the arguments to the specific function.
+
+ The .S files for the other calls just #define socket and #include this.
+ They also #define a 'number-of-arguments' word in NARGS, which
+ defaults to 3. */
+
+#ifndef NARGS
+#ifdef socket
+#error NARGS not defined
+#endif
+#define NARGS 3
+#endif
+
+/* 0(r1) and 4(r1) are reserved by the ABI, 8(r1), 12(r1), 16(r1) are used
+ for temp saves. 44(r1) is used to save r30. */
+#define stackblock 20
+
+#ifndef __socket
+# ifndef NO_WEAK_ALIAS
+# define __socket P(__,socket)
+# else
+# define __socket socket
+# endif
+#endif
+
+ .text
+ENTRY(__socket)
+ stwu r1,-48(r1)
+ cfi_adjust_cfa_offset(48)
+#if NARGS >= 1
+ stw r3,stackblock(r1)
+#endif
+#if NARGS >= 2
+ stw r4,4+stackblock(r1)
+#endif
+#if NARGS >= 3
+ stw r5,8+stackblock(r1)
+#endif
+#if NARGS >= 4
+ stw r6,12+stackblock(r1)
+#endif
+#if NARGS >= 5
+ stw r7,16+stackblock(r1)
+#endif
+#if NARGS >= 6
+ stw r8,20+stackblock(r1)
+#endif
+#if NARGS >= 7
+#error too many arguments!
+#endif
+
+#if defined NEED_CANCELLATION && defined CENABLE
+ SINGLE_THREAD_P
+ bne- .Lsocket_cancel
+#endif
+
+ li r3,P(SOCKOP_,socket)
+ addi r4,r1,stackblock
+ DO_CALL(SYS_ify(socketcall))
+ addi r1,r1,48
+ PSEUDO_RET
+
+#if defined NEED_CANCELLATION && defined CENABLE
+.Lsocket_cancel:
+ mflr r9
+ stw r9,52(r1)
+ cfi_offset (lr, 4)
+ CGOTSETUP
+ CENABLE
+ stw r3,16(r1)
+ li r3,P(SOCKOP_,socket)
+ addi r4,r1,stackblock
+ DO_CALL(SYS_ify(socketcall))
+ mfcr r0
+ stw r3,8(r1)
+ stw r0,12(r1)
+ lwz r3,16(r1)
+ CDISABLE
+ lwz r4,52(r1)
+ lwz r0,12(r1)
+ lwz r3,8(r1)
+ CGOTRESTORE
+ mtlr r4
+ mtcr r0
+ addi r1,r1,48
+ PSEUDO_RET
+#endif
+
+PSEUDO_END (__socket)
+
+#ifndef NO_WEAK_ALIAS
+weak_alias (__socket, socket)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext-common.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext-common.S
new file mode 100644
index 000000000..0c7b945ed
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext-common.S
@@ -0,0 +1,517 @@
+/* Save current context and jump to a new context.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+/* This is the common implementation of setcontext for powerpc32.
+ It not complete in itself should be included in to a framework that
+ defines:
+ __CONTEXT_FUNC_NAME
+ and if appropriate:
+ __CONTEXT_ENABLE_FPRS
+ __CONTEXT_ENABLE_VRS
+ Any archecture that implements the Vector unit is assumed to also
+ implement the floating unit. */
+
+/* Stack frame offsets. */
+#define _FRAME_BACKCHAIN 0
+#define _FRAME_LR_SAVE 4
+#define _FRAME_PARM_SAVE1 8
+#define _FRAME_PARM_SAVE2 12
+#define _FRAME_PARM_SAVE3 16
+#define _FRAME_PARM_SAVE4 20
+
+#ifdef __CONTEXT_ENABLE_VRS
+ .machine "altivec"
+#endif
+ENTRY(__CONTEXT_FUNC_NAME)
+ stwu r1,-16(r1)
+ cfi_adjust_cfa_offset (16)
+/* Insure that the _UC_REGS start on a quadword boundary. */
+ stw r3,_FRAME_PARM_SAVE1(r1)
+ addi r3,r3,_UC_REG_SPACE+12
+ stw r4,_FRAME_PARM_SAVE2(r1) /* new context pointer */
+ clrrwi r3,r3,4
+
+/* Save the general purpose registers */
+ stw r0,_UC_GREGS+(PT_R0*4)(r3)
+ mflr r0
+ stw r2,_UC_GREGS+(PT_R2*4)(r3)
+ stw r4,_UC_GREGS+(PT_R4*4)(r3)
+/* Set the callers LR_SAVE, and the ucontext LR and NIP to the callers
+ return address. */
+ stw r0,_UC_GREGS+(PT_LNK*4)(r3)
+ stw r0,_UC_GREGS+(PT_NIP*4)(r3)
+ stw r0,_FRAME_LR_SAVE+16(r1)
+ cfi_offset (lr, _FRAME_LR_SAVE)
+ stw r5,_UC_GREGS+(PT_R5*4)(r3)
+ stw r6,_UC_GREGS+(PT_R6*4)(r3)
+ stw r7,_UC_GREGS+(PT_R7*4)(r3)
+ stw r8,_UC_GREGS+(PT_R8*4)(r3)
+ stw r9,_UC_GREGS+(PT_R9*4)(r3)
+ stw r10,_UC_GREGS+(PT_R10*4)(r3)
+ stw r11,_UC_GREGS+(PT_R11*4)(r3)
+ stw r12,_UC_GREGS+(PT_R12*4)(r3)
+ stw r13,_UC_GREGS+(PT_R13*4)(r3)
+ stw r14,_UC_GREGS+(PT_R14*4)(r3)
+ stw r15,_UC_GREGS+(PT_R15*4)(r3)
+ stw r16,_UC_GREGS+(PT_R16*4)(r3)
+ stw r17,_UC_GREGS+(PT_R17*4)(r3)
+ stw r18,_UC_GREGS+(PT_R18*4)(r3)
+ stw r19,_UC_GREGS+(PT_R19*4)(r3)
+ stw r20,_UC_GREGS+(PT_R20*4)(r3)
+ stw r21,_UC_GREGS+(PT_R21*4)(r3)
+ stw r22,_UC_GREGS+(PT_R22*4)(r3)
+ stw r23,_UC_GREGS+(PT_R23*4)(r3)
+ stw r24,_UC_GREGS+(PT_R24*4)(r3)
+ stw r25,_UC_GREGS+(PT_R25*4)(r3)
+ stw r26,_UC_GREGS+(PT_R26*4)(r3)
+ stw r27,_UC_GREGS+(PT_R27*4)(r3)
+ stw r28,_UC_GREGS+(PT_R28*4)(r3)
+ stw r29,_UC_GREGS+(PT_R29*4)(r3)
+ stw r30,_UC_GREGS+(PT_R30*4)(r3)
+ stw r31,_UC_GREGS+(PT_R31*4)(r3)
+
+/* Save the value of R1. We had to push the stack before we
+ had the address of uc_reg_space. So compute the address of
+ the callers stack pointer and save it as R1. */
+ addi r8,r1,16
+ li r0,0
+/* Save the count, exception and condition registers. */
+ mfctr r11
+ mfxer r10
+ mfcr r9
+ stw r8,_UC_GREGS+(PT_R1*4)(r3)
+ stw r11,_UC_GREGS+(PT_CTR*4)(r3)
+ stw r10,_UC_GREGS+(PT_XER*4)(r3)
+ stw r9,_UC_GREGS+(PT_CCR*4)(r3)
+/* Set the return value of getcontext to "success". R3 is the only
+ register whose value is not preserved in the saved context. */
+ stw r0,_UC_GREGS+(PT_R3*4)(r3)
+
+ /* Zero fill fields that can't be set in user state. */
+ stw r0,_UC_GREGS+(PT_MSR*4)(r3)
+ stw r0,_UC_GREGS+(PT_MQ*4)(r3)
+
+#ifdef __CONTEXT_ENABLE_FPRS
+ /* Save the floating-point registers */
+ stfd fp0,_UC_FREGS+(0*8)(r3)
+ stfd fp1,_UC_FREGS+(1*8)(r3)
+ stfd fp2,_UC_FREGS+(2*8)(r3)
+ stfd fp3,_UC_FREGS+(3*8)(r3)
+ stfd fp4,_UC_FREGS+(4*8)(r3)
+ stfd fp5,_UC_FREGS+(5*8)(r3)
+ stfd fp6,_UC_FREGS+(6*8)(r3)
+ stfd fp7,_UC_FREGS+(7*8)(r3)
+ stfd fp8,_UC_FREGS+(8*8)(r3)
+ stfd fp9,_UC_FREGS+(9*8)(r3)
+ stfd fp10,_UC_FREGS+(10*8)(r3)
+ stfd fp11,_UC_FREGS+(11*8)(r3)
+ stfd fp12,_UC_FREGS+(12*8)(r3)
+ stfd fp13,_UC_FREGS+(13*8)(r3)
+ stfd fp14,_UC_FREGS+(14*8)(r3)
+ stfd fp15,_UC_FREGS+(15*8)(r3)
+ stfd fp16,_UC_FREGS+(16*8)(r3)
+ stfd fp17,_UC_FREGS+(17*8)(r3)
+ stfd fp18,_UC_FREGS+(18*8)(r3)
+ stfd fp19,_UC_FREGS+(19*8)(r3)
+ stfd fp20,_UC_FREGS+(20*8)(r3)
+ stfd fp21,_UC_FREGS+(21*8)(r3)
+ stfd fp22,_UC_FREGS+(22*8)(r3)
+ stfd fp23,_UC_FREGS+(23*8)(r3)
+ stfd fp24,_UC_FREGS+(24*8)(r3)
+ stfd fp25,_UC_FREGS+(25*8)(r3)
+ stfd fp26,_UC_FREGS+(26*8)(r3)
+ stfd fp27,_UC_FREGS+(27*8)(r3)
+ stfd fp28,_UC_FREGS+(28*8)(r3)
+ stfd fp29,_UC_FREGS+(29*8)(r3)
+ mffs fp0
+ stfd fp30,_UC_FREGS+(30*8)(r3)
+ stfd fp31,_UC_FREGS+(31*8)(r3)
+ stfd fp0,_UC_FREGS+(32*8)(r3)
+
+# ifdef __CONTEXT_ENABLE_VRS
+# ifdef PIC
+ mflr r8
+# ifdef HAVE_ASM_PPC_REL16
+ bcl 20,31,1f
+1: mflr r7
+ addis r7,r7,_GLOBAL_OFFSET_TABLE_-1b@ha
+ addi r7,r7,_GLOBAL_OFFSET_TABLE_-1b@l
+# else
+ bl _GLOBAL_OFFSET_TABLE_@local-4
+ mflr r7
+# endif
+# ifdef SHARED
+ lwz r7,_rtld_global_ro@got(r7)
+ mtlr r8
+ lwz r7,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r7)
+# else
+ lwz r7,_dl_hwcap@got(r7)
+ mtlr r8
+ lwz r7,0(r7)
+# endif
+# else
+ lis r7,_dl_hwcap@ha
+ lwz r7,_dl_hwcap@l(r7)
+# endif
+ andis. r7,r7,(PPC_FEATURE_HAS_ALTIVEC >> 16)
+
+ la r10,(_UC_VREGS)(r3)
+ la r9,(_UC_VREGS+16)(r3)
+
+/* beq L(no_vec)*/
+ beq 2f
+/* address of the combined VSCR/VSAVE quadword. */
+ la r8,(_UC_VREGS+512)(r3)
+
+/* Save the vector registers */
+ stvx v0,0,r10
+ stvx v1,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+/* We need to get the Vector Status and Control Register early to avoid
+ store order problems later with the VSAVE register that shares the
+ same quadword. */
+ mfvscr v0
+
+ stvx v2,0,r10
+ stvx v3,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v0,0,r8
+
+ stvx v4,0,r10
+ stvx v5,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v6,0,r10
+ stvx v7,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v8,0,r10
+ stvx v9,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v10,0,r10
+ stvx v11,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v12,0,r10
+ stvx v13,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v14,0,r10
+ stvx v15,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v16,0,r10
+ stvx v17,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v18,0,r10
+ stvx v19,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v20,0,r10
+ stvx v21,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v22,0,r10
+ stvx v23,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v24,0,r10
+ stvx v25,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v26,0,r10
+ stvx v27,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v28,0,r10
+ stvx v29,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ mfvscr v0
+ stvx v30,0,r10
+ stvx v31,0,r9
+ stw r0,0(r8)
+
+2: /*L(no_vec):*/
+# endif /* __CONTEXT_ENABLE_VRS */
+#endif /* __CONTEXT_ENABLE_FPRS */
+
+/* Restore ucontext (parm1) from stack. */
+ lwz r12,_FRAME_PARM_SAVE1(r1)
+ li r4,0
+ stw r3,_UC_REGS_PTR(r12)
+ addi r5,r12,_UC_SIGMASK
+ li r3,SIG_SETMASK
+ bl __sigprocmask@local
+ cmpwi r3,0
+ bne 3f /* L(error_exit) */
+
+ /*
+ * If the new ucontext refers to the point where we were interrupted
+ * by a signal, we have to use the rt_sigreturn system call to
+ * return to the context so we get both LR and CTR restored.
+ *
+ * Otherwise, the context we are restoring is either just after
+ * a procedure call (getcontext/swapcontext) or at the beginning
+ * of a procedure call (makecontext), so we don't need to restore
+ * r0, xer, ctr. We don't restore r2 since it will be used as
+ * the TLS pointer.
+ */
+ lwz r4,_FRAME_PARM_SAVE2(r1)
+ lwz r31,_UC_REGS_PTR(r4)
+ lwz r0,_UC_GREGS+(PT_MSR*4)(r31)
+ cmpwi r0,0
+ bne 4f /* L(do_sigret) */
+
+#ifdef __CONTEXT_ENABLE_FPRS
+# ifdef __CONTEXT_ENABLE_VRS
+
+# ifdef PIC
+ mflr r8
+# ifdef HAVE_ASM_PPC_REL16
+ bcl 20,31,5f
+5: mflr r7
+ addis r7,r7,_GLOBAL_OFFSET_TABLE_-1b@ha
+ addi r7,r7,_GLOBAL_OFFSET_TABLE_-1b@l
+# else
+ bl _GLOBAL_OFFSET_TABLE_@local-4
+ mflr r7
+# endif
+ mtlr r8
+# ifdef SHARED
+ lwz r7,_rtld_global_ro@got(r7)
+ lwz r7,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r7)
+# else
+ lwz r7,_dl_hwcap@got(r7)
+ lwz r7,0(r7)
+# endif
+# else
+ lis r7,_dl_hwcap@ha
+ lwz r7,_dl_hwcap@l(r7)
+# endif
+ andis. r7,r7,(PPC_FEATURE_HAS_ALTIVEC >> 16)
+ la r10,(_UC_VREGS)(r31)
+ beq 6f /* L(has_no_vec) */
+
+ lwz r0,(32*16)(r10)
+ li r9,(32*16)
+ cmpwi r0,0
+ mtspr VRSAVE,r0
+ beq 6f /* L(has_no_vec) */
+
+ lvx v19,r9,r10
+ la r9,(16)(r10)
+
+ lvx v0,0,r10
+ lvx v1,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ mtvscr v19
+ lvx v2,0,r10
+ lvx v3,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v4,0,r10
+ lvx v5,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v6,0,r10
+ lvx v7,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v8,0,r10
+ lvx v9,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v10,0,r10
+ lvx v11,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v12,0,r10
+ lvx v13,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v14,0,r10
+ lvx v15,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v16,0,r10
+ lvx v17,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v18,0,r10
+ lvx v19,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v20,0,r10
+ lvx v21,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v22,0,r10
+ lvx v23,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v24,0,r10
+ lvx v25,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v26,0,r10
+ lvx v27,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v28,0,r10
+ lvx v29,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v30,0,r10
+ lvx v31,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v10,0,r10
+ lvx v11,0,r9
+
+6: /* L(has_no_vec): */
+# endif /* __CONTEXT_ENABLE_VRS */
+ /* Restore the floating-point registers */
+ lfd fp31,_UC_FREGS+(32*8)(r31)
+ lfd fp0,_UC_FREGS+(0*8)(r31)
+ mtfsf 0xff,fp31
+ lfd fp1,_UC_FREGS+(1*8)(r31)
+ lfd fp2,_UC_FREGS+(2*8)(r31)
+ lfd fp3,_UC_FREGS+(3*8)(r31)
+ lfd fp4,_UC_FREGS+(4*8)(r31)
+ lfd fp5,_UC_FREGS+(5*8)(r31)
+ lfd fp6,_UC_FREGS+(6*8)(r31)
+ lfd fp7,_UC_FREGS+(7*8)(r31)
+ lfd fp8,_UC_FREGS+(8*8)(r31)
+ lfd fp9,_UC_FREGS+(9*8)(r31)
+ lfd fp10,_UC_FREGS+(10*8)(r31)
+ lfd fp11,_UC_FREGS+(11*8)(r31)
+ lfd fp12,_UC_FREGS+(12*8)(r31)
+ lfd fp13,_UC_FREGS+(13*8)(r31)
+ lfd fp14,_UC_FREGS+(14*8)(r31)
+ lfd fp15,_UC_FREGS+(15*8)(r31)
+ lfd fp16,_UC_FREGS+(16*8)(r31)
+ lfd fp17,_UC_FREGS+(17*8)(r31)
+ lfd fp18,_UC_FREGS+(18*8)(r31)
+ lfd fp19,_UC_FREGS+(19*8)(r31)
+ lfd fp20,_UC_FREGS+(20*8)(r31)
+ lfd fp21,_UC_FREGS+(21*8)(r31)
+ lfd fp22,_UC_FREGS+(22*8)(r31)
+ lfd fp23,_UC_FREGS+(23*8)(r31)
+ lfd fp24,_UC_FREGS+(24*8)(r31)
+ lfd fp25,_UC_FREGS+(25*8)(r31)
+ lfd fp26,_UC_FREGS+(26*8)(r31)
+ lfd fp27,_UC_FREGS+(27*8)(r31)
+ lfd fp28,_UC_FREGS+(28*8)(r31)
+ lfd fp29,_UC_FREGS+(29*8)(r31)
+ lfd fp30,_UC_FREGS+(30*8)(r31)
+ lfd fp31,_UC_FREGS+(31*8)(r31)
+#endif /* __CONTEXT_ENABLE_FPRS */
+
+ /* Restore LR and CCR, and set CTR to the NIP value */
+ lwz r3,_UC_GREGS+(PT_LNK*4)(r31)
+ lwz r4,_UC_GREGS+(PT_NIP*4)(r31)
+ lwz r5,_UC_GREGS+(PT_CCR*4)(r31)
+ mtlr r3
+ mtctr r4
+ mtcr r5
+
+ /* Restore the general registers */
+ lwz r3,_UC_GREGS+(PT_R3*4)(r31)
+ lwz r4,_UC_GREGS+(PT_R4*4)(r31)
+ lwz r5,_UC_GREGS+(PT_R5*4)(r31)
+ lwz r6,_UC_GREGS+(PT_R6*4)(r31)
+ lwz r7,_UC_GREGS+(PT_R7*4)(r31)
+ lwz r8,_UC_GREGS+(PT_R8*4)(r31)
+ lwz r9,_UC_GREGS+(PT_R9*4)(r31)
+ lwz r10,_UC_GREGS+(PT_R10*4)(r31)
+ lwz r11,_UC_GREGS+(PT_R11*4)(r31)
+ lwz r12,_UC_GREGS+(PT_R12*4)(r31)
+ lwz r13,_UC_GREGS+(PT_R13*4)(r31)
+ lwz r14,_UC_GREGS+(PT_R14*4)(r31)
+ lwz r15,_UC_GREGS+(PT_R15*4)(r31)
+ lwz r16,_UC_GREGS+(PT_R16*4)(r31)
+ lwz r17,_UC_GREGS+(PT_R17*4)(r31)
+ lwz r18,_UC_GREGS+(PT_R18*4)(r31)
+ lwz r19,_UC_GREGS+(PT_R19*4)(r31)
+ lwz r20,_UC_GREGS+(PT_R20*4)(r31)
+ lwz r21,_UC_GREGS+(PT_R21*4)(r31)
+ lwz r22,_UC_GREGS+(PT_R22*4)(r31)
+ lwz r23,_UC_GREGS+(PT_R23*4)(r31)
+ lwz r24,_UC_GREGS+(PT_R24*4)(r31)
+ lwz r25,_UC_GREGS+(PT_R25*4)(r31)
+ lwz r26,_UC_GREGS+(PT_R26*4)(r31)
+ lwz r27,_UC_GREGS+(PT_R27*4)(r31)
+ lwz r28,_UC_GREGS+(PT_R28*4)(r31)
+ lwz r29,_UC_GREGS+(PT_R29*4)(r31)
+ lwz r30,_UC_GREGS+(PT_R30*4)(r31)
+ lwz r1,_UC_GREGS+(PT_R1*4)(r31)
+ lwz r31,_UC_GREGS+(PT_R31*4)(r31)
+
+ bctr
+
+3:/*L(error_exit):*/
+ lwz r0,_FRAME_LR_SAVE+16(r1)
+ addi r1,r1,16
+ mtlr r0
+ blr
+
+4:/*L(do_sigret):*/
+ addi r1,r4,-0xd0
+ li r0,SYS_ify(rt_sigreturn)
+ sc
+ /* NOTREACHED */
+
+END(__CONTEXT_FUNC_NAME)
+
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S
new file mode 100644
index 000000000..0605f3d10
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S
@@ -0,0 +1,84 @@
+/* Save current context and jump to a new context.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#include <rtld-global-offsets.h>
+#include <shlib-compat.h>
+#include <kernel-features.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include "ucontext_i.h"
+
+#define __CONTEXT_FUNC_NAME __swapcontext
+#define __CONTEXT_ENABLE_FPRS 1
+#define __CONTEXT_ENABLE_VRS 1
+
+/* Size of ucontext in GLIBC_2.3.4 and later. */
+#define _UC_SIZE_2_3_4 1184
+
+#ifdef __ASSUME_SWAPCONTEXT_SYSCALL
+ .section ".text";
+ENTRY (__swapcontext)
+ li r5,_UC_SIZE_2_3_4;
+ DO_CALL (SYS_ify (swapcontext));
+ bso- cr0,1f
+/* the kernel does not set the return code for the success case */
+ li r3,0
+ blr
+1:
+ b __syscall_error@local
+END(__swapcontext)
+#else
+# include "swapcontext-common.S"
+#endif
+
+versioned_symbol (libc, __swapcontext, swapcontext, GLIBC_2_3_4)
+
+#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
+
+ compat_text_section
+
+# undef __CONTEXT_FUNC_NAME
+# define __CONTEXT_FUNC_NAME __novec_swapcontext
+# undef __CONTEXT_ENABLE_VRS
+
+# include "swapcontext-common.S"
+
+ .previous
+
+compat_symbol (libc, __novec_swapcontext, swapcontext, GLIBC_2_3_3)
+
+#endif
+
+#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_3_3)
+
+# define _ERRNO_H 1
+# include <bits/errno.h>
+
+ compat_text_section
+ENTRY (__swapcontext_stub)
+ li r3,ENOSYS
+ b __syscall_error@local
+END (__swapcontext_stub)
+ .previous
+
+compat_symbol (libc, __swapcontext_stub, swapcontext, GLIBC_2_1)
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list
new file mode 100644
index 000000000..82025b485
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list
@@ -0,0 +1,5 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+# System calls with wrappers.
+oldgetrlimit EXTRA getrlimit i:ip __old_getrlimit getrlimit@GLIBC_2.0
+oldsetrlimit EXTRA setrlimit i:ip __old_setrlimit setrlimit@GLIBC_2.0
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
new file mode 100644
index 000000000..470da5aa6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
@@ -0,0 +1,297 @@
+/* Copyright (C) 1992,1997-2003,2004,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_POWERPC_SYSDEP_H
+#define _LINUX_POWERPC_SYSDEP_H 1
+
+#include <sysdeps/unix/powerpc/sysdep.h>
+#include <tls.h>
+
+/* Some systen calls got renamed over time, but retained the same semantics.
+ Handle them here so they can be catched by both C and assembler stubs in
+ glibc. */
+
+#ifdef __NR_pread64
+# ifdef __NR_pread
+# error "__NR_pread and __NR_pread64 both defined???"
+# endif
+# define __NR_pread __NR_pread64
+#endif
+
+#ifdef __NR_pwrite64
+# ifdef __NR_pwrite
+# error "__NR_pwrite and __NR_pwrite64 both defined???"
+# endif
+# define __NR_pwrite __NR_pwrite64
+#endif
+
+/* For Linux we can use the system call table in the header file
+ /usr/include/asm/unistd.h
+ of the kernel. But these symbols do not follow the SYS_* syntax
+ so we have to redefine the `SYS_ify' macro here. */
+#undef SYS_ify
+#ifdef __STDC__
+# define SYS_ify(syscall_name) __NR_##syscall_name
+#else
+# define SYS_ify(syscall_name) __NR_/**/syscall_name
+#endif
+
+#ifndef __ASSEMBLER__
+
+# include <errno.h>
+
+# ifdef SHARED
+# define INLINE_VSYSCALL(name, nr, args...) \
+ ({ \
+ __label__ out; \
+ __label__ iserr; \
+ INTERNAL_SYSCALL_DECL (sc_err); \
+ long int sc_ret; \
+ \
+ if (__vdso_##name != NULL) \
+ { \
+ sc_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, sc_err, nr, ##args); \
+ if (!INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
+ goto out; \
+ if (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err) != ENOSYS) \
+ goto iserr; \
+ } \
+ \
+ sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, ##args); \
+ if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
+ { \
+ iserr: \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
+ sc_ret = -1L; \
+ } \
+ out: \
+ sc_ret; \
+ })
+# else
+# define INLINE_VSYSCALL(name, nr, args...) \
+ INLINE_SYSCALL (name, nr, ##args)
+# endif
+
+# ifdef SHARED
+# define INTERNAL_VSYSCALL(name, err, nr, args...) \
+ ({ \
+ __label__ out; \
+ long int v_ret; \
+ \
+ if (__vdso_##name != NULL) \
+ { \
+ v_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, err, nr, ##args); \
+ if (!INTERNAL_SYSCALL_ERROR_P (v_ret, err) \
+ || INTERNAL_SYSCALL_ERRNO (v_ret, err) != ENOSYS) \
+ goto out; \
+ } \
+ v_ret = INTERNAL_SYSCALL (name, err, nr, ##args); \
+ out: \
+ v_ret; \
+ })
+# else
+# define INTERNAL_VSYSCALL(name, err, nr, args...) \
+ INTERNAL_SYSCALL (name, err, nr, ##args)
+# endif
+
+# define INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK(name, err, nr, args...) \
+ ({ \
+ long int sc_ret = ENOSYS; \
+ \
+ if (__vdso_##name != NULL) \
+ sc_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, err, nr, ##args); \
+ else \
+ err = 1 << 28; \
+ sc_ret; \
+ })
+
+/* List of system calls which are supported as vsyscalls. */
+# define HAVE_CLOCK_GETRES_VSYSCALL 1
+# define HAVE_CLOCK_GETTIME_VSYSCALL 1
+
+/* Define a macro which expands inline into the wrapper code for a VDSO
+ call. This use is for internal calls that do not need to handle errors
+ normally. It will never touch errno.
+ On powerpc a system call basically clobbers the same registers like a
+ function call, with the exception of LR (which is needed for the
+ "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
+ an error return status). */
+# define INTERNAL_VSYSCALL_NCS(funcptr, err, nr, args...) \
+ ({ \
+ register void *r0 __asm__ ("r0"); \
+ register long int r3 __asm__ ("r3"); \
+ register long int r4 __asm__ ("r4"); \
+ register long int r5 __asm__ ("r5"); \
+ register long int r6 __asm__ ("r6"); \
+ register long int r7 __asm__ ("r7"); \
+ register long int r8 __asm__ ("r8"); \
+ register long int r9 __asm__ ("r9"); \
+ register long int r10 __asm__ ("r10"); \
+ register long int r11 __asm__ ("r11"); \
+ register long int r12 __asm__ ("r12"); \
+ LOADARGS_##nr (funcptr, args); \
+ __asm__ __volatile__ \
+ ("mtctr %0\n\t" \
+ "bctrl\n\t" \
+ "mfcr %0" \
+ : "=&r" (r0), \
+ "=&r" (r3), "=&r" (r4), "=&r" (r5), "=&r" (r6), "=&r" (r7), \
+ "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12) \
+ : ASM_INPUT_##nr \
+ : "cr0", "ctr", "lr", "memory"); \
+ err = (long int) r0; \
+ (int) r3; \
+ })
+
+# undef INLINE_SYSCALL
+# define INLINE_SYSCALL(name, nr, args...) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (sc_err); \
+ long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \
+ if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
+ sc_ret = -1L; \
+ } \
+ sc_ret; \
+ })
+
+/* Define a macro which expands inline into the wrapper code for a system
+ call. This use is for internal calls that do not need to handle errors
+ normally. It will never touch errno.
+ On powerpc a system call basically clobbers the same registers like a
+ function call, with the exception of LR (which is needed for the
+ "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
+ an error return status). */
+
+# undef INTERNAL_SYSCALL_DECL
+# define INTERNAL_SYSCALL_DECL(err) long int err
+
+# undef INTERNAL_SYSCALL
+# define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({ \
+ register long int r0 __asm__ ("r0"); \
+ register long int r3 __asm__ ("r3"); \
+ register long int r4 __asm__ ("r4"); \
+ register long int r5 __asm__ ("r5"); \
+ register long int r6 __asm__ ("r6"); \
+ register long int r7 __asm__ ("r7"); \
+ register long int r8 __asm__ ("r8"); \
+ register long int r9 __asm__ ("r9"); \
+ register long int r10 __asm__ ("r10"); \
+ register long int r11 __asm__ ("r11"); \
+ register long int r12 __asm__ ("r12"); \
+ LOADARGS_##nr(name, args); \
+ __asm__ __volatile__ \
+ ("sc \n\t" \
+ "mfcr %0" \
+ : "=&r" (r0), \
+ "=&r" (r3), "=&r" (r4), "=&r" (r5), "=&r" (r6), "=&r" (r7), \
+ "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12) \
+ : ASM_INPUT_##nr \
+ : "cr0", "ctr", "memory"); \
+ err = r0; \
+ (int) r3; \
+ })
+# define INTERNAL_SYSCALL(name, err, nr, args...) \
+ INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
+
+# undef INTERNAL_SYSCALL_ERROR_P
+# define INTERNAL_SYSCALL_ERROR_P(val, err) \
+ ((void) (val), __builtin_expect ((err) & (1 << 28), 0))
+
+# undef INTERNAL_SYSCALL_ERRNO
+# define INTERNAL_SYSCALL_ERRNO(val, err) (val)
+
+# define LOADARGS_0(name, dummy) \
+ r0 = name
+# define LOADARGS_1(name, __arg1) \
+ long int arg1 = (long int) (__arg1); \
+ LOADARGS_0(name, 0); \
+ extern void __illegally_sized_syscall_arg1 (void); \
+ if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 4) \
+ __illegally_sized_syscall_arg1 (); \
+ r3 = arg1
+# define LOADARGS_2(name, __arg1, __arg2) \
+ long int arg2 = (long int) (__arg2); \
+ LOADARGS_1(name, __arg1); \
+ extern void __illegally_sized_syscall_arg2 (void); \
+ if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 4) \
+ __illegally_sized_syscall_arg2 (); \
+ r4 = arg2
+# define LOADARGS_3(name, __arg1, __arg2, __arg3) \
+ long int arg3 = (long int) (__arg3); \
+ LOADARGS_2(name, __arg1, __arg2); \
+ extern void __illegally_sized_syscall_arg3 (void); \
+ if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 4) \
+ __illegally_sized_syscall_arg3 (); \
+ r5 = arg3
+# define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
+ long int arg4 = (long int) (__arg4); \
+ LOADARGS_3(name, __arg1, __arg2, __arg3); \
+ extern void __illegally_sized_syscall_arg4 (void); \
+ if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 4) \
+ __illegally_sized_syscall_arg4 (); \
+ r6 = arg4
+# define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
+ long int arg5 = (long int) (__arg5); \
+ LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
+ extern void __illegally_sized_syscall_arg5 (void); \
+ if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 4) \
+ __illegally_sized_syscall_arg5 (); \
+ r7 = arg5
+# define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
+ long int arg6 = (long int) (__arg6); \
+ LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
+ extern void __illegally_sized_syscall_arg6 (void); \
+ if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 4) \
+ __illegally_sized_syscall_arg6 (); \
+ r8 = arg6
+
+# define ASM_INPUT_0 "0" (r0)
+# define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
+# define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
+# define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
+# define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
+# define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
+# define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
+
+#endif /* __ASSEMBLER__ */
+
+
+/* Pointer mangling support. */
+#if defined NOT_IN_libc && defined IS_IN_rtld
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+ earlier than the descriptor is initialized. */
+#else
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(reg, tmpreg) \
+ lwz tmpreg,POINTER_GUARD(r2); \
+ xor reg,tmpreg,reg
+# define PTR_MANGLE2(reg, tmpreg) \
+ xor reg,tmpreg,reg
+# define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
+# define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
+# else
+# define PTR_MANGLE(var) \
+ (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+# define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* linux/powerpc/powerpc32/sysdep.h */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c
new file mode 100644
index 000000000..f107e8437
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 1997,1998,1999,2000,2002,2005,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_truncate64
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+/* The variable is shared between all wrappers around *truncate64 calls. */
+int __have_no_truncate64;
+#endif
+
+
+/* Truncate the file FD refers to to LENGTH bytes. */
+int
+truncate64 (path, length)
+ const char *path;
+ off64_t length;
+{
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if (! __have_no_truncate64)
+#endif
+ {
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ int saved_errno = errno;
+#endif
+ /* On PPC32 64bit values are aligned in odd/even register pairs. */
+ int result = INLINE_SYSCALL (truncate64, 4, CHECK_STRING (path), 0,
+ (long) (length >> 32),
+ (long) length);
+
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if (result != -1 || errno != ENOSYS)
+#endif
+ return result;
+
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ __set_errno (saved_errno);
+ __have_no_truncate64 = 1;
+#endif
+ }
+
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if ((off_t) length != length)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ return __truncate (path, (off_t) length);
+#endif
+}
+
+#else
+/* Use the generic implementation. */
+# include <misc/truncate64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.sym b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.sym
new file mode 100644
index 000000000..293761f26
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.sym
@@ -0,0 +1,26 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+--
+
+SIG_BLOCK
+SIG_SETMASK
+
+-- Offsets in ucontext_t.
+#define ucontext(member) offsetof (ucontext_t, member)
+_UC_LINK ucontext (uc_link)
+_UC_STACK_SP ucontext (uc_stack.ss_sp)
+_UC_STACK_SIZE ucontext (uc_stack.ss_size)
+_UC_REGS_PTR ucontext (uc_mcontext.uc_regs)
+_UC_SIGMASK ucontext (uc_sigmask)
+_UC_REG_SPACE ucontext (uc_reg_space)
+
+-- Offsets in mcontext_t.
+#define mcontext(member) offsetof (mcontext_t, member)
+_UC_GREGS mcontext (gregs)
+_UC_FREGS mcontext (fpregs)
+_UC_VREGS mcontext (vrregs)
+_UC_VREGS mcontext (vrregs)
+_UC_VSCR mcontext (vrregs.vscr)
+_UC_VRSAVE mcontext (vrregs.vrsave)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S
new file mode 100644
index 000000000..66a149f10
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S
@@ -0,0 +1,59 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+
+#ifdef __NR_vfork
+
+ DO_CALL (SYS_ify (vfork))
+
+# ifdef __ASSUME_VFORK_SYSCALL
+ PSEUDO_RET
+# else
+ bnslr+
+ /* Check if vfork syscall is known at all. */
+ cmpwi r3,ENOSYS
+ bne- .Lsyscall_error
+
+# endif
+#endif
+
+#ifndef __ASSUME_VFORK_SYSCALL
+ /* If we don't have vfork, fork is close enough. */
+
+ DO_CALL (SYS_ify (fork))
+ bnslr+
+
+.Lsyscall_error:
+ b __syscall_error@local
+#endif
+
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/xstat.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/xstat.c
new file mode 100644
index 000000000..e9869f550
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/xstat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/xstat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/Implies b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/Implies
new file mode 100644
index 000000000..8d91c8009
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/Implies
@@ -0,0 +1 @@
+unix/sysv/linux/wordsize-64
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions
new file mode 100644
index 000000000..8334741ae
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions
@@ -0,0 +1,22 @@
+libc {
+ GLIBC_2.2 {
+ # functions used in other libraries
+
+ # g*
+ glob64;
+
+ # New rlimit interface
+ getrlimit; setrlimit; getrlimit64; setrlimit64;
+
+ # r*
+ readdir64; readdir64_r;
+
+ # s*
+ scandir64;
+ }
+ GLIBC_2.3.4 {
+ getcontext;
+ setcontext;
+ swapcontext;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/brk.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/brk.S
new file mode 100644
index 000000000..f2ac00d4c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/brk.S
@@ -0,0 +1,50 @@
+/* brk system call for Linux. PowerPC64 version.
+ Copyright (C) 1995,96,97,99, 2000,02, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <bp-sym.h>
+#include <bp-asm.h>
+
+ .comm __curbrk,8,8
+ .section ".toc","aw"
+.LC__curbrk:
+ .tc __curbrk[TC],__curbrk
+ .section ".text"
+ENTRY (BP_SYM (__brk))
+ CALL_MCOUNT 1
+ DISCARD_BOUNDS (r3) /* the bounds are meaningless, so toss 'em. */
+
+ stdu r1,-64(r1)
+ cfi_adjust_cfa_offset (64)
+ std r3,48(r1)
+ DO_CALL(SYS_ify(brk))
+ ld r6,48(r1)
+ ld r5,.LC__curbrk@toc(r2)
+ std r3,0(r5)
+ cmpld r6,r3
+ addi r1,r1,64
+ li r3,0
+ blelr+
+ li r3,ENOMEM
+ b JUMPTARGET(__syscall_error)
+END (BP_SYM (__brk))
+
+weak_alias (BP_SYM (__brk), BP_SYM (brk))
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S
new file mode 100644
index 000000000..f1a55e64d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S
@@ -0,0 +1,143 @@
+/* Wrapper around clone system call. PowerPC64 version.
+ Copyright (C) 1997,98,99,2000,02,04, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <bp-sym.h>
+#include <bp-asm.h>
+
+#define CLONE_VM 0x00000100
+#define CLONE_THREAD 0x00010000
+
+/* This is the only really unusual system call in PPC linux, but not
+ because of any weirdness in the system call itself; because of
+ all the freaky stuff we have to do to make the call useful. */
+
+/* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
+ int flags [r5], void *arg [r6], void *parent_tid [r7],
+ void *tls [r8], void *child_tid [r9]); */
+
+ENTRY (BP_SYM (__clone))
+ CALL_MCOUNT 7
+ /* GKM FIXME: add bounds checks, where sensible. */
+ DISCARD_BOUNDS (r4)
+ DISCARD_BOUNDS (r6)
+
+ /* Check for child_stack == NULL || fn == NULL. */
+ cmpdi cr0,r4,0
+ cmpdi cr1,r3,0
+ cror cr0*4+eq,cr1*4+eq,cr0*4+eq
+ beq- cr0,L(badargs)
+
+ /* Set up stack frame for parent. */
+ stdu r1,-80(r1)
+ cfi_adjust_cfa_offset (80)
+ std r29,56(r1)
+ std r30,64(r1)
+ std r31,72(r1)
+ cfi_offset(r29,-56)
+ cfi_offset(r30,-64)
+ cfi_offset(r31,-72)
+#ifdef RESET_PID
+ std r28,48(r1)
+ cfi_offset(r28,-48)
+#endif
+
+ /* Set up stack frame for child. */
+ clrrdi r4,r4,4
+ li r0,0
+ stdu r0,-48(r4) /* min stack frame is 48 bytes per ABI */
+
+ /* Save fn, args, stack across syscall. */
+ mr r29,r3 /* Function in r29. */
+ mr r30,r4 /* Stack pointer in r30. */
+#ifdef RESET_PID
+ mr r28,r5 /* Flags in r28. */
+#endif
+ mr r31,r6 /* Argument in r31. */
+
+ /* 'flags' argument is first parameter to clone syscall. (The other
+ argument is the stack pointer, already in r4.) */
+ mr r3,r5
+ /* Move the parent_tid, child_tid and tls arguments. */
+ mr r5,r7
+ mr r6,r8
+ mr r7,r9
+
+ /* End FDE now, because in the child the unwind info will be
+ wrong. */
+ cfi_endproc
+
+ /* Do the call. */
+ DO_CALL(SYS_ify(clone))
+
+ /* Check for child process. */
+ cmpdi cr1,r3,0
+ crandc cr1*4+eq,cr1*4+eq,cr0*4+so
+ bne- cr1,L(parent) /* The '-' is to minimise the race. */
+
+#ifdef RESET_PID
+ andis. r0,r28,CLONE_THREAD>>16
+ bne+ cr0,L(oldpid)
+ andi. r0,r28,CLONE_VM
+ li r3,-1
+ bne- cr0,L(nomoregetpid)
+ DO_CALL(SYS_ify(getpid))
+L(nomoregetpid):
+ stw r3,TID(r13)
+ stw r3,PID(r13)
+L(oldpid):
+#endif
+
+ std r2,40(r1)
+ /* Call procedure. */
+ ld r0,0(r29)
+ ld r2,8(r29)
+ mtctr r0
+ mr r3,r31
+ bctrl
+ ld r2,40(r1)
+ /* Call _exit with result from procedure. */
+#ifdef SHARED
+ b JUMPTARGET(__GI__exit)
+#else
+ b JUMPTARGET(_exit)
+#endif
+
+L(parent):
+ /* Parent. Restore registers & return. */
+#ifdef RESET_PID
+ ld r28,48(r1)
+#endif
+ ld r31,72(r1)
+ ld r30,64(r1)
+ ld r29,56(r1)
+ addi r1,r1,80
+ bnslr+
+ b JUMPTARGET(__syscall_error)
+
+L(badargs):
+ li r3,EINVAL
+ b JUMPTARGET(__syscall_error)
+
+ cfi_startproc
+END (BP_SYM (__clone))
+
+weak_alias (BP_SYM (__clone), BP_SYM (clone))
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/dl-cache.h b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/dl-cache.h
new file mode 100644
index 000000000..c12655834
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/dl-cache.h
@@ -0,0 +1,25 @@
+/* Support for reading /etc/ld.so.cache files written by Linux ldconfig.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define _DL_CACHE_DEFAULT_ID 0x503
+
+#define _dl_cache_check_flags(flags) \
+ ((flags) == _DL_CACHE_DEFAULT_ID)
+
+#include_next <dl-cache.h>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c
new file mode 100644
index 000000000..e7ec85de6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c
@@ -0,0 +1,72 @@
+/* Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <sysdep-cancel.h> /* Must come before <fcntl.h>. */
+#include <fcntl.h>
+#include <stdarg.h>
+
+#include <sys/syscall.h>
+
+
+#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 INLINE_SYSCALL (fcntl, 3, 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 (cmd >= F_GETLK64 && cmd <= F_SETLKW64)
+ cmd -= F_GETLK64 - F_GETLK;
+
+ if (SINGLE_THREAD_P || cmd != F_SETLKW)
+ return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = INLINE_SYSCALL (fcntl, 3, 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/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fe_nomask.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fe_nomask.c
new file mode 100644
index 000000000..62f735514
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fe_nomask.c
@@ -0,0 +1,43 @@
+/* Procedure definition for FE_NOMASK_ENV for Linux/ppc64.
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <fenv.h>
+#include <errno.h>
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <sys/prctl.h>
+#include <kernel-features.h>
+
+const fenv_t *
+__fe_nomask_env (void)
+{
+#if defined PR_SET_FPEXC && defined PR_FP_EXC_PRECISE
+ int result;
+ INTERNAL_SYSCALL_DECL (err);
+ result = INTERNAL_SYSCALL (prctl, err, 2, PR_SET_FPEXC, PR_FP_EXC_PRECISE);
+# ifndef __ASSUME_NEW_PRCTL_SYSCALL
+ if (INTERNAL_SYSCALL_ERROR_P (result, err)
+ && INTERNAL_SYSCALL_ERRNO (result, err) == EINVAL)
+ __set_errno (ENOSYS);
+# endif
+#else
+ __set_errno (ENOSYS);
+#endif
+ return FE_ENABLED_ENV;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fpu/Implies b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fpu/Implies
new file mode 100644
index 000000000..6243d2ef2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/fpu/Implies
@@ -0,0 +1,2 @@
+# Override ldbl-opt with powerpc64 specific routines.
+powerpc/powerpc64/fpu
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S
new file mode 100644
index 000000000..8d7c959ff
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S
@@ -0,0 +1,411 @@
+/* Save current context.
+ Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#include <rtld-global-offsets.h>
+#include <shlib-compat.h>
+#include <kernel-features.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include <asm/errno.h>
+#include "ucontext_i.h"
+
+
+#if SHLIB_COMPAT (libc, GLIBC_2_3, GLIBC_2_3_4)
+ENTRY(__novec_getcontext)
+ CALL_MCOUNT 1
+#ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL
+ std r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r3)
+ std r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r3)
+ mflr r0
+ std r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r3)
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r3)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset (128)
+ std r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r3)
+ std r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r3)
+ std r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r3)
+ std r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r3)
+ std r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r3)
+ std r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r3)
+ std r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r3)
+ std r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r3)
+ std r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r3)
+ std r13,(SIGCONTEXT_GP_REGS+(PT_R13*8))(r3)
+ std r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r3)
+ std r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r3)
+ std r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r3)
+ std r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r3)
+ std r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r3)
+ std r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r3)
+ std r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r3)
+ std r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r3)
+ std r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r3)
+ std r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r3)
+ std r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r3)
+ std r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r3)
+ std r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r3)
+ std r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r3)
+ std r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r3)
+ std r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r3)
+ std r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r3)
+ std r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r3)
+ mfctr r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_CTR*8))(r3)
+ mfxer r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r3)
+ mfcr r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r3)
+
+ /* Set the return value of swapcontext to "success". R3 is the only
+ register whose value is not preserved in the saved context. */
+ li r0,0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r3)
+
+ /* Zero fill fields that can't be set in user state or are unused. */
+ std r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(34*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_SOFTE*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(40*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(41*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(42*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_RESULT*8))(r3)
+
+ /* Set the PT_REGS pointer to the address of sigcontext's gp_regs
+ field. Struct pt_regs and elf_gregset_t are the same thing.
+ We kept the regs field for backwards compatibility with
+ libraries built before we extended sigcontext. */
+ addi r0,r3,SIGCONTEXT_GP_REGS
+ std r0,SIGCONTEXT_PT_REGS(r3)
+
+ stfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r3)
+ stfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r3)
+ stfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r3)
+ stfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r3)
+ stfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r3)
+ stfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r3)
+ stfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r3)
+ stfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r3)
+ stfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r3)
+ stfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r3)
+ stfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r3)
+ stfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r3)
+ stfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r3)
+ stfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r3)
+ stfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r3)
+ stfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r3)
+ stfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r3)
+ stfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r3)
+ stfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r3)
+ stfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r3)
+ stfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r3)
+ stfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r3)
+ stfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r3)
+ stfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r3)
+ stfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r3)
+ stfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r3)
+ stfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r3)
+ stfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r3)
+ stfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r3)
+ stfd fp29,(SIGCONTEXT_FP_REGS+(PT_R29*8))(r3)
+ mffs fp0
+ stfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r3)
+ stfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r3)
+ stfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r3)
+
+ addi r5,r3,UCONTEXT_SIGMASK
+ li r4,0
+ li r3,SIG_BLOCK
+ bl JUMPTARGET(__sigprocmask)
+ nop
+#else
+ /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */
+ mflr r0
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset(128)
+ li r3,ENOSYS
+ bl JUMPTARGET(__syscall_error)
+ nop
+ li r3,-1
+#endif
+
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ blr
+PSEUDO_END(__novec_getcontext)
+
+compat_symbol (libc, __novec_getcontext, getcontext, GLIBC_2_3)
+
+#endif
+
+ .section ".toc","aw"
+.LC__dl_hwcap:
+#ifdef SHARED
+ .tc _rtld_global_ro[TC],_rtld_global_ro
+#else
+ .tc _dl_hwcap[TC],_dl_hwcap
+#endif
+ .section ".text"
+
+ .machine "altivec"
+ENTRY(__getcontext)
+ CALL_MCOUNT 1
+#ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL
+ std r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r3)
+ std r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r3)
+ mflr r0
+ std r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r3)
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r3)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset (128)
+ std r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r3)
+ std r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r3)
+ std r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r3)
+ std r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r3)
+ std r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r3)
+ std r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r3)
+ std r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r3)
+ std r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r3)
+ std r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r3)
+ std r13,(SIGCONTEXT_GP_REGS+(PT_R13*8))(r3)
+ std r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r3)
+ std r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r3)
+ std r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r3)
+ std r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r3)
+ std r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r3)
+ std r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r3)
+ std r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r3)
+ std r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r3)
+ std r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r3)
+ std r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r3)
+ std r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r3)
+ std r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r3)
+ std r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r3)
+ std r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r3)
+ std r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r3)
+ std r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r3)
+ std r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r3)
+ std r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r3)
+ mfctr r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_CTR*8))(r3)
+ mfxer r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r3)
+ mfcr r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r3)
+
+ /* Set the return value of swapcontext to "success". R3 is the only
+ register whose value is not preserved in the saved context. */
+ li r0,0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r3)
+
+ /* Zero fill fields that can't be set in user state or are unused. */
+ std r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(34*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_SOFTE*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(40*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(41*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(42*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_RESULT*8))(r3)
+
+ /* Set the PT_REGS pointer to the address of sigcontext's gp_regs
+ field. Struct pt_regs and elf_gregset_t are the same thing.
+ We kept the regs field for backwards compatibility with
+ libraries built before we extended sigcontext. */
+ addi r0,r3,SIGCONTEXT_GP_REGS
+ std r0,SIGCONTEXT_PT_REGS(r3)
+
+ stfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r3)
+ stfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r3)
+ stfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r3)
+ stfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r3)
+ stfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r3)
+ stfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r3)
+ stfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r3)
+ stfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r3)
+ stfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r3)
+ stfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r3)
+ stfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r3)
+ stfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r3)
+ stfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r3)
+ stfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r3)
+ stfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r3)
+ stfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r3)
+ stfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r3)
+ stfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r3)
+ stfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r3)
+ stfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r3)
+ stfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r3)
+ stfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r3)
+ stfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r3)
+ stfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r3)
+ stfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r3)
+ stfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r3)
+ stfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r3)
+ stfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r3)
+ stfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r3)
+ stfd fp29,(SIGCONTEXT_FP_REGS+(PT_R29*8))(r3)
+ mffs fp0
+ stfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r3)
+ stfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r3)
+ stfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r3)
+
+ ld r5,.LC__dl_hwcap@toc(r2)
+# ifdef SHARED
+/* Load _rtld-global._dl_hwcap. */
+ ld r5,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r5)
+# else
+ ld r5,0(r5) /* Load extern _dl_hwcap. */
+# endif
+ la r10,(SIGCONTEXT_V_RESERVE+8)(r3)
+ la r9,(SIGCONTEXT_V_RESERVE+24)(r3)
+
+ andis. r5,r5,(PPC_FEATURE_HAS_ALTIVEC >> 16)
+
+ clrrdi r10,r10,4
+ beq L(has_no_vec)
+ clrrdi r9,r9,4
+ mr r5,r10 /* Capture *v_regs value in r5. */
+
+ stvx v0,0,r10
+ stvx v1,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v2,0,r10
+ stvx v3,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v4,0,r10
+ stvx v5,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v6,0,r10
+ stvx v7,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v8,0,r10
+ stvx v9,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v10,0,r10
+ stvx v11,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v12,0,r10
+ stvx v13,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v14,0,r10
+ stvx v15,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v16,0,r10
+ stvx v17,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v18,0,r10
+ stvx v19,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v20,0,r10
+ stvx v21,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v22,0,r10
+ stvx v23,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v24,0,r10
+ stvx v25,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v26,0,r10
+ stvx v27,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v28,0,r10
+ stvx v29,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v30,0,r10
+ stvx v31,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ mfvscr v0
+ mfspr r0,VRSAVE
+ stvx v0,0,r10
+ stw r0,0(9)
+
+L(has_no_vec):
+/*
+ Store either a NULL or a quadword aligned pointer to the Vector register
+ array into *v_regs.
+*/
+ std r5,(SIGCONTEXT_V_REGS_PTR)(r3)
+
+ addi r5,r3,UCONTEXT_SIGMASK
+ li r4,0
+ li r3,SIG_BLOCK
+ bl JUMPTARGET(__sigprocmask)
+ nop
+#else
+ /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */
+ mflr r0
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset (128)
+ li r3,ENOSYS
+ bl JUMPTARGET(__syscall_error)
+ nop
+ li r3,-1
+#endif
+
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ blr
+PSEUDO_END(__getcontext)
+
+versioned_symbol (libc, __getcontext, getcontext, GLIBC_2_3_4)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/kernel_stat.h b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/kernel_stat.h
new file mode 100644
index 000000000..8a43ea4a1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/kernel_stat.h
@@ -0,0 +1,21 @@
+/* Definition of `struct stat' used in the kernel.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define STAT_IS_KERNEL_STAT 1
+#define XSTAT_IS_XSTAT64 1
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/ldsodefs.h b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/ldsodefs.h
new file mode 100644
index 000000000..1ead3dd63
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/ldsodefs.h
@@ -0,0 +1,77 @@
+/* Run-time dynamic linker data structures for loaded ELF shared objects.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LDSODEFS_H
+
+/* Get the real definitions. */
+#include_next <ldsodefs.h>
+
+/* Now define our stuff. */
+
+static __always_inline bool
+_dl_ppc64_is_opd_sym (const struct link_map *l, const ElfW(Sym) *sym)
+{
+ return (ELFW(ST_TYPE) (sym->st_info) == STT_FUNC
+ && l->l_addr + sym->st_value >= (ElfW(Addr)) l->l_ld
+ && l->l_addr + sym->st_value < l->l_map_end
+ && sym->st_size != 0);
+}
+
+static __always_inline bool
+_dl_ppc64_addr_sym_match (const struct link_map *l, const ElfW(Sym) *sym,
+ const ElfW(Sym) *matchsym, ElfW(Addr) addr)
+{
+ ElfW(Addr) value = l->l_addr + sym->st_value;
+ if (_dl_ppc64_is_opd_sym (l, sym))
+ {
+ if (addr < value || addr >= value + 24)
+ {
+ value = *(ElfW(Addr) *) value;
+ if (addr < value || addr >= value + sym->st_size)
+ return false;
+ }
+ }
+ else if (sym->st_size == 0)
+ {
+ if (addr != value)
+ return false;
+ }
+ else if (addr < value || addr >= value + sym->st_size)
+ return false;
+
+ if (matchsym == NULL)
+ return true;
+
+ ElfW(Addr) matchvalue = l->l_addr + matchsym->st_value;
+ if (_dl_ppc64_is_opd_sym (l, matchsym)
+ && (addr < matchvalue || addr > matchvalue + 24))
+ matchvalue = *(ElfW(Addr) *) matchvalue;
+
+ return matchvalue < value;
+}
+
+/* If this is a function symbol defined past the end of our dynamic
+ section, then it must be a function descriptor. Allow these symbols
+ to match their associated function code range as well as the
+ descriptor addresses. */
+#undef DL_ADDR_SYM_MATCH
+#define DL_ADDR_SYM_MATCH(L, SYM, MATCHSYM, ADDR) \
+ _dl_ppc64_addr_sym_match (L, SYM, MATCHSYM, ADDR)
+
+#endif /* ldsodefs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S
new file mode 100644
index 000000000..4a82802d9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S
@@ -0,0 +1,187 @@
+/* Create new context.
+ Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#include <kernel-features.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include "ucontext_i.h"
+#include <asm/errno.h>
+
+ENTRY(__makecontext)
+ CALL_MCOUNT 3
+#ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL
+ /* Save parameters into the parameter save area of callers frame. */
+ std r3,FRAME_PARM1_SAVE(r1) /* ucontext_t *ucp */
+ std r4,FRAME_PARM2_SAVE(r1) /* void (*func)(void) */
+ std r5,FRAME_PARM3_SAVE(r1) /* int argc */
+ std r6,FRAME_PARM4_SAVE(r1) /* ... */
+ std r7,FRAME_PARM5_SAVE(r1)
+ std r8,FRAME_PARM6_SAVE(r1)
+ std r9,FRAME_PARM7_SAVE(r1)
+ std r10,FRAME_PARM8_SAVE(r1)
+ mflr r0
+ /* Get the address of the target functions first parameter. */
+ addi r6,r1,FRAME_PARM4_SAVE
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset (128)
+
+ /* Get the ucontexts stack pointer and size. Compute the top of stack
+ and round down to a quadword boundary. Then stack a dummy frame
+ with a null back chain. We store the context pointer in the frames
+ "compiler double word" field so we can recover if is the function
+ returns. Finally save the callers link register and TOC pointer
+ into this frame so the debugger can display a backtrace.
+ */
+ ld r7,UCONTEXT_STACK_SP(r3)
+ ld r0,UCONTEXT_STACK_SIZE(r3)
+ add r7,r7,r0
+ clrrdi r7,r7,4
+ li r0,0
+ stdu r0,-64(r7)
+ std r3,FRAME_PARM1_SAVE(r7) /* Store context in dummy parm1. */
+ mflr r0
+ std r2,FRAME_TOC_SAVE(r7) /* Store the TOC pointer for later. */
+ std r0,FRAME_LR_SAVE(r7)
+
+ /* Now we need to stack another frame to hold the parameter save area
+ for the function. We need to allocate a frame with the minimum 48
+ byte header and 8 parameter register. However if there are more
+ than 8 parameters addition space is need to hold all the parameters.
+ The total size it rounded up to a quadword multiple then a frame is
+ stacked. This address is stored in the ucontext as GPR 1. */
+
+ cmpdi cr1,r5,8
+ sldi r8,r5,3
+ bgt cr1,L(gt8)
+ li r8,64
+L(gt8):
+ addi r8,r8,FRAME_PARM_SAVE+8 /* Add header plus rounding factor. */
+ clrrdi r8,r8,4 /* Round down to quadword. */
+
+ subf r8,r8,r7
+ std r7,0(r8) /* Stack the frame. */
+ std r8,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r3)
+
+ /* Now we need to copy the target functions parameters. The functions
+ parameters are saved in the parameter save area. We skip over the
+ first three parameters and copy up to 8 double word into the
+ SIGCONTEXT_GP_REGS starting with R3. If there are more than 8
+ parameters then doublewords 8-N are copied into the parameter
+ save area of the context frame. */
+ cmpdi r5,0
+ beq L(noparms)
+ mr r0,r5
+ ble cr1,L(le8)
+ li r0,8
+L(le8):
+ mtctr r0
+ addi r7,r6,-8
+ addi r9,r3,(SIGCONTEXT_GP_REGS+(PT_R3*8)-8)
+L(parmloop2):
+ ldu r0,8(r7)
+ stdu r0,8(r9)
+ bdnz L(parmloop2)
+
+ addi r0,r5,-8
+ ble cr1,L(noparms)
+ mtctr r0
+ addi r9,r8,FRAME_PARM9_SAVE-8
+L(parmloop):
+ ldu r0,8(r7)
+ stdu r0,8(r9)
+ bdnz L(parmloop)
+
+L(noparms):
+
+ /* Load the function address and TOC from the function descriptor
+ and store them in the ucontext as NIP and r2. Store the 3rd
+ field of the function descriptor into the ucontext as r11 in case
+ the calling language needs the "environment pointer". */
+ ld r0,0(r4)
+ ld r10,8(r4);
+ ld r9,16(r4);
+ std r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r3)
+ std r10,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r3)
+ std r9,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r3)
+
+ /* If the target function returns we need to do some cleanup. We use a
+ code trick to get the address of our cleanup function into the link
+ register. Do not add any code between here and L(exitcode). */
+ bl L(gotexitcodeaddr);
+
+ /* This is the helper code which gets called if a function which
+ is registered with 'makecontext' returns. In this case we
+ have to install the context listed in the uc_link element of
+ the context 'makecontext' manipulated at the time of the
+ 'makecontext' call. If the pointer is NULL the process must
+ terminate. */
+L(exitcode):
+ /* Recover the ucontext and TOC from the dummy frame. */
+ ld r1,FRAME_BACKCHAIN(r1) /* Unstack the parameter save area frame. */
+ ld r3,FRAME_PARM1_SAVE(r1)
+ ld r2,FRAME_TOC_SAVE(r1)
+ ld r3,UCONTEXT_LINK(r3) /* Load the resume context. */
+ cmpdi r3,0
+ beq L(BADSTATUS)
+ bl JUMPTARGET(__setcontext)
+ nop
+
+L(BADSTATUS):
+/* If setcontext returns (which can happen if the syscall fails) we will
+ exit the program with error status (-1). */
+ li r3,-1
+#ifdef SHARED
+ b JUMPTARGET(__GI_exit);
+#else
+ b JUMPTARGET(exit);
+#endif
+
+ /* The address of the exit code is in the link register. Store the lr
+ in the ucontext as LNK so the target function will return to our
+ exit code. */
+L(gotexitcodeaddr):
+ mflr r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r3)
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ blr
+#else
+ /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */
+ mflr r0
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset (128)
+ li r3,ENOSYS
+ bl JUMPTARGET(__syscall_error)
+ nop
+ li r3,-1
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ blr
+#endif
+END(__makecontext)
+
+weak_alias (__makecontext, makecontext)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pread.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pread.c
new file mode 100644
index 000000000..315d1195e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pread.c
@@ -0,0 +1,85 @@
+/* Copyright (C) 1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
+
+# if __ASSUME_PREAD_SYSCALL == 0
+static ssize_t __emulate_pread (int fd, void *buf, size_t count,
+ off_t offset) internal_function;
+# endif
+
+
+ssize_t
+__libc_pread (fd, buf, count, offset)
+ int fd;
+ void *buf;
+ size_t count;
+ off_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ result = INLINE_SYSCALL (pread, 4, fd, CHECK_N (buf, count), count,
+ offset);
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread (fd, buf, count, offset);
+# endif
+
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ result = INLINE_SYSCALL (pread, 4, fd, CHECK_N (buf, count), count,
+ offset);
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+strong_alias (__libc_pread, __pread)
+weak_alias (__libc_pread, pread)
+
+# define __libc_pread(fd, buf, count, offset) \
+ static internal_function __emulate_pread (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PREAD_SYSCALL == 0
+# include <sysdeps/posix/pread.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pread64.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pread64.c
new file mode 100644
index 000000000..f775e1f1e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pread64.c
@@ -0,0 +1,84 @@
+/* Copyright (C) 1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
+
+# if __ASSUME_PREAD_SYSCALL == 0
+static ssize_t __emulate_pread64 (int fd, void *buf, size_t count,
+ off64_t offset) internal_function;
+# endif
+
+
+ssize_t
+__libc_pread64 (fd, buf, count, offset)
+ int fd;
+ void *buf;
+ size_t count;
+ off64_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ result = INLINE_SYSCALL (pread, 4, fd, CHECK_N (buf, count), count,
+ offset);
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread64 (fd, buf, count, offset);
+# endif
+
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ result = INLINE_SYSCALL (pread, 4, fd, CHECK_N (buf, count), count,
+ offset);
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread64 (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+weak_alias (__libc_pread64, __pread64)
+weak_alias (__libc_pread64, pread64)
+
+# define __libc_pread64(fd, buf, count, offset) \
+ static internal_function __emulate_pread64 (fd, buf, count, offset)
+#endif
+
+# if __ASSUME_PREAD_SYSCALL == 0
+# include <sysdeps/posix/pread64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pwrite.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pwrite.c
new file mode 100644
index 000000000..0f509154e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pwrite.c
@@ -0,0 +1,85 @@
+/* Copyright (C) 1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
+
+# if __ASSUME_PWRITE_SYSCALL == 0
+static ssize_t __emulate_pwrite (int fd, const void *buf, size_t count,
+ off_t offset) internal_function;
+# endif
+
+
+ssize_t
+__libc_pwrite (fd, buf, count, offset)
+ int fd;
+ const void *buf;
+ size_t count;
+ off_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ result = INLINE_SYSCALL (pwrite, 4, fd, CHECK_N (buf, count), count,
+ offset);
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite (fd, buf, count, offset);
+# endif
+
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ result = INLINE_SYSCALL (pwrite, 4, fd, CHECK_N (buf, count), count,
+ offset);
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+strong_alias (__libc_pwrite, __pwrite)
+weak_alias (__libc_pwrite, pwrite)
+
+# define __libc_pwrite(fd, buf, count, offset) \
+ static internal_function __emulate_pwrite (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PWRITE_SYSCALL == 0
+# include <sysdeps/posix/pwrite.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pwrite64.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pwrite64.c
new file mode 100644
index 000000000..22224324a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/pwrite64.c
@@ -0,0 +1,85 @@
+/* Copyright (C) 1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
+
+# if __ASSUME_PWRITE_SYSCALL == 0
+static ssize_t __emulate_pwrite64 (int fd, const void *buf, size_t count,
+ off64_t offset) internal_function;
+# endif
+
+
+ssize_t
+__libc_pwrite64 (fd, buf, count, offset)
+ int fd;
+ const void *buf;
+ size_t count;
+ off64_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ result = INLINE_SYSCALL (pwrite, 4, fd, CHECK_N (buf, count), count,
+ offset);
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite64 (fd, buf, count, offset);
+# endif
+
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ result = INLINE_SYSCALL (pwrite, 4, fd, CHECK_N (buf, count), count,
+ offset);
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite64 (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+weak_alias (__libc_pwrite64, __pwrite64)
+libc_hidden_weak (__pwrite64)
+weak_alias (__libc_pwrite64, pwrite64)
+
+# define __libc_pwrite64(fd, buf, count, offset) \
+ static internal_function __emulate_pwrite64 (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PWRITE_SYSCALL == 0
+# include <sysdeps/posix/pwrite64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S
new file mode 100644
index 000000000..48e9af363
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S
@@ -0,0 +1,469 @@
+/* Switch to context.
+ Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#include <rtld-global-offsets.h>
+#include <shlib-compat.h>
+#include <kernel-features.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include "ucontext_i.h"
+#include <asm/errno.h>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_3, GLIBC_2_3_4)
+ENTRY(__novec_setcontext)
+ CALL_MCOUNT 1
+#ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL
+ mflr r0
+ std r31,-8(1)
+ cfi_offset(r31,-8)
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset (128)
+ mr r31,r3
+
+/*
+ * If this ucontext refers to the point where we were interrupted
+ * by a signal, we have to use the rt_sigreturn system call to
+ * return to the context so we get both LR and CTR restored.
+ *
+ * Otherwise, the context we are restoring is either just after
+ * a procedure call (getcontext/swapcontext) or at the beginning
+ * of a procedure call (makecontext), so we don't need to restore
+ * msr and ctr. We don't restore r13 since it will be used as
+ * the TLS pointer. */
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r31)
+ cmpdi r0,0
+ bne L(nv_do_sigret)
+
+ li r5,0
+ addi r4,r3,UCONTEXT_SIGMASK
+ li r3,SIG_SETMASK
+ bl JUMPTARGET(__sigprocmask)
+ nop
+ cmpdi r3,0
+ bne L(nv_error_exit)
+
+ lfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r31)
+ lfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r31)
+ lfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r31)
+ mtfsf 0xff,fp0
+ lfd fp29,(SIGCONTEXT_FP_REGS+(PT_R29*8))(r31)
+ lfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r31)
+ lfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r31)
+ lfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r31)
+ lfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r31)
+ lfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r31)
+ lfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r31)
+ lfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r31)
+ lfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r31)
+ lfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r31)
+ lfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r31)
+ lfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r31)
+ lfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r31)
+ lfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r31)
+ lfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r31)
+ lfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r31)
+ lfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r31)
+ lfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r31)
+ lfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r31)
+ lfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r31)
+ lfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r31)
+ lfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r31)
+ lfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r31)
+ lfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r31)
+ lfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r31)
+ lfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r31)
+ lfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r31)
+ lfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r31)
+ lfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r31)
+ lfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r31)
+
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r31)
+ ld r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r31)
+ mtlr r0
+ ld r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r31)
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r31)
+ ld r3,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r31)
+ mtxer r0
+ ld r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r31)
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r31)
+ ld r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r31)
+ mtcr r0
+ ld r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r31)
+ ld r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r31)
+ ld r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r31)
+ ld r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r31)
+ ld r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r31)
+ ld r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r31)
+ ld r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r31)
+ /* Don't reload the thread ID or TLS pointer (r13). */
+ ld r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r31)
+ ld r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r31)
+ ld r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r31)
+ ld r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r31)
+ ld r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r31)
+ ld r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r31)
+ ld r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r31)
+ ld r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r31)
+ ld r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r31)
+ ld r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r31)
+ ld r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r31)
+ ld r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r31)
+ ld r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r31)
+ ld r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r31)
+ ld r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r31)
+ ld r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r31)
+ ld r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r31)
+
+ /* Now we branch to the "Next Instruction Pointer" from the saved
+ context. With the powerpc64 instruction set there is no good way to
+ do this (from user state) without clobbering either the LR or CTR.
+ The makecontext and swapcontext functions depend on the callers
+ LR being preserved so we use the CTR. */
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r31)
+ mtctr r0
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r31)
+ ld r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r31)
+ bctr
+
+L(nv_error_exit):
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ ld r31,-8(r1)
+ blr
+
+ /* At this point we assume that the ucontext was created by a
+ rt_signal and we should use rt_sigreturn to restore the original
+ state. As of the 2.4.21 kernel the ucontext is the first thing
+ (offset 0) in the rt_signal frame and rt_sigreturn expects the
+ ucontext address in R1. Normally the rt-signal trampoline handles
+ this by popping dummy frame before the rt_signal syscall. In our
+ case the stack may not be in its original (signal handler return with
+ R1 pointing at the dummy frame) state. We do have the ucontext
+ address in R3, so simply copy R3 to R1 before the syscall. */
+L(nv_do_sigret):
+ mr r1,r3,
+ li r0,SYS_ify(rt_sigreturn)
+ sc
+ /* No return. */
+#else
+ /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */
+ mflr r0
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset(lr,FRAME_LR_SAVE)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset(128)
+ li r3,ENOSYS
+ bl JUMPTARGET(__syscall_error)
+ nop
+ li r3,-1
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ blr
+#endif
+
+PSEUDO_END(__novec_setcontext)
+
+compat_symbol (libc, __novec_setcontext, setcontext, GLIBC_2_3)
+
+#endif
+
+ .section ".toc","aw"
+.LC__dl_hwcap:
+#ifdef SHARED
+ .tc _rtld_global_ro[TC],_rtld_global_ro
+#else
+ .tc _dl_hwcap[TC],_dl_hwcap
+#endif
+ .section ".text"
+
+ .machine "altivec"
+ENTRY(__setcontext)
+ CALL_MCOUNT 1
+#ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL
+ mflr r0
+ std r31,-8(1)
+ cfi_offset(r31,-8)
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset (128)
+ mr r31,r3
+
+/*
+ * If this ucontext refers to the point where we were interrupted
+ * by a signal, we have to use the rt_sigreturn system call to
+ * return to the context so we get both LR and CTR restored.
+ *
+ * Otherwise, the context we are restoring is either just after
+ * a procedure call (getcontext/swapcontext) or at the beginning
+ * of a procedure call (makecontext), so we don't need to restore
+ * msr and ctr. We don't restore r13 since it will be used as
+ * the TLS pointer. */
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r31)
+ cmpdi r0,0
+ bne L(do_sigret)
+
+ li r5,0
+ addi r4,r3,UCONTEXT_SIGMASK
+ li r3,SIG_SETMASK
+ bl JUMPTARGET(__sigprocmask)
+ nop
+ cmpdi r3,0
+ bne L(error_exit)
+
+ ld r5,.LC__dl_hwcap@toc(r2)
+ ld r10,(SIGCONTEXT_V_REGS_PTR)(r31)
+# ifdef SHARED
+/* Load _rtld-global._dl_hwcap. */
+ ld r5,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r5)
+# else
+ ld r5,0(r5) /* Load extern _dl_hwcap. */
+# endif
+ andis. r5,r5,(PPC_FEATURE_HAS_ALTIVEC >> 16)
+ beq L(has_no_vec)
+
+ cmpdi r10,0
+ beq L(has_no_vec)
+ lwz r0,(33*16)(r10)
+
+ li r9,(16*32)
+ mtspr VRSAVE,r0
+ cmpwi r0,0
+ beq L(has_no_vec)
+
+ lvx v19,r9,r10
+ la r9,(16)(r10)
+
+ lvx v0,0,r10
+ lvx v1,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ mtvscr v19
+ lvx v2,0,r10
+ lvx v3,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v4,0,r10
+ lvx v5,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v6,0,r10
+ lvx v7,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v8,0,r10
+ lvx v9,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v10,0,r10
+ lvx v11,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v12,0,r10
+ lvx v13,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v14,0,r10
+ lvx v15,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v16,0,r10
+ lvx v17,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v18,0,r10
+ lvx v19,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v20,0,r10
+ lvx v21,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v22,0,r10
+ lvx v23,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v24,0,r10
+ lvx v25,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v26,0,r10
+ lvx v27,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v28,0,r10
+ lvx v29,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v30,0,r10
+ lvx v31,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v10,0,r10
+ lvx v11,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+L(has_no_vec):
+ lfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r31)
+ lfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r31)
+ lfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r31)
+ mtfsf 0xff,fp0
+ lfd fp29,(SIGCONTEXT_FP_REGS+(PT_R29*8))(r31)
+ lfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r31)
+ lfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r31)
+ lfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r31)
+ lfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r31)
+ lfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r31)
+ lfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r31)
+ lfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r31)
+ lfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r31)
+ lfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r31)
+ lfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r31)
+ lfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r31)
+ lfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r31)
+ lfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r31)
+ lfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r31)
+ lfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r31)
+ lfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r31)
+ lfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r31)
+ lfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r31)
+ lfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r31)
+ lfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r31)
+ lfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r31)
+ lfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r31)
+ lfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r31)
+ lfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r31)
+ lfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r31)
+ lfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r31)
+ lfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r31)
+ lfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r31)
+ lfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r31)
+
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r31)
+ ld r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r31)
+ mtlr r0
+ ld r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r31)
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r31)
+ ld r3,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r31)
+ mtxer r0
+ ld r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r31)
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r31)
+ ld r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r31)
+ ld r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r31)
+ ld r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r31)
+ ld r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r31)
+ ld r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r31)
+ mtcr r0
+ ld r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r31)
+ ld r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r31)
+ ld r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r31)
+ /* Don't reload the thread ID or TLS pointer (r13). */
+ ld r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r31)
+ ld r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r31)
+ ld r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r31)
+ ld r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r31)
+ ld r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r31)
+ ld r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r31)
+ ld r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r31)
+ ld r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r31)
+ ld r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r31)
+ ld r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r31)
+ ld r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r31)
+ ld r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r31)
+ ld r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r31)
+ ld r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r31)
+ ld r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r31)
+ ld r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r31)
+ ld r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r31)
+
+ /* Now we branch to the "Next Instruction Pointer" from the saved
+ context. With the powerpc64 instruction set there is no good way to
+ do this (from user state) without clobbering either the LR or CTR.
+ The makecontext and swapcontext functions depend on the callers
+ LR being preserved so we use the CTR. */
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r31)
+ mtctr r0
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r31)
+ ld r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r31)
+ bctr
+
+L(error_exit):
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ ld r31,-8(r1)
+ blr
+
+ /* At this point we assume that the ucontext was created by a
+ rt_signal and we should use rt_sigreturn to restore the original
+ state. As of the 2.4.21 kernel the ucontext is the first thing
+ (offset 0) in the rt_signal frame and rt_sigreturn expects the
+ ucontext address in R1. Normally the rt-signal trampoline handles
+ this by popping dummy frame before the rt_signal syscall. In our
+ case the stack may not be in its original (signal handler return with
+ R1 pointing at the dummy frame) state. We do have the ucontext
+ address in R3, so simply copy R3 to R1 before the syscall. */
+L(do_sigret):
+ mr r1,r3,
+ li r0,SYS_ify(rt_sigreturn)
+ sc
+ /* No return. */
+#else
+ /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */
+ mflr r0
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset (128)
+ li r3,ENOSYS
+ bl JUMPTARGET(__syscall_error)
+ nop
+ li r3,-1
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ blr
+#endif
+
+PSEUDO_END(__setcontext)
+
+versioned_symbol (libc, __setcontext, setcontext, GLIBC_2_3_4)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S
new file mode 100644
index 000000000..15d8e84c1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S
@@ -0,0 +1,123 @@
+/* Copyright (C) 1995,96,97,99, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 51 Franklin Street,
+ Fifth Floor, Boston MA 02110-1301, USA. */
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+#define P(a, b) P2(a, b)
+#define P2(a, b) a##b
+
+/* The socket-oriented system calls are handled unusally in Linux.
+ They are all gated through the single `socketcall' system call number.
+ `socketcall' takes two arguments: the first is the subcode, specifying
+ which socket function is being called; and the second is a pointer to
+ the arguments to the specific function.
+
+ The .S files for the other calls just #define socket and #include this.
+ They also #define a 'number-of-arguments' word in NARGS, which
+ defaults to 3. */
+
+#ifndef NARGS
+#ifdef socket
+#error NARGS not defined
+#endif
+#define NARGS 3
+#endif
+
+#define stackblock 80 /* offset to socket parm area. */
+
+#ifndef __socket
+# ifndef NO_WEAK_ALIAS
+# define __socket P(__,socket)
+# else
+# define __socket socket
+# endif
+#endif
+
+ .text
+ENTRY(__socket)
+ CALL_MCOUNT NARGS
+ stdu r1,-144(r1)
+ cfi_adjust_cfa_offset(144)
+#if NARGS >= 1
+ std r3,stackblock(r1)
+#endif
+#if NARGS >= 2
+ std r4,8+stackblock(r1)
+#endif
+#if NARGS >= 3
+ std r5,16+stackblock(r1)
+#endif
+#if NARGS >= 4
+ std r6,24+stackblock(r1)
+#endif
+#if NARGS >= 5
+ std r7,32+stackblock(r1)
+#endif
+#if NARGS >= 6
+ std r8,40+stackblock(r1)
+#endif
+#if NARGS >= 7
+ std r9,48+stackblock(r1)
+#endif
+#if NARGS >= 8
+ std r10,56+stackblock(r1)
+#endif
+#if NARGS >= 9
+#error too many arguments!
+#endif
+
+#if defined NEED_CANCELLATION && defined CENABLE
+ SINGLE_THREAD_P
+ bne- .Lsocket_cancel
+#endif
+
+ li r3,P(SOCKOP_,socket)
+ addi r4,r1,stackblock
+ DO_CALL(SYS_ify(socketcall))
+ addi r1,r1,144
+ PSEUDO_RET
+
+#if defined NEED_CANCELLATION && defined CENABLE
+.Lsocket_cancel:
+ mflr r9
+ std r9,144+16(r1)
+ cfi_offset (lr, 16)
+ CENABLE
+ std r3,72(r1)
+ li r3,P(SOCKOP_,socket)
+ addi r4,r1,stackblock
+ DO_CALL(SYS_ify(socketcall))
+ mfcr r0
+ std r3,64(r1)
+ std r0,8(r1)
+ ld r3,72(r1)
+ CDISABLE
+ ld r4,144+16(r1)
+ ld r0,8(r1)
+ ld r3,64(r1)
+ mtlr r4
+ mtcr r0
+ addi r1,r1,144
+ PSEUDO_RET
+#endif
+PSEUDO_END (__socket)
+
+#ifndef NO_WEAK_ALIAS
+weak_alias (__socket, socket)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S
new file mode 100644
index 000000000..936d641b6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S
@@ -0,0 +1,769 @@
+/* Save current context and install the given one.
+ Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#include <rtld-global-offsets.h>
+#include <shlib-compat.h>
+#include <kernel-features.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include "ucontext_i.h"
+#include <asm/errno.h>
+
+#if SHLIB_COMPAT (libc, GLIBC_2_3, GLIBC_2_3_4)
+ENTRY(__novec_swapcontext)
+ CALL_MCOUNT 2
+#ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL
+ std r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r3)
+ std r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r3)
+ mflr r0
+ std r31,-8(1)
+ cfi_offset(r31,-8)
+ std r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r3)
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r3)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset (128)
+ std r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r3)
+ std r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r3)
+ std r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r3)
+ std r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r3)
+ std r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r3)
+ std r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r3)
+ std r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r3)
+ std r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r3)
+ std r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r3)
+ std r13,(SIGCONTEXT_GP_REGS+(PT_R13*8))(r3)
+ std r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r3)
+ std r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r3)
+ std r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r3)
+ std r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r3)
+ std r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r3)
+ std r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r3)
+ std r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r3)
+ std r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r3)
+ std r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r3)
+ std r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r3)
+ std r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r3)
+ std r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r3)
+ std r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r3)
+ std r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r3)
+ std r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r3)
+ std r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r3)
+ std r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r3)
+ std r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r3)
+ mfctr r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_CTR*8))(r3)
+ mfxer r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r3)
+ mfcr r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r3)
+
+ /* Set the return value of swapcontext to "success". R3 is the only
+ register whose value is not preserved in the saved context. */
+ li r0,0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r3)
+
+ /* Zero fill fields that can't be set in user state or are unused. */
+ std r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(34*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_SOFTE*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(40*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(41*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(42*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_RESULT*8))(r3)
+
+ /* Set the PT_REGS pointer to the address of sigcontext gp_regs
+ field. Struct pt_regs and elf_gregset_t are the same thing.
+ We kept the regs field for backwards compatibility with
+ libraries built before we extended sigcontext. */
+ addi r0,r3,SIGCONTEXT_GP_REGS
+ std r0,SIGCONTEXT_PT_REGS(r3)
+
+ stfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r3)
+ stfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r3)
+ stfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r3)
+ stfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r3)
+ stfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r3)
+ stfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r3)
+ stfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r3)
+ stfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r3)
+ stfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r3)
+ stfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r3)
+ stfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r3)
+ stfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r3)
+ stfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r3)
+ stfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r3)
+ stfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r3)
+ stfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r3)
+ stfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r3)
+ stfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r3)
+ stfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r3)
+ stfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r3)
+ stfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r3)
+ stfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r3)
+ stfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r3)
+ stfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r3)
+ stfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r3)
+ stfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r3)
+ stfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r3)
+ stfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r3)
+ stfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r3)
+ stfd fp29,(SIGCONTEXT_FP_REGS+(PT_R29*8))(r3)
+ mffs fp0
+ stfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r3)
+ stfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r3)
+ stfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r3)
+
+ mr r31,r4
+ addi r5,r3,UCONTEXT_SIGMASK
+ addi r4,r4,UCONTEXT_SIGMASK
+ li r3,SIG_SETMASK
+ bl JUMPTARGET(__sigprocmask)
+ nop
+ cmpdi r3,0
+ bne L(nv_error_exit)
+
+/*
+ * If this new ucontext refers to the point where we were interrupted
+ * by a signal, we have to use the rt_sigreturn system call to
+ * return to the context so we get both LR and CTR restored.
+ *
+ * Otherwise, the context we are restoring is either just after
+ * a procedure call (getcontext/swapcontext) or at the beginning
+ * of a procedure call (makecontext), so we don't need to restore
+ * msr and ctr. We don't restore r13 since it will be used as
+ * the TLS pointer. */
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r31)
+ cmpdi r0,0
+ bne L(nv_do_sigret)
+
+ lfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r31)
+ lfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r31)
+ lfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r31)
+ mtfsf 0xff,fp0
+ lfd fp29,(SIGCONTEXT_FP_REGS+(PT_R29*8))(r31)
+ lfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r31)
+ lfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r31)
+ lfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r31)
+ lfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r31)
+ lfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r31)
+ lfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r31)
+ lfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r31)
+ lfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r31)
+ lfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r31)
+ lfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r31)
+ lfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r31)
+ lfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r31)
+ lfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r31)
+ lfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r31)
+ lfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r31)
+ lfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r31)
+ lfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r31)
+ lfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r31)
+ lfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r31)
+ lfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r31)
+ lfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r31)
+ lfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r31)
+ lfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r31)
+ lfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r31)
+ lfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r31)
+ lfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r31)
+ lfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r31)
+ lfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r31)
+ lfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r31)
+
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r31)
+ ld r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r31)
+ mtlr r0
+ ld r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r31)
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r31)
+ ld r3,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r31)
+ mtxer r0
+ ld r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r31)
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r31)
+ ld r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r31)
+ mtcr r0
+ ld r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r31)
+ ld r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r31)
+ ld r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r31)
+ ld r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r31)
+ ld r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r31)
+ ld r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r31)
+ ld r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r31)
+ /* Don't reload the thread ID or TLS pointer (r13). */
+ ld r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r31)
+ ld r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r31)
+ ld r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r31)
+ ld r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r31)
+ ld r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r31)
+ ld r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r31)
+ ld r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r31)
+ ld r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r31)
+ ld r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r31)
+ ld r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r31)
+ ld r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r31)
+ ld r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r31)
+ ld r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r31)
+ ld r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r31)
+ ld r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r31)
+ ld r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r31)
+ ld r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r31)
+
+ /* Now we branch to the "Next Instruction Pointer" from the saved
+ context. With the powerpc64 instruction set there is no good way to
+ do this (from user state) without clobbering either the LR or CTR.
+ The makecontext and swapcontext functions depend on the callers
+ LR being preserved so we use the CTR. */
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r31)
+ mtctr r0
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r31)
+ ld r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r31)
+ bctr
+
+L(nv_error_exit):
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ ld r31,-8(r1)
+ blr
+
+ /* At this point we assume that the ucontext was created by a
+ rt_signal and we should use rt_sigreturn to restore the original
+ state. As of the 2.4.21 kernel the ucontext is the first thing
+ (offset 0) in the rt_signal frame and rt_sigreturn expects the
+ ucontext address in R1. Normally the rt-signal trampoline handles
+ this by popping dummy frame before the rt_signal syscall. In our
+ case the stack may not be in its original (signal handler return with
+ R1 pointing at the dummy frame) state. We do have the ucontext
+ address in R3, so simply copy R3 to R1 before the syscall. */
+L(nv_do_sigret):
+ mr r1,r3,
+ li r0,SYS_ify(rt_sigreturn)
+ sc
+ /* No return. */
+#else
+ /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */
+ mflr r0
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset(lr,FRAME_LR_SAVE)
+ stdu r1,-128(r1)
+ li r3,ENOSYS
+ bl JUMPTARGET(__syscall_error)
+ nop
+ li r3,-1
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ blr
+#endif
+
+PSEUDO_END(__novec_swapcontext)
+
+compat_symbol (libc, __novec_swapcontext, swapcontext, GLIBC_2_3)
+
+#endif
+
+ .section ".toc","aw"
+.LC__dl_hwcap:
+#ifdef SHARED
+ .tc _rtld_global_ro[TC],_rtld_global_ro
+#else
+ .tc _dl_hwcap[TC],_dl_hwcap
+#endif
+ .section ".text"
+
+ .machine "altivec"
+ENTRY(__swapcontext)
+ CALL_MCOUNT 2
+#ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL
+ std r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r3)
+ std r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r3)
+ mflr r0
+ std r31,-8(1)
+ cfi_offset(r31,-8)
+ std r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r3)
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r3)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset(128)
+ std r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r3)
+ std r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r3)
+ std r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r3)
+ std r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r3)
+ std r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r3)
+ std r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r3)
+ std r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r3)
+ std r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r3)
+ std r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r3)
+ std r13,(SIGCONTEXT_GP_REGS+(PT_R13*8))(r3)
+ std r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r3)
+ std r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r3)
+ std r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r3)
+ std r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r3)
+ std r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r3)
+ std r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r3)
+ std r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r3)
+ std r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r3)
+ std r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r3)
+ std r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r3)
+ std r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r3)
+ std r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r3)
+ std r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r3)
+ std r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r3)
+ std r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r3)
+ std r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r3)
+ std r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r3)
+ std r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r3)
+ mfctr r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_CTR*8))(r3)
+ mfxer r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r3)
+ mfcr r0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r3)
+
+ /* Set the return value of swapcontext to "success". R3 is the only
+ register whose value is not preserved in the saved context. */
+ li r0,0
+ std r0,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r3)
+
+ /* Zero fill fields that can't be set in user state or are unused. */
+ std r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(34*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_SOFTE*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(40*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(41*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(42*8))(r3)
+ std r0,(SIGCONTEXT_GP_REGS+(PT_RESULT*8))(r3)
+
+ /* Set the PT_REGS pointer to the address of sigcontext gp_regs
+ field. Struct pt_regs and elf_gregset_t are the same thing.
+ We kept the regs field for backwards compatibility with
+ libraries built before we extended sigcontext. */
+ addi r0,r3,SIGCONTEXT_GP_REGS
+ std r0,SIGCONTEXT_PT_REGS(r3)
+
+ stfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r3)
+ stfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r3)
+ stfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r3)
+ stfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r3)
+ stfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r3)
+ stfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r3)
+ stfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r3)
+ stfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r3)
+ stfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r3)
+ stfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r3)
+ stfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r3)
+ stfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r3)
+ stfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r3)
+ stfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r3)
+ stfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r3)
+ stfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r3)
+ stfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r3)
+ stfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r3)
+ stfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r3)
+ stfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r3)
+ stfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r3)
+ stfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r3)
+ stfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r3)
+ stfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r3)
+ stfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r3)
+ stfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r3)
+ stfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r3)
+ stfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r3)
+ stfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r3)
+ stfd fp29,(SIGCONTEXT_FP_REGS+(PT_R29*8))(r3)
+ mffs fp0
+ stfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r3)
+ stfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r3)
+ stfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r3)
+
+ ld r8,.LC__dl_hwcap@toc(r2)
+#ifdef SHARED
+/* Load _rtld-global._dl_hwcap. */
+ ld r8,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r8)
+#else
+ ld r8,0(r8) /* Load extern _dl_hwcap. */
+#endif
+ la r10,(SIGCONTEXT_V_RESERVE+8)(r3)
+ la r9,(SIGCONTEXT_V_RESERVE+24)(r3)
+
+ andis. r8,r8,(PPC_FEATURE_HAS_ALTIVEC >> 16)
+
+ clrrdi r10,r10,4
+ beq L(has_no_vec)
+
+ clrrdi r9,r9,4
+ mr r8,r10 /* Capture *v_regs value in r5. */
+
+ stvx v0,0,r10
+ stvx v1,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v2,0,r10
+ stvx v3,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v4,0,r10
+ stvx v5,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v6,0,r10
+ stvx v7,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v8,0,r10
+ stvx v9,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v10,0,r10
+ stvx v11,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v12,0,r10
+ stvx v13,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v14,0,r10
+ stvx v15,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v16,0,r10
+ stvx v17,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v18,0,r10
+ stvx v19,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v20,0,r10
+ stvx v21,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v22,0,r10
+ stvx v23,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v24,0,r10
+ stvx v25,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v26,0,r10
+ stvx v27,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v28,0,r10
+ stvx v29,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ stvx v30,0,r10
+ stvx v31,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ mfvscr v0
+ mfspr r0,VRSAVE
+ stvx v0,0,r10
+ stw r0,0(r9)
+
+L(has_no_vec):
+/*
+ Store either a NULL or a quadword aligned pointer to the Vector register
+ array into *v_regs.
+*/
+ std r8,(SIGCONTEXT_V_REGS_PTR)(r3)
+
+ mr r31,r4
+ addi r5,r3,UCONTEXT_SIGMASK
+ addi r4,r4,UCONTEXT_SIGMASK
+ li r3,SIG_SETMASK
+ bl JUMPTARGET(__sigprocmask)
+ nop
+ cmpdi r3,0
+ bne L(error_exit)
+
+/*
+ * If this new ucontext refers to the point where we were interrupted
+ * by a signal, we have to use the rt_sigreturn system call to
+ * return to the context so we get both LR and CTR restored.
+ *
+ * Otherwise, the context we are restoring is either just after
+ * a procedure call (getcontext/swapcontext) or at the beginning
+ * of a procedure call (makecontext), so we don't need to restore
+ * msr and ctr. We don't restore r13 since it will be used as
+ * the TLS pointer. */
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r31)
+ cmpdi r0,0
+ bne L(do_sigret)
+
+ ld r8,.LC__dl_hwcap@toc(r2)
+ ld r10,(SIGCONTEXT_V_REGS_PTR)(r31)
+# ifdef SHARED
+/* Load _rtld-global._dl_hwcap. */
+ ld r8,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r8)
+# else
+ ld r8,0(r8) /* Load extern _dl_hwcap. */
+# endif
+ andis. r8,r8,(PPC_FEATURE_HAS_ALTIVEC >> 16)
+ beq L(has_no_vec2)
+
+ cmpdi r10,0
+ beq L(has_no_vec2)
+ lwz r0,(33*16)(r10)
+
+ li r9,(16*32)
+ mtspr VRSAVE,r0
+ cmpwi r0,0
+ beq L(has_no_vec2)
+
+ lvx v19,r9,r10
+ la r9,(16)(r10)
+
+ lvx v0,0,r10
+ lvx v1,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ mtvscr v19
+ lvx v2,0,r10
+ lvx v3,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v4,0,r10
+ lvx v5,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v6,0,r10
+ lvx v7,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v8,0,r10
+ lvx v9,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v10,0,r10
+ lvx v11,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v12,0,r10
+ lvx v13,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v14,0,r10
+ lvx v15,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v16,0,r10
+ lvx v17,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v18,0,r10
+ lvx v19,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v20,0,r10
+ lvx v21,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v22,0,r10
+ lvx v23,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v24,0,r10
+ lvx v25,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v26,0,r10
+ lvx v27,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v28,0,r10
+ lvx v29,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v30,0,r10
+ lvx v31,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+ lvx v10,0,r10
+ lvx v11,0,r9
+ addi r10,r10,32
+ addi r9,r9,32
+
+L(has_no_vec2):
+
+ lfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r31)
+ lfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r31)
+ lfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r31)
+ mtfsf 0xff,fp0
+ lfd fp29,(SIGCONTEXT_FP_REGS+(PT_R29*8))(r31)
+ lfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r31)
+ lfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r31)
+ lfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r31)
+ lfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r31)
+ lfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r31)
+ lfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r31)
+ lfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r31)
+ lfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r31)
+ lfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r31)
+ lfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r31)
+ lfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r31)
+ lfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r31)
+ lfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r31)
+ lfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r31)
+ lfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r31)
+ lfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r31)
+ lfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r31)
+ lfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r31)
+ lfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r31)
+ lfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r31)
+ lfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r31)
+ lfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r31)
+ lfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r31)
+ lfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r31)
+ lfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r31)
+ lfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r31)
+ lfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r31)
+ lfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r31)
+ lfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r31)
+
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r31)
+ ld r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r31)
+ mtlr r0
+ ld r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r31)
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r31)
+ ld r3,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r31)
+ mtxer r0
+ ld r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r31)
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r31)
+ ld r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r31)
+ ld r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r31)
+ ld r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r31)
+ ld r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r31)
+ ld r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r31)
+ mtcr r0
+ ld r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r31)
+ ld r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r31)
+ ld r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r31)
+ /* Don't reload the thread ID or TLS pointer (r13). */
+ ld r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r31)
+ ld r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r31)
+ ld r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r31)
+ ld r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r31)
+ ld r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r31)
+ ld r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r31)
+ ld r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r31)
+ ld r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r31)
+ ld r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r31)
+ ld r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r31)
+ ld r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r31)
+ ld r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r31)
+ ld r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r31)
+ ld r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r31)
+ ld r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r31)
+ ld r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r31)
+ ld r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r31)
+
+ /* Now we branch to the "Next Instruction Pointer" from the saved
+ context. With the powerpc64 instruction set there is no good way to
+ do this (from user state) without clobbering either the LR or CTR.
+ The makecontext and swapcontext functions depend on the callers
+ LR being preserved so we use the CTR. */
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r31)
+ mtctr r0
+ ld r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r31)
+ ld r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r31)
+ bctr
+
+L(error_exit):
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ ld r31,-8(r1)
+ blr
+
+ /* At this point we assume that the ucontext was created by a
+ rt_signal and we should use rt_sigreturn to restore the original
+ state. As of the 2.4.21 kernel the ucontext is the first thing
+ (offset 0) in the rt_signal frame and rt_sigreturn expects the
+ ucontext address in R1. Normally the rt-signal trampoline handles
+ this by popping dummy frame before the rt_signal syscall. In our
+ case the stack may not be in its original (signal handler return with
+ R1 pointing at the dummy frame) state. We do have the ucontext
+ address in R3, so simply copy R3 to R1 before the syscall. */
+L(do_sigret):
+ mr r1,r3,
+ li r0,SYS_ify(rt_sigreturn)
+ sc
+ /* No return. */
+#else
+ /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */
+ mflr r0
+ std r0,FRAME_LR_SAVE(r1)
+ cfi_offset (lr, FRAME_LR_SAVE)
+ stdu r1,-128(r1)
+ cfi_adjust_cfa_offset (128)
+ li r3,ENOSYS
+ bl JUMPTARGET(__syscall_error)
+ nop
+ li r3,-1
+ ld r0,128+FRAME_LR_SAVE(r1)
+ addi r1,r1,128
+ mtlr r0
+ blr
+#endif
+
+PSEUDO_END(__swapcontext)
+
+versioned_symbol (libc, __swapcontext, swapcontext, GLIBC_2_3_4)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list
new file mode 100644
index 000000000..aee60bf9d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list
@@ -0,0 +1,3 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+getrlimit - ugetrlimit i:ip __getrlimit getrlimit getrlimit64
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
new file mode 100644
index 000000000..fd67f5698
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
@@ -0,0 +1,311 @@
+/* Copyright (C) 1992,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Alan Modra <amodra@bigpond.net.au> rewrote the INLINE_SYSCALL macro */
+
+#ifndef _LINUX_POWERPC_SYSDEP_H
+#define _LINUX_POWERPC_SYSDEP_H 1
+
+#include <sysdeps/unix/powerpc/sysdep.h>
+#include <tls.h>
+
+/* Define __set_errno() for INLINE_SYSCALL macro below. */
+#ifndef __ASSEMBLER__
+#include <errno.h>
+#endif
+
+/* Some systen calls got renamed over time, but retained the same semantics.
+ Handle them here so they can be catched by both C and assembler stubs in
+ glibc. */
+
+#ifdef __NR_pread64
+# ifdef __NR_pread
+# error "__NR_pread and __NR_pread64 both defined???"
+# endif
+# define __NR_pread __NR_pread64
+#endif
+
+#ifdef __NR_pwrite64
+# ifdef __NR_pwrite
+# error "__NR_pwrite and __NR_pwrite64 both defined???"
+# endif
+# define __NR_pwrite __NR_pwrite64
+#endif
+
+/* For Linux we can use the system call table in the header file
+ /usr/include/asm/unistd.h
+ of the kernel. But these symbols do not follow the SYS_* syntax
+ so we have to redefine the `SYS_ify' macro here. */
+#undef SYS_ify
+#ifdef __STDC__
+# define SYS_ify(syscall_name) __NR_##syscall_name
+#else
+# define SYS_ify(syscall_name) __NR_/**/syscall_name
+#endif
+
+#ifdef __ASSEMBLER__
+
+/* This seems to always be the case on PPC. */
+# define ALIGNARG(log2) log2
+/* For ELF we need the `.type' directive to make shared libs work right. */
+# define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
+# define ASM_SIZE_DIRECTIVE(name) .size name,.-name
+
+#endif /* __ASSEMBLER__ */
+
+/* This version is for kernels that implement system calls that
+ behave like function calls as far as register saving.
+ It falls back to the syscall in the case that the vDSO doesn't
+ exist or fails for ENOSYS */
+#ifdef SHARED
+# define INLINE_VSYSCALL(name, nr, args...) \
+ ({ \
+ __label__ out; \
+ __label__ iserr; \
+ INTERNAL_SYSCALL_DECL (sc_err); \
+ long int sc_ret; \
+ \
+ if (__vdso_##name != NULL) \
+ { \
+ sc_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, sc_err, nr, ##args); \
+ if (!INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
+ goto out; \
+ if (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err) != ENOSYS) \
+ goto iserr; \
+ } \
+ \
+ sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, ##args); \
+ if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
+ { \
+ iserr: \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
+ sc_ret = -1L; \
+ } \
+ out: \
+ sc_ret; \
+ })
+#else
+# define INLINE_VSYSCALL(name, nr, args...) \
+ INLINE_SYSCALL (name, nr, ##args)
+#endif
+
+#ifdef SHARED
+# define INTERNAL_VSYSCALL(name, err, nr, args...) \
+ ({ \
+ __label__ out; \
+ long int v_ret; \
+ \
+ if (__vdso_##name != NULL) \
+ { \
+ v_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, err, nr, ##args); \
+ if (!INTERNAL_SYSCALL_ERROR_P (v_ret, err) \
+ || INTERNAL_SYSCALL_ERRNO (v_ret, err) != ENOSYS) \
+ goto out; \
+ } \
+ v_ret = INTERNAL_SYSCALL (name, err, nr, ##args); \
+ out: \
+ v_ret; \
+ })
+#else
+# define INTERNAL_VSYSCALL(name, err, nr, args...) \
+ INTERNAL_SYSCALL (name, err, nr, ##args)
+#endif
+
+/* This version is for internal uses when there is no desire
+ to set errno */
+#define INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK(name, err, nr, args...) \
+ ({ \
+ long int sc_ret = ENOSYS; \
+ \
+ if (__vdso_##name != NULL) \
+ sc_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, err, nr, ##args); \
+ else \
+ err = 1 << 28; \
+ sc_ret; \
+ })
+
+/* List of system calls which are supported as vsyscalls. */
+#define HAVE_CLOCK_GETRES_VSYSCALL 1
+#define HAVE_CLOCK_GETTIME_VSYSCALL 1
+
+/* Define a macro which expands inline into the wrapper code for a system
+ call. This use is for internal calls that do not need to handle errors
+ normally. It will never touch errno. This returns just what the kernel
+ gave back in the non-error (CR0.SO cleared) case, otherwise (CR0.SO set)
+ the negation of the return value in the kernel gets reverted. */
+
+#define INTERNAL_VSYSCALL_NCS(funcptr, err, nr, args...) \
+ ({ \
+ register void *r0 __asm__ ("r0"); \
+ register long int r3 __asm__ ("r3"); \
+ register long int r4 __asm__ ("r4"); \
+ register long int r5 __asm__ ("r5"); \
+ register long int r6 __asm__ ("r6"); \
+ register long int r7 __asm__ ("r7"); \
+ register long int r8 __asm__ ("r8"); \
+ LOADARGS_##nr (funcptr, args); \
+ __asm__ __volatile__ \
+ ("mtctr %0\n\t" \
+ "bctrl\n\t" \
+ "mfcr %0\n\t" \
+ "0:" \
+ : "=&r" (r0), \
+ "=&r" (r3), "=&r" (r4), "=&r" (r5), \
+ "=&r" (r6), "=&r" (r7), "=&r" (r8) \
+ : ASM_INPUT_##nr \
+ : "r9", "r10", "r11", "r12", \
+ "cr0", "ctr", "lr", "memory"); \
+ err = (long int) r0; \
+ (int) r3; \
+ })
+
+#undef INLINE_SYSCALL
+
+/* This version is for kernels that implement system calls that
+ behave like function calls as far as register saving. */
+#define INLINE_SYSCALL(name, nr, args...) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (sc_err); \
+ long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \
+ if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
+ sc_ret = -1L; \
+ } \
+ sc_ret; \
+ })
+
+/* Define a macro which expands inline into the wrapper code for a system
+ call. This use is for internal calls that do not need to handle errors
+ normally. It will never touch errno. This returns just what the kernel
+ gave back in the non-error (CR0.SO cleared) case, otherwise (CR0.SO set)
+ the negation of the return value in the kernel gets reverted. */
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({ \
+ register long int r0 __asm__ ("r0"); \
+ register long int r3 __asm__ ("r3"); \
+ register long int r4 __asm__ ("r4"); \
+ register long int r5 __asm__ ("r5"); \
+ register long int r6 __asm__ ("r6"); \
+ register long int r7 __asm__ ("r7"); \
+ register long int r8 __asm__ ("r8"); \
+ LOADARGS_##nr (name, ##args); \
+ __asm__ __volatile__ \
+ ("sc\n\t" \
+ "mfcr %0\n\t" \
+ "0:" \
+ : "=&r" (r0), \
+ "=&r" (r3), "=&r" (r4), "=&r" (r5), \
+ "=&r" (r6), "=&r" (r7), "=&r" (r8) \
+ : ASM_INPUT_##nr \
+ : "r9", "r10", "r11", "r12", \
+ "cr0", "ctr", "memory"); \
+ err = r0; \
+ (int) r3; \
+ })
+#define INTERNAL_SYSCALL(name, err, nr, args...) \
+ INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, args)
+
+#undef INTERNAL_SYSCALL_DECL
+#define INTERNAL_SYSCALL_DECL(err) long int err
+
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+ ((void) (val), __builtin_expect ((err) & (1 << 28), 0))
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val, err) (val)
+
+#define LOADARGS_0(name, dummy) \
+ r0 = name
+#define LOADARGS_1(name, __arg1) \
+ long int arg1 = (long int) (__arg1); \
+ LOADARGS_0(name, 0); \
+ extern void __illegally_sized_syscall_arg1 (void); \
+ if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 8) \
+ __illegally_sized_syscall_arg1 (); \
+ r3 = arg1
+#define LOADARGS_2(name, __arg1, __arg2) \
+ long int arg2 = (long int) (__arg2); \
+ LOADARGS_1(name, __arg1); \
+ extern void __illegally_sized_syscall_arg2 (void); \
+ if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 8) \
+ __illegally_sized_syscall_arg2 (); \
+ r4 = arg2
+#define LOADARGS_3(name, __arg1, __arg2, __arg3) \
+ long int arg3 = (long int) (__arg3); \
+ LOADARGS_2(name, __arg1, __arg2); \
+ extern void __illegally_sized_syscall_arg3 (void); \
+ if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 8) \
+ __illegally_sized_syscall_arg3 (); \
+ r5 = arg3
+#define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
+ long int arg4 = (long int) (__arg4); \
+ LOADARGS_3(name, __arg1, __arg2, __arg3); \
+ extern void __illegally_sized_syscall_arg4 (void); \
+ if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 8) \
+ __illegally_sized_syscall_arg4 (); \
+ r6 = arg4
+#define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
+ long int arg5 = (long int) (__arg5); \
+ LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
+ extern void __illegally_sized_syscall_arg5 (void); \
+ if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 8) \
+ __illegally_sized_syscall_arg5 (); \
+ r7 = arg5
+#define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
+ long int arg6 = (long int) (__arg6); \
+ LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
+ extern void __illegally_sized_syscall_arg6 (void); \
+ if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 8) \
+ __illegally_sized_syscall_arg6 (); \
+ r8 = arg6
+
+#define ASM_INPUT_0 "0" (r0)
+#define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
+#define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
+#define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
+#define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
+#define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
+#define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
+
+
+/* Pointer mangling support. */
+#if defined NOT_IN_libc && defined IS_IN_rtld
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+ earlier than the descriptor is initialized. */
+#else
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(reg, tmpreg) \
+ ld tmpreg,POINTER_GUARD(r13); \
+ xor reg,tmpreg,reg
+# define PTR_MANGLE2(reg, tmpreg) \
+ xor reg,tmpreg,reg
+# define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
+# define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
+# else
+# define PTR_MANGLE(var) \
+ (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+# define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* linux/powerpc/powerpc64/sysdep.h */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.sym b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.sym
new file mode 100644
index 000000000..a35418d9d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.sym
@@ -0,0 +1,50 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+--
+
+SIG_BLOCK
+SIG_SETMASK
+
+
+-- Offsets of the fields in the powerpc64 ABI stack frame.
+-- XXX Do these correspond to some struct?
+
+FRAME_BACKCHAIN 0
+FRAME_CR_SAVE 8
+FRAME_LR_SAVE 16
+FRAME_COMPILER_DW 24
+FRAME_LINKER_DW 32
+FRAME_TOC_SAVE 40
+FRAME_PARM_SAVE 48
+FRAME_PARM1_SAVE 48
+FRAME_PARM2_SAVE 56
+FRAME_PARM3_SAVE 64
+FRAME_PARM4_SAVE 72
+FRAME_PARM5_SAVE 80
+FRAME_PARM6_SAVE 88
+FRAME_PARM7_SAVE 96
+FRAME_PARM8_SAVE 104
+FRAME_PARM9_SAVE 112
+
+
+-- Offsets of the fields in the ucontext_t structure.
+#define ucontext(member) offsetof (ucontext_t, member)
+#define mcontext(member) ucontext (uc_mcontext.member)
+
+UCONTEXT_LINK ucontext (uc_link)
+UCONTEXT_STACK ucontext (uc_stack)
+UCONTEXT_STACK_SP ucontext (uc_stack.ss_sp)
+UCONTEXT_STACK_FLAGS ucontext (uc_stack.ss_flags)
+UCONTEXT_STACK_SIZE ucontext (uc_stack.ss_size)
+UCONTEXT_SIGMASK ucontext (uc_sigmask)
+UCONTEXT_MCONTEXT ucontext (uc_mcontext)
+SIGCONTEXT_SIGNAL mcontext (signal)
+SIGCONTEXT_HANDLER mcontext (handler)
+SIGCONTEXT_OLDMASK mcontext (oldmask)
+SIGCONTEXT_PT_REGS mcontext (regs)
+SIGCONTEXT_GP_REGS mcontext (gp_regs)
+SIGCONTEXT_FP_REGS mcontext (fp_regs)
+SIGCONTEXT_V_REGS_PTR mcontext (v_regs)
+SIGCONTEXT_V_RESERVE mcontext (vmx_reserve)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/umount.c b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/umount.c
new file mode 100644
index 000000000..e10b40f96
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/umount.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/x86_64/umount.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S
new file mode 100644
index 000000000..2f5df38cf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S
@@ -0,0 +1,57 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+ CALL_MCOUNT 0
+
+#ifdef __NR_vfork
+
+ DO_CALL (SYS_ify (vfork))
+
+# ifdef __ASSUME_VFORK_SYSCALL
+ PSEUDO_RET
+# else
+ bnslr+
+ /* Check if vfork syscall is known at all. */
+ cmpdi r3,ENOSYS
+ bne JUMPTARGET(__syscall_error)
+
+# endif
+#endif
+
+#ifndef __ASSUME_VFORK_SYSCALL
+ /* If we don't have vfork, fork is close enough. */
+
+ DO_CALL (SYS_ify (fork))
+ PSEUDO_RET
+#endif
+
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/profil-counter.h b/libc/sysdeps/unix/sysv/linux/powerpc/profil-counter.h
new file mode 100644
index 000000000..8a6a0bcf3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/profil-counter.h
@@ -0,0 +1,2 @@
+/* We can use the ix86 version. */
+#include <sysdeps/unix/sysv/linux/i386/profil-counter.h>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/putmsg.c b/libc/sysdeps/unix/sysv/linux/powerpc/putmsg.c
new file mode 100644
index 000000000..ebc1680ca
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/putmsg.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/putmsg.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/readdir64.c b/libc/sysdeps/unix/sysv/linux/powerpc/readdir64.c
new file mode 100644
index 000000000..2ea26dd40
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/readdir64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/readdir64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/readdir64_r.c b/libc/sysdeps/unix/sysv/linux/powerpc/readdir64_r.c
new file mode 100644
index 000000000..9f54f897e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/readdir64_r.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/readdir64_r.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/readelflib.c b/libc/sysdeps/unix/sysv/linux/powerpc/readelflib.c
new file mode 100644
index 000000000..3c6b2daf8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/readelflib.c
@@ -0,0 +1,61 @@
+/* Special checks on libraries for ldconfig. Linux/PowerPC version.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+int process_elf32_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+int process_elf64_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+
+/* Returns 0 if everything is ok, != 0 in case of error. */
+int
+process_elf_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname, void *file_contents,
+ size_t file_length)
+{
+ ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
+ int ret;
+
+ if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
+ return process_elf32_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ else
+ {
+ ret = process_elf64_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ /* PowerPC 64bit libraries are always libc.so.6+. */
+ if (!ret)
+ *flag = FLAG_POWERPC_LIB64|FLAG_ELF_LIBC6;
+ return ret;
+ }
+}
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf32_file
+#define __ELF_NATIVE_CLASS 32
+#include "elf/readelflib.c"
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf64_file
+#define __ELF_NATIVE_CLASS 64
+#include "elf/readelflib.c"
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/rt-sysdep.c b/libc/sysdeps/unix/sysv/linux/powerpc/rt-sysdep.c
new file mode 100644
index 000000000..3ff55952e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/rt-sysdep.c
@@ -0,0 +1 @@
+#include <sysdep.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/scandir64.c b/libc/sysdeps/unix/sysv/linux/powerpc/scandir64.c
new file mode 100644
index 000000000..506fd8877
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/scandir64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/scandir64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/setrlimit.c b/libc/sysdeps/unix/sysv/linux/powerpc/setrlimit.c
new file mode 100644
index 000000000..bfaef74c3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/setrlimit.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setrlimit.c>
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h b/libc/sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h
new file mode 100644
index 000000000..138a15cfa
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h
@@ -0,0 +1,27 @@
+/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <signal.h>
+
+#define SIGCONTEXT struct sigcontext *
+#define SIGCONTEXT_EXTRA_ARGS
+#define GET_PC(ctx) ((void *)((ctx)->regs->nip))
+#define GET_FRAME(ctx) (*(void **)((ctx)->regs->gpr[1]))
+#define GET_STACK(ctx) ((void *)((ctx)->regs->gpr[1]))
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/sys/procfs.h b/libc/sysdeps/unix/sysv/linux/powerpc/sys/procfs.h
new file mode 100644
index 000000000..577689f18
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/sys/procfs.h
@@ -0,0 +1,140 @@
+/* Copyright (C) 1996, 1997, 1999, 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H 1
+
+/* This is somehow modelled after the file of the same name on SysVr4
+ systems. It provides a definition of the core file format for ELF
+ used on Linux. */
+
+#include <features.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/ucontext.h>
+#include <sys/user.h>
+
+__BEGIN_DECLS
+
+/* These definitions are normally provided by ucontext.h via
+ asm/sigcontext.h, asm/ptrace.h, and asm/elf.h. Otherwise we define
+ them here. */
+#if !defined __PPC64_ELF_H && !defined _ASM_POWERPC_ELF_H
+#define ELF_NGREG 48 /* includes nip, msr, lr, etc. */
+#define ELF_NFPREG 33 /* includes fpscr */
+#if __WORDSIZE == 32
+# define ELF_NVRREG 33 /* includes vscr */
+#else
+# define ELF_NVRREG 34 /* includes vscr */
+#endif
+
+typedef unsigned long elf_greg_t;
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+typedef double elf_fpreg_t;
+typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
+
+/* Altivec registers */
+typedef struct {
+ unsigned int u[4];
+} __attribute__ ((aligned (16))) elf_vrreg_t;
+typedef elf_vrreg_t elf_vrregset_t[ELF_NVRREG];
+#endif
+
+struct elf_siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_code; /* Extra code. */
+ int si_errno; /* Errno. */
+ };
+
+
+/* Definitions to generate Intel SVR4-like core files. These mostly
+ have the same names as the SVR4 types with "elf_" tacked on the
+ front to prevent clashes with linux definitions, and the typedef
+ forms have been avoided. This is mostly like the SVR4 structure,
+ but more Linuxy, with things that Linux does not support and which
+ gdb doesn't really use excluded. Fields present but not used are
+ marked with "XXX". */
+struct elf_prstatus
+ {
+#if 0
+ long int pr_flags; /* XXX Process flags. */
+ short int pr_why; /* XXX Reason for process halt. */
+ short int pr_what; /* XXX More detailed reason. */
+#endif
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned long int pr_sigpend; /* Set of pending signals. */
+ unsigned long int pr_sighold; /* Set of held signals. */
+#if 0
+ struct sigaltstack pr_altstack; /* Alternate stack info. */
+ struct sigaction pr_action; /* Signal action for current sig. */
+#endif
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct timeval pr_utime; /* User time. */
+ struct timeval pr_stime; /* System time. */
+ struct timeval pr_cutime; /* Cumulative user time. */
+ struct timeval pr_cstime; /* Cumulative system time. */
+#if 0
+ long int pr_instr; /* Current instruction. */
+#endif
+ elf_gregset_t pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+
+#define ELF_PRARGSZ (80) /* Number of chars for args */
+
+struct elf_prpsinfo
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned long int pr_flag; /* Flags. */
+ __uid_t pr_uid;
+ __gid_t pr_gid;
+ __pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+/* Addresses. */
+typedef void *psaddr_t;
+
+/* Register sets. Linux has different names. */
+typedef elf_gregset_t prgregset_t;
+typedef elf_fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+ therefore habe only ine PID type. */
+typedef __pid_t lwpid_t;
+
+
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+__END_DECLS
+
+#endif /* sys/procfs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h b/libc/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
new file mode 100644
index 000000000..91a87307f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
@@ -0,0 +1,99 @@
+/* `ptrace' debugger support interface. Linux version.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PTRACE_H
+#define _SYS_PTRACE_H 1
+
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* Type of the REQUEST argument to `ptrace.' */
+enum __ptrace_request
+{
+ /* Indicate that the process making this request should be traced.
+ All signals received by this process can be intercepted by its
+ parent, and its parent can use the other `ptrace' requests. */
+ PTRACE_TRACEME = 0,
+#define PT_TRACE_ME PTRACE_TRACEME
+
+ /* Return the word in the process's text space at address ADDR. */
+ PTRACE_PEEKTEXT = 1,
+#define PT_READ_I PTRACE_PEEKTEXT
+
+ /* Return the word in the process's data space at address ADDR. */
+ PTRACE_PEEKDATA = 2,
+#define PT_READ_D PTRACE_PEEKDATA
+
+ /* Return the word in the process's user area at offset ADDR. */
+ PTRACE_PEEKUSER = 3,
+#define PT_READ_U PTRACE_PEEKUSER
+
+ /* Write the word DATA into the process's text space at address ADDR. */
+ PTRACE_POKETEXT = 4,
+#define PT_WRITE_I PTRACE_POKETEXT
+
+ /* Write the word DATA into the process's data space at address ADDR. */
+ PTRACE_POKEDATA = 5,
+#define PT_WRITE_D PTRACE_POKEDATA
+
+ /* Write the word DATA into the process's user area at offset ADDR. */
+ PTRACE_POKEUSER = 6,
+#define PT_WRITE_U PTRACE_POKEUSER
+
+ /* Continue the process. */
+ PTRACE_CONT = 7,
+#define PT_CONTINUE PTRACE_CONT
+
+ /* Kill the process. */
+ PTRACE_KILL = 8,
+#define PT_KILL PTRACE_KILL
+
+ /* Single step the process.
+ This is not supported on all machines. */
+ PTRACE_SINGLESTEP = 9,
+#define PT_STEP PTRACE_SINGLESTEP
+
+ /* Attach to a process that is already running. */
+ PTRACE_ATTACH = 16,
+#define PT_ATTACH PTRACE_ATTACH
+
+ /* Detach from a process attached to with PTRACE_ATTACH. */
+ PTRACE_DETACH = 17,
+#define PT_DETACH PTRACE_DETACH
+
+ /* Continue and stop at the next (return from) syscall. */
+ PTRACE_SYSCALL = 24
+#define PT_SYSCALL PTRACE_SYSCALL
+};
+
+/* Perform process tracing functions. REQUEST is one of the values
+ above, and determines the action to be taken.
+ For all requests except PTRACE_TRACEME, PID specifies the process to be
+ traced.
+
+ PID and the other arguments described above for the various requests should
+ appear (those that are used for the particular request) as:
+ pid_t PID, void *ADDR, int DATA, void *ADDR2
+ after REQUEST. */
+extern long int ptrace (enum __ptrace_request __request, ...) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_PTRACE_H */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h b/libc/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
new file mode 100644
index 000000000..9eb50aa96
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
@@ -0,0 +1,177 @@
+/* Copyright (C) 1998, 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+
+#include <features.h>
+#include <signal.h>
+
+/* We need the signal context definitions even if they are not used
+ included in <signal.h>. */
+#include <bits/sigcontext.h>
+
+#if __WORDSIZE == 32
+
+/* Number of general registers. */
+# define NGREG 48
+
+/* Container for all general registers. */
+typedef unsigned long gregset_t[NGREG];
+
+/* Container for floating-point registers and status */
+typedef struct _libc_fpstate
+{
+ double fpregs[32];
+ double fpscr;
+ unsigned int _pad[2];
+} fpregset_t;
+
+/* Container for Altivec/VMX registers and status.
+ Needs to be aligned on a 16-byte boundary. */
+typedef struct _libc_vrstate
+{
+ unsigned int vrregs[32][4];
+ unsigned int vrsave;
+ unsigned int _pad[2];
+ unsigned int vscr;
+} vrregset_t;
+
+/* Context to describe whole processor state. */
+typedef struct
+{
+ gregset_t gregs;
+ fpregset_t fpregs;
+ vrregset_t vrregs __attribute__((__aligned__(16)));
+} mcontext_t;
+
+#else
+
+/* For 64-bit kernels with Altivec support, a machine context is exactly
+ * a sigcontext. For older kernel (without Altivec) the sigcontext matches
+ * the mcontext upto but not including the v_regs field. For kernels that
+ * don't AT_HWCAP or return AT_HWCAP without PPC_FEATURE_HAS_ALTIVEC the
+ * v_regs field may not exit and should not be referenced. The v_regd field
+ * can be refernced safely only after verifying that PPC_FEATURE_HAS_ALTIVEC
+ * is set in AT_HWCAP. */
+
+/* Number of general registers. */
+# define NGREG 48 /* includes r0-r31, nip, msr, lr, etc. */
+# define NFPREG 33 /* includes fp0-fp31 &fpscr. */
+# define NVRREG 34 /* includes v0-v31, vscr, & vrsave in split vectors */
+
+typedef unsigned long gregset_t[NGREG];
+typedef double fpregset_t[NFPREG];
+
+/* Container for Altivec/VMX Vector Status and Control Register. Only 32-bits
+ but can only be copied to/from a 128-bit vector register. So we allocated
+ a whole quadword speedup save/restore. */
+typedef struct _libc_vscr
+{
+ unsigned int __pad[3];
+ unsigned int vscr_word;
+} vscr_t;
+
+/* Container for Altivec/VMX registers and status.
+ Must to be aligned on a 16-byte boundary. */
+typedef struct _libc_vrstate
+{
+ unsigned int vrregs[32][4];
+ vscr_t vscr;
+ unsigned int vrsave;
+ unsigned int __pad[3];
+} vrregset_t __attribute__((__aligned__(16)));
+
+typedef struct {
+ unsigned long __unused[4];
+ int signal;
+ int __pad0;
+ unsigned long handler;
+ unsigned long oldmask;
+ struct pt_regs *regs;
+ gregset_t gp_regs;
+ fpregset_t fp_regs;
+/*
+ * To maintain compatibility with current implementations the sigcontext is
+ * extended by appending a pointer (v_regs) to a quadword type (elf_vrreg_t)
+ * followed by an unstructured (vmx_reserve) field of 69 doublewords. This
+ * allows the array of vector registers to be quadword aligned independent of
+ * the alignment of the containing sigcontext or ucontext. It is the
+ * responsibility of the code setting the sigcontext to set this pointer to
+ * either NULL (if this processor does not support the VMX feature) or the
+ * address of the first quadword within the allocated (vmx_reserve) area.
+ *
+ * The pointer (v_regs) of vector type (elf_vrreg_t) is essentually
+ * an array of 34 quadword entries. The entries with
+ * indexes 0-31 contain the corresponding vector registers. The entry with
+ * index 32 contains the vscr as the last word (offset 12) within the
+ * quadword. This allows the vscr to be stored as either a quadword (since
+ * it must be copied via a vector register to/from storage) or as a word.
+ * The entry with index 33 contains the vrsave as the first word (offset 0)
+ * within the quadword.
+ */
+ vrregset_t *v_regs;
+ long vmx_reserve[NVRREG+NVRREG+1];
+} mcontext_t;
+
+#endif
+
+/* Userlevel context. */
+typedef struct ucontext
+ {
+ unsigned long int uc_flags;
+ struct ucontext *uc_link;
+ stack_t uc_stack;
+#if __WORDSIZE == 32
+ /*
+ * These fields are set up this way to maximize source and
+ * binary compatibility with code written for the old
+ * ucontext_t definition, which didn't include space for the
+ * registers.
+ *
+ * Different versions of the kernel have stored the registers on
+ * signal delivery at different offsets from the ucontext struct.
+ * Programs should thus use the uc_mcontext.uc_regs pointer to
+ * find where the registers are actually stored. The registers
+ * will be stored within the ucontext_t struct but not necessarily
+ * at a fixed address. As a side-effect, this lets us achieve
+ * 16-byte alignment for the register storage space if the
+ * Altivec registers are to be saved, without requiring 16-byte
+ * alignment on the whole ucontext_t.
+ *
+ * The uc_mcontext.regs field is included for source compatibility
+ * with programs written against the older ucontext_t definition,
+ * and its name should therefore not change. The uc_pad field
+ * is for binary compatibility with programs compiled against the
+ * old ucontext_t; it ensures that uc_mcontext.regs and uc_sigmask
+ * are at the same offset as previously.
+ */
+ int uc_pad[7];
+ union uc_regs_ptr {
+ struct pt_regs *regs;
+ mcontext_t *uc_regs;
+ } uc_mcontext;
+ sigset_t uc_sigmask;
+ char uc_reg_space[sizeof(mcontext_t) + 12]; /* last for extensibility */
+#else /* 64-bit */
+ sigset_t uc_sigmask;
+ mcontext_t uc_mcontext; /* last for extensibility */
+#endif
+ } ucontext_t;
+
+#endif /* sys/ucontext.h */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/sys/user.h b/libc/sysdeps/unix/sysv/linux/powerpc/sys/user.h
new file mode 100644
index 000000000..e8a8aaa95
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/sys/user.h
@@ -0,0 +1,40 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_USER_H
+
+#define _SYS_USER_H 1
+#include <features.h>
+
+#include <asm/ptrace.h>
+
+struct user {
+ struct pt_regs regs; /* entire machine state */
+ size_t u_tsize; /* text size (pages) */
+ size_t u_dsize; /* data size (pages) */
+ size_t u_ssize; /* stack size (pages) */
+ unsigned long start_code; /* text starting address */
+ unsigned long start_data; /* data starting address */
+ unsigned long start_stack; /* stack starting address */
+ long int signal; /* signal causing core dump */
+ struct regs * u_ar0; /* help gdb find registers */
+ unsigned long magic; /* identifies a core file */
+ char u_comm[32]; /* user command name */
+};
+
+#endif /* sys/user.h */
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/syscall.S b/libc/sysdeps/unix/sysv/linux/powerpc/syscall.S
new file mode 100644
index 000000000..aab3c5300
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/syscall.S
@@ -0,0 +1,31 @@
+/* Copyright (C) 1991, 1992, 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+ENTRY (syscall)
+ mr r0,r3
+ mr r3,r4
+ mr r4,r5
+ mr r5,r6
+ mr r6,r7
+ mr r7,r8
+ mr r8,r9
+ sc
+ PSEUDO_RET
+PSEUDO_END (syscall)
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/syscalls.list b/libc/sysdeps/unix/sysv/linux/powerpc/syscalls.list
new file mode 100644
index 000000000..a6665936e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/syscalls.list
@@ -0,0 +1,3 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+waitpid - waitpid Ci:ipi __waitpid waitpid __libc_waitpid
diff --git a/libc/sysdeps/unix/sysv/linux/powerpc/sysdep.c b/libc/sysdeps/unix/sysv/linux/powerpc/sysdep.c
new file mode 100644
index 000000000..f16c4c938
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/powerpc/sysdep.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <errno.h>
+
+/* This routine is jumped to by all the syscall handlers, to stash
+ an error number into errno. */
+int
+__syscall_error (int err_no)
+{
+ __set_errno (err_no);
+ return -1;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ppoll.c b/libc/sysdeps/unix/sysv/linux/ppoll.c
new file mode 100644
index 000000000..cfc86ba80
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ppoll.c
@@ -0,0 +1,76 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2006.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <time.h>
+#include <sys/poll.h>
+#include <kernel-features.h>
+#include <sysdep-cancel.h>
+
+
+#ifdef __NR_ppoll
+static int __generic_ppoll (struct pollfd *fds, nfds_t nfds,
+ const struct timespec *timeout,
+ const sigset_t *sigmask);
+
+
+int
+ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
+ const sigset_t *sigmask)
+{
+ /* The Linux kernel can in some situations update the timeout value.
+ We do not want that so use a local variable. */
+ struct timespec tval;
+ if (timeout != NULL)
+ {
+ tval = *timeout;
+ timeout = &tval;
+ }
+
+ int result;
+
+ if (SINGLE_THREAD_P)
+ result = INLINE_SYSCALL (ppoll, 5, fds, nfds, timeout, sigmask, _NSIG / 8);
+ else
+ {
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ result = INLINE_SYSCALL (ppoll, 5, fds, nfds, timeout, sigmask,
+ _NSIG / 8);
+
+ LIBC_CANCEL_RESET (oldtype);
+ }
+
+# ifndef __ASSUME_PPOLL
+ if (result == -1 && errno == ENOSYS)
+ result = __generic_ppoll (fds, nfds, timeout, sigmask);
+# endif
+
+ return result;
+}
+
+# ifndef __ASSUME_PPOLL
+# define ppoll static __generic_ppoll
+# endif
+#endif
+
+#ifndef __ASSUME_PPOLL
+# include <io/ppoll.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/pread.c b/libc/sysdeps/unix/sysv/linux/pread.c
new file mode 100644
index 000000000..d459e98f2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/pread.c
@@ -0,0 +1,96 @@
+/* Copyright (C) 1997-2000,2002,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pread
+# error "__NR_pread and __NR_pread64 both defined???"
+# endif
+# define __NR_pread __NR_pread64
+#endif
+
+#if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
+
+# if __ASSUME_PREAD_SYSCALL == 0
+static ssize_t __emulate_pread (int fd, void *buf, size_t count,
+ off_t offset) internal_function;
+# endif
+
+
+static ssize_t
+#ifdef NO_CANCELLATION
+inline __attribute ((always_inline))
+#endif
+do_pread (int fd, void *buf, size_t count, off_t offset)
+{
+ ssize_t result;
+
+ /* First try the syscall. */
+ assert (sizeof (offset) == 4);
+ result = INLINE_SYSCALL (pread, 5, fd, CHECK_N (buf, count), count,
+ __LONG_LONG_PAIR (offset >> 31, offset));
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread (fd, buf, count, offset);
+# endif
+
+ return result;
+}
+
+
+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)
+
+# define __libc_pread(fd, buf, count, offset) \
+ static internal_function __emulate_pread (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PREAD_SYSCALL == 0
+# include <sysdeps/posix/pread.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/pread64.c b/libc/sysdeps/unix/sysv/linux/pread64.c
new file mode 100644
index 000000000..07d8b68ac
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/pread64.c
@@ -0,0 +1,93 @@
+/* Copyright (C) 1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pread
+# error "__NR_pread and __NR_pread64 both defined???"
+# endif
+# define __NR_pread __NR_pread64
+#endif
+
+#if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
+
+# if __ASSUME_PREAD_SYSCALL == 0
+static ssize_t __emulate_pread64 (int fd, void *buf, size_t count,
+ off64_t offset) internal_function;
+# endif
+
+
+static ssize_t
+do_pread64 (int fd, void *buf, size_t count, off64_t offset)
+{
+ ssize_t result;
+
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pread, 5, fd, CHECK_N (buf, count), count,
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread64 (fd, buf, count, offset);
+# endif
+
+ return result;
+}
+
+
+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)
+
+# define __libc_pread64(fd, buf, count, offset) \
+ static internal_function __emulate_pread64 (fd, buf, count, offset)
+#endif
+
+# if __ASSUME_PREAD_SYSCALL == 0
+# include <sysdeps/posix/pread64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/prof-freq.c b/libc/sysdeps/unix/sysv/linux/prof-freq.c
new file mode 100644
index 000000000..49ec257e7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/prof-freq.c
@@ -0,0 +1,51 @@
+/* Determine realtime clock frequency.
+ Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/time.h>
+#include <libc-internal.h>
+#include <kernel-features.h>
+#include <ldsodefs.h>
+
+
+int
+__profile_frequency (void)
+{
+#ifdef __ASSUME_AT_CLKTCK
+ return GLRO(dl_clktck);
+#else
+ if (GLRO(dl_clktck) != 0)
+ return GLRO(dl_clktck);
+
+ struct itimerval tim;
+
+ tim.it_interval.tv_sec = 0;
+ tim.it_interval.tv_usec = 1;
+ tim.it_value.tv_sec = 0;
+ tim.it_value.tv_usec = 0;
+
+ __setitimer (ITIMER_REAL, &tim, 0);
+ __setitimer (ITIMER_REAL, 0, &tim);
+
+ if (tim.it_interval.tv_usec < 2)
+ return 0;
+
+ return 1000000 / tim.it_interval.tv_usec;
+#endif
+}
+libc_hidden_def (__profile_frequency)
diff --git a/libc/sysdeps/unix/sysv/linux/profil.c b/libc/sysdeps/unix/sysv/linux/profil.c
new file mode 100644
index 000000000..5918ecebf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/profil.c
@@ -0,0 +1,3 @@
+/* Linux defines the profil system call but doesn't actually implement
+ it. Use the generic posix implementation. */
+#include <sysdeps/posix/profil.c>
diff --git a/libc/sysdeps/unix/sysv/linux/pselect.c b/libc/sysdeps/unix/sysv/linux/pselect.c
new file mode 100644
index 000000000..0dd744f52
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/pselect.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2006.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <time.h>
+#include <sys/poll.h>
+#include <kernel-features.h>
+#include <sysdep-cancel.h>
+
+
+#ifdef __NR_pselect6
+static int __generic_pselect (int nfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds,
+ const struct timespec *timeout,
+ const sigset_t *sigmask);
+
+
+int
+__pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
+ const struct timespec *timeout, const sigset_t *sigmask)
+{
+ /* The Linux kernel can in some situations update the timeout value.
+ We do not want that so use a local variable. */
+ struct timespec tval;
+ if (timeout != NULL)
+ {
+ tval = *timeout;
+ timeout = &tval;
+ }
+
+ /* Note: the system call expects 7 values but on most architectures
+ we can only pass in 6 directly. If there is an architecture with
+ support for more parameters a new version of this file needs to
+ be created. */
+ struct
+ {
+ const sigset_t *ss;
+ size_t ss_len;
+ } data;
+
+ data.ss = sigmask;
+ data.ss_len = _NSIG / 8;
+
+ int result;
+
+#ifndef CALL_PSELECT6
+# define CALL_PSELECT6(nfds, readfds, writefds, exceptfds, timeout, data) \
+ INLINE_SYSCALL (pselect6, 6, nfds, readfds, writefds, exceptfds, \
+ timeout, data)
+#endif
+
+ if (SINGLE_THREAD_P)
+ result = CALL_PSELECT6 (nfds, readfds, writefds, exceptfds, timeout,
+ &data);
+ else
+ {
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ result = CALL_PSELECT6 (nfds, readfds, writefds, exceptfds, timeout,
+ &data);
+
+ LIBC_CANCEL_RESET (oldtype);
+ }
+
+# ifndef __ASSUME_PSELECT
+ if (result == -1 && errno == ENOSYS)
+ result = __generic_pselect (nfds, readfds, writefds, exceptfds, timeout,
+ sigmask);
+# endif
+
+ return result;
+}
+weak_alias (__pselect, pselect)
+strong_alias (__pselect, __libc_pselect)
+
+# ifndef __ASSUME_PSELECT
+# define __pselect static __generic_pselect
+# endif
+#endif
+
+#ifndef __ASSUME_PSELECT
+# include <misc/pselect.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/ptrace.c b/libc/sysdeps/unix/sysv/linux/ptrace.c
new file mode 100644
index 000000000..e33eee0ee
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ptrace.c
@@ -0,0 +1,113 @@
+/* Copyright (C) 1995,1996,1997,1998,2000,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/ptrace.h>
+#include <sys/user.h>
+#include <stdarg.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+long int
+ptrace (enum __ptrace_request request, ...)
+{
+ long int res, ret;
+ va_list ap;
+ pid_t pid;
+ void *addr, *data;
+
+ va_start (ap, request);
+ pid = va_arg (ap, pid_t);
+ addr = va_arg (ap, void *);
+ data = va_arg (ap, void *);
+ va_end (ap);
+
+ if (request > 0 && request < 4)
+ data = &ret;
+
+#if __BOUNDED_POINTERS__
+ switch (request)
+ {
+ case PTRACE_PEEKTEXT:
+ case PTRACE_PEEKDATA:
+ case PTRACE_PEEKUSER:
+ case PTRACE_POKETEXT:
+ case PTRACE_POKEDATA:
+ case PTRACE_POKEUSER:
+ (void) CHECK_1 ((int *) addr);
+ (void) CHECK_1 ((int *) data);
+ break;
+
+ case PTRACE_GETREGS:
+ case PTRACE_SETREGS:
+#ifdef __i386__
+ (void) CHECK_1 ((struct user_regs_struct *) data);
+#else
+ /* We don't know the size of data, so the best we can do is ensure
+ that `data' is valid for at least one word. */
+ (void) CHECK_1 ((int *) data);
+#endif
+ break;
+
+ case PTRACE_GETFPREGS:
+ case PTRACE_SETFPREGS:
+#ifdef __i386__
+ (void) CHECK_1 ((struct user_fpregs_struct *) data);
+#else
+ /* We don't know the size of data, so the best we can do is ensure
+ that `data' is valid for at least one word. */
+ (void) CHECK_1 ((int *) data);
+#endif
+ break;
+
+ case PTRACE_GETFPXREGS:
+ case PTRACE_SETFPXREGS:
+#ifdef __i386__
+ (void) CHECK_1 ((struct user_fpxregs_struct *) data);
+#else
+ /* We don't know the size of data, so the best we can do is ensure
+ that `data' is valid for at least one word. */
+ (void) CHECK_1 ((int *) data);
+#endif
+ break;
+
+ case PTRACE_TRACEME:
+ case PTRACE_CONT:
+ case PTRACE_KILL:
+ case PTRACE_SINGLESTEP:
+ case PTRACE_ATTACH:
+ case PTRACE_DETACH:
+ case PTRACE_SYSCALL:
+ /* Neither `data' nor `addr' needs any checks. */
+ break;
+ };
+#endif
+
+ res = INLINE_SYSCALL (ptrace, 4, request, pid,
+ __ptrvalue (addr), __ptrvalue (data));
+ if (res >= 0 && request > 0 && request < 4)
+ {
+ __set_errno (0);
+ return ret;
+ }
+
+ return res;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ptsname.c b/libc/sysdeps/unix/sysv/linux/ptsname.c
new file mode 100644
index 000000000..9c364b18b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ptsname.c
@@ -0,0 +1,167 @@
+/* Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <paths.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include <stdio-common/_itoa.h>
+
+/* Check if DEV corresponds to a master pseudo terminal device. */
+#define MASTER_P(Dev) \
+ (major ((Dev)) == 2 \
+ || (major ((Dev)) == 4 && minor ((Dev)) >= 128 && minor ((Dev)) < 192) \
+ || (major ((Dev)) >= 128 && major ((Dev)) < 136))
+
+/* Check if DEV corresponds to a slave pseudo terminal device. */
+#define SLAVE_P(Dev) \
+ (major ((Dev)) == 3 \
+ || (major ((Dev)) == 4 && minor ((Dev)) >= 192 && minor ((Dev)) < 256) \
+ || (major ((Dev)) >= 136 && major ((Dev)) < 144))
+
+/* Note that major number 4 corresponds to the old BSD style pseudo
+ terminal devices. As of Linux 2.1.115 these are no longer
+ supported. They have been replaced by major numbers 2 (masters)
+ and 3 (slaves). */
+
+/* Directory where we can find the slave pty nodes. */
+#define _PATH_DEVPTS "/dev/pts/"
+
+/* The are declared in getpt.c. */
+extern const char __libc_ptyname1[] attribute_hidden;
+extern const char __libc_ptyname2[] attribute_hidden;
+
+/* Static buffer for `ptsname'. */
+static char buffer[sizeof (_PATH_DEVPTS) + 20];
+
+
+/* Return the pathname of the pseudo terminal slave assoicated with
+ the master FD is open on, or NULL on errors.
+ The returned storage is good until the next call to this function. */
+char *
+ptsname (int fd)
+{
+ return __ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer;
+}
+
+
+/* Store at most BUFLEN characters of the pathname of the slave pseudo
+ terminal associated with the master FD is open on in BUF.
+ Return 0 on success, otherwise an error number. */
+int
+__ptsname_r (int fd, char *buf, size_t buflen)
+{
+ int save_errno = errno;
+ struct stat64 st;
+ unsigned int ptyno;
+
+ if (buf == NULL)
+ {
+ __set_errno (EINVAL);
+ return EINVAL;
+ }
+
+ if (!__isatty (fd))
+ {
+ __set_errno (ENOTTY);
+ return ENOTTY;
+ }
+
+#ifdef TIOCGPTN
+ if (__ioctl (fd, TIOCGPTN, &ptyno) == 0)
+ {
+ /* Buffer we use to print the number in. For a maximum size for
+ `int' of 8 bytes we never need more than 20 digits. */
+ char numbuf[21];
+ const char *devpts = _PATH_DEVPTS;
+ const size_t devptslen = strlen (_PATH_DEVPTS);
+ char *p;
+
+ numbuf[sizeof (numbuf) - 1] = '\0';
+ p = _itoa_word (ptyno, &numbuf[sizeof (numbuf) - 1], 10, 0);
+
+ if (buflen < devptslen + (&numbuf[sizeof (numbuf)] - p))
+ {
+ __set_errno (ERANGE);
+ return ERANGE;
+ }
+
+ memcpy (__stpcpy (buf, devpts), p, &numbuf[sizeof (numbuf)] - p);
+ }
+ else if (errno == EINVAL)
+#endif
+ {
+ char *p;
+
+ if (buflen < strlen (_PATH_TTY) + 3)
+ {
+ __set_errno (ERANGE);
+ return ERANGE;
+ }
+
+ if (__fxstat64 (_STAT_VER, fd, &st) < 0)
+ return errno;
+
+ /* Check if FD really is a master pseudo terminal. */
+ if (! MASTER_P (st.st_rdev))
+ {
+ __set_errno (ENOTTY);
+ return ENOTTY;
+ }
+
+ ptyno = minor (st.st_rdev);
+ /* This is for the old BSD pseudo terminals. As of Linux
+ 2.1.115 these are no longer supported. */
+ if (major (st.st_rdev) == 4)
+ ptyno -= 128;
+
+ if (ptyno / 16 >= strlen (__libc_ptyname1))
+ {
+ __set_errno (ENOTTY);
+ return ENOTTY;
+ }
+
+ p = __stpcpy (buf, _PATH_TTY);
+ p[0] = __libc_ptyname1[ptyno / 16];
+ p[1] = __libc_ptyname2[ptyno % 16];
+ p[2] = '\0';
+ }
+
+ if (__xstat64 (_STAT_VER, buf, &st) < 0)
+ return errno;
+
+ /* Check if the name we're about to return really corresponds to a
+ slave pseudo terminal. */
+ if (! S_ISCHR (st.st_mode) || ! SLAVE_P (st.st_rdev))
+ {
+ /* This really is a configuration problem. */
+ __set_errno (ENOTTY);
+ return ENOTTY;
+ }
+
+ __set_errno (save_errno);
+ return 0;
+}
+weak_alias (__ptsname_r, ptsname_r)
diff --git a/libc/sysdeps/unix/sysv/linux/pwrite.c b/libc/sysdeps/unix/sysv/linux/pwrite.c
new file mode 100644
index 000000000..7afb81451
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/pwrite.c
@@ -0,0 +1,96 @@
+/* Copyright (C) 1997-2000,2002,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pwrite
+# error "__NR_pwrite and __NR_pwrite64 both defined???"
+# endif
+# define __NR_pwrite __NR_pwrite64
+#endif
+
+#if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
+
+# if __ASSUME_PWRITE_SYSCALL == 0
+static ssize_t __emulate_pwrite (int fd, const void *buf, size_t count,
+ off_t offset) internal_function;
+# endif
+
+
+static ssize_t
+#ifdef NO_CANCELLATION
+inline __attribute ((always_inline))
+#endif
+do_pwrite (int fd, const void *buf, size_t count, off_t offset)
+{
+ ssize_t result;
+
+ /* First try the syscall. */
+ assert (sizeof (offset) == 4);
+ result = INLINE_SYSCALL (pwrite, 5, fd, CHECK_N (buf, count), count,
+ __LONG_LONG_PAIR (offset >> 31, offset));
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite (fd, buf, count, offset);
+# endif
+
+ return result;
+}
+
+
+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)
+
+# define __libc_pwrite(fd, buf, count, offset) \
+ static internal_function __emulate_pwrite (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PWRITE_SYSCALL == 0
+# include <sysdeps/posix/pwrite.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/pwrite64.c b/libc/sysdeps/unix/sysv/linux/pwrite64.c
new file mode 100644
index 000000000..a0a6a0831
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/pwrite64.c
@@ -0,0 +1,94 @@
+/* Copyright (C) 1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pwrite
+# error "__NR_pwrite and __NR_pwrite64 both defined???"
+# endif
+# define __NR_pwrite __NR_pwrite64
+#endif
+
+#if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
+
+# if __ASSUME_PWRITE_SYSCALL == 0
+static ssize_t __emulate_pwrite64 (int fd, const void *buf, size_t count,
+ off64_t offset) internal_function;
+# endif
+
+
+static ssize_t
+do_pwrite64 (int fd, const void *buf, size_t count, off64_t offset)
+{
+ ssize_t result;
+
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pwrite, 5, fd, CHECK_N (buf, count), count,
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite64 (fd, buf, count, offset);
+# endif
+
+ return result;
+}
+
+
+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)
+
+# define __libc_pwrite64(fd, buf, count, offset) \
+ static internal_function __emulate_pwrite64 (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PWRITE_SYSCALL == 0
+# include <sysdeps/posix/pwrite64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/readahead.c b/libc/sysdeps/unix/sysv/linux/readahead.c
new file mode 100644
index 000000000..dc628b2b2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/readahead.c
@@ -0,0 +1,48 @@
+/* Provide kernel hint to read ahead.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+
+#ifdef __NR_readahead
+
+ssize_t
+__readahead (int fd, off64_t offset, size_t count)
+{
+ return INLINE_SYSCALL (readahead, 4, fd, (off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff), count);
+}
+#else
+ssize_t
+__readahead (int fd, off64_t offset, size_t count)
+{
+ __set_errno (ENOSYS);
+ return -1;
+}
+stub_warning (readahead)
+
+# include <stub-tag.h>
+#endif
+
+weak_alias (__readahead, readahead)
diff --git a/libc/sysdeps/unix/sysv/linux/readdir64.c b/libc/sysdeps/unix/sysv/linux/readdir64.c
new file mode 100644
index 000000000..e2c500239
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/readdir64.c
@@ -0,0 +1,7 @@
+#define __READDIR __readdir64
+#define __GETDENTS __getdents64
+#define DIRENT_TYPE struct dirent64
+
+#include <sysdeps/unix/readdir.c>
+
+weak_alias (__readdir64, readdir64)
diff --git a/libc/sysdeps/unix/sysv/linux/readdir64_r.c b/libc/sysdeps/unix/sysv/linux/readdir64_r.c
new file mode 100644
index 000000000..bce56124e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/readdir64_r.c
@@ -0,0 +1,7 @@
+#define __READDIR_R __readdir64_r
+#define __GETDENTS __getdents64
+#define DIRENT_TYPE struct dirent64
+
+#include <sysdeps/unix/readdir_r.c>
+
+weak_alias (__readdir64_r, readdir64_r)
diff --git a/libc/sysdeps/unix/sysv/linux/readlinkat.c b/libc/sysdeps/unix/sysv/linux/readlinkat.c
new file mode 100644
index 000000000..136159650
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/readlinkat.c
@@ -0,0 +1,90 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysdep.h>
+#include <unistd.h>
+#include <kernel-features.h>
+
+
+/* Read the contents of the symbolic link PATH relative to FD into no
+ more than LEN bytes of BUF. */
+ssize_t
+readlinkat (fd, path, buf, len)
+ int fd;
+ const char *path;
+ char *buf;
+ size_t len;
+{
+ int result;
+
+#ifdef __NR_readlinkat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INLINE_SYSCALL (readlinkat, 4, fd, path, buf, len);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ char *pathbuf = NULL;
+
+ if (fd != AT_FDCWD && path[0] != '/')
+ {
+ size_t pathlen = strlen (path);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + pathlen;
+ pathbuf = __alloca (buflen);
+
+ __snprintf (pathbuf, buflen, procfd, fd, path);
+ path = pathbuf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+ result = INTERNAL_SYSCALL (readlink, err, 3, path, buf, len);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, pathbuf);
+ result = -1;
+ }
+
+ return result;
+#endif
+}
+libc_hidden_def (readlinkat)
diff --git a/libc/sysdeps/unix/sysv/linux/readonly-area.c b/libc/sysdeps/unix/sysv/linux/readonly-area.c
new file mode 100644
index 000000000..69e926a7a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/readonly-area.c
@@ -0,0 +1,103 @@
+/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <stdlib.h>
+#include <string.h>
+#include "libio/libioP.h"
+
+/* Return 1 if the whole area PTR .. PTR+SIZE is not writable.
+ Return -1 if it is writable. */
+
+int
+__readonly_area (const char *ptr, size_t size)
+{
+ const void *ptr_end = ptr + size;
+
+ FILE *fp = fopen ("/proc/self/maps", "rc");
+ if (fp == NULL)
+ {
+ /* It is the system administrator's choice to not have /proc
+ available to this process (e.g., because it runs in a chroot
+ environment. Don't fail in this case. */
+ if (errno == ENOENT
+ /* The kernel has a bug in that a process is denied access
+ to the /proc filesystem if it is set[ug]id. There has
+ been no willingness to change this in the kernel so
+ far. */
+ || errno == EACCES)
+ return 1;
+ return -1;
+ }
+
+ /* We need no locking. */
+ __fsetlocking (fp, FSETLOCKING_BYCALLER);
+
+ char *line = NULL;
+ size_t linelen = 0;
+
+ while (! feof_unlocked (fp))
+ {
+ if (_IO_getdelim (&line, &linelen, '\n', fp) <= 0)
+ break;
+
+ char *p;
+ uintptr_t from = strtoul (line, &p, 16);
+
+ if (p == line || *p++ != '-')
+ break;
+
+ char *q;
+ uintptr_t to = strtoul (p, &q, 16);
+
+ if (q == p || *q++ != ' ')
+ break;
+
+ if (from < (uintptr_t) ptr_end && to > (uintptr_t) ptr)
+ {
+ /* Found an entry that at least partially covers the area. */
+ if (*q++ != 'r' || *q++ != '-')
+ break;
+
+ if (from <= (uintptr_t) ptr && to >= (uintptr_t) ptr_end)
+ {
+ size = 0;
+ break;
+ }
+ else if (from <= (uintptr_t) ptr)
+ size -= to - (uintptr_t) ptr;
+ else if (to >= (uintptr_t) ptr_end)
+ size -= (uintptr_t) ptr_end - from;
+ else
+ size -= to - from;
+
+ if (!size)
+ break;
+ }
+ }
+
+ fclose (fp);
+ free (line);
+
+ /* If the whole area between ptr and ptr_end is covered by read-only
+ VMAs, return 1. Otherwise return -1. */
+ return size == 0 ? 1 : -1;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/readv.c b/libc/sysdeps/unix/sysv/linux/readv.c
new file mode 100644
index 000000000..250c00a07
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/readv.c
@@ -0,0 +1,76 @@
+/* readv supports all Linux kernels >= 2.0.
+ Copyright (C) 1997,1998,2000,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/param.h>
+#include <sys/uio.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+static ssize_t __atomic_readv_replacement (int, __const struct iovec *,
+ int) internal_function;
+
+
+/* Not all versions of the kernel support the large number of records. */
+#ifndef UIO_FASTIOV
+# define UIO_FASTIOV 8 /* 8 is a safe number. */
+#endif
+
+
+/* We should deal with kernel which have a smaller UIO_FASTIOV as well
+ as a very big count. */
+static ssize_t
+do_readv (int fd, const struct iovec *vector, int count)
+{
+ ssize_t bytes_read;
+
+ bytes_read = INLINE_SYSCALL (readv, 3, fd, CHECK_N (vector, count), count);
+
+ if (bytes_read >= 0 || errno != EINVAL || count <= UIO_FASTIOV)
+ return bytes_read;
+
+ return __atomic_readv_replacement (fd, vector, count);
+}
+
+
+ssize_t
+__libc_readv (fd, vector, count)
+ int fd;
+ const struct iovec *vector;
+ int count;
+{
+ if (SINGLE_THREAD_P)
+ return do_readv (fd, vector, count);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = do_readv (fd, vector, count);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+strong_alias (__libc_readv, __readv)
+weak_alias (__libc_readv, readv)
+
+#define __libc_readv static internal_function __atomic_readv_replacement
+#include <sysdeps/posix/readv.c>
diff --git a/libc/sysdeps/unix/sysv/linux/reboot.c b/libc/sysdeps/unix/sysv/linux/reboot.c
new file mode 100644
index 000000000..e936f0456
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/reboot.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996, 1997, 1998, 1999, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/reboot.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Call kernel with additional two arguments the syscall requires. */
+int
+reboot (int howto)
+{
+ return INLINE_SYSCALL (reboot, 3, (int) 0xfee1dead, 672274793, howto);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/recv.S b/libc/sysdeps/unix/sysv/linux/recv.S
new file mode 100644
index 000000000..331844abc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/recv.S
@@ -0,0 +1,6 @@
+#define socket recv
+#define __socket __libc_recv
+#define NARGS 4
+#define NEED_CANCELLATION
+#include <socket.S>
+weak_alias (__libc_recv, __recv)
diff --git a/libc/sysdeps/unix/sysv/linux/recvfrom.S b/libc/sysdeps/unix/sysv/linux/recvfrom.S
new file mode 100644
index 000000000..ccbb0a75d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/recvfrom.S
@@ -0,0 +1,6 @@
+#define socket recvfrom
+#define __socket __libc_recvfrom
+#define NARGS 6
+#define NEED_CANCELLATION
+#include <socket.S>
+weak_alias (__libc_recvfrom, __recvfrom)
diff --git a/libc/sysdeps/unix/sysv/linux/recvmsg.S b/libc/sysdeps/unix/sysv/linux/recvmsg.S
new file mode 100644
index 000000000..d44bc39f9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/recvmsg.S
@@ -0,0 +1,6 @@
+#define socket recvmsg
+#define __socket __libc_recvmsg
+#define NARGS 3
+#define NEED_CANCELLATION
+#include <socket.S>
+weak_alias (__libc_recvmsg, __recvmsg)
diff --git a/libc/sysdeps/unix/sysv/linux/renameat.c b/libc/sysdeps/unix/sysv/linux/renameat.c
new file mode 100644
index 000000000..86bb75a7b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/renameat.c
@@ -0,0 +1,184 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <kernel-features.h>
+#include <sysdep.h>
+
+
+#ifndef __ASSUME_ATFCTS
+void
+attribute_hidden
+__atfct_seterrno_2 (int errval, int fd1, const char *buf1, int fd2,
+ const char *buf2)
+{
+ if (buf1 != NULL || buf2 != NULL)
+ {
+ struct stat64 st;
+
+ if (errval == ENOTDIR)
+ {
+ /* This can mean either the file descriptor is invalid or
+ /proc is not mounted. */
+ if (buf1 != NULL)
+ {
+ if (__fxstat64 (_STAT_VER, fd1, &st) != 0)
+ /* errno is already set correctly. */
+ return;
+
+ /* If /proc is not mounted there is nothing we can do. */
+ if (S_ISDIR (st.st_mode)
+ && (__xstat64 (_STAT_VER, "/proc/self/fd", &st) != 0
+ || !S_ISDIR (st.st_mode)))
+ {
+ errval = ENOSYS;
+ goto out;
+ }
+ }
+
+ if (buf2 != NULL)
+ {
+ if (__fxstat64 (_STAT_VER, fd2, &st) != 0)
+ /* errno is already set correctly. */
+ return;
+
+ /* If /proc is not mounted there is nothing we can do. */
+ if (S_ISDIR (st.st_mode)
+ && (__xstat64 (_STAT_VER, "/proc/self/fd", &st) != 0
+ || !S_ISDIR (st.st_mode)))
+ errval = ENOSYS;
+ }
+ }
+ else if (errval == ENOENT)
+ {
+ /* This could mean the file descriptor is not valid. We
+ reuse BUF for the stat call. Find the slash after the
+ file descriptor number. */
+ if (buf1 != NULL)
+ {
+ *(char *) strchr (buf1 + sizeof "/proc/self/fd", '/') = '\0';
+
+ int e = __lxstat64 (_STAT_VER, buf1, &st);
+ if ((e == -1 && errno == ENOENT)
+ ||(e == 0 && !S_ISLNK (st.st_mode)))
+ {
+ errval = EBADF;
+ goto out;
+ }
+ }
+
+ if (buf2 != NULL)
+ {
+ *(char *) strchr (buf2 + sizeof "/proc/self/fd", '/') = '\0';
+
+ int e = __lxstat64 (_STAT_VER, buf2, &st);
+ if ((e == -1 && errno == ENOENT)
+ ||(e == 0 && !S_ISLNK (st.st_mode)))
+ errval = EBADF;
+ }
+ }
+ }
+
+ out:
+ __set_errno (errval);
+}
+#endif
+
+
+/* Rename the file OLD relative to OLDFD to NEW relative to NEWFD. */
+int
+renameat (oldfd, old, newfd, new)
+ int oldfd;
+ const char *old;
+ int newfd;
+ const char *new;
+{
+ int result;
+
+#ifdef __NR_renameat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INLINE_SYSCALL (renameat, 4, oldfd, old, newfd, new);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ char *bufold = NULL;
+
+ if (oldfd != AT_FDCWD && old[0] != '/')
+ {
+ size_t filelen = strlen (old);
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ bufold = alloca (buflen);
+
+ __snprintf (bufold, buflen, procfd, oldfd, old);
+ old = bufold;
+ }
+
+ char *bufnew = NULL;
+
+ if (newfd != AT_FDCWD && new[0] != '/')
+ {
+ size_t filelen = strlen (new);
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ bufnew = alloca (buflen);
+
+ __snprintf (bufnew, buflen, procfd, newfd, new);
+ new = bufnew;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+ result = INTERNAL_SYSCALL (rename, err, 2, old, new);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+ __atfct_seterrno_2 (INTERNAL_SYSCALL_ERRNO (result, err), newfd, bufnew,
+ oldfd, bufold);
+ result = -1;
+ }
+
+ return result;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/s390/Implies b/libc/sysdeps/unix/sysv/linux/s390/Implies
new file mode 100644
index 000000000..efda9d27c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/Implies
@@ -0,0 +1,3 @@
+# These supply the ABI compatibility for when long double was double.
+ieee754/ldbl-64-128
+ieee754/ldbl-opt
diff --git a/libc/sysdeps/unix/sysv/linux/s390/Makefile b/libc/sysdeps/unix/sysv/linux/s390/Makefile
new file mode 100644
index 000000000..5c5381871
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/Makefile
@@ -0,0 +1,8 @@
+64bit-predefine = __s390x__
+ifeq ($(subdir),rt)
+librt-routines += rt-sysdep
+endif
+
+ifeq ($(subdir),stdlib)
+gen-as-const-headers += ucontext_i.sym
+endif
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/elfclass.h b/libc/sysdeps/unix/sysv/linux/s390/bits/elfclass.h
new file mode 100644
index 000000000..dd3d02809
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/elfclass.h
@@ -0,0 +1,39 @@
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This file specifies the native word size of the machine, which indicates
+ the ELF file class used for executables and shared objects on this
+ machine. */
+
+#ifndef _LINK_H
+# error "Never use <bits/elfclass.h> directly; include <link.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#define __ELF_NATIVE_CLASS __WORDSIZE
+
+#if __WORDSIZE == 64
+/* 64 bit Linux for S/390 is exceptional as it has .hash section with
+ 64 bit entries. */
+typedef uint64_t Elf_Symndx;
+#else
+/* 32 bit Linux for S/390 has normal .hash section entries with 32 bits. */
+typedef uint32_t Elf_Symndx;
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/environments.h b/libc/sysdeps/unix/sysv/linux/s390/bits/environments.h
new file mode 100644
index 000000000..713d21c9a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/environments.h
@@ -0,0 +1,87 @@
+/* Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _UNISTD_H
+# error "Never include this file directly. Use <unistd.h> instead"
+#endif
+
+#include <bits/wordsize.h>
+
+/* This header should define the following symbols under the described
+ situations. A value `1' means that the model is always supported,
+ `-1' means it is never supported. Undefined means it cannot be
+ statically decided.
+
+ _POSIX_V6_ILP32_OFF32 32bit int, long, pointers, and off_t type
+ _POSIX_V6_ILP32_OFFBIG 32bit int, long, and pointers and larger off_t type
+
+ _POSIX_V6_LP64_OFF32 64bit long and pointers and 32bit off_t type
+ _POSIX_V6_LPBIG_OFFBIG 64bit long and pointers and large off_t type
+
+ The macros _XBS5_ILP32_OFF32, _XBS5_ILP32_OFFBIG, _XBS5_LP64_OFF32, and
+ _XBS5_LPBIG_OFFBIG were used in previous versions of the Unix standard
+ and are available only for compatibility.
+*/
+
+#if __WORDSIZE == 64
+
+/* Environments with 32-bit wide pointers are optionally provided.
+ Therefore following macros aren't defined:
+ # undef _POSIX_V6_ILP32_OFF32
+ # undef _POSIX_V6_ILP32_OFFBIG
+ # undef _XBS5_ILP32_OFF32
+ # undef _XBS5_ILP32_OFFBIG
+ and users need to check at runtime. */
+
+/* We also have no use (for now) for an environment with bigger pointers
+ and offsets. */
+# define _POSIX_V6_LPBIG_OFFBIG -1
+# define _XBS5_LPBIG_OFFBIG -1
+
+/* By default we have 64-bit wide `long int', pointers and `off_t'. */
+# define _POSIX_V6_LP64_OFF64 1
+# define _XBS5_LP64_OFF64 1
+
+#else /* __WORDSIZE == 32 */
+
+/* By default we have 32-bit wide `int', `long int', pointers and `off_t'
+ and all platforms support LFS. */
+# define _POSIX_V6_ILP32_OFF32 1
+# define _POSIX_V6_ILP32_OFFBIG 1
+# define _XBS5_ILP32_OFF32 1
+# define _XBS5_ILP32_OFFBIG 1
+
+/* We optionally provide an environment with the above size but an 64-bit
+ side `off_t'. Therefore we don't define _XBS5_ILP32_OFFBIG. */
+
+/* Environments with 64-bit wide pointers can be provided,
+ so these macros aren't defined:
+ # undef _POSIX_V6_LP64_OFF64
+ # undef _POSIX_V6_LPBIG_OFFBIG
+ # undef _XBS5_LP64_OFF64
+ # undef _XBS5_LPBIG_OFFBIG
+ and sysconf tests for it at runtime. */
+
+#endif /* __WORDSIZE == 32 */
+
+#define __ILP32_OFF32_CFLAGS "-m31"
+#define __ILP32_OFFBIG_CFLAGS "-m31 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+#define __ILP32_OFF32_LDFLAGS "-m31"
+#define __ILP32_OFFBIG_LDFLAGS "-m31"
+#define __LP64_OFF64_CFLAGS "-m64"
+#define __LP64_OFF64_LDFLAGS "-m64"
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/fcntl.h b/libc/sysdeps/unix/sysv/linux/s390/bits/fcntl.h
new file mode 100644
index 000000000..e5a917dbf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/fcntl.h
@@ -0,0 +1,256 @@
+/* O_*, F_*, FD_* bit values for Linux.
+ Copyright (C) 2000, 2001, 2002, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <sys/types.h>
+#include <bits/wordsize.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+
+
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on an ext2 file system */
+#define O_ACCMODE 0003
+#define O_RDONLY 00
+#define O_WRONLY 01
+#define O_RDWR 02
+#define O_CREAT 0100 /* not fcntl */
+#define O_EXCL 0200 /* not fcntl */
+#define O_NOCTTY 0400 /* not fcntl */
+#define O_TRUNC 01000 /* not fcntl */
+#define O_APPEND 02000
+#define O_NONBLOCK 04000
+#define O_NDELAY O_NONBLOCK
+#define O_SYNC 010000
+#define O_FSYNC O_SYNC
+#define O_ASYNC 020000
+
+#ifdef __USE_GNU
+# define O_DIRECT 040000 /* Direct disk access. */
+# define O_DIRECTORY 0200000 /* Must be a directory. */
+# define O_NOFOLLOW 0400000 /* Do not follow links. */
+# define O_NOATIME 01000000 /* Do not set atime. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+# if __WORDSIZE == 64
+/* Not necessary, files are always with 64bit off_t. */
+# define O_LARGEFILE 0
+# else
+# define O_LARGEFILE 0100000
+# endif
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#if __WORDSIZE == 64
+# define F_GETLK 5 /* Get record locking info. */
+# define F_SETLK 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW 7 /* Set record locking info (blocking). */
+/* Not necessary, we always have 64-bit offsets. */
+# define F_GETLK64 5 /* Get record locking info. */
+# define F_SETLK64 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW64 7 /* Set record locking info (blocking). */
+#else
+# ifndef __USE_FILE_OFFSET64
+# define F_GETLK 5 /* Get record locking info. */
+# define F_SETLK 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW 7 /* Set record locking info (blocking). */
+# else
+# define F_GETLK F_GETLK64 /* Get record locking info. */
+# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
+# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
+# endif
+# define F_GETLK64 12 /* Get record locking info. */
+# define F_SETLK64 13 /* Set record locking info (non-blocking). */
+# define F_SETLKW64 14 /* Set record locking info (blocking). */
+#endif
+
+#if defined __USE_BSD || defined __USE_UNIX98
+# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */
+# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+#endif
+
+/* For F_[GET|SET]FD. */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
+#define F_RDLCK 0 /* Read lock. */
+#define F_WRLCK 1 /* Write lock. */
+#define F_UNLCK 2 /* Remove lock. */
+
+/* for old implementation of bsd flock () */
+#define F_EXLCK 4 /* or 3 */
+#define F_SHLCK 8 /* or 4 */
+
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation */
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#endif
+
+struct flock
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+#if __WORDSIZE == 64 || !defined __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
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# if __WORDSIZE == 64
+# define POSIX_FADV_DONTNEED 6 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 7 /* Data will be accessed once. */
+# else
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+# endif
+#endif
+
+
+#ifdef __USE_GNU
+/* Flags for SYNC_FILE_RANGE. */
+# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
+ in the range before performing the
+ write. */
+# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
+ dirty pages in the range which are
+ not presently under writeback. */
+# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
+ the range after performing the
+ write. */
+
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+#endif
+
+__BEGIN_DECLS
+
+#ifdef __USE_GNU
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+
+/* Selective file content synch'ing. */
+extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
+ unsigned int __flags);
+
+
+/* Splice address range into a pipe. */
+extern int vmsplice (int __fdout, const struct iovec *__iov, size_t __count,
+ unsigned int __flags);
+
+/* Splice two files together. */
+extern int splice (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+/* In-kernel implementation of tee for pipe buffers. */
+extern int tee (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+#endif
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/ipc.h b/libc/sysdeps/unix/sysv/linux/s390/bits/ipc.h
new file mode 100644
index 000000000..e3a82d0c4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/ipc.h
@@ -0,0 +1,61 @@
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IPC_H
+# error "Never use <bits/ipc.h> directly; include <sys/ipc.h> instead."
+#endif
+
+#include <bits/types.h>
+#include <bits/wordsize.h>
+
+/* Mode bits for `msgget', `semget', and `shmget'. */
+#define IPC_CREAT 01000 /* Create key if key does not exist. */
+#define IPC_EXCL 02000 /* Fail if key exists. */
+#define IPC_NOWAIT 04000 /* Return error on wait. */
+
+/* Control commands for `msgctl', `semctl', and `shmctl'. */
+#define IPC_RMID 0 /* Remove identifier. */
+#define IPC_SET 1 /* Set `ipc_perm' options. */
+#define IPC_STAT 2 /* Get `ipc_perm' options. */
+#ifdef __USE_GNU
+#define IPC_INFO 3 /* See ipcs. */
+#endif
+
+/* Special key values. */
+#define IPC_PRIVATE ((__key_t) 0) /* Private key. */
+
+
+/* Data structure used to pass permission information to IPC operations. */
+struct ipc_perm
+ {
+ __key_t __key; /* Key. */
+ __uid_t uid; /* Owner's user ID. */
+ __gid_t gid; /* Owner's group ID. */
+ __uid_t cuid; /* Creator's user ID. */
+ __gid_t cgid; /* Creator's group ID. */
+#if __WORDSIZE == 64
+ __mode_t mode; /* Read/write permission. */
+#else
+ unsigned short int mode; /* Read/write permission. */
+ unsigned short int __pad1;
+#endif
+ unsigned short int __seq; /* Sequence number. */
+ unsigned short int __pad2;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ };
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/mman.h b/libc/sysdeps/unix/sysv/linux/s390/bits/mman.h
new file mode 100644
index 000000000..d25531c28
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/mman.h
@@ -0,0 +1,104 @@
+/* Definitions for POSIX memory map interface. Linux/s390 version.
+ Copyright (C) 2000,2001,2002,2003,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MMAN_H
+# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead."
+#endif
+
+/* The following definitions basically come from the kernel headers.
+ But the kernel header is not namespace clean. */
+
+
+/* Protections are chosen from these bits, OR'd together. The
+ implementation does not necessarily support PROT_EXEC or PROT_WRITE
+ without PROT_READ. The only guarantees are that no writing will be
+ allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
+
+#define PROT_READ 0x1 /* Page can be read. */
+#define PROT_WRITE 0x2 /* Page can be written. */
+#define PROT_EXEC 0x4 /* Page can be executed. */
+#define PROT_NONE 0x0 /* Page can not be accessed. */
+#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
+ growsdown vma (mprotect only). */
+#define PROT_GROWSUP 0x02000000 /* Extend change to start of
+ growsup vma (mprotect only). */
+
+/* Sharing types (must choose one and only one of these). */
+#define MAP_SHARED 0x01 /* Share changes. */
+#define MAP_PRIVATE 0x02 /* Changes are private. */
+#ifdef __USE_MISC
+# define MAP_TYPE 0x0f /* Mask for type of mapping. */
+#endif
+
+/* Other flags. */
+#define MAP_FIXED 0x10 /* Interpret addr exactly. */
+#ifdef __USE_MISC
+# define MAP_FILE 0
+# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
+# define MAP_ANON MAP_ANONYMOUS
+#endif
+
+/* These are Linux-specific. */
+#ifdef __USE_MISC
+# define MAP_GROWSDOWN 0x00100 /* Stack-like segment. */
+# define MAP_GROWSUP 0x00200 /* Register stack-like segment */
+# define MAP_DENYWRITE 0x00800 /* ETXTBSY */
+# define MAP_EXECUTABLE 0x01000 /* Mark it as an executable. */
+# define MAP_LOCKED 0x02000 /* Lock the mapping. */
+# define MAP_NORESERVE 0x04000 /* Don't check for reservations. */
+# define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */
+# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
+#endif
+
+/* Flags to `msync'. */
+#define MS_ASYNC 1 /* Sync memory asynchronously. */
+#define MS_SYNC 4 /* Synchronous memory sync. */
+#define MS_INVALIDATE 2 /* Invalidate the caches. */
+
+/* Flags for `mlockall'. */
+#define MCL_CURRENT 1 /* Lock all currently mapped pages. */
+#define MCL_FUTURE 2 /* Lock all additions to address
+ space. */
+
+/* Flags for `mremap'. */
+#ifdef __USE_GNU
+# define MREMAP_MAYMOVE 1
+# define MREMAP_FIXED 2
+#endif
+
+/* Advice to `madvise'. */
+#ifdef __USE_BSD
+# define MADV_NORMAL 0 /* No further special treatment. */
+# define MADV_RANDOM 1 /* Expect random page references. */
+# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define MADV_WILLNEED 3 /* Will need these pages. */
+# define MADV_DONTNEED 4 /* Don't need these pages. */
+# define MADV_REMOVE 9 /* Remove these pages and resources. */
+# define MADV_DONTFORK 10 /* Do not inherit across fork. */
+# define MADV_DOFORK 11 /* Do inherit across fork. */
+#endif
+
+/* The POSIX people had to invent similar names for the same things. */
+#ifdef __USE_XOPEN2K
+# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/msq.h b/libc/sysdeps/unix/sysv/linux/s390/bits/msq.h
new file mode 100644
index 000000000..ecdd03e17
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/msq.h
@@ -0,0 +1,84 @@
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MSG_H
+# error "Never use <bits/msq.h> directly; include <sys/msg.h> instead."
+#endif
+
+#include <bits/types.h>
+#include <bits/wordsize.h>
+
+/* Define options for message queue functions. */
+#define MSG_NOERROR 010000 /* no error if message is too big */
+#ifdef __USE_GNU
+# define MSG_EXCEPT 020000 /* recv any msg except of specified type */
+#endif
+
+/* Types used in the structure definition. */
+typedef unsigned long int msgqnum_t;
+typedef unsigned long int msglen_t;
+
+
+/* Structure of record for one message inside the kernel.
+ The type `struct msg' is opaque. */
+struct msqid_ds
+{
+ struct ipc_perm msg_perm; /* structure describing operation permission */
+ __time_t msg_stime; /* time of last msgsnd command */
+#if __WORDSIZE != 64
+ unsigned long int __unused1;
+#endif
+ __time_t msg_rtime; /* time of last msgrcv command */
+#if __WORDSIZE != 64
+ unsigned long int __unused2;
+#endif
+ __time_t msg_ctime; /* time of last change */
+#if __WORDSIZE != 64
+ unsigned long int __unused3;
+#endif
+ unsigned long int __msg_cbytes; /* current number of bytes on queue */
+ msgqnum_t msg_qnum; /* number of messages currently on queue */
+ msglen_t msg_qbytes; /* max number of bytes allowed on queue */
+ __pid_t msg_lspid; /* pid of last msgsnd() */
+ __pid_t msg_lrpid; /* pid of last msgrcv() */
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+};
+
+#ifdef __USE_MISC
+
+# define msg_cbytes __msg_cbytes
+
+/* ipcs ctl commands */
+# define MSG_STAT 11
+# define MSG_INFO 12
+
+/* buffer for msgctl calls IPC_INFO, MSG_INFO */
+struct msginfo
+ {
+ int msgpool;
+ int msgmap;
+ int msgmax;
+ int msgmnb;
+ int msgmni;
+ int msgssz;
+ int msgtql;
+ unsigned short int msgseg;
+ };
+
+#endif /* __USE_MISC */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/sem.h b/libc/sysdeps/unix/sysv/linux/s390/bits/sem.h
new file mode 100644
index 000000000..1fb152c3a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/sem.h
@@ -0,0 +1,92 @@
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SEM_H
+# error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
+#endif
+
+#include <bits/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 != 64
+ unsigned long int __unused1;
+#endif
+ __time_t sem_ctime; /* last time changed by semctl() */
+#if __WORDSIZE != 64
+ unsigned long int __unused2;
+#endif
+ unsigned long int sem_nsems; /* number of semaphores in set */
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+};
+
+/* The user should define a union like the following to use it for arguments
+ for `semctl'.
+
+ union semun
+ {
+ int val; <= value for SETVAL
+ struct semid_ds *buf; <= buffer for IPC_STAT & IPC_SET
+ unsigned short int *array; <= array for GETALL & SETALL
+ struct seminfo *__buf; <= buffer for IPC_INFO
+ };
+
+ Previous versions of this file used to define this union but this is
+ incorrect. One can test the macro _SEM_SEMUN_UNDEFINED to see whether
+ one must define the union or not. */
+#define _SEM_SEMUN_UNDEFINED 1
+
+#ifdef __USE_MISC
+
+/* ipcs ctl cmds */
+# define SEM_STAT 18
+# define SEM_INFO 19
+
+struct seminfo
+{
+ int semmap;
+ int semmni;
+ int semmns;
+ int semmnu;
+ int semmsl;
+ int semopm;
+ int semume;
+ int semusz;
+ int semvmx;
+ int semaem;
+};
+
+#endif /* __USE_MISC */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/shm.h b/libc/sysdeps/unix/sysv/linux/s390/bits/shm.h
new file mode 100644
index 000000000..d88ed36ef
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/shm.h
@@ -0,0 +1,110 @@
+/* Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_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 */
+
+/* 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 set of semaphores. */
+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 != 64
+ unsigned long int __unused1;
+#endif
+ __time_t shm_dtime; /* time of last shmdt() */
+#if __WORDSIZE != 64
+ unsigned long int __unused2;
+#endif
+ __time_t shm_ctime; /* time of last change by shmctl() */
+#if __WORDSIZE != 64
+ unsigned long int __unused3;
+#endif
+ __pid_t shm_cpid; /* pid of creator */
+ __pid_t shm_lpid; /* pid of last shmop */
+ shmatt_t shm_nattch; /* number of current attaches */
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+ };
+
+#ifdef __USE_MISC
+
+/* ipcs ctl commands */
+# define SHM_STAT 13
+# define SHM_INFO 14
+
+/* shm_mode upper byte flags */
+# define SHM_DEST 01000 /* segment will be destroyed on last detach */
+# define SHM_LOCKED 02000 /* segment will not be swapped */
+# define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */
+# define SHM_NORESERVE 010000 /* don't check for reservations */
+
+struct shminfo
+ {
+ unsigned long int shmmax;
+ unsigned long int shmmin;
+ unsigned long int shmmni;
+ unsigned long int shmseg;
+ unsigned long int shmall;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+ };
+
+struct shm_info
+ {
+ int used_ids;
+ unsigned long int shm_tot; /* total allocated shm */
+ unsigned long int shm_rss; /* total resident shm */
+ unsigned long int shm_swp; /* total swapped shm */
+ unsigned long int swap_attempts;
+ unsigned long int swap_successes;
+ };
+
+#endif /* __USE_MISC */
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/sigaction.h b/libc/sysdeps/unix/sysv/linux/s390/bits/sigaction.h
new file mode 100644
index 000000000..308cb5bd7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/sigaction.h
@@ -0,0 +1,110 @@
+/* Definitions for 31 & 64 bit S/390 sigaction.
+ Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIGNAL_H
+# error "Never include <bits/sigaction.h> directly; use <signal.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+/* Structure describing the action to be taken when a signal arrives. */
+struct sigaction
+ {
+ /* Signal handler. */
+#ifdef __USE_POSIX199309
+ union
+ {
+ /* Used if SA_SIGINFO is not set. */
+ __sighandler_t sa_handler;
+ /* Used if SA_SIGINFO is set. */
+ void (*sa_sigaction) (int, siginfo_t *, void *);
+ }
+ __sigaction_handler;
+# define sa_handler __sigaction_handler.sa_handler
+# define sa_sigaction __sigaction_handler.sa_sigaction
+#else
+ __sighandler_t sa_handler;
+#endif
+
+ /* Special flags. */
+ unsigned long int sa_flags;
+
+ /* Restore handler. */
+ void (*sa_restorer) (void);
+
+ /* Additional set of signals to be blocked. */
+ __sigset_t sa_mask;
+ };
+#else
+/* Structure describing the action to be taken when a signal arrives. */
+struct sigaction
+ {
+ /* Signal handler. */
+#ifdef __USE_POSIX199309
+ union
+ {
+ /* Used if SA_SIGINFO is not set. */
+ __sighandler_t sa_handler;
+ /* Used if SA_SIGINFO is set. */
+ void (*sa_sigaction) (int, siginfo_t *, void *);
+ }
+ __sigaction_handler;
+# define sa_handler __sigaction_handler.sa_handler
+# define sa_sigaction __sigaction_handler.sa_sigaction
+#else
+ __sighandler_t sa_handler;
+#endif
+
+ /* Additional set of signals to be blocked. */
+ __sigset_t sa_mask;
+
+ /* Special flags. */
+ int sa_flags;
+
+ /* Restore handler. */
+ void (*sa_restorer) (void);
+ };
+#endif
+
+/* Bits in `sa_flags'. */
+#define SA_NOCLDSTOP 1 /* Don't send SIGCHLD when children stop. */
+#define SA_NOCLDWAIT 2 /* Don't create zombie on child death. */
+#define SA_SIGINFO 4 /* Invoke signal-catching function with
+ three arguments instead of one. */
+#if defined __USE_UNIX98 || defined __USE_MISC
+# define SA_ONSTACK 0x08000000 /* Use signal stack by using `sa_restorer'. */
+# define SA_RESTART 0x10000000 /* Restart syscall on signal return. */
+# define SA_NODEFER 0x40000000 /* Don't automatically block the signal when
+ its handler is being executed. */
+# define SA_RESETHAND 0x80000000 /* Reset to SIG_DFL on entry to handler. */
+#endif
+#ifdef __USE_MISC
+# define SA_INTERRUPT 0x20000000 /* Historical no-op. */
+
+/* Some aliases for the SA_ constants. */
+# define SA_NOMASK SA_NODEFER
+# define SA_ONESHOT SA_RESETHAND
+# define SA_STACK SA_ONSTACK
+#endif
+
+/* Values for the HOW argument to `sigprocmask'. */
+#define SIG_BLOCK 0 /* Block signals. */
+#define SIG_UNBLOCK 1 /* Unblock signals. */
+#define SIG_SETMASK 2 /* Set the set of blocked signals. */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/siginfo.h b/libc/sysdeps/unix/sysv/linux/s390/bits/siginfo.h
new file mode 100644
index 000000000..0b7985313
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/siginfo.h
@@ -0,0 +1,311 @@
+/* siginfo_t, sigevent and constants. S/390 version.
+ Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#if !defined _SIGNAL_H && !defined __need_siginfo_t \
+ && !defined __need_sigevent_t
+# error "Never include this file directly. Use <signal.h> instead"
+#endif
+
+#include <bits/wordsize.h>
+
+#if (!defined __have_sigval_t \
+ && (defined _SIGNAL_H || defined __need_siginfo_t \
+ || defined __need_sigevent_t))
+# define __have_sigval_t 1
+
+/* Type for data associated with a signal. */
+typedef union sigval
+ {
+ int sival_int;
+ void *sival_ptr;
+ } sigval_t;
+#endif
+
+#if (!defined __have_siginfo_t \
+ && (defined _SIGNAL_H || defined __need_siginfo_t))
+# define __have_siginfo_t 1
+
+# define __SI_MAX_SIZE 128
+# if __WORDSIZE == 64
+# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 4)
+# else
+# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
+# endif
+
+typedef struct siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_errno; /* If non-zero, an errno value associated with
+ this signal, as defined in <errno.h>. */
+ int si_code; /* Signal code. */
+
+ union
+ {
+ int _pad[__SI_PAD_SIZE];
+
+ /* kill(). */
+ struct
+ {
+ __pid_t si_pid; /* Sending process ID. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ } _kill;
+
+ /* POSIX.1b timers. */
+ struct
+ {
+ int si_tid; /* Timer ID. */
+ int si_overrun; /* Overrun count. */
+ sigval_t si_sigval; /* Signal value. */
+ } _timer;
+
+ /* POSIX.1b signals. */
+ struct
+ {
+ __pid_t si_pid; /* Sending process ID. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ sigval_t si_sigval; /* Signal value. */
+ } _rt;
+
+ /* SIGCHLD. */
+ struct
+ {
+ __pid_t si_pid; /* Which child. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ int si_status; /* Exit value or signal. */
+ __clock_t si_utime;
+ __clock_t si_stime;
+ } _sigchld;
+
+ /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
+ struct
+ {
+ void *si_addr; /* Faulting insn/memory ref. */
+ int si_trapno;
+ } _sigfault;
+
+ /* SIGPOLL. */
+ struct
+ {
+ long int si_band; /* Band event for SIGPOLL. */
+ int si_fd;
+ } _sigpoll;
+ } _sifields;
+ } siginfo_t;
+
+
+/* X/Open requires some more fields with fixed names. */
+# define si_pid _sifields._kill.si_pid
+# define si_uid _sifields._kill.si_uid
+# define si_timerid _sifields._timer.si_tid
+# define si_overrun _sifields._timer.si_overrun
+# define si_status _sifields._sigchld.si_status
+# define si_utime _sifields._sigchld.si_utime
+# define si_stime _sifields._sigchld.si_stime
+# define si_value _sifields._rt.si_sigval
+# define si_int _sifields._rt.si_sigval.sival_int
+# define si_ptr _sifields._rt.si_sigval.sival_ptr
+# define si_addr _sifields._sigfault.si_addr
+# define si_trapno _sifields._sigfault.si_trapno
+# define si_band _sifields._sigpoll.si_band
+# define si_fd _sifields._sigpoll.si_fd
+
+
+/* Values for `si_code'. Positive values are reserved for kernel-generated
+ signals. */
+enum
+{
+ SI_ASYNCNL = -60, /* Sent by asynch name lookup completion. */
+# define SI_ASYNCNL SI_ASYNCNL
+ SI_TKILL = -6, /* Sent by tkill. */
+# define SI_TKILL SI_TKILL
+ SI_SIGIO, /* Sent by queued SIGIO. */
+# define SI_SIGIO SI_SIGIO
+ SI_ASYNCIO, /* Sent by AIO completion. */
+# define SI_ASYNCIO SI_ASYNCIO
+ SI_MESGQ, /* Sent by real time mesq state change. */
+# define SI_MESGQ SI_MESGQ
+ SI_TIMER, /* Sent by timer expiration. */
+# define SI_TIMER SI_TIMER
+ SI_QUEUE, /* Sent by sigqueue. */
+# define SI_QUEUE SI_QUEUE
+ SI_USER, /* Sent by kill, sigsend, raise. */
+# define SI_USER SI_USER
+ SI_KERNEL = 0x80 /* Send by kernel. */
+#define SI_KERNEL SI_KERNEL
+};
+
+
+/* `si_code' values for SIGILL signal. */
+enum
+{
+ ILL_ILLOPC = 1, /* Illegal opcode. */
+# define ILL_ILLOPC ILL_ILLOPC
+ ILL_ILLOPN, /* Illegal operand. */
+# define ILL_ILLOPN ILL_ILLOPN
+ ILL_ILLADR, /* Illegal addressing mode. */
+# define ILL_ILLADR ILL_ILLADR
+ ILL_ILLTRP, /* Illegal trap. */
+# define ILL_ILLTRP ILL_ILLTRP
+ ILL_PRVOPC, /* Privileged opcode. */
+# define ILL_PRVOPC ILL_PRVOPC
+ ILL_PRVREG, /* Privileged register. */
+# define ILL_PRVREG ILL_PRVREG
+ ILL_COPROC, /* Coprocessor error. */
+# define ILL_COPROC ILL_COPROC
+ ILL_BADSTK /* Internal stack error. */
+# define ILL_BADSTK ILL_BADSTK
+};
+
+/* `si_code' values for SIGFPE signal. */
+enum
+{
+ FPE_INTDIV = 1, /* Integer divide by zero. */
+# define FPE_INTDIV FPE_INTDIV
+ FPE_INTOVF, /* Integer overflow. */
+# define FPE_INTOVF FPE_INTOVF
+ FPE_FLTDIV, /* Floating point divide by zero. */
+# define FPE_FLTDIV FPE_FLTDIV
+ FPE_FLTOVF, /* Floating point overflow. */
+# define FPE_FLTOVF FPE_FLTOVF
+ FPE_FLTUND, /* Floating point underflow. */
+# define FPE_FLTUND FPE_FLTUND
+ FPE_FLTRES, /* Floating point inexact result. */
+# define FPE_FLTRES FPE_FLTRES
+ FPE_FLTINV, /* Floating point invalid operation. */
+# define FPE_FLTINV FPE_FLTINV
+ FPE_FLTSUB /* Subscript out of range. */
+# define FPE_FLTSUB FPE_FLTSUB
+};
+
+/* `si_code' values for SIGSEGV signal. */
+enum
+{
+ SEGV_MAPERR = 1, /* Address not mapped to object. */
+# define SEGV_MAPERR SEGV_MAPERR
+ SEGV_ACCERR /* Invalid permissions for mapped object. */
+# define SEGV_ACCERR SEGV_ACCERR
+};
+
+/* `si_code' values for SIGBUS signal. */
+enum
+{
+ BUS_ADRALN = 1, /* Invalid address alignment. */
+# define BUS_ADRALN BUS_ADRALN
+ BUS_ADRERR, /* Non-existant physical address. */
+# define BUS_ADRERR BUS_ADRERR
+ BUS_OBJERR /* Object specific hardware error. */
+# define BUS_OBJERR BUS_OBJERR
+};
+
+/* `si_code' values for SIGTRAP signal. */
+enum
+{
+ TRAP_BRKPT = 1, /* Process breakpoint. */
+# define TRAP_BRKPT TRAP_BRKPT
+ TRAP_TRACE /* Process trace trap. */
+# define TRAP_TRACE TRAP_TRACE
+};
+
+/* `si_code' values for SIGCHLD signal. */
+enum
+{
+ CLD_EXITED = 1, /* Child has exited. */
+# define CLD_EXITED CLD_EXITED
+ CLD_KILLED, /* Child was killed. */
+# define CLD_KILLED CLD_KILLED
+ CLD_DUMPED, /* Child terminated abnormally. */
+# define CLD_DUMPED CLD_DUMPED
+ CLD_TRAPPED, /* Traced child has trapped. */
+# define CLD_TRAPPED CLD_TRAPPED
+ CLD_STOPPED, /* Child has stopped. */
+# define CLD_STOPPED CLD_STOPPED
+ CLD_CONTINUED /* Stopped child has continued. */
+# define CLD_CONTINUED CLD_CONTINUED
+};
+
+/* `si_code' values for SIGPOLL signal. */
+enum
+{
+ POLL_IN = 1, /* Data input available. */
+# define POLL_IN POLL_IN
+ POLL_OUT, /* Output buffers available. */
+# define POLL_OUT POLL_OUT
+ POLL_MSG, /* Input message available. */
+# define POLL_MSG POLL_MSG
+ POLL_ERR, /* I/O error. */
+# define POLL_ERR POLL_ERR
+ POLL_PRI, /* High priority input available. */
+# define POLL_PRI POLL_PRI
+ POLL_HUP /* Device disconnected. */
+# define POLL_HUP POLL_HUP
+};
+
+# undef __need_siginfo_t
+#endif /* !have siginfo_t && (have _SIGNAL_H || need siginfo_t). */
+
+
+#if (defined _SIGNAL_H || defined __need_sigevent_t) \
+ && !defined __have_sigevent_t
+# define __have_sigevent_t 1
+
+/* Structure to transport application-defined values with signals. */
+# define __SIGEV_MAX_SIZE 64
+# if __WORDSIZE == 64
+# define __SIGEV_PAD_SIZE ((__SIGEV_MAX_SIZE / sizeof (int)) - 4)
+# else
+# define __SIGEV_PAD_SIZE ((__SIGEV_MAX_SIZE / sizeof (int)) - 3)
+# endif
+
+typedef struct sigevent
+ {
+ sigval_t sigev_value;
+ int sigev_signo;
+ int sigev_notify;
+
+ union
+ {
+ int _pad[__SIGEV_PAD_SIZE];
+
+ struct
+ {
+ void (*_function) (sigval_t); /* Function to start. */
+ void *_attribute; /* Really pthread_attr_t. */
+ } _sigev_thread;
+ } _sigev_un;
+ } sigevent_t;
+
+/* POSIX names to access some of the members. */
+# define sigev_notify_function _sigev_un._sigev_thread._function
+# define sigev_notify_attributes _sigev_un._sigev_thread._attribute
+
+/* `sigev_notify' values. */
+enum
+{
+ SIGEV_SIGNAL = 0, /* Notify via signal. */
+# define SIGEV_SIGNAL SIGEV_SIGNAL
+ SIGEV_NONE, /* Other notification: meaningless. */
+# define SIGEV_NONE SIGEV_NONE
+ SIGEV_THREAD, /* Deliver via thread creation. */
+# define SIGEV_THREAD SIGEV_THREAD
+
+ SIGEV_THREAD_ID = 4 /* Send signal to specific thread. */
+#define SIGEV_THREAD_ID SIGEV_THREAD_ID
+};
+
+#endif /* have _SIGNAL_H. */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/stat.h b/libc/sysdeps/unix/sysv/linux/s390/bits/stat.h
new file mode 100644
index 000000000..c8ff532d4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/stat.h
@@ -0,0 +1,256 @@
+/* Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STAT_H
+# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+/* Versions of the `struct stat' data structure. */
+# define _STAT_VER_KERNEL 0
+# define _STAT_VER_LINUX 1
+# define _STAT_VER _STAT_VER_LINUX
+
+/* Versions of the `xmknod' interface. */
+#define _MKNOD_VER_LINUX 0
+#else
+/* Versions of the `struct stat' data structure. */
+# define _STAT_VER_LINUX_OLD 1
+# define _STAT_VER_KERNEL 1
+# define _STAT_VER_SVR4 2
+# define _STAT_VER_LINUX 3
+# define _STAT_VER _STAT_VER_LINUX
+
+/* Versions of the `xmknod' interface. */
+# define _MKNOD_VER_LINUX 1
+# define _MKNOD_VER_SVR4 2
+# define _MKNOD_VER _MKNOD_VER_LINUX
+#endif
+
+#if __WORDSIZE == 64
+struct stat
+ {
+ __dev_t st_dev; /* Device. */
+ __ino_t st_ino; /* File serial number. */
+ __nlink_t st_nlink; /* Link count. */
+ __mode_t st_mode; /* File mode. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ int pad0;
+ __dev_t st_rdev; /* Device number, if device. */
+ __off_t st_size; /* Size of file, in bytes. */
+#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
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ __blkcnt_t st_blocks; /* Nr. 512-byte blocks allocated. */
+ long int __unused[3];
+ };
+#else
+struct stat
+ {
+ __dev_t st_dev; /* Device. */
+ unsigned int __pad1;
+# ifndef __USE_FILE_OFFSET64
+ __ino_t st_ino; /* File serial number. */
+# else
+ __ino_t __st_ino; /* 32bit file serial number. */
+# endif
+ __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. */
+ unsigned int __pad2;
+# ifndef __USE_FILE_OFFSET64
+ __off_t st_size; /* Size of file, in bytes. */
+# else
+ __off64_t st_size; /* Size of file, in bytes. */
+# endif
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+# ifndef __USE_FILE_OFFSET64
+ __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
+# else
+ __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
+# endif
+#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
+# ifndef __USE_FILE_OFFSET64
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+# else
+ __ino64_t st_ino; /* File serial number. */
+# endif
+ };
+#endif
+
+#ifdef __USE_LARGEFILE64
+# if __WORDSIZE == 64
+/* Note stat64 is the same shape as stat. */
+struct stat64
+ {
+ __dev_t st_dev; /* Device. */
+ __ino64_t st_ino; /* File serial number. */
+ __nlink_t st_nlink; /* Link count. */
+ __mode_t st_mode; /* File mode. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ int pad0;
+ __dev_t st_rdev; /* Device number, if device. */
+ __off_t st_size; /* Size of file, in bytes. */
+#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
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */
+ long int __unused[3];
+ };
+# else
+struct stat64
+ {
+ __dev_t st_dev; /* Device. */
+ unsigned int __pad1;
+
+ __ino_t __st_ino; /* 32bit 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. */
+ unsigned int __pad2;
+ __off64_t st_size; /* Size of file, in bytes. */
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+ __blkcnt64_t st_blocks; /* Number 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. */
+# 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
+ __ino64_t st_ino; /* File serial number. */
+ };
+# endif
+#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. */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/statfs.h b/libc/sysdeps/unix/sysv/linux/s390/bits/statfs.h
new file mode 100644
index 000000000..d838e6bf4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/statfs.h
@@ -0,0 +1,67 @@
+/* Copyright (C) 1997, 1998, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STATFS_H
+# error "Never include <bits/statfs.h> directly; use <sys/statfs.h> instead."
+#endif
+
+#include <bits/types.h> /* for __fsid_t and __fsblkcnt_t. */
+
+struct statfs
+ {
+ int f_type;
+ int f_bsize;
+#ifndef __USE_FILE_OFFSET64
+ __fsblkcnt_t f_blocks;
+ __fsblkcnt_t f_bfree;
+ __fsblkcnt_t f_bavail;
+ __fsfilcnt_t f_files;
+ __fsfilcnt_t f_ffree;
+#else
+ __fsblkcnt64_t f_blocks;
+ __fsblkcnt64_t f_bfree;
+ __fsblkcnt64_t f_bavail;
+ __fsfilcnt64_t f_files;
+ __fsfilcnt64_t f_ffree;
+#endif
+ __fsid_t f_fsid;
+ int f_namelen;
+ int f_frsize;
+ int f_spare[5];
+ };
+
+#ifdef __USE_LARGEFILE64
+struct statfs64
+ {
+ int f_type;
+ int 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;
+ int f_namelen;
+ int f_frsize;
+ int f_spare[5];
+ };
+#endif
+
+/* Tell code we have this member. */
+#define _STATFS_F_NAMELEN
+#define _STATFS_F_FRSIZE
diff --git a/libc/sysdeps/unix/sysv/linux/s390/bits/typesizes.h b/libc/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
new file mode 100644
index 000000000..2d9cd8779
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
@@ -0,0 +1,72 @@
+/* bits/typesizes.h -- underlying types for *_t. Linux/s390 version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _BITS_TYPES_H
+# error "Never include <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 __UWORD_TYPE
+#define __OFF_T_TYPE __SLONGWORD_TYPE
+#define __OFF64_T_TYPE __SQUAD_TYPE
+#define __PID_T_TYPE __S32_TYPE
+#define __RLIM_T_TYPE __ULONGWORD_TYPE
+#define __RLIM64_T_TYPE __UQUAD_TYPE
+#define __BLKCNT_T_TYPE __SLONGWORD_TYPE
+#define __BLKCNT64_T_TYPE __SQUAD_TYPE
+#define __FSBLKCNT_T_TYPE __ULONGWORD_TYPE
+#define __FSBLKCNT64_T_TYPE __UQUAD_TYPE
+#define __FSFILCNT_T_TYPE __ULONGWORD_TYPE
+#define __FSFILCNT64_T_TYPE __UQUAD_TYPE
+#define __ID_T_TYPE __U32_TYPE
+#define __CLOCK_T_TYPE __SLONGWORD_TYPE
+#define __TIME_T_TYPE __SLONGWORD_TYPE
+#define __USECONDS_T_TYPE __U32_TYPE
+#define __SUSECONDS_T_TYPE __SLONGWORD_TYPE
+#define __DADDR_T_TYPE __S32_TYPE
+#define __SWBLK_T_TYPE __SLONGWORD_TYPE
+#define __KEY_T_TYPE __S32_TYPE
+#define __CLOCKID_T_TYPE __S32_TYPE
+#define __TIMER_T_TYPE void *
+#define __BLKSIZE_T_TYPE __SLONGWORD_TYPE
+#define __FSID_T_TYPE struct { int __val[2]; }
+#if defined __GNUC__ && __GNUC__ <= 2
+/* Compatibility with g++ 2.95.x. */
+#define __SSIZE_T_TYPE __SWORD_TYPE
+#else
+/* size_t is unsigned long int on s390 -m31. */
+#define __SSIZE_T_TYPE __SLONGWORD_TYPE
+#endif
+
+/* Number of descriptors that can fit in an `fd_set'. */
+#define __FD_SETSIZE 1024
+
+
+#endif /* bits/typesizes.h */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/brk.c b/libc/sysdeps/unix/sysv/linux/s390/brk.c
new file mode 100644
index 000000000..ae6af2178
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/brk.c
@@ -0,0 +1,56 @@
+/*
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sysdep.h>
+
+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/x86 ELF
+ dynamic linker. Sigh. */
+weak_alias (__curbrk, ___brk_addr)
+
+int
+__brk (void *addr)
+{
+ void *newbrk;
+
+ {
+ register void *__addr asm("2") = addr;
+
+ asm ("svc %b1\n\t" /* call sys_brk */
+ : "=d" (__addr)
+ : "I" (SYS_ify(brk)), "r" (__addr)
+ : "cc", "memory" );
+ newbrk = __addr;
+ }
+ __curbrk = newbrk;
+
+ if (newbrk < addr)
+ {
+ __set_errno (ENOMEM);
+ return -1;
+ }
+
+ return 0;
+}
+weak_alias (__brk, brk)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/dl-cache.h b/libc/sysdeps/unix/sysv/linux/s390/dl-cache.h
new file mode 100644
index 000000000..766bba426
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/dl-cache.h
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/sparc/dl-cache.h>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/fpu/Implies b/libc/sysdeps/unix/sysv/linux/s390/fpu/Implies
new file mode 100644
index 000000000..3a8e22598
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/fpu/Implies
@@ -0,0 +1,2 @@
+# Override ldbl-opt with s390 specific routines.
+s390/fpu
diff --git a/libc/sysdeps/unix/sysv/linux/s390/ldconfig.h b/libc/sysdeps/unix/sysv/linux/s390/ldconfig.h
new file mode 100644
index 000000000..4a472671b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/ldconfig.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/generic/ldconfig.h>
+
+#define SYSDEP_KNOWN_INTERPRETER_NAMES \
+ { "/lib/ld.so.1", FLAG_ELF_LIBC6 }, \
+ { "/lib/ld64.so.1", FLAG_ELF_LIBC6 },
+#define SYSDEP_KNOWN_LIBRARY_NAMES \
+ { "libc.so.6", FLAG_ELF_LIBC6 }, \
+ { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/libc/sysdeps/unix/sysv/linux/s390/ldd-rewrite.sed b/libc/sysdeps/unix/sysv/linux/s390/ldd-rewrite.sed
new file mode 100644
index 000000000..6b4f1bfca
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/ldd-rewrite.sed
@@ -0,0 +1,15 @@
+/LD_TRACE_LOADED_OBJECTS=1/a\
+add_env="$add_env LD_LIBRARY_VERSION=\\$verify_out"
+
+# ldd is generated from elf/ldd.bash.in with the name
+# of ld.so as generated in Makeconfig
+
+# that name is replaced by a pair referring to both
+# the 32bit and 64bit dynamic linker.
+
+# /lib(64|)/*(64|).so* is replaced with /lib/*.so* and /lib/*64.so*
+# this works for /lib64/ld64.so.x and /lib/ld.so.x as input
+s_lib64_lib_
+s_64\.so_\.so_
+s_^RTLDLIST=\(.*lib\)\(/[^/]*\)\(\.so\.[0-9.]*\)[[:blank:]]*$_RTLDLIST="\1\2\3 \1\264\3"_
+
diff --git a/libc/sysdeps/unix/sysv/linux/s390/nldbl-abi.h b/libc/sysdeps/unix/sysv/linux/s390/nldbl-abi.h
new file mode 100644
index 000000000..bd985cc59
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/nldbl-abi.h
@@ -0,0 +1,8 @@
+/* ABI version for long double switch.
+ This is used by the Versions and math_ldbl_opt.h files in
+ sysdeps/ieee754/ldbl-opt/. It gives the ABI version where
+ long double == double was replaced with proper long double
+ for libm *l functions and libc functions using long double. */
+
+#define NLDBL_VERSION GLIBC_2.4
+#define LONG_DOUBLE_COMPAT_VERSION GLIBC_2_4
diff --git a/libc/sysdeps/unix/sysv/linux/s390/readelflib.c b/libc/sysdeps/unix/sysv/linux/s390/readelflib.c
new file mode 100644
index 000000000..2782bc1e0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/readelflib.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 2001, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+int process_elf32_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+int process_elf64_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+
+/* Returns 0 if everything is ok, != 0 in case of error. */
+int
+process_elf_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname, void *file_contents,
+ size_t file_length)
+{
+ ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
+ int ret;
+
+ if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
+ return process_elf32_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ else
+ {
+ ret = process_elf64_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ /* S/390 64bit libraries are always libc.so.6+. */
+ if (!ret)
+ *flag = FLAG_S390_LIB64|FLAG_ELF_LIBC6;
+ return ret;
+ }
+}
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf32_file
+#define __ELF_NATIVE_CLASS 32
+#include "elf/readelflib.c"
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf64_file
+#define __ELF_NATIVE_CLASS 64
+#include "elf/readelflib.c"
diff --git a/libc/sysdeps/unix/sysv/linux/s390/rt-sysdep.S b/libc/sysdeps/unix/sysv/linux/s390/rt-sysdep.S
new file mode 100644
index 000000000..f966bf1e5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/rt-sysdep.S
@@ -0,0 +1 @@
+#include <sysdep.S>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/Makefile b/libc/sysdeps/unix/sysv/linux/s390/s390-32/Makefile
new file mode 100644
index 000000000..359c863c0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/Makefile
@@ -0,0 +1,15 @@
+ifeq ($(subdir),misc)
+sysdep_headers += sys/elf.h
+endif
+
+ifeq ($(subdir),resource)
+sysdep_routines += oldgetrlimit64
+endif
+
+ifeq ($(subdir),elf)
+ifeq (yes,$(build-shared))
+# This is needed to support g++ v2 and v3.
+sysdep_routines += framestate
+shared-only-routines += framestate
+endif
+endif
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/Versions b/libc/sysdeps/unix/sysv/linux/s390/s390-32/Versions
new file mode 100644
index 000000000..8d6a660cb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/Versions
@@ -0,0 +1,29 @@
+libc {
+ GLIBC_2.0 {
+ # Exception handling support functions from libgcc
+ __register_frame; __register_frame_table; __deregister_frame;
+ __frame_state_for; __register_frame_info_table;
+ }
+ GLIBC_2.2 {
+ # functions used in other libraries
+ __xstat64; __fxstat64; __lxstat64;
+
+ # a*
+ alphasort64;
+
+ # New rlimit interface
+ getrlimit; setrlimit; getrlimit64;
+
+ # r*
+ readdir64; readdir64_r;
+
+ # s*
+ scandir64;
+
+ # v*
+ versionsort64;
+ }
+ GLIBC_2.3.3 {
+ posix_fadvise64; posix_fallocate64;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/alphasort64.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/alphasort64.c
new file mode 100644
index 000000000..0b5ae47d2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/alphasort64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/alphasort64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/chown.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/chown.c
new file mode 100644
index 000000000..5909ba8a4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/chown.c
@@ -0,0 +1,120 @@
+/* Copyright (C) 2000,2001,2002,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <shlib-compat.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+/*
+ In Linux 2.1.x the chown functions have been changed. A new function lchown
+ was introduced. The new chown now follows symlinks - the old chown and the
+ new lchown do not follow symlinks.
+ The new lchown function has the same number as the old chown had and the
+ new chown has a new number. When compiling with headers from Linux > 2.1.8x
+ it's impossible to run this libc with older kernels. In these cases libc
+ has therefore to route calls to chown to the old chown function.
+*/
+
+/* Running under Linux > 2.1.80. */
+
+#ifdef __NR_chown32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_chown32 */
+
+int
+__real_chown (const char *file, uid_t owner, gid_t group)
+{
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (chown32, 3, CHECK_STRING (file), owner, group);
+#else
+ static int __libc_old_chown;
+ int result;
+
+ if (!__libc_old_chown)
+ {
+ int saved_errno = errno;
+# ifdef __NR_chown32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+ int saved_errno = errno;
+
+ result = INLINE_SYSCALL (chown32, 3, CHECK_STRING (file), owner, group);
+ if (result == 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_chown32 */
+ if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ result = INLINE_SYSCALL (chown, 3, CHECK_STRING (file), owner, group);
+
+ if (result >= 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_old_chown = 1;
+ }
+
+ return __lchown (file, owner, group);
+#endif
+}
+
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+/* Compiling for compatibiity. */
+int
+attribute_compat_text_section
+__chown_is_lchown (const char *file, uid_t owner, gid_t group)
+{
+ return __lchown (file, owner, group);
+}
+#endif
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__chown_is_lchown, _chown_is_lchown)
+compat_symbol (libc, __chown_is_lchown, __chown, GLIBC_2_0);
+compat_symbol (libc, _chown_is_lchown, chown, GLIBC_2_0);
+
+strong_alias (__real_chown, _real_chown)
+versioned_symbol (libc, __real_chown, __chown, GLIBC_2_1);
+versioned_symbol (libc, _real_chown, chown, GLIBC_2_1);
+libc_hidden_ver (__real_chown, __chown)
+#else
+strong_alias (__real_chown, __chown)
+libc_hidden_def (__chown)
+weak_alias (__real_chown, chown)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/clone.S b/libc/sysdeps/unix/sysv/linux/s390/s390-32/clone.S
new file mode 100644
index 000000000..70f695a95
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/clone.S
@@ -0,0 +1,76 @@
+/* Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* clone is even more special than fork as it mucks with stacks
+ and invokes a function in the right context after its all over. */
+
+#include <sysdep.h>
+#include <tls.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+/* int __clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
+ pid_t *parent_tid, void *tls, pid_t *child_tid); */
+/* sys_clone (void *child_stack, unsigned long flags,
+ pid_t *parent_tid, pid_t *child_tid, void *tls); */
+
+ .text
+ENTRY(__clone)
+ st %r6,24(%r15) /* store %r6 to save area */
+ cfi_offset (%r6, -72)
+ lr %r0,%r5 /* move *arg out of the way */
+ ltr %r1,%r2 /* check fn and move to %r1 */
+ jz error /* no NULL function pointers */
+ ltr %r2,%r3 /* check child_stack and move to %r2 */
+ jz error /* no NULL stack pointers */
+ lr %r3,%r4 /* move flags to %r3 */
+ lr %r4,%r6 /* move parent_tid to %r4 */
+ l %r5,100(%r15) /* load child_tid from stack */
+ l %r6,96(%r15) /* load tls from stack */
+ svc SYS_ify(clone)
+ ltr %r2,%r2 /* check return code */
+ jz thread_start
+ l %r6,24(%r15) /* restore %r6 */
+ jm SYSCALL_ERROR_LABEL
+ br %r14
+error:
+ lhi %r2,-EINVAL
+ j SYSCALL_ERROR_LABEL
+PSEUDO_END (__clone)
+
+thread_start:
+#ifdef RESET_PID
+ tmh %r3,1 /* CLONE_THREAD == 0x00010000 */
+ jne 1f
+ lhi %r2,-1
+ tml %r3,256 /* CLONE_VM == 0x00000100 */
+ jne 2f
+ svc SYS_ify(getpid)
+2: ear %r3,%a0
+ st %r2,PID(%r3)
+ st %r2,TID(%r3)
+1:
+#endif
+ /* fn is in gpr 1, arg in gpr 0 */
+ lr %r2,%r0 /* set first parameter to void *arg */
+ ahi %r15,-96 /* make room on the stack for the save area */
+ xc 0(4,%r15),0(%r15)
+ basr %r14,%r1 /* jump to fn */
+ DO_CALL (exit, 1)
+weak_alias (__clone, clone)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/fchown.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/fchown.c
new file mode 100644
index 000000000..3a69ecc9e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/fchown.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fchown.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/fchownat.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/fchownat.c
new file mode 100644
index 000000000..abc06b07d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/fchownat.c
@@ -0,0 +1,159 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <shlib-compat.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+/*
+ In Linux 2.1.x the chown functions have been changed. A new function lchown
+ was introduced. The new chown now follows symlinks - the old chown and the
+ new lchown do not follow symlinks.
+ The new lchown function has the same number as the old chown had and the
+ new chown has a new number. When compiling with headers from Linux > 2.1.8x
+ it's impossible to run this libc with older kernels. In these cases libc
+ has therefore to route calls to chown to the old chown function.
+*/
+
+/* Running under Linux > 2.1.80. */
+
+#ifdef __NR_chown32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_chown32 */
+
+int
+fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
+{
+ int result;
+
+#ifdef __NR_fchownat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INLINE_SYSCALL (fchownat, 5, fd, file, owner, group, flag);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ if (flag & ~AT_SYMLINK_NOFOLLOW)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+# if __ASSUME_32BITUIDS > 0
+ result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file), owner,
+ group);
+# else
+ static int __libc_old_chown;
+
+# ifdef __NR_chown32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lchown32, err, 3, CHECK_STRING (file),
+ owner, group);
+ else
+ result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file),
+ owner, group);
+
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return result;
+ if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ goto fail;
+
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_chown32 */
+ if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (!__libc_old_chown && (flag & AT_SYMLINK_NOFOLLOW) == 0)
+ {
+ result = INTERNAL_SYSCALL (chown, err, 3, CHECK_STRING (file), owner,
+ group);
+
+ if (!INTERNAL_SYSCALL_ERROR_P (result, err))
+ return result;
+ if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ goto fail;
+
+ __libc_old_chown = 1;
+ }
+
+ result = INTERNAL_SYSCALL (lchown, err, 3, CHECK_STRING (file), owner,
+ group);
+# endif
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+ fail:
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+ result = -1;
+ }
+
+ return result;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/fcntl.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/fcntl.c
new file mode 100644
index 000000000..ea951bc4f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/fcntl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/fxstat.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/fxstat.c
new file mode 100644
index 000000000..4f219f0b9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/fxstat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/fxstatat.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/fxstatat.c
new file mode 100644
index 000000000..0f8b3135d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/fxstatat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstatat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S
new file mode 100644
index 000000000..3b38d1948
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S
@@ -0,0 +1,75 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <features.h>
+
+#include "ucontext_i.h"
+
+/* __getcontext (const ucontext_t *ucp)
+
+ Saves the machine context in UCP such that when it is activated,
+ it appears as if __getcontext() returned again.
+
+ This implementation is intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to save anything
+ other than the PRESERVED state. */
+
+ENTRY(__getcontext)
+ lr %r5,%r2
+
+ /* sigprocmask (SIG_BLOCK, NULL, &sc->sc_mask). */
+ la %r2,SIG_BLOCK
+ slr %r3,%r3
+ la %r4,SC_MASK(%r5)
+ svc SYS_ify(rt_sigprocmask)
+
+ /* Store fpu context. */
+ stfpc SC_FPC(%r5)
+ std %f0,SC_FPRS(%r5)
+ std %f1,SC_FPRS+8(%r5)
+ std %f2,SC_FPRS+16(%r5)
+ std %f3,SC_FPRS+24(%r5)
+ std %f4,SC_FPRS+32(%r5)
+ std %f5,SC_FPRS+40(%r5)
+ std %f6,SC_FPRS+48(%r5)
+ std %f7,SC_FPRS+56(%r5)
+ std %f8,SC_FPRS+64(%r5)
+ std %f9,SC_FPRS+72(%r5)
+ std %f10,SC_FPRS+80(%r5)
+ std %f11,SC_FPRS+88(%r5)
+ std %f12,SC_FPRS+96(%r5)
+ std %f13,SC_FPRS+104(%r5)
+ std %f14,SC_FPRS+112(%r5)
+ std %f15,SC_FPRS+120(%r5)
+
+ /* Set __getcontext return value to 0. */
+ slr %r2,%r2
+
+ /* Store access registers. */
+ stam %a0,%a15,SC_ACRS(%r5)
+
+ /* Store general purpose registers. */
+ stm %r0,%r15,SC_GPRS(%r5)
+
+ /* Return. */
+ br %r14
+END(__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/getdents64.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getdents64.c
new file mode 100644
index 000000000..0c75fb5a0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getdents64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getdents64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/getegid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getegid.c
new file mode 100644
index 000000000..37b4b4a53
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getegid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getegid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/geteuid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/geteuid.c
new file mode 100644
index 000000000..ebcb555b5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/geteuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/geteuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/getgid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getgid.c
new file mode 100644
index 000000000..0a4d6061f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/getgroups.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getgroups.c
new file mode 100644
index 000000000..20a716610
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getgroups.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getgroups.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/getresgid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getresgid.c
new file mode 100644
index 000000000..b703a414c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getresgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getresgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/getresuid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getresuid.c
new file mode 100644
index 000000000..0b14cefe3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getresuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getresuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/getrlimit.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getrlimit.c
new file mode 100644
index 000000000..fc06dbd64
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getrlimit.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getrlimit.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/getrlimit64.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getrlimit64.c
new file mode 100644
index 000000000..fef018f47
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getrlimit64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getrlimit64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/getuid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getuid.c
new file mode 100644
index 000000000..d682c79a4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/getuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/lchown.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/lchown.c
new file mode 100644
index 000000000..1e64a0ef7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/lchown.c
@@ -0,0 +1,69 @@
+/* Copyright (C) 2000, 2001, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+# ifdef __NR_lchown32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+# endif /* __NR_lchown32 */
+
+int
+__lchown (const char *file, uid_t owner, gid_t group)
+{
+# if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (lchown32, 3, CHECK_STRING (file), owner, group);
+# else
+# ifdef __NR_lchown32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+ int saved_errno = errno;
+
+ result = INLINE_SYSCALL (lchown32, 3, CHECK_STRING (file), owner, group);
+ if (result == 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_lchown32 */
+
+ if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+ || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return INLINE_SYSCALL (lchown, 3, CHECK_STRING (file), owner, group);
+# endif
+}
+
+weak_alias (__lchown, lchown)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/lockf64.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/lockf64.c
new file mode 100644
index 000000000..a88f5a784
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/lockf64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/lockf64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/lxstat.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/lxstat.c
new file mode 100644
index 000000000..0efa0aea4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/lxstat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/lxstat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c
new file mode 100644
index 000000000..29c8640e9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c
@@ -0,0 +1,101 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <libintl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ucontext.h>
+
+/* This implementation can handle any ARGC value but only
+ normal integer type parameters. Parameters of type float,
+ double, complex and structure with sizes 0, 2, 4 or 8
+ won't work.
+ makecontext sets up a stack and the registers for the
+ context. The stack looks like this:
+ size offset
+ %r15 -> +-----------------------+
+ 4 | back chain (zero) | 0
+ 4 | reserved | 4
+ 88 | save area for (*func) | 8
+ +-----------------------+
+ n | overflow parameters | 96
+ +-----------------------+
+ 8 | trampoline | 96+n
+ +-----------------------+
+ The registers are set up like this:
+ %r2-%r6: parameters 1 to 5
+ %r7 : (*func) pointer
+ %r8 : uc_link from ucontext structure
+ %r9 : address of setcontext
+ %r14 : return address to uc_link trampoline
+ %r15 : stack pointer.
+
+ The trampoline looks like this:
+ basr %r14,%r7
+ lr %r2,%r8
+ br %r9. */
+
+void
+__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
+{
+ unsigned long *sp;
+ va_list ap;
+ int i;
+
+ sp = (long *) (((long) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & -8L);
+
+ /* Setup the trampoline. */
+ *--sp = 0x07f90000;
+ *--sp = 0x0de71828;
+
+ /* Set the return address to trampoline. */
+ ucp->uc_mcontext.gregs[14] = (long) sp;
+
+ /* Set register parameters. */
+ va_start (ap, argc);
+ for (i = 0; (i < argc) && (i < 5); i++)
+ ucp->uc_mcontext.gregs[2+i] = va_arg (ap, long);
+
+ /* The remaining arguments go to the overflow area. */
+ if (argc > 5) {
+ sp -= argc - 5;
+ for (i = 5; i < argc; i++)
+ sp[i] = va_arg(ap, long);
+ }
+ va_end (ap);
+
+ /* Make room for the save area and set the backchain. */
+ sp -= 24;
+ *sp = 0;
+
+ /* Pass (*func) to __start_context in %r7. */
+ ucp->uc_mcontext.gregs[7] = (long) func;
+
+ /* Pass ucp->uc_link to __start_context in %r8. */
+ ucp->uc_mcontext.gregs[8] = (long) ucp->uc_link;
+
+ /* Pass address of setcontext in %r9. */
+ ucp->uc_mcontext.gregs[9] = (long) &setcontext;
+
+ /* Set stack pointer. */
+ ucp->uc_mcontext.gregs[15] = (long) sp;
+}
+
+weak_alias (__makecontext, makecontext)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/mmap.S b/libc/sysdeps/unix/sysv/linux/s390/s390-32/mmap.S
new file mode 100644
index 000000000..c0d7cd459
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/mmap.S
@@ -0,0 +1,84 @@
+/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#define EINVAL 22
+
+ .text
+ENTRY(__mmap)
+ /* Save registers and setup stack frame. */
+ stm %r6,%r15,24(%r15)
+ cfi_offset (%r15, -36)
+ cfi_offset (%r14, -40)
+ cfi_offset (%r13, -44)
+ cfi_offset (%r12, -48)
+ cfi_offset (%r11, -52)
+ cfi_offset (%r10, -56)
+ cfi_offset (%r9, -60)
+ cfi_offset (%r8, -64)
+ cfi_offset (%r7, -68)
+ cfi_offset (%r6, -72)
+ lr %r1,%r15
+ ahi %r15,-120 /* buy stack space */
+ cfi_adjust_cfa_offset (120)
+ st %r1,0(%r15) /* store back chain */
+
+ /* Store parameters on stack, because old_mmap/mmap2
+ * take only one parameter: a pointer to the parameter area
+ */
+ st %r6,0x70(%r15) /* Store 'fd'. */
+ st %r5,0x6C(%r15) /* Store 'flags'. */
+ st %r4,0x68(%r15) /* Store 'prot'. */
+ st %r3,0x64(%r15) /* Store 'length'. */
+ st %r2,0x60(%r15) /* Store 'start'. */
+ l %r1,216(%r15) /* Load offset. */
+
+#ifdef __ASSUME_MMAP2_SYSCALL
+ /* I don't think it is worthwhile trying to use mmap2 whenever
+ * it is available. Only use it when we are sure the syscall
+ * exists. */
+ tml %r1,0x0fff /* Offset page aligned ? */
+ lhi %r2,-EINVAL
+ jnz 1f /* No -> EINVAL. */
+ srl %r1,12 /* mmap2 takes the offset in pages. */
+ st %r1,0x74(%r15) /* Store page offset. */
+ la %r2,0x60(%r15) /* Load address of parameter list. */
+ svc SYS_ify(mmap2) /* Do the system call trap. */
+#else
+ st %r1,0x74(%r15) /* Store offset unmodified. */
+ la %r2,0x60(%r15) /* Load address of parameter list. */
+ svc SYS_ify(mmap) /* Do the system call trap. */
+#endif
+
+1: l %r15,0(%r15) /* Load back chain. */
+ cfi_adjust_cfa_offset (-120)
+ lm %r6,%r15,24(%r15) /* Load registers. */
+
+ /* check gpr 2 for error */
+ lhi %r0,-4096
+ clr %r2,%r0
+ jnl SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+ br %r14
+
+PSEUDO_END (__mmap)
+
+weak_alias (__mmap, mmap)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S b/libc/sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S
new file mode 100644
index 000000000..aba4ac34e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S
@@ -0,0 +1,113 @@
+/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#define EINVAL 22
+#define ENOSYS 38
+
+ .text
+ENTRY(__mmap64)
+ /* Save registers and setup stack frame. */
+ stm %r6,%r15,24(%r15)
+ cfi_offset (%r15, -36)
+ cfi_offset (%r14, -40)
+ cfi_offset (%r13, -44)
+ cfi_offset (%r12, -48)
+ cfi_offset (%r11, -52)
+ cfi_offset (%r10, -56)
+ cfi_offset (%r9, -60)
+ cfi_offset (%r8, -64)
+ cfi_offset (%r7, -68)
+ cfi_offset (%r6, -72)
+ lr %r1,%r15
+ ahi %r15,-120 /* Buy stack space. */
+ cfi_adjust_cfa_offset (120)
+ st %r1,0(%r15) /* Store back chain. */
+
+ /* Store parameters on stack, because mmap2 and old_mmap
+ * take only one parameter: a pointer to the parameter area. */
+ st %r6,0x70(%r15) /* Store 'fd'. */
+ st %r5,0x6C(%r15) /* Store 'flags'. */
+ st %r4,0x68(%r15) /* Store 'prot'. */
+ st %r3,0x64(%r15) /* Store 'length'. */
+ st %r2,0x60(%r15) /* Store 'start'. */
+
+#ifdef __NR_mmap2
+ lm %r0,%r1,216(%r15) /* Load 64 bit offset. */
+ tml %r1,0x0fff /* Offset page aligned ? */
+ jnz 2f /* No -> EINVAL. */
+ srdl %r0,12 /* mmap2 takes the offset in pages. */
+ ltr %r0,%r0 /* Offset > 2^44 ? */
+ jnz 2f
+ st %r1,0x74(%r15) /* Store page offset. */
+
+ la %r2,0x60(%r15) /* Load address of parameter list. */
+ svc SYS_ify(mmap2) /* Do the system call trap. */
+
+#ifndef __ASSUME_MMAP2_SYSCALL
+ chi %r2,-ENOSYS
+ je 1f
+#endif
+
+ l %r15,0(%r15) /* Load back chain. */
+ cfi_adjust_cfa_offset (-120)
+ lm %r6,%r15,24(%r15) /* Load registers. */
+
+ /* Check gpr 2 for error. */
+ lhi %r0,-4096
+ clr %r2,%r0
+ jnl SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+ br %r14
+
+#endif
+
+#if !defined __ASSUME_MMAP2_SYSCALL || !defined __NR_mmap2
+1: lm %r0,%r1,216(%r15) /* Load 64 bit offset. */
+ st %r1,0x74(%r15) /* Store lower word of offset. */
+ ltr %r0,%r0 /* Offset > 2^32 ? */
+ jnz 2f
+ alr %r1,%r3 /* Add length to offset. */
+ brc 3,2f /* Carry -> EINVAL. */
+
+ la %r2,0x60(%r15) /* Load address of parameter list. */
+ svc SYS_ify(mmap) /* Do the system call trap. */
+
+ l %r15,0(%r15) /* Load back chain. */
+ lm %r6,%r15,24(%r15) /* Load registers. */
+
+ /* Check gpr 2 for error. */
+ lhi %r0,-4096
+ clr %r2,%r0
+ jnl SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+ br %r14
+#endif
+
+2: lhi %r2,-EINVAL
+ l %r15,0(%r15) /* Load back chain. */
+ lm %r6,%r15,24(%r15) /* Load registers. */
+ j SYSCALL_ERROR_LABEL
+
+PSEUDO_END (__mmap64)
+
+weak_alias (__mmap64, mmap64)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/msgctl.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/msgctl.c
new file mode 100644
index 000000000..9f9b8431a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/msgctl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/msgctl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/oldgetrlimit64.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/oldgetrlimit64.c
new file mode 100644
index 000000000..4c27e957b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/oldgetrlimit64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
new file mode 100644
index 000000000..e0fed24af
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/posix_fadvise64.c
@@ -0,0 +1,91 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+
+int __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise);
+int __posix_fadvise64_l32 (int fd, off64_t offset, size_t len, int advise);
+
+/* Advice the system about the expected behaviour of the application with
+ respect to the file associated with FD. */
+
+struct fadvise64_64_layout
+{
+ int fd;
+ off64_t offset;
+ off64_t len;
+ int advise;
+};
+
+int
+__posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
+{
+#ifdef __NR_fadvise64_64
+ struct fadvise64_64_layout parameters;
+ INTERNAL_SYSCALL_DECL (err);
+
+ parameters.fd = fd;
+ parameters.offset = offset;
+ parameters.len = len;
+ parameters.advise = advise;
+ int ret = INTERNAL_SYSCALL (fadvise64_64, err, 1, &parameters);
+ if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
+ return 0;
+# ifndef __ASSUME_FADVISE64_64_SYSCALL
+ if (INTERNAL_SYSCALL_ERRNO (ret, err) != ENOSYS)
+# endif
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+#endif
+#ifndef __ASSUME_FADVISE64_64_SYSCALL
+# ifdef __NR_fadvise64
+ if (len != (off_t) len)
+ return EOVERFLOW;
+
+ INTERNAL_SYSCALL_DECL (err2);
+ int ret2 = INTERNAL_SYSCALL (fadvise64, err2, 5, fd,
+ __LONG_LONG_PAIR ((long) (offset >> 32),
+ (long) offset),
+ (off_t) len, advise);
+ if (!INTERNAL_SYSCALL_ERROR_P (ret2, err2))
+ return 0;
+ return INTERNAL_SYSCALL_ERRNO (ret2, err2);
+# else
+ return ENOSYS;
+# endif
+#endif
+}
+
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT(libc, GLIBC_2_2, GLIBC_2_3_3)
+
+int
+attribute_compat_text_section
+__posix_fadvise64_l32 (int fd, off64_t offset, size_t len, int advise)
+{
+ return __posix_fadvise64_l64 (fd, offset, len, advise);
+}
+
+versioned_symbol (libc, __posix_fadvise64_l64, posix_fadvise64, GLIBC_2_3_3);
+compat_symbol (libc, __posix_fadvise64_l32, posix_fadvise64, GLIBC_2_2);
+#else
+strong_alias (__posix_fadvise64_l64, posix_fadvise64);
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/profil-counter.h b/libc/sysdeps/unix/sysv/linux/s390/s390-32/profil-counter.h
new file mode 100644
index 000000000..d913dbb61
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/profil-counter.h
@@ -0,0 +1,27 @@
+/* Low-level statistical profiling support function. Linux/s390 version.
+ Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <signal.h>
+#include <sigcontextinfo.h>
+
+static void
+profil_counter (int signo, SIGCONTEXT scp)
+{
+ profil_count((void *) ((unsigned long) GET_PC (scp) & 0x7fffffffUL));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c
new file mode 100644
index 000000000..2ea26dd40
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/readdir64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c
new file mode 100644
index 000000000..9f54f897e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/readdir64_r.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/register-dump.h b/libc/sysdeps/unix/sysv/linux/s390/s390-32/register-dump.h
new file mode 100644
index 000000000..2030bfef3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/register-dump.h
@@ -0,0 +1,130 @@
+/* Dump registers.
+ Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/uio.h>
+#include <stdio-common/_itoa.h>
+
+/* We will print the register dump in this format:
+
+ GPR0: XXXXXXXX GPR1: XXXXXXXX GPR2: XXXXXXXX GPR3: XXXXXXXX
+ GPR4: XXXXXXXX GPR5: XXXXXXXX GPR6: XXXXXXXX GPR7: XXXXXXXX
+ GPR8: XXXXXXXX GPR9: XXXXXXXX GPRA: XXXXXXXX GPRB: XXXXXXXX
+ GPRC: XXXXXXXX GPRD: XXXXXXXX GPRE: XXXXXXXX GPRF: XXXXXXXX
+
+ PSW.MASK: XXXXXXXX PSW.ADDR: XXXXXXXX
+
+ ST(0) XXXX XXXXXXXXXXXXXXXX ST(1) XXXX XXXXXXXXXXXXXXXX
+ ST(2) XXXX XXXXXXXXXXXXXXXX ST(3) XXXX XXXXXXXXXXXXXXXX
+ ST(4) XXXX XXXXXXXXXXXXXXXX ST(5) XXXX XXXXXXXXXXXXXXXX
+ ST(6) XXXX XXXXXXXXXXXXXXXX ST(7) XXXX XXXXXXXXXXXXXXXX
+
+ */
+
+static void
+hexvalue (unsigned long int value, char *buf, size_t len)
+{
+ char *cp = _itoa_word (value, buf + len, 16, 0);
+ while (cp > buf)
+ *--cp = '0';
+}
+
+static void
+register_dump (int fd, struct sigcontext *ctx)
+{
+ char regs[19][8];
+ struct iovec iov[40];
+ size_t nr = 0;
+
+#define ADD_STRING(str) \
+ iov[nr].iov_base = (char *) str; \
+ iov[nr].iov_len = strlen (str); \
+ ++nr
+#define ADD_MEM(str, len) \
+ iov[nr].iov_base = str; \
+ iov[nr].iov_len = len; \
+ ++nr
+
+ /* Generate strings of register contents. */
+ hexvalue (ctx->sregs->regs.gprs[0], regs[0], 8);
+ hexvalue (ctx->sregs->regs.gprs[1], regs[1], 8);
+ hexvalue (ctx->sregs->regs.gprs[2], regs[2], 8);
+ hexvalue (ctx->sregs->regs.gprs[3], regs[3], 8);
+ hexvalue (ctx->sregs->regs.gprs[4], regs[4], 8);
+ hexvalue (ctx->sregs->regs.gprs[5], regs[5], 8);
+ hexvalue (ctx->sregs->regs.gprs[6], regs[6], 8);
+ hexvalue (ctx->sregs->regs.gprs[7], regs[7], 8);
+ hexvalue (ctx->sregs->regs.gprs[8], regs[8], 8);
+ hexvalue (ctx->sregs->regs.gprs[9], regs[9], 8);
+ hexvalue (ctx->sregs->regs.gprs[10], regs[10], 8);
+ hexvalue (ctx->sregs->regs.gprs[11], regs[11], 8);
+ hexvalue (ctx->sregs->regs.gprs[12], regs[12], 8);
+ hexvalue (ctx->sregs->regs.gprs[13], regs[13], 8);
+ hexvalue (ctx->sregs->regs.gprs[14], regs[14], 8);
+ hexvalue (ctx->sregs->regs.gprs[15], regs[15], 8);
+ hexvalue (ctx->sregs->regs.psw.mask, regs[16], 8);
+ hexvalue (ctx->sregs->regs.psw.addr, regs[17], 8);
+
+ /* Generate the output. */
+ ADD_STRING ("Register dump:\n\n GPR0: ");
+ ADD_MEM (regs[0], 8);
+ ADD_STRING (" GPR1: ");
+ ADD_MEM (regs[1], 8);
+ ADD_STRING (" GPR2: ");
+ ADD_MEM (regs[2], 8);
+ ADD_STRING (" GPR3: ");
+ ADD_MEM (regs[3], 8);
+ ADD_STRING ("\n GPR4: ");
+ ADD_MEM (regs[4], 8);
+ ADD_STRING (" GPR5: ");
+ ADD_MEM (regs[5], 8);
+ ADD_STRING (" GPR6: ");
+ ADD_MEM (regs[6], 8);
+ ADD_STRING (" GPR7: ");
+ ADD_MEM (regs[7], 8);
+ ADD_STRING ("\n GPR8: ");
+ ADD_MEM (regs[8], 8);
+ ADD_STRING (" GPR9: ");
+ ADD_MEM (regs[9], 8);
+ ADD_STRING (" GPRA: ");
+ ADD_MEM (regs[10], 8);
+ ADD_STRING (" GPRB: ");
+ ADD_MEM (regs[11], 8);
+ ADD_STRING ("\n GPRC: ");
+ ADD_MEM (regs[12], 8);
+ ADD_STRING (" GPRD: ");
+ ADD_MEM (regs[13], 8);
+ ADD_STRING (" GPRE: ");
+ ADD_MEM (regs[14], 8);
+ ADD_STRING (" GPRF: ");
+ ADD_MEM (regs[15], 8);
+ ADD_STRING ("\n\n PSW.MASK: ");
+ ADD_MEM (regs[16], 8);
+ ADD_STRING (" PSW.ADDR: ");
+ ADD_MEM (regs[17], 8);
+ ADD_STRING (" TRAP: ");
+ ADD_MEM (regs[18], 4);
+ ADD_STRING ("\n");
+
+ /* Write the stuff out. */
+ writev (fd, iov, nr);
+}
+
+
+#define REGISTER_DUMP register_dump (fd, ctx)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/scandir64.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/scandir64.c
new file mode 100644
index 000000000..506fd8877
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/scandir64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/scandir64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/semctl.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/semctl.c
new file mode 100644
index 000000000..e9b1a483c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/semctl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/semctl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setcontext.S b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setcontext.S
new file mode 100644
index 000000000..cce8d2973
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setcontext.S
@@ -0,0 +1,72 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <features.h>
+
+#include "ucontext_i.h"
+
+/* __setcontext (const ucontext_t *ucp)
+
+ Restores the machine context in UCP and thereby resumes execution
+ in that context.
+
+ This implementation is intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to restore anything
+ other than the PRESERVED state. */
+
+ENTRY(__setcontext)
+ lr %r5,%r2
+
+ /* sigprocmask (SIG_SETMASK, &sc->sc_mask, NULL). */
+ la %r2,SIG_BLOCK
+ la %r3,SC_MASK(%r5)
+ slr %r4,%r4
+ svc SYS_ify(rt_sigprocmask)
+
+ /* Load fpu context. */
+ lfpc SC_FPC(%r5)
+ ld %f0,SC_FPRS(%r5)
+ ld %f1,SC_FPRS+8(%r5)
+ ld %f2,SC_FPRS+16(%r5)
+ ld %f3,SC_FPRS+24(%r5)
+ ld %f4,SC_FPRS+32(%r5)
+ ld %f5,SC_FPRS+40(%r5)
+ ld %f6,SC_FPRS+48(%r5)
+ ld %f7,SC_FPRS+56(%r5)
+ ld %f8,SC_FPRS+64(%r5)
+ ld %f9,SC_FPRS+72(%r5)
+ ld %f10,SC_FPRS+80(%r5)
+ ld %f11,SC_FPRS+88(%r5)
+ ld %f12,SC_FPRS+96(%r5)
+ ld %f13,SC_FPRS+104(%r5)
+ ld %f14,SC_FPRS+112(%r5)
+ ld %f15,SC_FPRS+120(%r5)
+
+ /* Don't touch %a0, used for thread purposes. */
+ lam %a1,%a15,SC_ACRS+4(%r5)
+
+ /* Load general purpose registers. */
+ lm %r0,%r15,SC_GPRS(%r5)
+
+ /* Return. */
+ br %r14
+END(__setcontext)
+
+weak_alias (__setcontext, setcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setegid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setegid.c
new file mode 100644
index 000000000..2e3a54c89
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setegid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setegid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/seteuid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/seteuid.c
new file mode 100644
index 000000000..18e41d08c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/seteuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/seteuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setfsgid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setfsgid.c
new file mode 100644
index 000000000..088671256
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setfsgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setfsgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setfsuid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setfsuid.c
new file mode 100644
index 000000000..a9f22eb8a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setfsuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setfsuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setgid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setgid.c
new file mode 100644
index 000000000..377021d9e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setgroups.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setgroups.c
new file mode 100644
index 000000000..0e7086278
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setgroups.c
@@ -0,0 +1,2 @@
+/* We also have to rewrite the kernel gid_t to the user land type. */
+#include <sysdeps/unix/sysv/linux/i386/setgroups.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setregid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setregid.c
new file mode 100644
index 000000000..99c57ad20
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setregid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setregid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setresgid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setresgid.c
new file mode 100644
index 000000000..daca1a483
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setresgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setresgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setresuid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setresuid.c
new file mode 100644
index 000000000..3aeabe9ad
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setresuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setresuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setreuid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setreuid.c
new file mode 100644
index 000000000..8ad61226e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setreuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setreuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setrlimit.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setrlimit.c
new file mode 100644
index 000000000..bfaef74c3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setrlimit.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setrlimit.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/setuid.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setuid.c
new file mode 100644
index 000000000..c8fa23e35
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/setuid.c
@@ -0,0 +1,2 @@
+#include <sysdeps/unix/sysv/linux/i386/setuid.c>
+
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/shmctl.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/shmctl.c
new file mode 100644
index 000000000..7eac6380d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/shmctl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/shmctl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/socket.S b/libc/sysdeps/unix/sysv/linux/s390/s390-32/socket.S
new file mode 100644
index 000000000..bc0153324
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/socket.S
@@ -0,0 +1,143 @@
+/* Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+/* &%/$&!! preprocessor */
+#define P(a, b) P2(a, b)
+#define P2(a, b) a##b
+
+ .text
+/* The socket-oriented system calls are handled unusally in Linux.
+ They are all gated through the single `socketcall' system call number.
+ `socketcall' takes two arguments: the first is the subcode, specifying
+ which socket function is being called; and the second is a pointer to
+ the arguments to the specific function.
+
+ The .S files for the other calls just #define socket and #include this. */
+
+#ifndef __socket
+#ifndef NO_WEAK_ALIAS
+#define __socket P(__,socket)
+#else
+#define __socket socket
+#endif
+#endif
+
+#ifndef NARGS /* the socket.o object is compiled directly ... */
+#define NARGS 3
+#endif
+
+.globl __socket
+ENTRY(__socket)
+ /* Save registers and setup stack. */
+ stm %r6,%r15,24(%r15) /* save registers */
+ cfi_offset (%r15, -36)
+ cfi_offset (%r14, -40)
+ cfi_offset (%r13, -44)
+ cfi_offset (%r12, -48)
+ cfi_offset (%r11, -52)
+ cfi_offset (%r10, -56)
+ cfi_offset (%r9, -60)
+ cfi_offset (%r8, -64)
+ cfi_offset (%r7, -68)
+ cfi_offset (%r6, -72)
+ lr %r1,%r15
+ l %r0,4(0,%r15) /* load eos */
+ ahi %r15,-120 /* buy stack space */
+ cfi_adjust_cfa_offset (120)
+ st %r1,0(0,%r15) /* store back chain */
+ st %r0,4(0,%r15) /* store eos */
+
+ /* Reorder arguments */
+#if (NARGS >= 6)
+ mvc 0x74(4,%r15),216(%r15) /* move between parameter lists */
+#endif
+#if (NARGS >= 5)
+ st %r6,0x70(0,%r15) /* store into parameter list */
+#endif
+#if (NARGS >= 4)
+ st %r5,0x6C(0,%r15) /* store into parameter list */
+#endif
+#if (NARGS >= 3)
+ st %r4,0x68(0,%r15) /* store into parameter list */
+#endif
+#if (NARGS >= 2)
+ st %r3,0x64(0,%r15) /* store into parameter list */
+ st %r2,0x60(0,%r15)
+#endif
+
+#if defined NEED_CANCELLATION && defined CENABLE
+ SINGLE_THREAD_P (%r4)
+ jne L(socket_cancel)
+#endif
+
+ /* load subcode for socket syscall */
+ lhi %r2,P(SOCKOP_,socket)
+ la %r3,0x60(0,%r15) /* load address of parameter list */
+
+ /* Do the system call trap. */
+ svc SYS_ify(socketcall)
+
+4:
+ l %r15,0(0,%r15) /* load back chain */
+ lm %r6,15,24(%r15) /* load registers */
+
+ /* gpr2 is < 0 if there was an error. */
+ lhi %r0,-125
+ clr %r2,%r0
+ jnl SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+ br %r14
+
+#if defined NEED_CANCELLATION && defined CENABLE
+L(socket_cancel):
+ basr %r13,0
+1: l %r1,2f-1b(%r13)
+ /* call CENABLE. */
+ bas %r14,0(%r13,%r1)
+ lr %r0,%r2
+
+ /* load subcode for socket syscall */
+ lhi %r2,P(SOCKOP_,socket)
+ la %r3,0x60(0,%r15) /* load address of parameter list */
+
+ /* Do the system call trap. */
+ svc SYS_ify(socketcall)
+
+ l %r3,3f-1b(%r13)
+ lr %r12,%r2
+ lr %r2,%r0
+ /* call CDISABLE. */
+ bas %r14,0(%r13,%r3)
+ lr %r2,%r12
+ j 4b
+
+2: .long CENABLE-1b
+3: .long CDISABLE-1b
+#endif
+
+ SYSCALL_ERROR_HANDLER
+END (__socket)
+
+#ifndef NO_WEAK_ALIAS
+weak_alias (__socket, socket)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S b/libc/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S
new file mode 100644
index 000000000..bf70f11cc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S
@@ -0,0 +1,108 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <features.h>
+
+#include "ucontext_i.h"
+
+/* __swapcontext (ucontext_t *oucp, const ucontext_t *ucp)
+
+ Saves the machine context in oucp such that when it is activated,
+ it appears as if __swapcontextt() returned again, restores the
+ machine context in ucp and thereby resumes execution in that
+ context.
+
+ This implementation is intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to save anything
+ other than the PRESERVED state. */
+
+ENTRY(__swapcontext)
+ lr %r1,%r2
+ lr %r5,%r3
+
+ /* sigprocmask (SIG_BLOCK, NULL, &sc->sc_mask). */
+ la %r2,SIG_BLOCK
+ slr %r3,%r3
+ la %r4,SC_MASK(%r1)
+ svc SYS_ify(rt_sigprocmask)
+
+ /* Store fpu context. */
+ stfpc SC_FPC(%r1)
+ std %f0,SC_FPRS(%r1)
+ std %f1,SC_FPRS+8(%r1)
+ std %f2,SC_FPRS+16(%r1)
+ std %f3,SC_FPRS+24(%r1)
+ std %f4,SC_FPRS+32(%r1)
+ std %f5,SC_FPRS+40(%r1)
+ std %f6,SC_FPRS+48(%r1)
+ std %f7,SC_FPRS+56(%r1)
+ std %f8,SC_FPRS+64(%r1)
+ std %f9,SC_FPRS+72(%r1)
+ std %f10,SC_FPRS+80(%r1)
+ std %f11,SC_FPRS+88(%r1)
+ std %f12,SC_FPRS+96(%r1)
+ std %f13,SC_FPRS+104(%r1)
+ std %f14,SC_FPRS+112(%r1)
+ std %f15,SC_FPRS+120(%r1)
+
+ /* Set __swapcontext return value to 0. */
+ slr %r2,%r2
+
+ /* Store access registers. */
+ stam %a0,%a15,SC_ACRS(%r1)
+
+ /* Store general purpose registers. */
+ stm %r0,%r15,SC_GPRS(%r1)
+
+ /* sigprocmask (SIG_SETMASK, &sc->sc_mask, NULL). */
+ la %r2,SIG_BLOCK
+ la %r3,SC_MASK(%r5)
+ slr %r4,%r4
+ svc SYS_ify(rt_sigprocmask)
+
+ /* Load fpu context. */
+ lfpc SC_FPC(%r5)
+ ld %f0,SC_FPRS(%r5)
+ ld %f1,SC_FPRS+8(%r5)
+ ld %f2,SC_FPRS+16(%r5)
+ ld %f3,SC_FPRS+24(%r5)
+ ld %f4,SC_FPRS+32(%r5)
+ ld %f5,SC_FPRS+40(%r5)
+ ld %f6,SC_FPRS+48(%r5)
+ ld %f7,SC_FPRS+56(%r5)
+ ld %f8,SC_FPRS+64(%r5)
+ ld %f9,SC_FPRS+72(%r5)
+ ld %f10,SC_FPRS+80(%r5)
+ ld %f11,SC_FPRS+88(%r5)
+ ld %f12,SC_FPRS+96(%r5)
+ ld %f13,SC_FPRS+104(%r5)
+ ld %f14,SC_FPRS+112(%r5)
+ ld %f15,SC_FPRS+120(%r5)
+
+ /* Don't touch %a0, used for thread purposes. */
+ lam %a1,%a15,SC_ACRS+4(%r5)
+
+ /* Load general purpose registers. */
+ lm %r0,%r15,SC_GPRS(%r5)
+
+ /* Return. */
+ br %r14
+END(__swapcontext)
+weak_alias (__swapcontext, swapcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/syscall.S b/libc/sysdeps/unix/sysv/linux/s390/s390-32/syscall.S
new file mode 100644
index 000000000..b7e173689
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/syscall.S
@@ -0,0 +1,68 @@
+/* Copyright (C) 2000, 2001, 2006 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* Please consult the file sysdeps/unix/sysv/linux/s390/sysdep.h for
+ more information about the value -4095 used below.*/
+
+ENTRY (syscall)
+ /* Save registers and setup stack. */
+ stm %r6,%r15,24(%r15) /* save registers */
+ cfi_offset (%r15, -36)
+ cfi_offset (%r14, -40)
+ cfi_offset (%r13, -44)
+ cfi_offset (%r12, -48)
+ cfi_offset (%r11, -52)
+ cfi_offset (%r10, -56)
+ cfi_offset (%r9, -60)
+ cfi_offset (%r8, -64)
+ cfi_offset (%r7, -68)
+ cfi_offset (%r6, -72)
+ lr %r1,%r15
+ l %r0,4(0,%r15) /* load eos */
+ ahi %r15,-96 /* buy stack space */
+ cfi_adjust_cfa_offset (96)
+ st %r1,0(0,%r15) /* store back chain */
+ st %r0,4(0,%r15) /* store eos */
+
+ lr %r1,%r2 /* move syscall number */
+ lr %r2,%r3 /* first parameter */
+ lr %r3,%r4 /* second parameter */
+ lr %r4,%r5 /* third parameter */
+ lr %r5,%r6 /* fourth parameter */
+ l %r6,192(%r15) /* fifth parameter */
+ l %r7,196(%r15) /* sixth parameter */
+
+ basr %r8,0
+0: cl %r1,4f-0b(%r8) /* svc number < 256? */
+ jl 2f
+1: svc 0
+ j 3f
+2: ex %r1,1b-0b(%r8) /* lsb of R1 is subsituted as SVC number */
+3: l %r15,0(%r15) /* load back chain */
+ cfi_adjust_cfa_offset (-96)
+ lm %r6,15,24(%r15) /* load registers */
+
+ lhi %r0,-4095
+ clr %r2,%r0 /* check R2 for error */
+ jnl SYSCALL_ERROR_LABEL
+ br %r14 /* return to caller */
+4: .long 256
+PSEUDO_END (syscall)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list b/libc/sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list
new file mode 100644
index 000000000..0e7685730
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list
@@ -0,0 +1,5 @@
+# File name Caller Syscall name Args Strong name Weak names
+
+oldgetrlimit EXTRA getrlimit i:ip __old_getrlimit getrlimit@GLIBC_2.0
+oldsetrlimit EXTRA setrlimit i:ip __old_setrlimit setrlimit@GLIBC_2.0
+vfork - vfork 0 __vfork vfork
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S b/libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S
new file mode 100644
index 000000000..2a1dad069
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S
@@ -0,0 +1,137 @@
+/* Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <tls.h>
+
+/* The following code is only used in the shared library when we
+ compile the reentrant version. Otherwise each system call defines
+ each own version. */
+
+/* The syscall stubs jump here when they detect an error. */
+
+#undef CALL_MCOUNT
+#define CALL_MCOUNT
+
+ .text
+ENTRY(__syscall_error)
+#ifndef PIC
+# if USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+# define SYSCALL_ERROR_ERRNO errno
+# endif
+ basr %r1,0
+0: l %r1,1f-0b(%r1)
+ ear %r3,%a0
+ lcr %r2,%r2
+ st %r2,0(%r1,%r3)
+ lhi %r2,-1
+ br %r14
+1: .long SYSCALL_ERROR_ERRNO@ntpoff
+# elif !defined _LIBC_REENTRANT
+ basr %r1,0
+0: l %r1,1f-0b(%r1)
+ lcr %r2,%r2
+ st %r2,0(%r1)
+ lhi %r2,-1
+ br %r14
+1: .long errno
+# else
+ stm %r13,%r15,52(%r15)
+ cfi_offset (%r15, -36)
+ cfi_offset (%r14, -40)
+ cfi_offset (%r13, -44)
+ lr %r0,%r15
+ ahi %r15,-96
+ cfi_adjust_cfa_offset (96)
+ lcr %r13,%r2
+ st %r0,0(%r15)
+ basr %r1,0
+0: l %r1,1f-0b(%r1)
+ basr %r14,%r1
+ st %r13,0(%r2)
+ lm %r13,%r15,148(%r15)
+ cfi_adjust_cfa_offset (-96)
+ lhi %r2,-1
+ br %r14
+1: .long __errno_location
+#endif
+#else
+# if RTLD_PRIVATE_ERRNO
+ basr %r1,0
+0: al %r1,1f-0b(%r1)
+ lcr %r2,%r2
+ st %r2,0(%r1)
+ lhi %r2,-1
+ br %r14
+1: .long rtld_errno - 0b
+# elif USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+# define SYSCALL_ERROR_ERRNO errno
+# endif
+ basr %r1,0
+0: al %r1,1f-0b(%r1)
+ ear %r3,%a0
+ l %r1,SYSCALL_ERROR_ERRNO@gotntpoff(%r1)
+ lcr %r2,%r2
+ st %r2,0(%r1,%r3)
+ lhi %r2,-1
+ br %r14
+1: .long _GLOBAL_OFFSET_TABLE_-0b
+# elif !defined _LIBC_REENTRANT
+ basr %r1,0
+0: al %r1,1f-0b(%r1)
+ l %r1,errno@GOT(%r1)
+ lcr %r2,%r2
+ st %r2,0(0,%r1)
+ lhi %r2,-1
+ br %r14
+1: .long _GLOBAL_OFFSET_TABLE_-0b
+# else
+ stm %r11,%r15,44(%r15)
+ cfi_offset (%r15, -36)
+ cfi_offset (%r14, -40)
+ cfi_offset (%r13, -44)
+ cfi_offset (%r12, -48)
+ cfi_offset (%r11, -52)
+ lr %r0,%r15
+ ahi %r15,-96
+ cfi_adjust_cfa_offset (96)
+ lcr %r11,%r2
+ st %r0,0(%r15)
+ basr %r13,0
+0: l %r12,1f-0b(%r13)
+ l %r1,2f-0b(%r13)
+ la %r12,0(%r12,%r13)
+ bas %r14,0(%r1,%r13)
+ st %r11,0(%r2)
+ lm %r11,%r15,140(%r15)
+ cfi_adjust_cfa_offset (-96)
+ lhi %r2,-1
+ br %r14
+1: .long _GLOBAL_OFFSET_TABLE_-0b
+2: .long __errno_location@PLT-0b
+# endif
+#endif
+
+END (__syscall_error)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h b/libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
new file mode 100644
index 000000000..b86072bd3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
@@ -0,0 +1,301 @@
+/* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_S390_SYSDEP_H
+#define _LINUX_S390_SYSDEP_H
+
+#include <sysdeps/s390/s390-32/sysdep.h>
+#include <sysdeps/unix/sysdep.h>
+#include <dl-sysdep.h> /* For RTLD_PRIVATE_ERRNO. */
+#include <tls.h>
+
+/* For Linux we can use the system call table in the header file
+ /usr/include/asm/unistd.h
+ of the kernel. But these symbols do not follow the SYS_* syntax
+ so we have to redefine the `SYS_ify' macro here. */
+/* in newer 2.1 kernels __NR_syscall is missing so we define it here */
+#define __NR_syscall 0
+
+#undef SYS_ify
+#define SYS_ify(syscall_name) __NR_##syscall_name
+
+#ifdef __ASSEMBLER__
+
+/* Linux uses a negative return value to indicate syscall errors, unlike
+ most Unices, which use the condition codes' carry flag.
+
+ Since version 2.1 the return value of a system call might be negative
+ even if the call succeeded. E.g., the `lseek' system call might return
+ a large offset. Therefore we must not anymore test for < 0, but test
+ for a real error by making sure the value in gpr2 is a real error
+ number. Linus said he will make sure the no syscall returns a value
+ in -1 .. -4095 as a valid result so we can savely test with -4095. */
+
+#undef PSEUDO
+#define PSEUDO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args); \
+ lhi %r4,-4095 ; \
+ clr %r2,%r4 ; \
+ jnl SYSCALL_ERROR_LABEL
+
+#undef PSEUDO_END
+#define PSEUDO_END(name) \
+ SYSCALL_ERROR_HANDLER; \
+ END (name)
+
+#undef PSEUDO_NOERRNO
+#define PSEUDO_NOERRNO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args)
+
+#undef PSEUDO_END_NOERRNO
+#define PSEUDO_END_NOERRNO(name) \
+ END (name)
+
+#undef PSEUDO_ERRVAL
+#define PSEUDO_ERRVAL(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args); \
+ lcr %r2,%r2
+
+#undef PSEUDO_END_ERRVAL
+#define PSEUDO_END_ERRVAL(name) \
+ END (name)
+
+#ifndef PIC
+# define SYSCALL_ERROR_LABEL 0f
+# define SYSCALL_ERROR_HANDLER \
+0: basr %r1,0; \
+1: l %r1,2f-1b(%r1); \
+ br %r1; \
+2: .long syscall_error
+#else
+# if RTLD_PRIVATE_ERRNO
+# define SYSCALL_ERROR_LABEL 0f
+# define SYSCALL_ERROR_HANDLER \
+0: basr %r1,0; \
+1: al %r1,2f-1b(%r1); \
+ lcr %r2,%r2; \
+ st %r2,0(%r1); \
+ lhi %r2,-1; \
+ br %r14; \
+2: .long rtld_errno-1b
+# elif defined _LIBC_REENTRANT
+# if USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+# define SYSCALL_ERROR_ERRNO errno
+# endif
+# define SYSCALL_ERROR_LABEL 0f
+# define SYSCALL_ERROR_HANDLER \
+0: lcr %r0,%r2; \
+ basr %r1,0; \
+1: al %r1,2f-1b(%r1); \
+ l %r1,SYSCALL_ERROR_ERRNO@gotntpoff(%r1); \
+ ear %r2,%a0; \
+ st %r0,0(%r1,%r2); \
+ lhi %r2,-1; \
+ br %r14; \
+2: .long _GLOBAL_OFFSET_TABLE_-1b
+# else
+# define SYSCALL_ERROR_LABEL 0f
+# define SYSCALL_ERROR_HANDLER \
+0: basr %r1,0; \
+1: al %r1,2f-1b(%r1); \
+ br %r1; \
+2: .long syscall_error@plt-1b
+# endif
+# else
+# define SYSCALL_ERROR_LABEL 0f
+# define SYSCALL_ERROR_HANDLER \
+0: basr %r1,0; \
+1: al %r1,2f-1b(%r1); \
+ l %r1,errno@GOT(%r1); \
+ lcr %r2,%r2; \
+ st %r2,0(%r1); \
+ lhi %r2,-1; \
+ br %r14; \
+2: .long _GLOBAL_OFFSET_TABLE_-1b
+# endif /* _LIBC_REENTRANT */
+#endif /* PIC */
+
+/* Linux takes system call arguments in registers:
+
+ syscall number 1 call-clobbered
+ arg 1 2 call-clobbered
+ arg 2 3 call-clobbered
+ arg 3 4 call-clobbered
+ arg 4 5 call-clobbered
+ arg 5 6 call-saved
+ arg 6 7 call-saved
+
+ (Of course a function with say 3 arguments does not have entries for
+ arguments 4 and 5.)
+ For system calls with 6 parameters a stack operation is required
+ to load the 6th parameter to register 7. Call saved register 7 is
+ moved to register 0 and back to avoid an additional stack frame.
+ */
+
+#define DO_CALL(syscall, args) \
+ .if args > 5; \
+ lr %r0,%r7; \
+ l %r7,96(%r15); \
+ .endif; \
+ .if SYS_ify (syscall) < 256; \
+ svc SYS_ify (syscall); \
+ .else; \
+ lhi %r1,SYS_ify (syscall); \
+ svc 0; \
+ .endif; \
+ .if args > 5; \
+ lr %r7,%r0; \
+ .endif
+
+#define ret \
+ br 14
+
+#define ret_NOERRNO \
+ br 14
+
+#define ret_ERRVAL \
+ br 14
+
+#endif /* __ASSEMBLER__ */
+
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...) \
+ ({ \
+ unsigned int _ret = INTERNAL_SYSCALL (name, , nr, args); \
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_ret, ), 0)) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (_ret, )); \
+ _ret = 0xffffffff; \
+ } \
+ (int) _ret; })
+
+#undef INTERNAL_SYSCALL_DECL
+#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
+
+#undef INTERNAL_SYSCALL_DIRECT
+#define INTERNAL_SYSCALL_DIRECT(name, err, nr, args...) \
+ ({ \
+ DECLARGS_##nr(args) \
+ register int _ret asm("2"); \
+ asm volatile ( \
+ "svc %b1\n\t" \
+ : "=d" (_ret) \
+ : "i" (__NR_##name) ASMFMT_##nr \
+ : "memory" ); \
+ _ret; })
+
+#undef INTERNAL_SYSCALL_SVC0
+#define INTERNAL_SYSCALL_SVC0(name, err, nr, args...) \
+ ({ \
+ DECLARGS_##nr(args) \
+ register unsigned long _nr asm("1") = (unsigned long)(__NR_##name); \
+ register int _ret asm("2"); \
+ asm volatile ( \
+ "svc 0\n\t" \
+ : "=d" (_ret) \
+ : "d" (_nr) ASMFMT_##nr \
+ : "memory" ); \
+ _ret; })
+
+#undef INTERNAL_SYSCALL_NCS
+#define INTERNAL_SYSCALL_NCS(no, err, nr, args...) \
+ ({ \
+ DECLARGS_##nr(args) \
+ register unsigned long _nr asm("1") = (unsigned long)(no); \
+ register int _ret asm("2"); \
+ asm volatile ( \
+ "svc 0\n\t" \
+ : "=d" (_ret) \
+ : "d" (_nr) ASMFMT_##nr \
+ : "memory" ); \
+ _ret; })
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, err, nr, args...) \
+ (((__NR_##name) < 256) ? \
+ INTERNAL_SYSCALL_DIRECT(name, err, nr, args) : \
+ INTERNAL_SYSCALL_SVC0(name, err,nr, args))
+
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+ ((unsigned int) (val) >= 0xfffff001u)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
+
+#define DECLARGS_0()
+#define DECLARGS_1(arg1) \
+ register unsigned long gpr2 asm ("2") = (unsigned long)(arg1);
+#define DECLARGS_2(arg1, arg2) \
+ DECLARGS_1(arg1) \
+ register unsigned long gpr3 asm ("3") = (unsigned long)(arg2);
+#define DECLARGS_3(arg1, arg2, arg3) \
+ DECLARGS_2(arg1, arg2) \
+ register unsigned long gpr4 asm ("4") = (unsigned long)(arg3);
+#define DECLARGS_4(arg1, arg2, arg3, arg4) \
+ DECLARGS_3(arg1, arg2, arg3) \
+ register unsigned long gpr5 asm ("5") = (unsigned long)(arg4);
+#define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
+ DECLARGS_4(arg1, arg2, arg3, arg4) \
+ register unsigned long gpr6 asm ("6") = (unsigned long)(arg5);
+#define DECLARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
+ DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
+ register unsigned long gpr7 asm ("7") = (unsigned long)(arg6);
+
+#define ASMFMT_0
+#define ASMFMT_1 , "0" (gpr2)
+#define ASMFMT_2 , "0" (gpr2), "d" (gpr3)
+#define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4)
+#define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5)
+#define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
+#define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7)
+
+
+/* Pointer mangling support. */
+#if defined NOT_IN_libc && defined IS_IN_rtld
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+ earlier than the descriptor is initialized. */
+#else
+/* For the time being just use stack_guard rather than a separate
+ pointer_guard. */
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(reg, tmpreg) \
+ ear tmpreg,%a0; \
+ x reg,STACK_GUARD(tmpreg)
+# define PTR_MANGLE2(reg, tmpreg) \
+ x reg,STACK_GUARD(tmpreg)
+# define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
+# else
+# define PTR_MANGLE(var) \
+ (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+# define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* _LINUX_S390_SYSDEP_H */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/versionsort64.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/versionsort64.c
new file mode 100644
index 000000000..144b691e5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/versionsort64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/versionsort64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-32/xstat.c b/libc/sysdeps/unix/sysv/linux/s390/s390-32/xstat.c
new file mode 100644
index 000000000..e9869f550
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-32/xstat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/xstat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/Implies b/libc/sysdeps/unix/sysv/linux/s390/s390-64/Implies
new file mode 100644
index 000000000..8d91c8009
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/Implies
@@ -0,0 +1 @@
+unix/sysv/linux/wordsize-64
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/Makefile b/libc/sysdeps/unix/sysv/linux/s390/s390-64/Makefile
new file mode 100644
index 000000000..283361b3f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/Makefile
@@ -0,0 +1,11 @@
+ifeq ($(subdir),misc)
+sysdep_headers += sys/elf.h
+endif
+
+ifeq ($(subdir),elf)
+ifeq (yes,$(build-shared))
+# This is needed to support g++ v2 and v3.
+sysdep_routines += framestate
+shared-only-routines += framestate
+endif
+endif
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/Versions b/libc/sysdeps/unix/sysv/linux/s390/s390-64/Versions
new file mode 100644
index 000000000..83092db48
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/Versions
@@ -0,0 +1,7 @@
+libc {
+ GLIBC_2.2 {
+ # Exception handling support functions from libgcc
+ __register_frame; __register_frame_table; __deregister_frame;
+ __frame_state_for; __register_frame_info_table;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/clone.S b/libc/sysdeps/unix/sysv/linux/s390/s390-64/clone.S
new file mode 100644
index 000000000..cdc6716a1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/clone.S
@@ -0,0 +1,79 @@
+/* Wrapper around clone system call. 64 bit S/390 version.
+ Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* clone is even more special than fork as it mucks with stacks
+ and invokes a function in the right context after its all over. */
+
+#include <sysdep.h>
+#include <tls.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+/* int __clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
+ pid_t *parent_tid, void *tls, pid_t *child_tid); */
+/* sys_clone (void *child_stack, unsigned long flags,
+ pid_t *parent_tid, pid_t *child_tid, void *tls); */
+
+ .text
+ENTRY(__clone)
+ stg %r6,48(%r15) /* store %r6 to save area */
+ cfi_offset (%r6,-112)
+ lgr %r0,%r5 /* move *arg out of the way */
+ ltgr %r1,%r2 /* check fn and move to %r1 */
+ jz error /* no NULL function pointers */
+ ltgr %r2,%r3 /* check child_stack and move to %r2 */
+ jz error /* no NULL stack pointers */
+ lgr %r3,%r4 /* move flags to %r3 */
+ lgr %r4,%r6 /* move parent_tid to %r4 */
+ lg %r5,168(%r15) /* load child_tid from stack */
+ lg %r6,160(%r15) /* load tls from stack */
+ svc SYS_ify(clone)
+ ltgr %r2,%r2 /* check return code */
+ jz thread_start
+ lg %r6,48(%r15) /* restore %r6 */
+ jgm SYSCALL_ERROR_LABEL
+ br %r14
+error:
+ lghi %r2,-EINVAL
+ jg SYSCALL_ERROR_LABEL
+PSEUDO_END (__clone)
+
+thread_start:
+#ifdef RESET_PID
+ tmh %r3,1 /* CLONE_THREAD == 0x00010000 */
+ jne 1f
+ lhi %r2,-1
+ tml %r3,256 /* CLONE_VM == 0x00000100 */
+ jne 2f
+ svc SYS_ify(getpid)
+2: ear %r3,%a0
+ sllg %r3,%r3,32
+ ear %r3,%a1
+ st %r2,PID(%r3)
+ st %r2,TID(%r3)
+1:
+#endif
+ /* fn is in gpr 1, arg in gpr 0 */
+ lgr %r2,%r0 /* set first parameter to void *arg */
+ aghi %r15,-160 /* make room on the stack for the save area */
+ xc 0(8,%r15),0(%r15)
+ basr %r14,%r1 /* jump to fn */
+ DO_CALL (exit, 1)
+weak_alias (__clone, clone)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/dl-cache.h b/libc/sysdeps/unix/sysv/linux/s390/s390-64/dl-cache.h
new file mode 100644
index 000000000..14e1c662b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/dl-cache.h
@@ -0,0 +1,25 @@
+/* Support for reading /etc/ld.so.cache files written by Linux ldconfig.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define _DL_CACHE_DEFAULT_ID 0x403
+
+#define _dl_cache_check_flags(flags) \
+ ((flags) == _DL_CACHE_DEFAULT_ID)
+
+#include_next <dl-cache.h>
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S b/libc/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S
new file mode 100644
index 000000000..8889b5359
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S
@@ -0,0 +1,75 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <features.h>
+
+#include "ucontext_i.h"
+
+/* __getcontext (const ucontext_t *ucp)
+
+ Saves the machine context in UCP such that when it is activated,
+ it appears as if __getcontext() returned again.
+
+ This implementation is intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to save anything
+ other than the PRESERVED state. */
+
+ENTRY(__getcontext)
+ lgr %r5,%r2
+
+ /* sigprocmask (SIG_BLOCK, NULL, &sc->sc_mask). */
+ la %r2,SIG_BLOCK
+ slgr %r3,%r3
+ la %r4,SC_MASK(%r5)
+ svc SYS_ify(rt_sigprocmask)
+
+ /* Store fpu context. */
+ stfpc SC_FPC(%r5)
+ std %f0,SC_FPRS(%r5)
+ std %f1,SC_FPRS+8(%r5)
+ std %f2,SC_FPRS+16(%r5)
+ std %f3,SC_FPRS+24(%r5)
+ std %f4,SC_FPRS+32(%r5)
+ std %f5,SC_FPRS+40(%r5)
+ std %f6,SC_FPRS+48(%r5)
+ std %f7,SC_FPRS+56(%r5)
+ std %f8,SC_FPRS+64(%r5)
+ std %f9,SC_FPRS+72(%r5)
+ std %f10,SC_FPRS+80(%r5)
+ std %f11,SC_FPRS+88(%r5)
+ std %f12,SC_FPRS+96(%r5)
+ std %f13,SC_FPRS+104(%r5)
+ std %f14,SC_FPRS+112(%r5)
+ std %f15,SC_FPRS+120(%r5)
+
+ /* Set __getcontext return value to 0. */
+ slgr %r2,%r2
+
+ /* Store access registers. */
+ stam %a0,%a15,SC_ACRS(%r5)
+
+ /* Store general purpose registers. */
+ stmg %r0,%r15,SC_GPRS(%r5)
+
+ /* Return. */
+ br %r14
+END(__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/kernel_stat.h b/libc/sysdeps/unix/sysv/linux/s390/s390-64/kernel_stat.h
new file mode 100644
index 000000000..ef11dc94d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/kernel_stat.h
@@ -0,0 +1,21 @@
+/* Definition of `struct stat' used in the kernel.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define STAT_IS_KERNEL_STAT 1
+#define XSTAT_IS_XSTAT64 1
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c b/libc/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c
new file mode 100644
index 000000000..cdff9a4f2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <libintl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ucontext.h>
+
+/* This implementation can handle any ARGC value but only
+ normal integer type parameters. Parameters of type float,
+ double, complex and structure with sizes 0, 2, 4 or 8
+ won't work.
+ makecontext sets up a stack and the registers for the
+ user context. The stack looks like this:
+ size offset
+ %r15 -> +-----------------------+
+ 8 | back chain (zero) | 0
+ 8 | reserved | 8
+ 144 | save area for (*func) | 16
+ +-----------------------+
+ n | overflow parameters | 160
+ +-----------------------+
+ 8 | trampoline | 160+n
+ +-----------------------+
+ The registers are set up like this:
+ %r2-%r6: parameters 1 to 5
+ %r7 : (*func) pointer
+ %r8 : uc_link from ucontext structure
+ %r9 : address of setcontext
+ %r14 : return address to uc_link trampoline
+ %r15 : stack pointer.
+
+ The trampoline looks like this:
+ basr %r14,%r7
+ lgr %r2,%r8
+ br %r9. */
+
+void
+__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
+{
+ unsigned long *sp;
+ va_list ap;
+ int i;
+
+ sp = (long *) (((long) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & -8L);
+
+ /* Setup the trampoline. */
+ *--sp = 0x0de7b904002807f9;
+
+ /* Set the return address to trampoline. */
+ ucp->uc_mcontext.gregs[14] = (long) sp;
+
+ /* Set register parameters. */
+ va_start (ap, argc);
+ for (i = 0; (i < argc) && (i < 5); i++)
+ ucp->uc_mcontext.gregs[2+i] = va_arg (ap, long);
+
+ /* The remaining arguments go to the overflow area. */
+ if (argc > 5) {
+ sp -= argc - 5;
+ for (i = 5; i < argc; i++)
+ sp[i] = va_arg(ap, long);
+ }
+ va_end (ap);
+
+ /* Make room for the save area and set the backchain. */
+ sp -= 20;
+ *sp = 0;
+
+ /* Pass (*func) to __start_context in %r7. */
+ ucp->uc_mcontext.gregs[7] = (long) func;
+
+ /* Pass ucp->uc_link to __start_context in %r8. */
+ ucp->uc_mcontext.gregs[8] = (long) ucp->uc_link;
+
+ /* Pass address of setcontext in %r9. */
+ ucp->uc_mcontext.gregs[9] = (long) &setcontext;
+
+ /* Set stack pointer. */
+ ucp->uc_mcontext.gregs[15] = (long) sp;
+}
+
+weak_alias (__makecontext, makecontext)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/mmap.S b/libc/sysdeps/unix/sysv/linux/s390/s390-64/mmap.S
new file mode 100644
index 000000000..443d432e1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/mmap.S
@@ -0,0 +1,79 @@
+/* Wrapper around mmap system call. 64 bit S/390 version.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#define EINVAL 22
+
+ .text
+
+ENTRY(__mmap)
+ /* Save registers and setup stack frame. */
+ stmg %r6,%r15,48(%r15)
+ cfi_offset (%r15,-40)
+ cfi_offset (%r14,-48)
+ cfi_offset (%r13,-56)
+ cfi_offset (%r12,-64)
+ cfi_offset (%r11,-72)
+ cfi_offset (%r10,-80)
+ cfi_offset (%r9,-88)
+ cfi_offset (%r8,-96)
+ cfi_offset (%r7,-104)
+ cfi_offset (%r6,-112)
+ lgr %r1,%r15
+ lg %r0,8(%r15) /* Load eos. */
+ aghi %r15,-208 /* Buy stack space. */
+ cfi_adjust_cfa_offset (208)
+ stg %r1,0(%r15) /* Store back chain. */
+ stg %r0,8(%r15) /* Store eos. */
+
+ /* Store parameters on stack, because old_mmap
+ takes only one parameter: a pointer to the parameter area. */
+ mvc 200(8,%r15),368(%r15) /* Move 'offset'. */
+ lgfr %r6,%r6
+ stg %r6,192(%r15) /* Store 'fd'. */
+ lgfr %r5,%r5
+ stg %r5,184(%r15) /* Store 'flags'. */
+ lgfr %r4,%r4
+ stg %r4,176(%r15) /* Store 'prot'. */
+ stg %r3,168(%r15) /* Store 'length'. */
+ stg %r2,160(%r15) /* Store 'start'. */
+
+ la %r2,160(%r15) /* Load address of parameter list. */
+ /* Do the system call trap. */
+ svc SYS_ify(mmap)
+
+ lg %r15,0(%r15) /* Load back chain. */
+ cfi_adjust_cfa_offset (-208)
+ lmg %r6,%r15,48(%r15) /* Load registers. */
+
+ /* Check gpr 2 for error. */
+ lghi %r0,-4096
+ clgr %r2,%r0
+ jgnl SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+ br %r14
+
+PSEUDO_END (__mmap)
+
+weak_alias (__mmap, mmap)
+weak_alias (__mmap, mmap64)
+weak_alias (__mmap, __mmap64)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/profil-counter.h b/libc/sysdeps/unix/sysv/linux/s390/s390-64/profil-counter.h
new file mode 100644
index 000000000..d151b529b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/profil-counter.h
@@ -0,0 +1,27 @@
+/* Low-level statistical profiling support function. Linux/s390 version.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <signal.h>
+#include <sigcontextinfo.h>
+
+static void
+profil_counter (int signo, SIGCONTEXT scp)
+{
+ profil_count ((void *) GET_PC (scp));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/register-dump.h b/libc/sysdeps/unix/sysv/linux/s390/s390-64/register-dump.h
new file mode 100644
index 000000000..d705dd76d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/register-dump.h
@@ -0,0 +1,133 @@
+/* Dump registers. 64 bit S/390 version.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/uio.h>
+#include <stdio-common/_itoa.h>
+
+/* We will print the register dump in this format:
+
+ GPR0: XXXXXXXXXXXXXXXX GPR1: XXXXXXXXXXXXXXXX
+ GPR2: XXXXXXXXXXXXXXXX GPR3: XXXXXXXXXXXXXXXX
+ GPR4: XXXXXXXXXXXXXXXX GPR5: XXXXXXXXXXXXXXXX
+ GPR6: XXXXXXXXXXXXXXXX GPR7: XXXXXXXXXXXXXXXX
+ GPR8: XXXXXXXXXXXXXXXX GPR9: XXXXXXXXXXXXXXXX
+ GPRA: XXXXXXXXXXXXXXXX GPRB: XXXXXXXXXXXXXXXX
+ GPRC: XXXXXXXXXXXXXXXX GPRD: XXXXXXXXXXXXXXXX
+ GPRE: XXXXXXXXXXXXXXXX GPRF: XXXXXXXXXXXXXXXX
+
+ PSW.MASK: XXXXXXXXXXXXXXXX PSW.ADDR: XXXXXXXXXXXXXXXX
+
+ ST(0) XXXX XXXXXXXXXXXXXXXX ST(1) XXXX XXXXXXXXXXXXXXXX
+ ST(2) XXXX XXXXXXXXXXXXXXXX ST(3) XXXX XXXXXXXXXXXXXXXX
+ ST(4) XXXX XXXXXXXXXXXXXXXX ST(5) XXXX XXXXXXXXXXXXXXXX
+ ST(6) XXXX XXXXXXXXXXXXXXXX ST(7) XXXX XXXXXXXXXXXXXXXX
+ */
+
+static void
+hexvalue (unsigned long int value, char *buf, size_t len)
+{
+ char *cp = _itoa_word (value, buf + len, 16, 0);
+ while (cp > buf)
+ *--cp = '0';
+}
+
+static void
+register_dump (int fd, struct sigcontext *ctx)
+{
+ char regs[19][16];
+ struct iovec iov[40];
+ size_t nr = 0;
+
+#define ADD_STRING(str) \
+ iov[nr].iov_base = (char *) str; \
+ iov[nr].iov_len = strlen (str); \
+ ++nr
+#define ADD_MEM(str, len) \
+ iov[nr].iov_base = str; \
+ iov[nr].iov_len = len; \
+ ++nr
+
+ /* Generate strings of register contents. */
+ hexvalue (ctx->sregs->regs.gprs[0], regs[0], 16);
+ hexvalue (ctx->sregs->regs.gprs[1], regs[1], 16);
+ hexvalue (ctx->sregs->regs.gprs[2], regs[2], 16);
+ hexvalue (ctx->sregs->regs.gprs[3], regs[3], 16);
+ hexvalue (ctx->sregs->regs.gprs[4], regs[4], 16);
+ hexvalue (ctx->sregs->regs.gprs[5], regs[5], 16);
+ hexvalue (ctx->sregs->regs.gprs[6], regs[6], 16);
+ hexvalue (ctx->sregs->regs.gprs[7], regs[7], 16);
+ hexvalue (ctx->sregs->regs.gprs[8], regs[8], 16);
+ hexvalue (ctx->sregs->regs.gprs[9], regs[9], 16);
+ hexvalue (ctx->sregs->regs.gprs[10], regs[10], 16);
+ hexvalue (ctx->sregs->regs.gprs[11], regs[11], 16);
+ hexvalue (ctx->sregs->regs.gprs[12], regs[12], 16);
+ hexvalue (ctx->sregs->regs.gprs[13], regs[13], 16);
+ hexvalue (ctx->sregs->regs.gprs[14], regs[14], 16);
+ hexvalue (ctx->sregs->regs.gprs[15], regs[15], 16);
+ hexvalue (ctx->sregs->regs.psw.mask, regs[16], 16);
+ hexvalue (ctx->sregs->regs.psw.addr, regs[17], 16);
+
+ /* Generate the output. */
+ ADD_STRING ("Register dump:\n\n GPR0: ");
+ ADD_MEM (regs[0], 16);
+ ADD_STRING (" GPR1: ");
+ ADD_MEM (regs[1], 16);
+ ADD_STRING (" GPR2: ");
+ ADD_MEM (regs[2], 16);
+ ADD_STRING (" GPR3: ");
+ ADD_MEM (regs[3], 16);
+ ADD_STRING ("\n GPR4: ");
+ ADD_MEM (regs[4], 16);
+ ADD_STRING (" GPR5: ");
+ ADD_MEM (regs[5], 16);
+ ADD_STRING (" GPR6: ");
+ ADD_MEM (regs[6], 16);
+ ADD_STRING (" GPR7: ");
+ ADD_MEM (regs[7], 16);
+ ADD_STRING ("\n GPR8: ");
+ ADD_MEM (regs[8], 16);
+ ADD_STRING (" GPR9: ");
+ ADD_MEM (regs[9], 16);
+ ADD_STRING (" GPRA: ");
+ ADD_MEM (regs[10], 16);
+ ADD_STRING (" GPRB: ");
+ ADD_MEM (regs[11], 16);
+ ADD_STRING ("\n GPRC: ");
+ ADD_MEM (regs[12], 16);
+ ADD_STRING (" GPRD: ");
+ ADD_MEM (regs[13], 16);
+ ADD_STRING (" GPRE: ");
+ ADD_MEM (regs[14], 16);
+ ADD_STRING (" GPRF: ");
+ ADD_MEM (regs[15], 16);
+ ADD_STRING ("\n\n PSW.MASK: ");
+ ADD_MEM (regs[16], 16);
+ ADD_STRING (" PSW.ADDR: ");
+ ADD_MEM (regs[17], 16);
+ ADD_STRING (" TRAP: ");
+ ADD_MEM (regs[18], 4);
+ ADD_STRING ("\n");
+
+ /* Write the stuff out. */
+ writev (fd, iov, nr);
+}
+
+
+#define REGISTER_DUMP register_dump (fd, ctx)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/setcontext.S b/libc/sysdeps/unix/sysv/linux/s390/s390-64/setcontext.S
new file mode 100644
index 000000000..7beca847c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/setcontext.S
@@ -0,0 +1,72 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <features.h>
+
+#include "ucontext_i.h"
+
+/* __setcontext (const ucontext_t *ucp)
+
+ Restores the machine context in UCP and thereby resumes execution
+ in that context.
+
+ This implementation is intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to restore anything
+ other than the PRESERVED state. */
+
+ENTRY(__setcontext)
+ lgr %r5,%r2
+
+ /* sigprocmask (SIG_SETMASK, &sc->sc_mask, NULL). */
+ la %r2,SIG_BLOCK
+ la %r3,SC_MASK(%r5)
+ slgr %r4,%r4
+ svc SYS_ify(rt_sigprocmask)
+
+ /* Load fpu context. */
+ lfpc SC_FPC(%r5)
+ ld %f0,SC_FPRS(%r5)
+ ld %f1,SC_FPRS+8(%r5)
+ ld %f2,SC_FPRS+16(%r5)
+ ld %f3,SC_FPRS+24(%r5)
+ ld %f4,SC_FPRS+32(%r5)
+ ld %f5,SC_FPRS+40(%r5)
+ ld %f6,SC_FPRS+48(%r5)
+ ld %f7,SC_FPRS+56(%r5)
+ ld %f8,SC_FPRS+64(%r5)
+ ld %f9,SC_FPRS+72(%r5)
+ ld %f10,SC_FPRS+80(%r5)
+ ld %f11,SC_FPRS+88(%r5)
+ ld %f12,SC_FPRS+96(%r5)
+ ld %f13,SC_FPRS+104(%r5)
+ ld %f14,SC_FPRS+112(%r5)
+ ld %f15,SC_FPRS+120(%r5)
+
+ /* Don't touch %a0 and %a1, used for thread purposes. */
+ lam %a2,%a15,SC_ACRS+8(%r5)
+
+ /* Load general purpose registers. */
+ lmg %r0,%r15,SC_GPRS(%r5)
+
+ /* Return. */
+ br %r14
+END(__setcontext)
+
+weak_alias (__setcontext, setcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/sigaction.c b/libc/sysdeps/unix/sysv/linux/s390/s390-64/sigaction.c
new file mode 100644
index 000000000..eff4f1785
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/sigaction.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* 64 bit Linux for S/390 only has rt signals, thus we do not even want to try
+ falling back to the old style signals as the default Linux handler does. */
+
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. This is the definition. */
+
+
+/* If ACT is not NULL, change the action for SIG to *ACT.
+ If OACT is not NULL, put the old action for SIG in *OACT. */
+int
+__libc_sigaction (sig, act, oact)
+ int sig;
+ const struct sigaction *act;
+ struct sigaction *oact;
+{
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ return INLINE_SYSCALL (rt_sigaction, 4, sig, act, oact, _NSIG / 8);
+}
+libc_hidden_def (__libc_sigaction)
+
+#ifdef WRAPPER_INCLUDE
+# include WRAPPER_INCLUDE
+#endif
+
+#ifndef LIBC_SIGACTION
+weak_alias (__libc_sigaction, __sigaction)
+libc_hidden_weak (__sigaction)
+weak_alias (__libc_sigaction, sigaction)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/sigpending.c b/libc/sysdeps/unix/sysv/linux/s390/s390-64/sigpending.c
new file mode 100644
index 000000000..808687436
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/sigpending.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* 64 bit Linux for S/390 only has rt signals, thus we do not even want to try
+ falling back to the old style signals as the default Linux handler does. */
+
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Change the set of blocked signals to SET,
+ wait until a signal arrives, and restore the set of blocked signals. */
+int
+sigpending (set)
+ sigset_t *set;
+{
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ return INLINE_SYSCALL (rt_sigpending, 2, set, _NSIG / 8);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/sigprocmask.c b/libc/sysdeps/unix/sysv/linux/s390/s390-64/sigprocmask.c
new file mode 100644
index 000000000..a6dd9159a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/sigprocmask.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* 64 bit Linux for S/390 only has rt signals, thus we do not even want to try
+ falling back to the old style signals as the default Linux handler does. */
+
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Get and/or change the set of blocked signals. */
+int
+__sigprocmask (how, set, oset)
+ int how;
+ const sigset_t *set;
+ sigset_t *oset;
+{
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ return INLINE_SYSCALL (rt_sigprocmask, 4, how, set, oset, _NSIG / 8);
+}
+weak_alias (__sigprocmask, sigprocmask)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/socket.S b/libc/sysdeps/unix/sysv/linux/s390/s390-64/socket.S
new file mode 100644
index 000000000..d4c3a1c4e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/socket.S
@@ -0,0 +1,137 @@
+/* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+/* &%/$&!! preprocessor */
+#define P(a, b) P2(a, b)
+#define P2(a, b) a##b
+
+ .text
+/* The socket-oriented system calls are handled unusally in Linux.
+ They are all gated through the single `socketcall' system call number.
+ `socketcall' takes two arguments: the first is the subcode, specifying
+ which socket function is being called; and the second is a pointer to
+ the arguments to the specific function.
+
+ The .S files for the other calls just #define socket and #include this. */
+
+#ifndef __socket
+#ifndef NO_WEAK_ALIAS
+#define __socket P(__,socket)
+#else
+#define __socket socket
+#endif
+#endif
+
+#ifndef NARGS /* The socket.o object is compiled directly ... */
+#define NARGS 3
+#endif
+
+.globl __socket
+ENTRY(__socket)
+ /* Save registers and setup stack. */
+ stmg %r6,%r15,48(%r15) /* Save registers. */
+ cfi_offset (%r15,-40)
+ cfi_offset (%r14,-48)
+ cfi_offset (%r13,-56)
+ cfi_offset (%r12,-64)
+ cfi_offset (%r11,-72)
+ cfi_offset (%r10,-80)
+ cfi_offset (%r9,-88)
+ cfi_offset (%r8,-96)
+ cfi_offset (%r7,-104)
+ cfi_offset (%r6,-112)
+ lgr %r1,%r15
+ lg %r0,8(%r15) /* Load eos. */
+ ahi %r15,-208 /* Buy stack space. */
+ cfi_adjust_cfa_offset (208)
+ stg %r1,0(%r15) /* Store back chain. */
+ stg %r0,8(%r15) /* Store eos. */
+
+ /* Reorder arguments. */
+#if (NARGS >= 6)
+ mvc 200(8,%r15),368(%r15) /* Move between parameter lists. */
+#endif
+#if (NARGS >= 5)
+ stg %r6,192(%r15) /* Store into parameter list. */
+#endif
+#if (NARGS >= 4)
+ stg %r5,184(%r15) /* Store into parameter list. */
+#endif
+#if (NARGS >= 3)
+ stg %r4,176(%r15) /* Store into parameter list. */
+#endif
+#if (NARGS >= 2)
+ stg %r3,168(%r15) /* Store into parameter list. */
+ stg %r2,160(%r15)
+#endif
+
+#if defined NEED_CANCELLATION && defined CENABLE
+ SINGLE_THREAD_P
+ jne L(socket_cancel)
+#endif
+
+ /* Load subcode for socket syscall. */
+ lghi %r2,P(SOCKOP_,socket)
+ la %r3,160(%r15) /* Load address of parameter list. */
+
+ /* Do the system call trap. */
+ svc SYS_ify(socketcall)
+
+4:
+ lg %r15,0(%r15) /* Load back chain. */
+ lmg %r6,15,48(%r15) /* Load registers. */
+
+ /* gpr2 is < 0 if there was an error. */
+ lghi %r0,-125
+ clgr %r2,%r0
+ jgnl SYSCALL_ERROR_LABEL
+
+ /* Successful; return the syscall's value. */
+ br %r14
+
+#if defined NEED_CANCELLATION && defined CENABLE
+L(socket_cancel):
+ brasl %r14,CENABLE
+ lr %r0,%r2
+
+ /* Load subcode for socket syscall. */
+ lghi %r2,P(SOCKOP_,socket)
+ la %r3,160(%r15) /* Load address of parameter list. */
+
+ /* Do the system call trap. */
+ svc SYS_ify(socketcall)
+
+ lgr %r12,%r2
+ lr %r2,%r0
+ brasl %r14,CDISABLE
+
+ lgr %r2,%r12
+ j 4b
+#endif
+
+ SYSCALL_ERROR_HANDLER
+END (__socket)
+
+#ifndef NO_WEAK_ALIAS
+weak_alias (__socket, socket)
+#endif
+
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S b/libc/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S
new file mode 100644
index 000000000..cb96fd3b6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S
@@ -0,0 +1,108 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <features.h>
+
+#include "ucontext_i.h"
+
+/* __swapcontext (ucontext_t *oucp, const ucontext_t *ucp)
+
+ Saves the machine context in oucp such that when it is activated,
+ it appears as if __swapcontextt() returned again, restores the
+ machine context in ucp and thereby resumes execution in that
+ context.
+
+ This implementation is intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to save anything
+ other than the PRESERVED state. */
+
+ENTRY(__swapcontext)
+ lgr %r1,%r2
+ lgr %r5,%r3
+
+ /* sigprocmask (SIG_BLOCK, NULL, &sc->sc_mask). */
+ la %r2,SIG_BLOCK
+ slgr %r3,%r3
+ la %r4,SC_MASK(%r1)
+ svc SYS_ify(rt_sigprocmask)
+
+ /* Store fpu context. */
+ stfpc SC_FPC(%r1)
+ std %f0,SC_FPRS(%r1)
+ std %f1,SC_FPRS+8(%r1)
+ std %f2,SC_FPRS+16(%r1)
+ std %f3,SC_FPRS+24(%r1)
+ std %f4,SC_FPRS+32(%r1)
+ std %f5,SC_FPRS+40(%r1)
+ std %f6,SC_FPRS+48(%r1)
+ std %f7,SC_FPRS+56(%r1)
+ std %f8,SC_FPRS+64(%r1)
+ std %f9,SC_FPRS+72(%r1)
+ std %f10,SC_FPRS+80(%r1)
+ std %f11,SC_FPRS+88(%r1)
+ std %f12,SC_FPRS+96(%r1)
+ std %f13,SC_FPRS+104(%r1)
+ std %f14,SC_FPRS+112(%r1)
+ std %f15,SC_FPRS+120(%r1)
+
+ /* Set __swapcontext return value to 0. */
+ slgr %r2,%r2
+
+ /* Store access registers. */
+ stam %a0,%a15,SC_ACRS(%r1)
+
+ /* Store general purpose registers. */
+ stmg %r0,%r15,SC_GPRS(%r1)
+
+ /* sigprocmask (SIG_SETMASK, &sc->sc_mask, NULL). */
+ la %r2,SIG_BLOCK
+ la %r3,SC_MASK(%r5)
+ slgr %r4,%r4
+ svc SYS_ify(rt_sigprocmask)
+
+ /* Load fpu context. */
+ lfpc SC_FPC(%r5)
+ ld %f0,SC_FPRS(%r5)
+ ld %f1,SC_FPRS+8(%r5)
+ ld %f2,SC_FPRS+16(%r5)
+ ld %f3,SC_FPRS+24(%r5)
+ ld %f4,SC_FPRS+32(%r5)
+ ld %f5,SC_FPRS+40(%r5)
+ ld %f6,SC_FPRS+48(%r5)
+ ld %f7,SC_FPRS+56(%r5)
+ ld %f8,SC_FPRS+64(%r5)
+ ld %f9,SC_FPRS+72(%r5)
+ ld %f10,SC_FPRS+80(%r5)
+ ld %f11,SC_FPRS+88(%r5)
+ ld %f12,SC_FPRS+96(%r5)
+ ld %f13,SC_FPRS+104(%r5)
+ ld %f14,SC_FPRS+112(%r5)
+ ld %f15,SC_FPRS+120(%r5)
+
+ /* Don't touch %a0 and %a1, used for thread purposes. */
+ lam %a2,%a15,SC_ACRS+8(%r5)
+
+ /* Load general purpose registers. */
+ lmg %r0,%r15,SC_GPRS(%r5)
+
+ /* Return. */
+ br %r14
+END(__swapcontext)
+weak_alias (__swapcontext, swapcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/syscall.S b/libc/sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
new file mode 100644
index 000000000..31b55d73f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
@@ -0,0 +1,69 @@
+/* Copyright (C) 2001, 2006 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* Please consult the file sysdeps/unix/sysv/linux/s390/sysdep.h for
+ more information about the value -4095 used below.*/
+
+ENTRY (syscall)
+ /* Save registers and setup stack. */
+ stmg %r6,%r15,48(%r15) /* Save registers. */
+ cfi_offset (%r15,-40)
+ cfi_offset (%r14,-48)
+ cfi_offset (%r13,-56)
+ cfi_offset (%r12,-64)
+ cfi_offset (%r11,-72)
+ cfi_offset (%r10,-80)
+ cfi_offset (%r9,-88)
+ cfi_offset (%r8,-96)
+ cfi_offset (%r7,-104)
+ cfi_offset (%r6,-112)
+ lgr %r1,%r15
+ lg %r0,8(%r15) /* Load eos. */
+ aghi %r15,-160 /* Buy stack space. */
+ cfi_adjust_cfa_offset (160)
+ stg %r1,0(%r15) /* Store back chain. */
+ stg %r0,8(%r15) /* Store eos. */
+
+ lgr %r1,%r2 /* Move syscall number. */
+ lgr %r2,%r3 /* First parameter. */
+ lgr %r3,%r4 /* Second parameter. */
+ lgr %r4,%r5 /* Third parameter. */
+ lgr %r5,%r6 /* Fourth parameter. */
+ lg %r6,320(%r15) /* Fifth parameter. */
+ lg %r7,328(%r15) /* Sixth parameter. */
+
+ basr %r8,0
+0: clg %r1,4f-0b(%r8) /* svc number < 256? */
+ jl 2f
+1: svc 0
+ j 3f
+2: ex %r1,1b-0b(%r8) /* lsb of R1 is subsituted as SVC number */
+3: lg %r15,0(%r15) /* load back chain */
+ cfi_adjust_cfa_offset (-160)
+ lmg %r6,15,48(%r15) /* Load registers. */
+
+ lghi %r0,-4095
+ clgr %r2,%r0 /* Check R2 for error. */
+ jgnl SYSCALL_ERROR_LABEL
+ br %r14 /* Return to caller. */
+4: .quad 256
+PSEUDO_END (syscall)
+
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/syscalls.list b/libc/sysdeps/unix/sysv/linux/s390/s390-64/syscalls.list
new file mode 100644
index 000000000..791ab9ba5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/syscalls.list
@@ -0,0 +1,35 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+vfork - vfork 0 __vfork vfork
+
+# semaphore and shm system calls
+msgctl - msgctl i:iip __msgctl msgctl
+msgget - msgget i:ii __msgget msgget
+msgrcv - msgrcv Ci:ibnii __msgrcv msgrcv
+msgsnd - msgsnd Ci:ibni __msgsnd msgsnd
+shmat - shmat i:ipi __shmat shmat
+shmctl - shmctl i:iip __shmctl shmctl
+shmdt - shmdt i:s __shmdt shmdt
+shmget - shmget i:iii __shmget shmget
+semop - semop i:ipi __semop semop
+semget - semget i:iii __semget semget
+semctl - semctl i:iiii __semctl semctl
+
+# proper socket implementations:
+accept - accept Ci:iBN __libc_accept __accept accept
+bind - bind i:ipi __bind bind
+connect - connect Ci:ipi __libc_connect __connect_internal __connect connect
+getpeername - getpeername i:ipp __getpeername getpeername
+getsockname - getsockname i:ipp __getsockname getsockname
+getsockopt - getsockopt i:iiiBN __getsockopt getsockopt
+listen - listen i:ii __listen listen
+recv - recv Ci:ibni __libc_recv __recv recv
+recvfrom - recvfrom Ci:ibniBN __libc_recvfrom __recvfrom recvfrom
+recvmsg - recvmsg Ci:ipi __libc_recvmsg __recvmsg recvmsg
+send - send Ci:ibni __libc_send __send send
+sendmsg - sendmsg Ci:ipi __libc_sendmsg __sendmsg sendmsg
+sendto - sendto Ci:ibnibn __libc_sendto __sendto sendto
+setsockopt - setsockopt i:iiibn __setsockopt setsockopt
+shutdown - shutdown i:ii __shutdown shutdown
+socket - socket i:iii __socket socket
+socketpair - socketpair i:iiif __socketpair socketpair
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S b/libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S
new file mode 100644
index 000000000..bb61e894f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S
@@ -0,0 +1,123 @@
+/* Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <tls.h>
+
+
+/* The following code is only used in the shared library when we
+ compile the reentrant version. Otherwise each system call defines
+ each own version. */
+
+/* The syscall stubs jump here when they detect an error. */
+
+#undef CALL_MCOUNT
+#define CALL_MCOUNT
+
+.text
+ENTRY(__syscall_error)
+#ifndef PIC
+# if USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+# define SYSCALL_ERROR_ERRNO errno
+# endif
+ basr %r1,0
+0: lg %r1,1f-0b(%r1)
+ ear %r3,%a0
+ sllg %r3,%r3,32
+ ear %r3,%a1
+ lcr %r2,%r2
+ st %r2,0(%r1,%r3)
+ lghi %r2,-1
+ br %r14
+1: .quad SYSCALL_ERROR_ERRNO@ntpoff
+# elif !defined _LIBC_REENTRANT
+ larl %r1,errno
+ lcr %r2,%r2
+ st %r2,0(%r1)
+ lghi %r2,-1
+ br %r14
+# else
+ stmg %r13,%r15,104(%r15)
+ cfi_offset (%r15,-40)
+ cfi_offset (%r14,-48)
+ cfi_offset (%r13,-56)
+ lgr %r0,%r15
+ aghi %r15,-160
+ cfi_adjust_cfa_offset (160)
+ lcr %r13,%r2
+ stg %r0,0(%r15)
+ brasl %r14,__errno_location
+ st %r13,0(%r2)
+ lmg %r13,%r15,264(%r15)
+ cfi_adjust_cfa_offset (-160)
+ lghi %r2,-1
+ br %r14
+#endif
+#else
+# if RTLD_PRIVATE_ERRNO
+ larl %r1,rtld_errno
+ lcr %r2,%r2
+ st %r2,0(%r1)
+ lghi %r2,-1
+ br %r14
+# elif USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+# define SYSCALL_ERROR_ERRNO errno
+# endif
+ larl %r1,_GLOBAL_OFFSET_TABLE_
+ lg %r1,SYSCALL_ERROR_ERRNO@gotntpoff(%r1)
+ ear %r3,%a0
+ sllg %r3,%r3,32
+ ear %r3,%a1
+ lcr %r2,%r2
+ st %r2,0(%r1,%r3)
+ lghi %r2,-1
+ br %r14
+# elif !defined _LIBC_REENTRANT
+ larl %r1,_GLOBAL_OFFSET_TABLE_
+ lg %r1,errno@GOT(%r1)
+ lcr %r2,%r2
+ st %r2,0(%r1)
+ lghi %r2,-1
+ br %r14
+# else
+ stmg %r13,%r15,104(%r15)
+ cfi_offset (%r15,-40)
+ cfi_offset (%r14,-48)
+ cfi_offset (%r13,-56)
+ lgr %r0,%r15
+ aghi %r15,-160
+ cfi_adjust_cfa_offset (160)
+ lcr %r13,%r2
+ stg %r0,0(%r15)
+ brasl %r14,__errno_location@PLT
+ st %r13,0(%r2)
+ lmg %r13,%r15,264(%r15)
+ cfi_adjust_cfa_offset (-160)
+ lghi %r2,-1
+ br %r14
+# endif
+#endif
+
+END (__syscall_error)
diff --git a/libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h b/libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
new file mode 100644
index 000000000..9ddec8e04
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
@@ -0,0 +1,304 @@
+/* Assembler macros for 64 bit S/390.
+ Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_S390_SYSDEP_H
+#define _LINUX_S390_SYSDEP_H
+
+#include <sysdeps/s390/s390-64/sysdep.h>
+#include <sysdeps/unix/sysdep.h>
+#include <dl-sysdep.h> /* For RTLD_PRIVATE_ERRNO. */
+#include <tls.h>
+
+/* For Linux we can use the system call table in the header file
+ /usr/include/asm/unistd.h
+ of the kernel. But these symbols do not follow the SYS_* syntax
+ so we have to redefine the `SYS_ify' macro here. */
+/* In newer 2.1 kernels __NR_syscall is missing so we define it here. */
+#define __NR_syscall 0
+
+/*
+ * Newer kernel versions redefined __NR_pread and __NR_pwrite to
+ * __NR_pread64 and __NR_pwrite64.
+ */
+#ifndef __NR_pread
+# define __NR_pread __NR_pread64
+#endif
+#ifndef __NR_pwrite
+# define __NR_pwrite __NR_pwrite64
+#endif
+
+#undef SYS_ify
+#define SYS_ify(syscall_name) __NR_##syscall_name
+
+#ifdef __ASSEMBLER__
+
+/* Linux uses a negative return value to indicate syscall errors, unlike
+ most Unices, which use the condition codes' carry flag.
+
+ Since version 2.1 the return value of a system call might be negative
+ even if the call succeeded. E.g., the `lseek' system call might return
+ a large offset. Therefore we must not anymore test for < 0, but test
+ for a real error by making sure the value in gpr2 is a real error
+ number. Linus said he will make sure the no syscall returns a value
+ in -1 .. -4095 as a valid result so we can savely test with -4095. */
+
+#undef PSEUDO
+#define PSEUDO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args); \
+ lghi %r4,-4095 ; \
+ clgr %r2,%r4 ; \
+ jgnl SYSCALL_ERROR_LABEL
+
+#undef PSEUDO_END
+#define PSEUDO_END(name) \
+ SYSCALL_ERROR_HANDLER; \
+ END (name)
+
+#undef PSEUDO_NOERRNO
+#define PSEUDO_NOERRNO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args)
+
+#undef PSEUDO_END_NOERRNO
+#define PSEUDO_END_NOERRNO(name) \
+ SYSCALL_ERROR_HANDLER; \
+ END (name)
+
+#undef PSEUDO_ERRVAL
+#define PSEUDO_ERRVAL(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args); \
+ lcgr %r2,%r2
+
+#undef PSEUDO_END_ERRVAL
+#define PSEUDO_END_ERRVAL(name) \
+ SYSCALL_ERROR_HANDLER; \
+ END (name)
+
+#ifndef PIC
+# define SYSCALL_ERROR_LABEL syscall_error
+# define SYSCALL_ERROR_HANDLER
+#else
+# if RTLD_PRIVATE_ERRNO
+# define SYSCALL_ERROR_LABEL 0f
+# define SYSCALL_ERROR_HANDLER \
+0: larl %r1,rtld_errno; \
+ lcr %r2,%r2; \
+ st %r2,0(%r1); \
+ lghi %r2,-1; \
+ br %r14
+# elif defined _LIBC_REENTRANT
+# if USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+# define SYSCALL_ERROR_ERRNO errno
+# endif
+# define SYSCALL_ERROR_LABEL 0f
+# define SYSCALL_ERROR_HANDLER \
+0: lcr %r0,%r2; \
+ larl %r1,SYSCALL_ERROR_ERRNO@indntpoff; \
+ lg %r1,0(%r1); \
+ ear %r2,%a0; \
+ sllg %r2,%r2,32; \
+ ear %r2,%a1; \
+ st %r0,0(%r1,%r2); \
+ lghi %r2,-1; \
+ br %r14
+# else
+# define SYSCALL_ERROR_LABEL syscall_error@plt
+# define SYSCALL_ERROR_HANDLER
+# endif
+# else
+# define SYSCALL_ERROR_LABEL 0f
+# define SYSCALL_ERROR_HANDLER \
+0: larl %r1,_GLOBAL_OFFSET_TABLE_; \
+ lg %r1,errno@GOT(%r1); \
+ lcr %r2,%r2; \
+ st %r2,0(%r1); \
+ lghi %r2,-1; \
+ br %r14
+# endif /* _LIBC_REENTRANT */
+#endif /* PIC */
+
+/* Linux takes system call arguments in registers:
+
+ syscall number 1 call-clobbered
+ arg 1 2 call-clobbered
+ arg 2 3 call-clobbered
+ arg 3 4 call-clobbered
+ arg 4 5 call-clobbered
+ arg 5 6 call-saved
+ arg 6 7 call-saved
+
+ (Of course a function with say 3 arguments does not have entries for
+ arguments 4 and 5.)
+ For system calls with 6 parameters a stack operation is required
+ to load the 6th parameter to register 7. Call saved register 7 is
+ moved to register 0 and back to avoid an additional stack frame.
+ */
+
+#define DO_CALL(syscall, args) \
+ .if args > 5; \
+ lgr %r0,%r7; \
+ lg %r7,160(%r15); \
+ .endif; \
+ .if SYS_ify (syscall) < 256; \
+ svc SYS_ify (syscall); \
+ .else; \
+ lghi %r1,SYS_ify (syscall); \
+ svc 0; \
+ .endif; \
+ .if args > 5; \
+ lgr %r7,%r0; \
+ .endif
+
+#define ret \
+ br 14
+
+#define ret_NOERRNO \
+ br 14
+
+#define ret_ERRVAL \
+ br 14
+
+#endif /* __ASSEMBLER__ */
+
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...) \
+ ({ \
+ long _ret = INTERNAL_SYSCALL (name, , nr, args); \
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_ret, ), 0)) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (_ret, )); \
+ _ret = -1; \
+ } \
+ _ret; })
+
+#undef INTERNAL_SYSCALL_DECL
+#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
+
+#undef INTERNAL_SYSCALL_DIRECT
+#define INTERNAL_SYSCALL_DIRECT(name, err, nr, args...) \
+ ({ \
+ DECLARGS_##nr(args) \
+ register long _ret asm("2"); \
+ asm volatile ( \
+ "svc %b1\n\t" \
+ : "=d" (_ret) \
+ : "i" (__NR_##name) ASMFMT_##nr \
+ : "memory" ); \
+ _ret; })
+
+#undef INTERNAL_SYSCALL_SVC0
+#define INTERNAL_SYSCALL_SVC0(name, err, nr, args...) \
+ ({ \
+ DECLARGS_##nr(args) \
+ register unsigned long _nr asm("1") = (unsigned long)(__NR_##name); \
+ register long _ret asm("2"); \
+ asm volatile ( \
+ "svc 0\n\t" \
+ : "=d" (_ret) \
+ : "d" (_nr) ASMFMT_##nr \
+ : "memory" ); \
+ _ret; })
+
+#undef INTERNAL_SYSCALL_NCS
+#define INTERNAL_SYSCALL_NCS(no, err, nr, args...) \
+ ({ \
+ DECLARGS_##nr(args) \
+ register unsigned long _nr asm("1") = (unsigned long)(no); \
+ register long _ret asm("2"); \
+ asm volatile ( \
+ "svc 0\n\t" \
+ : "=d" (_ret) \
+ : "d" (_nr) ASMFMT_##nr \
+ : "memory" ); \
+ _ret; })
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, err, nr, args...) \
+ (((__NR_##name) < 256) ? \
+ INTERNAL_SYSCALL_DIRECT(name, err, nr, args) : \
+ INTERNAL_SYSCALL_SVC0(name, err,nr, args))
+
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+ ((unsigned long) (val) >= -4095UL)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
+
+#define DECLARGS_0()
+#define DECLARGS_1(arg1) \
+ register unsigned long gpr2 asm ("2") = (unsigned long)(arg1);
+#define DECLARGS_2(arg1, arg2) \
+ DECLARGS_1(arg1) \
+ register unsigned long gpr3 asm ("3") = (unsigned long)(arg2);
+#define DECLARGS_3(arg1, arg2, arg3) \
+ DECLARGS_2(arg1, arg2) \
+ register unsigned long gpr4 asm ("4") = (unsigned long)(arg3);
+#define DECLARGS_4(arg1, arg2, arg3, arg4) \
+ DECLARGS_3(arg1, arg2, arg3) \
+ register unsigned long gpr5 asm ("5") = (unsigned long)(arg4);
+#define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
+ DECLARGS_4(arg1, arg2, arg3, arg4) \
+ register unsigned long gpr6 asm ("6") = (unsigned long)(arg5);
+#define DECLARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
+ DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
+ register unsigned long gpr7 asm ("7") = (unsigned long)(arg6);
+
+#define ASMFMT_0
+#define ASMFMT_1 , "0" (gpr2)
+#define ASMFMT_2 , "0" (gpr2), "d" (gpr3)
+#define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4)
+#define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5)
+#define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
+#define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7)
+
+/* Pointer mangling support. */
+#if defined NOT_IN_libc && defined IS_IN_rtld
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+ earlier than the descriptor is initialized. */
+#else
+/* For the time being just use stack_guard rather than a separate
+ pointer_guard. */
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(reg, tmpreg) \
+ ear tmpreg,%a0; \
+ sllg tmpreg,tmpreg,32; \
+ ear tmpreg,%a1; \
+ xg reg,STACK_GUARD(tmpreg)
+# define PTR_MANGLE2(reg, tmpreg) \
+ xg reg,STACK_GUARD(tmpreg)
+# define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
+# else
+# define PTR_MANGLE(var) \
+ (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+# define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* _LINUX_S390_SYSDEP_H */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/semtimedop.c b/libc/sysdeps/unix/sysv/linux/s390/semtimedop.c
new file mode 100644
index 000000000..d8990dd02
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/semtimedop.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/sem.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Perform user-defined atomical operation of array of semaphores. */
+
+int
+semtimedop (semid, sops, nsops, timeout)
+ int semid;
+ struct sembuf *sops;
+ size_t nsops;
+ const struct timespec *timeout;
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semtimedop,
+ semid, (int) nsops, timeout, sops);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h b/libc/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h
new file mode 100644
index 000000000..ef9126471
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h
@@ -0,0 +1,28 @@
+/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+ Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <signal.h>
+
+#define SIGCONTEXT struct sigcontext *
+#define SIGCONTEXT_EXTRA_ARGS
+#define GET_PC(ctx) ((void *)((ctx)->sregs->regs.psw.addr))
+#define GET_FRAME(ctx) (*(void **)((ctx)->sregs->regs.gprs[11]))
+#define GET_STACK(ctx) ((void *)((ctx)->sregs->regs.gprs[15]))
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
diff --git a/libc/sysdeps/unix/sysv/linux/s390/sys/elf.h b/libc/sysdeps/unix/sysv/linux/s390/sys/elf.h
new file mode 100644
index 000000000..431b79b44
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/sys/elf.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_ELF_H
+#define _SYS_ELF_H 1
+
+#warning "This header is obsolete; use <sys/procfs.h> instead."
+
+#include <sys/procfs.h>
+
+#endif /* _SYS_ELF_H */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/sys/procfs.h b/libc/sysdeps/unix/sysv/linux/s390/sys/procfs.h
new file mode 100644
index 000000000..9c6caacae
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/sys/procfs.h
@@ -0,0 +1,176 @@
+/* Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H 1
+
+/* This is somewhat modelled after the file of the same name on SVR4
+ systems. It provides a definition of the core file format for ELF
+ used on Linux. It doesn't have anything to do with the /proc file
+ system, even though Linux has one.
+
+ Anyway, the whole purpose of this file is for GDB and GDB only.
+ Don't read too much into it. Don't use it for anything other than
+ GDB unless you know what you are doing. */
+
+#include <features.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/user.h>
+#include <sys/ucontext.h>
+
+__BEGIN_DECLS
+
+typedef greg_t elf_greg_t;
+#define ELF_NGREG NGREG
+typedef gregset_t elf_gregset_t;
+typedef fpreg_t elf_fpreg_t;
+typedef fpregset_t elf_fpregset_t;
+
+/* Signal info. */
+struct elf_siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_code; /* Extra code. */
+ int si_errno; /* Errno. */
+ };
+
+
+/* Definitions to generate Intel SVR4-like core files. These mostly
+ have the same names as the SVR4 types with "elf_" tacked on the
+ front to prevent clashes with Linux definitions, and the typedef
+ forms have been avoided. This is mostly like the SVR4 structure,
+ but more Linuxy, with things that Linux does not support and which
+ GDB doesn't really use excluded. */
+
+struct elf_prstatus
+ {
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned long int pr_sigpend; /* Set of pending signals. */
+ unsigned long int pr_sighold; /* Set of held signals. */
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct timeval pr_utime; /* User time. */
+ struct timeval pr_stime; /* System time. */
+ struct timeval pr_cutime; /* Cumulative user time. */
+ struct timeval pr_cstime; /* Cumulative system time. */
+ elf_gregset_t pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+
+#define ELF_PRARGSZ (80) /* Number of chars for args. */
+
+struct elf_prpsinfo
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned long int pr_flag; /* Flags. */
+#if __WORDSIZE == 64
+ unsigned int pr_uid;
+ unsigned int pr_gid;
+#else
+ unsigned short int pr_uid;
+ unsigned short int pr_gid;
+#endif
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+/* The rest of this file provides the types for emulation of the
+ Solaris <proc_service.h> interfaces that should be implemented by
+ users of libthread_db. */
+
+/* Addresses. */
+typedef void *psaddr_t;
+
+/* Register sets. Linux has different names. */
+typedef elf_gregset_t prgregset_t;
+typedef elf_fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+ therefore have only one PID type. */
+typedef __pid_t lwpid_t;
+
+/* Process status and info. In the end we do provide typedefs for them. */
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+#if __WORDSIZE == 64
+
+/* Provide 32-bit variants so that BFD can read 32-bit
+ core files. */
+#define ELF_NGREG32 36
+typedef unsigned int elf_greg_t32;
+typedef elf_greg_t32 elf_gregset_t32[ELF_NGREG32];
+typedef elf_fpregset_t elf_fpregset_t32;
+
+struct elf_prstatus32
+ {
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned int pr_sigpend; /* Set of pending signals. */
+ unsigned int pr_sighold; /* Set of held signals. */
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct
+ {
+ int tv_sec, tv_usec;
+ } pr_utime, /* User time. */
+ pr_stime, /* System time. */
+ pr_cutime, /* Cumulative user time. */
+ pr_cstime; /* Cumulative system time. */
+ elf_gregset_t32 pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+struct elf_prpsinfo32
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned int pr_flag; /* Flags. */
+ unsigned short int pr_uid;
+ unsigned short int pr_gid;
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+typedef elf_gregset_t32 prgregset32_t;
+typedef elf_fpregset_t32 prfpregset32_t;
+
+typedef struct elf_prstatus32 prstatus32_t;
+typedef struct elf_prpsinfo32 prpsinfo32_t;
+
+#endif
+
+__END_DECLS
+
+#endif /* sys/procfs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/sys/ptrace.h b/libc/sysdeps/unix/sysv/linux/s390/sys/ptrace.h
new file mode 100644
index 000000000..d26cf114e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/sys/ptrace.h
@@ -0,0 +1,138 @@
+/* `ptrace' debugger support interface. Linux version.
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ Contributed by Denis Joseph Barrow (djbarrow@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PTRACE_H
+#define _SYS_PTRACE_H 1
+
+#include <features.h>
+
+__BEGIN_DECLS
+#ifdef _LINUX_PTRACE_H
+/* Kludge to stop stuff gdb & strace compiles from getting upset
+ */
+#undef PTRACE_TRACEME
+#undef PTRACE_PEEKTEXT
+#undef PTRACE_PEEKDATA
+#undef PTRACE_PEEKUSR
+#undef PTRACE_POKETEXT
+#undef PTRACE_POKEDATA
+#undef PTRACE_POKEUSR
+#undef PTRACE_CONT
+#undef PTRACE_KILL
+#undef PTRACE_SINGLESTEP
+
+#undef PTRACE_ATTACH
+#undef PTRACE_DETACH
+
+#undef PTRACE_SYSCALL
+#endif
+/* Type of the REQUEST argument to `ptrace.' */
+enum __ptrace_request
+{
+ /* Indicate that the process making this request should be traced.
+ All signals received by this process can be intercepted by its
+ parent, and its parent can use the other `ptrace' requests. */
+ PTRACE_TRACEME = 0,
+#define PT_TRACE_ME PTRACE_TRACEME
+
+ /* Return the word in the process's text space at address ADDR. */
+ PTRACE_PEEKTEXT = 1,
+#define PT_READ_I PTRACE_PEEKTEXT
+
+ /* Return the word in the process's data space at address ADDR. */
+ PTRACE_PEEKDATA = 2,
+#define PT_READ_D PTRACE_PEEKDATA
+
+ /* Return the word in the process's user area at offset ADDR. */
+ PTRACE_PEEKUSER = 3,
+#define PT_READ_U PTRACE_PEEKUSER
+
+ /* Write the word DATA into the process's text space at address ADDR. */
+ PTRACE_POKETEXT = 4,
+#define PT_WRITE_I PTRACE_POKETEXT
+
+ /* Write the word DATA into the process's data space at address ADDR. */
+ PTRACE_POKEDATA = 5,
+#define PT_WRITE_D PTRACE_POKEDATA
+
+ /* Write the word DATA into the process's user area at offset ADDR. */
+ PTRACE_POKEUSER = 6,
+#define PT_WRITE_U PTRACE_POKEUSER
+
+ /* Continue the process. */
+ PTRACE_CONT = 7,
+#define PT_CONTINUE PTRACE_CONT
+
+ /* Kill the process. */
+ PTRACE_KILL = 8,
+#define PT_KILL PTRACE_KILL
+
+ /* Single step the process.
+ This is not supported on all machines. */
+ PTRACE_SINGLESTEP = 9,
+#define PT_STEP PTRACE_SINGLESTEP
+
+ /* Get all general purpose registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_GETREGS = 12,
+#define PT_GETREGS PTRACE_GETREGS
+
+ /* Set all general purpose registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_SETREGS = 13,
+#define PT_SETREGS PTRACE_SETREGS
+
+ /* Get all floating point registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_GETFPREGS = 14,
+#define PT_GETFPREGS PTRACE_GETFPREGS
+
+ /* Set all floating point registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_SETFPREGS = 15,
+#define PT_SETFPREGS PTRACE_SETFPREGS
+
+ /* Attach to a process that is already running. */
+ PTRACE_ATTACH = 16,
+#define PT_ATTACH PTRACE_ATTACH
+
+ /* Detach from a process attached to with PTRACE_ATTACH. */
+ PTRACE_DETACH = 17,
+#define PT_DETACH PTRACE_DETACH
+
+ /* Continue and stop at the next (return from) syscall. */
+ PTRACE_SYSCALL = 24
+#define PT_SYSCALL PTRACE_SYSCALL
+};
+
+/* Perform process tracing functions. REQUEST is one of the values
+ above, and determines the action to be taken.
+ For all requests except PTRACE_TRACEME, PID specifies the process to be
+ traced.
+
+ PID and the other arguments described above for the various requests should
+ appear (those that are used for the particular request) as:
+ pid_t PID, void *ADDR, int DATA, void *ADDR2
+ after REQUEST. */
+extern long int ptrace (enum __ptrace_request __request, ...);
+
+__END_DECLS
+
+#endif /* _SYS_PTRACE_H */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/sys/ucontext.h b/libc/sysdeps/unix/sysv/linux/s390/sys/ucontext.h
new file mode 100644
index 000000000..4e32361c3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/sys/ucontext.h
@@ -0,0 +1,88 @@
+/* Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+ Contributed by Denis Joseph Barrow (djbarrow@de.ibm.com).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+/* Forward definition to avoid parse errors */
+struct ucontext;
+typedef struct ucontext ucontext_t;
+#include <features.h>
+#include <signal.h>
+
+/* We need the signal context definitions even if they are not used
+ included in <signal.h>. */
+#include <bits/sigcontext.h>
+
+/* Type for a program status word. */
+typedef struct
+{
+ unsigned long mask;
+ unsigned long addr;
+} __attribute__ ((aligned(8))) __psw_t;
+
+/* Type for a general-purpose register. */
+typedef unsigned long greg_t;
+
+/* And the whole bunch of them. We should have used `struct s390_regs',
+ but to avoid name space pollution and since the tradition says that
+ the register set is an array, we make gregset_t a simple array
+ that has the same size as s390_regs. This is needed for the
+ elf_prstatus structure. */
+#if __WORDSIZE == 64
+# define NGREG 27
+#else
+# define NGREG 36
+#endif
+/* Must match kernels psw_t alignment. */
+typedef greg_t gregset_t[NGREG] __attribute__ ((aligned(8)));
+
+typedef union
+ {
+ double d;
+ float f;
+ } fpreg_t;
+
+/* Register set for the floating-point registers. */
+typedef struct
+ {
+ unsigned int fpc;
+ fpreg_t fprs[16];
+ } fpregset_t;
+
+/* Context to describe whole processor state. */
+typedef struct
+ {
+ __psw_t psw;
+ unsigned long gregs[16];
+ unsigned int aregs[16];
+ fpregset_t fpregs;
+ } mcontext_t;
+
+/* Userlevel context. */
+struct ucontext
+ {
+ unsigned long int uc_flags;
+ struct ucontext *uc_link;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ __sigset_t uc_sigmask;
+ };
+
+
+#endif /* sys/ucontext.h */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/sys/user.h b/libc/sysdeps/unix/sysv/linux/s390/sys/user.h
new file mode 100644
index 000000000..f00caea84
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/sys/user.h
@@ -0,0 +1,83 @@
+/* Copyright (C) 2000,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_USER_H
+#define _SYS_USER_H 1
+
+/* The whole purpose of this file is for GDB and GDB only. Don't read
+ too much into it. Don't use it for anything other than GDB unless
+ you know what you are doing. */
+
+struct _user_psw_struct
+{
+ unsigned long mask;
+ unsigned long addr;
+};
+
+struct _user_fpregs_struct
+{
+ unsigned int fpc;
+ double fprs[16];
+};
+
+struct _user_per_struct
+{
+ unsigned long control_regs[3];
+ unsigned single_step : 1;
+ unsigned instruction_fetch : 1;
+ unsigned : 30;
+ unsigned long starting_addr;
+ unsigned long ending_addr;
+ unsigned short perc_atmid;
+ unsigned long address;
+ unsigned char access_id;
+};
+
+struct _user_regs_struct
+{
+ struct _user_psw_struct psw; /* Program status word. */
+ unsigned long gprs[16]; /* General purpose registers. */
+ unsigned int acrs[16]; /* Access registers. */
+ unsigned long orig_gpr2; /* Original gpr2. */
+ struct _user_fpregs_struct fp_regs; /* Floating point registers. */
+ struct _user_per_struct per_info; /* Hardware tracing registers. */
+ unsigned long ieee_instruction_pointer;
+};
+
+struct user {
+ struct _user_regs_struct regs; /* User registers. */
+ unsigned long int u_tsize; /* Text segment size (pages). */
+ unsigned long int u_dsize; /* Data segment size (pages). */
+ unsigned long int u_ssize; /* Stack segment size (pages). */
+ unsigned long start_code; /* Starting address of text. */
+ unsigned long start_stack; /* Starting address of stack area. */
+ long int signal; /* Signal causing the core dump. */
+ struct _user_regs_struct *u_ar0; /* Help gdb find registers. */
+ unsigned long magic; /* Identifies a core file. */
+ char u_comm[32]; /* User command naem. */
+};
+
+#define PAGE_SHIFT 12
+#define PAGE_SIZE (1UL << PAGE_SHIFT)
+#define PAGE_MASK (~(PAGE_SIZE-1))
+#define NBPG PAGE_SIZE
+#define UPAGES 1
+#define HOST_TEXT_START_ADDR (u.start_code)
+#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
+
+#endif /* _SYS_USER_H */
diff --git a/libc/sysdeps/unix/sysv/linux/s390/system.c b/libc/sysdeps/unix/sysv/linux/s390/system.c
new file mode 100644
index 000000000..13a1331ad
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/system.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <kernel-features.h>
+
+/* We have to and actually can handle cancelable system(). The big
+ problem: we have to kill the child process if necessary. To do
+ this a cleanup handler has to be registered and is has to be able
+ to find the PID of the child. The main problem is to reliable have
+ the PID when needed. It is not necessary for the parent thread to
+ return. It might still be in the kernel when the cancellation
+ request comes. Therefore we have to use the clone() calls ability
+ to have the kernel write the PID into the user-level variable. */
+#ifdef __ASSUME_CLONE_THREAD_FLAGS
+# define FORK() \
+ INLINE_SYSCALL (clone, 3, 0, CLONE_PARENT_SETTID | SIGCHLD, &pid)
+#endif
+
+#include "../system.c"
diff --git a/libc/sysdeps/unix/sysv/linux/s390/ucontext_i.sym b/libc/sysdeps/unix/sysv/linux/s390/ucontext_i.sym
new file mode 100644
index 000000000..525b54300
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/s390/ucontext_i.sym
@@ -0,0 +1,23 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+--
+
+SIG_BLOCK
+SIG_UNBLOCK
+SIG_SETMASK
+
+#define ucontext(member) offsetof (ucontext_t, member)
+#define mcontext(member) ucontext (uc_mcontext.member)
+
+SC_FLGS ucontext (uc_flags)
+SC_LINK ucontext (uc_link)
+SC_STCK ucontext (uc_stack.ss_sp)
+SC_STSZ ucontext (uc_stack.ss_size)
+SC_PSW mcontext (psw)
+SC_GPRS mcontext (gregs)
+SC_ACRS mcontext (aregs)
+SC_FPC mcontext (fpregs.fpc)
+SC_FPRS mcontext (fpregs.fprs)
+SC_MASK ucontext (uc_sigmask)
diff --git a/libc/sysdeps/unix/sysv/linux/sa_len.c b/libc/sysdeps/unix/sysv/linux/sa_len.c
new file mode 100644
index 000000000..ae5616bf4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sa_len.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/socket.h>
+
+#include <netash/ash.h>
+#include <netatalk/at.h>
+#include <netax25/ax25.h>
+#include <neteconet/ec.h>
+#include <netinet/in.h>
+#include <netipx/ipx.h>
+#include <netpacket/packet.h>
+#include <netrose/rose.h>
+#include <sys/un.h>
+
+int
+__libc_sa_len (sa_family_t af)
+{
+ switch (af)
+ {
+ case AF_APPLETALK:
+ return sizeof (struct sockaddr_at);
+ case AF_ASH:
+ return sizeof (struct sockaddr_ash);
+ case AF_AX25:
+ return sizeof (struct sockaddr_ax25);
+ case AF_ECONET:
+ return sizeof (struct sockaddr_ec);
+ case AF_INET:
+ return sizeof (struct sockaddr_in);
+ case AF_INET6:
+ return sizeof (struct sockaddr_in6);
+ case AF_IPX:
+ return sizeof (struct sockaddr_ipx);
+ case AF_LOCAL:
+ return sizeof (struct sockaddr_un);
+ case AF_PACKET:
+ return sizeof (struct sockaddr_ll);
+ case AF_ROSE:
+ return sizeof (struct sockaddr_rose);
+ }
+ return 0;
+}
+INTDEF(__libc_sa_len)
diff --git a/libc/sysdeps/unix/sysv/linux/sched_getaffinity.c b/libc/sysdeps/unix/sysv/linux/sched_getaffinity.c
new file mode 100644
index 000000000..ab171123b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sched_getaffinity.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sched.h>
+#include <string.h>
+#include <sysdep.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <shlib-compat.h>
+
+
+#ifdef __NR_sched_getaffinity
+int
+__sched_getaffinity_new (pid_t pid, size_t cpusetsize, cpu_set_t *cpuset)
+{
+ int res = INLINE_SYSCALL (sched_getaffinity, 3, pid,
+ MIN (INT_MAX, cpusetsize), cpuset);
+ if (res != -1)
+ {
+ /* Clean the rest of the memory the kernel didn't do. */
+ memset ((char *) cpuset + res, '\0', cpusetsize - res);
+
+ res = 0;
+ }
+ return res;
+}
+versioned_symbol (libc, __sched_getaffinity_new, sched_getaffinity,
+ GLIBC_2_3_4);
+
+
+# if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
+int
+attribute_compat_text_section
+__sched_getaffinity_old (pid_t pid, cpu_set_t *cpuset)
+{
+ /* The old interface by default assumed a 1024 processor bitmap. */
+ return __sched_getaffinity_new (pid, 128, cpuset);
+}
+compat_symbol (libc, __sched_getaffinity_old, sched_getaffinity, GLIBC_2_3_3);
+# endif
+#else
+# include <posix/sched_getaffinity.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sched_setaffinity.c b/libc/sysdeps/unix/sysv/linux/sched_setaffinity.c
new file mode 100644
index 000000000..ccd3c8f51
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sched_setaffinity.c
@@ -0,0 +1,88 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sched.h>
+#include <string.h>
+#include <sysdep.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <shlib-compat.h>
+#include <alloca.h>
+
+
+#ifdef __NR_sched_setaffinity
+static size_t __kernel_cpumask_size;
+
+
+int
+__sched_setaffinity_new (pid_t pid, size_t cpusetsize, const cpu_set_t *cpuset)
+{
+ if (__builtin_expect (__kernel_cpumask_size == 0, 0))
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ int res;
+
+ size_t psize = 128;
+ void *p = alloca (psize);
+
+ while (res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, getpid (),
+ psize, p),
+ INTERNAL_SYSCALL_ERROR_P (res, err)
+ && INTERNAL_SYSCALL_ERRNO (res, err) == EINVAL)
+ p = extend_alloca (p, psize, 2 * psize);
+
+ if (res == 0 || INTERNAL_SYSCALL_ERROR_P (res, err))
+ {
+ __set_errno (INTERNAL_SYSCALL_ERRNO (res, err));
+ return -1;
+ }
+
+ __kernel_cpumask_size = res;
+ }
+
+ /* We now know the size of the kernel cpumask_t. Make sure the user
+ does not request to set a bit beyond that. */
+ for (size_t cnt = __kernel_cpumask_size; cnt < cpusetsize; ++cnt)
+ if (((char *) cpuset)[cnt] != '\0')
+ {
+ /* Found a nonzero byte. This means the user request cannot be
+ fulfilled. */
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return INLINE_SYSCALL (sched_setaffinity, 3, pid, cpusetsize, cpuset);
+}
+versioned_symbol (libc, __sched_setaffinity_new, sched_setaffinity,
+ GLIBC_2_3_4);
+
+
+# if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
+int
+attribute_compat_text_section
+__sched_setaffinity_old (pid_t pid, const cpu_set_t *cpuset)
+{
+ /* The old interface by default assumed a 1024 processor bitmap. */
+ return __sched_setaffinity_new (pid, 128, cpuset);
+}
+compat_symbol (libc, __sched_setaffinity_old, sched_setaffinity, GLIBC_2_3_3);
+# endif
+#else
+# include <posix/sched_setaffinity.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/scsi/scsi.h b/libc/sysdeps/unix/sysv/linux/scsi/scsi.h
new file mode 100644
index 000000000..49ab75806
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/scsi/scsi.h
@@ -0,0 +1,226 @@
+/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/*
+ * This header file contains public constants and structures used by
+ * the scsi code for linux.
+ */
+
+#ifndef _SCSI_SCSI_H
+#define _SCSI_SCSI_H 1
+
+#include <features.h>
+
+/*
+ * SCSI opcodes
+ */
+
+#define TEST_UNIT_READY 0x00
+#define REZERO_UNIT 0x01
+#define REQUEST_SENSE 0x03
+#define FORMAT_UNIT 0x04
+#define READ_BLOCK_LIMITS 0x05
+#define REASSIGN_BLOCKS 0x07
+#define READ_6 0x08
+#define WRITE_6 0x0a
+#define SEEK_6 0x0b
+#define READ_REVERSE 0x0f
+#define WRITE_FILEMARKS 0x10
+#define SPACE 0x11
+#define INQUIRY 0x12
+#define RECOVER_BUFFERED_DATA 0x14
+#define MODE_SELECT 0x15
+#define RESERVE 0x16
+#define RELEASE 0x17
+#define COPY 0x18
+#define ERASE 0x19
+#define MODE_SENSE 0x1a
+#define START_STOP 0x1b
+#define RECEIVE_DIAGNOSTIC 0x1c
+#define SEND_DIAGNOSTIC 0x1d
+#define ALLOW_MEDIUM_REMOVAL 0x1e
+
+#define SET_WINDOW 0x24
+#define READ_CAPACITY 0x25
+#define READ_10 0x28
+#define WRITE_10 0x2a
+#define SEEK_10 0x2b
+#define WRITE_VERIFY 0x2e
+#define VERIFY 0x2f
+#define SEARCH_HIGH 0x30
+#define SEARCH_EQUAL 0x31
+#define SEARCH_LOW 0x32
+#define SET_LIMITS 0x33
+#define PRE_FETCH 0x34
+#define READ_POSITION 0x34
+#define SYNCHRONIZE_CACHE 0x35
+#define LOCK_UNLOCK_CACHE 0x36
+#define READ_DEFECT_DATA 0x37
+#define MEDIUM_SCAN 0x38
+#define COMPARE 0x39
+#define COPY_VERIFY 0x3a
+#define WRITE_BUFFER 0x3b
+#define READ_BUFFER 0x3c
+#define UPDATE_BLOCK 0x3d
+#define READ_LONG 0x3e
+#define WRITE_LONG 0x3f
+#define CHANGE_DEFINITION 0x40
+#define WRITE_SAME 0x41
+#define READ_TOC 0x43
+#define LOG_SELECT 0x4c
+#define LOG_SENSE 0x4d
+#define MODE_SELECT_10 0x55
+#define RESERVE_10 0x56
+#define RELEASE_10 0x57
+#define MODE_SENSE_10 0x5a
+#define PERSISTENT_RESERVE_IN 0x5e
+#define PERSISTENT_RESERVE_OUT 0x5f
+#define MOVE_MEDIUM 0xa5
+#define READ_12 0xa8
+#define WRITE_12 0xaa
+#define WRITE_VERIFY_12 0xae
+#define SEARCH_HIGH_12 0xb0
+#define SEARCH_EQUAL_12 0xb1
+#define SEARCH_LOW_12 0xb2
+#define READ_ELEMENT_STATUS 0xb8
+#define SEND_VOLUME_TAG 0xb6
+#define WRITE_LONG_2 0xea
+
+/*
+ * Status codes
+ */
+
+#define GOOD 0x00
+#define CHECK_CONDITION 0x01
+#define CONDITION_GOOD 0x02
+#define BUSY 0x04
+#define INTERMEDIATE_GOOD 0x08
+#define INTERMEDIATE_C_GOOD 0x0a
+#define RESERVATION_CONFLICT 0x0c
+#define COMMAND_TERMINATED 0x11
+#define QUEUE_FULL 0x14
+
+#define STATUS_MASK 0x3e
+
+/*
+ * SENSE KEYS
+ */
+
+#define NO_SENSE 0x00
+#define RECOVERED_ERROR 0x01
+#define NOT_READY 0x02
+#define MEDIUM_ERROR 0x03
+#define HARDWARE_ERROR 0x04
+#define ILLEGAL_REQUEST 0x05
+#define UNIT_ATTENTION 0x06
+#define DATA_PROTECT 0x07
+#define BLANK_CHECK 0x08
+#define COPY_ABORTED 0x0a
+#define ABORTED_COMMAND 0x0b
+#define VOLUME_OVERFLOW 0x0d
+#define MISCOMPARE 0x0e
+
+
+/*
+ * DEVICE TYPES
+ */
+
+#define TYPE_DISK 0x00
+#define TYPE_TAPE 0x01
+#define TYPE_PROCESSOR 0x03 /* HP scanners use this */
+#define TYPE_WORM 0x04 /* Treated as ROM by our system */
+#define TYPE_ROM 0x05
+#define TYPE_SCANNER 0x06
+#define TYPE_MOD 0x07 /* Magneto-optical disk -
+ * - treated as TYPE_DISK */
+#define TYPE_MEDIUM_CHANGER 0x08
+#define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
+#define TYPE_NO_LUN 0x7f
+
+/*
+ * standard mode-select header prepended to all mode-select commands
+ *
+ * moved here from cdrom.h -- kraxel
+ */
+
+struct ccs_modesel_head
+ {
+ unsigned char _r1; /* reserved. */
+ unsigned char medium; /* device-specific medium type. */
+ unsigned char _r2; /* reserved. */
+ unsigned char block_desc_length; /* block descriptor length. */
+ unsigned char density; /* device-specific density code. */
+ unsigned char number_blocks_hi; /* number of blocks in this block
+ desc. */
+ unsigned char number_blocks_med;
+ unsigned char number_blocks_lo;
+ unsigned char _r3;
+ unsigned char block_length_hi; /* block length for blocks in this
+ desc. */
+ unsigned char block_length_med;
+ unsigned char block_length_lo;
+ };
+
+/*
+ * MESSAGE CODES
+ */
+
+#define COMMAND_COMPLETE 0x00
+#define EXTENDED_MESSAGE 0x01
+#define EXTENDED_MODIFY_DATA_POINTER 0x00
+#define EXTENDED_SDTR 0x01
+#define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */
+#define EXTENDED_WDTR 0x03
+#define SAVE_POINTERS 0x02
+#define RESTORE_POINTERS 0x03
+#define DISCONNECT 0x04
+#define INITIATOR_ERROR 0x05
+#define ABORT 0x06
+#define MESSAGE_REJECT 0x07
+#define NOP 0x08
+#define MSG_PARITY_ERROR 0x09
+#define LINKED_CMD_COMPLETE 0x0a
+#define LINKED_FLG_CMD_COMPLETE 0x0b
+#define BUS_DEVICE_RESET 0x0c
+
+#define INITIATE_RECOVERY 0x0f /* SCSI-II only */
+#define RELEASE_RECOVERY 0x10 /* SCSI-II only */
+
+#define SIMPLE_QUEUE_TAG 0x20
+#define HEAD_OF_QUEUE_TAG 0x21
+#define ORDERED_QUEUE_TAG 0x22
+
+/*
+ * Here are some scsi specific ioctl commands which are sometimes useful.
+ */
+/* These are a few other constants only used by scsi devices. */
+
+#define SCSI_IOCTL_GET_IDLUN 0x5382
+
+/* Used to turn on and off tagged queuing for scsi devices. */
+
+#define SCSI_IOCTL_TAGGED_ENABLE 0x5383
+#define SCSI_IOCTL_TAGGED_DISABLE 0x5384
+
+/* Used to obtain the host number of a device. */
+#define SCSI_IOCTL_PROBE_HOST 0x5385
+
+/* Used to get the bus number for a device. */
+#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
+
+#endif /* scsi/scsi.h */
diff --git a/libc/sysdeps/unix/sysv/linux/scsi/scsi_ioctl.h b/libc/sysdeps/unix/sysv/linux/scsi/scsi_ioctl.h
new file mode 100644
index 000000000..11f016179
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/scsi/scsi_ioctl.h
@@ -0,0 +1,34 @@
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SCSI_IOCTL_H
+#define _SCSI_IOCTL_H
+
+/* IOCTLs for SCSI. */
+#define SCSI_IOCTL_SEND_COMMAND 1 /* Send a command to the SCSI host. */
+#define SCSI_IOCTL_TEST_UNIT_READY 2 /* Test if unit is ready. */
+#define SCSI_IOCTL_BENCHMARK_COMMAND 3
+#define SCSI_IOCTL_SYNC 4 /* Request synchronous parameters. */
+#define SCSI_IOCTL_START_UNIT 5
+#define SCSI_IOCTL_STOP_UNIT 6
+#define SCSI_IOCTL_DOORLOCK 0x5380 /* Lock the eject mechanism. */
+#define SCSI_IOCTL_DOORUNLOCK 0x5381 /* Unlock the mechanism. */
+
+#endif
+
+
diff --git a/libc/sysdeps/unix/sysv/linux/scsi/sg.h b/libc/sysdeps/unix/sysv/linux/scsi/sg.h
new file mode 100644
index 000000000..b0dc0ad7d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/scsi/sg.h
@@ -0,0 +1,275 @@
+/* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/*
+ History:
+ Started: Aug 9 by Lawrence Foard (entropy@world.std.com), to allow user
+ process control of SCSI devices.
+ Development Sponsored by Killy Corp. NY NY
+*/
+
+#ifndef _SCSI_SG_H
+#define _SCSI_SG_H 1
+
+#include <features.h>
+
+
+/* New interface introduced in the 3.x SG drivers follows */
+
+/* Same structure as used by readv() Linux system call. It defines one
+ scatter-gather element. */
+typedef struct sg_iovec
+{
+ void * iov_base; /* Starting address */
+ size_t iov_len; /* Length in bytes */
+} sg_iovec_t;
+
+
+typedef struct sg_io_hdr
+{
+ int interface_id; /* [i] 'S' for SCSI generic (required) */
+ int dxfer_direction; /* [i] data transfer direction */
+ unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
+ unsigned char mx_sb_len; /* [i] max length to write to sbp */
+ unsigned short int iovec_count; /* [i] 0 implies no scatter gather */
+ unsigned int dxfer_len; /* [i] byte count of data transfer */
+ void * dxferp; /* [i], [*io] points to data transfer memory
+ or scatter gather list */
+ unsigned char * cmdp; /* [i], [*i] points to command to perform */
+ unsigned char * sbp; /* [i], [*o] points to sense_buffer memory */
+ unsigned int timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
+ unsigned int flags; /* [i] 0 -> default, see SG_FLAG... */
+ int pack_id; /* [i->o] unused internally (normally) */
+ void * usr_ptr; /* [i->o] unused internally */
+ unsigned char status; /* [o] scsi status */
+ unsigned char masked_status;/* [o] shifted, masked scsi status */
+ unsigned char msg_status; /* [o] messaging level data (optional) */
+ unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
+ unsigned short int host_status; /* [o] errors from host adapter */
+ unsigned short int driver_status;/* [o] errors from software driver */
+ int resid; /* [o] dxfer_len - actual_transferred */
+ unsigned int duration; /* [o] time taken by cmd (unit: millisec) */
+ unsigned int info; /* [o] auxiliary information */
+} sg_io_hdr_t;
+
+
+/* Use negative values to flag difference from original sg_header structure. */
+#define SG_DXFER_NONE -1 /* e.g. a SCSI Test Unit Ready command */
+#define SG_DXFER_TO_DEV -2 /* e.g. a SCSI WRITE command */
+#define SG_DXFER_FROM_DEV -3 /* e.g. a SCSI READ command */
+#define SG_DXFER_TO_FROM_DEV -4 /* treated like SG_DXFER_FROM_DEV with the
+ additional property than during indirect
+ IO the user buffer is copied into the
+ kernel buffers before the transfer */
+
+
+/* following flag values can be "or"-ed together */
+#define SG_FLAG_DIRECT_IO 1 /* default is indirect IO */
+#define SG_FLAG_LUN_INHIBIT 2 /* default is to put device's lun into */
+ /* the 2nd byte of SCSI command */
+#define SG_FLAG_NO_DXFER 0x10000 /* no transfer of kernel buffers to/from */
+ /* user space (debug indirect IO) */
+
+/* The following 'info' values are "or"-ed together. */
+#define SG_INFO_OK_MASK 0x1
+#define SG_INFO_OK 0x0 /* no sense, host nor driver "noise" */
+#define SG_INFO_CHECK 0x1 /* something abnormal happened */
+
+#define SG_INFO_DIRECT_IO_MASK 0x6
+#define SG_INFO_INDIRECT_IO 0x0 /* data xfer via kernel buffers (or no xfer) */
+#define SG_INFO_DIRECT_IO 0x2 /* direct IO requested and performed */
+#define SG_INFO_MIXED_IO 0x4 /* part direct, part indirect IO */
+
+
+/* Request information about a specific SG device, used by
+ SG_GET_SCSI_ID ioctl (). */
+struct sg_scsi_id {
+ /* Host number as in "scsi<n>" where 'n' is one of 0, 1, 2 etc. */
+ int host_no;
+ int channel;
+ /* SCSI id of target device. */
+ int scsi_id;
+ int lun;
+ /* TYPE_... defined in <scsi/scsi.h>. */
+ int scsi_type;
+ /* Host (adapter) maximum commands per lun. */
+ short int h_cmd_per_lun;
+ /* Device (or adapter) maximum queue length. */
+ short int d_queue_depth;
+ /* Unused, set to 0 for now. */
+ int unused[2];
+};
+
+/* Used by SG_GET_REQUEST_TABLE ioctl(). */
+typedef struct sg_req_info {
+ char req_state; /* 0 -> not used, 1 -> written, 2 -> ready to read */
+ char orphan; /* 0 -> normal request, 1 -> from interruped SG_IO */
+ char sg_io_owned; /* 0 -> complete with read(), 1 -> owned by SG_IO */
+ char problem; /* 0 -> no problem detected, 1 -> error to report */
+ int pack_id; /* pack_id associated with request */
+ void * usr_ptr; /* user provided pointer (in new interface) */
+ unsigned int duration; /* millisecs elapsed since written (req_state==1)
+ or request duration (req_state==2) */
+ int unused;
+} sg_req_info_t;
+
+
+/* IOCTLs: Those ioctls that are relevant to the SG 3.x drivers follow.
+ [Those that only apply to the SG 2.x drivers are at the end of the file.]
+ (_GET_s yield result via 'int *' 3rd argument unless otherwise indicated) */
+
+#define SG_EMULATED_HOST 0x2203 /* true for emulated host adapter (ATAPI) */
+
+/* Used to configure SCSI command transformation layer for ATAPI devices */
+/* Only supported by the ide-scsi driver */
+#define SG_SET_TRANSFORM 0x2204 /* N.B. 3rd arg is not pointer but value: */
+ /* 3rd arg = 0 to disable transform, 1 to enable it */
+#define SG_GET_TRANSFORM 0x2205
+
+#define SG_SET_RESERVED_SIZE 0x2275 /* request a new reserved buffer size */
+#define SG_GET_RESERVED_SIZE 0x2272 /* actual size of reserved buffer */
+
+/* The following ioctl has a 'sg_scsi_id_t *' object as its 3rd argument. */
+#define SG_GET_SCSI_ID 0x2276 /* Yields fd's bus, chan, dev, lun + type */
+/* SCSI id information can also be obtained from SCSI_IOCTL_GET_IDLUN */
+
+/* Override host setting and always DMA using low memory ( <16MB on i386) */
+#define SG_SET_FORCE_LOW_DMA 0x2279 /* 0-> use adapter setting, 1-> force */
+#define SG_GET_LOW_DMA 0x227a /* 0-> use all ram for dma; 1-> low dma ram */
+
+/* When SG_SET_FORCE_PACK_ID set to 1, pack_id is input to read() which
+ tries to fetch a packet with a matching pack_id, waits, or returns EAGAIN.
+ If pack_id is -1 then read oldest waiting. When ...FORCE_PACK_ID set to 0
+ then pack_id ignored by read() and oldest readable fetched. */
+#define SG_SET_FORCE_PACK_ID 0x227b
+#define SG_GET_PACK_ID 0x227c /* Yields oldest readable pack_id (or -1) */
+
+#define SG_GET_NUM_WAITING 0x227d /* Number of commands awaiting read() */
+
+/* Yields max scatter gather tablesize allowed by current host adapter */
+#define SG_GET_SG_TABLESIZE 0x227F /* 0 implies can't do scatter gather */
+
+#define SG_GET_VERSION_NUM 0x2282 /* Example: version 2.1.34 yields 20134 */
+
+/* Returns -EBUSY if occupied. 3rd argument pointer to int (see next) */
+#define SG_SCSI_RESET 0x2284
+/* Associated values that can be given to SG_SCSI_RESET follow */
+#define SG_SCSI_RESET_NOTHING 0
+#define SG_SCSI_RESET_DEVICE 1
+#define SG_SCSI_RESET_BUS 2
+#define SG_SCSI_RESET_HOST 3
+
+/* synchronous SCSI command ioctl, (only in version 3 interface) */
+#define SG_IO 0x2285 /* similar effect as write() followed by read() */
+
+#define SG_GET_REQUEST_TABLE 0x2286 /* yields table of active requests */
+
+/* How to treat EINTR during SG_IO ioctl(), only in SG 3.x series */
+#define SG_SET_KEEP_ORPHAN 0x2287 /* 1 -> hold for read(), 0 -> drop (def) */
+#define SG_GET_KEEP_ORPHAN 0x2288
+
+
+#define SG_SCATTER_SZ (8 * 4096) /* PAGE_SIZE not available to user */
+/* Largest size (in bytes) a single scatter-gather list element can have.
+ The value must be a power of 2 and <= (PAGE_SIZE * 32) [131072 bytes on
+ i386]. The minimum value is PAGE_SIZE. If scatter-gather not supported
+ by adapter then this value is the largest data block that can be
+ read/written by a single scsi command. The user can find the value of
+ PAGE_SIZE by calling getpagesize() defined in unistd.h . */
+
+#define SG_DEFAULT_RETRIES 1
+
+/* Defaults, commented if they differ from original sg driver */
+#define SG_DEF_FORCE_LOW_DMA 0 /* was 1 -> memory below 16MB on i386 */
+#define SG_DEF_FORCE_PACK_ID 0
+#define SG_DEF_KEEP_ORPHAN 0
+#define SG_DEF_RESERVED_SIZE SG_SCATTER_SZ /* load time option */
+
+/* maximum outstanding requests, write() yields EDOM if exceeded */
+#define SG_MAX_QUEUE 16
+
+#define SG_BIG_BUFF SG_DEF_RESERVED_SIZE /* for backward compatibility */
+
+/* Alternate style type names, "..._t" variants preferred */
+typedef struct sg_io_hdr Sg_io_hdr;
+typedef struct sg_io_vec Sg_io_vec;
+typedef struct sg_scsi_id Sg_scsi_id;
+typedef struct sg_req_info Sg_req_info;
+
+
+/* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
+/* The older SG interface based on the 'sg_header' structure follows. */
+/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
+
+#define SG_MAX_SENSE 16 /* this only applies to the sg_header interface */
+
+struct sg_header
+ {
+ /* Length of incoming packet (including header). */
+ int pack_len;
+ /* Maximal length of expected reply. */
+ int reply_len;
+ /* Id number of packet. */
+ int pack_id;
+ /* 0==ok, otherwise error number. */
+ int result;
+ /* Force 12 byte command length for group 6 & 7 commands. */
+ unsigned int twelve_byte:1;
+ /* SCSI status from target. */
+ unsigned int target_status:5;
+ /* Host status (see "DID" codes). */
+ unsigned int host_status:8;
+ /* Driver status+suggestion. */
+ unsigned int driver_status:8;
+ /* Unused. */
+ unsigned int other_flags:10;
+ /* Output in 3 cases:
+ when target_status is CHECK_CONDITION or
+ when target_status is COMMAND_TERMINATED or
+ when (driver_status & DRIVER_SENSE) is true. */
+ unsigned char sense_buffer[SG_MAX_SENSE];
+ };
+
+
+/* IOCTLs: The following are not required (or ignored) when the sg_io_hdr_t
+ interface is used. They are kept for backward compatibility with
+ the original and version 2 drivers. */
+
+#define SG_SET_TIMEOUT 0x2201 /* Set timeout; *(int *)arg==timeout. */
+#define SG_GET_TIMEOUT 0x2202 /* Get timeout; return timeout. */
+
+/* Get/set command queuing state per fd (default is SG_DEF_COMMAND_Q). */
+#define SG_GET_COMMAND_Q 0x2270 /* Yields 0 (queuing off) or 1 (on). */
+#define SG_SET_COMMAND_Q 0x2271 /* Change queuing state with 0 or 1. */
+
+/* Turn on error sense trace (1..8), dump this device to log/console (9)
+ or dump all sg device states ( >9 ) to log/console. */
+#define SG_SET_DEBUG 0x227e /* 0 -> turn off debug */
+
+#define SG_NEXT_CMD_LEN 0x2283 /* Override SCSI command length with given
+ number on the next write() on this file
+ descriptor. */
+
+/* Defaults, commented if they differ from original sg driver */
+#define SG_DEFAULT_TIMEOUT (60*HZ) /* HZ == 'jiffies in 1 second' */
+#define SG_DEF_COMMAND_Q 0 /* command queuing is always on when
+ the new interface is used */
+#define SG_DEF_UNDERRUN_FLAG 0
+
+
+#endif /* scsi/sg.h */
diff --git a/libc/sysdeps/unix/sysv/linux/segfault.c b/libc/sysdeps/unix/sysv/linux/segfault.c
new file mode 100644
index 000000000..a417df9c4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/segfault.c
@@ -0,0 +1,2 @@
+#define HAVE_PROC_SELF 1
+#include <debug/segfault.c>
diff --git a/libc/sysdeps/unix/sysv/linux/semctl.c b/libc/sysdeps/unix/sysv/linux/semctl.c
new file mode 100644
index 000000000..2f5471f8f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/semctl.c
@@ -0,0 +1,192 @@
+/* Copyright (C) 1995,1997,1998,2000,2003,2004,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <sys/sem.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <string.h>
+#include <sys/syscall.h>
+#include <shlib-compat.h>
+
+#include <kernel-features.h>
+
+struct __old_semid_ds
+{
+ struct __old_ipc_perm sem_perm; /* operation permission struct */
+ __time_t sem_otime; /* last semop() time */
+ __time_t sem_ctime; /* last time changed by semctl() */
+ struct sem *__unbounded __sembase; /* ptr to first semaphore in array */
+ struct sem_queue *__unbounded __sem_pending; /* pending operations */
+ struct sem_queue *__unbounded __sem_pending_last; /* last pending operation */
+ struct sem_undo *__unbounded __undo; /* ondo requests on this array */
+ unsigned short int sem_nsems; /* number of semaphores in set */
+};
+
+/* Define a `union semun' suitable for Linux here. */
+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 */
+ struct __old_semid_ds *__old_buf;
+};
+
+#include <bp-checks.h>
+#include <bp-semctl.h> /* definition of CHECK_SEMCTL needs union semum */
+
+/* Return identifier for array of NSEMS semaphores associated with
+ KEY. */
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int __old_semctl (int semid, int semnum, int cmd, ...);
+#endif
+int __new_semctl (int semid, int semnum, int cmd, ...);
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int
+attribute_compat_text_section
+__old_semctl (int semid, int semnum, int cmd, ...)
+{
+ union semun arg;
+ va_list ap;
+
+ va_start (ap, cmd);
+
+ /* Get the argument only if required. */
+ arg.buf = NULL;
+ switch (cmd)
+ {
+ case SETVAL: /* arg.val */
+ case GETALL: /* arg.array */
+ case SETALL:
+ case IPC_STAT: /* arg.buf */
+ case IPC_SET:
+ case SEM_STAT:
+ case IPC_INFO: /* arg.__buf */
+ case SEM_INFO:
+ va_start (ap, cmd);
+ arg = va_arg (ap, union semun);
+ va_end (ap);
+ break;
+ }
+
+ va_end (ap);
+
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd));
+}
+compat_symbol (libc, __old_semctl, semctl, GLIBC_2_0);
+#endif
+
+int
+__new_semctl (int semid, int semnum, int cmd, ...)
+{
+ union semun arg;
+ va_list ap;
+
+ va_start (ap, cmd);
+
+ /* Get the argument only if required. */
+ arg.buf = NULL;
+ switch (cmd)
+ {
+ case SETVAL: /* arg.val */
+ case GETALL: /* arg.array */
+ case SETALL:
+ case IPC_STAT: /* arg.buf */
+ case IPC_SET:
+ case SEM_STAT:
+ case IPC_INFO: /* arg.__buf */
+ case SEM_INFO:
+ va_start (ap, cmd);
+ arg = va_arg (ap, union semun);
+ va_end (ap);
+ break;
+ }
+
+ va_end (ap);
+
+#if __ASSUME_IPC64 > 0
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd | __IPC_64,
+ CHECK_SEMCTL (&arg, semid, cmd | __IPC_64));
+#else
+ switch (cmd)
+ {
+ case SEM_STAT:
+ case IPC_STAT:
+ case IPC_SET:
+ break;
+ default:
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd));
+ }
+
+ {
+ int save_errno = errno, result;
+ struct __old_semid_ds old;
+ struct semid_ds *buf;
+
+ /* Unfortunately there is no way how to find out for sure whether
+ we should use old or new semctl. */
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd | __IPC_64,
+ CHECK_SEMCTL (&arg, semid, cmd | __IPC_64));
+ if (result != -1 || errno != EINVAL)
+ return result;
+
+ __set_errno(save_errno);
+ buf = arg.buf;
+ arg.__old_buf = &old;
+ if (cmd == IPC_SET)
+ {
+ old.sem_perm.uid = buf->sem_perm.uid;
+ old.sem_perm.gid = buf->sem_perm.gid;
+ old.sem_perm.mode = buf->sem_perm.mode;
+ if (old.sem_perm.uid != buf->sem_perm.uid ||
+ old.sem_perm.gid != buf->sem_perm.gid)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd));
+ if (result != -1 && cmd != IPC_SET)
+ {
+ memset(buf, 0, sizeof(*buf));
+ buf->sem_perm.__key = old.sem_perm.__key;
+ buf->sem_perm.uid = old.sem_perm.uid;
+ buf->sem_perm.gid = old.sem_perm.gid;
+ buf->sem_perm.cuid = old.sem_perm.cuid;
+ buf->sem_perm.cgid = old.sem_perm.cgid;
+ buf->sem_perm.mode = old.sem_perm.mode;
+ buf->sem_perm.__seq = old.sem_perm.__seq;
+ buf->sem_otime = old.sem_otime;
+ buf->sem_ctime = old.sem_ctime;
+ buf->sem_nsems = old.sem_nsems;
+ }
+ return result;
+ }
+#endif
+}
+
+versioned_symbol (libc, __new_semctl, semctl, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/semget.c b/libc/sysdeps/unix/sysv/linux/semget.c
new file mode 100644
index 000000000..639bb0229
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/semget.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 1995, 1997, 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/sem.h>
+#include <ipc_priv.h>
+#include <stdlib.h> /* for definition of NULL */
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Return identifier for array of NSEMS semaphores associated with
+ KEY. */
+
+int
+semget (key, nsems, semflg)
+ key_t key;
+ int nsems;
+ int semflg;
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semget, key, nsems, semflg, NULL);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/semop.c b/libc/sysdeps/unix/sysv/linux/semop.c
new file mode 100644
index 000000000..4bf297661
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/semop.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 1995, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/sem.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Perform user-defined atomical operation of array of semaphores. */
+
+int
+semop (semid, sops, nsops)
+ int semid;
+ struct sembuf *sops;
+ size_t nsops;
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semop,
+ semid, (int) nsops, 0, CHECK_N (sops, nsops));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/semtimedop.c b/libc/sysdeps/unix/sysv/linux/semtimedop.c
new file mode 100644
index 000000000..b37284181
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/semtimedop.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 1995, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/sem.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Perform user-defined atomical operation of array of semaphores. */
+
+int
+semtimedop (semid, sops, nsops, timeout)
+ int semid;
+ struct sembuf *sops;
+ size_t nsops;
+ const struct timespec *timeout;
+{
+ return INLINE_SYSCALL (ipc, 6, IPCOP_semtimedop,
+ semid, (int) nsops, 0, CHECK_N (sops, nsops),
+ timeout);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/send.S b/libc/sysdeps/unix/sysv/linux/send.S
new file mode 100644
index 000000000..259748f44
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/send.S
@@ -0,0 +1,7 @@
+#define socket send
+#define __socket __libc_send
+#define NARGS 4
+#define NEED_CANCELLATION
+#include <socket.S>
+weak_alias (__libc_send, __send)
+libc_hidden_def (__send)
diff --git a/libc/sysdeps/unix/sysv/linux/sendmsg.S b/libc/sysdeps/unix/sysv/linux/sendmsg.S
new file mode 100644
index 000000000..a220894cc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sendmsg.S
@@ -0,0 +1,6 @@
+#define socket sendmsg
+#define __socket __libc_sendmsg
+#define NARGS 3
+#define NEED_CANCELLATION
+#include <socket.S>
+weak_alias (__libc_sendmsg, __sendmsg)
diff --git a/libc/sysdeps/unix/sysv/linux/sendto.S b/libc/sysdeps/unix/sysv/linux/sendto.S
new file mode 100644
index 000000000..a65e44fb6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sendto.S
@@ -0,0 +1,6 @@
+#define socket sendto
+#define __socket __libc_sendto
+#define NARGS 6
+#define NEED_CANCELLATION
+#include <socket.S>
+weak_alias (__libc_sendto, __sendto)
diff --git a/libc/sysdeps/unix/sysv/linux/setegid.c b/libc/sysdeps/unix/sysv/linux/setegid.c
new file mode 100644
index 000000000..c0400aa12
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/setegid.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 1998,2000,2002,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+#include <kernel-features.h>
+
+
+#if defined __NR_setresgid || __ASSUME_SETRESGID_SYSCALL > 0
+
+extern int __setresgid (gid_t rgid, gid_t egid, gid_t sgid);
+
+int
+setegid (gid_t gid)
+{
+ int result;
+
+ if (gid == (gid_t) ~0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+# if __ASSUME_32BITUIDS > 0 && defined __NR_setresgid32
+ result = INLINE_SETXID_SYSCALL (setresgid32, 3, -1, gid, -1);
+# else
+ /* First try the syscall. */
+ result = INLINE_SETXID_SYSCALL (setresgid, 3, -1, gid, -1);
+# if __ASSUME_SETRESGID_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use emulation. This may not work
+ since `setregid' also sets the saved group ID when GID is not
+ equal to the real group ID, making it impossible to switch back. */
+ result = __setregid (-1, gid);
+# endif
+# endif
+
+ return result;
+}
+#ifndef setegid
+libc_hidden_def (setegid)
+#endif
+#else
+# include <sysdeps/unix/bsd/setegid.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/seteuid.c b/libc/sysdeps/unix/sysv/linux/seteuid.c
new file mode 100644
index 000000000..4a1a29eaa
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/seteuid.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 1998,1999,2002,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+#include <kernel-features.h>
+
+
+#if defined __NR_setresuid || __ASSUME_SETRESUID_SYSCALL > 0
+
+extern int __setresuid (uid_t ruid, uid_t euid, uid_t suid);
+
+int
+seteuid (uid_t uid)
+{
+ int result;
+
+ if (uid == (uid_t) ~0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+# if __ASSUME_32BITUIDS > 0 && defined __NR_setresuid32
+ result = INLINE_SETXID_SYSCALL (setresuid32, 3, -1, uid, -1);
+# else
+ /* First try the syscall. */
+ result = INLINE_SETXID_SYSCALL (setresuid, 3, -1, uid, -1);
+# if __ASSUME_SETRESUID_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use emulation. This may not work
+ since `setreuid' also sets the saved user ID when UID is not
+ equal to the real user ID, making it impossible to switch back. */
+ result = __setreuid (-1, uid);
+# endif
+# endif
+
+ return result;
+}
+#ifndef seteuid
+libc_hidden_def (seteuid)
+#endif
+#else
+# include <sysdeps/unix/bsd/seteuid.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/setgid.c b/libc/sysdeps/unix/sysv/linux/setgid.c
new file mode 100644
index 000000000..1411f5365
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/setgid.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+
+
+int
+__setgid (gid_t gid)
+{
+ return INLINE_SETXID_SYSCALL (setgid, 1, gid);
+}
+#ifndef __setgid
+weak_alias (__setgid, setgid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sethostid.c b/libc/sysdeps/unix/sysv/linux/sethostid.c
new file mode 100644
index 000000000..eb71b74a1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sethostid.c
@@ -0,0 +1,2 @@
+#define SET_PROCEDURE 1
+#include "gethostid.c"
diff --git a/libc/sysdeps/unix/sysv/linux/setipv4sourcefilter.c b/libc/sysdeps/unix/sysv/linux/setipv4sourcefilter.c
new file mode 100644
index 000000000..050d0a3e9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/setipv4sourcefilter.c
@@ -0,0 +1,65 @@
+/* Set IPv4 source filter. Linux version.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <alloca.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+
+
+int
+setipv4sourcefilter (int s, struct in_addr interface, struct in_addr group,
+ uint32_t fmode, uint32_t numsrc,
+ const struct in_addr *slist)
+{
+ /* We have to create an struct ip_msfilter object which we can pass
+ to the kernel. */
+ size_t needed = IP_MSFILTER_SIZE (numsrc);
+ int use_alloca = __libc_use_alloca (needed);
+
+ struct ip_msfilter *imsf;
+ if (use_alloca)
+ imsf = (struct ip_msfilter *) alloca (needed);
+ else
+ {
+ imsf = (struct ip_msfilter *) malloc (needed);
+ if (imsf == NULL)
+ return -1;
+ }
+
+ imsf->imsf_multiaddr = group;
+ imsf->imsf_interface = interface;
+ imsf->imsf_fmode = fmode;
+ imsf->imsf_numsrc = numsrc;
+ memcpy (imsf->imsf_slist, slist, numsrc * sizeof (struct in_addr));
+
+ int result = __setsockopt (s, SOL_IP, IP_MSFILTER, imsf, needed);
+
+ if (! use_alloca)
+ {
+ int save_errno = errno;
+ free (imsf);
+ __set_errno (save_errno);
+ }
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/setregid.c b/libc/sysdeps/unix/sysv/linux/setregid.c
new file mode 100644
index 000000000..df79eae91
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/setregid.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+
+
+int
+__setregid (gid_t rgid, gid_t egid)
+{
+ return INLINE_SETXID_SYSCALL (setregid, 2, rgid, egid);
+}
+#ifndef __setregid
+weak_alias (__setregid, setregid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/setresgid.c b/libc/sysdeps/unix/sysv/linux/setresgid.c
new file mode 100644
index 000000000..d6c9758d7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/setresgid.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+
+
+int
+__setresgid (gid_t rgid, gid_t egid, gid_t sgid)
+{
+ return INLINE_SETXID_SYSCALL (setresgid, 3, rgid, egid, sgid);
+}
+libc_hidden_def (__setresgid)
+#ifndef __setresgid
+weak_alias (__setresgid, setresgid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/setresuid.c b/libc/sysdeps/unix/sysv/linux/setresuid.c
new file mode 100644
index 000000000..e7feeefce
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/setresuid.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+
+
+int
+__setresuid (uid_t ruid, uid_t euid, uid_t suid)
+{
+ return INLINE_SETXID_SYSCALL (setresuid, 3, ruid, euid, suid);
+}
+libc_hidden_def (__setresuid)
+#ifndef __setresuid
+weak_alias (__setresuid, setresuid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/setreuid.c b/libc/sysdeps/unix/sysv/linux/setreuid.c
new file mode 100644
index 000000000..ce30d3c69
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/setreuid.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+
+
+int
+__setreuid (uid_t ruid, uid_t euid)
+{
+ return INLINE_SETXID_SYSCALL (setreuid, 2, ruid, euid);
+}
+#ifndef __setreuid
+weak_alias (__setreuid, setreuid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/setsockopt.S b/libc/sysdeps/unix/sysv/linux/setsockopt.S
new file mode 100644
index 000000000..4e40ccba5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/setsockopt.S
@@ -0,0 +1,5 @@
+#define socket setsockopt
+#define NARGS 5
+#define NO_WEAK_ALIAS 1
+#include <socket.S>
+weak_alias (setsockopt, __setsockopt)
diff --git a/libc/sysdeps/unix/sysv/linux/setsourcefilter.c b/libc/sysdeps/unix/sysv/linux/setsourcefilter.c
new file mode 100644
index 000000000..dc223de84
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/setsourcefilter.c
@@ -0,0 +1,78 @@
+/* Set source filter. Linux version.
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <alloca.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+
+
+/* Defined in getsourcefilter.c. */
+extern int __get_sol (int af, socklen_t len);
+
+
+int
+setsourcefilter (int s, uint32_t interface, const struct sockaddr *group,
+ socklen_t grouplen, uint32_t fmode, uint32_t numsrc,
+ const struct sockaddr_storage *slist)
+{
+ /* We have to create an struct ip_msfilter object which we can pass
+ to the kernel. */
+ size_t needed = GROUP_FILTER_SIZE (numsrc);
+ int use_alloca = __libc_use_alloca (needed);
+
+ struct group_filter *gf;
+ if (use_alloca)
+ gf = (struct group_filter *) alloca (needed);
+ else
+ {
+ gf = (struct group_filter *) malloc (needed);
+ if (gf == NULL)
+ return -1;
+ }
+
+ gf->gf_interface = interface;
+ memcpy (&gf->gf_group, group, grouplen);
+ gf->gf_fmode = fmode;
+ gf->gf_numsrc = numsrc;
+ memcpy (gf->gf_slist, slist, numsrc * sizeof (struct sockaddr_storage));
+
+ /* We need to provide the appropriate socket level value. */
+ int result;
+ int sol = __get_sol (group->sa_family, grouplen);
+ if (sol == -1)
+ {
+ __set_errno (EINVAL);
+ result = -1;
+ }
+ else
+ result = __setsockopt (s, sol, MCAST_MSFILTER, gf, needed);
+
+ if (! use_alloca)
+ {
+ int save_errno = errno;
+ free (gf);
+ __set_errno (save_errno);
+ }
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/setuid.c b/libc/sysdeps/unix/sysv/linux/setuid.c
new file mode 100644
index 000000000..a523dfdbd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/setuid.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <setxid.h>
+
+int
+__setuid (uid_t uid)
+{
+ return INLINE_SETXID_SYSCALL (setuid, 1, uid);
+}
+#ifndef __setuid
+weak_alias (__setuid, setuid)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sh/Makefile b/libc/sysdeps/unix/sysv/linux/sh/Makefile
new file mode 100644
index 000000000..6d72cb029
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/Makefile
@@ -0,0 +1,11 @@
+ifeq ($(subdir),io)
+sysdep_routines += pipe
+endif
+
+ifeq ($(subdir),misc)
+sysdep_headers += sys/io.h
+endif
+
+ifeq ($(subdir),stdlib)
+gen-as-const-headers += ucontext_i.sym
+endif
diff --git a/libc/sysdeps/unix/sysv/linux/sh/Versions b/libc/sysdeps/unix/sysv/linux/sh/Versions
new file mode 100644
index 000000000..763be6022
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/Versions
@@ -0,0 +1,27 @@
+libc {
+ GLIBC_2.2 {
+ # functions used in other libraries
+ __xstat64; __fxstat64; __lxstat64;
+
+ # a*
+ alphasort64;
+
+ # g*
+ glob64;
+
+ # New rlimit interface
+ getrlimit; setrlimit; getrlimit64;
+
+ # r*
+ readdir64; readdir64_r;
+
+ # s*
+ scandir64;
+
+ # v*
+ versionsort64;
+ }
+ GLIBC_2.3.3 {
+ posix_fadvise64; posix_fallocate64;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sh/bits/atomic.h b/libc/sysdeps/unix/sysv/linux/sh/bits/atomic.h
new file mode 100644
index 000000000..a0e5918f0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/bits/atomic.h
@@ -0,0 +1,419 @@
+/* Atomic operations used inside libc. Linux/SH version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdint.h>
+
+
+typedef int8_t atomic8_t;
+typedef uint8_t uatomic8_t;
+typedef int_fast8_t atomic_fast8_t;
+typedef uint_fast8_t uatomic_fast8_t;
+
+typedef int16_t atomic16_t;
+typedef uint16_t uatomic16_t;
+typedef int_fast16_t atomic_fast16_t;
+typedef uint_fast16_t uatomic_fast16_t;
+
+typedef int32_t atomic32_t;
+typedef uint32_t uatomic32_t;
+typedef int_fast32_t atomic_fast32_t;
+typedef uint_fast32_t uatomic_fast32_t;
+
+typedef int64_t atomic64_t;
+typedef uint64_t uatomic64_t;
+typedef int_fast64_t atomic_fast64_t;
+typedef uint_fast64_t uatomic_fast64_t;
+
+typedef intptr_t atomicptr_t;
+typedef uintptr_t uatomicptr_t;
+typedef intmax_t atomic_max_t;
+typedef uintmax_t uatomic_max_t;
+
+/* SH kernel has implemented a gUSA ("g" User Space Atomicity) support
+ for the user space atomicity. The atomicity macros use this scheme.
+
+ Reference:
+ Niibe Yutaka, "gUSA: Simple and Efficient User Space Atomicity
+ Emulation with Little Kernel Modification", Linux Conference 2002,
+ Japan. http://lc.linux.or.jp/lc2002/papers/niibe0919h.pdf (in
+ Japanese).
+
+ B.N. Bershad, D. Redell, and J. Ellis, "Fast Mutual Exclusion for
+ Uniprocessors", Proceedings of the Fifth Architectural Support for
+ Programming Languages and Operating Systems (ASPLOS), pp. 223-233,
+ October 1992. http://www.cs.washington.edu/homes/bershad/Papers/Rcs.ps
+
+ SuperH ABI:
+ r15: -(size of atomic instruction sequence) < 0
+ r0: end point
+ r1: saved stack pointer
+*/
+
+#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
+ ({ __typeof (*(mem)) __result; \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.b @%1,%0\n\
+ cmp/eq %0,%3\n\
+ bf 1f\n\
+ mov.b %2,@%1\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result) : "r" (mem), "r" (newval), "r" (oldval) \
+ : "r0", "r1", "t", "memory"); \
+ __result; })
+
+#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
+ ({ __typeof (*(mem)) __result; \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.w @%1,%0\n\
+ cmp/eq %0,%3\n\
+ bf 1f\n\
+ mov.w %2,@%1\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result) : "r" (mem), "r" (newval), "r" (oldval) \
+ : "r0", "r1", "t", "memory"); \
+ __result; })
+
+#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
+ ({ __typeof (*(mem)) __result; \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.l @%1,%0\n\
+ cmp/eq %0,%3\n\
+ bf 1f\n\
+ mov.l %2,@%1\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result) : "r" (mem), "r" (newval), "r" (oldval) \
+ : "r0", "r1", "t", "memory"); \
+ __result; })
+
+/* XXX We do not really need 64-bit compare-and-exchange. At least
+ not in the moment. Using it would mean causing portability
+ problems since not many other 32-bit architectures have support for
+ such an operation. So don't define any code for now. */
+
+# define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
+ (abort (), (__typeof (*mem)) 0)
+
+#define atomic_exchange_and_add(mem, value) \
+ ({ __typeof (*(mem)) __result, __tmp, __value = (value); \
+ if (sizeof (*(mem)) == 1) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.b @%2,%0\n\
+ add %0,%1\n\
+ mov.b %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result), "=&r" (__tmp) : "r" (mem), "1" (__value) \
+ : "r0", "r1", "memory"); \
+ else if (sizeof (*(mem)) == 2) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.w @%2,%0\n\
+ add %0,%1\n\
+ mov.w %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result), "=&r" (__tmp) : "r" (mem), "1" (__value) \
+ : "r0", "r1", "memory"); \
+ else if (sizeof (*(mem)) == 4) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.l @%2,%0\n\
+ add %0,%1\n\
+ mov.l %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result), "=&r" (__tmp) : "r" (mem), "1" (__value) \
+ : "r0", "r1", "memory"); \
+ else \
+ { \
+ __typeof (mem) memp = (mem); \
+ do \
+ __result = *memp; \
+ while (__arch_compare_and_exchange_val_64_acq \
+ (memp, __result + __value, __result) == __result); \
+ (void) __value; \
+ } \
+ __result; })
+
+#define atomic_add(mem, value) \
+ (void) ({ __typeof (*(mem)) __tmp, __value = (value); \
+ if (sizeof (*(mem)) == 1) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.b @%1,r2\n\
+ add r2,%0\n\
+ mov.b %0,@%1\n\
+ 1: mov r1,r15"\
+ : "=&r" (__tmp) : "r" (mem), "0" (__value) \
+ : "r0", "r1", "r2", "memory"); \
+ else if (sizeof (*(mem)) == 2) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.w @%1,r2\n\
+ add r2,%0\n\
+ mov.w %0,@%1\n\
+ 1: mov r1,r15"\
+ : "=&r" (__tmp) : "r" (mem), "0" (__value) \
+ : "r0", "r1", "r2", "memory"); \
+ else if (sizeof (*(mem)) == 4) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.l @%1,r2\n\
+ add r2,%0\n\
+ mov.l %0,@%1\n\
+ 1: mov r1,r15"\
+ : "=&r" (__tmp) : "r" (mem), "0" (__value) \
+ : "r0", "r1", "r2", "memory"); \
+ else \
+ { \
+ __typeof (*(mem)) oldval; \
+ __typeof (mem) memp = (mem); \
+ do \
+ oldval = *memp; \
+ while (__arch_compare_and_exchange_val_64_acq \
+ (memp, oldval + __value, oldval) == oldval); \
+ (void) __value; \
+ } \
+ })
+
+#define atomic_add_negative(mem, value) \
+ ({ unsigned char __result; \
+ __typeof (*(mem)) __tmp, __value = (value); \
+ if (sizeof (*(mem)) == 1) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.b @%2,r2\n\
+ add r2,%1\n\
+ mov.b %1,@%2\n\
+ 1: mov r1,r15\n\
+ shal %1\n\
+ movt %0"\
+ : "=r" (__result), "=&r" (__tmp) : "r" (mem), "1" (__value) \
+ : "r0", "r1", "r2", "t", "memory"); \
+ else if (sizeof (*(mem)) == 2) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.w @%2,r2\n\
+ add r2,%1\n\
+ mov.w %1,@%2\n\
+ 1: mov r1,r15\n\
+ shal %1\n\
+ movt %0"\
+ : "=r" (__result), "=&r" (__tmp) : "r" (mem), "1" (__value) \
+ : "r0", "r1", "r2", "t", "memory"); \
+ else if (sizeof (*(mem)) == 4) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.l @%2,r2\n\
+ add r2,%1\n\
+ mov.l %1,@%2\n\
+ 1: mov r1,r15\n\
+ shal %1\n\
+ movt %0"\
+ : "=r" (__result), "=&r" (__tmp) : "r" (mem), "1" (__value) \
+ : "r0", "r1", "r2", "t", "memory"); \
+ else \
+ abort (); \
+ __result; })
+
+#define atomic_add_zero(mem, value) \
+ ({ unsigned char __result; \
+ __typeof (*(mem)) __tmp, __value = (value); \
+ if (sizeof (*(mem)) == 1) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.b @%2,r2\n\
+ add r2,%1\n\
+ mov.b %1,@%2\n\
+ 1: mov r1,r15\n\
+ tst %1,%1\n\
+ movt %0"\
+ : "=r" (__result), "=&r" (__tmp) : "r" (mem), "1" (__value) \
+ : "r0", "r1", "r2", "t", "memory"); \
+ else if (sizeof (*(mem)) == 2) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.w @%2,r2\n\
+ add r2,%1\n\
+ mov.w %1,@%2\n\
+ 1: mov r1,r15\n\
+ tst %1,%1\n\
+ movt %0"\
+ : "=r" (__result), "=&r" (__tmp) : "r" (mem), "1" (__value) \
+ : "r0", "r1", "r2", "t", "memory"); \
+ else if (sizeof (*(mem)) == 4) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.l @%2,r2\n\
+ add r2,%1\n\
+ mov.l %1,@%2\n\
+ 1: mov r1,r15\n\
+ tst %1,%1\n\
+ movt %0"\
+ : "=r" (__result), "=&r" (__tmp) : "r" (mem), "1" (__value) \
+ : "r0", "r1", "r2", "t", "memory"); \
+ else \
+ abort (); \
+ __result; })
+
+#define atomic_increment_and_test(mem) atomic_add_zero((mem), 1)
+#define atomic_decrement_and_test(mem) atomic_add_zero((mem), -1)
+
+#define atomic_bit_set(mem, bit) \
+ (void) ({ unsigned int __mask = 1 << (bit); \
+ if (sizeof (*(mem)) == 1) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.b @%0,r2\n\
+ or %1,r2\n\
+ mov.b r2,@%0\n\
+ 1: mov r1,r15"\
+ : : "r" (mem), "r" (__mask) \
+ : "r0", "r1", "r2", "memory"); \
+ else if (sizeof (*(mem)) == 2) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.w @%0,r2\n\
+ or %1,r2\n\
+ mov.w r2,@%0\n\
+ 1: mov r1,r15"\
+ : : "r" (mem), "r" (__mask) \
+ : "r0", "r1", "r2", "memory"); \
+ else if (sizeof (*(mem)) == 4) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.l @%0,r2\n\
+ or %1,r2\n\
+ mov.l r2,@%0\n\
+ 1: mov r1,r15"\
+ : : "r" (mem), "r" (__mask) \
+ : "r0", "r1", "r2", "memory"); \
+ else \
+ abort (); \
+ })
+
+#define atomic_bit_test_set(mem, bit) \
+ ({ unsigned int __mask = 1 << (bit); \
+ unsigned int __result = __mask; \
+ if (sizeof (*(mem)) == 1) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.b @%2,r2\n\
+ or r2,%1\n\
+ and r2,%0\n\
+ mov.b %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result), "=&r" (__mask) \
+ : "r" (mem), "0" (__result), "1" (__mask) \
+ : "r0", "r1", "r2", "memory"); \
+ else if (sizeof (*(mem)) == 2) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.w @%2,r2\n\
+ or r2,%1\n\
+ and r2,%0\n\
+ mov.w %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result), "=&r" (__mask) \
+ : "r" (mem), "0" (__result), "1" (__mask) \
+ : "r0", "r1", "r2", "memory"); \
+ else if (sizeof (*(mem)) == 4) \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.l @%2,r2\n\
+ or r2,%1\n\
+ and r2,%0\n\
+ mov.l %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result), "=&r" (__mask) \
+ : "r" (mem), "0" (__result), "1" (__mask) \
+ : "r0", "r1", "r2", "memory"); \
+ else \
+ abort (); \
+ __result; })
diff --git a/libc/sysdeps/unix/sysv/linux/sh/bits/fcntl.h b/libc/sysdeps/unix/sysv/linux/sh/bits/fcntl.h
new file mode 100644
index 000000000..1f7ac0f25
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/bits/fcntl.h
@@ -0,0 +1,236 @@
+/* O_*, F_*, FD_* bit values for Linux.
+ Copyright (C) 1995, 1996, 1997, 1998, 2000, 2004, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <sys/types.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+
+
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on an ext2 file system */
+#define O_ACCMODE 0003
+#define O_RDONLY 00
+#define O_WRONLY 01
+#define O_RDWR 02
+#define O_CREAT 0100 /* not fcntl */
+#define O_EXCL 0200 /* not fcntl */
+#define O_NOCTTY 0400 /* not fcntl */
+#define O_TRUNC 01000 /* not fcntl */
+#define O_APPEND 02000
+#define O_NONBLOCK 04000
+#define O_NDELAY O_NONBLOCK
+#define O_SYNC 010000
+#define O_FSYNC O_SYNC
+#define O_ASYNC 020000
+
+#ifdef __USE_GNU
+# define O_DIRECT 040000 /* Direct disk access. */
+# define O_DIRECTORY 0200000 /* Must be a directory. */
+# define O_NOFOLLOW 0400000 /* Do not follow links. */
+# define O_NOATIME 01000000 /* Do not set atime. */
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+# define O_LARGEFILE 0100000
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#ifndef __USE_FILE_OFFSET64
+# define F_GETLK 5 /* Get record locking info. */
+# define F_SETLK 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW 7 /* Set record locking info (blocking). */
+#else
+# define F_GETLK F_GETLK64 /* Get record locking info. */
+# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
+# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
+#endif
+#define F_GETLK64 12 /* Get record locking info. */
+#define F_SETLK64 13 /* Set record locking info (non-blocking). */
+#define F_SETLKW64 14 /* Set record locking info (blocking). */
+
+#if defined __USE_BSD || defined __USE_UNIX98
+# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */
+# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+#endif
+
+/* For F_[GET|SET]FD. */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
+#define F_RDLCK 0 /* Read lock. */
+#define F_WRLCK 1 /* Write lock. */
+#define F_UNLCK 2 /* Remove lock. */
+
+/* For old implementation of bsd flock(). */
+#define F_EXLCK 4 /* or 3 */
+#define F_SHLCK 8 /* or 4 */
+
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation. */
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#endif
+
+struct flock
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+#ifndef __USE_FILE_OFFSET64
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+#else
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+#endif
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+
+#ifdef __USE_LARGEFILE64
+struct flock64
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+#endif
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+#endif
+
+
+#ifdef __USE_GNU
+/* Flags for SYNC_FILE_RANGE. */
+# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
+ in the range before performing the
+ write. */
+# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
+ dirty pages in the range which are
+ not presently under writeback. */
+# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
+ the range after performing the
+ write. */
+
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+#endif
+
+__BEGIN_DECLS
+
+#ifdef __USE_GNU
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+
+/* Selective file content synch'ing. */
+extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
+ unsigned int __flags);
+
+
+/* Splice address range into a pipe. */
+extern int vmsplice (int __fdout, const struct iovec *__iov, size_t __count,
+ unsigned int __flags);
+
+/* Splice two files together. */
+extern int splice (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+/* In-kernel implementation of tee for pipe buffers. */
+extern int tee (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+#endif
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/sh/bits/mman.h b/libc/sysdeps/unix/sysv/linux/sh/bits/mman.h
new file mode 100644
index 000000000..7a6b572a4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/bits/mman.h
@@ -0,0 +1,103 @@
+/* Definitions for POSIX memory map interface. Linux/SH version.
+ Copyright (C) 1997,1999,2000,2003,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MMAN_H
+# error "Never include this file directly. Use <sys/mman.h> instead"
+#endif
+
+/* The following definitions basically come from the kernel headers.
+ But the kernel header is not namespace clean. */
+
+
+/* Protections are chosen from these bits, OR'd together. The
+ implementation does not necessarily support PROT_EXEC or PROT_WRITE
+ without PROT_READ. The only guarantees are that no writing will be
+ allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
+
+#define PROT_READ 0x1 /* Page can be read. */
+#define PROT_WRITE 0x2 /* Page can be written. */
+#define PROT_EXEC 0x4 /* Page can be executed. */
+#define PROT_NONE 0x0 /* Page can not be accessed. */
+#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
+ growsdown vma (mprotect only). */
+#define PROT_GROWSUP 0x02000000 /* Extend change to start of
+ growsup vma (mprotect only). */
+
+/* Sharing types (must choose one and only one of these). */
+#define MAP_SHARED 0x01 /* Share changes. */
+#define MAP_PRIVATE 0x02 /* Changes are private. */
+#ifdef __USE_MISC
+# define MAP_TYPE 0x0f /* Mask for type of mapping. */
+#endif
+
+/* Other flags. */
+#define MAP_FIXED 0x10 /* Interpret addr exactly. */
+#ifdef __USE_MISC
+# define MAP_FILE 0
+# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
+# define MAP_ANON MAP_ANONYMOUS
+#endif
+
+/* These are Linux-specific. */
+#ifdef __USE_MISC
+# define MAP_GROWSDOWN 0x0100 /* Stack-like segment. */
+# define MAP_DENYWRITE 0x0800 /* ETXTBSY */
+# define MAP_EXECUTABLE 0x1000 /* Mark it as an executable. */
+# define MAP_LOCKED 0x2000 /* Lock the mapping. */
+# define MAP_NORESERVE 0x4000 /* Don't check for reservations. */
+# define MAP_POPULATE 0x8000 /* Populate (prefault) pagetables. */
+# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
+#endif
+
+/* Flags to `msync'. */
+#define MS_ASYNC 1 /* Sync memory asynchronously. */
+#define MS_SYNC 4 /* Synchronous memory sync. */
+#define MS_INVALIDATE 2 /* Invalidate the caches. */
+
+/* Flags for `mlockall'. */
+#define MCL_CURRENT 1 /* Lock all currently mapped pages. */
+#define MCL_FUTURE 2 /* Lock all additions to address
+ space. */
+
+/* Flags for `mremap'. */
+#ifdef __USE_GNU
+# define MREMAP_MAYMOVE 1
+# define MREMAP_FIXED 2
+#endif
+
+/* Advice to `madvise'. */
+#ifdef __USE_BSD
+# define MADV_NORMAL 0 /* No further special treatment. */
+# define MADV_RANDOM 1 /* Expect random page references. */
+# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define MADV_WILLNEED 3 /* Will need these pages. */
+# define MADV_DONTNEED 4 /* Don't need these pages. */
+# define MADV_REMOVE 9 /* Remove these pages and resources. */
+# define MADV_DONTFORK 10 /* Do not inherit across fork. */
+# define MADV_DOFORK 11 /* Do inherit across fork. */
+#endif
+
+/* The POSIX people had to invent similar names for the same things. */
+#ifdef __USE_XOPEN2K
+# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sh/brk.c b/libc/sysdeps/unix/sysv/linux/sh/brk.c
new file mode 100644
index 000000000..0524478b5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/brk.c
@@ -0,0 +1,48 @@
+/* brk system call for Linux/SH.
+ Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sysdep.h>
+
+/* This must be initialized data because commons can't have aliases. */
+void *__curbrk = 0;
+
+int
+__brk (void *addr)
+{
+ void *newbrk;
+ register long r3 asm ("%r3") = SYS_ify (brk);
+ register long r4 asm ("%r4") = (long)addr;
+
+ asm volatile ("trapa #0x11\n\t" SYSCALL_INST_PAD
+ : "=z"(newbrk)
+ : "r" (r3), "r" (r4));
+
+ __curbrk = newbrk;
+
+ if (newbrk < addr)
+ {
+ __set_errno (ENOMEM);
+ return -1;
+ }
+
+ return 0;
+}
+weak_alias (__brk, brk)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/chown.c b/libc/sysdeps/unix/sysv/linux/sh/chown.c
new file mode 100644
index 000000000..e7193dc23
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/chown.c
@@ -0,0 +1,69 @@
+/* Copyright (C) 1998,2000,2002,2003,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+#ifdef __NR_chown32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_chown32 */
+
+int
+__chown (const char *file, uid_t owner, gid_t group)
+{
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (chown32, 3, CHECK_STRING (file), owner, group);
+#else
+# ifdef __NR_chown32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ int result;
+ int saved_errno = errno;
+
+ result = INLINE_SYSCALL (chown32, 3, CHECK_STRING (file), owner, group);
+ if (result == 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_chown32 */
+
+ if (((owner + 1) > (gid_t) ((__kernel_uid_t) -1U))
+ || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return INLINE_SYSCALL (chown, 3, CHECK_STRING (file), owner, group);
+#endif
+}
+libc_hidden_def (__chown)
+weak_alias (__chown, chown)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/clone.S b/libc/sysdeps/unix/sysv/linux/sh/clone.S
new file mode 100644
index 000000000..7941c6b3a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/clone.S
@@ -0,0 +1,132 @@
+/* Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* clone() is even more special than fork() as it mucks with stacks
+ and invokes a function in the right context after its all over. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#ifdef RESET_PID
+#include <tcb-offsets.h>
+#endif
+/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
+ pid_t *ptid, void *tls, pid_t *ctid); */
+
+ .text
+ENTRY(__clone)
+ /* sanity check arguments. */
+ tst r4, r4
+ bf/s 1f
+ tst r5, r5
+ bf/s 1f
+ mov #-EINVAL,r0
+ bra .Lsyscall_error
+ nop
+1:
+ /* insert the args onto the new stack */
+ mov.l r7, @-r5
+ /* save the function pointer as the 0th element */
+ mov.l r4, @-r5
+
+ /* do the system call */
+ mov r6, r4
+ mov.l @r15, r6
+ mov.l @(8,r15), r7
+ mov.l @(4,r15), r0
+ mov #+SYS_ify(clone), r3
+ trapa #0x15
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lclone_end
+.Lsyscall_error:
+ SYSCALL_ERROR_HANDLER
+.Lclone_end:
+ tst r0, r0
+ bt 2f
+.Lpseudo_end:
+ rts
+ nop
+2:
+ /* terminate the stack frame */
+ mov #0, r14
+#ifdef RESET_PID
+ mov r4, r0
+ shlr16 r0
+ tst #1, r0 // CLONE_THREAD = (1 << 16)
+ bf/s 4f
+ mov r4, r0
+ /* new pid */
+ shlr8 r0
+ tst #1, r0 // CLONE_VM = (1 << 8)
+ bf/s 3f
+ mov #-1, r0
+ mov #+SYS_ify(getpid), r3
+ trapa #0x15
+3:
+ stc gbr, r1
+ mov.w .Lpidoff, r2
+ add r1, r2
+ mov.l r0, @r2
+ mov.w .Ltidoff, r2
+ add r1, r2
+ mov.l r0, @r2
+4:
+#endif
+ /* thread starts */
+ mov.l @r15, r1
+ jsr @r1
+ mov.l @(4,r15), r4
+
+ /* we are done, passing the return value through r0 */
+ mov.l .L3, r1
+#ifdef SHARED
+ mov.l r12, @-r15
+ sts.l pr, @-r15
+ mov r0, r4
+ mova .LG, r0
+ mov.l .LG, r12
+ add r0, r12
+ mova .L3, r0
+ add r0, r1
+ jsr @r1
+ nop
+ lds.l @r15+, pr
+ rts
+ mov.l @r15+, r12
+#else
+ jmp @r1
+ mov r0, r4
+#endif
+ .align 2
+.LG:
+ .long _GLOBAL_OFFSET_TABLE_
+.L3:
+ .long PLTJMP(C_SYMBOL_NAME(_exit))
+#ifdef RESET_PID
+.Lpidoff:
+ .word PID - TLS_PRE_TCB_SIZE
+.Ltidoff:
+ .word TID - TLS_PRE_TCB_SIZE
+#endif
+PSEUDO_END (__clone)
+
+weak_alias (__clone, clone)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/fchown.c b/libc/sysdeps/unix/sysv/linux/sh/fchown.c
new file mode 100644
index 000000000..3a69ecc9e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/fchown.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fchown.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/fchownat.c b/libc/sysdeps/unix/sysv/linux/sh/fchownat.c
new file mode 100644
index 000000000..61df787c2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/fchownat.c
@@ -0,0 +1,140 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include <kernel-features.h>
+
+#ifdef __NR_chown32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_chown32 */
+
+int
+fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
+{
+ int result;
+
+#ifdef __NR_fchownat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INLINE_SYSCALL (fchownat, 5, fd, file, owner, group, flag);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ if (flag & ~AT_SYMLINK_NOFOLLOW)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+# if __ASSUME_32BITUIDS > 0
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lchown32, err, 3, CHECK_STRING (file), owner,
+ group);
+ else
+ result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file), owner,
+ group);
+# else
+# ifdef __NR_chown32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lchown32, err, 3, CHECK_STRING (file),
+ owner, group);
+ else
+ result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file), owner,
+ group);
+
+ if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+ return result;
+ if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+ goto fail;
+
+ __libc_missing_32bit_uids = 1;
+ }
+# endif /* __NR_chown32 */
+
+ if (((owner + 1) > (gid_t) ((__kernel_uid_t) -1U))
+ || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ result = INTERNAL_SYSCALL (lchown, err, 3, CHECK_STRING (file), owner,
+ group);
+ else
+ result = INTERNAL_SYSCALL (chown, err, 3, CHECK_STRING (file), owner,
+ group);
+# endif
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+ fail:
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+ result = -1;
+ }
+
+ return result;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sh/fcntl.c b/libc/sysdeps/unix/sysv/linux/sh/fcntl.c
new file mode 100644
index 000000000..ea951bc4f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/fcntl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/fxstat.c b/libc/sysdeps/unix/sysv/linux/sh/fxstat.c
new file mode 100644
index 000000000..4f219f0b9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/fxstat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/fxstatat.c b/libc/sysdeps/unix/sysv/linux/sh/fxstatat.c
new file mode 100644
index 000000000..0f8b3135d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/fxstatat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstatat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/getegid.c b/libc/sysdeps/unix/sysv/linux/sh/getegid.c
new file mode 100644
index 000000000..37b4b4a53
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/getegid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getegid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/geteuid.c b/libc/sysdeps/unix/sysv/linux/sh/geteuid.c
new file mode 100644
index 000000000..ebcb555b5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/geteuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/geteuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/getgroups.c b/libc/sysdeps/unix/sysv/linux/sh/getgroups.c
new file mode 100644
index 000000000..102ea24e1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/getgroups.c
@@ -0,0 +1,2 @@
+/* We also have to rewrite the kernel gid_t to the user land type. */
+#include <sysdeps/unix/sysv/linux/i386/getgroups.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/getresgid.c b/libc/sysdeps/unix/sysv/linux/sh/getresgid.c
new file mode 100644
index 000000000..b703a414c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/getresgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getresgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/getresuid.c b/libc/sysdeps/unix/sysv/linux/sh/getresuid.c
new file mode 100644
index 000000000..0b14cefe3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/getresuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getresuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/getrlimit.c b/libc/sysdeps/unix/sysv/linux/sh/getrlimit.c
new file mode 100644
index 000000000..fc06dbd64
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/getrlimit.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getrlimit.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/getrlimit64.c b/libc/sysdeps/unix/sysv/linux/sh/getrlimit64.c
new file mode 100644
index 000000000..fef018f47
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/getrlimit64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getrlimit64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/getuid.c b/libc/sysdeps/unix/sysv/linux/sh/getuid.c
new file mode 100644
index 000000000..d682c79a4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/getuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/lchown.c b/libc/sysdeps/unix/sysv/linux/sh/lchown.c
new file mode 100644
index 000000000..c89de99ba
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/lchown.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/lchown.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/lockf64.c b/libc/sysdeps/unix/sysv/linux/sh/lockf64.c
new file mode 100644
index 000000000..a88f5a784
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/lockf64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/lockf64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/lxstat.c b/libc/sysdeps/unix/sysv/linux/sh/lxstat.c
new file mode 100644
index 000000000..2371cd971
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/lxstat.c
@@ -0,0 +1,2 @@
+#include <sysdeps/unix/sysv/linux/i386/lxstat.c>
+
diff --git a/libc/sysdeps/unix/sysv/linux/sh/makecontext.S b/libc/sysdeps/unix/sysv/linux/sh/makecontext.S
new file mode 100644
index 000000000..877d78d39
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/makecontext.S
@@ -0,0 +1,145 @@
+/* Create new context.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+/* void __makecontext (struct ucontext *ucp, void (*func)(), int argc, ...);
+ __makecontext sets up a stack and registers for context to run a given
+ function. The registers are set up like this:
+ r4-r7: parameters 1 to 4
+ r8 : uc_link from ucontext structure
+ pc : (*func) pointer
+ pr : address of exitcode
+ r15 : stack pointer for func. */
+
+ .text
+ .align 5
+ENTRY(__makecontext)
+ mov #4, r3
+ mov.l @(oSS_SP,r4), r1
+ mov.l @(oSS_SIZE,r4), r2
+ add r1, r2
+ cmp/gt r6, r3
+ bf/s 1f
+ shlr2 r2
+ sub r6, r2
+ add r3, r2
+1:
+ shll2 r2
+ mov #oR15, r0
+ mov.l @(oLINK,r4), r1
+ mov.l r2, @(r0,r4)
+ mov.l r1, @(oR8,r4)
+ mov #oPC, r0
+ mov.l r5, @(r0,r4)
+
+ cmp/pl r6
+ bf/s .L1
+ dt r6
+ mov.l r7, @(oR4,r4)
+ cmp/pl r6
+ bf/s .L1
+ dt r6
+ mov.l @(0,r15), r1
+ mov.l r1, @(oR5,r4)
+ cmp/pl r6
+ bf/s .L1
+ dt r6
+ mov.l @(4,r15), r1
+ mov.l r1, @(oR6,r4)
+ cmp/pl r6
+ bf/s .L1
+ dt r6
+ mov.l @(8,r15), r1
+ mov.l r1, @(oR7,r4)
+ mov #12,r0
+.L0:
+ cmp/pl r6
+ bf/s .L1
+ dt r6
+ mov.l @(r0,r15), r1
+ mov.l r1, @r2
+ add #4, r0
+ bra .L0
+ add #4, r2
+.L1:
+#ifdef PIC
+ mova .Lexitcode, r0
+#else
+ mov.l .L2, r0
+#endif
+ add #oPR, r4
+ rts
+ mov.l r0, @r4
+#ifndef PIC
+ .align 2
+.L2:
+ .long .Lexitcode
+#endif
+ cfi_endproc
+
+ .align 5
+.Lexitcode:
+ tst r8, r8
+ bt/s 2f
+ mov r8, r4
+#ifdef PIC
+ mova .Lgot, r0
+ mov.l .Lgot, r12
+ add r0, r12
+ mov.l .L3, r1
+ bsrf r1
+.LPCS0:
+ nop
+#else
+ mov.l .L3, r1
+ jsr @r1
+ nop
+#endif
+2:
+ mov.l .L4, r1
+#ifdef PIC
+ add r12, r1
+#endif
+ jsr @r1
+ mov r0, r4
+0:
+ bra 0b
+ nop
+
+ .align 2
+#ifdef PIC
+.Lgot:
+ .long _GLOBAL_OFFSET_TABLE_
+.L3:
+ .long __setcontext@PLT-(.LPCS0+2-(.))
+.L4:
+ .long HIDDEN_JUMPTARGET(exit)@GOTOFF
+#else
+.L3:
+ .long __setcontext
+.L4:
+ .long HIDDEN_JUMPTARGET(exit)
+#endif
+ cfi_startproc
+PSEUDO_END(__makecontext)
+
+weak_alias (__makecontext, makecontext)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/msgctl.c b/libc/sysdeps/unix/sysv/linux/sh/msgctl.c
new file mode 100644
index 000000000..9f9b8431a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/msgctl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/msgctl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/pipe.S b/libc/sysdeps/unix/sysv/linux/sh/pipe.S
new file mode 100644
index 000000000..2b5cf77d1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/pipe.S
@@ -0,0 +1,43 @@
+/* Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+ENTRY (__libc_pipe)
+ mov #+__NR_pipe, r3
+ trapa #0x10
+ mov r0, r3
+ mov #-12, r2
+ shad r2, r3
+ not r3, r3 // r1=0 means r0 = -1 to -4095
+ tst r3, r3 // i.e. error in linux
+ bt 1f
+ mov.l r0, @r4
+ mov.l r1, @(4, r4)
+ rts
+ mov #0, r0
+1:
+ SYSCALL_ERROR_HANDLER
+.Lpseudo_end:
+ rts
+ nop
+PSEUDO_END (__libc_pipe)
+
+weak_alias (__libc_pipe, __pipe)
+libc_hidden_def (__pipe)
+weak_alias (__libc_pipe, pipe)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/pread.c b/libc/sysdeps/unix/sysv/linux/sh/pread.c
new file mode 100644
index 000000000..0186e40c9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/pread.c
@@ -0,0 +1,93 @@
+/* Copyright (C) 1997, 1998, 2000, 2002, 2003, 2004, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <unistd.h>
+#include <endian.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pread
+# error "__NR_pread and __NR_pread64 both defined???"
+# endif
+# define __NR_pread __NR_pread64
+#endif
+
+#if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
+
+# if __ASSUME_PREAD_SYSCALL == 0
+static ssize_t __emulate_pread (int fd, void *buf, size_t count,
+ off_t offset) internal_function;
+# endif
+
+ssize_t
+__libc_pread (fd, buf, count, offset)
+ int fd;
+ void *buf;
+ size_t count;
+ off_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR (offset >> 31, offset));
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread (fd, buf, count, offset);
+# endif
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR (offset >> 31, offset));
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+strong_alias (__libc_pread, __pread)
+weak_alias (__libc_pread, pread)
+
+# define __libc_pread(fd, buf, count, offset) \
+ static internal_function __emulate_pread (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PREAD_SYSCALL == 0
+# include <sysdeps/posix/pread.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sh/pread64.c b/libc/sysdeps/unix/sysv/linux/sh/pread64.c
new file mode 100644
index 000000000..f23d61909
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/pread64.c
@@ -0,0 +1,94 @@
+/* Copyright (C) 1997, 1998, 2000, 2002, 2003, 2004, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <endian.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pread
+# error "__NR_pread and __NR_pread64 both defined???"
+# endif
+# define __NR_pread __NR_pread64
+#endif
+
+#if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
+
+# if __ASSUME_PREAD_SYSCALL == 0
+static ssize_t __emulate_pread64 (int fd, void *buf, size_t count,
+ off64_t offset) internal_function;
+# endif
+
+ssize_t
+__libc_pread64 (fd, buf, count, offset)
+ int fd;
+ void *buf;
+ size_t count;
+ off64_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread64 (fd, buf, count, offset);
+# endif
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread64 (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+weak_alias (__libc_pread64, __pread64)
+weak_alias (__libc_pread64, pread64)
+
+# define __libc_pread64(fd, buf, count, offset) \
+ static internal_function __emulate_pread64 (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PREAD_SYSCALL == 0
+# include <sysdeps/posix/pread64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sh/profil-counter.h b/libc/sysdeps/unix/sysv/linux/sh/profil-counter.h
new file mode 100644
index 000000000..ae1b97828
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/profil-counter.h
@@ -0,0 +1,33 @@
+/* Low-level statistical profiling support function. Linux/SH version.
+ Copyright (C) 1996, 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <signal.h>
+
+static void
+profil_counter (int signo, int _a2, int _a3, int _a4, struct sigcontext sc)
+{
+ void *pc;
+ pc = (void *) sc.sc_pc;
+ profil_count (pc);
+
+ /* This is a hack to prevent the compiler from implementing the
+ above function call as a sibcall. The sibcall would overwrite
+ the signal context. */
+ asm volatile ("");
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sh/pwrite.c b/libc/sysdeps/unix/sysv/linux/sh/pwrite.c
new file mode 100644
index 000000000..f0e2bc7e0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/pwrite.c
@@ -0,0 +1,93 @@
+/* Copyright (C) 1997, 1998, 2000, 2002, 2003, 2004, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <unistd.h>
+#include <endian.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pwrite
+# error "__NR_pwrite and __NR_pwrite64 both defined???"
+# endif
+# define __NR_pwrite __NR_pwrite64
+#endif
+
+#if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
+
+# if __ASSUME_PWRITE_SYSCALL == 0
+static ssize_t __emulate_pwrite (int fd, const void *buf, size_t count,
+ off_t offset) internal_function;
+# endif
+
+ssize_t
+__libc_pwrite (fd, buf, count, offset)
+ int fd;
+ const void *buf;
+ size_t count;
+ off_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR (offset >> 31, offset));
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite (fd, buf, count, offset);
+# endif
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR (offset >> 31, offset));
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+strong_alias (__libc_pwrite, __pwrite)
+weak_alias (__libc_pwrite, pwrite)
+
+# define __libc_pwrite(fd, buf, count, offset) \
+ static internal_function __emulate_pwrite (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PWRITE_SYSCALL == 0
+# include <sysdeps/posix/pwrite.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sh/pwrite64.c b/libc/sysdeps/unix/sysv/linux/sh/pwrite64.c
new file mode 100644
index 000000000..eb1e50728
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/pwrite64.c
@@ -0,0 +1,96 @@
+/* Copyright (C) 1997, 1998, 2000, 2002, 2003, 2004, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ralf Baechle <ralf@gnu.org>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <endian.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pwrite
+# error "__NR_pwrite and __NR_pwrite64 both defined???"
+# endif
+# define __NR_pwrite __NR_pwrite64
+#endif
+
+#if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
+
+# if __ASSUME_PWRITE_SYSCALL == 0
+static ssize_t __emulate_pwrite64 (int fd, const void *buf, size_t count,
+ off64_t offset) internal_function;
+# endif
+
+ssize_t
+__libc_pwrite64 (fd, buf, count, offset)
+ int fd;
+ const void *buf;
+ size_t count;
+ off64_t offset;
+{
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite64 (fd, buf, count, offset);
+# endif
+
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite64 (fd, buf, count, offset);
+# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+weak_alias (__libc_pwrite64, __pwrite64)
+libc_hidden_weak (__pwrite64)
+weak_alias (__libc_pwrite64, pwrite64)
+
+# define __libc_pwrite64(fd, buf, count, offset) \
+ static internal_function __emulate_pwrite64 (fd, buf, count, offset)
+#endif
+
+#if __ASSUME_PWRITE_SYSCALL == 0
+# include <sysdeps/posix/pwrite64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sh/semctl.c b/libc/sysdeps/unix/sysv/linux/sh/semctl.c
new file mode 100644
index 000000000..e9b1a483c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/semctl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/semctl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/setegid.c b/libc/sysdeps/unix/sysv/linux/sh/setegid.c
new file mode 100644
index 000000000..2e3a54c89
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/setegid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setegid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/seteuid.c b/libc/sysdeps/unix/sysv/linux/sh/seteuid.c
new file mode 100644
index 000000000..18e41d08c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/seteuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/seteuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/setfsgid.c b/libc/sysdeps/unix/sysv/linux/sh/setfsgid.c
new file mode 100644
index 000000000..088671256
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/setfsgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setfsgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/setfsuid.c b/libc/sysdeps/unix/sysv/linux/sh/setfsuid.c
new file mode 100644
index 000000000..a9f22eb8a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/setfsuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setfsuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/setgid.c b/libc/sysdeps/unix/sysv/linux/sh/setgid.c
new file mode 100644
index 000000000..377021d9e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/setgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/setgroups.c b/libc/sysdeps/unix/sysv/linux/sh/setgroups.c
new file mode 100644
index 000000000..0e7086278
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/setgroups.c
@@ -0,0 +1,2 @@
+/* We also have to rewrite the kernel gid_t to the user land type. */
+#include <sysdeps/unix/sysv/linux/i386/setgroups.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/setregid.c b/libc/sysdeps/unix/sysv/linux/sh/setregid.c
new file mode 100644
index 000000000..99c57ad20
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/setregid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setregid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/setresgid.c b/libc/sysdeps/unix/sysv/linux/sh/setresgid.c
new file mode 100644
index 000000000..daca1a483
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/setresgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setresgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/setresuid.c b/libc/sysdeps/unix/sysv/linux/sh/setresuid.c
new file mode 100644
index 000000000..3aeabe9ad
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/setresuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setresuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/setreuid.c b/libc/sysdeps/unix/sysv/linux/sh/setreuid.c
new file mode 100644
index 000000000..8ad61226e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/setreuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setreuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/setrlimit.c b/libc/sysdeps/unix/sysv/linux/sh/setrlimit.c
new file mode 100644
index 000000000..bfaef74c3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/setrlimit.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setrlimit.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/setuid.c b/libc/sysdeps/unix/sysv/linux/sh/setuid.c
new file mode 100644
index 000000000..de394379b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/setuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh3/getcontext.S b/libc/sysdeps/unix/sysv/linux/sh/sh3/getcontext.S
new file mode 100644
index 000000000..66b3daaa3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh3/getcontext.S
@@ -0,0 +1,88 @@
+/* Save current context.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+/* int __getcontext (ucontext_t *uc); */
+
+ .text
+ .align 5
+ENTRY(__getcontext)
+
+ /* Return value of getcontext. R0 is the only register whose
+ value is not preserved. */
+ mov #0, r0
+ mov.l r0, @(oR0,r4)
+ mov.l r1, @(oR1,r4)
+ mov.l r2, @(oR2,r4)
+ mov.l r3, @(oR3,r4)
+ mov.l r4, @(oR4,r4)
+ mov.l r5, @(oR5,r4)
+ mov.l r6, @(oR6,r4)
+ mov.l r7, @(oR7,r4)
+ mov r4, r0
+ add #(oMACL+4), r0
+ sts.l macl, @-r0
+ sts.l mach, @-r0
+ stc.l gbr, @-r0
+
+ /* Save T flag to SR. */
+ movt r1
+ mov.l r1, @-r0
+ sts.l pr, @-r0
+
+ /* The return address of getcontext is the restart pc. */
+ sts.l pr, @-r0
+
+ mov.l r15, @-r0
+ mov.l r14, @-r0
+ mov.l r13, @-r0
+ mov.l r12, @-r0
+ mov.l r11, @-r0
+ mov.l r10, @-r0
+ mov.l r9, @-r0
+ mov.l r8, @-r0
+
+ /* sigprocmask (SIG_BLOCK, NULL, &uc->uc_sigmask). */
+ mov r4, r6
+ add #oSIGMASK, r6
+ mov #SIG_BLOCK, r4
+ mov #0, r5
+ mov #+SYS_ify(sigprocmask), r3
+ trapa #0x13
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lgetcontext_end
+.Lsyscall_error:
+ SYSCALL_ERROR_HANDLER
+.Lgetcontext_end:
+ /* All done, return 0 for success. */
+ mov #0, r0
+.Lpseudo_end:
+ rts
+ nop
+
+PSEUDO_END(__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh3/register-dump.h b/libc/sysdeps/unix/sysv/linux/sh/sh3/register-dump.h
new file mode 100644
index 000000000..561f3b3e8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh3/register-dump.h
@@ -0,0 +1,151 @@
+/* Dump registers.
+ Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/uio.h>
+#include <stdio-common/_itoa.h>
+
+/* We will print the register dump in this format:
+
+ R0: XXXXXXXX R1: XXXXXXXX R2: XXXXXXXX R3: XXXXXXXX
+ R4: XXXXXXXX R5: XXXXXXXX R6: XXXXXXXX R7: XXXXXXXX
+ R8: XXXXXXXX R9: XXXXXXXX R10: XXXXXXXX R11: XXXXXXXX
+ R12: XXXXXXXX R13: XXXXXXXX R14: XXXXXXXX R15: XXXXXXXX
+
+MACL: XXXXXXXX MACH: XXXXXXXX
+
+ PC: XXXXXXXX PR: XXXXXXXX GBR: XXXXXXXX SR: XXXXXXXX
+
+ FR0: XXXXXXXX FR1: XXXXXXXX FR2: XXXXXXXX FR3: XXXXXXXX
+ FR4: XXXXXXXX FR5: XXXXXXXX FR6: XXXXXXXX FR7: XXXXXXXX
+ FR8: XXXXXXXX FR9: XXXXXXXX FR10: XXXXXXXX FR11: XXXXXXXX
+FR12: XXXXXXXX FR13: XXXXXXXX FR14: XXXXXXXX FR15: XXXXXXXX
+
+ XR0: XXXXXXXX XR1: XXXXXXXX XR2: XXXXXXXX XR3: XXXXXXXX
+ XR4: XXXXXXXX XR5: XXXXXXXX XR6: XXXXXXXX XR7: XXXXXXXX
+ XR8: XXXXXXXX XR9: XXXXXXXX XR10: XXXXXXXX XR11: XXXXXXXX
+XR12: XXXXXXXX XR13: XXXXXXXX XR14: XXXXXXXX XR15: XXXXXXXX
+
+FPSCR: XXXXXXXX FPUL: XXXXXXXX
+
+ */
+
+static void
+hexvalue (unsigned long int value, char *buf, size_t len)
+{
+ char *cp = _itoa_word (value, buf + len, 16, 0);
+ while (cp > buf)
+ *--cp = '0';
+}
+
+static void
+register_dump (int fd, struct sigcontext *ctx)
+{
+ char regs[22][8];
+ struct iovec iov[112];
+ size_t nr = 0;
+
+#define ADD_STRING(str) \
+ iov[nr].iov_base = (char *) str; \
+ iov[nr].iov_len = strlen (str); \
+ ++nr
+#define ADD_MEM(str, len) \
+ iov[nr].iov_base = str; \
+ iov[nr].iov_len = len; \
+ ++nr
+
+ /* Generate strings of register contents. */
+ hexvalue (ctx->sc_regs[0], regs[0], 8);
+ hexvalue (ctx->sc_regs[1], regs[1], 8);
+ hexvalue (ctx->sc_regs[2], regs[2], 8);
+ hexvalue (ctx->sc_regs[3], regs[3], 8);
+ hexvalue (ctx->sc_regs[4], regs[4], 8);
+ hexvalue (ctx->sc_regs[5], regs[5], 8);
+ hexvalue (ctx->sc_regs[6], regs[6], 8);
+ hexvalue (ctx->sc_regs[7], regs[7], 8);
+ hexvalue (ctx->sc_regs[8], regs[8], 8);
+ hexvalue (ctx->sc_regs[9], regs[9], 8);
+ hexvalue (ctx->sc_regs[10], regs[10], 8);
+ hexvalue (ctx->sc_regs[11], regs[11], 8);
+ hexvalue (ctx->sc_regs[12], regs[12], 8);
+ hexvalue (ctx->sc_regs[13], regs[13], 8);
+ hexvalue (ctx->sc_regs[14], regs[14], 8);
+ hexvalue (ctx->sc_regs[15], regs[15], 8);
+ hexvalue (ctx->sc_macl, regs[16], 8);
+ hexvalue (ctx->sc_mach, regs[17], 8);
+ hexvalue (ctx->sc_pc, regs[18], 8);
+ hexvalue (ctx->sc_pr, regs[19], 8);
+ hexvalue (ctx->sc_gbr, regs[20], 8);
+ hexvalue (ctx->sc_sr, regs[21], 8);
+
+ /* Generate the output. */
+ ADD_STRING ("Register dump:\n\n R0: ");
+ ADD_MEM (regs[0], 8);
+ ADD_STRING (" R1: ");
+ ADD_MEM (regs[1], 8);
+ ADD_STRING (" R2: ");
+ ADD_MEM (regs[2], 8);
+ ADD_STRING (" R3: ");
+ ADD_MEM (regs[3], 8);
+ ADD_STRING ("\n R4: ");
+ ADD_MEM (regs[4], 8);
+ ADD_STRING (" R5: ");
+ ADD_MEM (regs[5], 8);
+ ADD_STRING (" R6: ");
+ ADD_MEM (regs[6], 8);
+ ADD_STRING (" R7: ");
+ ADD_MEM (regs[7], 8);
+ ADD_STRING ("\n R8: ");
+ ADD_MEM (regs[8], 8);
+ ADD_STRING (" R9: ");
+ ADD_MEM (regs[9], 8);
+ ADD_STRING (" R10: ");
+ ADD_MEM (regs[10], 8);
+ ADD_STRING (" R11: ");
+ ADD_MEM (regs[11], 8);
+ ADD_STRING ("\n R12: ");
+ ADD_MEM (regs[12], 8);
+ ADD_STRING (" R13: ");
+ ADD_MEM (regs[13], 8);
+ ADD_STRING (" R14: ");
+ ADD_MEM (regs[14], 8);
+ ADD_STRING (" R15: ");
+ ADD_MEM (regs[15], 8);
+
+ ADD_STRING ("\n\nMACL: ");
+ ADD_MEM (regs[16], 8);
+ ADD_STRING (" MACH: ");
+ ADD_MEM (regs[17], 8);
+
+ ADD_STRING ("\n\n PC: ");
+ ADD_MEM (regs[18], 8);
+ ADD_STRING (" PR: ");
+ ADD_MEM (regs[19], 8);
+ ADD_STRING (" GBR: ");
+ ADD_MEM (regs[20], 8);
+ ADD_STRING (" SR: ");
+ ADD_MEM (regs[21], 8);
+
+ ADD_STRING ("\n");
+
+ /* Write the stuff out. */
+ writev (fd, iov, nr);
+}
+
+
+#define REGISTER_DUMP register_dump (fd, &ctx)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh3/setcontext.S b/libc/sysdeps/unix/sysv/linux/sh/sh3/setcontext.S
new file mode 100644
index 000000000..3136267ac
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh3/setcontext.S
@@ -0,0 +1,99 @@
+/* Install given context.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+/* int __setcontext (const ucontext_t *uc); */
+
+ .text
+ .align 5
+ENTRY(__setcontext)
+
+ mov r4, r8
+
+ /* sigprocmask (SIG_SETMASK, &uc->uc_sigmask, NULL). */
+ mov r4, r5
+ add #oSIGMASK, r5
+ mov #SIG_SETMASK, r4
+ mov #0, r6
+ mov #+SYS_ify(sigprocmask), r3
+ trapa #0x13
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lsetcontext_restore
+.Lsyscall_error:
+ SYSCALL_ERROR_HANDLER
+.Lpseudo_end:
+ rts
+ nop
+
+.Lsetcontext_restore:
+ mov r8, r0
+ add #(oPC), r0
+ mov.l @r0+, r2
+ lds.l @r0+, pr
+
+ /* Restore T frag. */
+ mov.l @r0+, r1
+ shlr r1
+ /* Skip GBR which is used for thread pointer. */
+ add #4, r0
+
+ lds.l @r0+, mach
+ lds.l @r0+, macl
+
+ mov r8, r0
+ add #(oR9), r0
+ mov.l @r0+, r9
+ mov.l @r0+, r10
+ mov.l @r0+, r11
+ mov.l @r0+, r12
+ mov.l @r0+, r13
+ mov.l @r0+, r14
+ mov.l @r0+, r15
+
+ mov r8, r0
+ mov.l @(oR0,r0), r1
+ mov.l r1, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r1, 0)
+ mov.l r2, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r2, 0)
+
+ mov.l @(oR1,r0), r1
+ mov.l @(oR2,r0), r2
+ mov.l @(oR3,r0), r3
+ mov.l @(oR4,r0), r4
+ mov.l @(oR5,r0), r5
+ mov.l @(oR6,r0), r6
+ mov.l @(oR7,r0), r7
+ mov.l @(oR8,r0), r8
+ mov.l @r15+, r0
+ jmp @r0
+ mov.l @r15+, r0
+
+PSEUDO_END(__setcontext)
+
+weak_alias (__setcontext, setcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh3/swapcontext.S b/libc/sysdeps/unix/sysv/linux/sh/sh3/swapcontext.S
new file mode 100644
index 000000000..64035e554
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh3/swapcontext.S
@@ -0,0 +1,132 @@
+/* Save current context and install the given one.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+/* int __swapcontext (ucontext_t *ouc, const ucontext_t *uc); */
+
+ .text
+ .align 5
+ENTRY(__swapcontext)
+
+ /* Return value of getcontext. R0 is the only register whose
+ value is not preserved. */
+ mov #0, r0
+ mov.l r0, @(oR0,r4)
+ mov.l r1, @(oR1,r4)
+ mov.l r2, @(oR2,r4)
+ mov.l r3, @(oR3,r4)
+ mov.l r4, @(oR4,r4)
+ mov.l r5, @(oR5,r4)
+ mov.l r6, @(oR6,r4)
+ mov.l r7, @(oR7,r4)
+ mov r4, r0
+ add #(oMACL+4), r0
+ sts.l macl, @-r0
+ sts.l mach, @-r0
+ stc.l gbr, @-r0
+
+ /* Save T flag to SR. */
+ movt r1
+ mov.l r1, @-r0
+ sts.l pr, @-r0
+
+ /* The return address of getcontext is the restart pc. */
+ sts.l pr, @-r0
+
+ mov.l r15, @-r0
+ mov.l r14, @-r0
+ mov.l r13, @-r0
+ mov.l r12, @-r0
+ mov.l r11, @-r0
+ mov.l r10, @-r0
+ mov.l r9, @-r0
+ mov.l r8, @-r0
+
+ mov r5, r8
+
+ /* sigprocmask (SIG_SETMASK, &uc->uc_sigmask, &ouc->uc_sigmask). */
+ add #oSIGMASK, r5
+ mov r4, r6
+ add #oSIGMASK, r6
+ mov #SIG_SETMASK, r4
+ mov #+SYS_ify(sigprocmask), r3
+ trapa #0x13
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lswapcontext_restore
+.Lsyscall_error:
+ SYSCALL_ERROR_HANDLER
+.Lpseudo_end:
+ rts
+ nop
+.Lswapcontext_restore:
+ mov r8, r0
+ add #(oPC), r0
+ mov.l @r0+, r2
+ lds.l @r0+, pr
+
+ /* Restore T frag. */
+ mov.l @r0+, r1
+ shlr r1
+ /* Skip GBR which is used for thread pointer. */
+ add #4, r0
+
+ lds.l @r0+, mach
+ lds.l @r0+, macl
+
+ mov r8, r0
+ add #(oR9), r0
+ mov.l @r0+, r9
+ mov.l @r0+, r10
+ mov.l @r0+, r11
+ mov.l @r0+, r12
+ mov.l @r0+, r13
+ mov.l @r0+, r14
+ mov.l @r0+, r15
+
+ mov r8, r0
+ mov.l @(oR0,r0), r1
+ mov.l r1, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r1, 0)
+ mov.l r2, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r2, 0)
+
+ mov.l @(oR1,r0), r1
+ mov.l @(oR2,r0), r2
+ mov.l @(oR3,r0), r3
+ mov.l @(oR4,r0), r4
+ mov.l @(oR5,r0), r5
+ mov.l @(oR6,r0), r6
+ mov.l @(oR7,r0), r7
+ mov.l @(oR8,r0), r8
+ mov.l @r15+, r0
+ jmp @r0
+ mov.l @r15+, r0
+
+PSEUDO_END(__swapcontext)
+
+weak_alias (__swapcontext, swapcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh3/sys/ucontext.h b/libc/sysdeps/unix/sysv/linux/sh/sh3/sys/ucontext.h
new file mode 100644
index 000000000..946df0dfd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh3/sys/ucontext.h
@@ -0,0 +1,102 @@
+/* Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Where is System V/SH ABI? */
+
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+
+#include <features.h>
+#include <signal.h>
+
+/* We need the signal context definitions even if they are not used
+ included in <signal.h>. */
+#include <bits/sigcontext.h>
+
+
+typedef int greg_t;
+
+/* Number of general registers. */
+#define NFPREG 16
+
+/* Container for all general registers. */
+typedef greg_t gregset_t[NFPREG];
+
+#ifdef __USE_GNU
+/* Number of each register is the `gregset_t' array. */
+enum
+{
+ R0 = 0,
+#define R0 R0
+ R1 = 1,
+#define R1 R1
+ R2 = 2,
+#define R2 R2
+ R3 = 3,
+#define R3 R3
+ R4 = 4,
+#define R4 R4
+ R5 = 5,
+#define R5 R5
+ R6 = 6,
+#define R6 R6
+ R7 = 7,
+#define R7 R7
+ R8 = 8,
+#define R8 R8
+ R9 = 9,
+#define R9 R9
+ R10 = 10,
+#define R10 R10
+ R11 = 11,
+#define R11 R11
+ R12 = 12,
+#define R12 R12
+ R13 = 13,
+#define R13 R13
+ R14 = 14,
+#define R14 R14
+ R15 = 15,
+#define R15 R15
+};
+#endif
+
+/* Context to describe whole processor state. */
+typedef struct
+ {
+ unsigned int oldmask;
+ gregset_t gregs;
+ unsigned int pc;
+ unsigned int pr;
+ unsigned int sr;
+ unsigned int gbr;
+ unsigned int mach;
+ unsigned int macl;
+ } mcontext_t;
+
+/* Userlevel context. */
+typedef struct ucontext
+ {
+ unsigned long int uc_flags;
+ struct ucontext *uc_link;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ __sigset_t uc_sigmask;
+ } ucontext_t;
+
+#endif /* sys/ucontext.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym b/libc/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym
new file mode 100644
index 000000000..17397c551
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym
@@ -0,0 +1,38 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+--
+
+SIG_BLOCK
+SIG_SETMASK
+
+#define ucontext(member) offsetof (ucontext_t, member)
+#define mcontext(member) ucontext (uc_mcontext.member)
+
+oLINK ucontext (uc_link)
+oSS_SP ucontext (uc_stack.ss_sp)
+oSS_SIZE ucontext (uc_stack.ss_size)
+oR0 mcontext (gregs[R0])
+oR1 mcontext (gregs[R1])
+oR2 mcontext (gregs[R2])
+oR3 mcontext (gregs[R3])
+oR4 mcontext (gregs[R4])
+oR5 mcontext (gregs[R5])
+oR6 mcontext (gregs[R6])
+oR7 mcontext (gregs[R7])
+oR8 mcontext (gregs[R8])
+oR9 mcontext (gregs[R9])
+oR10 mcontext (gregs[R10])
+oR11 mcontext (gregs[R11])
+oR12 mcontext (gregs[R12])
+oR13 mcontext (gregs[R13])
+oR14 mcontext (gregs[R14])
+oR15 mcontext (gregs[R15])
+oPC mcontext (pc)
+oPR mcontext (pr)
+oSR mcontext (sr)
+oGBR mcontext (gbr)
+oMACH mcontext (mach)
+oMACL mcontext (macl)
+oSIGMASK ucontext (uc_sigmask)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh4/getcontext.S b/libc/sysdeps/unix/sysv/linux/sh/sh4/getcontext.S
new file mode 100644
index 000000000..68bc235bc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh4/getcontext.S
@@ -0,0 +1,131 @@
+/* Save current context.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+/* int __getcontext (ucontext_t *uc); */
+
+ .text
+ .align 5
+ENTRY(__getcontext)
+
+ /* Return value of getcontext. R0 is the only register whose
+ value is not preserved. */
+ mov #0, r0
+ mov.l r0, @(oR0,r4)
+ mov.l r1, @(oR1,r4)
+ mov.l r2, @(oR2,r4)
+ mov.l r3, @(oR3,r4)
+ mov.l r4, @(oR4,r4)
+ mov.l r5, @(oR5,r4)
+ mov.l r6, @(oR6,r4)
+ mov.l r7, @(oR7,r4)
+ mov r4, r0
+ add #(oMACL+4), r0
+ sts.l macl, @-r0
+ sts.l mach, @-r0
+ stc.l gbr, @-r0
+
+ /* Save T flag to SR. */
+ movt r1
+ mov.l r1, @-r0
+ sts.l pr, @-r0
+
+ /* The return address of getcontext is the restart pc. */
+ sts.l pr, @-r0
+
+ mov.l r15, @-r0
+ mov.l r14, @-r0
+ mov.l r13, @-r0
+ mov.l r12, @-r0
+ mov.l r11, @-r0
+ mov.l r10, @-r0
+ mov.l r9, @-r0
+ mov.l r8, @-r0
+
+ mov r4, r0
+ /* We need 2 add instruction because oFPUL+4 > 127. */
+ add #124,r0
+ add #(oFPUL+4-124),r0
+ sts.l fpul, @-r0
+ sts.l fpscr, @-r0
+ frchg
+ fmov.s fr15, @-r0
+ fmov.s fr14, @-r0
+ fmov.s fr13, @-r0
+ fmov.s fr12, @-r0
+ fmov.s fr11, @-r0
+ fmov.s fr10, @-r0
+ fmov.s fr9, @-r0
+ fmov.s fr8, @-r0
+ fmov.s fr7, @-r0
+ fmov.s fr6, @-r0
+ fmov.s fr5, @-r0
+ fmov.s fr4, @-r0
+ fmov.s fr3, @-r0
+ fmov.s fr2, @-r0
+ fmov.s fr1, @-r0
+ fmov.s fr0, @-r0
+ frchg
+ fmov.s fr15, @-r0
+ fmov.s fr14, @-r0
+ fmov.s fr13, @-r0
+ fmov.s fr12, @-r0
+ fmov.s fr11, @-r0
+ fmov.s fr10, @-r0
+ fmov.s fr9, @-r0
+ fmov.s fr8, @-r0
+ fmov.s fr7, @-r0
+ fmov.s fr6, @-r0
+ fmov.s fr5, @-r0
+ fmov.s fr4, @-r0
+ fmov.s fr3, @-r0
+ fmov.s fr2, @-r0
+ fmov.s fr1, @-r0
+ fmov.s fr0, @-r0
+
+ /* sigprocmask (SIG_BLOCK, NULL, &uc->uc_sigmask). */
+ mov r4, r6
+ /* We need 2 add instruction because oSIGMASK > 127. */
+ add #(oSIGMASK/2), r6
+ add #(oSIGMASK/2), r6
+ mov #SIG_BLOCK, r4
+ mov #0, r5
+ mov #+SYS_ify(sigprocmask), r3
+ trapa #0x13
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lgetcontext_end
+.Lsyscall_error:
+ SYSCALL_ERROR_HANDLER
+.Lgetcontext_end:
+ /* All done, return 0 for success. */
+ mov #0, r0
+.Lpseudo_end:
+ rts
+ nop
+
+PSEUDO_END(__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh4/register-dump.h b/libc/sysdeps/unix/sysv/linux/sh/sh4/register-dump.h
new file mode 100644
index 000000000..d09ad2a37
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh4/register-dump.h
@@ -0,0 +1,262 @@
+/* Dump registers.
+ Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/uio.h>
+#include <stdio-common/_itoa.h>
+
+/* We will print the register dump in this format:
+
+ R0: XXXXXXXX R1: XXXXXXXX R2: XXXXXXXX R3: XXXXXXXX
+ R4: XXXXXXXX R5: XXXXXXXX R6: XXXXXXXX R7: XXXXXXXX
+ R8: XXXXXXXX R9: XXXXXXXX R10: XXXXXXXX R11: XXXXXXXX
+ R12: XXXXXXXX R13: XXXXXXXX R14: XXXXXXXX R15: XXXXXXXX
+
+MACL: XXXXXXXX MACH: XXXXXXXX
+
+ PC: XXXXXXXX PR: XXXXXXXX GBR: XXXXXXXX SR: XXXXXXXX
+
+ FR0: XXXXXXXX FR1: XXXXXXXX FR2: XXXXXXXX FR3: XXXXXXXX
+ FR4: XXXXXXXX FR5: XXXXXXXX FR6: XXXXXXXX FR7: XXXXXXXX
+ FR8: XXXXXXXX FR9: XXXXXXXX FR10: XXXXXXXX FR11: XXXXXXXX
+FR12: XXXXXXXX FR13: XXXXXXXX FR14: XXXXXXXX FR15: XXXXXXXX
+
+ XR0: XXXXXXXX XR1: XXXXXXXX XR2: XXXXXXXX XR3: XXXXXXXX
+ XR4: XXXXXXXX XR5: XXXXXXXX XR6: XXXXXXXX XR7: XXXXXXXX
+ XR8: XXXXXXXX XR9: XXXXXXXX XR10: XXXXXXXX XR11: XXXXXXXX
+XR12: XXXXXXXX XR13: XXXXXXXX XR14: XXXXXXXX XR15: XXXXXXXX
+
+FPSCR: XXXXXXXX FPUL: XXXXXXXX
+
+ */
+
+static void
+hexvalue (unsigned long int value, char *buf, size_t len)
+{
+ char *cp = _itoa_word (value, buf + len, 16, 0);
+ while (cp > buf)
+ *--cp = '0';
+}
+
+static void
+register_dump (int fd, struct sigcontext *ctx)
+{
+ char regs[22][8];
+ char fpregs[34][8];
+ struct iovec iov[112];
+ size_t nr = 0;
+
+#define ADD_STRING(str) \
+ iov[nr].iov_base = (char *) str; \
+ iov[nr].iov_len = strlen (str); \
+ ++nr
+#define ADD_MEM(str, len) \
+ iov[nr].iov_base = str; \
+ iov[nr].iov_len = len; \
+ ++nr
+
+ /* Generate strings of register contents. */
+ hexvalue (ctx->sc_regs[0], regs[0], 8);
+ hexvalue (ctx->sc_regs[1], regs[1], 8);
+ hexvalue (ctx->sc_regs[2], regs[2], 8);
+ hexvalue (ctx->sc_regs[3], regs[3], 8);
+ hexvalue (ctx->sc_regs[4], regs[4], 8);
+ hexvalue (ctx->sc_regs[5], regs[5], 8);
+ hexvalue (ctx->sc_regs[6], regs[6], 8);
+ hexvalue (ctx->sc_regs[7], regs[7], 8);
+ hexvalue (ctx->sc_regs[8], regs[8], 8);
+ hexvalue (ctx->sc_regs[9], regs[9], 8);
+ hexvalue (ctx->sc_regs[10], regs[10], 8);
+ hexvalue (ctx->sc_regs[11], regs[11], 8);
+ hexvalue (ctx->sc_regs[12], regs[12], 8);
+ hexvalue (ctx->sc_regs[13], regs[13], 8);
+ hexvalue (ctx->sc_regs[14], regs[14], 8);
+ hexvalue (ctx->sc_regs[15], regs[15], 8);
+ hexvalue (ctx->sc_macl, regs[16], 8);
+ hexvalue (ctx->sc_mach, regs[17], 8);
+ hexvalue (ctx->sc_pc, regs[18], 8);
+ hexvalue (ctx->sc_pr, regs[19], 8);
+ hexvalue (ctx->sc_gbr, regs[20], 8);
+ hexvalue (ctx->sc_sr, regs[21], 8);
+
+ /* Generate the output. */
+ ADD_STRING ("Register dump:\n\n R0: ");
+ ADD_MEM (regs[0], 8);
+ ADD_STRING (" R1: ");
+ ADD_MEM (regs[1], 8);
+ ADD_STRING (" R2: ");
+ ADD_MEM (regs[2], 8);
+ ADD_STRING (" R3: ");
+ ADD_MEM (regs[3], 8);
+ ADD_STRING ("\n R4: ");
+ ADD_MEM (regs[4], 8);
+ ADD_STRING (" R5: ");
+ ADD_MEM (regs[5], 8);
+ ADD_STRING (" R6: ");
+ ADD_MEM (regs[6], 8);
+ ADD_STRING (" R7: ");
+ ADD_MEM (regs[7], 8);
+ ADD_STRING ("\n R8: ");
+ ADD_MEM (regs[8], 8);
+ ADD_STRING (" R9: ");
+ ADD_MEM (regs[9], 8);
+ ADD_STRING (" R10: ");
+ ADD_MEM (regs[10], 8);
+ ADD_STRING (" R11: ");
+ ADD_MEM (regs[11], 8);
+ ADD_STRING ("\n R12: ");
+ ADD_MEM (regs[12], 8);
+ ADD_STRING (" R13: ");
+ ADD_MEM (regs[13], 8);
+ ADD_STRING (" R14: ");
+ ADD_MEM (regs[14], 8);
+ ADD_STRING (" R15: ");
+ ADD_MEM (regs[15], 8);
+
+ ADD_STRING ("\n\nMACL: ");
+ ADD_MEM (regs[16], 8);
+ ADD_STRING (" MACH: ");
+ ADD_MEM (regs[17], 8);
+
+ ADD_STRING ("\n\n PC: ");
+ ADD_MEM (regs[18], 8);
+ ADD_STRING (" PR: ");
+ ADD_MEM (regs[19], 8);
+ ADD_STRING (" GBR: ");
+ ADD_MEM (regs[20], 8);
+ ADD_STRING (" SR: ");
+ ADD_MEM (regs[21], 8);
+
+ ADD_STRING ("\n");
+
+ if (ctx->sc_ownedfp != NULL)
+ {
+ hexvalue (ctx->sc_fpregs[0], fpregs[0], 8);
+ hexvalue (ctx->sc_fpregs[1], fpregs[1], 8);
+ hexvalue (ctx->sc_fpregs[2], fpregs[2], 8);
+ hexvalue (ctx->sc_fpregs[3], fpregs[3], 8);
+ hexvalue (ctx->sc_fpregs[4], fpregs[4], 8);
+ hexvalue (ctx->sc_fpregs[5], fpregs[5], 8);
+ hexvalue (ctx->sc_fpregs[6], fpregs[6], 8);
+ hexvalue (ctx->sc_fpregs[7], fpregs[7], 8);
+ hexvalue (ctx->sc_fpregs[8], fpregs[8], 8);
+ hexvalue (ctx->sc_fpregs[9], fpregs[9], 8);
+ hexvalue (ctx->sc_fpregs[10], fpregs[10], 8);
+ hexvalue (ctx->sc_fpregs[11], fpregs[11], 8);
+ hexvalue (ctx->sc_fpregs[12], fpregs[12], 8);
+ hexvalue (ctx->sc_fpregs[13], fpregs[13], 8);
+ hexvalue (ctx->sc_fpregs[14], fpregs[14], 8);
+ hexvalue (ctx->sc_fpregs[15], fpregs[15], 8);
+ hexvalue (ctx->sc_xfpregs[0], fpregs[16], 8);
+ hexvalue (ctx->sc_xfpregs[1], fpregs[17], 8);
+ hexvalue (ctx->sc_xfpregs[2], fpregs[18], 8);
+ hexvalue (ctx->sc_xfpregs[3], fpregs[19], 8);
+ hexvalue (ctx->sc_xfpregs[4], fpregs[20], 8);
+ hexvalue (ctx->sc_xfpregs[5], fpregs[21], 8);
+ hexvalue (ctx->sc_xfpregs[6], fpregs[22], 8);
+ hexvalue (ctx->sc_xfpregs[7], fpregs[23], 8);
+ hexvalue (ctx->sc_xfpregs[8], fpregs[24], 8);
+ hexvalue (ctx->sc_xfpregs[9], fpregs[25], 8);
+ hexvalue (ctx->sc_xfpregs[10], fpregs[26], 8);
+ hexvalue (ctx->sc_xfpregs[11], fpregs[27], 8);
+ hexvalue (ctx->sc_xfpregs[12], fpregs[28], 8);
+ hexvalue (ctx->sc_xfpregs[13], fpregs[29], 8);
+ hexvalue (ctx->sc_xfpregs[14], fpregs[30], 8);
+ hexvalue (ctx->sc_xfpregs[15], fpregs[31], 8);
+ hexvalue (ctx->sc_fpscr, fpregs[32], 8);
+ hexvalue (ctx->sc_fpul, fpregs[33], 8);
+
+ ADD_STRING ("\n\n FR0: ");
+ ADD_MEM (fpregs[0], 8);
+ ADD_STRING (" FR1: ");
+ ADD_MEM (fpregs[1], 8);
+ ADD_STRING (" FR2: ");
+ ADD_MEM (fpregs[2], 8);
+ ADD_STRING (" FR3: ");
+ ADD_MEM (fpregs[3], 8);
+ ADD_STRING ("\n FR4: ");
+ ADD_MEM (fpregs[4], 8);
+ ADD_STRING (" FR5: ");
+ ADD_MEM (fpregs[5], 8);
+ ADD_STRING (" FR6: ");
+ ADD_MEM (fpregs[6], 8);
+ ADD_STRING (" FR7: ");
+ ADD_MEM (fpregs[7], 8);
+ ADD_STRING ("\n FR8: ");
+ ADD_MEM (fpregs[8], 8);
+ ADD_STRING (" FR9: ");
+ ADD_MEM (fpregs[9], 8);
+ ADD_STRING (" FR10: ");
+ ADD_MEM (fpregs[10], 8);
+ ADD_STRING (" FR11: ");
+ ADD_MEM (fpregs[11], 8);
+ ADD_STRING ("\nFR12: ");
+ ADD_MEM (fpregs[12], 8);
+ ADD_STRING (" FR13: ");
+ ADD_MEM (fpregs[13], 8);
+ ADD_STRING (" FR14: ");
+ ADD_MEM (fpregs[14], 8);
+ ADD_STRING (" FR15: ");
+ ADD_MEM (fpregs[15], 8);
+ ADD_STRING ("\n\n XR0: ");
+ ADD_MEM (fpregs[16], 8);
+ ADD_STRING (" XR1: ");
+ ADD_MEM (fpregs[17], 8);
+ ADD_STRING (" XR2: ");
+ ADD_MEM (fpregs[18], 8);
+ ADD_STRING (" XR3: ");
+ ADD_MEM (fpregs[19], 8);
+ ADD_STRING ("\n XR4: ");
+ ADD_MEM (fpregs[20], 8);
+ ADD_STRING (" XR5: ");
+ ADD_MEM (fpregs[21], 8);
+ ADD_STRING (" XR6: ");
+ ADD_MEM (fpregs[22], 8);
+ ADD_STRING (" XR7: ");
+ ADD_MEM (fpregs[23], 8);
+ ADD_STRING ("\n XR8: ");
+ ADD_MEM (fpregs[24], 8);
+ ADD_STRING (" XR9: ");
+ ADD_MEM (fpregs[25], 8);
+ ADD_STRING (" XR10: ");
+ ADD_MEM (fpregs[26], 8);
+ ADD_STRING (" XR11: ");
+ ADD_MEM (fpregs[27], 8);
+ ADD_STRING ("\nXR12: ");
+ ADD_MEM (fpregs[28], 8);
+ ADD_STRING (" XR13: ");
+ ADD_MEM (fpregs[29], 8);
+ ADD_STRING (" XR14: ");
+ ADD_MEM (fpregs[30], 8);
+ ADD_STRING (" XR15: ");
+ ADD_MEM (fpregs[31], 8);
+
+ ADD_STRING ("\n\nFPSCR: ");
+ ADD_MEM (fpregs[32], 8);
+ ADD_STRING (" FPUL: ");
+ ADD_MEM (fpregs[33], 8);
+
+ ADD_STRING ("\n");
+ }
+
+ /* Write the stuff out. */
+ writev (fd, iov, nr);
+}
+
+
+#define REGISTER_DUMP register_dump (fd, &ctx)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh4/setcontext.S b/libc/sysdeps/unix/sysv/linux/sh/sh4/setcontext.S
new file mode 100644
index 000000000..2bc546d1a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh4/setcontext.S
@@ -0,0 +1,139 @@
+/* Install given context.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+/* int __setcontext (const ucontext_t *uc); */
+
+ .text
+ .align 5
+ENTRY(__setcontext)
+
+ mov r4, r8
+
+ /* sigprocmask (SIG_SETMASK, &uc->uc_sigmask, NULL). */
+ mov r4, r5
+ add #(oSIGMASK/2), r5
+ add #(oSIGMASK/2), r5
+ mov #SIG_SETMASK, r4
+ mov #0, r6
+ mov #+SYS_ify(sigprocmask), r3
+ trapa #0x13
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lsetcontext_restore
+.Lsyscall_error:
+ SYSCALL_ERROR_HANDLER
+.Lpseudo_end:
+ rts
+ nop
+
+.Lsetcontext_restore:
+ mov r8, r0
+ add #(oFR0),r0
+ fmov.s @r0+, fr0
+ fmov.s @r0+, fr1
+ fmov.s @r0+, fr2
+ fmov.s @r0+, fr3
+ fmov.s @r0+, fr4
+ fmov.s @r0+, fr5
+ fmov.s @r0+, fr6
+ fmov.s @r0+, fr7
+ fmov.s @r0+, fr8
+ fmov.s @r0+, fr9
+ fmov.s @r0+, fr10
+ fmov.s @r0+, fr11
+ fmov.s @r0+, fr12
+ fmov.s @r0+, fr13
+ fmov.s @r0+, fr14
+ fmov.s @r0+, fr15
+ frchg
+ fmov.s @r0+, fr0
+ fmov.s @r0+, fr1
+ fmov.s @r0+, fr2
+ fmov.s @r0+, fr3
+ fmov.s @r0+, fr4
+ fmov.s @r0+, fr5
+ fmov.s @r0+, fr6
+ fmov.s @r0+, fr7
+ fmov.s @r0+, fr8
+ fmov.s @r0+, fr9
+ fmov.s @r0+, fr10
+ fmov.s @r0+, fr11
+ fmov.s @r0+, fr12
+ fmov.s @r0+, fr13
+ fmov.s @r0+, fr14
+ fmov.s @r0+, fr15
+ frchg
+ lds.l @r0+, fpscr
+ lds.l @r0+, fpul
+
+ mov r8, r0
+ add #(oPC), r0
+ mov.l @r0+, r2
+ lds.l @r0+, pr
+
+ /* Restore T frag. */
+ mov.l @r0+, r1
+ shlr r1
+ /* Skip GBR which is used for thread pointer. */
+ add #4, r0
+
+ lds.l @r0+, mach
+ lds.l @r0+, macl
+
+ mov r8, r0
+ add #(oR9), r0
+ mov.l @r0+, r9
+ mov.l @r0+, r10
+ mov.l @r0+, r11
+ mov.l @r0+, r12
+ mov.l @r0+, r13
+ mov.l @r0+, r14
+ mov.l @r0+, r15
+
+ mov r8, r0
+ mov.l @(oR0,r0), r1
+ mov.l r1, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r1, 0)
+ mov.l r2, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r2, 0)
+
+ mov.l @(oR1,r0), r1
+ mov.l @(oR2,r0), r2
+ mov.l @(oR3,r0), r3
+ mov.l @(oR4,r0), r4
+ mov.l @(oR5,r0), r5
+ mov.l @(oR6,r0), r6
+ mov.l @(oR7,r0), r7
+ mov.l @(oR8,r0), r8
+ mov.l @r15+, r0
+ jmp @r0
+ mov.l @r15+, r0
+
+PSEUDO_END(__setcontext)
+
+weak_alias (__setcontext, setcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh4/swapcontext.S b/libc/sysdeps/unix/sysv/linux/sh/sh4/swapcontext.S
new file mode 100644
index 000000000..1aeca1b1a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh4/swapcontext.S
@@ -0,0 +1,214 @@
+/* Save current context and install the given one.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+/* int __swapcontext (ucontext_t *ouc, const ucontext_t *uc); */
+
+ .text
+ .align 5
+ENTRY(__swapcontext)
+
+ /* Return value of getcontext. R0 is the only register whose
+ value is not preserved. */
+ mov #0, r0
+ mov.l r0, @(oR0,r4)
+ mov.l r1, @(oR1,r4)
+ mov.l r2, @(oR2,r4)
+ mov.l r3, @(oR3,r4)
+ mov.l r4, @(oR4,r4)
+ mov.l r5, @(oR5,r4)
+ mov.l r6, @(oR6,r4)
+ mov.l r7, @(oR7,r4)
+ mov r4, r0
+ add #(oMACL+4), r0
+ sts.l macl, @-r0
+ sts.l mach, @-r0
+ stc.l gbr, @-r0
+
+ /* Save T flag to SR. */
+ movt r1
+ mov.l r1, @-r0
+ sts.l pr, @-r0
+
+ /* The return address of getcontext is the restart pc. */
+ sts.l pr, @-r0
+
+ mov.l r15, @-r0
+ mov.l r14, @-r0
+ mov.l r13, @-r0
+ mov.l r12, @-r0
+ mov.l r11, @-r0
+ mov.l r10, @-r0
+ mov.l r9, @-r0
+ mov.l r8, @-r0
+
+ mov r4, r0
+ /* We need 2 add instruction because oFPUL+4 >= 127. */
+ add #124,r0
+ add #(oFPUL+4-124),r0
+ sts.l fpul, @-r0
+ sts.l fpscr, @-r0
+ frchg
+ fmov.s fr15, @-r0
+ fmov.s fr14, @-r0
+ fmov.s fr13, @-r0
+ fmov.s fr12, @-r0
+ fmov.s fr11, @-r0
+ fmov.s fr10, @-r0
+ fmov.s fr9, @-r0
+ fmov.s fr8, @-r0
+ fmov.s fr7, @-r0
+ fmov.s fr6, @-r0
+ fmov.s fr5, @-r0
+ fmov.s fr4, @-r0
+ fmov.s fr3, @-r0
+ fmov.s fr2, @-r0
+ fmov.s fr1, @-r0
+ fmov.s fr0, @-r0
+ frchg
+ fmov.s fr15, @-r0
+ fmov.s fr14, @-r0
+ fmov.s fr13, @-r0
+ fmov.s fr12, @-r0
+ fmov.s fr11, @-r0
+ fmov.s fr10, @-r0
+ fmov.s fr9, @-r0
+ fmov.s fr8, @-r0
+ fmov.s fr7, @-r0
+ fmov.s fr6, @-r0
+ fmov.s fr5, @-r0
+ fmov.s fr4, @-r0
+ fmov.s fr3, @-r0
+ fmov.s fr2, @-r0
+ fmov.s fr1, @-r0
+ fmov.s fr0, @-r0
+
+ mov r5, r8
+
+ /* sigprocmask (SIG_SETMASK, &uc->uc_sigmask, &ouc->uc_sigmask). */
+ mov #oSIGMASK, r1
+ extu.b r1, r1
+ add r1, r5
+ mov r4, r6
+ add r1, r6
+ mov #SIG_SETMASK, r4
+ mov #+SYS_ify(sigprocmask), r3
+ trapa #0x13
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lswapcontext_restore
+.Lsyscall_error:
+ SYSCALL_ERROR_HANDLER
+.Lpseudo_end:
+ rts
+ nop
+.Lswapcontext_restore:
+ mov r8, r0
+ add #(oFR0),r0
+ fmov.s @r0+, fr0
+ fmov.s @r0+, fr1
+ fmov.s @r0+, fr2
+ fmov.s @r0+, fr3
+ fmov.s @r0+, fr4
+ fmov.s @r0+, fr5
+ fmov.s @r0+, fr6
+ fmov.s @r0+, fr7
+ fmov.s @r0+, fr8
+ fmov.s @r0+, fr9
+ fmov.s @r0+, fr10
+ fmov.s @r0+, fr11
+ fmov.s @r0+, fr12
+ fmov.s @r0+, fr13
+ fmov.s @r0+, fr14
+ fmov.s @r0+, fr15
+ frchg
+ fmov.s @r0+, fr0
+ fmov.s @r0+, fr1
+ fmov.s @r0+, fr2
+ fmov.s @r0+, fr3
+ fmov.s @r0+, fr4
+ fmov.s @r0+, fr5
+ fmov.s @r0+, fr6
+ fmov.s @r0+, fr7
+ fmov.s @r0+, fr8
+ fmov.s @r0+, fr9
+ fmov.s @r0+, fr10
+ fmov.s @r0+, fr11
+ fmov.s @r0+, fr12
+ fmov.s @r0+, fr13
+ fmov.s @r0+, fr14
+ fmov.s @r0+, fr15
+ frchg
+ lds.l @r0+, fpscr
+ lds.l @r0+, fpul
+
+ mov r8, r0
+ add #(oPC), r0
+ mov.l @r0+, r2
+ lds.l @r0+, pr
+
+ /* Restore T frag. */
+ mov.l @r0+, r1
+ shlr r1
+ /* Skip GBR which is used for thread pointer. */
+ add #4, r0
+
+ lds.l @r0+, mach
+ lds.l @r0+, macl
+
+ mov r8, r0
+ add #(oR9), r0
+ mov.l @r0+, r9
+ mov.l @r0+, r10
+ mov.l @r0+, r11
+ mov.l @r0+, r12
+ mov.l @r0+, r13
+ mov.l @r0+, r14
+ mov.l @r0+, r15
+
+ mov r8, r0
+ mov.l @(oR0,r0), r1
+ mov.l r1, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r1, 0)
+ mov.l r2, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r2, 0)
+
+ mov.l @(oR1,r0), r1
+ mov.l @(oR2,r0), r2
+ mov.l @(oR3,r0), r3
+ mov.l @(oR4,r0), r4
+ mov.l @(oR5,r0), r5
+ mov.l @(oR6,r0), r6
+ mov.l @(oR7,r0), r7
+ mov.l @(oR8,r0), r8
+ mov.l @r15+, r0
+ jmp @r0
+ mov.l @r15+, r0
+
+PSEUDO_END(__swapcontext)
+
+weak_alias (__swapcontext, swapcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh4/sys/ucontext.h b/libc/sysdeps/unix/sysv/linux/sh/sh4/sys/ucontext.h
new file mode 100644
index 000000000..cd831a7a2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh4/sys/ucontext.h
@@ -0,0 +1,115 @@
+/* Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Where is System V/SH ABI? */
+
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+
+#include <features.h>
+#include <signal.h>
+
+/* We need the signal context definitions even if they are not used
+ included in <signal.h>. */
+#include <bits/sigcontext.h>
+
+
+typedef int greg_t;
+
+/* Number of general registers. */
+#define NFPREG 16
+
+/* Container for all general registers. */
+typedef greg_t gregset_t[NFPREG];
+
+#ifdef __USE_GNU
+/* Number of each register is the `gregset_t' array. */
+enum
+{
+ R0 = 0,
+#define R0 R0
+ R1 = 1,
+#define R1 R1
+ R2 = 2,
+#define R2 R2
+ R3 = 3,
+#define R3 R3
+ R4 = 4,
+#define R4 R4
+ R5 = 5,
+#define R5 R5
+ R6 = 6,
+#define R6 R6
+ R7 = 7,
+#define R7 R7
+ R8 = 8,
+#define R8 R8
+ R9 = 9,
+#define R9 R9
+ R10 = 10,
+#define R10 R10
+ R11 = 11,
+#define R11 R11
+ R12 = 12,
+#define R12 R12
+ R13 = 13,
+#define R13 R13
+ R14 = 14,
+#define R14 R14
+ R15 = 15,
+#define R15 R15
+};
+#endif
+
+typedef int freg_t;
+
+/* Number of FPU registers. */
+#define NFPREG 16
+
+/* Structure to describe FPU registers. */
+typedef freg_t fpregset_t[NFPREG];
+
+/* Context to describe whole processor state. */
+typedef struct
+ {
+ unsigned int oldmask;
+ gregset_t gregs;
+ unsigned int pc;
+ unsigned int pr;
+ unsigned int sr;
+ unsigned int gbr;
+ unsigned int mach;
+ unsigned int macl;
+ fpregset_t fpregs;
+ fpregset_t xfpregs;
+ unsigned int fpscr;
+ unsigned int fpul;
+ unsigned int ownedfp;
+ } mcontext_t;
+
+/* Userlevel context. */
+typedef struct ucontext
+ {
+ unsigned long int uc_flags;
+ struct ucontext *uc_link;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ __sigset_t uc_sigmask;
+ } ucontext_t;
+
+#endif /* sys/ucontext.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh4/sysdep.h b/libc/sysdeps/unix/sysv/linux/sh/sh4/sysdep.h
new file mode 100644
index 000000000..852f8eed7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh4/sysdep.h
@@ -0,0 +1,4 @@
+/* 4 instruction cycles not accessing cache and TLB are needed after
+ trapa instruction to avoid an SH-4 silicon bug. */
+#define NEED_SYSCALL_INST_PAD
+#include <sysdeps/unix/sysv/linux/sh/sysdep.h>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym b/libc/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym
new file mode 100644
index 000000000..65633fbcf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym
@@ -0,0 +1,73 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+--
+
+SIG_BLOCK
+SIG_SETMASK
+
+#define ucontext(member) offsetof (ucontext_t, member)
+#define mcontext(member) ucontext (uc_mcontext.member)
+
+oLINK ucontext (uc_link)
+oSS_SP ucontext (uc_stack.ss_sp)
+oSS_SIZE ucontext (uc_stack.ss_size)
+oR0 mcontext (gregs[R0])
+oR1 mcontext (gregs[R1])
+oR2 mcontext (gregs[R2])
+oR3 mcontext (gregs[R3])
+oR4 mcontext (gregs[R4])
+oR5 mcontext (gregs[R5])
+oR6 mcontext (gregs[R6])
+oR7 mcontext (gregs[R7])
+oR8 mcontext (gregs[R8])
+oR9 mcontext (gregs[R9])
+oR10 mcontext (gregs[R10])
+oR11 mcontext (gregs[R11])
+oR12 mcontext (gregs[R12])
+oR13 mcontext (gregs[R13])
+oR14 mcontext (gregs[R14])
+oR15 mcontext (gregs[R15])
+oPC mcontext (pc)
+oPR mcontext (pr)
+oSR mcontext (sr)
+oGBR mcontext (gbr)
+oMACH mcontext (mach)
+oMACL mcontext (macl)
+oFR0 mcontext (fpregs[0])
+oFR1 mcontext (fpregs[1])
+oFR2 mcontext (fpregs[2])
+oFR3 mcontext (fpregs[3])
+oFR4 mcontext (fpregs[4])
+oFR5 mcontext (fpregs[5])
+oFR6 mcontext (fpregs[6])
+oFR7 mcontext (fpregs[7])
+oFR8 mcontext (fpregs[8])
+oFR9 mcontext (fpregs[9])
+oFR10 mcontext (fpregs[10])
+oFR11 mcontext (fpregs[11])
+oFR12 mcontext (fpregs[12])
+oFR13 mcontext (fpregs[13])
+oFR14 mcontext (fpregs[14])
+oFR15 mcontext (fpregs[15])
+oXFR0 mcontext (xfpregs[0])
+oXFR1 mcontext (xfpregs[1])
+oXFR2 mcontext (xfpregs[2])
+oXFR3 mcontext (xfpregs[3])
+oXFR4 mcontext (xfpregs[4])
+oXFR5 mcontext (xfpregs[5])
+oXFR6 mcontext (xfpregs[6])
+oXFR7 mcontext (xfpregs[7])
+oXFR8 mcontext (xfpregs[8])
+oXFR9 mcontext (xfpregs[9])
+oXFR10 mcontext (xfpregs[10])
+oXFR11 mcontext (xfpregs[11])
+oXFR12 mcontext (xfpregs[12])
+oXFR13 mcontext (xfpregs[13])
+oXFR14 mcontext (xfpregs[14])
+oXFR15 mcontext (xfpregs[15])
+oFPSCR mcontext (fpscr)
+oFPUL mcontext (fpul)
+oOWNEDFP mcontext (ownedfp)
+oSIGMASK ucontext (uc_sigmask)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/shmctl.c b/libc/sysdeps/unix/sysv/linux/sh/shmctl.c
new file mode 100644
index 000000000..7eac6380d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/shmctl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/shmctl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sigcontextinfo.h b/libc/sysdeps/unix/sysv/linux/sh/sigcontextinfo.h
new file mode 100644
index 000000000..3e1f3e949
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sigcontextinfo.h
@@ -0,0 +1,27 @@
+/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Philip Blundell <philb@gnu.org>, 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define SIGCONTEXT int _a2, int _a3, int _a4, struct sigcontext
+
+#define SIGCONTEXT_EXTRA_ARGS _a2, _a3, _a4,
+#define GET_PC(ctx) ((void *) ctx.sc_pc)
+#define GET_FRAME(ctx) ((void *) ctx.sc_regs[14])
+#define GET_STACK(ctx) ((void *) ctx.sc_regs[15])
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
diff --git a/libc/sysdeps/unix/sysv/linux/sh/socket.S b/libc/sysdeps/unix/sysv/linux/sh/socket.S
new file mode 100644
index 000000000..c83b0f260
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/socket.S
@@ -0,0 +1,180 @@
+/* Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+#include <tls.h>
+
+#define P(a, b) P2(a, b)
+#define P2(a, b) a##b
+
+ .text
+/* The socket-oriented system calls are handled unusally in Linux.
+ They are all gated through the single `socketcall' system call number.
+ `socketcall' takes two arguments: the first is the subcode, specifying
+ which socket function is being called; and the second is a pointer to
+ the arguments to the specific function.
+
+ The .S files for the other calls just #define socket and #include this. */
+
+#ifndef __socket
+#ifndef NO_WEAK_ALIAS
+#define __socket P(__,socket)
+#else
+#define __socket socket
+#endif
+#endif
+
+#define PUSHARGS_1 mov.l r4,@-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (r4, 0)
+#define PUSHARGS_2 mov.l r5,@-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (r5, 0); \
+ PUSHARGS_1
+#define PUSHARGS_3 mov.l r6,@-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (r6, 0); \
+ PUSHARGS_2
+#define PUSHARGS_4 mov.l r7,@-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (r7, 0); \
+ PUSHARGS_3
+#define PUSHARGS_5 PUSHARGS_4 /* Caller has already pushed arg 5 */
+#define PUSHARGS_6 PUSHARGS_4 /* Caller has already pushed arg 5,6 */
+
+#define POPARGS_1 add #4,r15; cfi_adjust_cfa_offset (-4)
+#define POPARGS_2 add #8,r15; cfi_adjust_cfa_offset (-8)
+#define POPARGS_3 add #12,r15; cfi_adjust_cfa_offset (-12)
+#define POPARGS_4 add #16,r15; cfi_adjust_cfa_offset (-16)
+#define POPARGS_5 POPARGS_4
+#define POPARGS_6 POPARGS_4
+
+#define ADJUSTCFI_1 cfi_adjust_cfa_offset (4); \
+ cfi_offset (r4, -4)
+#define ADJUSTCFI_2 cfi_adjust_cfa_offset (8); \
+ cfi_offset (r4, -4); \
+ cfi_offset (r5, -8)
+#define ADJUSTCFI_3 cfi_adjust_cfa_offset (12); \
+ cfi_offset (r4, -4); \
+ cfi_offset (r5, -8); \
+ cfi_offset (r6, -12)
+#define ADJUSTCFI_4 cfi_adjust_cfa_offset (16); \
+ cfi_offset (r4, -4); \
+ cfi_offset (r5, -8); \
+ cfi_offset (r6, -12); \
+ cfi_offset (r7, -16)
+#define ADJUSTCFI_5 ADJUSTCFI_4
+#define ADJUSTCFI_6 ADJUSTCFI_4
+
+#ifndef NARGS
+/* If we were called with no wrapper, this is really socket(). */
+#define NARGS 3
+#endif
+
+.globl __socket
+ENTRY (__socket)
+ /* This will not work in the case of a socket call being interrupted
+ by a signal. If the signal handler uses any stack the arguments
+ to socket will be trashed. The results of a restart of any
+ socket call are then unpredictable. */
+
+ /* Push args onto the stack. */
+ P(PUSHARGS_,NARGS)
+
+#if defined NEED_CANCELLATION && defined CENABLE
+ SINGLE_THREAD_P
+ bf .Lsocket_cancel
+#endif
+
+ /* Do the system call trap. */
+ mov #+P(SOCKOP_,socket), r4
+ mov r15, r5
+ mov.l .L1,r3
+ trapa #0x12
+
+ /* Pop args off the stack */
+ P(POPARGS_,NARGS)
+
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lpseudo_end
+.Lsyscall_error:
+ SYSCALL_ERROR_HANDLER
+.Lpseudo_end:
+ /* Successful; return the syscall's value. */
+ rts
+ nop
+
+#if defined NEED_CANCELLATION && defined CENABLE
+.Lsocket_cancel:
+ /* Enable asynchronous cancellation. */
+ P(ADJUSTCFI_,NARGS)
+ sts.l pr,@-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (pr, 0)
+ CENABLE
+ lds.l @r15+,pr
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (pr)
+
+ /* Do the system call trap. */
+ mov #+P(SOCKOP_,socket), r4
+ mov r15, r5
+ mov.l .L1,r3
+ trapa #0x12
+
+ sts.l pr,@-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (pr, 0)
+ mov.l r0,@-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (r0, 0)
+ CDISABLE
+ mov.l @r15+,r0
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (r0)
+ lds.l @r15+,pr
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (pr)
+
+ /* Pop args off the stack */
+ P(POPARGS_,NARGS)
+
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lpseudo_end
+ bra .Lsyscall_error
+ nop
+#endif
+
+ .align 2
+.L1:
+ .long SYS_ify(socketcall)
+
+PSEUDO_END (__socket)
+
+#ifndef NO_WEAK_ALIAS
+weak_alias (__socket, socket)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sys/io.h b/libc/sysdeps/unix/sysv/linux/sh/sys/io.h
new file mode 100644
index 000000000..6fdc44ff8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sys/io.h
@@ -0,0 +1,48 @@
+/* Copyright (C) 1996, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IO_H
+
+#define _SYS_IO_H 1
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* If TURN_ON is TRUE, request for permission to do direct i/o on the
+ port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
+ permission off for that range. This call requires root privileges. */
+extern int ioperm (unsigned long int __from, unsigned long int __num,
+ int __turn_on) __THROW;
+
+/* Set the I/O privilege level to LEVEL. If LEVEL is nonzero,
+ permission to access any I/O port is granted. This call requires
+ root privileges. */
+extern int iopl (int __level) __THROW;
+
+/* The functions that actually perform reads and writes. */
+extern unsigned char inb (unsigned long int port) __THROW;
+extern unsigned short int inw (unsigned long int port) __THROW;
+extern unsigned long int inl (unsigned long int port) __THROW;
+
+extern void outb (unsigned char value, unsigned long int port) __THROW;
+extern void outw (unsigned short value, unsigned long int port) __THROW;
+extern void outl (unsigned long value, unsigned long int port) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_IO_H */
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sys/procfs.h b/libc/sysdeps/unix/sysv/linux/sh/sys/procfs.h
new file mode 100644
index 000000000..8651ccb34
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sys/procfs.h
@@ -0,0 +1,115 @@
+/* Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H 1
+
+/* This is somehow modelled after the file of the same name on SysVr4
+ systems. It provides a definition of the core file format for ELF
+ used on Linux. */
+
+#include <features.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/ucontext.h>
+#include <sys/user.h>
+#include <asm/elf.h>
+
+__BEGIN_DECLS
+
+struct elf_siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_code; /* Extra code. */
+ int si_errno; /* Errno. */
+ };
+
+/* Definitions to generate Intel SVR4-like core files. These mostly
+ have the same names as the SVR4 types with "elf_" tacked on the
+ front to prevent clashes with linux definitions, and the typedef
+ forms have been avoided. This is mostly like the SVR4 structure,
+ but more Linuxy, with things that Linux does not support and which
+ gdb doesn't really use excluded. Fields present but not used are
+ marked with "XXX". */
+struct elf_prstatus
+ {
+#if 0
+ long int pr_flags; /* XXX Process flags. */
+ short int pr_why; /* XXX Reason for process halt. */
+ short int pr_what; /* XXX More detailed reason. */
+#endif
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned long int pr_sigpend; /* Set of pending signals. */
+ unsigned long int pr_sighold; /* Set of held signals. */
+#if 0
+ struct sigaltstack pr_altstack; /* Alternate stack info. */
+ struct sigaction pr_action; /* Signal action for current sig. */
+#endif
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct timeval pr_utime; /* User time. */
+ struct timeval pr_stime; /* System time. */
+ struct timeval pr_cutime; /* Cumulative user time. */
+ struct timeval pr_cstime; /* Cumulative system time. */
+#if 0
+ long int pr_instr; /* Current instruction. */
+#endif
+ elf_gregset_t pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+
+#define ELF_PRARGSZ (80) /* Number of chars for args */
+
+struct elf_prpsinfo
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned long int pr_flag; /* Flags. */
+ unsigned short int pr_uid;
+ unsigned short int pr_gid;
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+/* Addresses. */
+typedef void *psaddr_t;
+
+/* Register sets. Linux has different names. */
+typedef elf_gregset_t prgregset_t;
+typedef elf_fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+ therefore habe only ine PID type. */
+typedef __pid_t lwpid_t;
+
+
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+__END_DECLS
+
+#endif /* sys/procfs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sys/user.h b/libc/sysdeps/unix/sysv/linux/sh/sys/user.h
new file mode 100644
index 000000000..7f31bb62d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sys/user.h
@@ -0,0 +1,28 @@
+/* Copyright (C) 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_USER_H
+#define _SYS_USER_H 1
+
+#include <features.h>
+
+#include <asm/user.h>
+
+#undef start_thread
+
+#endif /* sys/user.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sh/syscall.S b/libc/sysdeps/unix/sysv/linux/sh/syscall.S
new file mode 100644
index 000000000..afa16c2fb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/syscall.S
@@ -0,0 +1,44 @@
+/* Copyright (C) 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+ENTRY (__syscall)
+ mov r4, r3 // syscall number
+ mov r5, r4 // p1
+ mov r6, r5 // p2
+ mov r7, r6 // p3
+ mov.l @r15, r7 // p4
+ mov.l @(4,r15), r0 // p5
+ mov.l @(8,r15), r1 // p6
+ mov.l @(12,r15), r2 // p7
+ trapa #0x17
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lpseudo_end
+ SYSCALL_ERROR_HANDLER
+.Lpseudo_end:
+ rts
+ nop
+
+PSEUDO_END (__syscall)
+
+weak_alias (__syscall, syscall)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/syscalls.list b/libc/sysdeps/unix/sysv/linux/sh/syscalls.list
new file mode 100644
index 000000000..a6665936e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/syscalls.list
@@ -0,0 +1,3 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+waitpid - waitpid Ci:ipi __waitpid waitpid __libc_waitpid
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sysdep.S b/libc/sysdeps/unix/sysv/linux/sh/sysdep.S
new file mode 100644
index 000000000..176d99aab
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sysdep.S
@@ -0,0 +1,34 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* The syscall stubs jump here when they detect an error.
+ The code for Linux is almost identical to the canonical Unix
+ code, except that the error number in R0 is negated. */
+
+#undef CALL_MCOUNT
+#define CALL_MCOUNT /* Don't insert the profiling call, it clobbers R0. */
+
+ENTRY (__syscall_error)
+ neg r4, r0
+ cfi_endproc
+
+#define __syscall_error __syscall_error_1
+#include <sysdeps/unix/sh/sysdep.S>
diff --git a/libc/sysdeps/unix/sysv/linux/sh/sysdep.h b/libc/sysdeps/unix/sysv/linux/sh/sysdep.h
new file mode 100644
index 000000000..f0be37edc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/sysdep.h
@@ -0,0 +1,391 @@
+/* Copyright (C) 1992,1993,1995,1996,1997,1998,1999,2000,2002,2003,2004,
+ 2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>, August 1995.
+ Changed by Kaz Kojima, <kkojima@rr.iij4u.or.jp>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_SH_SYSDEP_H
+#define _LINUX_SH_SYSDEP_H 1
+
+/* There is some commonality. */
+#include <sysdeps/unix/sh/sysdep.h>
+#include <tls.h>
+
+/* For Linux we can use the system call table in the header file
+ /usr/include/asm/unistd.h
+ of the kernel. But these symbols do not follow the SYS_* syntax
+ so we have to redefine the `SYS_ify' macro here. */
+#undef SYS_ify
+#define SYS_ify(syscall_name) (__NR_##syscall_name)
+
+
+#ifdef __ASSEMBLER__
+
+/* Linux uses a negative return value to indicate syscall errors,
+ unlike most Unices, which use the condition codes' carry flag.
+
+ Since version 2.1 the return value of a system call might be
+ negative even if the call succeeded. E.g., the `lseek' system call
+ might return a large offset. Therefore we must not anymore test
+ for < 0, but test for a real error by making sure the value in R0
+ is a real error number. Linus said he will make sure the no syscall
+ returns a value in -1 .. -4095 as a valid result so we can savely
+ test with -4095. */
+
+#define _IMM1 #-1
+#define _IMM12 #-12
+#undef PSEUDO
+#define PSEUDO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name); \
+ DO_CALL (syscall_name, args); \
+ mov r0,r1; \
+ mov _IMM12,r2; \
+ shad r2,r1; \
+ not r1,r1; \
+ tst r1,r1; \
+ bf .Lpseudo_end; \
+ SYSCALL_ERROR_HANDLER; \
+ .Lpseudo_end:
+
+#undef PSEUDO_END
+#define PSEUDO_END(name) \
+ END (name)
+
+#undef PSEUDO_NOERRNO
+#define PSEUDO_NOERRNO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name); \
+ DO_CALL (syscall_name, args)
+
+#undef PSEUDO_END_NOERRNO
+#define PSEUDO_END_NOERRNO(name) \
+ END (name)
+
+#define ret_NOERRNO ret
+
+#define PSEUDO_ERRVAL(name, syscall_name, args) \
+ .text; \
+ ENTRY (name); \
+ DO_CALL (syscall_name, args);
+
+#undef PSEUDO_END_ERRVAL
+#define PSEUDO_END_ERRVAL(name) \
+ END (name)
+
+#define ret_ERRVAL ret
+
+#ifndef PIC
+# define SYSCALL_ERROR_HANDLER \
+ mov.l 0f,r1; \
+ jmp @r1; \
+ mov r0,r4; \
+ .align 2; \
+ 0: .long __syscall_error
+#else
+# if RTLD_PRIVATE_ERRNO
+# define SYSCALL_ERROR_HANDLER \
+ neg r0,r1; \
+ mov.l 0f,r12; \
+ mova 0f,r0; \
+ add r0,r12; \
+ mov.l 1f,r0; \
+ mov.l r1,@(r0,r12); \
+ bra .Lpseudo_end; \
+ mov _IMM1,r0; \
+ .align 2; \
+ 0: .long _GLOBAL_OFFSET_TABLE_; \
+ 1: .long rtld_errno@GOTOFF
+
+# elif defined _LIBC_REENTRANT
+
+# if USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+# define SYSCALL_ERROR_ERRNO errno
+# endif
+# define SYSCALL_ERROR_HANDLER \
+ neg r0,r1; \
+ mov r12,r2; \
+ mov.l 0f,r12; \
+ mova 0f,r0; \
+ add r0,r12; \
+ mov.l 1f,r0; \
+ stc gbr, r4; \
+ mov.l @(r0,r12),r0; \
+ mov r2,r12; \
+ add r4,r0; \
+ mov.l r1,@r0; \
+ bra .Lpseudo_end; \
+ mov _IMM1,r0; \
+ .align 2; \
+ 0: .long _GLOBAL_OFFSET_TABLE_; \
+ 1: .long SYSCALL_ERROR_ERRNO@GOTTPOFF
+# else
+# define SYSCALL_ERROR_HANDLER \
+ neg r0,r1; \
+ mov.l r14,@-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (r14, 0); \
+ mov.l r12,@-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (r12, 0); \
+ mov.l r1,@-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (r1, 0); \
+ mov.l 0f,r12; \
+ mova 0f,r0; \
+ add r0,r12; \
+ sts.l pr,@-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (pr, 0); \
+ mov r15,r14; \
+ cfi_def_cfa_register (r14); \
+ mov.l 1f,r1; \
+ bsrf r1; \
+ nop; \
+ 2: mov r14,r15; \
+ lds.l @r15+,pr; \
+ mov.l @r15+,r1; \
+ mov.l r1,@r0; \
+ mov.l @r15+,r12; \
+ mov.l @r15+,r14; \
+ bra .Lpseudo_end; \
+ mov _IMM1,r0; \
+ .align 2; \
+ 0: .long _GLOBAL_OFFSET_TABLE_; \
+ 1: .long PLTJMP(C_SYMBOL_NAME(__errno_location))-(2b-.)
+/* A quick note: it is assumed that the call to `__errno_location' does
+ not modify the stack! */
+# endif
+# else
+/* Store (-r0) into errno through the GOT. */
+# define SYSCALL_ERROR_HANDLER \
+ neg r0,r1; \
+ mov r12,r2; \
+ mov.l 0f,r12; \
+ mova 0f,r0; \
+ add r0,r12; \
+ mov.l 1f,r0; \
+ mov.l @(r0,r12),r0; \
+ mov r2,r12; \
+ mov.l r1,@r0; \
+ bra .Lpseudo_end; \
+ mov _IMM1,r0; \
+ .align 2; \
+ 0: .long _GLOBAL_OFFSET_TABLE_; \
+ 1: .long errno@GOT
+# endif /* _LIBC_REENTRANT */
+#endif /* PIC */
+
+# ifdef NEED_SYSCALL_INST_PAD
+# define SYSCALL_INST_PAD \
+ or r0,r0; or r0,r0; or r0,r0; or r0,r0; or r0,r0
+# else
+# define SYSCALL_INST_PAD
+# endif
+
+#define SYSCALL_INST0 trapa #0x10
+#define SYSCALL_INST1 trapa #0x11
+#define SYSCALL_INST2 trapa #0x12
+#define SYSCALL_INST3 trapa #0x13
+#define SYSCALL_INST4 trapa #0x14
+#define SYSCALL_INST5 mov.l @(0,r15),r0; trapa #0x15
+#define SYSCALL_INST6 mov.l @(0,r15),r0; mov.l @(4,r15),r1; trapa #0x16
+
+#undef DO_CALL
+#define DO_CALL(syscall_name, args) \
+ mov.l 1f,r3; \
+ SYSCALL_INST##args; \
+ SYSCALL_INST_PAD; \
+ bra 2f; \
+ nop; \
+ .align 2; \
+ 1: .long SYS_ify (syscall_name); \
+ 2:
+
+#else /* not __ASSEMBLER__ */
+
+#define SYSCALL_INST_STR0 "trapa #0x10\n\t"
+#define SYSCALL_INST_STR1 "trapa #0x11\n\t"
+#define SYSCALL_INST_STR2 "trapa #0x12\n\t"
+#define SYSCALL_INST_STR3 "trapa #0x13\n\t"
+#define SYSCALL_INST_STR4 "trapa #0x14\n\t"
+#define SYSCALL_INST_STR5 "trapa #0x15\n\t"
+#define SYSCALL_INST_STR6 "trapa #0x16\n\t"
+
+# ifdef NEED_SYSCALL_INST_PAD
+# define SYSCALL_INST_PAD "\
+ or r0,r0; or r0,r0; or r0,r0; or r0,r0; or r0,r0"
+# else
+# define SYSCALL_INST_PAD
+# endif
+
+#define ASMFMT_0
+#define ASMFMT_1 \
+ , "r" (r4)
+#define ASMFMT_2 \
+ , "r" (r4), "r" (r5)
+#define ASMFMT_3 \
+ , "r" (r4), "r" (r5), "r" (r6)
+#define ASMFMT_4 \
+ , "r" (r4), "r" (r5), "r" (r6), "r" (r7)
+#define ASMFMT_5 \
+ , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0)
+#define ASMFMT_6 \
+ , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1)
+#define ASMFMT_7 \
+ , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1), "r" (r2)
+
+#define SUBSTITUTE_ARGS_0()
+#define SUBSTITUTE_ARGS_1(arg1) \
+ long int _arg1 = (long int) (arg1); \
+ register long int r4 asm ("%r4") = (long int) (_arg1)
+#define SUBSTITUTE_ARGS_2(arg1, arg2) \
+ long int _arg1 = (long int) (arg1); \
+ long int _arg2 = (long int) (arg2); \
+ register long int r4 asm ("%r4") = (long int) (_arg1); \
+ register long int r5 asm ("%r5") = (long int) (_arg2)
+#define SUBSTITUTE_ARGS_3(arg1, arg2, arg3) \
+ long int _arg1 = (long int) (arg1); \
+ long int _arg2 = (long int) (arg2); \
+ long int _arg3 = (long int) (arg3); \
+ register long int r4 asm ("%r4") = (long int) (_arg1); \
+ register long int r5 asm ("%r5") = (long int) (_arg2); \
+ register long int r6 asm ("%r6") = (long int) (_arg3)
+#define SUBSTITUTE_ARGS_4(arg1, arg2, arg3, arg4) \
+ long int _arg1 = (long int) (arg1); \
+ long int _arg2 = (long int) (arg2); \
+ long int _arg3 = (long int) (arg3); \
+ long int _arg4 = (long int) (arg4); \
+ register long int r4 asm ("%r4") = (long int) (_arg1); \
+ register long int r5 asm ("%r5") = (long int) (_arg2); \
+ register long int r6 asm ("%r6") = (long int) (_arg3); \
+ register long int r7 asm ("%r7") = (long int) (_arg4)
+#define SUBSTITUTE_ARGS_5(arg1, arg2, arg3, arg4, arg5) \
+ long int _arg1 = (long int) (arg1); \
+ long int _arg2 = (long int) (arg2); \
+ long int _arg3 = (long int) (arg3); \
+ long int _arg4 = (long int) (arg4); \
+ long int _arg5 = (long int) (arg5); \
+ register long int r4 asm ("%r4") = (long int) (_arg1); \
+ register long int r5 asm ("%r5") = (long int) (_arg2); \
+ register long int r6 asm ("%r6") = (long int) (_arg3); \
+ register long int r7 asm ("%r7") = (long int) (_arg4); \
+ register long int r0 asm ("%r0") = (long int) (_arg5)
+#define SUBSTITUTE_ARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
+ long int _arg1 = (long int) (arg1); \
+ long int _arg2 = (long int) (arg2); \
+ long int _arg3 = (long int) (arg3); \
+ long int _arg4 = (long int) (arg4); \
+ long int _arg5 = (long int) (arg5); \
+ long int _arg6 = (long int) (arg6); \
+ register long int r4 asm ("%r4") = (long int)(_arg1); \
+ register long int r5 asm ("%r5") = (long int) (_arg2); \
+ register long int r6 asm ("%r6") = (long int) (_arg3); \
+ register long int r7 asm ("%r7") = (long int) (_arg4); \
+ register long int r0 asm ("%r0") = (long int) (_arg5); \
+ register long int r1 asm ("%r1") = (long int) (_arg6)
+#define SUBSTITUTE_ARGS_7(arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
+ long int _arg1 = (long int) (arg1); \
+ long int _arg2 = (long int) (arg2); \
+ long int _arg3 = (long int) (arg3); \
+ long int _arg4 = (long int) (arg4); \
+ long int _arg5 = (long int) (arg5); \
+ long int _arg6 = (long int) (arg6); \
+ long int _arg7 = (long int) (arg7); \
+ register long int r4 asm ("%r4") = (long int) (_arg1); \
+ register long int r5 asm ("%r5") = (long int) (_arg2); \
+ register long int r6 asm ("%r6") = (long int) (_arg3); \
+ register long int r7 asm ("%r7") = (long int) (_arg4); \
+ register long int r0 asm ("%r0") = (long int) (_arg5); \
+ register long int r1 asm ("%r1") = (long int) (_arg6); \
+ register long int r2 asm ("%r2") = (long int) (_arg7)
+
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...) \
+ ({ \
+ unsigned int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
+ resultvar = 0xffffffff; \
+ } \
+ (int) resultvar; })
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, err, nr, args...) \
+ ({ \
+ unsigned long int resultvar; \
+ register long int r3 asm ("%r3") = SYS_ify (name); \
+ SUBSTITUTE_ARGS_##nr(args); \
+ \
+ asm volatile (SYSCALL_INST_STR##nr SYSCALL_INST_PAD \
+ : "=z" (resultvar) \
+ : "r" (r3) ASMFMT_##nr \
+ : "memory"); \
+ \
+ (int) resultvar; })
+
+/* The _NCS variant allows non-constant syscall numbers. */
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({ \
+ unsigned long int resultvar; \
+ register long int r3 asm ("%r3") = (name); \
+ SUBSTITUTE_ARGS_##nr(args); \
+ \
+ asm volatile (SYSCALL_INST_STR##nr SYSCALL_INST_PAD \
+ : "=z" (resultvar) \
+ : "r" (r3) ASMFMT_##nr \
+ : "memory"); \
+ \
+ (int) resultvar; })
+
+#undef INTERNAL_SYSCALL_DECL
+#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
+
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+ ((unsigned int) (val) >= 0xfffff001u)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
+
+#endif /* __ASSEMBLER__ */
+
+/* Pointer mangling support. */
+#if defined NOT_IN_libc && defined IS_IN_rtld
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+ earlier than the descriptor is initialized. Using a global variable
+ is too complicated here since we have no PC-relative addressing mode. */
+#else
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(reg, tmp) \
+ stc gbr,tmp; mov.l @(POINTER_GUARD,tmp),tmp; xor tmp,reg
+# define PTR_MANGLE2(reg, tmp) xor tmp,reg
+# define PTR_DEMANGLE(reg, tmp) PTR_MANGLE (reg, tmp)
+# define PTR_DEMANGLE2(reg, tmp) PTR_MANGLE2 (reg, tmp)
+# else
+# define PTR_MANGLE(var) \
+ (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+# define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* linux/sh/sysdep.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sh/vfork.S b/libc/sysdeps/unix/sysv/linux/sh/vfork.S
new file mode 100644
index 000000000..e926e3b19
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/vfork.S
@@ -0,0 +1,71 @@
+/* Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+
+#ifdef __NR_vfork
+ mov.w .L3, r3
+ trapa #0x10
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf 1f
+ mov.w .L1, r1
+ cmp/eq r1, r0
+ bt 2f
+ bra .Lsyscall_error
+ nop
+.L1:
+ .word -ENOSYS
+.L3: .word __NR_vfork
+1:
+ rts
+ nop
+2:
+#endif
+
+ /* If we don't have vfork, fork is close enough. */
+ mov #+__NR_fork, r3
+ trapa #0x10
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lpseudo_end
+.Lsyscall_error:
+ SYSCALL_ERROR_HANDLER
+.Lpseudo_end:
+ rts
+ nop
+
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/sysdeps/unix/sysv/linux/sh/xstat.c b/libc/sysdeps/unix/sysv/linux/sh/xstat.c
new file mode 100644
index 000000000..e9869f550
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sh/xstat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/xstat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/shm_open.c b/libc/sysdeps/unix/sysv/linux/shm_open.c
new file mode 100644
index 000000000..0d40632e5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/shm_open.c
@@ -0,0 +1,248 @@
+/* Copyright (C) 2000,2001,2002,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <mntent.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/statfs.h>
+#include <bits/libc-lock.h>
+#include "linux_fsinfo.h"
+
+#include <kernel-features.h>
+
+
+/* Mount point of the shared memory filesystem. */
+static struct
+{
+ char *dir;
+ size_t dirlen;
+} mountpoint;
+
+/* This is the default directory. */
+static const char defaultdir[] = "/dev/shm/";
+
+/* Protect the `mountpoint' variable above. */
+__libc_once_define (static, once);
+
+
+/* Determine where the shmfs is mounted (if at all). */
+static void
+where_is_shmfs (void)
+{
+ char buf[512];
+ struct statfs f;
+ struct mntent resmem;
+ struct mntent *mp;
+ FILE *fp;
+
+ /* The canonical place is /dev/shm. This is at least what the
+ documentation tells everybody to do. */
+ if (__statfs (defaultdir, &f) == 0 && f.f_type == SHMFS_SUPER_MAGIC)
+ {
+ /* It is in the normal place. */
+ mountpoint.dir = (char *) defaultdir;
+ mountpoint.dirlen = sizeof (defaultdir) - 1;
+
+ return;
+ }
+
+ /* OK, do it the hard way. Look through the /proc/mounts file and if
+ this does not exist through /etc/fstab to find the mount point. */
+ fp = __setmntent ("/proc/mounts", "r");
+ if (__builtin_expect (fp == NULL, 0))
+ {
+ fp = __setmntent (_PATH_MNTTAB, "r");
+ if (__builtin_expect (fp == NULL, 0))
+ /* There is nothing we can do. Blind guesses are not helpful. */
+ return;
+ }
+
+ /* Now read the entries. */
+ while ((mp = __getmntent_r (fp, &resmem, buf, sizeof buf)) != NULL)
+ /* The original name is "shm" but this got changed in early Linux
+ 2.4.x to "tmpfs". */
+ if (strcmp (mp->mnt_type, "tmpfs") == 0
+#ifndef __ASSUME_TMPFS_NAME
+ || strcmp (mp->mnt_type, "shm") == 0
+#endif
+ )
+ {
+ /* Found it. There might be more than one place where the
+ filesystem is mounted but one is enough for us. */
+ size_t namelen;
+
+ /* First make sure this really is the correct entry. At least
+ some versions of the kernel give wrong information because
+ of the implicit mount of the shmfs for SysV IPC. */
+ if (__statfs (mp->mnt_dir, &f) != 0 || f.f_type != SHMFS_SUPER_MAGIC)
+ continue;
+
+ namelen = strlen (mp->mnt_dir);
+
+ if (namelen == 0)
+ /* Hum, maybe some crippled entry. Keep on searching. */
+ continue;
+
+ mountpoint.dir = (char *) malloc (namelen + 2);
+ if (mountpoint.dir != NULL)
+ {
+ char *cp = __mempcpy (mountpoint.dir, mp->mnt_dir, namelen);
+ if (cp[-1] != '/')
+ *cp++ = '/';
+ *cp = '\0';
+ mountpoint.dirlen = cp - mountpoint.dir;
+ }
+
+ break;
+ }
+
+ /* Close the stream. */
+ __endmntent (fp);
+}
+
+
+/* Open shared memory object. This implementation assumes the shmfs
+ implementation introduced in the late 2.3.x kernel series to be
+ available. Normally the filesystem will be mounted at /dev/shm but
+ we fall back on searching for the actual mount point should opening
+ such a file fail. */
+int
+shm_open (const char *name, int oflag, mode_t mode)
+{
+ size_t namelen;
+ char *fname;
+ int fd;
+
+ /* Determine where the shmfs is mounted. */
+ __libc_once (once, where_is_shmfs);
+
+ /* If we don't know the mount points there is nothing we can do. Ever. */
+ if (mountpoint.dir == NULL)
+ {
+ __set_errno (ENOSYS);
+ return -1;
+ }
+
+ /* Construct the filename. */
+ while (name[0] == '/')
+ ++name;
+
+ if (name[0] == '\0')
+ {
+ /* The name "/" is not supported. */
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ namelen = strlen (name);
+ fname = (char *) alloca (mountpoint.dirlen + namelen + 1);
+ __mempcpy (__mempcpy (fname, mountpoint.dir, mountpoint.dirlen),
+ name, namelen + 1);
+
+ /* And get the file descriptor.
+ XXX Maybe we should test each descriptor whether it really is for a
+ file on the shmfs. If this is what should be done the whole function
+ should be revamped since we can determine whether shmfs is available
+ while trying to open the file, all in one turn. */
+ fd = open (fname, oflag | O_NOFOLLOW, mode);
+ if (fd != -1)
+ {
+ /* We got a descriptor. Now set the FD_CLOEXEC bit. */
+ int flags = fcntl (fd, F_GETFD, 0);
+
+ if (__builtin_expect (flags, 0) >= 0)
+ {
+ flags |= FD_CLOEXEC;
+ flags = fcntl (fd, F_SETFD, flags);
+ }
+
+ if (flags == -1)
+ {
+ /* Something went wrong. We cannot return the descriptor. */
+ int save_errno = errno;
+ close (fd);
+ fd = -1;
+ __set_errno (save_errno);
+ }
+ }
+ else if (__builtin_expect (errno == EISDIR, 0))
+ /* It might be better to fold this error with EINVAL since
+ directory names are just another example for unsuitable shared
+ object names and the standard does not mention EISDIR. */
+ __set_errno (EINVAL);
+
+ return fd;
+}
+
+
+/* Unlink a shared memory object. */
+int
+shm_unlink (const char *name)
+{
+ size_t namelen;
+ char *fname;
+
+ /* Determine where the shmfs is mounted. */
+ __libc_once (once, where_is_shmfs);
+
+ if (mountpoint.dir == NULL)
+ {
+ /* We cannot find the shmfs. If `name' is really a shared
+ memory object it must have been created by another process
+ and we have no idea where that process found the mountpoint. */
+ __set_errno (ENOENT);
+ return -1;
+ }
+
+ /* Construct the filename. */
+ while (name[0] == '/')
+ ++name;
+
+ if (name[0] == '\0')
+ {
+ /* The name "/" is not supported. */
+ __set_errno (ENOENT);
+ return -1;
+ }
+
+ namelen = strlen (name);
+ fname = (char *) alloca (mountpoint.dirlen + namelen + 1);
+ __mempcpy (__mempcpy (fname, mountpoint.dir, mountpoint.dirlen),
+ name, namelen + 1);
+
+ /* And remove the file. */
+ int ret = unlink (fname);
+ if (ret < 0 && errno == EPERM)
+ __set_errno (EACCES);
+ return ret;
+}
+
+
+/* Make sure the table is freed if we want to free everything before
+ exiting. */
+libc_freeres_fn (freeit)
+{
+ if (mountpoint.dir != defaultdir)
+ free (mountpoint.dir);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/shm_unlink.c b/libc/sysdeps/unix/sysv/linux/shm_unlink.c
new file mode 100644
index 000000000..55cece276
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/shm_unlink.c
@@ -0,0 +1 @@
+/* This function is for technical reason defined in shm_open.c. */
diff --git a/libc/sysdeps/unix/sysv/linux/shmat.c b/libc/sysdeps/unix/sysv/linux/shmat.c
new file mode 100644
index 000000000..2c243007f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/shmat.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 1995,1997,1998,1999,2000,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/shm.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Attach the shared memory segment associated with SHMID to the data
+ segment of the calling process. SHMADDR and SHMFLG determine how
+ and where the segment is attached. */
+
+void *
+shmat (shmid, shmaddr, shmflg)
+ int shmid;
+ const void *shmaddr;
+ int shmflg;
+{
+ void *__unbounded result;
+ void *__unbounded raddr;
+
+#if __BOUNDED_POINTERS__
+ size_t length = ~0;
+ struct shmid_ds shmds;
+ /* It's unfortunate that we need to make another system call to get
+ the shared memory segment length... */
+ if (shmctl (shmid, IPC_STAT, &shmds) == 0)
+ length = shmds.shm_segsz;
+#endif
+
+ result = (void *__unbounded) INLINE_SYSCALL (ipc, 5, IPCOP_shmat,
+ shmid, shmflg,
+ (long int) __ptrvalue (&raddr),
+ __ptrvalue ((void *) shmaddr));
+ if ((unsigned long) result <= -(unsigned long) SHMLBA)
+ result = raddr;
+
+ return BOUNDED_N (result, length);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/shmctl.c b/libc/sysdeps/unix/sysv/linux/shmctl.c
new file mode 100644
index 000000000..0fbddd920
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/shmctl.c
@@ -0,0 +1,161 @@
+/* Copyright (C) 1995,1997,1998,2000,2003,2004,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/shm.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <string.h>
+#include <sys/syscall.h>
+#include <bits/wordsize.h>
+#include <shlib-compat.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+struct __old_shmid_ds
+{
+ struct __old_ipc_perm shm_perm; /* operation permission struct */
+ int shm_segsz; /* size of segment in bytes */
+ __time_t shm_atime; /* time of last shmat() */
+ __time_t shm_dtime; /* time of last shmdt() */
+ __time_t shm_ctime; /* time of last change by shmctl() */
+ __ipc_pid_t shm_cpid; /* pid of creator */
+ __ipc_pid_t shm_lpid; /* pid of last shmop */
+ unsigned short int shm_nattch; /* number of current attaches */
+ unsigned short int __shm_npages; /* size of segment (pages) */
+ unsigned long int *__unbounded __shm_pages; /* array of ptrs to frames -> SHMMAX */
+ struct vm_area_struct *__unbounded __attaches; /* descriptors for attaches */
+};
+
+struct __old_shminfo
+{
+ int shmmax;
+ int shmmin;
+ int shmmni;
+ int shmseg;
+ int shmall;
+};
+
+/* Provide operations to control over shared memory segments. */
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int __old_shmctl (int, int, struct __old_shmid_ds *);
+#endif
+int __new_shmctl (int, int, struct shmid_ds *);
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int
+attribute_compat_text_section
+__old_shmctl (int shmid, int cmd, struct __old_shmid_ds *buf)
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_shmctl, shmid,
+ cmd, 0, CHECK_1_NULL_OK (buf));
+}
+compat_symbol (libc, __old_shmctl, shmctl, GLIBC_2_0);
+#endif
+
+int
+__new_shmctl (int shmid, int cmd, struct shmid_ds *buf)
+{
+#if __ASSUME_IPC64 > 0
+ return INLINE_SYSCALL (ipc, 5, IPCOP_shmctl, shmid, cmd | __IPC_64, 0,
+ CHECK_1 (buf));
+#else
+ switch (cmd) {
+ case SHM_STAT:
+ case IPC_STAT:
+ case IPC_SET:
+#if __WORDSIZE != 32
+ case IPC_INFO:
+#endif
+ break;
+ default:
+ return INLINE_SYSCALL (ipc, 5, IPCOP_shmctl, shmid, cmd, 0,
+ CHECK_1 (buf));
+ }
+
+ {
+ int save_errno = errno, result;
+ union
+ {
+ struct __old_shmid_ds ds;
+ struct __old_shminfo info;
+ } old;
+
+ /* Unfortunately there is no way how to find out for sure whether
+ we should use old or new shmctl. */
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_shmctl, shmid, cmd | __IPC_64, 0,
+ CHECK_1 (buf));
+ if (result != -1 || errno != EINVAL)
+ return result;
+
+ __set_errno(save_errno);
+ if (cmd == IPC_SET)
+ {
+ old.ds.shm_perm.uid = buf->shm_perm.uid;
+ old.ds.shm_perm.gid = buf->shm_perm.gid;
+ old.ds.shm_perm.mode = buf->shm_perm.mode;
+ if (old.ds.shm_perm.uid != buf->shm_perm.uid ||
+ old.ds.shm_perm.gid != buf->shm_perm.gid)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_shmctl, shmid, cmd, 0,
+ __ptrvalue (&old.ds));
+ if (result != -1 && (cmd == SHM_STAT || cmd == IPC_STAT))
+ {
+ memset(buf, 0, sizeof(*buf));
+ buf->shm_perm.__key = old.ds.shm_perm.__key;
+ buf->shm_perm.uid = old.ds.shm_perm.uid;
+ buf->shm_perm.gid = old.ds.shm_perm.gid;
+ buf->shm_perm.cuid = old.ds.shm_perm.cuid;
+ buf->shm_perm.cgid = old.ds.shm_perm.cgid;
+ buf->shm_perm.mode = old.ds.shm_perm.mode;
+ buf->shm_perm.__seq = old.ds.shm_perm.__seq;
+ buf->shm_atime = old.ds.shm_atime;
+ buf->shm_dtime = old.ds.shm_dtime;
+ buf->shm_ctime = old.ds.shm_ctime;
+ buf->shm_segsz = old.ds.shm_segsz;
+ buf->shm_nattch = old.ds.shm_nattch;
+ buf->shm_cpid = old.ds.shm_cpid;
+ buf->shm_lpid = old.ds.shm_lpid;
+ }
+#if __WORDSIZE != 32
+ else if (result != -1 && cmd == IPC_INFO)
+ {
+ struct shminfo *i = (struct shminfo *)buf;
+
+ memset(i, 0, sizeof(*i));
+ i->shmmax = old.info.shmmax;
+ i->shmmin = old.info.shmmin;
+ i->shmmni = old.info.shmmni;
+ i->shmseg = old.info.shmseg;
+ i->shmall = old.info.shmall;
+ }
+#endif
+ return result;
+ }
+#endif
+}
+
+versioned_symbol (libc, __new_shmctl, shmctl, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/shmdt.c b/libc/sysdeps/unix/sysv/linux/shmdt.c
new file mode 100644
index 000000000..413c85202
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/shmdt.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1995, 1997, 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/shm.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Detach shared memory segment starting at address specified by SHMADDR
+ from the caller's data segment. */
+
+int
+shmdt (shmaddr)
+ const void *shmaddr;
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_shmdt, 0, 0, 0, __ptrvalue ((void *) shmaddr));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/shmget.c b/libc/sysdeps/unix/sysv/linux/shmget.c
new file mode 100644
index 000000000..c8d509f26
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/shmget.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 1995, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/shm.h>
+#include <ipc_priv.h>
+#include <stdlib.h> /* for definition of NULL */
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Return an identifier for an shared memory segment of at least size SIZE
+ which is associated with KEY. */
+
+int
+shmget (key, size, shmflg)
+ key_t key;
+ size_t size;
+ int shmflg;
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_shmget, key, size, shmflg, NULL);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/shutdown.S b/libc/sysdeps/unix/sysv/linux/shutdown.S
new file mode 100644
index 000000000..e2462d0ec
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/shutdown.S
@@ -0,0 +1,3 @@
+#define socket shutdown
+#define NARGS 2
+#include <socket.S>
diff --git a/libc/sysdeps/unix/sysv/linux/sigaction.c b/libc/sysdeps/unix/sysv/linux/sigaction.c
new file mode 100644
index 000000000..7b44598c0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sigaction.c
@@ -0,0 +1,140 @@
+/* Copyright (C) 1997-2000,2002,2003,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+/* The difference here is that the sigaction structure used in the
+ kernel is not the same as we use in the libc. Therefore we must
+ translate it here. */
+#include <kernel_sigaction.h>
+
+#if __ASSUME_REALTIME_SIGNALS == 0
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. This is the definition. */
+int __libc_missing_rt_sigs;
+#endif
+
+
+/* If ACT is not NULL, change the action for SIG to *ACT.
+ If OACT is not NULL, put the old action for SIG in *OACT. */
+int
+__libc_sigaction (sig, act, oact)
+ int sig;
+ const struct sigaction *act;
+ struct sigaction *oact;
+{
+#if __ASSUME_REALTIME_SIGNALS == 0
+ struct old_kernel_sigaction k_sigact, k_osigact;
+#endif
+ int result;
+
+#if defined __NR_rt_sigaction || __ASSUME_REALTIME_SIGNALS > 0
+ /* First try the RT signals. */
+# if __ASSUME_REALTIME_SIGNALS == 0
+ if (!__libc_missing_rt_sigs)
+# endif
+ {
+ struct kernel_sigaction kact, koact;
+ /* Save the current error value for later. We need not do this
+ if we are guaranteed to have realtime signals. */
+# if __ASSUME_REALTIME_SIGNALS == 0
+ int saved_errno = errno;
+# endif
+
+ if (act)
+ {
+ kact.k_sa_handler = act->sa_handler;
+ memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
+ kact.sa_flags = act->sa_flags;
+# ifdef HAVE_SA_RESTORER
+ kact.sa_restorer = act->sa_restorer;
+# endif
+ }
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ result = INLINE_SYSCALL (rt_sigaction, 4, sig,
+ act ? __ptrvalue (&kact) : NULL,
+ oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
+
+# if __ASSUME_REALTIME_SIGNALS == 0
+ if (result >= 0 || errno != ENOSYS)
+# endif
+ {
+ if (oact && result >= 0)
+ {
+ oact->sa_handler = koact.k_sa_handler;
+ memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
+ oact->sa_flags = koact.sa_flags;
+# ifdef HAVE_SA_RESTORER
+ oact->sa_restorer = koact.sa_restorer;
+# endif
+ }
+ return result;
+ }
+
+# if __ASSUME_REALTIME_SIGNALS == 0
+ __set_errno (saved_errno);
+ __libc_missing_rt_sigs = 1;
+# endif
+ }
+#endif
+
+#if __ASSUME_REALTIME_SIGNALS == 0
+ if (act)
+ {
+ k_sigact.k_sa_handler = act->sa_handler;
+ k_sigact.sa_mask = act->sa_mask.__val[0];
+ k_sigact.sa_flags = act->sa_flags;
+# ifdef HAVE_SA_RESTORER
+ k_sigact.sa_restorer = act->sa_restorer;
+# endif
+ }
+ result = INLINE_SYSCALL (sigaction, 3, sig,
+ act ? __ptrvalue (&k_sigact) : NULL,
+ oact ? __ptrvalue (&k_osigact) : NULL);
+ if (oact && result >= 0)
+ {
+ oact->sa_handler = k_osigact.k_sa_handler;
+ oact->sa_mask.__val[0] = k_osigact.sa_mask;
+ oact->sa_flags = k_osigact.sa_flags;
+# ifdef HAVE_SA_RESTORER
+ oact->sa_restorer = k_osigact.sa_restorer;
+# endif
+ }
+ return result;
+#endif
+}
+libc_hidden_def (__libc_sigaction)
+
+#ifdef WRAPPER_INCLUDE
+# include WRAPPER_INCLUDE
+#endif
+
+#ifndef LIBC_SIGACTION
+weak_alias (__libc_sigaction, __sigaction)
+libc_hidden_weak (__sigaction)
+weak_alias (__libc_sigaction, sigaction)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/siglist.h b/libc/sysdeps/unix/sysv/linux/siglist.h
new file mode 100644
index 000000000..cc2b49ed2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/siglist.h
@@ -0,0 +1,25 @@
+/* Copyright (C) 1996,1997,1998,1999,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This file is included multiple times. */
+
+#include_next <siglist.h> /* Get the canonical list. */
+
+#define OLD_SIGLIST_SIZE 32 /* For GLIBC_2.0 binary compatibility. */
+
+#define OLD2_SIGLIST_SIZE 64 /* For GLIBC_2.1 binary compatibility. */
diff --git a/libc/sysdeps/unix/sysv/linux/signal.c b/libc/sysdeps/unix/sysv/linux/signal.c
new file mode 100644
index 000000000..bc4e4e844
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/signal.c
@@ -0,0 +1,3 @@
+/* We need this file since otherwise `signal' would be handled as a
+ system call. */
+#include <sysdeps/posix/signal.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sigpending.c b/libc/sysdeps/unix/sysv/linux/sigpending.c
new file mode 100644
index 000000000..f0036c113
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sigpending.c
@@ -0,0 +1,64 @@
+/* Copyright (C) 1997,1998,1999,2000,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. The definition is in sigaction.c. */
+extern int __libc_missing_rt_sigs;
+
+
+/* Change the set of blocked signals to SET,
+ wait until a signal arrives, and restore the set of blocked signals. */
+int
+sigpending (set)
+ sigset_t *set;
+{
+#if __ASSUME_REALTIME_SIGNALS > 0
+ return INLINE_SYSCALL (rt_sigpending, 2, CHECK_SIGSET (set), _NSIG / 8);
+#else
+# ifdef __NR_rt_sigpending
+ /* First try the RT signals. */
+ if (!__libc_missing_rt_sigs)
+ {
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ int saved_errno = errno;
+ int result = INLINE_SYSCALL (rt_sigpending, 2, CHECK_SIGSET (set), _NSIG / 8);
+
+ if (result >= 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_rt_sigs = 1;
+ }
+# endif
+
+ return INLINE_SYSCALL (sigpending, 1, CHECK_SIGSET (set));
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sigprocmask.c b/libc/sysdeps/unix/sysv/linux/sigprocmask.c
new file mode 100644
index 000000000..1b13ea74d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sigprocmask.c
@@ -0,0 +1,91 @@
+/* Copyright (C) 1997-2001,2003,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <string.h> /* Neede for string function builtin redirection. */
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. The definition is in sigaction.c. */
+extern int __libc_missing_rt_sigs;
+
+
+/* Get and/or change the set of blocked signals. */
+int
+__sigprocmask (how, set, oset)
+ int how;
+ const sigset_t *set;
+ sigset_t *oset;
+{
+#ifdef SIGCANCEL
+ sigset_t local_newmask;
+
+ /* The only thing we have to make sure here is that SIGCANCEL and
+ SIGSETXID are not blocked. */
+ if (set != NULL
+ && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
+# ifdef SIGSETXID
+ || __builtin_expect (__sigismember (set, SIGSETXID), 0)
+# endif
+ ))
+ {
+ local_newmask = *set;
+ __sigdelset (&local_newmask, SIGCANCEL);
+# ifdef SIGSETXID
+ __sigdelset (&local_newmask, SIGSETXID);
+# endif
+ set = &local_newmask;
+ }
+#endif
+
+#if __ASSUME_REALTIME_SIGNALS > 0
+ return INLINE_SYSCALL (rt_sigprocmask, 4, how, CHECK_SIGSET_NULL_OK (set),
+ CHECK_SIGSET_NULL_OK (oset), _NSIG / 8);
+#else
+# ifdef __NR_rt_sigprocmask
+ /* First try the RT signals. */
+ if (!__libc_missing_rt_sigs)
+ {
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ int saved_errno = errno;
+ int result = INLINE_SYSCALL (rt_sigprocmask, 4, how,
+ CHECK_SIGSET_NULL_OK (set),
+ CHECK_SIGSET_NULL_OK (oset), _NSIG / 8);
+
+ if (result >= 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_rt_sigs = 1;
+ }
+# endif
+
+ return INLINE_SYSCALL (sigprocmask, 3, how, CHECK_SIGSET_NULL_OK (set),
+ CHECK_SIGSET_NULL_OK (oset));
+#endif
+}
+weak_alias (__sigprocmask, sigprocmask)
diff --git a/libc/sysdeps/unix/sysv/linux/sigqueue.c b/libc/sysdeps/unix/sysv/linux/sigqueue.c
new file mode 100644
index 000000000..22a8036b6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sigqueue.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 1997, 1998, 2000, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#ifdef __NR_rt_sigqueueinfo
+/* Return any pending signal or wait for one for the given time. */
+int
+__sigqueue (pid, sig, val)
+ pid_t pid;
+ int sig;
+ const union sigval val;
+{
+ siginfo_t info;
+
+ /* First, clear the siginfo_t structure, so that we don't pass our
+ stack content to other tasks. */
+ memset (&info, 0, sizeof (siginfo_t));
+ /* We must pass the information about the data in a siginfo_t value. */
+ info.si_signo = sig;
+ info.si_code = SI_QUEUE;
+ info.si_pid = __getpid ();
+ info.si_uid = __getuid ();
+ info.si_value = val;
+
+ return INLINE_SYSCALL (rt_sigqueueinfo, 3, pid, sig, __ptrvalue (&info));
+}
+weak_alias (__sigqueue, sigqueue)
+#else
+# include <signal/sigqueue.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sigreturn.c b/libc/sysdeps/unix/sysv/linux/sigreturn.c
new file mode 100644
index 000000000..626b1eb8a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sigreturn.c
@@ -0,0 +1,3 @@
+/* The sigreturn syscall cannot be explicitly called on Linux, only
+ implicitly by returning from a signal handler. */
+#include <signal/sigreturn.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sigset-cvt-mask.h b/libc/sysdeps/unix/sysv/linux/sigset-cvt-mask.h
new file mode 100644
index 000000000..ca4774dbd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sigset-cvt-mask.h
@@ -0,0 +1,44 @@
+/* Convert between lowlevel sigmask and libc representation of sigset_t.
+ Linux version.
+ Copyright (C) 1998, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Joe Keane <jgk@jgk.org>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+static inline int __attribute__ ((unused))
+sigset_set_old_mask (sigset_t *set, int mask)
+{
+ unsigned long int *ptr;
+ int cnt;
+
+ ptr = &set->__val[0];
+
+ *ptr++ = (unsigned int) mask;
+
+ cnt = _SIGSET_NWORDS - 2;
+ do
+ *ptr++ = 0ul;
+ while (--cnt >= 0);
+
+ return 0;
+}
+
+static inline int __attribute__ ((unused))
+sigset_get_old_mask (const sigset_t *set)
+{
+ return (unsigned int) set->__val[0];
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sigstack.c b/libc/sysdeps/unix/sysv/linux/sigstack.c
new file mode 100644
index 000000000..76d212698
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sigstack.c
@@ -0,0 +1,69 @@
+/* Emulate sigstack function using sigaltstack.
+ Copyright (C) 1998, 2000, 2005 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <signal.h>
+#include <stddef.h>
+#include <sys/syscall.h>
+
+
+#ifdef __NR_sigaltstack
+int
+sigstack (ss, oss)
+ struct sigstack *ss;
+ struct sigstack *oss;
+{
+ stack_t sas;
+ stack_t *sasp = NULL;
+ stack_t osas;
+ stack_t *osasp = oss == NULL ? NULL : &osas;
+ int result;
+
+ if (ss != NULL)
+ {
+ /* We have to convert the information. */
+ sas.ss_sp = ss->ss_sp;
+ sas.ss_flags = ss->ss_onstack ? SS_ONSTACK : 0;
+
+ /* For the size of the stack we have no value we can pass to the
+ kernel. This is why this function should not be used. We simply
+ assume that all the memory down to address zero (in case the stack
+ grows down) is available. */
+ sas.ss_size = ss->ss_sp - NULL;
+
+ sasp = &sas;
+ }
+
+ /* Call the kernel. */
+ result = __sigaltstack (sasp, osasp);
+
+ /* Convert the result, if wanted and possible. */
+ if (result == 0 && oss != NULL)
+ {
+ oss->ss_sp = osas.ss_sp;
+ oss->ss_onstack = (osas.ss_flags & SS_ONSTACK) != 0;
+ }
+
+ return result;
+}
+
+link_warning (sigstack, "the `sigstack' function is dangerous. `sigaltstack' should be used instead.")
+#else
+# include <signal/sigstack.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sigsuspend.c b/libc/sysdeps/unix/sysv/linux/sigsuspend.c
new file mode 100644
index 000000000..adbdfddfd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sigsuspend.c
@@ -0,0 +1,95 @@
+/* Copyright (C) 1996,1997,1998,1999,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+
+#if !__ASSUME_REALTIME_SIGNALS
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. The definition is in sigaction.c. */
+extern int __libc_missing_rt_sigs;
+
+
+static int
+do_sigsuspend (const sigset_t *set)
+{
+# ifdef __NR_rt_sigsuspend
+ /* First try the RT signals. */
+ if (!__libc_missing_rt_sigs)
+ {
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ int saved_errno = errno;
+ int result = INLINE_SYSCALL (rt_sigsuspend, 2,
+ CHECK_SIGSET (set), _NSIG / 8);
+ if (result >= 0 || errno != ENOSYS)
+ return result;
+
+ __set_errno (saved_errno);
+ __libc_missing_rt_sigs = 1;
+ }
+# endif
+
+ return INLINE_SYSCALL (sigsuspend, 3, 0, 0, set->__val[0]);
+}
+#else
+static inline int __attribute__ ((always_inline))
+do_sigsuspend (const sigset_t *set)
+{
+ return INLINE_SYSCALL (rt_sigsuspend, 2, CHECK_SIGSET (set), _NSIG / 8);
+}
+#endif
+
+/* Change the set of blocked signals to SET,
+ wait until a signal arrives, and restore the set of blocked signals. */
+int
+__sigsuspend (set)
+ const sigset_t *set;
+{
+ if (SINGLE_THREAD_P)
+ return do_sigsuspend (set);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = do_sigsuspend (set);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+libc_hidden_def (__sigsuspend)
+weak_alias (__sigsuspend, sigsuspend)
+strong_alias (__sigsuspend, __libc_sigsuspend)
+
+#ifndef NO_CANCELLATION
+int
+__sigsuspend_nocancel (set)
+ const sigset_t *set;
+{
+ return do_sigsuspend (set);
+}
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sigtimedwait.c b/libc/sysdeps/unix/sysv/linux/sigtimedwait.c
new file mode 100644
index 000000000..879565276
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sigtimedwait.c
@@ -0,0 +1,93 @@
+/* Copyright (C) 1997,1998,2000,2002,2003,2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#ifdef __NR_rt_sigtimedwait
+
+static int
+do_sigtimedwait (const sigset_t *set, siginfo_t *info,
+ const struct timespec *timeout)
+{
+#ifdef SIGCANCEL
+ sigset_t tmpset;
+ if (set != NULL
+ && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
+# ifdef SIGSETXID
+ || __builtin_expect (__sigismember (set, SIGSETXID), 0)
+# endif
+ ))
+ {
+ /* Create a temporary mask without the bit for SIGCANCEL set. */
+ // We are not copying more than we have to.
+ memcpy (&tmpset, set, _NSIG / 8);
+ __sigdelset (&tmpset, SIGCANCEL);
+# ifdef SIGSETXID
+ __sigdelset (&tmpset, SIGSETXID);
+# endif
+ set = &tmpset;
+ }
+#endif
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ int result = INLINE_SYSCALL (rt_sigtimedwait, 4, CHECK_SIGSET (set),
+ CHECK_1 (info), timeout, _NSIG / 8);
+
+ /* The kernel generates a SI_TKILL code in si_code in case tkill is
+ used. tkill is transparently used in raise(). Since having
+ SI_TKILL as a code is useful in general we fold the results
+ here. */
+ if (result != -1 && info != NULL && info->si_code == SI_TKILL)
+ info->si_code = SI_USER;
+
+ return result;
+}
+
+
+/* Return any pending signal or wait for one for the given time. */
+int
+__sigtimedwait (set, info, timeout)
+ const sigset_t *set;
+ siginfo_t *info;
+ const struct timespec *timeout;
+{
+ if (SINGLE_THREAD_P)
+ return do_sigtimedwait (set, info, timeout);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ int result = do_sigtimedwait (set, info, timeout);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+libc_hidden_def (__sigtimedwait)
+weak_alias (__sigtimedwait, sigtimedwait)
+#else
+# include <signal/sigtimedwait.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sigwait.c b/libc/sysdeps/unix/sysv/linux/sigwait.c
new file mode 100644
index 000000000..279ca0203
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sigwait.c
@@ -0,0 +1,111 @@
+/* Copyright (C) 1997,1998,2000,2002-2004,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#define __need_NULL
+#include <stddef.h>
+#include <string.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#ifdef __NR_rt_sigtimedwait
+
+/* Return any pending signal or wait for one for the given time. */
+static int
+do_sigwait (const sigset_t *set, int *sig)
+{
+ int ret;
+
+#ifdef SIGCANCEL
+ sigset_t tmpset;
+ if (set != NULL
+ && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
+# ifdef SIGSETXID
+ || __builtin_expect (__sigismember (set, SIGSETXID), 0)
+# endif
+ ))
+ {
+ /* Create a temporary mask without the bit for SIGCANCEL set. */
+ // We are not copying more than we have to.
+ memcpy (&tmpset, set, _NSIG / 8);
+ __sigdelset (&tmpset, SIGCANCEL);
+# ifdef SIGSETXID
+ __sigdelset (&tmpset, SIGSETXID);
+# endif
+ set = &tmpset;
+ }
+#endif
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+#ifdef INTERNAL_SYSCALL
+ INTERNAL_SYSCALL_DECL (err);
+ do
+ ret = INTERNAL_SYSCALL (rt_sigtimedwait, err, 4, CHECK_SIGSET (set),
+ NULL, NULL, _NSIG / 8);
+ while (INTERNAL_SYSCALL_ERROR_P (ret, err)
+ && INTERNAL_SYSCALL_ERRNO (ret, err) == EINTR);
+ if (! INTERNAL_SYSCALL_ERROR_P (ret, err))
+ {
+ *sig = ret;
+ ret = 0;
+ }
+ else
+ ret = INTERNAL_SYSCALL_ERRNO (ret, err);
+#else
+ do
+ ret = INLINE_SYSCALL (rt_sigtimedwait, 4, CHECK_SIGSET (set),
+ NULL, NULL, _NSIG / 8);
+ while (ret == -1 && errno == EINTR);
+ if (ret != -1)
+ {
+ *sig = ret;
+ ret = 0;
+ }
+ else
+ ret = errno;
+#endif
+
+ return ret;
+}
+
+int
+__sigwait (set, sig)
+ const sigset_t *set;
+ int *sig;
+{
+ if (SINGLE_THREAD_P)
+ return do_sigwait (set, sig);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ int result = do_sigwait (set, sig);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+libc_hidden_def (__sigwait)
+weak_alias (__sigwait, sigwait)
+#else
+# include <sysdeps/posix/sigwait.c>
+#endif
+strong_alias (__sigwait, __libc_sigwait)
diff --git a/libc/sysdeps/unix/sysv/linux/sigwaitinfo.c b/libc/sysdeps/unix/sysv/linux/sigwaitinfo.c
new file mode 100644
index 000000000..80790df9e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sigwaitinfo.c
@@ -0,0 +1,94 @@
+/* Copyright (C) 1997,1998,2000,2002,2003,2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#define __need_NULL
+#include <stddef.h>
+#include <string.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#ifdef __NR_rt_sigtimedwait
+
+static int
+do_sigwaitinfo (const sigset_t *set, siginfo_t *info)
+{
+#ifdef SIGCANCEL
+ sigset_t tmpset;
+ if (set != NULL
+ && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
+# ifdef SIGSETXID
+ || __builtin_expect (__sigismember (set, SIGSETXID), 0)
+# endif
+ ))
+ {
+ /* Create a temporary mask without the bit for SIGCANCEL set. */
+ // We are not copying more than we have to.
+ memcpy (&tmpset, set, _NSIG / 8);
+ __sigdelset (&tmpset, SIGCANCEL);
+# ifdef SIGSETXID
+ __sigdelset (&tmpset, SIGSETXID);
+# endif
+ set = &tmpset;
+ }
+#endif
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ int result = INLINE_SYSCALL (rt_sigtimedwait, 4, CHECK_SIGSET (set),
+ CHECK_1 (info), NULL, _NSIG / 8);
+
+ /* The kernel generates a SI_TKILL code in si_code in case tkill is
+ used. tkill is transparently used in raise(). Since having
+ SI_TKILL as a code is useful in general we fold the results
+ here. */
+ if (result != -1 && info != NULL && info->si_code == SI_TKILL)
+ info->si_code = SI_USER;
+
+ return result;
+}
+
+
+/* Return any pending signal or wait for one for the given time. */
+int
+__sigwaitinfo (set, info)
+ const sigset_t *set;
+ siginfo_t *info;
+{
+ if (SINGLE_THREAD_P)
+ return do_sigwaitinfo (set, info);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ int result = do_sigwaitinfo (set, info);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+libc_hidden_def (__sigwaitinfo)
+weak_alias (__sigwaitinfo, sigwaitinfo)
+#else
+# include <signal/sigwaitinfo.c>
+#endif
+strong_alias (__sigwaitinfo, __libc_sigwaitinfo)
diff --git a/libc/sysdeps/unix/sysv/linux/sizes.h b/libc/sysdeps/unix/sysv/linux/sizes.h
new file mode 100644
index 000000000..18673e2fc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sizes.h
@@ -0,0 +1,24 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIZES_H
+#define _SIZES_H 1
+
+#define PTR_SIZE_STR "4"
+
+#endif /* sizes.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sleep.c b/libc/sysdeps/unix/sysv/linux/sleep.c
new file mode 100644
index 000000000..0e41a1133
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sleep.c
@@ -0,0 +1,149 @@
+/* Implementation of the POSIX sleep function using nanosleep.
+ Copyright (C) 1996,1997,1998,1999,2003,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <time.h>
+#include <signal.h>
+#include <string.h> /* For the real memset prototype. */
+#include <unistd.h>
+#include <sys/param.h>
+
+
+#if 0
+static void
+cl (void *arg)
+{
+ (void) __sigprocmask (SIG_SETMASK, arg, (sigset_t *) NULL);
+}
+#endif
+
+
+/* We are going to use the `nanosleep' syscall of the kernel. But the
+ kernel does not implement the stupid SysV SIGCHLD vs. SIG_IGN
+ behaviour for this syscall. Therefore we have to emulate it here. */
+unsigned int
+__sleep (unsigned int seconds)
+{
+ const unsigned int max
+ = (unsigned int) (((unsigned long int) (~((time_t) 0))) >> 1);
+ struct timespec ts;
+ sigset_t set, oset;
+ unsigned int result;
+
+ /* This is not necessary but some buggy programs depend on this. */
+ if (__builtin_expect (seconds == 0, 0))
+ {
+#ifdef CANCELLATION_P
+ CANCELLATION_P (THREAD_SELF);
+#endif
+ return 0;
+ }
+
+ ts.tv_sec = 0;
+ ts.tv_nsec = 0;
+ again:
+ if (sizeof (ts.tv_sec) <= sizeof (seconds))
+ {
+ /* Since SECONDS is unsigned assigning the value to .tv_sec can
+ overflow it. In this case we have to wait in steps. */
+ ts.tv_sec += MIN (seconds, max);
+ seconds -= (unsigned int) ts.tv_sec;
+ }
+ else
+ {
+ ts.tv_sec = (time_t) seconds;
+ seconds = 0;
+ }
+
+ /* Linux will wake up the system call, nanosleep, when SIGCHLD
+ arrives even if SIGCHLD is ignored. We have to deal with it
+ in libc. We block SIGCHLD first. */
+ __sigemptyset (&set);
+ __sigaddset (&set, SIGCHLD);
+ if (__sigprocmask (SIG_BLOCK, &set, &oset))
+ return -1;
+
+ /* If SIGCHLD is already blocked, we don't have to do anything. */
+ if (!__sigismember (&oset, SIGCHLD))
+ {
+ int saved_errno;
+ struct sigaction oact;
+
+ __sigemptyset (&set);
+ __sigaddset (&set, SIGCHLD);
+
+ /* We get the signal handler for SIGCHLD. */
+ if (__sigaction (SIGCHLD, (struct sigaction *) NULL, &oact) < 0)
+ {
+ saved_errno = errno;
+ /* Restore the original signal mask. */
+ (void) __sigprocmask (SIG_SETMASK, &oset, (sigset_t *) NULL);
+ __set_errno (saved_errno);
+ return -1;
+ }
+
+ /* Note the sleep() is a cancellation point. But since we call
+ nanosleep() which itself is a cancellation point we do not
+ have to do anything here. */
+ if (oact.sa_handler == SIG_IGN)
+ {
+ //__libc_cleanup_push (cl, &oset);
+
+ /* We should leave SIGCHLD blocked. */
+ while (1)
+ {
+ result = __nanosleep (&ts, &ts);
+
+ if (result != 0 || seconds == 0)
+ break;
+
+ if (sizeof (ts.tv_sec) <= sizeof (seconds))
+ {
+ ts.tv_sec = MIN (seconds, max);
+ seconds -= (unsigned int) ts.tv_nsec;
+ }
+ }
+
+ //__libc_cleanup_pop (0);
+
+ saved_errno = errno;
+ /* Restore the original signal mask. */
+ (void) __sigprocmask (SIG_SETMASK, &oset, (sigset_t *) NULL);
+ __set_errno (saved_errno);
+
+ goto out;
+ }
+
+ /* We should unblock SIGCHLD. Restore the original signal mask. */
+ (void) __sigprocmask (SIG_SETMASK, &oset, (sigset_t *) NULL);
+ }
+
+ result = __nanosleep (&ts, &ts);
+ if (result == 0 && seconds != 0)
+ goto again;
+
+ out:
+ if (result != 0)
+ /* Round remaining time. */
+ result = seconds + (unsigned int) ts.tv_sec + (ts.tv_nsec >= 500000000L);
+
+ return result;
+}
+weak_alias (__sleep, sleep)
diff --git a/libc/sysdeps/unix/sysv/linux/socketcall.h b/libc/sysdeps/unix/sysv/linux/socketcall.h
new file mode 100644
index 000000000..d836534f3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/socketcall.h
@@ -0,0 +1,48 @@
+/* ID for functions called via socketcall system call.
+ Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SOCKETCALL_H
+
+#define _SYS_SOCKETCALL_H 1
+
+/* Define unique numbers for the operations permitted on socket. Linux
+ uses a single system call for all these functions. The relevant code
+ file is /usr/include/linux/net.h.
+ We cannot use a enum here because the values are used in assembler
+ code. */
+
+#define SOCKOP_socket 1
+#define SOCKOP_bind 2
+#define SOCKOP_connect 3
+#define SOCKOP_listen 4
+#define SOCKOP_accept 5
+#define SOCKOP_getsockname 6
+#define SOCKOP_getpeername 7
+#define SOCKOP_socketpair 8
+#define SOCKOP_send 9
+#define SOCKOP_recv 10
+#define SOCKOP_sendto 11
+#define SOCKOP_recvfrom 12
+#define SOCKOP_shutdown 13
+#define SOCKOP_setsockopt 14
+#define SOCKOP_getsockopt 15
+#define SOCKOP_sendmsg 16
+#define SOCKOP_recvmsg 17
+
+#endif /* _SYS_SOCKETCALL_H */
diff --git a/libc/sysdeps/unix/sysv/linux/socketpair.S b/libc/sysdeps/unix/sysv/linux/socketpair.S
new file mode 100644
index 000000000..c954ad1a4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/socketpair.S
@@ -0,0 +1,3 @@
+#define socket socketpair
+#define NARGS 4
+#include <socket.S>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/Makefile b/libc/sysdeps/unix/sysv/linux/sparc/Makefile
new file mode 100644
index 000000000..9cb2a634d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/Makefile
@@ -0,0 +1,5 @@
+64bit-predefine = __sparc_v9__ __arch64__
+
+ifeq ($(subdir),rt)
+librt-routines += rt-sysdep
+endif
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/Versions b/libc/sysdeps/unix/sysv/linux/sparc/Versions
new file mode 100644
index 000000000..be3d2b96c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/Versions
@@ -0,0 +1,28 @@
+libc {
+ # The comment lines with "#errlist-compat" are magic; see errlist-compat.awk.
+ # When you get an error from errlist-compat.awk, you need to add a new
+ # version here.
+
+ GLIBC_2.0 {
+ #errlist-compat 127
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+ }
+ GLIBC_2.1 {
+ #errlist-compat 127
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+ }
+ GLIBC_2.3 {
+ #errlist-compat 128
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+ }
+ GLIBC_2.4 {
+ #errlist-compat 134
+ _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+ }
+}
+librt {
+ GLIBC_2.3 {
+ # AIO functions.
+ aio_cancel; aio_cancel64;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/a.out.h b/libc/sysdeps/unix/sysv/linux/sparc/a.out.h
new file mode 100644
index 000000000..6ea7065e1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/a.out.h
@@ -0,0 +1,174 @@
+#ifndef __A_OUT_GNU_H__
+#define __A_OUT_GNU_H__
+
+#include <bits/a.out.h>
+
+#define __GNU_EXEC_MACROS__
+
+struct exec
+{
+ unsigned char a_dynamic:1; /* A __DYNAMIC is in this image. */
+ unsigned char a_toolversion:7;
+ unsigned char a_machtype;
+ unsigned short a_info;
+ unsigned int a_text; /* Length of text, in bytes. */
+ unsigned int a_data; /* Length of data, in bytes. */
+ unsigned int a_bss; /* Length of bss, in bytes. */
+ unsigned int a_syms; /* Length of symbol table, in bytes. */
+ unsigned int a_entry; /* Where program begins. */
+ unsigned int a_trsize;
+ unsigned int a_drsize;
+};
+
+enum machine_type
+{
+ M_OLDSUN2 = 0,
+ M_68010 = 1,
+ M_68020 = 2,
+ M_SPARC = 3,
+ M_386 = 100,
+ M_MIPS1 = 151,
+ M_MIPS2 = 152
+};
+
+#define N_MAGIC(exec) ((exec).a_info & 0xffff)
+#define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
+#define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
+#define N_SET_INFO(exec, magic, type, flags) \
+ ((exec).a_info = ((magic) & 0xffff) \
+ | (((int)(type) & 0xff) << 16) \
+ | (((flags) & 0xff) << 24))
+#define N_SET_MAGIC(exec, magic) \
+ ((exec).a_info = ((exec).a_info & 0xffff0000) | ((magic) & 0xffff))
+#define N_SET_MACHTYPE(exec, machtype) \
+ ((exec).a_info = \
+ ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
+#define N_SET_FLAGS(exec, flags) \
+ ((exec).a_info = \
+ ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
+
+/* Code indicating object file or impure executable. */
+#define OMAGIC 0407
+/* Code indicating pure executable. */
+#define NMAGIC 0410
+/* Code indicating demand-paged executable. */
+#define ZMAGIC 0413
+/* This indicates a demand-paged executable with the header in the text.
+ The first page is unmapped to help trap NULL pointer references. */
+#define QMAGIC 0314
+/* Code indicating core file. */
+#define CMAGIC 0421
+
+#define N_TRSIZE(a) ((a).a_trsize)
+#define N_DRSIZE(a) ((a).a_drsize)
+#define N_SYMSIZE(a) ((a).a_syms)
+#define N_BADMAG(x) \
+ (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \
+ && N_MAGIC(x) != ZMAGIC && N_MAGIC(x) != QMAGIC)
+#define _N_HDROFF(x) (1024 - sizeof (struct exec))
+#define N_TXTOFF(x) \
+ (N_MAGIC(x) == ZMAGIC ? 0 : sizeof (struct exec))
+#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
+#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
+#define N_DRELOFF(x) (N_TRELOFF(x) + N_TRSIZE(x))
+#define N_SYMOFF(x) \
+ (N_TXTOFF(x) + (x).a_text + (x).a_data + (x).a_trsize + (x).a_drsize)
+#define N_STROFF(x) (N_SYMOFF(x) + N_SYMSIZE(x))
+
+#define SPARC_PGSIZE 0x2000
+
+/* Address of text segment in memory after it is loaded. */
+#define N_TXTADDR(x) \
+ (unsigned long)(((N_MAGIC(x) == ZMAGIC) && ((x).a_entry < SPARC_PGSIZE)) \
+ ? 0 : SPARC_PGSIZE)
+
+/* Address of data segment in memory after it is loaded. */
+#define SEGMENT_SIZE SPARC_PGSIZE
+
+#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
+#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
+
+#define N_DATADDR(x) \
+ (N_MAGIC(x)==OMAGIC \
+ ? (N_TXTADDR(x) + (x).a_text) \
+ : (unsigned long)(_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
+#define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
+
+#if !defined (N_NLIST_DECLARED)
+struct nlist
+{
+ union
+ {
+ char *n_name;
+ struct nlist *n_next;
+ long n_strx;
+ } n_un;
+ unsigned char n_type;
+ char n_other;
+ short n_desc;
+ unsigned long n_value;
+};
+#endif /* no N_NLIST_DECLARED. */
+
+#define N_UNDF 0
+#define N_ABS 2
+#define N_TEXT 4
+#define N_DATA 6
+#define N_BSS 8
+#define N_FN 15
+#define N_EXT 1
+#define N_TYPE 036
+#define N_STAB 0340
+#define N_INDR 0xa
+#define N_SETA 0x14 /* Absolute set element symbol. */
+#define N_SETT 0x16 /* Text set element symbol. */
+#define N_SETD 0x18 /* Data set element symbol. */
+#define N_SETB 0x1A /* Bss set element symbol. */
+#define N_SETV 0x1C /* Pointer to set vector in data area. */
+
+#if !defined (N_RELOCATION_INFO_DECLARED)
+enum reloc_type
+{
+ RELOC_8,
+ RELOC_16,
+ RELOC_32,
+ RELOC_DISP8,
+ RELOC_DISP16,
+ RELOC_DISP32,
+ RELOC_WDISP30,
+ RELOC_WDISP22,
+ RELOC_HI22,
+ RELOC_22,
+ RELOC_13,
+ RELOC_LO10,
+ RELOC_SFA_BASE,
+ RELOC_SFA_OFF13,
+ RELOC_BASE10,
+ RELOC_BASE13,
+ RELOC_BASE22,
+ RELOC_PC10,
+ RELOC_PC22,
+ RELOC_JMP_TBL,
+ RELOC_SEGOFF16,
+ RELOC_GLOB_DAT,
+ RELOC_JMP_SLOT,
+ RELOC_RELATIVE
+};
+
+/* This structure describes a single relocation to be performed.
+ The text-relocation section of the file is a vector of these structures,
+ all of which apply to the text section.
+ Likewise, the data-relocation section applies to the data section. */
+
+struct relocation_info
+{
+ unsigned int r_address;
+ unsigned int r_index:24;
+ unsigned int r_extern:1;
+ int r_pad:2;
+ enum reloc_type r_type:5;
+ int r_addend;
+};
+#endif /* no N_RELOCATION_INFO_DECLARED. */
+
+#endif /* __A_OUT_GNU_H__ */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/a.out.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/a.out.h
new file mode 100644
index 000000000..228a8d41a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/a.out.h
@@ -0,0 +1,13 @@
+#ifndef __A_OUT_GNU_H__
+# error "Never use <bits/a.out.h> directly; include <a.out.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+
+/* Signal to users of this header that this architecture really doesn't
+ support a.out binary format. */
+#define __NO_A_OUT_SUPPORT 1
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/environments.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/environments.h
new file mode 100644
index 000000000..a51a564cb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/environments.h
@@ -0,0 +1,87 @@
+/* Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _UNISTD_H
+# error "Never include this file directly. Use <unistd.h> instead"
+#endif
+
+#include <bits/wordsize.h>
+
+/* This header should define the following symbols under the described
+ situations. A value `1' means that the model is always supported,
+ `-1' means it is never supported. Undefined means it cannot be
+ statically decided.
+
+ _POSIX_V6_ILP32_OFF32 32bit int, long, pointers, and off_t type
+ _POSIX_V6_ILP32_OFFBIG 32bit int, long, and pointers and larger off_t type
+
+ _POSIX_V6_LP64_OFF32 64bit long and pointers and 32bit off_t type
+ _POSIX_V6_LPBIG_OFFBIG 64bit long and pointers and large off_t type
+
+ The macros _XBS5_ILP32_OFF32, _XBS5_ILP32_OFFBIG, _XBS5_LP64_OFF32, and
+ _XBS5_LPBIG_OFFBIG were used in previous versions of the Unix standard
+ and are available only for compatibility.
+*/
+
+#if __WORDSIZE == 64
+
+/* Environments with 32-bit wide pointers are optionally provided.
+ Therefore following macros aren't defined:
+ # undef _POSIX_V6_ILP32_OFF32
+ # undef _POSIX_V6_ILP32_OFFBIG
+ # undef _XBS5_ILP32_OFF32
+ # undef _XBS5_ILP32_OFFBIG
+ and users need to check at runtime. */
+
+/* We also have no use (for now) for an environment with bigger pointers
+ and offsets. */
+# define _POSIX_V6_LPBIG_OFFBIG -1
+# define _XBS5_LPBIG_OFFBIG -1
+
+/* By default we have 64-bit wide `long int', pointers and `off_t'. */
+# define _POSIX_V6_LP64_OFF64 1
+# define _XBS5_LP64_OFF64 1
+
+#else /* __WORDSIZE == 32 */
+
+/* By default we have 32-bit wide `int', `long int', pointers and `off_t'
+ and all platforms support LFS. */
+# define _POSIX_V6_ILP32_OFF32 1
+# define _POSIX_V6_ILP32_OFFBIG 1
+# define _XBS5_ILP32_OFF32 1
+# define _XBS5_ILP32_OFFBIG 1
+
+/* We optionally provide an environment with the above size but an 64-bit
+ side `off_t'. Therefore we don't define _XBS5_ILP32_OFFBIG. */
+
+/* Environments with 64-bit wide pointers can be provided,
+ so these macros aren't defined:
+ # undef _POSIX_V6_LP64_OFF64
+ # undef _POSIX_V6_LPBIG_OFFBIG
+ # undef _XBS5_LP64_OFF64
+ # undef _XBS5_LPBIG_OFFBIG
+ and sysconf tests for it at runtime. */
+
+#endif /* __WORDSIZE == 32 */
+
+#define __ILP32_OFF32_CFLAGS "-m32"
+#define __ILP32_OFFBIG_CFLAGS "-m32 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+#define __ILP32_OFF32_LDFLAGS "-m32"
+#define __ILP32_OFFBIG_LDFLAGS "-m32"
+#define __LP64_OFF64_CFLAGS "-m64"
+#define __LP64_OFF64_LDFLAGS "-m64"
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/errno.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/errno.h
new file mode 100644
index 000000000..02e200c08
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/errno.h
@@ -0,0 +1,58 @@
+/* Error constants. Linux/Sparc specific version.
+ Copyright (C) 1996,1997,1998,1999,2002,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifdef _ERRNO_H
+
+# undef EDOM
+# undef EILSEQ
+# undef ERANGE
+# include <linux/errno.h>
+
+/* Linux has no ENOTSUP error code. */
+# define ENOTSUP EOPNOTSUPP
+
+# ifndef ECANCELED
+# define ECANCELED 127
+# endif
+
+/* Support for error codes to support robust mutexes was added later, too. */
+# ifndef EOWNERDEAD
+# define EOWNERDEAD 132
+# define ENOTRECOVERABLE 133
+# endif
+
+# ifndef __ASSEMBLER__
+/* Function to get address of global `errno' variable. */
+extern int *__errno_location (void) __THROW __attribute__ ((__const__));
+
+# if !defined _LIBC || defined _LIBC_REENTRANT
+/* When using threads, errno is a per-thread value. */
+# define errno (*__errno_location ())
+# endif
+# endif /* !__ASSEMBLER__ */
+#endif /* _ERRNO_H */
+
+#if !defined _ERRNO_H && defined __need_Emath
+/* This is ugly but the kernel header is not clean enough. We must
+ define only the values EDOM, EILSEQ and ERANGE in case __need_Emath is
+ defined. */
+# define EDOM 33 /* Math argument out of domain of function. */
+# define EILSEQ 122 /* Illegal byte sequence. */
+# define ERANGE 34 /* Math result not representable. */
+#endif /* !_ERRNO_H && __need_Emath */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h
new file mode 100644
index 000000000..a965d3165
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h
@@ -0,0 +1,255 @@
+/* O_*, F_*, FD_* bit values for Linux/SPARC.
+ Copyright (C) 1995, 1996, 1997, 1998, 2000, 2003, 2004, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <sys/types.h>
+#include <bits/wordsize.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on an ext2 file system */
+#define O_RDONLY 0x0000
+#define O_WRONLY 0x0001
+#define O_RDWR 0x0002
+#define O_ACCMODE 0x0003
+#define O_APPEND 0x0008
+#define O_ASYNC 0x0040
+#define O_CREAT 0x0200 /* not fcntl */
+#define O_TRUNC 0x0400 /* not fcntl */
+#define O_EXCL 0x0800 /* not fcntl */
+#define O_SYNC 0x2000
+#define O_NONBLOCK 0x4000
+#define O_NDELAY (0x0004 | O_NONBLOCK)
+#define O_NOCTTY 0x8000 /* not fcntl */
+
+#ifdef __USE_GNU
+# define O_DIRECTORY 0x10000 /* must be a directory */
+# define O_NOFOLLOW 0x20000 /* don't follow links */
+# define O_DIRECT 0x100000 /* direct disk access hint */
+# define O_NOATIME 0x200000 /* Do not set atime. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+# if __WORDSIZE == 64
+# define O_LARGEFILE 0
+# else
+# define O_LARGEFILE 0x40000
+# endif
+#endif
+
+/* For now Linux has no synchronisity options for data and read
+ operations. We define the symbols here but let them do the same as
+ O_SYNC since this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#if defined __USE_BSD || defined __USE_UNIX98
+# define F_GETOWN 5 /* Get owner of socket (receiver of SIGIO). */
+# define F_SETOWN 6 /* Set owner of socket (receiver of SIGIO). */
+#endif
+#ifndef __USE_FILE_OFFSET64
+# define F_GETLK 7 /* Get record locking info. */
+# define F_SETLK 8 /* Set record locking info (non-blocking). */
+# define F_SETLKW 9 /* Set record locking info (blocking). */
+#else
+# define F_GETLK F_GETLK64 /* Get record locking info. */
+# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
+# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+#endif
+
+#if __WORDSIZE == 64
+# define F_GETLK64 7 /* Get record locking info. */
+# define F_SETLK64 8 /* Set record locking info (non-blocking). */
+# define F_SETLKW64 9 /* Set record locking info (blocking). */
+#else
+# define F_GETLK64 12 /* Get record locking info. */
+# define F_SETLK64 13 /* Set record locking info (non-blocking). */
+# define F_SETLKW64 14 /* Set record locking info (blocking). */
+#endif
+
+/* for F_[GET|SET]FD */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
+#define F_RDLCK 1 /* Read lock. */
+#define F_WRLCK 2 /* Write lock. */
+#define F_UNLCK 3 /* Remove lock. */
+
+/* for old implementation of bsd flock () */
+#define F_EXLCK 4 /* or 3 */
+#define F_SHLCK 8 /* or 4 */
+
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation */
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#endif
+
+struct flock
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+#ifndef __USE_FILE_OFFSET64
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+#else
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+#endif
+ __pid_t l_pid; /* Process holding the lock. */
+ short int __unused;
+ };
+
+#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. */
+ short int __unused;
+ };
+#endif
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+#endif
+
+
+#ifdef __USE_GNU
+/* Flags for SYNC_FILE_RANGE. */
+# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
+ in the range before performing the
+ write. */
+# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
+ dirty pages in the range which are
+ not presently under writeback. */
+# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
+ the range after performing the
+ write. */
+
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+#endif
+
+__BEGIN_DECLS
+
+#ifdef __USE_GNU
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+
+/* Selective file content synch'ing. */
+extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
+ unsigned int __flags);
+
+
+/* Splice address range into a pipe. */
+extern int vmsplice (int __fdout, const struct iovec *__iov, size_t __count,
+ unsigned int __flags);
+
+/* Splice two files together. */
+extern int splice (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+/* In-kernel implementation of tee for pipe buffers. */
+extern int tee (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+#endif
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/ioctls.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/ioctls.h
new file mode 100644
index 000000000..e86c503f2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/ioctls.h
@@ -0,0 +1,37 @@
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IOCTL_H
+# error "Never use <bits/ioctls.h> directly; include <sys/ioctl.h> instead."
+#endif
+
+/* Use the definitions from the kernel header files. */
+#include <asm/ioctls.h>
+
+/* Oh well, this is necessary since the kernel data structure is
+ different from the user-level version. */
+#undef TCGETS
+#undef TCSETS
+#undef TCSETSW
+#undef TCSETSF
+#define TCGETS _IOR ('T', 8, char[36])
+#define TCSETS _IOW ('T', 9, char[36])
+#define TCSETSW _IOW ('T', 10, char[36])
+#define TCSETSF _IOW ('T', 11, char[36])
+
+#include <linux/sockios.h>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/ipc.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/ipc.h
new file mode 100644
index 000000000..988dc125d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/ipc.h
@@ -0,0 +1,62 @@
+/* Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IPC_H
+# error "Never use <bits/ipc.h> directly; include <sys/ipc.h> instead."
+#endif
+
+#include <bits/types.h>
+#include <bits/wordsize.h>
+
+/* Mode bits for `msgget', `semget', and `shmget'. */
+#define IPC_CREAT 01000 /* Create key if key does not exist. */
+#define IPC_EXCL 02000 /* Fail if key exists. */
+#define IPC_NOWAIT 04000 /* Return error on wait. */
+
+/* Control commands for `msgctl', `semctl', and `shmctl'. */
+#define IPC_RMID 0 /* Remove identifier. */
+#define IPC_SET 1 /* Set `ipc_perm' options. */
+#define IPC_STAT 2 /* Get `ipc_perm' options. */
+#ifdef __USE_GNU
+# define IPC_INFO 3 /* See ipcs. */
+#endif
+
+/* Special key values. */
+#define IPC_PRIVATE ((__key_t) 0) /* Private key. */
+
+
+/* Data structure used to pass permission information to IPC operations. */
+struct ipc_perm
+ {
+ __key_t __key; /* Key. */
+ __uid_t uid; /* Owner's user ID. */
+ __gid_t gid; /* Owner's group ID. */
+ __uid_t cuid; /* Creator's user ID. */
+ __gid_t cgid; /* Creator's group ID. */
+#if __WORDSIZE == 32
+ unsigned short int __pad1;
+ unsigned short int mode; /* Read/write permission. */
+ unsigned short int __pad2;
+#else
+ __mode_t mode; /* Read/write permission. */
+ unsigned short int __pad1;
+#endif
+ unsigned short int __seq; /* Sequence number. */
+ unsigned long long int __unused1;
+ unsigned long long int __unused2;
+ };
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/mman.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/mman.h
new file mode 100644
index 000000000..be2b7eb28
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/mman.h
@@ -0,0 +1,106 @@
+/* Definitions for POSIX memory map interface. Linux/SPARC version.
+ Copyright (C) 1997,1999,2000,2003,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MMAN_H
+# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead."
+#endif
+
+/* The following definitions basically come from the kernel headers.
+ But the kernel header is not namespace clean. */
+
+
+/* Protections are chosen from these bits, OR'd together. The
+ implementation does not necessarily support PROT_EXEC or PROT_WRITE
+ without PROT_READ. The only guarantees are that no writing will be
+ allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
+
+#define PROT_READ 0x1 /* Page can be read. */
+#define PROT_WRITE 0x2 /* Page can be written. */
+#define PROT_EXEC 0x4 /* Page can be executed. */
+#define PROT_NONE 0x0 /* Page can not be accessed. */
+#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
+ growsdown vma (mprotect only). */
+#define PROT_GROWSUP 0x02000000 /* Extend change to start of
+ growsup vma (mprotect only). */
+
+/* Sharing types (must choose one and only one of these). */
+#define MAP_SHARED 0x01 /* Share changes. */
+#define MAP_PRIVATE 0x02 /* Changes are private. */
+#ifdef __USE_MISC
+# define MAP_TYPE 0x0f /* Mask for type of mapping. */
+#endif
+
+/* Other flags. */
+#define MAP_FIXED 0x10 /* Interpret addr exactly. */
+#ifdef __USE_MISC
+# define MAP_FILE 0x00
+# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
+# define MAP_ANON MAP_ANONYMOUS
+# define MAP_RENAME MAP_ANONYMOUS
+#endif
+
+/* These are Linux-specific. */
+#ifdef __USE_MISC
+# define MAP_GROWSDOWN 0x0200 /* Stack-like segment. */
+# define MAP_DENYWRITE 0x0800 /* ETXTBSY */
+# define MAP_EXECUTABLE 0x1000 /* Mark it as an executable. */
+# define MAP_LOCKED 0x0100 /* Lock the mapping. */
+# define MAP_NORESERVE 0x0040 /* Don't check for reservations. */
+# define _MAP_NEW 0x80000000 /* Binary compatibility with SunOS. */
+# define MAP_POPULATE 0x8000 /* Populate (prefault) pagetables. */
+# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
+#endif
+
+/* Flags to `msync'. */
+#define MS_ASYNC 1 /* Sync memory asynchronously. */
+#define MS_SYNC 4 /* Synchronous memory sync. */
+#define MS_INVALIDATE 2 /* Invalidate the caches. */
+
+/* Flags for `mlockall'. */
+#define MCL_CURRENT 0x2000 /* Lock all currently mapped pages. */
+#define MCL_FUTURE 0x4000 /* Lock all additions to address
+ space. */
+
+/* Flags for `mremap'. */
+#ifdef __USE_GNU
+# define MREMAP_MAYMOVE 1
+# define MREMAP_FIXED 2
+#endif
+
+/* Advice to `madvise'. */
+#ifdef __USE_BSD
+# define MADV_NORMAL 0 /* No further special treatment. */
+# define MADV_RANDOM 1 /* Expect random page references. */
+# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define MADV_WILLNEED 3 /* Will need these pages. */
+# define MADV_DONTNEED 4 /* Don't need these pages. */
+# define MADV_FREE 5 /* Content can be freed (Solaris). */
+# define MADV_REMOVE 9 /* Remove these pages and resources. */
+# define MADV_DONTFORK 10 /* Do not inherit across fork. */
+# define MADV_DOFORK 11 /* Do inherit across fork. */
+#endif
+
+/* The POSIX people had to invent similar names for the same things. */
+#ifdef __USE_XOPEN2K
+# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/msq.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/msq.h
new file mode 100644
index 000000000..1268dc858
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/msq.h
@@ -0,0 +1,84 @@
+/* Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MSG_H
+# error "Never use <bits/msq.h> directly; include <sys/msg.h> instead."
+#endif
+
+#include <bits/types.h>
+#include <bits/wordsize.h>
+
+/* Define options for message queue functions. */
+#define MSG_NOERROR 010000 /* no error if message is too big */
+#ifdef __USE_GNU
+# define MSG_EXCEPT 020000 /* recv any msg except of specified type */
+#endif
+
+/* Types used in the structure definition. */
+typedef unsigned long int msgqnum_t;
+typedef unsigned long int msglen_t;
+
+
+/* Structure of record for one message inside the kernel.
+ The type `struct msg' is opaque. */
+struct msqid_ds
+{
+ struct ipc_perm msg_perm; /* structure describing operation permission */
+#if __WORDSIZE == 32
+ unsigned int __pad1;
+#endif
+ __time_t msg_stime; /* time of last msgsnd command */
+#if __WORDSIZE == 32
+ unsigned int __pad2;
+#endif
+ __time_t msg_rtime; /* time of last msgrcv command */
+#if __WORDSIZE == 32
+ unsigned int __pad3;
+#endif
+ __time_t msg_ctime; /* time of last change */
+ 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 __unused1;
+ unsigned long int __unused2;
+};
+
+#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/libc/sysdeps/unix/sysv/linux/sparc/bits/poll.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/poll.h
new file mode 100644
index 000000000..53b94bc50
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/poll.h
@@ -0,0 +1,50 @@
+/* Copyright (C) 1997, 2001, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_POLL_H
+# error "Never use <bits/poll.h> directly; include <sys/poll.h> instead."
+#endif
+
+/* Event types that can be polled for. These bits may be set in `events'
+ to indicate the interesting event types; they will appear in `revents'
+ to indicate the status of the file descriptor. */
+#define POLLIN 0x001 /* There is data to read. */
+#define POLLPRI 0x002 /* There is urgent data to read. */
+#define POLLOUT 0x004 /* Writing now will not block. */
+
+#ifdef __USE_XOPEN
+/* These values are defined in XPG4.2. */
+# define POLLRDNORM 0x040 /* Normal data may be read. */
+# define POLLRDBAND 0x080 /* Priority data may be read. */
+# define POLLWRNORM POLLOUT /* Writing now will not block. */
+# define POLLWRBAND 0x100 /* Priority data may be written. */
+#endif
+
+#ifdef __USE_GNU
+/* These are extensions for Linux. */
+# define POLLMSG 0x200
+# define POLLREMOVE 0x400
+# define POLLRDHUP 0x800
+#endif
+
+/* Event types always implicitly polled for. These bits need not be set in
+ `events', but they will appear in `revents' to indicate the status of
+ the file descriptor. */
+#define POLLERR 0x008 /* Error condition. */
+#define POLLHUP 0x010 /* Hung up. */
+#define POLLNVAL 0x020 /* Invalid polling request. */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/resource.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/resource.h
new file mode 100644
index 000000000..3f2c60014
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/resource.h
@@ -0,0 +1,241 @@
+/* Bit values & structures for resource limits. Linux/SPARC version.
+ Copyright (C) 1994, 1996, 1997, 1998, 1999, 2000, 2004, 2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_RESOURCE_H
+# error "Never use <bits/resource.h> directly; include <sys/resource.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Transmute defines to enumerations. The macro re-definitions are
+ necessary because some programs want to test for operating system
+ features with #ifdef RUSAGE_SELF. In ISO C the reflexive
+ definition is a no-op. */
+
+/* Kinds of resource limit. */
+enum __rlimit_resource
+{
+ /* Per-process CPU limit, in seconds. */
+ RLIMIT_CPU = 0,
+#define RLIMIT_CPU RLIMIT_CPU
+
+ /* Largest file that can be created, in bytes. */
+ RLIMIT_FSIZE = 1,
+#define RLIMIT_FSIZE RLIMIT_FSIZE
+
+ /* Maximum size of data segment, in bytes. */
+ RLIMIT_DATA = 2,
+#define RLIMIT_DATA RLIMIT_DATA
+
+ /* Maximum size of stack segment, in bytes. */
+ RLIMIT_STACK = 3,
+#define RLIMIT_STACK RLIMIT_STACK
+
+ /* Largest core file that can be created, in bytes. */
+ RLIMIT_CORE = 4,
+#define RLIMIT_CORE RLIMIT_CORE
+
+ /* Largest resident set size, in bytes.
+ This affects swapping; processes that are exceeding their
+ resident set size will be more likely to have physical memory
+ taken from them. */
+ __RLIMIT_RSS = 5,
+#define RLIMIT_RSS __RLIMIT_RSS
+
+ /* Number of open files. */
+ RLIMIT_NOFILE = 6,
+ __RLIMIT_OFILE = RLIMIT_NOFILE, /* BSD name for same. */
+#define RLIMIT_NOFILE RLIMIT_NOFILE
+#define RLIMIT_OFILE __RLIMIT_OFILE
+
+ /* Address space limit (?) */
+ RLIMIT_AS = 9,
+#define RLIMIT_AS RLIMIT_AS
+
+ /* Number of processes. */
+ __RLIMIT_NPROC = 7,
+#define RLIMIT_NPROC __RLIMIT_NPROC
+
+ /* Locked-in-memory address space. */
+ __RLIMIT_MEMLOCK = 8,
+#define RLIMIT_MEMLOCK __RLIMIT_MEMLOCK
+
+ /* Maximum number of file locks. */
+ __RLIMIT_LOCKS = 10,
+#define RLIMIT_LOCKS __RLIMIT_LOCKS
+
+ /* Maximum number of pending signals. */
+ __RLIMIT_SIGPENDING = 11,
+#define RLIMIT_SIGPENDING __RLIMIT_SIGPENDING
+
+ /* Maximum bytes in POSIX message queues. */
+ __RLIMIT_MSGQUEUE = 12,
+#define RLIMIT_MSGQUEUE __RLIMIT_MSGQUEUE
+
+ /* Maximum nice priority allowed to raise to.
+ Nice levels 19 .. -20 correspond to 0 .. 39
+ values of this resource limit. */
+ __RLIMIT_NICE = 13,
+#define RLIMIT_NICE __RLIMIT_NICE
+
+ /* Maximum realtime priority allowed for non-priviledged
+ processes. */
+ __RLIMIT_RTPRIO = 14,
+#define RLIMIT_RTPRIO __RLIMIT_RTPRIO
+
+ __RLIMIT_NLIMITS = 15,
+ __RLIM_NLIMITS = __RLIMIT_NLIMITS
+#define RLIMIT_NLIMITS __RLIMIT_NLIMITS
+#define RLIM_NLIMITS __RLIM_NLIMITS
+};
+
+/* Value to indicate that there is no limit. */
+#if __WORDSIZE == 64
+
+#ifndef __USE_FILE_OFFSET64
+# define RLIM_INFINITY ((unsigned long int)(~0UL))
+#else
+# define RLIM_INFINITY 0xffffffffffffffffuLL
+#endif
+
+#ifdef __USE_LARGEFILE64
+# define RLIM64_INFINITY 0xffffffffffffffffuLL
+#endif
+
+#else
+
+#ifndef __USE_FILE_OFFSET64
+# define RLIM_INFINITY ((long int)(~0UL >> 1))
+#else
+# define RLIM_INFINITY 0x7fffffffffffffffLL
+#endif
+
+#ifdef __USE_LARGEFILE64
+# define RLIM64_INFINITY 0x7fffffffffffffffLL
+#endif
+
+#endif
+
+/* We can represent all limits. */
+#define RLIM_SAVED_MAX RLIM_INFINITY
+#define RLIM_SAVED_CUR RLIM_INFINITY
+
+
+/* Type for resource quantity measurement. */
+#ifndef __USE_FILE_OFFSET64
+typedef __rlim_t rlim_t;
+#else
+typedef __rlim64_t rlim_t;
+#endif
+#ifdef __USE_LARGEFILE64
+typedef __rlim64_t rlim64_t;
+#endif
+
+struct rlimit
+ {
+ /* The current (soft) limit. */
+ rlim_t rlim_cur;
+ /* The hard limit. */
+ rlim_t rlim_max;
+ };
+
+#ifdef __USE_LARGEFILE64
+struct rlimit64
+ {
+ /* The current (soft) limit. */
+ rlim64_t rlim_cur;
+ /* The hard limit. */
+ rlim64_t rlim_max;
+ };
+#endif
+
+/* Whose usage statistics do you want? */
+enum __rusage_who
+{
+ /* The calling process. */
+ RUSAGE_SELF = 0,
+#define RUSAGE_SELF RUSAGE_SELF
+
+ /* All of its terminated child processes. */
+ RUSAGE_CHILDREN = -1
+#define RUSAGE_CHILDREN RUSAGE_CHILDREN
+};
+
+#define __need_timeval
+#include <bits/time.h> /* For `struct timeval'. */
+
+/* Structure which says how much of each resource has been used. */
+struct rusage
+ {
+ /* Total amount of user time used. */
+ struct timeval ru_utime;
+ /* Total amount of system time used. */
+ struct timeval ru_stime;
+ /* Maximum resident set size (in kilobytes). */
+ long int ru_maxrss;
+ /* Amount of sharing of text segment memory
+ with other processes (kilobyte-seconds). */
+ long int ru_ixrss;
+ /* Amount of data segment memory used (kilobyte-seconds). */
+ long int ru_idrss;
+ /* Amount of stack memory used (kilobyte-seconds). */
+ long int ru_isrss;
+ /* Number of soft page faults (i.e. those serviced by reclaiming
+ a page from the list of pages awaiting reallocation. */
+ long int ru_minflt;
+ /* Number of hard page faults (i.e. those that required I/O). */
+ long int ru_majflt;
+ /* Number of times a process was swapped out of physical memory. */
+ long int ru_nswap;
+ /* Number of input operations via the file system. Note: This
+ and `ru_oublock' do not include operations with the cache. */
+ long int ru_inblock;
+ /* Number of output operations via the file system. */
+ long int ru_oublock;
+ /* Number of IPC messages sent. */
+ long int ru_msgsnd;
+ /* Number of IPC messages received. */
+ long int ru_msgrcv;
+ /* Number of signals delivered. */
+ long int ru_nsignals;
+ /* Number of voluntary context switches, i.e. because the process
+ gave up the process before it had to (usually to wait for some
+ resource to be available). */
+ long int ru_nvcsw;
+ /* Number of involuntary context switches, i.e. a higher priority process
+ became runnable or the current process used up its time slice. */
+ long int ru_nivcsw;
+ };
+
+/* Priority limits. */
+#define PRIO_MIN -20 /* Minimum priority a process can have. */
+#define PRIO_MAX 20 /* Maximum priority a process can have. */
+
+/* The type of the WHICH argument to `getpriority' and `setpriority',
+ indicating what flavor of entity the WHO argument specifies. */
+enum __priority_which
+{
+ PRIO_PROCESS = 0, /* WHO is a process ID. */
+#define PRIO_PROCESS PRIO_PROCESS
+ PRIO_PGRP = 1, /* WHO is a process group ID. */
+#define PRIO_PGRP PRIO_PGRP
+ PRIO_USER = 2 /* WHO is a user ID. */
+#define PRIO_USER PRIO_USER
+};
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/sem.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/sem.h
new file mode 100644
index 000000000..288076510
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/sem.h
@@ -0,0 +1,92 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SEM_H
+# error "Never include <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 */
+#if __WORDSIZE == 32
+ unsigned int __pad1;
+#endif
+ __time_t sem_otime; /* last semop() time */
+#if __WORDSIZE == 32
+ unsigned int __pad2;
+#endif
+ __time_t sem_ctime; /* last time changed by semctl() */
+ unsigned long int sem_nsems; /* number of semaphores in set */
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+};
+
+/* 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/libc/sysdeps/unix/sysv/linux/sparc/bits/setjmp.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/setjmp.h
new file mode 100644
index 000000000..b44cc0fcd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/setjmp.h
@@ -0,0 +1,69 @@
+/* Copyright (C) 1997, 1999, 2000, 2003, 2005, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _BITS_SETJMP_H
+#define _BITS_SETJMP_H 1
+
+#if !defined _SETJMP_H && !defined _PTHREAD_H
+# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+
+#ifndef _ASM
+typedef struct __sparc64_jmp_buf
+ {
+ struct __sparc64_jmp_buf *uc_link;
+ unsigned long uc_flags;
+ unsigned long uc_sigmask;
+ struct __sparc64_jmp_buf_mcontext
+ {
+ unsigned long mc_gregs[19];
+ unsigned long mc_fp;
+ unsigned long mc_i7;
+ struct __sparc64_jmp_buf_fpu
+ {
+ union
+ {
+ unsigned int sregs[32];
+ unsigned long dregs[32];
+ long double qregs[16];
+ } mcfpu_fpregs;
+ unsigned long mcfpu_fprs;
+ unsigned long mcfpu_gsr;
+ void *mcfpu_fq;
+ unsigned char mcfpu_qcnt;
+ unsigned char mcfpu_qentsz;
+ unsigned char mcfpu_enab;
+ } mc_fpregs;
+ } uc_mcontext;
+ } __jmp_buf[1];
+#endif
+
+#else
+
+#ifndef _ASM
+typedef int __jmp_buf[3];
+#endif
+
+#endif
+
+#endif /* bits/setjmp.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/shm.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/shm.h
new file mode 100644
index 000000000..03decb110
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/shm.h
@@ -0,0 +1,111 @@
+/* Copyright (C) 1995, 1996, 1997, 2000, 2002, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_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 */
+
+/* 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 set of semaphores. */
+struct shmid_ds
+ {
+ struct ipc_perm shm_perm; /* operation permission struct */
+#if __WORDSIZE == 32
+ unsigned int __pad1;
+#endif
+ __time_t shm_atime; /* time of last shmat() */
+#if __WORDSIZE == 32
+ unsigned int __pad2;
+#endif
+ __time_t shm_dtime; /* time of last shmdt() */
+#if __WORDSIZE == 32
+ unsigned int __pad3;
+#endif
+ __time_t shm_ctime; /* time of last change by shmctl() */
+ size_t shm_segsz; /* size of segment in bytes */
+ __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 __unused1;
+ unsigned long int __unused2;
+ };
+
+#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 shmmax;
+ unsigned long shmmin;
+ unsigned long shmmni;
+ unsigned long shmseg;
+ unsigned long shmall;
+ unsigned long __unused1;
+ unsigned long __unused2;
+ unsigned long __unused3;
+ unsigned long __unused4;
+ };
+
+struct shm_info
+ {
+ int used_ids;
+ unsigned long int shm_tot; /* total allocated shm */
+ unsigned long int shm_rss; /* total resident shm */
+ unsigned long int shm_swp; /* total swapped shm */
+ unsigned long int swap_attempts;
+ unsigned long int swap_successes;
+ };
+
+#endif /* __USE_MISC */
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/sigaction.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/sigaction.h
new file mode 100644
index 000000000..ee4196764
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/sigaction.h
@@ -0,0 +1,76 @@
+/* The proper definitions for Linux/SPARC sigaction.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIGNAL_H
+# error "Never include <bits/sigaction.h> directly; use <signal.h> instead."
+#endif
+
+/* Structure describing the action to be taken when a signal arrives. */
+struct sigaction
+ {
+ /* Signal handler. */
+#ifdef __USE_POSIX199309
+ union
+ {
+ /* Used if SA_SIGINFO is not set. */
+ __sighandler_t sa_handler;
+ /* Used if SA_SIGINFO is set. */
+ void (*sa_sigaction) (int, siginfo_t *, void *);
+ }
+ __sigaction_handler;
+# define sa_handler __sigaction_handler.sa_handler
+# define sa_sigaction __sigaction_handler.sa_sigaction
+#else
+ __sighandler_t sa_handler;
+#endif
+
+ /* Additional set of signals to be blocked. */
+ __sigset_t sa_mask;
+
+ /* Special flags. */
+ unsigned long sa_flags;
+
+ /* Not used by Linux/Sparc yet. */
+ void (*sa_restorer) (void);
+ };
+
+
+/* Bits in `sa_flags'. */
+#define SA_NOCLDSTOP 0x00000008 /* Don't send SIGCHLD when children stop. */
+#define SA_NOCLDWAIT 0x00000100 /* Don't create zombie on child death. */
+#define SA_SIGINFO 0x00000200 /* Invoke signal-catching function with
+ three arguments instead of one. */
+#if defined __USE_UNIX98 || defined __USE_MISC
+# define SA_ONSTACK 0x00000001 /* Use signal stack by using `sa_restorer'. */
+# define SA_RESTART 0x00000002 /* Restart syscall on signal return. */
+# define SA_INTERRUPT 0x00000010 /* Historical no-op. */
+# define SA_NOMASK 0x00000020 /* Don't automatically block the signal when
+ its handler is being executed. */
+# define SA_ONESHOT 0x00000004 /* Reset to SIG_DFL on entry to handler. */
+
+/* Some aliases for the SA_ constants. */
+# define SA_NODEFER SA_NOMASK
+# define SA_RESETHAND SA_ONESHOT
+# define SA_STACK SA_ONSTACK
+#endif
+
+/* Values for the HOW argument to `sigprocmask'. */
+#define SIG_BLOCK 1 /* Block signals. */
+#define SIG_UNBLOCK 2 /* Unblock signals. */
+#define SIG_SETMASK 4 /* Set the set of blocked signals. */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/sigcontext.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/sigcontext.h
new file mode 100644
index 000000000..42eca544e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/sigcontext.h
@@ -0,0 +1,78 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#if !defined _SIGNAL_H && !defined _SYS_UCONTEXT_H
+# error "Never use <bits/sigcontext.h> directly; include <signal.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 32
+
+/* It is quite hard to choose what to put here, because
+ Linux/sparc32 had at least 3 totally incompatible
+ signal stack layouts.
+ This one is for the "new" style signals, which are
+ now delivered unless SA_SIGINFO is requested. */
+
+struct sigcontext
+ {
+ struct
+ {
+ unsigned int psr;
+ unsigned int pc;
+ unsigned int npc;
+ unsigned int y;
+ unsigned int u_regs[16]; /* globals and ins */
+ } si_regs;
+ int si_mask;
+ };
+
+#else /* sparc64 */
+
+typedef struct
+ {
+ unsigned int si_float_regs [64];
+ unsigned long si_fsr;
+ unsigned long si_gsr;
+ unsigned long si_fprs;
+ } __siginfo_fpu_t;
+
+struct sigcontext
+ {
+ char sigc_info[128];
+ struct
+ {
+ unsigned long u_regs[16]; /* globals and ins */
+ unsigned long tstate;
+ unsigned long tpc;
+ unsigned long tnpc;
+ unsigned int y;
+ unsigned int fprs;
+ } sigc_regs;
+ __siginfo_fpu_t * sigc_fpu_save;
+ struct
+ {
+ void * ss_sp;
+ int ss_flags;
+ unsigned long ss_size;
+ } sigc_stack;
+ unsigned long sigc_mask;
+};
+
+#endif /* sparc64 */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/siginfo.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/siginfo.h
new file mode 100644
index 000000000..7ff1971c2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/siginfo.h
@@ -0,0 +1,318 @@
+/* siginfo_t, sigevent and constants. Linux/SPARC version.
+ Copyright (C) 1997-2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#if !defined _SIGNAL_H && !defined __need_siginfo_t \
+ && !defined __need_sigevent_t
+# error "Never include this file directly. Use <signal.h> instead"
+#endif
+
+#include <bits/wordsize.h>
+
+#if (!defined __have_sigval_t \
+ && (defined _SIGNAL_H || defined __need_siginfo_t \
+ || defined __need_sigevent_t))
+# define __have_sigval_t 1
+
+/* Type for data associated with a signal. */
+typedef union sigval
+ {
+ int sival_int;
+ void *sival_ptr;
+ } sigval_t;
+#endif
+
+#if (!defined __have_siginfo_t \
+ && (defined _SIGNAL_H || defined __need_siginfo_t))
+# define __have_siginfo_t 1
+
+# define __SI_MAX_SIZE 128
+# if __WORDSIZE == 64
+# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 4)
+# else
+# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
+# endif
+
+typedef struct siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_errno; /* If non-zero, an errno value associated with
+ this signal, as defined in <errno.h>. */
+ int si_code; /* Signal code. */
+
+ union
+ {
+ int _pad[__SI_PAD_SIZE];
+
+ /* kill(). */
+ struct
+ {
+ __pid_t si_pid; /* Sending process ID. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ } _kill;
+
+ /* POSIX.1b timers. */
+ struct
+ {
+ int si_tid; /* Timer ID. */
+ int si_overrun; /* Overrun count. */
+ sigval_t si_sigval; /* Signal value. */
+ } _timer;
+
+ /* POSIX.1b signals. */
+ struct
+ {
+ __pid_t si_pid; /* Sending process ID. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ sigval_t si_sigval; /* Signal value. */
+ } _rt;
+
+ /* SIGCHLD. */
+ struct
+ {
+ __pid_t si_pid; /* Which child. */
+ __uid_t si_uid; /* Real user ID of sending process. */
+ int si_status; /* Exit value or signal. */
+ __clock_t si_utime;
+ __clock_t si_stime;
+ } _sigchld;
+
+ /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
+ struct
+ {
+ void *si_addr; /* Faulting insn/memory ref. */
+ int si_trapno;
+ } _sigfault;
+
+ /* SIGPOLL. */
+ struct
+ {
+ int si_band; /* Band event for SIGPOLL. */
+ int si_fd;
+ } _sigpoll;
+ } _sifields;
+ } siginfo_t;
+
+
+/* X/Open requires some more fields with fixed names. */
+# define si_pid _sifields._kill.si_pid
+# define si_uid _sifields._kill.si_uid
+# define si_timerid _sifields._timer.si_tid
+# define si_overrun _sifields._timer.si_overrun
+# define si_status _sifields._sigchld.si_status
+# define si_utime _sifields._sigchld.si_utime
+# define si_stime _sifields._sigchld.si_stime
+# define si_value _sifields._rt.si_sigval
+# define si_int _sifields._rt.si_sigval.sival_int
+# define si_ptr _sifields._rt.si_sigval.sival_ptr
+# define si_addr _sifields._sigfault.si_addr
+# define si_trapno _sifields._sigfault.si_trapno
+# define si_band _sifields._sigpoll.si_band
+# define si_fd _sifields._sigpoll.si_fd
+
+
+/* Values for `si_code'. Positive values are reserved for kernel-generated
+ signals. */
+enum
+{
+ SI_ASYNCNL = -60, /* Sent by asynch name lookup completion. */
+# define SI_ASYNCNL SI_ASYNCNL
+ SI_TKILL = -6, /* Sent by tkill. */
+# define SI_TKILL SI_TKILL
+ SI_SIGIO, /* Sent by queued SIGIO. */
+# define SI_SIGIO SI_SIGIO
+ SI_ASYNCIO, /* Sent by AIO completion. */
+# define SI_ASYNCIO SI_ASYNCIO
+ SI_MESGQ, /* Sent by real time mesq state change. */
+# define SI_MESGQ SI_MESGQ
+ SI_TIMER, /* Sent by timer expiration. */
+# define SI_TIMER SI_TIMER
+ SI_QUEUE, /* Sent by sigqueue. */
+# define SI_QUEUE SI_QUEUE
+ SI_USER, /* Sent by kill, sigsend, raise. */
+# define SI_USER SI_USER
+ SI_KERNEL = 0x80 /* Send by kernel. */
+#define SI_KERNEL SI_KERNEL
+};
+
+
+/* `si_code' values for SIGILL signal. */
+enum
+{
+ ILL_ILLOPC = 1, /* Illegal opcode. */
+# define ILL_ILLOPC ILL_ILLOPC
+ ILL_ILLOPN, /* Illegal operand. */
+# define ILL_ILLOPN ILL_ILLOPN
+ ILL_ILLADR, /* Illegal addressing mode. */
+# define ILL_ILLADR ILL_ILLADR
+ ILL_ILLTRP, /* Illegal trap. */
+# define ILL_ILLTRP ILL_ILLTRP
+ ILL_PRVOPC, /* Privileged opcode. */
+# define ILL_PRVOPC ILL_PRVOPC
+ ILL_PRVREG, /* Privileged register. */
+# define ILL_PRVREG ILL_PRVREG
+ ILL_COPROC, /* Coprocessor error. */
+# define ILL_COPROC ILL_COPROC
+ ILL_BADSTK /* Internal stack error. */
+# define ILL_BADSTK ILL_BADSTK
+};
+
+/* `si_code' values for SIGFPE signal. */
+enum
+{
+ FPE_INTDIV = 1, /* Integer divide by zero. */
+# define FPE_INTDIV FPE_INTDIV
+ FPE_INTOVF, /* Integer overflow. */
+# define FPE_INTOVF FPE_INTOVF
+ FPE_FLTDIV, /* Floating point divide by zero. */
+# define FPE_FLTDIV FPE_FLTDIV
+ FPE_FLTOVF, /* Floating point overflow. */
+# define FPE_FLTOVF FPE_FLTOVF
+ FPE_FLTUND, /* Floating point underflow. */
+# define FPE_FLTUND FPE_FLTUND
+ FPE_FLTRES, /* Floating point inexact result. */
+# define FPE_FLTRES FPE_FLTRES
+ FPE_FLTINV, /* Floating point invalid operation. */
+# define FPE_FLTINV FPE_FLTINV
+ FPE_FLTSUB /* Subscript out of range. */
+# define FPE_FLTSUB FPE_FLTSUB
+};
+
+/* `si_code' values for SIGSEGV signal. */
+enum
+{
+ SEGV_MAPERR = 1, /* Address not mapped to object. */
+# define SEGV_MAPERR SEGV_MAPERR
+ SEGV_ACCERR /* Invalid permissions for mapped object. */
+# define SEGV_ACCERR SEGV_ACCERR
+};
+
+/* `si_code' values for SIGBUS signal. */
+enum
+{
+ BUS_ADRALN = 1, /* Invalid address alignment. */
+# define BUS_ADRALN BUS_ADRALN
+ BUS_ADRERR, /* Non-existant physical address. */
+# define BUS_ADRERR BUS_ADRERR
+ BUS_OBJERR /* Object specific hardware error. */
+# define BUS_OBJERR BUS_OBJERR
+};
+
+/* `si_code' values for SIGTRAP signal. */
+enum
+{
+ TRAP_BRKPT = 1, /* Process breakpoint. */
+# define TRAP_BRKPT TRAP_BRKPT
+ TRAP_TRACE /* Process trace trap. */
+# define TRAP_TRACE TRAP_TRACE
+};
+
+/* `si_code' values for SIGCHLD signal. */
+enum
+{
+ CLD_EXITED = 1, /* Child has exited. */
+# define CLD_EXITED CLD_EXITED
+ CLD_KILLED, /* Child was killed. */
+# define CLD_KILLED CLD_KILLED
+ CLD_DUMPED, /* Child terminated abnormally. */
+# define CLD_DUMPED CLD_DUMPED
+ CLD_TRAPPED, /* Traced child has trapped. */
+# define CLD_TRAPPED CLD_TRAPPED
+ CLD_STOPPED, /* Child has stopped. */
+# define CLD_STOPPED CLD_STOPPED
+ CLD_CONTINUED /* Stopped child has continued. */
+# define CLD_CONTINUED CLD_CONTINUED
+};
+
+/* `si_code' values for SIGPOLL signal. */
+enum
+{
+ POLL_IN = 1, /* Data input available. */
+# define POLL_IN POLL_IN
+ POLL_OUT, /* Output buffers available. */
+# define POLL_OUT POLL_OUT
+ POLL_MSG, /* Input message available. */
+# define POLL_MSG POLL_MSG
+ POLL_ERR, /* I/O error. */
+# define POLL_ERR POLL_ERR
+ POLL_PRI, /* High priority input available. */
+# define POLL_PRI POLL_PRI
+ POLL_HUP /* Device disconnected. */
+# define POLL_HUP POLL_HUP
+};
+
+/* `si_code' values for SIGEMT signal. */
+enum
+{
+ EMT_TAGOVF = 1 /* Tag overflow. */
+# define EMT_TAGOVF EMT_TAGOVF
+};
+
+# undef __need_siginfo_t
+#endif /* !have siginfo_t && (have _SIGNAL_H || need siginfo_t). */
+
+
+#if (defined _SIGNAL_H || defined __need_sigevent_t) \
+ && !defined __have_sigevent_t
+# define __have_sigevent_t 1
+
+/* Structure to transport application-defined values with signals. */
+# define __SIGEV_MAX_SIZE 64
+# if __WORDSIZE == 64
+# define __SIGEV_PAD_SIZE ((__SIGEV_MAX_SIZE / sizeof (int)) - 4)
+# else
+# define __SIGEV_PAD_SIZE ((__SIGEV_MAX_SIZE / sizeof (int)) - 3)
+# endif
+
+typedef struct sigevent
+ {
+ sigval_t sigev_value;
+ int sigev_signo;
+ int sigev_notify;
+
+ union
+ {
+ int _pad[__SIGEV_PAD_SIZE];
+
+ struct
+ {
+ void (*_function) (sigval_t); /* Function to start. */
+ void *_attribute; /* Really pthread_attr_t. */
+ } _sigev_thread;
+ } _sigev_un;
+ } sigevent_t;
+
+/* POSIX names to access some of the members. */
+# define sigev_notify_function _sigev_un._sigev_thread._function
+# define sigev_notify_attributes _sigev_un._sigev_thread._attribute
+
+/* `sigev_notify' values. */
+enum
+{
+ SIGEV_SIGNAL = 0, /* Notify via signal. */
+# define SIGEV_SIGNAL SIGEV_SIGNAL
+ SIGEV_NONE, /* Other notification: meaningless. */
+# define SIGEV_NONE SIGEV_NONE
+ SIGEV_THREAD, /* Deliver via thread creation. */
+# define SIGEV_THREAD SIGEV_THREAD
+
+ SIGEV_THREAD_ID = 4 /* Send signal to specific thread. */
+#define SIGEV_THREAD_ID SIGEV_THREAD_ID
+};
+
+#endif /* have _SIGNAL_H. */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/signum.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/signum.h
new file mode 100644
index 000000000..6b58ec29d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/signum.h
@@ -0,0 +1,84 @@
+/* Signal number definitions. Linux/SPARC version.
+ Copyright (C) 1996, 1997, 1998, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifdef _SIGNAL_H
+
+/* Fake signal functions. */
+#define SIG_ERR ((__sighandler_t) -1) /* Error return. */
+#define SIG_DFL ((__sighandler_t) 0) /* Default action. */
+#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */
+
+#ifdef __USE_UNIX98
+# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */
+#endif
+
+/*
+ * Linux/SPARC has different signal numbers that Linux/i386: I'm trying
+ * to make it OSF/1 binary compatible, at least for normal binaries.
+ */
+#define SIGHUP 1
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGILL 4
+#define SIGTRAP 5
+#define SIGABRT 6
+#define SIGIOT 6
+#define SIGEMT 7
+#define SIGFPE 8
+#define SIGKILL 9
+#define SIGBUS 10
+#define SIGSEGV 11
+#define SIGSYS 12
+#define SIGPIPE 13
+#define SIGALRM 14
+#define SIGTERM 15
+#define SIGURG 16
+
+/* SunOS values which deviate from the Linux/i386 ones */
+#define SIGSTOP 17
+#define SIGTSTP 18
+#define SIGCONT 19
+#define SIGCHLD 20
+#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */
+#define SIGTTIN 21
+#define SIGTTOU 22
+#define SIGIO 23
+#define SIGPOLL SIGIO /* SysV name for SIGIO */
+#define SIGXCPU 24
+#define SIGXFSZ 25
+#define SIGVTALRM 26
+#define SIGPROF 27
+#define SIGWINCH 28
+#define SIGLOST 29
+#define SIGPWR SIGLOST
+#define SIGUSR1 30
+#define SIGUSR2 31
+
+#define _NSIG 65 /* Biggest signal number + 1
+ (including real-time signals). */
+
+#define SIGRTMIN (__libc_current_sigrtmin ())
+#define SIGRTMAX (__libc_current_sigrtmax ())
+
+/* These are the hard limits of the kernel. These values should not be
+ used directly at user level. */
+#define __SIGRTMIN 32
+#define __SIGRTMAX (_NSIG - 1)
+
+#endif /* <signal.h> included. */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/sigstack.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/sigstack.h
new file mode 100644
index 000000000..df4653949
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/sigstack.h
@@ -0,0 +1,55 @@
+/* sigstack, sigaltstack definitions.
+ Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIGNAL_H
+# error "Never include this file directly. Use <signal.h> instead"
+#endif
+
+
+/* Structure describing a signal stack (obsolete). */
+struct sigstack
+ {
+ void *ss_sp; /* Signal stack pointer. */
+ int ss_onstack; /* Nonzero if executing on this stack. */
+ };
+
+
+/* Possible values for `ss_flags.'. */
+enum
+{
+ SS_ONSTACK = 1,
+#define SS_ONSTACK SS_ONSTACK
+ SS_DISABLE
+#define SS_DISABLE SS_DISABLE
+};
+
+/* Minimum stack size for a signal handler. */
+#define MINSIGSTKSZ 4096
+
+/* System default stack size. */
+#define SIGSTKSZ 16384
+
+
+/* Alternate, preferred interface. */
+typedef struct sigaltstack
+ {
+ void *ss_sp;
+ int ss_flags;
+ size_t ss_size;
+ } stack_t;
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/stat.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/stat.h
new file mode 100644
index 000000000..2fccb14cf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/stat.h
@@ -0,0 +1,165 @@
+/* Copyright (C) 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STAT_H
+# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
+#endif
+
+/* Versions of the `struct stat' data structure. */
+#define _STAT_VER_LINUX_OLD 1
+#define _STAT_VER_KERNEL 1
+#define _STAT_VER_SVR4 2
+#define _STAT_VER_LINUX 3
+#define _STAT_VER _STAT_VER_LINUX /* The one defined below. */
+
+/* Versions of the `xmknod' interface. */
+#define _MKNOD_VER_LINUX 1
+#define _MKNOD_VER_SVR4 2
+#define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
+
+
+struct stat
+ {
+ __dev_t st_dev; /* Device. */
+#if __WORDSIZE == 64 || !defined __USE_FILE_OFFSET64
+ unsigned short int __pad1;
+ __ino_t st_ino; /* File serial number. */
+#else
+ __ino64_t st_ino; /* File serial number. */
+#endif
+ __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. */
+ unsigned short int __pad2;
+#ifndef __USE_FILE_OFFSET64
+ __off_t st_size; /* Size of file, in bytes. */
+#else
+ __off64_t st_size; /* Size of file, in bytes. */
+#endif
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+#ifndef __USE_FILE_OFFSET64
+ __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
+#else
+ __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
+#endif
+#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
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+ };
+
+#ifdef __USE_LARGEFILE64
+struct stat64
+ {
+ __dev_t st_dev; /* Device. */
+#if __WORDSIZE == 64
+ unsigned short int __pad1;
+#endif
+ __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. */
+ unsigned short int __pad2;
+ __off64_t st_size; /* Size of file, in bytes. */
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+ __blkcnt64_t st_blocks; /* Number 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. */
+# 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
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+ };
+#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. */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/termios.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/termios.h
new file mode 100644
index 000000000..cea13227f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/termios.h
@@ -0,0 +1,233 @@
+/* termios type and macro definitions. Linux/SPARC version.
+ Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _TERMIOS_H
+# error "Never include <bits/termios.h> directly; use <termios.h> instead."
+#endif
+
+typedef unsigned char cc_t;
+typedef unsigned int speed_t;
+typedef unsigned int tcflag_t;
+
+#define NCCS 17
+struct termios
+ {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_line; /* line discipline */
+ cc_t c_cc[NCCS]; /* control characters */
+ };
+
+/* c_cc characters */
+#define VINTR 0
+#define VQUIT 1
+#define VERASE 2
+#define VKILL 3
+#define VEOF 4
+#define VEOL 5
+#define VEOL2 6
+#define VSWTC 7
+#define VSTART 8
+#define VSTOP 9
+#define VSUSP 10
+#define VDSUSP 11 /* SunOS POSIX nicety I do believe... */
+#define VREPRINT 12
+#define VDISCARD 13
+#define VWERASE 14
+#define VLNEXT 15
+
+/* User apps assume vmin/vtime is shared with eof/eol */
+#define VMIN VEOF
+#define VTIME VEOL
+
+/* c_iflag bits */
+#define IGNBRK 0x00000001
+#define BRKINT 0x00000002
+#define IGNPAR 0x00000004
+#define PARMRK 0x00000008
+#define INPCK 0x00000010
+#define ISTRIP 0x00000020
+#define INLCR 0x00000040
+#define IGNCR 0x00000080
+#define ICRNL 0x00000100
+#define IUCLC 0x00000200
+#define IXON 0x00000400
+#define IXANY 0x00000800
+#define IXOFF 0x00001000
+#define IMAXBEL 0x00002000
+#define IUTF8 0x00004000
+
+/* c_oflag bits */
+#define OPOST 0x00000001
+#define OLCUC 0x00000002
+#define ONLCR 0x00000004
+#define OCRNL 0x00000008
+#define ONOCR 0x00000010
+#define ONLRET 0x00000020
+#define OFILL 0x00000040
+#define OFDEL 0x00000080
+#if defined __USE_MISC || defined __USE_XOPEN
+# define NLDLY 0x00000100
+# define NL0 0x00000000
+# define NL1 0x00000100
+# define CRDLY 0x00000600
+# define CR0 0x00000000
+# define CR1 0x00000200
+# define CR2 0x00000400
+# define CR3 0x00000600
+# define TABDLY 0x00001800
+# define TAB0 0x00000000
+# define TAB1 0x00000800
+# define TAB2 0x00001000
+# define TAB3 0x00001800
+# define BSDLY 0x00002000
+# define BS0 0x00000000
+# define BS1 0x00002000
+#define FFDLY 0x00008000
+#define FF0 0x00000000
+#define FF1 0x00008000
+#endif
+#define VTDLY 0x00004000
+#define VT0 0x00000000
+#define VT1 0x00004000
+#define PAGEOUT 0x00010000 /* SUNOS specific */
+#define WRAP 0x00020000 /* SUNOS specific */
+
+#ifdef __USE_MISC
+# define XTABS 0x00001800
+#endif
+
+/* c_cflag bit meaning */
+#ifdef __USE_MISC
+# define CBAUD 0x0000100f
+#endif
+#define B0 0x00000000 /* hang up */
+#define B50 0x00000001
+#define B75 0x00000002
+#define B110 0x00000003
+#define B134 0x00000004
+#define B150 0x00000005
+#define B200 0x00000006
+#define B300 0x00000007
+#define B600 0x00000008
+#define B1200 0x00000009
+#define B1800 0x0000000a
+#define B2400 0x0000000b
+#define B4800 0x0000000c
+#define B9600 0x0000000d
+#define B19200 0x0000000e
+#define B38400 0x0000000f
+#ifdef __USE_MISC
+# define EXTA B19200
+# define EXTB B38400
+#endif
+#define CSIZE 0x00000030
+#define CS5 0x00000000
+#define CS6 0x00000010
+#define CS7 0x00000020
+#define CS8 0x00000030
+#define CSTOPB 0x00000040
+#define CREAD 0x00000080
+#define PARENB 0x00000100
+#define PARODD 0x00000200
+#define HUPCL 0x00000400
+#define CLOCAL 0x00000800
+#ifdef __USE_MISC
+# define CBAUDEX 0x00001000
+#endif
+#define B57600 0x00001001
+#define B115200 0x00001002
+#define B230400 0x00001003
+#define B460800 0x00001004
+#define B76800 0x00001005
+#define B153600 0x00001006
+#define B307200 0x00001007
+#define B614400 0x00001008
+#define B921600 0x00001009
+#define B500000 0x0000100a
+#define B576000 0x0000100b
+#define B1000000 0x0000100c
+#define B1152000 0x0000100d
+#define B1500000 0x0000100e
+#define B2000000 0x0000100f
+#define __MAX_BAUD B2000000
+
+#ifdef __USE_MISC
+# define CIBAUD 0x100f0000 /* input baud rate (not used) */
+# define CMSPAR 0x40000000 /* mark or space (stick) parity */
+# define CRTSCTS 0x80000000 /* flow control */
+#endif
+
+/* c_lflag bits */
+#define ISIG 0x00000001
+#define ICANON 0x00000002
+#if defined __USE_MISC || defined __USE_XOPEN
+# define XCASE 0x00000004
+#endif
+#define ECHO 0x00000008
+#define ECHOE 0x00000010
+#define ECHOK 0x00000020
+#define ECHONL 0x00000040
+#define NOFLSH 0x00000080
+#define TOSTOP 0x00000100
+#ifdef __USE_MISC
+# define ECHOCTL 0x00000200
+# define ECHOPRT 0x00000400
+# define ECHOKE 0x00000800
+# define DEFECHO 0x00001000 /* SUNOS thing, what is it? */
+# define FLUSHO 0x00002000
+# define PENDIN 0x00004000
+#endif
+#define IEXTEN 0x00008000
+
+/* modem lines */
+#define TIOCM_LE 0x001
+#define TIOCM_DTR 0x002
+#define TIOCM_RTS 0x004
+#define TIOCM_ST 0x008
+#define TIOCM_SR 0x010
+#define TIOCM_CTS 0x020
+#define TIOCM_CAR 0x040
+#define TIOCM_RNG 0x080
+#define TIOCM_DSR 0x100
+#define TIOCM_CD TIOCM_CAR
+#define TIOCM_RI TIOCM_RNG
+
+/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
+#define TIOCSER_TEMT 0x01 /* Transmitter physically empty */
+
+
+/* tcflow() and TCXONC use these */
+#define TCOOFF 0
+#define TCOON 1
+#define TCIOFF 2
+#define TCION 3
+
+/* tcflush() and TCFLSH use these */
+#define TCIFLUSH 0
+#define TCOFLUSH 1
+#define TCIOFLUSH 2
+
+/* tcsetattr uses these */
+#define TCSANOW 0
+#define TCSADRAIN 1
+#define TCSAFLUSH 2
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
new file mode 100644
index 000000000..b0dd1bd89
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
@@ -0,0 +1,66 @@
+/* bits/typesizes.h -- underlying types for *_t. Linux/SPARC version.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _BITS_TYPES_H
+# error "Never include <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 __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 __S32_TYPE
+#define __DADDR_T_TYPE __S32_TYPE
+#define __SWBLK_T_TYPE __SLONGWORD_TYPE
+#define __KEY_T_TYPE __S32_TYPE
+#define __CLOCKID_T_TYPE __S32_TYPE
+#define __TIMER_T_TYPE void *
+#define __BLKSIZE_T_TYPE __SLONGWORD_TYPE
+#define __FSID_T_TYPE struct { int __val[2]; }
+#define __SSIZE_T_TYPE __SWORD_TYPE
+
+/* Number of descriptors that can fit in an `fd_set'. */
+#define __FD_SETSIZE 1024
+
+
+#endif /* bits/typesizes.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h b/libc/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
new file mode 100644
index 000000000..2d958d29e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
@@ -0,0 +1,20 @@
+/* Determine the wordsize from the preprocessor defines. */
+
+#if defined __arch64__ || defined __sparcv9
+# define __WORDSIZE 64
+#else
+# define __WORDSIZE 32
+#endif
+
+#if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
+
+# if __WORDSIZE == 32
+/* Signal that in 32bit ABI we didn't used to have a `long double'.
+ The changes all the `long double' function variants to be redirects
+ to the double functions. */
+# define __LONG_DOUBLE_MATH_OPTIONAL 1
+# ifndef __LONG_DOUBLE_128__
+# define __NO_LONG_DOUBLE_MATH 1
+# endif
+# endif
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/dl-cache.h b/libc/sysdeps/unix/sysv/linux/sparc/dl-cache.h
new file mode 100644
index 000000000..df134b7e6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/dl-cache.h
@@ -0,0 +1,39 @@
+/* Support for reading /etc/ld.so.cache files written by Linux ldconfig.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define add_system_dir(dir) \
+ do \
+ { \
+ size_t len = strlen (dir); \
+ char path[len + 3]; \
+ memcpy (path, dir, len + 1); \
+ if (len >= 6 && ! memcmp (path + len - 6, "/lib64", 6)) \
+ { \
+ len -= 2; \
+ path[len] = '\0'; \
+ } \
+ add_dir (path); \
+ if (len >= 4 && ! memcmp (path + len - 4, "/lib", 4)) \
+ { \
+ memcpy (path + len, "64", 3); \
+ add_dir (path); \
+ } \
+ } while (0)
+
+#include <sysdeps/generic/dl-cache.h>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/fork.S b/libc/sysdeps/unix/sysv/linux/sparc/fork.S
new file mode 100644
index 000000000..2459b8c8c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/fork.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 1997, 1999, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Miguel de Icaza <miguel@gnu.ai.mit.edu>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+PSEUDO (__libc_fork, fork, 0)
+ sub %o1, 1, %o1
+ retl
+ and %o0, %o1, %o0
+PSEUDO_END (__libc_fork)
+
+weak_alias (__libc_fork, __fork)
+libc_hidden_def (__fork)
+weak_alias (__libc_fork, fork)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/getsysstats.c b/libc/sysdeps/unix/sysv/linux/sparc/getsysstats.c
new file mode 100644
index 000000000..f064b372f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/getsysstats.c
@@ -0,0 +1,55 @@
+/* Determine various system internal values, Linux/Sparc version.
+ Copyright (C) 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Schwab <schwab@suse.de> and
+ Jakub Jelinek <jj@ultra.linux.cz>
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+/* We need to define a special parser for /proc/cpuinfo. */
+#define GET_NPROCS_PARSER(FP, BUFFER, RESULT) \
+ do \
+ { \
+ (RESULT) = 0; \
+ /* Find the line that contains the information about the number of \
+ active cpus. We don't have to fear extremely long lines since \
+ the kernel will not generate them. 8192 bytes are really \
+ enough. */ \
+ while (fgets_unlocked (BUFFER, sizeof (BUFFER), FP) != NULL) \
+ if (sscanf (BUFFER, "ncpus active : %d", &(RESULT)) == 1) \
+ break; \
+ } \
+ while (0)
+
+
+/* On the Sparc we can distinguish between the number of configured and
+ active cpus. */
+#define GET_NPROCS_CONF_PARSER(FP, BUFFER, RESULT) \
+ do \
+ { \
+ (RESULT) = 0; \
+ /* Find the line that contains the information about the number of \
+ probed cpus. We don't have to fear extremely long lines since \
+ the kernel will not generate them. 8192 bytes are really \
+ enough. */ \
+ while (fgets_unlocked ((BUFFER), sizeof (BUFFER), (FP)) != NULL) \
+ if (sscanf (buffer, "ncpus probed : %d", &(RESULT)) == 1) \
+ break; \
+ } \
+ while (0)
+
+#include <sysdeps/unix/sysv/linux/getsysstats.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/kernel_termios.h b/libc/sysdeps/unix/sysv/linux/sparc/kernel_termios.h
new file mode 100644
index 000000000..e66d53a18
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/kernel_termios.h
@@ -0,0 +1,38 @@
+/* Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _KERNEL_TERMIOS_H
+#define _KERNEL_TERMIOS_H 1
+/* The following corresponds to the values from the Linux 2.1.20 kernel. */
+
+/* We need the definition of tcflag_t, cc_t, and speed_t. */
+#include <termios.h>
+
+#define __KERNEL_NCCS 17
+
+struct __kernel_termios
+ {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_line; /* line discipline */
+ cc_t c_cc[__KERNEL_NCCS]; /* control characters */
+ };
+
+#endif /* kernel_termios.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/ldd-rewrite.sed b/libc/sysdeps/unix/sysv/linux/sparc/ldd-rewrite.sed
new file mode 100644
index 000000000..7dc2698fa
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/ldd-rewrite.sed
@@ -0,0 +1,3 @@
+/LD_TRACE_LOADED_OBJECTS=1/a\
+add_env="$add_env LD_LIBRARY_VERSION=\\$verify_out"
+s_^\(RTLDLIST=\)\(.*lib\)\(\|64\)\(/[^/]*\.so\.[0-9.]*\)[ ]*$_\1"\2\4 \264\4"_
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/readelflib.c b/libc/sysdeps/unix/sysv/linux/sparc/readelflib.c
new file mode 100644
index 000000000..e12fbc782
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/readelflib.c
@@ -0,0 +1,62 @@
+/* Copyright (C) 1999, 2001, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Jaeger <aj@suse.de>, 1999 and
+ Jakub Jelinek <jakub@redhat.com>, 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+int process_elf32_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+int process_elf64_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+
+/* Returns 0 if everything is ok, != 0 in case of error. */
+int
+process_elf_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname, void *file_contents,
+ size_t file_length)
+{
+ ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
+ int ret;
+
+ if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
+ return process_elf32_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ else
+ {
+ ret = process_elf64_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ /* Sparc 64bit libraries are always libc.so.6+. */
+ if (!ret)
+ *flag = FLAG_SPARC_LIB64|FLAG_ELF_LIBC6;
+ return ret;
+ }
+}
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf32_file
+#define __ELF_NATIVE_CLASS 32
+#include "elf/readelflib.c"
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf64_file
+#define __ELF_NATIVE_CLASS 64
+#include "elf/readelflib.c"
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/rt-sysdep.c b/libc/sysdeps/unix/sysv/linux/sparc/rt-sysdep.c
new file mode 100644
index 000000000..3ff55952e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/rt-sysdep.c
@@ -0,0 +1 @@
+#include <sysdep.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/Implies b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/Implies
new file mode 100644
index 000000000..efda9d27c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/Implies
@@ -0,0 +1,3 @@
+# These supply the ABI compatibility for when long double was double.
+ieee754/ldbl-64-128
+ieee754/ldbl-opt
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/Makefile b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/Makefile
new file mode 100644
index 000000000..cd1b3fb79
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/Makefile
@@ -0,0 +1,21 @@
+asm-CPPFLAGS = -D__ASSEMBLY__
+ASFLAGS-.os += -fPIC
+LD += -melf32_sparc
+
+# When I get this to work, this is the right thing
+ifeq ($(subdir),elf)
+CFLAGS-rtld.c += -mcpu=v8
+#rtld-routines += dl-sysdepsparc
+sysdep-others += lddlibc4
+install-bin += lddlibc4
+endif # elf
+
+ifeq ($(subdir),math)
+# These 2 routines are normally in libgcc{.a,_s.so.1}.
+# However, sparc32 -mlong-double-128 libgcc relies on
+# glibc providing _Q_* routines and without these files
+# glibc relies on __multc3/__divtc3 only provided
+# by libgcc if configured with -mlong-double-128.
+# Provide these routines here as well.
+libm-routines += multc3 divtc3
+endif # math
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/Versions b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/Versions
new file mode 100644
index 000000000..c585af360
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/Versions
@@ -0,0 +1,23 @@
+libc {
+ GLIBC_2.0 {
+ # Exception handling support functions from libgcc
+ __register_frame; __register_frame_table; __deregister_frame;
+ __frame_state_for; __register_frame_info_table;
+ }
+ GLIBC_2.2 {
+ # functions used in other libraries
+ __xstat64; __fxstat64; __lxstat64;
+
+ # g*
+ glob64;
+
+ # r*
+ readdir64; readdir64_r;
+
+ # s*
+ scandir64;
+ }
+ GLIBC_2.3.3 {
+ posix_fadvise64; posix_fallocate64;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/brk.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/brk.c
new file mode 100644
index 000000000..bc0735994
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/brk.c
@@ -0,0 +1,55 @@
+/* brk system call for Linux/SPARC.
+ Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Miguel de Icaza (miguel@nuclecu.unam.mx)
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <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)
+{
+ void *newbrk;
+
+ {
+ register void *o0 __asm__("%o0") = addr;
+ register int g1 __asm__("%g1") = __NR_brk;
+ __asm ("t 0x10" : "=r"(o0) : "r"(g1), "0"(o0) : "cc");
+ newbrk = o0;
+ }
+
+ __curbrk = newbrk;
+
+ if (newbrk < addr)
+ {
+ __set_errno (ENOMEM);
+ return -1;
+ }
+
+ return 0;
+}
+weak_alias (__brk, brk)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/chown.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/chown.c
new file mode 100644
index 000000000..374131695
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/chown.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/sh/chown.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S
new file mode 100644
index 000000000..f91fc4f62
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S
@@ -0,0 +1,109 @@
+/* Copyright (C) 1996, 1997, 1998, 2000, 2003, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson (rth@tamu.edu).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* clone() is even more special than fork() as it mucks with stacks
+ and invokes a function in the right context after its all over. */
+
+#include <asm/errno.h>
+#include <asm/unistd.h>
+#include <tcb-offsets.h>
+#include <sysdep.h>
+
+#define CLONE_VM 0x00000100
+#define CLONE_THREAD 0x00010000
+
+/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
+ pid_t *ptid, void *tls, pid_t *ctid); */
+
+ .text
+ENTRY (__clone)
+ save %sp,-96,%sp
+ cfi_def_cfa_register(%fp)
+ cfi_window_save
+ cfi_register(%o7, %i7)
+
+ /* sanity check arguments */
+ orcc %i0,%g0,%g2
+ be .Lerror
+ orcc %i1,%g0,%o1
+ be .Lerror
+ mov %i2,%o0
+
+ /* The child_stack is the top of the stack, allocate one
+ whole stack frame from that as this is what the kernel
+ expects. */
+ sub %o1, 96, %o1
+ mov %i3, %g3
+ mov %i2, %g4
+
+ /* ptid */
+ mov %i4,%o2
+ /* tls */
+ mov %i5,%o3
+ /* ctid */
+ ld [%fp+92],%o4
+
+ /* Do the system call */
+ set __NR_clone,%g1
+ ta 0x10
+ bcs .Lerror
+ tst %o1
+ bne __thread_start
+ nop
+ jmpl %i7 + 8, %g0
+ restore %o0,%g0,%o0
+
+.Lerror:
+ call __errno_location
+ or %g0,EINVAL,%i0
+ st %i0,[%o0]
+ jmpl %i7 + 8, %g0
+ restore %g0,-1,%o0
+END(__clone)
+
+ .type __thread_start,@function
+__thread_start:
+ cfi_startproc
+
+#ifdef RESET_PID
+ sethi %hi(CLONE_THREAD), %l0
+ andcc %g4, %l0, %g0
+ bne 1f
+ andcc %g4, CLONE_VM, %g0
+ bne,a 2f
+ mov -1,%o0
+ set __NR_getpid,%g1
+ ta 0x10
+2:
+ st %o0,[%g7 + PID]
+ st %o0,[%g7 + TID]
+1:
+#endif
+ mov %g0, %fp /* terminate backtrace */
+ call %g2
+ mov %g3,%o0
+ call _exit,0
+ nop
+
+ cfi_endproc
+
+ .size __thread_start, .-__thread_start
+
+weak_alias (__clone, clone)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fchown.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fchown.c
new file mode 100644
index 000000000..3a69ecc9e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fchown.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fchown.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fchownat.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fchownat.c
new file mode 100644
index 000000000..7ba5bf44a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fchownat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/sh/fchownat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fcntl.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fcntl.c
new file mode 100644
index 000000000..ea951bc4f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fcntl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fpu/Implies b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fpu/Implies
new file mode 100644
index 000000000..dbcd1e9e6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fpu/Implies
@@ -0,0 +1,2 @@
+# We must list this here to move it ahead of the ldbl-opt code.
+sparc/sparc32/fpu
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fxstat.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fxstat.c
new file mode 100644
index 000000000..4f219f0b9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fxstat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fxstatat.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fxstatat.c
new file mode 100644
index 000000000..0f8b3135d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/fxstatat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstatat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getdents64.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getdents64.c
new file mode 100644
index 000000000..0c75fb5a0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getdents64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getdents64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getegid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getegid.c
new file mode 100644
index 000000000..37b4b4a53
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getegid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getegid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/geteuid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/geteuid.c
new file mode 100644
index 000000000..ebcb555b5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/geteuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/geteuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getgid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getgid.c
new file mode 100644
index 000000000..0a4d6061f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getgroups.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getgroups.c
new file mode 100644
index 000000000..102ea24e1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getgroups.c
@@ -0,0 +1,2 @@
+/* We also have to rewrite the kernel gid_t to the user land type. */
+#include <sysdeps/unix/sysv/linux/i386/getgroups.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getpagesize.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getpagesize.c
new file mode 100644
index 000000000..4760daff2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getpagesize.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 1997, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <unistd.h>
+#include <sys/param.h>
+#include <ldsodefs.h>
+#include <sysdep.h>
+
+/* Return the system page size. This value will either be 4k or 8k depending
+ on whether or not we are running on Sparc v9 machine. */
+
+/* If we are not a static program, this value is collected from the system
+ via the AT_PAGESZ auxiliary argument. If we are a static program, we
+ use the getpagesize system call. */
+
+int
+__getpagesize ()
+{
+ int ret = GLRO(dl_pagesize);
+ if (ret == 0)
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ ret = INTERNAL_SYSCALL (getpagesize, err, 0);
+#ifndef SHARED
+ GLRO(dl_pagesize) = ret;
+#endif
+ }
+ return ret;
+}
+libc_hidden_def (__getpagesize)
+weak_alias (__getpagesize, getpagesize)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getuid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getuid.c
new file mode 100644
index 000000000..d682c79a4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/getuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/getuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/glob64.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/glob64.c
new file mode 100644
index 000000000..82a9a296a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/glob64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/glob64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/kernel_stat.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/kernel_stat.h
new file mode 100644
index 000000000..a0da019c5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/kernel_stat.h
@@ -0,0 +1,32 @@
+/* Definition of `struct stat' used in the kernel */
+struct kernel_stat
+ {
+ unsigned short int st_dev;
+ unsigned long int st_ino;
+ unsigned short int st_mode;
+ short int st_nlink;
+ unsigned short int st_uid;
+ unsigned short int st_gid;
+ unsigned short int st_rdev;
+ long int st_size;
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ long int st_blksize;
+ long int st_blocks;
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+ };
+
+#define _HAVE___UNUSED4
+#define _HAVE___UNUSED5
+
+#define _HAVE_STAT___UNUSED4
+#define _HAVE_STAT___UNUSED5
+#define _HAVE_STAT___PAD1
+#define _HAVE_STAT___PAD2
+#define _HAVE_STAT64___UNUSED4
+#define _HAVE_STAT64___UNUSED5
+#define _HAVE_STAT64___PAD2
+#define _HAVE_STAT_NSEC
+#define _HAVE_STAT64_NSEC
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/lchown.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/lchown.c
new file mode 100644
index 000000000..c89de99ba
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/lchown.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/lchown.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/lockf64.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/lockf64.c
new file mode 100644
index 000000000..a88f5a784
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/lockf64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/lockf64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/lxstat.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/lxstat.c
new file mode 100644
index 000000000..2371cd971
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/lxstat.c
@@ -0,0 +1,2 @@
+#include <sysdeps/unix/sysv/linux/i386/lxstat.c>
+
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/msgctl.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/msgctl.c
new file mode 100644
index 000000000..9f9b8431a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/msgctl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/msgctl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/nldbl-abi.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/nldbl-abi.h
new file mode 100644
index 000000000..bd985cc59
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/nldbl-abi.h
@@ -0,0 +1,8 @@
+/* ABI version for long double switch.
+ This is used by the Versions and math_ldbl_opt.h files in
+ sysdeps/ieee754/ldbl-opt/. It gives the ABI version where
+ long double == double was replaced with proper long double
+ for libm *l functions and libc functions using long double. */
+
+#define NLDBL_VERSION GLIBC_2.4
+#define LONG_DOUBLE_COMPAT_VERSION GLIBC_2_4
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S
new file mode 100644
index 000000000..dbe087261
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S
@@ -0,0 +1,40 @@
+/* Copyright (C) 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Miguel de Icaza <miguel@gnu.ai.mit.edu>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+ .text
+ .globl __syscall_error
+ENTRY(__libc_pipe)
+ mov %o0, %o2 /* Save PIPEDES. */
+ mov SYS_ify(pipe),%g1
+ ta 0x10
+ bcc 1f
+ mov %o7, %g1
+ call __syscall_error
+ mov %g1, %o7
+1: st %o0, [%o2] /* PIPEDES[0] = %o0; */
+ st %o1, [%o2 + 4] /* PIPEDES[1] = %o1; */
+ retl
+ clr %o0
+END(__libc_pipe)
+
+weak_alias (__libc_pipe, __pipe)
+libc_hidden_def (__pipe)
+weak_alias (__libc_pipe, pipe)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/profil-counter.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/profil-counter.h
new file mode 100644
index 000000000..1e22e8cce
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/profil-counter.h
@@ -0,0 +1,26 @@
+/* Low-level statistical profiling support function. Linux/SPARC version.
+ Copyright (C) 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <signal.h>
+
+void
+profil_counter (int signo, struct sigcontext *si)
+{
+ profil_count ((void *) si->si_regs.pc);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c
new file mode 100644
index 000000000..2ea26dd40
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/readdir64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c
new file mode 100644
index 000000000..9f54f897e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/readdir64_r.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/register-dump.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/register-dump.h
new file mode 100644
index 000000000..2d3fa4277
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/register-dump.h
@@ -0,0 +1,336 @@
+/* Dump registers.
+ Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/uio.h>
+#include <stdio-common/_itoa.h>
+
+/* We will print the register dump in this format:
+
+ PSR: XXXXXXXX PC: XXXXXXXX NPC: XXXXXXXX Y: XXXXXXXX
+ g0: 00000000 g1: XXXXXXXX g2: XXXXXXXX g3: XXXXXXXX
+ g4: XXXXXXXX g5: XXXXXXXX g6: XXXXXXXX g7: XXXXXXXX
+ o0: XXXXXXXX o1: XXXXXXXX o2: XXXXXXXX o3: XXXXXXXX
+ o4: XXXXXXXX o5: XXXXXXXX sp: XXXXXXXX o7: XXXXXXXX
+ l0: XXXXXXXX l1: XXXXXXXX l2: XXXXXXXX l3: XXXXXXXX
+ l4: XXXXXXXX l5: XXXXXXXX l6: XXXXXXXX l7: XXXXXXXX
+ i0: XXXXXXXX i1: XXXXXXXX i2: XXXXXXXX i3: XXXXXXXX
+ i4: XXXXXXXX i5: XXXXXXXX fp: XXXXXXXX i7: XXXXXXXX
+
+ followed on sun4, sun4c, sun4d, sun4m by:
+
+ Old mask: XXXXXXXX FSR: XXXXXXXX FPQ: XXXXXXXX
+ f0: XXXXXXXXXXXXXXXX f2: XXXXXXXXXXXXXXXX f4: XXXXXXXXXXXXXXXX
+ f6: XXXXXXXXXXXXXXXX f8: XXXXXXXXXXXXXXXX f10: XXXXXXXXXXXXXXXX
+ f12: XXXXXXXXXXXXXXXX f14: XXXXXXXXXXXXXXXX f16: XXXXXXXXXXXXXXXX
+ f18: XXXXXXXXXXXXXXXX f20: XXXXXXXXXXXXXXXX f22: XXXXXXXXXXXXXXXX
+ f24: XXXXXXXXXXXXXXXX f26: XXXXXXXXXXXXXXXX f28: XXXXXXXXXXXXXXXX
+ f30: XXXXXXXXXXXXXXXX
+
+ and on sun4u by:
+
+ Old mask: XXXXXXXX XFSR: XXXXXXXXXXXXXXXX GSR: XX FPRS: X
+ f0: XXXXXXXXXXXXXXXX f2: XXXXXXXXXXXXXXXX f4: XXXXXXXXXXXXXXXX
+ f6: XXXXXXXXXXXXXXXX f8: XXXXXXXXXXXXXXXX f10: XXXXXXXXXXXXXXXX
+ f12: XXXXXXXXXXXXXXXX f14: XXXXXXXXXXXXXXXX f16: XXXXXXXXXXXXXXXX
+ f18: XXXXXXXXXXXXXXXX f20: XXXXXXXXXXXXXXXX f22: XXXXXXXXXXXXXXXX
+ f24: XXXXXXXXXXXXXXXX f26: XXXXXXXXXXXXXXXX f28: XXXXXXXXXXXXXXXX
+ f30: XXXXXXXXXXXXXXXX f32: XXXXXXXXXXXXXXXX f34: XXXXXXXXXXXXXXXX
+ f36: XXXXXXXXXXXXXXXX f38: XXXXXXXXXXXXXXXX f40: XXXXXXXXXXXXXXXX
+ f42: XXXXXXXXXXXXXXXX f44: XXXXXXXXXXXXXXXX f46: XXXXXXXXXXXXXXXX
+ f48: XXXXXXXXXXXXXXXX f50: XXXXXXXXXXXXXXXX f52: XXXXXXXXXXXXXXXX
+ f54: XXXXXXXXXXXXXXXX f56: XXXXXXXXXXXXXXXX f58: XXXXXXXXXXXXXXXX
+ f60: XXXXXXXXXXXXXXXX f62: XXXXXXXXXXXXXXXX
+
+ */
+
+static void
+hexvalue (unsigned long int value, char *buf, size_t len)
+{
+ char *cp = _itoa_word (value, buf + len, 16, 0);
+ while (cp > buf)
+ *--cp = '0';
+}
+
+struct __siginfo_sparc32_fpu
+{
+ unsigned int si_float_regs[32];
+ unsigned int si_fsr;
+ unsigned int si_fpq;
+};
+struct __siginfo_sparc64_fpu
+{
+ unsigned int si_float_regs[64];
+ unsigned int si_xfsr;
+ unsigned int si_fsr;
+ unsigned int _pad1;
+ unsigned int si_gsr;
+ unsigned int _pad2;
+ unsigned int si_fprs;
+};
+
+static void
+register_dump (int fd, SIGCONTEXT ctx)
+{
+ char regs[36][8];
+ char fregs[68][8];
+ struct iovec iov[150];
+ size_t nr = 0;
+ int i;
+ unsigned int *r = (unsigned int *)
+ ctx->si_regs.u_regs[14];
+
+#define ADD_STRING(str) \
+ iov[nr].iov_base = (char *) str; \
+ iov[nr].iov_len = strlen (str); \
+ ++nr
+#define ADD_MEM(str, len) \
+ iov[nr].iov_base = str; \
+ iov[nr].iov_len = len; \
+ ++nr
+
+ /* Generate strings of register contents. */
+ hexvalue (ctx->si_regs.psr, regs[0], 8);
+ hexvalue (ctx->si_regs.pc, regs[1], 8);
+ hexvalue (ctx->si_regs.npc, regs[2], 8);
+ hexvalue (ctx->si_regs.y, regs[3], 8);
+ for (i = 1; i <= 15; i++)
+ hexvalue (ctx->si_regs.u_regs[i], regs[3+i], 8);
+ for (i = 0; i <= 15; i++)
+ hexvalue (r[i], regs[19+i], 8);
+ hexvalue (ctx->si_mask, regs[35], 8);
+
+ /* Generate the output. */
+ ADD_STRING ("Register dump:\n\n PSR: ");
+ ADD_MEM (regs[0], 8);
+ ADD_STRING (" PC: ");
+ ADD_MEM (regs[1], 8);
+ ADD_STRING (" NPC: ");
+ ADD_MEM (regs[2], 8);
+ ADD_STRING (" Y: ");
+ ADD_MEM (regs[3], 8);
+ ADD_STRING ("\n g0: 00000000 g1: ");
+ ADD_MEM (regs[4], 8);
+ ADD_STRING (" g2: ");
+ ADD_MEM (regs[5], 8);
+ ADD_STRING (" g3: ");
+ ADD_MEM (regs[6], 8);
+ ADD_STRING ("\n g4: ");
+ ADD_MEM (regs[7], 8);
+ ADD_STRING (" g5: ");
+ ADD_MEM (regs[8], 8);
+ ADD_STRING (" g6: ");
+ ADD_MEM (regs[9], 8);
+ ADD_STRING (" g7: ");
+ ADD_MEM (regs[10], 8);
+ ADD_STRING ("\n o0: ");
+ ADD_MEM (regs[11], 8);
+ ADD_STRING (" o1: ");
+ ADD_MEM (regs[12], 8);
+ ADD_STRING (" o2: ");
+ ADD_MEM (regs[13], 8);
+ ADD_STRING (" o3: ");
+ ADD_MEM (regs[14], 8);
+ ADD_STRING ("\n o4: ");
+ ADD_MEM (regs[15], 8);
+ ADD_STRING (" o5: ");
+ ADD_MEM (regs[16], 8);
+ ADD_STRING (" sp: ");
+ ADD_MEM (regs[17], 8);
+ ADD_STRING (" o7: ");
+ ADD_MEM (regs[18], 8);
+ ADD_STRING ("\n l0: ");
+ ADD_MEM (regs[19], 8);
+ ADD_STRING (" l1: ");
+ ADD_MEM (regs[20], 8);
+ ADD_STRING (" l2: ");
+ ADD_MEM (regs[21], 8);
+ ADD_STRING (" l3: ");
+ ADD_MEM (regs[22], 8);
+ ADD_STRING ("\n l4: ");
+ ADD_MEM (regs[23], 8);
+ ADD_STRING (" l5: ");
+ ADD_MEM (regs[24], 8);
+ ADD_STRING (" l6: ");
+ ADD_MEM (regs[25], 8);
+ ADD_STRING (" l7: ");
+ ADD_MEM (regs[26], 8);
+ ADD_STRING ("\n i0: ");
+ ADD_MEM (regs[27], 8);
+ ADD_STRING (" i1: ");
+ ADD_MEM (regs[28], 8);
+ ADD_STRING (" i2: ");
+ ADD_MEM (regs[29], 8);
+ ADD_STRING (" i3: ");
+ ADD_MEM (regs[30], 8);
+ ADD_STRING ("\n i4: ");
+ ADD_MEM (regs[31], 8);
+ ADD_STRING (" i5: ");
+ ADD_MEM (regs[32], 8);
+ ADD_STRING (" fp: ");
+ ADD_MEM (regs[33], 8);
+ ADD_STRING (" i7: ");
+ ADD_MEM (regs[34], 8);
+ ADD_STRING ("\n\n Old mask: ");
+ ADD_MEM (regs[35], 8);
+
+ if ((ctx->si_regs.psr & 0xff000000) == 0xff000000)
+ {
+ struct __siginfo_sparc64_fpu *f;
+
+ f = *(struct __siginfo_sparc64_fpu **) (ctx + 1);
+ if (f != NULL)
+ {
+ for (i = 0; i < 64; i++)
+ hexvalue (f->si_float_regs[i], fregs[i], 8);
+ hexvalue (f->si_xfsr, fregs[64], 8);
+ hexvalue (f->si_fsr, fregs[65], 8);
+ hexvalue (f->si_gsr, fregs[66], 2);
+ hexvalue (f->si_fprs, fregs[67], 1);
+ ADD_STRING (" XFSR: ");
+ ADD_MEM (fregs[64], 8);
+ ADD_MEM (fregs[65], 8);
+ ADD_STRING (" GSR: ");
+ ADD_MEM (fregs[66], 2);
+ ADD_STRING (" FPRS: ");
+ ADD_MEM (fregs[67], 1);
+ ADD_STRING ("\n f0: ");
+ ADD_MEM (fregs[0], 16);
+ ADD_STRING (" f2: ");
+ ADD_MEM (fregs[2], 16);
+ ADD_STRING (" f4: ");
+ ADD_MEM (fregs[4], 16);
+ ADD_STRING ("\n f6: ");
+ ADD_MEM (fregs[6], 16);
+ ADD_STRING (" f8: ");
+ ADD_MEM (fregs[8], 16);
+ ADD_STRING (" f10: ");
+ ADD_MEM (fregs[10], 16);
+ ADD_STRING ("\n f12: ");
+ ADD_MEM (fregs[12], 16);
+ ADD_STRING (" f14: ");
+ ADD_MEM (fregs[14], 16);
+ ADD_STRING (" f16: ");
+ ADD_MEM (fregs[16], 16);
+ ADD_STRING ("\n f18: ");
+ ADD_MEM (fregs[18], 16);
+ ADD_STRING (" f20: ");
+ ADD_MEM (fregs[20], 16);
+ ADD_STRING (" f22: ");
+ ADD_MEM (fregs[22], 16);
+ ADD_STRING ("\n f24: ");
+ ADD_MEM (fregs[24], 16);
+ ADD_STRING (" f26: ");
+ ADD_MEM (fregs[26], 16);
+ ADD_STRING (" f28: ");
+ ADD_MEM (fregs[28], 16);
+ ADD_STRING ("\n f30: ");
+ ADD_MEM (fregs[30], 16);
+ ADD_STRING (" f32: ");
+ ADD_MEM (fregs[32], 16);
+ ADD_STRING (" f34: ");
+ ADD_MEM (fregs[34], 16);
+ ADD_STRING ("\n f36: ");
+ ADD_MEM (fregs[36], 16);
+ ADD_STRING (" f38: ");
+ ADD_MEM (fregs[38], 16);
+ ADD_STRING (" f40: ");
+ ADD_MEM (fregs[40], 16);
+ ADD_STRING ("\n f42: ");
+ ADD_MEM (fregs[42], 16);
+ ADD_STRING (" f44: ");
+ ADD_MEM (fregs[44], 16);
+ ADD_STRING (" f46: ");
+ ADD_MEM (fregs[46], 16);
+ ADD_STRING ("\n f48: ");
+ ADD_MEM (fregs[48], 16);
+ ADD_STRING (" f50: ");
+ ADD_MEM (fregs[50], 16);
+ ADD_STRING (" f52: ");
+ ADD_MEM (fregs[52], 16);
+ ADD_STRING ("\n f54: ");
+ ADD_MEM (fregs[54], 16);
+ ADD_STRING (" f56: ");
+ ADD_MEM (fregs[56], 16);
+ ADD_STRING (" f58: ");
+ ADD_MEM (fregs[58], 16);
+ ADD_STRING ("\n f60: ");
+ ADD_MEM (fregs[60], 16);
+ ADD_STRING (" f62: ");
+ ADD_MEM (fregs[62], 16);
+ }
+ }
+ else
+ {
+ struct __siginfo_sparc32_fpu *f;
+
+ f = *(struct __siginfo_sparc32_fpu **) (ctx + 1);
+ if (f != NULL)
+ {
+ for (i = 0; i < 32; i++)
+ hexvalue (f->si_float_regs[i], fregs[i], 8);
+ hexvalue (f->si_fsr, fregs[64], 8);
+ hexvalue (f->si_fpq, fregs[65], 8);
+ ADD_STRING (" FSR: ");
+ ADD_MEM (fregs[64], 8);
+ ADD_STRING (" FPQ: ");
+ ADD_MEM (fregs[65], 8);
+ ADD_STRING ("\n f0: ");
+ ADD_MEM (fregs[0], 16);
+ ADD_STRING (" f2: ");
+ ADD_MEM (fregs[2], 16);
+ ADD_STRING (" f4: ");
+ ADD_MEM (fregs[4], 16);
+ ADD_STRING ("\n f6: ");
+ ADD_MEM (fregs[6], 16);
+ ADD_STRING (" f8: ");
+ ADD_MEM (fregs[8], 16);
+ ADD_STRING (" f10: ");
+ ADD_MEM (fregs[10], 16);
+ ADD_STRING ("\n f12: ");
+ ADD_MEM (fregs[12], 16);
+ ADD_STRING (" f14: ");
+ ADD_MEM (fregs[14], 16);
+ ADD_STRING (" f16: ");
+ ADD_MEM (fregs[16], 16);
+ ADD_STRING ("\n f18: ");
+ ADD_MEM (fregs[18], 16);
+ ADD_STRING (" f20: ");
+ ADD_MEM (fregs[20], 16);
+ ADD_STRING (" f22: ");
+ ADD_MEM (fregs[22], 16);
+ ADD_STRING ("\n f24: ");
+ ADD_MEM (fregs[24], 16);
+ ADD_STRING (" f26: ");
+ ADD_MEM (fregs[26], 16);
+ ADD_STRING (" f28: ");
+ ADD_MEM (fregs[28], 16);
+ ADD_STRING ("\n f30: ");
+ ADD_MEM (fregs[30], 16);
+ }
+ }
+
+ ADD_STRING ("\n");
+
+ /* Write the stuff out. */
+ writev (fd, iov, nr);
+}
+
+
+#define REGISTER_DUMP register_dump (fd, ctx)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/scandir64.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/scandir64.c
new file mode 100644
index 000000000..506fd8877
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/scandir64.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/scandir64.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/semctl.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/semctl.c
new file mode 100644
index 000000000..64d47b34c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/semctl.c
@@ -0,0 +1,208 @@
+/* Semctl for architectures where word sized unions are passed indirectly
+ Copyright (C) 1995,1997,1998,2000,2002,2003,2004,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <sys/sem.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <string.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+#include <shlib-compat.h>
+
+struct __old_semid_ds
+{
+ struct __old_ipc_perm sem_perm; /* operation permission struct */
+ __time_t sem_otime; /* last semop() time */
+ __time_t sem_ctime; /* last time changed by semctl() */
+ struct sem *__sembase; /* ptr to first semaphore in array */
+ struct sem_queue *__sem_pending; /* pending operations */
+ struct sem_queue *__sem_pending_last; /* last pending operation */
+ struct sem_undo *__undo; /* ondo requests on this array */
+ unsigned short int sem_nsems; /* number of semaphores in set */
+};
+
+/* Define a `union semun' suitable for Linux here. */
+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 */
+ struct __old_semid_ds *__old_buf;
+};
+
+#include <bp-checks.h>
+#include <bp-semctl.h> /* definition of CHECK_SEMCTL needs union semum */
+
+#ifdef __NR_getuid32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+ uids. */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif
+
+/* Return identifier for array of NSEMS semaphores associated with
+ KEY. */
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int __old_semctl (int semid, int semnum, int cmd, ...);
+#endif
+int __new_semctl (int semid, int semnum, int cmd, ...);
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+int
+attribute_compat_text_section
+__old_semctl (int semid, int semnum, int cmd, ...)
+{
+ union semun arg;
+ va_list ap;
+
+ /* Get the argument only if required. */
+ arg.buf = NULL;
+ switch (cmd)
+ {
+ case SETVAL: /* arg.val */
+ case GETALL: /* arg.array */
+ case SETALL:
+ case IPC_STAT: /* arg.buf */
+ case IPC_SET:
+ case SEM_STAT:
+ case IPC_INFO: /* arg.__buf */
+ case SEM_INFO:
+ va_start (ap, cmd);
+ arg = va_arg (ap, union semun);
+ va_end (ap);
+ break;
+ }
+
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd));
+}
+compat_symbol (libc, __old_semctl, semctl, GLIBC_2_0);
+#endif
+
+int
+__new_semctl (int semid, int semnum, int cmd, ...)
+{
+ union semun arg;
+ va_list ap;
+
+ /* Get the argument only if required. */
+ arg.buf = NULL;
+ switch (cmd)
+ {
+ case SETVAL: /* arg.val */
+ case GETALL: /* arg.array */
+ case SETALL:
+ case IPC_STAT: /* arg.buf */
+ case IPC_SET:
+ case SEM_STAT:
+ case IPC_INFO: /* arg.__buf */
+ case SEM_INFO:
+ va_start (ap, cmd);
+ arg = va_arg (ap, union semun);
+ va_end (ap);
+ break;
+ }
+
+#if __ASSUME_32BITUIDS > 0
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd | __IPC_64,
+ CHECK_SEMCTL (&arg, semid, cmd | __IPC_64));
+#else
+ switch (cmd) {
+ case SEM_STAT:
+ case IPC_STAT:
+ case IPC_SET:
+ break;
+ default:
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd));
+ }
+
+ {
+ int result;
+ struct __old_semid_ds old;
+ struct semid_ds *buf;
+
+#ifdef __NR_getuid32
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ if (__libc_missing_32bit_uids < 0)
+ {
+ int save_errno = errno;
+
+ /* Test presence of new IPC by testing for getuid32 syscall. */
+ result = INLINE_SYSCALL (getuid32, 0);
+ if (result == -1 && errno == ENOSYS)
+ __libc_missing_32bit_uids = 1;
+ else
+ __libc_missing_32bit_uids = 0;
+ __set_errno(save_errno);
+ }
+ if (__libc_missing_32bit_uids <= 0)
+ {
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd | __IPC_64,
+ CHECK_SEMCTL (&arg, semid, cmd | __IPC_64));
+ return result;
+ }
+ }
+#endif
+
+ buf = arg.buf;
+ arg.__old_buf = &old;
+ if (cmd == IPC_SET)
+ {
+ old.sem_perm.uid = buf->sem_perm.uid;
+ old.sem_perm.gid = buf->sem_perm.gid;
+ old.sem_perm.mode = buf->sem_perm.mode;
+ if (old.sem_perm.uid != buf->sem_perm.uid ||
+ old.sem_perm.gid != buf->sem_perm.gid)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ }
+ result = INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd));
+ if (result != -1 && cmd != IPC_SET)
+ {
+ memset(buf, 0, sizeof(*buf));
+ buf->sem_perm.__key = old.sem_perm.__key;
+ buf->sem_perm.uid = old.sem_perm.uid;
+ buf->sem_perm.gid = old.sem_perm.gid;
+ buf->sem_perm.cuid = old.sem_perm.cuid;
+ buf->sem_perm.cgid = old.sem_perm.cgid;
+ buf->sem_perm.mode = old.sem_perm.mode;
+ buf->sem_perm.__seq = old.sem_perm.__seq;
+ buf->sem_otime = old.sem_otime;
+ buf->sem_ctime = old.sem_ctime;
+ buf->sem_nsems = old.sem_nsems;
+ }
+ return result;
+ }
+#endif
+}
+
+versioned_symbol (libc, __new_semctl, semctl, GLIBC_2_2);
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setegid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setegid.c
new file mode 100644
index 000000000..2e3a54c89
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setegid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setegid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/seteuid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/seteuid.c
new file mode 100644
index 000000000..18e41d08c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/seteuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/seteuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setfsgid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setfsgid.c
new file mode 100644
index 000000000..088671256
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setfsgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setfsgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setfsuid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setfsuid.c
new file mode 100644
index 000000000..a9f22eb8a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setfsuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setfsuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setgid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setgid.c
new file mode 100644
index 000000000..377021d9e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setgroups.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setgroups.c
new file mode 100644
index 000000000..0e7086278
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setgroups.c
@@ -0,0 +1,2 @@
+/* We also have to rewrite the kernel gid_t to the user land type. */
+#include <sysdeps/unix/sysv/linux/i386/setgroups.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setregid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setregid.c
new file mode 100644
index 000000000..99c57ad20
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setregid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setregid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setresgid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setresgid.c
new file mode 100644
index 000000000..daca1a483
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setresgid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setresgid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setresuid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setresuid.c
new file mode 100644
index 000000000..3aeabe9ad
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setresuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setresuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setreuid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setreuid.c
new file mode 100644
index 000000000..8ad61226e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setreuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setreuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setuid.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setuid.c
new file mode 100644
index 000000000..de394379b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/setuid.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/setuid.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/shmctl.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/shmctl.c
new file mode 100644
index 000000000..7eac6380d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/shmctl.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/shmctl.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c
new file mode 100644
index 000000000..3be801a93
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c
@@ -0,0 +1,161 @@
+/* POSIX.1 sigaction call for Linux/SPARC.
+ Copyright (C) 1997-2000,2002,2003,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Miguel de Icaza (miguel@nuclecu.unam.mx), 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <string.h>
+#include <syscall.h>
+#include <sys/signal.h>
+#include <errno.h>
+#include <kernel_sigaction.h>
+#include <sysdep.h>
+
+static void __rt_sigreturn_stub (void);
+static void __sigreturn_stub (void);
+
+/* The variable is shared between all wrappers around signal handling
+ functions which have RT equivalents. */
+int __libc_missing_rt_sigs;
+
+int
+__libc_sigaction (int sig, __const struct sigaction *act,
+ struct sigaction *oact)
+{
+ struct old_kernel_sigaction k_sigact, k_osigact;
+ int ret;
+
+#ifdef __NR_rt_sigaction
+ /* First try the RT signals. */
+ if (!__libc_missing_rt_sigs)
+ {
+ struct kernel_sigaction kact, koact;
+ unsigned long stub = 0;
+ int saved_errno = errno;
+
+ if (act)
+ {
+ kact.k_sa_handler = act->sa_handler;
+ memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
+ if (((kact.sa_flags = act->sa_flags) & SA_SIGINFO) != 0)
+ stub = (unsigned long) &__rt_sigreturn_stub;
+ else
+ stub = (unsigned long) &__sigreturn_stub;
+ stub -= 8;
+ kact.sa_restorer = NULL;
+ }
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ ret = INLINE_SYSCALL (rt_sigaction, 5, sig, act ? &kact : 0,
+ oact ? &koact : 0, stub, _NSIG / 8);
+
+ if (ret >= 0 || errno != ENOSYS)
+ {
+ if (oact && ret >= 0)
+ {
+ oact->sa_handler = koact.k_sa_handler;
+ memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
+ oact->sa_flags = koact.sa_flags;
+ oact->sa_restorer = koact.sa_restorer;
+ }
+ return ret;
+ }
+
+ __set_errno (saved_errno);
+ __libc_missing_rt_sigs = 1;
+ }
+#endif
+
+ /* Magic to tell the kernel we are using "new-style" signals, in that
+ the signal table is not kept in userspace. Not the same as the
+ really-new-style rt signals. */
+ sig = -sig;
+
+ if (act)
+ {
+ k_sigact.k_sa_handler = act->sa_handler;
+ k_sigact.sa_mask = act->sa_mask.__val[0];
+ k_sigact.sa_flags = act->sa_flags;
+ k_sigact.sa_restorer = NULL;
+ }
+
+ {
+ register int r_syscallnr __asm__("%g1") = __NR_sigaction;
+ register int r_sig __asm__("%o0") = sig;
+ register struct old_kernel_sigaction *r_act __asm__("%o1");
+ register struct old_kernel_sigaction *r_oact __asm__("%o2");
+
+ r_act = act ? &k_sigact : NULL;
+ r_oact = oact ? &k_osigact : NULL;
+
+ __asm__ __volatile__("t 0x10\n\t"
+ "bcc 1f\n\t"
+ " nop\n\t"
+ "sub %%g0,%%o0,%%o0\n"
+ "1:"
+ : "=r"(r_sig)
+ : "r"(r_syscallnr), "r"(r_act), "r"(r_oact),
+ "0"(r_sig));
+
+ ret = r_sig;
+ }
+
+ if (ret >= 0)
+ {
+ if (oact)
+ {
+ oact->sa_handler = k_osigact.k_sa_handler;
+ oact->sa_mask.__val[0] = k_osigact.sa_mask;
+ oact->sa_flags = k_osigact.sa_flags;
+ oact->sa_restorer = NULL;
+ }
+ return ret;
+ }
+
+ __set_errno (-ret);
+ return -1;
+}
+libc_hidden_def (__libc_sigaction)
+
+#ifdef WRAPPER_INCLUDE
+# include WRAPPER_INCLUDE
+#endif
+
+#ifndef LIBC_SIGACTION
+weak_alias (__libc_sigaction, __sigaction);
+libc_hidden_weak (__sigaction)
+weak_alias (__libc_sigaction, sigaction);
+#endif
+
+static void
+__rt_sigreturn_stub (void)
+{
+ __asm__ ("mov %0, %%g1\n\t"
+ "ta 0x10\n\t"
+ : /* no outputs */
+ : "i" (__NR_rt_sigreturn));
+}
+
+static void
+__sigreturn_stub (void)
+{
+ __asm__ ("mov %0, %%g1\n\t"
+ "ta 0x10\n\t"
+ : /* no outputs */
+ : "i" (__NR_sigreturn));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h
new file mode 100644
index 000000000..2c2770d07
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define SIGCONTEXT struct sigcontext *
+#define SIGCONTEXT_EXTRA_ARGS
+#define GET_PC(__ctx) ((void *) ((__ctx)->si_regs.pc))
+#define ADVANCE_STACK_FRAME(__next) \
+ ((void *) (((unsigned *)(__next))+14))
+
+#define GET_STACK(__ctx) ((void *) (__ctx)->si_regs.u_regs[14])
+#define GET_FRAME(__ctx) ADVANCE_STACK_FRAME (GET_STACK(__ctx))
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/socket.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/socket.S
new file mode 100644
index 000000000..71a63d5b7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/socket.S
@@ -0,0 +1,117 @@
+/* Copyright (C) 1997, 1998, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Miguel de Icaza <miguel@gnu.ai.mit.edu>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+#define P(a, b) P2(a, b)
+#define P2(a, b) a##b
+
+#ifndef NARGS
+#ifdef socket
+#error NARGS not defined
+#endif
+#define NARGS 3
+#endif
+
+ .text
+/* The socket-oriented system calls are handled unusually in Linux.
+ They are all gated through the single `socketcall' system call number.
+ `socketcall' takes two arguments: the first is the subcode, specifying
+ which socket function is being called; and the second is a pointer to
+ the arguments to the specific function.
+
+ The .S files for the other calls just #define socket and #include this. */
+
+#ifndef __socket
+# ifndef NO_WEAK_ALIAS
+# define __socket P(__,socket)
+# else
+# define __socket socket
+# endif
+#endif
+
+ .globl __syscall_error
+ENTRY (__socket)
+
+ /* Drop up to 6 arguments (recvfrom) into the memory allocated by
+ the caller for varargs, since that's really what we have. */
+ st %o0, [%sp + 68 + 0]
+ st %o1, [%sp + 68 + 4]
+#if NARGS > 2
+ st %o2, [%sp + 68 + 8]
+#if NARGS > 3
+ st %o3, [%sp + 68 + 12]
+#if NARGS > 4
+ st %o4, [%sp + 68 + 16]
+#if NARGS > 5
+ st %o5, [%sp + 68 + 20]
+#endif
+#endif
+#endif
+#endif
+
+#if defined NEED_CANCELLATION && defined CENABLE
+ SINGLE_THREAD_P
+ cmp %g1, 0
+ bne .Lsocket_cancel
+#endif
+ mov P(SOCKOP_,socket), %o0 /* arg 1: socket subfunction */
+ add %sp, 68, %o1 /* arg 2: parameter block */
+ LOADSYSCALL(socketcall)
+ t 0x10
+ bcc 1f
+ mov %o7, %g1
+ call __syscall_error
+ mov %g1, %o7
+1: jmpl %o7 + 8, %g0
+ nop
+
+#if defined NEED_CANCELLATION && defined CENABLE
+.Lsocket_cancel:
+ save %sp, -96, %sp
+ cfi_def_cfa_register(%fp)
+ cfi_window_save
+ cfi_register(%o7, %i7)
+ CENABLE
+ nop
+ mov %o0, %l0
+ add %sp, 68 + 96, %o1
+ mov P(SOCKOP_,socket), %o0
+ LOADSYSCALL(socketcall)
+ t 0x10
+ bcc 1f
+ mov %o0, %l1
+ CDISABLE;
+ mov %l0, %o0;
+ call __syscall_error;
+ mov %l1, %o0;
+ b 1f
+ mov -1, %l1;
+1: CDISABLE
+ mov %l0, %o0
+2: jmpl %i7 + 8, %g0
+ restore %g0, %l1, %o0
+#endif
+
+END (__socket)
+
+#ifndef NO_WEAK_ALIAS
+weak_alias (__socket, socket)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/get_clockfreq.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/get_clockfreq.c
new file mode 100644
index 000000000..4191085d1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/get_clockfreq.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/syscall.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/syscall.S
new file mode 100644
index 000000000..161074552
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/syscall.S
@@ -0,0 +1,37 @@
+/* Copyright (C) 1991, 1992, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+ .text
+ .globl __syscall_error
+ENTRY(syscall)
+ mov %o0, %g1
+ mov %o1, %o0
+ mov %o2, %o1
+ mov %o3, %o2
+ mov %o4, %o3
+ mov %o5, %o4
+ ta 0x10
+ bcc 1f
+ mov %o7, %g1
+ call __syscall_error
+ mov %g1, %o7
+1: retl
+ nop
+END(syscall)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list
new file mode 100644
index 000000000..2bfe376a3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list
@@ -0,0 +1,6 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+setrlimit - setrlimit 2 __setrlimit setrlimit
+getrlimit - getrlimit 2 __getrlimit getrlimit
+getresuid - getresuid32 3 getresuid
+getresgid - getresgid32 3 getresgid
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
new file mode 100644
index 000000000..c808a97fc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
@@ -0,0 +1,160 @@
+/* Copyright (C) 1997, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Miguel de Icaza <miguel@gnu.ai.mit.edu>, January 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_SPARC32_SYSDEP_H
+#define _LINUX_SPARC32_SYSDEP_H 1
+
+#include <sysdeps/unix/sparc/sysdep.h>
+
+#ifdef IS_IN_rtld
+# include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
+#endif
+#include <tls.h>
+
+#undef SYS_ify
+#define SYS_ify(syscall_name) __NR_##syscall_name
+
+#ifdef __ASSEMBLER__
+
+#define LOADSYSCALL(x) mov __NR_##x, %g1
+
+/* Linux/SPARC uses a different trap number */
+#undef PSEUDO
+#undef PSEUDO_NOERRNO
+#undef PSEUDO_ERRVAL
+#undef PSEUDO_END
+#undef ENTRY
+#undef END
+#undef LOC
+
+#define ENTRY(name) \
+ .align 4; \
+ .global C_SYMBOL_NAME(name); \
+ .type name, @function; \
+C_LABEL(name) \
+ cfi_startproc;
+
+#define END(name) \
+ cfi_endproc; \
+ .size name, . - name
+
+#define LOC(name) .L##name
+
+ /* If the offset to __syscall_error fits into a signed 22-bit
+ * immediate branch offset, the linker will relax the call into
+ * a normal branch.
+ */
+#define PSEUDO(name, syscall_name, args) \
+ .text; \
+ .globl __syscall_error; \
+ENTRY(name); \
+ LOADSYSCALL(syscall_name); \
+ ta 0x10; \
+ bcc 1f; \
+ mov %o7, %g1; \
+ call __syscall_error; \
+ mov %g1, %o7; \
+1:
+
+#define PSEUDO_NOERRNO(name, syscall_name, args)\
+ .text; \
+ENTRY(name); \
+ LOADSYSCALL(syscall_name); \
+ ta 0x10;
+
+#define PSEUDO_ERRVAL(name, syscall_name, args) \
+ .text; \
+ENTRY(name); \
+ LOADSYSCALL(syscall_name); \
+ ta 0x10;
+
+#define PSEUDO_END(name) \
+ END(name)
+
+#else /* __ASSEMBLER__ */
+
+#define __SYSCALL_STRING \
+ "ta 0x10;" \
+ "bcs 2f;" \
+ " nop;" \
+ "1:" \
+ ".subsection 2;" \
+ "2:" \
+ "save %%sp, -192, %%sp;" \
+ "call __errno_location;" \
+ " nop;" \
+ "st %%i0,[%%o0];" \
+ "ba 1b;" \
+ " restore %%g0, -1, %%o0;" \
+ ".previous;"
+
+#define __CLONE_SYSCALL_STRING \
+ "ta 0x10;" \
+ "bcs 2f;" \
+ " sub %%o1, 1, %%o1;" \
+ "and %%o0, %%o1, %%o0;" \
+ "1:" \
+ ".subsection 2;" \
+ "2:" \
+ "save %%sp, -192, %%sp;" \
+ "call __errno_location;" \
+ " nop;" \
+ "st %%i0, [%%o0];" \
+ "ba 1b;" \
+ " restore %%g0, -1, %%o0;" \
+ ".previous;"
+
+#define __INTERNAL_SYSCALL_STRING \
+ "ta 0x10;" \
+ "bcs,a 1f;" \
+ " sub %%g0, %%o0, %%o0;" \
+ "1:"
+
+#define __SYSCALL_CLOBBERS "g2", "g3", "g4", "g5", "g6", \
+ "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
+ "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
+ "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
+ "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
+ "cc", "memory"
+
+#include <sysdeps/unix/sysv/linux/sparc/sysdep.h>
+
+#endif /* __ASSEMBLER__ */
+
+/* Pointer mangling support. */
+#if defined NOT_IN_libc && defined IS_IN_rtld
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+ earlier than the descriptor is initialized. */
+#else
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(dreg, reg, tmpreg) \
+ ld [%g7 + POINTER_GUARD], tmpreg; \
+ xor reg, tmpreg, dreg
+# define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
+# define PTR_MANGLE2(dreg, reg, tmpreg) \
+ xor reg, tmpreg, dreg
+# define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
+# else
+# define PTR_MANGLE(var) \
+ (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+# define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* linux/sparc/sysdep.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc32/xstat.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/xstat.c
new file mode 100644
index 000000000..e9869f550
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc32/xstat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/xstat.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/Implies b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/Implies
new file mode 100644
index 000000000..8d91c8009
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/Implies
@@ -0,0 +1 @@
+unix/sysv/linux/wordsize-64
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/Makefile b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/Makefile
new file mode 100644
index 000000000..df4533af6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/Makefile
@@ -0,0 +1,2 @@
+sysdep-CFLAGS += -fcall-used-g6
+LD += -melf64_sparc
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/Versions b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/Versions
new file mode 100644
index 000000000..cfcc15b11
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/Versions
@@ -0,0 +1,11 @@
+libc {
+ GLIBC_2.0 {
+ # Exception handling support functions from libgcc
+ __register_frame; __register_frame_table; __deregister_frame;
+ __frame_state_for; __register_frame_info_table;
+ }
+ GLIBC_2.2.2 {
+ # w*
+ wordexp;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/__longjmp.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/__longjmp.S
new file mode 100644
index 000000000..3107179fd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/__longjmp.S
@@ -0,0 +1 @@
+/* There is no need for __longjmp what with setcontext. */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/brk.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/brk.S
new file mode 100644
index 000000000..134ce789f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/brk.S
@@ -0,0 +1,98 @@
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* __brk is a special syscall under Linux since it never returns an
+ error. Instead, the error condition is indicated by returning the old
+ break value (instead of the new, requested one). */
+
+#include <sysdep.h>
+#define _ERRNO_H
+#include <bits/errno.h>
+
+#ifdef PIC
+.section .bss
+ .align 8
+ .globl __curbrk
+__curbrk: .skip 8
+ .type __curbrk,@object
+ .size __curbrk,8
+#else
+.common __curbrk, 8, 8
+#endif
+
+ .text
+ENTRY (__brk)
+ save %sp, -192, %sp
+ cfi_def_cfa_register(%fp)
+ cfi_window_save
+ cfi_register(%o7, %i7)
+#ifdef PIC
+1: call 2f
+ sethi %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7
+2: or %l7, %lo(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7
+ add %l7, %o7, %l7
+#endif
+
+ LOADSYSCALL(brk)
+ mov %i0, %o0
+
+ ta 0x6d
+
+ /* All the ways we can fail... */
+ bcs,pn %xcc, .Lerr1
+ nop
+ brz,pt %i0, .Lok
+ subcc %i0, %o0, %g0
+ bne,pn %xcc, .Lerr0
+ nop
+
+ /* Update __curbrk and return cleanly. */
+.Lok: sethi %hi(__curbrk), %g1
+ or %g1, %lo(__curbrk), %g1
+#ifdef PIC
+ ldx [%l7+%g1], %g1
+#endif
+ stx %o0, [%g1]
+ mov %g0, %i0
+
+ /* Don't use "ret" cause the preprocessor will eat it. */
+ jmpl %i7+8, %g0
+ restore
+
+ /* What a horrible way to die. */
+.Lerr0: set ENOMEM, %o0
+.Lerr1:
+#ifndef _LIBC_REENTRANT
+ sethi %hi(errno), %g1
+ or %g1, %lo(errno), %g1
+#ifdef PIC
+ ldx [%l7+%g1], %g1
+#endif
+ st %o0, [%g1]
+#else
+ call __errno_location
+ mov %o0,%l1
+ st %l1, [%o0]
+#endif
+ sub %g0, 1, %i0
+ jmpl %i7+8, %g0
+ restore
+END (__brk)
+
+weak_alias (__brk, brk)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/bsd-_setjmp.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/bsd-_setjmp.S
new file mode 100644
index 000000000..4e6a2da56
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/bsd-_setjmp.S
@@ -0,0 +1 @@
+/* _setjmp is in setjmp.S */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/bsd-setjmp.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/bsd-setjmp.S
new file mode 100644
index 000000000..1da848d2f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/bsd-setjmp.S
@@ -0,0 +1 @@
+/* setjmp is in setjmp.S */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S
new file mode 100644
index 000000000..ebfce9e2c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S
@@ -0,0 +1,121 @@
+/* Copyright (C) 1997, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson (rth@tamu.edu).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* clone() is even more special than fork() as it mucks with stacks
+ and invokes a function in the right context after its all over. */
+
+#include <asm/errno.h>
+#include <asm/unistd.h>
+#include <tcb-offsets.h>
+#include <sysdep.h>
+
+#define CLONE_VM 0x00000100
+#define CLONE_THREAD 0x00010000
+
+/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
+ pid_t *ptid, void *tls, pid_t *ctid); */
+
+ .register %g2,#scratch
+ .register %g3,#scratch
+
+ .text
+
+ENTRY (__clone)
+ save %sp, -192, %sp
+ cfi_def_cfa_register(%fp)
+ cfi_window_save
+ cfi_register(%o7, %i7)
+
+ /* sanity check arguments */
+ brz,pn %i0, 99f /* fn non-NULL? */
+ mov %i0, %g2
+ brz,pn %i1, 99f /* child_stack non-NULL? */
+ mov %i2, %o0 /* clone flags */
+
+ /* The child_stack is the top of the stack, allocate one
+ whole stack frame from that as this is what the kernel
+ expects. Also, subtract STACK_BIAS. */
+ sub %i1, 192 + 0x7ff, %o1
+ mov %i3, %g3
+ mov %i2, %g4
+
+ mov %i4,%o2 /* PTID */
+ mov %i5,%o3 /* TLS */
+ ldx [%fp+0x7ff+176],%o4 /* CTID */
+
+ /* Do the system call */
+ set __NR_clone, %g1
+ ta 0x6d
+ bcs,pn %xcc, 99f
+ nop
+ brnz,pn %o1, __thread_start
+ nop
+ jmpl %i7 + 8, %g0
+ restore %o0, %g0, %o0
+99:
+#ifndef _LIBC_REENTRANT
+#ifdef PIC
+ call 1f
+ sethi %hi(_GLOBAL_OFFSET_TABLE_-(99b-.)), %l7
+1: or %l7, %lo(_GLOBAL_OFFSET_TABLE_-(99b-.)), %l7
+ add %l7, %o7, %l7
+ set EINVAL, %i0
+ sethi %hi(errno), %g2
+ or %g2, %lo(errno), %g2
+ st %i0, [%l7+%g2]
+#else
+ sethi %hi(errno), %g2
+ set EINVAL, %i0
+ st %i0, [%g2+%lo(errno)]
+#endif
+#else
+ call __errno_location
+ nop
+ st %i0, [%o0]
+#endif
+ jmpl %i7 + 8, %g0
+ restore %g0,-1,%o0
+END(__clone)
+
+ .type __thread_start,@function
+__thread_start:
+ cfi_startproc
+#ifdef RESET_PID
+ sethi %hi(CLONE_THREAD), %l0
+ andcc %g4, %l0, %g0
+ bne,pt %icc, 1f
+ andcc %g4, CLONE_VM, %g0
+ bne,a,pn %icc, 2f
+ mov -1,%o0
+ set __NR_getpid,%g1
+ ta 0x6d
+2: st %o0,[%g7 + PID]
+ st %o0,[%g7 + TID]
+1:
+#endif
+ mov %g0, %fp /* terminate backtrace */
+ call %g2
+ mov %g3,%o0
+ call _exit,0
+ nop
+ cfi_endproc
+
+ .size __thread_start, .-__thread_start
+
+weak_alias (__clone, clone)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/dl-brk.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/dl-brk.S
new file mode 100644
index 000000000..eeb96544e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/dl-brk.S
@@ -0,0 +1 @@
+#include <brk.S>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/dl-cache.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/dl-cache.h
new file mode 100644
index 000000000..131cbb8fb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/dl-cache.h
@@ -0,0 +1,25 @@
+/* Support for reading /etc/ld.so.cache files written by Linux ldconfig.
+ Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define _DL_CACHE_DEFAULT_ID 0x103
+
+#define _dl_cache_check_flags(flags) \
+ ((flags) == _DL_CACHE_DEFAULT_ID)
+
+#include_next <dl-cache.h>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/fxstat.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/fxstat.c
new file mode 100644
index 000000000..6b374777b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/fxstat.c
@@ -0,0 +1 @@
+#include "../../fxstat.c"
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/fxstatat.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/fxstatat.c
new file mode 100644
index 000000000..db08af8e0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/fxstatat.c
@@ -0,0 +1 @@
+#include "../../i386/fxstatat.c"
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c
new file mode 100644
index 000000000..e2d31a2e4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c
@@ -0,0 +1,238 @@
+/* Get frequency of the system processor. sparc64 version.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <libc-internal.h>
+#include <asm/openpromio.h>
+
+static hp_timing_t
+__get_clockfreq_via_cpuinfo (void)
+{
+ hp_timing_t result;
+ int fd;
+
+ result = 0;
+
+ fd = open ("/proc/cpuinfo", O_RDONLY);
+ if (fd != -1)
+ {
+ char buf[8192];
+ ssize_t n;
+
+ n = read (fd, buf, sizeof buf);
+ if (n > 0)
+ {
+ char *mhz = memmem (buf, n, "Cpu0ClkTck", 7);
+
+ if (mhz != NULL)
+ {
+ char *endp = buf + n;
+
+ /* Search for the beginning of the string. */
+ while (mhz < endp
+ && (*mhz < '0' || *mhz > '9')
+ && (*mhz < 'a' || *mhz > 'f')
+ && *mhz != '\n')
+ ++mhz;
+
+ while (mhz < endp && *mhz != '\n')
+ {
+ if ((*mhz >= '0' && *mhz <= '9') ||
+ (*mhz >= 'a' && *mhz <= 'f'))
+ {
+ result <<= 4;
+ if (*mhz >= '0' && *mhz <= '9')
+ result += *mhz - '0';
+ else
+ result += (*mhz - 'a') + 10;
+ }
+ ++mhz;
+ }
+ }
+ }
+
+ close (fd);
+ }
+
+ return result;
+}
+
+static hp_timing_t
+__get_clockfreq_via_proc_openprom (void)
+{
+ hp_timing_t result;
+ int obp_fd;
+
+ result = 0;
+
+ obp_fd = open ("/proc/openprom", O_RDONLY);
+ if (obp_fd != -1)
+ {
+ unsigned long int buf[4096 / sizeof (unsigned long int)];
+ struct dirent *dirp = (struct dirent *) buf;
+ off_t dbase = (off_t) 0;
+ ssize_t len;
+
+ while ((len = getdirentries (obp_fd, (char *) dirp,
+ sizeof (buf), &dbase)) > 0)
+ {
+ struct dirent *this_dirp = dirp;
+
+ while (len > 0)
+ {
+ char node[strlen ("/proc/openprom/")
+ + _D_ALLOC_NAMLEN (this_dirp)
+ + strlen ("/clock-frequency")];
+ char *prop;
+ int fd;
+
+ /* Note that
+ strlen("/clock-frequency") > strlen("/device_type")
+ */
+ __stpcpy (prop = __stpcpy (__stpcpy (node, "/proc/openprom/"),
+ this_dirp->d_name),
+ "/device_type");
+ fd = open (node, O_RDONLY);
+ if (fd != -1)
+ {
+ char type_string[128];
+ int ret;
+
+ ret = read (fd, type_string, sizeof (type_string));
+ if (ret > 0 && strncmp (type_string, "'cpu'", 5) == 0)
+ {
+ int clkfreq_fd;
+
+ __stpcpy (prop, "/clock-frequency");
+ clkfreq_fd = open (node, O_RDONLY);
+ if (fd != -1)
+ {
+ if (read (clkfreq_fd, type_string,
+ sizeof (type_string)) > 0)
+ result = (hp_timing_t)
+ strtoull (type_string, NULL, 16);
+ close (clkfreq_fd);
+ }
+ }
+ close (fd);
+ }
+
+ if (result != 0)
+ break;
+
+ len -= this_dirp->d_reclen;
+ this_dirp = (struct dirent *)
+ ((char *) this_dirp + this_dirp->d_reclen);
+ }
+ if (result != 0)
+ break;
+ }
+ close (obp_fd);
+ }
+
+ return result;
+}
+
+static hp_timing_t
+__get_clockfreq_via_dev_openprom (void)
+{
+ hp_timing_t result;
+ int obp_dev_fd;
+
+ result = 0;
+
+ obp_dev_fd = open ("/dev/openprom", O_RDONLY);
+ if (obp_dev_fd != -1)
+ {
+ char obp_buf[8192];
+ struct openpromio *obp_cmd = (struct openpromio *)obp_buf;
+ int ret;
+
+ obp_cmd->oprom_size =
+ sizeof (obp_buf) - sizeof (unsigned int);
+ *(int *) obp_cmd->oprom_array = 0;
+ ret = ioctl (obp_dev_fd, OPROMCHILD, (char *) obp_cmd);
+ if (ret == 0)
+ {
+ int cur_node = *(int *) obp_cmd->oprom_array;
+
+ while (cur_node != 0 && cur_node != -1)
+ {
+ obp_cmd->oprom_size = sizeof (obp_buf) - sizeof (unsigned int);
+ strcpy (obp_cmd->oprom_array, "device_type");
+ ret = ioctl (obp_dev_fd, OPROMGETPROP, (char *) obp_cmd);
+ if (ret == 0
+ && strncmp (obp_cmd->oprom_array, "cpu", 3) == 0)
+ {
+ obp_cmd->oprom_size = (sizeof (obp_buf)
+ - sizeof (unsigned int));
+ strcpy (obp_cmd->oprom_array, "clock-frequency");
+ ret = ioctl (obp_dev_fd, OPROMGETPROP, (char *) obp_cmd);
+ if (ret == 0)
+ result =
+ (hp_timing_t) *(unsigned int *) obp_cmd->oprom_array;
+ }
+ obp_cmd->oprom_size = sizeof (obp_buf) - sizeof (unsigned int);
+ *(int *) obp_cmd->oprom_array = cur_node;
+ ret = ioctl (obp_dev_fd, OPROMNEXT, (char *) obp_cmd);
+ if (ret < 0)
+ break;
+ cur_node = *(int *)obp_cmd->oprom_array;
+ }
+ }
+ }
+
+ return result;
+}
+
+hp_timing_t
+__get_clockfreq (void)
+{
+ static hp_timing_t result;
+
+ /* If this function was called before, we know the result. */
+ if (result != 0)
+ return result;
+
+ /* We first read the information from the /proc/cpuinfo file.
+ It contains at least one line like
+ Cpu0ClkTick : 000000002cb41780
+ We search for this line and convert the number in an integer. */
+ result = __get_clockfreq_via_cpuinfo ();
+ if (result != 0)
+ return result;
+
+ /* If that did not work, try to find an OpenPROM node
+ with device_type equal to 'cpu' using /dev/openprom
+ and fetch the clock-frequency property from there. */
+ result = __get_clockfreq_via_dev_openprom ();
+ if (result != 0)
+ return result;
+
+ /* Finally, try the same lookup as above but using /proc/openprom. */
+ result = __get_clockfreq_via_proc_openprom ();
+
+ return result;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/getcontext.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/getcontext.S
new file mode 100644
index 000000000..e6f5b55d6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/getcontext.S
@@ -0,0 +1,65 @@
+/* Copyright (C) 1997, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson (rth@tamu.edu).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include "ucontext_i.h"
+
+/* int getcontext(ucontext_t *); */
+
+ENTRY(__getcontext)
+
+ ldx [%o0 + UC_LINK], %o1 /* Preserve uc_link field, the
+ trap clears it. */
+ ta 0x6e
+1:
+ ldx [%o0 + UC_M_PC], %o2
+ ldx [%o0 + UC_M_NPC], %o3
+ ldx [%o0 + __UC_SIGMASK], %o4
+ stx %o1, [%o0 + UC_LINK]
+ add %o2, 2f - 1b, %o2
+ stx %o2, [%o0 + UC_M_PC]
+ add %o3, 2f - 1b, %o3
+ stx %o3, [%o0 + UC_M_NPC]
+#if SIGMASK_WORDS == 16
+ stx %o4, [%o0 + UC_SIGMASK]
+ stx %g0, [%o0 + UC_SIGMASK + 8]
+ stx %g0, [%o0 + UC_SIGMASK + 16]
+ stx %g0, [%o0 + UC_SIGMASK + 24]
+ stx %g0, [%o0 + UC_SIGMASK + 32]
+ stx %g0, [%o0 + UC_SIGMASK + 40]
+ stx %g0, [%o0 + UC_SIGMASK + 48]
+ stx %g0, [%o0 + UC_SIGMASK + 56]
+ stx %g0, [%o0 + UC_SIGMASK + 64]
+ stx %g0, [%o0 + UC_SIGMASK + 72]
+ stx %g0, [%o0 + UC_SIGMASK + 80]
+ stx %g0, [%o0 + UC_SIGMASK + 88]
+ stx %g0, [%o0 + UC_SIGMASK + 96]
+ stx %g0, [%o0 + UC_SIGMASK + 104]
+ stx %g0, [%o0 + UC_SIGMASK + 112]
+ stx %g0, [%o0 + UC_SIGMASK + 120]
+#else
+# error Adjust __getcontext
+#endif
+2:
+ retl
+ clr %o0
+
+END(__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/kernel_stat.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/kernel_stat.h
new file mode 100644
index 000000000..a4e411d13
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/kernel_stat.h
@@ -0,0 +1,47 @@
+/* Definition of `struct stat' used in the kernel */
+struct kernel_stat
+ {
+ unsigned int st_dev;
+ unsigned long int st_ino;
+ unsigned int st_mode;
+ short int st_nlink;
+ unsigned int st_uid;
+ unsigned int st_gid;
+ unsigned int st_rdev;
+ long int st_size;
+ long int st_atime_sec;
+ long int st_mtime_sec;
+ long int st_ctime_sec;
+ long int st_blksize;
+ long int st_blocks;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ };
+
+/* Definition of `struct stat64' used in the kernel. */
+struct kernel_stat64
+ {
+ unsigned long int st_dev;
+ unsigned long int st_ino;
+ unsigned long int st_nlink;
+
+ unsigned int st_mode;
+ unsigned int st_uid;
+ unsigned int st_gid;
+ unsigned int __pad0;
+
+ unsigned long int st_rdev;
+ long int st_size;
+ long int st_blksize;
+ long int st_blocks;
+
+ unsigned long int st_atime_sec;
+ unsigned long int st_atime_nsec;
+ unsigned long int st_mtime_sec;
+ unsigned long int st_mtime_nsec;
+ unsigned long int st_ctime_sec;
+ unsigned long int st_ctime_nsec;
+ long int __unused[3];
+ };
+
+#define XSTAT_IS_XSTAT64 1
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/longjmp.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/longjmp.S
new file mode 100644
index 000000000..88dc54e85
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/longjmp.S
@@ -0,0 +1,52 @@
+/* Copyright (C) 1997, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson (rth@tamu.edu).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* longjmp is implemented in terms of the setcontext trap on Linux/Sparc64. */
+
+#include <sysdep.h>
+
+/* Offsets into the jmp_buf structure. */
+
+#define O_mask_was_saved 512
+#define O_gregs 32
+#define O_g1 (O_gregs + 4*8)
+
+
+/* void longjmp (sigjmp_buf env, int val) */
+
+ENTRY(__libc_siglongjmp)
+
+ /* Modify the context with the value we want to return. */
+ movre %o1, 1, %o1
+ stx %o1, [%o0 + O_g1]
+
+ /* Let setcontext know if we want to modify the current sigmask. */
+ ld [%o0 + O_mask_was_saved], %o1
+
+ /* And bamf back to where we belong! */
+ ta 0x6f
+
+END(__libc_siglongjmp)
+
+strong_alias(__libc_siglongjmp, __longjmp)
+strong_alias(__libc_siglongjmp, __libc_longjmp)
+libc_hidden_def (__libc_longjmp)
+weak_alias (__libc_siglongjmp, longjmp)
+weak_alias (__libc_siglongjmp, _longjmp)
+weak_alias (__libc_siglongjmp, siglongjmp)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/lxstat.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/lxstat.c
new file mode 100644
index 000000000..7f1e98e43
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/lxstat.c
@@ -0,0 +1 @@
+#include "../../i386/lxstat.c"
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/makecontext.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/makecontext.c
new file mode 100644
index 000000000..52406dcce
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/makecontext.c
@@ -0,0 +1,67 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ucontext.h>
+
+void
+__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
+{
+ extern void __makecontext_ret (void);
+ unsigned long *sp, *topsp;
+ va_list ap;
+ int i;
+
+ sp = (long *) ((long) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
+ sp -= (argc > 6 ? argc : 6) + 32;
+ sp = (long *) (((long) sp) & -16L);
+ topsp = sp + (argc > 6 ? argc : 6) + 16;
+
+ ucp->uc_mcontext.mc_gregs[MC_PC] = (long) func;
+ ucp->uc_mcontext.mc_gregs[MC_NPC] = ((long) func) + 4;
+ ucp->uc_mcontext.mc_gregs[MC_O6] = ((long) sp) - 0x7ff;
+ ucp->uc_mcontext.mc_gregs[MC_O7] = ((long) __makecontext_ret) - 8;
+ ucp->uc_mcontext.mc_fp = ((long) topsp) - 0x7ff;
+ ucp->uc_mcontext.mc_i7 = 0;
+ topsp[14] = 0;
+ topsp[15] = 0;
+ sp[8] = (long) ucp->uc_link;
+ va_start (ap, argc);
+ for (i = 0; i < argc; ++i)
+ if (i < 6)
+ ucp->uc_mcontext.mc_gregs[MC_O0 + i] = va_arg (ap, long);
+ else
+ sp[16 + i] = va_arg (ap, long);
+ va_end (ap);
+}
+
+asm (" \n\
+ .text \n\
+ .type __makecontext_ret, #function \n\
+__makecontext_ret: \n\
+ mov 1, %o1 \n\
+ call __setcontext \n\
+ mov %i0, %o0 \n\
+ unimp 0 \n\
+ .size __makecontext_ret, .-__makecontext_ret \n\
+ ");
+
+weak_alias (__makecontext, makecontext)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/msgctl.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/msgctl.c
new file mode 100644
index 000000000..06a54a92b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/msgctl.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 1995, 1997, 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/msg.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Allows to control internal state and destruction of message queue
+ objects. */
+
+int
+msgctl (msqid, cmd, buf)
+ int msqid;
+ int cmd;
+ struct msqid_ds *buf;
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd, 0, CHECK_1 (buf));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c
new file mode 100644
index 000000000..2ec5bd39a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c
@@ -0,0 +1 @@
+#include <sysdeps/posix/pause.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S
new file mode 100644
index 000000000..14f244e62
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S
@@ -0,0 +1,41 @@
+/* Copyright (C) 1997, 1999, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Miguel de Icaza <miguel@gnu.ai.mit.edu>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+ .text
+
+ .globl __syscall_error
+ENTRY(__libc_pipe)
+ mov %o0, %o2 /* Save PIPEDES. */
+ LOADSYSCALL(pipe)
+ ta 0x6d
+ bcc,pt %xcc, 1f
+ mov %o7, %g1
+ call __syscall_error
+ mov %g1, %o7
+1: st %o0, [%o2] /* PIPEDES[0] = %o0; */
+ st %o1, [%o2 + 4] /* PIPEDES[1] = %o1; */
+ retl
+ clr %o0
+END(__libc_pipe)
+
+weak_alias (__libc_pipe, __pipe)
+libc_hidden_def (__pipe)
+weak_alias (__libc_pipe, pipe)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/profil-counter.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/profil-counter.h
new file mode 100644
index 000000000..813bc2ca8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/profil-counter.h
@@ -0,0 +1,26 @@
+/* Low-level statistical profiling support function. Linux/Sparc64 version.
+ Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <signal.h>
+
+void
+profil_counter (int signo, struct sigcontext *si)
+{
+ profil_count ((void *) si->sigc_regs.tpc);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/register-dump.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/register-dump.h
new file mode 100644
index 000000000..69265a284
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/register-dump.h
@@ -0,0 +1,257 @@
+/* Dump registers.
+ Copyright (C) 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jj@ultra.linux.cz>, 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/uio.h>
+#include <stdio-common/_itoa.h>
+
+/* We will print the register dump in this format:
+
+ TSTATE: XXXXXXXXXXXXXXXX TPC: XXXXXXXXXXXXXXXX TNPC: XXXXXXXXXXXXXXXX
+ Y: XXXXXXXX
+ g0: 0000000000000000 g1: XXXXXXXXXXXXXXXX g2: XXXXXXXXXXXXXXXX
+ g3: XXXXXXXXXXXXXXXX g4: XXXXXXXXXXXXXXXX g5: XXXXXXXXXXXXXXXX
+ g6: XXXXXXXXXXXXXXXX g7: XXXXXXXXXXXXXXXX
+ o0: XXXXXXXXXXXXXXXX o1: XXXXXXXXXXXXXXXX o2: XXXXXXXXXXXXXXXX
+ o3: XXXXXXXXXXXXXXXX o4: XXXXXXXXXXXXXXXX o5: XXXXXXXXXXXXXXXX
+ sp: XXXXXXXXXXXXXXXX o7: XXXXXXXXXXXXXXXX
+ l0: XXXXXXXXXXXXXXXX l1: XXXXXXXXXXXXXXXX l2: XXXXXXXXXXXXXXXX
+ l3: XXXXXXXXXXXXXXXX l4: XXXXXXXXXXXXXXXX l5: XXXXXXXXXXXXXXXX
+ l6: XXXXXXXXXXXXXXXX l7: XXXXXXXXXXXXXXXX
+ i0: XXXXXXXXXXXXXXXX i1: XXXXXXXXXXXXXXXX i2: XXXXXXXXXXXXXXXX
+ i3: XXXXXXXXXXXXXXXX i4: XXXXXXXXXXXXXXXX i5: XXXXXXXXXXXXXXXX
+ fp: XXXXXXXXXXXXXXXX i7: XXXXXXXXXXXXXXXX
+
+ Mask: XXXXXXXXXXXXXXXX XFSR: XXXXXXXXXXXXXXXX GSR: XX FPRS: X
+ f0: XXXXXXXXXXXXXXXX f2: XXXXXXXXXXXXXXXX f4: XXXXXXXXXXXXXXXX
+ f6: XXXXXXXXXXXXXXXX f8: XXXXXXXXXXXXXXXX f10: XXXXXXXXXXXXXXXX
+ f12: XXXXXXXXXXXXXXXX f14: XXXXXXXXXXXXXXXX f16: XXXXXXXXXXXXXXXX
+ f18: XXXXXXXXXXXXXXXX f20: XXXXXXXXXXXXXXXX f22: XXXXXXXXXXXXXXXX
+ f24: XXXXXXXXXXXXXXXX f26: XXXXXXXXXXXXXXXX f28: XXXXXXXXXXXXXXXX
+ f30: XXXXXXXXXXXXXXXX f32: XXXXXXXXXXXXXXXX f34: XXXXXXXXXXXXXXXX
+ f36: XXXXXXXXXXXXXXXX f38: XXXXXXXXXXXXXXXX f40: XXXXXXXXXXXXXXXX
+ f42: XXXXXXXXXXXXXXXX f44: XXXXXXXXXXXXXXXX f46: XXXXXXXXXXXXXXXX
+ f48: XXXXXXXXXXXXXXXX f50: XXXXXXXXXXXXXXXX f52: XXXXXXXXXXXXXXXX
+ f54: XXXXXXXXXXXXXXXX f56: XXXXXXXXXXXXXXXX f58: XXXXXXXXXXXXXXXX
+ f60: XXXXXXXXXXXXXXXX f62: XXXXXXXXXXXXXXXX
+
+ */
+
+static void
+hexvalue (unsigned long int value, char *buf, size_t len)
+{
+ char *cp = _itoa_word (value, buf + len, 16, 0);
+ while (cp > buf)
+ *--cp = '0';
+}
+
+static void
+register_dump (int fd, SIGCONTEXT ctx)
+{
+ char regs[36][16];
+ char fregs[68][8];
+ struct iovec iov[150];
+ size_t nr = 0;
+ int i;
+ unsigned long *r = (unsigned long *)
+ (ctx->sigc_regs.u_regs[14] + STACK_BIAS);
+ __siginfo_fpu_t *f;
+
+#define ADD_STRING(str) \
+ iov[nr].iov_base = (char *) str; \
+ iov[nr].iov_len = strlen (str); \
+ ++nr
+#define ADD_MEM(str, len) \
+ iov[nr].iov_base = str; \
+ iov[nr].iov_len = len; \
+ ++nr
+
+ /* Generate strings of register contents. */
+ hexvalue (ctx->sigc_regs.tstate, regs[0], 16);
+ hexvalue (ctx->sigc_regs.tpc, regs[1], 16);
+ hexvalue (ctx->sigc_regs.tnpc, regs[2], 16);
+ hexvalue (ctx->sigc_regs.y, regs[3], 8);
+ for (i = 1; i <= 15; i++)
+ hexvalue (ctx->sigc_regs.u_regs[i], regs[3+i], 16);
+ for (i = 0; i <= 15; i++)
+ hexvalue (r[i], regs[19+i], 16);
+ hexvalue (ctx->sigc_mask, regs[35], 16);
+
+ /* Generate the output. */
+ ADD_STRING ("Register dump:\n\n TSTATE: ");
+ ADD_MEM (regs[0], 16);
+ ADD_STRING (" TPC: ");
+ ADD_MEM (regs[1], 16);
+ ADD_STRING (" TNPC: ");
+ ADD_MEM (regs[2], 16);
+ ADD_STRING ("\n Y: ");
+ ADD_MEM (regs[3], 8);
+ ADD_STRING ("\n g0: 0000000000000000 g1: ");
+ ADD_MEM (regs[4], 16);
+ ADD_STRING (" g2: ");
+ ADD_MEM (regs[5], 16);
+ ADD_STRING ("\n g3: ");
+ ADD_MEM (regs[6], 16);
+ ADD_STRING (" g4: ");
+ ADD_MEM (regs[7], 16);
+ ADD_STRING (" g5: ");
+ ADD_MEM (regs[8], 16);
+ ADD_STRING ("\n g6: ");
+ ADD_MEM (regs[9], 16);
+ ADD_STRING (" g7: ");
+ ADD_MEM (regs[10], 16);
+ ADD_STRING ("\n o0: ");
+ ADD_MEM (regs[11], 16);
+ ADD_STRING (" o1: ");
+ ADD_MEM (regs[12], 16);
+ ADD_STRING (" o2: ");
+ ADD_MEM (regs[13], 16);
+ ADD_STRING ("\n o3: ");
+ ADD_MEM (regs[14], 16);
+ ADD_STRING (" o4: ");
+ ADD_MEM (regs[15], 16);
+ ADD_STRING (" o5: ");
+ ADD_MEM (regs[16], 16);
+ ADD_STRING ("\n sp: ");
+ ADD_MEM (regs[17], 16);
+ ADD_STRING (" o7: ");
+ ADD_MEM (regs[18], 16);
+ ADD_STRING ("\n l0: ");
+ ADD_MEM (regs[19], 16);
+ ADD_STRING (" l1: ");
+ ADD_MEM (regs[20], 16);
+ ADD_STRING (" l2: ");
+ ADD_MEM (regs[21], 16);
+ ADD_STRING ("\n l3: ");
+ ADD_MEM (regs[22], 16);
+ ADD_STRING (" l4: ");
+ ADD_MEM (regs[23], 16);
+ ADD_STRING (" l5: ");
+ ADD_MEM (regs[24], 16);
+ ADD_STRING ("\n l6: ");
+ ADD_MEM (regs[25], 16);
+ ADD_STRING (" l7: ");
+ ADD_MEM (regs[26], 16);
+ ADD_STRING ("\n i0: ");
+ ADD_MEM (regs[27], 16);
+ ADD_STRING (" i1: ");
+ ADD_MEM (regs[28], 16);
+ ADD_STRING (" i2: ");
+ ADD_MEM (regs[29], 16);
+ ADD_STRING ("\n i3: ");
+ ADD_MEM (regs[30], 16);
+ ADD_STRING (" i4: ");
+ ADD_MEM (regs[31], 16);
+ ADD_STRING (" i5: ");
+ ADD_MEM (regs[32], 16);
+ ADD_STRING ("\n fp: ");
+ ADD_MEM (regs[33], 16);
+ ADD_STRING (" i7: ");
+ ADD_MEM (regs[34], 16);
+ ADD_STRING ("\n\n Mask: ");
+ ADD_MEM (regs[35], 16);
+
+ f = ctx->sigc_fpu_save;
+ if (f != NULL)
+ {
+ for (i = 0; i < 64; i++)
+ hexvalue (f->si_float_regs[i], fregs[i], 8);
+ hexvalue (f->si_fsr, fregs[64], 16);
+ hexvalue (f->si_gsr, fregs[66], 2);
+ hexvalue (f->si_fprs, fregs[67], 1);
+ ADD_STRING (" XFSR: ");
+ ADD_MEM (fregs[64], 16);
+ ADD_STRING (" GSR: ");
+ ADD_MEM (fregs[66], 2);
+ ADD_STRING (" FPRS: ");
+ ADD_MEM (fregs[67], 1);
+ ADD_STRING ("\n f0: ");
+ ADD_MEM (fregs[0], 16);
+ ADD_STRING (" f2: ");
+ ADD_MEM (fregs[2], 16);
+ ADD_STRING (" f4: ");
+ ADD_MEM (fregs[4], 16);
+ ADD_STRING ("\n f6: ");
+ ADD_MEM (fregs[6], 16);
+ ADD_STRING (" f8: ");
+ ADD_MEM (fregs[8], 16);
+ ADD_STRING (" f10: ");
+ ADD_MEM (fregs[10], 16);
+ ADD_STRING ("\n f12: ");
+ ADD_MEM (fregs[12], 16);
+ ADD_STRING (" f14: ");
+ ADD_MEM (fregs[14], 16);
+ ADD_STRING (" f16: ");
+ ADD_MEM (fregs[16], 16);
+ ADD_STRING ("\n f18: ");
+ ADD_MEM (fregs[18], 16);
+ ADD_STRING (" f20: ");
+ ADD_MEM (fregs[20], 16);
+ ADD_STRING (" f22: ");
+ ADD_MEM (fregs[22], 16);
+ ADD_STRING ("\n f24: ");
+ ADD_MEM (fregs[24], 16);
+ ADD_STRING (" f26: ");
+ ADD_MEM (fregs[26], 16);
+ ADD_STRING (" f28: ");
+ ADD_MEM (fregs[28], 16);
+ ADD_STRING ("\n f30: ");
+ ADD_MEM (fregs[30], 16);
+ ADD_STRING (" f32: ");
+ ADD_MEM (fregs[32], 16);
+ ADD_STRING (" f34: ");
+ ADD_MEM (fregs[34], 16);
+ ADD_STRING ("\n f36: ");
+ ADD_MEM (fregs[36], 16);
+ ADD_STRING (" f38: ");
+ ADD_MEM (fregs[38], 16);
+ ADD_STRING (" f40: ");
+ ADD_MEM (fregs[40], 16);
+ ADD_STRING ("\n f42: ");
+ ADD_MEM (fregs[42], 16);
+ ADD_STRING (" f44: ");
+ ADD_MEM (fregs[44], 16);
+ ADD_STRING (" f46: ");
+ ADD_MEM (fregs[46], 16);
+ ADD_STRING ("\n f48: ");
+ ADD_MEM (fregs[48], 16);
+ ADD_STRING (" f50: ");
+ ADD_MEM (fregs[50], 16);
+ ADD_STRING (" f52: ");
+ ADD_MEM (fregs[52], 16);
+ ADD_STRING ("\n f54: ");
+ ADD_MEM (fregs[54], 16);
+ ADD_STRING (" f56: ");
+ ADD_MEM (fregs[56], 16);
+ ADD_STRING (" f58: ");
+ ADD_MEM (fregs[58], 16);
+ ADD_STRING ("\n f60: ");
+ ADD_MEM (fregs[60], 16);
+ ADD_STRING (" f62: ");
+ ADD_MEM (fregs[62], 16);
+ }
+
+ ADD_STRING ("\n");
+
+ /* Write the stuff out. */
+ writev (fd, iov, nr);
+}
+
+
+#define REGISTER_DUMP register_dump (fd, ctx)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/semctl.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/semctl.c
new file mode 100644
index 000000000..057e28782
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/semctl.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 1995, 1997, 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <sys/sem.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Define a `union semun' suitable for Linux here. */
+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 */
+};
+
+#include <bp-checks.h>
+#include <bp-semctl.h> /* definition of CHECK_SEMCTL needs union semum */
+
+/* Return identifier for array of NSEMS semaphores associated with
+ KEY. */
+
+int
+semctl (int semid, int semnum, int cmd, ...)
+{
+ union semun arg;
+ va_list ap;
+
+ va_start (ap, cmd);
+
+ /* Get the argument. */
+ arg = va_arg (ap, union semun);
+
+ va_end (ap);
+
+ return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd,
+ CHECK_SEMCTL (&arg, semid, cmd));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/setcontext.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/setcontext.S
new file mode 100644
index 000000000..90d47c18f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/setcontext.S
@@ -0,0 +1,39 @@
+/* Copyright (C) 1997, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson (rth@tamu.edu).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include "ucontext_i.h"
+
+/* int setcontext(ucontext_t *ctx); */
+.weak setcontext
+ENTRY(setcontext)
+
+ ba,pt %xcc, 1f
+ mov 1, %o1
+
+END(setcontext)
+
+/* int __setcontext(ucontext_t *ctx, int restoremask); */
+ENTRY(__setcontext)
+
+1: ldx [%o0 + UC_SIGMASK], %o2
+ stx %o2, [%o0 + __UC_SIGMASK]
+ ta 0x6f
+
+END(__setcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/setjmp.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/setjmp.S
new file mode 100644
index 000000000..ab1690bb4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/setjmp.S
@@ -0,0 +1,67 @@
+/* Copyright (C) 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson (rth@tamu.edu).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* __sigsetjmp is implemented in terms of the getcontext trap on
+ Linux/Sparc64. */
+
+#include <sysdep.h>
+
+/* Offsets into the jmp_buf structure. */
+
+#define O_mask_was_saved 512
+#define O_gregs 32
+#define O_g1 (O_gregs + 4*8)
+
+/* int _setjmp(jmp_buf) */
+
+ENTRY(_setjmp)
+ ba __sigsetjmp_local
+ set 0, %o1
+END(_setjmp)
+libc_hidden_def (_setjmp)
+
+/* int setjmp(jmp_buf) */
+
+ENTRY(setjmp)
+ ba,pt %xcc, __sigsetjmp_local
+ set 1, %o1
+END(setjmp)
+
+/* int __sigsetjmp(jmp_buf, savemask) */
+
+ENTRY(__sigsetjmp)
+__sigsetjmp_local:
+
+ /* Record whether the user is intending to save the sigmask. */
+ st %o1, [%o0 + O_mask_was_saved]
+
+ /* Load up our return value, as longjmp is going to override
+ the jmp_buf on its way back. */
+ mov %g0, %g1
+
+ /* And call getcontext! */
+ ta 0x6e
+
+ retl
+ mov %g1, %o0
+
+END(__sigsetjmp)
+
+weak_extern(_setjmp)
+weak_extern(setjmp)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/shmctl.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/shmctl.c
new file mode 100644
index 000000000..797b3500f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/shmctl.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1995, 1997, 1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/shm.h>
+#include <ipc_priv.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Provide operations to control over shared memory segments. */
+
+int
+shmctl (shmid, cmd, buf)
+ int shmid;
+ int cmd;
+ struct shmid_ds *buf;
+{
+ return INLINE_SYSCALL (ipc, 5, IPCOP_shmctl, shmid, cmd, 0, CHECK_1 (buf));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigaction.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigaction.c
new file mode 100644
index 000000000..b5e35f4e4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigaction.c
@@ -0,0 +1,85 @@
+/* POSIX.1 sigaction call for Linux/SPARC64.
+ Copyright (C) 1997-2000,2002,2003,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Miguel de Icaza (miguel@nuclecu.unam.mx) and
+ Jakub Jelinek (jj@ultra.linux.cz).
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <string.h>
+#include <syscall.h>
+#include <sysdep.h>
+#include <sys/signal.h>
+#include <errno.h>
+
+#include <kernel_sigaction.h>
+
+/* SPARC 64bit userland requires a kernel that has rt signals anyway. */
+
+static void __rt_sigreturn_stub (void);
+
+int
+__libc_sigaction (int sig, __const struct sigaction *act,
+ struct sigaction *oact)
+{
+ int ret;
+ struct kernel_sigaction kact, koact;
+ unsigned long stub = ((unsigned long) &__rt_sigreturn_stub) - 8;
+
+ if (act)
+ {
+ kact.k_sa_handler = act->sa_handler;
+ memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
+ kact.sa_flags = act->sa_flags;
+ kact.sa_restorer = NULL;
+ }
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ ret = INLINE_SYSCALL (rt_sigaction, 5, sig,
+ act ? __ptrvalue (&kact) : 0,
+ oact ? __ptrvalue (&koact) : 0, stub, _NSIG / 8);
+
+ if (oact && ret >= 0)
+ {
+ oact->sa_handler = koact.k_sa_handler;
+ memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
+ oact->sa_flags = koact.sa_flags;
+ oact->sa_restorer = koact.sa_restorer;
+ }
+
+ return ret;
+}
+libc_hidden_def (__libc_sigaction)
+
+#ifdef WRAPPER_INCLUDE
+# include WRAPPER_INCLUDE
+#endif
+
+#ifndef LIBC_SIGACTION
+weak_alias (__libc_sigaction, __sigaction);
+libc_hidden_weak (__sigaction)
+weak_alias (__libc_sigaction, sigaction);
+#endif
+
+static void
+__rt_sigreturn_stub (void)
+{
+ __asm__ ("mov %0, %%g1\n\t"
+ "ta 0x6d\n\t"
+ : /* no outputs */
+ : "i" (__NR_rt_sigreturn));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h
new file mode 100644
index 000000000..47e0d27f8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h
@@ -0,0 +1,32 @@
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jj@ultra.linux.cz>, 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef STACK_BIAS
+#define STACK_BIAS 2047
+#endif
+#define SIGCONTEXT struct sigcontext *
+#define SIGCONTEXT_EXTRA_ARGS
+#define GET_PC(__ctx) ((void *) ((__ctx)->sigc_regs.tpc))
+#define ADVANCE_STACK_FRAME(__next) \
+ ((void *) (((unsigned long *) (((unsigned long int) (__next)) \
+ + STACK_BIAS))+14))
+#define GET_STACK(__ctx) ((void *) ((__ctx)->sigc_regs.u_regs[14]))
+#define GET_FRAME(__ctx) ADVANCE_STACK_FRAME (GET_STACK (__ctx))
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigjmp.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigjmp.S
new file mode 100644
index 000000000..940ccbcf6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigjmp.S
@@ -0,0 +1 @@
+/* There is no need for __sigjmp_save what with getcontext. */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigpending.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigpending.c
new file mode 100644
index 000000000..016a28534
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigpending.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Change the set of blocked signals to SET,
+ wait until a signal arrives, and restore the set of blocked signals. */
+int
+sigpending (set)
+ sigset_t *set;
+{
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ return INLINE_SYSCALL (rt_sigpending, 2, CHECK_SIGSET (set), _NSIG / 8);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigprocmask.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigprocmask.c
new file mode 100644
index 000000000..d077b9be4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sigprocmask.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Get and/or change the set of blocked signals. */
+int
+__sigprocmask (how, set, oset)
+ int how;
+ const sigset_t *set;
+ sigset_t *oset;
+{
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ return INLINE_SYSCALL (rt_sigprocmask, 4, how, CHECK_SIGSET (set),
+ CHECK_SIGSET_NULL_OK (oset), _NSIG / 8);
+}
+weak_alias (__sigprocmask, sigprocmask)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sizes.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sizes.h
new file mode 100644
index 000000000..0c7f4d5d2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sizes.h
@@ -0,0 +1,24 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIZES_H
+#define _SIZES_H 1
+
+#define PTR_SIZE_STR "8"
+
+#endif /* sizes.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/socket.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/socket.S
new file mode 100644
index 000000000..353705b4a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/socket.S
@@ -0,0 +1,119 @@
+/* Copyright (C) 1997, 1998, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Miguel de Icaza <miguel@gnu.ai.mit.edu>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+#define P(a, b) P2(a, b)
+#define P2(a, b) a##b
+
+#ifndef NARGS
+#ifdef socket
+#error NARGS not defined
+#endif
+#define NARGS 3
+#endif
+
+ .text
+/* The socket-oriented system calls are handled unusually in Linux.
+ They are all gated through the single `socketcall' system call number.
+ `socketcall' takes two arguments: the first is the subcode, specifying
+ which socket function is being called; and the second is a pointer to
+ the arguments to the specific function.
+
+ The .S files for the other calls just #define socket and #include this. */
+
+#ifndef __socket
+# ifndef NO_WEAK_ALIAS
+# define __socket P(__,socket)
+# else
+# define __socket socket
+# endif
+#endif
+
+ .globl __syscall_error
+ENTRY(__socket)
+
+ /* Drop up to 6 arguments (recvfrom) into the memory allocated by
+ the caller for varargs, since that's really what we have. */
+ stx %o0, [%sp + STACK_BIAS + 128 + 0]
+ stx %o1, [%sp + STACK_BIAS + 128 + 8]
+#if NARGS > 2
+ stx %o2, [%sp + STACK_BIAS + 128 + 16]
+#if NARGS > 3
+ stx %o3, [%sp + STACK_BIAS + 128 + 24]
+#if NARGS > 4
+ stx %o4, [%sp + STACK_BIAS + 128 + 32]
+#if NARGS > 5
+ stx %o5, [%sp + STACK_BIAS + 128 + 40]
+#endif
+#endif
+#endif
+#endif
+
+#if defined NEED_CANCELLATION && defined CENABLE
+ SINGLE_THREAD_P
+ cmp %g1, 0
+ bne .Lsocket_cancel
+#endif
+ mov P(SOCKOP_,socket), %o0 /* arg 1: socket subfunction */
+ add %sp, STACK_BIAS + 128, %o1 /* arg 2: parameter block */
+ LOADSYSCALL(socketcall)
+ ta 0x6d
+
+ bcc,pt %xcc, 1f
+ mov %o7, %g1
+ call __syscall_error
+ mov %g1, %o7
+1: retl
+ nop
+
+#if defined NEED_CANCELLATION && defined CENABLE
+.Lsocket_cancel:
+ save %sp, -160, %sp
+ cfi_def_cfa_register (%fp)
+ cfi_window_save
+ cfi_register (%o7, %i7)
+ CENABLE
+ nop
+ mov %o0, %l0
+ add %sp, 160 + STACK_BIAS + 128, %o1
+ mov P(SOCKOP_,socket), %o0
+ LOADSYSCALL(socketcall)
+ ta 0x6d
+
+ bcc,pt %xcc, 1f
+ mov %o0, %l1
+ CDISABLE;
+ mov %l0, %o0;
+ call __syscall_error;
+ mov %l1, %o0;
+ ba,pt %xcc, 2f
+ mov -1, %l1;
+1: CDISABLE
+ mov %l0, %o0
+2: jmpl %i7 + 8, %g0
+ restore %g0, %l1, %o0
+#endif
+
+END(__socket)
+
+#ifndef NO_WEAK_ALIAS
+weak_alias (__socket, socket)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/swapcontext.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/swapcontext.c
new file mode 100644
index 000000000..ac6fd5bc6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/swapcontext.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ucontext.h>
+
+extern int __getcontext (ucontext_t *ucp);
+extern int __setcontext (const ucontext_t *ucp, int restoremask);
+
+int
+__swapcontext (ucontext_t *oucp, const ucontext_t *ucp)
+{
+ extern void __swapcontext_ret (void);
+ /* Save the current machine context to oucp. */
+ __getcontext (oucp);
+ /* Modify oucp to skip the __setcontext call on reactivation. */
+ oucp->uc_mcontext.mc_gregs[MC_PC] = (long) __swapcontext_ret;
+ oucp->uc_mcontext.mc_gregs[MC_NPC] = ((long) __swapcontext_ret) + 4;
+ /* Restore the machine context in ucp. */
+ __setcontext (ucp, 1);
+ return 0;
+}
+
+asm (" \n\
+ .text \n\
+ .type __swapcontext_ret, #function \n\
+__swapcontext_ret: \n\
+ return %i7 + 8 \n\
+ clr %o0 \n\
+ .size __swapcontext_ret, .-__swapcontext_ret \n\
+ ");
+
+weak_alias (__swapcontext, swapcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/syscall.S b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/syscall.S
new file mode 100644
index 000000000..27487d8ed
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/syscall.S
@@ -0,0 +1,39 @@
+/* Copyright (C) 1997, 1999, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+ .text
+
+ .globl __syscall_error
+ENTRY(syscall)
+ mov %o0,%g1
+ mov %o1,%o0
+ mov %o2,%o1
+ mov %o3,%o2
+ mov %o4,%o3
+ mov %o5,%o4
+
+ ta 0x6d
+
+ bcc,pt %xcc, 1f
+ mov %o7, %g1
+ call __syscall_error
+ mov %g1, %o7
+1: retl
+ nop
+END(syscall)
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
new file mode 100644
index 000000000..ca2953c6b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
@@ -0,0 +1,20 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+# Override select.S in parent directory:
+select - select C:5 __select select
+accept - accept C:3 __libc_accept __accept accept
+bind - bind 3 __bind bind
+connect - connect C:3 __libc_connect __connect_internal __connect connect
+getpeername - getpeername 3 __getpeername getpeername
+getsockname - getsockname 3 __getsockname getsockname
+getsockopt - getsockopt 5 __getsockopt getsockopt
+listen - listen 2 __listen listen
+recv - recv C:4 __libc_recv __recv recv
+recvfrom - recvfrom C:6 __libc_recvfrom __recvfrom recvfrom
+recvmsg - recvmsg C:3 __libc_recvmsg __recvmsg recvmsg
+send - send C:4 __libc_send __send send
+sendmsg - sendmsg C:3 __libc_sendmsg __sendmsg sendmsg
+sendto - sendto C:6 __libc_sendto __sendto sendto
+setsockopt - setsockopt 5 __setsockopt setsockopt
+shutdown - shutdown 2 __shutdown shutdown
+socketpair - socketpair 4 __socketpair socketpair
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
new file mode 100644
index 000000000..f156f9241
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h
@@ -0,0 +1,175 @@
+/* Copyright (C) 1997, 2000, 2002, 2003, 2004, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_SPARC64_SYSDEP_H
+#define _LINUX_SPARC64_SYSDEP_H 1
+
+#include <sysdeps/unix/sysdep.h>
+
+#ifdef IS_IN_rtld
+# include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
+#endif
+#include <tls.h>
+
+#undef SYS_ify
+#define SYS_ify(syscall_name) __NR_##syscall_name
+
+/* This is a kludge to make syscalls.list find these under the names
+ pread and pwrite, since some kernel headers define those names
+ and some define the *64 names for the same system calls. */
+#if !defined __NR_pread && defined __NR_pread64
+# define __NR_pread __NR_pread64
+#endif
+#if !defined __NR_pwrite && defined __NR_pwrite64
+# define __NR_pwrite __NR_pwrite64
+#endif
+
+#ifdef __ASSEMBLER__
+
+#define LOADSYSCALL(x) mov __NR_##x, %g1
+
+/* Linux/SPARC uses a different trap number */
+#undef PSEUDO
+#undef PSEUDO_NOERRNO
+#undef PSEUDO_ERRVAL
+#undef PSEUDO_END
+#undef ENTRY
+#undef END
+
+#define ENTRY(name) \
+ .align 4; \
+ .global C_SYMBOL_NAME(name); \
+ .type name, @function; \
+C_LABEL(name) \
+ cfi_startproc;
+
+#define END(name) \
+ cfi_endproc; \
+ .size name, . - name
+
+ /* If the offset to __syscall_error fits into a signed 22-bit
+ * immediate branch offset, the linker will relax the call into
+ * a normal branch.
+ */
+#define PSEUDO(name, syscall_name, args) \
+ .text; \
+ .globl __syscall_error; \
+ENTRY(name); \
+ LOADSYSCALL(syscall_name); \
+ ta 0x6d; \
+ bcc,pt %xcc, 1f; \
+ mov %o7, %g1; \
+ call __syscall_error; \
+ mov %g1, %o7; \
+1:
+
+#define PSEUDO_NOERRNO(name, syscall_name, args)\
+ .text; \
+ENTRY(name); \
+ LOADSYSCALL(syscall_name); \
+ ta 0x6d;
+
+#define PSEUDO_ERRVAL(name, syscall_name, args) \
+ .text; \
+ENTRY(name); \
+ LOADSYSCALL(syscall_name); \
+ ta 0x6d;
+
+#define PSEUDO_END(name) \
+ END(name)
+
+
+/* Careful here! This "ret" define can interfere; use jmpl if unsure. */
+#define ret retl; nop
+#define ret_NOERRNO retl; nop
+#define ret_ERRVAL retl; nop
+#define r0 %o0
+#define r1 %o1
+#define MOVE(x,y) mov x, y
+
+#else /* __ASSEMBLER__ */
+
+#define __SYSCALL_STRING \
+ "ta 0x6d;" \
+ "bcc,pt %%xcc, 1f;" \
+ " nop;" \
+ "save %%sp, -192, %%sp;" \
+ "call __errno_location;" \
+ " nop;" \
+ "st %%i0,[%%o0];" \
+ "restore %%g0, -1, %%o0;" \
+ "1:"
+
+#define __CLONE_SYSCALL_STRING \
+ "ta 0x6d;" \
+ "bcc,pt %%xcc, 1f;" \
+ " sub %%o1, 1, %%o1;" \
+ "save %%sp, -192, %%sp;" \
+ "call __errno_location;" \
+ " mov -1, %%i1;" \
+ "st %%i0,[%%o0];" \
+ "restore %%g0, -1, %%o0;" \
+ "1:" \
+ "and %%o0, %%o1, %%o0"
+
+#define __INTERNAL_SYSCALL_STRING \
+ "ta 0x6d;" \
+ "bcs,a,pt %%xcc, 1f;" \
+ " sub %%g0, %%o0, %%o0;" \
+ "1:"
+
+#define __SYSCALL_CLOBBERS "g2", "g3", "g4", "g5", "g6", \
+ "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
+ "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
+ "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
+ "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
+ "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", \
+ "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62", \
+ "cc", "memory"
+
+#include <sysdeps/unix/sysv/linux/sparc/sysdep.h>
+
+#endif /* __ASSEMBLER__ */
+
+/* This is the offset from the %sp to the backing store above the
+ register windows. So if you poke stack memory directly you add this. */
+#define STACK_BIAS 2047
+
+/* Pointer mangling support. */
+#if defined NOT_IN_libc && defined IS_IN_rtld
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+ earlier than the descriptor is initialized. */
+#else
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(dreg, reg, tmpreg) \
+ ldx [%g7 + POINTER_GUARD], tmpreg; \
+ xor reg, tmpreg, dreg
+# define PTR_DEMANGLE(dreg, reg, tmpreg) PTR_MANGLE (dreg, reg, tmpreg)
+# define PTR_MANGLE2(dreg, reg, tmpreg) \
+ xor reg, tmpreg, dreg
+# define PTR_DEMANGLE2(dreg, reg, tmpreg) PTR_MANGLE2 (dreg, reg, tmpreg)
+# else
+# define PTR_MANGLE(var) \
+ (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+# define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* linux/sparc64/sysdep.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/time.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/time.c
new file mode 100644
index 000000000..3a64ef195
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/time.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/time.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/ucontext_i.h b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/ucontext_i.h
new file mode 100644
index 000000000..03db063c8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/ucontext_i.h
@@ -0,0 +1,28 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Constants shared between setcontext() and getcontext(). Don't
+ install this header file. */
+
+#define UC_LINK 0
+#define __UC_SIGMASK 16
+#define UC_M_PC 40
+#define UC_M_NPC 48
+#define UC_SIGMASK 536
+#define SIGMASK_WORDS 16
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/wordexp.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/wordexp.c
new file mode 100644
index 000000000..2e3d5bc2e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/wordexp.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/alpha/wordexp.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/xstat.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/xstat.c
new file mode 100644
index 000000000..9f4c02c78
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/xstat.c
@@ -0,0 +1,8 @@
+#include "../../i386/xstat.c"
+
+#ifdef __NR_stat64
+# if __ASSUME_STAT64_SYSCALL == 0
+/* The variable is shared between all wrappers around *stat{,64} calls. */
+int __have_no_stat64;
+# endif
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sparc64/xstatconv.c b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/xstatconv.c
new file mode 100644
index 000000000..d3f49eea4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sparc64/xstatconv.c
@@ -0,0 +1,127 @@
+/* Convert between the kernel's `struct stat' format, and libc's.
+ Copyright (C) 1991, 1995, 1996, 1997, 2000, 2002, 2003, 2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+#include <string.h>
+#include <kernel-features.h>
+
+int
+__xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
+{
+ switch (vers)
+ {
+ case _STAT_VER_KERNEL:
+ /* Nothing to do. The struct is in the form the kernel expects.
+ We should have short-circuted before we got here, but for
+ completeness... */
+ *(struct kernel_stat *) ubuf = *kbuf;
+ break;
+
+ case _STAT_VER_LINUX:
+ {
+ struct stat *buf = ubuf;
+
+ /* Convert to current kernel version of `struct stat'. */
+ buf->st_dev = kbuf->st_dev;
+ buf->__pad1 = 0;
+ buf->st_ino = kbuf->st_ino;
+ buf->st_mode = kbuf->st_mode;
+ buf->st_nlink = kbuf->st_nlink;
+ buf->st_uid = kbuf->st_uid;
+ buf->st_gid = kbuf->st_gid;
+ buf->st_rdev = kbuf->st_rdev;
+ buf->__pad2 = 0;
+ buf->st_size = kbuf->st_size;
+ buf->st_blksize = kbuf->st_blksize;
+ buf->st_blocks = kbuf->st_blocks;
+ buf->st_atim.tv_sec = kbuf->st_atime_sec;
+ buf->st_atim.tv_nsec = 0;
+ buf->st_mtim.tv_sec = kbuf->st_mtime_sec;
+ buf->st_mtim.tv_nsec = 0;
+ buf->st_ctim.tv_sec = kbuf->st_ctime_sec;
+ buf->st_ctim.tv_nsec = 0;
+ buf->__unused4 = 0;
+ buf->__unused5 = 0;
+ }
+ break;
+
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+__xstat32_conv (int vers, struct stat64 *sbuf, struct stat *buf)
+{
+ struct kernel_stat64 *kbuf;
+
+ /* *stat64 syscalls on sparc64 really fill in struct kernel_stat64,
+ rather than struct stat64. But it is the same size as
+ struct kernel_stat64, so use this hack so that we can reuse
+ i386 {,f,l}xstat{,at}.c routines. */
+ __asm ("" : "=r" (kbuf) : "0" (sbuf));
+ assert (sizeof (struct stat) == sizeof (struct stat64));
+ assert (sizeof (struct stat64) >= sizeof (struct kernel_stat64));
+
+ switch (vers)
+ {
+ case _STAT_VER_LINUX:
+ {
+ /* Convert current kernel version of `struct stat64' to
+ `struct stat'. */
+ buf->st_dev = kbuf->st_dev;
+ buf->__pad1 = 0;
+ buf->st_ino = kbuf->st_ino;
+ buf->st_mode = kbuf->st_mode;
+ buf->st_nlink = kbuf->st_nlink;
+ buf->st_uid = kbuf->st_uid;
+ buf->st_gid = kbuf->st_gid;
+ buf->st_rdev = kbuf->st_rdev;
+ buf->__pad2 = 0;
+ buf->st_size = kbuf->st_size;
+ buf->st_blksize = kbuf->st_blksize;
+ buf->st_blocks = kbuf->st_blocks;
+ buf->st_atim.tv_sec = kbuf->st_atime_sec;
+ buf->st_atim.tv_nsec = kbuf->st_atime_nsec;
+ buf->st_mtim.tv_sec = kbuf->st_mtime_sec;
+ buf->st_mtim.tv_nsec = kbuf->st_mtime_nsec;
+ buf->st_ctim.tv_sec = kbuf->st_ctime_sec;
+ buf->st_ctim.tv_nsec = kbuf->st_ctime_nsec;
+ buf->__unused4 = 0;
+ buf->__unused5 = 0;
+ }
+ break;
+
+ /* If struct stat64 is different from struct stat then
+ _STAT_VER_KERNEL does not make sense. */
+ case _STAT_VER_KERNEL:
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sys/procfs.h b/libc/sysdeps/unix/sysv/linux/sparc/sys/procfs.h
new file mode 100644
index 000000000..2827b1ec3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sys/procfs.h
@@ -0,0 +1,211 @@
+/* Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H 1
+
+/* This is somehow modelled after the file of the same name on SysVr4
+ systems. It provides a definition of the core file format for ELF
+ used on Linux. */
+
+#include <features.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/ucontext.h>
+#include <sys/user.h>
+#include <bits/wordsize.h>
+
+__BEGIN_DECLS
+
+#if __WORDSIZE == 64
+
+#define ELF_NGREG 36
+
+typedef struct
+ {
+ unsigned long pr_regs[32];
+ unsigned long pr_fsr;
+ unsigned long pr_gsr;
+ unsigned long pr_fprs;
+ } elf_fpregset_t;
+
+#else /* sparc32 */
+
+#define ELF_NGREG 38
+
+typedef struct
+ {
+ union
+ {
+ unsigned long pr_regs[32];
+ double pr_dregs[16];
+ } pr_fr;
+ unsigned long __unused;
+ unsigned long pr_fsr;
+ unsigned char pr_qcnt;
+ unsigned char pr_q_entrysize;
+ unsigned char pr_en;
+ unsigned int pr_q[64];
+ } elf_fpregset_t;
+
+#endif /* sparc32 */
+
+typedef unsigned long elf_greg_t;
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+struct elf_siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_code; /* Extra code. */
+ int si_errno; /* Errno. */
+ };
+
+/* Definitions to generate Intel SVR4-like core files. These mostly
+ have the same names as the SVR4 types with "elf_" tacked on the
+ front to prevent clashes with linux definitions, and the typedef
+ forms have been avoided. This is mostly like the SVR4 structure,
+ but more Linuxy, with things that Linux does not support and which
+ gdb doesn't really use excluded. Fields present but not used are
+ marked with "XXX". */
+struct elf_prstatus
+ {
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned long int pr_sigpend; /* Set of pending signals. */
+ unsigned long int pr_sighold; /* Set of held signals. */
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct timeval pr_utime; /* User time. */
+ struct timeval pr_stime; /* System time. */
+ struct timeval pr_cutime; /* Cumulative user time. */
+ struct timeval pr_cstime; /* Cumulative system time. */
+ elf_gregset_t pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+
+#define ELF_PRARGSZ (80) /* Number of chars for args */
+
+struct elf_prpsinfo
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned long int pr_flag; /* Flags. */
+#if __WORDSIZE == 64
+ unsigned int pr_uid;
+ unsigned int pr_gid;
+#else
+ unsigned short int pr_uid;
+ unsigned short int pr_gid;
+#endif
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+/* Addresses. */
+typedef void *psaddr_t;
+
+/* Register sets. Linux has different names. */
+typedef elf_gregset_t prgregset_t;
+typedef elf_fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+ therefore have only one PID type. */
+typedef __pid_t lwpid_t;
+
+
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+#if __WORDSIZE == 64
+
+/* Provide 32-bit variants so that BFD can read 32-bit
+ core files. */
+#define ELF_NGREG32 38
+typedef struct
+ {
+ union
+ {
+ unsigned int pr_regs[32];
+ double pr_dregs[16];
+ } pr_fr;
+ unsigned int __unused;
+ unsigned int pr_fsr;
+ unsigned char pr_qcnt;
+ unsigned char pr_q_entrysize;
+ unsigned char pr_en;
+ unsigned int pr_q[64];
+ } elf_fpregset_t32;
+
+typedef unsigned int elf_greg_t32;
+typedef elf_greg_t32 elf_gregset_t32[ELF_NGREG32];
+
+struct elf_prstatus32
+ {
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned int pr_sigpend; /* Set of pending signals. */
+ unsigned int pr_sighold; /* Set of held signals. */
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct
+ {
+ int tv_sec, tv_usec;
+ } pr_utime, /* User time. */
+ pr_stime, /* System time. */
+ pr_cutime, /* Cumulative user time. */
+ pr_cstime; /* Cumulative system time. */
+ elf_gregset_t32 pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+struct elf_prpsinfo32
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned int pr_flag; /* Flags. */
+ unsigned short int pr_uid;
+ unsigned short int pr_gid;
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+typedef elf_gregset_t32 prgregset32_t;
+typedef elf_fpregset_t32 prfpregset32_t;
+
+typedef struct elf_prstatus32 prstatus32_t;
+typedef struct elf_prpsinfo32 prpsinfo32_t;
+
+#endif /* sparc64 */
+
+__END_DECLS
+
+#endif /* sys/procfs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sys/ptrace.h b/libc/sysdeps/unix/sysv/linux/sparc/sys/ptrace.h
new file mode 100644
index 000000000..d573f0e99
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sys/ptrace.h
@@ -0,0 +1,183 @@
+/* `ptrace' debugger support interface. Linux/SPARC version.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PTRACE_H
+#define _SYS_PTRACE_H 1
+
+#include <features.h>
+
+#include <bits/wordsize.h>
+
+/* Linux/SPARC kernels up to 2.3.18 do not care much
+ about what namespace polution, so use a kludge now. */
+#undef PTRACE_GETREGS
+#undef PTRACE_SETREGS
+#undef PTRACE_GETFPREGS
+#undef PTRACE_SETFPREGS
+#undef PTRACE_READDATA
+#undef PTRACE_WRITEDATA
+#undef PTRACE_READTEXT
+#undef PTRACE_WRITETEXT
+#undef PTRACE_SUNDETACH
+
+__BEGIN_DECLS
+
+/* Type of the REQUEST argument to `ptrace.' */
+enum __ptrace_request
+{
+ /* Indicate that the process making this request should be traced.
+ All signals received by this process can be intercepted by its
+ parent, and its parent can use the other `ptrace' requests. */
+ PTRACE_TRACEME = 0,
+#define PT_TRACE_ME PTRACE_TRACEME
+
+ /* Return the word in the process's text space at address ADDR. */
+ PTRACE_PEEKTEXT = 1,
+#define PT_READ_I PTRACE_PEEKTEXT
+
+ /* Return the word in the process's data space at address ADDR. */
+ PTRACE_PEEKDATA = 2,
+#define PT_READ_D PTRACE_PEEKDATA
+
+ /* Return the word in the process's user area at offset ADDR. */
+ PTRACE_PEEKUSER = 3,
+#define PT_READ_U PTRACE_PEEKUSER
+
+ /* Write the word DATA into the process's text space at address ADDR. */
+ PTRACE_POKETEXT = 4,
+#define PT_WRITE_I PTRACE_POKETEXT
+
+ /* Write the word DATA into the process's data space at address ADDR. */
+ PTRACE_POKEDATA = 5,
+#define PT_WRITE_D PTRACE_POKEDATA
+
+ /* Write the word DATA into the process's user area at offset ADDR. */
+ PTRACE_POKEUSER = 6,
+#define PT_WRITE_U PTRACE_POKEUSER
+
+ /* Continue the process. */
+ PTRACE_CONT = 7,
+#define PT_CONTINUE PTRACE_CONT
+
+ /* Kill the process. */
+ PTRACE_KILL = 8,
+#define PT_KILL PTRACE_KILL
+
+ /* Single step the process.
+ This is not supported on all machines. */
+ PTRACE_SINGLESTEP = 9,
+#define PT_STEP PTRACE_SINGLESTEP
+
+ /* Detach from a process attached to with PTRACE_ATTACH. */
+ PTRACE_DETACH = 11,
+#define PT_DETACH PTRACE_DETACH
+
+ /* This define is needed for older programs which were
+ trying to work around sparc-linux ptrace nastiness. */
+#define PTRACE_SUNDETACH PTRACE_DETACH
+
+#if __WORDSIZE == 32
+
+ /* Get all general purpose registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_GETREGS = 12,
+#define PT_GETREGS PTRACE_GETREGS
+
+ /* Set all general purpose registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_SETREGS = 13,
+#define PT_SETREGS PTRACE_SETREGS
+
+ /* Get all floating point registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_GETFPREGS = 14,
+#define PT_GETFPREGS PTRACE_GETFPREGS
+
+ /* Set all floating point registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_SETFPREGS = 15,
+#define PT_SETFPREGS PTRACE_SETFPREGS
+
+#endif
+
+ /* Attach to a process that is already running. */
+ PTRACE_ATTACH = 16,
+#define PT_ATTACH PTRACE_ATTACH
+
+ /* Write several bytes at a time. */
+ PTRACE_WRITEDATA = 17,
+#define PTRACE_WRITEDATA PTRACE_WRITEDATA
+
+ /* Read several bytes at a time. */
+ PTRACE_READTEXT = 18,
+#define PTRACE_READTEXT PTRACE_READTEXT
+#define PTRACE_READDATA PTRACE_READTEXT
+
+ /* Write several bytes at a time. */
+ PTRACE_WRITETEXT = 19,
+#define PTRACE_WRITETEXT PTRACE_WRITETEXT
+
+#if __WORDSIZE == 64
+
+ /* Get all general purpose registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_GETREGS = 22,
+#define PT_GETREGS PTRACE_GETREGS
+
+ /* Set all general purpose registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_SETREGS = 23,
+#define PT_SETREGS PTRACE_SETREGS
+
+#endif
+
+ /* Continue and stop at the next (return from) syscall. */
+ PTRACE_SYSCALL = 24
+#define PTRACE_SYSCALL PTRACE_SYSCALL
+
+#if __WORDSIZE == 64
+
+ ,
+ /* Get all floating point registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_GETFPREGS = 25,
+#define PT_GETFPREGS PTRACE_GETFPREGS
+
+ /* Set all floating point registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_SETFPREGS = 26
+#define PT_SETFPREGS PTRACE_SETFPREGS
+
+#endif
+};
+
+/* Perform process tracing functions. REQUEST is one of the values
+ above, and determines the action to be taken.
+ For all requests except PTRACE_TRACEME, PID specifies the process to be
+ traced.
+
+ PID and the other arguments described above for the various requests should
+ appear (those that are used for the particular request) as:
+ pid_t PID, void *ADDR, int DATA, void *ADDR2
+ after REQUEST. */
+extern long int ptrace (enum __ptrace_request __request, ...) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_PTRACE_H */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sys/trap.h b/libc/sysdeps/unix/sysv/linux/sparc/sys/trap.h
new file mode 100644
index 000000000..99b9c60e0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sys/trap.h
@@ -0,0 +1,7 @@
+/* Include Linux/SPARC specific trap definitions. */
+#ifndef _SYS_TRAP_H
+#define _SYS_TRAP_H 1
+
+#include <asm/traps.h>
+
+#endif /* sys/trap.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sys/ucontext.h b/libc/sysdeps/unix/sysv/linux/sparc/sys/ucontext.h
new file mode 100644
index 000000000..b1102b04c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sys/ucontext.h
@@ -0,0 +1,270 @@
+/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+
+#include <features.h>
+#include <signal.h>
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+
+#define MC_TSTATE 0
+#define MC_PC 1
+#define MC_NPC 2
+#define MC_Y 3
+#define MC_G1 4
+#define MC_G2 5
+#define MC_G3 6
+#define MC_G4 7
+#define MC_G5 8
+#define MC_G6 9
+#define MC_G7 10
+#define MC_O0 11
+#define MC_O1 12
+#define MC_O2 13
+#define MC_O3 14
+#define MC_O4 15
+#define MC_O5 16
+#define MC_O6 17
+#define MC_O7 18
+#define MC_NGREG 19
+
+typedef unsigned long mc_greg_t;
+typedef mc_greg_t mc_gregset_t[MC_NGREG];
+
+#define MC_MAXFPQ 16
+struct mc_fq {
+ unsigned long *mcfq_addr;
+ unsigned int mcfq_insn;
+};
+
+struct mc_fpu {
+ union {
+ unsigned int sregs[32];
+ unsigned long dregs[32];
+ long double qregs[16];
+ } mcfpu_fregs;
+ unsigned long mcfpu_fsr;
+ unsigned long mcfpu_fprs;
+ unsigned long mcfpu_gsr;
+ struct mc_fq *mcfpu_fq;
+ unsigned char mcfpu_qcnt;
+ unsigned char mcfpu_qentsz;
+ unsigned char mcfpu_enab;
+};
+typedef struct mc_fpu mc_fpu_t;
+
+typedef struct {
+ mc_gregset_t mc_gregs;
+ mc_greg_t mc_fp;
+ mc_greg_t mc_i7;
+ mc_fpu_t mc_fpregs;
+} mcontext_t;
+
+typedef struct ucontext {
+ struct ucontext *uc_link;
+ unsigned long uc_flags;
+ unsigned long __uc_sigmask;
+ mcontext_t uc_mcontext;
+ stack_t uc_stack;
+ __sigset_t uc_sigmask;
+} ucontext_t;
+
+#endif /* __WORDISIZE == 64 */
+
+/*
+ * Location of the users' stored registers relative to R0.
+ * Usage is as an index into a gregset_t array or as u.u_ar0[XX].
+ */
+#define REG_PSR (0)
+#define REG_PC (1)
+#define REG_nPC (2)
+#define REG_Y (3)
+#define REG_G1 (4)
+#define REG_G2 (5)
+#define REG_G3 (6)
+#define REG_G4 (7)
+#define REG_G5 (8)
+#define REG_G6 (9)
+#define REG_G7 (10)
+#define REG_O0 (11)
+#define REG_O1 (12)
+#define REG_O2 (13)
+#define REG_O3 (14)
+#define REG_O4 (15)
+#define REG_O5 (16)
+#define REG_O6 (17)
+#define REG_O7 (18)
+
+/*
+ * A gregset_t is defined as an array type for compatibility with the reference
+ * source. This is important due to differences in the way the C language
+ * treats arrays and structures as parameters.
+ *
+ * Note that NGREG is really (sizeof (struct regs) / sizeof (greg_t)),
+ * but that the ABI defines it absolutely to be 21 (resp. 19).
+ */
+
+#if __WORDSIZE == 64
+
+#define REG_ASI (19)
+#define REG_FPRS (20)
+
+#define NGREG 21
+typedef long greg_t;
+
+#else /* __WORDSIZE == 32 */
+
+#define NGREG 19
+typedef int greg_t;
+
+#endif /* __WORDSIZE == 32 */
+
+typedef greg_t gregset_t[NGREG];
+
+/*
+ * The following structures define how a register window can appear on the
+ * stack. This structure is available (when required) through the `gwins'
+ * field of an mcontext (nested within ucontext). SPARC_MAXWINDOW is the
+ * maximum number of outstanding regiters window defined in the SPARC
+ * architecture (*not* implementation).
+ */
+#define SPARC_MAXREGWINDOW 31 /* max windows in SPARC arch. */
+struct rwindow
+ {
+ greg_t rw_local[8]; /* locals */
+ greg_t rw_in[8]; /* ins */
+ };
+
+#define rw_fp rw_in[6] /* frame pointer */
+#define rw_rtn rw_in[7] /* return address */
+
+typedef struct gwindows
+ {
+ int wbcnt;
+ int *spbuf[SPARC_MAXREGWINDOW];
+ struct rwindow wbuf[SPARC_MAXREGWINDOW];
+ } gwindows_t;
+
+/*
+ * Floating point definitions.
+ */
+
+#define MAXFPQ 16 /* max # of fpu queue entries currently supported */
+
+/*
+ * struct fq defines the minimal format of a floating point instruction queue
+ * entry. The size of entries in the floating point queue are implementation
+ * dependent. The union FQu is guarenteed to be the first field in any ABI
+ * conformant system implementation. Any additional fields provided by an
+ * implementation should not be used applications designed to be ABI conformant. */
+
+struct fpq
+ {
+ unsigned long *fpq_addr; /* address */
+ unsigned long fpq_instr; /* instruction */
+ };
+
+struct fq
+ {
+ union /* FPU inst/addr queue */
+ {
+ double whole;
+ struct fpq fpq;
+ } FQu;
+ };
+
+#define FPU_REGS_TYPE unsigned
+#define FPU_DREGS_TYPE unsigned long long
+#define V7_FPU_FSR_TYPE unsigned
+#define V9_FPU_FSR_TYPE unsigned long long
+#define V9_FPU_FPRS_TYPE unsigned
+
+#if __WORDSIZE == 64
+
+typedef struct fpu
+ {
+ union { /* FPU floating point regs */
+ unsigned fpu_regs[32]; /* 32 singles */
+ double fpu_dregs[16]; /* 32 doubles */
+ long double fpu_qregs[16]; /* 16 quads */
+ } fpu_fr;
+ struct fq *fpu_q; /* ptr to array of FQ entries */
+ unsigned long fpu_fsr; /* FPU status register */
+ unsigned char fpu_qcnt; /* # of entries in saved FQ */
+ unsigned char fpu_q_entrysize; /* # of bytes per FQ entry */
+ unsigned char fpu_en; /* flag signifying fpu in use */
+ } fpregset_t;
+
+#else /* __WORDSIZE == 32 */
+
+typedef struct fpu
+ {
+ union { /* FPU floating point regs */
+ unsigned long long fpu_regs[32]; /* 32 singles */
+ double fpu_dregs[16]; /* 16 doubles */
+ } fpu_fr;
+ struct fq *fpu_q; /* ptr to array of FQ entries */
+ unsigned fpu_fsr; /* FPU status register */
+ unsigned char fpu_qcnt; /* # of entries in saved FQ */
+ unsigned char fpu_q_entrysize; /* # of bytes per FQ entry */
+ unsigned char fpu_en; /* flag signifying fpu in use */
+ } fpregset_t;
+
+/*
+ * The following structure is for associating extra register state with
+ * the ucontext structure and is kept within the uc_mcontext filler area.
+ *
+ * If (xrs_id == XRS_ID) then the xrs_ptr field is a valid pointer to
+ * extra register state. The exact format of the extra register state
+ * pointed to by xrs_ptr is platform-dependent.
+ *
+ * Note: a platform may or may not manage extra register state.
+ */
+typedef struct
+ {
+ unsigned int xrs_id; /* indicates xrs_ptr validity */
+ void * xrs_ptr; /* ptr to extra reg state */
+ } xrs_t;
+
+#define XRS_ID 0x78727300 /* the string "xrs" */
+
+typedef struct
+ {
+ gregset_t gregs; /* general register set */
+ gwindows_t *gwins; /* POSSIBLE pointer to register windows */
+ fpregset_t fpregs; /* floating point register set */
+ xrs_t xrs; /* POSSIBLE extra register state association */
+ long filler[19];
+ } mcontext_t;
+
+
+/* Userlevel context. */
+typedef struct ucontext
+ {
+ unsigned long uc_flags;
+ struct ucontext *uc_link;
+ __sigset_t uc_sigmask;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ } ucontext_t;
+
+#endif /* __WORDSIZE == 32 */
+#endif /* sys/ucontext.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sys/user.h b/libc/sysdeps/unix/sysv/linux/sparc/sys/user.h
new file mode 100644
index 000000000..2aad01b0f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sys/user.h
@@ -0,0 +1,85 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_USER_H
+#define _SYS_USER_H 1
+
+struct sunos_regs
+{
+ unsigned int psr, pc, npc, y;
+ unsigned int regs[15];
+};
+
+struct sunos_fpqueue
+{
+ unsigned int *addr;
+ unsigned int inst;
+};
+
+struct sunos_fp
+{
+ union
+ {
+ unsigned int regs[32];
+ double reg_dbls[16];
+ } fregs;
+ unsigned int fsr;
+ unsigned int flags;
+ unsigned int extra;
+ unsigned int fpq_count;
+ struct sunos_fpqueue fpq[16];
+};
+
+struct sunos_fpu
+{
+ struct sunos_fp fpstatus;
+};
+
+/* The SunOS core file header layout. */
+struct user {
+ unsigned int magic;
+ unsigned int len;
+ struct sunos_regs regs;
+ struct
+ {
+ unsigned char a_dynamic :1;
+ unsigned char a_toolversion :7;
+ unsigned char a_machtype;
+ unsigned short a_info;
+ unsigned int a_text;
+ unsigned int a_data;
+ unsigned int a_bss;
+ unsigned int a_syms;
+ unsigned int a_entry;
+ unsigned int a_trsize;
+ unsigned int a_drsize;
+ } uexec;
+ int signal;
+ size_t u_tsize;
+ size_t u_dsize;
+ size_t u_ssize;
+ char u_comm[17];
+ struct sunos_fpu fpu;
+ unsigned int sigcode;
+};
+
+#define NBPG 0x2000
+#define UPAGES 1
+#define SUNOS_CORE_MAGIC 0x080456
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/syscalls.list b/libc/sysdeps/unix/sysv/linux/sparc/syscalls.list
new file mode 100644
index 000000000..a6665936e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/syscalls.list
@@ -0,0 +1,3 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+waitpid - waitpid Ci:ipi __waitpid waitpid __libc_waitpid
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sysdep.c b/libc/sysdeps/unix/sysv/linux/sparc/sysdep.c
new file mode 100644
index 000000000..f86414570
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sysdep.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/powerpc/sysdep.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/sysdep.h b/libc/sysdeps/unix/sysv/linux/sparc/sysdep.h
new file mode 100644
index 000000000..a60937976
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/sysdep.h
@@ -0,0 +1,153 @@
+/* Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2000.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_SPARC_SYSDEP_H
+#define _LINUX_SPARC_SYSDEP_H 1
+
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...) \
+ inline_syscall##nr(__SYSCALL_STRING, __NR_##name, args)
+
+#undef INTERNAL_SYSCALL_DECL
+#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, err, nr, args...) \
+ inline_syscall##nr(__INTERNAL_SYSCALL_STRING, __NR_##name, args)
+
+#undef INTERNAL_SYSCALL_NCS
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ inline_syscall##nr(__INTERNAL_SYSCALL_STRING, name, args)
+
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+ ((unsigned long) (val) >= -515L)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
+
+#define inline_syscall0(string,name,dummy...) \
+({ \
+ register long __o0 __asm__ ("o0"); \
+ register long __g1 __asm__ ("g1") = name; \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
+ "0" (__g1) : \
+ __SYSCALL_CLOBBERS); \
+ __o0; \
+})
+
+#define inline_syscall1(string,name,arg1) \
+({ \
+ register long __o0 __asm__ ("o0") = (long)(arg1); \
+ register long __g1 __asm__ ("g1") = name; \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
+ "0" (__g1), "1" (__o0) : \
+ __SYSCALL_CLOBBERS); \
+ __o0; \
+})
+
+#define inline_syscall2(string,name,arg1,arg2) \
+({ \
+ register long __o0 __asm__ ("o0") = (long)(arg1); \
+ register long __o1 __asm__ ("o1") = (long)(arg2); \
+ register long __g1 __asm__ ("g1") = name; \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
+ "0" (__g1), "1" (__o0), "r" (__o1) : \
+ __SYSCALL_CLOBBERS); \
+ __o0; \
+})
+
+#define inline_syscall3(string,name,arg1,arg2,arg3) \
+({ \
+ register long __o0 __asm__ ("o0") = (long)(arg1); \
+ register long __o1 __asm__ ("o1") = (long)(arg2); \
+ register long __o2 __asm__ ("o2") = (long)(arg3); \
+ register long __g1 __asm__ ("g1") = name; \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
+ "0" (__g1), "1" (__o0), "r" (__o1), \
+ "r" (__o2) : \
+ __SYSCALL_CLOBBERS); \
+ __o0; \
+})
+
+#define inline_syscall4(string,name,arg1,arg2,arg3,arg4) \
+({ \
+ register long __o0 __asm__ ("o0") = (long)(arg1); \
+ register long __o1 __asm__ ("o1") = (long)(arg2); \
+ register long __o2 __asm__ ("o2") = (long)(arg3); \
+ register long __o3 __asm__ ("o3") = (long)(arg4); \
+ register long __g1 __asm__ ("g1") = name; \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
+ "0" (__g1), "1" (__o0), "r" (__o1), \
+ "r" (__o2), "r" (__o3) : \
+ __SYSCALL_CLOBBERS); \
+ __o0; \
+})
+
+#define inline_syscall5(string,name,arg1,arg2,arg3,arg4,arg5) \
+({ \
+ register long __o0 __asm__ ("o0") = (long)(arg1); \
+ register long __o1 __asm__ ("o1") = (long)(arg2); \
+ register long __o2 __asm__ ("o2") = (long)(arg3); \
+ register long __o3 __asm__ ("o3") = (long)(arg4); \
+ register long __o4 __asm__ ("o4") = (long)(arg5); \
+ register long __g1 __asm__ ("g1") = name; \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
+ "0" (__g1), "1" (__o0), "r" (__o1), \
+ "r" (__o2), "r" (__o3), "r" (__o4) : \
+ __SYSCALL_CLOBBERS); \
+ __o0; \
+})
+
+#define inline_syscall6(string,name,arg1,arg2,arg3,arg4,arg5,arg6) \
+({ \
+ register long __o0 __asm__ ("o0") = (long)(arg1); \
+ register long __o1 __asm__ ("o1") = (long)(arg2); \
+ register long __o2 __asm__ ("o2") = (long)(arg3); \
+ register long __o3 __asm__ ("o3") = (long)(arg4); \
+ register long __o4 __asm__ ("o4") = (long)(arg5); \
+ register long __o5 __asm__ ("o5") = (long)(arg6); \
+ register long __g1 __asm__ ("g1") = name; \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
+ "0" (__g1), "1" (__o0), "r" (__o1), \
+ "r" (__o2), "r" (__o3), "r" (__o4), \
+ "r" (__o5) : \
+ __SYSCALL_CLOBBERS); \
+ __o0; \
+})
+
+#define INLINE_CLONE_SYSCALL(arg1,arg2,arg3,arg4,arg5) \
+({ \
+ register long __o0 __asm__ ("o0") = (long)(arg1); \
+ register long __o1 __asm__ ("o1") = (long)(arg2); \
+ register long __o2 __asm__ ("o2") = (long)(arg3); \
+ register long __o3 __asm__ ("o3") = (long)(arg4); \
+ register long __o4 __asm__ ("o4") = (long)(arg5); \
+ register long __g1 __asm__ ("g1") = __NR_clone; \
+ __asm __volatile (__CLONE_SYSCALL_STRING : \
+ "=r" (__g1), "=r" (__o0), "=r" (__o1) : \
+ "0" (__g1), "1" (__o0), "2" (__o1), \
+ "r" (__o2), "r" (__o3), "r" (__o4) : \
+ __SYSCALL_CLOBBERS); \
+ __o0; \
+})
+
+
+
+#endif /* _LINUX_SPARC_SYSDEP_H */
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/system.c b/libc/sysdeps/unix/sysv/linux/sparc/system.c
new file mode 100644
index 000000000..22bef622d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/system.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <kernel-features.h>
+
+/* We have to and actually can handle cancelable system(). The big
+ problem: we have to kill the child process if necessary. To do
+ this a cleanup handler has to be registered and is has to be able
+ to find the PID of the child. The main problem is to reliable have
+ the PID when needed. It is not necessary for the parent thread to
+ return. It might still be in the kernel when the cancellation
+ request comes. Therefore we have to use the clone() calls ability
+ to have the kernel write the PID into the user-level variable. */
+#ifdef __ASSUME_CLONE_THREAD_FLAGS
+# define FORK() \
+ INLINE_CLONE_SYSCALL (CLONE_PARENT_SETTID | SIGCHLD, 0, &pid, NULL, NULL)
+#endif
+
+#include "../system.c"
diff --git a/libc/sysdeps/unix/sysv/linux/sparc/vfork.S b/libc/sysdeps/unix/sysv/linux/sparc/vfork.S
new file mode 100644
index 000000000..eda860e46
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sparc/vfork.S
@@ -0,0 +1,29 @@
+/* Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jj@ultra.linux.cz>, 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+PSEUDO (__vfork, vfork, 0)
+ sub %o1, 1, %o1
+ retl
+ and %o0, %o1, %o0
+
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+weak_alias (__vfork, vfork)
diff --git a/libc/sysdeps/unix/sysv/linux/speed.c b/libc/sysdeps/unix/sysv/linux/speed.c
new file mode 100644
index 000000000..ba394cb05
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/speed.c
@@ -0,0 +1,111 @@
+/* `struct termios' speed frobnication functions. Linux version.
+ Copyright (C) 1991,1992,1993,1995,1996,1997,1998,2000,2002,2003
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <errno.h>
+#include <termios.h>
+
+
+/* This is a gross hack around a kernel bug. If the cfsetispeed functions
+ is called with the SPEED argument set to zero this means use the same
+ speed as for output. But we don't have independent input and output
+ speeds and therefore cannot record this.
+
+ We use an unused bit in the `c_iflag' field to keep track of this
+ use of `cfsetispeed'. The value here must correspond to the one used
+ in `tcsetattr.c'. */
+#define IBAUD0 020000000000
+
+
+/* Return the output baud rate stored in *TERMIOS_P. */
+speed_t
+cfgetospeed (termios_p)
+ const struct termios *termios_p;
+{
+ return termios_p->c_cflag & (CBAUD | CBAUDEX);
+}
+
+/* Return the input baud rate stored in *TERMIOS_P.
+ Although for Linux there is no difference between input and output
+ speed, the numerical 0 is a special case for the input baud rate. It
+ should set the input baud rate to the output baud rate. */
+speed_t
+cfgetispeed (termios_p)
+ const struct termios *termios_p;
+{
+ return ((termios_p->c_iflag & IBAUD0)
+ ? 0 : termios_p->c_cflag & (CBAUD | CBAUDEX));
+}
+
+/* Set the output baud rate stored in *TERMIOS_P to SPEED. */
+int
+cfsetospeed (termios_p, speed)
+ struct termios *termios_p;
+ speed_t speed;
+{
+ if ((speed & ~CBAUD) != 0
+ && (speed < B57600 || speed > __MAX_BAUD))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+#ifdef _HAVE_STRUCT_TERMIOS_C_OSPEED
+ termios_p->c_ospeed = speed;
+#endif
+ termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
+ termios_p->c_cflag |= speed;
+
+ return 0;
+}
+libc_hidden_def (cfsetospeed)
+
+
+/* Set the input baud rate stored in *TERMIOS_P to SPEED.
+ Although for Linux there is no difference between input and output
+ speed, the numerical 0 is a special case for the input baud rate. It
+ should set the input baud rate to the output baud rate. */
+int
+cfsetispeed (termios_p, speed)
+ struct termios *termios_p;
+ speed_t speed;
+{
+ if ((speed & ~CBAUD) != 0
+ && (speed < B57600 || speed > __MAX_BAUD))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+#ifdef _HAVE_STRUCT_TERMIOS_C_ISPEED
+ termios_p->c_ispeed = speed;
+#endif
+ if (speed == 0)
+ termios_p->c_iflag |= IBAUD0;
+ else
+ {
+ termios_p->c_iflag &= ~IBAUD0;
+ termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
+ termios_p->c_cflag |= speed;
+ }
+
+ return 0;
+}
+libc_hidden_def (cfsetispeed)
diff --git a/libc/sysdeps/unix/sysv/linux/statfs64.c b/libc/sysdeps/unix/sysv/linux/statfs64.c
new file mode 100644
index 000000000..9ccc7a7d6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/statfs64.c
@@ -0,0 +1,74 @@
+/* Return information about the filesystem on which FILE resides.
+ Copyright (C) 1996-2000,2003,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <string.h>
+#include <sys/statfs.h>
+#include <stddef.h>
+#include <sysdep.h>
+
+
+# if __ASSUME_STATFS64 == 0
+int __no_statfs64 attribute_hidden;
+#endif
+
+/* Return information about the filesystem on which FILE resides. */
+int
+__statfs64 (const char *file, struct statfs64 *buf)
+{
+#ifdef __NR_statfs64
+# if __ASSUME_STATFS64 == 0
+ if (! __no_statfs64)
+# endif
+ {
+ int result = INLINE_SYSCALL (statfs64, 3, file, sizeof (*buf), buf);
+
+# if __ASSUME_STATFS64 == 0
+ if (result == 0 || errno != ENOSYS)
+# endif
+ return result;
+
+# if __ASSUME_STATFS64 == 0
+ __no_statfs64 = 1;
+# endif
+ }
+#endif
+
+#if __ASSUME_STATFS64 == 0
+ struct statfs buf32;
+
+ if (__statfs (file, &buf32) < 0)
+ return -1;
+
+ buf->f_type = buf32.f_type;
+ buf->f_bsize = buf32.f_bsize;
+ buf->f_blocks = buf32.f_blocks;
+ buf->f_bfree = buf32.f_bfree;
+ buf->f_bavail = buf32.f_bavail;
+ buf->f_files = buf32.f_files;
+ buf->f_ffree = buf32.f_ffree;
+ buf->f_fsid = buf32.f_fsid;
+ buf->f_namelen = buf32.f_namelen;
+ buf->f_frsize = buf32.f_frsize;
+ memcpy (buf->f_spare, buf32.f_spare, sizeof (buf32.f_spare));
+
+ return 0;
+#endif
+}
+weak_alias (__statfs64, statfs64)
diff --git a/libc/sysdeps/unix/sysv/linux/statvfs.c b/libc/sysdeps/unix/sysv/linux/statvfs.c
new file mode 100644
index 000000000..51d4f4fd0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/statvfs.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 1998, 2000, 2002, 2003 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <sys/stat.h>
+#include <sys/statfs.h>
+#include <sys/statvfs.h>
+
+extern void __internal_statvfs (const char *name, struct statvfs *buf,
+ struct statfs *fsbuf, struct stat64 *st);
+
+
+int
+statvfs (const char *file, struct statvfs *buf)
+{
+ struct statfs fsbuf;
+ struct stat64 st;
+
+ /* Get as much information as possible from the system. */
+ if (__statfs (file, &fsbuf) < 0)
+ return -1;
+
+ /* Convert the result. */
+ __internal_statvfs (file, buf, &fsbuf,
+ stat64 (file, &st) == -1 ? NULL : &st);
+
+ /* We signal success if the statfs call succeeded. */
+ return 0;
+}
+libc_hidden_def (statvfs)
diff --git a/libc/sysdeps/unix/sysv/linux/statvfs64.c b/libc/sysdeps/unix/sysv/linux/statvfs64.c
new file mode 100644
index 000000000..bcef1d3af
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/statvfs64.c
@@ -0,0 +1,74 @@
+/* Return information about the filesystem on which FILE resides.
+ Copyright (C) 1998, 2000, 2001, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/statfs.h>
+#include <sys/statvfs.h>
+#include <kernel-features.h>
+
+
+extern void __internal_statvfs64 (const char *name, struct statvfs64 *buf,
+ struct statfs64 *fsbuf, struct stat64 *st);
+
+
+/* Return information about the filesystem on which FILE resides. */
+int
+__statvfs64 (const char *file, struct statvfs64 *buf)
+{
+ struct statfs64 fsbuf;
+ int res = __statfs64 (file, &fsbuf);
+
+#ifndef __ASSUME_STATFS64
+ if (res < 0 && errno == ENOSYS)
+ {
+ struct statvfs buf32;
+
+ res = statvfs (file, &buf32);
+ if (res == 0)
+ {
+ buf->f_bsize = buf32.f_bsize;
+ buf->f_frsize = buf32.f_frsize;
+ buf->f_blocks = buf32.f_blocks;
+ buf->f_bfree = buf32.f_bfree;
+ buf->f_bavail = buf32.f_bavail;
+ buf->f_files = buf32.f_files;
+ buf->f_ffree = buf32.f_ffree;
+ buf->f_favail = buf32.f_favail;
+ buf->f_fsid = buf32.f_fsid;
+ buf->f_flag = buf32.f_flag;
+ buf->f_namemax = buf32.f_namemax;
+ memcpy (buf->__f_spare, buf32.__f_spare, sizeof (buf32.__f_spare));
+ }
+ }
+#endif
+
+ if (res == 0)
+ {
+ /* Convert the result. */
+ struct stat64 st;
+ __internal_statvfs64 (file, buf, &fsbuf,
+ stat64 (file, &st) == -1 ? NULL : &st);
+ }
+
+ return res;
+}
+weak_alias (__statvfs64, statvfs64)
diff --git a/libc/sysdeps/unix/sysv/linux/symlinkat.c b/libc/sysdeps/unix/sysv/linux/symlinkat.c
new file mode 100644
index 000000000..4cfc924bf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/symlinkat.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysdep.h>
+#include <unistd.h>
+#include <kernel-features.h>
+
+
+/* Make a symbolic link to FROM named TO relative to TOFD. */
+int
+symlinkat (from, tofd, to)
+ const char *from;
+ int tofd;
+ const char *to;
+{
+ int result;
+
+#ifdef __NR_symlinkat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INLINE_SYSCALL (symlinkat, 3, from, tofd, to);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ char *buf = NULL;
+
+ if (tofd != AT_FDCWD && to[0] != '/')
+ {
+ size_t tolen = strlen (to);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + tolen;
+ buf = __alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, tofd, to);
+ to = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+ result = INTERNAL_SYSCALL (symlink, err, 2, from, to);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), tofd, buf);
+ result = -1;
+ }
+
+ return result;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/sync_file_range.c b/libc/sysdeps/unix/sysv/linux/sync_file_range.c
new file mode 100644
index 000000000..7519bb7fe
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sync_file_range.c
@@ -0,0 +1,47 @@
+/* Selective file content synch'ing.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+
+#ifdef __NR_sync_file_range
+int
+sync_file_range (int fd, __off64_t from, __off64_t to, int flags)
+{
+ return INLINE_SYSCALL (sync_file_range, 6, fd,
+ __LONG_LONG_PAIR ((long) (from >> 32), (long) from),
+ __LONG_LONG_PAIR ((long) (to >> 32), (long) to),
+ flags);
+}
+#else
+int
+sync_file_range (int fd, __off64_t from, __off64_t to, int flags)
+{
+ __set_errno (ENOSYS);
+ return -1;
+}
+stub_warning (sync_file_range)
+
+# include <stub-tag.h>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sys/acct.h b/libc/sysdeps/unix/sysv/linux/sys/acct.h
new file mode 100644
index 000000000..9ee8564f7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/acct.h
@@ -0,0 +1,77 @@
+/* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_ACCT_H
+#define _SYS_ACCT_H 1
+
+#include <features.h>
+
+#define __need_time_t
+#include <time.h>
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+#define ACCT_COMM 16
+
+/*
+ comp_t is a 16-bit "floating" point number with a 3-bit base 8
+ exponent and a 13-bit fraction. See linux/kernel/acct.c for the
+ specific encoding system used.
+*/
+
+typedef u_int16_t comp_t;
+
+struct acct
+ {
+ char ac_flag; /* Accounting flags. */
+ u_int16_t ac_uid; /* Accounting user ID. */
+ u_int16_t ac_gid; /* Accounting group ID. */
+ u_int16_t ac_tty; /* Controlling tty. */
+ u_int32_t ac_btime; /* Beginning time. */
+ comp_t ac_utime; /* Accounting user time. */
+ comp_t ac_stime; /* Accounting system time. */
+ comp_t ac_etime; /* Accounting elapsed time. */
+ comp_t ac_mem; /* Accounting average memory usage. */
+ comp_t ac_io; /* Accounting chars transferred. */
+ comp_t ac_rw; /* Accounting blocks read or written. */
+ comp_t ac_minflt; /* Accounting minor pagefaults. */
+ comp_t ac_majflt; /* Accounting major pagefaults. */
+ comp_t ac_swaps; /* Accounting number of swaps. */
+ u_int32_t ac_exitcode; /* Accounting process exitcode. */
+ char ac_comm[ACCT_COMM+1]; /* Accounting command name. */
+ char ac_pad[10]; /* Accounting padding bytes. */
+ };
+
+enum
+ {
+ AFORK = 0x01, /* Has executed fork, but no exec. */
+ ASU = 0x02, /* Used super-user privileges. */
+ ACORE = 0x08, /* Dumped core. */
+ AXSIG = 0x10 /* Killed by a signal. */
+ };
+
+#define AHZ 100
+
+
+/* Switch process accounting on and off. */
+extern int acct (__const char *__filename) __THROW;
+
+__END_DECLS
+
+#endif /* sys/acct.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/epoll.h b/libc/sysdeps/unix/sysv/linux/sys/epoll.h
new file mode 100644
index 000000000..68f173a04
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/epoll.h
@@ -0,0 +1,110 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_EPOLL_H
+#define _SYS_EPOLL_H 1
+
+#include <stdint.h>
+#include <sys/types.h>
+
+
+enum EPOLL_EVENTS
+ {
+ EPOLLIN = 0x001,
+#define EPOLLIN EPOLLIN
+ EPOLLPRI = 0x002,
+#define EPOLLPRI EPOLLPRI
+ EPOLLOUT = 0x004,
+#define EPOLLOUT EPOLLOUT
+ EPOLLRDNORM = 0x040,
+#define EPOLLRDNORM EPOLLRDNORM
+ EPOLLRDBAND = 0x080,
+#define EPOLLRDBAND EPOLLRDBAND
+ EPOLLWRNORM = 0x100,
+#define EPOLLWRNORM EPOLLWRNORM
+ EPOLLWRBAND = 0x200,
+#define EPOLLWRBAND EPOLLWRBAND
+ EPOLLMSG = 0x400,
+#define EPOLLMSG EPOLLMSG
+ EPOLLERR = 0x008,
+#define EPOLLERR EPOLLERR
+ EPOLLHUP = 0x010,
+#define EPOLLHUP EPOLLHUP
+ EPOLLONESHOT = (1 << 30),
+#define EPOLLONESHOT EPOLLONESHOT
+ EPOLLET = (1 << 31)
+#define EPOLLET EPOLLET
+ };
+
+
+/* Valid opcodes ( "op" parameter ) to issue to epoll_ctl(). */
+#define EPOLL_CTL_ADD 1 /* Add a file decriptor to the interface. */
+#define EPOLL_CTL_DEL 2 /* Remove a file decriptor from the interface. */
+#define EPOLL_CTL_MOD 3 /* Change file decriptor epoll_event structure. */
+
+
+typedef union epoll_data
+{
+ void *ptr;
+ int fd;
+ uint32_t u32;
+ uint64_t u64;
+} epoll_data_t;
+
+struct epoll_event
+{
+ uint32_t events; /* Epoll events */
+ epoll_data_t data; /* User data variable */
+};
+
+
+__BEGIN_DECLS
+
+/* Creates an epoll instance. Returns an fd for the new instance.
+ The "size" parameter is a hint specifying the number of file
+ descriptors to be associated with the new instance. The fd
+ returned by epoll_create() should be closed with close(). */
+extern int epoll_create (int __size) __THROW;
+
+
+/* Manipulate an epoll instance "epfd". Returns 0 in case of success,
+ -1 in case of error ( the "errno" variable will contain the
+ specific error code ) The "op" parameter is one of the EPOLL_CTL_*
+ constants defined above. The "fd" parameter is the target of the
+ operation. The "event" parameter describes which events the caller
+ is interested in and any associated user data. */
+extern int epoll_ctl (int __epfd, int __op, int __fd,
+ struct epoll_event *__event) __THROW;
+
+
+/* Wait for events on an epoll instance "epfd". Returns the number of
+ triggered events returned in "events" buffer. Or -1 in case of
+ error with the "errno" variable set to the specific error code. The
+ "events" parameter is a buffer that will contain triggered
+ events. The "maxevents" is the maximum number of events to be
+ returned ( usually size of "events" ). The "timeout" parameter
+ specifies the maximum wait time in milliseconds (-1 == infinite).
+
+ This function is a cancellation point and therefore not marked with
+ __THROW. */
+extern int epoll_wait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout);
+
+__END_DECLS
+
+#endif /* sys/epoll.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/fsuid.h b/libc/sysdeps/unix/sysv/linux/sys/fsuid.h
new file mode 100644
index 000000000..4ecb19918
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/fsuid.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_FSUID_H
+#define _SYS_FSUID_H 1
+
+#include <features.h>
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+/* Change uid used for file access control to UID, without affecting
+ other privileges (such as who can send signals at the process). */
+extern int setfsuid (__uid_t __uid) __THROW;
+
+/* Ditto for group id. */
+extern int setfsgid (__gid_t __gid) __THROW;
+
+__END_DECLS
+
+#endif /* fsuid.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/inotify.h b/libc/sysdeps/unix/sysv/linux/sys/inotify.h
new file mode 100644
index 000000000..0131db9d3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/inotify.h
@@ -0,0 +1,92 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_INOTIFY_H
+#define _SYS_INOTIFY_H 1
+
+#include <stdint.h>
+
+
+/* Structure describing an inotify event. */
+struct inotify_event
+{
+ int wd; /* Watch descriptor. */
+ uint32_t mask; /* Watch mask. */
+ uint32_t cookie; /* Cookie to synchronize two events. */
+ uint32_t len; /* Length (including NULs) of name. */
+ char name __flexarr; /* Name. */
+};
+
+
+/* Supported events suitable for MASK parameter of INOTIFY_ADD_WATCH. */
+#define IN_ACCESS 0x00000001 /* File was accessed. */
+#define IN_MODIFY 0x00000002 /* File was modified. */
+#define IN_ATTRIB 0x00000004 /* Metadata changed. */
+#define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed. */
+#define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed. */
+#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* Close. */
+#define IN_OPEN 0x00000020 /* File was opened. */
+#define IN_MOVED_FROM 0x00000040 /* File was moved from X. */
+#define IN_MOVED_TO 0x00000080 /* File was moved to Y. */
+#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* Moves. */
+#define IN_CREATE 0x00000100 /* Subfile was created. */
+#define IN_DELETE 0x00000200 /* Subfile was deleted. */
+#define IN_DELETE_SELF 0x00000400 /* Self was deleted. */
+#define IN_MOVE_SELF 0x00000800 /* Self was moved. */
+
+/* Events sent by the kernel. */
+#define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted. */
+#define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed. */
+#define IN_IGNORED 0x00008000 /* File was ignored. */
+
+/* Helper events. */
+#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* Close. */
+#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* Moves. */
+
+/* Special flags. */
+#define IN_ONLYDIR 0x01000000 /* Only watch the path if it is a
+ directory. */
+#define IN_DONT_FOLLOW 0x02000000 /* Do not follow a sym link. */
+#define IN_MASK_ADD 0x20000000 /* Add to the mask of an already
+ existing watch. */
+#define IN_ISDIR 0x40000000 /* Event occurred against dir. */
+#define IN_ONESHOT 0x80000000 /* Only send event once. */
+
+/* All events which a program can wait on. */
+#define IN_ALL_EVENTS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE \
+ | IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM \
+ | IN_MOVED_TO | IN_CREATE | IN_DELETE \
+ | IN_DELETE_SELF | IN_MOVE_SELF)
+
+
+__BEGIN_DECLS
+
+/* Create and initialize inotify instance. */
+extern int inotify_init (void) __THROW;
+
+/* Add watch of object NAME to inotify instance FD. Notify about
+ events specified by MASK. */
+extern int inotify_add_watch (int __fd, const char *__name, uint32_t __mask)
+ __THROW;
+
+/* Remove the watch specified by WD from the inotify instance FD. */
+extern int inotify_rm_watch (int __fd, uint32_t __wd) __THROW;
+
+__END_DECLS
+
+#endif /* sys/inotify.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/kd.h b/libc/sysdeps/unix/sysv/linux/sys/kd.h
new file mode 100644
index 000000000..d459c079e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/kd.h
@@ -0,0 +1,35 @@
+/* Copyright (C) 1996, 1997, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_KD_H
+#define _SYS_KD_H 1
+
+/* Make sure the <linux/types.h> header is not loaded. */
+#ifndef _LINUX_TYPES_H
+# define _LINUX_TYPES_H 1
+# define __undef_LINUX_TYPES_H
+#endif
+
+#include <linux/kd.h>
+
+#ifdef __undef_LINUX_TYPES_H
+# undef _LINUX_TYPES_H
+# undef __undef_LINUX_TYPES_H
+#endif
+
+#endif /* sys/kd.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/kdaemon.h b/libc/sysdeps/unix/sysv/linux/sys/kdaemon.h
new file mode 100644
index 000000000..61491f93d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/kdaemon.h
@@ -0,0 +1,33 @@
+/* Copyright (C) 1996, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Interfaces to control the various kernel daemons. */
+
+#ifndef _SYS_KDAEMON_H
+
+#define _SYS_KDAEMON_H 1
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* Start, flush, or tune the kernel's buffer flushing daemon. */
+extern int bdflush (int __func, long int __data) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_KDAEMON_H */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/klog.h b/libc/sysdeps/unix/sysv/linux/sys/klog.h
new file mode 100644
index 000000000..35f5fe40e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/klog.h
@@ -0,0 +1,34 @@
+/* Copyright (C) 1996, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_KLOG_H
+
+#define _SYS_KLOG_H 1
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* Control the kernel's logging facility. This corresponds exactly to
+ the kernel's syslog system call, but that name is easily confused
+ with the user-level syslog facility, which is something completely
+ different. */
+extern int klogctl (int __type, char *__bufp, int __len) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_KLOG_H */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/mount.h b/libc/sysdeps/unix/sysv/linux/sys/mount.h
new file mode 100644
index 000000000..b30554987
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/mount.h
@@ -0,0 +1,119 @@
+/* Header file for mounting/unmount Linux filesystems.
+ Copyright (C) 1996,1997,1998,1999,2000,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This is taken from /usr/include/linux/fs.h. */
+
+#ifndef _SYS_MOUNT_H
+#define _SYS_MOUNT_H 1
+
+#include <features.h>
+#include <sys/ioctl.h>
+
+#define BLOCK_SIZE 1024
+#define BLOCK_SIZE_BITS 10
+
+
+/* These are the fs-independent mount-flags: up to 16 flags are
+ supported */
+enum
+{
+ MS_RDONLY = 1, /* Mount read-only. */
+#define MS_RDONLY MS_RDONLY
+ MS_NOSUID = 2, /* Ignore suid and sgid bits. */
+#define MS_NOSUID MS_NOSUID
+ MS_NODEV = 4, /* Disallow access to device special files. */
+#define MS_NODEV MS_NODEV
+ MS_NOEXEC = 8, /* Disallow program execution. */
+#define MS_NOEXEC MS_NOEXEC
+ MS_SYNCHRONOUS = 16, /* Writes are synced at once. */
+#define MS_SYNCHRONOUS MS_SYNCHRONOUS
+ MS_REMOUNT = 32, /* Alter flags of a mounted FS. */
+#define MS_REMOUNT MS_REMOUNT
+ MS_MANDLOCK = 64, /* Allow mandatory locks on an FS. */
+#define MS_MANDLOCK MS_MANDLOCK
+ S_WRITE = 128, /* Write on file/directory/symlink. */
+#define S_WRITE S_WRITE
+ S_APPEND = 256, /* Append-only file. */
+#define S_APPEND S_APPEND
+ S_IMMUTABLE = 512, /* Immutable file. */
+#define S_IMMUTABLE S_IMMUTABLE
+ MS_NOATIME = 1024, /* Do not update access times. */
+#define MS_NOATIME MS_NOATIME
+ MS_NODIRATIME = 2048, /* Do not update directory access times. */
+#define MS_NODIRATIME MS_NODIRATIME
+ MS_BIND = 4096, /* Bind directory at different place. */
+#define MS_BIND MS_BIND
+};
+
+/* Flags that can be altered by MS_REMOUNT */
+#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME \
+ |MS_NODIRATIME)
+
+
+/* Magic mount flag number. Has to be or-ed to the flag values. */
+
+#define MS_MGC_VAL 0xc0ed0000 /* Magic flag number to indicate "new" flags */
+#define MS_MGC_MSK 0xffff0000 /* Magic flag number mask */
+
+
+/* The read-only stuff doesn't really belong here, but any other place
+ is probably as bad and I don't want to create yet another include
+ file. */
+
+#define BLKROSET _IO(0x12, 93) /* Set device read-only (0 = read-write). */
+#define BLKROGET _IO(0x12, 94) /* Get read-only status (0 = read_write). */
+#define BLKRRPART _IO(0x12, 95) /* Re-read partition table. */
+#define BLKGETSIZE _IO(0x12, 96) /* Return device size. */
+#define BLKFLSBUF _IO(0x12, 97) /* Flush buffer cache. */
+#define BLKRASET _IO(0x12, 98) /* Set read ahead for block device. */
+#define BLKRAGET _IO(0x12, 99) /* Get current read ahead setting. */
+#define BLKFRASET _IO(0x12,100) /* Set filesystem read-ahead. */
+#define BLKFRAGET _IO(0x12,101) /* Get filesystem read-ahead. */
+#define BLKSECTSET _IO(0x12,102) /* Set max sectors per request. */
+#define BLKSECTGET _IO(0x12,103) /* Get max sectors per request. */
+#define BLKSSZGET _IO(0x12,104) /* Get block device sector size. */
+#define BLKBSZGET _IOR(0x12,112,size_t)
+#define BLKBSZSET _IOW(0x12,113,size_t)
+#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size. */
+
+
+/* Possible value for FLAGS parameter of `umount2'. */
+enum
+{
+ MNT_FORCE = 1 /* Force unmounting. */
+#define MNT_FORCE MNT_FORCE
+};
+
+
+__BEGIN_DECLS
+
+/* Mount a filesystem. */
+extern int mount (__const char *__special_file, __const char *__dir,
+ __const char *__fstype, unsigned long int __rwflag,
+ __const void *__data) __THROW;
+
+/* Unmount a filesystem. */
+extern int umount (__const char *__special_file) __THROW;
+
+/* Unmount a filesystem. Force unmounting if FLAGS is set to MNT_FORCE. */
+extern int umount2 (__const char *__special_file, int __flags) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_MOUNT_H */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/param.h b/libc/sysdeps/unix/sysv/linux/sys/param.h
new file mode 100644
index 000000000..0b0424eb9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/param.h
@@ -0,0 +1,72 @@
+/* Copyright (C) 1995,1996,1997,2000,2001,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PARAM_H
+#define _SYS_PARAM_H 1
+
+#include <limits.h>
+#include <linux/limits.h>
+#include <linux/param.h>
+
+/* BSD names for some <limits.h> values. */
+
+#define NBBY CHAR_BIT
+#ifndef NGROUPS
+# define NGROUPS NGROUPS_MAX
+#endif
+#define MAXSYMLINKS 20
+#define CANBSIZ MAX_CANON
+#define NCARGS ARG_MAX
+#define MAXPATHLEN PATH_MAX
+/* The following is not really correct but it is a value we used for a
+ long time and which seems to be usable. People should not use NOFILE
+ anyway. */
+#define NOFILE 256
+
+
+#include <sys/types.h>
+
+/* Bit map related macros. */
+#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
+#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
+#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
+#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
+
+/* Macros for counting and rounding. */
+#ifndef howmany
+# define howmany(x, y) (((x) + ((y) - 1)) / (y))
+#endif
+#ifdef __GNUC__
+# define roundup(x, y) (__builtin_constant_p (y) && powerof2 (y) \
+ ? (((x) + (y) - 1) & ~((y) - 1)) \
+ : ((((x) + ((y) - 1)) / (y)) * (y)))
+#else
+# define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
+#endif
+#define powerof2(x) ((((x) - 1) & (x)) == 0)
+
+/* Macros for min/max. */
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+
+/* Unit of `st_blocks'. */
+#define DEV_BSIZE 512
+
+
+#endif /* sys/param.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/pci.h b/libc/sysdeps/unix/sysv/linux/sys/pci.h
new file mode 100644
index 000000000..fb26269b4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/pci.h
@@ -0,0 +1,25 @@
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PCI_H
+#define _SYS_PCI_H 1
+
+/* We use the constants from the kernel. */
+#include <linux/pci.h>
+
+#endif /* sys/pci.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/personality.h b/libc/sysdeps/unix/sysv/linux/sys/personality.h
new file mode 100644
index 000000000..5d14a9bc8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/personality.h
@@ -0,0 +1,73 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Taken verbatim from Linux 2.4 (include/linux/personality.h). */
+
+#ifndef _SYS_PERSONALITY_H
+#define _SYS_PERSONALITY_H 1
+
+#include <features.h>
+
+/* Flags for bug emulation.
+ These occupy the top three bytes. */
+enum
+ {
+ MMAP_PAGE_ZERO = 0x0100000,
+ ADDR_LIMIT_32BIT = 0x0800000,
+ SHORT_INODE = 0x1000000,
+ WHOLE_SECONDS = 0x2000000,
+ STICKY_TIMEOUTS = 0x4000000,
+ };
+
+/* Personality types.
+
+ These go in the low byte. Avoid using the top bit, it will
+ conflict with error returns. */
+enum
+ {
+ PER_LINUX = 0x0000,
+ PER_LINUX_32BIT = 0x0000 | ADDR_LIMIT_32BIT,
+ PER_SVR4 = 0x0001 | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
+ PER_SVR3 = 0x0002 | STICKY_TIMEOUTS | SHORT_INODE,
+ PER_SCOSVR3 = 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS | SHORT_INODE,
+ PER_OSR5 = 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS,
+ PER_WYSEV386 = 0x0004 | STICKY_TIMEOUTS | SHORT_INODE,
+ PER_ISCR4 = 0x0005 | STICKY_TIMEOUTS,
+ PER_BSD = 0x0006,
+ PER_SUNOS = 0x0006 | STICKY_TIMEOUTS,
+ PER_XENIX = 0x0007 | STICKY_TIMEOUTS | SHORT_INODE,
+ PER_LINUX32 = 0x0008,
+ PER_IRIX32 = 0x0009 | STICKY_TIMEOUTS, /* IRIX5 32-bit */
+ PER_IRIXN32 = 0x000a | STICKY_TIMEOUTS, /* IRIX6 new 32-bit */
+ PER_IRIX64 = 0x000b | STICKY_TIMEOUTS, /* IRIX6 64-bit */
+ PER_RISCOS = 0x000c,
+ PER_SOLARIS = 0x000d | STICKY_TIMEOUTS,
+ PER_UW7 = 0x000e | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
+ PER_HPUX = 0x000f,
+ PER_OSF4 = 0x0010,
+ PER_MASK = 0x00ff,
+ };
+
+__BEGIN_DECLS
+
+/* Set different ABIs (personalities). */
+extern int personality (unsigned long int __persona) __THROW;
+
+__END_DECLS
+
+#endif /* sys/personality.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/prctl.h b/libc/sysdeps/unix/sysv/linux/sys/prctl.h
new file mode 100644
index 000000000..7e9b72d3a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/prctl.h
@@ -0,0 +1,32 @@
+/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PRCTL_H
+#define _SYS_PRCTL_H 1
+
+#include <features.h>
+#include <linux/prctl.h> /* The magic values come from here */
+
+__BEGIN_DECLS
+
+/* Control process execution. */
+extern int prctl (int __option, ...) __THROW;
+
+__END_DECLS
+
+#endif /* sys/prctl.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/procfs.h b/libc/sysdeps/unix/sysv/linux/sys/procfs.h
new file mode 100644
index 000000000..619bb2d06
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/procfs.h
@@ -0,0 +1,115 @@
+/* Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H 1
+
+/* This is somehow modelled after the file of the same name on SysVr4
+ systems. It provides a definition of the core file format for ELF
+ used on Linux. */
+
+#include <features.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/ucontext.h>
+#include <sys/user.h>
+#include <asm/elf.h>
+
+__BEGIN_DECLS
+
+struct elf_siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_code; /* Extra code. */
+ int si_errno; /* Errno. */
+ };
+
+/* Definitions to generate Intel SVR4-like core files. These mostly
+ have the same names as the SVR4 types with "elf_" tacked on the
+ front to prevent clashes with linux definitions, and the typedef
+ forms have been avoided. This is mostly like the SVR4 structure,
+ but more Linuxy, with things that Linux does not support and which
+ gdb doesn't really use excluded. Fields present but not used are
+ marked with "XXX". */
+struct elf_prstatus
+ {
+#if 0
+ long int pr_flags; /* XXX Process flags. */
+ short int pr_why; /* XXX Reason for process halt. */
+ short int pr_what; /* XXX More detailed reason. */
+#endif
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned long int pr_sigpend; /* Set of pending signals. */
+ unsigned long int pr_sighold; /* Set of held signals. */
+#if 0
+ struct sigaltstack pr_altstack; /* Alternate stack info. */
+ struct sigaction pr_action; /* Signal action for current sig. */
+#endif
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct timeval pr_utime; /* User time. */
+ struct timeval pr_stime; /* System time. */
+ struct timeval pr_cutime; /* Cumulative user time. */
+ struct timeval pr_cstime; /* Cumulative system time. */
+#if 0
+ long int pr_instr; /* Current instruction. */
+#endif
+ elf_gregset_t pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+
+#define ELF_PRARGSZ (80) /* Number of chars for args */
+
+struct elf_prpsinfo
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned long int pr_flag; /* Flags. */
+ unsigned short int pr_uid;
+ unsigned short int pr_gid;
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+/* Addresses. */
+typedef void *psaddr_t;
+
+/* Register sets. Linux has different names. */
+typedef gregset_t prgregset_t;
+typedef fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+ therefore habe only ine PID type. */
+typedef __pid_t lwpid_t;
+
+
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+__END_DECLS
+
+#endif /* sys/procfs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/ptrace.h b/libc/sysdeps/unix/sysv/linux/sys/ptrace.h
new file mode 100644
index 000000000..b4aec4f20
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/ptrace.h
@@ -0,0 +1,129 @@
+/* `ptrace' debugger support interface. Linux version.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PTRACE_H
+#define _SYS_PTRACE_H 1
+
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* Type of the REQUEST argument to `ptrace.' */
+enum __ptrace_request
+{
+ /* Indicate that the process making this request should be traced.
+ All signals received by this process can be intercepted by its
+ parent, and its parent can use the other `ptrace' requests. */
+ PTRACE_TRACEME = 0,
+#define PT_TRACE_ME PTRACE_TRACEME
+
+ /* Return the word in the process's text space at address ADDR. */
+ PTRACE_PEEKTEXT = 1,
+#define PT_READ_I PTRACE_PEEKTEXT
+
+ /* Return the word in the process's data space at address ADDR. */
+ PTRACE_PEEKDATA = 2,
+#define PT_READ_D PTRACE_PEEKDATA
+
+ /* Return the word in the process's user area at offset ADDR. */
+ PTRACE_PEEKUSER = 3,
+#define PT_READ_U PTRACE_PEEKUSER
+
+ /* Write the word DATA into the process's text space at address ADDR. */
+ PTRACE_POKETEXT = 4,
+#define PT_WRITE_I PTRACE_POKETEXT
+
+ /* Write the word DATA into the process's data space at address ADDR. */
+ PTRACE_POKEDATA = 5,
+#define PT_WRITE_D PTRACE_POKEDATA
+
+ /* Write the word DATA into the process's user area at offset ADDR. */
+ PTRACE_POKEUSER = 6,
+#define PT_WRITE_U PTRACE_POKEUSER
+
+ /* Continue the process. */
+ PTRACE_CONT = 7,
+#define PT_CONTINUE PTRACE_CONT
+
+ /* Kill the process. */
+ PTRACE_KILL = 8,
+#define PT_KILL PTRACE_KILL
+
+ /* Single step the process.
+ This is not supported on all machines. */
+ PTRACE_SINGLESTEP = 9,
+#define PT_STEP PTRACE_SINGLESTEP
+
+ /* Get all general purpose registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_GETREGS = 12,
+#define PT_GETREGS PTRACE_GETREGS
+
+ /* Set all general purpose registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_SETREGS = 13,
+#define PT_SETREGS PTRACE_SETREGS
+
+ /* Get all floating point registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_GETFPREGS = 14,
+#define PT_GETFPREGS PTRACE_GETFPREGS
+
+ /* Set all floating point registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_SETFPREGS = 15,
+#define PT_SETFPREGS PTRACE_SETFPREGS
+
+ /* Attach to a process that is already running. */
+ PTRACE_ATTACH = 16,
+#define PT_ATTACH PTRACE_ATTACH
+
+ /* Detach from a process attached to with PTRACE_ATTACH. */
+ PTRACE_DETACH = 17,
+#define PT_DETACH PTRACE_DETACH
+
+ /* Get all extended floating point registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_GETFPXREGS = 18,
+#define PT_GETFPXREGS PTRACE_GETFPXREGS
+
+ /* Set all extended floating point registers used by a processes.
+ This is not supported on all machines. */
+ PTRACE_SETFPXREGS = 19,
+#define PT_SETFPXREGS PTRACE_SETFPXREGS
+
+ /* Continue and stop at the next (return from) syscall. */
+ PTRACE_SYSCALL = 24
+#define PT_SYSCALL PTRACE_SYSCALL
+};
+
+/* Perform process tracing functions. REQUEST is one of the values
+ above, and determines the action to be taken.
+ For all requests except PTRACE_TRACEME, PID specifies the process to be
+ traced.
+
+ PID and the other arguments described above for the various requests should
+ appear (those that are used for the particular request) as:
+ pid_t PID, void *ADDR, int DATA, void *ADDR2
+ after REQUEST. */
+extern long int ptrace (enum __ptrace_request __request, ...) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_PTRACE_H */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/quota.h b/libc/sysdeps/unix/sysv/linux/sys/quota.h
new file mode 100644
index 000000000..5aa0ec07d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/quota.h
@@ -0,0 +1,225 @@
+/* This just represents the non-kernel parts of <linux/quota.h>.
+ *
+ * here's the corresponding copyright:
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Robert Elz at The University of Melbourne.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SYS_QUOTA_H
+#define _SYS_QUOTA_H 1
+
+#include <features.h>
+#include <sys/types.h>
+
+/*
+ * Select between different incompatible quota versions.
+ * Default to the version used by Linux kernel version 2.4.22
+ * or later. */
+#ifndef _LINUX_QUOTA_VERSION
+# define _LINUX_QUOTA_VERSION 2
+#endif
+
+/*
+ * Convert diskblocks to blocks and the other way around.
+ * currently only to fool the BSD source. :-)
+ */
+#define dbtob(num) ((num) << 10)
+#define btodb(num) ((num) >> 10)
+
+/*
+ * Convert count of filesystem blocks to diskquota blocks, meant
+ * for filesystems where i_blksize != BLOCK_SIZE
+ */
+#define fs_to_dq_blocks(num, blksize) (((num) * (blksize)) / BLOCK_SIZE)
+
+/*
+ * Definitions for disk quotas imposed on the average user
+ * (big brother finally hits Linux).
+ *
+ * The following constants define the amount of time given a user
+ * before the soft limits are treated as hard limits (usually resulting
+ * in an allocation failure). The timer is started when the user crosses
+ * their soft limit, it is reset when they go below their soft limit.
+ */
+#define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */
+#define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */
+
+#define MAXQUOTAS 2
+#define USRQUOTA 0 /* element used for user quotas */
+#define GRPQUOTA 1 /* element used for group quotas */
+
+/*
+ * Definitions for the default names of the quotas files.
+ */
+#define INITQFNAMES { \
+ "user", /* USRQUOTA */ \
+ "group", /* GRPQUOTA */ \
+ "undefined", \
+};
+
+#define QUOTAFILENAME "quota"
+#define QUOTAGROUP "staff"
+
+#define NR_DQHASH 43 /* Just an arbitrary number any suggestions ? */
+#define NR_DQUOTS 256 /* Number of quotas active at one time */
+
+/*
+ * Command definitions for the 'quotactl' system call.
+ * The commands are broken into a main command defined below
+ * and a subcommand that is used to convey the type of
+ * quota that is being manipulated (see above).
+ */
+#define SUBCMDMASK 0x00ff
+#define SUBCMDSHIFT 8
+#define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
+
+#if _LINUX_QUOTA_VERSION < 2
+# define Q_QUOTAON 0x0100 /* enable quotas */
+# define Q_QUOTAOFF 0x0200 /* disable quotas */
+# define Q_GETQUOTA 0x0300 /* get limits and usage */
+# define Q_SETQUOTA 0x0400 /* set limits and usage */
+# define Q_SETUSE 0x0500 /* set usage */
+# define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */
+# define Q_SETQLIM 0x0700 /* set limits */
+# define Q_GETSTATS 0x0800 /* get collected stats */
+# define Q_RSQUASH 0x1000 /* set root_squash option */
+#else
+# define Q_SYNC 0x800001 /* sync disk copy of a filesystems quotas */
+# define Q_QUOTAON 0x800002 /* turn quotas on */
+# define Q_QUOTAOFF 0x800003 /* turn quotas off */
+# define Q_GETFMT 0x800004 /* get quota format used on given filesystem */
+# define Q_GETINFO 0x800005 /* get information about quota files */
+# define Q_SETINFO 0x800006 /* set information about quota files */
+# define Q_GETQUOTA 0x800007 /* get user quota structure */
+# define Q_SETQUOTA 0x800008 /* set user quota structure */
+#endif
+
+/*
+ * The following structure defines the format of the disk quota file
+ * (as it appears on disk) - the file is an array of these structures
+ * indexed by user or group number.
+ */
+#if _LINUX_QUOTA_VERSION < 2
+struct dqblk
+ {
+ u_int32_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
+ u_int32_t dqb_bsoftlimit; /* preferred limit on disk blks */
+ u_int32_t dqb_curblocks; /* current block count */
+ u_int32_t dqb_ihardlimit; /* maximum # allocated inodes */
+ u_int32_t dqb_isoftlimit; /* preferred inode limit */
+ u_int32_t dqb_curinodes; /* current # allocated inodes */
+ time_t dqb_btime; /* time limit for excessive disk use */
+ time_t dqb_itime; /* time limit for excessive files */
+ };
+#else
+
+/* Flags that indicate which fields in dqblk structure are valid. */
+#define QIF_BLIMITS 1
+#define QIF_SPACE 2
+#define QIF_ILIMITS 4
+#define QIF_INODES 8
+#define QIF_BTIME 16
+#define QIF_ITIME 32
+#define QIF_LIMITS (QIF_BLIMITS | QIF_ILIMITS)
+#define QIF_USAGE (QIF_SPACE | QIF_INODES)
+#define QIF_TIMES (QIF_BTIME | QIF_ITIME)
+#define QIF_ALL (QIF_LIMITS | QIF_USAGE | QIF_TIMES)
+
+struct dqblk
+ {
+ u_int64_t dqb_bhardlimit; /* absolute limit on disk quota blocks alloc */
+ u_int64_t dqb_bsoftlimit; /* preferred limit on disk quota blocks */
+ u_int64_t dqb_curspace; /* current quota block count */
+ u_int64_t dqb_ihardlimit; /* maximum # allocated inodes */
+ u_int64_t dqb_isoftlimit; /* preferred inode limit */
+ u_int64_t dqb_curinodes; /* current # allocated inodes */
+ u_int64_t dqb_btime; /* time limit for excessive disk use */
+ u_int64_t dqb_itime; /* time limit for excessive files */
+ u_int32_t dqb_valid; /* bitmask of QIF_* constants */
+ };
+#endif
+
+/*
+ * Shorthand notation.
+ */
+#define dq_bhardlimit dq_dqb.dqb_bhardlimit
+#define dq_bsoftlimit dq_dqb.dqb_bsoftlimit
+#if _LINUX_QUOTA_VERSION < 2
+# define dq_curblocks dq_dqb.dqb_curblocks
+#else
+# define dq_curspace dq_dqb.dqb_curspace
+# define dq_valid dq_dqb.dqb_valid
+#endif
+#define dq_ihardlimit dq_dqb.dqb_ihardlimit
+#define dq_isoftlimit dq_dqb.dqb_isoftlimit
+#define dq_curinodes dq_dqb.dqb_curinodes
+#define dq_btime dq_dqb.dqb_btime
+#define dq_itime dq_dqb.dqb_itime
+
+#define dqoff(UID) ((loff_t)((UID) * sizeof (struct dqblk)))
+
+#if _LINUX_QUOTA_VERSION < 2
+struct dqstats
+ {
+ u_int32_t lookups;
+ u_int32_t drops;
+ u_int32_t reads;
+ u_int32_t writes;
+ u_int32_t cache_hits;
+ u_int32_t pages_allocated;
+ u_int32_t allocated_dquots;
+ u_int32_t free_dquots;
+ u_int32_t syncs;
+ };
+#else
+
+/* Flags that indicate which fields in dqinfo structure are valid. */
+# define IIF_BGRACE 1
+# define IIF_IGRACE 2
+# define IIF_FLAGS 4
+# define IIF_ALL (IIF_BGRACE | IIF_IGRACE | IIF_FLAGS)
+
+struct dqinfo
+ {
+ u_int64_t dqi_bgrace;
+ u_int64_t dqi_igrace;
+ u_int32_t dqi_flags;
+ u_int32_t dqi_valid;
+ };
+#endif
+
+__BEGIN_DECLS
+
+extern int quotactl (int __cmd, const char *__special, int __id,
+ caddr_t __addr) __THROW;
+
+__END_DECLS
+
+#endif /* sys/quota.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/raw.h b/libc/sysdeps/unix/sysv/linux/sys/raw.h
new file mode 100644
index 000000000..642f78ce5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/raw.h
@@ -0,0 +1,39 @@
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_RAW_H
+#define _SYS_RAW_H 1
+
+#include <stdint.h>
+#include <sys/ioctl.h>
+
+/* The major device number for raw devices. */
+#define RAW_MAJOR 162
+
+/* `ioctl' commands for raw devices. */
+#define RAW_SETBIND _IO(0xac, 0)
+#define RAW_GETBIND _IO(0xac, 1)
+
+struct raw_config_request
+{
+ int raw_minor;
+ uint64_t block_major;
+ uint64_t block_minor;
+};
+
+#endif /* sys/raw.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/reboot.h b/libc/sysdeps/unix/sysv/linux/sys/reboot.h
new file mode 100644
index 000000000..2a719c7a3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/reboot.h
@@ -0,0 +1,49 @@
+/* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This file should define RB_* macros to be used as flag
+ bits in the argument to the `reboot' system call. */
+
+#ifndef _SYS_REBOOT_H
+#define _SYS_REBOOT_H 1
+
+#include <features.h>
+
+/* Perform a hard reset now. */
+#define RB_AUTOBOOT 0x01234567
+
+/* Halt the system. */
+#define RB_HALT_SYSTEM 0xcdef0123
+
+/* Enable reboot using Ctrl-Alt-Delete keystroke. */
+#define RB_ENABLE_CAD 0x89abcdef
+
+/* Disable reboot using Ctrl-Alt-Delete keystroke. */
+#define RB_DISABLE_CAD 0
+
+/* Stop system and switch power off if possible. */
+#define RB_POWER_OFF 0x4321fedc
+
+__BEGIN_DECLS
+
+/* Reboot or halt the system. */
+extern int reboot (int __howto) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_REBOOT_H */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/soundcard.h b/libc/sysdeps/unix/sysv/linux/sys/soundcard.h
new file mode 100644
index 000000000..fade986fe
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/soundcard.h
@@ -0,0 +1 @@
+#include <linux/soundcard.h>
diff --git a/libc/sysdeps/unix/sysv/linux/sys/swap.h b/libc/sysdeps/unix/sysv/linux/sys/swap.h
new file mode 100644
index 000000000..b6e7bef5d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/swap.h
@@ -0,0 +1,43 @@
+/* Calls to enable and disable swapping on specified locations. Linux version.
+ Copyright (C) 1996, 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SWAP_H
+
+#define _SYS_SWAP_H 1
+#include <features.h>
+
+/* The swap priority is encoded as:
+ (prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK
+*/
+#define SWAP_FLAG_PREFER 0x8000 /* Set if swap priority is specified. */
+#define SWAP_FLAG_PRIO_MASK 0x7fff
+#define SWAP_FLAG_PRIO_SHIFT 0
+
+__BEGIN_DECLS
+
+/* Make the block special device PATH available to the system for swapping.
+ This call is restricted to the super-user. */
+extern int swapon (__const char *__path, int __flags) __THROW;
+
+/* Stop using block special device PATH for swapping. */
+extern int swapoff (__const char *__path) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_SWAP_H */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/syscall.h b/libc/sysdeps/unix/sysv/linux/sys/syscall.h
new file mode 100644
index 000000000..445ca3763
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/syscall.h
@@ -0,0 +1,35 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYSCALL_H
+#define _SYSCALL_H 1
+
+/* This file should list the numbers of the system the system knows.
+ But instead of duplicating this we use the information available
+ from the kernel sources. */
+#include <asm/unistd.h>
+
+#ifndef _LIBC
+/* The Linux kernel header file defines macros `__NR_<name>', but some
+ programs expect the traditional form `SYS_<name>'. So in building libc
+ we scan the kernel's list and produce <bits/syscall.h> with macros for
+ all the `SYS_' names. */
+# include <bits/syscall.h>
+#endif
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sys/sysctl.h b/libc/sysdeps/unix/sysv/linux/sys/sysctl.h
new file mode 100644
index 000000000..110efaa76
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/sysctl.h
@@ -0,0 +1,72 @@
+/* Copyright (C) 1996, 1999, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SYSCTL_H
+#define _SYS_SYSCTL_H 1
+
+#include <features.h>
+#define __need_size_t
+#include <stddef.h>
+/* Prevent more kernel headers than necessary to be included. */
+#ifndef _LINUX_KERNEL_H
+# define _LINUX_KERNEL_H 1
+# define __undef_LINUX_KERNEL_H
+#endif
+#ifndef _LINUX_TYPES_H
+# define _LINUX_TYPES_H 1
+# define __undef_LINUX_TYPES_H
+#endif
+#ifndef _LINUX_LIST_H
+# define _LINUX_LIST_H 1
+# define __undef_LINUX_LIST_H
+#endif
+#ifndef __LINUX_COMPILER_H
+# define __LINUX_COMPILER_H 1
+# define __user
+# define __undef__LINUX_COMPILER_H
+#endif
+
+#include <linux/sysctl.h>
+
+#ifdef __undef_LINUX_KERNEL_H
+# undef _LINUX_KERNEL_H
+# undef __undef_LINUX_KERNEL_H
+#endif
+#ifdef __undef_LINUX_TYPES_H
+# undef _LINUX_TYPES_H
+# undef __undef_LINUX_TYPES_H
+#endif
+#ifdef __undef_LINUX_LIST_H
+# undef _LINUX_LIST_H
+# undef __undef_LINUX_LIST_H
+#endif
+#ifdef __undef__LINUX_COMPILER_H
+# undef __LINUX_COMPILER_H
+# undef __user
+# undef __undef__LINUX_COMPILER_H
+#endif
+
+__BEGIN_DECLS
+
+/* Read or write system parameters. */
+extern int sysctl (int *__name, int __nlen, void *__oldval,
+ size_t *__oldlenp, void *__newval, size_t __newlen) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_SYSCTL_H */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/sysinfo.h b/libc/sysdeps/unix/sysv/linux/sys/sysinfo.h
new file mode 100644
index 000000000..a6727b21e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/sysinfo.h
@@ -0,0 +1,48 @@
+/* Copyright (C) 1996, 1999, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SYSINFO_H
+#define _SYS_SYSINFO_H 1
+
+#include <features.h>
+
+/* Get sysinfo structure from kernel header. */
+#include <linux/kernel.h>
+
+__BEGIN_DECLS
+
+/* Returns information on overall system statistics. */
+extern int sysinfo (struct sysinfo *__info) __THROW;
+
+
+/* Return number of configured processors. */
+extern int get_nprocs_conf (void) __THROW;
+
+/* Return number of available processors. */
+extern int get_nprocs (void) __THROW;
+
+
+/* Return number of physical pages of memory in the system. */
+extern long int get_phys_pages (void) __THROW;
+
+/* Return number of available physical pages of memory in the system. */
+extern long int get_avphys_pages (void) __THROW;
+
+__END_DECLS
+
+#endif /* sys/sysinfo.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/sysmacros.h b/libc/sysdeps/unix/sysv/linux/sys/sysmacros.h
new file mode 100644
index 000000000..179642ff4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/sysmacros.h
@@ -0,0 +1,69 @@
+/* Definitions of macros to access `dev_t' values.
+ Copyright (C) 1996, 1997, 1999, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SYSMACROS_H
+#define _SYS_SYSMACROS_H 1
+
+#include <features.h>
+
+/* If the compiler does not know long long it is out of luck. We are
+ not going to hack weird hacks to support the dev_t representation
+ they need. */
+#ifdef __GLIBC_HAVE_LONG_LONG
+__extension__
+extern __inline unsigned int gnu_dev_major (unsigned long long int __dev)
+ __THROW;
+__extension__
+extern __inline unsigned int gnu_dev_minor (unsigned long long int __dev)
+ __THROW;
+__extension__
+extern __inline unsigned long long int gnu_dev_makedev (unsigned int __major,
+ unsigned int __minor)
+ __THROW;
+
+# if defined __GNUC__ && __GNUC__ >= 2
+__extension__ extern __inline unsigned int
+__NTH (gnu_dev_major (unsigned long long int __dev))
+{
+ return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
+}
+
+__extension__ extern __inline unsigned int
+__NTH (gnu_dev_minor (unsigned long long int __dev))
+{
+ return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);
+}
+
+__extension__ extern __inline unsigned long long int
+__NTH (gnu_dev_makedev (unsigned int __major, unsigned int __minor))
+{
+ return ((__minor & 0xff) | ((__major & 0xfff) << 8)
+ | (((unsigned long long int) (__minor & ~0xff)) << 12)
+ | (((unsigned long long int) (__major & ~0xfff)) << 32));
+}
+# endif
+
+
+/* Access the functions with their traditional names. */
+# define major(dev) gnu_dev_major (dev)
+# define minor(dev) gnu_dev_minor (dev)
+# define makedev(maj, min) gnu_dev_makedev (maj, min)
+#endif
+
+#endif /* sys/sysmacros.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/timex.h b/libc/sysdeps/unix/sysv/linux/sys/timex.h
new file mode 100644
index 000000000..773a5ab8d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/timex.h
@@ -0,0 +1,127 @@
+/* Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_TIMEX_H
+#define _SYS_TIMEX_H 1
+
+#include <features.h>
+#include <sys/time.h>
+
+/* These definitions from linux/timex.h as of 2.2.0. */
+
+struct ntptimeval
+{
+ struct timeval time; /* current time (ro) */
+ long int maxerror; /* maximum error (us) (ro) */
+ long int esterror; /* estimated error (us) (ro) */
+};
+
+struct timex
+{
+ unsigned int modes; /* mode selector */
+ long int offset; /* time offset (usec) */
+ long int freq; /* frequency offset (scaled ppm) */
+ long int maxerror; /* maximum error (usec) */
+ long int esterror; /* estimated error (usec) */
+ int status; /* clock command/status */
+ long int constant; /* pll time constant */
+ long int precision; /* clock precision (usec) (read only) */
+ long int tolerance; /* clock frequency tolerance (ppm) (read only) */
+ struct timeval time; /* (read only) */
+ long int tick; /* (modified) usecs between clock ticks */
+
+ long int ppsfreq; /* pps frequency (scaled ppm) (ro) */
+ long int jitter; /* pps jitter (us) (ro) */
+ int shift; /* interval duration (s) (shift) (ro) */
+ long int stabil; /* pps stability (scaled ppm) (ro) */
+ long int jitcnt; /* jitter limit exceeded (ro) */
+ long int calcnt; /* calibration intervals (ro) */
+ long int errcnt; /* calibration errors (ro) */
+ long int stbcnt; /* stability limit exceeded (ro) */
+
+ /* ??? */
+ int :32; int :32; int :32; int :32;
+ int :32; int :32; int :32; int :32;
+ int :32; int :32; int :32; int :32;
+};
+
+/* Mode codes (timex.mode) */
+#define ADJ_OFFSET 0x0001 /* time offset */
+#define ADJ_FREQUENCY 0x0002 /* frequency offset */
+#define ADJ_MAXERROR 0x0004 /* maximum time error */
+#define ADJ_ESTERROR 0x0008 /* estimated time error */
+#define ADJ_STATUS 0x0010 /* clock status */
+#define ADJ_TIMECONST 0x0020 /* pll time constant */
+#define ADJ_TICK 0x4000 /* tick value */
+#define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */
+
+/* xntp 3.4 compatibility names */
+#define MOD_OFFSET ADJ_OFFSET
+#define MOD_FREQUENCY ADJ_FREQUENCY
+#define MOD_MAXERROR ADJ_MAXERROR
+#define MOD_ESTERROR ADJ_ESTERROR
+#define MOD_STATUS ADJ_STATUS
+#define MOD_TIMECONST ADJ_TIMECONST
+#define MOD_CLKB ADJ_TICK
+#define MOD_CLKA ADJ_OFFSET_SINGLESHOT /* 0x8000 in original */
+
+
+/* Status codes (timex.status) */
+#define STA_PLL 0x0001 /* enable PLL updates (rw) */
+#define STA_PPSFREQ 0x0002 /* enable PPS freq discipline (rw) */
+#define STA_PPSTIME 0x0004 /* enable PPS time discipline (rw) */
+#define STA_FLL 0x0008 /* select frequency-lock mode (rw) */
+
+#define STA_INS 0x0010 /* insert leap (rw) */
+#define STA_DEL 0x0020 /* delete leap (rw) */
+#define STA_UNSYNC 0x0040 /* clock unsynchronized (rw) */
+#define STA_FREQHOLD 0x0080 /* hold frequency (rw) */
+
+#define STA_PPSSIGNAL 0x0100 /* PPS signal present (ro) */
+#define STA_PPSJITTER 0x0200 /* PPS signal jitter exceeded (ro) */
+#define STA_PPSWANDER 0x0400 /* PPS signal wander exceeded (ro) */
+#define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */
+
+#define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */
+
+#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \
+ STA_PPSERROR | STA_CLOCKERR) /* read-only bits */
+
+/* Clock states (time_state) */
+#define TIME_OK 0 /* clock synchronized, no leap second */
+#define TIME_INS 1 /* insert leap second */
+#define TIME_DEL 2 /* delete leap second */
+#define TIME_OOP 3 /* leap second in progress */
+#define TIME_WAIT 4 /* leap second has occurred */
+#define TIME_ERROR 5 /* clock not synchronized */
+#define TIME_BAD TIME_ERROR /* bw compat */
+
+/* Maximum time constant of the PLL. */
+#define MAXTC 6
+
+__BEGIN_DECLS
+
+extern int __adjtimex (struct timex *__ntx) __THROW;
+extern int adjtimex (struct timex *__ntx) __THROW;
+
+extern int ntp_gettime (struct ntptimeval *__ntv) __THROW;
+extern int ntp_adjtime (struct timex *__tntx) __THROW;
+
+__END_DECLS
+
+#endif /* sys/timex.h */
diff --git a/libc/sysdeps/unix/sysv/linux/sys/ttydefaults.h b/libc/sysdeps/unix/sysv/linux/sys/ttydefaults.h
new file mode 100644
index 000000000..9be168b83
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/ttydefaults.h
@@ -0,0 +1,100 @@
+/*-
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ttydefaults.h 8.4 (Berkeley) 1/21/94
+ */
+
+/*
+ * System wide defaults for terminal state. Linux version.
+ */
+#ifndef _SYS_TTYDEFAULTS_H_
+#define _SYS_TTYDEFAULTS_H_
+
+/*
+ * Defaults on "first" open.
+ */
+#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY)
+#define TTYDEF_OFLAG (OPOST | ONLCR | XTABS)
+#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL)
+#define TTYDEF_CFLAG (CREAD | CS7 | PARENB | HUPCL)
+#define TTYDEF_SPEED (B9600)
+
+/*
+ * Control Character Defaults
+ */
+#define CTRL(x) (x&037)
+#define CEOF CTRL('d')
+#ifdef _POSIX_VDISABLE
+# define CEOL _POSIX_VDISABLE
+#else
+# define CEOL '\0' /* XXX avoid _POSIX_VDISABLE */
+#endif
+#define CERASE 0177
+#define CINTR CTRL('c')
+#ifdef _POSIX_VDISABLE
+# define CSTATUS _POSIX_VDISABLE
+#else
+# define CSTATUS '\0' /* XXX avoid _POSIX_VDISABLE */
+#endif
+#define CKILL CTRL('u')
+#define CMIN 1
+#define CQUIT 034 /* FS, ^\ */
+#define CSUSP CTRL('z')
+#define CTIME 0
+#define CDSUSP CTRL('y')
+#define CSTART CTRL('q')
+#define CSTOP CTRL('s')
+#define CLNEXT CTRL('v')
+#define CDISCARD CTRL('o')
+#define CWERASE CTRL('w')
+#define CREPRINT CTRL('r')
+#define CEOT CEOF
+/* compat */
+#define CBRK CEOL
+#define CRPRNT CREPRINT
+#define CFLUSH CDISCARD
+
+/* PROTECTED INCLUSION ENDS HERE */
+#endif /* !_SYS_TTYDEFAULTS_H_ */
+
+/*
+ * #define TTYDEFCHARS to include an array of default control characters.
+ */
+#ifdef TTYDEFCHARS
+cc_t ttydefchars[NCCS] = {
+ CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT,
+ _POSIX_VDISABLE, CINTR, CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT,
+ CDISCARD, CMIN, CTIME, CSTATUS, _POSIX_VDISABLE
+};
+#undef TTYDEFCHARS
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/sys/ultrasound.h b/libc/sysdeps/unix/sysv/linux/sys/ultrasound.h
new file mode 100644
index 000000000..a65c385bc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/ultrasound.h
@@ -0,0 +1 @@
+#include <linux/ultrasound.h>
diff --git a/libc/sysdeps/unix/sysv/linux/sys/user.h b/libc/sysdeps/unix/sysv/linux/sys/user.h
new file mode 100644
index 000000000..30e9b57ab
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/user.h
@@ -0,0 +1 @@
+#include <linux/user.h>
diff --git a/libc/sysdeps/unix/sysv/linux/sys/vt.h b/libc/sysdeps/unix/sysv/linux/sys/vt.h
new file mode 100644
index 000000000..834abfbc8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sys/vt.h
@@ -0,0 +1 @@
+#include <linux/vt.h>
diff --git a/libc/sysdeps/unix/sysv/linux/syscalls.list b/libc/sysdeps/unix/sysv/linux/syscalls.list
new file mode 100644
index 000000000..afb6d8097
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/syscalls.list
@@ -0,0 +1,97 @@
+# File name Caller Syscall name Args Strong name Weak names
+
+adjtimex adjtime adjtimex i:p __adjtimex adjtimex ntp_adjtime __adjtimex_internal
+bdflush EXTRA bdflush i:ii bdflush
+capget EXTRA capget i:pp capget
+capset EXTRA capset i:pp capset
+creat - creat Ci:si __libc_creat creat
+create_module EXTRA create_module 3 create_module
+delete_module EXTRA delete_module 3 delete_module
+epoll_create EXTRA epoll_create i:i epoll_create
+epoll_ctl EXTRA epoll_ctl i:iiip epoll_ctl
+epoll_wait EXTRA epoll_wait Ci:ipii epoll_wait
+fdatasync - fdatasync i:i fdatasync
+flock - flock i:ii __flock flock
+fork - fork i: __libc_fork __fork fork
+get_kernel_syms EXTRA get_kernel_syms i:p get_kernel_syms
+getegid - getegid Ei: __getegid getegid
+geteuid - geteuid Ei: __geteuid geteuid
+getpgid - getpgid i:i __getpgid getpgid
+getpgrp - getpgrp Ei: getpgrp
+getpmsg - getpmsg i:ipppp getpmsg
+getppid - getppid Ei: __getppid getppid
+getresuid - getresuid i:ppp getresuid
+getresgid - getresgid i:ppp getresgid
+getsid - getsid i:i getsid
+init_module EXTRA init_module 5 init_module
+inotify_add_watch EXTRA inotify_add_watch i:isi inotify_add_watch
+inotify_init EXTRA inotify_init i: inotify_init
+inotify_rm_watch EXTRA inotify_rm_watch i:ii inotify_rm_watch
+ioperm - ioperm i:iii ioperm
+iopl - iopl i:i iopl
+klogctl EXTRA syslog i:isi klogctl
+lchown - lchown i:sii __lchown lchown
+posix_madvise - madvise Vi:pii posix_madvise
+madvise - madvise i:pii madvise
+mincore - mincore i:anV mincore
+mlock - mlock i:bn mlock
+mlockall - mlockall i:i mlockall
+mmap - mmap b:aniiii __mmap mmap
+mount EXTRA mount i:sssip __mount mount
+mremap EXTRA mremap b:ainip __mremap mremap
+munlock - munlock i:ai munlock
+munlockall - munlockall i: munlockall
+nanosleep - nanosleep Ci:pp __libc_nanosleep __nanosleep nanosleep
+nfsservctl EXTRA nfsservctl i:ipp nfsservctl
+pause - pause Ci: __libc_pause pause
+personality init-first personality i:i __personality personality
+pipe - pipe i:f __pipe pipe
+pivot_root EXTRA pivot_root i:ss pivot_root
+prctl EXTRA prctl i:iiiii __prctl prctl
+putpmsg - putpmsg i:ippii putpmsg
+query_module EXTRA query_module i:sipip query_module
+quotactl EXTRA quotactl i:isip quotactl
+remap_file_pages - remap_file_pages i:piiii __remap_file_pages remap_file_pages
+sched_getp - sched_getparam i:ip __sched_getparam sched_getparam
+sched_gets - sched_getscheduler i:i __sched_getscheduler sched_getscheduler
+sched_primax - sched_get_priority_max i:i __sched_get_priority_max sched_get_priority_max
+sched_primin - sched_get_priority_min i:i __sched_get_priority_min sched_get_priority_min
+sched_rr_gi - sched_rr_get_interval i:ip __sched_rr_get_interval sched_rr_get_interval
+sched_setp - sched_setparam i:ip __sched_setparam sched_setparam
+sched_sets - sched_setscheduler i:iip __sched_setscheduler sched_setscheduler
+sched_yield - sched_yield i: __sched_yield sched_yield
+select - _newselect Ci:iPPPP __select __libc_select select
+sendfile - sendfile i:iipi sendfile
+sendfile64 - sendfile64 i:iipi sendfile64
+setfsgid EXTRA setfsgid i:i setfsgid
+setfsuid EXTRA setfsuid i:i setfsuid
+setpgid - setpgid i:ii __setpgid setpgid
+sigaltstack - sigaltstack i:PP __sigaltstack sigaltstack
+splice EXTRA splice i:iiii splice
+sysinfo EXTRA sysinfo i:p sysinfo
+swapon - swapon i:si __swapon swapon
+swapoff - swapoff i:s __swapoff swapoff
+tee EXTRA tee i:iiii tee
+unshare EXTRA unshare i:i unshare
+uselib EXTRA uselib i:s uselib
+vmsplice EXTRA vmsplice i:iPii vmsplice
+wait4 - wait4 i:iWiP __wait4 wait4
+
+chown - chown i:sii __libc_chown __chown chown
+
+setxattr - setxattr i:sspii setxattr
+lsetxattr - lsetxattr i:sspii lsetxattr
+fsetxattr - fsetxattr i:ispii fsetxattr
+getxattr - getxattr i:sspi getxattr
+lgetxattr - lgetxattr i:sspi lgetxattr
+fgetxattr - fgetxattr i:ispi fgetxattr
+listxattr - listxattr i:ssi listxattr
+llistxattr - llistxattr i:ssi llistxattr
+flistxattr - flistxattr i:isi flistxattr
+removexattr - removexattr i:ss removexattr
+lremovexattr - lremovexattr i:ss lremovexattr
+fremovexattr - fremovexattr i:is fremovexattr
+
+mq_timedsend - mq_timedsend Ci:ipiip __GI_mq_timedsend mq_timedsend
+mq_timedreceive - mq_timedreceive Ci:ipipp __GI_mq_timedreceive mq_timedreceive
+mq_setattr - mq_getsetattr i:ipp __GI_mq_setattr mq_setattr
diff --git a/libc/sysdeps/unix/sysv/linux/sysconf.c b/libc/sysdeps/unix/sysv/linux/sysconf.c
new file mode 100644
index 000000000..f9f6f1bfa
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sysconf.c
@@ -0,0 +1,118 @@
+/* Get file-specific information about a file. Linux version.
+ Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <sysdep.h>
+#include <time.h>
+#include <unistd.h>
+#include <not-cancel.h>
+
+static long int posix_sysconf (int name);
+
+
+/* Get the value of the system variable NAME. */
+long int
+__sysconf (int name)
+{
+ const char *procfname = NULL;
+
+ switch (name)
+ {
+#ifdef __NR_clock_getres
+ case _SC_MONOTONIC_CLOCK:
+ /* Check using the clock_getres system call. */
+ {
+ struct timespec ts;
+ INTERNAL_SYSCALL_DECL (err);
+ int r;
+ r = INTERNAL_SYSCALL (clock_getres, err, 2, CLOCK_MONOTONIC, &ts);
+ return INTERNAL_SYSCALL_ERROR_P (r, err) ? -1 : _POSIX_VERSION;
+ }
+#endif
+
+#if defined __NR_clock_getres || HP_TIMING_AVAIL
+ case _SC_CPUTIME:
+ case _SC_THREAD_CPUTIME:
+ {
+ /* If we have HP_TIMING, we will fall back on that if the system
+ call does not work, so we support it either way. */
+# if !HP_TIMING_AVAIL
+ /* Check using the clock_getres system call. */
+ struct timespec ts;
+ INTERNAL_SYSCALL_DECL (err);
+ int r = INTERNAL_SYSCALL (clock_getres, err, 2,
+ (name == _SC_CPUTIME
+ ? CLOCK_PROCESS_CPUTIME_ID
+ : CLOCK_THREAD_CPUTIME_ID),
+ &ts);
+ if (INTERNAL_SYSCALL_ERROR_P (r, err))
+ return -1;
+# endif
+ return _POSIX_VERSION;
+ }
+#endif
+
+ case _SC_NGROUPS_MAX:
+ /* Try to read the information from the /proc/sys/kernel/ngroups_max
+ file. */
+ procfname = "/proc/sys/kernel/ngroups_max";
+ break;
+
+ case _SC_SIGQUEUE_MAX:
+ /* The /proc/sys/kernel/rtsig-max file contains the answer. */
+ procfname = "/proc/sys/kernel/rtsig-max";
+ break;
+
+ default:
+ break;
+ }
+
+ if (procfname != NULL)
+ {
+ int fd = open_not_cancel_2 (procfname, O_RDONLY);
+ if (fd != -1)
+ {
+ /* This is more than enough, the file contains a single integer. */
+ char buf[32];
+ ssize_t n;
+ n = TEMP_FAILURE_RETRY (read_not_cancel (fd, buf, sizeof (buf) - 1));
+ close_not_cancel_no_status (fd);
+
+ if (n > 0)
+ {
+ /* Terminate the string. */
+ buf[n] = '\0';
+
+ char *endp;
+ long int res = strtol (buf, &endp, 10);
+ if (endp != buf && (*endp == '\0' || *endp == '\n'))
+ return res;
+ }
+ }
+ }
+
+ return posix_sysconf (name);
+}
+
+/* Now the POSIX version. */
+#undef __sysconf
+#define __sysconf static posix_sysconf
+#include <sysdeps/posix/sysconf.c>
diff --git a/libc/sysdeps/unix/sysv/linux/sysctl.c b/libc/sysdeps/unix/sysv/linux/sysctl.c
new file mode 100644
index 000000000..637fca596
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/sysctl.c
@@ -0,0 +1,49 @@
+/* Read or write system information. Linux version.
+ Copyright (C) 1996-2000,2002,2003,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <string.h> /* For the real memset prototype. */
+#include <sys/sysctl.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+int
+__sysctl (int *name, int nlen, void *oldval, size_t *oldlenp,
+ void *newval, size_t newlen)
+{
+ /* GKM FIXME: force __sysctl_args decl to have unbounded pointers. */
+ struct __sysctl_args args =
+ {
+ .name = name,
+ .nlen = nlen,
+ .oldval = oldval,
+ .oldlenp = oldlenp,
+ .newval = newval,
+ .newlen = newlen
+ };
+ (void) CHECK_N (name, nlen);
+ (void) CHECK_N (oldval, *oldlenp);
+ (void) CHECK_N (newval, newlen);
+
+ return INLINE_SYSCALL (_sysctl, 1, __ptrvalue (&args));
+}
+libc_hidden_def (__sysctl)
+weak_alias (__sysctl, sysctl)
diff --git a/libc/sysdeps/unix/sysv/linux/syslog.c b/libc/sysdeps/unix/sysv/linux/syslog.c
new file mode 100644
index 000000000..145e22b52
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/syslog.c
@@ -0,0 +1,10 @@
+#include <kernel-features.h>
+
+#if __ASSUME_MSG_NOSIGNAL
+# define NO_SIGPIPE
+# define send_flags MSG_NOSIGNAL
+#else
+# define send_flags 0
+#endif
+
+#include <misc/syslog.c>
diff --git a/libc/sysdeps/unix/sysv/linux/system.c b/libc/sysdeps/unix/sysv/linux/system.c
new file mode 100644
index 000000000..c5b389ea2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/system.c
@@ -0,0 +1,78 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sched.h>
+#include <signal.h>
+#include <string.h> /* For the real memset prototype. */
+#include <sysdep.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <bits/libc-lock.h>
+#include <kernel-features.h>
+
+/* We have to and actually can handle cancelable system(). The big
+ problem: we have to kill the child process if necessary. To do
+ this a cleanup handler has to be registered and is has to be able
+ to find the PID of the child. The main problem is to reliable have
+ the PID when needed. It is not necessary for the parent thread to
+ return. It might still be in the kernel when the cancellation
+ request comes. Therefore we have to use the clone() calls ability
+ to have the kernel write the PID into the user-level variable. */
+#if defined __ASSUME_CLONE_THREAD_FLAGS && !defined FORK
+# define FORK() \
+ INLINE_SYSCALL (clone, 3, CLONE_PARENT_SETTID | SIGCHLD, 0, &pid)
+#endif
+
+#ifdef _LIBC_REENTRANT
+static void cancel_handler (void *arg);
+
+# define CLEANUP_HANDLER \
+ __libc_cleanup_region_start (1, cancel_handler, &pid)
+
+# define CLEANUP_RESET \
+ __libc_cleanup_region_end (0)
+#endif
+
+
+/* Linux has waitpid(), so override the generic unix version. */
+#include <sysdeps/posix/system.c>
+
+
+#ifdef _LIBC_REENTRANT
+/* The cancellation handler. */
+static void
+cancel_handler (void *arg)
+{
+ pid_t child = *(pid_t *) arg;
+
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (kill, err, 2, child, SIGKILL);
+
+ TEMP_FAILURE_RETRY (__waitpid (child, NULL, 0));
+
+ DO_LOCK ();
+
+ if (SUB_REF () == 0)
+ {
+ (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
+ (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
+ }
+
+ DO_UNLOCK ();
+}
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/tcdrain.c b/libc/sysdeps/unix/sysv/linux/tcdrain.c
new file mode 100644
index 000000000..4868565ed
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/tcdrain.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <sysdep-cancel.h>
+
+/* Wait for pending output to be written on FD. */
+int
+__libc_tcdrain (int fd)
+{
+ if (SINGLE_THREAD_P)
+ /* With an argument of 1, TCSBRK for output to be drain. */
+ return INLINE_SYSCALL (ioctl, 3, fd, TCSBRK, 1);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* With an argument of 1, TCSBRK for output to be drain. */
+ int result = INLINE_SYSCALL (ioctl, 3, fd, TCSBRK, 1);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+weak_alias (__libc_tcdrain, tcdrain)
diff --git a/libc/sysdeps/unix/sysv/linux/tcflow.c b/libc/sysdeps/unix/sysv/linux/tcflow.c
new file mode 100644
index 000000000..6e7237027
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/tcflow.c
@@ -0,0 +1,31 @@
+/* tcflow -- Suspend or restart transmission on termios file descriptor.
+ Copyright (C) 1993,1997,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+
+/* Suspend or restart transmission on FD. */
+int
+tcflow (fd, action)
+ int fd;
+ int action;
+{
+ return __ioctl (fd, TCXONC, action);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/tcflush.c b/libc/sysdeps/unix/sysv/linux/tcflush.c
new file mode 100644
index 000000000..cae419f4a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/tcflush.c
@@ -0,0 +1,31 @@
+/* tcflush -- Flush pending data on termios file descriptor. Linux version.
+ Copyright (C) 1993,1997,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+
+/* Flush pending data on FD. */
+int
+tcflush (fd, queue_selector)
+ int fd;
+ int queue_selector;
+{
+ return __ioctl (fd, TCFLSH, queue_selector);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/tcgetattr.c b/libc/sysdeps/unix/sysv/linux/tcgetattr.c
new file mode 100644
index 000000000..28e3e535b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/tcgetattr.c
@@ -0,0 +1,82 @@
+/* Copyright (C) 1992,1995,1997,1998,2003,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sysdep.h>
+
+/* The difference here is that the termios structure used in the
+ kernel is not the same as we use in the libc. Therefore we must
+ translate it here. */
+#include <kernel_termios.h>
+
+/* Put the state of FD into *TERMIOS_P. */
+int
+__tcgetattr (fd, termios_p)
+ int fd;
+ struct termios *termios_p;
+{
+ struct __kernel_termios k_termios;
+ int retval;
+
+ retval = INLINE_SYSCALL (ioctl, 3, fd, TCGETS, &k_termios);
+
+ if (__builtin_expect (retval == 0, 1))
+ {
+ termios_p->c_iflag = k_termios.c_iflag;
+ termios_p->c_oflag = k_termios.c_oflag;
+ termios_p->c_cflag = k_termios.c_cflag;
+ termios_p->c_lflag = k_termios.c_lflag;
+ termios_p->c_line = k_termios.c_line;
+#ifdef _HAVE_STRUCT_TERMIOS_C_ISPEED
+# ifdef _HAVE_C_ISPEED
+ termios_p->c_ispeed = k_termios.c_ispeed;
+# else
+ termios_p->c_ispeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
+# endif
+#endif
+#ifdef _HAVE_STRUCT_TERMIOS_C_OSPEED
+# ifdef _HAVE_C_OSPEED
+ termios_p->c_ospeed = k_termios.c_ospeed;
+# else
+ termios_p->c_ospeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
+# endif
+#endif
+ if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0
+ || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1)
+ memset (__mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
+ __KERNEL_NCCS * sizeof (cc_t)),
+ _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
+ else
+ {
+ memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
+ __KERNEL_NCCS * sizeof (cc_t));
+
+ for (size_t cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt)
+ termios_p->c_cc[cnt] = _POSIX_VDISABLE;
+ }
+ }
+
+ return retval;
+}
+
+weak_alias (__tcgetattr, tcgetattr)
diff --git a/libc/sysdeps/unix/sysv/linux/tcgetpgrp.c b/libc/sysdeps/unix/sysv/linux/tcgetpgrp.c
new file mode 100644
index 000000000..d899fc78f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/tcgetpgrp.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/bsd/tcgetpgrp.c>
diff --git a/libc/sysdeps/unix/sysv/linux/tcsetattr.c b/libc/sysdeps/unix/sysv/linux/tcsetattr.c
new file mode 100644
index 000000000..f73ec8883
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/tcsetattr.c
@@ -0,0 +1,85 @@
+/* Copyright (C) 1993,1996,1997,1998,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <string.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sysdep.h>
+
+/* The difference here is that the termios structure used in the
+ kernel is not the same as we use in the libc. Therefore we must
+ translate it here. */
+#include <kernel_termios.h>
+
+
+/* This is a gross hack around a kernel bug. If the cfsetispeed functions
+ is called with the SPEED argument set to zero this means use the same
+ speed as for output. But we don't have independent input and output
+ speeds and therefore cannot record this.
+
+ We use an unused bit in the `c_iflag' field to keep track of this
+ use of `cfsetispeed'. The value here must correspond to the one used
+ in `speed.c'. */
+#define IBAUD0 020000000000
+
+
+/* Set the state of FD to *TERMIOS_P. */
+int
+tcsetattr (fd, optional_actions, termios_p)
+ int fd;
+ int optional_actions;
+ const struct termios *termios_p;
+{
+ struct __kernel_termios k_termios;
+ unsigned long int cmd;
+
+ switch (optional_actions)
+ {
+ case TCSANOW:
+ cmd = TCSETS;
+ break;
+ case TCSADRAIN:
+ cmd = TCSETSW;
+ break;
+ case TCSAFLUSH:
+ cmd = TCSETSF;
+ break;
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ k_termios.c_iflag = termios_p->c_iflag & ~IBAUD0;
+ k_termios.c_oflag = termios_p->c_oflag;
+ k_termios.c_cflag = termios_p->c_cflag;
+ k_termios.c_lflag = termios_p->c_lflag;
+ k_termios.c_line = termios_p->c_line;
+#if defined _HAVE_C_ISPEED && defined _HAVE_STRUCT_TERMIOS_C_ISPEED
+ k_termios.c_ispeed = termios_p->c_ispeed;
+#endif
+#if defined _HAVE_C_OSPEED && defined _HAVE_STRUCT_TERMIOS_C_OSPEED
+ k_termios.c_ospeed = termios_p->c_ospeed;
+#endif
+ memcpy (&k_termios.c_cc[0], &termios_p->c_cc[0],
+ __KERNEL_NCCS * sizeof (cc_t));
+
+ return INLINE_SYSCALL (ioctl, 3, fd, cmd, &k_termios);
+}
+libc_hidden_def (tcsetattr)
diff --git a/libc/sysdeps/unix/sysv/linux/tcsetpgrp.c b/libc/sysdeps/unix/sysv/linux/tcsetpgrp.c
new file mode 100644
index 000000000..e4d483390
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/tcsetpgrp.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/bsd/tcsetpgrp.c>
diff --git a/libc/sysdeps/unix/sysv/linux/termio.h b/libc/sysdeps/unix/sysv/linux/termio.h
new file mode 100644
index 000000000..0e610f0c5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/termio.h
@@ -0,0 +1,6 @@
+/* Compatible <termio.h> for old `struct termio' ioctl interface.
+ This is obsolete; use the POSIX.1 `struct termios' interface
+ defined in <termios.h> instead. */
+
+#include <termios.h>
+#include <sys/ioctl.h>
diff --git a/libc/sysdeps/unix/sysv/linux/testrtsig.h b/libc/sysdeps/unix/sysv/linux/testrtsig.h
new file mode 100644
index 000000000..f823a3f5a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/testrtsig.h
@@ -0,0 +1,36 @@
+/* Test whether RT signals are really available.
+ Copyright (C) 1997, 1999, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <string.h>
+#include <sys/utsname.h>
+
+#include <kernel-features.h>
+
+static int
+kernel_has_rtsig (void)
+{
+#if __ASSUME_REALTIME_SIGNALS
+ return 1;
+#else
+ struct utsname name;
+
+ return uname (&name) == 0 && __strverscmp (name.release, "2.1.70") >= 0;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/time.c b/libc/sysdeps/unix/sysv/linux/time.c
new file mode 100644
index 000000000..83667906d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/time.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <time.h>
+
+#include <sysdep.h>
+
+#ifdef __NR_time
+
+time_t
+time (t)
+ time_t *t;
+{
+ INTERNAL_SYSCALL_DECL (err);
+ time_t res = INTERNAL_SYSCALL (time, err, 1, NULL);
+ /* There cannot be any error. */
+ if (t != NULL)
+ *t = res;
+ return res;
+}
+libc_hidden_def (time)
+
+#else
+
+# include <sysdeps/unix/time.c>
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/truncate64.c b/libc/sysdeps/unix/sysv/linux/truncate64.c
new file mode 100644
index 000000000..f43cffe01
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/truncate64.c
@@ -0,0 +1,76 @@
+/* Copyright (C) 1997-2000,2003,2004,2005,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/types.h>
+#include <endian.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#ifdef __NR_truncate64
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+/* The variable is shared between all wrappers around *truncate64 calls. */
+int __have_no_truncate64;
+#endif
+
+/* Truncate the file FD refers to to LENGTH bytes. */
+int
+truncate64 (const char *path, off64_t length)
+{
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if (! __have_no_truncate64)
+#endif
+ {
+ unsigned int low = length & 0xffffffff;
+ unsigned int high = length >> 32;
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ int saved_errno = errno;
+#endif
+ int result = INLINE_SYSCALL (truncate64, 3, CHECK_STRING (path),
+ __LONG_LONG_PAIR (high, low));
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if (result != -1 || errno != ENOSYS)
+#endif
+ return result;
+
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ __set_errno (saved_errno);
+ __have_no_truncate64 = 1;
+#endif
+ }
+
+#ifndef __ASSUME_TRUNCATE64_SYSCALL
+ if ((off_t) length != length)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ return __truncate (path, (off_t) length);
+#endif
+}
+
+#else
+/* Use the generic implementation. */
+# include <misc/truncate64.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/tst-clone.c b/libc/sysdeps/unix/sysv/linux/tst-clone.c
new file mode 100644
index 000000000..8e249c2f0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/tst-clone.c
@@ -0,0 +1,56 @@
+/* Test for proper error/errno handling in clone.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* BZ #2386 */
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sched.h>
+
+int child_fn(void *arg)
+{
+ puts ("FAIL: in child_fn(); should not be here");
+ exit(1);
+}
+
+static int
+do_test (void)
+{
+ int result;
+
+#ifdef __ia64__
+ result = __clone2(child_fn, NULL, 0, 0, NULL, NULL, NULL);
+#else
+ result = clone(child_fn, NULL, (int) NULL, NULL);
+#endif
+
+ if (errno != EINVAL || result != -1)
+ {
+ printf ("FAIL: clone()=%d (wanted -1) errno=%d (wanted %d)\n",
+ result, errno, EINVAL);
+ return 1;
+ }
+
+ puts ("All OK");
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/sysdeps/unix/sysv/linux/ttyname.c b/libc/sysdeps/unix/sysv/linux/ttyname.c
new file mode 100644
index 000000000..aed0fd8e0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ttyname.c
@@ -0,0 +1,200 @@
+/* Copyright (C) 1991,92,93,1996-2002,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <limits.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <stdio-common/_itoa.h>
+#include <kernel-features.h>
+
+#if 0
+/* Is this used anywhere? It is not exported. */
+char *__ttyname;
+#endif
+
+static char *getttyname (const char *dev, dev_t mydev,
+ ino64_t myino, int save, int *dostat)
+ internal_function;
+
+
+libc_freeres_ptr (static char *getttyname_name);
+
+static char *
+internal_function attribute_compat_text_section
+getttyname (const char *dev, dev_t mydev, ino64_t myino, int save, int *dostat)
+{
+ static size_t namelen;
+ struct stat64 st;
+ DIR *dirstream;
+ struct dirent64 *d;
+ size_t devlen = strlen (dev) + 1;
+
+ dirstream = __opendir (dev);
+ if (dirstream == NULL)
+ {
+ *dostat = -1;
+ return NULL;
+ }
+
+ while ((d = __readdir64 (dirstream)) != NULL)
+ if ((d->d_fileno == myino || *dostat)
+ && strcmp (d->d_name, "stdin")
+ && strcmp (d->d_name, "stdout")
+ && strcmp (d->d_name, "stderr"))
+ {
+ size_t dlen = _D_ALLOC_NAMLEN (d);
+ if (devlen + dlen > namelen)
+ {
+ free (getttyname_name);
+ namelen = 2 * (devlen + dlen); /* Big enough. */
+ getttyname_name = malloc (namelen);
+ if (! getttyname_name)
+ {
+ *dostat = -1;
+ /* Perhaps it helps to free the directory stream buffer. */
+ (void) __closedir (dirstream);
+ return NULL;
+ }
+ *((char *) __mempcpy (getttyname_name, dev, devlen - 1)) = '/';
+ }
+ memcpy (&getttyname_name[devlen], d->d_name, dlen);
+ if (__xstat64 (_STAT_VER, getttyname_name, &st) == 0
+#ifdef _STATBUF_ST_RDEV
+ && S_ISCHR (st.st_mode) && st.st_rdev == mydev
+#else
+ && d->d_fileno == myino && st.st_dev == mydev
+#endif
+ )
+ {
+ (void) __closedir (dirstream);
+#if 0
+ __ttyname = getttyname_name;
+#endif
+ __set_errno (save);
+ return getttyname_name;
+ }
+ }
+
+ (void) __closedir (dirstream);
+ __set_errno (save);
+ return NULL;
+}
+
+
+/* Static buffer in `ttyname'. */
+libc_freeres_ptr (static char *ttyname_buf);
+
+
+/* Return the pathname of the terminal FD is open on, or NULL on errors.
+ The returned storage is good only until the next call to this function. */
+char *
+ttyname (int fd)
+{
+ static size_t buflen;
+ char procname[30];
+ struct stat64 st, st1;
+ int dostat = 0;
+ char *name;
+ int save = errno;
+
+ if (__builtin_expect (!__isatty (fd), 0))
+ {
+ __set_errno (ENOTTY);
+ return NULL;
+ }
+
+ /* We try using the /proc filesystem. */
+ *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0';
+
+ if (buflen == 0)
+ {
+ buflen = 4095;
+ ttyname_buf = (char *) malloc (buflen + 1);
+ if (ttyname_buf == NULL)
+ {
+ buflen = 0;
+ return NULL;
+ }
+ }
+
+ ssize_t len = __readlink (procname, ttyname_buf, buflen);
+ if (__builtin_expect (len == -1 && errno == ENOENT, 0))
+ {
+ __set_errno (EBADF);
+ return NULL;
+ }
+
+ if (__builtin_expect (len != -1
+#ifndef __ASSUME_PROC_SELF_FD_SYMLINK
+ /* This is for Linux 2.0. */
+ && ttyname_buf[0] != '['
+#endif
+ , 1))
+ {
+ if ((size_t) len >= buflen)
+ return NULL;
+ /* readlink need not terminate the string. */
+ ttyname_buf[len] = '\0';
+ return ttyname_buf;
+ }
+
+ if (__fxstat64 (_STAT_VER, fd, &st) < 0)
+ return NULL;
+
+ if (__xstat64 (_STAT_VER, "/dev/pts", &st1) == 0 && S_ISDIR (st1.st_mode))
+ {
+#ifdef _STATBUF_ST_RDEV
+ name = getttyname ("/dev/pts", st.st_rdev, st.st_ino, save, &dostat);
+#else
+ name = getttyname ("/dev/pts", st.st_dev, st.st_ino, save, &dostat);
+#endif
+ }
+ else
+ {
+ __set_errno (save);
+ name = NULL;
+ }
+
+ if (!name && dostat != -1)
+ {
+#ifdef _STATBUF_ST_RDEV
+ name = getttyname ("/dev", st.st_rdev, st.st_ino, save, &dostat);
+#else
+ name = getttyname ("/dev", st.st_dev, st.st_ino, save, &dostat);
+#endif
+ }
+
+ if (!name && dostat != -1)
+ {
+ dostat = 1;
+#ifdef _STATBUF_ST_RDEV
+ name = getttyname ("/dev", st.st_rdev, st.st_ino, save, &dostat);
+#else
+ name = getttyname ("/dev", st.st_dev, st.st_ino, save, &dostat);
+#endif
+ }
+
+ return name;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ttyname_r.c b/libc/sysdeps/unix/sysv/linux/ttyname_r.c
new file mode 100644
index 000000000..bd415f167
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ttyname_r.c
@@ -0,0 +1,203 @@
+/* Copyright (C) 1991,92,93,1995-2001,2003,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <limits.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <stdio-common/_itoa.h>
+#include <kernel-features.h>
+
+static int getttyname_r (char *buf, size_t buflen,
+ dev_t mydev, ino64_t myino, int save,
+ int *dostat) internal_function;
+
+static int
+internal_function attribute_compat_text_section
+getttyname_r (char *buf, size_t buflen, dev_t mydev, ino64_t myino,
+ int save, int *dostat)
+{
+ struct stat64 st;
+ DIR *dirstream;
+ struct dirent64 *d;
+ size_t devlen = strlen (buf);
+
+ dirstream = __opendir (buf);
+ if (dirstream == NULL)
+ {
+ *dostat = -1;
+ return errno;
+ }
+
+ while ((d = __readdir64 (dirstream)) != NULL)
+ if ((d->d_fileno == myino || *dostat)
+ && strcmp (d->d_name, "stdin")
+ && strcmp (d->d_name, "stdout")
+ && strcmp (d->d_name, "stderr"))
+ {
+ char *cp;
+ size_t needed = _D_EXACT_NAMLEN (d) + 1;
+
+ if (needed > buflen)
+ {
+ *dostat = -1;
+ (void) __closedir (dirstream);
+ __set_errno (ERANGE);
+ return ERANGE;
+ }
+
+ cp = __stpncpy (buf + devlen, d->d_name, needed);
+ cp[0] = '\0';
+
+ if (__xstat64 (_STAT_VER, buf, &st) == 0
+#ifdef _STATBUF_ST_RDEV
+ && S_ISCHR (st.st_mode) && st.st_rdev == mydev
+#else
+ && d->d_fileno == myino && st.st_dev == mydev
+#endif
+ )
+ {
+ (void) __closedir (dirstream);
+ __set_errno (save);
+ return 0;
+ }
+ }
+
+ (void) __closedir (dirstream);
+ __set_errno (save);
+ /* It is not clear what to return in this case. `isatty' says FD
+ refers to a TTY but no entry in /dev has this inode. */
+ return ENOTTY;
+}
+
+/* Store at most BUFLEN character of the pathname of the terminal FD is
+ open on in BUF. Return 0 on success, otherwise an error number. */
+int
+__ttyname_r (int fd, char *buf, size_t buflen)
+{
+ char procname[30];
+ struct stat64 st, st1;
+ int dostat = 0;
+ int save = errno;
+
+ /* Test for the absolute minimal size. This makes life easier inside
+ the loop. */
+ if (!buf)
+ {
+ __set_errno (EINVAL);
+ return EINVAL;
+ }
+
+ if (buflen < sizeof ("/dev/pts/"))
+ {
+ __set_errno (ERANGE);
+ return ERANGE;
+ }
+
+ if (__builtin_expect (!__isatty (fd), 0))
+ {
+ __set_errno (ENOTTY);
+ return ENOTTY;
+ }
+
+ /* We try using the /proc filesystem. */
+ *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0';
+
+ ssize_t ret = __readlink (procname, buf, buflen - 1);
+ if (__builtin_expect (ret == -1 && errno == ENOENT, 0))
+ {
+ __set_errno (EBADF);
+ return EBADF;
+ }
+
+ if (__builtin_expect (ret == -1 && errno == ENAMETOOLONG, 0))
+ {
+ __set_errno (ERANGE);
+ return ERANGE;
+ }
+
+ if (__builtin_expect (ret != -1
+#ifndef __ASSUME_PROC_SELF_FD_SYMLINK
+ /* This is for Linux 2.0. */
+ && buf[0] != '['
+#endif
+ , 1))
+ {
+ buf[ret] = '\0';
+ return 0;
+ }
+
+ if (__fxstat64 (_STAT_VER, fd, &st) < 0)
+ return errno;
+
+ /* Prepare the result buffer. */
+ memcpy (buf, "/dev/pts/", sizeof ("/dev/pts/"));
+ buflen -= sizeof ("/dev/pts/") - 1;
+
+ if (__xstat64 (_STAT_VER, buf, &st1) == 0 && S_ISDIR (st1.st_mode))
+ {
+#ifdef _STATBUF_ST_RDEV
+ ret = getttyname_r (buf, buflen, st.st_rdev, st.st_ino, save,
+ &dostat);
+#else
+ ret = getttyname_r (buf, buflen, st.st_dev, st.st_ino, save,
+ &dostat);
+#endif
+ }
+ else
+ {
+ __set_errno (save);
+ ret = ENOENT;
+ }
+
+ if (ret && dostat != -1)
+ {
+ buf[sizeof ("/dev/") - 1] = '\0';
+ buflen += sizeof ("pts/") - 1;
+#ifdef _STATBUF_ST_RDEV
+ ret = getttyname_r (buf, buflen, st.st_rdev, st.st_ino, save,
+ &dostat);
+#else
+ ret = getttyname_r (buf, buflen, st.st_dev, st.st_ino, save,
+ &dostat);
+#endif
+ }
+
+ if (ret && dostat != -1)
+ {
+ buf[sizeof ("/dev/") - 1] = '\0';
+ dostat = 1;
+#ifdef _STATBUF_ST_RDEV
+ ret = getttyname_r (buf, buflen, st.st_rdev, st.st_ino,
+ save, &dostat);
+#else
+ ret = getttyname_r (buf, buflen, st.st_dev, st.st_ino,
+ save, &dostat);
+#endif
+ }
+
+ return ret;
+}
+
+weak_alias (__ttyname_r, ttyname_r)
diff --git a/libc/sysdeps/unix/sysv/linux/ualarm.c b/libc/sysdeps/unix/sysv/linux/ualarm.c
new file mode 100644
index 000000000..5522f5889
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ualarm.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/bsd/ualarm.c>
diff --git a/libc/sysdeps/unix/sysv/linux/ulimit.c b/libc/sysdeps/unix/sysv/linux/ulimit.c
new file mode 100644
index 000000000..9c309c371
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ulimit.c
@@ -0,0 +1,86 @@
+/* Copyright (C) 1991,92,1994-1998,2000,2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <sysdep.h>
+#include <ulimit.h>
+#include <unistd.h>
+#include <sys/resource.h>
+
+/* Function depends on CMD:
+ 1 = Return the limit on the size of a file, in units of 512 bytes.
+ 2 = Set the limit on the size of a file to NEWLIMIT. Only the
+ super-user can increase the limit.
+ 3 = illegal due to shared libraries; normally is
+ (Return the maximum possible address of the data segment.)
+ 4 = Return the maximum number of files that the calling process
+ can open.
+ Returns -1 on errors. */
+long int
+__ulimit (int cmd, ...)
+{
+ struct rlimit limit;
+ va_list va;
+ long int result = -1;
+
+ va_start (va, cmd);
+
+ switch (cmd)
+ {
+ case UL_GETFSIZE:
+ /* Get limit on file size. */
+ if (__getrlimit (RLIMIT_FSIZE, &limit) == 0)
+ /* Convert from bytes to 512 byte units. */
+ result = limit.rlim_cur / 512;
+ break;
+
+ case UL_SETFSIZE:
+ /* Set limit on file size. */
+ {
+ long int newlimit = va_arg (va, long int);
+
+ if ((rlim_t) newlimit > RLIM_INFINITY / 512)
+ {
+ limit.rlim_cur = RLIM_INFINITY;
+ limit.rlim_max = RLIM_INFINITY;
+ }
+ else
+ {
+ limit.rlim_cur = newlimit * 512;
+ limit.rlim_max = newlimit * 512;
+ }
+
+ result = __setrlimit (RLIMIT_FSIZE, &limit);
+ }
+ break;
+
+ case __UL_GETOPENMAX:
+ result = __sysconf (_SC_OPEN_MAX);
+ break;
+
+ default:
+ __set_errno (EINVAL);
+ }
+
+ va_end (va);
+
+ return result;
+}
+
+weak_alias (__ulimit, ulimit);
diff --git a/libc/sysdeps/unix/sysv/linux/umount.S b/libc/sysdeps/unix/sysv/linux/umount.S
new file mode 100644
index 000000000..e18463e2e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/umount.S
@@ -0,0 +1,12 @@
+/* This hack is necessary since the kernel people are making "strange"
+ changes. They simply rename old system calls. */
+
+#include <sysdep.h>
+#ifdef __NR_oldumount
+PSEUDO (__umount, oldumount, 1)
+#else
+PSEUDO (__umount, umount, 1)
+#endif
+ ret
+PSEUDO_END(__umount)
+weak_alias (__umount, umount)
diff --git a/libc/sysdeps/unix/sysv/linux/umount2.S b/libc/sysdeps/unix/sysv/linux/umount2.S
new file mode 100644
index 000000000..92241bbf9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/umount2.S
@@ -0,0 +1,13 @@
+/* umount system call with two parameters. */
+
+#include <sysdep.h>
+#if defined __NR_oldumount || defined __NR_umount2
+#ifdef __NR_oldumount
+PSEUDO (__umount2, umount, 2)
+#else
+PSEUDO (__umount2, umount2, 2)
+#endif
+ ret
+PSEUDO_END(__umount2)
+weak_alias (__umount2, umount2)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/unlinkat.c b/libc/sysdeps/unix/sysv/linux/unlinkat.c
new file mode 100644
index 000000000..0a07a8a87
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/unlinkat.c
@@ -0,0 +1,97 @@
+/* unlinkat -- Remove a link by relative name.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysdep.h>
+#include <unistd.h>
+#include <kernel-features.h>
+
+
+/* Remove the link named NAME. */
+int
+unlinkat (fd, file, flag)
+ int fd;
+ const char *file;
+ int flag;
+{
+ int result;
+
+#ifdef __NR_unlinkat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ result = INLINE_SYSCALL (unlinkat, 3, fd, file, flag);
+# ifndef __ASSUME_ATFCTS
+ if (result == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return result;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ if (flag & ~AT_REMOVEDIR)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = __alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+ if (flag & AT_REMOVEDIR)
+ result = INTERNAL_SYSCALL (rmdir, err, 1, file);
+ else
+ result = INTERNAL_SYSCALL (unlink, err, 1, file);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+ {
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+ result = -1;
+ }
+
+ return result;
+#endif
+}
diff --git a/libc/sysdeps/unix/sysv/linux/unlockpt.c b/libc/sysdeps/unix/sysv/linux/unlockpt.c
new file mode 100644
index 000000000..c5044efe5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/unlockpt.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+
+
+/* Unlock the slave pseudo terminal associated with the master pseudo
+ terminal specified by FD. */
+int
+unlockpt (int fd)
+{
+#ifdef TIOCSPTLCK
+ int save_errno = errno;
+ int unlock = 0;
+
+ if (__ioctl (fd, TIOCSPTLCK, &unlock))
+ {
+ if (errno == EINVAL)
+ {
+ __set_errno (save_errno);
+ return 0;
+ }
+ else
+ return -1;
+ }
+#endif
+ /* If we have no TIOCSPTLCK ioctl, all slave pseudo terminals are
+ unlocked by default. */
+ return 0;
+}
diff --git a/libc/sysdeps/unix/sysv/linux/updwtmp.c b/libc/sysdeps/unix/sysv/linux/updwtmp.c
new file mode 100644
index 000000000..d4d3f2cb7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/updwtmp.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1998, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <string.h>
+#include <unistd.h>
+
+#define TRANSFORM_UTMP_FILE_NAME(file_name) \
+ ((strcmp (file_name, _PATH_UTMP) == 0 \
+ && __access (_PATH_UTMP "x", F_OK) == 0) ? (_PATH_UTMP "x") : \
+ ((strcmp (file_name, _PATH_WTMP) == 0 \
+ && __access ( _PATH_WTMP "x", F_OK) == 0) ? (_PATH_WTMP "x") : \
+ ((strcmp (file_name, _PATH_UTMP "x") == 0 \
+ && __access (_PATH_UTMP "x", F_OK) != 0) ? _PATH_UTMP : \
+ ((strcmp (file_name, _PATH_WTMP "x") == 0 \
+ && __access (_PATH_WTMP "x", F_OK) != 0) ? _PATH_WTMP : \
+ file_name))))
+
+#include <login/updwtmp.c>
diff --git a/libc/sysdeps/unix/sysv/linux/usleep.c b/libc/sysdeps/unix/sysv/linux/usleep.c
new file mode 100644
index 000000000..f770c5788
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/usleep.c
@@ -0,0 +1,34 @@
+/* Implementation of the BSD usleep function using nanosleep.
+ Copyright (C) 1996, 1997, 1999, 2001, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <time.h>
+#include <unistd.h>
+
+int
+usleep (useconds_t useconds)
+{
+ struct timespec ts = { .tv_sec = (long int) (useconds / 1000000),
+ .tv_nsec = (long int) (useconds % 1000000) * 1000ul };
+
+ /* Note the usleep() is a cancellation point. But since we call
+ nanosleep() which itself is a cancellation point we do not have
+ to do anything here. */
+ return __nanosleep (&ts, NULL);
+}
diff --git a/libc/sysdeps/unix/sysv/linux/ustat.c b/libc/sysdeps/unix/sysv/linux/ustat.c
new file mode 100644
index 000000000..6ac30d8d8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/ustat.c
@@ -0,0 +1,42 @@
+/* Copyright (C) 1997, 1998, 2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/ustat.h>
+#include <sys/sysmacros.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+int
+ustat (dev_t dev, struct ustat *ubuf)
+{
+ unsigned long long int k_dev;
+
+ /* 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 (ustat, 2, (unsigned int) k_dev, CHECK_1 (ubuf));
+}
diff --git a/libc/sysdeps/unix/sysv/linux/utimes.c b/libc/sysdeps/unix/sysv/linux/utimes.c
new file mode 100644
index 000000000..a6095aaea
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/utimes.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 1995, 1997, 2000, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <utime.h>
+#include <sys/time.h>
+#include <sysdep.h>
+#include <kernel-features.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])
+{
+#ifdef __NR_utimes
+ int result = INLINE_SYSCALL (utimes, 2, file, tvp);
+# ifndef __ASSUME_UTIMES
+ if (result != -1 || errno != ENOSYS)
+# endif
+ return result;
+#endif
+
+ /* The utimes() syscall does not exist or is not available in the
+ used kernel. Use utime(). For this we have to convert to the
+ data format utime() expects. */
+#ifndef __ASSUME_UTIMES
+ struct utimbuf buf;
+ struct utimbuf *times;
+
+ if (tvp != NULL)
+ {
+ times = &buf;
+ buf.actime = tvp[0].tv_sec + tvp[0].tv_usec / 1000000;
+ buf.modtime = tvp[1].tv_sec + tvp[1].tv_usec / 1000000;
+ }
+ else
+ times = NULL;
+
+ return INLINE_SYSCALL (utime, 2, file, times);
+#endif
+}
+
+weak_alias (__utimes, utimes)
diff --git a/libc/sysdeps/unix/sysv/linux/utmp_file.c b/libc/sysdeps/unix/sysv/linux/utmp_file.c
new file mode 100644
index 000000000..958619a03
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/utmp_file.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1998, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <string.h>
+#include <unistd.h>
+
+#define TRANSFORM_UTMP_FILE_NAME(file_name) \
+ ((strcmp (file_name, _PATH_UTMP) == 0 \
+ && __access (_PATH_UTMP "x", F_OK) == 0) ? (_PATH_UTMP "x") : \
+ ((strcmp (file_name, _PATH_WTMP) == 0 \
+ && __access ( _PATH_WTMP "x", F_OK) == 0) ? (_PATH_WTMP "x") : \
+ ((strcmp (file_name, _PATH_UTMP "x") == 0 \
+ && __access (_PATH_UTMP "x", F_OK) != 0) ? _PATH_UTMP : \
+ ((strcmp (file_name, _PATH_WTMP "x") == 0 \
+ && __access (_PATH_WTMP "x", F_OK) != 0) ? _PATH_WTMP : \
+ file_name))))
+
+#include <login/utmp_file.c>
diff --git a/libc/sysdeps/unix/sysv/linux/vfork.c b/libc/sysdeps/unix/sysv/linux/vfork.c
new file mode 100644
index 000000000..c8c13d0fd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/vfork.c
@@ -0,0 +1 @@
+#include <posix/vfork.c>
diff --git a/libc/sysdeps/unix/sysv/linux/wait.c b/libc/sysdeps/unix/sysv/linux/wait.c
new file mode 100644
index 000000000..39d1066dd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wait.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 1991,1995,1996,1997,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/wait.h>
+#include <errno.h>
+#include <sys/resource.h>
+#include <stddef.h>
+#include <sysdep-cancel.h>
+
+/* Wait for a child to die. When one does, put its status in *STAT_LOC
+ and return its process ID. For errors, return (pid_t) -1. */
+pid_t
+__libc_wait (__WAIT_STATUS_DEFN stat_loc)
+{
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (wait4, 4, WAIT_ANY, stat_loc, 0,
+ (struct rusage *) NULL);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ pid_t result = INLINE_SYSCALL (wait4, 4, WAIT_ANY, stat_loc, 0,
+ (struct rusage *) NULL);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+weak_alias (__libc_wait, __wait)
+weak_alias (__libc_wait, wait)
diff --git a/libc/sysdeps/unix/sysv/linux/wait3.c b/libc/sysdeps/unix/sysv/linux/wait3.c
new file mode 100644
index 000000000..0b3bdee77
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wait3.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/bsd/bsd4.4/wait3.c>
diff --git a/libc/sysdeps/unix/sysv/linux/waitid.c b/libc/sysdeps/unix/sysv/linux/waitid.c
new file mode 100644
index 000000000..71d5d3aa1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/waitid.c
@@ -0,0 +1,71 @@
+/* Linux implementation of waitid.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h>
+#include <errno.h>
+#include <sys/wait.h>
+#include <kernel-features.h>
+#include <sysdep.h>
+
+
+#ifdef __NR_waitid
+
+# if __ASSUME_WAITID_SYSCALL > 0
+
+static inline int
+do_waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
+{
+ /* The unused fifth argument is a `struct rusage *' that we could
+ pass if we were using waitid to simulate wait3/wait4. */
+ return INLINE_SYSCALL (waitid, 5, idtype, id, infop, options, NULL);
+}
+# define NO_DO_WAITID
+
+# else
+
+static int do_compat_waitid (idtype_t idtype, id_t id,
+ siginfo_t *infop, int options);
+# define DO_WAITID do_compat_waitid
+
+static int
+do_waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
+{
+ static int waitid_works;
+ if (waitid_works > 0)
+ return INLINE_SYSCALL (waitid, 5, idtype, id, infop, options, NULL);
+ if (waitid_works == 0)
+ {
+ int result = INLINE_SYSCALL (waitid, 5,
+ idtype, id, infop, options, NULL);
+ if (result < 0 && errno == ENOSYS)
+ waitid_works = -1;
+ else
+ {
+ waitid_works = 1;
+ return result;
+ }
+ }
+ return do_compat_waitid (idtype, id, infop, options);
+}
+
+# endif
+
+#endif
+
+#include "sysdeps/posix/waitid.c"
diff --git a/libc/sysdeps/unix/sysv/linux/waitpid.c b/libc/sysdeps/unix/sysv/linux/waitpid.c
new file mode 100644
index 000000000..32b01c0a5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/waitpid.c
@@ -0,0 +1,50 @@
+/* Copyright (C) 1991,92,95,96,97,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sysdep-cancel.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+
+__pid_t
+__libc_waitpid (__pid_t pid, int *stat_loc, int options)
+{
+ if (SINGLE_THREAD_P)
+ {
+#ifdef __NR_waitpid
+ return INLINE_SYSCALL (waitpid, 3, pid, stat_loc, options);
+#else
+ return INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL);
+#endif
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+#ifdef __NR_waitpid
+ int result = INLINE_SYSCALL (waitpid, 3, pid, stat_loc, options);
+#else
+ int result = INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL);
+#endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+weak_alias (__libc_waitpid, __waitpid)
+libc_hidden_weak (__waitpid)
+weak_alias (__libc_waitpid, waitpid)
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/fstatfs64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/fstatfs64.c
new file mode 100644
index 000000000..2be4e59ba
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/fstatfs64.c
@@ -0,0 +1 @@
+/* fstatfs64 is the same as fstatfs. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/fstatvfs.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/fstatvfs.c
new file mode 100644
index 000000000..d04bcd4b5
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/fstatvfs.c
@@ -0,0 +1,5 @@
+#define __fstatvfs64(file, buf) __no_fstatvfs64(file, buf)
+#define fstatvfs64(file, buf) no_fstatvfs64(file, buf)
+#include "../fstatvfs.c"
+strong_alias (fstatvfs, __fstatvfs64)
+weak_alias (fstatvfs, fstatvfs64)
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/fstatvfs64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/fstatvfs64.c
new file mode 100644
index 000000000..60f3dfec6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/fstatvfs64.c
@@ -0,0 +1 @@
+/* fstatvfs64 is the same as fstatvfs. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
new file mode 100644
index 000000000..673a8b525
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/ftruncate64.c
@@ -0,0 +1 @@
+/* ftruncate64 is the same as ftruncate. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstat.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstat.c
new file mode 100644
index 000000000..5d69eb830
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstat.c
@@ -0,0 +1,48 @@
+/* fxstat using old-style Unix fstat system call.
+ Copyright (C) 1991, 1995, 1996, 1997, 1998, 2000, 2002, 2003, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, since xstat == xstat64 we must get rid of the prototype or gcc
+ will complain since they don't strictly match. */
+#define __fxstat64 __fxstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Get information about the file FD in BUF. */
+int
+__fxstat (int vers, int fd, struct stat *buf)
+{
+ if (vers == _STAT_VER_KERNEL || vers == _STAT_VER_LINUX)
+ return INLINE_SYSCALL (fstat, 2, fd, CHECK_1 (buf));
+
+ __set_errno (EINVAL);
+ return -1;
+}
+
+hidden_def (__fxstat)
+weak_alias (__fxstat, _fxstat);
+#undef __fxstat64
+strong_alias (__fxstat, __fxstat64);
+hidden_ver (__fxstat, __fxstat64)
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstat64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstat64.c
new file mode 100644
index 000000000..9eff9ebeb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstat64.c
@@ -0,0 +1 @@
+/* fxstat64 is in fxstat.c */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c
new file mode 100644
index 000000000..8b1c932ba
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c
@@ -0,0 +1,109 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, since fxstatat == fxstatat64 we must get rid of the
+ prototype or gcc will complain since they don't strictly match. */
+#define __fxstatat64 __fxstatat64_disable
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#include <sysdep.h>
+#include <kernel-features.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+
+/* Get information about the file NAME relative to FD in ST. */
+int
+__fxstatat (int vers, int fd, const char *file, struct stat *st, int flag)
+{
+ if (vers != _STAT_VER_KERNEL && vers != _STAT_VER_LINUX)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ int res;
+
+#ifdef __NR_newfstatat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ res = INLINE_SYSCALL (newfstatat, 4, fd, file, st, flag);
+# ifndef __ASSUME_ATFCTS
+ if (res == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return res;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ res = INTERNAL_SYSCALL (lstat, err, 2, file, CHECK_1 (st));
+ else
+ res = INTERNAL_SYSCALL (stat, err, 2, file, CHECK_1 (st));
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (res, err), 0))
+ {
+ __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (res, err), fd, buf);
+ res = -1;
+ }
+
+ return res;
+#endif
+}
+libc_hidden_def (__fxstatat)
+#undef __fxstatat64
+strong_alias (__fxstatat, __fxstatat64);
+strong_alias (__fxstatat64, __GI___fxstatat64)
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstatat64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstatat64.c
new file mode 100644
index 000000000..05e7f413b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/fxstatat64.c
@@ -0,0 +1 @@
+/* fxstatat64 is in fxstatat.c */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/getdents.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/getdents.c
new file mode 100644
index 000000000..5ea4c572a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/getdents.c
@@ -0,0 +1,4 @@
+#define __getdents64 __no___getdents64_decl
+#include <sysdeps/unix/sysv/linux/getdents.c>
+#undef __getdents64
+weak_alias (__getdents, __getdents64);
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/getdents64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/getdents64.c
new file mode 100644
index 000000000..0df2c8f4c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/getdents64.c
@@ -0,0 +1 @@
+/* getdents64 is in getdents.c */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/getrlimit64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/getrlimit64.c
new file mode 100644
index 000000000..9feab0e6b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/getrlimit64.c
@@ -0,0 +1 @@
+/* getrlimit64 is the same as getrlimit. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/glob64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/glob64.c
new file mode 100644
index 000000000..33918ea6a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/glob64.c
@@ -0,0 +1 @@
+/* glob64 is in glob.c */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/internal_statvfs64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/internal_statvfs64.c
new file mode 100644
index 000000000..d2a3509c6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/internal_statvfs64.c
@@ -0,0 +1 @@
+/* Nothing. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/lxstat.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/lxstat.c
new file mode 100644
index 000000000..2b937760e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/lxstat.c
@@ -0,0 +1,48 @@
+/* lxstat using old-style Unix lstat system call.
+ Copyright (C) 1991, 1995, 1996, 1997, 1998, 2000, 2002, 2003, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, since xstat == xstat64 we must get rid of the prototype or gcc
+ will complain since they don't strictly match. */
+#define __lxstat64 __lxstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Get information about the file FD in BUF. */
+int
+__lxstat (int vers, const char *name, struct stat *buf)
+{
+ if (vers == _STAT_VER_KERNEL || vers == _STAT_VER_LINUX)
+ return INLINE_SYSCALL (lstat, 2, CHECK_STRING (name), CHECK_1 (buf));
+
+ __set_errno (EINVAL);
+ return -1;
+}
+
+hidden_def (__lxstat)
+weak_alias (__lxstat, _lxstat);
+#undef __lxstat64
+strong_alias (__lxstat, __lxstat64);
+hidden_ver (__lxstat, __lxstat64)
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/lxstat64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/lxstat64.c
new file mode 100644
index 000000000..bb5dbd0ff
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/lxstat64.c
@@ -0,0 +1 @@
+/* lxstat64 is in lxstat.c */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/mmap64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/mmap64.c
new file mode 100644
index 000000000..0dbd384a6
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/mmap64.c
@@ -0,0 +1 @@
+/* mmap64 is the same as mmap. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/posix_fadvise.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/posix_fadvise.c
new file mode 100644
index 000000000..b23074804
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/posix_fadvise.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define posix_fadvise64 __no_posix_fadvise64
+#include <errno.h>
+#include <fcntl.h>
+#include <sysdep.h>
+#undef posix_fadvise64
+
+/* 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)
+{
+#ifdef __NR_fadvise64
+ INTERNAL_SYSCALL_DECL (err);
+ int ret = INTERNAL_SYSCALL (fadvise64, err, 4, fd, offset, len, advise);
+ if (INTERNAL_SYSCALL_ERROR_P (ret, err))
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+ return 0;
+#else
+ return ENOSYS;
+#endif
+}
+strong_alias (posix_fadvise, posix_fadvise64)
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/posix_fadvise64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/posix_fadvise64.c
new file mode 100644
index 000000000..c9f72c4ce
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/posix_fadvise64.c
@@ -0,0 +1 @@
+/* posix_fadvise64 is in posix_fadvise.c */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/pread64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/pread64.c
new file mode 100644
index 000000000..b7f298dea
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/pread64.c
@@ -0,0 +1 @@
+/* Empty since the pread syscall is equivalent. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/pwrite64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/pwrite64.c
new file mode 100644
index 000000000..b7f298dea
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/pwrite64.c
@@ -0,0 +1 @@
+/* Empty since the pread syscall is equivalent. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir.c
new file mode 100644
index 000000000..300ebb262
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir.c
@@ -0,0 +1,7 @@
+#define readdir64 __no_readdir64_decl
+#define __readdir64 __no___readdir64_decl
+#include <sysdeps/unix/readdir.c>
+#undef __readdir64
+strong_alias (__readdir, __readdir64)
+#undef readdir64
+weak_alias (__readdir, readdir64)
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir64.c
new file mode 100644
index 000000000..9796431dc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir64.c
@@ -0,0 +1 @@
+/* readdir64 is in readdir.c */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c
new file mode 100644
index 000000000..b8fe9a31b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c
@@ -0,0 +1 @@
+/* readdir64_r is in readdir_r.c */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c
new file mode 100644
index 000000000..adb92db6a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c
@@ -0,0 +1,4 @@
+#define readdir64_r __no_readdir64_r_decl
+#include <sysdeps/unix/readdir_r.c>
+#undef readdir64_r
+weak_alias (__readdir_r, readdir64_r)
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/sendfile64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/sendfile64.c
new file mode 100644
index 000000000..4c451bd09
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/sendfile64.c
@@ -0,0 +1 @@
+/* sendfile64 is alias of sendfile syscall. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/setrlimit64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/setrlimit64.c
new file mode 100644
index 000000000..8edcff008
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/setrlimit64.c
@@ -0,0 +1 @@
+/* setrlimit64 is the same as setrlimit. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/statfs64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/statfs64.c
new file mode 100644
index 000000000..06bc68826
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/statfs64.c
@@ -0,0 +1 @@
+/* statfs64 is the same as statfs. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/statvfs.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/statvfs.c
new file mode 100644
index 000000000..f369976cc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/statvfs.c
@@ -0,0 +1,5 @@
+#define __statvfs64(file, buf) __no_statvfs64(file, buf)
+#define statvfs64(file, buf) no_statvfs64(file, buf)
+#include "../statvfs.c"
+strong_alias (statvfs, __statvfs64)
+weak_alias (statvfs, statvfs64)
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/statvfs64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/statvfs64.c
new file mode 100644
index 000000000..510015e42
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/statvfs64.c
@@ -0,0 +1 @@
+/* statvfs64 is the same as statvfs. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list b/libc/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
new file mode 100644
index 000000000..d377db968
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
@@ -0,0 +1,17 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+# Whee! 64-bit systems naturally implement llseek.
+llseek EXTRA lseek Ci:iii __libc_lseek __lseek lseek __libc_lseek64 __llseek llseek __lseek64 lseek64
+lseek llseek -
+pread - pread Ci:ibni __libc_pread __libc_pread64 __pread pread __pread64 pread64
+pwrite - pwrite Ci:ibni __libc_pwrite __libc_pwrite64 __pwrite pwrite __pwrite64 pwrite64
+fstatfs - fstatfs i:ip __fstatfs fstatfs fstatfs64 __fstatfs64
+statfs - statfs i:sp __statfs statfs statfs64
+mmap - mmap b:aniiii __mmap mmap __mmap64 mmap64
+ftruncate - ftruncate i:ii __ftruncate ftruncate ftruncate64 __ftruncate64
+truncate - truncate i:si truncate truncate64
+getrlimit - getrlimit i:ip __getrlimit getrlimit getrlimit64
+setrlimit - setrlimit i:ip __setrlimit setrlimit setrlimit64
+readahead - readahead i:iii __readahead readahead
+sendfile - sendfile i:iipi sendfile sendfile64
+sync_file_range - sync_file_range i:iiii sync_file_range
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/truncate64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/truncate64.c
new file mode 100644
index 000000000..899976887
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/truncate64.c
@@ -0,0 +1 @@
+/* truncate64 is the same as truncate. */
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/xstat.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/xstat.c
new file mode 100644
index 000000000..38f32b664
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/xstat.c
@@ -0,0 +1,47 @@
+/* xstat using old-style Unix stat system call.
+ Copyright (C) 1991, 1995, 1996, 1997, 1998, 2000, 2002, 2003, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, since xstat == xstat64 we must get rid of the prototype or gcc
+ will complain since they don't strictly match. */
+#define __xstat64 __xstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Get information about the file NAME in BUF. */
+int
+__xstat (int vers, const char *name, struct stat *buf)
+{
+ if (vers == _STAT_VER_KERNEL || vers == _STAT_VER_LINUX)
+ return INLINE_SYSCALL (stat, 2, name, CHECK_1 (buf));
+
+ __set_errno (EINVAL);
+ return -1;
+}
+hidden_def (__xstat)
+weak_alias (__xstat, _xstat);
+#undef __xstat64
+strong_alias (__xstat, __xstat64);
+hidden_ver (__xstat, __xstat64)
diff --git a/libc/sysdeps/unix/sysv/linux/wordsize-64/xstat64.c b/libc/sysdeps/unix/sysv/linux/wordsize-64/xstat64.c
new file mode 100644
index 000000000..e7acd3b45
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/wordsize-64/xstat64.c
@@ -0,0 +1 @@
+/* xstat64 is in xstat.c */
diff --git a/libc/sysdeps/unix/sysv/linux/writev.c b/libc/sysdeps/unix/sysv/linux/writev.c
new file mode 100644
index 000000000..05978665f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/writev.c
@@ -0,0 +1,75 @@
+/* writev supports all Linux kernels >= 2.0.
+ Copyright (C) 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/param.h>
+#include <sys/uio.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+static ssize_t __atomic_writev_replacement (int, const struct iovec *,
+ int) internal_function;
+
+
+/* Not all versions of the kernel support the large number of records. */
+#ifndef UIO_FASTIOV
+# define UIO_FASTIOV 8 /* 8 is a safe number. */
+#endif
+
+
+/* We should deal with kernel which have a smaller UIO_FASTIOV as well
+ as a very big count. */
+static ssize_t
+do_writev (int fd, const struct iovec *vector, int count)
+{
+ ssize_t bytes_written;
+
+ bytes_written = INLINE_SYSCALL (writev, 3, fd, CHECK_N (vector, count), count);
+
+ if (bytes_written >= 0 || errno != EINVAL || count <= UIO_FASTIOV)
+ return bytes_written;
+
+ return __atomic_writev_replacement (fd, vector, count);
+}
+
+ssize_t
+__libc_writev (fd, vector, count)
+ int fd;
+ const struct iovec *vector;
+ int count;
+{
+ if (SINGLE_THREAD_P)
+ return do_writev (fd, vector, count);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = do_writev (fd, vector, count);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+strong_alias (__libc_writev, __writev)
+weak_alias (__libc_writev, writev)
+
+#define __libc_writev static internal_function __atomic_writev_replacement
+#include <sysdeps/posix/writev.c>
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/Implies b/libc/sysdeps/unix/sysv/linux/x86_64/Implies
new file mode 100644
index 000000000..8d91c8009
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/Implies
@@ -0,0 +1 @@
+unix/sysv/linux/wordsize-64
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/Makefile b/libc/sysdeps/unix/sysv/linux/x86_64/Makefile
new file mode 100644
index 000000000..0f2036723
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/Makefile
@@ -0,0 +1,15 @@
+32bit-predefine = __i386__
+64bit-predefine = __x86_64__
+
+ifeq ($(subdir),misc)
+sysdep_routines += ioperm iopl
+sysdep_headers += sys/perm.h sys/reg.h sys/debugreg.h sys/io.h
+endif
+
+ifeq ($(subdir),stdlib)
+sysdep_routines += __start_context
+endif
+
+ifeq ($(subdir),stdlib)
+gen-as-const-headers += ucontext_i.sym
+endif
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/Versions b/libc/sysdeps/unix/sysv/linux/x86_64/Versions
new file mode 100644
index 000000000..fd1b3cc29
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/Versions
@@ -0,0 +1,9 @@
+libc {
+ GLIBC_2.2.5 {
+ arch_prctl; __arch_prctl;
+
+ ioperm; iopl;
+
+ modify_ldt;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/__start_context.S b/libc/sysdeps/unix/sysv/linux/x86_64/__start_context.S
new file mode 100644
index 000000000..37d391760
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/__start_context.S
@@ -0,0 +1,49 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Jaeger <aj@suse.de>, 2002.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* This is the helper code which gets called if a function which is
+ registered with 'makecontext' returns. In this case we have to
+ install the context listed in the uc_link element of the context
+ 'makecontext' manipulated at the time of the 'makecontext' call.
+ If the pointer is NULL the process must terminate. */
+
+
+ENTRY(__start_context)
+ /* This removes the parameters passed to the function given to
+ 'makecontext' from the stack. RBX contains the address
+ on the stack pointer for the next context. */
+ movq %rbx, %rsp
+
+ popq %rdi /* This is the next context. */
+ cfi_adjust_cfa_offset(-8)
+ testq %rdi, %rdi
+ je 2f /* If it is zero exit. */
+
+ call JUMPTARGET(__setcontext)
+ /* If this returns (which can happen if the syscall fails) we'll
+ exit the program with the return error value (-1). */
+
+2: movq %rax,%rdi
+ call HIDDEN_JUMPTARGET(exit)
+ /* The 'exit' call should never return. In case it does cause
+ the process to terminate. */
+ hlt
+END(__start_context)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/bits/a.out.h b/libc/sysdeps/unix/sysv/linux/x86_64/bits/a.out.h
new file mode 100644
index 000000000..228a8d41a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/bits/a.out.h
@@ -0,0 +1,13 @@
+#ifndef __A_OUT_GNU_H__
+# error "Never use <bits/a.out.h> directly; include <a.out.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+
+/* Signal to users of this header that this architecture really doesn't
+ support a.out binary format. */
+#define __NO_A_OUT_SUPPORT 1
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/bits/environments.h b/libc/sysdeps/unix/sysv/linux/x86_64/bits/environments.h
new file mode 100644
index 000000000..a51a564cb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/bits/environments.h
@@ -0,0 +1,87 @@
+/* Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _UNISTD_H
+# error "Never include this file directly. Use <unistd.h> instead"
+#endif
+
+#include <bits/wordsize.h>
+
+/* This header should define the following symbols under the described
+ situations. A value `1' means that the model is always supported,
+ `-1' means it is never supported. Undefined means it cannot be
+ statically decided.
+
+ _POSIX_V6_ILP32_OFF32 32bit int, long, pointers, and off_t type
+ _POSIX_V6_ILP32_OFFBIG 32bit int, long, and pointers and larger off_t type
+
+ _POSIX_V6_LP64_OFF32 64bit long and pointers and 32bit off_t type
+ _POSIX_V6_LPBIG_OFFBIG 64bit long and pointers and large off_t type
+
+ The macros _XBS5_ILP32_OFF32, _XBS5_ILP32_OFFBIG, _XBS5_LP64_OFF32, and
+ _XBS5_LPBIG_OFFBIG were used in previous versions of the Unix standard
+ and are available only for compatibility.
+*/
+
+#if __WORDSIZE == 64
+
+/* Environments with 32-bit wide pointers are optionally provided.
+ Therefore following macros aren't defined:
+ # undef _POSIX_V6_ILP32_OFF32
+ # undef _POSIX_V6_ILP32_OFFBIG
+ # undef _XBS5_ILP32_OFF32
+ # undef _XBS5_ILP32_OFFBIG
+ and users need to check at runtime. */
+
+/* We also have no use (for now) for an environment with bigger pointers
+ and offsets. */
+# define _POSIX_V6_LPBIG_OFFBIG -1
+# define _XBS5_LPBIG_OFFBIG -1
+
+/* By default we have 64-bit wide `long int', pointers and `off_t'. */
+# define _POSIX_V6_LP64_OFF64 1
+# define _XBS5_LP64_OFF64 1
+
+#else /* __WORDSIZE == 32 */
+
+/* By default we have 32-bit wide `int', `long int', pointers and `off_t'
+ and all platforms support LFS. */
+# define _POSIX_V6_ILP32_OFF32 1
+# define _POSIX_V6_ILP32_OFFBIG 1
+# define _XBS5_ILP32_OFF32 1
+# define _XBS5_ILP32_OFFBIG 1
+
+/* We optionally provide an environment with the above size but an 64-bit
+ side `off_t'. Therefore we don't define _XBS5_ILP32_OFFBIG. */
+
+/* Environments with 64-bit wide pointers can be provided,
+ so these macros aren't defined:
+ # undef _POSIX_V6_LP64_OFF64
+ # undef _POSIX_V6_LPBIG_OFFBIG
+ # undef _XBS5_LP64_OFF64
+ # undef _XBS5_LPBIG_OFFBIG
+ and sysconf tests for it at runtime. */
+
+#endif /* __WORDSIZE == 32 */
+
+#define __ILP32_OFF32_CFLAGS "-m32"
+#define __ILP32_OFFBIG_CFLAGS "-m32 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+#define __ILP32_OFF32_LDFLAGS "-m32"
+#define __ILP32_OFFBIG_LDFLAGS "-m32"
+#define __LP64_OFF64_CFLAGS "-m64"
+#define __LP64_OFF64_LDFLAGS "-m64"
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/bits/fcntl.h b/libc/sysdeps/unix/sysv/linux/x86_64/bits/fcntl.h
new file mode 100644
index 000000000..4f10f2222
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/bits/fcntl.h
@@ -0,0 +1,250 @@
+/* O_*, F_*, FD_* bit values for Linux/x86-64.
+ Copyright (C) 2001, 2002, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <sys/types.h>
+#include <bits/wordsize.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+
+
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on an ext2 file system */
+#define O_ACCMODE 0003
+#define O_RDONLY 00
+#define O_WRONLY 01
+#define O_RDWR 02
+#define O_CREAT 0100 /* not fcntl */
+#define O_EXCL 0200 /* not fcntl */
+#define O_NOCTTY 0400 /* not fcntl */
+#define O_TRUNC 01000 /* not fcntl */
+#define O_APPEND 02000
+#define O_NONBLOCK 04000
+#define O_NDELAY O_NONBLOCK
+#define O_SYNC 010000
+#define O_FSYNC O_SYNC
+#define O_ASYNC 020000
+
+#ifdef __USE_GNU
+# define O_DIRECT 040000 /* Direct disk access. */
+# define O_DIRECTORY 0200000 /* Must be a directory. */
+# define O_NOFOLLOW 0400000 /* Do not follow links. */
+# define O_NOATIME 01000000 /* Do not set atime. */
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+# if __WORDSIZE == 64
+# define O_LARGEFILE 0
+# else
+# define O_LARGEFILE 0100000
+# endif
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#if __WORDSIZE == 64
+# define F_GETLK 5 /* Get record locking info. */
+# define F_SETLK 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW 7 /* Set record locking info (blocking). */
+/* Not necessary, we always have 64-bit offsets. */
+# define F_GETLK64 5 /* Get record locking info. */
+# define F_SETLK64 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW64 7 /* Set record locking info (blocking). */
+#else
+# ifndef __USE_FILE_OFFSET64
+# define F_GETLK 5 /* Get record locking info. */
+# define F_SETLK 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW 7 /* Set record locking info (blocking). */
+# else
+# define F_GETLK F_GETLK64 /* Get record locking info. */
+# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
+# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
+# endif
+# define F_GETLK64 12 /* Get record locking info. */
+# define F_SETLK64 13 /* Set record locking info (non-blocking). */
+# define F_SETLKW64 14 /* Set record locking info (blocking). */
+#endif
+
+#if defined __USE_BSD || defined __USE_UNIX98
+# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */
+# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+#endif
+
+/* For F_[GET|SET]FD. */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
+#define F_RDLCK 0 /* Read lock. */
+#define F_WRLCK 1 /* Write lock. */
+#define F_UNLCK 2 /* Remove lock. */
+
+/* For old implementation of bsd flock(). */
+#define F_EXLCK 4 /* or 3 */
+#define F_SHLCK 8 /* or 4 */
+
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation. */
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#endif
+
+struct flock
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+#ifndef __USE_FILE_OFFSET64
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+#else
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+#endif
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+
+#ifdef __USE_LARGEFILE64
+struct flock64
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+#endif
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+#endif
+
+
+#ifdef __USE_GNU
+/* Flags for SYNC_FILE_RANGE. */
+# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
+ in the range before performing the
+ write. */
+# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
+ dirty pages in the range which are
+ not presently under writeback. */
+# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
+ the range after performing the
+ write. */
+
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+#endif
+
+__BEGIN_DECLS
+
+#ifdef __USE_GNU
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+
+/* Selective file content synch'ing. */
+extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
+ unsigned int __flags);
+
+
+/* Splice address range into a pipe. */
+extern int vmsplice (int __fdout, const struct iovec *__iov, size_t __count,
+ unsigned int __flags);
+
+/* Splice two files together. */
+extern int splice (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+/* In-kernel implementation of tee for pipe buffers. */
+extern int tee (int __fdin, int __fdout, size_t __len, unsigned int __flags)
+ __THROW;
+
+#endif
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/bits/mman.h b/libc/sysdeps/unix/sysv/linux/x86_64/bits/mman.h
new file mode 100644
index 000000000..535c9edcf
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/bits/mman.h
@@ -0,0 +1,104 @@
+/* Definitions for POSIX memory map interface. Linux/x86_64 version.
+ Copyright (C) 2001, 2003, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MMAN_H
+# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead."
+#endif
+
+/* The following definitions basically come from the kernel headers.
+ But the kernel header is not namespace clean. */
+
+
+/* Protections are chosen from these bits, OR'd together. The
+ implementation does not necessarily support PROT_EXEC or PROT_WRITE
+ without PROT_READ. The only guarantees are that no writing will be
+ allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
+
+#define PROT_READ 0x1 /* Page can be read. */
+#define PROT_WRITE 0x2 /* Page can be written. */
+#define PROT_EXEC 0x4 /* Page can be executed. */
+#define PROT_NONE 0x0 /* Page can not be accessed. */
+#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
+ growsdown vma (mprotect only). */
+#define PROT_GROWSUP 0x02000000 /* Extend change to start of
+ growsup vma (mprotect only). */
+
+/* Sharing types (must choose one and only one of these). */
+#define MAP_SHARED 0x01 /* Share changes. */
+#define MAP_PRIVATE 0x02 /* Changes are private. */
+#ifdef __USE_MISC
+# define MAP_TYPE 0x0f /* Mask for type of mapping. */
+#endif
+
+/* Other flags. */
+#define MAP_FIXED 0x10 /* Interpret addr exactly. */
+#ifdef __USE_MISC
+# define MAP_FILE 0
+# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
+# define MAP_ANON MAP_ANONYMOUS
+# define MAP_32BIT 0x40 /* Only give out 32-bit addresses. */
+#endif
+
+/* These are Linux-specific. */
+#ifdef __USE_MISC
+# define MAP_GROWSDOWN 0x00100 /* Stack-like segment. */
+# define MAP_DENYWRITE 0x00800 /* ETXTBSY */
+# define MAP_EXECUTABLE 0x01000 /* Mark it as an executable. */
+# define MAP_LOCKED 0x02000 /* Lock the mapping. */
+# define MAP_NORESERVE 0x04000 /* Don't check for reservations. */
+# define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */
+# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
+#endif
+
+/* Flags to `msync'. */
+#define MS_ASYNC 1 /* Sync memory asynchronously. */
+#define MS_SYNC 4 /* Synchronous memory sync. */
+#define MS_INVALIDATE 2 /* Invalidate the caches. */
+
+/* Flags for `mlockall'. */
+#define MCL_CURRENT 1 /* Lock all currently mapped pages. */
+#define MCL_FUTURE 2 /* Lock all additions to address
+ space. */
+
+/* Flags for `mremap'. */
+#ifdef __USE_GNU
+# define MREMAP_MAYMOVE 1
+# define MREMAP_FIXED 2
+#endif
+
+/* Advice to `madvise'. */
+#ifdef __USE_BSD
+# define MADV_NORMAL 0 /* No further special treatment. */
+# define MADV_RANDOM 1 /* Expect random page references. */
+# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define MADV_WILLNEED 3 /* Will need these pages. */
+# define MADV_DONTNEED 4 /* Don't need these pages. */
+# define MADV_REMOVE 9 /* Remove these pages and resources. */
+# define MADV_DONTFORK 10 /* Do not inherit across fork. */
+# define MADV_DOFORK 11 /* Do inherit across fork. */
+#endif
+
+/* The POSIX people had to invent similar names for the same things. */
+#ifdef __USE_XOPEN2K
+# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/bits/msq.h b/libc/sysdeps/unix/sysv/linux/x86_64/bits/msq.h
new file mode 100644
index 000000000..422218a5f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/bits/msq.h
@@ -0,0 +1,83 @@
+/* Copyright (C) 1995, 1996, 1997, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_MSG_H
+# error "Never use <bits/msq.h> directly; include <sys/msg.h> instead."
+#endif
+
+#include <bits/types.h>
+#include <bits/wordsize.h>
+
+/* Define options for message queue functions. */
+#define MSG_NOERROR 010000 /* no error if message is too big */
+#ifdef __USE_GNU
+# define MSG_EXCEPT 020000 /* recv any msg except of specified type */
+#endif
+
+/* Types used in the structure definition. */
+typedef unsigned long int msgqnum_t;
+typedef unsigned long int msglen_t;
+
+/* Structure of record for one message inside the kernel.
+ The type `struct msg' is opaque. */
+struct msqid_ds
+{
+ struct ipc_perm msg_perm; /* structure describing operation permission */
+ __time_t msg_stime; /* time of last msgsnd command */
+#if __WORDSIZE == 32
+ unsigned long int __unused1;
+#endif
+ __time_t msg_rtime; /* time of last msgrcv command */
+#if __WORDSIZE == 32
+ unsigned long int __unused2;
+#endif
+ __time_t msg_ctime; /* time of last change */
+#if __WORDSIZE == 32
+ unsigned long int __unused3;
+#endif
+ unsigned long int __msg_cbytes; /* current number of bytes on queue */
+ msgqnum_t msg_qnum; /* number of messages currently on queue */
+ msglen_t msg_qbytes; /* max number of bytes allowed on queue */
+ __pid_t msg_lspid; /* pid of last msgsnd() */
+ __pid_t msg_lrpid; /* pid of last msgrcv() */
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+};
+
+#ifdef __USE_MISC
+
+# define msg_cbytes __msg_cbytes
+
+/* ipcs ctl commands */
+# define MSG_STAT 11
+# define MSG_INFO 12
+
+/* buffer for msgctl calls IPC_INFO, MSG_INFO */
+struct msginfo
+ {
+ int msgpool;
+ int msgmap;
+ int msgmax;
+ int msgmnb;
+ int msgmni;
+ int msgssz;
+ int msgtql;
+ unsigned short int msgseg;
+ };
+
+#endif /* __USE_MISC */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/bits/sem.h b/libc/sysdeps/unix/sysv/linux/x86_64/bits/sem.h
new file mode 100644
index 000000000..9b1d993ee
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/bits/sem.h
@@ -0,0 +1,87 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SEM_H
+# error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
+#endif
+
+#include <sys/types.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 */
+ unsigned long int __unused1;
+ __time_t sem_ctime; /* last time changed by semctl() */
+ unsigned long int __unused2;
+ unsigned long int sem_nsems; /* number of semaphores in set */
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+};
+
+/* The user should define a union like the following to use it for arguments
+ for `semctl'.
+
+ union semun
+ {
+ int val; <= value for SETVAL
+ struct semid_ds *buf; <= buffer for IPC_STAT & IPC_SET
+ unsigned short int *array; <= array for GETALL & SETALL
+ struct seminfo *__buf; <= buffer for IPC_INFO
+ };
+
+ Previous versions of this file used to define this union but this is
+ incorrect. One can test the macro _SEM_SEMUN_UNDEFINED to see whether
+ one must define the union or not. */
+#define _SEM_SEMUN_UNDEFINED 1
+
+#ifdef __USE_MISC
+
+/* ipcs ctl cmds */
+# define SEM_STAT 18
+# define SEM_INFO 19
+
+struct seminfo
+{
+ int semmap;
+ int semmni;
+ int semmns;
+ int semmnu;
+ int semmsl;
+ int semopm;
+ int semume;
+ int semusz;
+ int semvmx;
+ int semaem;
+};
+
+#endif /* __USE_MISC */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/bits/shm.h b/libc/sysdeps/unix/sysv/linux/x86_64/bits/shm.h
new file mode 100644
index 000000000..3d8c05d21
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/bits/shm.h
@@ -0,0 +1,110 @@
+/* Copyright (C) 1995, 1996, 1997, 2000, 2002, 2004
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_SHM_H
+# error "Never include <bits/shm.h> directly; use <sys/shm.h> instead."
+#endif
+
+#include <bits/types.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 */
+
+/* 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 set of semaphores. */
+struct shmid_ds
+ {
+ struct ipc_perm shm_perm; /* operation permission struct */
+ size_t shm_segsz; /* size of segment in bytes */
+ __time_t shm_atime; /* time of last shmat() */
+#if __WORDSIZE == 32
+ unsigned long int __unused1;
+#endif
+ __time_t shm_dtime; /* time of last shmdt() */
+#if __WORDSIZE == 32
+ unsigned long int __unused2;
+#endif
+ __time_t shm_ctime; /* time of last change by shmctl() */
+#if __WORDSIZE == 32
+ unsigned long int __unused3;
+#endif
+ __pid_t shm_cpid; /* pid of creator */
+ __pid_t shm_lpid; /* pid of last shmop */
+ shmatt_t shm_nattch; /* number of current attaches */
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+ };
+
+#ifdef __USE_MISC
+
+/* ipcs ctl commands */
+# define SHM_STAT 13
+# define SHM_INFO 14
+
+/* shm_mode upper byte flags */
+# define SHM_DEST 01000 /* segment will be destroyed on last detach */
+# define SHM_LOCKED 02000 /* segment will not be swapped */
+# define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */
+# define SHM_NORESERVE 010000 /* don't check for reservations */
+
+struct shminfo
+ {
+ unsigned long int shmmax;
+ unsigned long int shmmin;
+ unsigned long int shmmni;
+ unsigned long int shmseg;
+ unsigned long int shmall;
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+ };
+
+struct shm_info
+ {
+ int used_ids;
+ unsigned long int shm_tot; /* total allocated shm */
+ unsigned long int shm_rss; /* total resident shm */
+ unsigned long int shm_swp; /* total swapped shm */
+ unsigned long int swap_attempts;
+ unsigned long int swap_successes;
+ };
+
+#endif /* __USE_MISC */
+
+__END_DECLS
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/bits/sigcontext.h b/libc/sysdeps/unix/sysv/linux/x86_64/bits/sigcontext.h
new file mode 100644
index 000000000..c0d5fe72d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/bits/sigcontext.h
@@ -0,0 +1,159 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _BITS_SIGCONTEXT_H
+#define _BITS_SIGCONTEXT_H 1
+
+#if !defined _SIGNAL_H && !defined _SYS_UCONTEXT_H
+# error "Never use <bits/sigcontext.h> directly; include <signal.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+struct _fpreg
+{
+ unsigned short significand[4];
+ unsigned short exponent;
+};
+
+struct _fpxreg
+{
+ unsigned short significand[4];
+ unsigned short exponent;
+ unsigned short padding[3];
+};
+
+struct _xmmreg
+{
+ __uint32_t element[4];
+};
+
+
+
+#if __WORDSIZE == 32
+
+struct _fpstate
+{
+ /* Regular FPU environment. */
+ __uint32_t cw;
+ __uint32_t sw;
+ __uint32_t tag;
+ __uint32_t ipoff;
+ __uint32_t cssel;
+ __uint32_t dataoff;
+ __uint32_t datasel;
+ struct _fpreg _st[8];
+ unsigned short status;
+ unsigned short magic;
+
+ /* FXSR FPU environment. */
+ __uint32_t _fxsr_env[6];
+ __uint32_t mxcsr;
+ __uint32_t reserved;
+ struct _fpxreg _fxsr_st[8];
+ struct _xmmreg _xmm[8];
+ __uint32_t padding[56];
+};
+
+#ifndef sigcontext_struct
+/* Kernel headers before 2.1.1 define a struct sigcontext_struct, but
+ we need sigcontext. Some packages have come to rely on
+ sigcontext_struct being defined on 32-bit x86, so define this for
+ their benefit. */
+# define sigcontext_struct sigcontext
+#endif
+
+struct sigcontext
+{
+ unsigned short gs, __gsh;
+ unsigned short fs, __fsh;
+ unsigned short es, __esh;
+ unsigned short ds, __dsh;
+ unsigned long edi;
+ unsigned long esi;
+ unsigned long ebp;
+ unsigned long esp;
+ unsigned long ebx;
+ unsigned long edx;
+ unsigned long ecx;
+ unsigned long eax;
+ unsigned long trapno;
+ unsigned long err;
+ unsigned long eip;
+ unsigned short cs, __csh;
+ unsigned long eflags;
+ unsigned long esp_at_signal;
+ unsigned short ss, __ssh;
+ struct _fpstate * fpstate;
+ unsigned long oldmask;
+ unsigned long cr2;
+};
+
+#else /* __WORDSIZE == 64 */
+
+struct _fpstate
+{
+ /* FPU environment matching the 64-bit FXSAVE layout. */
+ __uint16_t cwd;
+ __uint16_t swd;
+ __uint16_t ftw;
+ __uint16_t fop;
+ __uint64_t rip;
+ __uint64_t rdp;
+ __uint32_t mxcsr;
+ __uint32_t mxcr_mask;
+ struct _fpxreg _st[8];
+ struct _xmmreg _xmm[16];
+ __uint32_t padding[24];
+};
+
+struct sigcontext
+{
+ unsigned long r8;
+ unsigned long r9;
+ unsigned long r10;
+ unsigned long r11;
+ unsigned long r12;
+ unsigned long r13;
+ unsigned long r14;
+ unsigned long r15;
+ unsigned long rdi;
+ unsigned long rsi;
+ unsigned long rbp;
+ unsigned long rbx;
+ unsigned long rdx;
+ unsigned long rax;
+ unsigned long rcx;
+ unsigned long rsp;
+ unsigned long rip;
+ unsigned long eflags;
+ unsigned short cs;
+ unsigned short gs;
+ unsigned short fs;
+ unsigned short __pad0;
+ unsigned long err;
+ unsigned long trapno;
+ unsigned long oldmask;
+ unsigned long cr2;
+ struct _fpstate * fpstate;
+ unsigned long __reserved1 [8];
+};
+
+#endif /* __WORDSIZE == 64 */
+
+#endif /* _BITS_SIGCONTEXT_H */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/bits/stat.h b/libc/sysdeps/unix/sysv/linux/x86_64/bits/stat.h
new file mode 100644
index 000000000..e756d7e8c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/bits/stat.h
@@ -0,0 +1,203 @@
+/* Copyright (C) 1999,2000,2001,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_STAT_H
+# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
+#endif
+
+/* Versions of the `struct stat' data structure. */
+#define _STAT_VER_KERNEL 0
+
+#if __WORDSIZE == 32
+# define _STAT_VER_SVR4 2
+# define _STAT_VER_LINUX 3
+
+/* i386 versions of the `xmknod' interface. */
+# define _MKNOD_VER_LINUX 1
+# define _MKNOD_VER_SVR4 2
+# define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
+#else
+# define _STAT_VER_LINUX 1
+
+/* x86-64 versions of the `xmknod' interface. */
+# define _MKNOD_VER_LINUX 0
+#endif
+
+#define _STAT_VER _STAT_VER_LINUX
+
+struct stat
+ {
+ __dev_t st_dev; /* Device. */
+#if __WORDSIZE == 32
+ unsigned short int __pad1;
+#endif
+#if __WORDSIZE == 64 || !defined __USE_FILE_OFFSET64
+ __ino_t st_ino; /* File serial number. */
+#else
+ __ino_t __st_ino; /* 32bit file serial number. */
+#endif
+#if __WORDSIZE == 32
+ __mode_t st_mode; /* File mode. */
+ __nlink_t st_nlink; /* Link count. */
+#else
+ __nlink_t st_nlink; /* Link count. */
+ __mode_t st_mode; /* File mode. */
+#endif
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+#if __WORDSIZE == 64
+ int pad0;
+#endif
+ __dev_t st_rdev; /* Device number, if device. */
+#if __WORDSIZE == 32
+ unsigned short int __pad2;
+#endif
+#if __WORDSIZE == 64 || !defined __USE_FILE_OFFSET64
+ __off_t st_size; /* Size of file, in bytes. */
+#else
+ __off64_t st_size; /* Size of file, in bytes. */
+#endif
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+#if __WORDSIZE == 64 || !defined __USE_FILE_OFFSET64
+ __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
+#else
+ __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
+#endif
+#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
+#if __WORDSIZE == 64
+ long int __unused[3];
+#else
+# ifndef __USE_FILE_OFFSET64
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+# else
+ __ino64_t st_ino; /* File serial number. */
+# endif
+#endif
+ };
+
+#ifdef __USE_LARGEFILE64
+/* Note stat64 has the same shape as stat for x86-64. */
+struct stat64
+ {
+ __dev_t st_dev; /* Device. */
+#if __WORDSIZE == 64
+ __ino64_t st_ino; /* File serial number. */
+ __nlink_t st_nlink; /* Link count. */
+ __mode_t st_mode; /* File mode. */
+#else
+ unsigned int __pad1;
+ __ino_t __st_ino; /* 32bit file serial number. */
+ __mode_t st_mode; /* File mode. */
+ __nlink_t st_nlink; /* Link count. */
+#endif
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+#if __WORDSIZE == 64
+ int pad0;
+ __dev_t st_rdev; /* Device number, if device. */
+ __off_t st_size; /* Size of file, in bytes. */
+#else
+ __dev_t st_rdev; /* Device number, if device. */
+ unsigned int __pad2;
+ __off64_t st_size; /* Size of file, in bytes. */
+#endif
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ __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. */
+# 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
+#if __WORDSIZE == 64
+ long int __unused[3];
+#else
+ __ino64_t st_ino; /* File serial number. */
+#endif
+ };
+#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. */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/brk.c b/libc/sysdeps/unix/sysv/linux/x86_64/brk.c
new file mode 100644
index 000000000..8b18c4dbb
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/brk.c
@@ -0,0 +1,42 @@
+/* brk system call for Linux/x86_64.
+ Copyright (C) 1995, 1996, 2000, 2001, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sysdep.h>
+
+/* This must be initialized data because commons can't have aliases. */
+void *__curbrk = 0;
+
+int
+__brk (void *addr)
+{
+ void *newbrk;
+
+ __curbrk = newbrk = (void *) INLINE_SYSCALL (brk, 1, addr);
+
+ if (newbrk < addr)
+ {
+ __set_errno (ENOMEM);
+ return -1;
+ }
+
+ return 0;
+}
+weak_alias (__brk, brk)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/clone.S b/libc/sysdeps/unix/sysv/linux/x86_64/clone.S
new file mode 100644
index 000000000..8a12b0903
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/clone.S
@@ -0,0 +1,120 @@
+/* Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* clone() is even more special than fork() as it mucks with stacks
+ and invokes a function in the right context after its all over. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <asm-syntax.h>
+#include <bp-sym.h>
+#include <bp-asm.h>
+
+#define CLONE_VM 0x00000100
+#define CLONE_THREAD 0x00010000
+
+/* The userland implementation is:
+ int clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg),
+ the kernel entry is:
+ int clone (long flags, void *child_stack).
+
+ The parameters are passed in register and on the stack from userland:
+ rdi: fn
+ rsi: child_stack
+ rdx: flags
+ rcx: arg
+ r8d: TID field in parent
+ r9d: thread pointer
+%esp+8: TID field in child
+
+ The kernel expects:
+ rax: system call number
+ rdi: flags
+ rsi: child_stack
+ rdx: TID field in parent
+ r10: TID field in child
+ r8: thread pointer */
+
+
+ .text
+ENTRY (BP_SYM (__clone))
+ /* Sanity check arguments. */
+ movq $-EINVAL,%rax
+ testq %rdi,%rdi /* no NULL function pointers */
+ jz SYSCALL_ERROR_LABEL
+ testq %rsi,%rsi /* no NULL stack pointers */
+ jz SYSCALL_ERROR_LABEL
+
+ /* Insert the argument onto the new stack. */
+ subq $16,%rsi
+ movq %rcx,8(%rsi)
+
+ /* Save the function pointer. It will be popped off in the
+ child in the ebx frobbing below. */
+ movq %rdi,0(%rsi)
+
+ /* Do the system call. */
+ movq %rdx, %rdi
+ movq %r8, %rdx
+ movq %r9, %r8
+ movq 8(%rsp), %r10
+ movl $SYS_ify(clone),%eax
+
+ /* End FDE now, because in the child the unwind info will be
+ wrong. */
+ cfi_endproc;
+ syscall
+
+ testq %rax,%rax
+ jl SYSCALL_ERROR_LABEL
+ jz L(thread_start)
+
+L(pseudo_end):
+ ret
+
+L(thread_start):
+ /* Clear the frame pointer. The ABI suggests this be done, to mark
+ the outermost frame obviously. */
+ xorl %ebp, %ebp
+
+#ifdef RESET_PID
+ testq $CLONE_THREAD, %rdi
+ jne 1f
+ testq $CLONE_VM, %rdi
+ movl $-1, %eax
+ jne 2f
+ movl $SYS_ify(getpid), %eax
+ syscall
+2: movl %eax, %fs:PID
+ movl %eax, %fs:TID
+1:
+#endif
+
+ /* Set up arguments for the function call. */
+ popq %rax /* Function to call. */
+ popq %rdi /* Argument. */
+ call *%rax
+ /* Call exit with return value from function call. */
+ movq %rax, %rdi
+ call HIDDEN_JUMPTARGET (_exit)
+
+ cfi_startproc;
+PSEUDO_END (BP_SYM (__clone))
+
+weak_alias (BP_SYM (__clone), BP_SYM (clone))
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/dl-cache.h b/libc/sysdeps/unix/sysv/linux/x86_64/dl-cache.h
new file mode 100644
index 000000000..cb647abf8
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/dl-cache.h
@@ -0,0 +1,25 @@
+/* Support for reading /etc/ld.so.cache files written by Linux ldconfig.
+ Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define _DL_CACHE_DEFAULT_ID 0x303
+
+#define _dl_cache_check_flags(flags) \
+ ((flags) == _DL_CACHE_DEFAULT_ID)
+
+#include <sysdeps/unix/sysv/linux/sparc/dl-cache.h>
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.c b/libc/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.c
new file mode 100644
index 000000000..6662a94d0
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.c
@@ -0,0 +1,5 @@
+#ifdef IS_IN_ldconfig
+# include <sysdeps/i386/dl-procinfo.c>
+#else
+# include <sysdeps/generic/dl-procinfo.c>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.h b/libc/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.h
new file mode 100644
index 000000000..31455204c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.h
@@ -0,0 +1,5 @@
+#ifdef IS_IN_ldconfig
+# include <sysdeps/unix/sysv/linux/i386/dl-procinfo.h>
+#else
+# include <sysdeps/generic/dl-procinfo.h>
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/get_clockfreq.c b/libc/sysdeps/unix/sysv/linux/x86_64/get_clockfreq.c
new file mode 100644
index 000000000..a58d40a9c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/get_clockfreq.c
@@ -0,0 +1 @@
+#include "../i386/get_clockfreq.c"
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/getcontext.S b/libc/sysdeps/unix/sysv/linux/x86_64/getcontext.S
new file mode 100644
index 000000000..4bbc7a4d2
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/getcontext.S
@@ -0,0 +1,88 @@
+/* Save current context.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Jaeger <aj@suse.de>, 2002.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+/* int __getcontext (ucontext_t *ucp)
+
+ Saves the machine context in UCP such that when it is activated,
+ it appears as if __getcontext() returned again.
+
+ This implementation is intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to save anything
+ other than the PRESERVED state. */
+
+
+ENTRY(__getcontext)
+ /* Save the preserved registers, the registers used for passing
+ args, and the return address. */
+ movq %rbx, oRBX(%rdi)
+ movq %rbp, oRBP(%rdi)
+ movq %r12, oR12(%rdi)
+ movq %r13, oR13(%rdi)
+ movq %r14, oR14(%rdi)
+ movq %r15, oR15(%rdi)
+
+ movq %rdi, oRDI(%rdi)
+ movq %rsi, oRSI(%rdi)
+ movq %rdx, oRDX(%rdi)
+ movq %rcx, oRCX(%rdi)
+ movq %r8, oR8(%rdi)
+ movq %r9, oR9(%rdi)
+
+ movq (%rsp), %rcx
+ movq %rcx, oRIP(%rdi)
+ leaq 8(%rsp), %rcx /* Exclude the return address. */
+ movq %rcx, oRSP(%rdi)
+
+ /* We have separate floating-point register content memory on the
+ stack. We use the __fpregs_mem block in the context. Set the
+ links up correctly. */
+
+ leaq oFPREGSMEM(%rdi), %rcx
+ movq %rcx, oFPREGS(%rdi)
+ /* Save the floating-point environment. */
+ fnstenv (%rcx)
+ stmxcsr oMXCSR(%rdi)
+
+ /* Save the current signal mask with
+ rt_sigprocmask (SIG_BLOCK, NULL, set,_NSIG/8). */
+ leaq oSIGMASK(%rdi), %rdx
+ xorl %esi,%esi
+#if SIG_BLOCK == 0
+ xorl %edi, %edi
+#else
+ movl $SIG_BLOCK, %edi
+#endif
+ movl $_NSIG8,%r10d
+ movl $__NR_rt_sigprocmask, %eax
+ syscall
+ cmpq $-4095, %rax /* Check %rax for error. */
+ jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
+
+ /* All done, return 0 for success. */
+ xorl %eax, %eax
+L(pseudo_end):
+ ret
+PSEUDO_END(__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/gettimeofday.S b/libc/sysdeps/unix/sysv/linux/x86_64/gettimeofday.S
new file mode 100644
index 000000000..84a99b040
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/gettimeofday.S
@@ -0,0 +1,44 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+/* For the calculation see asm/vsyscall.h. */
+#define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
+
+
+ENTRY (__gettimeofday)
+ /* Align stack. */
+ sub $0x8, %rsp
+ cfi_adjust_cfa_offset(8)
+ movq $VSYSCALL_ADDR_vgettimeofday, %rax
+ callq *%rax
+ /* Check error return. */
+ cmpl $-4095, %eax
+ jae SYSCALL_ERROR_LABEL
+
+L(pseudo_end):
+ add $0x8, %rsp
+ cfi_adjust_cfa_offset(-8)
+ ret
+PSEUDO_END(__gettimeofday)
+
+strong_alias (__gettimeofday, __gettimeofday_internal)
+weak_alias (__gettimeofday, gettimeofday)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/kernel_stat.h b/libc/sysdeps/unix/sysv/linux/x86_64/kernel_stat.h
new file mode 100644
index 000000000..ef11dc94d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/kernel_stat.h
@@ -0,0 +1,21 @@
+/* Definition of `struct stat' used in the kernel.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define STAT_IS_KERNEL_STAT 1
+#define XSTAT_IS_XSTAT64 1
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/ldconfig.h b/libc/sysdeps/unix/sysv/linux/x86_64/ldconfig.h
new file mode 100644
index 000000000..f7f64eb1e
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/ldconfig.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/generic/ldconfig.h>
+
+#define SYSDEP_KNOWN_INTERPRETER_NAMES \
+ { "/lib/ld-linux.so.2", FLAG_ELF_LIBC6 }, \
+ { "/lib64/ld-linux-x86-64.so.2", FLAG_ELF_LIBC6 },
+#define SYSDEP_KNOWN_LIBRARY_NAMES \
+ { "libc.so.6", FLAG_ELF_LIBC6 }, \
+ { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/ldd-rewrite.sed b/libc/sysdeps/unix/sysv/linux/x86_64/ldd-rewrite.sed
new file mode 100644
index 000000000..3f1530d31
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/ldd-rewrite.sed
@@ -0,0 +1,3 @@
+/LD_TRACE_LOADED_OBJECTS=1/a\
+add_env="$add_env LD_LIBRARY_VERSION=\\$verify_out"
+s_^\(RTLDLIST=\)\(.*lib\)\(\|64\)\(/[^/]*\)\(-x86-64\)\(\.so\.[0-9.]*\)[ ]*$_\1"\2\4\6 \264\4\5\6"_
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/makecontext.c b/libc/sysdeps/unix/sysv/linux/x86_64/makecontext.c
new file mode 100644
index 000000000..5deea7d1b
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/makecontext.c
@@ -0,0 +1,113 @@
+/* Create new context.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Jaeger <aj@suse.de>, 2002.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+#include "ucontext_i.h"
+
+/* This implementation can handle any ARGC value but only
+ normal integer parameters.
+ makecontext sets up a stack and the registers for the
+ user context. The stack looks like this:
+ +-----------------------+
+ | next context |
+ +-----------------------+
+ | parameter 7-n |
+ +-----------------------+
+ | trampoline address |
+ %rsp -> +-----------------------+
+
+ The registers are set up like this:
+ %rdi,%rsi,%rdx,%rcx,%r8,%r9: parameter 1 to 6
+ %rbx : address of next context
+ %rsp : stack pointer.
+*/
+
+/* XXX: This implementation currently only handles integer arguments.
+ To handle long int and pointer arguments the va_arg arguments needs
+ to be changed to long and also the stdlib/tst-setcontext.c file needs
+ to be changed to pass long arguments to makecontext. */
+
+
+void
+__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
+{
+ extern void __start_context (void);
+ unsigned long int *sp, idx_uc_link;
+ va_list ap;
+ int i;
+
+ /* Generate room on stack for parameter if needed and uc_link. */
+ sp = (unsigned long int *) ((uintptr_t) ucp->uc_stack.ss_sp
+ + ucp->uc_stack.ss_size);
+ sp -= (argc > 6 ? argc - 6 : 0) + 1;
+ /* Align stack and make space for trampoline address. */
+ sp = (unsigned long int *) ((((uintptr_t) sp) & -16L) - 8);
+
+ idx_uc_link = (argc > 6 ? argc - 6 : 0) + 1;
+
+ /* Setup context ucp. */
+ /* Address to jump to. */
+ ucp->uc_mcontext.gregs[REG_RIP] = (long int) func;
+ /* Setup rbx.*/
+ ucp->uc_mcontext.gregs[REG_RBX] = (long int) &sp[idx_uc_link];
+ ucp->uc_mcontext.gregs[REG_RSP] = (long int) sp;
+
+ /* Setup stack. */
+ sp[0] = (unsigned long int) &__start_context;
+ sp[idx_uc_link] = (unsigned long int) ucp->uc_link;
+
+ va_start (ap, argc);
+ /* Handle arguments. */
+ for (i = 0; i < argc; ++i)
+ switch (i)
+ {
+ case 0:
+ ucp->uc_mcontext.gregs [REG_RDI] = va_arg (ap, int);
+ break;
+ case 1:
+ ucp->uc_mcontext.gregs [REG_RSI] = va_arg (ap, int);
+ break;
+ case 2:
+ ucp->uc_mcontext.gregs [REG_RDX] = va_arg (ap, int);
+ break;
+ case 3:
+ ucp->uc_mcontext.gregs [REG_RCX] = va_arg (ap, int);
+ break;
+ case 4:
+ ucp->uc_mcontext.gregs [REG_R8] = va_arg (ap, int);
+ break;
+ case 5:
+ ucp->uc_mcontext.gregs [REG_R9] = va_arg (ap, int);
+ break;
+ default:
+ /* Put value on stack. */
+ sp[(i - 5)] = va_arg (ap, int);
+ break;
+ }
+ va_end (ap);
+
+}
+
+
+weak_alias (__makecontext, makecontext)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/profil-counter.h b/libc/sysdeps/unix/sysv/linux/x86_64/profil-counter.h
new file mode 100644
index 000000000..0b244175a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/profil-counter.h
@@ -0,0 +1,32 @@
+/* Low-level statistical profiling support function. Linux/x86-64 version.
+ Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <signal.h>
+#include <sigcontextinfo.h>
+
+static void
+profil_counter (int signo, SIGCONTEXT scp)
+{
+ profil_count ((void *) GET_PC (scp));
+
+ /* This is a hack to prevent the compiler from implementing the
+ above function call as a sibcall. The sibcall would overwrite
+ the signal context. */
+ asm volatile ("");
+}
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/readelflib.c b/libc/sysdeps/unix/sysv/linux/x86_64/readelflib.c
new file mode 100644
index 000000000..5a49af3fa
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/readelflib.c
@@ -0,0 +1,62 @@
+/* Copyright (C) 1999, 2001, 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Jaeger <aj@suse.de>, 1999 and
+ Jakub Jelinek <jakub@redhat.com>, 1999.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+int process_elf32_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+int process_elf64_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname,
+ void *file_contents, size_t file_length);
+
+/* Returns 0 if everything is ok, != 0 in case of error. */
+int
+process_elf_file (const char *file_name, const char *lib, int *flag,
+ unsigned int *osversion, char **soname, void *file_contents,
+ size_t file_length)
+{
+ ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
+ int ret;
+
+ if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
+ return process_elf32_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ else
+ {
+ ret = process_elf64_file (file_name, lib, flag, osversion, soname,
+ file_contents, file_length);
+ /* x86-64 64bit libraries are always libc.so.6+. */
+ if (!ret)
+ *flag = FLAG_X8664_LIB64|FLAG_ELF_LIBC6;
+ return ret;
+ }
+}
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf32_file
+#define __ELF_NATIVE_CLASS 32
+#include "elf/readelflib.c"
+
+#undef __ELF_NATIVE_CLASS
+#undef process_elf_file
+#define process_elf_file process_elf64_file
+#define __ELF_NATIVE_CLASS 64
+#include "elf/readelflib.c"
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/recv.c b/libc/sysdeps/unix/sysv/linux/x86_64/recv.c
new file mode 100644
index 000000000..2fa1794d3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/recv.c
@@ -0,0 +1,42 @@
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/socket.h>
+#include <sysdep-cancel.h>
+
+/* Read N bytes into BUF from socket FD.
+ Returns the number read or -1 for errors. */
+
+ssize_t
+__libc_recv (int fd, void *buf, size_t n, int flags)
+{
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (recvfrom, 6, fd, buf, n, flags, NULL, NULL);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = INLINE_SYSCALL (recvfrom, 6, fd, buf, n, flags, NULL, NULL);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+weak_alias (__libc_recv, __recv)
+weak_alias (__recv, recv)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/register-dump.h b/libc/sysdeps/unix/sysv/linux/x86_64/register-dump.h
new file mode 100644
index 000000000..50f589d0d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/register-dump.h
@@ -0,0 +1,346 @@
+/* Dump registers.
+ Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/uio.h>
+#include <stdio-common/_itoa.h>
+
+/* We will print the register dump in this format:
+
+ RAX: XXXXXXXXXXXXXXXX RBX: XXXXXXXXXXXXXXXX RCX: XXXXXXXXXXXXXXXX
+ RDX: XXXXXXXXXXXXXXXX RSI: XXXXXXXXXXXXXXXX RDI: XXXXXXXXXXXXXXXX
+ RBP: XXXXXXXXXXXXXXXX R8 : XXXXXXXXXXXXXXXX R9 : XXXXXXXXXXXXXXXX
+ R10: XXXXXXXXXXXXXXXX R11: XXXXXXXXXXXXXXXX R12: XXXXXXXXXXXXXXXX
+ R13: XXXXXXXXXXXXXXXX R14: XXXXXXXXXXXXXXXX R15: XXXXXXXXXXXXXXXX
+ RSP: XXXXXXXXXXXXXXXX
+
+ RIP: XXXXXXXXXXXXXXXX EFLAGS: XXXXXXXX
+
+ CS: XXXX DS: XXXX ES: XXXX FS: XXXX GS: XXXX
+
+ Trap: XXXXXXXX Error: XXXXXXXX OldMask: XXXXXXXX
+ RSP/SIGNAL: XXXXXXXXXXXXXXXX CR2: XXXXXXXX
+
+ FPUCW: XXXXXXXX FPUSW: XXXXXXXX TAG: XXXXXXXX
+ IPOFF: XXXXXXXX CSSEL: XXXX DATAOFF: XXXXXXXX DATASEL: XXXX
+
+ ST(0) XXXX XXXXXXXXXXXXXXXX ST(1) XXXX XXXXXXXXXXXXXXXX
+ ST(2) XXXX XXXXXXXXXXXXXXXX ST(3) XXXX XXXXXXXXXXXXXXXX
+ ST(4) XXXX XXXXXXXXXXXXXXXX ST(5) XXXX XXXXXXXXXXXXXXXX
+ ST(6) XXXX XXXXXXXXXXXXXXXX ST(7) XXXX XXXXXXXXXXXXXXXX
+
+ mxcsr: XXXX
+ XMM0 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XMM1 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ XMM2 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XMM3 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ XMM4 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XMM5 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ XMM6 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XMM7 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ XMM8 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XMM9 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ XMM10: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XMM11: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ XMM12: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XMM13: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ XMM14: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XMM15: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+
+ */
+
+static void
+hexvalue (unsigned long int value, char *buf, size_t len)
+{
+ char *cp = _itoa_word (value, buf + len, 16, 0);
+ while (cp > buf)
+ *--cp = '0';
+}
+
+static void
+register_dump (int fd, struct ucontext *ctx)
+{
+ char regs[25][16];
+ char fpregs[30][8];
+ char xmmregs[16][32];
+ struct iovec iov[147];
+ size_t nr = 0;
+ int i;
+
+#define ADD_STRING(str) \
+ iov[nr].iov_base = (char *) str; \
+ iov[nr].iov_len = strlen (str); \
+ ++nr
+#define ADD_MEM(str, len) \
+ iov[nr].iov_base = str; \
+ iov[nr].iov_len = len; \
+ ++nr
+
+ /* Generate strings of register contents. */
+ hexvalue (ctx->uc_mcontext.gregs[REG_RAX], regs[0], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_RBX], regs[1], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_RCX], regs[2], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_RDX], regs[3], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_RSI], regs[4], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_RDI], regs[5], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_RBP], regs[6], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_R8], regs[7], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_R9], regs[8], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_R10], regs[9], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_R11], regs[10], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_R12], regs[11], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_R13], regs[12], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_R14], regs[13], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_R15], regs[14], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_RSP], regs[15], 16);
+ hexvalue (ctx->uc_mcontext.gregs[REG_RIP], regs[16], 16);
+
+ hexvalue (ctx->uc_mcontext.gregs[REG_EFL], regs[17], 8);
+ hexvalue (ctx->uc_mcontext.gregs[REG_CSGSFS] & 0xffff, regs[18], 4);
+ hexvalue ((ctx->uc_mcontext.gregs[REG_CSGSFS] >> 16) & 0xffff, regs[19], 4);
+ hexvalue ((ctx->uc_mcontext.gregs[REG_CSGSFS] >> 32) & 0xffff, regs[20], 4);
+ /* hexvalue (ctx->ss, regs[23], 4); */
+ hexvalue (ctx->uc_mcontext.gregs[REG_TRAPNO], regs[21], 8);
+ hexvalue (ctx->uc_mcontext.gregs[REG_ERR], regs[22], 8);
+ hexvalue (ctx->uc_mcontext.gregs[REG_OLDMASK], regs[23], 8);
+ hexvalue (ctx->uc_mcontext.gregs[REG_CR2], regs[24], 8);
+
+ /* Generate the output. */
+ ADD_STRING ("Register dump:\n\n RAX: ");
+ ADD_MEM (regs[0], 16);
+ ADD_STRING (" RBX: ");
+ ADD_MEM (regs[1], 16);
+ ADD_STRING (" RCX: ");
+ ADD_MEM (regs[2], 16);
+ ADD_STRING ("\n RDX: ");
+ ADD_MEM (regs[3], 16);
+ ADD_STRING (" RSI: ");
+ ADD_MEM (regs[4], 16);
+ ADD_STRING (" RDI: ");
+ ADD_MEM (regs[5], 16);
+ ADD_STRING ("\n RBP: ");
+ ADD_MEM (regs[6], 16);
+ ADD_STRING (" R8 : ");
+ ADD_MEM (regs[7], 16);
+ ADD_STRING (" R9 : ");
+ ADD_MEM (regs[8], 16);
+ ADD_STRING ("\n R10: ");
+ ADD_MEM (regs[9], 16);
+ ADD_STRING (" R11: ");
+ ADD_MEM (regs[10], 16);
+ ADD_STRING (" R12: ");
+ ADD_MEM (regs[11], 16);
+ ADD_STRING ("\n R13: ");
+ ADD_MEM (regs[12], 16);
+ ADD_STRING (" R14: ");
+ ADD_MEM (regs[13], 16);
+ ADD_STRING (" R15: ");
+ ADD_MEM (regs[14], 16);
+ ADD_STRING ("\n RSP: ");
+ ADD_MEM (regs[15], 16);
+ ADD_STRING ("\n\n RIP: ");
+ ADD_MEM (regs[16], 16);
+ ADD_STRING (" EFLAGS: ");
+ ADD_MEM (regs[17], 8);
+ ADD_STRING ("\n\n CS: ");
+ ADD_MEM (regs[18], 4);
+ ADD_STRING (" FS: ");
+ ADD_MEM (regs[19], 4);
+ ADD_STRING (" GS: ");
+ ADD_MEM (regs[20], 4);
+ /*
+ ADD_STRING (" SS: ");
+ ADD_MEM (regs[23], 4);
+ */
+ ADD_STRING ("\n\n Trap: ");
+ ADD_MEM (regs[21], 8);
+ ADD_STRING (" Error: ");
+ ADD_MEM (regs[22], 8);
+ ADD_STRING (" OldMask: ");
+ ADD_MEM (regs[23], 8);
+ ADD_STRING (" CR2: ");
+ ADD_MEM (regs[24], 8);
+
+ if (ctx->uc_mcontext.fpregs != NULL)
+ {
+
+ /* Generate output for the FPU control/status registers. */
+ hexvalue (ctx->uc_mcontext.fpregs->cwd, fpregs[0], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->swd, fpregs[1], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->ftw, fpregs[2], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->rip, fpregs[3], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->rdp, fpregs[4], 8);
+
+ ADD_STRING ("\n\n FPUCW: ");
+ ADD_MEM (fpregs[0], 8);
+ ADD_STRING (" FPUSW: ");
+ ADD_MEM (fpregs[1], 8);
+ ADD_STRING (" TAG: ");
+ ADD_MEM (fpregs[2], 8);
+ ADD_STRING ("\n RIP: ");
+ ADD_MEM (fpregs[3], 8);
+ ADD_STRING (" RDP: ");
+ ADD_MEM (fpregs[4], 8);
+
+ /* Now the real FPU registers. */
+ hexvalue (ctx->uc_mcontext.fpregs->_st[0].exponent, fpregs[5], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[0].significand[3] << 16
+ | ctx->uc_mcontext.fpregs->_st[0].significand[2], fpregs[6],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[0].significand[1] << 16
+ | ctx->uc_mcontext.fpregs->_st[0].significand[0], fpregs[7],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[1].exponent, fpregs[8], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[1].significand[3] << 16
+ | ctx->uc_mcontext.fpregs->_st[1].significand[2], fpregs[9],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[1].significand[1] << 16
+ | ctx->uc_mcontext.fpregs->_st[1].significand[0], fpregs[10],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[2].exponent, fpregs[11], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[2].significand[3] << 16
+ | ctx->uc_mcontext.fpregs->_st[2].significand[2], fpregs[12],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[2].significand[1] << 16
+ | ctx->uc_mcontext.fpregs->_st[2].significand[0], fpregs[13],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[3].exponent, fpregs[14], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[3].significand[3] << 16
+ | ctx->uc_mcontext.fpregs->_st[3].significand[2], fpregs[15],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[3].significand[1] << 16
+ | ctx->uc_mcontext.fpregs->_st[3].significand[0], fpregs[16],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[4].exponent, fpregs[17], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[4].significand[3] << 16
+ | ctx->uc_mcontext.fpregs->_st[4].significand[2], fpregs[18],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[4].significand[1] << 16
+ | ctx->uc_mcontext.fpregs->_st[4].significand[0], fpregs[19],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[5].exponent, fpregs[20], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[5].significand[3] << 16
+ | ctx->uc_mcontext.fpregs->_st[5].significand[2], fpregs[21],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[5].significand[1] << 16
+ | ctx->uc_mcontext.fpregs->_st[5].significand[0], fpregs[22],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[6].exponent, fpregs[23], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[6].significand[3] << 16
+ | ctx->uc_mcontext.fpregs->_st[6].significand[2], fpregs[24],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[6].significand[1] << 16
+ | ctx->uc_mcontext.fpregs->_st[6].significand[0], fpregs[25],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[7].exponent, fpregs[26], 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[7].significand[3] << 16
+ | ctx->uc_mcontext.fpregs->_st[7].significand[2], fpregs[27],
+ 8);
+ hexvalue (ctx->uc_mcontext.fpregs->_st[7].significand[1] << 16
+ | ctx->uc_mcontext.fpregs->_st[7].significand[0], fpregs[28],
+ 8);
+
+ hexvalue (ctx->uc_mcontext.fpregs->mxcsr, fpregs[29], 4);
+
+ for (i = 0; i < 16; i++)
+ hexvalue (ctx->uc_mcontext.fpregs->_xmm[i].element[3] << 24
+ | ctx->uc_mcontext.fpregs->_xmm[i].element[2] << 16
+ | ctx->uc_mcontext.fpregs->_xmm[i].element[1] << 8
+ | ctx->uc_mcontext.fpregs->_xmm[i].element[0], xmmregs[i],
+ 32);
+
+
+ ADD_STRING ("\n\n ST(0) ");
+ ADD_MEM (fpregs[5], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[6], 8);
+ ADD_MEM (fpregs[7], 8);
+ ADD_STRING (" ST(1) ");
+ ADD_MEM (fpregs[8], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[9], 8);
+ ADD_MEM (fpregs[10], 8);
+ ADD_STRING ("\n ST(2) ");
+ ADD_MEM (fpregs[11], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[12], 8);
+ ADD_MEM (fpregs[13], 8);
+ ADD_STRING (" ST(3) ");
+ ADD_MEM (fpregs[14], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[15], 8);
+ ADD_MEM (fpregs[16], 8);
+ ADD_STRING ("\n ST(4) ");
+ ADD_MEM (fpregs[17], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[18], 8);
+ ADD_MEM (fpregs[19], 8);
+ ADD_STRING (" ST(5) ");
+ ADD_MEM (fpregs[20], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[21], 8);
+ ADD_MEM (fpregs[22], 8);
+ ADD_STRING ("\n ST(6) ");
+ ADD_MEM (fpregs[23], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[24], 8);
+ ADD_MEM (fpregs[25], 8);
+ ADD_STRING (" ST(7) ");
+ ADD_MEM (fpregs[27], 4);
+ ADD_STRING (" ");
+ ADD_MEM (fpregs[27], 8);
+ ADD_MEM (fpregs[28], 8);
+
+ ADD_STRING ("\n mxcsr: ");
+ ADD_MEM (fpregs[29], 4);
+
+ ADD_STRING ("\n XMM0: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING (" XMM1: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING ("\n XMM2: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING (" XMM3: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING ("\n XMM4: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING (" XMM5: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING ("\n XMM6: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING (" XMM7: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING ("\n XMM8: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING (" XMM9: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING ("\n XMM10: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING (" XMM11: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING ("\n XMM12: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING (" XMM13: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING ("\n XMM14: ");
+ ADD_MEM (xmmregs[0], 32);
+ ADD_STRING (" XMM15: ");
+ ADD_MEM (xmmregs[0], 32);
+
+ }
+
+ ADD_STRING ("\n");
+
+ /* Write the stuff out. */
+ writev (fd, iov, nr);
+}
+
+
+#define REGISTER_DUMP register_dump (fd, ctx)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/send.c b/libc/sysdeps/unix/sysv/linux/x86_64/send.c
new file mode 100644
index 000000000..c484ce69f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/send.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/socket.h>
+#include <sysdep-cancel.h>
+
+/* Send N bytes of BUF to socket FD. Returns the number sent or -1. */
+ssize_t
+__libc_send (int fd, const void *buf, size_t n, int flags)
+{
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (sendto, 6, fd, buf, n, flags, NULL, NULL);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = INLINE_SYSCALL (sendto, 6, fd, buf, n, flags, NULL, NULL);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
+}
+
+weak_alias (__libc_send, __send)
+libc_hidden_weak (__send)
+weak_alias (__send, send)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/setcontext.S b/libc/sysdeps/unix/sysv/linux/x86_64/setcontext.S
new file mode 100644
index 000000000..61fc07f44
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/setcontext.S
@@ -0,0 +1,105 @@
+/* Install given context.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Jaeger <aj@suse.de>, 2002.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+/* int __setcontext (const ucontext_t *ucp)
+
+ Restores the machine context in UCP and thereby resumes execution
+ in that context.
+
+ This implementation is intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to restore anything
+ other than the PRESERVED state. */
+
+ENTRY(__setcontext)
+ /* Save argument since syscall will destroy it. */
+ pushq %rdi
+ cfi_adjust_cfa_offset(8)
+
+ /* Set the signal mask with
+ rt_sigprocmask (SIG_SETMASK, mask, NULL, _NSIG/8). */
+ leaq oSIGMASK(%rdi), %rsi
+ xorl %edx, %edx
+ movl $SIG_SETMASK, %edi
+ movl $_NSIG8,%r10d
+ movl $__NR_rt_sigprocmask, %eax
+ syscall
+ popq %rdi /* Reload %rdi, adjust stack. */
+ cfi_adjust_cfa_offset(-8)
+ cmpq $-4095, %rax /* Check %rax for error. */
+ jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
+
+ /* Restore the floating-point context. Not the registers, only the
+ rest. */
+ movq oFPREGS(%rdi), %rcx
+ fldenv (%rcx)
+ ldmxcsr oMXCSR(%rdi)
+
+
+ /* Load the new stack pointer, the preserved registers and
+ registers used for passing args. */
+ cfi_def_cfa(%rdi, 0)
+ cfi_offset(%rbx,oRBX)
+ cfi_offset(%rbp,oRBP)
+ cfi_offset(%r12,oR12)
+ cfi_offset(%r13,oR13)
+ cfi_offset(%r14,oR14)
+ cfi_offset(%r15,oR15)
+ cfi_offset(%rsp,oRSP)
+ cfi_offset(%rip,oRIP)
+
+ movq oRSP(%rdi), %rsp
+ movq oRBX(%rdi), %rbx
+ movq oRBP(%rdi), %rbp
+ movq oR12(%rdi), %r12
+ movq oR13(%rdi), %r13
+ movq oR14(%rdi), %r14
+ movq oR15(%rdi), %r15
+
+ /* The following ret should return to the address set with
+ getcontext. Therefore push the address on the stack. */
+ movq oRIP(%rdi), %rcx
+ pushq %rcx
+
+ movq oRSI(%rdi), %rsi
+ movq oRDX(%rdi), %rdx
+ movq oRCX(%rdi), %rcx
+ movq oR8(%rdi), %r8
+ movq oR9(%rdi), %r9
+
+ /* Setup finally %rdi. */
+ movq oRDI(%rdi), %rdi
+
+ /* End FDE here, we fall into another context. */
+ cfi_endproc
+ cfi_startproc
+
+ /* Clear rax to indicate success. */
+ xorl %eax, %eax
+
+L(pseudo_end):
+ ret
+PSEUDO_END(__setcontext)
+
+weak_alias (__setcontext, setcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sigaction.c b/libc/sysdeps/unix/sysv/linux/x86_64/sigaction.c
new file mode 100644
index 000000000..d6f4558ce
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sigaction.c
@@ -0,0 +1,112 @@
+/* POSIX.1 `sigaction' call for Linux/x86-64.
+ Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <stddef.h>
+#include <signal.h>
+#include <string.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+#include <kernel-features.h>
+
+/* The difference here is that the sigaction structure used in the
+ kernel is not the same as we use in the libc. Therefore we must
+ translate it here. */
+#include <kernel_sigaction.h>
+
+/* We do not globally define the SA_RESTORER flag so do it here. */
+#define SA_RESTORER 0x04000000
+
+/* Using the hidden attribute here does not change the code but it
+ helps to avoid warnings. */
+#if defined HAVE_HIDDEN && defined HAVE_VISIBILITY_ATTRIBUTE \
+ && !defined HAVE_BROKEN_VISIBILITY_ATTRIBUTE
+extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
+#else
+static void restore_rt (void) asm ("__restore_rt");
+#endif
+
+
+/* If ACT is not NULL, change the action for SIG to *ACT.
+ If OACT is not NULL, put the old action for SIG in *OACT. */
+int
+__libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
+{
+ int result;
+ struct kernel_sigaction kact, koact;
+
+ if (act)
+ {
+ kact.k_sa_handler = act->sa_handler;
+ memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
+ kact.sa_flags = act->sa_flags | SA_RESTORER;
+
+ kact.sa_restorer = &restore_rt;
+ }
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ result = INLINE_SYSCALL (rt_sigaction, 4,
+ sig, act ? __ptrvalue (&kact) : NULL,
+ oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
+ if (oact && result >= 0)
+ {
+ oact->sa_handler = koact.k_sa_handler;
+ memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
+ oact->sa_flags = koact.sa_flags;
+ oact->sa_restorer = koact.sa_restorer;
+ }
+ return result;
+}
+libc_hidden_def (__libc_sigaction)
+
+#ifdef WRAPPER_INCLUDE
+# include WRAPPER_INCLUDE
+#endif
+
+#ifndef LIBC_SIGACTION
+weak_alias (__libc_sigaction, __sigaction)
+libc_hidden_weak (__sigaction)
+weak_alias (__libc_sigaction, sigaction)
+#endif
+
+/* NOTE: Please think twice before making any changes to the bits of
+ code below. GDB needs some intimate knowledge about it to
+ recognize them as signal trampolines, and make backtraces through
+ signal handlers work right. Important are both the names
+ (__restore_rt) and the exact instruction sequence.
+ If you ever feel the need to make any changes, please notify the
+ appropriate GDB maintainer. */
+
+#define RESTORE(name, syscall) RESTORE2 (name, syscall)
+# define RESTORE2(name, syscall) \
+asm \
+ ( \
+ ".align 16\n" \
+ CFI_STARTPROC "\n" \
+ "__" #name ":\n" \
+ " movq $" #syscall ", %rax\n" \
+ " syscall\n" \
+ CFI_ENDPROC "\n" \
+ );
+/* The return code for realtime-signals. */
+RESTORE (restore_rt, __NR_rt_sigreturn)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h b/libc/sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h
new file mode 100644
index 000000000..11493c580
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define SIGCONTEXT siginfo_t *_si, struct ucontext *
+#define SIGCONTEXT_EXTRA_ARGS _si,
+#define GET_PC(ctx) ((void *) (ctx)->uc_mcontext.gregs[REG_RIP])
+#define GET_FRAME(ctx) ((void *) (ctx)->uc_mcontext.gregs[REG_RBP])
+#define GET_STACK(ctx) ((void *) (ctx)->uc_mcontext.gregs[REG_RSP])
+
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sigpending.c b/libc/sysdeps/unix/sysv/linux/x86_64/sigpending.c
new file mode 100644
index 000000000..c7ddb1fbd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sigpending.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/ia64/sigpending.c>
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sigprocmask.c b/libc/sysdeps/unix/sysv/linux/x86_64/sigprocmask.c
new file mode 100644
index 000000000..bc0927f45
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sigprocmask.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/ia64/sigprocmask.c>
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/libc/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
new file mode 100644
index 000000000..fc7996ccd
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
@@ -0,0 +1,123 @@
+/* Save current context and install the given one.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Jaeger <aj@suse.de>, 2002.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+/* int __swapcontext (ucontext_t *oucp, const ucontext_t *ucp);
+
+ Saves the machine context in oucp such that when it is activated,
+ it appears as if __swapcontextt() returned again, restores the
+ machine context in ucp and thereby resumes execution in that
+ context.
+
+ This implementation is intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to save anything
+ other than the PRESERVED state. */
+
+ENTRY(__swapcontext)
+ /* Save the preserved registers, the registers used for passing args,
+ and the return address. */
+ movq %rbx, oRBX(%rdi)
+ movq %rbp, oRBP(%rdi)
+ movq %r12, oR12(%rdi)
+ movq %r13, oR13(%rdi)
+ movq %r14, oR14(%rdi)
+ movq %r15, oR15(%rdi)
+
+ movq %rdi, oRDI(%rdi)
+ movq %rsi, oRSI(%rdi)
+ movq %rdx, oRDX(%rdi)
+ movq %rcx, oRCX(%rdi)
+ movq %r8, oR8(%rdi)
+ movq %r9, oR9(%rdi)
+
+ movq (%rsp), %rcx
+ movq %rcx, oRIP(%rdi)
+ leaq 8(%rsp), %rcx /* Exclude the return address. */
+ movq %rcx, oRSP(%rdi)
+
+ /* We have separate floating-point register content memory on the
+ stack. We use the __fpregs_mem block in the context. Set the
+ links up correctly. */
+ leaq oFPREGSMEM(%rdi), %rcx
+ movq %rcx, oFPREGS(%rdi)
+ /* Save the floating-point environment. */
+ fnstenv (%rcx)
+ stmxcsr oMXCSR(%rdi)
+
+
+ /* The syscall destroys some registers, save them. */
+ movq %rsi, %r12
+
+ /* Save the current signal mask and install the new one with
+ rt_sigprocmask (SIG_BLOCK, newset, oldset,_NSIG/8). */
+ leaq oSIGMASK(%rdi), %rdx
+ leaq oSIGMASK(%rsi), %rsi
+ movl $SIG_SETMASK, %edi
+ movl $_NSIG8,%r10d
+ movl $__NR_rt_sigprocmask, %eax
+ syscall
+ cmpq $-4095, %rax /* Check %rax for error. */
+ jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
+
+ /* Restore destroyed registers. */
+ movq %r12, %rsi
+
+ /* Restore the floating-point context. Not the registers, only the
+ rest. */
+ movq oFPREGS(%rsi), %rcx
+ fldenv (%rcx)
+ ldmxcsr oMXCSR(%rsi)
+
+ /* Load the new stack pointer and the preserved registers. */
+ movq oRSP(%rsi), %rsp
+ movq oRBX(%rsi), %rbx
+ movq oRBP(%rsi), %rbp
+ movq oR12(%rsi), %r12
+ movq oR13(%rsi), %r13
+ movq oR14(%rsi), %r14
+ movq oR15(%rsi), %r15
+
+ /* The following ret should return to the address set with
+ getcontext. Therefore push the address on the stack. */
+ movq oRIP(%rsi), %rcx
+ pushq %rcx
+
+ /* Setup registers used for passing args. */
+ movq oRDI(%rsi), %rdi
+ movq oRDX(%rsi), %rdx
+ movq oRCX(%rsi), %rcx
+ movq oR8(%rsi), %r8
+ movq oR9(%rsi), %r9
+
+ /* Setup finally %rsi. */
+ movq oRSI(%rsi), %rsi
+
+ /* Clear rax to indicate success. */
+ xorl %eax, %eax
+
+L(pseudo_end):
+ ret
+PSEUDO_END(__swapcontext)
+
+weak_alias (__swapcontext, swapcontext)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sys/debugreg.h b/libc/sysdeps/unix/sysv/linux/x86_64/sys/debugreg.h
new file mode 100644
index 000000000..8abbf7546
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sys/debugreg.h
@@ -0,0 +1,88 @@
+/* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_DEBUGREG_H
+#define _SYS_DEBUGREG_H 1
+#include <bits/wordsize.h>
+
+/* Indicate the register numbers for a number of the specific
+ debug registers. Registers 0-3 contain the addresses we wish to trap on */
+#define DR_FIRSTADDR 0 /* u_debugreg[DR_FIRSTADDR] */
+#define DR_LASTADDR 3 /* u_debugreg[DR_LASTADDR] */
+
+#define DR_STATUS 6 /* u_debugreg[DR_STATUS] */
+#define DR_CONTROL 7 /* u_debugreg[DR_CONTROL] */
+
+/* Define a few things for the status register. We can use this to determine
+ which debugging register was responsible for the trap. The other bits
+ are either reserved or not of interest to us. */
+
+#define DR_TRAP0 (0x1) /* db0 */
+#define DR_TRAP1 (0x2) /* db1 */
+#define DR_TRAP2 (0x4) /* db2 */
+#define DR_TRAP3 (0x8) /* db3 */
+
+#define DR_STEP (0x4000) /* single-step */
+#define DR_SWITCH (0x8000) /* task switch */
+
+/* Now define a bunch of things for manipulating the control register.
+ The top two bytes of the control register consist of 4 fields of 4
+ bits - each field corresponds to one of the four debug registers,
+ and indicates what types of access we trap on, and how large the data
+ field is that we are looking at */
+
+#define DR_CONTROL_SHIFT 16 /* Skip this many bits in ctl register */
+#define DR_CONTROL_SIZE 4 /* 4 control bits per register */
+
+#define DR_RW_EXECUTE (0x0) /* Settings for the access types to trap on */
+#define DR_RW_WRITE (0x1)
+#define DR_RW_READ (0x3)
+
+#define DR_LEN_1 (0x0) /* Settings for data length to trap on */
+#define DR_LEN_2 (0x4)
+#define DR_LEN_4 (0xC)
+#define DR_LEN_8 (0x8)
+
+/* The low byte to the control register determine which registers are
+ enabled. There are 4 fields of two bits. One bit is "local", meaning
+ that the processor will reset the bit after a task switch and the other
+ is global meaning that we have to explicitly reset the bit. With linux,
+ you can use either one, since we explicitly zero the register when we enter
+ kernel mode. */
+
+#define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit */
+#define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit */
+#define DR_ENABLE_SIZE 2 /* 2 enable bits per register */
+
+#define DR_LOCAL_ENABLE_MASK (0x55) /* Set local bits for all 4 regs */
+#define DR_GLOBAL_ENABLE_MASK (0xAA) /* Set global bits for all 4 regs */
+
+/* The second byte to the control register has a few special
+ things. */
+
+
+
+#if __WORDSIZE == 64
+# define DR_CONTROL_RESERVED (0xFFFFFFFF0000FC00UL) /* Reserved */
+#else
+# define DR_CONTROL_RESERVED (0x00FC00U) /* Reserved */
+#endif
+#define DR_LOCAL_SLOWDOWN (0x100) /* Local slow the pipeline */
+#define DR_GLOBAL_SLOWDOWN (0x200) /* Global slow the pipeline */
+
+#endif /* sys/debugreg.h */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sys/epoll.h b/libc/sysdeps/unix/sysv/linux/x86_64/sys/epoll.h
new file mode 100644
index 000000000..02672d3c7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sys/epoll.h
@@ -0,0 +1,110 @@
+/* Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_EPOLL_H
+#define _SYS_EPOLL_H 1
+
+#include <stdint.h>
+#include <sys/types.h>
+
+
+enum EPOLL_EVENTS
+ {
+ EPOLLIN = 0x001,
+#define EPOLLIN EPOLLIN
+ EPOLLPRI = 0x002,
+#define EPOLLPRI EPOLLPRI
+ EPOLLOUT = 0x004,
+#define EPOLLOUT EPOLLOUT
+ EPOLLRDNORM = 0x040,
+#define EPOLLRDNORM EPOLLRDNORM
+ EPOLLRDBAND = 0x080,
+#define EPOLLRDBAND EPOLLRDBAND
+ EPOLLWRNORM = 0x100,
+#define EPOLLWRNORM EPOLLWRNORM
+ EPOLLWRBAND = 0x200,
+#define EPOLLWRBAND EPOLLWRBAND
+ EPOLLMSG = 0x400,
+#define EPOLLMSG EPOLLMSG
+ EPOLLERR = 0x008,
+#define EPOLLERR EPOLLERR
+ EPOLLHUP = 0x010,
+#define EPOLLHUP EPOLLHUP
+ EPOLLONESHOT = (1 << 30),
+#define EPOLLONESHOT EPOLLONESHOT
+ EPOLLET = (1 << 31)
+#define EPOLLET EPOLLET
+ };
+
+
+/* Valid opcodes ( "op" parameter ) to issue to epoll_ctl(). */
+#define EPOLL_CTL_ADD 1 /* Add a file decriptor to the interface. */
+#define EPOLL_CTL_DEL 2 /* Remove a file decriptor from the interface. */
+#define EPOLL_CTL_MOD 3 /* Change file decriptor epoll_event structure. */
+
+
+typedef union epoll_data
+{
+ void *ptr;
+ int fd;
+ uint32_t u32;
+ uint64_t u64;
+} epoll_data_t;
+
+struct epoll_event
+{
+ uint32_t events; /* Epoll events */
+ epoll_data_t data; /* User data variable */
+} __attribute__ ((__packed__));
+
+
+__BEGIN_DECLS
+
+/* Creates an epoll instance. Returns an fd for the new instance.
+ The "size" parameter is a hint specifying the number of file
+ descriptors to be associated with the new instance. The fd
+ returned by epoll_create() should be closed with close(). */
+extern int epoll_create (int __size) __THROW;
+
+
+/* Manipulate an epoll instance "epfd". Returns 0 in case of success,
+ -1 in case of error ( the "errno" variable will contain the
+ specific error code ) The "op" parameter is one of the EPOLL_CTL_*
+ constants defined above. The "fd" parameter is the target of the
+ operation. The "event" parameter describes which events the caller
+ is interested in and any associated user data. */
+extern int epoll_ctl (int __epfd, int __op, int __fd,
+ struct epoll_event *__event) __THROW;
+
+
+/* Wait for events on an epoll instance "epfd". Returns the number of
+ triggered events returned in "events" buffer. Or -1 in case of
+ error with the "errno" variable set to the specific error code. The
+ "events" parameter is a buffer that will contain triggered
+ events. The "maxevents" is the maximum number of events to be
+ returned ( usually size of "events" ). The "timeout" parameter
+ specifies the maximum wait time in milliseconds (-1 == infinite).
+
+ This function is a cancellation point and therefore not marked with
+ __THROW. */
+extern int epoll_wait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout);
+
+__END_DECLS
+
+#endif /* sys/epoll.h */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sys/io.h b/libc/sysdeps/unix/sysv/linux/x86_64/sys/io.h
new file mode 100644
index 000000000..802a0dfb4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sys/io.h
@@ -0,0 +1,181 @@
+/* Copyright (C) 1996, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_IO_H
+#define _SYS_IO_H 1
+
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* If TURN_ON is TRUE, request for permission to do direct i/o on the
+ port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
+ permission off for that range. This call requires root privileges.
+
+ Portability note: not all Linux platforms support this call. Most
+ platforms based on the PC I/O architecture probably will, however.
+ E.g., Linux/Alpha for Alpha PCs supports this. */
+extern int ioperm (unsigned long int __from, unsigned long int __num,
+ int __turn_on) __THROW;
+
+/* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
+ access any I/O port is granted. This call requires root
+ privileges. */
+extern int iopl (int __level) __THROW;
+
+#if defined __GNUC__ && __GNUC__ >= 2
+
+static __inline unsigned char
+inb (unsigned short int port)
+{
+ unsigned char _v;
+
+ __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned char
+inb_p (unsigned short int port)
+{
+ unsigned char _v;
+
+ __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned short int
+inw (unsigned short int port)
+{
+ unsigned short _v;
+
+ __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned short int
+inw_p (unsigned short int port)
+{
+ unsigned short int _v;
+
+ __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned int
+inl (unsigned short int port)
+{
+ unsigned int _v;
+
+ __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned int
+inl_p (unsigned short int port)
+{
+ unsigned int _v;
+ __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline void
+outb (unsigned char value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
+}
+
+static __inline void
+outb_p (unsigned char value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
+ "Nd" (port));
+}
+
+static __inline void
+outw (unsigned short int value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
+
+}
+
+static __inline void
+outw_p (unsigned short int value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
+ "Nd" (port));
+}
+
+static __inline void
+outl (unsigned int value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
+}
+
+static __inline void
+outl_p (unsigned int value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
+ "Nd" (port));
+}
+
+static __inline void
+insb (unsigned short int port, void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+static __inline void
+insw (unsigned short int port, void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+static __inline void
+insl (unsigned short int port, void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+static __inline void
+outsb (unsigned short int port, const void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+static __inline void
+outsw (unsigned short int port, const void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+static __inline void
+outsl (unsigned short int port, const void *addr, unsigned long int count)
+{
+ __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
+ "=c" (count):"d" (port), "0" (addr), "1" (count));
+}
+
+#endif /* GNU C */
+
+__END_DECLS
+#endif /* _SYS_IO_H */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sys/perm.h b/libc/sysdeps/unix/sysv/linux/x86_64/sys/perm.h
new file mode 100644
index 000000000..382fa92ee
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sys/perm.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 1996, 1999, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PERM_H
+
+#define _SYS_PERM_H 1
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* Set port input/output permissions. */
+extern int ioperm (unsigned long int __from, unsigned long int __num,
+ int __turn_on) __THROW;
+
+
+/* Change I/O privilege level. */
+extern int iopl (int __level) __THROW;
+
+__END_DECLS
+
+#endif /* _SYS_PERM_H */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sys/procfs.h b/libc/sysdeps/unix/sysv/linux/x86_64/sys/procfs.h
new file mode 100644
index 000000000..853d7db49
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sys/procfs.h
@@ -0,0 +1,142 @@
+/* Copyright (C) 2001, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H 1
+
+/* This is somewhat modelled after the file of the same name on SVR4
+ systems. It provides a definition of the core file format for ELF
+ used on Linux. It doesn't have anything to do with the /proc file
+ system, even though Linux has one.
+
+ Anyway, the whole purpose of this file is for GDB and GDB only.
+ Don't read too much into it. Don't use it for anything other than
+ GDB unless you know what you are doing. */
+
+#include <features.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/user.h>
+
+__BEGIN_DECLS
+
+/* Type for a general-purpose register. */
+typedef unsigned long elf_greg_t;
+
+/* And the whole bunch of them. We could have used `struct
+ user_regs_struct' directly in the typedef, but tradition says that
+ the register set is an array, which does have some peculiar
+ semantics, so leave it that way. */
+#define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof(elf_greg_t))
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+#if __WORDSIZE == 32
+/* Register set for the floating-point registers. */
+typedef struct user_fpregs_struct elf_fpregset_t;
+
+/* Register set for the extended floating-point registers. Includes
+ the Pentium III SSE registers in addition to the classic
+ floating-point stuff. */
+typedef struct user_fpxregs_struct elf_fpxregset_t;
+#else
+/* Register set for the extended floating-point registers. Includes
+ the Pentium III SSE registers in addition to the classic
+ floating-point stuff. */
+typedef struct user_fpregs_struct elf_fpregset_t;
+#endif
+
+/* Signal info. */
+struct elf_siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_code; /* Extra code. */
+ int si_errno; /* Errno. */
+ };
+
+
+/* Definitions to generate Intel SVR4-like core files. These mostly
+ have the same names as the SVR4 types with "elf_" tacked on the
+ front to prevent clashes with Linux definitions, and the typedef
+ forms have been avoided. This is mostly like the SVR4 structure,
+ but more Linuxy, with things that Linux does not support and which
+ GDB doesn't really use excluded. */
+
+struct elf_prstatus
+ {
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned long int pr_sigpend; /* Set of pending signals. */
+ unsigned long int pr_sighold; /* Set of held signals. */
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct timeval pr_utime; /* User time. */
+ struct timeval pr_stime; /* System time. */
+ struct timeval pr_cutime; /* Cumulative user time. */
+ struct timeval pr_cstime; /* Cumulative system time. */
+ elf_gregset_t pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+
+#define ELF_PRARGSZ (80) /* Number of chars for args. */
+
+struct elf_prpsinfo
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned long int pr_flag; /* Flags. */
+#if __WORDSIZE == 32
+ unsigned short int pr_uid;
+ unsigned short int pr_gid;
+#else
+ unsigned int pr_uid;
+ unsigned int pr_gid;
+#endif
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+
+/* The rest of this file provides the types for emulation of the
+ Solaris <proc_service.h> interfaces that should be implemented by
+ users of libthread_db. */
+
+/* Addresses. */
+typedef void *psaddr_t;
+
+/* Register sets. Linux has different names. */
+typedef elf_gregset_t prgregset_t;
+typedef elf_fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+ therefore have only one PID type. */
+typedef __pid_t lwpid_t;
+
+/* Process status and info. In the end we do provide typedefs for them. */
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+__END_DECLS
+
+#endif /* sys/procfs.h */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sys/reg.h b/libc/sysdeps/unix/sysv/linux/x86_64/sys/reg.h
new file mode 100644
index 000000000..acb71a2bc
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sys/reg.h
@@ -0,0 +1,79 @@
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_REG_H
+#define _SYS_REG_H 1
+#include <bits/wordsize.h>
+
+
+#if __WORDSIZE == 64
+/* Index into an array of 8 byte longs returned from ptrace for
+ location of the users' stored general purpose registers. */
+
+# define R15 0
+# define R14 1
+# define R13 2
+# define R12 3
+# define RBP 4
+# define RBX 5
+# define R11 6
+# define R10 7
+# define R9 8
+# define R8 9
+# define RAX 10
+# define RCX 11
+# define RDX 12
+# define RSI 13
+# define RDI 14
+# define ORIG_RAX 15
+# define RIP 16
+# define CS 17
+# define EFLAGS 18
+# define RSP 19
+# define SS 20
+# define FS_BASE 21
+# define GS_BASE 22
+# define DS 23
+# define ES 24
+# define FS 25
+# define GS 26
+#else
+
+/* Index into an array of 4 byte integers returned from ptrace for
+ * location of the users' stored general purpose registers. */
+
+# define EBX 0
+# define ECX 1
+# define EDX 2
+# define ESI 3
+# define EDI 4
+# define EBP 5
+# define EAX 6
+# define DS 7
+# define ES 8
+# define FS 9
+# define GS 10
+# define ORIG_EAX 11
+# define EIP 12
+# define CS 13
+# define EFL 14
+# define UESP 15
+# define SS 16
+#endif
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sys/ucontext.h b/libc/sysdeps/unix/sysv/linux/x86_64/sys/ucontext.h
new file mode 100644
index 000000000..b59cd292f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sys/ucontext.h
@@ -0,0 +1,248 @@
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+
+#include <features.h>
+#include <signal.h>
+#include <bits/wordsize.h>
+
+/* We need the signal context definitions even if they are not used
+ included in <signal.h>. */
+#include <bits/sigcontext.h>
+
+#if __WORDSIZE == 64
+
+/* Type for general register. */
+typedef long int greg_t;
+
+/* Number of general registers. */
+#define NGREG 23
+
+/* Container for all general registers. */
+typedef greg_t gregset_t[NGREG];
+
+#ifdef __USE_GNU
+/* Number of each register in the `gregset_t' array. */
+enum
+{
+ REG_R8 = 0,
+# define REG_R8 REG_R8
+ REG_R9,
+# define REG_R9 REG_R9
+ REG_R10,
+# define REG_R10 REG_R10
+ REG_R11,
+# define REG_R11 REG_R11
+ REG_R12,
+# define REG_R12 REG_R12
+ REG_R13,
+# define REG_R13 REG_R13
+ REG_R14,
+# define REG_R14 REG_R14
+ REG_R15,
+# define REG_R15 REG_R15
+ REG_RDI,
+# define REG_RDI REG_RDI
+ REG_RSI,
+# define REG_RSI REG_RSI
+ REG_RBP,
+# define REG_RBP REG_RBP
+ REG_RBX,
+# define REG_RBX REG_RBX
+ REG_RDX,
+# define REG_RDX REG_RDX
+ REG_RAX,
+# define REG_RAX REG_RAX
+ REG_RCX,
+# define REG_RCX REG_RCX
+ REG_RSP,
+# define REG_RSP REG_RSP
+ REG_RIP,
+# define REG_RIP REG_RIP
+ REG_EFL,
+# define REG_EFL REG_EFL
+ REG_CSGSFS, /* Actually short cs, gs, fs, __pad0. */
+# define REG_CSGSFS REG_CSGSFS
+ REG_ERR,
+# define REG_ERR REG_ERR
+ REG_TRAPNO,
+# define REG_TRAPNO REG_TRAPNO
+ REG_OLDMASK,
+# define REG_OLDMASK REG_OLDMASK
+ REG_CR2
+# define REG_CR2 REG_CR2
+};
+#endif
+
+struct _libc_fpxreg
+{
+ unsigned short int significand[4];
+ unsigned short int exponent;
+ unsigned short int padding[3];
+};
+
+struct _libc_xmmreg
+{
+ __uint32_t element[4];
+};
+
+struct _libc_fpstate
+{
+ /* 64-bit FXSAVE format. */
+ __uint16_t cwd;
+ __uint16_t swd;
+ __uint16_t ftw;
+ __uint16_t fop;
+ __uint64_t rip;
+ __uint64_t rdp;
+ __uint32_t mxcsr;
+ __uint32_t mxcr_mask;
+ struct _libc_fpxreg _st[8];
+ struct _libc_xmmreg _xmm[16];
+ __uint32_t padding[24];
+};
+
+/* Structure to describe FPU registers. */
+typedef struct _libc_fpstate *fpregset_t;
+
+/* Context to describe whole processor state. */
+typedef struct
+ {
+ gregset_t gregs;
+ /* Note that fpregs is a pointer. */
+ fpregset_t fpregs;
+ unsigned long __reserved1 [8];
+} mcontext_t;
+
+/* Userlevel context. */
+typedef struct ucontext
+ {
+ unsigned long int uc_flags;
+ struct ucontext *uc_link;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ __sigset_t uc_sigmask;
+ struct _libc_fpstate __fpregs_mem;
+ } ucontext_t;
+
+#else /* __WORDSIZE == 32 */
+
+/* Type for general register. */
+typedef int greg_t;
+
+/* Number of general registers. */
+#define NGREG 19
+
+/* Container for all general registers. */
+typedef greg_t gregset_t[NGREG];
+
+#ifdef __USE_GNU
+/* Number of each register is the `gregset_t' array. */
+enum
+{
+ REG_GS = 0,
+# define REG_GS REG_GS
+ REG_FS,
+# define REG_FS REG_FS
+ REG_ES,
+# define REG_ES REG_ES
+ REG_DS,
+# define REG_DS REG_DS
+ REG_EDI,
+# define REG_EDI REG_EDI
+ REG_ESI,
+# define REG_ESI REG_ESI
+ REG_EBP,
+# define REG_EBP REG_EBP
+ REG_ESP,
+# define REG_ESP REG_ESP
+ REG_EBX,
+# define REG_EBX REG_EBX
+ REG_EDX,
+# define REG_EDX REG_EDX
+ REG_ECX,
+# define REG_ECX REG_ECX
+ REG_EAX,
+# define REG_EAX REG_EAX
+ REG_TRAPNO,
+# define REG_TRAPNO REG_TRAPNO
+ REG_ERR,
+# define REG_ERR REG_ERR
+ REG_EIP,
+# define REG_EIP REG_EIP
+ REG_CS,
+# define REG_CS REG_CS
+ REG_EFL,
+# define REG_EFL REG_EFL
+ REG_UESP,
+# define REG_UESP REG_UESP
+ REG_SS
+# define REG_SS REG_SS
+};
+#endif
+
+/* Definitions taken from the kernel headers. */
+struct _libc_fpreg
+{
+ unsigned short int significand[4];
+ unsigned short int exponent;
+};
+
+struct _libc_fpstate
+{
+ unsigned long int cw;
+ unsigned long int sw;
+ unsigned long int tag;
+ unsigned long int ipoff;
+ unsigned long int cssel;
+ unsigned long int dataoff;
+ unsigned long int datasel;
+ struct _libc_fpreg _st[8];
+ unsigned long int status;
+};
+
+/* Structure to describe FPU registers. */
+typedef struct _libc_fpstate *fpregset_t;
+
+/* Context to describe whole processor state. */
+typedef struct
+ {
+ gregset_t gregs;
+ /* Due to Linux's history we have to use a pointer here. The SysV/i386
+ ABI requires a struct with the values. */
+ fpregset_t fpregs;
+ unsigned long int oldmask;
+ unsigned long int cr2;
+ } mcontext_t;
+
+/* Userlevel context. */
+typedef struct ucontext
+ {
+ unsigned long int uc_flags;
+ struct ucontext *uc_link;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ __sigset_t uc_sigmask;
+ struct _libc_fpstate __fpregs_mem;
+ } ucontext_t;
+
+#endif /* __WORDSIZE == 32 */
+
+#endif /* sys/ucontext.h */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sys/user.h b/libc/sysdeps/unix/sysv/linux/x86_64/sys/user.h
new file mode 100644
index 000000000..ceadcf478
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sys/user.h
@@ -0,0 +1,175 @@
+/* Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_USER_H
+#define _SYS_USER_H 1
+
+/* The whole purpose of this file is for GDB and GDB only. Don't read
+ too much into it. Don't use it for anything other than GDB unless
+ you know what you are doing. */
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+
+struct user_fpregs_struct
+{
+ __uint16_t cwd;
+ __uint16_t swd;
+ __uint16_t ftw;
+ __uint16_t fop;
+ __uint64_t rip;
+ __uint64_t rdp;
+ __uint32_t mxcsr;
+ __uint32_t mxcr_mask;
+ __uint32_t st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
+ __uint32_t xmm_space[64]; /* 16*16 bytes for each XMM-reg = 256 bytes */
+ __uint32_t padding[24];
+};
+
+struct user_regs_struct
+{
+ unsigned long r15;
+ unsigned long r14;
+ unsigned long r13;
+ unsigned long r12;
+ unsigned long rbp;
+ unsigned long rbx;
+ unsigned long r11;
+ unsigned long r10;
+ unsigned long r9;
+ unsigned long r8;
+ unsigned long rax;
+ unsigned long rcx;
+ unsigned long rdx;
+ unsigned long rsi;
+ unsigned long rdi;
+ unsigned long orig_rax;
+ unsigned long rip;
+ unsigned long cs;
+ unsigned long eflags;
+ unsigned long rsp;
+ unsigned long ss;
+ unsigned long fs_base;
+ unsigned long gs_base;
+ unsigned long ds;
+ unsigned long es;
+ unsigned long fs;
+ unsigned long gs;
+};
+
+struct user
+{
+ struct user_regs_struct regs;
+ int u_fpvalid;
+ struct user_fpregs_struct i387;
+ unsigned long int u_tsize;
+ unsigned long int u_dsize;
+ unsigned long int u_ssize;
+ unsigned long start_code;
+ unsigned long start_stack;
+ long int signal;
+ int reserved;
+ struct user_regs_struct* u_ar0;
+ struct user_fpregs_struct* u_fpstate;
+ unsigned long int magic;
+ char u_comm [32];
+ unsigned long int u_debugreg [8];
+};
+
+#else
+/* These are the 32-bit x86 structures. */
+struct user_fpregs_struct
+{
+ long int cwd;
+ long int swd;
+ long int twd;
+ long int fip;
+ long int fcs;
+ long int foo;
+ long int fos;
+ long int st_space [20];
+};
+
+struct user_fpxregs_struct
+{
+ unsigned short int cwd;
+ unsigned short int swd;
+ unsigned short int twd;
+ unsigned short int fop;
+ long int fip;
+ long int fcs;
+ long int foo;
+ long int fos;
+ long int mxcsr;
+ long int reserved;
+ long int st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
+ long int xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
+ long int padding[56];
+};
+
+struct user_regs_struct
+{
+ long int ebx;
+ long int ecx;
+ long int edx;
+ long int esi;
+ long int edi;
+ long int ebp;
+ long int eax;
+ long int xds;
+ long int xes;
+ long int xfs;
+ long int xgs;
+ long int orig_eax;
+ long int eip;
+ long int xcs;
+ long int eflags;
+ long int esp;
+ long int xss;
+};
+
+struct user
+{
+ struct user_regs_struct regs;
+ int u_fpvalid;
+ struct user_fpregs_struct i387;
+ unsigned long int u_tsize;
+ unsigned long int u_dsize;
+ unsigned long int u_ssize;
+ unsigned long start_code;
+ unsigned long start_stack;
+ long int signal;
+ int reserved;
+ struct user_regs_struct* u_ar0;
+ struct user_fpregs_struct* u_fpstate;
+ unsigned long int magic;
+ char u_comm [32];
+ int u_debugreg [8];
+};
+#endif /* __WORDSIZE */
+
+#define PAGE_SHIFT 12
+#define PAGE_SIZE (1UL << PAGE_SHIFT)
+#define PAGE_MASK (~(PAGE_SIZE-1))
+#define NBPG PAGE_SIZE
+#define UPAGES 1
+#define HOST_TEXT_START_ADDR (u.start_code)
+#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
+
+#endif /* _SYS_USER_H */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/syscall.S b/libc/sysdeps/unix/sysv/linux/x86_64/syscall.S
new file mode 100644
index 000000000..cf49dbcd1
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/syscall.S
@@ -0,0 +1,44 @@
+/* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* Please consult the file sysdeps/unix/sysv/linux/x86-64/sysdep.h for
+ more information about the value -4095 used below. */
+
+/* Usage: long syscall (syscall_number, arg1, arg2, arg3, arg4, arg5, arg6)
+ We need to do some arg shifting, the syscall_number will be in
+ rax. */
+
+
+ .text
+ENTRY (syscall)
+ movq %rdi, %rax /* Syscall number -> rax. */
+ movq %rsi, %rdi /* shift arg1 - arg5. */
+ movq %rdx, %rsi
+ movq %rcx, %rdx
+ movq %r8, %r10
+ movq %r9, %r8
+ movq 8(%rsp),%r9 /* arg6 is on the stack. */
+ syscall /* Do the system call. */
+ cmpq $-4095, %rax /* Check %rax for error. */
+ jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
+L(pseudo_end):
+ ret /* Return to caller. */
+
+PSEUDO_END (syscall)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/syscalls.list b/libc/sysdeps/unix/sysv/linux/x86_64/syscalls.list
new file mode 100644
index 000000000..a9d40446d
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/syscalls.list
@@ -0,0 +1,36 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+arch_prctl EXTRA arch_prctl i:ii __arch_prctl arch_prctl
+modify_ldt EXTRA modify_ldt i:ipi __modify_ldt modify_ldt
+
+# semaphore and shm system calls
+msgctl - msgctl i:iip __msgctl msgctl
+msgget - msgget i:ii __msgget msgget
+msgrcv - msgrcv Ci:ibnii __msgrcv msgrcv
+msgsnd - msgsnd Ci:ibni __msgsnd msgsnd
+shmat - shmat i:ipi __shmat shmat
+shmctl - shmctl i:iip __shmctl shmctl
+shmdt - shmdt i:s __shmdt shmdt
+shmget - shmget i:iii __shmget shmget
+semop - semop i:ipi __semop semop
+semtimedop - semtimedop i:ipip semtimedop
+semget - semget i:iii __semget semget
+semctl - semctl i:iiii __semctl semctl
+
+
+# proper socket implementations:
+accept - accept Ci:iBN __libc_accept __accept accept
+bind - bind i:ipi __bind bind
+connect - connect Ci:ipi __libc_connect __connect_internal __connect connect
+getpeername - getpeername i:ipp __getpeername getpeername
+getsockname - getsockname i:ipp __getsockname getsockname
+getsockopt - getsockopt i:iiiBN __getsockopt getsockopt
+listen - listen i:ii __listen listen
+recvfrom - recvfrom Ci:ibniBN __libc_recvfrom __recvfrom recvfrom
+recvmsg - recvmsg Ci:ipi __libc_recvmsg __recvmsg recvmsg
+sendmsg - sendmsg Ci:ipi __libc_sendmsg __sendmsg sendmsg
+sendto - sendto Ci:ibnibn __libc_sendto __sendto sendto
+setsockopt - setsockopt i:iiibn __setsockopt setsockopt
+shutdown - shutdown i:ii __shutdown shutdown
+socket - socket i:iii __socket socket
+socketpair - socketpair i:iiif __socketpair socketpair
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sysconf.c b/libc/sysdeps/unix/sysv/linux/x86_64/sysconf.c
new file mode 100644
index 000000000..726c5e33a
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sysconf.c
@@ -0,0 +1,326 @@
+/* Get file-specific information about a file. Linux version.
+ Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static long int linux_sysconf (int name);
+
+
+static const struct intel_02_cache_info
+{
+ unsigned int idx;
+ int name;
+ long int size;
+ long int assoc;
+ long int linesize;
+} intel_02_known[] =
+ {
+ { 0x06, _SC_LEVEL1_ICACHE_SIZE, 8192, 4, 32 },
+ { 0x08, _SC_LEVEL1_ICACHE_SIZE, 16384, 4, 32 },
+ { 0x0a, _SC_LEVEL1_DCACHE_SIZE, 8192, 2, 32 },
+ { 0x0c, _SC_LEVEL1_DCACHE_SIZE, 16384, 4, 32 },
+ { 0x22, _SC_LEVEL3_CACHE_SIZE, 524288, 4, 64 },
+ { 0x23, _SC_LEVEL3_CACHE_SIZE, 1048576, 8, 64 },
+ { 0x25, _SC_LEVEL3_CACHE_SIZE, 2097152, 8, 64 },
+ { 0x29, _SC_LEVEL3_CACHE_SIZE, 4194304, 8, 64 },
+ { 0x2c, _SC_LEVEL1_DCACHE_SIZE, 32768, 8, 64 },
+ { 0x30, _SC_LEVEL1_ICACHE_SIZE, 32768, 8, 64 },
+ { 0x39, _SC_LEVEL2_CACHE_SIZE, 131072, 4, 64 },
+ { 0x3a, _SC_LEVEL2_CACHE_SIZE, 196608, 6, 64 },
+ { 0x3b, _SC_LEVEL2_CACHE_SIZE, 131072, 2, 64 },
+ { 0x3c, _SC_LEVEL2_CACHE_SIZE, 262144, 4, 64 },
+ { 0x3d, _SC_LEVEL2_CACHE_SIZE, 393216, 6, 64 },
+ { 0x3e, _SC_LEVEL2_CACHE_SIZE, 524288, 4, 64 },
+ { 0x41, _SC_LEVEL2_CACHE_SIZE, 131072, 4, 32 },
+ { 0x42, _SC_LEVEL2_CACHE_SIZE, 262144, 4, 32 },
+ { 0x43, _SC_LEVEL2_CACHE_SIZE, 524288, 4, 32 },
+ { 0x44, _SC_LEVEL2_CACHE_SIZE, 1048576, 4, 32 },
+ { 0x45, _SC_LEVEL2_CACHE_SIZE, 2097152, 4, 32 },
+ { 0x46, _SC_LEVEL3_CACHE_SIZE, 4194304, 4, 64 },
+ { 0x47, _SC_LEVEL3_CACHE_SIZE, 8388608, 8, 64 },
+ { 0x49, _SC_LEVEL3_CACHE_SIZE, 4194304, 16, 64 },
+ { 0x4a, _SC_LEVEL3_CACHE_SIZE, 6291456, 12, 64 },
+ { 0x4b, _SC_LEVEL3_CACHE_SIZE, 8388608, 16, 64 },
+ { 0x4c, _SC_LEVEL3_CACHE_SIZE, 12582912, 12, 64 },
+ { 0x4d, _SC_LEVEL3_CACHE_SIZE, 16777216, 16, 64 },
+ { 0x60, _SC_LEVEL1_DCACHE_SIZE, 16384, 8, 64 },
+ { 0x66, _SC_LEVEL1_DCACHE_SIZE, 8192, 4, 64 },
+ { 0x67, _SC_LEVEL1_DCACHE_SIZE, 16384, 4, 64 },
+ { 0x68, _SC_LEVEL1_DCACHE_SIZE, 32768, 4, 64 },
+ { 0x78, _SC_LEVEL2_CACHE_SIZE, 1048576, 8, 64 },
+ { 0x79, _SC_LEVEL2_CACHE_SIZE, 131072, 8, 64 },
+ { 0x7a, _SC_LEVEL2_CACHE_SIZE, 262144, 8, 64 },
+ { 0x7b, _SC_LEVEL2_CACHE_SIZE, 524288, 8, 64 },
+ { 0x7c, _SC_LEVEL2_CACHE_SIZE, 1048576, 8, 64 },
+ { 0x7d, _SC_LEVEL2_CACHE_SIZE, 2097152, 8, 64 },
+ { 0x7f, _SC_LEVEL2_CACHE_SIZE, 524288, 2, 64 },
+ { 0x82, _SC_LEVEL2_CACHE_SIZE, 262144, 8, 32 },
+ { 0x83, _SC_LEVEL2_CACHE_SIZE, 524288, 8, 32 },
+ { 0x84, _SC_LEVEL2_CACHE_SIZE, 1048576, 8, 32 },
+ { 0x85, _SC_LEVEL2_CACHE_SIZE, 2097152, 8, 32 },
+ { 0x86, _SC_LEVEL2_CACHE_SIZE, 524288, 4, 64 },
+ { 0x87, _SC_LEVEL2_CACHE_SIZE, 1048576, 8, 64 },
+ };
+#define nintel_02_known (sizeof (intel_02_known) / sizeof (intel_02_known[0]))
+
+
+static int
+intel_02_known_compare (const void *p1, const void *p2)
+{
+ const struct intel_02_cache_info *i1;
+ const struct intel_02_cache_info *i2;
+
+ i1 = (const struct intel_02_cache_info *) p1;
+ i2 = (const struct intel_02_cache_info *) p2;
+
+ if (i1->idx == i2->idx)
+ return 0;
+
+ return i1->idx < i2->idx ? -1 : 1;
+}
+
+
+static long int
+intel_check_word (int name, unsigned int value, bool *has_level_2,
+ bool *no_level_2_or_3)
+{
+ if ((value & 0x80000000) != 0)
+ /* The register value is reserved. */
+ return 0;
+
+ /* Fold the name. The _SC_ constants are always in the order SIZE,
+ ASSOC, LINESIZE. */
+ int folded_name = (_SC_LEVEL1_ICACHE_SIZE
+ + ((name - _SC_LEVEL1_ICACHE_SIZE) / 3) * 3);
+
+ while (value != 0)
+ {
+ unsigned int byte = value & 0xff;
+
+ if (byte == 0x40)
+ {
+ *no_level_2_or_3 = true;
+
+ if (folded_name == _SC_LEVEL3_CACHE_SIZE)
+ /* No need to look further. */
+ break;
+ }
+ else
+ {
+ struct intel_02_cache_info *found;
+ struct intel_02_cache_info search;
+
+ search.idx = byte;
+ found = bsearch (&search, intel_02_known, nintel_02_known,
+ sizeof (intel_02_known[0]), intel_02_known_compare);
+ if (found != NULL)
+ {
+ if (found->name == folded_name)
+ {
+ unsigned int offset = name - folded_name;
+
+ if (offset == 0)
+ /* Cache size. */
+ return found->size;
+ if (offset == 1)
+ return found->assoc;
+
+ assert (offset == 2);
+ return found->linesize;
+ }
+
+ if (found->name == _SC_LEVEL2_CACHE_SIZE)
+ *has_level_2 = true;
+ }
+ }
+
+ /* Next byte for the next round. */
+ value >>= 8;
+ }
+
+ /* Nothing found. */
+ return 0;
+}
+
+
+static long int __attribute__ ((noinline))
+handle_intel (int name, unsigned int maxidx)
+{
+ assert (maxidx >= 2);
+
+ /* OK, we can use the CPUID instruction to get all info about the
+ caches. */
+ unsigned int cnt = 0;
+ unsigned int max = 1;
+ long int result = 0;
+ bool no_level_2_or_3 = false;
+ bool has_level_2 = false;
+ while (cnt++ < max)
+ {
+ unsigned int eax;
+ unsigned int ebx;
+ unsigned int ecx;
+ unsigned int edx;
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
+ : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
+ : "0" (2));
+
+ /* The low byte of EAX in the first round contain the number of
+ rounds we have to make. At least one, the one we are already
+ doing. */
+ if (cnt == 1)
+ {
+ max = eax & 0xff;
+ eax &= 0xffffff00;
+ }
+
+ /* Process the individual registers' value. */
+ result = intel_check_word (name, eax, &has_level_2, &no_level_2_or_3);
+ if (result != 0)
+ return result;
+
+ result = intel_check_word (name, ebx, &has_level_2, &no_level_2_or_3);
+ if (result != 0)
+ return result;
+
+ result = intel_check_word (name, ecx, &has_level_2, &no_level_2_or_3);
+ if (result != 0)
+ return result;
+
+ result = intel_check_word (name, edx, &has_level_2, &no_level_2_or_3);
+ if (result != 0)
+ return result;
+ }
+
+ if (name >= _SC_LEVEL2_CACHE_SIZE && name <= _SC_LEVEL3_CACHE_LINESIZE
+ && no_level_2_or_3)
+ return -1;
+
+ return 0;
+}
+
+
+static long int __attribute__ ((noinline))
+handle_amd (int name)
+{
+ unsigned int eax;
+ unsigned int ebx;
+ unsigned int ecx;
+ unsigned int edx;
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
+ : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
+ : "0" (0x80000000));
+
+ if (name >= _SC_LEVEL3_CACHE_SIZE)
+ return 0;
+
+ unsigned int fn = 0x80000005 + (name >= _SC_LEVEL2_CACHE_SIZE);
+ if (eax < fn)
+ return 0;
+
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
+ : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
+ : "0" (fn));
+
+ if (name < _SC_LEVEL1_DCACHE_SIZE)
+ {
+ name += _SC_LEVEL1_DCACHE_SIZE - _SC_LEVEL1_ICACHE_SIZE;
+ ecx = edx;
+ }
+
+ switch (name)
+ {
+ case _SC_LEVEL1_DCACHE_SIZE:
+ return (ecx >> 14) & 0x3fc00;
+ case _SC_LEVEL1_DCACHE_ASSOC:
+ ecx >>= 16;
+ if ((ecx & 0xff) == 0xff)
+ /* Fully associative. */
+ return (ecx << 2) & 0x3fc00;
+ return ecx & 0xff;
+ case _SC_LEVEL1_DCACHE_LINESIZE:
+ return ecx & 0xff;
+ case _SC_LEVEL2_CACHE_SIZE:
+ return (ecx & 0xf000) == 0 ? 0 : (ecx >> 6) & 0x3fffc00;
+ case _SC_LEVEL2_CACHE_ASSOC:
+ ecx >>= 12;
+ switch (ecx & 0xf)
+ {
+ case 0:
+ case 1:
+ case 2:
+ case 4:
+ return ecx & 0xf;
+ case 6:
+ return 8;
+ case 8:
+ return 16;
+ case 0xf:
+ return (ecx << 6) & 0x3fffc00;
+ default:
+ return 0;
+ }
+ case _SC_LEVEL2_CACHE_LINESIZE:
+ return (ecx & 0xf000) == 0 ? 0 : ecx & 0xff;
+ default:
+ assert (! "cannot happen");
+ }
+ return -1;
+}
+
+
+/* Get the value of the system variable NAME. */
+long int
+__sysconf (int name)
+{
+ /* We only handle the cache information here (for now). */
+ if (name < _SC_LEVEL1_ICACHE_SIZE || name > _SC_LEVEL4_CACHE_LINESIZE)
+ return linux_sysconf (name);
+
+ /* Find out what brand of processor. */
+ unsigned int eax;
+ unsigned int ebx;
+ unsigned int ecx;
+ unsigned int edx;
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
+ : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
+ : "0" (0));
+
+ /* This spells out "GenuineIntel". */
+ if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69)
+ return handle_intel (name, eax);
+
+ /* This spells out "AuthenticAMD". */
+ if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
+ return handle_amd (name);
+
+ // XXX Fill in more vendors.
+
+ /* CPU not known, we have no information. */
+ return 0;
+}
+
+/* Now the generic Linux version. */
+#undef __sysconf
+#define __sysconf static linux_sysconf
+#include "../sysconf.c"
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sysdep.S b/libc/sysdeps/unix/sysv/linux/x86_64/sysdep.S
new file mode 100644
index 000000000..5b72cef20
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sysdep.S
@@ -0,0 +1,41 @@
+/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+
+/* The following code is only used in the shared library when we
+ compile the reentrant version. Otherwise each system call defines
+ each own version. */
+
+#ifndef PIC
+
+/* The syscall stubs jump here when they detect an error.
+ The code for Linux is almost identical to the canonical Unix
+ code, except that the error number in %rax is negated. */
+
+#undef CALL_MCOUNT
+#define CALL_MCOUNT /* Don't insert the profiling call, it clobbers %rax. */
+
+ .text
+ENTRY (__syscall_error)
+ negq %rax
+
+#define __syscall_error __syscall_error_1
+#include <sysdeps/unix/x86_64/sysdep.S>
+
+#endif /* !PIC */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/libc/sysdeps/unix/sysv/linux/x86_64/sysdep.h
new file mode 100644
index 000000000..5dfffca45
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -0,0 +1,341 @@
+/* Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LINUX_X86_64_SYSDEP_H
+#define _LINUX_X86_64_SYSDEP_H 1
+
+/* There is some commonality. */
+#include <sysdeps/unix/x86_64/sysdep.h>
+#include <bp-sym.h>
+#include <bp-asm.h>
+#include <tls.h>
+
+#ifdef IS_IN_rtld
+# include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
+#endif
+
+/* For Linux we can use the system call table in the header file
+ /usr/include/asm/unistd.h
+ of the kernel. But these symbols do not follow the SYS_* syntax
+ so we have to redefine the `SYS_ify' macro here. */
+#undef SYS_ify
+#define SYS_ify(syscall_name) __NR_##syscall_name
+
+/* This is a kludge to make syscalls.list find these under the names
+ pread and pwrite, since some kernel headers define those names
+ and some define the *64 names for the same system calls. */
+#if !defined __NR_pread && defined __NR_pread64
+# define __NR_pread __NR_pread64
+#endif
+#if !defined __NR_pwrite && defined __NR_pwrite64
+# define __NR_pwrite __NR_pwrite64
+#endif
+
+/* This is to help the old kernel headers where __NR_semtimedop is not
+ available. */
+#ifndef __NR_semtimedop
+# define __NR_semtimedop 220
+#endif
+
+
+#ifdef __ASSEMBLER__
+
+/* Linux uses a negative return value to indicate syscall errors,
+ unlike most Unices, which use the condition codes' carry flag.
+
+ Since version 2.1 the return value of a system call might be
+ negative even if the call succeeded. E.g., the `lseek' system call
+ might return a large offset. Therefore we must not anymore test
+ for < 0, but test for a real error by making sure the value in %eax
+ is a real error number. Linus said he will make sure the no syscall
+ returns a value in -1 .. -4095 as a valid result so we can savely
+ test with -4095. */
+
+/* We don't want the label for the error handle to be global when we define
+ it here. */
+#ifdef PIC
+# define SYSCALL_ERROR_LABEL 0f
+#else
+# define SYSCALL_ERROR_LABEL syscall_error
+#endif
+
+#undef PSEUDO
+#define PSEUDO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args); \
+ cmpq $-4095, %rax; \
+ jae SYSCALL_ERROR_LABEL; \
+ L(pseudo_end):
+
+#undef PSEUDO_END
+#define PSEUDO_END(name) \
+ SYSCALL_ERROR_HANDLER \
+ END (name)
+
+#undef PSEUDO_NOERRNO
+#define PSEUDO_NOERRNO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args)
+
+#undef PSEUDO_END_NOERRNO
+#define PSEUDO_END_NOERRNO(name) \
+ END (name)
+
+#define ret_NOERRNO ret
+
+#undef PSEUDO_ERRVAL
+#define PSEUDO_ERRVAL(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ DO_CALL (syscall_name, args); \
+ negq %rax
+
+#undef PSEUDO_END_ERRVAL
+#define PSEUDO_END_ERRVAL(name) \
+ END (name)
+
+#define ret_ERRVAL ret
+
+#ifndef PIC
+#define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
+#elif RTLD_PRIVATE_ERRNO
+# define SYSCALL_ERROR_HANDLER \
+0: \
+ leaq rtld_errno(%rip), %rcx; \
+ xorl %edx, %edx; \
+ subq %rax, %rdx; \
+ movl %edx, (%rcx); \
+ orq $-1, %rax; \
+ jmp L(pseudo_end);
+#elif USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+# define SYSCALL_ERROR_ERRNO errno
+# endif
+# define SYSCALL_ERROR_HANDLER \
+0: \
+ movq SYSCALL_ERROR_ERRNO@GOTTPOFF(%rip), %rcx;\
+ xorl %edx, %edx; \
+ subq %rax, %rdx; \
+ movl %edx, %fs:(%rcx); \
+ orq $-1, %rax; \
+ jmp L(pseudo_end);
+#elif defined _LIBC_REENTRANT
+/* Store (- %rax) into errno through the GOT.
+ Note that errno occupies only 4 bytes. */
+# define SYSCALL_ERROR_HANDLER \
+0: \
+ xorl %edx, %edx; \
+ subq %rax, %rdx; \
+ pushq %rdx; \
+ cfi_adjust_cfa_offset(8); \
+ PUSH_ERRNO_LOCATION_RETURN; \
+ call BP_SYM (__errno_location)@PLT; \
+ POP_ERRNO_LOCATION_RETURN; \
+ popq %rdx; \
+ cfi_adjust_cfa_offset(-8); \
+ movl %edx, (%rax); \
+ orq $-1, %rax; \
+ jmp L(pseudo_end);
+
+/* A quick note: it is assumed that the call to `__errno_location' does
+ not modify the stack! */
+#else /* Not _LIBC_REENTRANT. */
+# define SYSCALL_ERROR_HANDLER \
+0:movq errno@GOTPCREL(%RIP), %rcx; \
+ xorl %edx, %edx; \
+ subq %rax, %rdx; \
+ movl %edx, (%rcx); \
+ orq $-1, %rax; \
+ jmp L(pseudo_end);
+#endif /* PIC */
+
+/* The Linux/x86-64 kernel expects the system call parameters in
+ registers according to the following table:
+
+ syscall number rax
+ arg 1 rdi
+ arg 2 rsi
+ arg 3 rdx
+ arg 4 r10
+ arg 5 r8
+ arg 6 r9
+
+ The Linux kernel uses and destroys internally these registers:
+ return address from
+ syscall rcx
+ additionally clobered: r12-r15,rbx,rbp
+ eflags from syscall r11
+
+ Normal function call, including calls to the system call stub
+ functions in the libc, get the first six parameters passed in
+ registers and the seventh parameter and later on the stack. The
+ register use is as follows:
+
+ system call number in the DO_CALL macro
+ arg 1 rdi
+ arg 2 rsi
+ arg 3 rdx
+ arg 4 rcx
+ arg 5 r8
+ arg 6 r9
+
+ We have to take care that the stack is aligned to 16 bytes. When
+ called the stack is not aligned since the return address has just
+ been pushed.
+
+
+ Syscalls of more than 6 arguments are not supported. */
+
+#undef DO_CALL
+#define DO_CALL(syscall_name, args) \
+ DOARGS_##args \
+ movl $SYS_ify (syscall_name), %eax; \
+ syscall;
+
+#define DOARGS_0 /* nothing */
+#define DOARGS_1 /* nothing */
+#define DOARGS_2 /* nothing */
+#define DOARGS_3 /* nothing */
+#define DOARGS_4 movq %rcx, %r10;
+#define DOARGS_5 DOARGS_4
+#define DOARGS_6 DOARGS_5
+
+#else /* !__ASSEMBLER__ */
+/* Define a macro which expands inline into the wrapper code for a system
+ call. */
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...) \
+ ({ \
+ unsigned long resultvar = INTERNAL_SYSCALL (name, , nr, args); \
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
+ resultvar = (unsigned long) -1; \
+ } \
+ (long) resultvar; })
+
+#undef INTERNAL_SYSCALL_DECL
+#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
+
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({ \
+ unsigned long resultvar; \
+ LOAD_ARGS_##nr (args) \
+ LOAD_REGS_##nr \
+ asm volatile ( \
+ "syscall\n\t" \
+ : "=a" (resultvar) \
+ : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
+ (long) resultvar; })
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, err, nr, args...) \
+ INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
+
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+ ((unsigned long) (val) >= -4095L)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
+
+#define LOAD_ARGS_0()
+#define LOAD_REGS_0
+#define ASM_ARGS_0
+
+#define LOAD_ARGS_1(a1) \
+ long int __arg1 = (long) (a1); \
+ LOAD_ARGS_0 ()
+#define LOAD_REGS_1 \
+ register long int _a1 asm ("rdi") = __arg1; \
+ LOAD_REGS_0
+#define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
+
+#define LOAD_ARGS_2(a1, a2) \
+ long int __arg2 = (long) (a2); \
+ LOAD_ARGS_1 (a1)
+#define LOAD_REGS_2 \
+ register long int _a2 asm ("rsi") = __arg2; \
+ LOAD_REGS_1
+#define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
+
+#define LOAD_ARGS_3(a1, a2, a3) \
+ long int __arg3 = (long) (a3); \
+ LOAD_ARGS_2 (a1, a2)
+#define LOAD_REGS_3 \
+ register long int _a3 asm ("rdx") = __arg3; \
+ LOAD_REGS_2
+#define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
+
+#define LOAD_ARGS_4(a1, a2, a3, a4) \
+ long int __arg4 = (long) (a4); \
+ LOAD_ARGS_3 (a1, a2, a3)
+#define LOAD_REGS_4 \
+ register long int _a4 asm ("r10") = __arg4; \
+ LOAD_REGS_3
+#define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
+
+#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
+ long int __arg5 = (long) (a5); \
+ LOAD_ARGS_4 (a1, a2, a3, a4)
+#define LOAD_REGS_5 \
+ register long int _a5 asm ("r8") = __arg5; \
+ LOAD_REGS_4
+#define ASM_ARGS_5 ASM_ARGS_4, "r" (_a5)
+
+#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
+ long int __arg6 = (long) (a6); \
+ LOAD_ARGS_5 (a1, a2, a3, a4, a5)
+#define LOAD_REGS_6 \
+ register long int _a6 asm ("r9") = __arg6; \
+ LOAD_REGS_5
+#define ASM_ARGS_6 ASM_ARGS_5, "r" (_a6)
+
+#endif /* __ASSEMBLER__ */
+
+
+/* Pointer mangling support. */
+#if defined NOT_IN_libc && defined IS_IN_rtld
+/* We cannot use the thread descriptor because in ld.so we use setjmp
+ earlier than the descriptor is initialized. */
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(reg) xorq __pointer_chk_guard_local(%rip), reg
+# define PTR_DEMANGLE(reg) PTR_MANGLE (reg)
+# else
+# define PTR_MANGLE(reg) asm ("xorq __pointer_chk_guard_local(%%rip), %0"\
+ : "=r" (reg) : "0" (reg))
+# define PTR_DEMANGLE(reg) PTR_MANGLE (reg)
+# endif
+#else
+# ifdef __ASSEMBLER__
+# define PTR_MANGLE(reg) xorq %fs:POINTER_GUARD, reg
+# define PTR_DEMANGLE(reg) PTR_MANGLE (reg)
+# else
+# define PTR_MANGLE(var) asm ("xorq %%fs:%c2, %0" \
+ : "=r" (var) \
+ : "0" (var), \
+ "i" (offsetof (tcbhead_t, \
+ pointer_guard)))
+# define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* linux/x86_64/sysdep.h */
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/time.S b/libc/sysdeps/unix/sysv/linux/x86_64/time.S
new file mode 100644
index 000000000..e3f326876
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/time.S
@@ -0,0 +1,42 @@
+/* Copyright (C) 2001,02, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+/* For the calculation see asm/vsyscall.h. */
+#define VSYSCALL_ADDR_vtime 0xffffffffff600400
+
+
+/* Return the current time as a `time_t' and also put it in *T if T is
+ not NULL. Time is represented as seconds from Jan 1 00:00:00 1970. */
+
+ENTRY (time)
+ /* Align stack. */
+ sub $0x8, %rsp
+ cfi_adjust_cfa_offset(8)
+
+ movq $VSYSCALL_ADDR_vtime, %rax
+ callq *%rax
+
+ add $0x8, %rsp
+ cfi_adjust_cfa_offset(-8)
+ ret
+PSEUDO_END_NOERRNO(time)
+libc_hidden_def (time)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym b/libc/sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym
new file mode 100644
index 000000000..b3cfe9aa4
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym
@@ -0,0 +1,34 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+--
+
+SIG_BLOCK
+SIG_SETMASK
+
+_NSIG8 (_NSIG / 8)
+
+#define ucontext(member) offsetof (ucontext_t, member)
+#define mcontext(member) ucontext (uc_mcontext.member)
+#define mreg(reg) mcontext (gregs[REG_##reg])
+
+oRBP mreg (RBP)
+oRSP mreg (RSP)
+oRBX mreg (RBX)
+oR8 mreg (R8)
+oR9 mreg (R9)
+oR12 mreg (R12)
+oR13 mreg (R13)
+oR14 mreg (R14)
+oR15 mreg (R15)
+oRDI mreg (RDI)
+oRSI mreg (RSI)
+oRDX mreg (RDX)
+oRAX mreg (RAX)
+oRCX mreg (RCX)
+oRIP mreg (RIP)
+oFPREGS mcontext (fpregs)
+oSIGMASK ucontext (uc_sigmask)
+oFPREGSMEM ucontext (__fpregs_mem)
+oMXCSR ucontext (__fpregs_mem.mxcsr)
diff --git a/libc/sysdeps/unix/sysv/linux/x86_64/umount.c b/libc/sysdeps/unix/sysv/linux/x86_64/umount.c
new file mode 100644
index 000000000..a17c5c579
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/umount.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2000, 2001, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Huggins-Daines <dhd@debian.org>, 2000.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Since we don'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/libc/sysdeps/unix/sysv/linux/x86_64/vfork.S b/libc/sysdeps/unix/sysv/linux/x86_64/vfork.S
new file mode 100644
index 000000000..4bad38892
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/x86_64/vfork.S
@@ -0,0 +1,61 @@
+/* Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+
+ /* Pop the return PC value into RDI. We need a register that
+ is preserved by the syscall and that we're allowed to destroy. */
+ popq %rdi
+ cfi_adjust_cfa_offset(-8)
+
+#ifdef SAVE_PID
+ SAVE_PID
+#endif
+
+ /* Stuff the syscall number in RAX and enter into the kernel. */
+ movl $SYS_ify (vfork), %eax
+ syscall
+
+ /* Push back the return PC. */
+ pushq %rdi
+ cfi_adjust_cfa_offset(8)
+
+#ifdef RESTORE_PID
+ RESTORE_PID
+#endif
+
+ cmpl $-4095, %eax
+ jae SYSCALL_ERROR_LABEL /* Branch forward if it failed. */
+
+ /* Normal return. */
+.Lpseudo_end:
+ ret
+
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/sysdeps/unix/sysv/linux/xmknod.c b/libc/sysdeps/unix/sysv/linux/xmknod.c
new file mode 100644
index 000000000..38d902e65
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/xmknod.c
@@ -0,0 +1,57 @@
+/* xmknod call using old-style Unix mknod system call.
+ Copyright (C) 1991, 1993, 1995, 1996, 1997, 1998, 2000, 2002, 2003
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.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 (mknod, 3, CHECK_STRING (path), mode,
+ (unsigned int) k_dev);
+}
+
+weak_alias (__xmknod, _xmknod)
+libc_hidden_def (__xmknod)
diff --git a/libc/sysdeps/unix/sysv/linux/xmknodat.c b/libc/sysdeps/unix/sysv/linux/xmknodat.c
new file mode 100644
index 000000000..ef27b686c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/xmknodat.c
@@ -0,0 +1,95 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+
+#include <sysdep.h>
+#include <kernel-features.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+
+/* Create a device file named PATH relative to FD, 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
+__xmknodat (int vers, int fd, const char *file, mode_t mode, dev_t *dev)
+{
+ if (vers != _MKNOD_VER)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* We must convert the value to dev_t type used by the kernel. */
+ unsigned long long int k_dev = (*dev) & ((1ULL << 32) - 1);
+ if (k_dev != *dev)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+#ifdef __NR_mknodat
+# ifndef __ASSUME_ATFCTS
+ if (__have_atfcts >= 0)
+# endif
+ {
+ int res = INLINE_SYSCALL (mknodat, 4, fd, file, mode,
+ (unsigned int) k_dev);
+# ifndef __ASSUME_ATFCTS
+ if (res == -1 && errno == ENOSYS)
+ __have_atfcts = -1;
+ else
+# endif
+ return res;
+ }
+#endif
+
+#ifndef __ASSUME_ATFCTS
+ char *buf = NULL;
+
+ if (fd != AT_FDCWD && file[0] != '/')
+ {
+ size_t filelen = strlen (file);
+ static const char procfd[] = "/proc/self/fd/%d/%s";
+ /* Buffer for the path name we are going to use. It consists of
+ - the string /proc/self/fd/
+ - the file descriptor number
+ - the file name provided.
+ The final NUL is included in the sizeof. A bit of overhead
+ due to the format elements compensates for possible negative
+ numbers. */
+ size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+ buf = alloca (buflen);
+
+ __snprintf (buf, buflen, procfd, fd, file);
+ file = buf;
+ }
+
+ return INLINE_SYSCALL (mknod, 3, CHECK_STRING (file), mode,
+ (unsigned int) k_dev);
+#endif
+}
+
+libc_hidden_def (__xmknodat)
diff --git a/libc/sysdeps/unix/sysv/linux/xstat.c b/libc/sysdeps/unix/sysv/linux/xstat.c
new file mode 100644
index 000000000..60138ee93
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/xstat.c
@@ -0,0 +1,64 @@
+/* xstat using old-style Unix stat system call.
+ Copyright (C) 1991,1995-1998,2000,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Ho hum, if xstat == xstat64 we must get rid of the prototype or gcc
+ will complain since they don't strictly match. */
+#define __xstat64 __xstat64_disable
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <xstatconv.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 (stat, 2, CHECK_STRING (name),
+ CHECK_1 ((struct kernel_stat *) buf));
+
+#ifdef STAT_IS_KERNEL_STAT
+ errno = EINVAL;
+ return -1;
+#else
+ struct kernel_stat kbuf;
+ int result;
+
+ result = INLINE_SYSCALL (stat, 2, CHECK_STRING (name),
+ __ptrvalue (&kbuf));
+ if (result == 0)
+ result = __xstat_conv (vers, &kbuf, buf);
+
+ return result;
+#endif
+}
+hidden_def (__xstat)
+weak_alias (__xstat, _xstat);
+#ifdef XSTAT_IS_XSTAT64
+#undef __xstat64
+strong_alias (__xstat, __xstat64);
+hidden_ver (__xstat, __xstat64)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/xstat64.c b/libc/sysdeps/unix/sysv/linux/xstat64.c
new file mode 100644
index 000000000..096aac813
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/xstat64.c
@@ -0,0 +1,97 @@
+/* xstat64 using old-style Unix stat system call.
+ Copyright (C) 1991,1995-2002,2003,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <kernel-features.h>
+
+#if __ASSUME_STAT64_SYSCALL == 0
+# include <xstatconv.h>
+#endif
+
+#ifdef __NR_stat64
+# if __ASSUME_STAT64_SYSCALL == 0
+/* The variable is shared between all wrappers around *stat64 calls.
+ This is the definition. */
+int __have_no_stat64;
+# endif
+#endif
+
+/* Get information about the file NAME in BUF. */
+
+int
+___xstat64 (int vers, const char *name, struct stat64 *buf)
+{
+ int result;
+#if __ASSUME_STAT64_SYSCALL > 0
+ result = INLINE_SYSCALL (stat64, 2, CHECK_STRING (name), CHECK_1 (buf));
+# if defined _HAVE_STAT64___ST_INO && __ASSUME_ST_INO_64_BIT == 0
+ if (__builtin_expect (!result, 1) && buf->__st_ino != (__ino_t) buf->st_ino)
+ buf->st_ino = buf->__st_ino;
+# endif
+ return result;
+#else
+ struct kernel_stat kbuf;
+# if defined __NR_stat64
+ if (! __have_no_stat64)
+ {
+ int saved_errno = errno;
+ result = INLINE_SYSCALL (stat64, 2, CHECK_STRING (name), CHECK_1 (buf));
+
+ if (result != -1 || errno != ENOSYS)
+ {
+# if defined _HAVE_STAT64___ST_INO && __ASSUME_ST_INO_64_BIT == 0
+ if (!result && buf->__st_ino != (__ino_t) buf->st_ino)
+ buf->st_ino = buf->__st_ino;
+# endif
+ return result;
+ }
+
+ __set_errno (saved_errno);
+ __have_no_stat64 = 1;
+ }
+# endif
+
+ result = INLINE_SYSCALL (stat, 2, CHECK_STRING (name), __ptrvalue (&kbuf));
+ if (result == 0)
+ result = __xstat64_conv (vers, &kbuf, buf);
+
+ return result;
+#endif
+}
+
+
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+versioned_symbol (libc, ___xstat64, __xstat64, GLIBC_2_2);
+strong_alias (___xstat64, __old__xstat64)
+compat_symbol (libc, __old__xstat64, __xstat64, GLIBC_2_1);
+hidden_ver (___xstat64, __xstat64)
+#else
+strong_alias (___xstat64, __xstat64)
+hidden_def (__xstat64)
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/xstatconv.c b/libc/sysdeps/unix/sysv/linux/xstatconv.c
new file mode 100644
index 000000000..805e33978
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/xstatconv.c
@@ -0,0 +1,285 @@
+/* Convert between the kernel's `struct stat' format, and libc's.
+ Copyright (C) 1991,1995-1997,2000,2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#ifdef STAT_IS_KERNEL_STAT
+
+/* Dummy. */
+struct kernel_stat;
+
+#else
+
+#include <string.h>
+
+
+#if !defined __ASSUME_STAT64_SYSCALL || defined XSTAT_IS_XSTAT64
+int
+__xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
+{
+ switch (vers)
+ {
+ case _STAT_VER_KERNEL:
+ /* Nothing to do. The struct is in the form the kernel expects.
+ We should have short-circuted before we got here, but for
+ completeness... */
+ *(struct kernel_stat *) ubuf = *kbuf;
+ break;
+
+ case _STAT_VER_LINUX:
+ {
+ struct stat *buf = ubuf;
+
+ /* Convert to current kernel version of `struct stat'. */
+ buf->st_dev = kbuf->st_dev;
+#ifdef _HAVE_STAT___PAD1
+ buf->__pad1 = 0;
+#endif
+ buf->st_ino = kbuf->st_ino;
+ buf->st_mode = kbuf->st_mode;
+ buf->st_nlink = kbuf->st_nlink;
+ buf->st_uid = kbuf->st_uid;
+ buf->st_gid = kbuf->st_gid;
+ buf->st_rdev = kbuf->st_rdev;
+#ifdef _HAVE_STAT___PAD2
+ buf->__pad2 = 0;
+#endif
+ buf->st_size = kbuf->st_size;
+ buf->st_blksize = kbuf->st_blksize;
+ buf->st_blocks = kbuf->st_blocks;
+#ifdef _HAVE_STAT_NSEC
+ buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
+ buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
+ buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
+ buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
+ buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
+ buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
+#else
+ buf->st_atime = kbuf->st_atime;
+ buf->st_mtime = kbuf->st_mtime;
+ buf->st_ctime = kbuf->st_ctime;
+#endif
+#ifdef _HAVE_STAT___UNUSED1
+ buf->__unused1 = 0;
+#endif
+#ifdef _HAVE_STAT___UNUSED2
+ buf->__unused2 = 0;
+#endif
+#ifdef _HAVE_STAT___UNUSED3
+ buf->__unused3 = 0;
+#endif
+#ifdef _HAVE_STAT___UNUSED4
+ buf->__unused4 = 0;
+#endif
+#ifdef _HAVE_STAT___UNUSED5
+ buf->__unused5 = 0;
+#endif
+ }
+ break;
+
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return 0;
+}
+#endif
+
+int
+__xstat64_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
+{
+#ifdef XSTAT_IS_XSTAT64
+ return __xstat_conv (vers, kbuf, ubuf);
+#else
+ switch (vers)
+ {
+ case _STAT_VER_LINUX:
+ {
+ struct stat64 *buf = ubuf;
+
+ /* Convert to current kernel version of `struct stat64'. */
+ buf->st_dev = kbuf->st_dev;
+#ifdef _HAVE_STAT64___PAD1
+ buf->__pad1 = 0;
+#endif
+ buf->st_ino = kbuf->st_ino;
+#ifdef _HAVE_STAT64___ST_INO
+ buf->__st_ino = kbuf->st_ino;
+#endif
+ buf->st_mode = kbuf->st_mode;
+ buf->st_nlink = kbuf->st_nlink;
+ buf->st_uid = kbuf->st_uid;
+ buf->st_gid = kbuf->st_gid;
+ buf->st_rdev = kbuf->st_rdev;
+#ifdef _HAVE_STAT64___PAD2
+ buf->__pad2 = 0;
+#endif
+ buf->st_size = kbuf->st_size;
+ buf->st_blksize = kbuf->st_blksize;
+ buf->st_blocks = kbuf->st_blocks;
+#ifdef _HAVE_STAT64_NSEC
+ buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
+ buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
+ buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
+ buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
+ buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
+ buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
+#else
+ buf->st_atime = kbuf->st_atime;
+ buf->st_mtime = kbuf->st_mtime;
+ buf->st_ctime = kbuf->st_ctime;
+#endif
+#ifdef _HAVE_STAT64___UNUSED1
+ buf->__unused1 = 0;
+#endif
+#ifdef _HAVE_STAT64___UNUSED2
+ buf->__unused2 = 0;
+#endif
+#ifdef _HAVE_STAT64___UNUSED3
+ buf->__unused3 = 0;
+#endif
+#ifdef _HAVE_STAT64___UNUSED4
+ buf->__unused4 = 0;
+#endif
+#ifdef _HAVE_STAT64___UNUSED5
+ buf->__unused5 = 0;
+#endif
+ }
+ break;
+
+ /* If struct stat64 is different from struct stat then
+ _STAT_VER_KERNEL does not make sense. */
+ case _STAT_VER_KERNEL:
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return 0;
+#endif
+}
+
+int
+__xstat32_conv (int vers, struct stat64 *kbuf, struct stat *buf)
+{
+ switch (vers)
+ {
+ case _STAT_VER_LINUX:
+ {
+ /* Convert current kernel version of `struct stat64' to
+ `struct stat'. */
+ buf->st_dev = kbuf->st_dev;
+#ifdef _HAVE_STAT___PAD1
+ buf->__pad1 = 0;
+#endif
+#ifdef _HAVE_STAT64___ST_INO
+# if __ASSUME_ST_INO_64_BIT == 0
+ if (kbuf->st_ino == 0)
+ buf->st_ino = kbuf->__st_ino;
+ else
+# endif
+ {
+ buf->st_ino = kbuf->st_ino;
+ if (sizeof (buf->st_ino) != sizeof (kbuf->st_ino)
+ && buf->st_ino != kbuf->st_ino)
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+ }
+#else
+ buf->st_ino = kbuf->st_ino;
+ if (sizeof (buf->st_ino) != sizeof (kbuf->st_ino)
+ && buf->st_ino != kbuf->st_ino)
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+#endif
+ buf->st_mode = kbuf->st_mode;
+ buf->st_nlink = kbuf->st_nlink;
+ buf->st_uid = kbuf->st_uid;
+ buf->st_gid = kbuf->st_gid;
+ buf->st_rdev = kbuf->st_rdev;
+#ifdef _HAVE_STAT___PAD2
+ buf->__pad2 = 0;
+#endif
+ buf->st_size = kbuf->st_size;
+ /* Check for overflow. */
+ if (sizeof (buf->st_size) != sizeof (kbuf->st_size)
+ && buf->st_size != kbuf->st_size)
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+ buf->st_blksize = kbuf->st_blksize;
+ buf->st_blocks = kbuf->st_blocks;
+ /* Check for overflow. */
+ if (sizeof (buf->st_blocks) != sizeof (kbuf->st_blocks)
+ && buf->st_blocks != kbuf->st_blocks)
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+#ifdef _HAVE_STAT_NSEC
+ buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
+ buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
+ buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
+ buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
+ buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
+ buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
+#else
+ buf->st_atime = kbuf->st_atime;
+ buf->st_mtime = kbuf->st_mtime;
+ buf->st_ctime = kbuf->st_ctime;
+#endif
+
+#ifdef _HAVE_STAT___UNUSED1
+ buf->__unused1 = 0;
+#endif
+#ifdef _HAVE_STAT___UNUSED2
+ buf->__unused2 = 0;
+#endif
+#ifdef _HAVE_STAT___UNUSED3
+ buf->__unused3 = 0;
+#endif
+#ifdef _HAVE_STAT___UNUSED4
+ buf->__unused4 = 0;
+#endif
+#ifdef _HAVE_STAT___UNUSED5
+ buf->__unused5 = 0;
+#endif
+ }
+ break;
+
+ /* If struct stat64 is different from struct stat then
+ _STAT_VER_KERNEL does not make sense. */
+ case _STAT_VER_KERNEL:
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/libc/sysdeps/unix/sysv/linux/xstatconv.h b/libc/sysdeps/unix/sysv/linux/xstatconv.h
new file mode 100644
index 000000000..7e3662043
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/linux/xstatconv.h
@@ -0,0 +1,27 @@
+/* Convert between the kernel's `struct stat' format, and libc's.
+ Copyright (C) 1991,1995-1997,2000,2002,2003,2006
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <kernel-features.h>
+
+#ifndef STAT_IS_KERNEL_STAT
+extern int __xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf);
+extern int __xstat64_conv (int vers, struct kernel_stat *kbuf, void *ubuf);
+#endif
+extern int __xstat32_conv (int vers, struct stat64 *kbuf, struct stat *buf);
diff --git a/libc/sysdeps/unix/sysv/setrlimit.c b/libc/sysdeps/unix/sysv/setrlimit.c
new file mode 100644
index 000000000..06e2efb18
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/setrlimit.c
@@ -0,0 +1,57 @@
+/* setrlimit function for systems with ulimit system call (SYSV).
+ Copyright (C) 1991, 1992, 1996, 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* This only implements those functions which are available via ulimit. */
+
+#include <sys/resource.h>
+#include <stddef.h>
+#include <errno.h>
+
+/* Set the soft and hard limits for RESOURCE to *RLIMITS.
+ Only the super-user can increase hard limits.
+ Return 0 if successful, -1 if not (and sets errno). */
+int
+setrlimit (resource, rlimits)
+ enum __rlimit_resource resource;
+ const struct rlimit *rlimits;
+{
+ if (rlimits == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ switch (resource)
+ {
+ case RLIMIT_FSIZE:
+ return __ulimit (2, rlimits->rlim_cur);
+
+ case RLIMIT_DATA:
+ case RLIMIT_CPU:
+ case RLIMIT_STACK:
+ case RLIMIT_CORE:
+ case RLIMIT_RSS:
+ __set_errno (ENOSYS);
+ return -1;
+
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/settimeofday.c b/libc/sysdeps/unix/sysv/settimeofday.c
new file mode 100644
index 000000000..e2c4102ef
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/settimeofday.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 1992, 1995, 1996, 1997, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+
+/* Set the current time of day and timezone information.
+ This call is restricted to the super-user. */
+int
+__settimeofday (tv, tz)
+ const struct timeval *tv;
+ const struct timezone *tz;
+{
+ time_t when;
+
+ if (tv == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (tz != NULL || tv->tv_usec % 1000000 != 0)
+ {
+ __set_errno (ENOSYS);
+ return -1;
+ }
+
+ when = tv->tv_sec + (tv->tv_usec / 1000000);
+ return stime (&when);
+}
+
+weak_alias (__settimeofday, settimeofday)
diff --git a/libc/sysdeps/unix/sysv/sigaction.c b/libc/sysdeps/unix/sysv/sigaction.c
new file mode 100644
index 000000000..e90b2a854
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/sigaction.c
@@ -0,0 +1,84 @@
+/* Copyright (C) 1992,1994,1995,1996,1997,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <stddef.h>
+#include <signal.h>
+
+
+/* If ACT is not NULL, change the action for SIG to *ACT.
+ If OACT is not NULL, put the old action for SIG in *OACT. */
+int
+__sigaction (sig, act, oact)
+ int sig;
+ const struct sigaction *act;
+ struct sigaction *oact;
+{
+ sighandler_t handler;
+ int save;
+
+ if (sig <= 0 || sig >= NSIG)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (act == NULL)
+ {
+ if (oact == NULL)
+ return 0;
+ /* Race condition, but this is the only way to do it. */
+ handler = signal (sig, SIG_IGN);
+ if (handler == SIG_ERR)
+ return -1;
+ save = errno;
+ (void) signal (sig, handler);
+ __set_errno (save);
+ }
+ else
+ {
+ int i;
+
+ if (act->sa_flags != 0)
+ {
+ unimplemented:
+ __set_errno (ENOSYS);
+ return -1;
+ }
+
+ for (i = 1; i < NSIG; ++i)
+ if (__sigismember (&act->sa_mask, i))
+ goto unimplemented;
+
+ handler = signal (sig, act->sa_handler);
+ if (handler == SIG_ERR)
+ return -1;
+ }
+
+ if (oact != NULL)
+ {
+ oact->sa_handler = handler;
+ __sigemptyset (&oact->sa_mask);
+ oact->sa_flags = 0;
+ }
+
+ return 0;
+}
+libc_hidden_def (__sigaction)
+weak_alias (__sigaction, sigaction)
diff --git a/libc/sysdeps/unix/sysv/syscalls.list b/libc/sysdeps/unix/sysv/syscalls.list
new file mode 100644
index 000000000..436d05eb9
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/syscalls.list
@@ -0,0 +1,16 @@
+# File name Caller Syscall name # args Strong name Weak names
+
+alarm - alarm i:i alarm
+ftime - ftime i:p ftime
+nice - nice i:i nice
+pause - pause Ci: pause
+poll - poll Ci:pii poll
+s_getdents getdents getdents i:ipi __getdents
+setrlimit - setrlimit i:ip __setrlimit setrlimit
+settimeofday - settimeofday i:PP __settimeofday settimeofday
+signal - signal i:ii signal
+stime - stime i:p stime
+time - time Ei:P time
+times - times i:p __times times
+ulimit - ulimit i:ii ulimit
+utime - utime i:sP utime
diff --git a/libc/sysdeps/unix/sysv/sysv_termio.h b/libc/sysdeps/unix/sysv/sysv_termio.h
new file mode 100644
index 000000000..ebede410c
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/sysv_termio.h
@@ -0,0 +1,155 @@
+/* Copyright (C) 1992, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* In various parts of this file we define the System V values for
+ things as _SYSV_<whatever>. Those are the values that System V
+ uses for termio, and also (SVR4) termios. Not necessarily the
+ same as the GNU termios that the library user sees. */
+
+/* Number of elements of c_cc. termio only. */
+#define _SYSV_NCC 8
+
+#define _SYSV_VINTR 0
+#define _SYSV_VQUIT 1
+#define _SYSV_VERASE 2
+#define _SYSV_VKILL 3
+#define _SYSV_VEOF 4
+/* This field means VEOF if ICANON, VMIN if not. */
+#define _SYSV_VMIN 4
+#define _SYSV_VEOL 5
+/* This field means VEOL if ICANON, VTIME if not. */
+#define _SYSV_VTIME 5
+#define _SYSV_VEOL2 6
+
+/* Flags in c_iflag. */
+#define _SYSV_IGNBRK 1
+#define _SYSV_BRKINT 2
+#define _SYSV_IGNPAR 4
+#define _SYSV_PARMRK 8
+#define _SYSV_INPCK 0x10
+#define _SYSV_ISTRIP 0x20
+#define _SYSV_INLCR 0x40
+#define _SYSV_IGNCR 0x80
+#define _SYSV_ICRNL 0x100
+#define _SYSV_IUCLC 0x200
+#define _SYSV_IXON 0x400
+#define _SYSV_IXANY 0x800
+#define _SYSV_IXOFF 0x1000
+#define _SYSV_IMAXBEL 0x2000
+
+/* Flags in c_cflag. */
+#define _SYSV_CBAUD 0xf
+#define _SYSV_CIBAUD 0xf0000 /* termios only. */
+#define _SYSV_IBSHIFT 16
+/* Values for CBAUD and CIBAUD. */
+#define _SYSV_B0 0
+#define _SYSV_B50 1
+#define _SYSV_B75 2
+#define _SYSV_B110 3
+#define _SYSV_B134 4
+#define _SYSV_B150 5
+#define _SYSV_B200 6
+#define _SYSV_B300 7
+#define _SYSV_B600 8
+#define _SYSV_B1200 9
+#define _SYSV_B1800 10
+#define _SYSV_B2400 11
+#define _SYSV_B4800 12
+#define _SYSV_B9600 13
+#define _SYSV_B19200 14
+#define _SYSV_B38400 15
+
+#define _SYSV_CS5 0
+#define _SYSV_CS6 0x10
+#define _SYSV_CS7 0x20
+#define _SYSV_CS8 0x30
+#define _SYSV_CSIZE 0x30
+#define _SYSV_CSTOPB 0x40
+#define _SYSV_CREAD 0x80
+#define _SYSV_PARENB 0x100
+#define _SYSV_PARODD 0x200
+#define _SYSV_HUPCL 0x400
+#define _SYSV_CLOCAL 0x800
+
+/* Flags in c_lflag. */
+#define _SYSV_ISIG 1
+#define _SYSV_ICANON 2
+#define _SYSV_ECHO 8
+#define _SYSV_ECHOE 0x10
+#define _SYSV_ECHOK 0x20
+#define _SYSV_ECHONL 0x40
+#define _SYSV_NOFLSH 0x80
+#define _SYSV_TOSTOP 0x100
+#define _SYSV_ECHOCTL 0x200
+#define _SYSV_ECHOPRT 0x400
+#define _SYSV_ECHOKE 0x800
+#define _SYSV_FLUSHO 0x2000
+#define _SYSV_PENDIN 0x4000
+#define _SYSV_IEXTEN 0x8000
+
+/* Flags in c_oflag. */
+#define _SYSV_OPOST 1
+#define _SYSV_OLCUC 2
+#define _SYSV_ONLCR 4
+#define _SYSV_NLDLY 0x100
+#define _SYSV_NL0 0
+#define _SYSV_NL1 0x100
+#define _SYSV_CRDLY 0x600
+#define _SYSV_CR0 0
+#define _SYSV_CR1 0x200
+#define _SYSV_CR2 0x400
+#define _SYSV_CR3 0x600
+#define _SYSV_TABDLY 0x1800
+#define _SYSV_TAB0 0
+#define _SYSV_TAB1 0x0800
+#define _SYSV_TAB2 0x1000
+/* TAB3 is an obsolete name for XTABS. But we provide it since some
+ programs expect it to exist. */
+#define _SYSV_TAB3 0x1800
+#define _SYSV_XTABS 0x1800
+#define _SYSV_BSDLY 0x2000
+#define _SYSV_BS0 0
+#define _SYSV_BS1 0x2000
+#define _SYSV_VTDLY 0x4000
+#define _SYSV_VT0 0
+#define _SYSV_VT1 0x4000
+#define _SYSV_FFDLY 0x8000
+#define _SYSV_FF0 0
+#define _SYSV_FF1 0x8000
+
+/* ioctl's. */
+
+#define _TCGETA 0x5401
+#define _TCSETA 0x5402
+#define _TCSETAW 0x5403
+#define _TCSETAF 0x5404
+#define _TCSBRK 0x5405
+#define _TCXONC 0x5406
+#define _TCFLSH 0x5407
+#define _TIOCGPGRP 0x7414
+#define _TIOCSPGRP 0x7415
+
+struct __sysv_termio
+ {
+ unsigned short c_iflag;
+ unsigned short c_oflag;
+ unsigned short c_cflag;
+ unsigned short c_lflag;
+ char c_line;
+ unsigned char c_cc[_SYSV_NCC];
+ };
diff --git a/libc/sysdeps/unix/sysv/tcdrain.c b/libc/sysdeps/unix/sysv/tcdrain.c
new file mode 100644
index 000000000..2f44fd156
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/tcdrain.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sysv_termio.h>
+#include <sys/ioctl.h>
+
+/* Wait for pending output to be written on FD. */
+int
+__libc_tcdrain (int fd)
+{
+ /* With an argument of 1, TCSBRK just waits for output to drain. */
+ return __ioctl (fd, _TCSBRK, 1);
+}
+weak_alias (__libc_tcdrain, tcdrain)
diff --git a/libc/sysdeps/unix/sysv/tcflow.c b/libc/sysdeps/unix/sysv/tcflow.c
new file mode 100644
index 000000000..dc67d0664
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/tcflow.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 1992, 1996, 1997, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
+#include <sysv_termio.h>
+
+/* Suspend or restart transmission on FD. */
+int
+tcflow (fd, action)
+ int fd;
+ int action;
+{
+ switch (action)
+ {
+ case TCOOFF:
+ return __ioctl (fd, _TCXONC, 0);
+ case TCOON:
+ return __ioctl (fd, _TCXONC, 1);
+ case TCIOFF:
+ return __ioctl (fd, _TCXONC, 2);
+ case TCION:
+ return __ioctl (fd, _TCXONC, 3);
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/tcflush.c b/libc/sysdeps/unix/sysv/tcflush.c
new file mode 100644
index 000000000..a98f13327
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/tcflush.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
+#include <sysv_termio.h>
+
+/* Flush pending data on FD. */
+int
+tcflush (fd, queue_selector)
+ int fd;
+ int queue_selector;
+{
+ switch (queue_selector)
+ {
+ case TCIFLUSH:
+ return __ioctl (fd, _TCFLSH, 0);
+ case TCOFLUSH:
+ return __ioctl (fd, _TCFLSH, 1);
+ case TCIOFLUSH:
+ return __ioctl (fd, _TCFLSH, 2);
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+}
diff --git a/libc/sysdeps/unix/sysv/tcgetattr.c b/libc/sysdeps/unix/sysv/tcgetattr.c
new file mode 100644
index 000000000..8cc912300
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/tcgetattr.c
@@ -0,0 +1,171 @@
+/* Copyright (C) 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sysv_termio.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+
+/* Put the state of FD into *TERMIOS_P. */
+int
+__tcgetattr (fd, termios_p)
+ int fd;
+ struct termios *termios_p;
+{
+ struct __sysv_termio buf;
+ int termio_speed;
+
+ if (termios_p == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (__ioctl (fd, _TCGETA, &buf) < 0)
+ return -1;
+
+ termio_speed = buf.c_cflag & _SYSV_CBAUD;
+ termios_p->__ospeed =
+ (termio_speed == _SYSV_B0 ? 0 :
+ termio_speed == _SYSV_B50 ? 50 :
+ termio_speed == _SYSV_B75 ? 75 :
+ termio_speed == _SYSV_B110 ? 110 :
+ termio_speed == _SYSV_B134 ? 134 :
+ termio_speed == _SYSV_B150 ? 150 :
+ termio_speed == _SYSV_B200 ? 200 :
+ termio_speed == _SYSV_B300 ? 300 :
+ termio_speed == _SYSV_B600 ? 600 :
+ termio_speed == _SYSV_B1200 ? 1200 :
+ termio_speed == _SYSV_B1800 ? 1800 :
+ termio_speed == _SYSV_B2400 ? 2400 :
+ termio_speed == _SYSV_B4800 ? 4800 :
+ termio_speed == _SYSV_B9600 ? 9600 :
+ termio_speed == _SYSV_B19200 ? 19200 :
+ termio_speed == _SYSV_B38400 ? 38400 :
+ -1);
+ termios_p->__ispeed = termios_p->__ospeed;
+
+ termios_p->c_iflag = 0;
+ if (buf.c_iflag & _SYSV_IGNBRK)
+ termios_p->c_iflag |= IGNBRK;
+ if (buf.c_iflag & _SYSV_BRKINT)
+ termios_p->c_iflag |= BRKINT;
+ if (buf.c_iflag & _SYSV_IGNPAR)
+ termios_p->c_iflag |= IGNPAR;
+ if (buf.c_iflag & _SYSV_PARMRK)
+ termios_p->c_iflag |= PARMRK;
+ if (buf.c_iflag & _SYSV_INPCK)
+ termios_p->c_iflag |= INPCK;
+ if (buf.c_iflag & _SYSV_ISTRIP)
+ termios_p->c_iflag |= ISTRIP;
+ if (buf.c_iflag & _SYSV_INLCR)
+ termios_p->c_iflag |= INLCR;
+ if (buf.c_iflag & _SYSV_IGNCR)
+ termios_p->c_iflag |= IGNCR;
+ if (buf.c_iflag & _SYSV_ICRNL)
+ termios_p->c_iflag |= ICRNL;
+ if (buf.c_iflag & _SYSV_IXON)
+ termios_p->c_iflag |= IXON;
+ if (buf.c_iflag & _SYSV_IXOFF)
+ termios_p->c_iflag |= IXOFF;
+ if (buf.c_iflag & _SYSV_IXANY)
+ termios_p->c_iflag |= IXANY;
+ if (buf.c_iflag & _SYSV_IMAXBEL)
+ termios_p->c_iflag |= IMAXBEL;
+
+ termios_p->c_oflag = 0;
+ if (buf.c_oflag & OPOST)
+ termios_p->c_oflag |= OPOST;
+ if (buf.c_oflag & ONLCR)
+ termios_p->c_oflag |= ONLCR;
+ termios_p->c_cflag = 0;
+ switch (buf.c_cflag & _SYSV_CSIZE)
+ {
+ case _SYSV_CS5:
+ termios_p->c_cflag |= CS5;
+ break;
+ case _SYSV_CS6:
+ termios_p->c_cflag |= CS6;
+ break;
+ case _SYSV_CS7:
+ termios_p->c_cflag |= CS7;
+ break;
+ case _SYSV_CS8:
+ termios_p->c_cflag |= CS8;
+ break;
+ }
+ if (buf.c_cflag & _SYSV_CSTOPB)
+ termios_p->c_cflag |= CSTOPB;
+ if (buf.c_cflag & _SYSV_CREAD)
+ termios_p->c_cflag |= CREAD;
+ if (buf.c_cflag & _SYSV_PARENB)
+ termios_p->c_cflag |= PARENB;
+ if (buf.c_cflag & _SYSV_PARODD)
+ termios_p->c_cflag |= PARODD;
+ if (buf.c_cflag & _SYSV_HUPCL)
+ termios_p->c_cflag |= HUPCL;
+ if (buf.c_cflag & _SYSV_CLOCAL)
+ termios_p->c_cflag |= CLOCAL;
+ termios_p->c_lflag = 0;
+ if (buf.c_lflag & _SYSV_ISIG)
+ termios_p->c_lflag |= _ISIG;
+ if (buf.c_lflag & _SYSV_ICANON)
+ termios_p->c_lflag |= _ICANON;
+ if (buf.c_lflag & _SYSV_ECHO)
+ termios_p->c_lflag |= _ECHO;
+ if (buf.c_lflag & _SYSV_ECHOE)
+ termios_p->c_lflag |= _ECHOE;
+ if (buf.c_lflag & _SYSV_ECHOK)
+ termios_p->c_lflag |= _ECHOK;
+ if (buf.c_lflag & _SYSV_ECHONL)
+ termios_p->c_lflag |= _ECHONL;
+ if (buf.c_lflag & _SYSV_NOFLSH)
+ termios_p->c_lflag |= _NOFLSH;
+ if (buf.c_lflag & _SYSV_TOSTOP)
+ termios_p->c_lflag |= _TOSTOP;
+ if (buf.c_lflag & _SYSV_ECHOKE)
+ termios_p->c_lflag |= ECHOKE;
+ if (buf.c_lflag & _SYSV_ECHOPRT)
+ termios_p->c_lflag |= ECHOPRT;
+ if (buf.c_lflag & _SYSV_ECHOCTL)
+ termios_p->c_lflag |= ECHOCTL;
+ if (buf.c_lflag & _SYSV_FLUSHO)
+ termios_p->c_lflag |= FLUSHO;
+ if (buf.c_lflag & _SYSV_PENDIN)
+ termios_p->c_lflag |= PENDIN;
+ if (buf.c_lflag & _SYSV_IEXTEN)
+ termios_p->c_lflag |= IEXTEN;
+
+ termios_p->c_cc[VEOF] = buf.c_cc[_SYSV_VEOF];
+ termios_p->c_cc[VEOL] = buf.c_cc[_SYSV_VEOL];
+ termios_p->c_cc[VEOL2] = buf.c_cc[_SYSV_VEOL2];
+ termios_p->c_cc[VERASE] = buf.c_cc[_SYSV_VERASE];
+ termios_p->c_cc[VKILL] = buf.c_cc[_SYSV_VKILL];
+ termios_p->c_cc[VINTR] = buf.c_cc[_SYSV_VINTR];
+ termios_p->c_cc[VQUIT] = buf.c_cc[_SYSV_VQUIT];
+ termios_p->c_cc[VSTART] = '\021'; /* XON (^Q). */
+ termios_p->c_cc[VSTOP] = '\023'; /* XOFF (^S). */
+ termios_p->c_cc[VSUSP] = '\0'; /* System V release 3 lacks job control. */
+ termios_p->c_cc[VMIN] = buf.c_cc[_SYSV_VMIN];
+ termios_p->c_cc[VTIME] = buf.c_cc[_SYSV_VTIME];
+
+ return 0;
+}
+
+weak_alias (__tcgetattr, tcgetattr)
diff --git a/libc/sysdeps/unix/sysv/tcgetpgrp.c b/libc/sysdeps/unix/sysv/tcgetpgrp.c
new file mode 100644
index 000000000..4f64eac63
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/tcgetpgrp.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 1992, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <termios.h>
+#include <sysv_termio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+/* Return the foreground process group ID of FD. */
+pid_t
+tcgetpgrp (fd)
+ int fd;
+{
+ int pgrp;
+ if (__ioctl (fd, _TIOCGPGRP, &pgrp) < 0)
+ return (pid_t) -1;
+ return (pid_t) pgrp;
+}
+libc_hidden_def (tcgetpgrp)
diff --git a/libc/sysdeps/unix/sysv/tcsendbrk.c b/libc/sysdeps/unix/sysv/tcsendbrk.c
new file mode 100644
index 000000000..f67e623e7
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/tcsendbrk.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <signal.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sysv_termio.h>
+#include <sys/ioctl.h>
+
+/* Send zero bits on FD. */
+int
+tcsendbreak (fd, duration)
+ int fd;
+ int duration;
+{
+ /* The break lasts 0.25 to 0.5 seconds if DURATION is zero,
+ and an implementation-defined period if DURATION is nonzero.
+ We define a positive DURATION to be number of milliseconds to break. */
+ if (duration <= 0)
+ return __ioctl (fd, _TCSBRK, 0);
+
+ /* ioctl can't send a break of any other duration for us.
+ This could be changed to use trickery (e.g. lower speed and
+ send a '\0') to send the break, but for now just return an error. */
+ __set_errno (EINVAL);
+ return -1;
+}
diff --git a/libc/sysdeps/unix/sysv/tcsetattr.c b/libc/sysdeps/unix/sysv/tcsetattr.c
new file mode 100644
index 000000000..d39ac76a3
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/tcsetattr.c
@@ -0,0 +1,210 @@
+/* Copyright (C) 1992, 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+
+#include <sysv_termio.h>
+
+
+const speed_t __unix_speeds[] =
+ {
+ 0,
+ 50,
+ 75,
+ 110,
+ 134,
+ 150,
+ 200,
+ 300,
+ 600,
+ 1200,
+ 1800,
+ 2400,
+ 4800,
+ 9600,
+ 19200,
+ 38400,
+ };
+
+
+/* Set the state of FD to *TERMIOS_P. */
+int
+tcsetattr (fd, optional_actions, termios_p)
+ int fd;
+ int optional_actions;
+ const struct termios *termios_p;
+{
+ struct __sysv_termio buf;
+ int ioctl_function;
+ size_t i;
+
+ if (termios_p == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ switch (optional_actions)
+ {
+ case TCSANOW:
+ ioctl_function = _TCSETA;
+ break;
+ case TCSADRAIN:
+ ioctl_function = _TCSETAW;
+ break;
+ case TCSAFLUSH:
+ ioctl_function = _TCSETAF;
+ break;
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ if (termios_p->__ispeed != termios_p->__ospeed)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ buf.c_cflag = -1;
+ for (i = 0; i <= sizeof (__unix_speeds) / sizeof (__unix_speeds[0]); ++i)
+ {
+ if (__unix_speeds[i] == termios_p->__ispeed)
+ buf.c_cflag = i;
+ }
+ if (buf.c_cflag == -1)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ buf.c_iflag = 0;
+ if (termios_p->c_iflag & IGNBRK)
+ buf.c_iflag |= _SYSV_IGNBRK;
+ if (termios_p->c_iflag & BRKINT)
+ buf.c_iflag |= _SYSV_BRKINT;
+ if (termios_p->c_iflag & IGNPAR)
+ buf.c_iflag |= _SYSV_IGNPAR;
+ if (termios_p->c_iflag & PARMRK)
+ buf.c_iflag |= _SYSV_PARMRK;
+ if (termios_p->c_iflag & INPCK)
+ buf.c_iflag |= _SYSV_INPCK;
+ if (termios_p->c_iflag & ISTRIP)
+ buf.c_iflag |= _SYSV_ISTRIP;
+ if (termios_p->c_iflag & INLCR)
+ buf.c_iflag |= _SYSV_INLCR;
+ if (termios_p->c_iflag & IGNCR)
+ buf.c_iflag |= _SYSV_IGNCR;
+ if (termios_p->c_iflag & ICRNL)
+ buf.c_iflag |= _SYSV_ICRNL;
+ if (termios_p->c_iflag & IXON)
+ buf.c_iflag |= _SYSV_IXON;
+ if (termios_p->c_iflag & IXOFF)
+ buf.c_iflag |= _SYSV_IXOFF;
+ if (termios_p->c_iflag & IXANY)
+ buf.c_iflag |= _SYSV_IXANY;
+ if (termios_p->c_iflag & IMAXBEL)
+ buf.c_iflag |= _SYSV_IMAXBEL;
+
+ buf.c_oflag = 0;
+ if (termios_p->c_oflag & OPOST)
+ buf.c_oflag |= _SYSV_OPOST;
+ if (termios_p->c_oflag & ONLCR)
+ buf.c_oflag |= _SYSV_ONLCR;
+
+ /* So far, buf.c_cflag contains the speed in CBAUD. */
+ if (termios_p->c_cflag & CSTOPB)
+ buf.c_cflag |= _SYSV_CSTOPB;
+ if (termios_p->c_cflag & CREAD)
+ buf.c_cflag |= _SYSV_CREAD;
+ if (termios_p->c_cflag & PARENB)
+ buf.c_cflag |= _SYSV_PARENB;
+ if (termios_p->c_cflag & PARODD)
+ buf.c_cflag |= _SYSV_PARODD;
+ if (termios_p->c_cflag & HUPCL)
+ buf.c_cflag |= _SYSV_HUPCL;
+ if (termios_p->c_cflag & CLOCAL)
+ buf.c_cflag |= _SYSV_CLOCAL;
+ switch (termios_p->c_cflag & CSIZE)
+ {
+ case CS5:
+ buf.c_cflag |= _SYSV_CS5;
+ break;
+ case CS6:
+ buf.c_cflag |= _SYSV_CS6;
+ break;
+ case CS7:
+ buf.c_cflag |= _SYSV_CS7;
+ break;
+ case CS8:
+ buf.c_cflag |= _SYSV_CS8;
+ break;
+ }
+
+ buf.c_lflag = 0;
+ if (termios_p->c_lflag & ISIG)
+ buf.c_lflag |= _SYSV_ISIG;
+ if (termios_p->c_lflag & ICANON)
+ buf.c_lflag |= _SYSV_ICANON;
+ if (termios_p->c_lflag & ECHO)
+ buf.c_lflag |= _SYSV_ECHO;
+ if (termios_p->c_lflag & ECHOE)
+ buf.c_lflag |= _SYSV_ECHOE;
+ if (termios_p->c_lflag & ECHOK)
+ buf.c_lflag |= _SYSV_ECHOK;
+ if (termios_p->c_lflag & ECHONL)
+ buf.c_lflag |= _SYSV_ECHONL;
+ if (termios_p->c_lflag & NOFLSH)
+ buf.c_lflag |= _SYSV_NOFLSH;
+ if (termios_p->c_lflag & TOSTOP)
+ buf.c_lflag |= _SYSV_TOSTOP;
+ if (termios_p->c_lflag & ECHOCTL)
+ buf.c_lflag |= _SYSV_ECHOCTL;
+ if (termios_p->c_lflag & ECHOPRT)
+ buf.c_lflag |= _SYSV_ECHOPRT;
+ if (termios_p->c_lflag & ECHOKE)
+ buf.c_lflag |= _SYSV_ECHOKE;
+ if (termios_p->c_lflag & FLUSHO)
+ buf.c_lflag |= _SYSV_FLUSHO;
+ if (termios_p->c_lflag & PENDIN)
+ buf.c_lflag |= _SYSV_PENDIN;
+ if (termios_p->c_lflag & IEXTEN)
+ buf.c_lflag |= _SYSV_IEXTEN;
+
+ buf.c_cc[_SYSV_VINTR] = termios_p->c_cc[VINTR];
+ buf.c_cc[_SYSV_VQUIT] = termios_p->c_cc[VQUIT];
+ buf.c_cc[_SYSV_VERASE] = termios_p->c_cc[VERASE];
+ buf.c_cc[_SYSV_VKILL] = termios_p->c_cc[VKILL];
+ if (buf.c_lflag & _SYSV_ICANON)
+ {
+ buf.c_cc[_SYSV_VEOF] = termios_p->c_cc[VEOF];
+ buf.c_cc[_SYSV_VEOL] = termios_p->c_cc[VEOL];
+ }
+ else
+ {
+ buf.c_cc[_SYSV_VMIN] = termios_p->c_cc[VMIN];
+ buf.c_cc[_SYSV_VTIME] = termios_p->c_cc[VTIME];
+ }
+ buf.c_cc[_SYSV_VEOL2] = termios_p->c_cc[VEOL2];
+
+ if (__ioctl (fd, ioctl_function, &buf) < 0)
+ return -1;
+ return 0;
+}
+libc_hidden_def (tcsetattr)
diff --git a/libc/sysdeps/unix/sysv/tcsetpgrp.c b/libc/sysdeps/unix/sysv/tcsetpgrp.c
new file mode 100644
index 000000000..5bcaee76f
--- /dev/null
+++ b/libc/sysdeps/unix/sysv/tcsetpgrp.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1992, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/types.h>
+#include <sysv_termio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
+/* Set the foreground process group ID of FD set PGRP_ID. */
+int
+tcsetpgrp (fd, pgrp_id)
+ int fd;
+ pid_t pgrp_id;
+{
+ return __ioctl (fd, _TIOCSPGRP, &pgrp_id);
+}
diff --git a/libc/sysdeps/unix/telldir.c b/libc/sysdeps/unix/telldir.c
new file mode 100644
index 000000000..cb9efcfa3
--- /dev/null
+++ b/libc/sysdeps/unix/telldir.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1991, 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <dirent.h>
+
+#include <dirstream.h>
+
+/* Return the current position of DIRP. */
+long int
+telldir (DIR *dirp)
+{
+ return dirp->filepos;
+}
diff --git a/libc/sysdeps/unix/time.c b/libc/sysdeps/unix/time.c
new file mode 100644
index 000000000..f31ee9634
--- /dev/null
+++ b/libc/sysdeps/unix/time.c
@@ -0,0 +1,42 @@
+/* Copyright (C) 1991,92,97,2001,02 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stddef.h> /* For NULL. */
+#include <time.h>
+#include <sys/time.h>
+
+
+/* Return the current time as a `time_t' and also put it in *T if T is
+ not NULL. Time is represented as seconds from Jan 1 00:00:00 1970. */
+time_t
+time (t)
+ time_t *t;
+{
+ struct timeval tv;
+ time_t result;
+
+ if (__gettimeofday (&tv, (struct timezone *) NULL))
+ result = (time_t) -1;
+ else
+ result = (time_t) tv.tv_sec;
+
+ if (t != NULL)
+ *t = result;
+ return result;
+}
+libc_hidden_def (time)
diff --git a/libc/sysdeps/unix/utime.c b/libc/sysdeps/unix/utime.c
new file mode 100644
index 000000000..4a1815b2c
--- /dev/null
+++ b/libc/sysdeps/unix/utime.c
@@ -0,0 +1,50 @@
+/* Copyright (C) 1991,94,97,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <utime.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+
+/* Set the access and modification times of FILE to those given in TIMES.
+ If TIMES is NULL, set them to the current time. */
+int
+utime (file, times)
+ const char *file;
+ const struct utimbuf *times;
+{
+ struct timeval timevals[2];
+ struct timeval *tvp;
+
+ if (times != NULL)
+ {
+ timevals[0].tv_sec = (time_t) times->actime;
+ timevals[0].tv_usec = 0L;
+ timevals[1].tv_sec = (time_t) times->modtime;
+ timevals[1].tv_usec = 0L;
+ tvp = timevals;
+ }
+ else
+ tvp = NULL;
+
+ return __utimes (file, tvp);
+}
+libc_hidden_def (utime)
diff --git a/libc/sysdeps/unix/x86_64/sysdep.S b/libc/sysdeps/unix/x86_64/sysdep.S
new file mode 100644
index 000000000..aca81fef2
--- /dev/null
+++ b/libc/sysdeps/unix/x86_64/sysdep.S
@@ -0,0 +1,90 @@
+/* Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#define _ERRNO_H
+#include <bits/errno.h>
+#include <bp-asm.h>
+#include <bp-sym.h>
+#include <tls.h>
+
+#ifdef IS_IN_rtld
+# include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
+#endif
+
+.globl C_SYMBOL_NAME(errno)
+.globl syscall_error
+
+#undef syscall_error
+#ifdef NO_UNDERSCORES
+__syscall_error:
+#else
+syscall_error:
+#endif
+#if defined (EWOULDBLOCK_sys) && EWOULDBLOCK_sys != EAGAIN
+ /* We translate the system's EWOULDBLOCK error into EAGAIN.
+ The GNU C library always defines EWOULDBLOCK==EAGAIN.
+ EWOULDBLOCK_sys is the original number. */
+ cmpq $EWOULDBLOCK_sys, %rax /* Is it the old EWOULDBLOCK? */
+ jne notb /* Branch if not. */
+ movl $EAGAIN, %eax /* Yes; translate it to EAGAIN. */
+notb:
+#endif
+#if USE___THREAD
+# ifdef PIC
+ movq C_SYMBOL_NAME(errno@GOTTPOFF)(%rip), %rcx
+ movl %eax, %fs:0(%rcx)
+# else
+ movl %eax, %fs:C_SYMBOL_NAME(errno@TPOFF)
+# endif
+#elif !defined PIC
+# ifndef _LIBC_REENTRANT
+ movl %eax, C_SYMBOL_NAME(errno)
+# else
+ pushq %rax
+ cfi_adjust_cfa_offset(8)
+ PUSH_ERRNO_LOCATION_RETURN
+ call BP_SYM (__errno_location)
+ POP_ERRNO_LOCATION_RETURN
+ popq %rcx
+ cfi_adjust_cfa_offset(-8)
+ movl %ecx, (%rax)
+# endif
+#else
+# if RTLD_PRIVATE_ERRNO
+ leaq rtld_errno(%rip), %rcx
+ movl %eax, (%rcx)
+# elif !defined _LIBC_REENTRANT
+ movq C_SYMBOL_NAME(errno)@GOTPCREL(%rip), %rcx
+ movl %eax, (%rcx)
+# else
+ pushq %rax
+ cfi_adjust_cfa_offset(8)
+ PUSH_ERRNO_LOCATION_RETURN
+ call C_SYMBOL_NAME (BP_SYM (__errno_location)@PLT)
+ POP_ERRNO_LOCATION_RETURN
+ popq %rcx
+ cfi_adjust_cfa_offset(-8)
+ movl %ecx, (%rax)
+# endif
+#endif
+ movq $-1, %rax
+ ret
+
+#undef __syscall_error
+END (__syscall_error)
diff --git a/libc/sysdeps/unix/x86_64/sysdep.h b/libc/sysdeps/unix/x86_64/sysdep.h
new file mode 100644
index 000000000..95e456c17
--- /dev/null
+++ b/libc/sysdeps/unix/x86_64/sysdep.h
@@ -0,0 +1,35 @@
+/* Copyright (C) 1991, 92, 93, 95, 96, 97, 2000, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdeps/unix/sysdep.h>
+#include <sysdeps/x86_64/sysdep.h>
+
+#ifdef __ASSEMBLER__
+
+/* This is defined as a separate macro so that other sysdep.h files
+ can include this one and then redefine DO_CALL. */
+
+#define DO_CALL(syscall_name, args) \
+ lea SYS_ify (syscall_name), %rax; \
+ syscall
+
+#define r0 %rax /* Normal return-value register. */
+#define r1 %rbx /* Secondary return-value register. */
+#define MOVE(x,y) movq x, y
+
+#endif /* __ASSEMBLER__ */
diff --git a/libc/sysdeps/unix/xmknod.c b/libc/sysdeps/unix/xmknod.c
new file mode 100644
index 000000000..92f420f72
--- /dev/null
+++ b/libc/sysdeps/unix/xmknod.c
@@ -0,0 +1,42 @@
+/* xmknod call using old-style Unix mknod system call.
+ Copyright (C) 1991,1993,1995,1996,1997,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+extern int __syscall_mknod (const char *, mode_t, dev_t);
+
+/* 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)
+{
+ if (vers != _MKNOD_VER)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return __syscall_mknod (path, mode, *dev);
+}
+
+weak_alias (__xmknod, _xmknod)
+libc_hidden_def (__xmknod)
diff --git a/libc/sysdeps/unix/xstat.c b/libc/sysdeps/unix/xstat.c
new file mode 100644
index 000000000..f54c3d4df
--- /dev/null
+++ b/libc/sysdeps/unix/xstat.c
@@ -0,0 +1,39 @@
+/* xstat using old-style Unix stat system call.
+ Copyright (C) 1991,1995,1996,1997,2000,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <bp-checks.h>
+
+extern int __syscall_stat (const char *__unbounded, struct stat *__unbounded);
+
+int
+__xstat (int vers, const char *file, struct stat *buf)
+{
+ if (vers != _STAT_VER)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return __syscall_stat (CHECK_STRING (file), CHECK_1 (buf));
+}
+hidden_def (__xstat)
+weak_alias (__xstat, _xstat)