summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <sthibault@debian.org>2024-01-21 16:56:29 +0000
committerSamuel Thibault <sthibault@debian.org>2024-01-21 17:53:06 +0000
commit95f0e08fe16bc73b6c5ab337ea461ae119a38728 (patch)
treeb39ffa3c872bfe5aa3d8866205845a1bf3dd8c98
parent472cbf018f2397cd108c06e4730a0536e39df915 (diff)
patches/err: Better error reportingmaster
-rw-r--r--debian/changelog5
-rw-r--r--debian/patches/err125
-rw-r--r--debian/patches/series1
3 files changed, 129 insertions, 2 deletions
diff --git a/debian/changelog b/debian/changelog
index 50b8e1ff..b0f92768 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-rumpkernel (0~20211031+repack-4) UNRELEASED; urgency=medium
+rumpkernel (0~20211031+repack-4) unreleased; urgency=medium
* patches/PAE: Fix 64bit build of PAE support.
* rules: Make blhc happier by disabling format-security rather that not
@@ -9,8 +9,9 @@ rumpkernel (0~20211031+repack-4) UNRELEASED; urgency=medium
* patches/vm_allocate_contiguous_align: Work-around allocating with
alignment larger than a page.
* control: Replace extra priority with optional.
+ * patches/err: Better error reporting.
- -- Samuel Thibault <sthibault@debian.org> Tue, 19 Sep 2023 18:29:43 +0200
+ -- Samuel Thibault <sthibault@debian.org> Sun, 21 Jan 2024 16:54:04 +0000
rumpkernel (0~20211031+repack-3) unreleased; urgency=medium
diff --git a/debian/patches/err b/debian/patches/err
new file mode 100644
index 00000000..983c2c1e
--- /dev/null
+++ b/debian/patches/err
@@ -0,0 +1,125 @@
+err() prints from errno, not from eval.
+Also, better print a backtrace in some cases
+
+---
+ pci-userspace/src-gnu/pci_user-gnu.c | 48 +++++++++++++++++++++++++++++------
+ 1 file changed, 41 insertions(+), 7 deletions(-)
+
+Index: rumpkernel/pci-userspace/src-gnu/pci_user-gnu.c
+===================================================================
+--- rumpkernel.orig/pci-userspace/src-gnu/pci_user-gnu.c
++++ rumpkernel/pci-userspace/src-gnu/pci_user-gnu.c
+@@ -45,7 +45,9 @@
+ #include <sys/io.h>
+
+ #include <assert.h>
++#include <stdarg.h>
+ #include <err.h>
++#include <execinfo.h>
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <inttypes.h>
+@@ -96,6 +98,26 @@ static device_t acpi_dev;
+ #define PCI_CFG1_START 0xcf8
+ #define PCI_CFG1_END 0xcff
+
++static void err_backtrace(int eval, const char *fmt, ...)
++{
++ static const size_t size = 128;
++ static const int skip = 1;
++ void *buffer[size];
++ int nptrs;
++
++ nptrs = backtrace(buffer, size);
++
++ if (nptrs > skip) {
++ backtrace_symbols_fd(&buffer[skip], nptrs - skip, STDERR_FILENO);
++ fflush(stderr);
++ }
++
++ va_list ap;
++ va_start(ap, fmt);
++ verr(eval, fmt, ap);
++ va_end(ap);
++}
++
+ int
+ rumpcomp_pci_iospace_init(void)
+ {
+@@ -119,6 +141,7 @@ static struct pci_device *pci_devices[NU
+ static void
+ pci_userspace_init(void)
+ {
++ kern_return_t ret;
+ /* FIXME: add a hook to make rump call this, once and only once */
+ static int is_init = 0;
+ if (is_init)
+@@ -126,11 +149,15 @@ pci_userspace_init(void)
+
+ MACH_PRINT("pci_userspace_init\n");
+
+- if (get_privileged_ports (&master_host, &master_device))
++ if ((ret = get_privileged_ports (&master_host, &master_device))) {
++ errno = ret;
+ err(1, "get_privileged_ports");
++ }
+
+- if (device_open (master_device, D_READ, "irq", &irq_dev))
++ if ((ret = device_open (master_device, D_READ, "irq", &irq_dev))) {
++ errno = ret;
+ err(2, "device_open irq");
++ }
+
+ /* Optional */
+ if (device_open (master_device, D_READ, "acpi", &acpi_dev)) {
+@@ -522,8 +549,10 @@ rumpcomp_pci_virt_to_mach(void *virt)
+
+ tp = mach_task_self();
+ ret = mach_vm_region_info(tp, vaddr, &region, &object);
+- if (KERN_SUCCESS != ret)
+- err(ret, "mach_vm_region_info");
++ if (KERN_SUCCESS != ret) {
++ errno = ret;
++ err_backtrace(ret, "mach_vm_region_info(%p)", (void*) vaddr);
++ }
+
+ ret = mach_vm_object_pages_phys(object, &pages_phys, &pagesCnt);
+ if (ret == KERN_SUCCESS)
+@@ -547,16 +576,20 @@ rumpcomp_pci_virt_to_mach(void *virt)
+ }
+
+ ret = vm_deallocate(tp, (vm_address_t)pages_phys, pagesCnt*sizeof(*pages_phys));
+- if (KERN_SUCCESS != ret)
+- err(ret, "vm_deallocate");
++ if (KERN_SUCCESS != ret) {
++ errno = ret;
++ err_backtrace(ret, "vm_deallocate(%p)", (void*) pages_phys);
++ }
+ }
+ else
+ {
+ /* Fallback to non-PAE RPC, hoping for the best */
+
+ ret = mach_vm_object_pages(object, &pages, &pagesCnt);
+- if (KERN_SUCCESS != ret)
+- err(ret, "mach_vm_object_pages");
++ if (KERN_SUCCESS != ret) {
++ errno = ret;
++ err_backtrace(ret, "mach_vm_object_pages(%u)", object);
++ }
+
+ mach_port_deallocate(mach_task_self(), object);
+
+@@ -577,8 +610,10 @@ rumpcomp_pci_virt_to_mach(void *virt)
+ }
+
+ ret = vm_deallocate(tp, (vm_address_t)pages, pagesCnt*sizeof(*pages));
+- if (KERN_SUCCESS != ret)
+- err(ret, "vm_deallocate");
++ if (KERN_SUCCESS != ret) {
++ errno = ret;
++ err_backtrace(ret, "vm_deallocate(%p)", (void*) pages);
++ }
+ }
+
+ if (paddr == 0){
diff --git a/debian/patches/series b/debian/patches/series
index 258d22ec..6c86979c 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -23,3 +23,4 @@ non-fhs-shell
clean_external
PAE
vm_allocate_contiguous_align
+err