diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/objc/src/message/apple | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/objc/src/message/apple')
-rw-r--r-- | third_party/rust/objc/src/message/apple/arm.rs | 40 | ||||
-rw-r--r-- | third_party/rust/objc/src/message/apple/arm64.rs | 18 | ||||
-rw-r--r-- | third_party/rust/objc/src/message/apple/mod.rs | 40 | ||||
-rw-r--r-- | third_party/rust/objc/src/message/apple/x86.rs | 40 | ||||
-rw-r--r-- | third_party/rust/objc/src/message/apple/x86_64.rs | 32 |
5 files changed, 170 insertions, 0 deletions
diff --git a/third_party/rust/objc/src/message/apple/arm.rs b/third_party/rust/objc/src/message/apple/arm.rs new file mode 100644 index 0000000000..d26defc0de --- /dev/null +++ b/third_party/rust/objc/src/message/apple/arm.rs @@ -0,0 +1,40 @@ +use std::any::{Any, TypeId}; +use std::mem; + +use runtime::Imp; + +extern { + fn objc_msgSend(); + fn objc_msgSend_stret(); + + fn objc_msgSendSuper(); + fn objc_msgSendSuper_stret(); +} + +pub fn msg_send_fn<R: Any>() -> Imp { + // Double-word sized fundamental data types don't use stret, + // but any composite type larger than 4 bytes does. + // <http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf> + + let type_id = TypeId::of::<R>(); + if mem::size_of::<R>() <= 4 || + type_id == TypeId::of::<i64>() || + type_id == TypeId::of::<u64>() || + type_id == TypeId::of::<f64>() { + objc_msgSend + } else { + objc_msgSend_stret + } +} + +pub fn msg_send_super_fn<R: Any>() -> Imp { + let type_id = TypeId::of::<R>(); + if mem::size_of::<R>() <= 4 || + type_id == TypeId::of::<i64>() || + type_id == TypeId::of::<u64>() || + type_id == TypeId::of::<f64>() { + objc_msgSendSuper + } else { + objc_msgSendSuper_stret + } +} diff --git a/third_party/rust/objc/src/message/apple/arm64.rs b/third_party/rust/objc/src/message/apple/arm64.rs new file mode 100644 index 0000000000..54cfc897c5 --- /dev/null +++ b/third_party/rust/objc/src/message/apple/arm64.rs @@ -0,0 +1,18 @@ +use runtime::Imp; + +extern { + fn objc_msgSend(); + + fn objc_msgSendSuper(); +} + +pub fn msg_send_fn<R>() -> Imp { + // stret is not even available in arm64. + // <https://twitter.com/gparker/status/378079715824660480> + + objc_msgSend +} + +pub fn msg_send_super_fn<R>() -> Imp { + objc_msgSendSuper +} diff --git a/third_party/rust/objc/src/message/apple/mod.rs b/third_party/rust/objc/src/message/apple/mod.rs new file mode 100644 index 0000000000..30f59ca870 --- /dev/null +++ b/third_party/rust/objc/src/message/apple/mod.rs @@ -0,0 +1,40 @@ +use std::any::Any; + +use runtime::{Class, Object, Sel}; +use super::{Message, MessageArguments, MessageError, Super}; + +#[cfg(target_arch = "x86")] +#[path = "x86.rs"] +mod arch; +#[cfg(target_arch = "x86_64")] +#[path = "x86_64.rs"] +mod arch; +#[cfg(target_arch = "arm")] +#[path = "arm.rs"] +mod arch; +#[cfg(target_arch = "aarch64")] +#[path = "arm64.rs"] +mod arch; + +use self::arch::{msg_send_fn, msg_send_super_fn}; + +pub unsafe fn send_unverified<T, A, R>(obj: *const T, sel: Sel, args: A) + -> Result<R, MessageError> + where T: Message, A: MessageArguments, R: Any { + let receiver = obj as *mut T as *mut Object; + let msg_send_fn = msg_send_fn::<R>(); + objc_try!({ + A::invoke(msg_send_fn, receiver, sel, args) + }) +} + +pub unsafe fn send_super_unverified<T, A, R>(obj: *const T, superclass: &Class, + sel: Sel, args: A) -> Result<R, MessageError> + where T: Message, A: MessageArguments, R: Any { + let sup = Super { receiver: obj as *mut T as *mut Object, superclass: superclass }; + let receiver = &sup as *const Super as *mut Object; + let msg_send_fn = msg_send_super_fn::<R>(); + objc_try!({ + A::invoke(msg_send_fn, receiver, sel, args) + }) +} diff --git a/third_party/rust/objc/src/message/apple/x86.rs b/third_party/rust/objc/src/message/apple/x86.rs new file mode 100644 index 0000000000..93422de24b --- /dev/null +++ b/third_party/rust/objc/src/message/apple/x86.rs @@ -0,0 +1,40 @@ +use std::any::{Any, TypeId}; +use std::mem; + +use runtime::Imp; + +extern { + fn objc_msgSend(); + fn objc_msgSend_fpret(); + fn objc_msgSend_stret(); + + fn objc_msgSendSuper(); + fn objc_msgSendSuper_stret(); +} + +pub fn msg_send_fn<R: Any>() -> Imp { + // Structures 1 or 2 bytes in size are placed in EAX. + // Structures 4 or 8 bytes in size are placed in: EAX and EDX. + // Structures of other sizes are placed at the address supplied by the caller. + // <https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html> + + let type_id = TypeId::of::<R>(); + let size = mem::size_of::<R>(); + if type_id == TypeId::of::<f32>() || + type_id == TypeId::of::<f64>() { + objc_msgSend_fpret + } else if size == 0 || size == 1 || size == 2 || size == 4 || size == 8 { + objc_msgSend + } else { + objc_msgSend_stret + } +} + +pub fn msg_send_super_fn<R: Any>() -> Imp { + let size = mem::size_of::<R>(); + if size == 0 || size == 1 || size == 2 || size == 4 || size == 8 { + objc_msgSendSuper + } else { + objc_msgSendSuper_stret + } +} diff --git a/third_party/rust/objc/src/message/apple/x86_64.rs b/third_party/rust/objc/src/message/apple/x86_64.rs new file mode 100644 index 0000000000..49c90ce53e --- /dev/null +++ b/third_party/rust/objc/src/message/apple/x86_64.rs @@ -0,0 +1,32 @@ +use std::mem; + +use runtime::Imp; + +extern { + fn objc_msgSend(); + fn objc_msgSend_stret(); + + fn objc_msgSendSuper(); + fn objc_msgSendSuper_stret(); +} + +pub fn msg_send_fn<R>() -> Imp { + // If the size of an object is larger than two eightbytes, it has class MEMORY. + // If the type has class MEMORY, then the caller provides space for the return + // value and passes the address of this storage. + // <http://people.freebsd.org/~obrien/amd64-elf-abi.pdf> + + if mem::size_of::<R>() <= 16 { + objc_msgSend + } else { + objc_msgSend_stret + } +} + +pub fn msg_send_super_fn<R>() -> Imp { + if mem::size_of::<R>() <= 16 { + objc_msgSendSuper + } else { + objc_msgSendSuper_stret + } +} |