Given a memory region mem_min_overlap will iterate all avoid region
to find the first one which overlap with it. This function will be
used later.

Signed-off-by: Baoquan He <b...@redhat.com>
---
 arch/x86/boot/compressed/aslr.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/arch/x86/boot/compressed/aslr.c b/arch/x86/boot/compressed/aslr.c
index 26610a2..ded3959 100644
--- a/arch/x86/boot/compressed/aslr.c
+++ b/arch/x86/boot/compressed/aslr.c
@@ -213,6 +213,38 @@ static bool mem_avoid_overlap(struct mem_vector *img)
        return false;
 }
 
+static unsigned long mem_min_overlap(struct mem_vector *img, struct mem_vector 
*out)
+{
+       int i;
+       struct setup_data *ptr;
+       unsigned long min = img->start + img->size;
+
+       for (i = 0; i < MEM_AVOID_MAX; i++) {
+               if (mem_overlaps(img, &mem_avoid[i]) && (mem_avoid[i].start < 
min) ) {
+                       *out = mem_avoid[i];
+                       min = mem_avoid[i].start;
+               }
+       }
+
+       /* Check all entries in the setup_data linked list. */
+       ptr = (struct setup_data *)(unsigned long)real_mode->hdr.setup_data;
+       while (ptr) {
+               struct mem_vector avoid;
+
+               avoid.start = (unsigned long)ptr;
+               avoid.size = sizeof(*ptr) + ptr->len;
+
+               if (mem_overlaps(img, &avoid) && (avoid.start < min) ) {
+                       *out = avoid;
+                       min = avoid.start;
+               }
+
+               ptr = (struct setup_data *)(unsigned long)ptr->next;
+       }
+
+       return min;
+}
+
 static unsigned long slots[CONFIG_RANDOMIZE_BASE_MAX_OFFSET /
                           CONFIG_PHYSICAL_ALIGN];
 
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to