Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions accel/tcg/cpu-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
#ifdef CONFIG_LATX_KZT
Dl_info dl_info;
if (option_kzt && itb->pc > reserved_va &&
if (latx_kzt_runtime_enabled() && itb->pc > reserved_va &&
dladdr ((const void *)((onebridge_t *)itb->pc)->f, &dl_info)) {
qemu_log_mask_and_addr(CPU_LOG_EXEC, itb->pc,
"pid(%d) - tid(%" PRIuPTR ") Trace cpu%d: %p [ "
Expand Down Expand Up @@ -285,7 +285,7 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
}
lazypc = rettb->pc + rettb->lazypc[0];
#if defined(CONFIG_LATX_KZT)
if (option_kzt && lazypc >= reserved_va) {
if (latx_kzt_runtime_enabled() && lazypc >= reserved_va) {
uintptr_t alt_pc = (uintptr_t)getAlternate((void *)(uintptr_t)lazypc);
if (alt_pc != (uintptr_t)lazypc) {
lazypc = alt_pc;
Expand Down Expand Up @@ -853,7 +853,7 @@ TranslationBlock * kzt_tb_find_exp(
static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
{
#if defined(CONFIG_LATX_KZT)
if (option_kzt) {
if (latx_kzt_runtime_enabled()) {
CPUArchState *env = cpu->env_ptr;
if(env->eip == (uint64_t)&RunFunctionWithState){
*ret = 0xCC;
Expand Down Expand Up @@ -945,7 +945,7 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,
TranslationBlock **last_tb)
{
#if defined(CONFIG_LATX_KZT)
if (option_kzt) {
if (latx_kzt_runtime_enabled()) {
CPUArchState *env = cpu->env_ptr;
if(env->eip == (uint64_t)&RunFunctionWithState){
*last_tb = NULL;
Expand Down
1 change: 1 addition & 0 deletions accel/tcg/tb-flush.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count)
}
#if defined(CONFIG_LATX_KZT)
CPU_FOREACH(cpu) {
/* The installer also checks the effective library-group mask. */
if (cpu && option_kzt) {
kzt_install_runtime_callbacks(cpu, &info1);
}
Expand Down
2 changes: 1 addition & 1 deletion accel/tcg/translate-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -3817,7 +3817,7 @@ void *page_alloc_target_data(target_ulong address, size_t size)
bool page_check_range(target_ulong start, target_ulong len, int flags)
{
#if defined(CONFIG_LATX_KZT)
if (option_kzt && start > reserved_va) {
if (latx_kzt_runtime_enabled() && start > reserved_va) {
return true;
}
#endif
Expand Down
5 changes: 3 additions & 2 deletions accel/tcg/user-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,8 @@ int cpu_signal_handler(int host_signum, void *pinfo,
}
}
#if defined(CONFIG_LATX_KZT)
if (option_kzt && (int64_t)info->si_addr >= info1.start_data &&
if (latx_kzt_runtime_enabled() &&
(int64_t)info->si_addr >= info1.start_data &&
(int64_t)info->si_addr <= info1.end_data &&
info->si_signo == SIGSEGV) {
int ret = elf_data_interpret(info, uc);
Expand All @@ -1369,7 +1370,7 @@ int cpu_signal_handler(int host_signum, void *pinfo,
return 1;
}
}
if (option_kzt && info->si_signo == SIGSEGV) {
if (latx_kzt_runtime_enabled() && info->si_signo == SIGSEGV) {
for (int i = 0; i < sizeof(elf_native_func) / sizeof(int); i++) {
if (!find_stack_func_exist(elf_native_func[i], 4)) {
int ret = elf_data_interpret(info, uc);
Expand Down
6 changes: 3 additions & 3 deletions include/exec/cpu_ldst.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#define CPU_LDST_H

#if defined(CONFIG_LATX_KZT)
extern int option_kzt;
#include "kzt-runtime.h"
#endif
#if defined(CONFIG_USER_ONLY)
/* sparc32plus has 64bit long but 32bit space address
Expand Down Expand Up @@ -93,7 +93,7 @@ static inline void *g2h(CPUState *cs, abi_ptr x)
static inline bool guest_addr_valid_untagged(abi_ulong x)
{
#if defined(CONFIG_LATX_KZT)
if (option_kzt) {
if (latx_kzt_runtime_enabled()) {
return true;
} else
#endif
Expand All @@ -103,7 +103,7 @@ static inline bool guest_addr_valid_untagged(abi_ulong x)
static inline bool guest_range_valid_untagged(abi_ulong start, abi_ulong len)
{
#if defined(CONFIG_LATX_KZT)
if (option_kzt) {
if (latx_kzt_runtime_enabled()) {
return true;
} else
#endif
Expand Down
2 changes: 1 addition & 1 deletion linux-user/i386/cpu_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void cpu_loop(CPUX86State *env)
cpu_exec_end(cs);
process_queued_cpu_work(cs);
#if defined(CONFIG_LATX_KZT)
if(option_kzt && trapnr == 0xCC)
if (latx_kzt_runtime_enabled() && trapnr == 0xCC)
break;
#endif
switch(trapnr) {
Expand Down
3 changes: 2 additions & 1 deletion linux-user/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,8 @@ static void host_signal_handler(int host_signum, siginfo_t *info,
cpu_exit(thread_cpu);
#if defined(CONFIG_LATX_KZT)
#define SIGCANCEL __SIGRTMIN
if (host_signum == SIGCANCEL + 2 && option_kzt && pc > reserved_va) {
if (host_signum == SIGCANCEL + 2 && latx_kzt_runtime_enabled() &&
pc > reserved_va) {
#define BTSIZT 64
void * array[BTSIZT] = {0};
size_t size;
Expand Down
75 changes: 55 additions & 20 deletions target/i386/latx/context/elfloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,22 @@ static int isChromeApp(elfheader_t* h, int con_score)
return 0;
}

int CheckEnableKZT(elfheader_t* h, char** target_argv, int target_argc)
static bool kzt_soname_matches_filename(const char *soname,
const char *filename)
{
const char *suffix = strstr(soname, ".so");
size_t prefix_length;

if (!suffix) {
return !strcmp(soname, filename);
}
prefix_length = suffix - soname + strlen(".so");
return !strncmp(soname, filename, prefix_length) &&
(filename[prefix_length] == '\0' ||
filename[prefix_length] == '.');
}

void CheckEnableKZT(elfheader_t *h, char **target_argv, int target_argc)
{
path_collection_t lib_path = {0,0,0};
char *rpathref;
Expand All @@ -675,11 +690,6 @@ int CheckEnableKZT(elfheader_t* h, char** target_argv, int target_argc)
}
break;
case DT_NEEDED:
if (strstr(h->DynStrTab+h->delta+h->Dynamic[i].d_un.d_val, "libgtk-3.so")||//skip gtk
strstr(h->DynStrTab+h->delta+h->Dynamic[i].d_un.d_val, "libXt.so")) {//skip mainexec needed libXt.so
printf_log(LOG_INFO, "latx find libgtk or libXt, skip kzt\n");
return 0;
}
++needlibcnt;
break;
}
Expand All @@ -696,11 +706,6 @@ int CheckEnableKZT(elfheader_t* h, char** target_argv, int target_argc)
if (!kzt_library_is_enabled(wrappedlibs_name[i])) {
continue;
}
char *p = box_strdup(wrappedlibs_name[i]);
char *p2 = strchr(p, '.');
if (++p2) {
*p2 = '\0';
}
for (int j=0; j<lib_path.size; ++j) {
DIR *dir = opendir(lib_path.paths[j]);
if (dir == NULL) {
Expand All @@ -710,26 +715,56 @@ int CheckEnableKZT(elfheader_t* h, char** target_argv, int target_argc)

struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_REG) { // Check if it's a regular file
if (!strncmp(entry->d_name, p, strlen(p))) {
printf_log(LOG_INFO, "File starting with '%s' found: %s at %s\n", p, entry->d_name, lib_path.paths[j]);
closedir(dir);
FreeCollection(&lib_path);
return 0;
}
char candidate[PATH_MAX];
char reason[PATH_MAX + 96];
KztLibraryGroup group;
int candidate_length;

if (!kzt_soname_matches_filename(wrappedlibs_name[i],
entry->d_name)) {
continue;
}
candidate_length = snprintf(
candidate, sizeof(candidate), "%s%s%s", lib_path.paths[j],
lib_path.paths[j][strlen(lib_path.paths[j]) - 1] == '/'
? "" : "/",
entry->d_name);
if (candidate_length < 0 ||
(size_t)candidate_length >= sizeof(candidate)) {
continue;
}
if (!FileExist(candidate, IS_FILE) ||
!FileIsX64ELF(candidate)) {
continue;
}
group = kzt_group_for_library(wrappedlibs_name[i]);
snprintf(reason, sizeof(reason),
"guest %s resolved from application path %s",
entry->d_name, lib_path.paths[j]);
kzt_group_disable(group, reason);
break;
}
closedir(dir);
if (!kzt_library_is_enabled(wrappedlibs_name[i])) {
break;
}
}
}
FreeCollection(&lib_path);
//disable kzt chrome app
for(int i = 0; i < target_argc; i++) {
if (!strcmp(target_argv[i], "--no-sandbox")) {
return !isChromeApp(h, 5);
if (isChromeApp(h, 5)) {
kzt_groups_disable_all(
"main executable matched the Chrome compatibility gate");
}
return;
}
}
return !isChromeApp(h, 10);
if (isChromeApp(h, 10)) {
kzt_groups_disable_all(
"main executable matched the Chrome compatibility gate");
}
}

const char* ElfName(elfheader_t* head)
Expand Down
70 changes: 60 additions & 10 deletions target/i386/latx/context/kzt-groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ static const KztLibraryGroupEntry kzt_library_groups[] = {
#undef GO
#undef GOALIAS

static uint32_t enabled_groups = KZT_GROUP_STABLE;
static uint32_t requested_groups = KZT_GROUP_STABLE;
uint32_t kzt_effective_groups = KZT_GROUP_STABLE;
static bool group_log_enabled;
static char group_error[128];
static bool library_decision_logged[ARRAY_SIZE(kzt_library_groups)];
Expand Down Expand Up @@ -268,7 +269,7 @@ static void kzt_groups_log_effective(const char *spec, uint32_t dependencies,
if (pruned) {
kzt_groups_log_mask("disabled dependent library groups", pruned);
}
kzt_groups_log_mask("enabled library groups", enabled_groups);
kzt_groups_log_mask("enabled library groups", kzt_effective_groups);
}

KztLibraryGroup kzt_group_for_library(const char *soname)
Expand Down Expand Up @@ -326,7 +327,8 @@ void kzt_groups_print_available(void)

void kzt_groups_reset(void)
{
enabled_groups = KZT_GROUP_STABLE;
requested_groups = KZT_GROUP_STABLE;
kzt_effective_groups = KZT_GROUP_STABLE;
group_log_enabled = false;
group_error[0] = '\0';
memset(library_decision_logged, 0, sizeof(library_decision_logged));
Expand All @@ -349,7 +351,8 @@ bool kzt_groups_configure(const char *spec, bool log_enabled)
memset(library_decision_logged, 0, sizeof(library_decision_logged));
if (!kzt_parse_group_spec(spec, &mode, &selected, &added, &removed,
&use_stable)) {
enabled_groups = KZT_GROUP_NONE;
requested_groups = KZT_GROUP_NONE;
kzt_effective_groups = KZT_GROUP_NONE;
group_log_enabled = log_enabled;
return false;
}
Expand All @@ -367,28 +370,75 @@ bool kzt_groups_configure(const char *spec, bool log_enabled)
dependencies = groups & ~before_dependencies;
groups &= ~removed;
before_prune = groups;
enabled_groups = kzt_prune_missing_dependencies(groups);
pruned = before_prune & ~enabled_groups;
requested_groups = kzt_prune_missing_dependencies(groups);
kzt_effective_groups = requested_groups;
pruned = before_prune & ~kzt_effective_groups;
group_log_enabled = log_enabled;
kzt_groups_log_effective(spec, dependencies, removed, pruned);
return true;
}

void kzt_groups_reject_configuration(const char *reason, bool log_enabled)
{
enabled_groups = KZT_GROUP_NONE;
requested_groups = KZT_GROUP_NONE;
kzt_effective_groups = KZT_GROUP_NONE;
group_log_enabled = log_enabled;
snprintf(group_error, sizeof(group_error), "%s", reason);
}

uint32_t kzt_groups_enabled_mask(void)
uint32_t kzt_groups_requested_mask(void)
{
return enabled_groups;
return requested_groups;
}

uint32_t kzt_groups_effective_mask(void)
{
return kzt_effective_groups;
}

bool kzt_group_disable(KztLibraryGroup group, const char *reason)
{
uint32_t before_prune;
uint32_t pruned;

if (group == KZT_GROUP_NONE || !(kzt_effective_groups & group)) {
return false;
}

kzt_effective_groups &= ~group;
before_prune = kzt_effective_groups;
kzt_effective_groups = kzt_prune_missing_dependencies(kzt_effective_groups);
pruned = before_prune & ~kzt_effective_groups;

if (group_log_enabled) {
fprintf(stderr, "KZT: disabled library group %s: %s\n",
kzt_group_name(group),
reason ? reason : "compatibility check failed");
if (pruned) {
kzt_groups_log_mask("disabled dependent library groups", pruned);
}
kzt_groups_log_mask("enabled library groups", kzt_effective_groups);
}
return true;
}

void kzt_groups_disable_all(const char *reason)
{
if (kzt_effective_groups == KZT_GROUP_NONE) {
return;
}
kzt_effective_groups = KZT_GROUP_NONE;
if (group_log_enabled) {
fprintf(stderr, "KZT: disabled all library groups: %s\n",
reason ? reason : "compatibility check failed");
kzt_groups_log_mask("enabled library groups", kzt_effective_groups);
}
}

bool kzt_group_is_enabled(KztLibraryGroup group)
{
return group != KZT_GROUP_NONE && (enabled_groups & group) == group;
return group != KZT_GROUP_NONE &&
(kzt_effective_groups & group) == group;
}

bool kzt_library_is_enabled(const char *soname)
Expand Down
Loading