Re: Address range returned by malloc
Re: Address range returned by malloc
- Subject: Re: Address range returned by malloc
- From: Terry Lambert <email@hidden>
- Date: Sat, 04 Oct 2008 13:16:37 -0700
On Oct 4, 2008, at 12:56 PM, Greg <email@hidden> wrote:
On Oct 4, 2008, at 3:29 PM, Terry Lambert wrote:
Kernel virtual address space for a 32 bit kernel is limited to 32
bits.
Pointers are NOT signed values, so do not store the returned
pointer into a signed integer, or you may truncate it to 31 bits
and overwrite/access something in lower memory than your allocation
actually occurred when you go to use it. This would be Bad(tm).
Thanks Terry, and I searched online and found that it appears that
Apple will continue to use a 32-bit kernel (I hope).
I'm aware that void* is unsigned, but I wasn't sure if converting
that to a signed type and then back again would lose information.
For example this program (with gcc -O0) displays "equal":
unsigned int a = 4294967295; // 2^32-1
int b = (int)a;
unsigned int c = (unsigned int)b;
printf("%s\n", a == c ? "equal" : "not equal");
So what's going on? It doesn't appear to lose any information here.
The short answer is that if you do pointer math on an address above 2G
in a signed it, it will subtract rather than add, and you will get the
wrong address. Don't do that.
The longer answer is that, as an architectural detail, Intel
processors expect high bits not current supported to be set instead of
cleared, so the compiler sign extends pointers on conversion from
integsr before assignment.
In both cases, you are getting luck because of the simplicity of your
example.
In any event, it doesn't matter if I say this because there are over
15,000 google hits on the information: google the terms: SnowLeopard
kernel 64bit.
You will be very unhappy if you use a 32 bit integer type to contain a
kernel pointer in SnowLeopard.
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden