This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
patch for ppc sim to fix open()
- To: gdb-patches at sources dot redhat dot com
- Subject: patch for ppc sim to fix open()
- From: Geoff Keating <geoffk at geoffk dot org>
- Date: Mon, 15 Jan 2001 15:29:24 -0800
- Reply-to: Geoff Keating <geoffk at redhat dot com>
This makes the sim's emulation of the open() syscall match NetBSD,
even on hosts where the constants are different. I wanted this so
that Perennial tests could create temporary files.
(It's also dangerous to call open() with random flag values.)
--
- Geoffrey Keating <geoffk@geoffk.org>
===File ~/patches/cygnus/sim-ppcopen.patch==================
2000-12-29 Geoffrey Keating <geoffk@redhat.com>
* emul_netbsd.c (do_open): Translate the flag parameter to the
open syscall to the numbers supported by the host.
Index: emul_netbsd.c
===================================================================
RCS file: /cvs/cvsfiles/devo/sim/ppc/emul_netbsd.c,v
retrieving revision 1.30
diff -u -p -r1.30 emul_netbsd.c
--- emul_netbsd.c 2000/03/02 09:22:28 1.30
+++ emul_netbsd.c 2001/01/09 22:51:06
@@ -386,6 +386,7 @@ do_open(os_emul_data *emul,
char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
int flags = (int)cpu_registers(processor)->gpr[arg0+1];
int mode = (int)cpu_registers(processor)->gpr[arg0+2];
+ int hostflags;
int status;
if (WITH_TRACE && ppc_trace[trace_os_emul])
@@ -393,8 +394,25 @@ do_open(os_emul_data *emul,
SYS(open);
+ /* Do some translation on 'flags' to match it to the host's version. */
+ /* These flag values were taken from the NetBSD 1.4 header files. */
+ if ((flags & 3) == 0)
+ hostflags = O_RDONLY;
+ else if ((flags & 3) == 1)
+ hostflags = O_WRONLY;
+ else
+ hostflags = O_RDWR;
+ if (flags & 0x00000008)
+ hostflags |= O_APPEND;
+ if (flags & 0x00000200)
+ hostflags |= O_CREAT;
+ if (flags & 0x00000400)
+ hostflags |= O_TRUNC;
+ if (flags & 0x00000800)
+ hostflags |= O_EXCL;
+
/* Can't combine these statements, cuz open sets errno. */
- status = open(path, flags, mode);
+ status = open(path, hostflags, mode);
emul_write_status(processor, status, errno);
}
============================================================