Skip to content

closure: port use of dlsym to Windows #1601

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

Merged
merged 1 commit into from
Jun 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions closure/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#if TARGET_OS_WIN32
#include <Windows.h>
#include <Psapi.h>
#else
#include <dlfcn.h>
#endif
#if __has_include(<os/assumes.h>)
#include <os/assumes.h>
#else
Expand Down Expand Up @@ -245,7 +250,26 @@ void _Block_use_RR( void (*retain)(const void *),
void (*release)(const void *)) {
_Block_retain_object = retain;
_Block_release_object = release;
#if TARGET_OS_WIN32
HANDLE hProcess = GetCurrentProcess();
HMODULE hModule[1024];
DWORD cbNeeded = 0;

if (!EnumProcessModules(hProcess, hModule, sizeof(hModule), &cbNeeded))
return;
if (cbNeeded > sizeof(hModule))
return;

for (unsigned I = 0; I < (cbNeeded / sizeof(HMODULE)); ++I) {
_Block_destructInstance =
(void (*)(const void *))GetProcAddress(hModule[I],
"objc_destructInstance");
if (_Block_destructInstance)
break;
}
#else
_Block_destructInstance = dlsym(RTLD_DEFAULT, "objc_destructInstance");
#endif
}

// Called from CF to indicate MRR. Newer version uses a versioned structure, so we can add more functions
Expand Down