Subject: Re: kernel->userland r/o page mapping
To: None <tech-kern@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 03/08/2007 10:51:44
> If init_main.c allocated a wired kernel physical page and mapped it
> in init(8)'s virtual space as a wired, read-only, inheritable page,
> how would userland reliably know at which address the page was mapped
> to, without a new syscall?  Perhaps throuh sysctl?

That'd work.

> Or if a specific address had to be decided on, would there be an
> arch-independent address that would suit this?

I can't see how there could be, when we support at least two different
pointer sizes.

> Would using "page 0" for this be out of the question?

I hope so!

> An alternative would possibly be a new device, say krtm(4) with only
> mmap support,

That'd work too.

Another alternative would be for the kernel to stuff the address in a
register before jumping to the entry point when starting a process.
Userland would normally then stash the pointer in a global variable
(presumably libc-private) in crt0.  This would save syscalls, but
requires a system rebuild to work at all, whereas the syscall-based
methods can be deployed much mroe incrementally.  The kernel could also
stuff the address into an environment variable, though that feels ugly
and fragile.

> I could see various users of this such as to access the current time
> faster.

That's the canonical use.  There are subtleties, such as dealing with
the difficulty many arches have reading something as large as the time
atomically.  I'm not sure what else it would be good for.

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B