This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Committed: Fix mmix access function. Update comment on _exit return value


Nelson H. F. Beebe reported (thanks) in private email (please use
bugzilla) that the access function in the mmixware port didn't work,
even for the restricted cases that the source claimed would work.

About that magic value, I don't know what I was thinking; the
simulator has no support for it and off the top of my head I can't
figure out how it could be used sanely.  Either way, better keep it
simple and just use _open; it's not more restricted than what can be
done with a SYS_Fopen .. SYS_Fclose pair.

If you don't immediately see the problem (you'd have to look at the
TRAP3f macro definition ad finitum - or the gcc -E result), it's that
TMPFNO is 127, which is compared to the valid range 0..32, and as it
doesn't fit, access() will always yield EBADF.  All nicely optimized
away by gcc into a "errno = EBADF; return -1". :)

Also, I took the opportunity to update the comment about the simulator
not passing on the exit value from the simulated program.  It now does
(Prof. Knuth kindly agreed this'd be useful, years ago).
Unfortunately, there's the caveat described in the comment, just in
case people wonder why the dejagnu baseboard file (see dejagnu-1.4.4)
mmix-sim.exp "still" sets needs_status_wrapper.

PS. sourceware.org/newlib still refers to sources.redhat.com, the
obsolete name.

Committed after running the GCC test-suite.

	* libc/sys/mmixware/access.c (access): Do not try to use a magic
	file-handle and a direct syscall, just use _open.
	* libc/sys/mmixware/sys/syscall.h (TMPFNO): Remove this magic
	file-handle.

	* libc/sys/mmixware/_exit.c (_exit): Update comment about
	passing on the exit value.

Index: libc/sys/mmixware/access.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/mmixware/access.c,v
retrieving revision 1.3
diff -p -u -r1.3 access.c
--- libc/sys/mmixware/access.c	18 Nov 2001 23:47:59 -0000	1.3
+++ libc/sys/mmixware/access.c	10 Jun 2007 12:28:59 -0000
@@ -1,6 +1,6 @@
 /* access for MMIXware.

-   Copyright (C) 2001 Hans-Peter Nilsson
+   Copyright (C) 2001, 2007 Hans-Peter Nilsson

    Permission to use, copy, modify, and distribute this software is
    freely granted, provided that the above copyright notice, this notice
@@ -24,18 +24,17 @@ access (const char *fn, int flags)
      implementations.  Opening a directory as a file usually works, so
      let's try and open it and use the openability, regardless of what
      kind of test or file it is.  */
-  long ret;
+  int fd;

   /* We'll just assume that if we can open the file for reading, then it's
      Z-able, no matter what Z was.  */
-  ret = TRAP3f (SYS_Fopen, TMPFNO, fn, BinaryRead);
-  if (ret == 0)
+  fd = _open (fn, O_RDONLY);
+  if (fd >= 0)
     {
       /* Yes, this was readable.  As in other simulator access functions,
 	 we always return success in this case (though the others check
 	 for directory access).  */
-      TRAP1f (SYS_Fclose, TMPFNO);
-      return 0;
+      return _close (fd);
     }

   errno = EACCES;
Index: libc/sys/mmixware/sys/syscall.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/mmixware/sys/syscall.h,v
retrieving revision 1.4
diff -p -u -r1.4 syscall.h
--- libc/sys/mmixware/sys/syscall.h	10 Jul 2002 22:15:49 -0000	1.4
+++ libc/sys/mmixware/sys/syscall.h	10 Jun 2007 12:28:59 -0000
@@ -1,6 +1,6 @@
 /* syscall defines for MMIXware.

-   Copyright (C) 2001, 2002 Hans-Peter Nilsson
+   Copyright (C) 2001, 2002, 2007 Hans-Peter Nilsson

    Permission to use, copy, modify, and distribute this software is
    freely granted, provided that the above copyright notice, this notice
@@ -42,10 +42,6 @@ enum MMIX_filemode
    track of it.  A value of 0 denotes a free handle.  */
 extern unsigned char _MMIX_allocated_filehandle[N_MMIX_FILEHANDLES];

-/* We use this file-handle number as a temporary; not used by usual file
-   I/O.  */
-#define TMPFNO 127
-
 /* Simulator call with one argument.  Also used for zero-argument calls;
    pass a zero as ARG1.  Make the asm volatile so we can safely ignore the
    return-value and only get the benefit from the supposed side-effect

Index: libc/sys/mmixware/_exit.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/mmixware/_exit.c,v
retrieving revision 1.3
diff -p -u -r1.3 _exit.c
--- libc/sys/mmixware/_exit.c	18 Nov 2001 23:47:59 -0000	1.3
+++ libc/sys/mmixware/_exit.c	10 Jun 2007 12:28:59 -0000
@@ -18,9 +18,11 @@

 void _exit (int n)
 {
-  /* Unfortunately, the return status is not returned by Knuth's mmix
-     simulator, so it seems in effect ineffective.  We set it anyway;
-     there may be a purpose.  */
+  /* The return status is passed on at exit from the simulator by all
+     but the oldest versions of Knuth's mmixware simulator.  Beware,
+     "TRAP 0,0,0" is the instruction corresponding to (int32_t) 0 and
+     the value 0 in $255 is common enough that a program crash jumping
+     to e.g. uninitialized memory will look like "exit (0)".  */
   __asm__ ("SET $255,%0\n\tTRAP 0,0,0"
 	   : /* No outputs.  */
 	   : "r" (n)

brgds, H-P


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]