>
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, July 02, 2002 6:07 AM
> Subject: [rtl] problem in allocating memory in kernel
>
>
> hi,all
>
> In my program, memory (by using kmalloc) is allocated to form a chain
> table in kernel(RTLinux v3.1):
>
> code in kernel:
> int allocate_mem(unsigned int fifo)
> {
> ......
> p0=(struct Head_Struct *)kmalloc(HEAD_LEN_SIZE);
> ......
> }
>
> int init_module(void)
> {
> .....
> rtf_create_handler(PLC_DATA_FIFO, &allocate_mem);
> .....
> }
>
> code in userspace:
> write(fd1,p,HEAD_LEN_SIZE);
>
> it works well if the chain table is short, But if the chain table is longer
> ,there is an error: segmentation fault.
> why?
>
a posible expaination could be that kmalloc does not zero memory that it
allocates , and it is rounded to the next page_size*2^n that fits the
requested memmory, so you potentially have trailing garbage that if you
are accessing it beond the actally intended area could lead to problems.
the other problem could be what you consider "short" and "longer", kmalloc
is limited to 128KByte, and gcc will not fuss at you if you ask for more
than that - but if your try to write there you will segfault.
hofrat
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/