1
1
// RUN: %empty-directory(%t)
2
- // RUN: %clang %s -isysroot %sdk -o %t/main
2
+ // RUN: %target- clang %s -std=c++11 -isysroot %sdk -o %t/main
3
3
// RUN: %target-codesign %t/main
4
4
// RUN: %target-build-swift %S/Inputs/at-main-struct-simple.swift -O -parse-as-library -emit-library -o %t/libHowdy.dylib -module-name Howdy
5
+ // RUN: %target-codesign %t/libHowdy.dylib
5
6
// RUN: %target-run %t/main %t/libHowdy.dylib | %FileCheck %s
6
7
7
- // REQUIRES: OS=macosx,CPU=x86_64
8
+ // REQUIRES: VENDOR=apple
8
9
// REQUIRES: executable_test
9
10
// UNSUPPORTED: remote_run
10
11
13
14
#include < mach-o/getsect.h>
14
15
#include < stdio.h>
15
16
#include < string.h>
17
+ #include < ptrauth.h>
18
+
19
+ #if __POINTER_WIDTH__ == 64
20
+ using mach_header_platform = mach_header_64;
21
+ #else
22
+ using mach_header_platform = mach_header;
23
+ #endif
16
24
17
25
int main (int argc, char *argv[]) {
18
26
if (argc != 2 ) {
@@ -35,12 +43,19 @@ int main(int argc, char *argv[]) {
35
43
continue ;
36
44
}
37
45
auto *header =
38
- reinterpret_cast <const mach_header_64 *>(_dyld_get_image_header (index));
46
+ reinterpret_cast <const mach_header_platform *>(_dyld_get_image_header (index));
39
47
size_t size;
40
48
auto *data = getsectiondata (header, " __TEXT" , " __swift5_entry" , &size);
41
49
int32_t offset = *reinterpret_cast <int32_t *>(data);
42
50
mainFunction = reinterpret_cast <MainFunction *>(
43
- reinterpret_cast <int64_t >(data) + offset);
51
+ ptrauth_sign_unauthenticated (
52
+ reinterpret_cast <void *>(
53
+ reinterpret_cast <long >(data) + offset
54
+ ),
55
+ ptrauth_key_function_pointer,
56
+ ptrauth_function_pointer_type_discriminator (MainFunction)
57
+ )
58
+ );
44
59
45
60
break ;
46
61
}
0 commit comments