Subject: Re: COMPAT_LINUX/powerpc: mmap'ing dynamic libraries
To: None <tech-kern@netbsd.org>
From: Emmanuel Dreyfus <p99dreyf@criens.u-psud.fr>
List: tech-kern
Date: 01/08/2001 23:08:37
> mmap could be the problem here. I would try to see if a statically linked
> mmap test works as expected.

I did this, but I omitted it in my last post. Sorry about it. Here is
the test code:
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>

int main (int argc, char** argv) {
  int fd;
  char* ptr;
  
  fd=open("/etc/passwd",O_RDONLY,0);
  if (fd<0) {printf("open failed\n"); exit(-1);}

  (void*)ptr=mmap(NULL,512,PROT_READ,MAP_PRIVATE|MAP_FILE,fd,0);
  if (ptr==NULL) {perror("mmap failed"); exit(-1);}

  printf("%c-%c-%c-%c\n",ptr[0],ptr[1],ptr[2],ptr[3]);
  
  return 0;
}

And here is the ktrace output:
  3718 ktrace   EMUL  "netbsd"
  3718 ktrace   RET   ktrace 0
  3718 ktrace   CALL  execve(0x7fffeac3,0x7fffea18,0x7fffea20)
  3718 ktrace   NAMI  "./mmap"
  3718 mmap     EMUL  "linux"
  3718 mmap     RET   olduname -1 errno -2 No such file or directory
  3718 mmap     CALL  personality(0)
  3718 mmap     RET   personality 0
  3718 mmap     CALL  geteuid
  3718 mmap     RET   geteuid 500/0x1f4
  3718 mmap     CALL  getuid
  3718 mmap     RET   getuid 500/0x1f4
  3718 mmap     CALL  getegid
  3718 mmap     RET   getegid 500/0x1f4
  3718 mmap     CALL  getgid
  3718 mmap     RET   getgid 500/0x1f4
  3718 mmap     CALL  open(0x1830b48,0,0)
  3718 mmap     NAMI  "/emul/linux/etc/passwd"
  3718 mmap     NAMI  "/etc/passwd"
  3718 mmap     RET   open 3
  3718 mmap     CALL  mmap(0,0x200,0x1,0x2,0x3,0,0x1830000,0x1870000)
  3718 mmap     RET   mmap 1099366400/0x41870000
  3718 mmap     PSIG  SIGSEGV SIG_DFL
  3718 mmap     NAMI  "mmap.core"

Is this 8 argument mmap() normal? mmap() has only 6 argument. I can
recognise my 6 parameters, but where are the 0x1830000, and 0x1870000
parameters comming from? 

If I compile a NetBSD version of the program, it works, and I have this:

  3724 mmap     NAMI  "/etc/passwd"
  3724 mmap     RET   open 3
  3724 mmap     CALL  mmap(0,0x200,0x1,0x2,0x3,0,0,0)
  3724 mmap     RET   mmap 1099898880/0x418f2000

Again 8 arguments. I'm totally confused.

> >   171 arg.dyn  RET   olduname -1 errno -2 No such file or directory
[ instead of execve JUSTRETURN ]

> Hmm, new syscall reorg related lossage?

I just had an idea: in the i386 version, there is a linux_syssigreturn()
function that returns EJUSTRETURN in linux_machdep.c. In the powerpc
version, I just erased everyhting in the function (I plan to work on
signal when I'll be done with dynamic libraries), and the function
currently returns 0. Could this be the problem?

-- 
Emmanuel Dreyfus.  
JavaScript est encapsule dans HTML, qui encapsulait
deja pas mal d'autres conneries comme ca.
p99dreyf@criens.u-psud.fr