To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit 215a4eac authored by john's avatar john
Browse files

changed over to use execvp and waitpid which should align more closely with...

changed over to use execvp and waitpid which should align more closely with windows, and alleviate issues with argument delimiters
parent ba6b675e
......@@ -46,45 +46,6 @@
#define NONE "<none>"
/*
#define LOG_CLASS(jni_table,jvmti_env,klass) \
{\
char* signature = NULL;\
char* generic = NULL;\
\
JVMTI_FUNC_PTR(jvmti_env,GetClassSignature)(jvmti_env,klass,&signature,&generic);\
log_field_string(signature);\
\
if (signature!=NULL) JVMTI_FUNC_PTR(jvmti_env,Deallocate)(jvmti_env,(unsigned char*)signature);\
if (generic!=NULL) JVMTI_FUNC_PTR(jvmti_env,Deallocate)(jvmti_env,(unsigned char*)generic);\
}
#define LOG_OBJECT_CLASS(x)
*/
/*
#define LOG_OBJECT_CLASS(jni_table,jni_env,jvmti_env,object) \
{\
if (object != NULL) {\
jobject klass = JVM_FUNC_PTR(jni_table,GetObjectClass)(jni_env,object); \
jlong klass_tag = 0; \
\
jboolean klass_has_new_tag = getTag(klass,&klass_tag);\
\
log_field_jlong(klass_tag);\
\
if (klass_has_new_tag) {\
LOG_CLASS(jni_table,jvmti_env,JVM_FUNC_PTR(jni_table,GetObjectClass)(jni_env,object));\
} else {\
log_field_string(NULL); \
}\
} else {\
log_field_jlong(0);\
log_field_string(NULL);\
}\
}
*/
#define DEFINE_CALLBACK(cb,c,s) \
(cb)->c = callback##c; \
{ \
......
......@@ -7,6 +7,11 @@
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pthread.h>
......@@ -586,6 +591,59 @@ static jboolean isNotExcluded(const char* name)
return !FALSE;
}
/*
*/
#define JAVA_COMMAND "java"
static int
invokeProcessClassFile(const char* jarSet, const char* infile, const char* outfile, const char* name, const char* agentOptions) {
if (name == NULL) name = "NULL";
pid_t pid = fork();
if (pid == 0) {
char* jarSet_Tmp = (char*)malloc(sizeof(char)*(strlen(jarSet)+1));
char* infile_Tmp = (char*)malloc(sizeof(char)*(strlen(infile)+1));
char* outfile_Tmp = (char*)malloc(sizeof(char)*(strlen(outfile)+1));
char* agentOptions_Tmp = (char*)malloc(sizeof(char)*(strlen(agentOptions)+1));
char* name_Tmp = (char*)malloc(sizeof(char)*(strlen(name)+1));
strcpy(jarSet_Tmp, jarSet);
strcpy(infile_Tmp, infile);
strcpy(outfile_Tmp, outfile);
strcpy(agentOptions_Tmp, agentOptions);
strcpy(name_Tmp, name);
/* child execvp */
char *const args[] = {
JAVA_COMMAND,
"-classpath",
jarSet_Tmp,
"org.dacapo.instrument.Instrument",
infile_Tmp,
outfile_Tmp,
name_Tmp,
agentOptions_Tmp,
NULL
};
execvp(JAVA_COMMAND,args);
exit(10);
} else if (pid == -1) {
fprintf(stderr,"HERE(B)\n");
/* failed to create child */
return -10;
} else {
/* parent wait4 child */
int status = 0;
int options = 0;
pid_t cpid = waitpid(pid,&status,options);
return (pid!=cpid)?-10:WEXITSTATUS(status);
}
}
static void JNICALL
callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv* env,
jclass class_being_redefined, jobject loader,
......@@ -611,11 +669,17 @@ callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv* env,
*new_class_data = NULL;
*new_class_data_len = 0;
/*
sprintf(command, "java -classpath \"%s\" org.dacapo.instrument.Instrument \"%s\" \"%s\" \"%s\" \"%s\"",jarSet,infile,outfile,(name!=NULL?name:"NULL"),agentOptions);
if (system(command) == 0) {
readClassData(infile,new_class_data,new_class_data_len);
}
*/
if (invokeProcessClassFile(jarSet, infile, outfile, name, agentOptions) == 0) {
readClassData(infile,new_class_data,new_class_data_len);
}
}
rawMonitorExit(&lockClass);
......
......@@ -3,11 +3,6 @@
#include "dacapo.h"
/* Agent library externals to export. */
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved);
JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm);
void JNICALL callbackClassPrepare(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jclass klass);
void setLogState(jboolean logState);
......
#include "dacapolock.h"
jboolean rawMonitorInit(jvmtiEnv* baseEnv, const char* name, MonitorLockType* lock) {
#ifdef USE_JAVA_LOCKS
return JVMTI_FUNC_PTR(baseEnv,CreateRawMonitor)(baseEnv, name, lock)==JNI_OK;
#else
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
/* pthread_mutex_t m = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; */
......@@ -12,61 +9,32 @@ jboolean rawMonitorInit(jvmtiEnv* baseEnv, const char* name, MonitorLockType* lo
lock->wait_count = 0;
return !FALSE;
#endif
}
/* Enter a critical section by doing a JVMTI Raw Monitor Enter */
void rawMonitorEnter(MonitorLockType* lock)
{
#ifdef USE_JAVA_LOCKS
if (JVMTI_FUNC_PTR(baseEnv,RawMonitorEnter)(baseEnv, *lock) != JNI_OK) {
fprintf(stderr, "cannot enter with raw monitor\n");
}
#else
pthread_mutex_lock(&(lock->lock));
#endif
}
/* Exit a critical section by doing a JVMTI Raw Monitor Exit */
void rawMonitorExit(MonitorLockType* lock)
{
#ifdef USE_JAVA_LOCKS
if (JVMTI_FUNC_PTR(baseEnv,RawMonitorExit)(baseEnv, *lock) != JNI_OK) {
fprintf(stderr, "cannot exit with raw monitor\n");
}
#else
pthread_mutex_unlock(&(lock->lock));
#endif
}
jboolean rawMonitorWait(MonitorLockType* lock,jlong timeout)
{
#ifdef USE_JAVA_LOCKS
jvmtiError error = JVMTI_FUNC_PTR(baseEnv,RawMonitorWait)(baseEnv,*lock,timeout);
if (error != JNI_OK && error != JVMTI_ERROR_NOT_MONITOR_OWNER) {
fprintf(stderr, "cannot wait with raw monitor\n");
}
return error == JNI_OK;
#else
lock->wait_count++;
pthread_cond_wait(&(lock->cond),&(lock->lock));
lock->wait_count--;
return !FALSE;
#endif
}
void rawMonitorNotify(MonitorLockType* lock)
{
#ifdef USE_JAVA_LOCKS
if (JVMTI_FUNC_PTR(baseEnv,RawMonitorNotify)(baseEnv,*lock)!=JNI_OK) {
fprintf(stderr, "cannot notify raw monitor\n");
}
#else
/* do not signal if nothing is waiting */
if (0<lock->wait_count)
pthread_cond_signal(&(lock->cond));
#endif
}
......@@ -5,18 +5,12 @@
#include "dacapo.h"
/* #define USE_JAVA_LOCKS */
#ifdef USE_JAVA_LOCKS
typedef jrawMonitorID MonitorLockType;
#else
struct MonitorLockType_s {
pthread_mutex_t lock;
pthread_cond_t cond;
int wait_count;
};
typedef struct MonitorLockType_s MonitorLockType;
#endif
jboolean rawMonitorInit(jvmtiEnv* baseEnv, const char* name, MonitorLockType* lock);
......
......@@ -24,20 +24,6 @@
MonitorLockType lockLog;
MonitorLockType gcLock;
/*
#define FILE_TYPE FILE*
#define FILE_IS_CLOSED NULL
#define FILE_FLAGS "w+"
#define CLOSE(f) fclose(f)
#define OPEN(f,m) fopen(f,FILE_FLAGS)
#define FLUSH(f) fflush(f)
#define WRITE(b,e,n,f) fwrite(b,e,n,f)
FILE_TYPE logFile = FILE_IS_CLOSED;
*/
#define FILE_TYPE int
#define FILE_IS_CLOSED -1
......
......@@ -52,7 +52,6 @@
extern MonitorLockType lockLog;
extern MonitorLockType agentLock;
/* extern FILE* logFile; */
extern jboolean logState;
_Bool dacapo_log_init();
......
......@@ -6,28 +6,12 @@
#include <sys/time.h>
#include <unistd.h>
/*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdarg.h>
*/
#include "dacapooptions.h"
#ifndef FALSE
#define FALSE 0
#endif
/*
public static final String CLASSES_INITIALIZATION = "clinit";
public static final String METHOD_CALLS = "method_calls";
public static final String LOG_START = "log_start";
public static final String LOG_STOP = "log_stop";
public static final String RUNTIME = "runtime";
*/
struct option_s {
struct option_s* next;
char* option;
......
......@@ -10,8 +10,6 @@ void thread_live(jvmtiEnv* jvmti, JNIEnv* env);
void thread_logon(JNIEnv* env);
void thread_class(jvmtiEnv *env, JNIEnv *jnienv, jthread thread, jclass klass);
/* void thread_log(JNIEnv* env, jthread thread, jlong thread_tag, jboolean thread_has_new_tag); */
void thread_agent_log(JNIEnv *env, jclass klass, jobject thread);
void threads_states(JNIEnv* env);
......
package org.dacapo.instrument;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URI;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
import org.dacapo.instrument.instrumenters.AllocateInstrument;
import org.dacapo.instrument.instrumenters.CallChainInstrument;
import org.dacapo.instrument.instrumenters.ClinitInstrument;
import org.dacapo.instrument.instrumenters.Instrumenter;
import org.dacapo.instrument.instrumenters.InstrumenterFactory;
import org.dacapo.instrument.instrumenters.LogInstrument;
import org.dacapo.instrument.instrumenters.MethodInstrument;
import org.dacapo.instrument.instrumenters.MonitorInstrument;
import org.dacapo.instrument.instrumenters.RuntimeInstrument;
import org.dacapo.instrument.instrumenters.VersionChanger;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.AdviceAdapter;
......@@ -68,8 +49,6 @@ public class Instrument extends Instrumenter {
// read the class to do some pre-processing
ClassReader reader = readClassFromFile(infile);
//
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassVisitor cv = writer;
......@@ -165,7 +144,6 @@ public class Instrument extends Instrumenter {
private static class Maxs extends AdviceAdapter {
public String encodedName;
public int maxLocals;
public int maxStack;
private TreeMap<String,Integer> methodToLargestLocal;
public Maxs(int access, String klass, String name, String desc, MethodVisitor mv, TreeMap<String,Integer> methodToLargestLocal) {
......@@ -173,7 +151,6 @@ public class Instrument extends Instrumenter {
this.encodedName = encodeMethodName(klass,name,desc);
this.maxLocals = getArgumentSizes(access, desc);
this.maxStack = 0;
this.methodToLargestLocal = methodToLargestLocal;
this.methodToLargestLocal.put(this.encodedName, new Integer(this.maxLocals));
......@@ -190,7 +167,6 @@ public class Instrument extends Instrumenter {
public void visitMaxs(int maxStack, int maxLocals) {
this.maxLocals = maxLocals;
if (this.maxLocals < maxStack) {
this.maxStack = maxStack;
methodToLargestLocal.put(encodedName, new Integer(this.maxLocals));
}
super.visitMaxs(maxStack, maxLocals);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment