[SIGAR-44] Add 64-bit vmware support
This commit is contained in:
		
							parent
							
								
									280181adee
								
							
						
					
					
						commit
						ba91081747
					
				@ -65,11 +65,29 @@ static void vmware_throw_last_error(JNIEnv *env, void *ptr, int type)
 | 
			
		||||
#define vmware_throw_last_server_error() \
 | 
			
		||||
    vmware_throw_last_error(env, server, VMWARE_EX_SERVER)
 | 
			
		||||
 | 
			
		||||
static jint vmware_get_pointer(JNIEnv *env, jobject obj)
 | 
			
		||||
static void *vmware_get_pointer(JNIEnv *env, jobject obj)
 | 
			
		||||
{
 | 
			
		||||
    jclass cls = JENV->GetObjectClass(env, obj);
 | 
			
		||||
#ifdef __LP64__
 | 
			
		||||
    jfieldID field = JENV->GetFieldID(env, cls, "ptr64", "J");
 | 
			
		||||
    return (void *)JENV->GetLongField(env, obj, field);
 | 
			
		||||
#else
 | 
			
		||||
    jfieldID field = JENV->GetFieldID(env, cls, "ptr", "I");
 | 
			
		||||
    return JENV->GetIntField(env, obj, field);
 | 
			
		||||
    return (void *)JENV->GetIntField(env, obj, field);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void vmware_set_pointer(JNIEnv *env, jobject obj, const void *ptr) {
 | 
			
		||||
    jfieldID pointer_field;
 | 
			
		||||
    jclass cls = JENV->GetObjectClass(env, obj);
 | 
			
		||||
 | 
			
		||||
#ifdef __LP64__
 | 
			
		||||
    pointer_field = JENV->GetFieldID(env, cls, "ptr64", "J");
 | 
			
		||||
    JENV->SetLongField(env, obj, pointer_field, (jlong)ptr);
 | 
			
		||||
#else
 | 
			
		||||
    pointer_field = JENV->GetFieldID(env, cls, "ptr", "I");
 | 
			
		||||
    JENV->SetIntField(env, obj, pointer_field, (int)ptr);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define dVM(obj) \
 | 
			
		||||
@ -110,11 +128,11 @@ JNIEXPORT jboolean VMWARE_JNI(VMwareObject_init)
 | 
			
		||||
    return VMControl_Init() && VMControl_VMInit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
JNIEXPORT jint VMWARE_JNI(ConnectParams_create)
 | 
			
		||||
(JNIEnv *env, jclass classinstance,
 | 
			
		||||
JNIEXPORT void VMWARE_JNI(ConnectParams_create)
 | 
			
		||||
(JNIEnv *env, jobject obj,
 | 
			
		||||
 jstring jhost, jint port, jstring juser, jstring jpass)
 | 
			
		||||
{
 | 
			
		||||
    jint ptr;
 | 
			
		||||
    VMControlConnectParams *params;
 | 
			
		||||
    const char *host=NULL;
 | 
			
		||||
    const char *user=NULL;
 | 
			
		||||
    const char *pass=NULL;
 | 
			
		||||
@ -129,7 +147,7 @@ JNIEXPORT jint VMWARE_JNI(ConnectParams_create)
 | 
			
		||||
        pass = JENV->GetStringUTFChars(env, jpass, NULL);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ptr = (jint)VMControl_ConnectParamsNew(host, port, user, pass);
 | 
			
		||||
    params = VMControl_ConnectParamsNew(host, port, user, pass);
 | 
			
		||||
 | 
			
		||||
    if (host) {
 | 
			
		||||
        JENV->ReleaseStringUTFChars(env, jhost, host);
 | 
			
		||||
@ -141,7 +159,7 @@ JNIEXPORT jint VMWARE_JNI(ConnectParams_create)
 | 
			
		||||
        JENV->ReleaseStringUTFChars(env, jpass, pass);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return ptr;
 | 
			
		||||
    vmware_set_pointer(env, obj, params);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
JNIEXPORT void VMWARE_JNI(ConnectParams_destroy)
 | 
			
		||||
@ -151,10 +169,10 @@ JNIEXPORT void VMWARE_JNI(ConnectParams_destroy)
 | 
			
		||||
    VMControl_ConnectParamsDestroy(params);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
JNIEXPORT jint VMWARE_JNI(VMwareServer_create)
 | 
			
		||||
(JNIEnv *env, jclass classinstance)
 | 
			
		||||
JNIEXPORT void VMWARE_JNI(VMwareServer_create)
 | 
			
		||||
(JNIEnv *env, jobject obj)
 | 
			
		||||
{
 | 
			
		||||
    return (jint)VMControl_ServerNewEx();
 | 
			
		||||
    vmware_set_pointer(env, obj, VMControl_ServerNewEx());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
JNIEXPORT void VMWARE_JNI(VMwareServer_destroy)
 | 
			
		||||
@ -287,10 +305,10 @@ JNIEXPORT jstring VMWARE_JNI(VMwareServer_exec)
 | 
			
		||||
    return retval;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
JNIEXPORT jint VMWARE_JNI(VM_create)
 | 
			
		||||
(JNIEnv *env, jclass classinstance)
 | 
			
		||||
JNIEXPORT void VMWARE_JNI(VM_create)
 | 
			
		||||
(JNIEnv *env, jclass obj)
 | 
			
		||||
{
 | 
			
		||||
    return (jint)VMControl_VMNewEx();
 | 
			
		||||
    vmware_set_pointer(env, obj, VMControl_VMNewEx());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
JNIEXPORT void VMWARE_JNI(VM_destroy)
 | 
			
		||||
 | 
			
		||||
@ -19,7 +19,7 @@
 | 
			
		||||
#ifndef VMCONTROL_WRAPPER_H
 | 
			
		||||
#define VMCONTROL_WRAPPER_H
 | 
			
		||||
 | 
			
		||||
#if defined(WIN32) || defined(__linux__) && !defined(__LP64__)
 | 
			
		||||
#if defined(WIN32) || defined(__linux__)
 | 
			
		||||
 | 
			
		||||
#define VMCONTROL_WRAPPER_SUPPORTED
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -20,8 +20,8 @@ package org.hyperic.sigar.vmware;
 | 
			
		||||
 | 
			
		||||
public class ConnectParams extends VMwareObject {
 | 
			
		||||
 | 
			
		||||
    private static native int create(String host, int port,
 | 
			
		||||
                                     String user, String pass);
 | 
			
		||||
    private native void create(String host, int port,
 | 
			
		||||
                               String user, String pass);
 | 
			
		||||
 | 
			
		||||
    native void destroy();
 | 
			
		||||
 | 
			
		||||
@ -32,6 +32,6 @@ public class ConnectParams extends VMwareObject {
 | 
			
		||||
    public ConnectParams(String host, int port,
 | 
			
		||||
                         String user, String pass)
 | 
			
		||||
    {
 | 
			
		||||
        this.ptr = create(host, port, user, pass);
 | 
			
		||||
        create(host, port, user, pass);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -71,7 +71,7 @@ public class VM extends VMwareObject {
 | 
			
		||||
 | 
			
		||||
    native void destroy();
 | 
			
		||||
 | 
			
		||||
    private static native int create();
 | 
			
		||||
    private static native void create();
 | 
			
		||||
 | 
			
		||||
    private native void connect(ConnectParams params, String config, int mks)
 | 
			
		||||
        throws VMwareException;
 | 
			
		||||
@ -329,6 +329,6 @@ public class VM extends VMwareObject {
 | 
			
		||||
        throws VMwareException;
 | 
			
		||||
 | 
			
		||||
    public VM() {
 | 
			
		||||
        this.ptr = create();
 | 
			
		||||
        create();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -25,11 +25,14 @@ import java.io.IOException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.hyperic.jni.ArchName;
 | 
			
		||||
import org.hyperic.sigar.SigarLoader;
 | 
			
		||||
import org.hyperic.sigar.win32.RegistryKey;
 | 
			
		||||
import org.hyperic.sigar.win32.Win32Exception;
 | 
			
		||||
 | 
			
		||||
public class VMControlLibrary {
 | 
			
		||||
    private static final boolean IS64 = ArchName.is64();
 | 
			
		||||
 | 
			
		||||
    public static final String REGISTRY_ROOT =
 | 
			
		||||
        "SOFTWARE\\VMware, Inc.";
 | 
			
		||||
 | 
			
		||||
@ -42,7 +45,8 @@ public class VMControlLibrary {
 | 
			
		||||
    private static final String VMCONTROL_TAR =
 | 
			
		||||
        getProperty("control.tar", VMWARE_LIB + "/perl/control.tar");
 | 
			
		||||
 | 
			
		||||
    private static final String VMCONTROL = "vmcontrol";
 | 
			
		||||
    private static final String VMCONTROL =
 | 
			
		||||
        "vmcontrol" + (IS64 ? "64" : "");
 | 
			
		||||
 | 
			
		||||
    private static final String VMCONTROL_DLL =
 | 
			
		||||
        VMCONTROL + "lib.dll";
 | 
			
		||||
@ -230,13 +234,6 @@ public class VMControlLibrary {
 | 
			
		||||
            throw new IOException("Cannot write to: " + dir);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        File libssl = getLibSSL();
 | 
			
		||||
        File libcrypto = getLibCrypto();
 | 
			
		||||
 | 
			
		||||
        if (!libssl.exists()) {
 | 
			
		||||
            throw new FileNotFoundException(libssl.toString());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        File obj = new File(dir, VMCONTROL_OBJ);
 | 
			
		||||
        if (!obj.exists()) {
 | 
			
		||||
            //extract vmcontrol.o
 | 
			
		||||
@ -259,24 +256,37 @@ public class VMControlLibrary {
 | 
			
		||||
        link_args.add("-o");
 | 
			
		||||
        link_args.add(out.getPath());
 | 
			
		||||
        link_args.add(obj.getPath());
 | 
			
		||||
 | 
			
		||||
        //Skip rpath for ESX 3.x
 | 
			
		||||
        if (!new File(libssl.getParent(), "libc.so.6").exists()) {
 | 
			
		||||
            final String rpath = "-Wl,-rpath";
 | 
			
		||||
 | 
			
		||||
            link_args.add(rpath);
 | 
			
		||||
            link_args.add(libssl.getParent());
 | 
			
		||||
 | 
			
		||||
            //check if libcrypto is in a different directory
 | 
			
		||||
            if (!libssl.getParent().equals(libcrypto.getParent())) {
 | 
			
		||||
                link_args.add(rpath);
 | 
			
		||||
                link_args.add(libcrypto.getParent());
 | 
			
		||||
            }
 | 
			
		||||
        
 | 
			
		||||
        if (IS64) {
 | 
			
		||||
            link_args.add("-lcrypto");
 | 
			
		||||
            link_args.add("-lssl");
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            File libssl = getLibSSL();
 | 
			
		||||
            File libcrypto = getLibCrypto();
 | 
			
		||||
 | 
			
		||||
        link_args.add(libssl.getPath());
 | 
			
		||||
        link_args.add(libcrypto.getPath());
 | 
			
		||||
            if (!libssl.exists()) {
 | 
			
		||||
                throw new FileNotFoundException(libssl.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            //Skip rpath for ESX 3.x
 | 
			
		||||
            if (!new File(libssl.getParent(), "libc.so.6").exists()) {
 | 
			
		||||
                final String rpath = "-Wl,-rpath";
 | 
			
		||||
 | 
			
		||||
                link_args.add(rpath);
 | 
			
		||||
                link_args.add(libssl.getParent());
 | 
			
		||||
 | 
			
		||||
                //check if libcrypto is in a different directory
 | 
			
		||||
                if (!libssl.getParent().equals(libcrypto.getParent())) {
 | 
			
		||||
                    link_args.add(rpath);
 | 
			
		||||
                    link_args.add(libcrypto.getParent());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            link_args.add(libssl.getPath());
 | 
			
		||||
            link_args.add(libcrypto.getPath());
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        exec((String[])link_args.toArray(new String[0]));
 | 
			
		||||
 | 
			
		||||
        setSharedLibrary(out.getPath());
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,8 @@ import org.hyperic.sigar.SigarLoader;
 | 
			
		||||
abstract class VMwareObject {
 | 
			
		||||
    public static final boolean LOADED;
 | 
			
		||||
 | 
			
		||||
    protected int ptr = 0;
 | 
			
		||||
    int ptr = 0;
 | 
			
		||||
    long ptr64 = 0;
 | 
			
		||||
 | 
			
		||||
    private static native boolean init(String lib);
 | 
			
		||||
 | 
			
		||||
@ -81,9 +82,10 @@ abstract class VMwareObject {
 | 
			
		||||
    abstract void destroy();
 | 
			
		||||
 | 
			
		||||
    public void dispose() {
 | 
			
		||||
        if (this.ptr != 0) {
 | 
			
		||||
        if ((this.ptr != 0) || (this.ptr64 != 0)) {
 | 
			
		||||
            destroy();
 | 
			
		||||
            this.ptr = 0;
 | 
			
		||||
            this.ptr64 = 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -23,7 +23,7 @@ import java.util.List;
 | 
			
		||||
public class VMwareServer extends VMwareObject {
 | 
			
		||||
    native void destroy();
 | 
			
		||||
 | 
			
		||||
    private static native int create();
 | 
			
		||||
    private native int create();
 | 
			
		||||
 | 
			
		||||
    public native boolean connect(ConnectParams params)
 | 
			
		||||
        throws VMwareException;
 | 
			
		||||
@ -45,6 +45,6 @@ public class VMwareServer extends VMwareObject {
 | 
			
		||||
        throws VMwareException;
 | 
			
		||||
 | 
			
		||||
    public VMwareServer() {
 | 
			
		||||
        this.ptr = create();
 | 
			
		||||
        create();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user