summaryrefslogtreecommitdiffstats
path: root/src/interface
diff options
context:
space:
mode:
authorMichael Brown2025-04-30 14:22:54 +0200
committerMichael Brown2025-04-30 16:38:15 +0200
commitcd803ff2e2424b56a7ae5886e4cfe17b47652e6e (patch)
tree7aa8c5e39ba398b19881a0dc181a4bdbf48e7723 /src/interface
parent[image] Move embedded images from .rodata to .data (diff)
downloadipxe-cd803ff2e2424b56a7ae5886e4cfe17b47652e6e.tar.gz
ipxe-cd803ff2e2424b56a7ae5886e4cfe17b47652e6e.tar.xz
ipxe-cd803ff2e2424b56a7ae5886e4cfe17b47652e6e.zip
[image] Add the concept of a static image
Not all images are allocated via alloc_image(). For example: embedded images, the static images created to hold a runtime command line, and the images used by unit tests are all static structures. Using image_set_cmdline() (via e.g. the "imgargs" command) to set the command-line arguments of a static image will succeed but will leak memory, since nothing will ever free the allocated command line. There are no code paths that can lead to calling image_set_len() on a static image, but there is no safety check against future code paths attempting this. Define a flag IMAGE_STATIC to mark an image as statically allocated, generalise free_image() to also handle freeing dynamically allocated portions of static images (such as the command line), and expose free_image() for use by static images. Define a related flag IMAGE_STATIC_NAME to mark the name as statically allocated. Allow a statically allocated name to be replaced with a dynamically allocated name since this is a potentially valid use case (e.g. if "imgdecrypt --name <name>" is used on an embedded image). Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/interface')
-rw-r--r--src/interface/efi/efi_cmdline.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/interface/efi/efi_cmdline.c b/src/interface/efi/efi_cmdline.c
index 13ad0fc35..59bce925f 100644
--- a/src/interface/efi/efi_cmdline.c
+++ b/src/interface/efi/efi_cmdline.c
@@ -58,6 +58,7 @@ static void efi_cmdline_free ( struct refcnt *refcnt ) {
struct image *image = container_of ( refcnt, struct image, refcnt );
DBGC ( image, "CMDLINE freeing command line\n" );
+ free_image ( refcnt );
free ( efi_cmdline_copy );
}
@@ -65,6 +66,7 @@ static void efi_cmdline_free ( struct refcnt *refcnt ) {
static struct image efi_cmdline_image = {
.refcnt = REF_INIT ( efi_cmdline_free ),
.name = "<CMDLINE>",
+ .flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ),
.type = &script_image_type,
};