-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Basilisk II hangs in direct addressing when frame buffer base address is lower than ram base address #203
Comments
This is my first attempt to use Mac OS X I started acquire RAM in an arbitrary address. Then I used next_address to acquire ROM and frame buffer. It failed randomly due to the fact that host memory can allocate the framebuffer right after RAM+ROM memory allocation. My first attempt doesn't solve the problem. But it seems the similar trick works quite well in Linux. See below:
I believe the better approach is to allocate all memory at once for Mac RAM, Mac ROM and frame buffer in Mac OS X. Then assign them separately. If you have any better ideas, I'm all ears. |
@asvitkine Another bug I found from master branch is in the line 201. My C may be rusty. But the line 201 disabled line 202-209 every time it is called. macemu/BasiliskII/src/SDL/video_sdl.cpp Lines 198 to 213 in 5cbf07e
|
Problem StatementWhen the host OS is Mac OS X, direct addressing in BII doesn't guarantee that the allocated memory for frame buffer base address in the host (FrameBaseHost) satisfies the following conditions:
where RamBaseHost refers to the emulated RAM base address in the host. This may cause the random hang problem where the allocated frame address failed to meet the conditions above. Because the direct addressing mapping is a simple math:
SolutionSolution 1Force Mac OS X uses memory bank addressing in configure.ac. Pros:
Cons:
Solution 2Allocate host memory for guest RAM, guest ROM and guest frame buffer all at once. Assign each memory blocks later. Pros:
Cons:
Solution 3Check the conditions. If it doesn't meet the conditions, let it crash and print out a nice message to ask people to restart. Pros:
Cons:
SummaryI haven't fix the old bug yet. If you have a better ideas, please let me know. Linux is quite special. Their mmap doesn't seem to have the problem like Mac OS X. But in Linux it starts the mmap in a very special location address: macemu/BasiliskII/src/CrossPlatform/vm_alloc.cpp Lines 88 to 96 in 5cbf07e
I can't find any helpful information regarding to the Mac OS X application virtual memory address mapping. Especially with ASLR, this is a myth to me. |
I benchmark two addressing: direct and memory banks. As I expected, the memory banks is a little bit slower than direct. But in general, there are no noticeable issues at all to run any Apps in BII under direct or memory banks. But what makes the huge performance differences is the GCC compiler optimization flag:
As you can see, memory banks is 10x slower in no optimization flag. In summary, I will send a PR of solution 1. In configure.ac, when it detects Mac OS X and Intel platform, it will force addressing to memory banks. |
When the host OS is Mac OS X, direct addressing in BII doesn't guarantee that the allocated memory for frame buffer base address in the host (FrameBaseHost) satisfies the following conditions: - FrameBaseHost > RamBaseHost - (FrameBaseHost - RamBaseHost) + Frame_Size < 4GiB where RamBaseHost refers to the emulated RAM base address in the host. This may cause the random hang problem where the allocated frame address failed to meet the conditions above. Because the direct addressing mapping is a simple math: RamAddrMac = RamAddrHost - RamBaseHost. See details: cebix#203 Signed-off-by: Ricky Zhang <rickyzhang@gmail.com>
In case you didn't already figure it out, your C is rusty. The |
Thanks for pointing it out. This makes much sense now. For direct addressing, the consecutive memory allocation are not guaranteed in modern OS. We may have to adopt solution 2 or if you have a better idea? |
I debugged the issues in SDL2. I found the culprit which is hidden for very long time.
As the title suggested, in direct addressing the mapping is a simple math:
RamAddrMac = RamAddrHost - RamBaseHost.
But BII never check when allocating the frame buffer in the host, the FrameBaseHost satisfies the following:
In the absence of the checking above, it cause random hang.
See my last comment in kanjitalk755#43
The text was updated successfully, but these errors were encountered: