From: Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: [PATCH 4/6] sim: callback: inline wrap helper
Date: Sat, 24 Apr 2021 14:41:42 -0400 [thread overview]
Message-ID: <20210424184144.23736-4-vapier@gentoo.org> (raw)
In-Reply-To: <20210424184144.23736-1-vapier@gentoo.org>
This is annoying as it requires inlining boiler plate, but we don't
have much choice: the wrap helper assumes the return value is always
an int, but that's already not the case with some of the callbacks
which use long. GCC has extensions to define macros-as-functions,
but we can't assume GCC.
---
sim/common/callback.c | 84 ++++++++++++++++++++++++++++++-------------
1 file changed, 59 insertions(+), 25 deletions(-)
diff --git a/sim/common/callback.c b/sim/common/callback.c
index 6b7951d2a5ec..2b27226f0060 100644
--- a/sim/common/callback.c
+++ b/sim/common/callback.c
@@ -58,15 +58,6 @@ extern CB_TARGET_DEFS_MAP cb_init_syscall_map[];
extern CB_TARGET_DEFS_MAP cb_init_errno_map[];
extern CB_TARGET_DEFS_MAP cb_init_open_map[];
-/* Set the callback copy of errno from what we see now. */
-
-static int
-wrap (host_callback *p, int val)
-{
- p->last_errno = errno;
- return val;
-}
-
/* Make sure the FD provided is ok. If not, return non-zero
and set errno. */
@@ -143,7 +134,8 @@ os_close (host_callback *p, int fd)
return 0;
}
- result = wrap (p, close (fdmap (p, fd)));
+ result = close (fdmap (p, fd));
+ p->last_errno = errno;
}
p->fd_buddy[fd] = -1;
@@ -207,8 +199,9 @@ os_isatty (host_callback *p, int fd)
result = fdbad (p, fd);
if (result)
return result;
- result = wrap (p, isatty (fdmap (p, fd)));
+ result = isatty (fdmap (p, fd));
+ p->last_errno = errno;
return result;
}
@@ -220,7 +213,9 @@ os_lseek (host_callback *p, int fd, long off, int way)
result = fdbad (p, fd);
if (result)
return result;
- result = wrap (p, lseek (fdmap (p, fd), off, way));
+
+ result = lseek (fdmap (p, fd), off, way);
+ p->last_errno = errno;
return result;
}
@@ -296,14 +291,19 @@ os_read (host_callback *p, int fd, char *buf, int len)
return len;
}
- result = wrap (p, read (fdmap (p, fd), buf, len));
+ result = read (fdmap (p, fd), buf, len);
+ p->last_errno = errno;
return result;
}
static int
os_read_stdin (host_callback *p, char *buf, int len)
{
- return wrap (p, read (0, buf, len));
+ int result;
+
+ result = read (0, buf, len);
+ p->last_errno = errno;
+ return result;
}
static int
@@ -362,7 +362,8 @@ os_write (host_callback *p, int fd, const char *buf, int len)
switch (real_fd)
{
default:
- result = wrap (p, write (real_fd, buf, len));
+ result = write (real_fd, buf, len);
+ p->last_errno = errno;
break;
case 1:
result = p->write_stdout (p, buf, len);
@@ -401,42 +402,64 @@ os_flush_stderr (host_callback *p ATTRIBUTE_UNUSED)
static int
os_rename (host_callback *p, const char *f1, const char *f2)
{
- return wrap (p, rename (f1, f2));
+ int result;
+
+ result = rename (f1, f2);
+ p->last_errno = errno;
+ return result;
}
static int
os_system (host_callback *p, const char *s)
{
- return wrap (p, system (s));
+ int result;
+
+ result = system (s);
+ p->last_errno = errno;
+ return result;
}
static long
os_time (host_callback *p, long *t)
{
- return wrap (p, time (t));
+ long result;
+
+ result = time (t);
+ p->last_errno = errno;
+ return result;
}
static int
os_unlink (host_callback *p, const char *f1)
{
- return wrap (p, unlink (f1));
+ int result;
+
+ result = unlink (f1);
+ p->last_errno = errno;
+ return result;
}
static int
os_stat (host_callback *p, const char *file, struct stat *buf)
{
+ int result;
+
/* ??? There is an issue of when to translate to the target layout.
One could do that inside this function, or one could have the
caller do it. It's more flexible to let the caller do it, though
I'm not sure the flexibility will ever be useful. */
- return wrap (p, stat (file, buf));
+ result = stat (file, buf);
+ p->last_errno = errno;
+ return result;
}
static int
os_fstat (host_callback *p, int fd, struct stat *buf)
{
+ int result;
+
if (fdbad (p, fd))
return -1;
@@ -475,18 +498,24 @@ os_fstat (host_callback *p, int fd, struct stat *buf)
One could do that inside this function, or one could have the
caller do it. It's more flexible to let the caller do it, though
I'm not sure the flexibility will ever be useful. */
- return wrap (p, fstat (fdmap (p, fd), buf));
+ result = fstat (fdmap (p, fd), buf);
+ p->last_errno = errno;
+ return result;
}
static int
os_lstat (host_callback *p, const char *file, struct stat *buf)
{
+ int result;
+
/* NOTE: hpn/2004-12-12: Same issue here as with os_fstat. */
#ifdef HAVE_LSTAT
- return wrap (p, lstat (file, buf));
+ result = lstat (file, buf);
#else
- return wrap (p, stat (file, buf));
+ result = stat (file, buf);
#endif
+ p->last_errno = errno;
+ return result;
}
static int
@@ -503,7 +532,8 @@ os_ftruncate (host_callback *p, int fd, long len)
if (result)
return result;
#ifdef HAVE_FTRUNCATE
- result = wrap (p, ftruncate (fdmap (p, fd), len));
+ result = ftruncate (fdmap (p, fd), len);
+ p->last_errno = errno;
#else
p->last_errno = EINVAL;
result = -1;
@@ -515,7 +545,11 @@ static int
os_truncate (host_callback *p, const char *file, long len)
{
#ifdef HAVE_TRUNCATE
- return wrap (p, truncate (file, len));
+ int result;
+
+ result = truncate (file, len);
+ p->last_errno = errno;
+ return result;
#else
p->last_errno = EINVAL;
return -1;
--
2.30.2
next prev parent reply other threads:[~2021-04-24 18:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-24 18:41 [PATCH 1/6] gdb: callback: always include necessary headers Mike Frysinger via Gdb-patches
2021-04-24 18:41 ` [PATCH 2/6] gdb: callback: use ATTRIBUTE_NORETURN Mike Frysinger via Gdb-patches
2021-04-24 18:41 ` [PATCH 3/6] gdb: callback: inline PTR define Mike Frysinger via Gdb-patches
2021-04-24 18:41 ` Mike Frysinger via Gdb-patches [this message]
2021-04-24 18:41 ` [PATCH 5/6] sim: callback: convert time interface to 64-bit Mike Frysinger via Gdb-patches
2021-04-24 21:11 ` Tom Tromey
2021-04-24 22:36 ` Mike Frysinger via Gdb-patches
2021-05-14 5:39 ` [PATCH 5/6 v2] " Mike Frysinger via Gdb-patches
2021-05-14 14:00 ` Tom Tromey
2021-04-24 18:41 ` [PATCH 6/6] sim: callback: convert FS interfaces " Mike Frysinger via Gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210424184144.23736-4-vapier@gentoo.org \
--to=gdb-patches@sourceware.org \
--cc=vapier@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox