[patch] sim/common/syscall.c: implement SYS_{argc,argn,argnlen}
Mike Frysinger
vapier@gentoo.org
Fri Feb 5 09:57:00 GMT 2010
some ports leverage the argc/argn/argnlen syscalls to get at argv[] rather
than the more complicated argv/argvlen syscalls. so add support for these to
the common code. not that it makes too much of a difference today since these
argv funcs are #if 0 pending something ...
-mike
2010-02-05 Mike Frysinger <vapier@gentoo.org>
* common/syscall.c (cb_syscall): Handle CB_SYS_argc, CB_SYS_argn,
and CB_SYS_argnlen.
RCS file: /cvs/src/src/sim/common/syscall.c,v
retrieving revision 1.16
diff -u -p -r1.16 syscall.c
--- sim/common/syscall.c 1 Jan 2010 10:03:27 -0000 1.16
+++ sim/common/syscall.c 5 Feb 2010 09:53:22 -0000
@@ -153,11 +153,13 @@ cb_syscall (cb, sc)
CB_SYSCALL *sc;
{
TWORD result = 0, errcode = 0;
+ int host_syscall;
if (sc->magic != CB_SYSCALL_MAGIC)
abort ();
- switch (cb_target_to_host_syscall (cb, sc->func))
+ host_syscall = cb_target_to_host_syscall (cb, sc->func);
+ switch (host_syscall)
{
#if 0 /* FIXME: wip */
case CB_SYS_argvlen :
@@ -248,6 +250,56 @@ cb_syscall (cb, sc)
sc->result2 = envc;
break;
}
+
+ /* Compute the number of arguments. */
+ case CB_SYS_argc :
+ /* Compute the length of a specific argument. */
+ case CB_SYS_argnlen :
+ /* Copy a specific argument. */
+ case CB_SYS_argn :
+ {
+ int argc, len;
+ const char **argv = cb->init_argv;
+
+ argc = 0;
+ if (argv)
+ {
+ for ( ; argv[argc]; ++argc)
+ continue;
+ }
+ if (host_syscall == CB_SYS_argc)
+ {
+ result = argc;
+ break;
+ }
+
+ if (sc->arg1 < argc)
+ {
+ TADDR tbuf = sc->arg2;
+ int written, len = strlen (argv[sc->arg1]);
+ if (host_syscall == CB_SYS_argnlen)
+ {
+ result = len;
+ break;
+ }
+
+ written = (*sc->write_mem) (cb, sc, tbuf, argv[sc->arg1], len + 1);
+ if (written != len)
+ {
+ result = -1;
+ errcode = EINVAL;
+ goto FinishSyscall;
+ }
+ result = sc->arg2;
+ }
+ else
+ {
+ result = -1;
+ errcode = EINVAL;
+ goto FinishSyscall;
+ }
+ }
+ break;
#endif /* wip */
case CB_SYS_exit :
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20100205/68b00e95/attachment.sig>
More information about the Gdb-patches
mailing list