gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] Some Confirmation Of Recent Bug Fixes


From: Christoph Schlegel
Subject: Re: [Gm2] Some Confirmation Of Recent Bug Fixes
Date: Wed, 29 Sep 2004 21:01:42 +0200
User-agent: Mozilla Thunderbird 0.8 (X11/20040913)

Gaius Mulley wrote:

[snip]

yes, thanks for asking about it as I forgot to cvs add this file.
Here is the start of SYSTEM.c - which needs the rest of the system
calls to be initialized. It would be great if this could be done
during configure (or perhaps during the library build) by a script
(python?) reading the sys/syscall.h. Then we need to modify the
gm2 front end to automatically include the appropriate search path
and include SYSTEM.o during linking.

I don't think it's a good idea to use Python here. Modula-2 is a
language for systems programming and I do not want to get a
Python-interpreter up and running before my Modula-2 compiler
can be built. Python is a nice language but in my case I need
a compiler which runs in a minimum environment (eg cross-compile
a small NetBSD-kernel plus basic utilities and GCC: nothing else).

Gaius

---------------------------
#include <sys/syscall.h>
#include <stdarg.h>
#include <errno.h>

#if !defined(TRUE)
#   define TRUE (1==1)
#endif

#if !defined(FALSE)
#   define FALSE (1==0)
#endif

extern int read (int, void *, int);
extern int write (int, void *, int);

static int (*syscalls[200])();
static int initialized = 0;

int mywrite (int fd, void *buf, int len)
{
  return write (fd, buf, len);
}

int
SYSTEM_UNIXCALL (int syscall, int *r0, int *r1, ...)
{
  va_list ap;
  int p1, p2, p3;

  if (! initialized)
    _M2_SYSTEM_init();

  va_start (ap, r1);
  p1 = va_arg (ap, int);
  p2 = va_arg (ap, int);
  p3 = va_arg (ap, int);
  *r0 = (*syscalls[syscall]) (p1, p2, p3);
  va_end (ap);
  return (*r0) >= 0;
}

/*
 *  UNIXFORK - returns TRUE if successful and pid is set to the son pid
 *             if the parent is returning. If the child is returning pid=0.
 *             UNIXFORK returns FALSE if an error occurs and errno is held in 
pid.
 */

int
SYSTEM_UNIXFORK (unsigned int *pid)
{
  int p = fork();

  if (p == -1) {
    *pid = errno;
    return FALSE;
  }
  *pid = p;

  return TRUE;
}

_M2_SYSTEM_init ()
{
  syscalls[__NR_write] = (void *)mywrite;
  syscalls[__NR_read]  = (void *)read;
  initialized = 1;
}

_______________________________________________
gm2 mailing list
address@hidden
http://floppsie.comp.glam.ac.uk/mailman/listinfo/gm2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]