• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[SOLVED] static variables and kernel panic
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] static variables and kernel panic


  • Subject: [SOLVED] static variables and kernel panic
  • From: Jean Suisse <email@hidden>
  • Date: Sat, 01 Sep 2012 18:04:19 +0200

Solved, by avoiding to declare static structures unless they are to be used only within the kext.
Instead, I declare a static pointer on the structure and allocate it at runtime using a call to OSMalloc.


On 1 sept. 2012, at 02:09, Jean Suisse wrote:

Hello,

I am stuck with a kernel panic, and thought I know which line of code causes it, I can't understand the source of the error.
The code is located in a network kernel extension.

In FirstFile.h file, I declare a structure and a function:

struct anObject
{
void** pointerArray; 
};

void initObject (struct anObject* theObject);

In FirstFile.c I implement the function:

void initObject(struct anObject* theObject)
{
theObject->pointerArray = OSMalloc(….); 
}

In SecondFile.c file, I declare a static variable :

static struct anObject myObject = { NULL };

and I call:
 initObject(&myObject);

This will cause the kernel panic. Specifically the line with OSMalloc in initObject(…).

What I can tell :
- &myObject != NULL;
- &myObject->pointerArray == NULL;
- the OSMallocTag I use with OSMalloc is valid. And works for any other call
- The size I want to alloc is very reasonable (40 Bytes)

Also, I am wondering… could this be linked to the use of static variables ?
A few days ago, I decided to replace a dynamically allocated structure (OSMalloc) with a static variable structure that I would reuse. I did that for efficiency, since I found out that I was using the structure a lot, and I only needed one instance of the structure at any given time.
Well, I started to get kernel panics when passing the address of the structure to ctl_enqueuedata… solved by reverting back to a static pointer towards the OSMalloc'd structure...

Any idea on what's happening ?

Best regards,
Jean








 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Next by Date: sleep in the NKE unload function
  • Next by thread: sleep in the NKE unload function
  • Index(es):
    • Date
    • Thread