|
|
391fb8 |
From 29736faa92d5e4b4242786ee583ce339263d6adb Mon Sep 17 00:00:00 2001
|
|
|
391fb8 |
From: Laszlo Ersek <lersek@redhat.com>
|
|
|
391fb8 |
Date: Mon, 22 Dec 2014 13:11:43 +0100
|
|
|
391fb8 |
Subject: [PATCH 12/15] hw/loader: split out load_image_gzipped_buffer()
|
|
|
391fb8 |
|
|
|
391fb8 |
In the next patch we'd like to reuse the image decompression facility
|
|
|
391fb8 |
without installing the output as a ROM at a specific guest-phys address.
|
|
|
391fb8 |
|
|
|
391fb8 |
In addition, expose LOAD_IMAGE_MAX_GUNZIP_BYTES, because that's a
|
|
|
391fb8 |
straightforward "max_sz" argument for the new load_image_gzipped_buffer().
|
|
|
391fb8 |
|
|
|
391fb8 |
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
391fb8 |
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
|
|
|
391fb8 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
391fb8 |
Message-id: 1419250305-31062-10-git-send-email-pbonzini@redhat.com
|
|
|
391fb8 |
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
|
|
|
391fb8 |
(cherry picked from commit 7d48a0f7217474899c5f5920b21f4cfdf4efa8d1)
|
|
|
391fb8 |
---
|
|
|
391fb8 |
hw/core/loader.c | 30 +++++++++++++++++++++---------
|
|
|
391fb8 |
include/hw/loader.h | 9 +++++++++
|
|
|
391fb8 |
2 files changed, 30 insertions(+), 9 deletions(-)
|
|
|
391fb8 |
|
|
|
391fb8 |
diff --git a/hw/core/loader.c b/hw/core/loader.c
|
|
|
391fb8 |
index 7527fd3..f2b34da 100644
|
|
|
391fb8 |
--- a/hw/core/loader.c
|
|
|
391fb8 |
+++ b/hw/core/loader.c
|
|
|
391fb8 |
@@ -614,14 +614,9 @@ int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz)
|
|
|
391fb8 |
NULL, NULL);
|
|
|
391fb8 |
}
|
|
|
391fb8 |
|
|
|
391fb8 |
-/* This simply prevents g_malloc in the function below from allocating
|
|
|
391fb8 |
- * a huge amount of memory, by placing a limit on the maximum
|
|
|
391fb8 |
- * uncompressed image size that load_image_gzipped will read.
|
|
|
391fb8 |
- */
|
|
|
391fb8 |
-#define LOAD_IMAGE_MAX_GUNZIP_BYTES (256 << 20)
|
|
|
391fb8 |
-
|
|
|
391fb8 |
-/* Load a gzip-compressed kernel. */
|
|
|
391fb8 |
-int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz)
|
|
|
391fb8 |
+/* Load a gzip-compressed kernel to a dynamically allocated buffer. */
|
|
|
391fb8 |
+int load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
|
|
|
391fb8 |
+ uint8_t **buffer)
|
|
|
391fb8 |
{
|
|
|
391fb8 |
uint8_t *compressed_data = NULL;
|
|
|
391fb8 |
uint8_t *data = NULL;
|
|
|
391fb8 |
@@ -653,8 +648,11 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz)
|
|
|
391fb8 |
goto out;
|
|
|
391fb8 |
}
|
|
|
391fb8 |
|
|
|
391fb8 |
- rom_add_blob_fixed(filename, data, bytes, addr);
|
|
|
391fb8 |
+ /* trim to actual size and return to caller */
|
|
|
391fb8 |
+ *buffer = g_realloc(data, bytes);
|
|
|
391fb8 |
ret = bytes;
|
|
|
391fb8 |
+ /* ownership has been transferred to caller */
|
|
|
391fb8 |
+ data = NULL;
|
|
|
391fb8 |
|
|
|
391fb8 |
out:
|
|
|
391fb8 |
g_free(compressed_data);
|
|
|
391fb8 |
@@ -662,6 +660,20 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz)
|
|
|
391fb8 |
return ret;
|
|
|
391fb8 |
}
|
|
|
391fb8 |
|
|
|
391fb8 |
+/* Load a gzip-compressed kernel. */
|
|
|
391fb8 |
+int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz)
|
|
|
391fb8 |
+{
|
|
|
391fb8 |
+ int bytes;
|
|
|
391fb8 |
+ uint8_t *data;
|
|
|
391fb8 |
+
|
|
|
391fb8 |
+ bytes = load_image_gzipped_buffer(filename, max_sz, &data);
|
|
|
391fb8 |
+ if (bytes != -1) {
|
|
|
391fb8 |
+ rom_add_blob_fixed(filename, data, bytes, addr);
|
|
|
391fb8 |
+ g_free(data);
|
|
|
391fb8 |
+ }
|
|
|
391fb8 |
+ return bytes;
|
|
|
391fb8 |
+}
|
|
|
391fb8 |
+
|
|
|
391fb8 |
/*
|
|
|
391fb8 |
* Functions for reboot-persistent memory regions.
|
|
|
391fb8 |
* - used for vga bios and option roms.
|
|
|
391fb8 |
diff --git a/include/hw/loader.h b/include/hw/loader.h
|
|
|
391fb8 |
index 6481639..8997620 100644
|
|
|
391fb8 |
--- a/include/hw/loader.h
|
|
|
391fb8 |
+++ b/include/hw/loader.h
|
|
|
391fb8 |
@@ -16,6 +16,15 @@ int load_image(const char *filename, uint8_t *addr); /* deprecated */
|
|
|
391fb8 |
ssize_t load_image_size(const char *filename, void *addr, size_t size);
|
|
|
391fb8 |
int load_image_targphys(const char *filename, hwaddr,
|
|
|
391fb8 |
uint64_t max_sz);
|
|
|
391fb8 |
+
|
|
|
391fb8 |
+/* This is the limit on the maximum uncompressed image size that
|
|
|
391fb8 |
+ * load_image_gzipped_buffer() and load_image_gzipped() will read. It prevents
|
|
|
391fb8 |
+ * g_malloc() in those functions from allocating a huge amount of memory.
|
|
|
391fb8 |
+ */
|
|
|
391fb8 |
+#define LOAD_IMAGE_MAX_GUNZIP_BYTES (256 << 20)
|
|
|
391fb8 |
+
|
|
|
391fb8 |
+int load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
|
|
|
391fb8 |
+ uint8_t **buffer);
|
|
|
391fb8 |
int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);
|
|
|
391fb8 |
|
|
|
391fb8 |
#define ELF_LOAD_FAILED -1
|
|
|
391fb8 |
--
|
|
|
391fb8 |
2.1.0
|
|
|
391fb8 |
|