[SeaBIOS] [PATCH v5 2/4] malloc: support looking up a given pattern in FSEG
Michael S. Tsirkin
mst at redhat.com
Sun Sep 29 06:42:12 CEST 2013
On Thu, Sep 26, 2013 at 08:33:53PM -0400, Kevin O'Connor wrote:
> On Wed, Sep 25, 2013 at 12:54:42PM +0300, Michael S. Tsirkin wrote:
> > Will be used to find RSDP there.
> >
> > Signed-off-by: Michael S. Tsirkin <mst at 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;
> > +}
>
> This shouldn't be in malloc.c - it's not part of the core memory
> allocation system. Either scan the whole of 0xf0000-0x100000, use
> extern zonefseg_end/start in another file, or scan the allocations
> made in romfile-loader.
BTW ACPI spec says 0xe0000 and not 0xf0000:
5.2.5.1 Finding the RSDP on IA-PC Systems
OSPM finds the Root System Description Pointer (RSDP) structure by
searching physical memory
ranges on 16-byte boundaries for a valid Root System Description Pointer
structure signature and
checksum match as follows:
•
The first 1 KB of the Extended BIOS Data Area (EBDA). For EISA or MCA
systems, the
EBDA can be found in the two-byte location 40:0Eh on the BIOS data area.
•
The BIOS read-only memory space between 0E0000h and 0FFFFFh.
> Also, this shouldn't scan every byte for the pattern. It should scan
> on 16 byte boundaries and do the acpi checksum check. See the code in
> fw/biostable.c:copy_acpi_rsdp as an example. Nothing stops something
> else from allocating ram which happens to have an rsdp signature in
> it. It's unlikely, but not worth the risk.
>
> The rest of the series looks okay to me.
>
> -Kevin
More information about the SeaBIOS
mailing list