Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Structures | Functions | Variables
filter.cc File Reference
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include "memoryprotection/filter.h"

Go to the source code of this file.

Data Structures

struct  AddressTable
 

Functions

int bSearchAddress (unsigned long address, int head, int tail)
 
int findAddress (unsigned long address)
 
int insertAddress (unsigned long address)
 
void outputAddresses (char *cmd)
 
void generategdbscripts ()
 

Variables

int position = -1
 
struct AddressTable Detected
 

Function Documentation

int bSearchAddress ( unsigned long  address,
int  head,
int  tail 
)

Definition at line 18 of file filter.cc.

References AddressTable::addresses, and Detected.

Referenced by findAddress().

19 {
20  if (head >= tail)
21  {
22  position = tail;
23 
24  return -1;
25  }
26  int middle = (head + tail) / 2;
27  if (Detected.addresses[middle] == address)
28  {
29  position = middle;
30  return 0;
31  }
32  else if (Detected.addresses[middle] < address)
33  return bSearchAddress(address, middle + 1, tail);
34  else
35  return bSearchAddress(address, 0, middle);
36 }
struct AddressTable Detected
Posf * head
Definition: deflate.h:137
int bSearchAddress(unsigned long address, int head, int tail)
Definition: filter.cc:18
unsigned long * addresses
Definition: filter.cc:15
int findAddress ( unsigned long  address)

Definition at line 38 of file filter.cc.

References bSearchAddress(), AddressTable::counter, and Detected.

Referenced by insertAddress().

39 {
40  if (position == -1) return -1;
41  return bSearchAddress(address, 0, Detected.counter);
42 }
struct AddressTable Detected
int counter
Definition: filter.cc:13
int bSearchAddress(unsigned long address, int head, int tail)
Definition: filter.cc:18
void generategdbscripts ( )

Definition at line 97 of file filter.cc.

References AddressTable::addresses, AddressTable::counter, and Detected.

Referenced by openFilter().

98 {
99  int i;
100 
101  pid_t myselfpid = getpid();
102  char gdbcommands[1024];
103  gdbcommands[0] = 0;
104  sprintf(gdbcommands, "./gdbcommands.%d", myselfpid);
105 
106  FILE *fp = fopen(gdbcommands, "w+");
107  for (i = 0 ; i < Detected.counter ; i++)
108  {
109  fprintf(fp, "break *0x%lx\n", Detected.addresses[i]);
110  fprintf(fp, "commands\n");
111  fprintf(fp, "bt 10\n");
112  fprintf(fp, "cont\n");
113  fprintf(fp, "end\n");
114  }
115  fprintf(fp, "cont\n");
116  fclose(fp);
117 }
struct AddressTable Detected
int counter
Definition: filter.cc:13
unsigned long * addresses
Definition: filter.cc:15
int insertAddress ( unsigned long  address)

Definition at line 44 of file filter.cc.

References AddressTable::addresses, assert, AddressTable::counter, Detected, findAddress(), malloc(), position, realloc(), and AddressTable::space.

Referenced by openFilter().

45 {
46  if (position == -1)
47  {
48  Detected.space = 4096;
49  assert(0 != (Detected.addresses = (unsigned long *) malloc(sizeof(unsigned long) * Detected.space)));
50  Detected.counter = 1;
51  position = 0;
52  #ifdef ADDRESSTABLEDEBUG
53  printf("Inserted position: %d, address: 0x%lx.\n", position, address);
54  #endif
55  Detected.addresses[position] = address;
56  return 0;
57  }
58  else
59  {
60  if (-1 == findAddress(address))
61  {
62  #ifdef ADDRESSTABLEDEBUG
63  printf("Inserted position: %d, address: 0x%lx.\n", position, address);
64  #endif
65  Detected.counter++;
67  {
68  Detected.space = Detected.space + 4096;
69 
70  assert(0 != (Detected.addresses = (unsigned long *) realloc((char *)Detected.addresses, sizeof(unsigned long) * Detected.space)));
71  }
72  int i;
73  for (i = Detected.counter - 1; i > position ; i--)
75  Detected.addresses[i] = address;
76 
77  return 0;
78  }
79  else
80  return -1;
81  }
82 }
struct AddressTable Detected
#define assert(x)
Definition: mymalloc.cc:1309
int space
Definition: filter.cc:14
int counter
Definition: filter.cc:13
int position
Definition: filter.cc:7
int findAddress(unsigned long address)
Definition: filter.cc:38
void * realloc(void *__ptr, size_t __size)
Definition: hjmalloc.cc:103
unsigned long * addresses
Definition: filter.cc:15
void * malloc(size_t __size)
Definition: hjmalloc.cc:30
void outputAddresses ( char *  cmd)

Definition at line 84 of file filter.cc.

References AddressTable::addresses, AddressTable::counter, and Detected.

Referenced by openFilter().

85 {
86  int i;
87  char convertcmd[1024];
88  printf("Lines that produce segmentation faults:\n");
89  for (i = 0 ; i < Detected.counter ; i++)
90  {
91  sprintf(convertcmd, "addr2line -e %s 0x%lx", cmd, Detected.addresses[i]);
92  system(convertcmd);
93  printf("%s address[%d]= 0x%lx\n", cmd, i, Detected.addresses[i]);
94  }
95 }
struct AddressTable Detected
char cmd[1024]
Definition: tracer.cxx:25
int counter
Definition: filter.cc:13
unsigned long * addresses
Definition: filter.cc:15

Variable Documentation

struct AddressTable Detected
int position = -1

Definition at line 7 of file filter.cc.

Referenced by G4ArrayOps::Add(), G4eLowEnergyLoss::AlongStepDoIt(), G4GDMLReadSolids::BooleanRead(), G4SafetyHelper::CheckNextStep(), G4SafetyHelper::ComputeSafety(), G4MultiNavigator::ComputeSafety(), G4PathFinder::ComputeSafety(), RE02NestedPhantomParameterisation::ComputeTransformation(), G02DetectorConstruction::ConstructAssembly(), G4ArrayOps::Copy(), G4LowEnergyIonisation::DeexciteAtom(), G4ArrayOps::Divide(), Par01PiModel::DoIt(), G4DNAIndirectHit::G4DNAIndirectHit(), G4PAIPhotonModel::GetAlongStepTransfer(), G4PAIxSection::GetCerenkovEnergyTransfer(), XrayFluoDetectorConstruction::GetDetectorPosition(), G4PAIxSection::GetEnergyTransfer(), G4PAIxSection::GetMMEnergyTransfer(), G4PAIxSection::GetPlasmonEnergyTransfer(), G4PAIPhotonModel::GetPostStepTransfer(), G4VXTRenergyLoss::GetRandomAngle(), G4SynchrotronRadiationInMat::GetRandomEnergySR(), G4PAIxSection::GetResonanceEnergyTransfer(), G4PAIxSection::GetRutherfordEnergyTransfer(), G4PAIySection::GetStepCerenkovLoss(), G4PAIySection::GetStepEnergyLoss(), G4PAIySection::GetStepPlasmonLoss(), G4VXTRenergyLoss::GetXTRrandomEnergy(), HepMCG4Interface::HepMC2G4(), insertAddress(), G4PathFinder::Locate(), G4MultiNavigator::LocateGlobalPointWithinVolume(), G4ArrayOps::Multiply(), G4GDMLReadParamvol::ParametersRead(), G4GDMLReadStructure::PhysvolRead(), G4GDMLReadDefine::PositionRead(), G4PathFinder::PrepareNewTrack(), CexmcTrackPoints::ProcessHits(), G4FastStep::ProposePrimaryTrackFinalPosition(), G4GDMLReadSolids::ReflectedSolidRead(), G4PathFinder::ReLocate(), G4GDMLReadStructure::ReplicaRead(), CexmcPhysicsList< BasePhysics, StudiedPhysics, ProductionModel >::ResampleTrackLengthInTarget(), G4PAIPhotData::SampleAlongStepPhotonTransfer(), G4PAIPhotData::SampleAlongStepPlasmonTransfer(), G4PAIPhotData::SampleAlongStepTransfer(), G4PAIModelData::SampleAlongStepTransfer(), G4PAIPhotData::SamplePostStepPhotonTransfer(), G4PAIPhotData::SamplePostStepPlasmonTransfer(), G4PAIModelData::SamplePostStepTransfer(), G4PAIPhotData::SamplePostStepTransfer(), G4NuclNuclDiffuseElastic::SampleTableThetaCMS(), G4DiffuseElastic::SampleTableThetaCMS(), G4ArrayOps::Set(), CexmcParticleGun::SetOrigPosition(), G4INCL::Particle::setPosition(), G4INCL::StandardPropagationModel::shootComposite(), G4INCL::StandardPropagationModel::shootParticle(), and G4ArrayOps::Subtract().