Will be used to find RSDP there.
Signed-off-by: Michael S. Tsirkin mst@redhat.com --- src/malloc.h | 1 + src/malloc.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/malloc.h b/src/malloc.h index af8a21d..feb8938 100644 --- a/src/malloc.h +++ b/src/malloc.h @@ -19,6 +19,7 @@ void *_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align); int _free(void *data); u32 malloc_getspace(struct zone_s *zone); void *malloc_find(u32 handle); +void *malloc_find_fseg_pattern(void *pattern, unsigned pattern_size);
#define MALLOC_DEFAULT_HANDLE 0xFFFFFFFF // Minimum alignment of malloc'd memory diff --git a/src/malloc.c b/src/malloc.c index 281f41e..0f5fae7 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -12,7 +12,7 @@ #include "output.h" // dprintf #include "stacks.h" // wait_preempt #include "std/optionrom.h" // OPTION_ROM_ALIGN -#include "string.h" // memset +#include "string.h" // memset, memcmp
// Information on a reserved area. struct allocinfo_s { @@ -273,6 +273,23 @@ _free(void *data) return 0; }
+// Find the data block in zone matching a given pattern. +void *malloc_find_fseg_pattern(void *pattern, unsigned pattern_size) +{ + extern u8 zonefseg_start[], zonefseg_end[]; + unsigned space = zonefseg_end - zonefseg_start; + int off; + + if (space < pattern_size) + return NULL; + + for (off = 0; off < space - pattern_size; ++off) { + if (!memcmp(zonefseg_start + off, pattern, pattern_size)) + return zonefseg_start + off; + } + return NULL; +} + // Find the amount of free space in a given zone. u32 malloc_getspace(struct zone_s *zone)