Hi, I was wondering about few things concerning the function copy_thread(...) in arch/.../kernel/process.c. Here is the code for the m68k architecture (no mmu), which I try to edit: int copy_thread(int nr, unsigned long clone_flags, unsigned long usp, unsigned long topstk, struct task_struct * p, struct pt_regs * regs) { 1 struct pt_regs * childregs; 2 struct switch_stack * childstack, *stack; 3 unsigned long stack_offset, *retp; 4 5 stack_offset = KTHREAD_SIZE - sizeof(struct pt_regs); 6 childregs = (struct pt_regs *) ((unsigned long) p + stack_offset); 7 8 *childregs = *regs; 9 childregs->d0 = 0; 10 11 retp = ((unsigned long *) regs); 12 stack = ((struct switch_stack *) retp) - 1; 13 14 childstack = ((struct switch_stack *) childregs) - 1; 15 *childstack = *stack; 16 childstack->retpc = (unsigned long)ret_from_fork; 17 18 p->thread.usp = usp; 19 p->thread.ksp = (unsigned long)childstack; 20 /* 21 * Must save the current SFC/DFC value, NOT the value when 22 * the parent was last descheduled - RGH 10-08-96 23 */ 24 p->thread.fs = get_fs().seg; return 0; } Motorola defines "struct switch_stack" as some kind of extended stack, since they define some registers like d6, d7, a3, a4, retpc etc. which are not defined in pt_regs structure. But that doesn't matter since I don't wan't to use switch_stack at all (I decided to declare all registers in pt_regs). But these are the things I don't understand: 1) In lines 5 and 6 they do some pointer arithmetic in order to calculate the bottom of the childstack. Am I right? I guess KTHREAD_SIZE is the size of the kernel stack and is 2K, so they get a stack_offset. Why do they need stack_offset? 2) After line 6 has been executed, the variable childregs points to p + stack_offset. Is p the top of the previous stack? If so, then do they overwrite the previous stack? I mean, doesn't the stack grow downwards in linux? p + stack_offset is greater the p and than the previous stack would be overwritten. Best regards, Paul -- 5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail +++ GMX - die erste Adresse für Mail, Message, More +++ -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/