Skip to content

Commit

Permalink
Initial implementation of system call events in ProcControlAPI.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilygemberjacobson authored and wrwilliams committed Jun 19, 2014
1 parent 49d12d6 commit 7b8d777
Show file tree
Hide file tree
Showing 16 changed files with 3,565 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/h/dyn_regs.h
Expand Up @@ -89,9 +89,13 @@ namespace Dyninst
static MachRegister getPC(Dyninst::Architecture arch);
static MachRegister getFramePointer(Dyninst::Architecture arch);
static MachRegister getStackPointer(Dyninst::Architecture arch);
static MachRegister getSyscallNumberReg(Dyninst::Architecture arch);
static MachRegister getSyscallReturnValueReg(Dyninst::Architecture arch);
bool isPC() const;
bool isFramePointer() const;
bool isStackPointer() const;
bool isSyscallNumberReg() const;
bool isSyscallReturnValueReg() const;

void getROSERegister(int &c, int &n, int &p);

Expand Down
136 changes: 136 additions & 0 deletions common/src/MachSyscall.C
@@ -0,0 +1,136 @@
#include "dynutil/h/MachSyscall.h"
#include "dynutil/h/dyntypes.h"

using namespace std;
using namespace Dyninst;

bool Platform::operator==(const Platform & p) const
{
return ((_arch == p._arch) && (_os == p._os));
}


class SyscallInformation
{
public:
static SyscallInformation * getInstance();

MachSyscall::SyscallName findName(Platform, MachSyscall::SyscallIDPlatform);
MachSyscall::SyscallIDPlatform findIDPlatform(Platform, MachSyscall::SyscallIDIndependent);

private:
SyscallInformation();
static SyscallInformation * theInstance;

typedef dyn_hash_map<MachSyscall::SyscallIDIndependent, MachSyscall::SyscallIDPlatform> syscallNumbersMap;
typedef dyn_hash_map<MachSyscall::SyscallIDPlatform, MachSyscall::SyscallName> syscallNamesMap;

syscallNumbersMap Linux_Arch_x86_syscallNumbers;
syscallNamesMap Linux_Arch_x86_syscallNames;

syscallNumbersMap Linux_Arch_x86_64_syscallNumbers;
syscallNamesMap Linux_Arch_x86_64_syscallNames;

syscallNumbersMap Linux_Arch_ppc32_syscallNumbers;
syscallNamesMap Linux_Arch_ppc32_syscallNames;

syscallNumbersMap Linux_Arch_ppc64_syscallNumbers;
syscallNamesMap Linux_Arch_ppc64_syscallNames;
};

SyscallInformation * SyscallInformation::theInstance = NULL;

SyscallInformation * SyscallInformation::getInstance()
{
if(SyscallInformation::theInstance == NULL) {
SyscallInformation::theInstance = new SyscallInformation;
}
return SyscallInformation::theInstance;
}

MachSyscall::SyscallName SyscallInformation::findName(Platform plat, MachSyscall::SyscallIDPlatform id)
{
syscallNamesMap curMap;
if (plat == Platform(Arch_x86, Linux)) {
curMap = Linux_Arch_x86_syscallNames;
} else if (plat == Platform(Arch_x86_64, Linux)) {
curMap = Linux_Arch_x86_64_syscallNames;
} else if (plat == Platform(Arch_ppc32, Linux)) {
curMap = Linux_Arch_ppc32_syscallNames;
} else if (plat == Platform(Arch_ppc64, Linux)) {
curMap = Linux_Arch_ppc64_syscallNames;
} else {
// We don't know anything about this platform
return "unknownSyscall";
}

auto found = curMap.find(id);
if (found == curMap.end()) {
// Well, crap
return "unknownSyscall";
}
return found->second;
}

MachSyscall::SyscallIDPlatform SyscallInformation::findIDPlatform(Platform plat, MachSyscall::SyscallIDIndependent id)
{
syscallNumbersMap curMap;
if (plat == Platform(Arch_x86, Linux)) {
curMap = Linux_Arch_x86_syscallNumbers;
} else if (plat == Platform(Arch_x86_64, Linux)) {
curMap = Linux_Arch_x86_64_syscallNumbers;
} else if (plat == Platform(Arch_ppc32, Linux)) {
curMap = Linux_Arch_ppc32_syscallNumbers;
} else if (plat == Platform(Arch_ppc64, Linux)) {
curMap = Linux_Arch_ppc64_syscallNumbers;
} else {
// We don't know anything about this platform
return -1;
}

auto found = curMap.find(id);
if (found == curMap.end()) {
// Well, crap
return -1;
}
return found->second;
}

/* This file is auto-generated from syscalls/generateSyscallInformation.py */
#include "SyscallInformation.C"

/* Lookup the system call string name based on platform-specific ID */
MachSyscall::SyscallName MachSyscall::nameLookup(Platform plat, SyscallIDPlatform id)
{
return SyscallInformation::getInstance()->findName(plat, id);
}

MachSyscall MachSyscall::makeFromPlatform(Platform plat, SyscallIDIndependent id)
{
// 1. Convert SyscallIDIndependent to SyscallIDPlatform
SyscallIDPlatform syscallNumber = SyscallInformation::getInstance()->findIDPlatform(plat, id);
if (syscallNumber == (MachSyscall::SyscallIDPlatform)-1) {
return MachSyscall(plat, -1, "unknownSyscall");
}

// 2. MachSyscall::nameLookup(SyscallIDPlatform)
SyscallName syscallName= nameLookup(plat, syscallNumber);

return MachSyscall(plat, syscallNumber, syscallName);
}

unsigned long MachSyscall::num() const
{
return _id;
}

MachSyscall::SyscallName MachSyscall::name() const
{
return _name;
}

bool MachSyscall::operator==(const MachSyscall & m) const
{
return ((_plat == m._plat) && (_id == m._id));
}

0 comments on commit 7b8d777

Please sign in to comment.