From owner-freebsd-hackers Thu Jul 5 5:37:41 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from bugz.infotecs.ru (bugz.infotecs.ru [195.210.139.22]) by hub.freebsd.org (Postfix) with ESMTP id 37DDA37B401 for ; Thu, 5 Jul 2001 05:37:34 -0700 (PDT) (envelope-from vel@bugz.infotecs.ru) Received: (from vel@localhost) by bugz.infotecs.ru (8.11.1/8.11.1) id f65CpMp03726 for freebsd-hackers@freebsd.org; Thu, 5 Jul 2001 16:51:22 +0400 (MSD) (envelope-from vel) From: "Eugene L. Vorokov" Message-Id: <200107051251.f65CpMp03726@bugz.infotecs.ru> Subject: kernel panic when trying to use init's address space To: freebsd-hackers@freebsd.org Date: Thu, 5 Jul 2001 16:51:22 +0400 (MSD) X-Mailer: ELM [version 2.4ME+ PL82 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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