Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9a56a4c
LATX, refactor: add KZT guest object registry
LaurenIsACoder Jun 29, 2026
12af38b
LATX, refactor: add KZT guest link map reader
LaurenIsACoder Jun 30, 2026
7ba2852
LATX, refactor: add KZT observation adapter
LaurenIsACoder Jun 30, 2026
07f6cb7
LATX, refactor: route KZT callback through registry adapter
LaurenIsACoder Jun 30, 2026
dda9427
LATX, refactor: add KZT guest registry diagnostics
LaurenIsACoder Jun 30, 2026
621c7e1
LATX, test: cover KZT guest registry concurrency
LaurenIsACoder Jun 30, 2026
60dfbf1
LATX, refactor: wire KZT registry diagnostics logging
LaurenIsACoder Jun 30, 2026
ceddda0
LATX, refactor: add KZT registry diagnostics option
LaurenIsACoder Jun 30, 2026
51d37d0
LATX, fix: gate KZT registry diagnostics output
LaurenIsACoder Jun 30, 2026
7f33d0a
LATX, doc: describe KZT registry diagnostics option
LaurenIsACoder Jun 30, 2026
312b76f
LATX, test: cover KZT registry diagnostics gate
LaurenIsACoder Jul 1, 2026
a86e45a
CI, fix: lowercase GHCR image owner
LaurenIsACoder Jul 1, 2026
7a52689
LATX, refactor: add KZT guest dynamic parser
LaurenIsACoder Jul 6, 2026
125277a
LATX, refactor: report KZT dynamic parser edges
LaurenIsACoder Jul 6, 2026
4f22a8d
LATX, refactor: store KZT guest dynamic snapshots
LaurenIsACoder Jul 6, 2026
75ad9a3
LATX, refactor: commit KZT dynamic views from adapter
LaurenIsACoder Jul 7, 2026
191c58c
LATX, refactor: add KZT dynamic diagnostics helper
LaurenIsACoder Jul 7, 2026
b6af8a3
LATX, refactor: summarize KZT dynamic comparisons
LaurenIsACoder Jul 7, 2026
bfff4b8
LATX, refactor: add KZT patch planner contract
LaurenIsACoder Jul 7, 2026
e47ef30
LATX, feat: Add KZT runtime GOT/PLT candidates
LaurenIsACoder Jul 7, 2026
4f92229
LATX, kzt: add patch spike guard gate
LaurenIsACoder Jul 7, 2026
a9b80cc
LATX, kzt: add patch spike writer helper
LaurenIsACoder Jul 8, 2026
20dec00
LATX, kzt: build immediate jump slot candidates
LaurenIsACoder Jul 8, 2026
5f0fffc
LATX, kzt: hook immediate jump slot writer
LaurenIsACoder Jul 9, 2026
fa252fd
LATX, kzt: add Step4 writer gate tests
LaurenIsACoder Jul 9, 2026
d740137
LATX, kzt: share immediate jump slot writer route
LaurenIsACoder Jul 9, 2026
b03fda0
LATX, kzt: refresh Step4 writer test report
LaurenIsACoder Jul 9, 2026
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
15 changes: 8 additions & 7 deletions .github/workflows/build-docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ jobs:
with:
persist-credentials: false

- name: Pull existing image
run: docker pull ghcr.io/${{ github.repository_owner }}/${{ matrix.IMAGE.TAG_NAME }} || true
if: github.event_name != 'schedule' && github.event_name != 'workflow_dispatch'

- name: Get image name
id: image-name
run: |
ATTEST_IMAGE=$(echo "${{ matrix.IMAGE.TAG_NAME }}" | cut -d ':' -f 1)
echo "ATTEST_IMAGE=${ATTEST_IMAGE}" | tee -a "$GITHUB_OUTPUT"
echo "GHCR_OWNER=${GITHUB_REPOSITORY_OWNER,,}" | tee -a "$GITHUB_OUTPUT"

- name: Pull existing image
run: docker pull "ghcr.io/${{ steps.image-name.outputs.GHCR_OWNER }}/${{ matrix.IMAGE.TAG_NAME }}" || true
if: github.event_name != 'schedule' && github.event_name != 'workflow_dispatch'

- name: Setup QEMU
uses: docker/setup-qemu-action@v4
Expand All @@ -70,15 +71,15 @@ jobs:
id: docker-build
with:
context: ${{ matrix.IMAGE.DOCKERFILE_PATH }}
cache-from: ghcr.io/${{ github.repository_owner }}/${{ matrix.IMAGE.TAG_NAME }}
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.IMAGE.TAG_NAME }}
cache-from: ghcr.io/${{ steps.image-name.outputs.GHCR_OWNER }}/${{ matrix.IMAGE.TAG_NAME }}
tags: ghcr.io/${{ steps.image-name.outputs.GHCR_OWNER }}/${{ matrix.IMAGE.TAG_NAME }}
platforms: ${{ matrix.IMAGE.DOCKER_PLATFORM }}
pull: true
push: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/master' }}

- uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
with:
subject-name: "ghcr.io/${{ github.repository_owner }}/${{ steps.image-name.outputs.ATTEST_IMAGE }}"
subject-name: "ghcr.io/${{ steps.image-name.outputs.GHCR_OWNER }}/${{ steps.image-name.outputs.ATTEST_IMAGE }}"
subject-digest: ${{ steps.docker-build.outputs.digest }}
push-to-registry: true
if: (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/master'
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ jobs:

- name: "Build LATX"
run: |
DOCKER_IMAGE="ghcr.io/${{ github.repository_owner }}/${{ matrix.container }}:loong64"
GHCR_OWNER="${GITHUB_REPOSITORY_OWNER,,}"
DOCKER_IMAGE="ghcr.io/${GHCR_OWNER}/${{ matrix.container }}:loong64"
DOCKER_CMD="./latxbuild/${{ matrix.type }}.sh -c"
docker run --rm \
--platform linux/loong64 \
Expand Down
6 changes: 6 additions & 0 deletions docs/user/latx-environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ AOT(预翻译)会保存恢复预翻译信息,某些配置与 AOT 冲突,
- 库直通
-
-
* - LATX\_KZT\_REGISTRY\_DIAGNOSTICS
- ``-latx-kzt-registry-diagnostics``
- kzt\_registry\_diagnostics
- KZT registry 诊断输出
-
- 仅控制 KZT registry 诊断输出,不单独启用 KZT;通常需配合 ``LATX_KZT=2`` 或 ``-latx-kzt 2``
* - LATX\_FPUTAG
- ``-latx-fputag``
- option\_fputag
Expand Down
35 changes: 35 additions & 0 deletions linux-user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ int box64_pagesize;
uintptr_t box64_load_addr = 0;
int dlsym_error = 0;
int kzt_call_log = 0;
int kzt_registry_diagnostics = 0;
int cycle_log = 0;
int allow_missing_libs = 1;
int box64_nogtk = 0;
Expand Down Expand Up @@ -635,6 +636,28 @@ static void handle_arg_latx_kzt(const char *arg)
{
option_kzt = strtol(arg, NULL, 0);
}

static void handle_arg_latx_kzt_registry_diagnostics(const char *arg)
{
kzt_registry_diagnostics = strtol(arg, NULL, 0);
}

static void handle_arg_latx_kzt_patch_spike(const char *arg)
{
option_kzt_patch_spike = strtol(arg, NULL, 0) > 0;
}

static void handle_arg_latx_kzt_patch_spike_write(const char *arg)
{
option_kzt_patch_spike_write = strtol(arg, NULL, 0) > 0;
}

static void handle_arg_latx_kzt_patch_spike_budget(const char *arg)
{
long value = strtol(arg, NULL, 0);

option_kzt_patch_spike_budget = value > 0 ? (unsigned long)value : 0;
}
#endif

static void handle_arg_latx_fputag(const char *arg)
Expand Down Expand Up @@ -818,6 +841,18 @@ static const struct qemu_argument arg_table[] = {
#if defined(CONFIG_LATX_KZT)
{"latx-kzt", "LATX_KZT", true, handle_arg_latx_kzt,
"", "enable kuzhitong"},
{"latx-kzt-registry-diagnostics", "LATX_KZT_REGISTRY_DIAGNOSTICS",
true, handle_arg_latx_kzt_registry_diagnostics,
"", "enable KZT guest registry diagnostics"},
{"latx-kzt-patch-spike", "LATX_KZT_PATCH_SPIKE",
true, handle_arg_latx_kzt_patch_spike,
"", "enable KZT controlled patch spike planning"},
{"latx-kzt-patch-spike-write", "LATX_KZT_PATCH_SPIKE_WRITE",
true, handle_arg_latx_kzt_patch_spike_write,
"", "authorize KZT controlled patch spike writes"},
{"latx-kzt-patch-spike-budget", "LATX_KZT_PATCH_SPIKE_BUDGET",
true, handle_arg_latx_kzt_patch_spike_budget,
"", "set KZT controlled patch spike write budget"},
#endif
{"latx-fputag", "LATX_FPUTAG", true, handle_arg_latx_fputag,
"", "enable fputag"},
Expand Down
40 changes: 40 additions & 0 deletions target/i386/latx/context/box64context.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "librarian.h"
#include "library.h"
#include "wrapper.h"
#ifdef CONFIG_LATX_KZT
#include "kzt_guest_registry.h"
#endif
#include <pthread.h>

box64context_t *NewBox64Context(int argc)
Expand All @@ -34,6 +37,39 @@ box64context_t *NewBox64Context(int argc)
return context;
}

#ifdef CONFIG_LATX_KZT
kzt_guest_registry_t *KztGuestRegistryForContext(box64context_t *context)
{
if (!context) {
return NULL;
}
if (!context->kzt_guest_registry) {
context->kzt_guest_registry = kzt_guest_registry_init();
}
return context->kzt_guest_registry;
}
#endif

kzt_patch_spike_guard_t *KztPatchSpikeGuardForContext(box64context_t *context)
{
#ifdef CONFIG_LATX_KZT
if (!context) {
return NULL;
}
if (!context->kzt_patch_spike_guard_initialized) {
kzt_patch_spike_config_t config;

kzt_patch_spike_config_from_options(&config);
kzt_patch_spike_guard_init(&context->kzt_patch_spike_guard, &config);
context->kzt_patch_spike_guard_initialized = 1;
}
return &context->kzt_patch_spike_guard;
#else
(void)context;
return NULL;
#endif
}

EXPORTDYN
void FreeBox64Context(box64context_t** context)
{
Expand All @@ -45,6 +81,10 @@ void FreeBox64Context(box64context_t** context)

box64context_t* ctx = *context; // local copy to do the cleanning

#ifdef CONFIG_LATX_KZT
kzt_guest_registry_destroy(&ctx->kzt_guest_registry);
#endif

if(ctx->local_maplib)
FreeLibrarian(&ctx->local_maplib);
if(ctx->maplib)
Expand Down
71 changes: 69 additions & 2 deletions target/i386/latx/context/elfloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,70 @@
#include "dictionnary.h"
#include "symbols.h"
#include "lsenv.h"
#include "kzt_rela_immediate_candidate.h"

void* my__IO_2_1_stderr_ = NULL;
void* my__IO_2_1_stdin_ = NULL;
void* my__IO_2_1_stdout_ = NULL;

static int RelocateElfRELATryImmediateJumpSlotWriter(elfheader_t *head,
int need_resolv_present, int entry_index, Elf64_Rela *rela,
uint64_t *slot, uintptr_t slot_current_value,
unsigned long symbol_index, const char *symbol_name, const char *version,
uintptr_t bridge_target)
{
kzt_rela_immediate_candidate_request_t request;
kzt_rela_immediate_writer_result_t result;

if (!head || !rela || !slot) {
return 0;
}

memset(&request, 0, sizeof(request));
request.relocation_type = ELF64_R_TYPE(rela->r_info);
request.table_kind = need_resolv_present ? KZT_PATCH_TABLE_PLT_RELA :
KZT_PATCH_TABLE_RELA;
request.entry_index = entry_index;
request.entry_addr = (uintptr_t)rela;
request.source.known = 1;
request.source.map_start = (uintptr_t)head->memory;
request.source.map_end = (uintptr_t)head->memory + head->memsz;
request.source.soname = head->name;
request.source.path = head->path;
request.dynamic_addr = (uintptr_t)head->Dynamic;
request.load_bias = head->delta;
request.dynamic_view_available = 1;
request.slot_addr = (uintptr_t)slot;
request.slot_current_value_present = 1;
request.slot_current_value = slot_current_value;
request.symbol_index = symbol_index;
request.symbol_name = symbol_name;
request.version = version;
request.owner_match = KZT_PATCH_OWNER_UNKNOWN;
request.wrapper_match = KZT_PATCH_WRAPPER_NO_MANIFEST;
request.bridge_target = bridge_target;

if (kzt_rela_immediate_jump_slot_try_write(
&request, KztPatchSpikeGuardForContext(my_context), NULL,
&result) != 0) {
return 0;
}

if (!result.writer_called) {
return 0;
}

printf_log(LOG_DEBUG,
"KZT: RelocateElfRELA immediate JUMP_SLOT writer %s/%s "
"slot=%p bridge=%p sym=%s\n",
kzt_patch_spike_result_name(result.record.result),
kzt_patch_spike_failure_name(result.record.failure),
(void *)slot, (void *)bridge_target,
symbol_name ? symbol_name : "(none)");

return result.skip_legacy_write;
}

void ResetSpecialCaseMainElf(elfheader_t* h)
{
Elf64_Sym *sym = NULL;
Expand Down Expand Up @@ -688,8 +748,15 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t
) {
if (offs){
if(p) {
printf_log(LOG_INFO, "RelocateElfRELA : Apply %s R_X86_64_JUMP_SLOT @%p with sym=%s (%p -> %p)\n", (bind==STB_LOCAL)?"Local":"Global", p, symname, *(void**)p, (void*)(offs+rela[i].r_addend));
*p =(uint64_t) (offs + rela[i].r_addend);
uintptr_t bridge_target = offs + rela[i].r_addend;

printf_log(LOG_INFO, "RelocateElfRELA : Apply %s R_X86_64_JUMP_SLOT @%p with sym=%s (%p -> %p)\n", (bind==STB_LOCAL)?"Local":"Global", p, symname, *(void**)p, (void*)bridge_target);
if (!RelocateElfRELATryImmediateJumpSlotWriter(
head, need_resolv != NULL, i, &rela[i], p,
(uintptr_t)(*p), ELF64_R_SYM(rela[i].r_info),
symname, vername, bridge_target)) {
*p = (uint64_t)bridge_target;
}
} else {
printf_log(LOG_INFO, "Warning, Symbol %s found, but Jump Slot Offset is NULL \n", symname);
}
Expand Down
Loading
Loading