x86: uint32_t keeps changing to 2 bytes in function signature
See original GitHub issueDescribe the bug When editing a function, uint32_t, when formed by AX:BX or CX:DX, keeps changing to 2 bytes.
To Reproduce Steps to reproduce the behavior:
- Disassemble TELEN.EXE (from https://www.dosgamesarchive.com/download/telengard/)
- Go to
1000:ac13
. This is theidiv32
function. - Attempt to edit its function signature to
uint32_t __cdecl16near idiv32(uint32_t x, uint32_t y)
with custom storage, either in the decompilation window or in the listing window. You can initially set the storage for x to AX and BX, and for y to CX and DX. However, any attempt to set the return type to uint32_t and its storage to AX and BX will result in a “too much storage” error, because for some reason Ghidra thinks that a return type of uint32_t is only 2 bytes.
Expected behavior A return type of uint32_t is 4 bytes, and its storage can be allocated to two 16-bit registers.
Screenshots
Environment (please complete the following information):
- OS: Windows 10
- Java Version: 11.0
- Ghidra Version: 9.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Can I assume the size of long int is always 4 bytes?
However on machine with e.g. CHAR_BIT equal to 16, a long int could be 2 bytes long. Here's a real-world example. For the...
Read more >Types and signatures - Numba
A signature specifies the type of a function. Exactly which kind of signature is allowed depends on the context (AOT or JIT compilation),...
Read more >Detecting Memory (x86) - OSDev Wiki
It is the only BIOS function that can detect memory areas above 4G. ... of an entry is 2 uint64_t's and a uint32_t...
Read more >htons(), htonl(), ntohs(), ntohl() - GTA/UFRJ
Convert multi-byte integer types from host byte order to network byte order ... The upshot of this is that if you send() a...
Read more >X64 Function Hooking by Example - Kyle Halladay
The other two will use those same concepts to hook MSPaint and ... The real fun of function hooking is that you can...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Totally makes sense, and I think we’re basically on the same page. Apologies for not checking out the Digital Mars code immediately - interesting example, definitely not the norm.
You make a good case for adding the C99 types as Builtins. That might avoid a lot of general confusion. We have things that are obviously close to being equivalent, e.g the DWord
and UnsignedIntegerBuiltins are defined to be 4 bytes in length (admittedly, not necessarily 32 bits). The question, I think, is whether adding the C99 types as Builtins will create confusion or conflict with defined types with identical names, but obviously for things like uint32_t with a pretty clear definition adding them might be reasonable.Will raise this with the team and get back to you. Thanks!
Follow on: going to correct me own comment above - the UnsignedInteger Builtin is dynamic (vice the DWord builtin). Am definitely making your point about how confusing this is.
I’m going to re-submit this as an enhancement, so we can continue the discussion there!
Well for unix.org now it is working. I was getting some sort of a temporary page basically saying “nothing there”, so you can forget about that, not sure what happened.
And you can find here:
And this compiler is fairly modern (aka still maintained) and support DOS16, DOS32, WIN16 and WIN32. I don’t think so it support 64bit mode, but that’s not really it’s purpose anyway.
This stdint.h is of course valid only for Digital Mars C.
I’m not sure to be really clear in my explanation:
C99 clearly define that each of intXX_t and uintXX_t must have a strict size to have types that are not compiler and environment dependent. And as they are not really native type the compiler maker have to set them using typedefs in a way which for that specific compiler make sure they mean exactly what they say depending on how the compiler treat char/short/int/long. On the other hand Ghidra should NOT do the same and not rely on a compiler set of header to set theses specific types, so if a user who probably don’t know what compiler was used these specific set of C99 types should not have random size because it happen that Ghidra use typedef internally and the current architecture says that
int32_t == int
andint == 16 bit
soint32_t == 16bits
that’s non sense.Of course if you parse header that are not meant for an architecture and then get your types wrong that a different story (and would cause issue with real compiler), but C99 type that are standardizes with specific definition, Ghidra should treat them as Builtin types and not defined types.
Hope it makes more sense…