Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
-mno-red-zone for 64-bit drivers?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

-mno-red-zone for 64-bit drivers?



The AMD64 Application Binary Interface specifies that the 128-byte
area below register %rsp (the 64-bit stack pointer) is considered
reserved and may not be used by signal or interrupt handlers.  This is
described on page 16, section 3.2.2, and in figure 3.3:

  http://www.x86-64.org/documentation.html

However in section A.2.2 on page 124, it says that the Linux kernel
doesn't honor the red zone, and so one must give GCC the -mno-red-zone
flag.

What about Mac OS X?  Does OS X kernel code need -mno-red-zone?  If
the red zone is to be enabled, could some of Apple's kernel code be
failing to honor it?

I've been investigating a kernel panic that has only my driver and
10.6.1 - I have installed no other software on it.  If I do a lot of
I/O, I will eventually get a kernel panic.  A local variable in one of
my functions will get clobbered - and always the same way.  That is,
if it is clobbered at all, the value that is written into it is always
the same value.

I had a vague idea there might be a compiler bug, and indeed I found
that altering this function in very innocuous ways would make my panic
go away.  But it wasn't making sense to me that it could be a compiler
bug, as it only happens after gigabytes of I/O activity.  If it were a
compiler bug it ought to happen sooner.

It was while studying the disassembly of my function, and reading the
AMD64 ABI that I discovered the red zone.  It turns out that my
original code uses the red zone, but if I add any subroutine calls at
all to it, it stops using the red zone - and stops panicking.

I put my code back the way it was to start with and then built my
driver with Other C++ Flags set to -mno-red-zone.  I have a great big
copy that's been running for about ten minutes now and I'm not getting
the panic.

The GCC man page that comes with Xcode 3.2 says that -mkernel will set
-mno-red-zone internally.  But possibly that is only for the Linux
version of GCC.  What does Apple's GCC do?  If -mkernel should enable
-mno-red-zone but doesn't, I'll be happy to file a radar bug.

Thanks,

Mike
--
Michael David Crawford
mdcrawford at gmail dot com

   GoingWare's Bag of Programming Tricks
      http://www.goingware.com/tips/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-drivers mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.