poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[COMMITTED] libpoke: improve error handling in ios-dev-mmap.c


From: Jose E. Marchesi
Subject: [COMMITTED] libpoke: improve error handling in ios-dev-mmap.c
Date: Wed, 25 Sep 2024 12:21:03 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

This commit makes the functions in ios-dev-mmap.c to return better IO
device error codes and also to not print diagnostics in the terminal.

2024-09-25  Jose E. Marchesi  <jemarch@gnu.org>

        * libpoke/ios-dev-mmap.c (ios_dev_mmap_open): Improve error codes
        and do not print in terminal.
        (ios_dev_mmap_flush): Likewise.
        * libpoke/pkl-rt.pk (open): Fix exception msg for IOD_EMMAP.
---
 ChangeLog              |  7 +++++++
 libpoke/ios-dev-mmap.c | 23 ++++-------------------
 libpoke/ios-dev.h      |  2 +-
 libpoke/pkl-rt.pk      |  2 +-
 4 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 82dcc84f..e0afa8f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-09-25  Jose E. Marchesi  <jemarch@gnu.org>
+
+       * libpoke/ios-dev-mmap.c (ios_dev_mmap_open): Improve error codes
+       and do not print in terminal.
+       (ios_dev_mmap_flush): Likewise.
+       * libpoke/pkl-rt.pk (open): Fix exception msg for IOD_EMMAP.
+
 2024-09-25  Jose E. Marchesi  <jemarch@gnu.org>
 
        * poke/pk-cmd.c (pk_cmd_exec): Clear lexical cuckolding if
diff --git a/libpoke/ios-dev-mmap.c b/libpoke/ios-dev-mmap.c
index 9c1ee1c2..41acaed6 100644
--- a/libpoke/ios-dev-mmap.c
+++ b/libpoke/ios-dev-mmap.c
@@ -36,8 +36,6 @@
 #include "ios.h"
 #include "ios-dev.h"
 
-#include "pkt.h"
-
 /* State associated with a file device.  */
 struct ios_dev_mmap
 {
@@ -199,8 +197,7 @@ ios_dev_mmap_open (const char *handler, uint64_t flags, int 
*error,
       fd = open (dev_map->filename, open_flags);
       if (fd == -1)
         {
-          pk_printf ("Error in open of %s err: %s\n",
-                     dev_map->filename, strerror (errno));
+          internal_error = IOD_ENOENT;
           goto err;
         }
       flags = mode_flags;
@@ -229,8 +226,7 @@ ios_dev_mmap_open (const char *handler, uint64_t flags, int 
*error,
         }
       if (fd == -1)
         {
-          pk_printf ("Error in open of %s err: %s\n",
-                     dev_map->filename, strerror (errno));
+          internal_error = IOD_ENOENT;
           goto err;
         }
     }
@@ -240,8 +236,7 @@ ios_dev_mmap_open (const char *handler, uint64_t flags, int 
*error,
   ret = fstat (fd, &st);
   if (ret == -1)
     {
-      pk_printf ("Error in fstat of %s err: %s\n",
-                 dev_map->filename, strerror (errno));
+      internal_error = IOD_ENOENT;
       goto err;
     }
   if ((st.st_mode & S_IFMT) == S_IFREG)
@@ -261,9 +256,6 @@ ios_dev_mmap_open (const char *handler, uint64_t flags, int 
*error,
                         fd, dev_map->base);
   if (dev_map->addr == MAP_FAILED)
     {
-      pk_printf ("Error in mmap of %s base: 0x%x len: 0x%x prot: 0x%x err: 
%s\n",
-                 dev_map->filename, dev_map->base, dev_map->size,
-                 dev_map->prot, strerror (errno));
       internal_error = IOD_EMMAP;
       goto err;
     }
@@ -273,8 +265,6 @@ ios_dev_mmap_open (const char *handler, uint64_t flags, int 
*error,
      But we double check because pread and pwrite rely on this alignment */
   if ((unsigned long)dev_map->addr & ((unsigned long)getpagesize () - 1))
     {
-      pk_printf ("Alignment issue treated as error in mmap of %s addr: 0x%x\n",
-                 dev_map->filename, dev_map->addr);
       internal_error = IOD_EMMAP;
       goto err;
     }
@@ -436,12 +426,7 @@ ios_dev_mmap_flush (void *iod, ios_dev_off offset)
     {
       ret = msync (dev_map->addr, dev_map->size, MS_SYNC);
       if (ret == -1)
-        {
-          pk_printf ("Error in msync of %s base: 0x%lx len: 0x%lx err: %s\n",
-                     dev_map->filename, dev_map->addr, dev_map->size,
-                     strerror (errno));
-          return IOD_ERROR;
-        }
+        return IOD_EMMAP;
     }
 
   return IOD_OK;
diff --git a/libpoke/ios-dev.h b/libpoke/ios-dev.h
index aa8126ac..c30f9066 100644
--- a/libpoke/ios-dev.h
+++ b/libpoke/ios-dev.h
@@ -35,7 +35,7 @@ typedef uint64_t ios_dev_off;
 /* Error codes to be used in the interface below.
 
    If you update them, please adjust the PK_IOS_* constants in
-   libpoke.h accordingly.  */
+   libpoke.h accordingly and also the open builtin in pkl-rt.pk.  */
 
 #define IOD_OK      0 /* The operation was performed to completion,
                          in the expected way.  */
diff --git a/libpoke/pkl-rt.pk b/libpoke/pkl-rt.pk
index 8566c25f..d4ba6bc9 100644
--- a/libpoke/pkl-rt.pk
+++ b/libpoke/pkl-rt.pk
@@ -1007,7 +1007,7 @@ immutable fun open = (string handler, uint<64> flags = 0) 
int<32>:
   else if (ios == -7)
     raise Exception { code = EC_io,
                       name = E_io.name,
-                      msg = "IO space already opened" };
+                      msg = "memory mapping error" };
   else if (ios == -8)
     raise Exception { code = EC_noent,
                       name = E_noent.name,
-- 
2.30.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]