summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-06-21 14:25:47 +0000
committerMoonchild <moonchild@palemoon.org>2022-06-21 14:25:47 +0000
commit27347bc82722fad7c2f4eac05dcde7b51f19cd2c (patch)
treed3c46e5d121613c8979d2ae2716d193567704c8f
parente837b693ba074674157cd78491d34235af5acf72 (diff)
parent532cd0ae7a726a245380f00476b5474b25d55c7a (diff)
downloaduxp-27347bc82722fad7c2f4eac05dcde7b51f19cd2c.tar.gz
Merge pull request 'Final set of Apple Silicon (ARM64) Macintosh changes.' (#1923) from dbsoft/UXP:AppleARMPart4 into master
Reviewed-on: https://repo.palemoon.org/MoonchildProductions/UXP/pulls/1923
-rw-r--r--build/autoconf/toolchain.m42
-rw-r--r--dom/base/Navigator.cpp5
-rw-r--r--dom/system/OSFileConstants.cpp8
-rw-r--r--js/src/ctypes/CTypes.cpp15
-rw-r--r--netwerk/protocol/http/nsHttpHandler.cpp2
-rw-r--r--toolkit/components/osfile/modules/osfile_shared_allthreads.jsm8
-rw-r--r--toolkit/components/osfile/modules/osfile_unix_back.jsm2
-rw-r--r--toolkit/components/osfile/modules/osfile_unix_front.jsm4
-rw-r--r--xpcom/reflect/xptcall/md/unix/xptcinvoke_aarch64.cpp180
9 files changed, 132 insertions, 94 deletions
diff --git a/build/autoconf/toolchain.m4 b/build/autoconf/toolchain.m4
index 9fc76a3f6e..47f4ec0505 100644
--- a/build/autoconf/toolchain.m4
+++ b/build/autoconf/toolchain.m4
@@ -27,7 +27,7 @@ fi
if test "`echo | $AS -o conftest.out -v 2>&1 | grep -c GNU`" != "0"; then
GNU_AS=1
fi
-if test "`echo | $AS -o conftest.out -v 2>&1 | grep -c LLVM`" != "0"; then
+if test "`echo | $AS -o conftest.out -v 2>&1 | grep -c Apple`" != "0"; then
GNU_AS=1
fi
rm -f conftest.out
diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp
index 28b66be3db..05268a5156 100644
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1390,9 +1390,8 @@ Navigator::GetPlatform(nsAString& aPlatform, bool aUsePrefOverriddenValue)
aPlatform.AssignLiteral("Win32");
#elif defined(XP_MACOSX) && defined(__ppc__)
aPlatform.AssignLiteral("MacPPC");
-#elif defined(XP_MACOSX) && defined(__i386__)
- aPlatform.AssignLiteral("MacIntel");
-#elif defined(XP_MACOSX) && defined(__x86_64__)
+#elif defined(XP_MACOSX)
+ // Always return "MacIntel", even on ARM64 macOS like Safari does.
aPlatform.AssignLiteral("MacIntel");
#else
// XXX Communicator uses compiled-in build-time string defines
diff --git a/dom/system/OSFileConstants.cpp b/dom/system/OSFileConstants.cpp
index 551ed5773f..2f985f45d6 100644
--- a/dom/system/OSFileConstants.cpp
+++ b/dom/system/OSFileConstants.cpp
@@ -704,10 +704,10 @@ static const dom::ConstantSpec gLibcProperties[] =
// Under MacOSX, to avoid using deprecated functions that do not
// match the constants we define in this object (including
// |sizeof|/|offsetof| stuff, but not only), for a number of
- // functions, we need to adapt the name of the symbols we are using,
- // whenever macro _DARWIN_FEATURE_64_BIT_INODE is set. We export
- // this value to be able to do so from JavaScript.
-#if defined(_DARWIN_FEATURE_64_BIT_INODE)
+ // functions, we need to use functions with a $INODE64 suffix.
+ // That is true on Intel-based mac when the _DARWIN_FEATURE_64_BIT_INODE
+ // macro is set. But not on Apple Silicon.
+#if defined(_DARWIN_FEATURE_64_BIT_INODE) && !defined(__aarch64__)
{ "_DARWIN_FEATURE_64_BIT_INODE", JS::Int32Value(1) },
#endif // defined(_DARWIN_FEATURE_64_BIT_INODE)
diff --git a/js/src/ctypes/CTypes.cpp b/js/src/ctypes/CTypes.cpp
index b75b42072f..3bc249e015 100644
--- a/js/src/ctypes/CTypes.cpp
+++ b/js/src/ctypes/CTypes.cpp
@@ -6708,12 +6708,15 @@ PrepareCIF(JSContext* cx,
if (!rtype)
return false;
- ffi_status status =
- ffi_prep_cif(&fninfo->mCIF,
- abi,
- fninfo->mFFITypes.length(),
- rtype,
- fninfo->mFFITypes.begin());
+ ffi_status status;
+ if (fninfo->mIsVariadic) {
+ status = ffi_prep_cif_var(&fninfo->mCIF, abi, fninfo->mArgTypes.length(),
+ fninfo->mFFITypes.length(), rtype,
+ fninfo->mFFITypes.begin());
+ } else {
+ status = ffi_prep_cif(&fninfo->mCIF, abi, fninfo->mFFITypes.length(), rtype,
+ fninfo->mFFITypes.begin());
+ }
switch (status) {
case FFI_OK:
diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp
index 7b6dcc0216..92cf9d5b54 100644
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -830,7 +830,7 @@ nsHttpHandler::InitUserAgentComponents()
#elif defined (XP_MACOSX)
#if defined(__ppc__)
mOscpu.AssignLiteral("PPC Mac OS X");
-#elif defined(__i386__) || defined(__x86_64__)
+#else
mOscpu.AssignLiteral("Intel Mac OS X");
#endif
SInt32 majorVersion = nsCocoaFeatures::macOSVersionMajor();
diff --git a/toolkit/components/osfile/modules/osfile_shared_allthreads.jsm b/toolkit/components/osfile/modules/osfile_shared_allthreads.jsm
index c5c5051026..5d09d765c3 100644
--- a/toolkit/components/osfile/modules/osfile_shared_allthreads.jsm
+++ b/toolkit/components/osfile/modules/osfile_shared_allthreads.jsm
@@ -1130,6 +1130,14 @@ var declareFFI = function declareFFI(lib, symbol, abi,
throw new TypeError("Missing type for argument " + ( i - 3 ) +
" of symbol " + symbol);
}
+ // Ellipsis for variadic arguments.
+ if (current == "...") {
+ if (i != arguments.length - 1) {
+ throw new TypeError("Variadic ellipsis must be the last argument");
+ }
+ signature.push(current);
+ continue;
+ }
if (!current.implementation) {
throw new TypeError("Missing implementation for argument " + (i - 3)
+ " of symbol " + symbol
diff --git a/toolkit/components/osfile/modules/osfile_unix_back.jsm b/toolkit/components/osfile/modules/osfile_unix_back.jsm
index 4cc4445673..6678edf25b 100644
--- a/toolkit/components/osfile/modules/osfile_unix_back.jsm
+++ b/toolkit/components/osfile/modules/osfile_unix_back.jsm
@@ -435,7 +435,7 @@
/*return*/ Type.negativeone_or_fd,
/*path*/ Type.path,
/*oflags*/ Type.int,
- /*mode*/ Type.int);
+ "...");
if (OS.Constants.Sys.Name == "NetBSD") {
libc.declareLazyFFI(SysFile, "opendir",
diff --git a/toolkit/components/osfile/modules/osfile_unix_front.jsm b/toolkit/components/osfile/modules/osfile_unix_front.jsm
index 4e41036dfc..44454daf1d 100644
--- a/toolkit/components/osfile/modules/osfile_unix_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_unix_front.jsm
@@ -320,7 +320,7 @@
flags |= Const.O_APPEND;
}
}
- return error_or_file(UnixFile.open(path, flags, omode), path);
+ return error_or_file(UnixFile.open(path, flags, ctypes.int(omode)), path);
};
/**
@@ -675,7 +675,7 @@
// If necessary, fail if the destination file exists
if (options.noOverwrite) {
- let fd = UnixFile.open(destPath, Const.O_RDONLY, 0);
+ let fd = UnixFile.open(destPath, Const.O_RDONLY);
if (fd != -1) {
fd.dispose();
// The file exists and we have access
diff --git a/xpcom/reflect/xptcall/md/unix/xptcinvoke_aarch64.cpp b/xpcom/reflect/xptcall/md/unix/xptcinvoke_aarch64.cpp
index e5807dbcde..385cba17ad 100644
--- a/xpcom/reflect/xptcall/md/unix/xptcinvoke_aarch64.cpp
+++ b/xpcom/reflect/xptcall/md/unix/xptcinvoke_aarch64.cpp
@@ -23,109 +23,137 @@
#error "Only little endian compatibility was tested"
#endif
-/*
- * Allocation of integer function arguments initially to registers r1-r7
- * and then to stack. Handling of 'that' argument which goes to register r0
- * is handled separately and does not belong here.
- *
- * 'ireg_args' - pointer to the current position in the buffer,
- * corresponding to the register arguments
- * 'stack_args' - pointer to the current position in the buffer,
- * corresponding to the arguments on stack
- * 'end' - pointer to the end of the registers argument
- * buffer.
- */
-static inline void alloc_word(uint64_t* &ireg_args,
- uint64_t* &stack_args,
- uint64_t* end,
- uint64_t data)
-{
- if (ireg_args < end) {
- *ireg_args = data;
- ireg_args++;
- } else {
- *stack_args = data;
- stack_args++;
- }
+// The AAPCS doesn't require argument widening, but Apple's calling convention
+// does. If we are really fortunate, the compiler will clean up all the
+// copying for us.
+template<typename T>
+inline uint64_t normalize_arg(T value) {
+ return (uint64_t)value;
}
-static inline void alloc_double(double* &freg_args,
- uint64_t* &stack_args,
- double* end,
- double data)
-{
- if (freg_args < end) {
- *freg_args = data;
- freg_args++;
- } else {
- memcpy(stack_args, &data, sizeof(data));
- stack_args++;
- }
+template<>
+inline uint64_t normalize_arg(float value) {
+ uint64_t result = 0;
+ memcpy(&result, &value, sizeof(value));
+ return result;
+}
+
+template<>
+inline uint64_t normalize_arg(double value) {
+ uint64_t result = 0;
+ memcpy(&result, &value, sizeof(value));
+ return result;
}
-static inline void alloc_float(double* &freg_args,
- uint64_t* &stack_args,
- double* end,
- float data)
+/*
+ * Allocation of function arguments to their appropriate place in registers
+ * if possible and then to the stack. Handling of 'that' argument which
+ * goes to register r0 is handled separately and does not belong here.
+ *
+ * Note that we are handling integer arguments and floating-point arguments
+ * identically, depending on which register area is passed to this function.
+ *
+ * 'reg_args' - pointer to the current position in the buffer,
+ * corresponding to the register arguments.
+ * 'reg_args_end' - pointer to the end of the registers argument
+ * buffer.
+ * 'stack_args' - pointer to the current position in the buffer,
+ * corresponding to the arguments on stack.
+ * 'data' - typed data to put on the stack.
+ */
+template<typename T>
+static inline void alloc_arg(uint64_t* &reg_args,
+ uint64_t* reg_args_end,
+ void* &stack_args,
+ T* data)
{
- if (freg_args < end) {
- memcpy(freg_args, &data, sizeof(data));
- freg_args++;
+ if (reg_args < reg_args_end) {
+ *reg_args = normalize_arg(*data);
+ reg_args++;
} else {
- memcpy(stack_args, &data, sizeof(data));
- stack_args++;
+ // According to the ABI, types that are smaller than 8 bytes are
+ // passed in registers or 8-byte stack slots. This rule is only
+ // partially true on Apple platforms, where types smaller than 8
+ // bytes occupy only the space they require on the stack and
+ // their stack slot must be properly aligned.
+#ifdef __APPLE__
+ const size_t aligned_size = sizeof(T);
+#else
+ const size_t aligned_size = 8;
+#endif
+ // Ensure the pointer is aligned for the type
+ uintptr_t addr = (reinterpret_cast<uintptr_t>(stack_args) + aligned_size - 1) & ~(aligned_size - 1);
+ memcpy(reinterpret_cast<void*>(addr), data, sizeof(T));
+ // Point the stack to the next slot.
+ stack_args = reinterpret_cast<void*>(addr + aligned_size);
}
}
-
extern "C" void
invoke_copy_to_stack(uint64_t* stk, uint64_t *end,
uint32_t paramCount, nsXPTCVariant* s)
{
- uint64_t *ireg_args = stk;
- uint64_t *ireg_end = ireg_args + 8;
- double *freg_args = (double *)ireg_end;
- double *freg_end = freg_args + 8;
- uint64_t *stack_args = (uint64_t *)freg_end;
+ uint64_t* ireg_args = stk;
+ uint64_t* ireg_end = ireg_args + 8;
+ // Pun on integer and floating-point registers being the same size.
+ uint64_t* freg_args = ireg_end;
+ uint64_t* freg_end = freg_args + 8;
+ void* stack_args = freg_end;
// leave room for 'that' argument in x0
++ireg_args;
for (uint32_t i = 0; i < paramCount; i++, s++) {
- uint64_t word;
-
- if (s->IsPtrData()) {
- word = (uint64_t)s->ptr;
+ if (s->IsIndirect()) {
+ void* ptr = &s->val;
+ alloc_arg(ireg_args, ireg_end, stack_args, &ptr);
} else {
- // According to the ABI, integral types that are smaller than 8
- // bytes are to be passed in 8-byte registers or 8-byte stack
- // slots.
switch (s->type) {
case nsXPTType::T_FLOAT:
- alloc_float(freg_args, stack_args, freg_end, s->val.f);
- continue;
+ alloc_arg(freg_args, freg_end, stack_args, &s->val.f);
+ break;
case nsXPTType::T_DOUBLE:
- alloc_double(freg_args, stack_args, freg_end, s->val.d);
- continue;
- case nsXPTType::T_I8: word = s->val.i8; break;
- case nsXPTType::T_I16: word = s->val.i16; break;
- case nsXPTType::T_I32: word = s->val.i32; break;
- case nsXPTType::T_I64: word = s->val.i64; break;
- case nsXPTType::T_U8: word = s->val.u8; break;
- case nsXPTType::T_U16: word = s->val.u16; break;
- case nsXPTType::T_U32: word = s->val.u32; break;
- case nsXPTType::T_U64: word = s->val.u64; break;
- case nsXPTType::T_BOOL: word = s->val.b; break;
- case nsXPTType::T_CHAR: word = s->val.c; break;
- case nsXPTType::T_WCHAR: word = s->val.wc; break;
+ alloc_arg(freg_args, freg_end, stack_args, &s->val.d);
+ break;
+ case nsXPTType::T_I8:
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.i8);
+ break;
+ case nsXPTType::T_I16:
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.i16);
+ break;
+ case nsXPTType::T_I32:
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.i32);
+ break;
+ case nsXPTType::T_I64:
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.i64);
+ break;
+ case nsXPTType::T_U8:
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.u8);
+ break;
+ case nsXPTType::T_U16:
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.u16);
+ break;
+ case nsXPTType::T_U32:
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.u32);
+ break;
+ case nsXPTType::T_U64:
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.u64);
+ break;
+ case nsXPTType::T_BOOL:
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.b);
+ break;
+ case nsXPTType::T_CHAR:
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.c);
+ break;
+ case nsXPTType::T_WCHAR:
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.wc);
+ break;
default:
// all the others are plain pointer types
- word = reinterpret_cast<uint64_t>(s->val.p);
+ alloc_arg(ireg_args, ireg_end, stack_args, &s->val.p);
break;
}
}
-
- alloc_word(ireg_args, stack_args, ireg_end, word);
}
}