|
|
8631a2 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
8631a2 |
From: Javier Martinez Canillas <javierm@redhat.com>
|
|
|
8631a2 |
Date: Thu, 27 Sep 2018 10:49:14 +0200
|
|
|
8631a2 |
Subject: [PATCH] Move quicksort function from kernel.exec to the blscfg module
|
|
|
8631a2 |
|
|
|
8631a2 |
The qsort function is defined in the grub2 kernel and exported for modules
|
|
|
8631a2 |
to use. But this prevents the blscfg.mod to be loaded by old grub2 kernels
|
|
|
8631a2 |
that don't export this symbol.
|
|
|
8631a2 |
|
|
|
8631a2 |
Loading the latest blscfg module might be useful on legacy BIOS systems to
|
|
|
8631a2 |
avoid updating the first and second stage grub2 images in the boot device.
|
|
|
8631a2 |
|
|
|
8631a2 |
Since the only caller of the qsort function is the blscfg module, move the
|
|
|
8631a2 |
qsort function out of the grub2 kernel and only have it in the blscfg.mod.
|
|
|
8631a2 |
|
|
|
8631a2 |
While being there, also remove the grub_bsearch() function that is unused.
|
|
|
8631a2 |
|
|
|
8631a2 |
Related: rhbz#1633646
|
|
|
8631a2 |
|
|
|
8631a2 |
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
|
|
|
8631a2 |
---
|
|
|
8631a2 |
grub-core/Makefile.core.def | 2 +-
|
|
|
8631a2 |
grub-core/commands/blscfg.c | 3 ++-
|
|
|
8631a2 |
grub-core/{kern/qsort.c => commands/bls_qsort.h} | 30 +++---------------------
|
|
|
8631a2 |
include/grub/misc.h | 15 ------------
|
|
|
8631a2 |
4 files changed, 6 insertions(+), 44 deletions(-)
|
|
|
8631a2 |
rename grub-core/{kern/qsort.c => commands/bls_qsort.h} (93%)
|
|
|
8631a2 |
|
|
|
8631a2 |
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
|
|
|
8631a2 |
index 01c5f9ae351..f99fc994f6b 100644
|
|
|
8631a2 |
--- a/grub-core/Makefile.core.def
|
|
|
8631a2 |
+++ b/grub-core/Makefile.core.def
|
|
|
8631a2 |
@@ -129,7 +129,6 @@ kernel = {
|
|
|
8631a2 |
common = kern/rescue_parser.c;
|
|
|
8631a2 |
common = kern/rescue_reader.c;
|
|
|
8631a2 |
common = kern/term.c;
|
|
|
8631a2 |
- common = kern/qsort.c;
|
|
|
8631a2 |
common = kern/backtrace.c;
|
|
|
8631a2 |
common = kern/tpm.c;
|
|
|
8631a2 |
|
|
|
8631a2 |
@@ -781,6 +780,7 @@ module = {
|
|
|
8631a2 |
module = {
|
|
|
8631a2 |
name = blscfg;
|
|
|
8631a2 |
common = commands/blscfg.c;
|
|
|
8631a2 |
+ common = commands/bls_qsort.h;
|
|
|
8631a2 |
common = commands/loadenv.h;
|
|
|
8631a2 |
enable = efi;
|
|
|
8631a2 |
enable = i386_pc;
|
|
|
8631a2 |
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
|
|
|
8631a2 |
index abd6f00d0de..bec5a9ffe3e 100644
|
|
|
8631a2 |
--- a/grub-core/commands/blscfg.c
|
|
|
8631a2 |
+++ b/grub-core/commands/blscfg.c
|
|
|
8631a2 |
@@ -36,6 +36,7 @@
|
|
|
8631a2 |
|
|
|
8631a2 |
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
8631a2 |
|
|
|
8631a2 |
+#include "bls_qsort.h"
|
|
|
8631a2 |
#include "loadenv.h"
|
|
|
8631a2 |
|
|
|
8631a2 |
#define GRUB_BLS_CONFIG_PATH "/loader/entries/"
|
|
|
8631a2 |
@@ -717,7 +718,7 @@ read_fallback:
|
|
|
8631a2 |
use_version = false;
|
|
|
8631a2 |
}
|
|
|
8631a2 |
|
|
|
8631a2 |
- grub_qsort(&entries[0], nentries, sizeof (struct bls_entry *), bls_cmp, &use_version);
|
|
|
8631a2 |
+ bls_qsort(&entries[0], nentries, sizeof (struct bls_entry *), bls_cmp, &use_version);
|
|
|
8631a2 |
|
|
|
8631a2 |
grub_dprintf ("blscfg", "%s Creating %d entries from bls\n", __func__, nentries);
|
|
|
8631a2 |
for (r = nentries - 1; r >= 0; r--)
|
|
|
8631a2 |
diff --git a/grub-core/kern/qsort.c b/grub-core/commands/bls_qsort.h
|
|
|
8631a2 |
similarity index 93%
|
|
|
8631a2 |
rename from grub-core/kern/qsort.c
|
|
|
8631a2 |
rename to grub-core/commands/bls_qsort.h
|
|
|
8631a2 |
index 7f3fc9ffdae..572765fa3f2 100644
|
|
|
8631a2 |
--- a/grub-core/kern/qsort.c
|
|
|
8631a2 |
+++ b/grub-core/commands/bls_qsort.h
|
|
|
8631a2 |
@@ -64,6 +64,7 @@ typedef struct
|
|
|
8631a2 |
#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi)))
|
|
|
8631a2 |
#define STACK_NOT_EMPTY (stack < top)
|
|
|
8631a2 |
|
|
|
8631a2 |
+typedef int (*grub_compar_d_fn_t) (const void *p0, const void *p1, void *state);
|
|
|
8631a2 |
|
|
|
8631a2 |
/* Order size using quicksort. This implementation incorporates
|
|
|
8631a2 |
four optimizations discussed in Sedgewick:
|
|
|
8631a2 |
@@ -89,8 +90,8 @@ typedef struct
|
|
|
8631a2 |
smaller partition. This *guarantees* no more than log (total_elems)
|
|
|
8631a2 |
stack size is needed (actually O(1) in this case)! */
|
|
|
8631a2 |
|
|
|
8631a2 |
-void
|
|
|
8631a2 |
-grub_qsort (void *const pbase, grub_size_t total_elems, grub_size_t size,
|
|
|
8631a2 |
+static inline void UNUSED
|
|
|
8631a2 |
+bls_qsort (void *const pbase, grub_size_t total_elems, grub_size_t size,
|
|
|
8631a2 |
grub_compar_d_fn_t cmp, void *arg)
|
|
|
8631a2 |
{
|
|
|
8631a2 |
char *base_ptr = (char *) pbase;
|
|
|
8631a2 |
@@ -252,28 +253,3 @@ grub_qsort (void *const pbase, grub_size_t total_elems, grub_size_t size,
|
|
|
8631a2 |
}
|
|
|
8631a2 |
}
|
|
|
8631a2 |
|
|
|
8631a2 |
-void *
|
|
|
8631a2 |
-grub_bsearch (const void *key, const void *base, grub_size_t nmemb, grub_size_t size,
|
|
|
8631a2 |
- grub_compar_d_fn_t compar, void *state)
|
|
|
8631a2 |
-{
|
|
|
8631a2 |
- grub_size_t l, u, idx;
|
|
|
8631a2 |
- const void *p;
|
|
|
8631a2 |
- int comparison;
|
|
|
8631a2 |
-
|
|
|
8631a2 |
- l = 0;
|
|
|
8631a2 |
- u = nmemb;
|
|
|
8631a2 |
- while (l < u)
|
|
|
8631a2 |
- {
|
|
|
8631a2 |
- idx = (l + u) / 2;
|
|
|
8631a2 |
- p = (void *) (((const char *) base) + (idx * size));
|
|
|
8631a2 |
- comparison = (*compar) (key, p, state);
|
|
|
8631a2 |
- if (comparison < 0)
|
|
|
8631a2 |
- u = idx;
|
|
|
8631a2 |
- else if (comparison > 0)
|
|
|
8631a2 |
- l = idx + 1;
|
|
|
8631a2 |
- else
|
|
|
8631a2 |
- return (void *) p;
|
|
|
8631a2 |
- }
|
|
|
8631a2 |
-
|
|
|
8631a2 |
- return NULL;
|
|
|
8631a2 |
-}
|
|
|
8631a2 |
diff --git a/include/grub/misc.h b/include/grub/misc.h
|
|
|
8631a2 |
index 5f1c1c1be4e..de9016ab709 100644
|
|
|
8631a2 |
--- a/include/grub/misc.h
|
|
|
8631a2 |
+++ b/include/grub/misc.h
|
|
|
8631a2 |
@@ -510,19 +510,4 @@ void EXPORT_FUNC(grub_real_boot_time) (const char *file,
|
|
|
8631a2 |
#define grub_max(a, b) (((a) > (b)) ? (a) : (b))
|
|
|
8631a2 |
#define grub_min(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
8631a2 |
|
|
|
8631a2 |
-typedef int (*grub_compar_d_fn_t) (const void *p0, const void *p1, void *state);
|
|
|
8631a2 |
-
|
|
|
8631a2 |
-void *EXPORT_FUNC(grub_bsearch) (const void *key,
|
|
|
8631a2 |
- const void *base,
|
|
|
8631a2 |
- grub_size_t nmemb,
|
|
|
8631a2 |
- grub_size_t size,
|
|
|
8631a2 |
- grub_compar_d_fn_t compar,
|
|
|
8631a2 |
- void *state);
|
|
|
8631a2 |
-
|
|
|
8631a2 |
-void EXPORT_FUNC(grub_qsort) (void *const pbase,
|
|
|
8631a2 |
- grub_size_t total_elems,
|
|
|
8631a2 |
- grub_size_t size,
|
|
|
8631a2 |
- grub_compar_d_fn_t cmp,
|
|
|
8631a2 |
- void *state);
|
|
|
8631a2 |
-
|
|
|
8631a2 |
#endif /* ! GRUB_MISC_HEADER */
|