Skip to content

Commit

Permalink
libtcg: moved s2e-specifc functions to separate files
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr>
  • Loading branch information
vitalych committed Mar 2, 2024
1 parent f630b6b commit fcc688c
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 15 deletions.
2 changes: 2 additions & 0 deletions libcpu/src/softmmu_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "exec.h"
#include "timer.h"

#include <tcg/tcg-s2e.h>

#define DATA_SIZE (1 << SHIFT)

#if DATA_SIZE == 8
Expand Down
2 changes: 2 additions & 0 deletions libcpu/src/target-i386/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <tcg/exec/helper-info.c.inc>
#undef HELPER_H

#include <tcg/tcg-s2e.h>

// clang-format on

#include <cpu/disas.h>
Expand Down
49 changes: 49 additions & 0 deletions libtcg/include/tcg/tcg-s2e.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Tiny Code Generator for QEMU
*
* Copyright (c) 2008 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef TCGS2E_H
#define TCGS2E_H

#include <inttypes.h>
#include "tcg.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef CONFIG_SYMBEX
static inline int tcg_is_dyngen_addr(void *addr) {
uintptr_t a = (uintptr_t) addr;
return (a >= (uintptr_t) tcg_ctx->code_gen_buffer) &&
(a < ((uintptr_t) tcg_ctx->code_gen_buffer + (uintptr_t) tcg_ctx->code_gen_buffer_size));
}

void tcg_calc_regmask(TCGContext *s, uint64_t *rmask, uint64_t *wmask, uint64_t *accesses_mem);
#endif

#ifdef __cplusplus
}
#endif

#endif
14 changes: 0 additions & 14 deletions libtcg/include/tcg/tcg.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,14 +721,6 @@ extern const void *tcg_code_gen_epilogue;
extern uintptr_t tcg_splitwx_diff;
extern TCGv_env cpu_env;

#ifdef CONFIG_SYMBEX
static inline int tcg_is_dyngen_addr(void *addr) {
uintptr_t a = (uintptr_t) addr;
return (a >= (uintptr_t) tcg_ctx->code_gen_buffer) &&
(a < ((uintptr_t) tcg_ctx->code_gen_buffer + (uintptr_t) tcg_ctx->code_gen_buffer_size));
}
#endif

bool in_code_gen_buffer(const void *p);

#ifdef CONFIG_DEBUG_TCG
Expand Down Expand Up @@ -1246,12 +1238,6 @@ void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs);
void tcg_target_force_tb_exit(uintptr_t gen_code, uintptr_t max_addr);
bool tcg_can_emit_vecop_list(const TCGOpcode *, TCGType, unsigned);

#ifdef CONFIG_SYMBEX
void tcg_calc_regmask(TCGContext *s, uint64_t *rmask, uint64_t *wmask, uint64_t *accesses_mem);
#endif

const char *tcg_helper_get_name(TCGContext *s, void *func);

#define plugin_gen_disable_mem_helpers()

enum qemu_plugin_mem_rw {
Expand Down
2 changes: 1 addition & 1 deletion libtcg/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set (TCG_SOURCES)
list (APPEND TCG_SOURCES
utils/cutils.c utils/osdep.c utils/memalign.c utils/cache.c utils/log.c
utils/cpuinfo-i386.c utils/qtree.c utils/host-utils.c
region.c tcg.c tcg-op-ldst.c tcg-common.c tcg-op.c optimize.c tcg-op-gvec.c tcg-op-vec.c
region.c tcg.c tcg-s2e.c tcg-op-ldst.c tcg-common.c tcg-op.c optimize.c tcg-op-gvec.c tcg-op-vec.c
tcg-rt/tcg-runtime-gvec.c tcg-rt/tcg-runtime.c
atomic-helpers.c
fpu/softfloat.c)
Expand Down
77 changes: 77 additions & 0 deletions libtcg/src/tcg-s2e.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
///
/// Copyright (C) 2015-2024, Cyberhaven
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all
/// copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/// SOFTWARE.
///

#include <tcg/tcg-s2e.h>

// Computes the register mask of the last instruction in the current context
void tcg_calc_regmask(TCGContext *s, uint64_t *rmask, uint64_t *wmask, uint64_t *accesses_mem) {
const TCGOp *op;
const TCGOpDef *def;
int c, i, nb_oargs, nb_iargs;

*rmask = *wmask = *accesses_mem = 0;

// We must go in reverse as we need only the last instruction
QTAILQ_FOREACH_REVERSE(op, &s->ops, link) {
c = op->opc;
def = &tcg_op_defs[c];

if (c == INDEX_op_insn_start) {
break;
}

if (c == INDEX_op_call) {
/* variable number of arguments */
nb_oargs = TCGOP_CALLO(op);
nb_iargs = TCGOP_CALLI(op);

/* We don't track register masks for helpers anymore, assume access everything */
*rmask |= -1;
*wmask |= -1;
*accesses_mem |= 1;
return;
}

nb_oargs = def->nb_oargs;
nb_iargs = def->nb_iargs;

for (i = 0; i < nb_iargs; i++) {
TCGArg arg = op->args[nb_oargs + i];
TCGTemp *tmp = arg_temp(arg);
size_t idx = temp_idx(tmp);

if (idx < s->nb_globals) {
*rmask |= (1 << idx);
}
}

for (i = 0; i < nb_oargs; i++) {
TCGArg arg = op->args[i];
TCGTemp *tmp = arg_temp(arg);
size_t idx = temp_idx(tmp);

if (idx < s->nb_globals) {
*wmask |= (1 << idx);
}
}
}
}

0 comments on commit fcc688c

Please sign in to comment.