Date: Tue, 30 Sep 2003 01:13:35 -0700 From: Terry Lambert <tlambert2@mindspring.com> To: earthman <earthman@inbox.ru> Cc: freebsd-hackers@freebsd.org Subject: Re: user malloc from kernel Message-ID: <3F793B2F.F5CB8416@mindspring.com> References: <16244.53594.942762.784390@canoe.dclg.ca> <3F759589.9070700@mindspring.com> <811112091.20030929172247@inbox.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
earthman wrote: > how to allocate some memory chunk > in user space memory from kernel code? > how to do it correctly? If your intent is to allocate a chunk of memory which is shared between your kernel and a single process in user space, the normal way of doing this is to allocate the memory to a device driver in the kernel, and then support mmap() on it to establish a user space mapping for the kernel allocated memory. In general, you must do this so that the memory is wired down in the kernel address space, so that if you attempt to access it in the kernel while the process you are interested in sharing with is swapped out, you do not segfault and trap-12 ("page not present") panic your kernel. If your intent is to share memory with every process in user space (e.g. similar to what some OS's use to implement zero system call gettimeofday() functions, etc.), then you want to allocate the memory in kernel space (still), make sure it's on a page boundary, and set the PG_G and PG_U bits on the page(s) in question. -- Terry
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3F793B2F.F5CB8416>