Add ostest vfork test (does not work yet)

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5488 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2013-01-07 21:41:20 +00:00
parent a8dd4ebde0
commit c94512e81b
4 changed files with 54 additions and 16 deletions

View File

@ -16,6 +16,7 @@ config ARCH_8051
config ARCH_ARM config ARCH_ARM
bool "ARM" bool "ARM"
select ARCH_HAVE_INTERRUPTSTACK select ARCH_HAVE_INTERRUPTSTACK
select ARCH_HAVE_VFORK
---help--- ---help---
The ARM architectures The ARM architectures
@ -124,6 +125,10 @@ config ADDRENV
bool bool
default n default n
config ARCH_HAVE_VFORK
bool
default n
config ARCH_STACKDUMP config ARCH_STACKDUMP
bool "Dump stack on assertions" bool "Dump stack on assertions"
default n default n

View File

@ -50,7 +50,7 @@
************************************************************************************/ ************************************************************************************/
.file "vfork.S" .file "vfork.S"
.globl task_vfork .globl up_vfork
/************************************************************************************ /************************************************************************************
* Public Functions * Public Functions
@ -66,7 +66,7 @@
* from the function in which vfork() was called, or calls any other function before * from the function in which vfork() was called, or calls any other function before
* successfully calling _exit() or one of the exec family of functions. * successfully calling _exit() or one of the exec family of functions.
* *
* This thin layer implements vfork by simply calling task_vfork() with the vfork() * This thin layer implements vfork by simply calling up_vfork() with the vfork()
* context as an argument. The overall sequence is: * context as an argument. The overall sequence is:
* *
* 1) User code calls vfork(). vfork() collects context information and * 1) User code calls vfork(). vfork() collects context information and
@ -121,12 +121,12 @@ vfork:
str r0, [sp, #VFORK_SP_OFFSET] str r0, [sp, #VFORK_SP_OFFSET]
str lr, [sp, #VFORK_LR_OFFSET] str lr, [sp, #VFORK_LR_OFFSET]
/* Then, call task_vfork(), passing it a pointer to the stack structure */ /* Then, call up_vfork(), passing it a pointer to the stack structure */
mov r0, sp mov r0, sp
bl task_vfork bl up_vfork
/* Release the stack data and return the value returned by task_vfork */ /* Release the stack data and return the value returned by up_vfork */
add sp, sp, #VFORK_SIZEOF add sp, sp, #VFORK_SIZEOF
mov pc, lr mov pc, lr

View File

@ -52,7 +52,7 @@
.syntax unified .syntax unified
.thumb .thumb
.file "vfork.S" .file "vfork.S"
.globl task_vfork .globl up_vfork
/************************************************************************************ /************************************************************************************
* Public Functions * Public Functions
@ -68,7 +68,7 @@
* from the function in which vfork() was called, or calls any other function before * from the function in which vfork() was called, or calls any other function before
* successfully calling _exit() or one of the exec family of functions. * successfully calling _exit() or one of the exec family of functions.
* *
* This thin layer implements vfork by simply calling task_vfork() with the vfork() * This thin layer implements vfork by simply calling up_vfork() with the vfork()
* context as an argument. The overall sequence is: * context as an argument. The overall sequence is:
* *
* 1) User code calls vfork(). vfork() collects context information and * 1) User code calls vfork(). vfork() collects context information and
@ -124,12 +124,12 @@ vfork:
str r0, [sp, #VFORK_SP_OFFSET] str r0, [sp, #VFORK_SP_OFFSET]
str lr, [sp, #VFORK_LR_OFFSET] str lr, [sp, #VFORK_LR_OFFSET]
/* Then, call task_vfork(), passing it a pointer to the stack structure */ /* Then, call up_vfork(), passing it a pointer to the stack structure */
mov r0, sp mov r0, sp
bl task_vfork bl up_vfork
/* Release the stack data and return the value returned by task_vfork */ /* Release the stack data and return the value returned by up_vfork */
add sp, sp, #VFORK_SIZEOF add sp, sp, #VFORK_SIZEOF
bx lr bx lr

View File

@ -43,6 +43,7 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <debug.h>
#include <nuttx/sched.h> #include <nuttx/sched.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
@ -129,17 +130,28 @@ pid_t up_vfork(struct vfork_s *context)
_TCB *child; _TCB *child;
size_t stacksize; size_t stacksize;
uint32_t newsp; uint32_t newsp;
uint32_t newfp;
uint32_t stackutil; uint32_t stackutil;
int ret; int ret;
svdbg("r4:%08x r5:%08x r6:%08x r7:%08x\n",
context->r4, context->r5, context->r6, context->r7);
svdbg("r8:%08x r9:%08x r10:%08x\n",
context->r8, context->r9, context->r10);
svdbg("fp:%08x sp:%08x lr:%08x\n",
context->fp, context->sp, context->lr);
/* Allocate and initialize a TCB for the child task. */ /* Allocate and initialize a TCB for the child task. */
child = task_vforksetup((start_t)context->lr); child = task_vforksetup((start_t)(context->lr & ~1));
if (!child) if (!child)
{ {
sdbg("task_vforksetup failed\n");
return (pid_t)ERROR; return (pid_t)ERROR;
} }
svdbg("Parent=%p Child=%p\n", parent, child);
/* Get the size of the parent task's stack. Due to alignment operations, /* Get the size of the parent task's stack. Due to alignment operations,
* the adjusted stack size may be smaller than the stack size originally * the adjusted stack size may be smaller than the stack size originally
* requrested. * requrested.
@ -152,15 +164,18 @@ pid_t up_vfork(struct vfork_s *context)
ret = up_create_stack(child, stacksize); ret = up_create_stack(child, stacksize);
if (ret != OK) if (ret != OK)
{ {
sdbg("up_create_stack failed: %d\n", ret);
task_vforkabort(child, -ret); task_vforkabort(child, -ret);
return (pid_t)ERROR; return (pid_t)ERROR;
} }
/* How much of the parent's stack was utilized? */ /* How much of the parent's stack was utilized? */
DEBUGASSERT(parent->adj_stack_ptr > context->sp); DEBUGASSERT((uint32_t)parent->adj_stack_ptr > context->sp);
stackutil = (uint32_t)parent->adj_stack_ptr - context->sp; stackutil = (uint32_t)parent->adj_stack_ptr - context->sp;
svdbg("stacksize:%d stackutil:%d\n", stacksize, stackutil);
/* Make some feeble effort to perserve the stack contents. This is /* Make some feeble effort to perserve the stack contents. This is
* feeble because the stack surely contains invalid pointer and other * feeble because the stack surely contains invalid pointer and other
* content that will not work in the child context. However, if the * content that will not work in the child context. However, if the
@ -171,6 +186,24 @@ pid_t up_vfork(struct vfork_s *context)
newsp = (uint32_t)child->adj_stack_ptr - stackutil; newsp = (uint32_t)child->adj_stack_ptr - stackutil;
memcpy((void *)newsp, (const void *)context->sp, stackutil); memcpy((void *)newsp, (const void *)context->sp, stackutil);
/* Was there a frame pointer in place before? */
if (context->fp <= (uint32_t)parent->adj_stack_ptr &&
context->fp >= (uint32_t)parent->adj_stack_ptr - stacksize)
{
uint32_t frameutil = (uint32_t)parent->adj_stack_ptr - context->fp;
newfp = (uint32_t)child->adj_stack_ptr - frameutil;
}
else
{
newfp = context->fp;
}
svdbg("Old stack base:%08x SP:%08x FP:%08x\n",
parent->adj_stack_ptr, context->sp, context->fp);
svdbg("New stack base:%08x SP:%08x FP:%08x\n",
child->adj_stack_ptr, newsp, newfp);
/* Update the stack pointer, frame pointer, and voltile registers. When /* Update the stack pointer, frame pointer, and voltile registers. When
* the child TCB was initialized, all of the values were set to zero. * the child TCB was initialized, all of the values were set to zero.
* up_initial_state() altered a few values, but the return value in R0 * up_initial_state() altered a few values, but the return value in R0
@ -185,8 +218,8 @@ pid_t up_vfork(struct vfork_s *context)
child->xcp.regs[REG_R8] = context->r8; /* Volatile register r8 */ child->xcp.regs[REG_R8] = context->r8; /* Volatile register r8 */
child->xcp.regs[REG_R9] = context->r9; /* Volatile register r9 */ child->xcp.regs[REG_R9] = context->r9; /* Volatile register r9 */
child->xcp.regs[REG_R10] = context->r10; /* Volatile register r10 */ child->xcp.regs[REG_R10] = context->r10; /* Volatile register r10 */
child->xcp.regs[REG_FP] = context->fp; /* Frame pointer */ child->xcp.regs[REG_FP] = newfp; /* Frame pointer */
child->xcp.regs[REG_SP] = context->sp; /* Stack pointer */ child->xcp.regs[REG_SP] = newsp; /* Stack pointer */
/* And, finally, start the child task. On a failure, task_vforkstart() /* And, finally, start the child task. On a failure, task_vforkstart()
* will discard the TCB by calling task_vforkabort(). * will discard the TCB by calling task_vforkabort().