Page MenuHomeFreeBSD

D39504.diff
No OneTemporary

D39504.diff

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
@@ -17,14 +17,10 @@
* have 2 instructions stored in the trampoline, and each of them can take up
* to 16 bytes, 32 bytes is enough to cover even the worst case scenario.
*/
-#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_SIZE 32
+#define KINST_TRAMPCHUNK_SIZE PAGE_SIZE
+#define KINST_TRAMP_FILL_PATTERN ((uint8_t []){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,21 @@
static eventhandler_tag kinst_thread_ctor_handler;
static eventhandler_tag kinst_thread_dtor_handler;
+/*
+ * Fill the trampolines with KINST_TRAMP_FILL_PATTERN so that the kernel will
+ * crash cleanly if things somehow go wrong.
+ */
+static void
+kinst_trampoline_fill(uint8_t *addr, int size)
+{
+ int i;
+
+ for (i = 0; i < size; i += KINST_TRAMP_FILL_SIZE) {
+ memcpy(&addr[i], KINST_TRAMP_FILL_PATTERN,
+ KINST_TRAMP_FILL_SIZE);
+ }
+}
+
static struct trampchunk *
kinst_trampchunk_alloc(void)
{
@@ -77,7 +89,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);
@@ -171,7 +183,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 &&

File Metadata

Mime Type
text/plain
Expires
Mon, Feb 10, 3:55 PM (6 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16579703
Default Alt Text
D39504.diff (2 KB)

Event Timeline