Welcome! Log In Create A New Profile

Advanced

How to allocate memory with kmalloc for a new struct?

Posted by fbcyborg 
How to allocate memory with kmalloc for a new struct?
July 07, 2008 04:55AM
Hello,

I've a new stuct and I would like to know what's the correct way to allocate memory for it.
I know I have to use kmalloc which returns a pointer to the begin of the freed memory, but I don't know how to tell my program that my struct must be allocated there.

I Love
Re: How to allocate memory with kmalloc for a new struct?
July 12, 2008 01:42AM
I found the way to allocate memory for a struct.

struct my_struct *s = kmalloc(sizeof(my_struct),GFP_KERNEL);

There's a problem now.
If I declare a new structure in a new file to be pushed into the kernel (this file contains a new system call), I can do that without any problem.
I can initialize that struct doing something like s->field1=some_value, s->field2=some_other_value, and so on.
When I go to read that values from an user-space process, calling that system call, I can see the values I used to initialize the struct.

If I do that in the do_fork() function, this has some real trouble. Actually, the initial values are modified by the kernel without any reason. If I set to NULL, or zero all field in a struct, they will be automatically modified in a random way.

I can't understand why this may happen.

Can somebody tell me why please?

I Love
Re: How to allocate memory with kmalloc for a new struct?
July 25, 2008 05:25PM
Solved.

I Love
Author:

Your Email:


Subject:


Spam prevention:
Please, solve the mathematical question and enter the answer in the input field below. This is for blocking bots that try to post this form automatically.
Question: how much is 21 plus 8?
Message: