Skip to content

Commit

Permalink
syscalls2: add multi-abi support
Browse files Browse the repository at this point in the history
syscalls
  • Loading branch information
lacraig2 committed Oct 21, 2024
1 parent bbf9f45 commit e7593ef
Show file tree
Hide file tree
Showing 56 changed files with 78,303 additions and 14,603 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{%- for arch, syscalls in syscalls_arch|dictsort -%}
{%- for arch, syscalls in syscalls_arch.items() -%}
#if {{architectures[arch].get('boilerplate_target', architectures[arch].qemu_target)}}
{%- for syscall_name, syscall in syscalls|dictsort %}
#ifndef PPP_CB_BOILERPLATE_ENTER_ON_{{syscall.name|upper}}_ENTER
#define PPP_CB_BOILERPLATE_ENTER_ON_{{syscall.name|upper}}_ENTER
PPP_CB_BOILERPLATE(on_{{syscall.name}}_enter)
#endif
{%- endfor %}
#endif
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{%- for arch, syscalls in syscalls_arch|dictsort -%}
{%- for arch, syscalls in syscalls_arch.items() -%}
#if {{architectures[arch].get('boilerplate_target', architectures[arch].qemu_target)}}
{%- for syscall_name, syscall in syscalls|dictsort %}
#ifndef PPP_CB_BOILERPLATE_ENTER_ON_{{syscall.name|upper}}_RETURN
#define PPP_CB_BOILERPLATE_ENTER_ON_{{syscall.name|upper}}_RETURN
PPP_CB_BOILERPLATE(on_{{syscall.name}}_return)
#endif
{%- endfor %}
#endif
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{%- for arch, syscalls in syscalls_arch|dictsort -%}
#if {{architectures[arch].qemu_target}}
{%- for arch, syscalls in syscalls_arch.items() -%}
#if {{architectures[arch].get('boilerplate_target', architectures[arch].qemu_target)}}
{%- for syscall_name, syscall in syscalls|dictsort %}
#ifndef PPP_CB_EXTERN_ON_{{syscall.name|upper}}_ENTER
#define PPP_CB_EXTERN_ON_{{syscall.name|upper}}_ENTER
PPP_CB_EXTERN(on_{{syscall.name}}_enter)
#endif
{%- endfor %}
#endif
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{%- for arch, syscalls in syscalls_arch|dictsort -%}
#if {{architectures[arch].qemu_target}}
{%- for arch, syscalls in syscalls_arch.items() -%}
#if {{architectures[arch].get('boilerplate_target', architectures[arch].qemu_target)}}
{%- for syscall_name, syscall in syscalls|dictsort %}
#ifndef PPP_CB_EXTERN_ON_{{syscall.name|upper}}_RETURN
#define PPP_CB_EXTERN_ON_{{syscall.name|upper}}_RETURN
PPP_CB_EXTERN(on_{{syscall.name}}_return)
#endif
{%- endfor %}
#endif
{% endfor %}
Expand Down
30 changes: 23 additions & 7 deletions panda/plugins/syscalls2/generated-tpl/syscall_switch_enter.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
#include "hooks/hooks_int_fns.h"
#include "hw_proc_id/hw_proc_id_ext.h"

extern const syscall_info_t *syscall_info;
extern const syscall_meta_t *syscall_meta;
extern bool load_info;
#if {{ arch_conf.get('runner_target', arch_conf.qemu_target) }}
static bool first_load = true;
static syscall_info_t *info;
static syscall_meta_t *meta;
#endif

extern "C" {
#include "syscalls_ext_typedefs.h"
#include "syscall_ppp_extern_enter.h"
#include "syscall_ppp_extern_return.h"

extern Profile profiles[];
}

/**
Expand All @@ -23,26 +29,36 @@ extern "C" {
* arguments, return address) to prepare for handling the respective
* system call return callbacks.
*/
void syscall_enter_switch_{{os}}_{{arch}}(CPUState *cpu, target_ptr_t pc, int static_callno) {
void syscall_enter_switch_{{os}}_{{arch}}(CPUState *cpu, int profile, target_ptr_t pc, int static_callno) {
#if {{ arch_conf.get('runner_target', arch_conf.qemu_target) }}
CPUArchState *env = (CPUArchState*)cpu->env_ptr;
syscall_ctx_t ctx = {0};
ctx.profile = profile;
if (static_callno == -1) {
ctx.no = {{arch_conf.rt_callno_reg}};
} else {
ctx.no = static_callno;
}
ctx.asid = get_id(cpu);
ctx.retaddr = calc_retaddr(cpu, pc);
ctx.retaddr = calc_retaddr(cpu, &ctx, pc);
ctx.double_return = false;
bool panda_noreturn; // true if PANDA should not track the return of this system call
const syscall_info_t *call = NULL;
syscall_info_t zero = {0};
if (syscall_meta != NULL && ctx.no <= syscall_meta->max_generic) {

// only try this once
if (first_load){
first_load = false;
if (load_info){
sysinfo_load_profile(ctx.profile, &info, &meta);
}
}

if (meta != NULL && ctx.no <= meta->max_generic) {
// If the syscall_info object from dso_info_....c doesn't have an entry
// for this syscall, we want to leave it as a NULL pointer
if (memcmp(&syscall_info[ctx.no], &zero, sizeof(syscall_info_t)) != 0) {
call = &syscall_info[ctx.no];
if (memcmp(&info[ctx.no], &zero, sizeof(syscall_info_t)) != 0) {
call = &info[ctx.no];
}
}

Expand Down
21 changes: 16 additions & 5 deletions panda/plugins/syscalls2/generated-tpl/syscall_switch_return.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
#include "syscalls2.h"
#include "syscalls2_info.h"

extern const syscall_info_t *syscall_info;
extern const syscall_meta_t *syscall_meta;
extern bool load_info;
#if {{ arch_conf.get('runner_target', arch_conf.qemu_target) }}
static bool first_load = true;
static syscall_info_t *info;
static syscall_meta_t *meta;
#endif

extern "C" {
#include "syscalls_ext_typedefs.h"
Expand All @@ -16,11 +20,18 @@ void syscall_return_switch_{{os}}_{{arch}}(CPUState *cpu, target_ptr_t pc, const
#if {{ arch_conf.get('runner_target', arch_conf.qemu_target) }}
const syscall_info_t *call = NULL;
syscall_info_t zero = {0};
if (syscall_meta != NULL && ctx->no <= syscall_meta->max_generic) {
// only try this once
if (first_load){
first_load = false;
if (load_info){
sysinfo_load_profile(ctx->profile, &info, &meta);
}
}
if (meta != NULL && ctx->no <= meta->max_generic) {
// If the syscall_info object from dso_info_....c doesn't have an entry
// for this syscall, we want to leave it as a NULL pointer
if (memcmp(&syscall_info[ctx->no], &zero, sizeof(syscall_info_t)) != 0) {
call = &syscall_info[ctx->no];
if (memcmp(&info[ctx->no], &zero, sizeof(syscall_info_t)) != 0) {
call = &info[ctx->no];
}
}
switch (ctx->no) {
Expand Down
12 changes: 7 additions & 5 deletions panda/plugins/syscalls2/generated-tpl/syscalls_ext_typedefs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ struct syscall_ctx {
uint8_t args[GLOBAL_MAX_SYSCALL_ARGS]
[GLOBAL_MAX_SYSCALL_ARG_SIZE]; /**< arguments */
bool double_return;
int profile;
};
typedef struct syscall_ctx syscall_ctx_t;

/* Functions used to populate syscall_ctx_t structs. */
target_long get_return_val(CPUState *env);
target_ptr_t mask_retaddr_to_pc(target_ptr_t retaddr);
target_ptr_t calc_retaddr(CPUState *env, target_ptr_t pc);
target_long get_return_val(CPUState *env, int profile);
target_ptr_t mask_retaddr_to_pc(target_ptr_t retaddr, syscall_ctx_t *);
target_ptr_t calc_retaddr(CPUState *env, syscall_ctx_t*, target_ptr_t pc);
uint32_t get_32(CPUState *env, syscall_ctx_t*, uint32_t argnum);
int32_t get_s32(CPUState *env, syscall_ctx_t*, uint32_t argnum);
uint64_t get_64(CPUState *env, syscall_ctx_t*, uint32_t argnum);
Expand All @@ -44,9 +45,10 @@ uint32_t get_return_32(CPUState *env, syscall_ctx_t*, uint32_t argnum);
int32_t get_return_s32(CPUState *env, syscall_ctx_t*, uint32_t argnum);
uint64_t get_return_64(CPUState *env, syscall_ctx_t*, uint32_t argnum);
int64_t get_return_s64(CPUState *env, syscall_ctx_t*, uint32_t argnum);
void sysinfo_load_profile(int profile, syscall_info_t **syscall_info, syscall_meta_t **syscall_meta);

{% for arch, syscalls in syscalls_arch|dictsort -%}
#if {{architectures[arch].qemu_target}}
{% for arch, syscalls in syscalls_arch.items() -%}
#if {{architectures[arch].get('typedef_guard', architectures[arch].get('qemu_target'))}}
#include "syscalls_ext_typedefs_{{arch}}.h"
#endif
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
// files in this directory that contain subsections like this one.

{%- for syscall_name, syscall in syscalls|dictsort %}
#ifndef TYPEDEFS_PPP_SYSCALL_ON_{{syscall.name|upper}}_ENTER
#define TYPEDEFS_PPP_SYSCALL_ON_{{syscall.name|upper}}_ENTER 1
PPP_CB_TYPEDEF(void, on_{{syscall.name}}_enter, {{syscall.cargs_signature}});
#endif
#ifndef TYPEDEFS_PPP_SYSCALL_ON_{{syscall.name|upper}}_RETURN
#define TYPEDEFS_PPP_SYSCALL_ON_{{syscall.name|upper}}_RETURN 1
PPP_CB_TYPEDEF(void, on_{{syscall.name}}_return, {{syscall.cargs_signature}});
#endif
{%- endfor %}

// END_PYPANDA_NEEDS_THIS -- do not delete this comment!
Expand Down
Loading

0 comments on commit e7593ef

Please sign in to comment.