sourcemm/oslink.cpp
changeset 122 7c36121e2dfe
parent 9 01b8b7435e67
child 127 4f3bdf8aa859
     1.1 --- a/sourcemm/oslink.cpp	Wed Oct 05 21:51:02 2005 +0000
     1.2 +++ b/sourcemm/oslink.cpp	Thu Oct 06 00:59:01 2005 +0000
     1.3 @@ -36,3 +36,25 @@
     1.4  	return errno;
     1.5  }
     1.6  #endif
     1.7 +
     1.8 +bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength)
     1.9 +{
    1.10 +#if defined WIN32 || defined _WIN32
    1.11 +	MEMORY_BASIC_INFORMATION mem;
    1.12 +	if (!VirtualQuery((void *)pAddr, &mem, sizeof(mem)))
    1.13 +		return false;
    1.14 +	if (mem.AllocationBase == NULL)
    1.15 +		return false;
    1.16 +	HMODULE dll = (HMODULE)mem.AllocationBase;
    1.17 +	GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
    1.18 +#elif defined __linux__
    1.19 +	Dl_info info;
    1.20 +	if (!dladdr((void *)pAddr, &info))
    1.21 +		return false;
    1.22 +	if (!info.dli_fbase || !info.dli_fname)
    1.23 +		return false;
    1.24 +	const char *dllpath = info.dli_fname;
    1.25 +	snprintf(buffer, maxlength, "%s", dllpath);
    1.26 +#endif
    1.27 +	return true;
    1.28 +}