/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <windows.h>
#include <string.h>
#include "jni.h"
#include "jni_util.h"
#include "sun_tools_attach_WindowsVirtualMachine.h"
/* kernel32 */
/* only on Windows 64-bit or 32-bit application running under WOW64 */
/* psapi */
/* exported function in target VM */
/* OpenProcess with SE_DEBUG_NAME privilege */
static HANDLE
/* convert jstring to C string */
/*
* Data copied to target process
*/
typedef struct {
} DataBlock;
/*
* Return codes from enqueue function executed in target VM
*/
/*
* Code copied to target process
*/
#pragma check_stack (off)
{
HINSTANCE h;
if (h == NULL) {
return ERR_OPEN_JVM_FAIL;
}
}
return ERR_GET_ENQUEUE_FUNC_FAIL;
}
/* "null" command - does nothing in the target VM */
return 0;
} else {
}
}
/* This function marks the end of thread_func. */
static void thread_end (void) {
}
#pragma check_stack
/*
* Class: sun_tools_attach_WindowsVirtualMachine
* Method: init
* Signature: ()V
*/
{
}
/*
* Class: sun_tools_attach_WindowsVirtualMachine
* Method: generateStub
* Signature: ()[B
*/
{
/*
* We should replace this with a real stub generator at some point
*/
}
return array;
}
/*
* Class: sun_tools_attach_WindowsVirtualMachine
* Method: openProcess
* Signature: (I)J
*/
{
/* process is attaching to itself; get a pseudo handle instead */
/* duplicate the pseudo handle so it can be used in more contexts */
PROCESS_ALL_ACCESS, FALSE, 0) == 0) {
/*
* Could not duplicate the handle which isn't a good sign,
* but we'll try again with OpenProcess() below.
*/
}
}
/*
* Attempt to open process. If it fails then we try to enable the
* SE_DEBUG_NAME privilege and retry.
*/
}
if (GetLastError() == ERROR_INVALID_PARAMETER) {
} else {
/* include the last error in the default detail message */
(int)pid, (int)GetLastError());
}
return (jlong)0;
}
}
/*
* On Windows 64-bit we need to handle 32-bit tools trying to attach to 64-bit
* processes (and visa versa). X-architecture attaching is currently not supported
* by this implementation.
*/
if (_IsWow64Process != NULL) {
if (isCurrent32bit != isTarget32bit) {
#ifdef _WIN64
"Unable to attach to 32-bit process running under WOW64");
#else
"Unable to attach to 64-bit process");
#endif
}
}
}
/*
* Class: sun_tools_attach_WindowsVirtualMachine
* Method: closeProcess
* Signature: (J)V
*/
{
}
/*
* Class: sun_tools_attach_WindowsVirtualMachine
* Method: createPipe
*/
{
name, // pipe name
PIPE_ACCESS_INBOUND, // read access
PIPE_TYPE_BYTE | // byte mode
PIPE_WAIT, // blocking mode
1, // max. instances
128, // output buffer size
8192, // input buffer size
NMPWAIT_USE_DEFAULT_WAIT, // client time-out
NULL); // default security attribute
if (hPipe == INVALID_HANDLE_VALUE) {
}
}
/*
* Class: sun_tools_attach_WindowsVirtualMachine
* Method: closePipe
* Signature: (J)V
*/
{
}
/*
* Class: sun_tools_attach_WindowsVirtualMachine
* Method: connectPipe
* Signature: (J)V
*/
{
if (!fConnected) {
}
}
/*
* Class: sun_tools_attach_WindowsVirtualMachine
* Method: readPipe
* Signature: (J[BII)I
*/
{
}
buf, // buffer to receive data
len, // size of buffer
&nread, // number of bytes read
NULL); // not overlapped I/O
if (!fSuccess) {
if (GetLastError() == ERROR_BROKEN_PIPE) {
return (jint)-1;
} else {
}
} else {
if (nread == 0) {
} else {
}
}
}
/*
* Class: sun_tools_attach_WindowsVirtualMachine
* Method: enqueue
*/
{
/*
* Setup data to copy to target process
*/
/*
* Command and arguments
*/
if (argsLen > 0) {
}
for (i=0; i<argsLen; i++) {
} else {
}
}
}
}
/* pipe name */
/*
* Allocate memory in target process for data and code stub
* (assumed aligned and matches architecture of target process)
*/
return;
}
return;
}
if (isCopy) {
}
/*
* Create thread in target process to execute code
*/
NULL,
0,
0,
NULL );
} else {
if (exitCode) {
switch (exitCode) {
case ERR_OPEN_JVM_FAIL :
"jvm.dll not loaded by target process");
break;
case ERR_GET_ENQUEUE_FUNC_FAIL :
"Unable to enqueue operation: the target VM does not support attach mechanism");
break;
default :
"Remote thread failed for unknown reason");
}
}
}
} else {
if (GetLastError() == ERROR_NOT_ENOUGH_MEMORY) {
//
// This error will occur when attaching to a process belonging to
// another terminal session. See "Remarks":
//
"Insufficient memory or insufficient privileges to attach");
} else {
}
}
}
/*
* Attempts to enable the SE_DEBUG_NAME privilege and open the given process.
*/
static HANDLE
/*
* Get the access token
*/
if (!OpenThreadToken(GetCurrentThread(),
&hToken)) {
if (GetLastError() != ERROR_NO_TOKEN) {
}
/*
* No access token for the thread so impersonate the security context
* of the process.
*/
if (!ImpersonateSelf(SecurityImpersonation)) {
}
if (!OpenThreadToken(GetCurrentThread(),
&hToken)) {
}
}
/*
* Get LUID for the privilege
*/
error = GetLastError();
}
/*
* Enable the privilege
*/
error = 0;
&tp,
sizeof(TOKEN_PRIVILEGES),
&retLength)) {
/*
* If we enabled the privilege then attempt to open the
* process.
*/
if (GetLastError() == ERROR_SUCCESS) {
error = GetLastError();
}
} else {
}
/*
* Revert to the previous privileges
*/
NULL,
NULL);
} else {
error = GetLastError();
}
/*
* Close token and restore error
*/
return hProcess;
}
/* convert jstring to C string */
const char* str;
cstr[0] = '\0';
} else {
if (isCopy) {
}
}
}