Geant4  10.00.p03
ProtectedMemory.cc File Reference
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <libgen.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <assert.h>
#include <signal.h>
#include <execinfo.h>
#include <sys/syscall.h>
#include <pthread.h>
#include "tls.hh"
#include "memoryprotection/UDSignals.h"
#include "memoryprotection/MemorySegment.h"
+ Include dependency graph for ProtectedMemory.cc:

Go to the source code of this file.

Macros

#define MAXTHREADS   128
 

Functions

static pid_t gettid ()
 
void * AllocateInProtectedHeap (size_t size)
 
static void AllocateProtectedHeap (size_t totalSize, size_t pagesize)
 
static int readFile (char *filename, char *buf, int maxSize)
 
static char * readhex (char *string, long *value)
 
static char * readMapsLine (char *string, void **start, void **end, int *writable, char *filename)
 
static void * getPageNumber (void *theAddress)
 
static void setuphandler0 ()
 
static void setuphandler1 ()
 
static void setuphandler2 ()
 
static void SetUpAllProtect ()
 
static void UnSetUpAllProtect ()
 
void PhaseChange ()
 
static void record_stackframe ()
 
static void show_stackframe ()
 
static void handler0 (int, siginfo_t *, void *)
 
static void handler1 (int, siginfo_t *, void *)
 
static void handler2 (int, siginfo_t *, void *)
 
void BuildProtectedMemory (size_t totalHeap)
 
void addThread ()
 
void setuphandlers ()
 
void starttracer ()
 
void finishtracer ()
 
void StartDetection ()
 
void FinishDetection ()
 

Variables

static char * startPosition = 0
 
static char * currentPosition = 0
 
static char * nextPosition = 0
 
static char * endPosition = 0
 
static size_t pagesize
 
static int logpagesize
 
static char application [1024]
 
static int phase = 0
 
static G4ThreadLocal void * trace [100]
 
static int outputFile = -1
 
static int trace_size
 
static int isCalled = 0
 
int numberOfThreads = 0
 
pid_t threads [MAXTHREADS]
 
pid_t tracerpid
 

Macro Definition Documentation

#define MAXTHREADS   128

Definition at line 456 of file ProtectedMemory.cc.

Referenced by addThread().

Function Documentation

void addThread ( )

Definition at line 462 of file ProtectedMemory.cc.

References assert, gettid(), MAXTHREADS, numberOfThreads, and threads.

+ Here is the call graph for this function:

void* AllocateInProtectedHeap ( size_t  size)

Definition at line 36 of file ProtectedMemory.cc.

References currentPosition, endPosition, malloc(), nextPosition, and startPosition.

+ Here is the call graph for this function:

static void AllocateProtectedHeap ( size_t  totalSize,
size_t  pagesize 
)
static

Definition at line 55 of file ProtectedMemory.cc.

References currentPosition, endPosition, malloc(), nextPosition, pagesize, and startPosition.

Referenced by BuildProtectedMemory().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BuildProtectedMemory ( size_t  totalHeap)

Definition at line 183 of file ProtectedMemory.cc.

References AllocateProtectedHeap(), application, endPosition, getPageNumber(), logpagesize, nextPosition, outputFile, pagesize, phase, readFile(), readMapsLine(), and show_stackframe().

Referenced by starttracer().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void FinishDetection ( )

Definition at line 525 of file ProtectedMemory.cc.

References assert.

void finishtracer ( )

Definition at line 505 of file ProtectedMemory.cc.

References assert, outputFile, tracerpid, and UnSetUpAllProtect().

+ Here is the call graph for this function:

static void * getPageNumber ( void *  theAddress)
static

Definition at line 98 of file ProtectedMemory.cc.

References logpagesize.

Referenced by BuildProtectedMemory().

+ Here is the caller graph for this function:

static pid_t gettid ( )
static

Definition at line 24 of file ProtectedMemory.cc.

Referenced by addThread().

+ Here is the caller graph for this function:

static void handler0 ( int  ,
siginfo_t *  ,
void *   
)
static

Definition at line 133 of file ProtectedMemory.cc.

References assert, isCalled, and SetUpAllProtect().

Referenced by setuphandler0().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void handler1 ( int  ,
siginfo_t *  ,
void *   
)
static

Definition at line 152 of file ProtectedMemory.cc.

References assert, record_stackframe(), and UnSetUpAllProtect().

Referenced by setuphandler1().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void handler2 ( int  ,
siginfo_t *  ,
void *   
)
static

Definition at line 174 of file ProtectedMemory.cc.

References SetUpAllProtect().

Referenced by setuphandler2().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void PhaseChange ( )

Definition at line 104 of file ProtectedMemory.cc.

References outputFile, and phase.

static int readFile ( char *  filename,
char *  buf,
int  maxSize 
)
static

Definition at line 369 of file ProtectedMemory.cc.

Referenced by BuildProtectedMemory().

+ Here is the caller graph for this function:

static char * readhex ( char *  string,
long *  value 
)
static

Definition at line 389 of file ProtectedMemory.cc.

Referenced by readMapsLine().

+ Here is the caller graph for this function:

static char * readMapsLine ( char *  string,
void **  start,
void **  end,
int *  writable,
char *  filename 
)
static

Definition at line 403 of file ProtectedMemory.cc.

References readhex().

Referenced by BuildProtectedMemory().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void record_stackframe ( )
static

Definition at line 119 of file ProtectedMemory.cc.

References outputFile, trace, and trace_size.

Referenced by handler1().

+ Here is the caller graph for this function:

static void SetUpAllProtect ( )
static

Definition at line 421 of file ProtectedMemory.cc.

Referenced by handler0(), and handler2().

+ Here is the caller graph for this function:

static void setuphandler0 ( )
static

Definition at line 577 of file ProtectedMemory.cc.

References handler0().

Referenced by setuphandlers().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void setuphandler1 ( )
static

Definition at line 588 of file ProtectedMemory.cc.

References handler1().

Referenced by setuphandlers().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void setuphandler2 ( )
static

Definition at line 599 of file ProtectedMemory.cc.

References handler2().

Referenced by setuphandlers().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void setuphandlers ( )

Definition at line 570 of file ProtectedMemory.cc.

References setuphandler0(), setuphandler1(), and setuphandler2().

Referenced by starttracer().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void show_stackframe ( )
static

Definition at line 125 of file ProtectedMemory.cc.

References trace, and trace_size.

Referenced by BuildProtectedMemory().

+ Here is the caller graph for this function:

void StartDetection ( )

Definition at line 516 of file ProtectedMemory.cc.

References assert, and isCalled.

void starttracer ( )

Definition at line 474 of file ProtectedMemory.cc.

References application, BuildProtectedMemory(), numberOfThreads, setuphandlers(), threads, and tracerpid.

+ Here is the call graph for this function:

static void UnSetUpAllProtect ( )
static

Definition at line 440 of file ProtectedMemory.cc.

Referenced by finishtracer(), and handler1().

+ Here is the caller graph for this function:

Variable Documentation

char application[1024]
static

Definition at line 92 of file ProtectedMemory.cc.

Referenced by BuildProtectedMemory(), and starttracer().

int isCalled = 0
static

Definition at line 131 of file ProtectedMemory.cc.

Referenced by handler0(), and StartDetection().

int logpagesize
static

Definition at line 85 of file ProtectedMemory.cc.

Referenced by BuildProtectedMemory(), and getPageNumber().

char* nextPosition = 0
static
int numberOfThreads = 0

Definition at line 457 of file ProtectedMemory.cc.

Referenced by addThread(), and starttracer().

int outputFile = -1
static
size_t pagesize
static

Definition at line 84 of file ProtectedMemory.cc.

Referenced by AllocateProtectedHeap(), and BuildProtectedMemory().

int phase = 0
static
pid_t threads[MAXTHREADS]

Definition at line 458 of file ProtectedMemory.cc.

Referenced by addThread(), and starttracer().

G4ThreadLocal void* trace[100]
static

Definition at line 100 of file ProtectedMemory.cc.

Referenced by record_stackframe(), and show_stackframe().

int trace_size
static

Definition at line 102 of file ProtectedMemory.cc.

Referenced by record_stackframe(), and show_stackframe().

pid_t tracerpid

Definition at line 459 of file ProtectedMemory.cc.

Referenced by finishtracer(), and starttracer().