socsvn commit: r271064 - in soc2014/op/freebsd-base/sys: kern sys

op at FreeBSD.org op at FreeBSD.org
Fri Jul 18 08:48:46 UTC 2014


Author: op
Date: Fri Jul 18 08:48:44 2014
New Revision: 271064
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271064

Log:
  KSP: implemented basic kernel patching
  
  Signed-off-by: Oliver Pinter <oliver.pntr at gmail.com>
  
  git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch

Modified:
  soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c
  soc2014/op/freebsd-base/sys/sys/selfpatch.h

Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c
==============================================================================
--- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c	Fri Jul 18 08:48:32 2014	(r271063)
+++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c	Fri Jul 18 08:48:44 2014	(r271064)
@@ -42,6 +42,7 @@
 #include <machine/md_var.h>
 #include <machine/specialreg.h>
 
+
 bool
 lf_selfpatch_patch_needed(struct lf_selfpatch *p)
 {
@@ -89,13 +90,28 @@
 void
 lf_selfpatch(linker_file_t lf)
 {
+	struct lf_selfpatch *patch, *start, *stop;
+	int count, ret;
+
+	ret = linker_file_lookup_set(lf, "ksp_kpatch_set", &start, &stop, &count);
+	if (ret != 0) {
+		printf("linker_file_lookup_set faild to locate ksp_kpatch_set\n");
+		return;
+	}
 
-	printf("NOT IMPLEMENTED: %s\n", __func__);
+	for (patch = start; patch != stop; patch++) {
+		lf_selfpatch_apply(lf, patch);
+	}
 }
 
 void
-lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *patch)
+lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *p)
 {
+	if (!lf_selfpatch_patch_needed(p))
+		return;
+
+	KASSERT(p->patch_size == p->patchable_size,
+	    ("%s: patch_size != patchable_size", __func__));
 
-	printf("NOT IMPLEMENTED: %s\n", __func__);
+	memcpy(p->patchable, p->patch, p->patchable_size);
 }

Modified: soc2014/op/freebsd-base/sys/sys/selfpatch.h
==============================================================================
--- soc2014/op/freebsd-base/sys/sys/selfpatch.h	Fri Jul 18 08:48:32 2014	(r271063)
+++ soc2014/op/freebsd-base/sys/sys/selfpatch.h	Fri Jul 18 08:48:44 2014	(r271064)
@@ -36,7 +36,9 @@
 typedef struct lf_selfpatch {
 	void	*patchable;
 	void	*patch;
-	short	feature_selector;
+	int	patchable_size;
+	int	patch_size;
+	int	feature_selector;
 	int	feature;
 	char	*comment;
 } lf_selfpatch_t;


More information about the svn-soc-all mailing list