45 * ABI implementation for macOS on Apple silicon. Based on AAPCS with
46 * changes to va_list and passing arguments on the stack.
47 */
48 public final class MacOsAArch64Linker implements CLinker {
49 private static MacOsAArch64Linker instance;
50
51 static final long ADDRESS_SIZE = 64; // bits
52
53 public static MacOsAArch64Linker getInstance() {
54 if (instance == null) {
55 instance = new MacOsAArch64Linker();
56 }
57 return instance;
58 }
59
60 @Override
61 public final MethodHandle downcallHandle(FunctionDescriptor function) {
62 Objects.requireNonNull(function);
63 MethodType type = SharedUtils.inferMethodType(function, false);
64 MethodHandle handle = CallArranger.MACOS.arrangeDowncall(type, function);
65 if (!type.returnType().equals(MemorySegment.class)) {
66 // not returning segment, just insert a throwing allocator
67 handle = MethodHandles.insertArguments(handle, 1, SharedUtils.THROWING_ALLOCATOR);
68 }
69 return SharedUtils.wrapDowncall(handle, function);
70 }
71
72 @Override
73 public final NativeSymbol upcallStub(MethodHandle target, FunctionDescriptor function, ResourceScope scope) {
74 Objects.requireNonNull(scope);
75 Objects.requireNonNull(target);
76 Objects.requireNonNull(function);
77 MethodType type = SharedUtils.inferMethodType(function, true);
78 if (!type.equals(target.type())) {
79 throw new IllegalArgumentException("Wrong method handle type: " + target.type());
80 }
81 return CallArranger.MACOS.arrangeUpcall(target, target.type(), function, scope);
82 }
83
84 public static VaList newVaList(Consumer<VaList.Builder> actions, ResourceScope scope) {
85 MacOsAArch64VaList.Builder builder = MacOsAArch64VaList.builder(scope);
86 actions.accept(builder);
87 return builder.build();
88 }
|
45 * ABI implementation for macOS on Apple silicon. Based on AAPCS with
46 * changes to va_list and passing arguments on the stack.
47 */
48 public final class MacOsAArch64Linker implements CLinker {
49 private static MacOsAArch64Linker instance;
50
51 static final long ADDRESS_SIZE = 64; // bits
52
53 public static MacOsAArch64Linker getInstance() {
54 if (instance == null) {
55 instance = new MacOsAArch64Linker();
56 }
57 return instance;
58 }
59
60 @Override
61 public final MethodHandle downcallHandle(FunctionDescriptor function) {
62 Objects.requireNonNull(function);
63 MethodType type = SharedUtils.inferMethodType(function, false);
64 MethodHandle handle = CallArranger.MACOS.arrangeDowncall(type, function);
65 handle = SharedUtils.maybeInsertAllocator(handle);
66 return SharedUtils.wrapDowncall(handle, function);
67 }
68
69 @Override
70 public final NativeSymbol upcallStub(MethodHandle target, FunctionDescriptor function, ResourceScope scope) {
71 Objects.requireNonNull(scope);
72 Objects.requireNonNull(target);
73 Objects.requireNonNull(function);
74 MethodType type = SharedUtils.inferMethodType(function, true);
75 if (!type.equals(target.type())) {
76 throw new IllegalArgumentException("Wrong method handle type: " + target.type());
77 }
78 return CallArranger.MACOS.arrangeUpcall(target, target.type(), function, scope);
79 }
80
81 public static VaList newVaList(Consumer<VaList.Builder> actions, ResourceScope scope) {
82 MacOsAArch64VaList.Builder builder = MacOsAArch64VaList.builder(scope);
83 actions.accept(builder);
84 return builder.build();
85 }
|