X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=sim%2Fcommon%2Fsyscall.c;h=18128c74930c7a3ad9256fedb33ce0ea982ea60e;hb=05e682e3be7e3d9d63ec358dcf8943fd200545cb;hp=45f063e02178bc1fb05a04d6472c722bdbc9a685;hpb=97f669eda91b587c590bb5d0bb185d63c126d7fe;p=deliverable%2Fbinutils-gdb.git diff --git a/sim/common/syscall.c b/sim/common/syscall.c index 45f063e021..18128c7493 100644 --- a/sim/common/syscall.c +++ b/sim/common/syscall.c @@ -1,12 +1,12 @@ /* Remote target system call support. - Copyright 1997, 1998, 2002, 2004 Free Software Foundation, Inc. + Copyright 1997-2020 Free Software Foundation, Inc. Contributed by Cygnus Solutions. This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with GAS; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + along with this program. If not, see . */ /* This interface isn't intended to be specific to any particular kind of remote (hardware, simulator, whatever). As such, support for it @@ -25,15 +24,11 @@ supported. */ #ifdef HAVE_CONFIG_H -#include "cconfig.h" +#include "config.h" #endif #include "ansidecl.h" #include "libiberty.h" -#ifdef ANSI_PROTOTYPES #include -#else -#include -#endif #include #ifdef HAVE_STDLIB_H #include @@ -80,13 +75,9 @@ char *simulator_sysroot = ""; /* Utility of cb_syscall to fetch a path name or other string from the target. The result is 0 for success or a host errno value. */ -static int -get_string (cb, sc, buf, buflen, addr) - host_callback *cb; - CB_SYSCALL *sc; - char *buf; - int buflen; - TADDR addr; +int +cb_get_string (host_callback *cb, CB_SYSCALL *sc, char *buf, int buflen, + TADDR addr) { char *p, *pend; @@ -97,7 +88,7 @@ get_string (cb, sc, buf, buflen, addr) path name along with the syscall request, and cache the file name somewhere (or otherwise tweak this as desired). */ unsigned int count = (*sc->read_mem) (cb, sc, addr, p, 1); - + if (count != 1) return EINVAL; if (*p == 0) @@ -115,17 +106,13 @@ get_string (cb, sc, buf, buflen, addr) If an error occurs, no buffer is left malloc'd. */ static int -get_path (cb, sc, addr, bufp) - host_callback *cb; - CB_SYSCALL *sc; - TADDR addr; - char **bufp; +get_path (host_callback *cb, CB_SYSCALL *sc, TADDR addr, char **bufp) { char *buf = xmalloc (MAX_PATH_LEN); int result; int sysroot_len = strlen (simulator_sysroot); - result = get_string (cb, sc, buf, MAX_PATH_LEN - sysroot_len, addr); + result = cb_get_string (cb, sc, buf, MAX_PATH_LEN - sysroot_len, addr); if (result == 0) { /* Prepend absolute paths with simulator_sysroot. Relative paths @@ -152,9 +139,7 @@ get_path (cb, sc, addr, bufp) /* Perform a system call on behalf of the target. */ CB_RC -cb_syscall (cb, sc) - host_callback *cb; - CB_SYSCALL *sc; +cb_syscall (host_callback *cb, CB_SYSCALL *sc) { TWORD result = 0, errcode = 0; @@ -255,7 +240,7 @@ cb_syscall (cb, sc) #endif /* wip */ case CB_SYS_exit : - /* Caller must catch and handle. */ + /* Caller must catch and handle; see sim_syscall as an example. */ break; case CB_SYS_open : @@ -296,7 +281,7 @@ cb_syscall (cb, sc) while (count > 0) { - if (fd == 0) + if (cb_is_stdin (cb, fd)) result = (int) (*cb->read_stdin) (cb, buf, (count < FILE_XFR_SIZE ? count : FILE_XFR_SIZE)); @@ -349,12 +334,12 @@ cb_syscall (cb, sc) errcode = EINVAL; goto FinishSyscall; } - if (fd == 1) + if (cb_is_stdout (cb, fd)) { result = (int) (*cb->write_stdout) (cb, buf, bytes_read); (*cb->flush_stdout) (cb); } - else if (fd == 2) + else if (cb_is_stderr (cb, fd)) { result = (int) (*cb->write_stderr) (cb, buf, bytes_read); (*cb->flush_stderr) (cb); @@ -470,7 +455,7 @@ cb_syscall (cb, sc) result = -1; goto FinishSyscall; } - result = (*cb->stat) (cb, path, &statbuf); + result = (*cb->to_stat) (cb, path, &statbuf); free (path); if (result < 0) goto ErrorFinish; @@ -503,7 +488,7 @@ cb_syscall (cb, sc) struct stat statbuf; TADDR addr = sc->arg2; - result = (*cb->fstat) (cb, sc->arg1, &statbuf); + result = (*cb->to_fstat) (cb, sc->arg1, &statbuf); if (result < 0) goto ErrorFinish; buflen = cb_host_to_target_stat (cb, NULL, NULL); @@ -541,7 +526,7 @@ cb_syscall (cb, sc) result = -1; goto FinishSyscall; } - result = (*cb->lstat) (cb, path, &statbuf); + result = (*cb->to_lstat) (cb, path, &statbuf); free (path); if (result < 0) goto ErrorFinish;