Skip to content

Commit 9ae17f9

Browse files
committed
C#: Stub generator support for function pointer types.
1 parent e2882f0 commit 9ae17f9

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

csharp/ql/lib/semmle/code/csharp/Type.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,16 @@ class VarArgsCallingConvention extends CallingConvention {
935935
override string toString() { result = "VarArgsCallingConvention" }
936936
}
937937

938+
/**
939+
* Unmanaged calling convention that indicates that the specifics
940+
* are encoded as modopts.
941+
*/
942+
class UnmanagedCallingConvention extends CallingConvention {
943+
UnmanagedCallingConvention() { this = MkCallingConvention(9) }
944+
945+
override string toString() { result = "UnmanagedCallingConvention" }
946+
}
947+
938948
/**
939949
* A function pointer type, for example
940950
*

csharp/ql/src/Stubs/Stubs.qll

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,30 @@ private string stubClassName(Type t) {
513513
stubClassName(element), "," order by i
514514
) + ")"
515515
else
516-
if t instanceof ValueOrRefType
516+
if t instanceof FunctionPointerType
517517
then
518-
result =
519-
stubQualifiedNamePrefix(t) + t.getUndecoratedName() +
520-
stubGenericArguments(t)
521-
else result = "<error>"
518+
exists(CallingConvention callconvention, string calltext |
519+
callconvention = t.(FunctionPointerType).getCallingConvention() and
520+
(
521+
if callconvention instanceof UnmanagedCallingConvention
522+
then calltext = "unmanaged"
523+
else calltext = ""
524+
) and
525+
result =
526+
"delegate* " + calltext + "<" +
527+
concat(int i, Parameter p |
528+
p = t.(FunctionPointerType).getParameter(i)
529+
|
530+
stubClassName(p.getType()) + "," order by i
531+
) + stubClassName(t.(FunctionPointerType).getReturnType()) + ">"
532+
)
533+
else
534+
if t instanceof ValueOrRefType
535+
then
536+
result =
537+
stubQualifiedNamePrefix(t) + t.getUndecoratedName() +
538+
stubGenericArguments(t)
539+
else result = "<error>"
522540
}
523541

524542
language[monotonicAggregates]

0 commit comments

Comments
 (0)