From bd7cd64dbf115e80abd1369914fda54f63fb3b2b Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sun, 18 Jul 2021 21:23:40 +0200 Subject: [PATCH 1/3] Add support for ARM64 varargs calling convention --- src/providers/provider.tt | 95 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 4 deletions(-) diff --git a/src/providers/provider.tt b/src/providers/provider.tt index d21fd0a5..4552b022 100644 --- a/src/providers/provider.tt +++ b/src/providers/provider.tt @@ -57,6 +57,15 @@ namespace SQLitePCL { const CallingConvention CALLING_CONVENTION = CallingConvention.<#= CONV #>; +<# + if (KIND != "cil") + { +#> + static readonly bool IsArm64cc = RuntimeInformation.ProcessArchitecture == Architecture.Arm64; +<# + } +#> + <# if (KIND == "dynamic") { @@ -757,6 +766,16 @@ namespace SQLitePCL <#= KIND=="cil"?"unsafe ":"" #>int ISQLite3Provider.sqlite3_config(int op, int val) { +<# + if (KIND != "cil") + { +#> + if (IsArm64cc) + return NativeMethods.sqlite3_config_int_arm64cc(op, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, val); + +<# + } +#> return NativeMethods.sqlite3_config_int(op, val); } @@ -764,6 +783,16 @@ namespace SQLitePCL { fixed (byte* p_val = val) { +<# + if (KIND != "cil") + { +#> + if (IsArm64cc) + return NativeMethods.sqlite3_db_config_charptr_arm64cc(db, op, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, p_val); + +<# + } +#> return NativeMethods.sqlite3_db_config_charptr(db, op, p_val); } } @@ -771,7 +800,19 @@ namespace SQLitePCL unsafe int ISQLite3Provider.sqlite3_db_config(sqlite3 db, int op, int val, out int result) { int out_result = 0; - int native_result = NativeMethods.sqlite3_db_config_int_outint(db, op, val, &out_result); + int native_result; + +<# + if (KIND != "cil") + { +#> + if (IsArm64cc) + native_result = NativeMethods.sqlite3_db_config_int_outint_arm64cc(db, op, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, val, &out_result); + else +<# + } +#> + native_result = NativeMethods.sqlite3_db_config_int_outint(db, op, val, &out_result); result = out_result; @@ -780,6 +821,16 @@ namespace SQLitePCL <#= KIND=="cil"?"unsafe ":"" #> int ISQLite3Provider.sqlite3_db_config(sqlite3 db, int op, IntPtr ptr, int int0, int int1) { +<# + if (KIND != "cil") + { +#> + if (IsArm64cc) + return NativeMethods.sqlite3_db_config_intptr_int_int_arm64cc(db, op, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, ptr, int0, int1); + +<# + } +#> return NativeMethods.sqlite3_db_config_intptr_int_int(db, op, ptr, int0, int1); } @@ -937,8 +988,16 @@ namespace SQLitePCL } var h = new hook_handle(hi); disp_log_hook_handle = h; // TODO if valid - var rc = NativeMethods.sqlite3_config_log(raw.SQLITE_CONFIG_LOG, <#= get_cb_arg("cb") #>, h); - return rc; +<# + if (KIND != "cil") + { +#> + if (IsArm64cc) + return NativeMethods.sqlite3_config_log_arm64cc(raw.SQLITE_CONFIG_LOG, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, <#= get_cb_arg("cb") #>, h); +<# + } +#> + return NativeMethods.sqlite3_config_log(raw.SQLITE_CONFIG_LOG, <#= get_cb_arg("cb") #>, h); } unsafe void ISQLite3Provider.sqlite3_log(int errcode, utf8z s) @@ -3109,6 +3168,12 @@ namespace SQLitePCL #> <#= s #> = (MyDelegateTypes.<#= s #>) Load(gf, typeof(MyDelegateTypes.<#= s #>)); <#+ + if (f.varargs && f.extra_parms != null) + { +#> + <#= s #>_arm64cc = (MyDelegateTypes.<#= s #>_arm64cc) Load(gf, typeof(MyDelegateTypes.<#= s #>_arm64cc)); +<#+ + } } #> } @@ -3120,6 +3185,12 @@ namespace SQLitePCL #> public static MyDelegateTypes.<#= s #> <#= s #>; <#+ + if (f.varargs && f.extra_parms != null) + { +#> + public static MyDelegateTypes.<#= s #>_arm64cc <#= s #>_arm64cc; +<#+ + } } } void write_callback_delegates() @@ -3171,7 +3242,7 @@ namespace SQLitePCL void write_api_entries(string k) { - System.Collections.Generic.List get_parm_list(Function f) + System.Collections.Generic.List get_parm_list(Function f, bool arm64cc = false) { string get_fixed_parm_type(Parm p) { @@ -3210,6 +3281,13 @@ namespace SQLitePCL } if (f.varargs && f.extra_parms != null) { + if (arm64cc) + { + for (int i = a_parms.Count; i < 8; i++) + { + a_parms.Add("IntPtr dummy" + i); + } + } foreach (var p in f.extra_parms) { if (p.isOut) throw new Exception(); @@ -3472,11 +3550,20 @@ namespace SQLitePCL { throw new NotImplementedException(); } + #> <#= attr #> <#= front #> <#= f.ret #> <#= f.nam #>(<#= string.Join(", ", a_parms) #>); <#+ + if (f.varargs && f.extra_parms != null) + { +#> + <#= attr #> + <#= front #> <#= f.ret #> <#= f.nam #>_arm64cc(<#= string.Join(", ", get_parm_list(f, arm64cc: true)) #>); + +<#+ + } } } From e91bb9940b5bc84286259ee5962dcb1c88b61b47 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Fri, 12 Nov 2021 21:50:51 +0100 Subject: [PATCH 2/3] Change the condition to target only macOS and iOS --- src/providers/provider.tt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/providers/provider.tt b/src/providers/provider.tt index 4552b022..3dfe9c69 100644 --- a/src/providers/provider.tt +++ b/src/providers/provider.tt @@ -61,7 +61,9 @@ namespace SQLitePCL if (KIND != "cil") { #> - static readonly bool IsArm64cc = RuntimeInformation.ProcessArchitecture == Architecture.Arm64; + static readonly bool IsArm64cc = + RuntimeInformation.ProcessArchitecture == Architecture.Arm64 && + (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS"))); <# } #> From 13cb1b29202fde53503ee85fbee2b11a48d2467c Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Fri, 12 Nov 2021 21:52:14 +0100 Subject: [PATCH 3/3] Match the whitespace --- src/providers/provider.tt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/providers/provider.tt b/src/providers/provider.tt index 3dfe9c69..e29c6a5d 100644 --- a/src/providers/provider.tt +++ b/src/providers/provider.tt @@ -62,8 +62,8 @@ namespace SQLitePCL { #> static readonly bool IsArm64cc = - RuntimeInformation.ProcessArchitecture == Architecture.Arm64 && - (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS"))); + RuntimeInformation.ProcessArchitecture == Architecture.Arm64 && + (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS"))); <# } #>