[ale] Clones and printf()
Joe Steele
joe at madewell.com
Fri Mar 22 22:33:12 EST 2002
On Thu 3/21/02 6:58 PM, Chris Fowler wrote:
>
> I think I found one problem. Here is a snip
>
> int *stack = (int *)malloc(CHILD_STACK_SIZE); // 4096
>
> pid = clone(execTask, stack, SIGCHLD|CLONE_VM, task);
>
> The manpages states that a stack grows down.
Correct (at least on ix86 architecture), which means the stack
pointer should initially point past the end of the malloc'ed block:
int *stack = (int *)malloc(CHILD_STACK_SIZE); // 4096
stack = (int *)((char *)stack + CHILD_STACK_SIZE);
The first item pushed on the stack will be stored at stack - 1, the
next item pushed will be at stack - 2, etc. All items pushed will
fall inside the malloc'ed block.
> Since I'm
> passing a pointer to the beginning of the stack it is possible for
> the thread to write into the parents process. Corupting my
> program. Is this correct? I looked at some sampels on the
> internet and they do not show doing that.
>
> http://www.linuxjournal.com/modules.php?op=modload&name=NS-articles/misc/ima
> ges&file=5211l2
>
> Maybe that example is wrong.
No doubt (at least on ix86 architecture).
> Is there any *good* documentation
> online on using threads effectively. Maybe a book? It is just awesome
> to have multiple threads doing tasks and sharing data. It opens
> up many possibilites. I have some great planes with this.
One place to look would be the Linux Threads FAQ:
http://www.linuxdoc.org/FAQ/Threads-FAQ/index.html
Although it was last revised in '97, it still has useful info, along
with links to other useful resources.
I suspect that most people don't use clone() directly, but instead
use library functions which handle the cloning for them.
Consequently, finding examples which use clone() may be challenging.
--Joe
---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.
More information about the Ale
mailing list