Skip to content

Commit

Permalink
tests: Wire up macOS/arm64(e) cross-arch logic
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed May 3, 2024
1 parent 337b863 commit 84cc761
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
10 changes: 5 additions & 5 deletions tests/process-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ frida_test_process_backend_create (const char * path, gchar ** argv,
# elif defined (HAVE_ARM)
pref = (arch == FRIDA_TEST_ARCH_CURRENT) ? CPU_TYPE_ARM : CPU_TYPE_ARM64;
# elif defined (HAVE_ARM64)
# if __has_feature (ptrauth_calls)
pref = CPU_TYPE_ARM64;
# if __has_feature (ptrauth_calls)
if (arch == FRIDA_TEST_ARCH_CURRENT)
# else
if (arch == FRIDA_TEST_ARCH_OTHER)
# endif
{
special_path = g_strconcat (path, "64", NULL);
special_path = g_strconcat (path, "-arm64e", NULL);
path = special_path;
}
# else
pref = (arch == FRIDA_TEST_ARCH_CURRENT) ? CPU_TYPE_ARM64 : CPU_TYPE_ARM;
# endif
# endif
posix_spawnattr_setbinpref_np (&attr, 1, &pref, &ocount);

Expand Down
39 changes: 24 additions & 15 deletions tests/runner.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ namespace Frida.Test {
public static void run (string[] args) {
Environment.init (ref args);

if (os () == MACOS) {
switch (cpu ()) {
case ARM_64:
can_test_cross_arch_injection = false;
break;
case X86_64:
try {
if (can_test_cross_arch_injection && os () == MACOS) {
try {
switch (cpu ()) {
case ARM_64:
if (Gum.query_ptrauth_support () == UNSUPPORTED) {
string output;
GLib.Process.spawn_command_line_sync ("nvram boot-args", out output);

string[] tokens = output.strip ().split ("\t");
assert (tokens.length == 2);

unowned string boot_args = tokens[1];

can_test_cross_arch_injection = "-arm64e_preview_abi" in boot_args;
}
break;
case X86_64:
string raw_version;
GLib.Process.spawn_command_line_sync ("sw_vers -productVersion", out raw_version);

Expand All @@ -29,14 +39,13 @@ namespace Frida.Test {
uint minor = uint.parse (tokens[1]);

bool newer_than_mojave = major > 10 || (major == 10 && minor > 4);
if (newer_than_mojave)
can_test_cross_arch_injection = false;
} catch (GLib.Error e) {
assert_not_reached ();
}
break;
default:
break;
can_test_cross_arch_injection = !newer_than_mojave;
break;
default:
break;
}
} catch (GLib.Error e) {
assert_not_reached ();
}
}

Expand Down
10 changes: 8 additions & 2 deletions tests/test-host-session.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2146,7 +2146,10 @@ namespace Frida.HostSessionTest {
switch (Frida.Test.os ())
{
case Frida.Test.OS.MACOS:
suffix = "macos";
if (Frida.Test.cpu () == ARM_64)
suffix = (Gum.query_ptrauth_support () == SUPPORTED) ? "macos-arm64e" : "macos";
else
suffix = "macos";
break;
case Frida.Test.OS.TVOS:
suffix = "tvos";
Expand All @@ -2162,7 +2165,10 @@ namespace Frida.HostSessionTest {
private static string target_name_of_other (string name) {
string suffix;
if (Frida.Test.os () == Frida.Test.OS.MACOS) {
suffix = "macos32";
if (Frida.Test.cpu () == ARM_64)
suffix = (Gum.query_ptrauth_support () == SUPPORTED) ? "macos" : "macos-arm64e";
else
suffix = "macos32";
} else {
suffix = (Gum.query_ptrauth_support () == SUPPORTED) ? "ios64" : "ios32";
}
Expand Down

0 comments on commit 84cc761

Please sign in to comment.