[SeaBIOS] [PATCH v4 2/5] pmm: support looking up a given pattern in FSEG
Michael S. Tsirkin
mst at redhat.com
Mon Sep 23 20:20:28 CEST 2013
Will be used to find RSDP there.
Signed-off-by: Michael S. Tsirkin <mst at redhat.com>
---
src/malloc.h | 1 +
src/malloc.c | 20 +++++++++++++++++++-
2 files changed, 20 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..d150c90 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,24 @@ _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)
+{
+ struct allocinfo_s *info;
+ hlist_for_each_entry(info, &ZoneFSeg.head, node) {
+ unsigned space = info->dataend - info->data;
+ int off;
+
+ if (space < pattern_size)
+ continue;
+ for (off = 0; off < space - pattern_size; ++off) {
+ if (!memcmp(info->data + off, pattern, pattern_size))
+ return info->data + off;
+ }
+ }
+ return NULL;
+}
+
// Find the amount of free space in a given zone.
u32
malloc_getspace(struct zone_s *zone)
--
MST
More information about the SeaBIOS
mailing list