diff options
Diffstat (limited to 'tools/libxc')
-rw-r--r-- | tools/libxc/Makefile | 8 | ||||
-rw-r--r-- | tools/libxc/xc_dom_bzimageloader.c | 11 | ||||
-rw-r--r-- | tools/libxc/xc_dom_decompress_unsafe.c | 48 | ||||
-rw-r--r-- | tools/libxc/xc_dom_decompress_unsafe.h | 20 | ||||
-rw-r--r-- | tools/libxc/xc_dom_decompress_unsafe_bzip2.c | 14 | ||||
-rw-r--r-- | tools/libxc/xc_dom_decompress_unsafe_lzma.c | 14 | ||||
-rw-r--r-- | tools/libxc/xc_dom_decompress_unsafe_lzo1x.c | 49 | ||||
-rw-r--r-- | tools/libxc/xc_dom_decompress_unsafe_xz.c | 57 |
8 files changed, 221 insertions, 0 deletions
diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index d44abf92c6..640e333d9c 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -68,6 +68,14 @@ GUEST_SRCS-$(CONFIG_X86) += xc_hvm_build_x86.c GUEST_SRCS-$(CONFIG_ARM) += xc_dom_arm.c GUEST_SRCS-$(CONFIG_ARM) += xc_hvm_build_arm.c +ifeq ($(CONFIG_LIBXC_MINIOS),y) +GUEST_SRCS-y += xc_dom_decompress_unsafe.c +GUEST_SRCS-y += xc_dom_decompress_unsafe_bzip2.c +GUEST_SRCS-y += xc_dom_decompress_unsafe_lzma.c +GUEST_SRCS-y += xc_dom_decompress_unsafe_lzo1x.c +GUEST_SRCS-y += xc_dom_decompress_unsafe_xz.c +endif + OSDEP_SRCS-y += xenctrl_osdep_ENOSYS.c -include $(XEN_TARGET_ARCH)/Makefile diff --git a/tools/libxc/xc_dom_bzimageloader.c b/tools/libxc/xc_dom_bzimageloader.c index 6daa78ce2a..3870c6d5f5 100644 --- a/tools/libxc/xc_dom_bzimageloader.c +++ b/tools/libxc/xc_dom_bzimageloader.c @@ -35,6 +35,8 @@ #include "xg_private.h" #include "xc_dom.h" +#ifndef __MINIOS__ + #if defined(HAVE_BZLIB) #include <bzlib.h> @@ -562,6 +564,15 @@ static int xc_try_lzo1x_decode( #endif +#else /* __MINIOS__ */ + +int xc_try_bzip2_decode(struct xc_dom_image *dom, void **blob, size_t *size); +int xc_try_lzma_decode(struct xc_dom_image *dom, void **blob, size_t *size); +int xc_try_lzo1x_decode(struct xc_dom_image *dom, void **blob, size_t *size); +int xc_try_xz_decode(struct xc_dom_image *dom, void **blob, size_t *size); + +#endif /* !__MINIOS__ */ + struct setup_header { uint8_t _pad0[0x1f1]; /* skip uninteresting stuff */ uint8_t setup_sects; diff --git a/tools/libxc/xc_dom_decompress_unsafe.c b/tools/libxc/xc_dom_decompress_unsafe.c new file mode 100644 index 0000000000..164e35558f --- /dev/null +++ b/tools/libxc/xc_dom_decompress_unsafe.c @@ -0,0 +1,48 @@ +#include <stdio.h> +#include <stdlib.h> +#include <inttypes.h> + +#include "xg_private.h" +#include "xc_dom_decompress_unsafe.h" + +static struct xc_dom_image *unsafe_dom; +static unsigned char *output_blob; +static unsigned int output_size; + +static void unsafe_error(const char *msg) +{ + xc_dom_panic(unsafe_dom->xch, XC_INVALID_KERNEL, "%s", msg); +} + +static int unsafe_flush(void *src, unsigned int size) +{ + void *n = realloc(output_blob, output_size + size); + if (!n) + return -1; + output_blob = n; + + memcpy(&output_blob[output_size], src, size); + output_size += size; + return size; +} + +int xc_dom_decompress_unsafe( + decompress_fn fn, struct xc_dom_image *dom, void **blob, size_t *size) +{ + int ret; + + unsafe_dom = dom; + output_blob = NULL; + output_size = 0; + + ret = fn(dom->kernel_blob, dom->kernel_size, NULL, unsafe_flush, NULL, NULL, unsafe_error); + + if (ret) + free(output_blob); + else { + *blob = output_blob; + *size = output_size; + } + + return ret; +} diff --git a/tools/libxc/xc_dom_decompress_unsafe.h b/tools/libxc/xc_dom_decompress_unsafe.h new file mode 100644 index 0000000000..64f68864b1 --- /dev/null +++ b/tools/libxc/xc_dom_decompress_unsafe.h @@ -0,0 +1,20 @@ +#include "xc_dom.h" + +typedef int decompress_fn(unsigned char *inbuf, unsigned int len, + int (*fill)(void*, unsigned int), + int (*flush)(void*, unsigned int), + unsigned char *outbuf, unsigned int *posp, + void (*error)(const char *x)); + +int xc_dom_decompress_unsafe( + decompress_fn fn, struct xc_dom_image *dom, void **blob, size_t *size) + __attribute__((visibility("internal"))); + +int xc_try_bzip2_decode(struct xc_dom_image *dom, void **blob, size_t *size) + __attribute__((visibility("internal"))); +int xc_try_lzma_decode(struct xc_dom_image *dom, void **blob, size_t *size) + __attribute__((visibility("internal"))); +int xc_try_lzo1x_decode(struct xc_dom_image *dom, void **blob, size_t *size) + __attribute__((visibility("internal"))); +int xc_try_xz_decode(struct xc_dom_image *dom, void **blob, size_t *size) + __attribute__((visibility("internal"))); diff --git a/tools/libxc/xc_dom_decompress_unsafe_bzip2.c b/tools/libxc/xc_dom_decompress_unsafe_bzip2.c new file mode 100644 index 0000000000..4dcabe4061 --- /dev/null +++ b/tools/libxc/xc_dom_decompress_unsafe_bzip2.c @@ -0,0 +1,14 @@ +#include <stdio.h> +#include <stdlib.h> +#include <inttypes.h> + +#include "xg_private.h" +#include "xc_dom_decompress_unsafe.h" + +#include "../../xen/common/bunzip2.c" + +int xc_try_bzip2_decode( + struct xc_dom_image *dom, void **blob, size_t *size) +{ + return xc_dom_decompress_unsafe(bunzip2, dom, blob, size); +} diff --git a/tools/libxc/xc_dom_decompress_unsafe_lzma.c b/tools/libxc/xc_dom_decompress_unsafe_lzma.c new file mode 100644 index 0000000000..4ee8cdbab1 --- /dev/null +++ b/tools/libxc/xc_dom_decompress_unsafe_lzma.c @@ -0,0 +1,14 @@ +#include <stdio.h> +#include <stdlib.h> +#include <inttypes.h> + +#include "xg_private.h" +#include "xc_dom_decompress_unsafe.h" + +#include "../../xen/common/unlzma.c" + +int xc_try_lzma_decode( + struct xc_dom_image *dom, void **blob, size_t *size) +{ + return xc_dom_decompress_unsafe(unlzma, dom, blob, size); +} diff --git a/tools/libxc/xc_dom_decompress_unsafe_lzo1x.c b/tools/libxc/xc_dom_decompress_unsafe_lzo1x.c new file mode 100644 index 0000000000..57c73e30c1 --- /dev/null +++ b/tools/libxc/xc_dom_decompress_unsafe_lzo1x.c @@ -0,0 +1,49 @@ +#include <stdio.h> +#include <stdlib.h> +#include <inttypes.h> +#include <endian.h> +#include <stdint.h> + +#include "xg_private.h" +#include "xc_dom_decompress_unsafe.h" + +typedef uint8_t u8; +typedef uint32_t u32; +typedef uint16_t u16; + +#define likely(a) a +#define noinline +#define unlikely(a) a + +static inline u16 be16_to_cpup(const u16 *p) +{ + u16 v = *p; +#if BYTE_ORDER == LITTLE_ENDIAN + return (((v & 0x00ffU) << 8) | + ((v & 0xff00U) >> 8)); +#else + return v; +#endif +} + +static inline u32 be32_to_cpup(const u32 *p) +{ + u32 v = *p; +#if BYTE_ORDER == LITTLE_ENDIAN + return (((v & 0x000000ffUL) << 24) | + ((v & 0x0000ff00UL) << 8) | + ((v & 0x00ff0000UL) >> 8) | + ((v & 0xff000000UL) >> 24)); +#else + return v; +#endif +} + +#include "../../xen/common/lzo.c" +#include "../../xen/common/unlzo.c" + +int xc_try_lzo1x_decode( + struct xc_dom_image *dom, void **blob, size_t *size) +{ + return xc_dom_decompress_unsafe(unlzo, dom, blob, size); +} diff --git a/tools/libxc/xc_dom_decompress_unsafe_xz.c b/tools/libxc/xc_dom_decompress_unsafe_xz.c new file mode 100644 index 0000000000..2a32d40805 --- /dev/null +++ b/tools/libxc/xc_dom_decompress_unsafe_xz.c @@ -0,0 +1,57 @@ +#include <stdio.h> +#include <endian.h> +#include <stdlib.h> +#include <stddef.h> +#include <stdint.h> +#include <inttypes.h> + +#include "xg_private.h" +#include "xc_dom_decompress_unsafe.h" + +// TODO +#define XZ_DEC_X86 + +typedef char bool_t; +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint32_t __le32; + +static inline u32 cpu_to_le32(const u32 v) +{ +#if BYTE_ORDER == BIG_ENDIAN + return (((v & 0x000000ffUL) << 24) | + ((v & 0x0000ff00UL) << 8) | + ((v & 0x00ff0000UL) >> 8) | + ((v & 0xff000000UL) >> 24)); +#else + return v; +#endif +} + +static inline u32 le32_to_cpup(const u32 *p) +{ + return cpu_to_le32(*p); +} + +#define min(x,y) ({ \ + const typeof(x) _x = (x); \ + const typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x < _y ? _x : _y; }) + +#define min_t(type,x,y) \ + ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) +#define max_t(type,x,y) \ + ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) + +#define __force +#define always_inline + +#include "../../xen/common/unxz.c" + +int xc_try_xz_decode( + struct xc_dom_image *dom, void **blob, size_t *size) +{ + return xc_dom_decompress_unsafe(unxz, dom, blob, size); +} |