Add an explicit kexec_load_unload_compat() using the same method
that was used to create kexec_range_compat()
Signed-off-by: Simon Horman <horms@xxxxxxxxxxxx>
---
xen/common/compat/kexec.c | 4 --
xen/common/kexec.c | 63 ++++++++++++++++++++++++++++++---------------
2 files changed, 42 insertions(+), 25 deletions(-)
Index: xen-unstable.hg/xen/common/kexec.c
===================================================================
--- xen-unstable.hg.orig/xen/common/kexec.c 2008-02-29 15:13:43.000000000
+0900
+++ xen-unstable.hg/xen/common/kexec.c 2008-02-29 15:19:16.000000000 +0900
@@ -272,11 +272,6 @@ static int kexec_get_range_compat(XEN_GU
}
#endif /* CONFIG_COMPAT */
-#endif /* COMPAT */
-
-
-#ifndef COMPAT
-
static int kexec_load_get_bits(int type, int *base, int *bit)
{
switch ( type )
@@ -295,19 +290,13 @@ static int kexec_load_get_bits(int type,
return 0;
}
-#endif
-
-static int kexec_load_unload(unsigned long op, XEN_GUEST_HANDLE(void) uarg)
+static int kexec_load_unload_internal(unsigned long op, xen_kexec_load_t *load)
{
- xen_kexec_load_t load;
xen_kexec_image_t *image;
int base, bit, pos;
int ret = 0;
- if ( unlikely(copy_from_guest(&load, uarg, 1)) )
- return -EFAULT;
-
- if ( kexec_load_get_bits(load.type, &base, &bit) )
+ if ( kexec_load_get_bits(load->type, &base, &bit) )
return -EINVAL;
pos = (test_bit(bit, &kexec_flags) != 0);
@@ -319,13 +308,9 @@ static int kexec_load_unload(unsigned lo
BUG_ON(test_bit((base + !pos), &kexec_flags)); /* must be free */
-#ifndef COMPAT
- memcpy(image, &load.image, sizeof(*image));
-#else
- XLAT_kexec_image(image, &load.image);
-#endif
+ memcpy(image, &load->image, sizeof(*image));
- if ( !(ret = machine_kexec_load(load.type, base + !pos, image)) )
+ if ( !(ret = machine_kexec_load(load->type, base + !pos, image)) )
{
/* Set image present bit */
set_bit((base + !pos), &kexec_flags);
@@ -341,14 +326,46 @@ static int kexec_load_unload(unsigned lo
if ( test_and_clear_bit((base + pos), &kexec_flags) )
{
image = &kexec_image[base + pos];
- machine_kexec_unload(load.type, base + pos, image);
+ machine_kexec_unload(load->type, base + pos, image);
}
}
return ret;
}
-#ifndef COMPAT
+static int kexec_load_unload(unsigned long op, XEN_GUEST_HANDLE(void) uarg)
+{
+ xen_kexec_load_t load;
+
+ if ( unlikely(copy_from_guest(&load, uarg, 1)) )
+ return -EFAULT;
+
+ return kexec_load_unload_internal(op, &load);
+}
+
+#ifdef CONFIG_COMPAT
+static int kexec_load_unload_compat(unsigned long op,
+ XEN_GUEST_HANDLE(void) uarg)
+{
+ compat_kexec_load_t compat_load;
+ xen_kexec_load_t load;
+
+ if ( unlikely(copy_from_guest(&compat_load, uarg, 1)) )
+ return -EFAULT;
+
+ /* This is a bit dodgy, load.image is inside load,
+ * but XLAT_kexec_load (which is automatically generated)
+ * doesn't translate load.image (correctly)
+ * Just copy load->type, the only other member, manually instead.
+ *
+ * XLAT_kexec_load(&load, &compat_load);
+ */
+ load.type = compat_load.type;
+ XLAT_kexec_image(&load.image, &compat_load.image);
+
+ return kexec_load_unload_internal(op, &load);
+}
+#endif
static int kexec_exec(XEN_GUEST_HANDLE(void) uarg)
{
@@ -411,7 +428,11 @@ ret_t do_kexec_op(unsigned long op, XEN_
spin_lock_irqsave(&kexec_lock, flags);
if (!test_bit(KEXEC_FLAG_IN_PROGRESS, &kexec_flags))
{
+#ifndef COMPAT
ret = kexec_load_unload(op, uarg);
+#else
+ ret = kexec_load_unload_compat(op, uarg);
+#endif
}
spin_unlock_irqrestore(&kexec_lock, flags);
break;
Index: xen-unstable.hg/xen/common/compat/kexec.c
===================================================================
--- xen-unstable.hg.orig/xen/common/compat/kexec.c 2008-02-29
15:08:01.000000000 +0900
+++ xen-unstable.hg/xen/common/compat/kexec.c 2008-02-29 15:19:16.000000000
+0900
@@ -9,10 +9,6 @@
#define do_kexec_op compat_kexec_op
-#define kexec_load_unload compat_kexec_load_unload
-#define xen_kexec_load compat_kexec_load
-#define xen_kexec_load_t compat_kexec_load_t
-
CHECK_kexec_exec;
#include "../kexec.c"
--
--
Horms
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|