Skip to content

Commit db29fc0

Browse files
committed
inference: add [layout] output to silent plugins
dram_bound, kaslr_ceiling, phys_virt_synth, and riscv64_nonEFI_phys_base now print to stderr when they tighten a bound, consistent with all other inference plugins.
1 parent 52d7cb7 commit db29fc0

4 files changed

Lines changed: 45 additions & 6 deletions

File tree

src/inference/dram_bound.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "../include/kasld_inference.h"
4040

4141
#include <limits.h>
42+
#include <stdio.h>
4243
#include <string.h>
4344

4445
static void dram_bound_run(struct kasld_analysis_ctx *ctx) {
@@ -68,8 +69,13 @@ static void dram_bound_run(struct kasld_analysis_ctx *ctx) {
6869
pdram_lo = (pdram_lo + phys_align - 1) & ~(phys_align - 1);
6970

7071
if (pdram_lo > phys_arch_min && pdram_lo > ctx->phys_base_min &&
71-
pdram_lo < ctx->phys_base_max)
72+
pdram_lo < ctx->phys_base_max) {
73+
fprintf(stderr,
74+
"[layout] phys_base_min tightened by dram_bound:"
75+
" %#lx -> %#lx (min PHYS/DRAM=%#lx)\n",
76+
ctx->phys_base_min, pdram_lo, pdram_lo);
7277
ctx->phys_base_min = pdram_lo;
78+
}
7379
} else {
7480
/* Coupled arches: phys_to_virt() links physical DRAM to virtual text.
7581
* Derive a virtual text lower bound and align DOWN to stay conservative. */
@@ -88,8 +94,13 @@ static void dram_bound_run(struct kasld_analysis_ctx *ctx) {
8894
~(kaslr_align - 1);
8995

9096
if (virt_lo > kaslr_min && virt_lo > ctx->text_base_min &&
91-
virt_lo < ctx->text_base_max)
97+
virt_lo < ctx->text_base_max) {
98+
fprintf(stderr,
99+
"[layout] text_base_min tightened by dram_bound:"
100+
" %#lx -> %#lx (min PHYS/DRAM=%#lx)\n",
101+
ctx->text_base_min, virt_lo, pdram_lo);
92102
ctx->text_base_min = virt_lo;
103+
}
93104
}
94105
}
95106

src/inference/kaslr_ceiling.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,13 @@ static void kaslr_ceiling_run(struct kasld_analysis_ctx *ctx) {
102102
/* Valid base range: [KASLR_BASE_MIN, KASLR_BASE_MAX - kernel_size].
103103
* Align down to the nearest slot boundary. */
104104
unsigned long new_max = (kaslr_max - kernel_size) & ~(kaslr_align - 1);
105-
if (new_max > kaslr_min && new_max < ctx->text_base_max)
105+
if (new_max > kaslr_min && new_max < ctx->text_base_max) {
106+
fprintf(stderr,
107+
"[layout] text_base_max tightened by kaslr_ceiling:"
108+
" %#lx -> %#lx (kernel_size=%#lx)\n",
109+
ctx->text_base_max, new_max, kernel_size);
106110
ctx->text_base_max = new_max;
111+
}
107112
}
108113

109114
#if PHYS_VIRT_DECOUPLED
@@ -113,8 +118,13 @@ static void kaslr_ceiling_run(struct kasld_analysis_ctx *ctx) {
113118

114119
if (phys_max > phys_min && kernel_size < phys_max - phys_min) {
115120
unsigned long new_phys_max = (phys_max - kernel_size) & ~(phys_align - 1);
116-
if (new_phys_max > phys_min && new_phys_max < ctx->phys_base_max)
121+
if (new_phys_max > phys_min && new_phys_max < ctx->phys_base_max) {
122+
fprintf(stderr,
123+
"[layout] phys_base_max tightened by kaslr_ceiling:"
124+
" %#lx -> %#lx (kernel_size=%#lx)\n",
125+
ctx->phys_base_max, new_phys_max, kernel_size);
117126
ctx->phys_base_max = new_phys_max;
127+
}
118128
}
119129
#endif
120130
}

src/inference/phys_virt_synth.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "../include/kasld_inference.h"
4040

4141
#include <limits.h>
42+
#include <stdio.h>
4243
#include <string.h>
4344

4445
#define SYNTH_MAX_ORIGINS 128
@@ -124,10 +125,20 @@ static void phys_virt_synth_run(struct kasld_analysis_ctx *ctx) {
124125
if (cand_hi - cand_lo > kaslr_align)
125126
return;
126127

127-
if (cand_lo > ctx->page_offset_min)
128+
if (cand_lo > ctx->page_offset_min) {
129+
fprintf(stderr,
130+
"[layout] page_offset_min tightened by phys_virt_synth:"
131+
" %#lx -> %#lx\n",
132+
ctx->page_offset_min, cand_lo);
128133
ctx->page_offset_min = cand_lo;
129-
if (cand_hi < ctx->page_offset_max)
134+
}
135+
if (cand_hi < ctx->page_offset_max) {
136+
fprintf(stderr,
137+
"[layout] page_offset_max tightened by phys_virt_synth:"
138+
" %#lx -> %#lx\n",
139+
ctx->page_offset_max, cand_hi);
130140
ctx->page_offset_max = cand_hi;
141+
}
131142
}
132143

133144
static const struct kasld_inference phys_virt_synth = {

src/inference/riscv64_non_efi_phys_base.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "../include/kasld_inference.h"
5050

5151
#include <limits.h>
52+
#include <stdio.h>
5253
#include <string.h>
5354
#include <unistd.h>
5455

@@ -81,6 +82,12 @@ static void riscv64_nonEFI_phys_base_run(struct kasld_analysis_ctx *ctx) {
8182
if (phys_exact < ctx->phys_base_min || phys_exact > ctx->phys_base_max)
8283
return;
8384

85+
fprintf(
86+
stderr,
87+
"[layout] phys_base pinned by riscv64_nonEFI_phys_base:"
88+
" [%#lx, %#lx] -> %#lx (non-EFI, DRAM_BASE=%#lx + TEXT_OFFSET=%#lx)\n",
89+
ctx->phys_base_min, ctx->phys_base_max, phys_exact, pdram_lo,
90+
(unsigned long)TEXT_OFFSET);
8491
ctx->phys_base_min = phys_exact;
8592
ctx->phys_base_max = phys_exact;
8693
#else

0 commit comments

Comments
 (0)