|
|
8631a2 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
8631a2 |
From: Peter Jones <pjones@redhat.com>
|
|
|
8631a2 |
Date: Mon, 27 Aug 2018 13:14:06 -0400
|
|
|
8631a2 |
Subject: [PATCH] Make grub_error() more verbose
|
|
|
8631a2 |
|
|
|
8631a2 |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
8631a2 |
---
|
|
|
8631a2 |
grub-core/kern/efi/mm.c | 17 ++++++++++++++---
|
|
|
8631a2 |
grub-core/kern/err.c | 13 +++++++++++--
|
|
|
8631a2 |
include/grub/err.h | 5 ++++-
|
|
|
8631a2 |
3 files changed, 29 insertions(+), 6 deletions(-)
|
|
|
8631a2 |
|
|
|
8631a2 |
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
|
|
|
8631a2 |
index 5cdf6c943f2..7692e63ba24 100644
|
|
|
8631a2 |
--- a/grub-core/kern/efi/mm.c
|
|
|
8631a2 |
+++ b/grub-core/kern/efi/mm.c
|
|
|
8631a2 |
@@ -157,12 +157,20 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
|
|
|
8631a2 |
|
|
|
8631a2 |
/* Limit the memory access to less than 4GB for 32-bit platforms. */
|
|
|
8631a2 |
if (address > GRUB_EFI_MAX_USABLE_ADDRESS)
|
|
|
8631a2 |
- return 0;
|
|
|
8631a2 |
+ {
|
|
|
8631a2 |
+ grub_error (GRUB_ERR_BAD_ARGUMENT,
|
|
|
8631a2 |
+ N_("invalid memory address (0x%llx > 0x%llx)"),
|
|
|
8631a2 |
+ address, GRUB_EFI_MAX_USABLE_ADDRESS);
|
|
|
8631a2 |
+ return NULL;
|
|
|
8631a2 |
+ }
|
|
|
8631a2 |
|
|
|
8631a2 |
b = grub_efi_system_table->boot_services;
|
|
|
8631a2 |
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
|
|
|
8631a2 |
if (status != GRUB_EFI_SUCCESS)
|
|
|
8631a2 |
- return 0;
|
|
|
8631a2 |
+ {
|
|
|
8631a2 |
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
|
|
8631a2 |
+ return NULL;
|
|
|
8631a2 |
+ }
|
|
|
8631a2 |
|
|
|
8631a2 |
if (address == 0)
|
|
|
8631a2 |
{
|
|
|
8631a2 |
@@ -172,7 +180,10 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
|
|
|
8631a2 |
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
|
|
|
8631a2 |
grub_efi_free_pages (0, pages);
|
|
|
8631a2 |
if (status != GRUB_EFI_SUCCESS)
|
|
|
8631a2 |
- return 0;
|
|
|
8631a2 |
+ {
|
|
|
8631a2 |
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
|
|
8631a2 |
+ return NULL;
|
|
|
8631a2 |
+ }
|
|
|
8631a2 |
}
|
|
|
8631a2 |
|
|
|
8631a2 |
grub_efi_store_alloc (address, pages);
|
|
|
8631a2 |
diff --git a/grub-core/kern/err.c b/grub-core/kern/err.c
|
|
|
8631a2 |
index 53c734de70e..aebfe0cf839 100644
|
|
|
8631a2 |
--- a/grub-core/kern/err.c
|
|
|
8631a2 |
+++ b/grub-core/kern/err.c
|
|
|
8631a2 |
@@ -33,15 +33,24 @@ static struct grub_error_saved grub_error_stack_items[GRUB_ERROR_STACK_SIZE];
|
|
|
8631a2 |
static int grub_error_stack_pos;
|
|
|
8631a2 |
static int grub_error_stack_assert;
|
|
|
8631a2 |
|
|
|
8631a2 |
+#ifdef grub_error
|
|
|
8631a2 |
+#undef grub_error
|
|
|
8631a2 |
+#endif
|
|
|
8631a2 |
+
|
|
|
8631a2 |
grub_err_t
|
|
|
8631a2 |
-grub_error (grub_err_t n, const char *fmt, ...)
|
|
|
8631a2 |
+grub_error (grub_err_t n, const char *file, const int line, const char *fmt, ...)
|
|
|
8631a2 |
{
|
|
|
8631a2 |
va_list ap;
|
|
|
8631a2 |
+ int m;
|
|
|
8631a2 |
|
|
|
8631a2 |
grub_errno = n;
|
|
|
8631a2 |
|
|
|
8631a2 |
+ m = grub_snprintf (grub_errmsg, sizeof (grub_errmsg), "%s:%d:", file, line);
|
|
|
8631a2 |
+ if (m < 0)
|
|
|
8631a2 |
+ m = 0;
|
|
|
8631a2 |
+
|
|
|
8631a2 |
va_start (ap, fmt);
|
|
|
8631a2 |
- grub_vsnprintf (grub_errmsg, sizeof (grub_errmsg), _(fmt), ap);
|
|
|
8631a2 |
+ grub_vsnprintf (grub_errmsg + m, sizeof (grub_errmsg) - m, _(fmt), ap);
|
|
|
8631a2 |
va_end (ap);
|
|
|
8631a2 |
|
|
|
8631a2 |
return n;
|
|
|
8631a2 |
diff --git a/include/grub/err.h b/include/grub/err.h
|
|
|
8631a2 |
index 1590c688e1d..9b830757d35 100644
|
|
|
8631a2 |
--- a/include/grub/err.h
|
|
|
8631a2 |
+++ b/include/grub/err.h
|
|
|
8631a2 |
@@ -84,7 +84,10 @@ struct grub_error_saved
|
|
|
8631a2 |
extern grub_err_t EXPORT_VAR(grub_errno);
|
|
|
8631a2 |
extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG];
|
|
|
8631a2 |
|
|
|
8631a2 |
-grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *fmt, ...);
|
|
|
8631a2 |
+grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *file, const int line, const char *fmt, ...);
|
|
|
8631a2 |
+
|
|
|
8631a2 |
+#define grub_error(n, fmt, ...) grub_error (n, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
|
|
8631a2 |
+
|
|
|
8631a2 |
void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn));
|
|
|
8631a2 |
void EXPORT_FUNC(grub_error_push) (void);
|
|
|
8631a2 |
int EXPORT_FUNC(grub_error_pop) (void);
|