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