--- /dev/null
+.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
-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 $@
.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}
# 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
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}
.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
.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}
#include <fcntl.h>
#include <sys/errno.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <sys/xattr.h>
#include <sys/syscall.h>
#include <sys/param.h>
}
copyfile_debug(1, "debug value set to: %d\n", s->debug);
}
-
if (COPYFILE_CHECK & flags)
return copyfile_check(s);
#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;
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)
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)
}
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;
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;
/*
* 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);
if (adhdr->entries[1].type == AD_RESOURCE &&
adhdr->entries[1].length > 0)
{
- void * rsrcforkdata;
+ void * rsrcforkdata = NULL;
size_t length;
off_t offset;
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)
{
(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;
}
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;
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.
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 <endnamebuf; nameptr += namelen)
{
namelen = strlen(nameptr) + 1;
/* Skip over FinderInfo or Resource Fork names */
- if (strncmp(nameptr, XATTR_FINDERINFO_NAME, strlen(XATTR_FINDERINFO_NAME)) == 0 ||
- strncmp(nameptr, XATTR_RESOURCEFORK_NAME, strlen(XATTR_RESOURCEFORK_NAME)) == 0)
+ if (strcmp(nameptr, XATTR_FINDERINFO_NAME) == 0 ||
+ strcmp(nameptr, XATTR_RESOURCEFORK_NAME) == 0)
continue;
+ /* The system should prevent this from happening, but... */
+ if (namelen > XATTR_MAXNAMELEN + 1) {
+ namelen = XATTR_MAXNAMELEN + 1;
+ }
entry->namelen = namelen;
entry->flags = 0;
bcopy(nameptr, &entry->name[0], namelen);
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;
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)
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;
goto next;
}
databuf = malloc(datasize);
+ if (databuf == NULL) {
+ error = -1;
+ continue;
+ }
datasize = fgetxattr(s->src_fd, nameptr, databuf, datasize, 0, 0);
}
* 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);
goto exit;
}
exit:
- free(filehdr);
- free(attrnamebuf);
+ if (filehdr) free(filehdr);
+ if (attrnamebuf) free(attrnamebuf);
if (error)
return error;
#define LDBL_TO_ARRAY32(u, a) _ldbl2array32dd(u, a)
-#elif defined(__i386__)
+#elif defined(__i386__) || defined(__x86_64__)
union IEEEl2bits {
long double e;
#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
#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
---- 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;
- *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;
---- /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 <stdlib.h>
#include <string.h>
#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;
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
// 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;
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__)
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
movl $3,%eax
MACHDEP_SYSCALL_TRAP
addl $8,%esp
- movw %ax,%gs
ret
#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
LEAF(_bzero,0)
movl $(_COMM_PAGE_BZERO), %eax
- jmpl %eax
+ jmpl *%eax
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.
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
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
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:
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(ATPgetreq, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(ATPgetrsp, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(ATPsndreq, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(ATPsndrsp, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(ATgetmsg, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(ATputmsg, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(ATsocket, 3)
ret
.PATH: ${.CURDIR}/i386/sys
+
+AINC+= -I${.CURDIR}/i386/sys
MDSRCS+= ATPgetreq.s \
ATPgetrsp.s \
ATPsndreq.s \
call *_COMM_PAGE_COMPARE_AND_SWAP64
jnz 1b
movl %ebx, %eax
- movl %ecx, %ebx
+ movl %ecx, %edx
popl %esi
popl %ebx
ret
.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
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
PSEUDO(__mmap, mmap, 6)
ret
/*
* Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(__pthread_canceled, 1)
ret
/*
* Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(__pthread_markcancel, 1)
ret
/*
* Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(__semwait_signal, 6)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
PSEUDO(_exit, exit, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
PSEUDO(_getlogin, getlogin, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(__pthread_kill, 2)
ret
#include <architecture/i386/asm_help.h>
-#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
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)
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
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
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
PSEUDO(_setlogin, setlogin, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(__sysctl, 6)
ret
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(access, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(acct, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(add_profil, 4)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(adjtime, 2)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(aio_cancel, 2)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(aio_error, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(aio_fsync, 2)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(aio_read, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(aio_return, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(aio_suspend, 3)
- ret
\ No newline at end of file
+ ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(aio_write, 1)
- ret
\ No newline at end of file
+ ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(audit, 2)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(auditctl, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(auditon, 3)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(auditsvc, 2)
ret
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
.globl _errno
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(chdir, 1)
ret
/*
* Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(checkuseraccess, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(chflags, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(chmod, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(chown, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(chroot, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(close, 1)
ret
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(dup, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(dup2, 2)
ret
/*
* Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(exchangedata, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(execve, 3)
ret // execve(file, argv, arge)
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fchdir, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fchflags, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fchmod, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fchown, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fcntl, 3)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fgetxattr, 5)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fhopen, 2)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(flistxattr, 4)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(flock, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
LEAF(_fork, 0)
subl $28, %esp // Align the stack, with 16 bytes of extra padding that we'll need
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fpathconf, 2)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fremovexattr, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fsctl, 4)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fsetxattr, 5)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fstat, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fstatfs, 2)
ret
/*
* Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fstatv, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(fsync, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(ftruncate, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(futimes, 2)
ret
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getaudit, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getaudit_addr, 2)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getauid, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getdirentries, 4)
ret
/*
* Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getdirentriesattr, 0)
ret
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getdtablesize, 0)
ret // i = getdtablesize();
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getegid, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(geteuid, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getfh, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getfsstat, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getgid, 0)
ret // gid = getgid();
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getgroups, 2)
ret // ngroups = getgroups(gidsetsize, gidset)
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getitimer, 2)
ret
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getpgid, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getpgrp, 1)
ret // pgrp = getpgrp(pid);
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
.data
.private_extern __current_pid
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getppid,0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getpriority, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getrlimit, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getrusage, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getsid, 1)
ret
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getsockopt, 5)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getuid, 0)
ret // uid = getuid();
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(getxattr, 5)
ret
*/
/* Copyright 1998 Apple Computer, Inc. */
-#include "SYS.h"
+#include <SYS.h>
#define __APPLE_API_PRIVATE
#include <machine/cpu_capabilities.h>
LABEL(___commpage_gettimeofday)
mov $ _COMM_PAGE_GETTIMEOFDAY,%eax
- jmp %eax
+ jmp *%eax
/*
* This syscall is special cased: the timeval is returned in eax/edx.
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(ioctl, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(issetugid, 0)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(kevent, 6)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(kill, 2)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(kqueue, 0)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(kqueue_from_portset_np, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(kqueue_portset_np, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(ktrace, 4)
ret
/*
- * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2004, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(link, 2)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(lio_listio, 4)
ret
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(listxattr, 4)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(load_shared_file, 7)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL_INT(lseek, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(lstat, 2)
ret
/*
* Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(lstatv, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(madvise, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(mincore, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(minherit, 3)
ret
/*
* Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(mkcomplex, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(mkdir, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(mkfifo, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(mknod, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(mlock, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(mlockall, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(mount, 4)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(msgget, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(msgrcv, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(msgsnd, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(msgsys, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(munlock, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(munlockall, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(new_system_shared_regions, 0)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(nfsclnt, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(nfssvc, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(open, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(pathconf, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL_INT(pipe, 0)
movl 4(%esp),%ecx
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(poll, 3)
ret
*/
/* Copyright 1998 Apple Computer, Inc. */
-#include "SYS.h"
+#include <SYS.h>
PSEUDO(posix_madvise, madvise, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(pread, 4)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(profil, 4)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(pthread_sigmask, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
.globl _errno
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(pwrite, 4)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
#define SYS_quota 149
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(quotactl, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(read, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(readlink, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(readv, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(reboot, 2)
hlt
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(removexattr, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(rename, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(reset_shared_file, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(revoke, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(rmdir, 1)
ret
/*
* Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(searchfs, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(select, 5)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(sem_close, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(sem_destroy, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(sem_getvalue, 2)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(sem_init, 3)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(sem_post, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(sem_trywait, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(sem_wait, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(semget, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(semop, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(semsys, 3)
ret
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setaudit, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setaudit_addr, 2)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setauid, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setegid, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(seteuid, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setgid, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setgroups, 2)
ret // setgroups(gidsetsize, gidset)
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setitimer, 3)
ret
*/
#include <architecture/i386/asm_help.h>
-#include "SYS.h"
+#include <SYS.h>
-#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
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setpgid, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setpriority, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setprivexec, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
#define SYS_setquota 148
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setrlimit, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setsid, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setsockopt, 5)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(settimeofday, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setuid, 1)
ret
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(setxattr, 5)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(shmat, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(shmdt, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(shmget, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(shmsys, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(shutdown, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL_INT(sigaltstack, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(sigpending, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(sigprocmask, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL_INT(sigreturn, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(sigwait, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(socket, 3)
ret
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
+#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__ */
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(stat, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(statfs, 2);
ret
/*
* Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(statv, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(swapon, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(symlink, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(sync, 0)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
LEAF(_syscall, 0)
popl %ecx // ret addr
*
* @APPLE_LICENSE_HEADER_END@
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(table, 5)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(truncate, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(umask, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(undelete, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(unlink, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(unmount, 1)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(utimes, 2)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
#if defined(__DYNAMIC__)
#define GET_CURRENT_PID PICIFY(__current_pid)
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(wait4, 4)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(write, 3)
ret
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/
-#include "SYS.h"
+#include <SYS.h>
UNIX_SYSCALL(writev, 3)
ret
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 );
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.
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))
This file is public domain. */
#if defined (__ppc__) || defined (__ppc64__)
#include <ppc/limits.h>
-#elif defined (__i386__)
+#elif defined (__i386__) || defined(__x86_64__)
#include <i386/limits.h>
#else
#error architecture not supported
# 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}
*/
#if defined(__i386__)
#include <mach/i386/task.h>
+#elif defined(__x86_64__)
+#include <mach/x86_64/task.h>
#elif defined(__ppc__)
#include <mach/ppc/task.h>
#elif defined(__ppc64__)
*/
#if defined(__i386__)
#include <mach/i386/thread_act.h>
+#elif defined(__x86_64__)
+#include <mach/x86_64/thread_act.h>
#elif defined(__ppc__)
#include <mach/ppc/thread_act.h>
#elif defined(__ppc64__)
.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\//}
LEAF(__spin_lock_try, 0)
movl $(_COMM_PAGE_SPINLOCK_TRY), %eax
- jmpl %eax
+ jmpl *%eax
ALIGN
LEAF(__spin_lock, 0)
_spin_lock:
movl $(_COMM_PAGE_SPINLOCK_LOCK), %eax
- jmpl %eax
+ jmpl *%eax
/*
* void
LEAF(__spin_unlock, 0)
_spin_unlock:
movl $(_COMM_PAGE_SPINLOCK_UNLOCK), %eax
- jmpl %eax
+ jmpl *%eax
+
+#elif defined(__x86_64__)
+
+#include <architecture/i386/asm_help.h>
+
+/*
+ * 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
#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
#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.
_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;
subl $0x100,%eax
ret
+#elif defined(__x86_64__)
+
+#import <architecture/i386/asm_help.h>
+/*
+ * 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
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
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:
#if defined(__DYNAMIC__)
__in_sigtramp++;
#endif
-#ifdef __i386__
+#if defined(__i386__) || defined(__x86_64__)
if (sigstyle == UC_TRAD)
sa_handler(sig);
else {
--- /dev/null
+# 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
--- /dev/null
+/*
+ * 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 <architecture/i386/asm_help.h>
+
+.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
--- /dev/null
+# searching i386 directory as a fallback to avoid unnecessary code duplication
+.PATH: ${.CURDIR}/i386/mach
+MDSRCS += mach_absolute_time.c
--- /dev/null
+# 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
--- /dev/null
+/*
+ * 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 <machine/cpu_capabilities.h>
+#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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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 <mach/i386/syscall_sw.h>
+
+.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
--- /dev/null
+# Long double is 80 bits
+FBSDSRCS+=gdtoa_strtopx.c machdep_ldisx.c
--- /dev/null
+# $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
--- /dev/null
+/*
+ * 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.
+ */
--- /dev/null
+/*
+ * 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 <machine/cpu_capabilities.h>
+
+#include <architecture/i386/asm_help.h>
+
+ 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
--- /dev/null
+/*
+ * 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 <machine/cpu_capabilities.h>
+
+#include <architecture/i386/asm_help.h>
+
+ TEXT
+ ALIGN
+
+LEAF(_bzero,0)
+ movq $(_COMM_PAGE_BZERO), %rax
+ jmp *%rax
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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"
--- /dev/null
+/*
+ * 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"
--- /dev/null
+/*
+ * 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 <machine/cpu_capabilities.h>
+
+
+/* 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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 <machine/cpu_capabilities.h>
+
+
+// *****************
+// * 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
--- /dev/null
+.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
--- /dev/null
+/*
+ * 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 <machine/cpu_capabilities.h>
+
+#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
--- /dev/null
+/*
+ * 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 <sys/syscall.h>
+#include <architecture/i386/asm_help.h>
+#include <mach/i386/syscall_sw.h>
+
+#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
+
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+PSEUDO(__fcntl, fcntl, 3)
+ ret
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+PSEUDO(__ioctl, ioctl, 3)
+ ret
--- /dev/null
+/*
+ * 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 <architecture/i386/asm_help.h>
+
+#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)
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+ .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
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+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
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+ .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
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+#define __APPLE_API_PRIVATE
+#include <machine/cpu_capabilities.h>
+#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
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+UNIX_SYSCALL(lseek, 3)
+ ret
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+UNIX_SYSCALL(pipe, 0)
+ movl %eax, (%rdi)
+ movl %edx, 4(%rdi)
+ xorl %eax, %eax
+ ret
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+ .globl _errno
+
+LEAF(_ptrace, 0)
+ xorq %rax,%rax
+ REG_TO_EXTERN(%rax,_errno)
+UNIX_SYSCALL_NONAME(ptrace, 4)
+ ret
--- /dev/null
+/*
+ * 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 <architecture/i386/asm_help.h>
+#include <SYS.h>
+
+#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)
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+UNIX_SYSCALL(sigaltstack, 3)
+ ret
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+UNIX_SYSCALL(sigreturn, 2)
+ ret
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+// 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
--- /dev/null
+/*
+ * 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 <SYS.h>
+
+/*
+ * 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