From owner-freebsd-hackers Thu Jul 5 5:58:37 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by hub.freebsd.org (Postfix) with ESMTP id 49DD937B403 for ; Thu, 5 Jul 2001 05:58:33 -0700 (PDT) (envelope-from ticso@mail.cicely.de) Received: from mail.cicely.de (cicely20 [10.1.1.22]) by srv1.cosmo-project.de (8.11.0/8.11.0) with ESMTP id f65CwUV05154; Thu, 5 Jul 2001 14:58:31 +0200 (CEST) Received: (from ticso@localhost) by mail.cicely.de (8.11.0/8.11.0) id f65CxIi08455; Thu, 5 Jul 2001 14:59:18 +0200 (CEST) Date: Thu, 5 Jul 2001 14:59:17 +0200 From: Bernd Walter To: "Eugene L. Vorokov" Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: kernel panic when trying to use init's address space Message-ID: <20010705145917.A7717@cicely20.cicely.de> References: <200107051251.f65CpMp03726@bugz.infotecs.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200107051251.f65CpMp03726@bugz.infotecs.ru>; from vel@bugz.infotecs.ru on Thu, Jul 05, 2001 at 04:51:22PM +0400 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 On Thu, Jul 05, 2001 at 04:51:22PM +0400, Eugene L. Vorokov wrote: > 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 yhou don't care whicvh process you can just do: struct proc *p = &proc0; > 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 ? You are mmaping into the address space for the process you use the struct proc from. As long as it's this programm that is curproc everything is fine. That means you are called from that process such in kldload or interrupted that proccess. What you need is to use the address space that is common to all proccess while working in kernel mode not into the proccess specific. I don't know if it is possible to mmap into that space. -- B.Walter COSMO-Project http://www.cosmo-project.de ticso@cicely.de Usergroup info@cosmo-project.de To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message