Fix breakage of non-Windows binary emulation on Windows host #1143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
Which kind of PR do you create?
Coding convention?
Extra tests?
Changelog?
Target branch?
One last thing
Linux binary emulation for dynamically linked executable files on Windows host fails with the error
unicorn.unicorn.UcError: Invalid memory read (UC_ERR_READ_UNMAPPED)
as I mentioned in my pull request #1064 and another person reported in #974.I have investigated this issue for recent months and I finally found that truncation in the read() system call is the cause of the issue. In the following example, the beginning part of libc.so.6 is truncated into 0x304 bytes out of 0x340 bytes in the read() system call.
\x1a
is located at offset 0x304.\x1a
is the ASCII Substitute character (SUB) and it is used as EOF (Ctrl-Z) on Windows. This truncation is caused by opening files with text mode. It may cause failure of binary emulation for other operating systems. Opening files with binary mode by setting the O_BINARY flag can prevent it.