You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gs...@apache.org on 2008/03/03 13:09:34 UTC
svn commit: r633055 - in /harmony/enhanced/drlvm/trunk/vm: port/include/
port/src/modules/ port/src/modules/linux/ port/src/modules/win/
vmcore/include/ vmcore/src/util/ vmcore/src/util/linux/ vmcore/src/util/win/
Author: gshimansky
Date: Mon Mar 3 04:09:30 2008
New Revision: 633055
URL: http://svn.apache.org/viewvc?rev=633055&view=rev
Log:
Applied move patch 0005 from HARMONY-5504
[drlvm][port] Restructure DRLVM's sources to extract most of platform dependent code into portlib
Patch moves platform dependent modules code to portlib
Added:
harmony/enhanced/drlvm/trunk/vm/port/include/native_modules.h
- copied, changed from r632170, harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_modules.h
harmony/enhanced/drlvm/trunk/vm/port/src/modules/
harmony/enhanced/drlvm/trunk/vm/port/src/modules/linux/
harmony/enhanced/drlvm/trunk/vm/port/src/modules/linux/native_modules_os.c
- copied, changed from r632170, harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/native_modules.cpp
harmony/enhanced/drlvm/trunk/vm/port/src/modules/native_modules.c
- copied, changed from r632170, harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_modules_common.cpp
harmony/enhanced/drlvm/trunk/vm/port/src/modules/win/
harmony/enhanced/drlvm/trunk/vm/port/src/modules/win/native_modules_os.c
- copied, changed from r632170, harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/native_modules.cpp
Removed:
harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_modules.h
harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/native_modules.cpp
harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_modules_common.cpp
harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/native_modules.cpp
Copied: harmony/enhanced/drlvm/trunk/vm/port/include/native_modules.h (from r632170, harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_modules.h)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/include/native_modules.h?p2=harmony/enhanced/drlvm/trunk/vm/port/include/native_modules.h&p1=harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_modules.h&r1=632170&r2=633055&rev=633055&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_modules.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/include/native_modules.h Mon Mar 3 04:09:30 2008
@@ -22,11 +22,10 @@
#ifndef _NATIVE_MODULES_H_
#define _NATIVE_MODULES_H_
+#include <stddef.h>
#include <stdio.h>
+#include "open/types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
typedef enum {
SEGMENT_TYPE_UNKNOWN,
@@ -50,10 +49,40 @@
};
-bool get_all_native_modules(native_module_t**, int*);
-void dump_native_modules(native_module_t* modules, FILE *out);
-void clear_native_modules(native_module_t**);
-native_module_t* find_native_module(native_module_t* modules, void* code_ptr);
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+* Returns the list of modules loaded to the current process.
+* Module includes one or more segments of type <code>native_segment_t</code>.
+* @param list_ptr - an address of modules list pointer to fill
+* @param count_ptr - count of modules in the returned list
+* @return <code>TRUE</code> if OK; FALSE if error occured.
+*/
+Boolean port_get_all_modules(native_module_t** list_ptr, int* count_ptr);
+
+/**
+* Dumps the list of modules loaded to the current process..
+* @param modules - pointer to the list of modules to dump.
+* @param out - stream for printing the dump.
+*/
+void port_dump_modules(native_module_t* modules, FILE *out);
+
+/**
+* Clears the list of modules passed, writes NULL to the poiner.
+* @param modules - pointer to the list of modules to clear.
+*/
+void port_clear_modules(native_module_t** list_ptr);
+
+/**
+* Searches for the specific address in the list of modules.
+* @param modules - pointer to the list of modules to inspect.
+* @param code_ptr - the address to look for.
+* @return <code>native_module_t</code> pointer if OK; otherwise, NULL.
+*/
+native_module_t* port_find_module(native_module_t* modules, void* code_ptr);
#ifdef __cplusplus
Copied: harmony/enhanced/drlvm/trunk/vm/port/src/modules/linux/native_modules_os.c (from r632170, harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/native_modules.cpp)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/modules/linux/native_modules_os.c?p2=harmony/enhanced/drlvm/trunk/vm/port/src/modules/linux/native_modules_os.c&p1=harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/native_modules.cpp&r1=632170&r2=633055&rev=633055&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/native_modules.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/modules/linux/native_modules_os.c Mon Mar 3 04:09:30 2008
@@ -19,11 +19,11 @@
* @version $Revision: 1.1.2.1 $
*/
+#include <limits.h>
#include <stdio.h>
#include <memory.h>
#include <sys/types.h>
#include <unistd.h>
-#include "platform_lowlevel.h"
#include "open/types.h"
#include "port_malloc.h"
#include "native_modules.h"
@@ -36,8 +36,8 @@
{
void* start;
void* end;
- bool acc_r;
- bool acc_x;
+ Boolean acc_r;
+ Boolean acc_x;
char* name;
raw_module* next;
};
@@ -49,10 +49,12 @@
void native_clear_raw_list(raw_module* list)
{
+ raw_module* cur;
+
if (list->name)
STD_FREE(list->name);
- raw_module* cur = list->next;
+ cur = list->next;
while (cur)
{
@@ -88,6 +90,8 @@
native_module_t* native_fill_module(raw_module* rawModule, size_t count)
{
+ size_t i;
+
native_module_t* module =
(native_module_t*)STD_MALLOC(sizeof(native_module_t) + sizeof(native_segment_t)*(count - 1));
@@ -99,7 +103,7 @@
rawModule->name = NULL;
module->next = NULL;
- for (size_t i = 0; i < count; i++)
+ for (i = 0; i < count; i++)
{
if (rawModule->acc_x)
module->segments[i].type = SEGMENT_TYPE_CODE;
@@ -119,28 +123,34 @@
return module;
}
-bool get_all_native_modules(native_module_t** list_ptr, int* count_ptr)
+Boolean port_get_all_modules(native_module_t** list_ptr, int* count_ptr)
{
- char buf[_MAX_PATH];
+ char buf[PATH_MAX];
+ pid_t pid;
+ FILE* file;
+
+ POINTER_SIZE_INT start, end;
+ char acc_r, acc_x;
+ char filename[PATH_MAX];
+ raw_module module; // First raw module
+ raw_module* lastseg = &module; // Address of last filled segment
+ size_t segment_count;
+ int module_count;
+ native_module_t** cur_next_ptr;
if (list_ptr == NULL || count_ptr == NULL)
- return false;
+ return FALSE;
- pid_t pid = getpid();
+ pid = getpid();
sprintf(buf, "/proc/%d/maps", pid);
- FILE* file = fopen(buf, "rt");
+ file = fopen(buf, "rt");
if (!file)
- return false;
+ return FALSE;
- POINTER_SIZE_INT start, end;
- char acc_r, acc_x;
- char filename[_MAX_PATH];
- raw_module module; // First raw module
- raw_module* lastseg = &module; // Address of last filled segment
- size_t segment_count = 0;
- int module_count = 0;
- native_module_t** cur_next_ptr = list_ptr;
+ segment_count = 0;
+ module_count = 0;
+ cur_next_ptr = list_ptr;
module.name = NULL;
module.next = NULL;
*list_ptr = NULL;
@@ -168,9 +178,9 @@
if (!filled)
{
native_clear_raw_list(&module);
- clear_native_modules(list_ptr);
+ port_clear_modules(list_ptr);
fclose(file);
- return false;
+ return FALSE;
}
*cur_next_ptr = filled;
@@ -183,9 +193,9 @@
if (module.name == NULL)
{
native_clear_raw_list(&module);
- clear_native_modules(list_ptr);
+ port_clear_modules(list_ptr);
fclose(file);
- return false;
+ return FALSE;
}
strcpy(module.name, filename);
@@ -212,9 +222,9 @@
if (lastseg == NULL)
{
native_clear_raw_list(&module);
- clear_native_modules(list_ptr);
+ port_clear_modules(list_ptr);
fclose(file);
- return false;
+ return FALSE;
}
++segment_count;
@@ -228,9 +238,9 @@
if (!filled)
{
native_clear_raw_list(&module);
- clear_native_modules(list_ptr);
+ port_clear_modules(list_ptr);
fclose(file);
- return false;
+ return FALSE;
}
*cur_next_ptr = filled;
@@ -240,5 +250,5 @@
fclose(file);
*count_ptr = module_count;
- return true;
+ return TRUE;
}
Copied: harmony/enhanced/drlvm/trunk/vm/port/src/modules/native_modules.c (from r632170, harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_modules_common.cpp)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/modules/native_modules.c?p2=harmony/enhanced/drlvm/trunk/vm/port/src/modules/native_modules.c&p1=harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_modules_common.cpp&r1=632170&r2=633055&rev=633055&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_modules_common.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/modules/native_modules.c Mon Mar 3 04:09:30 2008
@@ -15,19 +15,25 @@
* limitations under the License.
*/
+#include <stdio.h>
#include "open/types.h"
-#include "native_modules.h"
#include "port_malloc.h"
+#include "native_modules.h"
-native_module_t* find_native_module(native_module_t* modules, void* code_ptr)
+
+native_module_t* port_find_module(native_module_t* modules, void* code_ptr)
{
- for (native_module_t* module = modules; NULL != module;
- module = module->next) {
- for (size_t s = 0; s < module->seg_count; s++) {
- void* base = module->segments[s].base;
+ native_module_t* module;
+ size_t s;
+
+ for (module = modules; NULL != module; module = module->next)
+ {
+ for (s = 0; s < module->seg_count; s++)
+ {
+ char* base = module->segments[s].base;
size_t size = module->segments[s].size;
- if (code_ptr >= base && code_ptr < (char*) base + size)
+ if ((char*)code_ptr >= base && (char*)code_ptr < base + size)
return module;
}
}
@@ -36,16 +42,19 @@
return NULL;
}
-void dump_native_modules(native_module_t* modules, FILE *out)
+void port_dump_modules(native_module_t* modules, FILE *out)
{
- for (native_module_t* module = modules; module; module = module->next)
+ native_module_t* module;
+ size_t i;
+
+ for (module = modules; module; module = module->next)
{
if (!module->filename)
continue;
fprintf(out, "%s:\n", module->filename);
- for (size_t i = 0; i < module->seg_count; i++)
+ for (i = 0; i < module->seg_count; i++)
{
size_t base = (size_t)module->segments[i].base;
@@ -55,7 +64,7 @@
}
}
-void clear_native_modules(native_module_t** list_ptr)
+void port_clear_modules(native_module_t** list_ptr)
{
native_module_t* cur = *list_ptr;
Copied: harmony/enhanced/drlvm/trunk/vm/port/src/modules/win/native_modules_os.c (from r632170, harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/native_modules.cpp)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/modules/win/native_modules_os.c?p2=harmony/enhanced/drlvm/trunk/vm/port/src/modules/win/native_modules_os.c&p1=harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/native_modules.cpp&r1=632170&r2=633055&rev=633055&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/native_modules.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/modules/win/native_modules_os.c Mon Mar 3 04:09:30 2008
@@ -27,7 +27,7 @@
static native_module_t* fill_module(MODULEENTRY32 src);
-bool get_all_native_modules(native_module_t** list_ptr, int* count_ptr)
+Boolean port_get_all_modules(native_module_t** list_ptr, int* count_ptr)
{
HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
MODULEENTRY32 module;
@@ -38,7 +38,7 @@
CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
if (hModuleSnap == INVALID_HANDLE_VALUE)
- return false;
+ return FALSE;
*list_ptr = NULL;
@@ -47,7 +47,7 @@
if ( !Module32First(hModuleSnap, &module) )
{
CloseHandle(hModuleSnap);
- return false;
+ return FALSE;
}
do
@@ -57,8 +57,8 @@
if (!filled)
{
CloseHandle(hModuleSnap);
- clear_native_modules(list_ptr);
- return false;
+ port_clear_modules(list_ptr);
+ return FALSE;
}
*cur_next_ptr = filled;
@@ -70,18 +70,20 @@
CloseHandle(hModuleSnap);
*count_ptr = count;
- return true;
+ return TRUE;
}
native_module_t* fill_module(MODULEENTRY32 src)
{
+ MEMORY_BASIC_INFORMATION mem_info;
+ size_t path_size = strlen(src.szExePath) + 1;
+
native_module_t* module =
(native_module_t*)STD_MALLOC(sizeof(native_module_t));
if (module == NULL)
return NULL;
- size_t path_size = strlen(src.szExePath) + 1;
module->filename = (char*)STD_MALLOC(path_size);
if (module->filename == NULL)
{
@@ -97,7 +99,6 @@
module->segments[0].size = (size_t)src.modBaseSize;
module->next = NULL;
- MEMORY_BASIC_INFORMATION mem_info;
VirtualQuery(src.modBaseAddr, &mem_info, sizeof(mem_info));
if ((mem_info.Protect & (PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) != 0)