Date: Thu, 27 Oct 2011 12:20:48 +0300 From: Kostik Belousov <kostikbel@gmail.com> To: Daniel Grech <dgre090@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: Kernel Space Memory Allocation Message-ID: <20111027092048.GK50300@deviant.kiev.zoral.com.ua> In-Reply-To: <CAG167sYaz3=Qvv0YYP7YvSkgm2HKkdP-XDu=HBUMv8TV1QUd5A@mail.gmail.com> References: <CAG167sYaz3=Qvv0YYP7YvSkgm2HKkdP-XDu=HBUMv8TV1QUd5A@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--te1vED83xZIPpfwV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Oct 27, 2011 at 10:31:43AM +0200, Daniel Grech wrote: > Hi, >=20 > I am allocating memory from a device driver in the kernel and passing it = on > to another driver. In the other driver it is neccessary for me to determi= ne > whether the address passed is from user space or kernel space as this dri= ver > can also be called from user space. I am currently using the following ch= eck > to determine if the address is in kernel space or userspace : >=20 > if ( ( (char *) VM_MIN_KERNEL_ADDRESS <=3D address) && (address <=3D (ch= ar *) > VM_MAX_KERNEL_ADDRESS) ) > { > KERNEL SPACE > } > else > { > USER SPACE > } >=20 > However, this does not always work. Sometimes although I allocate memory = in > the kernel using the malloc macro, this returns an address which is not in > the above range. Is there any workaround for this problem? >=20 > Thanks in advance for your help. Generally, you cannot determine the ownership of the address by its value. There are architectures that use separate kernel/user address spaces, e.g. Even for i386, there were a patch that switched page tables on the kernel entry, allowing the kernel to use whole 4GB of the address space. The proper way to do what you want is to supply explicit indicator of the address space referenced by the address. Read uio(9), in particular, look at the uio_seg. --te1vED83xZIPpfwV Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iEYEARECAAYFAk6pInAACgkQC3+MBN1Mb4jVpACg0yW/xfdT/fqc4rIZ6ESf5W32 4jkAoKwHoqoJdUuAJdXJS0XXN/Uu+e+g =FcZZ -----END PGP SIGNATURE----- --te1vED83xZIPpfwV--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111027092048.GK50300>