Skip to content
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

Feature request: native Windows support #23

Closed
aitap opened this issue Dec 8, 2020 · 9 comments · Fixed by #28
Closed

Feature request: native Windows support #23

aitap opened this issue Dec 8, 2020 · 9 comments · Fixed by #28

Comments

@aitap
Copy link
Contributor

aitap commented Dec 8, 2020

I have a Windows-only project that dmalloc could really help with. Currently, it seems that the only way to use dmalloc on Windows is to build it with Cygwin, since the only virtual memory APIs that dmalloc currently speaks are sbrk and mmap, and Windows has neither.

If you are interested in this, I could prepare a pull request modifying heap.c to use VirtualAlloc / VirtualFree in addition to mmap / munmap, bringing me closer to my goal of cross-compiling dmalloc for Windows using something like ./configure --build=i686-linux-gnu --host=i686-w64-mingw32. While lack of mmap could be worked around using INTERNAL_MEMORY_SPACE, it's not a good solution.

@aitap
Copy link
Contributor Author

aitap commented Dec 16, 2020

This is probably harder than it looks like:

  • Functions in append.c pass va_lists to other functions, expecting state modifications done by va_arg() in the callee to persist in the caller. Apparently this is not the case for mingw (where va_list could be just a char *), so loc_snprintf(setup, sizeof(setup), "debug=%#x,start=%s:%d", 0x400, loc_file, loc_line); crashes while trying to dereference 0x400 instead of loc_file.
  • For logging purposes, addresses are cast to long. Unfortunately, long is 32-bit in 64-bit Windows. Thankfully, there is only one longDMALLOC_PNT cast, in env.c. Fixing this in a portable manner would be "fun".

@j256
Copy link
Owner

j256 commented Dec 16, 2020

Thanks much @aitap . I don't quite understand your point. Am I doing something wrong with the va_list stuff or is there some incompatibility in it under windows?

@j256
Copy link
Owner

j256 commented Dec 16, 2020

OH! I see it. I bet that's a bug. Let me see if I can reproduce it in testing.

@j256
Copy link
Owner

j256 commented Dec 17, 2020

Fixed the va_args usage with #27

@j256
Copy link
Owner

j256 commented Dec 17, 2020

I get the second bullet now. Hrm. So when we are printing the value as "%#lx" and I extract it as a long, that won't work. Maybe I should be more religious about %p and extract it as a char *?

@j256
Copy link
Owner

j256 commented Dec 17, 2020

Is there a long long or some other 64 bit numerical type? I need something to be able to do arithmetic on the pointer to be able to display it.

@j256
Copy link
Owner

j256 commented Dec 17, 2020

I just pushed up this pull request. Does it fix anything? #28

@aitap
Copy link
Contributor Author

aitap commented Dec 17, 2020

Thanks a lot for your help!

@j256
Copy link
Owner

j256 commented Dec 17, 2020

Sure thing. Appreciate your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants