00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.12 $ */ 00002 /* Copyright (c) 2006, Sun Microsystems, Inc. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 00006 following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 00009 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 00010 disclaimer in the documentation and/or other materials provided with the distribution. 00011 * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 00012 from this software without specific prior written permission. 00013 00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00020 00021 00022 */ 00023 00024 // Support routines for Dynamic Link Libraries (DLLs) 00025 00026 class InterpretedDLL_Cache: public ValueObj { 00027 private: 00028 symbolOop _dll_name; 00029 symbolOop _funct_name; 00030 dll_func _entry_point; 00031 char _number_of_arguments; 00032 // Do not add more instance variables! Layout must correspond to DLL call in bytecodes! 00033 00034 public: 00035 symbolOop dll_name() const { return _dll_name; } 00036 symbolOop funct_name() const { return _funct_name; } 00037 dll_func entry_point() const { return _entry_point; } 00038 int number_of_arguments() const { return _number_of_arguments; } 00039 bool async() const; 00040 void set_entry_point(dll_func f) { _entry_point = f; } 00041 00042 // Debugging 00043 void verify(); 00044 void print(); 00045 }; 00046 00047 00048 // Layout of CompiledDLL_Caches 00049 // 00050 // mov edx, entry_point <- mov edx 00051 // test eax, dll_name <- test 1 00052 // test eax, function_name <- test 2 00053 // call sync_DLL/async_DLL <- call 00054 // ... <- this 00055 00056 class CompiledDLL_Cache: public NativeCall { 00057 private: 00058 enum Layout_constants { 00059 test_2_instruction_offset = -NativeCall::instruction_size - NativeTest::instruction_size, 00060 test_1_instruction_offset = test_2_instruction_offset - NativeTest::instruction_size, 00061 mov_edx_instruction_offset = test_1_instruction_offset - NativeMov::instruction_size, 00062 }; 00063 00064 NativeMov* mov_at(int offset) { return nativeMov_at(addr_at(offset)); } 00065 NativeTest* test_at(int offset) { return nativeTest_at(addr_at(offset)); } 00066 00067 public: 00068 symbolOop dll_name() { return symbolOop(test_at(test_1_instruction_offset)->data()); } 00069 symbolOop function_name() { return symbolOop(test_at(test_2_instruction_offset)->data()); } 00070 dll_func entry_point() { return (dll_func)mov_at(mov_edx_instruction_offset)->data(); } 00071 bool async() const; 00072 void set_entry_point(dll_func f) { mov_at(mov_edx_instruction_offset)->set_data(int(f)); } 00073 00074 // Debugging 00075 void verify(); 00076 void print(); 00077 00078 // Creation 00079 friend CompiledDLL_Cache* compiledDLL_Cache_from_return_address(char* return_address); 00080 friend CompiledDLL_Cache* compiledDLL_Cache_from_relocInfo(char* displacement_address); 00081 }; 00082 00083 class DLLs: AllStatic { 00084 public: 00085 // Lookup 00086 static dll_func lookup(symbolOop name, DLL* library); 00087 static DLL* load(symbolOop name); 00088 static bool unload(DLL* library); 00089 00090 static dll_func lookup_fail(symbolOop dll_name, symbolOop function_name); 00091 static dll_func lookup(symbolOop dll_name, symbolOop function_name); 00092 static dll_func lookup_and_patch_InterpretedDLL_Cache(); 00093 static dll_func lookup_and_patch_CompiledDLL_Cache(); 00094 00095 // Support for asynchronous DLL calls 00096 static void enter_async_call(DeltaProcess** addr); // called before each asynchronous DLL call 00097 static void exit_async_call(DeltaProcess** addr); // called after each asynchronous DLL call 00098 static void exit_sync_call(DeltaProcess** addr); // called after each synchronous DLL call 00099 };