Skip to content

Commit

Permalink
Merge pull request #425 from emclient/arm64cc
Browse files Browse the repository at this point in the history
Add support for ARM64 varargs calling convention
  • Loading branch information
ericsink authored Nov 23, 2021
2 parents c851e23 + 13cb1b2 commit 3cba065
Showing 1 changed file with 93 additions and 4 deletions.
97 changes: 93 additions & 4 deletions src/providers/provider.tt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ namespace SQLitePCL
{
const CallingConvention CALLING_CONVENTION = CallingConvention.<#= CONV #>;

<#
if (KIND != "cil")
{
#>
static readonly bool IsArm64cc =
RuntimeInformation.ProcessArchitecture == Architecture.Arm64 &&
(RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")));
<#
}
#>

<#
if (KIND == "dynamic")
{
Expand Down Expand Up @@ -743,21 +754,53 @@ namespace SQLitePCL

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);
}

unsafe int ISQLite3Provider.sqlite3_db_config(sqlite3 db, int op, utf8z val)
{
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);
}
}

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;

Expand All @@ -766,6 +809,16 @@ namespace SQLitePCL

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);
}

Expand Down Expand Up @@ -923,8 +976,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)
Expand Down Expand Up @@ -3088,6 +3149,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));
<#+
}
}
#>
}
Expand All @@ -3099,6 +3166,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()
Expand Down Expand Up @@ -3150,7 +3223,7 @@ namespace SQLitePCL

void write_api_entries(string k)
{
System.Collections.Generic.List<string> get_parm_list(Function f)
System.Collections.Generic.List<string> get_parm_list(Function f, bool arm64cc = false)
{
string get_fixed_parm_type(Parm p)
{
Expand All @@ -3165,6 +3238,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();
Expand Down Expand Up @@ -3239,11 +3319,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)) #>);

<#+
}
}
}

Expand Down

0 comments on commit 3cba065

Please sign in to comment.