Skip to content

Commit c00d6e0

Browse files
committed
Merge remote-tracking branch 'origin/patch'
2 parents 7ec765c + 26b7540 commit c00d6e0

File tree

3 files changed

+61
-24
lines changed
  • Ghidra

3 files changed

+61
-24
lines changed

Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/C/C.jj

+50-22
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
8-
*
8+
*
99
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
10+
*
1111
* Unless required by applicable law or agreed to in writing, software
1212
* distributed under the License is distributed on an "AS IS" BASIS,
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -83,6 +83,7 @@ package ghidra.app.util.cparser.C;
8383

8484
import ghidra.program.model.data.*;
8585
import ghidra.program.model.data.Enum;
86+
import ghidra.program.model.lang.CompilerSpec;
8687
import ghidra.util.Msg;
8788
import ghidra.util.task.TaskMonitor;
8889
import ghidra.util.InvalidNameException;
@@ -656,24 +657,42 @@ public class CParser {
656657
* @param funcDT function data type to qualify
657658
*/
658659
private void applyFunctionQualifiers(Declaration dec, FunctionDefinition funcDT) {
659-
List<Integer> qualifierList = dec.getQualifiers();
660-
if (qualifierList.contains(NORETURN) ) {
661-
funcDT.setNoReturn(true);
662-
}
663-
// TODO: switch to setting calling convention by string identifier
664-
for (Integer qualifier : qualifierList) {
665-
switch (qualifier) {
666-
case CDECL:
667-
funcDT.setGenericCallingConvention(GenericCallingConvention.cdecl);
668-
break;
669-
case STDCALL:
670-
funcDT.setGenericCallingConvention(GenericCallingConvention.stdcall);
671-
break;
672-
case FASTCALL:
673-
funcDT.setGenericCallingConvention(GenericCallingConvention.fastcall);
674-
break;
675-
}
676-
}
660+
List<Integer> qualifierList = dec.getQualifiers();
661+
if (qualifierList.contains(NORETURN)) {
662+
funcDT.setNoReturn(true);
663+
}
664+
665+
String convention = null;
666+
for (Integer qualifier : qualifierList) {
667+
switch (qualifier) {
668+
case CDECL:
669+
convention = CompilerSpec.CALLING_CONVENTION_cdecl;
670+
break;
671+
case STDCALL:
672+
convention = CompilerSpec.CALLING_CONVENTION_stdcall;
673+
break;
674+
case FASTCALL:
675+
convention = CompilerSpec.CALLING_CONVENTION_fastcall;
676+
break;
677+
case VECTORCALL:
678+
convention = CompilerSpec.CALLING_CONVENTION_vectorcall;
679+
break;
680+
case RUSTCALL:
681+
convention = CompilerSpec.CALLING_CONVENTION_rustcall;
682+
break;
683+
case PASCALCALL:
684+
convention = CompilerSpec.CALLING_CONVENTION_pascal;
685+
break;
686+
}
687+
}
688+
if (convention != null) {
689+
try {
690+
funcDT.setCallingConvention(convention);
691+
}
692+
catch (InvalidInputException e) {
693+
// should not happen
694+
}
695+
}
677696
}
678697

679698
private Integer getConstantValue (Object obj, int defaultValue) {
@@ -1164,8 +1183,6 @@ TOKEN :
11641183
|
11651184
<CONST : ( [ "_" ] )* "const">
11661185
|
1167-
<CDECL : ( [ "_" ] )+ "cdecl">
1168-
|
11691186
<DECLSPEC : "__declspec">
11701187
|
11711188
<PRAGMA : "#" "pragma"> {parenNesting=-1; SwitchTo(PRAGMALINE); }
@@ -1174,10 +1191,18 @@ TOKEN :
11741191
|
11751192
<READABLETO : "__readableTo">
11761193
|
1194+
<CDECL : ( [ "_" ] )+ "cdecl">
1195+
|
11771196
<STDCALL : ( [ "_" ] )+ "stdcall">
11781197
|
11791198
<FASTCALL : ( [ "_" ] )+ "fastcall">
11801199
|
1200+
<VECTORCALL : ( [ "_" ] )+ "vectorcall">
1201+
|
1202+
<RUSTCALL : ( [ "_" ] )+ "rustcall">
1203+
|
1204+
<PASCALCALL : ( [ "_" ] )+ "pascal">
1205+
|
11811206
<NORETURN : "_Noreturn" >
11821207
|
11831208
<ALIGNAS : "_Alignas" >
@@ -1799,6 +1824,9 @@ Declaration TypeQualifier(Declaration dec) : {}
17991824
<FAR> |
18001825
<STDCALL> { dec.addQualifier(STDCALL); } |
18011826
<FASTCALL> { dec.addQualifier(FASTCALL); } |
1827+
<VECTORCALL> { dec.addQualifier(VECTORCALL); } |
1828+
<RUSTCALL> { dec.addQualifier(RUSTCALL); } |
1829+
<PASCALCALL> { dec.addQualifier(PASCALCALL); } |
18021830
<NORETURN> { dec.addQualifier(NORETURN); } |
18031831
<W64> |
18041832
<PTR64> |

Ghidra/Features/Base/src/test/resources/ghidra/app/util/cparser/CParserTest.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -149,8 +149,14 @@ void __cdecl _Once(_Once_t *, void (__cdecl *)(void));
149149

150150
void __stdcall _Twice(void (__cdecl *)(void));
151151

152+
void __vectorcall _Vect(void (__cdecl *)(void));
153+
154+
void __rustcall _Rusty(void (__cdecl *)(void));
155+
152156
void _Thrice(void (__cdecl *)(void));
153157

158+
void _Iron(void (__rustcall *)(void));
159+
154160
/**
155161
** use of long as an attribute
156162
**/

Ghidra/Processors/AARCH64/data/languages/AARCH64.opinion

+3
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@
2222
<constraint loader="Portable Executable (PE)" compilerSpecID="windows">
2323
<constraint primary="43620" processor="AARCH64" endian="little" size="64" variant="v8A" />
2424
</constraint>
25+
<constraint loader="MS Common Object File Format (COFF)" compilerSpecID="windows">
26+
<constraint primary="-21916" processor="AARCH64" endian="little" size="64" variant="v8A" />
27+
</constraint>
2528
</opinions>

0 commit comments

Comments
 (0)