* [PATCH 1/3] sim: callback: add a getpid interface
@ 2021-06-21 3:55 Mike Frysinger
2021-06-21 3:55 ` [PATCH 2/3] sim: callback: generate signal map Mike Frysinger
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Mike Frysinger @ 2021-06-21 3:55 UTC (permalink / raw)
To: gdb-patches
Rather than hit the OS interface directly, use the existing callback
layer so the instantiator can decide behavior.
---
include/sim/callback.h | 1 +
sim/common/callback.c | 13 +++++++++++++
sim/common/syscall.c | 3 ++-
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/include/sim/callback.h b/include/sim/callback.h
index 4c162bc145ea..a6c536b1be1c 100644
--- a/include/sim/callback.h
+++ b/include/sim/callback.h
@@ -91,6 +91,7 @@ struct host_callback_struct
int (*to_lstat) (host_callback *, const char *, struct stat *);
int (*ftruncate) (host_callback *, int, int64_t);
int (*truncate) (host_callback *, const char *, int64_t);
+ int (*getpid) (host_callback *);
int (*pipe) (host_callback *, int *);
/* Called by the framework when a read call has emptied a pipe buffer. */
diff --git a/sim/common/callback.c b/sim/common/callback.c
index f2587a452540..071e7b149b97 100644
--- a/sim/common/callback.c
+++ b/sim/common/callback.c
@@ -556,6 +556,17 @@ os_truncate (host_callback *p, const char *file, int64_t len)
#endif
}
+static int
+os_getpid (host_callback *p)
+{
+ int result;
+
+ result = getpid ();
+ /* POSIX says getpid always succeeds. */
+ p->last_errno = 0;
+ return result;
+}
+
static int
os_pipe (host_callback *p, int *filedes)
{
@@ -737,6 +748,8 @@ host_callback default_callback =
os_ftruncate,
os_truncate,
+ os_getpid,
+
os_pipe,
os_pipe_empty,
os_pipe_nonempty,
diff --git a/sim/common/syscall.c b/sim/common/syscall.c
index 4e76d2008a30..7ef34b95e9cf 100644
--- a/sim/common/syscall.c
+++ b/sim/common/syscall.c
@@ -579,7 +579,8 @@ cb_syscall (host_callback *cb, CB_SYSCALL *sc)
break;
case CB_SYS_getpid:
- result = getpid ();
+ /* POSIX says getpid always succeeds. */
+ result = (*cb->getpid) (cb);
break;
case CB_SYS_time :
--
2.31.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] sim: callback: generate signal map
2021-06-21 3:55 [PATCH 1/3] sim: callback: add a getpid interface Mike Frysinger
@ 2021-06-21 3:55 ` Mike Frysinger
2021-06-21 3:55 ` [PATCH 3/3] sim: callback: add missing cb_target_to_host_signal Mike Frysinger
2021-06-21 22:58 ` [PATCH 1/3] sim: callback: add a getpid interface Christian Biesinger
2 siblings, 0 replies; 5+ messages in thread
From: Mike Frysinger @ 2021-06-21 3:55 UTC (permalink / raw)
To: gdb-patches
We've been generating the syscall/errno/open maps, but not the signal
map, even though we've been including them in the source constants.
---
sim/common/callback.c | 3 +++
sim/common/gentmap.c | 24 ++++++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/sim/common/callback.c b/sim/common/callback.c
index 071e7b149b97..aca0112853c4 100644
--- a/sim/common/callback.c
+++ b/sim/common/callback.c
@@ -32,6 +32,7 @@
#include <limits.h>
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -56,6 +57,7 @@ void sim_cb_eprintf (host_callback *, const char *, ...);
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_signal_map[];
extern CB_TARGET_DEFS_MAP cb_init_open_map[];
/* Make sure the FD provided is ok. If not, return non-zero
@@ -676,6 +678,7 @@ os_init (host_callback *p)
p->syscall_map = cb_init_syscall_map;
p->errno_map = cb_init_errno_map;
+ p->signal_map = cb_init_signal_map;
p->open_map = cb_init_open_map;
return 1;
diff --git a/sim/common/gentmap.c b/sim/common/gentmap.c
index 254ec3f11195..f1f1bc2c03f3 100644
--- a/sim/common/gentmap.c
+++ b/sim/common/gentmap.c
@@ -23,6 +23,13 @@ static struct tdefs errno_tdefs[] = {
{ 0, 0 }
};
+static struct tdefs signal_tdefs[] = {
+#define signal_defs
+#include "nltvals.def"
+#undef signal_defs
+ { 0, 0 }
+};
+
static struct tdefs open_tdefs[] = {
#define open_defs
#include "nltvals.def"
@@ -51,6 +58,11 @@ gen_targ_vals_h (void)
printf ("#define TARGET_%s %d\n", t->symbol, t->value);
printf ("\n");
+ printf ("/* signal values */\n");
+ for (t = &signal_tdefs[0]; t->symbol; ++t)
+ printf ("#define TARGET_%s %d\n", t->symbol, t->value);
+ printf ("\n");
+
printf ("/* open flag values */\n");
for (t = &open_tdefs[0]; t->symbol; ++t)
printf ("#define TARGET_%s 0x%x\n", t->symbol, t->value);
@@ -70,6 +82,7 @@ gen_targ_map_c (void)
printf ("#include \"defs.h\"\n");
printf ("#include <errno.h>\n");
printf ("#include <fcntl.h>\n");
+ printf ("#include <signal.h>\n");
printf ("#include \"ansidecl.h\"\n");
printf ("#include \"sim/callback.h\"\n");
printf ("#include \"targ-vals.h\"\n");
@@ -98,6 +111,17 @@ gen_targ_map_c (void)
printf (" { 0, 0, 0 }\n");
printf ("};\n\n");
+ printf ("/* signals mapping table */\n");
+ printf ("CB_TARGET_DEFS_MAP cb_init_signal_map[] = {\n");
+ for (t = &signal_tdefs[0]; t->symbol; ++t)
+ {
+ printf ("#ifdef %s\n", t->symbol);
+ printf (" { \"%s\", %s, TARGET_%s },\n", t->symbol, t->symbol, t->symbol);
+ printf ("#endif\n");
+ }
+ printf (" { 0, -1, -1 }\n");
+ printf ("};\n\n");
+
printf ("/* open flags mapping table */\n");
printf ("CB_TARGET_DEFS_MAP cb_init_open_map[] = {\n");
for (t = &open_tdefs[0]; t->symbol; ++t)
--
2.31.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] sim: callback: add missing cb_target_to_host_signal
2021-06-21 3:55 [PATCH 1/3] sim: callback: add a getpid interface Mike Frysinger
2021-06-21 3:55 ` [PATCH 2/3] sim: callback: generate signal map Mike Frysinger
@ 2021-06-21 3:55 ` Mike Frysinger
2021-06-21 22:58 ` [PATCH 1/3] sim: callback: add a getpid interface Christian Biesinger
2 siblings, 0 replies; 5+ messages in thread
From: Mike Frysinger @ 2021-06-21 3:55 UTC (permalink / raw)
To: gdb-patches
There's been a prototype for this forever, but the implementation was
missing. Probably because there weren't any callers, but we'll start
using it to implement the kill function.
---
sim/common/callback.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/sim/common/callback.c b/sim/common/callback.c
index aca0112853c4..06d76b477245 100644
--- a/sim/common/callback.c
+++ b/sim/common/callback.c
@@ -927,6 +927,19 @@ cb_target_to_host_open (host_callback *cb, int target_val)
return host_val;
}
+/* Translate the target's version of a signal number to the host's.
+ This isn't actually the host's version, rather a canonical form.
+ ??? Perhaps this should be renamed to ..._canon_signal. */
+
+int
+cb_target_to_host_signal (host_callback *cb, int target_val)
+{
+ const CB_TARGET_DEFS_MAP *m =
+ cb_target_map_entry (cb->signal_map, target_val);
+
+ return m ? m->host_val : -1;
+}
+
/* Utility for e.g. cb_host_to_target_stat to store values in the target's
stat struct.
--
2.31.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] sim: callback: add a getpid interface
2021-06-21 3:55 [PATCH 1/3] sim: callback: add a getpid interface Mike Frysinger
2021-06-21 3:55 ` [PATCH 2/3] sim: callback: generate signal map Mike Frysinger
2021-06-21 3:55 ` [PATCH 3/3] sim: callback: add missing cb_target_to_host_signal Mike Frysinger
@ 2021-06-21 22:58 ` Christian Biesinger
2021-06-21 23:50 ` Mike Frysinger
2 siblings, 1 reply; 5+ messages in thread
From: Christian Biesinger @ 2021-06-21 22:58 UTC (permalink / raw)
To: Mike Frysinger; +Cc: gdb-patches
On Sun, Jun 20, 2021 at 10:55 PM Mike Frysinger via Gdb-patches
<gdb-patches@sourceware.org> wrote:
> --- a/sim/common/callback.c
> +++ b/sim/common/callback.c
> @@ -556,6 +556,17 @@ os_truncate (host_callback *p, const char *file, int64_t len)
> #endif
> }
>
> +static int
> +os_getpid (host_callback *p)
> +{
> + int result;
> +
> + result = getpid ();
sim is C11, right? Why not write this as "int result = getpid ();"?
Christian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] sim: callback: add a getpid interface
2021-06-21 22:58 ` [PATCH 1/3] sim: callback: add a getpid interface Christian Biesinger
@ 2021-06-21 23:50 ` Mike Frysinger
0 siblings, 0 replies; 5+ messages in thread
From: Mike Frysinger @ 2021-06-21 23:50 UTC (permalink / raw)
To: Christian Biesinger; +Cc: gdb-patches
On 21 Jun 2021 17:58, Christian Biesinger wrote:
> On Sun, Jun 20, 2021 at 10:55 PM Mike Frysinger wrote:
> > --- a/sim/common/callback.c
> > +++ b/sim/common/callback.c
> > @@ -556,6 +556,17 @@ os_truncate (host_callback *p, const char *file, int64_t len)
> > #endif
> > }
> >
> > +static int
> > +os_getpid (host_callback *p)
> > +{
> > + int result;
> > +
> > + result = getpid ();
>
> sim is C11, right? Why not write this as "int result = getpid ();"?
just maintaining copy & paste style in this module, and because (iiuc), GNU
style wants a blank line after decls. so imo it looks nicer to have business
logic grouped together.
{
int result = getpid ();
p->last_errno = errno;
return result;
}
{
int result;
result = getpid ();
p->last_errno = errno;
return result;
}
-mike
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-06-21 23:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21 3:55 [PATCH 1/3] sim: callback: add a getpid interface Mike Frysinger
2021-06-21 3:55 ` [PATCH 2/3] sim: callback: generate signal map Mike Frysinger
2021-06-21 3:55 ` [PATCH 3/3] sim: callback: add missing cb_target_to_host_signal Mike Frysinger
2021-06-21 22:58 ` [PATCH 1/3] sim: callback: add a getpid interface Christian Biesinger
2021-06-21 23:50 ` Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).