Skip to content

Commit 16eda37

Browse files
committed
GP-5216 Correct calling convention name checks and BSim apply signature
1 parent 420dd7c commit 16eda37

File tree

5 files changed

+40
-41
lines changed

5 files changed

+40
-41
lines changed

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/EditFunctionSignatureDialog.java

+16-18
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.
@@ -22,11 +22,9 @@
2222
import ghidra.app.cmd.function.FunctionRenameOption;
2323
import ghidra.framework.cmd.Command;
2424
import ghidra.framework.cmd.CompoundCmd;
25-
import ghidra.framework.model.DomainObject;
2625
import ghidra.framework.plugintool.PluginTool;
2726
import ghidra.program.model.data.*;
28-
import ghidra.program.model.listing.Function;
29-
import ghidra.program.model.listing.FunctionSignature;
27+
import ghidra.program.model.listing.*;
3028
import ghidra.program.model.symbol.SourceType;
3129
import ghidra.util.Msg;
3230
import ghidra.util.exception.CancelledException;
@@ -148,7 +146,7 @@ private static boolean allowCallFixup(Function function) {
148146
@Override
149147
protected boolean applyChanges() throws CancelledException {
150148
// create the command
151-
Command command = createCommand();
149+
Command<Program> command = createCommand();
152150

153151
if (command == null) {
154152
return false;
@@ -164,9 +162,9 @@ protected boolean applyChanges() throws CancelledException {
164162
return true;
165163
}
166164

167-
private Command createCommand() throws CancelledException {
165+
private Command<Program> createCommand() throws CancelledException {
168166

169-
Command cmd = null;
167+
Command<Program> cmd = null;
170168
if (isSignatureChanged() || isCallingConventionChanged() ||
171169
(function.getSignatureSource() == SourceType.DEFAULT)) {
172170

@@ -179,20 +177,20 @@ private Command createCommand() throws CancelledException {
179177
FunctionRenameOption.RENAME);
180178
}
181179

182-
CompoundCmd compoundCommand = new CompoundCmd("Update Function Signature");
180+
CompoundCmd<Program> compoundCommand = new CompoundCmd<>("Update Function Signature");
183181

184-
compoundCommand.add(new Command() {
182+
compoundCommand.add(new Command<Program>() {
185183
String errMsg = null;
186184

187185
@Override
188-
public boolean applyTo(DomainObject obj) {
186+
public boolean applyTo(Program p) {
189187
try {
190188
String conventionName = getCallingConvention();
191189
function.setCallingConvention(conventionName);
192190
return true;
193191
}
194192
catch (InvalidInputException e) {
195-
errMsg = "Invalid calling convention. " + e.getMessage();
193+
errMsg = e.getMessage();
196194
Msg.error(this, "Unexpected Exception: " + e.getMessage(), e);
197195
return false;
198196
}
@@ -209,9 +207,9 @@ public String getStatusMsg() {
209207
}
210208
});
211209
if (allowInLine) {
212-
compoundCommand.add(new Command() {
210+
compoundCommand.add(new Command<Program>() {
213211
@Override
214-
public boolean applyTo(DomainObject obj) {
212+
public boolean applyTo(Program p) {
215213
function.setInline(isInlineSelected());
216214
return true;
217215
}
@@ -228,9 +226,9 @@ public String getStatusMsg() {
228226
});
229227
}
230228
if (allowNoReturn) {
231-
compoundCommand.add(new Command() {
229+
compoundCommand.add(new Command<Program>() {
232230
@Override
233-
public boolean applyTo(DomainObject obj) {
231+
public boolean applyTo(Program p) {
234232
function.setNoReturn(hasNoReturnSelected());
235233
return true;
236234
}
@@ -247,9 +245,9 @@ public String getStatusMsg() {
247245
});
248246
}
249247
if (allowCallFixup) {
250-
compoundCommand.add(new Command() {
248+
compoundCommand.add(new Command<Program>() {
251249
@Override
252-
public boolean applyTo(DomainObject obj) {
250+
public boolean applyTo(Program p) {
253251
function.setCallFixup(getCallFixupSelection());
254252
return true;
255253
}

Ghidra/Features/Base/src/main/java/ghidra/program/util/FunctionUtility.java

+13-3
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.
@@ -380,7 +380,17 @@ private static String determineCallingConventionName(Function destinationFunctio
380380
if (CompilerSpec.CALLING_CONVENTION_thiscall.equals(sourceConv)) {
381381
return sourceConv;
382382
}
383-
return sameLanguageAndCompilerSpec ? sourceFunction.getCallingConventionName()
383+
boolean applyConventionName = sameLanguageAndCompilerSpec;
384+
if (applyConventionName) {
385+
DataTypeManager dtMgr = destinationFunction.getProgram().getDataTypeManager();
386+
String name = destinationFunction.getCallingConventionName();
387+
if (GenericCallingConvention
388+
.getGenericCallingConvention(name) == GenericCallingConvention.unknown &&
389+
!dtMgr.getKnownCallingConventionNames().contains(name)) {
390+
applyConventionName = false;
391+
}
392+
}
393+
return applyConventionName ? sourceFunction.getCallingConventionName()
384394
: destinationFunction.getCallingConventionName();
385395
}
386396

Ghidra/Features/Decompiler/src/main/java/ghidra/app/cmd/function/DecompilerParameterIdCmd.java

+4-4
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.
@@ -314,8 +314,8 @@ private void checkModelNameConsistency(Function func) {
314314
func.setCallingConvention(CompilerSpec.CALLING_CONVENTION_cdecl);
315315
}
316316
catch (InvalidInputException e) {
317-
setStatusMsg("Invalid Calling Convention " + CompilerSpec.CALLING_CONVENTION_cdecl +
318-
" : " + e);
317+
setStatusMsg(
318+
"Unknown calling convention: " + CompilerSpec.CALLING_CONVENTION_cdecl);
319319
}
320320
}
321321
}

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -4144,10 +4144,9 @@ public byte getCallingConventionID(String name, boolean restrictive)
41444144
if (restrictive &&
41454145
GenericCallingConvention
41464146
.getGenericCallingConvention(name) == GenericCallingConvention.unknown &&
4147-
!getKnownCallingConventionNames().contains(name) &&
4148-
getCallingConvention(name) == null) {
4147+
!getKnownCallingConventionNames().contains(name)) {
41494148

4150-
throw new InvalidInputException("Invalid calling convention name: " + name);
4149+
throw new InvalidInputException("Unknown calling convention name: " + name);
41514150
}
41524151

41534152
return callingConventionAdapter.getCallingConventionId(name,

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/FunctionDefinitionDataType.java

+5-13
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.
@@ -188,17 +188,9 @@ public void setCallingConvention(String conventionName) throws InvalidInputExcep
188188
}
189189

190190
if (GenericCallingConvention
191-
.getGenericCallingConvention(conventionName) != GenericCallingConvention.unknown) {
192-
ProgramArchitecture arch = dataMgr != null ? dataMgr.getProgramArchitecture() : null;
193-
if (arch != null) {
194-
CompilerSpec compilerSpec = arch.getCompilerSpec();
195-
PrototypeModel callingConvention =
196-
compilerSpec.getCallingConvention(conventionName);
197-
if (callingConvention == null) {
198-
throw new InvalidInputException(
199-
"Invalid calling convention name: " + conventionName);
200-
}
201-
}
191+
.getGenericCallingConvention(conventionName) == GenericCallingConvention.unknown &&
192+
!dataMgr.getKnownCallingConventionNames().contains(name)) {
193+
throw new InvalidInputException("Unknown calling convention name: " + conventionName);
202194
}
203195

204196
this.callingConventionName = conventionName;

0 commit comments

Comments
 (0)