Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Jul 2001 16:51:22 +0400 (MSD)
From:      "Eugene L. Vorokov" <vel@bugz.infotecs.ru>
To:        freebsd-hackers@freebsd.org
Subject:   kernel panic when trying to use init's address space
Message-ID:  <200107051251.f65CpMp03726@bugz.infotecs.ru>

next in thread | raw e-mail | index | archive | help
Hello,

Some time ago I was asking about I/O in kernel mode when I don't have
struct proc to use syscalls. Actually I just wanted my kld to read it's
config file on load. Terry told me it's tricky, and I was thinking
about possible workarounds. I decided to try the following: look for
some process, get it's struct proc, allocate memory in it's address
space using mmap() syscall and then use open() and read() syscalls,
passing that struct proc to them. I first decided to look for init
process for this, since it always exists. So it looked like that:

 struct proc *p; register_t save; char *buf;
 struct mmap_args mem; int res;

 for (p = allproc.lh_first;
      p && (strcmp(p->p_comm, "init"));
      p = p->p_list.le_next);
 if (!p)
  return -1;
 save = p->p_retval[0];
 mem.addr = NULL;
 mem.len = size;   
 mem.prot = PROT_READ | PROT_WRITE;
 mem.flags = MAP_ANON;
 mem.fd = -1;
 mem.pad = 0;
 mem.pos = 0;       
 res = mmap(p, &mem);
 if (res)
  {
   p->p_retval[0] = save;
   return -1;
  }
 buf = (char *)p->p_retval[0];
 p->p_retval[0] = save;
 *buf = 0; 

However at this point kernel panics with page fault. I really don't
understand why could it be ...

Of course, I've found another workaround. I recalled that kldload
program is still active when my module loads, so I started looking
for it instead of init. It works just fine, I'm able to allocate
memory, use it and finally read my config file. But I'm curious,
why doesn't it work with init ? What's so special in init from this
point of view ?

Regards,
Eugene


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200107051251.f65CpMp03726>