All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Re: what`s wrong?
@ 2002-04-25  9:12 Huo Zhigang
  2002-04-25  9:50 ` Matti Aarnio
  0 siblings, 1 reply; 2+ messages in thread
From: Huo Zhigang @ 2002-04-25  9:12 UTC (permalink / raw)
  To: lkml

>On Apr 24, 2002  18:06 +0200, il boba wrote:
>> Is there anybody that can help me understand what`s wrong with this code?

>Yes, easily spotted a major problem without even reading the whole
>thing.

>> #define BUFSIZ 8192
>> 
>> int init_module()
>> {
>>  int err_frame[BUFSIZ];
>
>The entire kernel stack is only 8kB in size.  You have already killed
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>a bunch of random memory by allocating this much memory on the stack.
>You allocated 4*8192 = 32kB on the stack here.
  
   Sure, the kernel stack is 8192 Bytes, but "err_frame[]" is a local variable. Does the kernel allocate memory for "err_frame[]" from the stack?? 

>> int init_err_frame(int err_frame[]) {
>>  int i, k = 0, j = 0;
>>  char buffer[BUFSIZ];
>
>Another 8kB on the stack here - further random corruption.
   Here, I think, err_frame[] as a function parameter  will take 8K in the kernel stack.
   Am I correct?
  
   Thank you.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Re: what`s wrong?
  2002-04-25  9:12 Re: what`s wrong? Huo Zhigang
@ 2002-04-25  9:50 ` Matti Aarnio
  0 siblings, 0 replies; 2+ messages in thread
From: Matti Aarnio @ 2002-04-25  9:50 UTC (permalink / raw)
  To: Huo Zhigang; +Cc: lkml

On Thu, Apr 25, 2002 at 05:12:21PM +0800, Huo Zhigang wrote:
...
> >The entire kernel stack is only 8kB in size.  You have already killed
>   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >a bunch of random memory by allocating this much memory on the stack.
> >You allocated 4*8192 = 32kB on the stack here.
>   
>    Sure, the kernel stack is 8192 Bytes, but "err_frame[]" is a local 
>    variable. Does the kernel allocate memory for "err_frame[]" from the 
>    stack?? 

   It is not about how KERNEL does it, but how C (programming language)
   does it.  If you don't know C's memory management things regarding
   various classes of variables, I suggest you pick some good reference
   book and study it asap.

>    Here, I think, err_frame[] as a function parameter  will take 8K in 
>    the kernel stack.  Am I correct?

  Sorry, this isn't "programming in C"-education forum..

>    Thank you.

/Matti Aarnio

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-04-25  9:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-25  9:12 Re: what`s wrong? Huo Zhigang
2002-04-25  9:50 ` Matti Aarnio

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.