Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/x86/x86 Give patchbytes an array.
details: https://anonhg.NetBSD.org/src/rev/a853f89d3802
branches: trunk
changeset: 358543:a853f89d3802
user: maxv <maxv%NetBSD.org@localhost>
date: Sun Jan 07 11:24:45 2018 +0000
description:
Give patchbytes an array.
diffstat:
sys/arch/x86/x86/patch.c | 45 ++++++++++++++++++++++++++++++---------------
1 files changed, 30 insertions(+), 15 deletions(-)
diffs (99 lines):
diff -r 110fe97eec68 -r a853f89d3802 sys/arch/x86/x86/patch.c
--- a/sys/arch/x86/x86/patch.c Sun Jan 07 10:16:13 2018 +0000
+++ b/sys/arch/x86/x86/patch.c Sun Jan 07 11:24:45 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: patch.c,v 1.24 2017/10/27 23:22:01 riastradh Exp $ */
+/* $NetBSD: patch.c,v 1.25 2018/01/07 11:24:45 maxv Exp $ */
/*-
* Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.24 2017/10/27 23:22:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.25 2018/01/07 11:24:45 maxv Exp $");
#include "opt_lockdebug.h"
#ifdef i386
@@ -130,14 +130,14 @@
}
static inline void __unused
-patchbytes(void *addr, const int byte1, const int byte2, const int byte3)
+patchbytes(void *addr, const uint8_t *bytes, size_t size)
{
+ uint8_t *ptr = (uint8_t *)addr;
+ size_t i;
- ((uint8_t *)addr)[0] = (uint8_t)byte1;
- if (byte2 != -1)
- ((uint8_t *)addr)[1] = (uint8_t)byte2;
- if (byte3 != -1)
- ((uint8_t *)addr)[2] = (uint8_t)byte3;
+ for (i = 0; i < size; i++) {
+ ptr[i] = bytes[i];
+ }
}
void
@@ -169,11 +169,15 @@
#if !defined(GPROF)
if (!early && ncpu == 1) {
#ifndef LOCKDEBUG
+ const uint8_t bytes[] = {
+ X86_NOP
+ };
+
/* Uniprocessor: kill LOCK prefixes. */
for (i = 0; x86_lockpatch[i] != 0; i++)
- patchbytes(x86_lockpatch[i], X86_NOP, -1, -1);
+ patchbytes(x86_lockpatch[i], bytes, sizeof(bytes));
for (i = 0; atomic_lockpatch[i] != 0; i++)
- patchbytes(atomic_lockpatch[i], X86_NOP, -1, -1);
+ patchbytes(atomic_lockpatch[i], bytes, sizeof(bytes));
#endif /* !LOCKDEBUG */
}
if (!early && (cpu_feature[0] & CPUID_SSE2) != 0) {
@@ -237,9 +241,13 @@
(CPUID_TO_FAMILY(cpu_info_primary.ci_signature) == 0xe ||
(CPUID_TO_FAMILY(cpu_info_primary.ci_signature) == 0xf &&
CPUID_TO_EXTMODEL(cpu_info_primary.ci_signature) < 0x4))) {
+ const uint8_t bytes[] = {
+ 0x0F, 0xAE, 0xE8 /* lfence */
+ };
+
for (i = 0; x86_retpatch[i] != 0; i++) {
/* ret,nop,nop,ret -> lfence,ret */
- patchbytes(x86_retpatch[i], 0x0f, 0xae, 0xe8);
+ patchbytes(x86_retpatch[i], bytes, sizeof(bytes));
}
}
@@ -253,15 +261,22 @@
*/
if (!early && cpu_feature[5] & CPUID_SEF_SMAP) {
KASSERT(rcr4() & CR4_SMAP);
+ const uint8_t clac_bytes[] = {
+ 0x0F, 0x01, 0xCA /* clac */
+ };
+ const uint8_t stac_bytes[] = {
+ 0x0F, 0x01, 0xCB /* stac */
+ };
+
for (i = 0; x86_clacpatch[i] != NULL; i++) {
/* ret,int3,int3 -> clac */
- patchbytes(x86_clacpatch[i],
- 0x0f, 0x01, 0xca);
+ patchbytes(x86_clacpatch[i], clac_bytes,
+ sizeof(clac_bytes));
}
for (i = 0; x86_stacpatch[i] != NULL; i++) {
/* ret,int3,int3 -> stac */
- patchbytes(x86_stacpatch[i],
- 0x0f, 0x01, 0xcb);
+ patchbytes(x86_stacpatch[i], stac_bytes,
+ sizeof(stac_bytes));
}
}
#endif
Home |
Main Index |
Thread Index |
Old Index