diff --git a/sys/cddl/dev/kinst/amd64/kinst_isa.h b/sys/cddl/dev/kinst/amd64/kinst_isa.h --- a/sys/cddl/dev/kinst/amd64/kinst_isa.h +++ b/sys/cddl/dev/kinst/amd64/kinst_isa.h @@ -19,12 +19,8 @@ */ #define KINST_TRAMP_SIZE 32 #define KINST_TRAMPCHUNK_SIZE PAGE_SIZE - -/* - * Fill the trampolines with breakpoint instructions so that the kernel will - * crash cleanly if things somehow go wrong. - */ -#define KINST_TRAMP_INIT(t, s) memset((t), KINST_PATCHVAL, (s)) +#define KINST_TRAMP_FILL KINST_PATCHVAL +#define KINST_TRAMP_FILL_SIZE sizeof(uint8_t) typedef uint8_t kinst_patchval_t; diff --git a/sys/cddl/dev/kinst/trampoline.c b/sys/cddl/dev/kinst/trampoline.c --- a/sys/cddl/dev/kinst/trampoline.c +++ b/sys/cddl/dev/kinst/trampoline.c @@ -28,9 +28,6 @@ #include "kinst.h" #include "kinst_isa.h" -/* - * We can have 4KB/32B = 128 trampolines per chunk. - */ #define KINST_TRAMPS_PER_CHUNK (KINST_TRAMPCHUNK_SIZE / KINST_TRAMP_SIZE) struct trampchunk { @@ -47,6 +44,20 @@ static eventhandler_tag kinst_thread_ctor_handler; static eventhandler_tag kinst_thread_dtor_handler; +/* + * Fill the trampolines with KINST_TRAMP_FILL so that the kernel will crash + * cleanly if things somehow go wrong. + */ +static void +kinst_trampoline_fill(uint8_t *addr, int size) +{ + int i, v; + + v = KINST_TRAMP_FILL; + for (i = 0; i < size; i += KINST_TRAMP_FILL_SIZE) + memcpy(&addr[i], &v, KINST_TRAMP_FILL_SIZE); +} + static struct trampchunk * kinst_trampchunk_alloc(void) { @@ -77,7 +88,7 @@ M_WAITOK | M_EXEC); KASSERT(error == KERN_SUCCESS, ("kmem_back failed: %d", error)); - KINST_TRAMP_INIT((void *)trampaddr, KINST_TRAMPCHUNK_SIZE); + kinst_trampoline_fill((uint8_t *)trampaddr, KINST_TRAMPCHUNK_SIZE); /* Allocate a tracker for this chunk. */ chunk = malloc(sizeof(*chunk), M_KINST, M_WAITOK); @@ -169,7 +180,7 @@ TAILQ_FOREACH(chunk, &kinst_trampchunks, next) { for (off = 0; off < KINST_TRAMPS_PER_CHUNK; off++) { if (chunk->addr + off * KINST_TRAMP_SIZE == tramp) { - KINST_TRAMP_INIT(tramp, KINST_TRAMP_SIZE); + kinst_trampoline_fill(tramp, KINST_TRAMP_SIZE); BIT_SET(KINST_TRAMPS_PER_CHUNK, off, &chunk->free); if (freechunks &&