Date: Wed, 4 Jul 2007 11:00:54 +0200 From: "Nicolas Cormier" <n.cormier@gmail.com> To: "Robert Watson" <rwatson@freebsd.org> Cc: freebsd-hackers@freebsd.org Subject: Re: p_vmspace in syscall Message-ID: <c4630b800707040200n4a6de4f5j2008f60fefb149e6@mail.gmail.com> In-Reply-To: <20070704091349.T42421@fledge.watson.org> References: <c4630b800707020954s4aa0be68t2d5f3eb864f2dda5@mail.gmail.com> <20070704091349.T42421@fledge.watson.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 7/4/07, Robert Watson <rwatson@freebsd.org> wrote: > > On Mon, 2 Jul 2007, Nicolas Cormier wrote: > > > I am trying to map some data allocated in kernel to a user process (via a > > syscall). I need the proc's vmspace, but the value of p_vmspace of the input > > proc argument is NULL ... How can I get a valid vmspace ? > > When operating in a system call, the 'td' argument to the system call function > is the current thread pointer. You can follow td->td_proc to get to the > current process (and therefore, its address space). In general, I prefer > mapping user pages into kernel instead of kernel pages into user space, as it > reduces the chances of leakage of kernel data to user space, and there are > some useful primitives for making this easier. For example, take a look at > the sf_buf infrastructure used for things like socket zero-copy send, which > manages a temporary kernel mapping for a page. > Yes Roman told me in private that I'm wrong with the first argument, I thought that it was a proc*... For my module I try to create a simple interface of a network allocator: User code should look like this: unsigned id; void* data = netmalloc(host, size, &id); memcpy(data, "toto", sizeof("toto"); netdetach(data); and later in another process: void* data = netattach(host, id); ... netfree(data); netmalloc syscall does something like that: - query distant host to allocate size - receive an id from distant host - malloc in kernel size - map the buffer to user process (*) netdetach syscall: - send data to distant host netattach syscall: - get data from host - malloc in kernel size - map the buffer to user process (*) * I already watch the function vm_pgmoveco (http://fxr.watson.org/fxr/source/kern/kern_subr.c?v=RELENG62#L78) I used pgmoveco as follow: vm_map_t mapa = &proc->p_vmspace->vm_map, size = round_page(size); void* data = malloc(size, M_NETMALLOC, M_WAITOK); vm_offset_t addr = vm_map_min(mapa); vm_map_find(mapa, NULL, 0, &addr, size, TRUE, VM_PROT_ALL, VM_PROT_ALL, MAP_NOFAULT); vm_pgmoveco(mapa, (vm_offset_t)data, addr); With this I have a panic with vm_page_insert, I am not sure to understand the reason of this panic. I can't have multiple virtual pages on the same physical page ? Thanks! -- Nicolas Cormier
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?c4630b800707040200n4a6de4f5j2008f60fefb149e6>