On 7/4/07, Robert Watson <[EMAIL PROTECTED]> 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
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to