/* * This file declares some parameters which is common to all IPC mechanisms. Every IPC mechanism * inherits this class and implements the functions declared. Since Java has runtime binding * so the corresponding methods will be called. * * MAXNUMTHREADS - The maximum number of java threads running * EMUTHREADS - The number of emulator threads 1 java thread is reading from * COUNT - this many number of packets is allocated in the shared memory for each * application/emulator thread * */ package emulatorinterface.communication; import java.util.ArrayList; import java.util.concurrent.Semaphore; import config.SystemConfig; import emulatorinterface.GlobalTable; import emulatorinterface.RunnableThread; import generic.CircularPacketQueue; import generic.GenericCircularQueue; public abstract class IpcBase { // Must ensure that MAXNUMTHREADS*EMUTHREADS == MaxNumThreads on the PIN side // Do not move it to config file unless you can satisfy the first constraint //public static final int MaxNumJavaThreads = 1; //public static final int EmuThreadsPerJavaThread = 64; // public static int memMapping[] = new int[EmuThreadsPerJavaThread]; // state management for reader threads public boolean[] javaThreadTermination; public boolean[] javaThreadStarted; // number of instructions read by each of the threads // public long[] numInstructions = new long[MaxNumJavaThreads]; // to maintain synchronization between main thread and the reader threads public static final Semaphore free = new Semaphore(0, true); // public static InstructionTable insTable; public static GlobalTable glTable; // Initialise structures and objects public IpcBase () { javaThreadTermination = new boolean[SystemConfig.maxNumJavaThreads]; javaThreadStarted = new boolean[SystemConfig.maxNumJavaThreads]; for (int i=0; i fromPIN); public abstract int fetchManyPackets(int tidApp, CircularPacketQueue fromEmulator); //public abstract long update(int tidApp, int numReads); // The main thread waits for the finish of reader threads and returns total number of // instructions read // return the total packets produced by PIN till now //public abstract long totalProduced(int tidApp); public abstract void errorCheck(int tidApp, long totalReads); public void waitForJavaThreads() { try { // this takes care if no thread started yet. free.acquire(); int j=0; // if any thread has started and not finished then wait. for (int i=0; i