From 8e029c653e0567df7ce6933dde41f5830dbbbcda Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 6 Oct 2006 05:09:23 +0000 Subject: [PATCH] Libc-391.5.18.tar.gz --- BSDmakefile | 170 ++++++++++++++ GNUmakefile | 307 +------------------------ Makefile | 8 +- Makefile.xbs | 18 +- darwin/copyfile.c | 199 +++++++++++++--- fbsdcompat/_fpmath.h | 2 +- gdtoa/arith.h | 4 + gdtoa/gd_qnan.h | 2 +- gen/FreeBSD/getcwd.c.patch | 108 ++++++++- gen/FreeBSD/opendir.c.patch | 38 ++- gen/Makefile.inc | 2 +- gen/stack_logging.c | 8 +- i386/pthreads/pthread_set_self.s | 1 - i386/string/bcopy.s | 6 +- i386/string/bzero.s | 2 +- i386/string/memset.s | 6 +- i386/string/strncpy.s | 2 +- i386/sys/ATPgetreq.s | 2 +- i386/sys/ATPgetrsp.s | 2 +- i386/sys/ATPsndreq.s | 2 +- i386/sys/ATPsndrsp.s | 2 +- i386/sys/ATgetmsg.s | 2 +- i386/sys/ATputmsg.s | 2 +- i386/sys/ATsocket.s | 2 +- i386/sys/Makefile.inc | 2 + i386/sys/OSAtomic.s | 6 +- i386/sys/__mmap.s | 2 +- i386/sys/__pthread_canceled.s | 2 +- i386/sys/__pthread_markcancel.s | 2 +- i386/sys/__semwait_signal.s | 2 +- i386/sys/_exit.s | 2 +- i386/sys/_getlogin.s | 2 +- i386/sys/_pthread_kill.s | 2 +- i386/sys/_setjmp.s | 18 +- i386/sys/_setlogin.s | 2 +- i386/sys/_sysctl.s | 2 +- i386/sys/accept.s | 9 +- i386/sys/access.s | 2 +- i386/sys/acct.s | 2 +- i386/sys/add_profil.s | 2 +- i386/sys/adjtime.s | 2 +- i386/sys/aio_cancel.s | 2 +- i386/sys/aio_error.s | 2 +- i386/sys/aio_fsync.s | 2 +- i386/sys/aio_read.s | 2 +- i386/sys/aio_return.s | 2 +- i386/sys/aio_suspend.s | 4 +- i386/sys/aio_write.s | 4 +- i386/sys/audit.s | 2 +- i386/sys/auditctl.s | 2 +- i386/sys/auditon.s | 2 +- i386/sys/auditsvc.s | 2 +- i386/sys/bind.s | 9 +- i386/sys/cerror.s | 2 +- i386/sys/chdir.s | 2 +- i386/sys/checkuseraccess.s | 2 +- i386/sys/chflags.s | 2 +- i386/sys/chmod.s | 2 +- i386/sys/chown.s | 2 +- i386/sys/chroot.s | 2 +- i386/sys/close.s | 2 +- i386/sys/connect.s | 9 +- i386/sys/dup.s | 2 +- i386/sys/dup2.s | 2 +- i386/sys/exchangedata.s | 2 +- i386/sys/execve.s | 2 +- i386/sys/fchdir.s | 2 +- i386/sys/fchflags.s | 2 +- i386/sys/fchmod.s | 2 +- i386/sys/fchown.s | 2 +- i386/sys/fcntl.s | 2 +- i386/sys/fgetxattr.s | 2 +- i386/sys/fhopen.s | 2 +- i386/sys/flistxattr.s | 2 +- i386/sys/flock.s | 2 +- i386/sys/fork.s | 2 +- i386/sys/fpathconf.s | 2 +- i386/sys/fremovexattr.s | 2 +- i386/sys/fsctl.s | 2 +- i386/sys/fsetxattr.s | 2 +- i386/sys/fstat.s | 2 +- i386/sys/fstatfs.s | 2 +- i386/sys/fstatv.s | 2 +- i386/sys/fsync.s | 2 +- i386/sys/ftruncate.s | 2 +- i386/sys/futimes.s | 2 +- i386/sys/getattrlist.s | 9 +- i386/sys/getaudit.s | 2 +- i386/sys/getaudit_addr.s | 2 +- i386/sys/getauid.s | 2 +- i386/sys/getdirentries.s | 2 +- i386/sys/getdirentriesattr.s | 2 +- i386/sys/getdtablesize.s | 2 +- i386/sys/getegid.s | 2 +- i386/sys/geteuid.s | 2 +- i386/sys/getfh.s | 2 +- i386/sys/getfsstat.s | 2 +- i386/sys/getgid.s | 2 +- i386/sys/getgroups.s | 2 +- i386/sys/getitimer.s | 2 +- i386/sys/getpeername.s | 9 +- i386/sys/getpgid.s | 2 +- i386/sys/getpgrp.s | 2 +- i386/sys/getpid.s | 2 +- i386/sys/getppid.s | 2 +- i386/sys/getpriority.s | 2 +- i386/sys/getrlimit.s | 2 +- i386/sys/getrusage.s | 2 +- i386/sys/getsid.s | 2 +- i386/sys/getsockname.s | 9 +- i386/sys/getsockopt.s | 2 +- i386/sys/getuid.s | 2 +- i386/sys/getxattr.s | 2 +- i386/sys/i386_gettimeofday.s | 4 +- i386/sys/ioctl.s | 2 +- i386/sys/issetugid.s | 2 +- i386/sys/kevent.s | 2 +- i386/sys/kill.s | 2 +- i386/sys/kqueue.s | 2 +- i386/sys/kqueue_from_portset_np.s | 2 +- i386/sys/kqueue_portset_np.s | 2 +- i386/sys/ktrace.s | 2 +- i386/sys/lchown.s | 9 +- i386/sys/link.s | 2 +- i386/sys/lio_listio.s | 2 +- i386/sys/listen.s | 9 +- i386/sys/listxattr.s | 2 +- i386/sys/load_shared_file.s | 2 +- i386/sys/lseek.s | 2 +- i386/sys/lstat.s | 2 +- i386/sys/lstatv.s | 2 +- i386/sys/madvise.s | 2 +- i386/sys/mincore.s | 2 +- i386/sys/minherit.s | 2 +- i386/sys/mkcomplex.s | 2 +- i386/sys/mkdir.s | 2 +- i386/sys/mkfifo.s | 2 +- i386/sys/mknod.s | 2 +- i386/sys/mlock.s | 2 +- i386/sys/mlockall.s | 2 +- i386/sys/mount.s | 2 +- i386/sys/msgget.s | 2 +- i386/sys/msgrcv.s | 2 +- i386/sys/msgsnd.s | 2 +- i386/sys/msgsys.s | 2 +- i386/sys/munlock.s | 2 +- i386/sys/munlockall.s | 2 +- i386/sys/new_system_shared_regions.s | 2 +- i386/sys/nfsclnt.s | 2 +- i386/sys/nfssvc.s | 2 +- i386/sys/open.s | 2 +- i386/sys/pathconf.s | 2 +- i386/sys/pipe.s | 2 +- i386/sys/poll.s | 2 +- i386/sys/posix_madvise.s | 2 +- i386/sys/pread.s | 2 +- i386/sys/profil.s | 2 +- i386/sys/pthread_sigmask.s | 2 +- i386/sys/ptrace.s | 2 +- i386/sys/pwrite.s | 2 +- i386/sys/quota.s | 2 +- i386/sys/quotactl.s | 2 +- i386/sys/read.s | 2 +- i386/sys/readlink.s | 2 +- i386/sys/readv.s | 2 +- i386/sys/reboot.s | 2 +- i386/sys/recvfrom.s | 9 +- i386/sys/recvmsg.s | 9 +- i386/sys/removexattr.s | 2 +- i386/sys/rename.s | 2 +- i386/sys/reset_shared_file.s | 2 +- i386/sys/revoke.s | 2 +- i386/sys/rmdir.s | 2 +- i386/sys/searchfs.s | 2 +- i386/sys/select.s | 2 +- i386/sys/sem_close.s | 2 +- i386/sys/sem_destroy.s | 2 +- i386/sys/sem_getvalue.s | 2 +- i386/sys/sem_init.s | 2 +- i386/sys/sem_post.s | 2 +- i386/sys/sem_trywait.s | 2 +- i386/sys/sem_wait.s | 2 +- i386/sys/semget.s | 2 +- i386/sys/semop.s | 2 +- i386/sys/semsys.s | 2 +- i386/sys/sendmsg.s | 9 +- i386/sys/sendto.s | 9 +- i386/sys/setattrlist.s | 9 +- i386/sys/setaudit.s | 2 +- i386/sys/setaudit_addr.s | 2 +- i386/sys/setauid.s | 2 +- i386/sys/setegid.s | 2 +- i386/sys/seteuid.s | 2 +- i386/sys/setgid.s | 2 +- i386/sys/setgroups.s | 2 +- i386/sys/setitimer.s | 2 +- i386/sys/setjmp.s | 8 +- i386/sys/setpgid.s | 2 +- i386/sys/setpriority.s | 2 +- i386/sys/setprivexec.s | 2 +- i386/sys/setquota.s | 2 +- i386/sys/setrlimit.s | 2 +- i386/sys/setsid.s | 2 +- i386/sys/setsockopt.s | 2 +- i386/sys/settimeofday.s | 2 +- i386/sys/setuid.s | 2 +- i386/sys/setxattr.s | 2 +- i386/sys/shmat.s | 2 +- i386/sys/shmdt.s | 2 +- i386/sys/shmget.s | 2 +- i386/sys/shmsys.s | 2 +- i386/sys/shutdown.s | 2 +- i386/sys/sigaltstack.s | 2 +- i386/sys/sigpending.s | 2 +- i386/sys/sigprocmask.s | 2 +- i386/sys/sigreturn.s | 2 +- i386/sys/sigwait.s | 2 +- i386/sys/socket.s | 2 +- i386/sys/socketpair.s | 9 +- i386/sys/stat.s | 2 +- i386/sys/statfs.s | 2 +- i386/sys/statv.s | 2 +- i386/sys/swapon.s | 2 +- i386/sys/symlink.s | 2 +- i386/sys/sync.s | 2 +- i386/sys/syscall.s | 2 +- i386/sys/systable.s | 2 +- i386/sys/truncate.s | 2 +- i386/sys/umask.s | 2 +- i386/sys/undelete.s | 2 +- i386/sys/unlink.s | 2 +- i386/sys/unmount.s | 2 +- i386/sys/utimes.s | 2 +- i386/sys/vfork.s | 2 +- i386/sys/wait4.s | 2 +- i386/sys/write.s | 2 +- i386/sys/writev.s | 2 +- include/libkern/OSAtomic.h | 8 +- include/machine/limits.h | 2 +- locale/Makefile.inc | 13 +- mach/headers/task.h | 2 + mach/headers/thread_act.h | 2 + pthreads/Makefile.inc | 3 +- pthreads/lock.s | 48 +++- pthreads/pthread.c | 2 +- pthreads/pthread_internals.h | 6 +- pthreads/stack.s | 19 ++ pthreads/thread_setup.c | 47 ++++ sys/fcntl64.c | 3 + sys/sigtramp.c | 2 +- x86_64/gen/Makefile.inc | 6 + x86_64/gen/mcount.s | 52 +++++ x86_64/mach/Makefile.inc | 3 + x86_64/pthreads/Makefile.inc | 9 + x86_64/pthreads/get_cpu_capabilities.s | 36 +++ x86_64/pthreads/pthread_getspecific.s | 31 +++ x86_64/pthreads/pthread_self.s | 31 +++ x86_64/pthreads/pthread_set_self.s | 33 +++ x86_64/stdlib/gdtoa.mk | 2 + x86_64/string/Makefile.inc | 20 ++ x86_64/string/bcmp.s | 29 +++ x86_64/string/bcopy.s | 48 ++++ x86_64/string/bzero.s | 38 +++ x86_64/string/memcmp.s | 174 ++++++++++++++ x86_64/string/memcpy.s | 33 +++ x86_64/string/memmove.s | 33 +++ x86_64/string/memset.s | 216 +++++++++++++++++ x86_64/string/strcmp.s | 136 +++++++++++ x86_64/string/strcpy.s | 148 ++++++++++++ x86_64/string/strlen.s | 76 ++++++ x86_64/string/strncmp.s | 174 ++++++++++++++ x86_64/string/strncpy.s | 182 +++++++++++++++ x86_64/sys/Makefile.inc | 232 +++++++++++++++++++ x86_64/sys/OSAtomic.s | 163 +++++++++++++ x86_64/sys/SYS.h | 108 +++++++++ x86_64/sys/__fcntl.s | 29 +++ x86_64/sys/__ioctl.s | 29 +++ x86_64/sys/_setjmp.s | 123 ++++++++++ x86_64/sys/cerror.s | 47 ++++ x86_64/sys/fork.s | 131 +++++++++++ x86_64/sys/getpid.s | 51 ++++ x86_64/sys/i386_gettimeofday.s | 43 ++++ x86_64/sys/lseek.s | 29 +++ x86_64/sys/pipe.s | 32 +++ x86_64/sys/ptrace.s | 34 +++ x86_64/sys/setjmp.s | 104 +++++++++ x86_64/sys/sigaltstack.s | 29 +++ x86_64/sys/sigreturn.s | 29 +++ x86_64/sys/syscall.s | 32 +++ x86_64/sys/vfork.s | 65 ++++++ 290 files changed, 3795 insertions(+), 635 deletions(-) create mode 100644 BSDmakefile create mode 100644 x86_64/gen/Makefile.inc create mode 100644 x86_64/gen/mcount.s create mode 100644 x86_64/mach/Makefile.inc create mode 100644 x86_64/pthreads/Makefile.inc create mode 100644 x86_64/pthreads/get_cpu_capabilities.s create mode 100644 x86_64/pthreads/pthread_getspecific.s create mode 100644 x86_64/pthreads/pthread_self.s create mode 100644 x86_64/pthreads/pthread_set_self.s create mode 100644 x86_64/stdlib/gdtoa.mk create mode 100644 x86_64/string/Makefile.inc create mode 100644 x86_64/string/bcmp.s create mode 100644 x86_64/string/bcopy.s create mode 100644 x86_64/string/bzero.s create mode 100644 x86_64/string/memcmp.s create mode 100644 x86_64/string/memcpy.s create mode 100644 x86_64/string/memmove.s create mode 100644 x86_64/string/memset.s create mode 100644 x86_64/string/strcmp.s create mode 100644 x86_64/string/strcpy.s create mode 100644 x86_64/string/strlen.s create mode 100644 x86_64/string/strncmp.s create mode 100644 x86_64/string/strncpy.s create mode 100644 x86_64/sys/Makefile.inc create mode 100644 x86_64/sys/OSAtomic.s create mode 100644 x86_64/sys/SYS.h create mode 100644 x86_64/sys/__fcntl.s create mode 100644 x86_64/sys/__ioctl.s create mode 100644 x86_64/sys/_setjmp.s create mode 100644 x86_64/sys/cerror.s create mode 100644 x86_64/sys/fork.s create mode 100644 x86_64/sys/getpid.s create mode 100644 x86_64/sys/i386_gettimeofday.s create mode 100644 x86_64/sys/lseek.s create mode 100644 x86_64/sys/pipe.s create mode 100644 x86_64/sys/ptrace.s create mode 100644 x86_64/sys/setjmp.s create mode 100644 x86_64/sys/sigaltstack.s create mode 100644 x86_64/sys/sigreturn.s create mode 100644 x86_64/sys/syscall.s create mode 100644 x86_64/sys/vfork.s diff --git a/BSDmakefile b/BSDmakefile new file mode 100644 index 0000000..45d508d --- /dev/null +++ b/BSDmakefile @@ -0,0 +1,170 @@ +.ifndef OBJROOT +OBJROOT != pwd +.endif +.ifndef SYMROOT +SYMROOT != pwd +.endif +ARCH != arch +.ifndef RC_ARCHS +RC_ARCHS = $(ARCH) +RC_$(RC_ARCHS) = 1 +.endif +NARCHS != echo $(RC_ARCHS) | wc -w +.ifdef ALTUSRLOCALLIBSYSTEM +LIBSYS = $(ALTUSRLOCALLIBSYSTEM) +.else +LIBSYS = $(NEXT_ROOT)/usr/local/lib/system +.endif +NJOBS != perl -e '$$n = `/usr/sbin/sysctl -n hw.ncpu`; printf "%d\n", $$n < 2 ? 2 : ($$n * 1.5)' +BSDMAKE = bsdmake -f Makefile +#BSDMAKEJ = $(BSDMAKE) -j $(NJOBS) +BSDMAKEJ = $(BSDMAKE) -j $(NJOBS) -P + +# This variables are to guarantee that the left-hand side of an expression is +# always a variable +dynamic = dynamic +static = static + +# Remove the arch stuff, since we know better here. +LOCAL_CFLAGS != echo $(RC_CFLAGS) | sed 's/ *-arch [^ ][^ ]*//g' + +FORMS := dynamic debug profile static + +all: build + +# These are the non B&I defaults +.ifndef RC_ProjectName +installhdrs: installhdrs-real +build: build-static build-profile build-debug build-dynamic +install: installhdrs install-all + +.else # RC_ProjectName + +# And these are to deal with B&I building libc differently +# based on RC_ProjectName. +.if $(RC_ProjectName) == Libc +installhdrs: +build: build-dynamic +install: BI-install-dynamic +.endif +.if $(RC_ProjectName) == Libc_headers +installhdrs: installhdrs-real +build: +install: installhdrs-real +.endif +.if $(RC_ProjectName) == Libc_man +installhdrs: +build: +install: install-man +.endif +.if $(RC_ProjectName) == Libc_static +installhdrs: +build: build-static +install: BI-install-static +.endif +.if $(RC_ProjectName) == Libc_debug +installhdrs: +build: build-debug +install: BI-install-debug +.endif +.if $(RC_ProjectName) == Libc_profile +installhdrs: +build: build-profile +install: BI-install-profile +.endif +.endif # RC_ProjectName + +# Because of 3780028, there are random failures on HFS because the +# CC_PRINT_OPTIONS_FILE can't be created. So we touch it first. +.if !empty $(CC_PRINT_OPTIONS_FILE) +$(CC_PRINT_OPTIONS_FILE): + touch $(CC_PRINT_OPTIONS_FILE) +.endif # CC_PRINT_OPTIONS_FILE + +.for F in $(FORMS) +.if $(dynamic) == $(F) +SUFFIX$(F) = +.else +SUFFIX$(F) = _$(F) +.endif +LIPOARGS$(F) != perl -e 'printf "%s\n", join(" ", map(qq(-arch $$_ \"$(OBJROOT)/obj.$$_/libc$(SUFFIX$(F)).a\"), qw($(RC_ARCHS))))' + +build-$(F): autopatch $(CC_PRINT_OPTIONS_FILE) +.for A in $(RC_ARCHS) +build-$(F): build-$(A)-$(F) +.endfor # RC_ARCHS +build-$(F): +.if $(NARCHS) == 1 + cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc$(SUFFIX$(F)).a" "$(SYMROOT)" +.else + lipo -create $(LIPOARGS$(F)) -output $(SYMROOT)/libc$(SUFFIX$(F)).a +.endif + +.for A in $(RC_ARCHS) +build-$(A)-$(F): + mkdir -p $(OBJROOT)/obj.$(A) && \ + MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH="$(A)" \ + MAKEFLAGS="" CFLAGS="-arch $(A) $(LOCAL_CFLAGS)" $(BSDMAKEJ) libc$(SUFFIX$(F)).a +.endfor # RC_ARCHS +.endfor # FORMS + +# We have to separately call bsdmake to patch the FreeBSD files, because of +# the way its cache works, it would otherwise pick A file in ${SYMROOT}, even +# over A .s file. +autopatch: +.for A in $(RC_ARCHS) + MACHINE_ARCH="$(A)" $(BSDMAKEJ) autopatch +.endfor # RC_ARCHS + +installsrc: + pax -rw . "$(SRCROOT)" + +installhdrs-real: $(CC_PRINT_OPTIONS_FILE) + MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" MAKEFLAGS="" \ + $(BSDMAKEJ) installhdrs +.for A in $(RC_ARCHS) + mkdir -p "$(OBJROOT)/obj.$(A)" && \ + MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH="$(A)" \ + MAKEFLAGS="" $(BSDMAKEJ) installhdrs-md +.endfor # RC_ARCHS + +.for F in $(FORMS) +BI-install-$(F): build-$(F) + mkdir -p $(DSTROOT)/usr/local/lib/system + if [ -f "$(SYMROOT)/libc$(SUFFIX$(F)).a" ]; then \ + echo "Installing libc$(SUFFIX$(F)).a" && \ + install -c -m 444 "$(SYMROOT)/libc$(SUFFIX$(F)).a" \ + $(DSTROOT)/usr/local/lib/system && \ + ranlib "$(DSTROOT)/usr/local/lib/system/libc$(SUFFIX$(F)).a"; \ + fi +.if !empty $(RC_ppc) && ($(static) != $(F)) + if [ -f "$(OBJROOT)/obj.ppc/libc-ldbl128$(SUFFIX$(F)).a" ]; then \ + echo "Installing libldbl128$(SUFFIX$(F)).a" ; \ + $(SRCROOT)/make_libldbl128 "$(OBJROOT)/obj.ppc/libc-ldbl128$(SUFFIX$(F)).a" \ + "$(SUFFIX$(F))" "$(DSTROOT)/usr/local/lib/system" $(LIBSYS) ; \ + fi +.endif # RC_ppc && !static +.endfor # FORMS + +# Don't use -j here; it may try to make links before the files are copied +install-man: + mkdir -p $(DSTROOT)/usr/share/man/man2 + mkdir -p $(DSTROOT)/usr/share/man/man3 + mkdir -p $(DSTROOT)/usr/share/man/man4 + mkdir -p $(DSTROOT)/usr/share/man/man5 + mkdir -p $(DSTROOT)/usr/share/man/man7 + MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" NOMANCOMPRESS=1 \ + MACHINE_ARCH="$(ARCH)" MAKEFLAGS="" $(BSDMAKE) autopatchman maninstall + +install-all: build install-man +.for F in $(FORMS) +install-all: BI-install-$(F) +.endfor # FORMS + +clean: +.for F in $(FORMS) + rm -f $(OBJROOT)/libc$(SUFFIX$(F)).a +.endfor # FORMS +.for A in $(RC_ARCHS) + rm -rf $(OBJROOT)/obj.$(A) +.endfor # RC_ARCHS diff --git a/GNUmakefile b/GNUmakefile index 46b1c66..5b1746d 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,304 +1,5 @@ -ifndef $(OBJROOT) -OBJROOT = . -endif -ifndef $(SYMROOT) -SYMROOT = . -endif -ARCH = $(shell arch) -ifndef RC_ARCHS -RC_$(ARCH) = 1 -RC_ARCHS = $(ARCH) -endif -ifdef ALTUSRLOCALLIBSYSTEM -LIBSYS = $(ALTUSRLOCALLIBSYSTEM) -else -LIBSYS = $(NEXT_ROOT)/usr/local/lib/system -endif -NJOBS = $(shell perl -e '$$n = `/usr/sbin/sysctl -n hw.ncpu`; printf "%d\n", $$n < 2 ? 2 : ($$n * 1.5)') -BSDMAKE = bsdmake -j $(NJOBS) +all: + @bsdmake -# Remove the arch stuff, since we know better here. -LOCAL_CFLAGS = $(filter-out -arch ppc -arch ppc64 -arch i386,$(RC_CFLAGS)) - -all: build - -# These are the non B&I defaults -ifndef RC_ProjectName -installhdrs: installhdrs-real -build: build-static build-profile build-debug build-dynamic -install: installhdrs install-all -endif - -# And these are to deal with B&I building libc differently -# based on RC_ProjectName. -ifeq ($(RC_ProjectName),Libc) -installhdrs: -build: build-dynamic -install: BI-install-dynamic -endif -ifeq ($(RC_ProjectName),Libc_headers) -installhdrs: installhdrs-real -build: -install: installhdrs-real -endif -ifeq ($(RC_ProjectName),Libc_man) -installhdrs: -build: -install: install-man -endif -ifeq ($(RC_ProjectName),Libc_static) -installhdrs: -build: build-static -install: BI-install-static -endif -ifeq ($(RC_ProjectName),Libc_debug) -installhdrs: -build: build-debug -install: BI-install-debug -endif -ifeq ($(RC_ProjectName),Libc_profile) -installhdrs: -build: build-profile -install: BI-install-profile -endif - -# Because of 3780028, there are random failures on HFS because the -# CC_PRINT_OPTIONS_FILE can't be created. So we touch it first. -ifneq ($(CC_PRINT_OPTIONS_FILE),) -$(CC_PRINT_OPTIONS_FILE): - touch $(CC_PRINT_OPTIONS_FILE) -endif - -build-static: autopatch $(CC_PRINT_OPTIONS_FILE) build-ppc-static build-ppc64-static build-i386-static - @echo "Creating final libc_static.a" -ifeq ($(words $(RC_ARCHS)),1) - cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc_static.a" "$(SYMROOT)" -else - lipo -create \ - $(foreach A,$(RC_ARCHS),-arch $(A) "$(OBJROOT)/obj.$(A)/libc_static.a") \ - -output $(SYMROOT)/libc_static.a -endif -build-profile: autopatch $(CC_PRINT_OPTIONS_FILE) build-ppc-profile build-ppc64-profile build-i386-profile - @echo "Creating final libc_profile.a" -ifeq ($(words $(RC_ARCHS)),1) - cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc_profile.a" "$(SYMROOT)" -else - lipo -create \ - $(foreach A,$(RC_ARCHS),-arch $(A) "$(OBJROOT)/obj.$(A)/libc_profile.a") \ - -output $(SYMROOT)/libc_profile.a -endif -build-debug: autopatch $(CC_PRINT_OPTIONS_FILE) build-ppc-debug build-ppc64-debug build-i386-debug - @echo "Creating final libc_debug.a" -ifeq ($(words $(RC_ARCHS)),1) - cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc_debug.a" "$(SYMROOT)" -else - lipo -create \ - $(foreach A,$(RC_ARCHS),-arch $(A) "$(OBJROOT)/obj.$(A)/libc_debug.a") \ - -output $(SYMROOT)/libc_debug.a -endif -build-dynamic: autopatch $(CC_PRINT_OPTIONS_FILE) build-ppc-dynamic build-ppc64-dynamic build-i386-dynamic - @echo "Creating final libc.a" -ifeq ($(words $(RC_ARCHS)),1) - cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc.a" "$(SYMROOT)" -else - lipo -create \ - $(foreach A,$(RC_ARCHS),-arch $(A) "$(OBJROOT)/obj.$(A)/libc.a") \ - -output $(SYMROOT)/libc.a -endif -build-ppc-static: -ifneq ($(RC_ppc),) - mkdir -p $(OBJROOT)/obj.ppc ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \ - MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc_static.a -endif -build-ppc64-static: -ifneq ($(RC_ppc64),) - mkdir -p $(OBJROOT)/obj.ppc64 ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \ - MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_static.a -endif -build-i386-static: -ifneq ($(RC_i386),) - mkdir -p $(OBJROOT)/obj.i386 ; \ - MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \ - MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_static.a -endif -build-ppc-profile: -ifneq ($(RC_ppc),) - mkdir -p $(OBJROOT)/obj.ppc ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \ - MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc_profile.a -endif -build-ppc64-profile: -ifneq ($(RC_ppc64),) - mkdir -p $(OBJROOT)/obj.ppc64 ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \ - MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_profile.a -endif -build-i386-profile: -ifneq ($(RC_i386),) - mkdir -p $(OBJROOT)/obj.i386 ; \ - MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \ - MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_profile.a -endif -build-ppc-debug: -ifneq ($(RC_ppc),) - mkdir -p $(OBJROOT)/obj.ppc ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \ - MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc_debug.a -endif -build-ppc64-debug: -ifneq ($(RC_ppc64),) - mkdir -p $(OBJROOT)/obj.ppc64 ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \ - MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_debug.a -endif -build-i386-debug: -ifneq ($(RC_i386),) - mkdir -p $(OBJROOT)/obj.i386 ; \ - MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \ - MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_debug.a -endif -build-ppc-dynamic: -ifneq ($(RC_ppc),) - mkdir -p $(OBJROOT)/obj.ppc ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \ - MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc.a -endif -build-ppc64-dynamic: -ifneq ($(RC_ppc64),) - mkdir -p $(OBJROOT)/obj.ppc64 ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \ - MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc.a -endif -build-i386-dynamic: -ifneq ($(RC_i386),) - mkdir -p $(OBJROOT)/obj.i386 ; \ - MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \ - MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc.a -endif -build-ppc: -ifneq ($(RC_ppc),) - mkdir -p $(OBJROOT)/obj.ppc ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \ - MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) build -endif -build-ppc64: -ifneq ($(RC_ppc64),) - mkdir -p $(OBJROOT)/obj.ppc64 ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \ - MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) build -endif -build-i386: -ifneq ($(RC_i386),) - mkdir -p $(OBJROOT)/obj.i386 ; \ - MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \ - MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) build -endif - -# We have to separately call bsdmake to patch the FreeBSD files, because of -# the way its cache works, it would otherwise pick a file in ${SYMROOT}, even -# over a .s file. -autopatch: -ifneq ($(RC_i386),) - MACHINE_ARCH="i386" $(BSDMAKE) autopatch -endif -ifneq ($(RC_ppc),) - MACHINE_ARCH="ppc" $(BSDMAKE) autopatch -endif -ifneq ($(RC_ppc64),) - MACHINE_ARCH="ppc64" $(BSDMAKE) autopatch -endif - -installsrc: - $(_v) pax -rw . "$(SRCROOT)" - -installhdrs-real: $(CC_PRINT_OPTIONS_FILE) - MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" MAKEFLAGS="" \ - $(BSDMAKE) installhdrs -ifneq ($(RC_i386),) - mkdir -p "$(OBJROOT)/obj.i386" ; \ - MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \ - MAKEFLAGS="" $(BSDMAKE) installhdrs-md -endif -ifneq ($(RC_ppc),) - mkdir -p "$(OBJROOT)/obj.ppc" ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \ - MAKEFLAGS="" $(BSDMAKE) installhdrs-md -endif -ifneq ($(RC_ppc64),) - mkdir -p "$(OBJROOT)/obj.ppc64" ; \ - MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \ - MAKEFLAGS="" $(BSDMAKE) installhdrs-md -endif - -BI-install-static: build-static - mkdir -p $(DSTROOT)/usr/local/lib/system - if [ -f "$(SYMROOT)/libc_static.a" ]; then \ - echo "Installing libc_static.a" ; \ - install -c -m 444 "$(SYMROOT)/libc_static.a" \ - $(DSTROOT)/usr/local/lib/system; \ - ranlib "$(DSTROOT)/usr/local/lib/system/libc_static.a"; \ - fi -BI-install-profile: build-profile - mkdir -p $(DSTROOT)/usr/local/lib/system - if [ -f "$(SYMROOT)/libc_profile.a" ]; then \ - echo "Installing libc_profile.a" ; \ - install -c -m 444 "$(SYMROOT)/libc_profile.a" \ - $(DSTROOT)/usr/local/lib/system; \ - ranlib "$(DSTROOT)/usr/local/lib/system/libc_profile.a"; \ - fi -ifneq ($(RC_ppc),) - if [ -f "$(OBJROOT)/obj.ppc/libc-ldbl128_profile.a" ]; then \ - echo "Installing libldbl128_profile.a" ; \ - $(SRCROOT)/make_libldbl128 "$(OBJROOT)/obj.ppc/libc-ldbl128_profile.a" \ - "_profile" "$(DSTROOT)/usr/local/lib/system" $(LIBSYS) ; \ - fi -endif -BI-install-debug: build-debug - mkdir -p $(DSTROOT)/usr/local/lib/system - if [ -f "$(SYMROOT)/libc_debug.a" ]; then \ - echo "Installing libc_debug.a" ; \ - install -c -m 444 "$(SYMROOT)/libc_debug.a" \ - $(DSTROOT)/usr/local/lib/system; \ - ranlib "$(DSTROOT)/usr/local/lib/system/libc_debug.a"; \ - fi -ifneq ($(RC_ppc),) - if [ -f "$(OBJROOT)/obj.ppc/libc-ldbl128_debug.a" ]; then \ - echo "Installing libldbl128_debug.a" ; \ - $(SRCROOT)/make_libldbl128 "$(OBJROOT)/obj.ppc/libc-ldbl128_debug.a" \ - "_debug" "$(DSTROOT)/usr/local/lib/system" $(LIBSYS) ; \ - fi -endif -BI-install-dynamic: build-dynamic - mkdir -p $(DSTROOT)/usr/local/lib/system - if [ -f "$(SYMROOT)/libc.a" ]; then \ - echo "Installing libc.a" ; \ - install -c -m 444 "$(SYMROOT)/libc.a" \ - $(DSTROOT)/usr/local/lib/system; \ - ranlib "$(DSTROOT)/usr/local/lib/system/libc.a"; \ - fi -ifneq ($(RC_ppc),) - if [ -f "$(OBJROOT)/obj.ppc/libc-ldbl128.a" ]; then \ - echo "Installing libldbl128.a" ; \ - $(SRCROOT)/make_libldbl128 "$(OBJROOT)/obj.ppc/libc-ldbl128.a" \ - "" "$(DSTROOT)/usr/local/lib/system" $(LIBSYS) ; \ - fi -endif - -# Don't use -j here; it may try to make links before the files are copied -install-man: - mkdir -p $(DSTROOT)/usr/share/man/man2 - mkdir -p $(DSTROOT)/usr/share/man/man3 - mkdir -p $(DSTROOT)/usr/share/man/man4 - mkdir -p $(DSTROOT)/usr/share/man/man5 - mkdir -p $(DSTROOT)/usr/share/man/man7 - MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" NOMANCOMPRESS=1 \ - MACHINE_ARCH="$(shell arch)" MAKEFLAGS="" bsdmake autopatchman maninstall - -install-all: build install-man BI-install-dynamic BI-install-static BI-install-profile BI-install-debug - -clean: - rm -rf $(OBJROOT)/obj.ppc $(OBJROOT)/obj.i386 $(OBJROOT)/libc.a \ - $(OBJROOT)/libc_static.a $(OBJROOT)/libc_debug.a \ - $(OBJROOT)/libc_profile.a +.DEFAULT: + @bsdmake $@ diff --git a/Makefile b/Makefile index b190072..d8357bc 100644 --- a/Makefile +++ b/Makefile @@ -19,16 +19,16 @@ SHLIB_MINOR= 0 .if (${MACHINE_ARCH} == unknown) MACHINE_ARCH != /usr/bin/arch .endif +.if !empty $(MACHINE_ARCH:M*64) +LP64 = 1 +.endif CC = gcc-4.0 # always set __DARWIN_UNIX03 to zero (variant will set to one) except for ppc64 -.if (${MACHINE_ARCH} == ppc64) +.ifdef LP64 CFLAGS += -D__DARWIN_UNIX03=1 .else CFLAGS += -D__DARWIN_UNIX03=0 .endif -.if (${MACHINE_ARCH} == i386) -CFLAGS += -march=prescott -msse3 -.endif CFLAGS += -D__LIBC__ -DNOID -I${.CURDIR}/include .ifdef ALTLIBCHEADERS INCLUDEDIR = ${ALTLIBCHEADERS} diff --git a/Makefile.xbs b/Makefile.xbs index c8deeb2..efbfdac 100644 --- a/Makefile.xbs +++ b/Makefile.xbs @@ -19,6 +19,8 @@ # should only be installed once as well. Both of these get done when # we're invoked as "Libc". +BSDMAKE = bsdmake -f Makefile + .PATH: . .MAIN: all all: libc.a libc_static.a libc_debug.a libc_profile.a @@ -84,8 +86,8 @@ VARIANTS= VARIANTS+= LDBL MDSRCS += ldbl64.s .endif -# build UNIX03 variant except on ppc64 -.if (${MACHINE_ARCH} != ppc64) +# build UNIX03 variant except on LP64 +.ifndef LP64 VARIANTS+= UNIX03 .endif CFLAGS+= ${VARIANTCFLAGS} @@ -103,29 +105,29 @@ VARIANTCOMBOCFLAGS != ${.CURDIR}/makeCombos ${COMBOARGS} .endif # For each of the variant combinations as target (and possibly suffixed with # _D, _P, and _S for the four kinds on compile styles, we create a subdirectory -# to do the compiling in, and then call bsdmake with the new directory, and +# to do the compiling in, and then call $(BSDMAKE) with the new directory, and # setting VARIANTCFLAGS, which are the extra flags to be added to CFLAGS. .for _v in ${VARIANTCOMBOCFLAGS} VARIANTCOMBOS+= ${_v:H:S,/,,} ${_v:H:S,/,,}: .ifdef ${_v:H:S,/,,}SRCS mkdir -p ${MAKEOBJDIR}/${_v:H:S,/,,}; \ - MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" bsdmake -C "${.CURDIR}" build_${_v:H:S,/,,} + MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" $(BSDMAKE) -C "${.CURDIR}" build_${_v:H:S,/,,} .endif ${_v:H:S,/,,}_D: .ifdef ${_v:H:S,/,,}SRCS mkdir -p ${MAKEOBJDIR}/${_v:H:S,/,,}; \ - MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" bsdmake -C "${.CURDIR}" build_${_v:H:S,/,,}_D + MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" $(BSDMAKE) -C "${.CURDIR}" build_${_v:H:S,/,,}_D .endif ${_v:H:S,/,,}_P: .ifdef ${_v:H:S,/,,}SRCS mkdir -p ${MAKEOBJDIR}/${_v:H:S,/,,}; \ - MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" bsdmake -C "${.CURDIR}" build_${_v:H:S,/,,}_P + MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" $(BSDMAKE) -C "${.CURDIR}" build_${_v:H:S,/,,}_P .endif ${_v:H:S,/,,}_S: .ifdef ${_v:H:S,/,,}SRCS mkdir -p ${MAKEOBJDIR}/${_v:H:S,/,,}; \ - MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" bsdmake -C "${.CURDIR}" build_${_v:H:S,/,,}_S + MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" $(BSDMAKE) -C "${.CURDIR}" build_${_v:H:S,/,,}_S .endif .endfor @@ -136,7 +138,7 @@ ${_v:H:S,/,,}_S: .o-${_v}.o .do-${_v}.do .po-${_v}.po .So-${_v}.So: mv ${.IMPSRC} ${.TARGET} -# These are the build targets of the above bsdmake calls, which just builds +# These are the build targets of the above $(BSDMAKE) calls, which just builds # using the standard rules, but with the additional flags. VARIANTOBJS+= ${${_v}SRCS:N*.h:R:S/$/-${_v}.o/g:S,^,${_v}/,g} build_${_v}: ${${_v}SRCS:N*.h:R:S/$/-${_v}.o/g} diff --git a/darwin/copyfile.c b/darwin/copyfile.c index 69ffc7b..449f6ee 100644 --- a/darwin/copyfile.c +++ b/darwin/copyfile.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -123,7 +124,6 @@ int copyfile(const char *src, const char *dst, copyfile_state_t state, copyfile_ } copyfile_debug(1, "debug value set to: %d\n", s->debug); } - if (COPYFILE_CHECK & flags) return copyfile_check(s); @@ -951,12 +951,12 @@ swap_attrhdr(attr_header_t *ah) #endif } -static u_int32_t emptyfinfo[8] = {0}; +static const u_int32_t emptyfinfo[8] = {0}; static int copyfile_unpack(copyfile_state_t s) { - int bytes; - void * buffer; + ssize_t bytes; + void * buffer, * endptr; apple_double_header_t *adhdr; size_t hdrsize; int error = 0; @@ -967,6 +967,13 @@ static int copyfile_unpack(copyfile_state_t s) hdrsize = ATTR_MAX_HDR_SIZE; buffer = calloc(1, hdrsize); + if (buffer == NULL) { + copyfile_debug(1, "copyfile_unpack: calloc(1, %u) returned NULL", hdrsize); + error = -1; + goto exit; + } else + endptr = (char*)buffer + hdrsize; + bytes = pread(s->src_fd, buffer, hdrsize, 0); if (bytes < 0) @@ -1016,6 +1023,12 @@ static int copyfile_unpack(copyfile_state_t s) int count; int i; + if (hdrsize < sizeof(attr_header_t)) { + copyfile_warn("bad attribute header: %u < %u", hdrsize, sizeof(attr_header_t)); + error = -1; + goto exit; + } + attrhdr = (attr_header_t *)buffer; swap_attrhdr(attrhdr); if (attrhdr->magic != ATTR_HDR_MAGIC) @@ -1027,10 +1040,91 @@ static int copyfile_unpack(copyfile_state_t s) } count = attrhdr->num_attrs; entry = (attr_entry_t *)&attrhdr[1]; + for (i = 0; i < count; i++) { void * dataptr; + /* + * First we do some simple sanity checking. + * +) See if entry is within the buffer's range; + * + * +) Check the attribute name length; if it's longer than the + * maximum, we truncate it down. (We could error out as well; + * I'm not sure which is the better way to go here.) + * + * +) If, given the name length, it goes beyond the end of + * the buffer, error out. + * + * +) If the last byte isn't a NUL, make it a NUL. (Since we + * truncated the name length above, we truncate the name here.) + * + * +) If entry->offset is so large that it causes dataptr to + * go beyond the end of the buffer -- or, worse, so large that + * it wraps around! -- we error out. + * + * +) If entry->length would cause the entry to go beyond the + * end of the buffer (or, worse, wrap around to before it), + * *or* if the length is larger than the hdrsize, we error out. + * (An explanation of that: what we're checking for there is + * the small range of values such that offset+length would cause + * it to go beyond endptr, and then wrap around past buffer. We + * care about this because we are passing entry->length down to + * fgetxattr() below, and an erroneously large value could cause + * problems there. By making sure that it's less than hdrsize, + * which has already been sanity-checked above, we're safe. + * That may mean that the check against < buffer is unnecessary.) + */ + if ((void*)entry >= endptr || (void*)entry < buffer) { + if (COPYFILE_VERBOSE & s->flags) + copyfile_warn("Incomplete or corrupt attribute entry"); + error = -1; + goto exit; + } + + if (((void*)entry + sizeof(*entry)) > endptr) { + if (COPYFILE_VERBOSE & s->flags) + copyfile_warn("Incomplete or corrupt attribute entry"); + error = -1; + goto exit; + } + + if (entry->namelen > ATTR_MAX_NAME_LEN) { + entry->namelen = ATTR_MAX_NAME_LEN; + } + if ((void*)(entry->name + entry->namelen) >= endptr) { + if (COPYFILE_VERBOSE & s->flags) + copyfile_warn("Incomplete or corrupt attribute entry"); + error = -1; + goto exit; + } + + if (entry->name[entry->namelen] != 0) { + entry->name[entry->namelen] = 0; + } + + copyfile_debug(3, "extracting \"%s\" (%d bytes) at offset %u", + entry->name, entry->length, entry->offset); + + dataptr = (char *)attrhdr + entry->offset; + + if (dataptr >= endptr || dataptr < buffer) { + copyfile_debug(1, "Entry %d overflows: offset = %u", entry->offset); + error = -1; + goto exit; + } + if ((dataptr + entry->length) > endptr || + ((dataptr + entry->length) < buffer) || + (entry->length > hdrsize)) { + if (COPYFILE_VERBOSE & s->flags) + copyfile_warn("Incomplete or corrupt attribute entry"); + copyfile_debug(1, "Entry %d length overflows: dataptr = %u, offset = %u, length = %u, buffer = %u, endptr = %u", + i, dataptr, entry->offset, entry->length, buffer, endptr); + error = -1; + goto exit; + } + + if (COPYFILE_ACL & s->flags && strcmp((char*)entry->name, XATTR_SECURITY_NAME) == 0) copyfile_debug(2, "extracting \"%s\" (%d bytes)", entry->name, entry->length); dataptr = (char *)attrhdr + entry->offset; @@ -1053,8 +1147,7 @@ static int copyfile_unpack(copyfile_state_t s) copyfile_warn("setting security information"); acl_free(acl); } - } else - if (COPYFILE_XATTR & s->flags && (fsetxattr(s->dst_fd, entry->name, dataptr, entry->length, 0, 0))) { + } else if (COPYFILE_XATTR & s->flags && (fsetxattr(s->dst_fd, entry->name, dataptr, entry->length, 0, 0))) { if (COPYFILE_VERBOSE & s->flags) copyfile_warn("error %d setting attribute %s", error, entry->name); goto exit; @@ -1076,6 +1169,11 @@ static int copyfile_unpack(copyfile_state_t s) /* * Extract the Finder Info. */ + if (adhdr->entries[0].offset > (hdrsize - sizeof(emptyfinfo))) { + error = -1; + goto exit; + } + if (bcmp((u_int8_t*)buffer + adhdr->entries[0].offset, emptyfinfo, sizeof(emptyfinfo)) != 0) { copyfile_debug(1, " extracting \"%s\" (32 bytes)", XATTR_FINDERINFO_NAME); @@ -1090,7 +1188,7 @@ static int copyfile_unpack(copyfile_state_t s) if (adhdr->entries[1].type == AD_RESOURCE && adhdr->entries[1].length > 0) { - void * rsrcforkdata; + void * rsrcforkdata = NULL; size_t length; off_t offset; @@ -1098,6 +1196,13 @@ static int copyfile_unpack(copyfile_state_t s) offset = adhdr->entries[1].offset; rsrcforkdata = malloc(length); + if (rsrcforkdata == NULL) { + copyfile_debug(1, "could not allocate %u bytes for rsrcforkdata", + length); + error = -1; + goto bad; + } + bytes = pread(s->src_fd, rsrcforkdata, length, offset); if (bytes < length) { @@ -1112,21 +1217,23 @@ static int copyfile_unpack(copyfile_state_t s) (int)bytes, (int)length); } error = -1; - goto exit; + goto bad; } error = fsetxattr(s->dst_fd, XATTR_RESOURCEFORK_NAME, rsrcforkdata, bytes, 0, 0); if (error) { copyfile_debug(1, "error %d setting resource fork attribute", error); error = -1; - goto exit; + goto bad; } copyfile_debug(1, "extracting \"%s\" (%d bytes)", XATTR_RESOURCEFORK_NAME, (int)length); - free(rsrcforkdata); +bad: + if (rsrcforkdata) + free(rsrcforkdata); } exit: - free(buffer); + if (buffer) free(buffer); return error; } @@ -1201,11 +1308,11 @@ static int copyfile_pack_rsrcfork(copyfile_state_t s, attr_header_t *filehdr) static int copyfile_pack(copyfile_state_t s) { - char *attrnamebuf; - void *databuf; - attr_header_t *filehdr; + char *attrnamebuf = NULL, *endnamebuf; + void *databuf = NULL; + attr_header_t *filehdr, *endfilehdr; attr_entry_t *entry; - ssize_t listsize; + ssize_t listsize = 0; char *nameptr; int namelen; int entrylen; @@ -1215,7 +1322,20 @@ static int copyfile_pack(copyfile_state_t s) int error = 0; filehdr = (attr_header_t *) calloc(1, ATTR_MAX_SIZE); + if (filehdr == NULL) { + error = -1; + goto exit; + } else { + endfilehdr = ((void*)filehdr) + ATTR_MAX_SIZE; + } + attrnamebuf = calloc(1, ATTR_MAX_HDR_SIZE); + if (attrnamebuf == NULL) { + error = -1; + goto exit; + } else { + endnamebuf = ((char*)attrnamebuf) + ATTR_MAX_HDR_SIZE; + } /* * Fill in the Apple Double Header defaults. @@ -1260,26 +1380,36 @@ static int copyfile_pack(copyfile_state_t s) if (COPYFILE_XATTR & s->flags) { - if ((listsize = flistxattr(s->src_fd, attrnamebuf + offset, ATTR_MAX_HDR_SIZE, 0)) <= 0) + ssize_t left = ATTR_MAX_HDR_SIZE - offset; + if ((listsize = flistxattr(s->src_fd, attrnamebuf + offset, left, 0)) <= 0) { copyfile_debug(1, "no extended attributes found (%d)", errno); } - if (listsize > ATTR_MAX_HDR_SIZE) + if (listsize > left) { copyfile_debug(1, "extended attribute list too long"); listsize = ATTR_MAX_HDR_SIZE; } listsize += offset; + endnamebuf = attrnamebuf + listsize; + if (endnamebuf > (attrnamebuf + ATTR_MAX_HDR_SIZE)) { + error = -1; + goto exit; + } - for (nameptr = attrnamebuf; nameptr < attrnamebuf + listsize; nameptr += namelen) + for (nameptr = attrnamebuf; nameptr XATTR_MAXNAMELEN + 1) { + namelen = XATTR_MAXNAMELEN + 1; + } entry->namelen = namelen; entry->flags = 0; bcopy(nameptr, &entry->name[0], namelen); @@ -1287,7 +1417,12 @@ static int copyfile_pack(copyfile_state_t s) entrylen = ATTR_ENTRY_LENGTH(namelen); entry = (attr_entry_t *)(((char *)entry) + entrylen); - + + if ((void*)entry > (void*)endfilehdr) { + error = -1; + goto exit; + } + /* Update the attributes header. */ filehdr->num_attrs++; filehdr->data_start += entrylen; @@ -1301,14 +1436,13 @@ static int copyfile_pack(copyfile_state_t s) for (nameptr = attrnamebuf; nameptr < attrnamebuf + listsize; nameptr += namelen + 1) { - nameptr = nameptr; namelen = strlen(nameptr); - if (strncmp(nameptr, XATTR_SECURITY_NAME, strlen(XATTR_SECURITY_NAME)) == 0) + if (strcmp(nameptr, XATTR_SECURITY_NAME) == 0) copyfile_pack_acl(s, &databuf, &datasize); else /* Check for Finder Info. */ - if (strncmp(nameptr, XATTR_FINDERINFO_NAME, strlen(XATTR_FINDERINFO_NAME)) == 0) + if (strcmp(nameptr, XATTR_FINDERINFO_NAME) == 0) { datasize = fgetxattr(s->src_fd, nameptr, (u_int8_t*)filehdr + filehdr->appledouble.entries[0].offset, 32, 0, 0); if (datasize < 0) @@ -1328,7 +1462,7 @@ static int copyfile_pack(copyfile_state_t s) continue; /* finder info doesn't have an attribute entry */ } else /* Check for Resource Fork. */ - if (strncmp(nameptr, XATTR_RESOURCEFORK_NAME, strlen(XATTR_RESOURCEFORK_NAME)) == 0) + if (strcmp(nameptr, XATTR_RESOURCEFORK_NAME) == 0) { hasrsrcfork = 1; continue; @@ -1351,6 +1485,10 @@ static int copyfile_pack(copyfile_state_t s) goto next; } databuf = malloc(datasize); + if (databuf == NULL) { + error = -1; + continue; + } datasize = fgetxattr(s->src_fd, nameptr, databuf, datasize, 0, 0); } @@ -1364,7 +1502,12 @@ static int copyfile_pack(copyfile_state_t s) * the case when there are lots of attributes or one of * the attributes is very large. */ - bcopy(databuf, (char*)filehdr + entry->offset, datasize); + if (entry->offset > ATTR_MAX_SIZE || + (entry->offset + datasize > ATTR_MAX_SIZE)) { + error = -1; + } else { + bcopy(databuf, (char*)filehdr + entry->offset, datasize); + } free(databuf); copyfile_debug(1, "copied %ld bytes of \"%s\" data @ offset 0x%08x", datasize, nameptr, entry->offset); @@ -1404,8 +1547,8 @@ next: goto exit; } exit: - free(filehdr); - free(attrnamebuf); + if (filehdr) free(filehdr); + if (attrnamebuf) free(attrnamebuf); if (error) return error; diff --git a/fbsdcompat/_fpmath.h b/fbsdcompat/_fpmath.h index fff55b4..3871ec2 100644 --- a/fbsdcompat/_fpmath.h +++ b/fbsdcompat/_fpmath.h @@ -75,7 +75,7 @@ __private_extern__ void _ldbl2array32dd(union IEEEl2bits, uint32_t *); #define LDBL_TO_ARRAY32(u, a) _ldbl2array32dd(u, a) -#elif defined(__i386__) +#elif defined(__i386__) || defined(__x86_64__) union IEEEl2bits { long double e; diff --git a/gdtoa/arith.h b/gdtoa/arith.h index 0885212..f1c936e 100644 --- a/gdtoa/arith.h +++ b/gdtoa/arith.h @@ -37,6 +37,10 @@ #elif defined(__i386__) #define IEEE_8087 #define Arith_Kind_ASL 1 +#elif defined(__x86_64__) +#define IEEE_8087 +#define Arith_Kind_ASL 1 +#define Long int #else #error Unsupported architecture #endif diff --git a/gdtoa/gd_qnan.h b/gdtoa/gd_qnan.h index 7f432a3..ea5fd60 100644 --- a/gdtoa/gd_qnan.h +++ b/gdtoa/gd_qnan.h @@ -13,7 +13,7 @@ #define ldus_QNAN3 0x0 #define ldus_QNAN4 0x0 -#elif defined(__i386__) +#elif defined(__i386__) || defined(__x86_64__) #define f_QNAN 0xffc00000 #define d_QNAN0 0x0 diff --git a/gen/FreeBSD/getcwd.c.patch b/gen/FreeBSD/getcwd.c.patch index 818ed56..ac2f9cd 100644 --- a/gen/FreeBSD/getcwd.c.patch +++ b/gen/FreeBSD/getcwd.c.patch @@ -1,19 +1,98 @@ ---- getcwd.c.orig 2003-10-29 02:45:01.000000000 -0800 -+++ getcwd.c 2004-10-24 17:19:39.000000000 -0700 -@@ -54,8 +54,6 @@ +--- getcwd.c.orig 2006-01-19 18:35:45.000000000 -0800 ++++ getcwd.c 2006-02-08 17:53:41.000000000 -0800 +@@ -54,7 +54,81 @@ (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) -extern int __getcwd(char *, size_t); -- ++/* ++ * If __getcwd() ever becomes a syscall, we can remove this workaround. ++ * The problem here is that fcntl() assumes a buffer of size MAXPATHLEN, ++ * if size is less than MAXPATHLEN, we need to use a temporary buffer ++ * and see if it fits. We also have to assume that open() or fcntl() ++ * don't fail with errno=ERANGE. ++ */ ++static inline int ++__getcwd(char *buf, size_t size) ++{ ++ int fd, err, save; ++ struct stat dot, pt; ++ char *b; ++ ++ if ((fd = open(".", O_RDONLY)) < 0) ++ return -1; ++ if (fstat(fd, &dot) < 0) { ++ save = errno; ++ close(fd); ++ errno = save; ++ return -1; ++ } ++ /* check that the device and inode are non-zero, otherwise punt */ ++ if (dot.st_dev == 0 || dot.st_ino == 0) { ++ close(fd); ++ errno = EINVAL; ++ return -1; ++ } ++ if (size < MAXPATHLEN) { ++ /* the hard case; allocate a buffer of size MAXPATHLEN to use */ ++ b = (char *)alloca(MAXPATHLEN); ++ if (b == NULL) { ++ close(fd); ++ errno = ENOMEM; /* make sure it isn't ERANGE */ ++ return -1; ++ } ++ } else ++ b = buf; ++ ++ err = fcntl(fd, F_GETPATH, b); ++ if (err) { ++ save = errno; ++ close(fd); ++ errno = save; ++ return err; ++ } ++ close(fd); ++ /* ++ * now double-check that the path returned by fcntl() has the same ++ * device and inode number as '.'. ++ */ ++ if (stat(b, &pt) < 0) ++ return -1; ++ /* ++ * Since dot.st_dev and dot.st_ino are non-zero, we don't need to ++ * separately test for pt.st_dev and pt.st_ino being non-zero, because ++ * they have to match ++ */ ++ if (dot.st_dev != pt.st_dev || dot.st_ino != pt.st_ino) { ++ errno = EINVAL; ++ return -1; ++ } ++ /* ++ * For the case where we allocated a buffer, check that it can fit ++ * in the real buffer, and copy it over. ++ */ ++ if (size < MAXPATHLEN) { ++ if (strlen(b) >= size) { ++ errno = ERANGE; ++ return -1; ++ } ++ strcpy(buf, b); ++ } ++ return 0; ++} + char * getcwd(pt, size) - char *pt; -@@ -95,18 +93,6 @@ +@@ -91,31 +165,23 @@ + } + ept = pt + size; + } else { +- if ((pt = malloc(ptsize = 1024 - 4)) == NULL) ++ if ((pt = malloc(ptsize = MAXPATHLEN)) == NULL) return (NULL); ept = pt + ptsize; } -- if (__getcwd(pt, ept - pt) == 0) { + if (__getcwd(pt, ept - pt) == 0) { - if (*pt != '/') { - bpt = pt; - ept = pt + strlen(pt) - 1; @@ -23,8 +102,21 @@ - *ept-- = c; - } - } -- return (pt); + return (pt); - } ++ } else if (errno == ERANGE) /* failed because buffer too small */ ++ return NULL; bpt = ept - 1; *bpt = '\0'; + /* +- * Allocate bytes (1024 - malloc space) for the string of "../"'s. ++ * Allocate bytes MAXPATHLEN) for the string of "../"'s. + * Should always be enough (it's 340 levels). If it's not, allocate + * as necessary. Special case the first stat, it's ".", not "..". + */ +- if ((up = malloc(upsize = 1024 - 4)) == NULL) ++ if ((up = malloc(upsize = MAXPATHLEN)) == NULL) + goto err; + eup = up + MAXPATHLEN; + bup = up; diff --git a/gen/FreeBSD/opendir.c.patch b/gen/FreeBSD/opendir.c.patch index a868618..d26bc38 100644 --- a/gen/FreeBSD/opendir.c.patch +++ b/gen/FreeBSD/opendir.c.patch @@ -1,5 +1,5 @@ ---- /Volumes/XDisk/tmp/Libc/gen/FreeBSD/opendir.c.orig 2004-08-14 10:46:10.000000000 -0700 -+++ /Volumes/XDisk/tmp/Libc/gen/FreeBSD/opendir.c 2004-10-24 17:08:28.000000000 -0700 +--- opendir.c.orig 2004-11-25 11:38:01.000000000 -0800 ++++ opendir.c 2006-05-03 23:21:10.000000000 -0700 @@ -48,6 +48,7 @@ #include #include @@ -8,7 +8,39 @@ #include "un-namespace.h" #include "telldir.h" -@@ -269,7 +270,7 @@ +@@ -72,27 +73,15 @@ + int incr; + int saved_errno; + int unionstack; +- struct stat statb; + + /* +- * stat() before _open() because opening of special files may be +- * harmful. _fstat() after open because the file may have changed. ++ * Use O_DIRECTORY to only open directories (because opening of ++ * special files may be harmful). errno is set to ENOTDIR if ++ * not a directory. + */ +- if (stat(name, &statb) != 0) +- return (NULL); +- if (!S_ISDIR(statb.st_mode)) { +- errno = ENOTDIR; +- return (NULL); +- } +- if ((fd = _open(name, O_RDONLY | O_NONBLOCK)) == -1) ++ if ((fd = _open(name, O_RDONLY | O_NONBLOCK | O_DIRECTORY)) == -1) + return (NULL); + dirp = NULL; +- if (_fstat(fd, &statb) != 0) +- goto fail; +- if (!S_ISDIR(statb.st_mode)) { +- errno = ENOTDIR; +- goto fail; +- } + if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 || + (dirp = malloc(sizeof(DIR) + sizeof(struct _telldir))) == NULL) + goto fail; +@@ -269,7 +258,7 @@ dirp->dd_loc = 0; dirp->dd_fd = fd; dirp->dd_flags = flags; diff --git a/gen/Makefile.inc b/gen/Makefile.inc index e1de6c3..a3b7f89 100644 --- a/gen/Makefile.inc +++ b/gen/Makefile.inc @@ -42,7 +42,7 @@ FBSDMISRCS = _rand48.c alarm.c assert.c \ telldir.c termios.c time.c times.c \ ttyname.c ttyslot.c ualarm.c ulimit.c unvis.c usleep.c utime.c vis.c \ wait.c wait3.c waitpid.c -.if (${MACHINE_ARCH} != ppc64) +.ifndef LP64 FBSDMISRCS += timezone.c .endif FBSDHDRS = rand48.h telldir.h diff --git a/gen/stack_logging.c b/gen/stack_logging.c index ff59ae4..257d118 100644 --- a/gen/stack_logging.c +++ b/gen/stack_logging.c @@ -66,7 +66,7 @@ static inline void copy_pages(const void *source, void *dest, unsigned bytes) { // called when MallocStackLogging is set anyway, so they won't affect normal usage. static __attribute__((noinline)) void *first_frame_address(void) { -#if defined(__i386__) +#if defined(__i386__) || defined(__x86_64__) return __builtin_frame_address(0); #elif defined(__ppc__) || defined(__ppc64__) void *addr; @@ -81,8 +81,8 @@ static __attribute__((noinline)) void *first_frame_address(void) { static __attribute__((noinline)) void *next_frame_address(void *addr) { void *ret; -#if defined(__MACH__) && defined(__i386__) - __asm__ volatile("movl (%1),%0" : "=r" (ret) : "r" (addr)); +#if defined(__MACH__) && (defined(__i386__) || defined(__x86_64__)) + __asm__ volatile("mov (%1),%0" : "=r" (ret) : "r" (addr)); #elif defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__)) __asm__ volatile("lwz %0,0x0(%1)" : "=r" (ret) : "b" (addr)); #elif defined(__hpux__) @@ -96,7 +96,7 @@ static __attribute__((noinline)) void *next_frame_address(void *addr) { return ret; } -#if defined(__i386__) || defined (__m68k__) +#if defined(__i386__) || defined(__x86_64__) || defined (__m68k__) #define FP_LINK_OFFSET 1 #elif defined(__ppc__) || defined(__ppc64__) #define FP_LINK_OFFSET 2 diff --git a/i386/pthreads/pthread_set_self.s b/i386/pthreads/pthread_set_self.s index 82aab3a..45ae447 100644 --- a/i386/pthreads/pthread_set_self.s +++ b/i386/pthreads/pthread_set_self.s @@ -32,5 +32,4 @@ ___pthread_set_self: movl $3,%eax MACHDEP_SYSCALL_TRAP addl $8,%esp - movw %ax,%gs ret diff --git a/i386/string/bcopy.s b/i386/string/bcopy.s index d9c3bdf..d5fa77a 100644 --- a/i386/string/bcopy.s +++ b/i386/string/bcopy.s @@ -36,13 +36,13 @@ #if defined(MEMCOPY) LEAF(_memcpy,0) movl $(_COMM_PAGE_MEMCPY), %eax - jmpl %eax + jmpl *%eax #elif defined(MEMMOVE) LEAF(_memmove,0) movl $(_COMM_PAGE_MEMMOVE), %eax - jmpl %eax + jmpl *%eax #else LEAF(_bcopy,0) movl $(_COMM_PAGE_BCOPY), %eax - jmpl %eax + jmpl *%eax #endif diff --git a/i386/string/bzero.s b/i386/string/bzero.s index db162dd..3ab3083 100644 --- a/i386/string/bzero.s +++ b/i386/string/bzero.s @@ -35,4 +35,4 @@ LEAF(_bzero,0) movl $(_COMM_PAGE_BZERO), %eax - jmpl %eax + jmpl *%eax diff --git a/i386/string/memset.s b/i386/string/memset.s index 0e0ae2a..a0adaa2 100644 --- a/i386/string/memset.s +++ b/i386/string/memset.s @@ -56,7 +56,7 @@ _memset: // void *memset(void *b, int c, size_t len); movl $(_COMM_PAGE_BZERO),%eax// map memset(p,0,n) into bzero(p,n) movl %edx,8(%esp) // put count where bzero() expects it - jmp %eax // enter commpage + jmp *%eax // enter commpage // Handle memset of a nonzero value. @@ -136,7 +136,7 @@ LCallCommpage: jnz 1b 2: // ptr aligned, length long enough to justify movl $(_COMM_PAGE_MEMSET_PATTERN),%eax - call %eax // call commpage to do the heavy lifting + call *%eax // call commpage to do the heavy lifting movl 12(%esp),%eax // get return value (ie, original ptr) popl %esi popl %edi @@ -235,7 +235,7 @@ LAlignPtr: // NB: can drop down to here! LReady: movl $(_COMM_PAGE_MEMSET_PATTERN),%eax - call %eax // call commpage to do the heavy lifting + call *%eax // call commpage to do the heavy lifting popl %esi popl %edi ret diff --git a/i386/string/strncpy.s b/i386/string/strncpy.s index dced178..ddc53b9 100644 --- a/i386/string/strncpy.s +++ b/i386/string/strncpy.s @@ -180,7 +180,7 @@ LZeroBuffer: pushl %ecx // remaining buffer size pushl %edi // ptr to 1st unstored byte movl $(_COMM_PAGE_BZERO),%eax - call %eax + call *%eax addl $8,%esp // pop off the arguments LDone: diff --git a/i386/sys/ATPgetreq.s b/i386/sys/ATPgetreq.s index e74c2e1..7208af1 100644 --- a/i386/sys/ATPgetreq.s +++ b/i386/sys/ATPgetreq.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(ATPgetreq, 3) ret diff --git a/i386/sys/ATPgetrsp.s b/i386/sys/ATPgetrsp.s index 0ef8629..c16193c 100644 --- a/i386/sys/ATPgetrsp.s +++ b/i386/sys/ATPgetrsp.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(ATPgetrsp, 3) ret diff --git a/i386/sys/ATPsndreq.s b/i386/sys/ATPsndreq.s index 28b7f37..8955faf 100644 --- a/i386/sys/ATPsndreq.s +++ b/i386/sys/ATPsndreq.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(ATPsndreq, 3) ret diff --git a/i386/sys/ATPsndrsp.s b/i386/sys/ATPsndrsp.s index b260299..eee1744 100644 --- a/i386/sys/ATPsndrsp.s +++ b/i386/sys/ATPsndrsp.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(ATPsndrsp, 3) ret diff --git a/i386/sys/ATgetmsg.s b/i386/sys/ATgetmsg.s index 3d874d0..6d55929 100644 --- a/i386/sys/ATgetmsg.s +++ b/i386/sys/ATgetmsg.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(ATgetmsg, 3) ret diff --git a/i386/sys/ATputmsg.s b/i386/sys/ATputmsg.s index 7f25382..56344c8 100644 --- a/i386/sys/ATputmsg.s +++ b/i386/sys/ATputmsg.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(ATputmsg, 3) ret diff --git a/i386/sys/ATsocket.s b/i386/sys/ATsocket.s index b503df9..bdde188 100644 --- a/i386/sys/ATsocket.s +++ b/i386/sys/ATsocket.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(ATsocket, 3) ret diff --git a/i386/sys/Makefile.inc b/i386/sys/Makefile.inc index eee1da7..b16c248 100644 --- a/i386/sys/Makefile.inc +++ b/i386/sys/Makefile.inc @@ -1,4 +1,6 @@ .PATH: ${.CURDIR}/i386/sys + +AINC+= -I${.CURDIR}/i386/sys MDSRCS+= ATPgetreq.s \ ATPgetrsp.s \ ATPsndreq.s \ diff --git a/i386/sys/OSAtomic.s b/i386/sys/OSAtomic.s index c6dd151..23fd9f2 100644 --- a/i386/sys/OSAtomic.s +++ b/i386/sys/OSAtomic.s @@ -109,7 +109,7 @@ DECLARE(_OSAtomicAdd64) call *_COMM_PAGE_COMPARE_AND_SWAP64 jnz 1b movl %ebx, %eax - movl %ecx, %ebx + movl %ecx, %edx popl %esi popl %ebx ret @@ -142,13 +142,13 @@ DECLARE(_OSAtomicTestAndClear) .globl _OSSpinLockTry _OSSpinLockTry: movl $(_COMM_PAGE_SPINLOCK_TRY), %eax - jmpl %eax + jmpl *%eax .align 2, 0x90 .globl _OSSpinLockLock _OSSpinLockLock: movl $(_COMM_PAGE_SPINLOCK_LOCK), %eax - jmpl %eax + jmpl *%eax .align 2, 0x90 .globl _OSSpinLockUnlock diff --git a/i386/sys/__mmap.s b/i386/sys/__mmap.s index 689f154..b22d9a3 100644 --- a/i386/sys/__mmap.s +++ b/i386/sys/__mmap.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include PSEUDO(__mmap, mmap, 6) ret diff --git a/i386/sys/__pthread_canceled.s b/i386/sys/__pthread_canceled.s index 336ab27..0475e96 100644 --- a/i386/sys/__pthread_canceled.s +++ b/i386/sys/__pthread_canceled.s @@ -23,7 +23,7 @@ /* * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(__pthread_canceled, 1) ret diff --git a/i386/sys/__pthread_markcancel.s b/i386/sys/__pthread_markcancel.s index 5731ff5..bed8c1e 100644 --- a/i386/sys/__pthread_markcancel.s +++ b/i386/sys/__pthread_markcancel.s @@ -23,7 +23,7 @@ /* * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(__pthread_markcancel, 1) ret diff --git a/i386/sys/__semwait_signal.s b/i386/sys/__semwait_signal.s index 55b163e..370a578 100644 --- a/i386/sys/__semwait_signal.s +++ b/i386/sys/__semwait_signal.s @@ -23,7 +23,7 @@ /* * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(__semwait_signal, 6) ret diff --git a/i386/sys/_exit.s b/i386/sys/_exit.s index ab99c5f..2757478 100644 --- a/i386/sys/_exit.s +++ b/i386/sys/_exit.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include PSEUDO(_exit, exit, 1) ret diff --git a/i386/sys/_getlogin.s b/i386/sys/_getlogin.s index fd865ea..47107fe 100644 --- a/i386/sys/_getlogin.s +++ b/i386/sys/_getlogin.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include PSEUDO(_getlogin, getlogin, 0) ret diff --git a/i386/sys/_pthread_kill.s b/i386/sys/_pthread_kill.s index 04d70a4..6d0f630 100644 --- a/i386/sys/_pthread_kill.s +++ b/i386/sys/_pthread_kill.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(__pthread_kill, 2) ret diff --git a/i386/sys/_setjmp.s b/i386/sys/_setjmp.s index 0a09c63..0d355c7 100644 --- a/i386/sys/_setjmp.s +++ b/i386/sys/_setjmp.s @@ -42,9 +42,11 @@ #include -#define JB_ONSTACK 0 +// The FP control word is actually two bytes, but there's no harm in +// using four bytes for it and keeping the struct aligned. +#define JB_FPCW 0 #define JB_MASK 4 -#define JB_EAX 8 +#define JB_MXCSR 8 #define JB_EBX 12 #define JB_ECX 16 #define JB_EDX 20 @@ -66,7 +68,9 @@ LEAF(__setjmp, 0) movl 4(%esp), %ecx // jmp_buf (struct sigcontext *) - // now build sigcontext + // Build the jmp_buf + fnstcw JB_FPCW(%ecx) // Save the FP control word + stmxcsr JB_MXCSR(%ecx) // Save the MXCSR movl %ebx, JB_EBX(%ecx) movl %edi, JB_EDI(%ecx) movl %esi, JB_ESI(%ecx) @@ -101,13 +105,9 @@ LEAF(__setjmp, 0) LEAF(__longjmp, 0) - subl $2,%esp - fnstcw (%esp) // save FP control word fninit // reset FP coprocessor - fldcw (%esp) // restore FP control word - addl $2,%esp - movl 4(%esp), %ecx // jmp_buf (struct sigcontext *) + movl 4(%esp), %ecx // jmp_buf (struct sigcontext *) movl 8(%esp), %eax // return value testl %eax, %eax jnz 1f @@ -119,6 +119,8 @@ LEAF(__longjmp, 0) movl JB_EDI(%ecx), %edi movl JB_EBP(%ecx), %ebp movl JB_ESP(%ecx), %esp + fldcw JB_FPCW(%ecx) // Restore FP control word + ldmxcsr JB_MXCSR(%ecx) // Restore the MXCSR #if SAVE_SEG_REGS // segment registers diff --git a/i386/sys/_setlogin.s b/i386/sys/_setlogin.s index f4a599f..ca0d5b9 100644 --- a/i386/sys/_setlogin.s +++ b/i386/sys/_setlogin.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include PSEUDO(_setlogin, setlogin, 0) ret diff --git a/i386/sys/_sysctl.s b/i386/sys/_sysctl.s index b9276e3..b1157d7 100644 --- a/i386/sys/_sysctl.s +++ b/i386/sys/_sysctl.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(__sysctl, 6) ret diff --git a/i386/sys/accept.s b/i386/sys/accept.s index 1afca4e..e0f3fcd 100644 --- a/i386/sys/accept.s +++ b/i386/sys/accept.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(accept, 3) + ret +#else /* !__LP64__ */ PSEUDO(accept$UNIX2003, accept, 3) ret UNIX_SYSCALL_ERR(accept, 3, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/access.s b/i386/sys/access.s index 6d19163..1f0cbfd 100644 --- a/i386/sys/access.s +++ b/i386/sys/access.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(access, 2) ret diff --git a/i386/sys/acct.s b/i386/sys/acct.s index cfae023..5113338 100644 --- a/i386/sys/acct.s +++ b/i386/sys/acct.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(acct, 1) ret diff --git a/i386/sys/add_profil.s b/i386/sys/add_profil.s index 485a112..f29f838 100644 --- a/i386/sys/add_profil.s +++ b/i386/sys/add_profil.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(add_profil, 4) ret diff --git a/i386/sys/adjtime.s b/i386/sys/adjtime.s index 8aa59f8..4c4f26e 100644 --- a/i386/sys/adjtime.s +++ b/i386/sys/adjtime.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(adjtime, 2) ret diff --git a/i386/sys/aio_cancel.s b/i386/sys/aio_cancel.s index 00d9942..2070cb8 100644 --- a/i386/sys/aio_cancel.s +++ b/i386/sys/aio_cancel.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(aio_cancel, 2) ret diff --git a/i386/sys/aio_error.s b/i386/sys/aio_error.s index 3bc756b..5a1f828 100644 --- a/i386/sys/aio_error.s +++ b/i386/sys/aio_error.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(aio_error, 1) ret diff --git a/i386/sys/aio_fsync.s b/i386/sys/aio_fsync.s index 6c378f6..a8445ba 100644 --- a/i386/sys/aio_fsync.s +++ b/i386/sys/aio_fsync.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(aio_fsync, 2) ret diff --git a/i386/sys/aio_read.s b/i386/sys/aio_read.s index cb85324..4bafa16 100644 --- a/i386/sys/aio_read.s +++ b/i386/sys/aio_read.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(aio_read, 1) ret diff --git a/i386/sys/aio_return.s b/i386/sys/aio_return.s index b506812..6764958 100644 --- a/i386/sys/aio_return.s +++ b/i386/sys/aio_return.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(aio_return, 1) ret diff --git a/i386/sys/aio_suspend.s b/i386/sys/aio_suspend.s index 4137a27..d7d740e 100644 --- a/i386/sys/aio_suspend.s +++ b/i386/sys/aio_suspend.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(aio_suspend, 3) - ret \ No newline at end of file + ret diff --git a/i386/sys/aio_write.s b/i386/sys/aio_write.s index a82151e..4229f0e 100644 --- a/i386/sys/aio_write.s +++ b/i386/sys/aio_write.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(aio_write, 1) - ret \ No newline at end of file + ret diff --git a/i386/sys/audit.s b/i386/sys/audit.s index 04f7d6d..2b308ac 100644 --- a/i386/sys/audit.s +++ b/i386/sys/audit.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(audit, 2) ret diff --git a/i386/sys/auditctl.s b/i386/sys/auditctl.s index b557464..559a293 100644 --- a/i386/sys/auditctl.s +++ b/i386/sys/auditctl.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(auditctl, 1) ret diff --git a/i386/sys/auditon.s b/i386/sys/auditon.s index 4cff057..10d59d7 100644 --- a/i386/sys/auditon.s +++ b/i386/sys/auditon.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(auditon, 3) ret diff --git a/i386/sys/auditsvc.s b/i386/sys/auditsvc.s index 31f1864..5efd544 100644 --- a/i386/sys/auditsvc.s +++ b/i386/sys/auditsvc.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(auditsvc, 2) ret diff --git a/i386/sys/bind.s b/i386/sys/bind.s index cf645f1..0fcb725 100644 --- a/i386/sys/bind.s +++ b/i386/sys/bind.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(bind, 3) + ret +#else /* !__LP64__ */ PSEUDO(bind$UNIX2003, bind, 3) ret UNIX_SYSCALL_ERR(bind, 3, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/cerror.s b/i386/sys/cerror.s index b071f0a..1e4428b 100644 --- a/i386/sys/cerror.s +++ b/i386/sys/cerror.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include .globl _errno diff --git a/i386/sys/chdir.s b/i386/sys/chdir.s index 0a086d1..7453e4b 100644 --- a/i386/sys/chdir.s +++ b/i386/sys/chdir.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(chdir, 1) ret diff --git a/i386/sys/checkuseraccess.s b/i386/sys/checkuseraccess.s index e1d57dc..09c24d6 100644 --- a/i386/sys/checkuseraccess.s +++ b/i386/sys/checkuseraccess.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(checkuseraccess, 0) ret diff --git a/i386/sys/chflags.s b/i386/sys/chflags.s index 3a19cfb..099d9b0 100644 --- a/i386/sys/chflags.s +++ b/i386/sys/chflags.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(chflags, 2) ret diff --git a/i386/sys/chmod.s b/i386/sys/chmod.s index 912ffa5..02c3f0d 100644 --- a/i386/sys/chmod.s +++ b/i386/sys/chmod.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(chmod, 2) ret diff --git a/i386/sys/chown.s b/i386/sys/chown.s index 6683f31..0fcafd7 100644 --- a/i386/sys/chown.s +++ b/i386/sys/chown.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(chown, 3) ret diff --git a/i386/sys/chroot.s b/i386/sys/chroot.s index 61676fd..d8a30f9 100644 --- a/i386/sys/chroot.s +++ b/i386/sys/chroot.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(chroot, 1) ret diff --git a/i386/sys/close.s b/i386/sys/close.s index e43df39..2338bc4 100644 --- a/i386/sys/close.s +++ b/i386/sys/close.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(close, 1) ret diff --git a/i386/sys/connect.s b/i386/sys/connect.s index b323669..51fa9d7 100644 --- a/i386/sys/connect.s +++ b/i386/sys/connect.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(connect, 3) + ret +#else /* !__LP64__ */ PSEUDO(connect$UNIX2003, connect, 3) ret UNIX_SYSCALL_ERR(connect, 3, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/dup.s b/i386/sys/dup.s index 62b58d4..60fcd92 100644 --- a/i386/sys/dup.s +++ b/i386/sys/dup.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(dup, 2) ret diff --git a/i386/sys/dup2.s b/i386/sys/dup2.s index 7e13b9b..74ea431 100644 --- a/i386/sys/dup2.s +++ b/i386/sys/dup2.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(dup2, 2) ret diff --git a/i386/sys/exchangedata.s b/i386/sys/exchangedata.s index 45a7326..e6a4a56 100644 --- a/i386/sys/exchangedata.s +++ b/i386/sys/exchangedata.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(exchangedata, 0) ret diff --git a/i386/sys/execve.s b/i386/sys/execve.s index e6a6356..6a6759b 100644 --- a/i386/sys/execve.s +++ b/i386/sys/execve.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(execve, 3) ret // execve(file, argv, arge) diff --git a/i386/sys/fchdir.s b/i386/sys/fchdir.s index fd86bd2..fa458e2 100644 --- a/i386/sys/fchdir.s +++ b/i386/sys/fchdir.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(fchdir, 1) ret diff --git a/i386/sys/fchflags.s b/i386/sys/fchflags.s index 74c650a..f94f31f 100644 --- a/i386/sys/fchflags.s +++ b/i386/sys/fchflags.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(fchflags, 2) ret diff --git a/i386/sys/fchmod.s b/i386/sys/fchmod.s index c784388..1f87d1f 100644 --- a/i386/sys/fchmod.s +++ b/i386/sys/fchmod.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(fchmod, 2) ret diff --git a/i386/sys/fchown.s b/i386/sys/fchown.s index 2a5fa0c..7c1eb13 100644 --- a/i386/sys/fchown.s +++ b/i386/sys/fchown.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(fchown, 3) ret diff --git a/i386/sys/fcntl.s b/i386/sys/fcntl.s index fcda4a5..63dcabf 100644 --- a/i386/sys/fcntl.s +++ b/i386/sys/fcntl.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(fcntl, 3) ret diff --git a/i386/sys/fgetxattr.s b/i386/sys/fgetxattr.s index 83d7c62..14f1bd6 100644 --- a/i386/sys/fgetxattr.s +++ b/i386/sys/fgetxattr.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(fgetxattr, 5) ret diff --git a/i386/sys/fhopen.s b/i386/sys/fhopen.s index d94e9c7..a82c9af 100644 --- a/i386/sys/fhopen.s +++ b/i386/sys/fhopen.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(fhopen, 2) ret diff --git a/i386/sys/flistxattr.s b/i386/sys/flistxattr.s index f46ed4a..d953e2b 100644 --- a/i386/sys/flistxattr.s +++ b/i386/sys/flistxattr.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(flistxattr, 4) ret diff --git a/i386/sys/flock.s b/i386/sys/flock.s index ee2c2a8..097fe49 100644 --- a/i386/sys/flock.s +++ b/i386/sys/flock.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(flock, 2) ret diff --git a/i386/sys/fork.s b/i386/sys/fork.s index 8dc35d2..c78eb04 100644 --- a/i386/sys/fork.s +++ b/i386/sys/fork.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include LEAF(_fork, 0) subl $28, %esp // Align the stack, with 16 bytes of extra padding that we'll need diff --git a/i386/sys/fpathconf.s b/i386/sys/fpathconf.s index 4d6824c..a233793 100644 --- a/i386/sys/fpathconf.s +++ b/i386/sys/fpathconf.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(fpathconf, 2) ret diff --git a/i386/sys/fremovexattr.s b/i386/sys/fremovexattr.s index 4b7e6b4..63831a4 100644 --- a/i386/sys/fremovexattr.s +++ b/i386/sys/fremovexattr.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(fremovexattr, 3) ret diff --git a/i386/sys/fsctl.s b/i386/sys/fsctl.s index 763f145..dae5f18 100644 --- a/i386/sys/fsctl.s +++ b/i386/sys/fsctl.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(fsctl, 4) ret diff --git a/i386/sys/fsetxattr.s b/i386/sys/fsetxattr.s index 1da2ebb..e97b966 100644 --- a/i386/sys/fsetxattr.s +++ b/i386/sys/fsetxattr.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(fsetxattr, 5) ret diff --git a/i386/sys/fstat.s b/i386/sys/fstat.s index 869c4b9..820f99a 100644 --- a/i386/sys/fstat.s +++ b/i386/sys/fstat.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(fstat, 2) ret diff --git a/i386/sys/fstatfs.s b/i386/sys/fstatfs.s index 0bf2239..917cc77 100644 --- a/i386/sys/fstatfs.s +++ b/i386/sys/fstatfs.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(fstatfs, 2) ret diff --git a/i386/sys/fstatv.s b/i386/sys/fstatv.s index d23315b..323c96a 100644 --- a/i386/sys/fstatv.s +++ b/i386/sys/fstatv.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(fstatv, 0) ret diff --git a/i386/sys/fsync.s b/i386/sys/fsync.s index 0433dcd..1818d21 100644 --- a/i386/sys/fsync.s +++ b/i386/sys/fsync.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(fsync, 1) ret diff --git a/i386/sys/ftruncate.s b/i386/sys/ftruncate.s index 717be65..0d5a07d 100644 --- a/i386/sys/ftruncate.s +++ b/i386/sys/ftruncate.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(ftruncate, 2) ret diff --git a/i386/sys/futimes.s b/i386/sys/futimes.s index 6a01fae..b93a689 100644 --- a/i386/sys/futimes.s +++ b/i386/sys/futimes.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(futimes, 2) ret diff --git a/i386/sys/getattrlist.s b/i386/sys/getattrlist.s index bf679b9..a35ff4d 100644 --- a/i386/sys/getattrlist.s +++ b/i386/sys/getattrlist.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(getattrlist, 0) + ret +#else /* !__LP64__ */ PSEUDO(getattrlist$UNIX2003, getattrlist, 0) ret UNIX_SYSCALL_ERR(getattrlist, 0, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/getaudit.s b/i386/sys/getaudit.s index 11e5a6e..ebf8a6f 100644 --- a/i386/sys/getaudit.s +++ b/i386/sys/getaudit.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(getaudit, 1) ret diff --git a/i386/sys/getaudit_addr.s b/i386/sys/getaudit_addr.s index cdc345f..4579234 100644 --- a/i386/sys/getaudit_addr.s +++ b/i386/sys/getaudit_addr.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(getaudit_addr, 2) ret diff --git a/i386/sys/getauid.s b/i386/sys/getauid.s index 83a3590..a6a09fd 100644 --- a/i386/sys/getauid.s +++ b/i386/sys/getauid.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(getauid, 1) ret diff --git a/i386/sys/getdirentries.s b/i386/sys/getdirentries.s index 95c032f..2abc2bf 100644 --- a/i386/sys/getdirentries.s +++ b/i386/sys/getdirentries.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getdirentries, 4) ret diff --git a/i386/sys/getdirentriesattr.s b/i386/sys/getdirentriesattr.s index a0d321b..b69947e 100644 --- a/i386/sys/getdirentriesattr.s +++ b/i386/sys/getdirentriesattr.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getdirentriesattr, 0) ret diff --git a/i386/sys/getdtablesize.s b/i386/sys/getdtablesize.s index d014cc5..27bd6ad 100644 --- a/i386/sys/getdtablesize.s +++ b/i386/sys/getdtablesize.s @@ -21,7 +21,7 @@ * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(getdtablesize, 0) ret // i = getdtablesize(); diff --git a/i386/sys/getegid.s b/i386/sys/getegid.s index d8d3568..5b85e9c 100644 --- a/i386/sys/getegid.s +++ b/i386/sys/getegid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getegid, 0) ret diff --git a/i386/sys/geteuid.s b/i386/sys/geteuid.s index d7b119b..40c1fe4 100644 --- a/i386/sys/geteuid.s +++ b/i386/sys/geteuid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(geteuid, 0) ret diff --git a/i386/sys/getfh.s b/i386/sys/getfh.s index 09c4dfe..8ce000a 100644 --- a/i386/sys/getfh.s +++ b/i386/sys/getfh.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getfh, 2) ret diff --git a/i386/sys/getfsstat.s b/i386/sys/getfsstat.s index b0f24a9..2622be2 100644 --- a/i386/sys/getfsstat.s +++ b/i386/sys/getfsstat.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getfsstat, 3) ret diff --git a/i386/sys/getgid.s b/i386/sys/getgid.s index 5c4d7a7..58d6d41 100644 --- a/i386/sys/getgid.s +++ b/i386/sys/getgid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getgid, 0) ret // gid = getgid(); diff --git a/i386/sys/getgroups.s b/i386/sys/getgroups.s index cc4322a..61eb82c 100644 --- a/i386/sys/getgroups.s +++ b/i386/sys/getgroups.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getgroups, 2) ret // ngroups = getgroups(gidsetsize, gidset) diff --git a/i386/sys/getitimer.s b/i386/sys/getitimer.s index 9328751..e0d5c3b 100644 --- a/i386/sys/getitimer.s +++ b/i386/sys/getitimer.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getitimer, 2) ret diff --git a/i386/sys/getpeername.s b/i386/sys/getpeername.s index 55cc556..d7b3a0d 100644 --- a/i386/sys/getpeername.s +++ b/i386/sys/getpeername.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(getpeername, 3) + ret +#else /* !__LP64__ */ PSEUDO(getpeername$UNIX2003, getpeername, 3) ret UNIX_SYSCALL_ERR(getpeername, 3, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/getpgid.s b/i386/sys/getpgid.s index b0d52f7..a707ae8 100644 --- a/i386/sys/getpgid.s +++ b/i386/sys/getpgid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getpgid, 1) ret diff --git a/i386/sys/getpgrp.s b/i386/sys/getpgrp.s index 6a64c7d..cbe43b5 100644 --- a/i386/sys/getpgrp.s +++ b/i386/sys/getpgrp.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getpgrp, 1) ret // pgrp = getpgrp(pid); diff --git a/i386/sys/getpid.s b/i386/sys/getpid.s index d08bd95..728bf49 100644 --- a/i386/sys/getpid.s +++ b/i386/sys/getpid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include .data .private_extern __current_pid diff --git a/i386/sys/getppid.s b/i386/sys/getppid.s index b0a4555..0c27b8b 100644 --- a/i386/sys/getppid.s +++ b/i386/sys/getppid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getppid,0) ret diff --git a/i386/sys/getpriority.s b/i386/sys/getpriority.s index af90ad9..4c532ad 100644 --- a/i386/sys/getpriority.s +++ b/i386/sys/getpriority.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getpriority, 2) ret diff --git a/i386/sys/getrlimit.s b/i386/sys/getrlimit.s index 57e56d1..89595dd 100644 --- a/i386/sys/getrlimit.s +++ b/i386/sys/getrlimit.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getrlimit, 2) ret diff --git a/i386/sys/getrusage.s b/i386/sys/getrusage.s index e15e628..eb1bb5e 100644 --- a/i386/sys/getrusage.s +++ b/i386/sys/getrusage.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getrusage, 2) ret diff --git a/i386/sys/getsid.s b/i386/sys/getsid.s index 4afddff..7388e99 100644 --- a/i386/sys/getsid.s +++ b/i386/sys/getsid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getsid, 1) ret diff --git a/i386/sys/getsockname.s b/i386/sys/getsockname.s index 135a372..3cde723 100644 --- a/i386/sys/getsockname.s +++ b/i386/sys/getsockname.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(getsockname, 3) + ret +#else /* !__LP64__ */ PSEUDO(getsockname$UNIX2003, getsockname, 3) ret UNIX_SYSCALL_ERR(getsockname, 3, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/getsockopt.s b/i386/sys/getsockopt.s index 269a334..e0fb6d4 100644 --- a/i386/sys/getsockopt.s +++ b/i386/sys/getsockopt.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getsockopt, 5) ret diff --git a/i386/sys/getuid.s b/i386/sys/getuid.s index 2b36b4f..91505ba 100644 --- a/i386/sys/getuid.s +++ b/i386/sys/getuid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(getuid, 0) ret // uid = getuid(); diff --git a/i386/sys/getxattr.s b/i386/sys/getxattr.s index d4e7a8e..370d3d3 100644 --- a/i386/sys/getxattr.s +++ b/i386/sys/getxattr.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(getxattr, 5) ret diff --git a/i386/sys/i386_gettimeofday.s b/i386/sys/i386_gettimeofday.s index 5de6ca7..e32587c 100644 --- a/i386/sys/i386_gettimeofday.s +++ b/i386/sys/i386_gettimeofday.s @@ -22,7 +22,7 @@ */ /* Copyright 1998 Apple Computer, Inc. */ -#include "SYS.h" +#include #define __APPLE_API_PRIVATE #include @@ -30,7 +30,7 @@ LABEL(___commpage_gettimeofday) mov $ _COMM_PAGE_GETTIMEOFDAY,%eax - jmp %eax + jmp *%eax /* * This syscall is special cased: the timeval is returned in eax/edx. diff --git a/i386/sys/ioctl.s b/i386/sys/ioctl.s index 528950a..128bc3b 100644 --- a/i386/sys/ioctl.s +++ b/i386/sys/ioctl.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(ioctl, 3) ret diff --git a/i386/sys/issetugid.s b/i386/sys/issetugid.s index d986045..b1e56f1 100644 --- a/i386/sys/issetugid.s +++ b/i386/sys/issetugid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(issetugid, 0) ret diff --git a/i386/sys/kevent.s b/i386/sys/kevent.s index cedc7c0..aee6db5 100644 --- a/i386/sys/kevent.s +++ b/i386/sys/kevent.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(kevent, 6) ret diff --git a/i386/sys/kill.s b/i386/sys/kill.s index 59e17ad..7de3ab2 100644 --- a/i386/sys/kill.s +++ b/i386/sys/kill.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(kill, 2) ret diff --git a/i386/sys/kqueue.s b/i386/sys/kqueue.s index 398d766..6b8a0d4 100644 --- a/i386/sys/kqueue.s +++ b/i386/sys/kqueue.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(kqueue, 0) ret diff --git a/i386/sys/kqueue_from_portset_np.s b/i386/sys/kqueue_from_portset_np.s index b2e4697..a92fb53 100644 --- a/i386/sys/kqueue_from_portset_np.s +++ b/i386/sys/kqueue_from_portset_np.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(kqueue_from_portset_np, 1) ret diff --git a/i386/sys/kqueue_portset_np.s b/i386/sys/kqueue_portset_np.s index 1e782ea..8e093e2 100644 --- a/i386/sys/kqueue_portset_np.s +++ b/i386/sys/kqueue_portset_np.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(kqueue_portset_np, 1) ret diff --git a/i386/sys/ktrace.s b/i386/sys/ktrace.s index 77bd931..93a27c9 100644 --- a/i386/sys/ktrace.s +++ b/i386/sys/ktrace.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(ktrace, 4) ret diff --git a/i386/sys/lchown.s b/i386/sys/lchown.s index 2912367..7d7f72b 100644 --- a/i386/sys/lchown.s +++ b/i386/sys/lchown.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2004, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -20,10 +20,15 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(lchown, 3) + ret +#else /* !__LP64__ */ PSEUDO(lchown$UNIX2003, lchown, 3) ret UNIX_SYSCALL_ERR(lchown, 3, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/link.s b/i386/sys/link.s index 820375a..e26cf59 100644 --- a/i386/sys/link.s +++ b/i386/sys/link.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(link, 2) ret diff --git a/i386/sys/lio_listio.s b/i386/sys/lio_listio.s index b5fc01f..2642027 100644 --- a/i386/sys/lio_listio.s +++ b/i386/sys/lio_listio.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(lio_listio, 4) ret diff --git a/i386/sys/listen.s b/i386/sys/listen.s index 8bd5676..3257f81 100644 --- a/i386/sys/listen.s +++ b/i386/sys/listen.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(listen, 2) + ret +#else /* !__LP64__ */ PSEUDO(listen$UNIX2003, listen, 2) ret UNIX_SYSCALL_ERR(listen, 2, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/listxattr.s b/i386/sys/listxattr.s index 990d4a9..dce76a1 100644 --- a/i386/sys/listxattr.s +++ b/i386/sys/listxattr.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(listxattr, 4) ret diff --git a/i386/sys/load_shared_file.s b/i386/sys/load_shared_file.s index 900bdf8..e994324 100644 --- a/i386/sys/load_shared_file.s +++ b/i386/sys/load_shared_file.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(load_shared_file, 7) ret diff --git a/i386/sys/lseek.s b/i386/sys/lseek.s index 8dfc808..9f58dec 100644 --- a/i386/sys/lseek.s +++ b/i386/sys/lseek.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL_INT(lseek, 3) ret diff --git a/i386/sys/lstat.s b/i386/sys/lstat.s index b76854e..80abe5b 100644 --- a/i386/sys/lstat.s +++ b/i386/sys/lstat.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(lstat, 2) ret diff --git a/i386/sys/lstatv.s b/i386/sys/lstatv.s index d3994d4..e06c5f5 100644 --- a/i386/sys/lstatv.s +++ b/i386/sys/lstatv.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(lstatv, 0) ret diff --git a/i386/sys/madvise.s b/i386/sys/madvise.s index 849e702..b6e90ed 100644 --- a/i386/sys/madvise.s +++ b/i386/sys/madvise.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(madvise, 3) ret diff --git a/i386/sys/mincore.s b/i386/sys/mincore.s index 6b5871e..94b1412 100644 --- a/i386/sys/mincore.s +++ b/i386/sys/mincore.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(mincore, 3) ret diff --git a/i386/sys/minherit.s b/i386/sys/minherit.s index 84a5190..536c71f 100644 --- a/i386/sys/minherit.s +++ b/i386/sys/minherit.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(minherit, 3) ret diff --git a/i386/sys/mkcomplex.s b/i386/sys/mkcomplex.s index 45285c6..69ee538 100644 --- a/i386/sys/mkcomplex.s +++ b/i386/sys/mkcomplex.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(mkcomplex, 0) ret diff --git a/i386/sys/mkdir.s b/i386/sys/mkdir.s index df857a7..0dd87cf 100644 --- a/i386/sys/mkdir.s +++ b/i386/sys/mkdir.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(mkdir, 2) ret diff --git a/i386/sys/mkfifo.s b/i386/sys/mkfifo.s index f7b74df..e21263e 100644 --- a/i386/sys/mkfifo.s +++ b/i386/sys/mkfifo.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(mkfifo, 2) ret diff --git a/i386/sys/mknod.s b/i386/sys/mknod.s index 9170403..27df451 100644 --- a/i386/sys/mknod.s +++ b/i386/sys/mknod.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(mknod, 3) ret diff --git a/i386/sys/mlock.s b/i386/sys/mlock.s index 6f0b694..eccef85 100644 --- a/i386/sys/mlock.s +++ b/i386/sys/mlock.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(mlock, 3) ret diff --git a/i386/sys/mlockall.s b/i386/sys/mlockall.s index e85392c..0b077d9 100644 --- a/i386/sys/mlockall.s +++ b/i386/sys/mlockall.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(mlockall, 3) ret diff --git a/i386/sys/mount.s b/i386/sys/mount.s index 0dd8b59..5d25824 100644 --- a/i386/sys/mount.s +++ b/i386/sys/mount.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(mount, 4) ret diff --git a/i386/sys/msgget.s b/i386/sys/msgget.s index b707393..bc5cbe2 100644 --- a/i386/sys/msgget.s +++ b/i386/sys/msgget.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(msgget, 3) ret diff --git a/i386/sys/msgrcv.s b/i386/sys/msgrcv.s index 265f187..f0ba773 100644 --- a/i386/sys/msgrcv.s +++ b/i386/sys/msgrcv.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(msgrcv, 3) ret diff --git a/i386/sys/msgsnd.s b/i386/sys/msgsnd.s index 7421a4c..3877229 100644 --- a/i386/sys/msgsnd.s +++ b/i386/sys/msgsnd.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(msgsnd, 3) ret diff --git a/i386/sys/msgsys.s b/i386/sys/msgsys.s index 78a8809..8f7d12d 100644 --- a/i386/sys/msgsys.s +++ b/i386/sys/msgsys.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(msgsys, 3) ret diff --git a/i386/sys/munlock.s b/i386/sys/munlock.s index 2d0784b..d61cfe4 100644 --- a/i386/sys/munlock.s +++ b/i386/sys/munlock.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(munlock, 3) ret diff --git a/i386/sys/munlockall.s b/i386/sys/munlockall.s index 42dcd11..41f4a1d 100644 --- a/i386/sys/munlockall.s +++ b/i386/sys/munlockall.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(munlockall, 3) ret diff --git a/i386/sys/new_system_shared_regions.s b/i386/sys/new_system_shared_regions.s index 38bb951..6c1db69 100644 --- a/i386/sys/new_system_shared_regions.s +++ b/i386/sys/new_system_shared_regions.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(new_system_shared_regions, 0) ret diff --git a/i386/sys/nfsclnt.s b/i386/sys/nfsclnt.s index ebfc230..80dbcec 100644 --- a/i386/sys/nfsclnt.s +++ b/i386/sys/nfsclnt.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(nfsclnt, 2) ret diff --git a/i386/sys/nfssvc.s b/i386/sys/nfssvc.s index 7c461e1..ba92a9f 100644 --- a/i386/sys/nfssvc.s +++ b/i386/sys/nfssvc.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(nfssvc, 1) ret diff --git a/i386/sys/open.s b/i386/sys/open.s index 53748d1..463fe2b 100644 --- a/i386/sys/open.s +++ b/i386/sys/open.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(open, 3) ret diff --git a/i386/sys/pathconf.s b/i386/sys/pathconf.s index dca4d89..08a1e83 100644 --- a/i386/sys/pathconf.s +++ b/i386/sys/pathconf.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(pathconf, 2) ret diff --git a/i386/sys/pipe.s b/i386/sys/pipe.s index e681240..c49df43 100644 --- a/i386/sys/pipe.s +++ b/i386/sys/pipe.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL_INT(pipe, 0) movl 4(%esp),%ecx diff --git a/i386/sys/poll.s b/i386/sys/poll.s index abe42c5..8d3d8bd 100644 --- a/i386/sys/poll.s +++ b/i386/sys/poll.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(poll, 3) ret diff --git a/i386/sys/posix_madvise.s b/i386/sys/posix_madvise.s index 5c1535c..d08a4b6 100644 --- a/i386/sys/posix_madvise.s +++ b/i386/sys/posix_madvise.s @@ -22,7 +22,7 @@ */ /* Copyright 1998 Apple Computer, Inc. */ -#include "SYS.h" +#include PSEUDO(posix_madvise, madvise, 3) ret diff --git a/i386/sys/pread.s b/i386/sys/pread.s index 55b145f..ea48c9c 100644 --- a/i386/sys/pread.s +++ b/i386/sys/pread.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(pread, 4) ret diff --git a/i386/sys/profil.s b/i386/sys/profil.s index dfcb2a7..8610c95 100644 --- a/i386/sys/profil.s +++ b/i386/sys/profil.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(profil, 4) ret diff --git a/i386/sys/pthread_sigmask.s b/i386/sys/pthread_sigmask.s index 6f44630..510d269 100644 --- a/i386/sys/pthread_sigmask.s +++ b/i386/sys/pthread_sigmask.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(pthread_sigmask, 3) ret diff --git a/i386/sys/ptrace.s b/i386/sys/ptrace.s index 720e96b..cccd814 100644 --- a/i386/sys/ptrace.s +++ b/i386/sys/ptrace.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include .globl _errno diff --git a/i386/sys/pwrite.s b/i386/sys/pwrite.s index 26e7264..1ea681b 100644 --- a/i386/sys/pwrite.s +++ b/i386/sys/pwrite.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(pwrite, 4) ret diff --git a/i386/sys/quota.s b/i386/sys/quota.s index 254d961..402b0af 100644 --- a/i386/sys/quota.s +++ b/i386/sys/quota.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include #define SYS_quota 149 diff --git a/i386/sys/quotactl.s b/i386/sys/quotactl.s index 10de9cf..51d7c3e 100644 --- a/i386/sys/quotactl.s +++ b/i386/sys/quotactl.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(quotactl, 3) ret diff --git a/i386/sys/read.s b/i386/sys/read.s index 1714748..6035086 100644 --- a/i386/sys/read.s +++ b/i386/sys/read.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(read, 3) ret diff --git a/i386/sys/readlink.s b/i386/sys/readlink.s index aeaea49..bf690a3 100644 --- a/i386/sys/readlink.s +++ b/i386/sys/readlink.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(readlink, 3) ret diff --git a/i386/sys/readv.s b/i386/sys/readv.s index eddb6af..d3b3583 100644 --- a/i386/sys/readv.s +++ b/i386/sys/readv.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(readv, 3) ret diff --git a/i386/sys/reboot.s b/i386/sys/reboot.s index d020b9c..12da158 100644 --- a/i386/sys/reboot.s +++ b/i386/sys/reboot.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(reboot, 2) hlt diff --git a/i386/sys/recvfrom.s b/i386/sys/recvfrom.s index be58a7f..7fb485f 100644 --- a/i386/sys/recvfrom.s +++ b/i386/sys/recvfrom.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(recvfrom, 6) + ret +#else /* !__LP64__ */ PSEUDO(recvfrom$UNIX2003, recvfrom, 6) ret UNIX_SYSCALL_ERR(recvfrom, 6, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/recvmsg.s b/i386/sys/recvmsg.s index 25e44ab..347e1e0 100644 --- a/i386/sys/recvmsg.s +++ b/i386/sys/recvmsg.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(recvmsg, 3) + ret +#else /* !__LP64__ */ PSEUDO(recvmsg$UNIX2003, recvmsg, 3) ret UNIX_SYSCALL_ERR(recvmsg, 3, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/removexattr.s b/i386/sys/removexattr.s index 0d4db9f..77fe419 100644 --- a/i386/sys/removexattr.s +++ b/i386/sys/removexattr.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(removexattr, 3) ret diff --git a/i386/sys/rename.s b/i386/sys/rename.s index 43e59c2..9e2278f 100644 --- a/i386/sys/rename.s +++ b/i386/sys/rename.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(rename, 2) ret diff --git a/i386/sys/reset_shared_file.s b/i386/sys/reset_shared_file.s index 264188a..9dd0d42 100644 --- a/i386/sys/reset_shared_file.s +++ b/i386/sys/reset_shared_file.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(reset_shared_file, 3) ret diff --git a/i386/sys/revoke.s b/i386/sys/revoke.s index bba4914..8e92a8c 100644 --- a/i386/sys/revoke.s +++ b/i386/sys/revoke.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(revoke, 1) ret diff --git a/i386/sys/rmdir.s b/i386/sys/rmdir.s index a03b1f6..6576355 100644 --- a/i386/sys/rmdir.s +++ b/i386/sys/rmdir.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(rmdir, 1) ret diff --git a/i386/sys/searchfs.s b/i386/sys/searchfs.s index 990308b..1b343f8 100644 --- a/i386/sys/searchfs.s +++ b/i386/sys/searchfs.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(searchfs, 0) ret diff --git a/i386/sys/select.s b/i386/sys/select.s index ed61157..68af42e 100644 --- a/i386/sys/select.s +++ b/i386/sys/select.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(select, 5) ret diff --git a/i386/sys/sem_close.s b/i386/sys/sem_close.s index fc67d24..25cafa7 100644 --- a/i386/sys/sem_close.s +++ b/i386/sys/sem_close.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(sem_close, 1) ret diff --git a/i386/sys/sem_destroy.s b/i386/sys/sem_destroy.s index a4f9542..dc0cdd1 100644 --- a/i386/sys/sem_destroy.s +++ b/i386/sys/sem_destroy.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(sem_destroy, 1) ret diff --git a/i386/sys/sem_getvalue.s b/i386/sys/sem_getvalue.s index 2dff035..5812fe7 100644 --- a/i386/sys/sem_getvalue.s +++ b/i386/sys/sem_getvalue.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(sem_getvalue, 2) ret diff --git a/i386/sys/sem_init.s b/i386/sys/sem_init.s index 2e5fc53..c7027c2 100644 --- a/i386/sys/sem_init.s +++ b/i386/sys/sem_init.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(sem_init, 3) ret diff --git a/i386/sys/sem_post.s b/i386/sys/sem_post.s index 6586aae..5610342 100644 --- a/i386/sys/sem_post.s +++ b/i386/sys/sem_post.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(sem_post, 1) ret diff --git a/i386/sys/sem_trywait.s b/i386/sys/sem_trywait.s index cf74144..f2efe65 100644 --- a/i386/sys/sem_trywait.s +++ b/i386/sys/sem_trywait.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(sem_trywait, 1) ret diff --git a/i386/sys/sem_wait.s b/i386/sys/sem_wait.s index 2f4e8e8..5a656e5 100644 --- a/i386/sys/sem_wait.s +++ b/i386/sys/sem_wait.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(sem_wait, 1) ret diff --git a/i386/sys/semget.s b/i386/sys/semget.s index 32d8c33..cab8501 100644 --- a/i386/sys/semget.s +++ b/i386/sys/semget.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(semget, 3) ret diff --git a/i386/sys/semop.s b/i386/sys/semop.s index 8b1c2ee..5d0ff12 100644 --- a/i386/sys/semop.s +++ b/i386/sys/semop.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(semop, 3) ret diff --git a/i386/sys/semsys.s b/i386/sys/semsys.s index f2321ed..5813c69 100644 --- a/i386/sys/semsys.s +++ b/i386/sys/semsys.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(semsys, 3) ret diff --git a/i386/sys/sendmsg.s b/i386/sys/sendmsg.s index 31f0109..e30ee3b 100644 --- a/i386/sys/sendmsg.s +++ b/i386/sys/sendmsg.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(sendmsg, 3) + ret +#else /* !__LP64__ */ PSEUDO(sendmsg$UNIX2003, sendmsg, 3) ret UNIX_SYSCALL_ERR(sendmsg, 3, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/sendto.s b/i386/sys/sendto.s index db01bd1..14ba2bb 100644 --- a/i386/sys/sendto.s +++ b/i386/sys/sendto.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(sendto, 6) + ret +#else /* !__LP64__ */ PSEUDO(sendto$UNIX2003, sendto, 6) ret UNIX_SYSCALL_ERR(sendto, 6, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/setattrlist.s b/i386/sys/setattrlist.s index 6f33adc..801bde9 100644 --- a/i386/sys/setattrlist.s +++ b/i386/sys/setattrlist.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(setattrlist, 0) + ret +#else /* !__LP64__ */ PSEUDO(setattrlist$UNIX2003, setattrlist, 0) ret UNIX_SYSCALL_ERR(setattrlist, 0, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/setaudit.s b/i386/sys/setaudit.s index 253d5a8..77b4ec4 100644 --- a/i386/sys/setaudit.s +++ b/i386/sys/setaudit.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(setaudit, 1) ret diff --git a/i386/sys/setaudit_addr.s b/i386/sys/setaudit_addr.s index 4ead3a9..5857301 100644 --- a/i386/sys/setaudit_addr.s +++ b/i386/sys/setaudit_addr.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(setaudit_addr, 2) ret diff --git a/i386/sys/setauid.s b/i386/sys/setauid.s index ff5cc60..ac94ab2 100644 --- a/i386/sys/setauid.s +++ b/i386/sys/setauid.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(setauid, 1) ret diff --git a/i386/sys/setegid.s b/i386/sys/setegid.s index bdbad71..1d05963 100644 --- a/i386/sys/setegid.s +++ b/i386/sys/setegid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(setegid, 1) ret diff --git a/i386/sys/seteuid.s b/i386/sys/seteuid.s index c3302e2..38744f2 100644 --- a/i386/sys/seteuid.s +++ b/i386/sys/seteuid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(seteuid, 1) ret diff --git a/i386/sys/setgid.s b/i386/sys/setgid.s index df995db..142c4b0 100644 --- a/i386/sys/setgid.s +++ b/i386/sys/setgid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(setgid, 1) ret diff --git a/i386/sys/setgroups.s b/i386/sys/setgroups.s index 217f57f..bf8f0ed 100644 --- a/i386/sys/setgroups.s +++ b/i386/sys/setgroups.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(setgroups, 2) ret // setgroups(gidsetsize, gidset) diff --git a/i386/sys/setitimer.s b/i386/sys/setitimer.s index 47232da..52333d9 100644 --- a/i386/sys/setitimer.s +++ b/i386/sys/setitimer.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(setitimer, 3) ret diff --git a/i386/sys/setjmp.s b/i386/sys/setjmp.s index ac7b28b..0dba96f 100644 --- a/i386/sys/setjmp.s +++ b/i386/sys/setjmp.s @@ -43,11 +43,13 @@ */ #include -#include "SYS.h" +#include -#define JB_ONSTACK 0 +// The FP control word is actually two bytes, but there's no harm in +// using four bytes for it and keeping the struct aligned. +#define JB_FPCW 0 #define JB_MASK 4 -#define JB_EAX 8 +#define JB_MXCSR 8 #define JB_EBX 12 #define JB_ECX 16 #define JB_EDX 20 diff --git a/i386/sys/setpgid.s b/i386/sys/setpgid.s index b3c8af9..f0f5160 100644 --- a/i386/sys/setpgid.s +++ b/i386/sys/setpgid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(setpgid, 2) ret diff --git a/i386/sys/setpriority.s b/i386/sys/setpriority.s index e9546e1..b391375 100644 --- a/i386/sys/setpriority.s +++ b/i386/sys/setpriority.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(setpriority, 3) ret diff --git a/i386/sys/setprivexec.s b/i386/sys/setprivexec.s index f104e6c..4260a7f 100644 --- a/i386/sys/setprivexec.s +++ b/i386/sys/setprivexec.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(setprivexec, 3) ret diff --git a/i386/sys/setquota.s b/i386/sys/setquota.s index 330973b..fa7ad10 100644 --- a/i386/sys/setquota.s +++ b/i386/sys/setquota.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include #define SYS_setquota 148 diff --git a/i386/sys/setrlimit.s b/i386/sys/setrlimit.s index ae3e3cf..adac73c 100644 --- a/i386/sys/setrlimit.s +++ b/i386/sys/setrlimit.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(setrlimit, 2) ret diff --git a/i386/sys/setsid.s b/i386/sys/setsid.s index 42d3cbd..e074158 100644 --- a/i386/sys/setsid.s +++ b/i386/sys/setsid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(setsid, 0) ret diff --git a/i386/sys/setsockopt.s b/i386/sys/setsockopt.s index 0c5ffa8..4f4afd7 100644 --- a/i386/sys/setsockopt.s +++ b/i386/sys/setsockopt.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(setsockopt, 5) ret diff --git a/i386/sys/settimeofday.s b/i386/sys/settimeofday.s index 87a0b2f..8191332 100644 --- a/i386/sys/settimeofday.s +++ b/i386/sys/settimeofday.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(settimeofday, 2) ret diff --git a/i386/sys/setuid.s b/i386/sys/setuid.s index 25c6245..798dc02 100644 --- a/i386/sys/setuid.s +++ b/i386/sys/setuid.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(setuid, 1) ret diff --git a/i386/sys/setxattr.s b/i386/sys/setxattr.s index 8460c08..176a795 100644 --- a/i386/sys/setxattr.s +++ b/i386/sys/setxattr.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(setxattr, 5) ret diff --git a/i386/sys/shmat.s b/i386/sys/shmat.s index 41b50de..ae59417 100644 --- a/i386/sys/shmat.s +++ b/i386/sys/shmat.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(shmat, 3) ret diff --git a/i386/sys/shmdt.s b/i386/sys/shmdt.s index 9cfe18a..0d72820 100644 --- a/i386/sys/shmdt.s +++ b/i386/sys/shmdt.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(shmdt, 3) ret diff --git a/i386/sys/shmget.s b/i386/sys/shmget.s index b7441ee..69a6e37 100644 --- a/i386/sys/shmget.s +++ b/i386/sys/shmget.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(shmget, 3) ret diff --git a/i386/sys/shmsys.s b/i386/sys/shmsys.s index a0736e7..6120f95 100644 --- a/i386/sys/shmsys.s +++ b/i386/sys/shmsys.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(shmsys, 3) ret diff --git a/i386/sys/shutdown.s b/i386/sys/shutdown.s index fe07517..6f7d7c3 100644 --- a/i386/sys/shutdown.s +++ b/i386/sys/shutdown.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(shutdown, 2) ret diff --git a/i386/sys/sigaltstack.s b/i386/sys/sigaltstack.s index 724180a..cb42ea3 100644 --- a/i386/sys/sigaltstack.s +++ b/i386/sys/sigaltstack.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL_INT(sigaltstack, 3) ret diff --git a/i386/sys/sigpending.s b/i386/sys/sigpending.s index b8acf3f..08557e9 100644 --- a/i386/sys/sigpending.s +++ b/i386/sys/sigpending.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(sigpending, 1) ret diff --git a/i386/sys/sigprocmask.s b/i386/sys/sigprocmask.s index 52ce593..15e53c9 100644 --- a/i386/sys/sigprocmask.s +++ b/i386/sys/sigprocmask.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(sigprocmask, 3) ret diff --git a/i386/sys/sigreturn.s b/i386/sys/sigreturn.s index 76560ee..781005d 100644 --- a/i386/sys/sigreturn.s +++ b/i386/sys/sigreturn.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL_INT(sigreturn, 2) ret diff --git a/i386/sys/sigwait.s b/i386/sys/sigwait.s index 1952b31..f42d465 100644 --- a/i386/sys/sigwait.s +++ b/i386/sys/sigwait.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(sigwait, 2) ret diff --git a/i386/sys/socket.s b/i386/sys/socket.s index e28a635..ecb5df0 100644 --- a/i386/sys/socket.s +++ b/i386/sys/socket.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(socket, 3) ret diff --git a/i386/sys/socketpair.s b/i386/sys/socketpair.s index eaa2931..feae561 100644 --- a/i386/sys/socketpair.s +++ b/i386/sys/socketpair.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -23,10 +23,15 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include +#ifdef __LP64__ +UNIX_SYSCALL(socketpair, 5) + ret +#else /* !__LP64__ */ PSEUDO(socketpair$UNIX2003, socketpair, 5) ret UNIX_SYSCALL_ERR(socketpair, 5, cerror_cvt) ret +#endif /* !__LP64__ */ diff --git a/i386/sys/stat.s b/i386/sys/stat.s index 9a6feb2..8ab986e 100644 --- a/i386/sys/stat.s +++ b/i386/sys/stat.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(stat, 2) ret diff --git a/i386/sys/statfs.s b/i386/sys/statfs.s index 6c84dbe..50163bc 100644 --- a/i386/sys/statfs.s +++ b/i386/sys/statfs.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(statfs, 2); ret diff --git a/i386/sys/statv.s b/i386/sys/statv.s index 6473009..7ea9660 100644 --- a/i386/sys/statv.s +++ b/i386/sys/statv.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(statv, 0) ret diff --git a/i386/sys/swapon.s b/i386/sys/swapon.s index fe95cb0..7832499 100644 --- a/i386/sys/swapon.s +++ b/i386/sys/swapon.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(swapon, 1) ret diff --git a/i386/sys/symlink.s b/i386/sys/symlink.s index 28a88bc..ddc031a 100644 --- a/i386/sys/symlink.s +++ b/i386/sys/symlink.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(symlink, 2) ret diff --git a/i386/sys/sync.s b/i386/sys/sync.s index 1b3d72d..12863d8 100644 --- a/i386/sys/sync.s +++ b/i386/sys/sync.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(sync, 0) ret diff --git a/i386/sys/syscall.s b/i386/sys/syscall.s index 9b28f68..0e91b68 100644 --- a/i386/sys/syscall.s +++ b/i386/sys/syscall.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include LEAF(_syscall, 0) popl %ecx // ret addr diff --git a/i386/sys/systable.s b/i386/sys/systable.s index a2a1b28..0a7a6cb 100644 --- a/i386/sys/systable.s +++ b/i386/sys/systable.s @@ -20,7 +20,7 @@ * * @APPLE_LICENSE_HEADER_END@ */ -#include "SYS.h" +#include UNIX_SYSCALL(table, 5) ret diff --git a/i386/sys/truncate.s b/i386/sys/truncate.s index 522e0f9..7a81e56 100644 --- a/i386/sys/truncate.s +++ b/i386/sys/truncate.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(truncate, 2) ret diff --git a/i386/sys/umask.s b/i386/sys/umask.s index 55ff2bd..bf30626 100644 --- a/i386/sys/umask.s +++ b/i386/sys/umask.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(umask, 1) ret diff --git a/i386/sys/undelete.s b/i386/sys/undelete.s index 1b55879..36776c6 100644 --- a/i386/sys/undelete.s +++ b/i386/sys/undelete.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(undelete, 1) ret diff --git a/i386/sys/unlink.s b/i386/sys/unlink.s index d0af96b..cd77691 100644 --- a/i386/sys/unlink.s +++ b/i386/sys/unlink.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(unlink, 1) ret diff --git a/i386/sys/unmount.s b/i386/sys/unmount.s index f10804a..1e24673 100644 --- a/i386/sys/unmount.s +++ b/i386/sys/unmount.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(unmount, 1) ret diff --git a/i386/sys/utimes.s b/i386/sys/utimes.s index e83b038..824926f 100644 --- a/i386/sys/utimes.s +++ b/i386/sys/utimes.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(utimes, 2) ret diff --git a/i386/sys/vfork.s b/i386/sys/vfork.s index 1a4933a..b3e35ab 100644 --- a/i386/sys/vfork.s +++ b/i386/sys/vfork.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include #if defined(__DYNAMIC__) #define GET_CURRENT_PID PICIFY(__current_pid) diff --git a/i386/sys/wait4.s b/i386/sys/wait4.s index 5a11f3b..0d229b2 100644 --- a/i386/sys/wait4.s +++ b/i386/sys/wait4.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(wait4, 4) ret diff --git a/i386/sys/write.s b/i386/sys/write.s index 6fca232..a3a0959 100644 --- a/i386/sys/write.s +++ b/i386/sys/write.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(write, 3) ret diff --git a/i386/sys/writev.s b/i386/sys/writev.s index 538f68e..ff94496 100644 --- a/i386/sys/writev.s +++ b/i386/sys/writev.s @@ -23,7 +23,7 @@ /* * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ -#include "SYS.h" +#include UNIX_SYSCALL(writev, 3) ret diff --git a/include/libkern/OSAtomic.h b/include/libkern/OSAtomic.h index 83be1e3..1d42a8e 100644 --- a/include/libkern/OSAtomic.h +++ b/include/libkern/OSAtomic.h @@ -91,7 +91,7 @@ int32_t OSAtomicAnd32Barrier( uint32_t theMask, uint32_t *theValue ); int32_t OSAtomicXor32( uint32_t theMask, uint32_t *theValue ); int32_t OSAtomicXor32Barrier( uint32_t theMask, uint32_t *theValue ); -#if defined(__ppc64__) || defined(__i386__) +#if defined(__ppc64__) || defined(__i386__) || defined(__x86_64__) int64_t OSAtomicAdd64( int64_t theAmount, int64_t *theValue ); int64_t OSAtomicAdd64Barrier( int64_t theAmount, int64_t *theValue ); @@ -110,7 +110,7 @@ inline static int64_t OSAtomicDecrement64Barrier( int64_t *theValue ) { return OSAtomicAdd64Barrier( -1, theValue); } -#endif /* defined(__ppc64__) || defined(__i386__) */ +#endif /* defined(__ppc64__) || defined(__i386__) || defined(__x86_64__) */ /* Compare and swap. They return true if the swap occured. @@ -118,12 +118,12 @@ int64_t OSAtomicDecrement64Barrier( int64_t *theValue ) bool OSAtomicCompareAndSwap32( int32_t oldValue, int32_t newValue, int32_t *theValue ); bool OSAtomicCompareAndSwap32Barrier( int32_t oldValue, int32_t newValue, int32_t *theValue ); -#if defined(__ppc64__) || defined(__i386__) +#if defined(__ppc64__) || defined(__i386__) || defined(__x86_64__) bool OSAtomicCompareAndSwap64( int64_t oldValue, int64_t newValue, int64_t *theValue ); bool OSAtomicCompareAndSwap64Barrier( int64_t oldValue, int64_t newValue, int64_t *theValue ); -#endif /* defined(__ppc64__) || defined(__i386__) */ +#endif /* defined(__ppc64__) || defined(__i386__) || defined(__x86_64__) */ /* Test and set. They return the original value of the bit, and operate on bit (0x80>>(n&7)) diff --git a/include/machine/limits.h b/include/machine/limits.h index a669a74..0f40842 100644 --- a/include/machine/limits.h +++ b/include/machine/limits.h @@ -4,7 +4,7 @@ This file is public domain. */ #if defined (__ppc__) || defined (__ppc64__) #include -#elif defined (__i386__) +#elif defined (__i386__) || defined(__x86_64__) #include #else #error architecture not supported diff --git a/locale/Makefile.inc b/locale/Makefile.inc index fa29da5..82d344b 100644 --- a/locale/Makefile.inc +++ b/locale/Makefile.inc @@ -44,10 +44,15 @@ CFLAGS-lconv.c += -D__APPLE_PR_3333969_HACK__ # End hack for 3333969 -# for ppc64, we need to create rune32.h -.if (${MACHINE_ARCH} == ppc64) -# the following is good enough for ppc, ppc64 and i386 -ARCH32 != arch | sed 's/64//' +# for LP64, we need to create rune32.h +.ifdef LP64 +# the following is good enough for ppc, ppc64, i386 and x86_64 +_ARCH != arch +.if $(_ARCH) == x86_64 +ARCH32 = i386 +.else +ARCH32 = $(_ARCH:C/64$//) +.endif rune.So rune.do rune.po rune.o: ${SYMROOT}/rune32.h ${SYMROOT}/rune32.h: ${SYMROOT}/rune-fbsd.c ${CC} -arch ${ARCH32} -DRUNEOFF32 -o ${SYMROOT}/rune32 ${.ALLSRC} diff --git a/mach/headers/task.h b/mach/headers/task.h index ba1fd71..84799c2 100644 --- a/mach/headers/task.h +++ b/mach/headers/task.h @@ -22,6 +22,8 @@ */ #if defined(__i386__) #include +#elif defined(__x86_64__) +#include #elif defined(__ppc__) #include #elif defined(__ppc64__) diff --git a/mach/headers/thread_act.h b/mach/headers/thread_act.h index da011bc..843b9d5 100644 --- a/mach/headers/thread_act.h +++ b/mach/headers/thread_act.h @@ -22,6 +22,8 @@ */ #if defined(__i386__) #include +#elif defined(__x86_64__) +#include #elif defined(__ppc__) #include #elif defined(__ppc64__) diff --git a/pthreads/Makefile.inc b/pthreads/Makefile.inc index 1b0ef2a..2c38fa9 100644 --- a/pthreads/Makefile.inc +++ b/pthreads/Makefile.inc @@ -5,7 +5,8 @@ .PATH: ${.CURDIR}/pthreads MISRCS += pthread_cond.c pthread_tsd.c pthread.c \ - pthread_mutex.c thread_setup.c lock.s stack.s pthread_rwlock.c + pthread_mutex.c thread_setup.c stack.s pthread_rwlock.c \ + lock.s PTHREADS_INSTHDRS += pthread.h pthread_impl.h sched.h PTHREADS_INSTHDRS := ${PTHREADS_INSTHDRS:S/^/${.CURDIR}\/pthreads\//} diff --git a/pthreads/lock.s b/pthreads/lock.s index 6ff476f..18c05b1 100644 --- a/pthreads/lock.s +++ b/pthreads/lock.s @@ -97,7 +97,7 @@ END(__spin_unlock) LEAF(__spin_lock_try, 0) movl $(_COMM_PAGE_SPINLOCK_TRY), %eax - jmpl %eax + jmpl *%eax ALIGN @@ -105,7 +105,7 @@ LEAF(__spin_lock_try, 0) LEAF(__spin_lock, 0) _spin_lock: movl $(_COMM_PAGE_SPINLOCK_LOCK), %eax - jmpl %eax + jmpl *%eax /* * void @@ -120,7 +120,49 @@ _spin_lock: LEAF(__spin_unlock, 0) _spin_unlock: movl $(_COMM_PAGE_SPINLOCK_UNLOCK), %eax - jmpl %eax + jmpl *%eax + +#elif defined(__x86_64__) + +#include + +/* + * void + * _spin_lock(p) + * int *p; + * + * Lock the lock pointed to by p. Spin (possibly forever) until the next + * lock is available. + */ + TEXT + ALIGN + +LEAF(__spin_lock_try, 0) + movq $(_COMM_PAGE_SPINLOCK_TRY), %rax + jmp *%rax + + ALIGN + +.globl _spin_lock +LEAF(__spin_lock, 0) +_spin_lock: + movq $(_COMM_PAGE_SPINLOCK_LOCK), %rax + jmp *%rax + +/* + * void + * _spin_unlock(p) + * int *p; + * + * Unlock the lock pointed to by p. + */ + ALIGN + +.globl _spin_unlock +LEAF(__spin_unlock, 0) +_spin_unlock: + movl $0, (%rdi) + ret #else #error spin_locks not defined for this architecture diff --git a/pthreads/pthread.c b/pthreads/pthread.c index b2cc915..cc79c42 100644 --- a/pthreads/pthread.c +++ b/pthreads/pthread.c @@ -156,7 +156,7 @@ size_t _pthread_stack_size = 0; #if defined(__ppc__) || defined(__ppc64__) static const vm_address_t PTHREAD_STACK_HINT = 0xF0000000; -#elif defined(__i386__) +#elif defined(__i386__) || defined(__x86_64__) static const vm_address_t PTHREAD_STACK_HINT = 0xB0000000; #else #error Need to define a stack address hint for this architecture diff --git a/pthreads/pthread_internals.h b/pthreads/pthread_internals.h index b1a947e..795f38e 100644 --- a/pthreads/pthread_internals.h +++ b/pthreads/pthread_internals.h @@ -246,7 +246,7 @@ typedef struct { #include "pthread.h" -#if defined(__i386__) || defined(__ppc64__) +#if defined(__i386__) || defined(__ppc64__) || defined(__x86_64__) /* * Inside libSystem, we can use r13 or %gs directly to get access to the * thread-specific data area. The current thread is in the first slot. @@ -255,8 +255,8 @@ inline static pthread_t __attribute__((__pure__)) _pthread_self_direct(void) { pthread_t ret; -#if defined(__i386__) - asm("movl %%gs:%P1, %0" : "=r" (ret) : "i" (offsetof(struct _pthread, tsd[0]))); +#if defined(__i386__) || defined(__x86_64__) + asm("mov %%gs:%P1, %0" : "=r" (ret) : "i" (offsetof(struct _pthread, tsd[0]))); #elif defined(__ppc64__) register const pthread_t __pthread_self asm ("r13"); ret = __pthread_self; diff --git a/pthreads/stack.s b/pthreads/stack.s index 9ede930..5be1689 100644 --- a/pthreads/stack.s +++ b/pthreads/stack.s @@ -85,6 +85,25 @@ LEAF(__adjust_sp,0) subl $0x100,%eax ret +#elif defined(__x86_64__) + +#import +/* + * void *_sp(void) + */ + +LEAF(__sp,0) + movq %rsp,%rax + ret + +/* + * void *_adjust_sp(void *sp) + */ +LEAF(__adjust_sp,0) + movq %rdi,%rax + subq $0x100,%rax + ret + #else #error sp functions not defined for this architecture #endif diff --git a/pthreads/thread_setup.c b/pthreads/thread_setup.c index 5d0bfb9..dab0750 100644 --- a/pthreads/thread_setup.c +++ b/pthreads/thread_setup.c @@ -156,6 +156,53 @@ _pthread_setup(pthread_t thread, r); } +#elif defined(__x86_64__) + x86_thread_state64_t state = {0}; + x86_thread_state64_t *ts = &state; + uintptr_t *sp = vsp; + + /* + * Set up x86-64 registers & function call. + */ + count = x86_THREAD_STATE64_COUNT; + if (suspended) { + PTHREAD_MACH_CALL(thread_get_state(thread->kernel_thread, + x86_THREAD_STATE64, + (thread_state_t) &state, + &count), + r); + } + ts->rip = (uintptr_t) routine; + + /* + ** We need to simulate a 16-byte aligned stack frame as if we had + ** executed a call instruction. The stack should already be aligned + ** before it comes to us and we don't need to push any arguments, + ** so we shouldn't need to change it. + */ + + ts->rdi = (uintptr_t) thread; /* argument to function */ + *--sp = 0; /* fake return address */ + ts->rsp = (uintptr_t) sp; /* set stack pointer */ + /* Incase of needresume, suspend is always set */ + if (suspended) { + PTHREAD_MACH_CALL(thread_set_state(thread->kernel_thread, + x86_THREAD_STATE64, + (thread_state_t) &state, + x86_THREAD_STATE64_COUNT), + r); + if (needresume) + PTHREAD_MACH_CALL(thread_resume(thread->kernel_thread), + r); + } else { + PTHREAD_MACH_CALL(thread_create_running(mach_task_self(), + x86_THREAD_STATE64, + (thread_state_t) ts, + x86_THREAD_STATE64_COUNT, + &thread->kernel_thread), + r); + } + #else #error _pthread_setup not defined for this architecture #endif diff --git a/sys/fcntl64.c b/sys/fcntl64.c index c59c5c5..e791a63 100644 --- a/sys/fcntl64.c +++ b/sys/fcntl64.c @@ -40,10 +40,13 @@ fcntl(int fd, int cmd, ...) case F_SETLK: case F_SETLKW: case F_PREALLOCATE: + case F_SETSIZE: case F_RDADVISE: case F_READBOOTSTRAP: case F_WRITEBOOTSTRAP: case F_LOG2PHYS: + case F_GETPATH: + case F_PATHPKG_CHECK: arg = va_arg(ap, void *); break; default: diff --git a/sys/sigtramp.c b/sys/sigtramp.c index e960491..da72b83 100644 --- a/sys/sigtramp.c +++ b/sys/sigtramp.c @@ -173,7 +173,7 @@ _sigtramp( #if defined(__DYNAMIC__) __in_sigtramp++; #endif -#ifdef __i386__ +#if defined(__i386__) || defined(__x86_64__) if (sigstyle == UC_TRAD) sa_handler(sig); else { diff --git a/x86_64/gen/Makefile.inc b/x86_64/gen/Makefile.inc new file mode 100644 index 0000000..698fd5c --- /dev/null +++ b/x86_64/gen/Makefile.inc @@ -0,0 +1,6 @@ +# searching i386 directory as a fallback to avoid unnecessary code duplication +.PATH: ${.CURDIR}/x86_64/gen ${.CURDIR}/i386/gen + +MDSRCS+= icacheinval.s \ + mcount.s \ + setjmperr.c diff --git a/x86_64/gen/mcount.s b/x86_64/gen/mcount.s new file mode 100644 index 0000000..2311cbb --- /dev/null +++ b/x86_64/gen/mcount.s @@ -0,0 +1,52 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +#import + +.text + .globl mcount +mcount: + pushq %rbp // setup mcount's frame + movq %rsp,%rbp + + // The compiler doesn't preserve registers when calling mcount + // so we have to ensure that we don't trash any. + subq $8, %rsp // maintain 16-byte alignment + pushq %rdi + pushq %rsi + pushq %rax + + movq (%rbp),%rax // load the frame pointer of mcount's caller + movq 8(%rax),%rax // load mcount's caller's return address + movq 8(%rbp),%rdi // set up the selfpc parameter for moncount() + movq %rax,%rsi // set up the frompc parameter for moncount() + CALL_EXTERN(_moncount) // call moncount() + + popq %rax + popq %rsi + popq %rdi + // No need for an addq because we're restoring %rsp in the + // next instruction. + + movq %rbp,%rsp // tear down mcount's frame + popq %rbp + ret diff --git a/x86_64/mach/Makefile.inc b/x86_64/mach/Makefile.inc new file mode 100644 index 0000000..980ba6b --- /dev/null +++ b/x86_64/mach/Makefile.inc @@ -0,0 +1,3 @@ +# searching i386 directory as a fallback to avoid unnecessary code duplication +.PATH: ${.CURDIR}/i386/mach +MDSRCS += mach_absolute_time.c diff --git a/x86_64/pthreads/Makefile.inc b/x86_64/pthreads/Makefile.inc new file mode 100644 index 0000000..cfe58fd --- /dev/null +++ b/x86_64/pthreads/Makefile.inc @@ -0,0 +1,9 @@ +# searching i386 directory as a fallback to avoid unnecessary code duplication +.PATH: ${.CURDIR}/x86_64/pthreads ${.CURDIR}/i386/pthreads + +MDSRCS += \ + init_cpu_capabilities.c \ + get_cpu_capabilities.s \ + pthread_set_self.s \ + pthread_self.s \ + pthread_getspecific.s diff --git a/x86_64/pthreads/get_cpu_capabilities.s b/x86_64/pthreads/get_cpu_capabilities.s new file mode 100644 index 0000000..15f37ff --- /dev/null +++ b/x86_64/pthreads/get_cpu_capabilities.s @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* Get the cpu_capabilities bit vector out of the comm page */ + +#define __APPLE_API_PRIVATE +#include +#undef __APPLE_API_PRIVATE + +.text +.align 2, 0x90 +.private_extern __get_cpu_capabilities +__get_cpu_capabilities: + movq $(_COMM_PAGE_CPU_CAPABILITIES), %rax + movl (%rax), %eax + ret diff --git a/x86_64/pthreads/pthread_getspecific.s b/x86_64/pthreads/pthread_getspecific.s new file mode 100644 index 0000000..67c00f3 --- /dev/null +++ b/x86_64/pthreads/pthread_getspecific.s @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include "pthread_machdep.h" + +.text +.align 2, 0x90 +.globl _pthread_getspecific +_pthread_getspecific: + movq %gs:_PTHREAD_TSD_OFFSET(,%rdi,8),%rax + ret diff --git a/x86_64/pthreads/pthread_self.s b/x86_64/pthreads/pthread_self.s new file mode 100644 index 0000000..c040841 --- /dev/null +++ b/x86_64/pthreads/pthread_self.s @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include "pthread_machdep.h" + +.text +.align 2, 0x90 +.globl _pthread_self +_pthread_self: + movq %gs:_PTHREAD_TSD_OFFSET,%rax + ret diff --git a/x86_64/pthreads/pthread_set_self.s b/x86_64/pthreads/pthread_set_self.s new file mode 100644 index 0000000..999c0bf --- /dev/null +++ b/x86_64/pthreads/pthread_set_self.s @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include + +.text +.align 2, 0x90 +.globl ___pthread_set_self +___pthread_set_self: + movl $0, %esi // 0 as the second argument + movl $ SYSCALL_CONSTRUCT_MDEP(3), %eax // Machine-dependent syscall number 3 + MACHDEP_SYSCALL_TRAP + ret diff --git a/x86_64/stdlib/gdtoa.mk b/x86_64/stdlib/gdtoa.mk new file mode 100644 index 0000000..6a6a67d --- /dev/null +++ b/x86_64/stdlib/gdtoa.mk @@ -0,0 +1,2 @@ +# Long double is 80 bits +FBSDSRCS+=gdtoa_strtopx.c machdep_ldisx.c diff --git a/x86_64/string/Makefile.inc b/x86_64/string/Makefile.inc new file mode 100644 index 0000000..80c0b9d --- /dev/null +++ b/x86_64/string/Makefile.inc @@ -0,0 +1,20 @@ +# $Version$ +# +# x86-64-optimised string functions. +# +# +# +.PATH: ${.CURDIR}/x86_64/string + +MDSRCS += bcopy.s \ + bzero.s \ + memcpy.s \ + memmove.s \ + strlen.s \ + strcpy.s \ + strcmp.s \ + strncpy.s \ + strncmp.s \ + memcmp.s \ + bcmp.s \ + memset.s diff --git a/x86_64/string/bcmp.s b/x86_64/string/bcmp.s new file mode 100644 index 0000000..8f2cd80 --- /dev/null +++ b/x86_64/string/bcmp.s @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * bcmp() is implemented in memcmp.s, as it is equivalent to memcmp() in OSX. + * (The two symbols, bcmp and memcmp, have the same value.) + * This empty file is here to prevent the Free BSD machine independent version + * from building. + */ diff --git a/x86_64/string/bcopy.s b/x86_64/string/bcopy.s new file mode 100644 index 0000000..d06652d --- /dev/null +++ b/x86_64/string/bcopy.s @@ -0,0 +1,48 @@ +/* + * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Call the comm page routines + */ + +#define __APPLE_API_PRIVATE +#include + +#include + + TEXT + ALIGN + +#if defined(MEMCOPY) +LEAF(_memcpy,0) + movq $(_COMM_PAGE_MEMCPY), %rax + jmp *%rax +#elif defined(MEMMOVE) +LEAF(_memmove,0) + movq $(_COMM_PAGE_MEMMOVE), %rax + jmp *%rax +#else +LEAF(_bcopy,0) + movq $(_COMM_PAGE_BCOPY), %rax + jmp *%rax +#endif diff --git a/x86_64/string/bzero.s b/x86_64/string/bzero.s new file mode 100644 index 0000000..ef27202 --- /dev/null +++ b/x86_64/string/bzero.s @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Call the comm page routine + */ + +#define __APPLE_API_PRIVATE +#include + +#include + + TEXT + ALIGN + +LEAF(_bzero,0) + movq $(_COMM_PAGE_BZERO), %rax + jmp *%rax diff --git a/x86_64/string/memcmp.s b/x86_64/string/memcmp.s new file mode 100644 index 0000000..640ffb6 --- /dev/null +++ b/x86_64/string/memcmp.s @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + + +// *************** *********** +// * M E M C M P * and * B C M P * +// *************** *********** +// +// int memcmp(const char *s1, const char *s2, size_t len); +// int bcmp(const char *s1, const char *s2, size_t len); +// +// Bcmp returns (+,0,-), whereas memcmp returns the true difference +// between the first differing bytes, but we treat them identically. +// +// We optimize the compare by doing it with SSE. This introduces +// a complication: if we blindly did vector loads from both sides until +// finding a difference, we might get a spurious page fault by +// reading bytes past the difference. To avoid this, we never do a load +// that crosses a page boundary. + +#define kShort 18 // too short for vectors (must be >16) + + .text + .align 4 + + .globl _memcmp + .globl _bcmp + +_memcmp: // int memcmp(const char *s1,const char *s2,size_t len); +_bcmp: // int bcmp(const char *s1,const char *s2,size_t len); + cmpq $(kShort),%rdx // worth accelerating? + ja LNotShort // yes + + +// Too short to bother with parallel compares. Loop over bytes. +// %rdi = LHS ptr +// %rsi = RHS ptr +// %edx = length (<= kShort) + +LShort: + testl %edx,%edx // 0-length? + jnz LShortLoop // no + xorq %rax,%rax // return 0 + jmp LExit + .align 4,0x90 // align inner loops to optimize I-fetch +LShortLoop: // loop over bytes + movzb (%rdi),%eax // get LHS byte + movzb (%rsi),%ecx // get RHS byte + addq $1,%rdi + addq $1,%rsi + subl %ecx,%eax // compare them + jnz LExit // done if not equal + subq $1,%rdx // decrement length + jnz LShortLoop +LExit: // return value is in %eax + ret + +LNotEqual: // here from LLoopOverBytes with LHS in eax + movzb (%rsi),%ecx // get RHS byte + subl %ecx,%eax // generate return value (nonzero) + ret + + +// Loop over bytes until we reach end of a page. +// %rdi = LHS ptr +// %edi = RHS ptr +// %rdx = length remaining after end of loop (i.e., already adjusted) +// %ecx = #bytes until next page (1..15) + + .align 4,0x90 // align inner loops to optimize I-fetch +LLoopOverBytes: + movzb (%rdi),%eax // get LHS byte + addq $1,%rdi + cmpb (%rsi),%al // compare to RHS byte + jnz LNotEqual // done if not equal + addq $1,%rsi + subl $1,%ecx // more to go? + jnz LLoopOverBytes + + +// Long enough to justify overhead of setting up vector compares. In order to +// avoid spurious page faults, we loop over: +// +// min( length, bytes_in_LHS_page, bytes_in_RHS_page) >> 4 +// +// 16-byte chunks. When we near a page end, we have to revert to a byte-by-byte +// comparison until reaching the next page, then resume the vector comparison. +// %rdi = LHS ptr +// %rsi = RHS ptr +// %rdx = length (> kShort) + +LNotShort: + movq %rdi,%rax // copy ptrs + movq %rsi,%rcx + andq $4095,%rax // mask down to page offsets + andq $4095,%rcx + cmpq %rax,%rcx // which is bigger? + cmova %rcx,%rax // %eax = max(LHS offset, RHS offset); + movl $4096,%ecx + subl %eax,%ecx // get #bytes to next page crossing + cmpl %edx,%ecx // will operand run out first? + cmova %edx,%ecx // get min(length remaining, bytes to page end) + movl %ecx,%eax + shrl $4,%ecx // get #chunks till end of operand or page + jnz LLoopOverChunks // enter vector loop + +// Too near page end for vectors. + + subq %rax,%rdx // adjust length remaining + movl %eax,%ecx // %ecx <- #bytes to page end + cmpq $(kShort),%rdx // will there be enough after we cross page for vectors? + ja LLoopOverBytes // yes + addq %rax,%rdx // no, restore total length remaining + jmp LShortLoop // compare rest byte-by-byte (%ecx != 0) + + +// Loop over 16-byte chunks. +// %rdi = LHS ptr +// %rsi = RHS ptr +// %rdx = length remaining +// %ecx = chunk count + + .align 4,0x90 // align inner loops to optimize I-fetch +LLoopOverChunks: + movdqu (%rdi),%xmm0 // get LHS + movdqu (%rsi),%xmm1 // get RHS + addq $16,%rdi + pcmpeqb %xmm1,%xmm0 // compare LHS to RHS + addq $16,%rsi + pmovmskb %xmm0,%eax // collect comparison result bits (1 if equal) + subq $16,%rdx // adjust length remaining + xorl $0xFFFF,%eax // all equal? + jne LDifferent // no, we found differing bytes + subl $1,%ecx // more to go? + jnz LLoopOverChunks + + cmpq $(kShort),%rdx // a lot more to compare? + jbe LShort // no + jmp LNotShort // compute distance to next page crossing etc + + +// Found a difference. +// %rdi = LHS ptr, already advanced by 16 +// %rsi = RHS ptr, already advanced by 16 +// %eax = complemented compare vector (ie, 0 == equal) + +LDifferent: + bsf %eax,%edx // which byte differed? + subq $16,%rdi // point to byte 0 while we wait for bit scan + subq $16,%rsi + movzb (%rdi,%rdx),%eax // get LHS byte + movzb (%rsi,%rdx),%ecx // get RHS byte + subl %ecx,%eax // compute difference (ie, return value) + ret diff --git a/x86_64/string/memcpy.s b/x86_64/string/memcpy.s new file mode 100644 index 0000000..8160b02 --- /dev/null +++ b/x86_64/string/memcpy.s @@ -0,0 +1,33 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + * + * File: libc/i386/ansi/memcpy.c + * Author: Bruce Martin, NeXT Computer, Inc. + * + * HISTORY + * 24-Nov-92 Derek B Clegg (dclegg@next.com) + * Created for m98k. + */ +#define MEMCOPY +#include "bcopy.s" diff --git a/x86_64/string/memmove.s b/x86_64/string/memmove.s new file mode 100644 index 0000000..50fd4e2 --- /dev/null +++ b/x86_64/string/memmove.s @@ -0,0 +1,33 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. + * + * File: libc/i386/ansi/memmove.c + * Author: Bruce Martin, NeXT Computer, Inc. + * + * HISTORY + * 24-Nov-92 Derek B Clegg (dclegg@next.com) + * Created for m98k. + */ +#define MEMMOVE +#include "bcopy.s" diff --git a/x86_64/string/memset.s b/x86_64/string/memset.s new file mode 100644 index 0000000..423db2f --- /dev/null +++ b/x86_64/string/memset.s @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include + + +/* This file contains the following functions: + * + * void *memset(void *b, int c, size_t len); + * void memset_pattern4(void *b, const void *c4, size_t len); + * void memset_pattern8(void *b, const void *c8, size_t len); + * void memset_pattern16(void *b, const void *c16, size_t len); + * + * Calls of memset() with c==0 are routed to the bzero() routine. Most of the + * others go to _COMM_PAGE_MEMSET_PATTERN, which is entered as follows: + * %rdi = ptr to memory to set (aligned) + * %edx = length (which can be short, though we bias in favor of long operands) + * %xmm0 = the pattern to store + * Return conditions: + * %eax, %edi, %esi, %ecx, and %edx all trashed + * + * NB: we avoid "stos" family of instructions (stosl, stosb), as they are very slow + * on P4s and probably other processors. + */ + + #define kShort 255 // for nonzero memset(), too short for commpage + + + .text + .globl _memset + .align 2 +_memset: // void *memset(void *b, int c, size_t len); + andl $0xFF,%esi // (c==0) ? + jnz LNonzero // not a bzero + + movq $(_COMM_PAGE_BZERO),%rax// map memset(p,0,n) into bzero(p,n) + movq %rdx,%rsi // put count where bzero() expects it + jmp *%rax // enter commpage + + + // Handle memset of a nonzero value. + +LNonzero: + movq %rdi,%r8 // preserve the original pointer so we can return it + movl %esi,%eax // replicate byte in %esi into all four bytes + shll $8,%esi + orl %esi,%eax + movl %eax,%esi + shll $16,%esi + orl %esi,%eax // now %eax has "c" in all 4 bytes + cmpq $(kShort),%rdx // is operand too short for SSE? + ja LCallCommpage // no + +// Nonzero memset() too short to call commpage. +// %eax = replicated 4-byte pattern +// %rdi = ptr +// %edx = length (<= kShort) + + cmpl $16,%edx // long enough to word align? + jge 3f // yes + test %edx,%edx // length==0? + jz 6f +1: + movb %al,(%rdi) // pack in a byte + addq $1,%rdi + subl $1,%edx + jnz 1b + jmp 6f +2: + movb %al,(%rdi) // pack in a byte + addq $1,%rdi + subl $1,%edx +3: + test $3,%edi // is ptr doubleword aligned? + jnz 2b // no + movl %edx,%ecx // copy length + shrl $2,%edx // #doublewords to store +4: + movl %eax,(%rdi) // store aligned doubleword + addq $4,%rdi + subl $1,%edx + jnz 4b + andl $3,%ecx // any leftover bytes? + jz 6f // no +5: + movb %al,(%rdi) // pack in a byte + addq $1,%rdi + subl $1,%ecx + jnz 5b +6: + movq %r8,%rax // get return value (ie, original ptr) + ret + +// Nonzero memset() is long enough to call commpage. +// %eax = replicated 4-byte pattern +// %rdi = ptr +// %rdx = length (> kShort) + +LCallCommpage: + movd %eax,%xmm0 // move %eax to low 4 bytes of %xmm0 + pshufd $(0x00),%xmm0,%xmm0 // replicate across the vector + movq %rdi,%rcx // copy dest ptr + negl %ecx + andl $15,%ecx // get #bytes to align ptr + jz 2f // skip if already aligned + subq %rcx,%rdx // decrement length +1: + movb %al,(%rdi) // pack in a byte + addq $1,%rdi + subl $1,%ecx + jnz 1b +2: // ptr aligned, length long enough to justify + movq $(_COMM_PAGE_MEMSET_PATTERN),%rax + call *%rax // call commpage to do the heavy lifting + movq %r8,%rax // get return value (ie, original ptr) + ret + + +// Handle memset of a 16-byte pattern. + + .globl _memset_pattern16 + .align 2, 0x90 +_memset_pattern16: // void memset_pattern16(void *b, const void *c16, size_t len); + movdqu (%rsi),%xmm0 // load the pattern + jmp LAlignPtr + + +// Handle memset of an 8-byte pattern. + + .globl _memset_pattern8 + .align 2, 0x90 +_memset_pattern8: // void memset_pattern8(void *b, const void *c8, size_t len); + movq (%rsi),%xmm0 // load pattern into low 8 bytes + punpcklqdq %xmm0,%xmm0 // replicate into all 16 + jmp LAlignPtr + +// Handle memset of a 4-byte pattern. + + .globl _memset_pattern4 + .align 2, 0x90 +_memset_pattern4: // void memset_pattern4(void *b, const void *c4, size_t len); + movd (%rsi),%xmm0 // load pattern into low 4 bytes + pshufd $(0x00),%xmm0,%xmm0 // replicate the 4 bytes across the vector + + +// Align ptr if necessary. We must rotate the pattern right for each byte we +// store while aligning the ptr. Since there is no rotate instruction in SSE3, +// we have to synthesize the rotates. +// %rdi = ptr +// %rdx = length +// %xmm0 = pattern + +LAlignPtr: // NB: can drop down to here! + cmpq $100,%rdx // long enough to bother aligning ptr? + movq %rdi,%rcx // copy ptr + jb LReady // not long enough + negl %ecx + andl $15,%ecx // get #bytes to align ptr + jz LReady // already aligned + subq %rcx,%rdx // adjust length + + test $1,%cl // 1-byte store required? + movd %xmm0,%eax // get 4 low bytes in %eax + jz 2f // no + movdqa %xmm0,%xmm1 // copy pattern so we can shift in both directions + movb %al,(%rdi) // pack in the low-order byte + psrldq $1,%xmm0 // shift pattern right 1 byte + addq $1,%rdi + pslldq $15,%xmm1 // shift pattern left 15 bytes + shrl $8,%eax // in case 2-byte store is required + por %xmm1,%xmm0 // complete right rotate of pattern by 1 byte +2: + test $2,%cl // 2-byte store required? + jz 4f // no + psrldq $2,%xmm0 // shift pattern down 2 bytes + movw %ax,(%rdi) // pack in next two bytes + pinsrw $7,%eax,%xmm0 // insert low word of %eax into high word of %xmm0 + addq $2,%rdi // adjust ptr +4: + test $4,%cl // 4-byte store required? + jz 8f // no + movd %xmm0,(%rdi) // store low 4 bytes of %xmm0 + pshufd $(0x39),%xmm0,%xmm0 // rotate %xmm0 right 4 bytes (mask == 00 11 10 01) + addq $4,%rdi // adjust ptr +8: + test $8,%cl // 8-byte store required? + jz LReady // no + movq %xmm0,(%rdi) // store low 8 bytes of %xmm0 + pshufd $(0x4e),%xmm0,%xmm0 // rotate %xmm0 right 8 bytes (mask == 01 00 11 10) + addq $8,%rdi // adjust ptr + +// Ptr is aligned if practical, we're ready to call commpage to do the heavy lifting. + +LReady: + movq $(_COMM_PAGE_MEMSET_PATTERN),%rax + call *%rax // call commpage to do the heavy lifting + ret diff --git a/x86_64/string/strcmp.s b/x86_64/string/strcmp.s new file mode 100644 index 0000000..6a069c0 --- /dev/null +++ b/x86_64/string/strcmp.s @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + + +// *************** +// * S T R C M P * +// *************** +// +// int strcmp(const char *s1, const char *s2); +// +// We optimize the compare by doing it in parallel, using SSE. This introduces +// a complication: if we blindly did vector loads from both sides until +// finding a difference (or 0), we might get a spurious page fault by +// reading bytes past the difference. To avoid this, we never do a load +// that crosses a page boundary. + + .text + .globl _strcmp + + .align 4 +_strcmp: // int strcmp(const char *s1,const char *s2); + +// In order to avoid spurious page faults, we loop over: +// +// min( bytes_in_LHS_page, bytes_in_RHS_page) >> 4 +// +// 16-byte chunks. When we near a page end, we have to revert to a byte-by-byte +// comparison until reaching the next page, then resume the vector comparison. +// %rdi = LHS ptr +// %rsi = RHS ptr + +LNextChunk: + movl %edi,%eax // copy low 4 bytes of each ptr + movl %esi,%edx + andl $4095,%eax // mask down to page offsets + andl $4095,%edx + cmpl %eax,%edx // which is bigger? + cmova %edx,%eax // %eax = max(LHS offset, RHS offset); + movl $4096,%edx + subl %eax,%edx // get #bytes to next page crossing + movl %edx,%eax + shrl $4,%edx // get #chunks till end of operand or page + jnz LLoopOverChunks // enter vector loop + movl %eax,%edx // no chunks... + jmp LLoopOverBytes // ...so loop over bytes until page end + + +// Loop over bytes. +// %rdi = LHS ptr +// %rsi = RHS ptr +// %edx = byte count + + .align 4,0x90 // align inner loops to optimize I-fetch +LLoopOverBytes: + movzb (%rdi),%eax // get LHS byte + movzb (%rsi),%ecx // get RHS byte + addq $1,%rdi + addq $1,%rsi + testl %eax,%eax // 0? + jz LExit0 // yes, we're done + subl %ecx,%eax // compare them + jnz LExit // done if not equal + subl $1,%edx // more to go? + jnz LLoopOverBytes + + jmp LNextChunk // we've come to end of page + + +// Loop over 16-byte chunks. +// %rdi = LHS ptr +// %rsi = RHS ptr +// %edx = chunk count + + .align 4,0x90 // align inner loops to optimize I-fetch +LLoopOverChunks: + movdqu (%rdi),%xmm1 // get LHS + movdqu (%rsi),%xmm2 // get RHS + pxor %xmm0,%xmm0 // get some 0s in the shadow of the loads + addq $16,%rdi + pcmpeqb %xmm1,%xmm2 // compare LHS to RHS + pcmpeqb %xmm1,%xmm0 // compare LHS to 0s + addq $16,%rsi + pmovmskb %xmm2,%eax // get result mask for comparison of LHS and RHS + pmovmskb %xmm0,%ecx // get result mask for 0 check + xorl $0xFFFF,%eax // complement compare mask so 1 means "not equal" + orl %ecx,%eax // combine the masks and check for 1-bits + jnz LFoundDiffOr0 // we found differing bytes or a 0-byte + subl $1,%edx // more to go? + jnz LLoopOverChunks + + jmp LNextChunk // compare up to next page boundary + + +// Found a zero and/or a difference in vector compare. +// %rdi = LHS ptr, already advanced by 16 +// %rsi = RHS ptr, already advanced by 16 +// %eax = bit n set if bytes n differed or were 0 + +LFoundDiffOr0: + bsf %eax,%edx // which byte differed or was 0? + subq $16,%rdi // point to start of vectors while we wait for bit scan + subq $16,%rsi + movzb (%rdi,%rdx),%eax // get LHS byte + movzb (%rsi,%rdx),%ecx // get RHS byte + subl %ecx,%eax // compute difference (ie, return value) + ret + + +// Found a zero and/or difference in byte loop. +// %eax = LHS byte +// %ecx = RHS byte + +LExit0: + subl %ecx,%eax // compute difference (ie, return value) +LExit: // here with difference already in %eax + ret diff --git a/x86_64/string/strcpy.s b/x86_64/string/strcpy.s new file mode 100644 index 0000000..d667b05 --- /dev/null +++ b/x86_64/string/strcpy.s @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + + +// *************** +// * S T R C P Y * +// *************** +// +// char *strcpy(const char *dst, const char *src); +// +// We optimize the move by doing it vector parallel. This introduces +// a complication: if we blindly did vector load/stores until finding +// a 0, we might get a spurious page fault by touching bytes past it. +// To avoid this, we never do a load that crosses a page boundary, +// and never store a byte we don't have to. +// +// We align the destination, because unaligned vector stores are slow. + + .text + .globl _strcpy + + .align 4 +_strcpy: // char *strcpy(const char *dst, const char *src); + movq %rdi,%rcx // preserve dest ptr so we can return it + movl %edi,%edx // copy low 4 bytes of dest ptr + negl %edx + andl $15,%edx // how many bytes to align dest ptr? + jnz LLoopOverBytes // not aligned, so go do so + + +// In order to avoid spurious page faults, we loop until nearing the source page +// end. Then we revert to a byte-by-byte loop for 16 bytes until the page is crossed, +// then resume the vector loop. +// %rsi = source ptr (unaligned) +// %rdi = dest ptr (aligned) + +LNextChunk: + movl %esi,%eax // copy low 4 bytes of source ptr + movl $4096,%edx + andl $4095,%eax // get offset into source page + subl %eax,%edx // get #bytes remaining in source page + shrl $4,%edx // get #chunks till end of page + jnz LLoopOverChunks // enter vector loop + movl $16,%edx // move 16 bytes to cross page but keep dest aligned + jmp LLoopOverBytes + + +// Loop over bytes. +// %rsi = source ptr +// %rdi = dest ptr +// %edx = byte count + + .align 4,0x90 // align inner loops to optimize I-fetch +LLoopOverBytes: + movzb (%rsi),%eax // get source byte + addq $1,%rsi + movb %al,(%rdi) // pack into dest + addq $1,%rdi + testl %eax,%eax // 0? + jz LDone // yes, we're done + subl $1,%edx // more to go? + jnz LLoopOverBytes + + jmp LNextChunk // we've come to end of page + + +// Loop over 16-byte chunks. +// %rsi = source ptr (unaligned) +// %rdi = dest ptr (aligned) +// %edx = chunk count + + .align 4,0x90 // align inner loops to optimize I-fetch +LLoopOverChunks: + movdqu (%rsi),%xmm1 // get source + pxor %xmm0,%xmm0 // get some 0s + addq $16,%rsi + pcmpeqb %xmm1,%xmm0 // compare source to 0s + pmovmskb %xmm0,%eax // get result mask for 0 check + testl %eax,%eax // any 0s? + jnz LFound0 // yes, exit loop + movdqa %xmm1,(%rdi) // no 0s so do aligned store into destination + addq $16,%rdi + subl $1,%edx // more to go? + jnz LLoopOverChunks + + movl $16,%edx // move 16 bytes + jmp LLoopOverBytes // cross page but keep dest aligned + + +// Found a zero in the vector. Figure out where it is, and store the bytes +// up to it. +// %rdi = dest ptr (aligned) +// %eax = result mask +// %xmm1 = source vector + +LFound0: + bsf %eax,%edx // find first 0 + addl $1,%edx // we need to store the 0 too + test $16,%dl // was 0 last byte? + jz 8f // no + movdqa %xmm1,(%rdi) // yes, store entire vector + jmp LDone +8: + test $8,%dl // 8-byte store required? + jz 4f // no + movq %xmm1,(%rdi) // pack in 8 low bytes + psrldq $8,%xmm1 // then shift vector down 8 bytes + addq $8,%rdi +4: + test $4,%dl // 4-byte store required? + jz 3f // no + movd %xmm1,(%rdi) // pack in 4 low bytes + psrldq $4,%xmm1 // then shift vector down 4 bytes + addq $4,%rdi +3: + andl $3,%edx // more to go? + jz LDone // no + movd %xmm1,%eax // move remainders out of vector into %eax +1: // loop on up to three bytes + movb %al,(%rdi) // pack in next byte + shrl $8,%eax // shift next byte into position + addq $1,%rdi + dec %edx + jnz 1b + +LDone: + movq %rcx,%rax // original dest ptr is return value + ret diff --git a/x86_64/string/strlen.s b/x86_64/string/strlen.s new file mode 100644 index 0000000..51def0c --- /dev/null +++ b/x86_64/string/strlen.s @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Strlen, for processors with SSE3. + * + * Note that all memory references must be aligned, in order to avoid spurious + * page faults. Thus we have to load the aligned 16-byte chunk containing the + * first byte of the operand, then mask out false 0s that may occur before the + * first byte. + * + * We favor the fall-through (ie, short operand) path. + */ + + .text + .globl _strlen + .align 4, 0x90 +_strlen: // size_t strlen(char *b); + pxor %xmm0,%xmm0 // zero %xmm0 + movq %rdi,%rcx // copy ptr + movq %rdi,%rdx // make another copy + andq $(-16),%rdi // 16-byte align ptr + orl $(-1),%eax + pcmpeqb (%rdi),%xmm0 // check whole qw for 0s + andl $15,%ecx // get #bytes in aligned dq before operand + shl %cl,%eax // create mask for the bytes of aligned dq in operand + pmovmskb %xmm0,%ecx // collect mask of 0-bytes + andl %eax,%ecx // mask out any 0s that occur before 1st byte + jz LEnterLoop // no 0-bytes (ie, 1-bits), so enter by-16 loop + +// We've found a 0-byte. +// %rdi = aligned address of 16-byte block containing the terminating 0-byte +// %ecx = compare bit vector + +LFoundIt: + bsf %ecx,%eax // find first 1-bit (ie, first 0-byte) + movq %rdx,%rcx // recover ptr to 1st byte in string + addq %rdi,%rax // get address of the 0-byte + subq %rcx,%rax // subtract address of 1st byte to get string length + ret + +// Loop over aligned 16-byte blocks: +// %rdi = address of previous block + +LEnterLoop: + pxor %xmm0,%xmm0 // get some 0-bytes + addq $16,%rdi // advance ptr +LLoop: + movdqa (%rdi),%xmm1 // get next chunk + addq $16,%rdi + pcmpeqb %xmm0,%xmm1 // check for 0s + pmovmskb %xmm1,%ecx // collect mask of 0-bytes + test %ecx,%ecx // any 0-bytes? + jz LLoop // no 0-bytes, so get next dq + + subq $16,%rdi // back up ptr + jmp LFoundIt diff --git a/x86_64/string/strncmp.s b/x86_64/string/strncmp.s new file mode 100644 index 0000000..8608e70 --- /dev/null +++ b/x86_64/string/strncmp.s @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2005-2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + + +// ***************** +// * S T R N C M P * +// ***************** +// +// int strncmp(const char *s1, const char *s2, size_t len); +// +// We optimize the compare by doing it vector parallel. This introduces +// a complication: if we blindly did vector loads from both sides until +// finding a difference (or 0), we might get a spurious page fault by +// reading bytes past the difference. To avoid this, we never do a load +// that crosses a page boundary. + +#define kShort 20 // too short for vectors (must be >16) + + .text + .globl _strncmp + + .align 4 +_strncmp: // int strncmp(const char *s1, const char *s2, size_t len); + cmpq $(kShort),%rdx // worth accelerating? + ja LNotShort // yes + + +// Too short to bother with parallel compares. Loop over bytes. +// %rdi = LHS ptr +// %rsi = RHS ptr +// %edx = length (<= kShort) + +LShort: + testl %edx,%edx // 0-length? + jnz LShortLoop // no + jmp LReturn0 // yes, return 0 + .align 4,0x90 // align inner loops to optimize I-fetch +LShortLoop: // loop over bytes + movzb (%rdi),%eax // get LHS byte + movzb (%rsi),%ecx // get RHS byte + incq %rdi + incq %rsi + testl %eax,%eax // LHS==0 ? + jz LNotEqual // yes, this terminates comparison + cmpl %ecx,%eax // compare them (sub won't fuse, but cmp will) + jnz LNotEqual // done if not equal + decl %edx // decrement length + jnz LShortLoop +LReturn0: + xorl %eax,%eax // all bytes equal, so return 0 + ret + +LNotEqual: // LHS in eax, RHS in ecx + subl %ecx,%eax // generate return value (nonzero) + ret + + +// Loop over bytes until we reach end of a page. +// %rdi = LHS ptr +// %rsi = RHS ptr +// %rdx = length remaining after end of loop (ie, already adjusted) +// %r8d = #bytes until next page (1..15) + + .align 4,0x90 // align inner loops to optimize I-fetch +LLoopOverBytes: + movzb (%rdi),%eax // get LHS byte + movzb (%rsi),%ecx // get RHS byte + incq %rdi + incq %rsi + testl %eax,%eax // LHS==0 ? + jz LNotEqual // yes, this terminates comparison + cmpl %ecx,%eax // compare them (sub won't fuse, but cmp will) + jnz LNotEqual // done if not equal + decl %r8d // more to go? + jnz LLoopOverBytes + + +// Long enough to justify overhead of setting up vector compares. In order to +// avoid spurious page faults, we loop over: +// +// min( length, bytes_in_LHS_page, bytes_in_RHS_page) >> 4 +// +// 16-byte chunks. When we near a page end, we have to revert to a byte-by-byte +// comparison until reaching the next page, then resume the vector comparison. +// %rdi = LHS ptr +// %rsi = RHS ptr +// %rdx = length (> kShort) + +LNotShort: + movl %edi,%eax // copy ptrs + movl %esi,%r8d + andl $4095,%eax // mask down to page offsets + andl $4095,%r8d + cmpl %eax,%r8d // which is bigger? + cmova %r8d,%eax // %eax = max(LHS offset, RHS offset); + movl $4096,%r8d + subl %eax,%r8d // get #bytes to next page crossing + cmpq %rdx,%r8 // will operand run out first? + cmova %rdx,%r8 // get min(length remaining, bytes to page end) + movl %r8d,%eax // copy #bytes + shrl $4,%r8d // get #chunks till end of operand or page + testl %r8d,%r8d // test %r8d for 0 without partial flag update stall + jnz LLoopOverChunks // enter vector loop + +// Too near page end for vectors. + + subq %rax,%rdx // adjust length remaining + movl %eax,%r8d // %r8d <- #bytes to page end + cmpq $(kShort),%rdx // will there be enough after we cross page for vectors? + ja LLoopOverBytes // yes + addq %rax,%rdx // no, restore total length remaining + jmp LShortLoop // compare rest byte-by-byte (%rdx != 0) + + +// Loop over 16-byte chunks. +// %rdi = LHS ptr +// %rsi = RHS ptr +// %rdx = length remaining +// %r8d = chunk count + + .align 4,0x90 // align inner loops to optimize I-fetch +LLoopOverChunks: + movdqu (%rdi),%xmm1 // get LHS + movdqu (%rsi),%xmm2 // get RHS + pxor %xmm0,%xmm0 // get some 0s in the shadow of the loads + addq $16,%rdi + pcmpeqb %xmm1,%xmm2 // compare LHS to RHS + pcmpeqb %xmm1,%xmm0 // compare LHS to 0s + addq $16,%rsi + pmovmskb %xmm2,%eax // get result mask for comparison of LHS and RHS + pmovmskb %xmm0,%ecx // get result mask for 0 check + subq $16,%rdx // decrement length remaining + xorl $0xFFFF,%eax // complement compare mask so 1 means "not equal" + orl %ecx,%eax // combine the masks and check for 1-bits + jnz LFoundDiffOr0 // we found differing bytes or a 0-byte + decl %r8d // more to go? + jnz LLoopOverChunks // yes + + cmpq $(kShort),%rdx // a lot more to compare? + jbe LShort // no + jmp LNotShort // compute distance to next page crossing etc + + +// Found a zero and/or a difference in vector compare. +// %rdi = LHS ptr, already advanced by 16 +// %rsi = RHS ptr, already advanced by 16 +// %eax = bit n set if bytes n differed or were 0 + +LFoundDiffOr0: + bsf %eax,%edx // which byte differed or was 0? + movzb -16(%rdi,%rdx),%eax // get LHS byte + movzb -16(%rsi,%rdx),%edx // get RHS byte + subl %edx,%eax // compute difference (ie, return value) + ret diff --git a/x86_64/string/strncpy.s b/x86_64/string/strncpy.s new file mode 100644 index 0000000..7159cf1 --- /dev/null +++ b/x86_64/string/strncpy.s @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include + + +// ***************** +// * S T R N C P Y * +// ***************** +// +// char *strncpy(const char *dst, const char *src, size_t n); +// +// We optimize the move by doing it vector parallel. This introduces +// a complication: if we blindly did vector load/stores until finding +// a 0, we might get a spurious page fault by touching bytes past it. +// To avoid this, we never do a load that crosses a page boundary, +// and never store a byte we don't have to. +// +// We align the destination, because unaligned vector stores are slow. +// +// Recall that strncpy() zero fills the remainder of the dest buffer, +// and does not terminate the string if its length is greater than or +// equal to n. + +#define kShort 31 // too short to bother with vector loop + + .text + .globl _strncpy + + .align 4 +_strncpy: // char *strncpy(const char *dst, const char *src, size_t n); + movq %rdi,%r8 // preserve destination pointer so we can return it + movl %edi,%ecx // copy low 4 bytes of dest ptr + negl %ecx + andl $15,%ecx // how many bytes to align dest ptr? + jnz LCheckShortCopy // align destination first + + +// In order to avoid spurious page faults, we loop until nearing the source page +// end. Then we revert to a byte-by-byte loop for 16 bytes until the page is crossed, +// then resume the vector loop. +// %rsi = source ptr (unaligned) +// %rdi = dest ptr (aligned) +// %rdx = buffer length remaining + +LNextChunk: // NB: can drop down to here + movl %esi,%eax // copy the low 4 bytes of the source ptr + movl $4096,%ecx + andl $4095,%eax // get offset into source page + subl %eax,%ecx // get #bytes remaining in source page + cmpq %rdx,%rcx // will buffer run out before the page end? + cmova %rdx,%rcx // get min(length remaining, bytes to page end) + shrl $4,%ecx // get #chunks till end of page + jnz LLoopOverChunks // enter vector loop + +// We can't use the chunk loop yet. Check for short and empty buffers, then use byte loop. + +LCrossPage: // if buffer is large enough, cross source page + movl $16,%ecx // move 16 bytes to cross page but keep dest aligned +LCheckShortCopy: // we propose to copy %ecx bytes in byte loop + cmpq $(kShort),%rdx // much left? + ja LLoopOverBytes // yes, loop over bytes then more chunks + movl %edx,%ecx // no, use the byte loop for everything + testl %edx,%edx // have we filled buffer? + jnz LLoopOverBytes // no + jmp LDone + + +// Loop over bytes. +// %rsi = source ptr +// %rdi = dest ptr +// %rdx = buffer length remaining +// %rcx = count of bytes to loop over (<= buffer length) + + .align 4,0x90 // align inner loops to optimize I-fetch +LLoopOverBytes: + movzb (%rsi),%eax // get source byte + addq $1,%rsi + subq $1,%rdx // decrement length + movb %al,(%rdi) // pack into dest + addq $1,%rdi + testl %eax,%eax // 0? + jz LZeroBuffer // yes, we're done copying string + subq $1,%rcx // more to go? + jnz LLoopOverBytes + + testq %rdx,%rdx // at end of buffer? + jnz LNextChunk // no, xfer chunks + jmp LDone // yes + + +// Loop over 16-byte chunks. +// %rsi = source ptr (unaligned) +// %rdi = dest ptr (aligned) +// %rdx = buffer length remaining +// %ecx = chunk count + + .align 4,0x90 // align inner loops to optimize I-fetch +LLoopOverChunks: + movdqu (%rsi),%xmm1 // get source + pxor %xmm0,%xmm0 // get some 0s + addq $16,%rsi + pcmpeqb %xmm1,%xmm0 // compare source to 0s + pmovmskb %xmm0,%eax // get result mask for 0 check + testl %eax,%eax // any 0s? + jnz LFound0 // yes, exit loop + movdqa %xmm1,(%rdi) // no 0s so do aligned store into destination + addq $16,%rdi + subq $16,%rdx // decrement length remaining + subl $1,%ecx // more to go? + jnz LLoopOverChunks + + jmp LCrossPage // cross page but keep dest aligned + + +// Found a zero in the vector. Figure out where it is, and store the bytes +// up to it. It is possible that we should check to be sure (%rdx >= 16), and +// just do an aligned store of %xmm1 if so. But if we did, we'd be doing byte +// stores into the same double quadword in bzero(), which might hit a hazard. +// Experimentation needed. +// %rdi = dest ptr (aligned) +// %eax = result mask +// %rdx = buffer length remaining +// %xmm1 = source vector + +LFound0: + bsf %eax,%ecx // find first 0 + subq %rcx,%rdx // decrement remaining buffer length + test $8,%cl // 8-byte store required? + jz 4f // no + movq %xmm1,(%rdi) // pack in 8 low bytes + psrldq $8,%xmm1 // then shift vector down 8 bytes + addq $8,%rdi +4: + test $4,%cl // 4-byte store required? + jz 3f // no + movd %xmm1,(%rdi) // pack in 4 low bytes + psrldq $4,%xmm1 // then shift vector down 4 bytes + addq $4,%rdi +3: + andl $3,%ecx // more to go? + jz LZeroBuffer // no + movd %xmm1,%eax // move remainders out of vector into %eax +1: // loop on up to three bytes + movb %al,(%rdi) // pack in next byte + shrl $8,%eax // shift next byte into position + addq $1,%rdi + subl $1,%ecx + jnz 1b + +// We've copied the string. Now zero the rest of the buffer, using commpage bzero(). +// %rdi = dest ptr +// %rcx = buffer length remaining + +LZeroBuffer: + movq %rdx,%rsi // remaining buffer size (2nd argument) + movq $(_COMM_PAGE_BZERO),%rax + call *%rax + +LDone: + movq %r8,%rax // original dest ptr is return value + ret diff --git a/x86_64/sys/Makefile.inc b/x86_64/sys/Makefile.inc new file mode 100644 index 0000000..792418f --- /dev/null +++ b/x86_64/sys/Makefile.inc @@ -0,0 +1,232 @@ +.PATH: ${.CURDIR}/x86_64/sys ${.CURDIR}/i386/sys + +AINC+= -I${.CURDIR}/x86_64/sys +MDSRCS+= ATPgetreq.s \ + ATPgetrsp.s \ + ATPsndreq.s \ + ATPsndrsp.s \ + ATgetmsg.s \ + ATputmsg.s \ + ATsocket.s \ + _exit.s \ + __fcntl.s \ + _getlogin.s \ + __ioctl.s \ + __mmap.s \ + _pthread_kill.s \ + __pthread_canceled.s \ + __pthread_markcancel.s \ + __semwait_signal.s \ + _setjmp.s \ + _setlogin.s \ + _sysctl.s \ + accept.s \ + access.s \ + acct.s \ + add_profil.s \ + adjtime.s \ + aio_cancel.s \ + aio_error.s \ + aio_fsync.s \ + aio_read.s \ + aio_return.s \ + aio_suspend.s \ + aio_write.s \ + audit.s \ + auditctl.s \ + auditon.s \ + bind.s \ + cerror.s \ + chdir.s \ + checkuseraccess.s \ + chflags.s \ + chmod.s \ + chown.s \ + commpage.c \ + chroot.s \ + close.s \ + connect.s \ + dup.s \ + dup2.s \ + exchangedata.s \ + execve.s \ + fchdir.s \ + fchflags.s \ + fchmod.s \ + fchown.s \ + fgetxattr.s \ + fhopen.s \ + flistxattr.s \ + flock.s \ + fork.s \ + fpathconf.s \ + fremovexattr.s \ + fsctl.s \ + fsetxattr.s \ + fstat.s \ + fstatfs.s \ + fstatv.s \ + fsync.s \ + ftruncate.s \ + futimes.s \ + getattrlist.s \ + getaudit.s \ + getaudit_addr.s \ + getauid.s \ + getdirentries.s \ + getdirentriesattr.s \ + getdtablesize.s \ + getegid.s \ + geteuid.s \ + getfh.s \ + getfsstat.s \ + getgid.s \ + getgroups.s \ + getitimer.s \ + getpeername.s \ + getpgid.s \ + getpgrp.s \ + getpid.s \ + getppid.s \ + getpriority.s \ + getrlimit.s \ + getrusage.s \ + getsid.s \ + getsockname.s \ + getsockopt.s \ + getuid.s \ + getxattr.s \ + i386_gettimeofday.s \ + i386_get_ldt.s \ + i386_set_ldt.s \ + issetugid.s \ + kevent.s \ + kill.s \ + kqueue.s \ + kqueue_from_portset_np.s \ + kqueue_portset_np.s \ + ktrace.s \ + lchown.s \ + link.s \ + lio_listio.s \ + listen.s \ + listxattr.s \ + load_shared_file.s \ + lseek.s \ + lstat.s \ + lstatv.s \ + madvise.s \ + mincore.s \ + minherit.s \ + mkcomplex.s \ + mkdir.s \ + mkfifo.s \ + mknod.s \ + mlock.s \ + mlockall.s \ + mount.s \ + msgget.s \ + msgrcv.s \ + msgsnd.s \ + msgsys.s \ + munlock.s \ + munlockall.s \ + new_system_shared_regions.s \ + nfsclnt.s \ + nfssvc.s \ + open.s \ + OSAtomic.s \ + pathconf.s \ + pipe.s \ + poll.s \ + posix_madvise.s \ + pread.s \ + profil.s \ + pthread_sigmask.s \ + ptrace.s \ + pwrite.s \ + quota.s \ + quotactl.s \ + read.s \ + readlink.s \ + readv.s \ + reboot.s \ + recvfrom.s \ + recvmsg.s \ + removexattr.s \ + rename.s \ + reset_shared_file.s \ + revoke.s \ + rmdir.s \ + searchfs.s \ + select.s \ + sem_close.s \ + sem_destroy.s \ + sem_getvalue.s \ + sem_init.s \ + sem_post.s \ + sem_trywait.s \ + sem_wait.s \ + semget.s \ + semop.s \ + semsys.s \ + sendmsg.s \ + sendto.s \ + setattrlist.s \ + setaudit.s \ + setaudit_addr.s \ + setauid.s \ + setegid.s \ + seteuid.s \ + setgid.s \ + setgroups.s \ + setitimer.s \ + setjmp.s \ + setpgid.s \ + setpriority.s \ + setprivexec.s \ + setquota.s \ + setrlimit.s \ + setsid.s \ + setsockopt.s \ + settimeofday.s \ + setuid.s \ + setxattr.s \ + shmat.s \ + shmdt.s \ + shmget.s \ + shmsys.s \ + shutdown.s \ + sigaltstack.s \ + sigpending.s \ + sigprocmask.s \ + sigreturn.s \ + sigwait.s \ + socket.s \ + socketpair.s \ + stat.s \ + statfs.s \ + statv.s \ + swapon.s \ + symlink.s \ + sync.s \ + syscall.s \ + systable.s \ + truncate.s \ + umask.s \ + undelete.s \ + unlink.s \ + unmount.s \ + utimes.s \ + vfork.s \ + wait4.s \ + write.s \ + writev.s + +MISRCS+= fcntl64.c ioctl64.c + +.for _src in fhopen.s getfh.s nfsclnt.s +CFLAGS-${_src} += -DNFSCLIENT +.endfor + +CFLAGS-nfssvc.s += -DNFSSERVER diff --git a/x86_64/sys/OSAtomic.s b/x86_64/sys/OSAtomic.s new file mode 100644 index 0000000..1d3f778 --- /dev/null +++ b/x86_64/sys/OSAtomic.s @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2004-2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include + +#define DECLARE(x) \ +.align 2, 0x90 ; \ +.globl x ; \ +.globl x ## Barrier ; \ +x: ; \ +x ## Barrier: + +.text + + +// uint32_t OSAtomicAnd32( uint32_t mask, uint32_t *value); +DECLARE(_OSAtomicAnd32) + movq $(_COMM_PAGE_COMPARE_AND_SWAP32), %rcx + movl %edi, %r11d // save mask + movl (%rsi), %eax // get value + movq %rsi, %rdx // put ptr where compare-and-swap expects it +1: + movl %r11d, %esi // original mask + movl %eax, %edi // old value + andl %eax, %esi // new value + call *%rcx // %edi=old value, %esi=new value. %rdx=ptr + jnz 1b + movl %esi, %eax + ret + + +// uint32_t OSAtomicOr32( uint32_t mask, uint32_t *value); +DECLARE(_OSAtomicOr32) + movq $(_COMM_PAGE_COMPARE_AND_SWAP32), %rcx + movl %edi, %r11d // save mask + movl (%rsi), %eax // get value + movq %rsi, %rdx // put ptr where compare-and-swap expects it +1: + movl %r11d, %esi // original mask + movl %eax, %edi // old value + orl %eax, %esi // new value + call *%rcx // %edi=old value, %esi=new value. %rdx=ptr + jnz 1b + movl %esi, %eax + ret + + +// uint32_t OSAtomicXor32( uint32_t mask, uint32_t *value); +DECLARE(_OSAtomicXor32) + movq $(_COMM_PAGE_COMPARE_AND_SWAP32), %rcx + movl %edi, %r11d // save mask + movl (%rsi), %eax // get value + movq %rsi, %rdx // put ptr where compare-and-swap expects it +1: + movl %r11d, %esi // original mask + movl %eax, %edi // old value + xorl %eax, %esi // new value + call *%rcx // %edi=old value, %esi=new value. %rdx=ptr + jnz 1b + movl %esi, %eax + ret + + +// bool OSAtomicCompareAndSwap32( int32_t old, int32_t new, int32_t *value); +DECLARE(_OSAtomicCompareAndSwap32) + movq $(_COMM_PAGE_COMPARE_AND_SWAP32), %rcx + call *%rcx // %edi=old value, %esi=new value. %rdx=ptr + sete %al + ret + + +// bool OSAtomicCompareAndSwap64( int64_t old, int64_t new, int64_t *value); +DECLARE(_OSAtomicCompareAndSwap64) + movq $(_COMM_PAGE_COMPARE_AND_SWAP64), %rcx + call *%rcx // %rdi=old value, %rsi=new value. %rdx=ptr + sete %al + ret + + +// int32_t OSAtomicAdd32( int32_t amt, int32_t *value ); +DECLARE(_OSAtomicAdd32) + movq $(_COMM_PAGE_ATOMIC_ADD32), %rcx + movl %edi, %eax // save amt to add + call *%rcx + addl %edi,%eax // new value + ret + + +// int64_t OSAtomicAdd64( int64_t amt, int64_t *value ); +DECLARE(_OSAtomicAdd64) + movq $(_COMM_PAGE_ATOMIC_ADD64), %rcx + movq %rdi, %rax // save amt to add + call *%rcx + addq %rdi, %rax // new value + ret + + +// bool OSAtomicTestAndSet( uint32_t n, void *value ); +DECLARE(_OSAtomicTestAndSet) + movq $(_COMM_PAGE_BTS), %rax + xorl $7, %edi // bit position is numbered big endian + call *%rax + setc %al + ret + + +// bool OSAtomicTestAndClear( uint32_t n, void *value ); +DECLARE(_OSAtomicTestAndClear) + movq $(_COMM_PAGE_BTC), %rax + xorl $7, %edi // bit position is numbered big endian + call *%rax + setc %al + ret + +// bool OSSpinLockTry( OSSpinLock *lock ); + .align 2, 0x90 + .globl _OSSpinLockTry +_OSSpinLockTry: + movq $(_COMM_PAGE_SPINLOCK_TRY), %rax + jmp *%rax + + +// void OSSpinLockLock( OSSpinLock *lock ); + .align 2, 0x90 + .globl _OSSpinLockLock +_OSSpinLockLock: + movq $(_COMM_PAGE_SPINLOCK_LOCK), %rax + jmp *%rax + + +// void OSSpinLockUnlock( OSSpinLock *lock ); + .align 2, 0x90 + .globl _OSSpinLockUnlock +_OSSpinLockUnlock: + movl $0, (%rdi) + ret + + +// void OSMemoryBarrier( void ); + .align 2, 0x90 + .globl _OSMemoryBarrier +_OSMemoryBarrier: + ret diff --git a/x86_64/sys/SYS.h b/x86_64/sys/SYS.h new file mode 100644 index 0000000..dbe69be --- /dev/null +++ b/x86_64/sys/SYS.h @@ -0,0 +1,108 @@ +/* + * Copyright (c) 1999-2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + * + * File: SYS.h + * + * Definition of the user side of the UNIX system call interface + * for x86-64. + * + * HISTORY + * 12-3-92 Bruce Martin (Bruce_Martin@next.com) + * Created. + */ + +/* + * Headers + */ +#include +#include +#include + +#define UNIX_SYSCALL_SYSCALL \ + movq %rcx, %r10 ;\ + syscall + +/* + * This is the same as UNIX_SYSCALL, but it can call an alternate error + * return function. It's generic to support potential future callers. + */ +#define UNIX_SYSCALL_ERR(name, nargs,error_ret) \ + .globl error_ret ;\ +LEAF(_##name, 0) ;\ + movl $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax ;\ + UNIX_SYSCALL_SYSCALL ;\ + jnb 2f ;\ + BRANCH_EXTERN(error_ret) ;\ +2: + +#define UNIX_SYSCALL(name, nargs) \ + .globl cerror ;\ +LEAF(_##name, 0) ;\ + movl $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax ;\ + UNIX_SYSCALL_SYSCALL ;\ + jnb 2f ;\ + BRANCH_EXTERN(cerror) ;\ +2: + +#define UNIX_SYSCALL_NONAME(name, nargs) \ + .globl cerror ;\ + movl $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax ;\ + UNIX_SYSCALL_SYSCALL ;\ + jnb 2f ;\ + BRANCH_EXTERN(cerror) ;\ +2: + +#define PSEUDO(pseudo, name, nargs) \ +LEAF(_##pseudo, 0) ;\ + UNIX_SYSCALL_NONAME(name, nargs) + +#if !defined(SYS_getdirentriesattr) +#define SYS_getdirentriesattr 222 +#endif + +#if !defined(SYS_semsys) +#define SYS_semsys 251 +#define SYS_msgsys 252 +#define SYS_shmsys 253 +#define SYS_semctl 254 +#define SYS_semget 255 +#define SYS_semop 256 +/*#define SYS_semconfig 257*/ +#define SYS_msgctl 258 +#define SYS_msgget 259 +#define SYS_msgsnd 260 +#define SYS_msgrcv 261 +#define SYS_shmat 262 +#define SYS_shmctl 263 +#define SYS_shmdt 264 +#define SYS_shmget 265 +#endif + +#if !defined(SYS___pthread_canceled) +#define SYS___pthread_markcancel 332 +#define SYS___pthread_canceled 333 +#define SYS___semwait_signal 334 +#endif + diff --git a/x86_64/sys/__fcntl.s b/x86_64/sys/__fcntl.s new file mode 100644 index 0000000..aaedd45 --- /dev/null +++ b/x86_64/sys/__fcntl.s @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + +PSEUDO(__fcntl, fcntl, 3) + ret diff --git a/x86_64/sys/__ioctl.s b/x86_64/sys/__ioctl.s new file mode 100644 index 0000000..5256103 --- /dev/null +++ b/x86_64/sys/__ioctl.s @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + +PSEUDO(__ioctl, ioctl, 3) + ret diff --git a/x86_64/sys/_setjmp.s b/x86_64/sys/_setjmp.s new file mode 100644 index 0000000..7ebf81c --- /dev/null +++ b/x86_64/sys/_setjmp.s @@ -0,0 +1,123 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + * + * HISTORY + * 20-Apr-92 Bruce Martin (bmartin@next.com) + * Created from M68K sources. + */ + +/* + * C library -- _setjmp, _longjmp + * + * _longjmp(a,v) + * will generate a "return(v)" from + * the last call to + * _setjmp(a) + * by restoring registers from the stack, + * The previous signal state is NOT restored. + * + */ + +#include + +#define JB_RBX 0 +#define JB_RBP 8 +#define JB_RSP 16 +#define JB_R12 24 +#define JB_R13 32 +#define JB_R14 40 +#define JB_R15 48 +#define JB_RIP 56 +#define JB_RFLAGS 64 +#define JB_MXCSR 72 +#define JB_FPCONTROL 76 +#define JB_MASK 80 + +LEAF(__setjmp, 0) + // %rdi is a jmp_buf (struct sigcontext *) + + // now build sigcontext + movq %rbx, JB_RBX(%rdi) + movq %rbp, JB_RBP(%rdi) + movq %r12, JB_R12(%rdi) + movq %r13, JB_R13(%rdi) + movq %r14, JB_R14(%rdi) + movq %r15, JB_R15(%rdi) + + // RIP is set to the frame return address value + movq (%rsp), %rax + movq %rax, JB_RIP(%rdi) + // RSP is set to the frame return address plus 8 + movq %rsp, %rax + addq $8, %rax + movq %rax, JB_RSP(%rdi) + + // save rflags - you can't use movq + pushfq + popq %rax + movq %rax, JB_RFLAGS(%rdi) + + // save fp control word + fnstcw JB_FPCONTROL(%rdi) + + // save MXCSR + stmxcsr JB_MXCSR(%rdi) + + // return 0 + xorq %rax, %rax + ret + + +LEAF(__longjmp, 0) + fninit // reset FP coprocessor + + // %rdi is a jmp_buf (struct sigcontext *) + // %rsi is the return value + movq %rsi, %rax + testq %rax, %rax + jnz 1f + addq $1, %rax + + // general registers +1: + movq JB_RBX(%rdi), %rbx + movq JB_RBP(%rdi), %rbp + movq JB_RSP(%rdi), %rsp + movq JB_R12(%rdi), %r12 + movq JB_R13(%rdi), %r13 + movq JB_R14(%rdi), %r14 + movq JB_R15(%rdi), %r15 + + // restore FP control word + fldcw JB_FPCONTROL(%rdi) + + // restore MXCSR + ldmxcsr JB_MXCSR(%rdi) + + // rflags + pushq JB_RFLAGS(%rdi) + popfq + + jmp *JB_RIP(%rdi) diff --git a/x86_64/sys/cerror.s b/x86_64/sys/cerror.s new file mode 100644 index 0000000..1f7d10d --- /dev/null +++ b/x86_64/sys/cerror.s @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + + .globl _errno + +LABEL(cerror_cvt) + cmpq $102, %rax /* EOPNOTSUPP? */ + jnz cerror + movl $45, %eax /* Yes; make ENOTSUP for compatibility */ +LABEL(cerror) + REG_TO_EXTERN(%rax, _errno) + mov %rsp,%rdx + andq $-16,%rsp + subq $16,%rsp + // Preserve the original stack + movq %rdx,(%rsp) + movq %rax,%rdi + CALL_EXTERN(_cthread_set_errno_self) + // Restore the original stack + movq (%rsp),%rsp + movq $-1,%rax + movq $-1,%rdx /* in case a 128-bit value is returned */ + ret diff --git a/x86_64/sys/fork.s b/x86_64/sys/fork.s new file mode 100644 index 0000000..3fe1c1e --- /dev/null +++ b/x86_64/sys/fork.s @@ -0,0 +1,131 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + +LEAF(_fork, 0) + subq $24, %rsp // Align the stack, plus room for local storage + CALL_EXTERN(__cthread_fork_prepare) +#if defined(__DYNAMIC__) +// Just like __cthread_fork_prepare we need to prevent threads on the child's +// side from doing a mach call in the dynamic linker until __dyld_fork_child +// is run (see below). So we call __dyld_fork_prepare which takes out the dyld +// lock to prevent all other threads but this one from entering dyld. +.cstring +LC1: + .ascii "__dyld_fork_prepare\0" +.text + // Give a pointer to 8(%rsp) to _dyld_func_lookup for it to fill in. + leaq 8(%rsp),%rsi // get the address where we're going to store the pointer + leaq LC1(%rip), %rdi // copy the name of the function to look up + call __dyld_func_lookup + movq 8(%rsp),%rax // move the value returned in address parameter + call *%rax // call __dyld_fork_prepare +#endif + + movl $ SYSCALL_CONSTRUCT_UNIX(SYS_fork),%eax; // code for fork -> rax + UNIX_SYSCALL_TRAP // do the system call + jnc L1 // jump if CF==0 + +#if defined(__DYNAMIC__) +// __dyld_fork_parent() is called by the parent process after a fork syscall. +// This releases the dyld lock acquired by __dyld_fork_prepare(). In this case +// we just use it to clean up after a fork error so the parent process can +// dyld after fork() errors without deadlocking. +.cstring +LC2: + .ascii "__dyld_fork_parent\0" +.text + movq %rax, 16(%rsp) // save the return value (errno) + leaq 8(%rsp),%rsi // get the address where we're going to store the pointer + leaq LC2(%rip), %rdi // copy the name of the function to look up + call __dyld_func_lookup + call *8(%rsp) // call __dyld_fork_parent indirectly + movq 16(%rsp), %rax // restore the return value (errno) +#endif + CALL_EXTERN(cerror) + CALL_EXTERN(__cthread_fork_parent) + movq $-1, %rax + addq $24, %rsp // restore the stack + ret + +L1: + orl %edx,%edx // CF=OF=0, ZF set if zero result + jz L2 // parent, since r1 == 0 in parent, 1 in child + + //child here... +#if defined(__DYNAMIC__) +// Here on the child side of the fork we need to tell the dynamic linker that +// we have forked. To do this we call __dyld_fork_child in the dyanmic +// linker. But since we can't dynamically bind anything until this is done we +// do this by using the private extern __dyld_func_lookup() function to get the +// address of __dyld_fork_child (the 'C' code equivlent): +// +// _dyld_func_lookup("__dyld_fork_child", &address); +// address(); +// +.cstring +LC0: + .ascii "__dyld_fork_child\0" + +.text + leaq 8(%rsp),%rsi // get the address where we're going to store the pointer + leaq LC0(%rip), %rdi // copy the name of the function to look up + call __dyld_func_lookup + call *8(%rsp) // call __dyld_fork_child indirectly +#endif + xorq %rax, %rax + REG_TO_EXTERN(%rax, __current_pid) + CALL_EXTERN(__cthread_fork_child) +#if defined(__DYNAMIC__) +.cstring +LC10: + .ascii "__dyld_fork_child_final\0" + +.text + leaq 8(%rsp),%rsi // get the address where we're going to store the pointer + leaq LC10(%rip), %rdi // copy the name of the function to look up + call __dyld_func_lookup + call *8(%rsp) // call __dyld_fork_child_final indirectly +#endif + xorq %rax,%rax // zero rax + addq $24, %rsp // restore the stack + ret + + //parent here... +L2: + movl %eax, 16(%rsp) // save pid +#if defined(__DYNAMIC__) +// __dyld_fork_parent() is called by the parent process after a fork syscall. +// This releases the dyld lock acquired by __dyld_fork_prepare(). + leaq 8(%rsp),%rsi // get the address where we're going to store the pointer + leaq LC2(%rip), %rdi // copy the name of the function to look up + call __dyld_func_lookup + call *8(%rsp) // call __dyld_fork_parent indirectly +#endif + CALL_EXTERN_AGAIN(__cthread_fork_parent) + movl 16(%rsp), %eax // return pid + addq $24, %rsp // restore the stack + ret diff --git a/x86_64/sys/getpid.s b/x86_64/sys/getpid.s new file mode 100644 index 0000000..f3a738a --- /dev/null +++ b/x86_64/sys/getpid.s @@ -0,0 +1,51 @@ +/* + * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + + .data + .private_extern __current_pid +__current_pid: + .long 0 + +/* + * If __current_pid is > 0, return it, else make syscall. + * If __current_pid is 0, cache result of syscall. + */ +TEXT +LEAF(_getpid, 0) + movl __current_pid(%rip), %eax + testl %eax, %eax + jle 1f + ret +1: + UNIX_SYSCALL_NONAME(getpid, 0) + movl %eax, %edx + xorl %eax, %eax + leaq __current_pid(%rip), %rcx + lock + cmpxchgl %edx, (%rcx) + movl %edx, %eax + ret diff --git a/x86_64/sys/i386_gettimeofday.s b/x86_64/sys/i386_gettimeofday.s new file mode 100644 index 0000000..678ebf9 --- /dev/null +++ b/x86_64/sys/i386_gettimeofday.s @@ -0,0 +1,43 @@ +/* + * Copyright (c) 1999-2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include + +#define __APPLE_API_PRIVATE +#include +#undef __APPLE_API_PRIVATE + +LABEL(___commpage_gettimeofday) + movq $(_COMM_PAGE_GETTIMEOFDAY),%rax + jmp *%rax + +/* + * This syscall is special cased: the timeval is returned in rax:rdx. + */ +LABEL(___gettimeofday) + UNIX_SYSCALL_NONAME(gettimeofday,0) + movq %rax, (%rdi) + movl %edx, 8(%rdi) + xorl %eax, %eax + ret diff --git a/x86_64/sys/lseek.s b/x86_64/sys/lseek.s new file mode 100644 index 0000000..f99bab2 --- /dev/null +++ b/x86_64/sys/lseek.s @@ -0,0 +1,29 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + +UNIX_SYSCALL(lseek, 3) + ret diff --git a/x86_64/sys/pipe.s b/x86_64/sys/pipe.s new file mode 100644 index 0000000..5864575 --- /dev/null +++ b/x86_64/sys/pipe.s @@ -0,0 +1,32 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + +UNIX_SYSCALL(pipe, 0) + movl %eax, (%rdi) + movl %edx, 4(%rdi) + xorl %eax, %eax + ret diff --git a/x86_64/sys/ptrace.s b/x86_64/sys/ptrace.s new file mode 100644 index 0000000..6119772 --- /dev/null +++ b/x86_64/sys/ptrace.s @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + + .globl _errno + +LEAF(_ptrace, 0) + xorq %rax,%rax + REG_TO_EXTERN(%rax,_errno) +UNIX_SYSCALL_NONAME(ptrace, 4) + ret diff --git a/x86_64/sys/setjmp.s b/x86_64/sys/setjmp.s new file mode 100644 index 0000000..05ca533 --- /dev/null +++ b/x86_64/sys/setjmp.s @@ -0,0 +1,104 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +/* + * NeXT 386 setjmp/longjmp + * + * Written by Bruce Martin, NeXT Inc. 4/9/92 + */ + +/* + * C library -- setjmp, longjmp + * + * longjmp(a,v) + * will generate a "return(v)" from + * the last call to + * setjmp(a) + * by restoring registers from the stack, + * The previous value of the signal mask is + * restored. + * + */ + +#include +#include + +#define JB_RBX 0 +#define JB_RBP 8 +#define JB_RSP 16 +#define JB_R12 24 +#define JB_R13 32 +#define JB_R14 40 +#define JB_R15 48 +#define JB_RIP 56 +#define JB_RFLAGS 64 +#define JB_MXCSR 72 +#define JB_FPCONTROL 76 +#define JB_MASK 80 +#define JB_SAVEMASK 84 // sigsetjmp/siglongjmp only + + +LEAF(_sigsetjmp, 0) + // %rdi is sigjmp_buf * jmpbuf; + // %esi is int savemask + movl %esi, JB_SAVEMASK(%rdi) // jmpbuf[_JBLEN] = savemask; + cmpl $0, %esi // if savemask != 0 + jne _setjmp // setjmp(jmpbuf); + jmp L_do__setjmp // else _setjmp(jmpbuf); + +LEAF(_setjmp, 0) + pushq %rdi // Preserve the jmp_buf across the call + movl $1, %edi // how = SIG_BLOCK + xorq %rsi, %rsi // set = NULL + subq $8, %rsp // Allocate space for the return from sigprocmask + movq %rsp, %rdx + CALL_EXTERN(_sigprocmask) + popq %rax // Save the mask + popq %rdi // jmp_buf (struct sigcontext *) + movq %rax, JB_MASK(%rdi) +L_do__setjmp: + BRANCH_EXTERN(__setjmp) + +LEAF(_siglongjmp, 0) + // %rdi is sigjmp_buf * jmpbuf; + cmpl $0, JB_SAVEMASK(%rdi) // if jmpbuf[_JBLEN] != 0 + jne _longjmp // longjmp(jmpbuf, var); + jmp L_do__longjmp // else _longjmp(jmpbuf, var); + +LEAF(_longjmp, 0) + // %rdi is address of jmp_buf (saved context) + pushq %rdi // Preserve the jmp_buf across the call + pushq %rsi // Preserve the value across the call + pushq JB_MASK(%rdi) // Put the mask on the stack + movq $3, %rdi // how = SIG_SETMASK + movq %rsp, %rsi // set = address where we stored the mask + xorq %rdx, %rdx // oset = NULL + CALL_EXTERN_AGAIN(_sigprocmask) + addq $8, %rsp + popq %rsi // Restore the value + popq %rdi // Restore the jmp_buf +L_do__longjmp: + BRANCH_EXTERN(__longjmp) // else +END(_longjmp) diff --git a/x86_64/sys/sigaltstack.s b/x86_64/sys/sigaltstack.s new file mode 100644 index 0000000..819bb61 --- /dev/null +++ b/x86_64/sys/sigaltstack.s @@ -0,0 +1,29 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + +UNIX_SYSCALL(sigaltstack, 3) + ret diff --git a/x86_64/sys/sigreturn.s b/x86_64/sys/sigreturn.s new file mode 100644 index 0000000..2c140b5 --- /dev/null +++ b/x86_64/sys/sigreturn.s @@ -0,0 +1,29 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + +UNIX_SYSCALL(sigreturn, 2) + ret diff --git a/x86_64/sys/syscall.s b/x86_64/sys/syscall.s new file mode 100644 index 0000000..cc34346 --- /dev/null +++ b/x86_64/sys/syscall.s @@ -0,0 +1,32 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + +// For x86-64, the kernel slides the argument list for us. +// The number of arguments here is variable, but our macros ignore +// that value anyway. +UNIX_SYSCALL(syscall, 0); + ret diff --git a/x86_64/sys/vfork.s b/x86_64/sys/vfork.s new file mode 100644 index 0000000..05229ef --- /dev/null +++ b/x86_64/sys/vfork.s @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved + */ +#include + +/* + * If __current_pid >= 0, we want to put a -1 in there + * otherwise we just decrement it + */ + +LEAF(_vfork, 0) + movq __current_pid@GOTPCREL(%rip), %rax + movl (%rax), %eax +0: + xorl %ecx, %ecx + testl %eax, %eax + cmovs %eax, %ecx + subl $1, %ecx + movq __current_pid@GOTPCREL(%rip), %rdx + lock + cmpxchgl %ecx, (%rdx) + jne 0b + popq %rdi // return address in %rdi + movq $ SYSCALL_CONSTRUCT_UNIX(SYS_vfork), %rax // code for vfork -> rax + UNIX_SYSCALL_TRAP // do the system call + jnb L1 // jump if CF==0 + movq __current_pid@GOTPCREL(%rip), %rcx + lock + addq $1, (%rcx) + movq (%rcx), %rdi + BRANCH_EXTERN(cerror) + +L1: + testl %edx, %edx // CF=OF=0, ZF set if zero result + jz L2 // parent, since r1 == 0 in parent, 1 in child + xorq %rax, %rax // zero rax + jmp *%rdi + +L2: + movq __current_pid@GOTPCREL(%rip), %rdx + lock + addq $1, (%rdx) + jmp *%rdi -- 2.45.2