X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libjava%2Fwin32.cc;h=6a1c2c736defb31ca398cbf77ad19075bd5bc458;hb=422538b1da090320ceee9cc7a67dc289c9a01919;hp=a0ae0f0f9cb52c1c7097f5d863fe26c5e36a22ac;hpb=c44de8ab02bf815fb920a2e6f1e6e16aadf05b07;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libjava/win32.cc b/libjava/win32.cc index a0ae0f0f9cb..6a1c2c736de 100644 --- a/libjava/win32.cc +++ b/libjava/win32.cc @@ -12,8 +12,11 @@ details. */ #include #include #include +#include #include +#include + #include #include #include @@ -285,21 +288,6 @@ _Jv_platform_nanotime () return _Jv_platform_gettimeofday () * 1000LL; } -// The following definitions "fake out" mingw to think that -mthreads -// was enabled and that mingwthr.dll was linked. GCJ-compiled -// applications don't need this helper library because we can safely -// detect thread death (return from Thread.run()). - -int _CRT_MT = 1; - -extern "C" int -__mingwthr_key_dtor (DWORD, void (*) (void *)) -{ - // FIXME: for now we do nothing; this causes a memory leak of - // approximately 24 bytes per thread created. - return 0; -} - static bool dirExists (LPCTSTR dir) { DWORD dwAttrs = ::GetFileAttributes (dir); @@ -442,28 +430,6 @@ _Jv_platform_initProperties (java::util::Properties* newprops) } } -/* Store up to SIZE return address of the current program state in - ARRAY and return the exact number of values stored. */ -int -backtrace (void **__array, int __size) -{ - register void *_ebp __asm__ ("ebp"); - register void *_esp __asm__ ("esp"); - unsigned int *rfp; - - int i=0; - for (rfp = *(unsigned int**)_ebp; - rfp && i < __size; - rfp = *(unsigned int **)rfp) - { - int diff = *rfp - (unsigned int)rfp; - if ((void*)rfp < _esp || diff > 4 * 1024 || diff < 0) break; - - __array[i++] = (void*)(rfp[1]-4); - } - return i; -} - int _Jv_pipe (int filedes[2]) { @@ -477,3 +443,42 @@ _Jv_platform_close_on_exec (HANDLE h) // no effect under Win9X. SetHandleInformation (h, HANDLE_FLAG_INHERIT, 0); } + +// Given an address, find the object that defines it and the nearest +// defined symbol to that address. Returns 0 if no object defines this +// address. +int +_Jv_platform_dladdr (void *addr, _Jv_AddrInfo *info) +{ + // Since we do not have dladdr() on Windows, we use a trick involving + // VirtualQuery() to find the module (EXE or DLL) that contains a given + // address. This was taken from Matt Pietrek's "Under the Hood" column + // for the April 1997 issue of Microsoft Systems Journal. + + MEMORY_BASIC_INFORMATION mbi; + if (!VirtualQuery (addr, &mbi, sizeof (mbi))) + { + return 0; + } + + HMODULE hMod = (HMODULE) mbi.AllocationBase; + + char moduleName[MAX_PATH]; + + // FIXME: We explicitly use the ANSI variant of the function here. + if (!GetModuleFileNameA (hMod, moduleName, sizeof (moduleName))) + { + return 0; + } + + char *file_name = (char *)(malloc (strlen (moduleName) + 1)); + strcpy (file_name, moduleName); + info->file_name = file_name; + + // FIXME. + info->base = NULL; + info->sym_name = NULL; + info->sym_addr = NULL; + + return 1; +}