Rename up_addrenv_assign() to up_addrenv_clone() and generalize its arguments so that can be used for other purposes

This commit is contained in:
Gregory Nutt 2014-08-26 12:16:05 -06:00
parent a14cb94b45
commit b13d9b4161
8 changed files with 66 additions and 62 deletions

View File

@ -112,7 +112,7 @@
<a href="#up_addrenv_vdata">4.4.4 <code>up_addrenv_vdata()</code></a></br> <a href="#up_addrenv_vdata">4.4.4 <code>up_addrenv_vdata()</code></a></br>
<a href="#up_addrenv_select">4.4.5 <code>up_addrenv_select()</code></a></br> <a href="#up_addrenv_select">4.4.5 <code>up_addrenv_select()</code></a></br>
<a href="#up_addrenv_restore">4.4.6 <code>up_addrenv_restore()</code></a></br> <a href="#up_addrenv_restore">4.4.6 <code>up_addrenv_restore()</code></a></br>
<a href="#up_addrenv_assign">4.4.7 <code>up_addrenv_assign()</code></a></br> <a href="#up_addrenv_clone">4.4.7 <code>up_addrenv_clone()</code></a></br>
<a href="#up_addrenv_attach">4.4.8 <code>up_addrenv_attach()</code></a></br> <a href="#up_addrenv_attach">4.4.8 <code>up_addrenv_attach()</code></a></br>
<a href="#up_addrenv_detach">4.4.9 <code>up_addrenv_detach()</code></a> <a href="#up_addrenv_detach">4.4.9 <code>up_addrenv_detach()</code></a>
</ul> </ul>
@ -2960,8 +2960,8 @@ VxWorks provides the following comparable interface:
Restore an address environment. Restore an address environment.
</li> </li>
<li> <li>
<a href="#up_addrenv_assign">4.4.7 <code>up_addrenv_assign()</code></a>: <a href="#up_addrenv_clone">4.4.7 <code>up_addrenv_clone()</code></a>:
Assign an address environment to a thread. Copy an address environment from one location to another.
</li> </li>
</ul> </ul>
</li> </li>
@ -2969,7 +2969,7 @@ VxWorks provides the following comparable interface:
<p> <p>
<b>Tasking Support</b>. <b>Tasking Support</b>.
Other interfaces must be provided to support higher-level interfaces used by the NuttX tasking logic. Other interfaces must be provided to support higher-level interfaces used by the NuttX tasking logic.
These interfaces are* used by the functions in <code>sched/</code> and all operate on the task group which as been assigned an address environment by <code>up_addrenv_assign()</code>. These interfaces are* used by the functions in <code>sched/</code> and all operate on the task group which as been assigned an address environment by <code>up_addrenv_clone()</code>.
</p> </p>
<ul> <ul>
<li> <li>
@ -3108,19 +3108,19 @@ VxWorks provides the following comparable interface:
Zero (<code>OK</code>) on success; a negated <code>errno</code> value on failure. Zero (<code>OK</code>) on success; a negated <code>errno</code> value on failure.
</ul> </ul>
<h3><a name="up_addrenv_assign">4.4.7 <code>up_addrenv_assign()</code></a></h3> <h3><a name="up_addrenv_clone">4.4.7 <code>up_addrenv_clone()</code></a></h3>
<p><b>Function Prototype</b>:<p> <p><b>Function Prototype</b>:<p>
<ul> <ul>
<code>int up_addrenv_assign(FAR const group_addrenv_t *addrenv, FAR struct task_group_s *group);</code> <code>int up_addrenv_clone(FAR const task_group_s *src, FAR struct task_group_s *dest);</code>
</ul> </ul>
<p><b>Description</b>:</p> <p><b>Description</b>:</p>
<ul> <ul>
Assign an address environment to a new task group. Duplicate an address environment. This does not copy the underlying memory, only the representation that can be used to instantiate that memory as an address environment.
</ul> </ul>
<p><b>Input Parameters</b>:</p> <p><b>Input Parameters</b>:</p>
<ul> <ul>
<li><code>addrenv</code>: The representation of the group address environment previously returned by <code>up_addrenv_create</code>.</li> <li><code>src</code>: The address environment to be copied.</li>
<li><code>group</code>: The new task group to receive the address environment.</li> <li><code>dest</code>: The location to receive the copied address environment.</li>
</ul> </ul>
<p><b>Returned Value</b>:</p> <p><b>Returned Value</b>:</p>
<ul> <ul>

View File

@ -48,11 +48,12 @@
* address environment * address environment
* up_addrenv_select - Instantiate an address environment * up_addrenv_select - Instantiate an address environment
* up_addrenv_restore - Restore an address environment * up_addrenv_restore - Restore an address environment
* up_addrenv_assign - Assign an address environment to a group * up_addrenv_clone - Copy an address environment from one location to
* another.
* *
* Higher-level interfaces used by the tasking logic. These interfaces are * Higher-level interfaces used by the tasking logic. These interfaces are
* used by the functions in sched/ and all operate on the thread which whose * used by the functions in sched/ and all operate on the thread which whose
* group been assigned an address environment by up_addrenv_assign(). * group been assigned an address environment by up_addrenv_clone().
* *
* up_addrenv_attach - Clone the address environment assigned to one TCB * up_addrenv_attach - Clone the address environment assigned to one TCB
* to another. This operation is done when a pthread * to another. This operation is done when a pthread
@ -661,30 +662,31 @@ int up_addrenv_restore(FAR const save_addrenv_t *oldenv)
} }
/**************************************************************************** /****************************************************************************
* Name: up_addrenv_assign * Name: up_addrenv_clone
* *
* Description: * Description:
* Assign an address environment to a new task group. * Duplicate an address environment. This does not copy the underlying
* memory, only the representation that can be used to instantiate that
* memory as an address environment.
* *
* Input Parameters: * Input Parameters:
* addrenv - The representation of the task address environment previously * src - The address environment to be copied.
* returned by up_addrenv_create(). * dest - The location to receive the copied address environment.
* group - The new task group to receive the address environment.
* *
* Returned Value: * Returned Value:
* Zero (OK) on success; a negated errno value on failure. * Zero (OK) on success; a negated errno value on failure.
* *
****************************************************************************/ ****************************************************************************/
int up_addrenv_assign(FAR const group_addrenv_t *addrenv, int up_addrenv_clone(FAR const group_addrenv_t *src,
FAR struct task_group_s *group) FAR group_addrenv_t *dest)
{ {
DEBUGASSERT(addrenv && group); bvdbg("src=%p dest=%p\n", src, dest);
bvdbg("addrenv=%p group->addrenv=%p\n", addrenv, &group->addrenv); DEBUGASSERT(src && dest);
/* Just copy the address environment into the group */ /* Just copy the address environment from the source to the destination */
memcpy(&group->addrenv, addrenv, sizeof(group_addrenv_t)); memcpy(dest, src, sizeof(group_addrenv_t));
return OK; return OK;
} }

View File

@ -192,11 +192,12 @@ return g_physhandle ? OK : -ENOMEM;
* address environment * address environment
* up_addrenv_select - Instantiate an address environment * up_addrenv_select - Instantiate an address environment
* up_addrenv_restore - Restore an address environment * up_addrenv_restore - Restore an address environment
* up_addrenv_assign - Assign an address environment to a group * up_addrenv_clone - Copy an address environment from one location to
* another.
* *
* Higher-level interfaces used by the tasking logic. These interfaces are * Higher-level interfaces used by the tasking logic. These interfaces are
* used by the functions in sched/ and all operate on the thread which whose * used by the functions in sched/ and all operate on the thread which whose
* group been assigned an address environment by up_addrenv_assign(). * group been assigned an address environment by up_addrenv_clone().
* *
* up_addrenv_attach - Clone the address environment assigned to one TCB * up_addrenv_attach - Clone the address environment assigned to one TCB
* to another. This operation is done when a pthread * to another. This operation is done when a pthread
@ -457,33 +458,32 @@ int up_addrenv_restore(FAR const save_addrenv_t *oldenv)
} }
/**************************************************************************** /****************************************************************************
* Name: up_addrenv_assign * Name: up_addrenv_clone
* *
* Description: * Description:
* Assign an address environment to a task group. * Duplicate an address environment. This does not copy the underlying
* memory, only the representation that can be used to instantiate that
* memory as an address environment.
* *
* Input Parameters: * Input Parameters:
* addrenv - The representation of the task address environment previously * src - The address environment to be copied.
* returned by up_addrenv_create(). * dest - The location to receive the copied address environment.
* group - The task group to receive the address environment.
* *
* Returned Value: * Returned Value:
* Zero (OK) on success; a negated errno value on failure. * Zero (OK) on success; a negated errno value on failure.
* *
****************************************************************************/ ****************************************************************************/
int up_addrenv_assign(FAR const group_addrenv_t *addrenv, int up_addrenv_clone(FAR const group_addrenv_t *src,
FAR struct task_group_s *group) FAR group_addrenv_t *dest);
{ {
/* Make sure that there is no address environment in place on this TCB */ DEBUGASSERT(src && dest);
DEBUGASSERT(addrenv && group->addrenv == NULL); /* Copy the CBR structure. This is an atomic operation so no special
* precautions should be needed.
/* Save the CBR structure in the group. This is an atomic operation so no
* special precautions should be needed.
*/ */
group->addrenv = *addrenv; *dest = *src;
return OK; return OK;
} }

View File

@ -163,9 +163,9 @@ int exec_module(FAR const struct binary_s *binp)
goto errout; goto errout;
} }
#ifndef CONFIG_CUSTOM_STACK
/* Allocate the stack for the new task (always from the user heap) */ /* Allocate the stack for the new task (always from the user heap) */
#ifndef CONFIG_CUSTOM_STACK
stack = (FAR uint32_t*)kumalloc(binp->stacksize); stack = (FAR uint32_t*)kumalloc(binp->stacksize);
if (!tcb) if (!tcb)
{ {
@ -193,11 +193,11 @@ int exec_module(FAR const struct binary_s *binp)
/* Note that tcb->flags are not modified. 0=normal task */ /* Note that tcb->flags are not modified. 0=normal task */
/* tcb->flags |= TCB_FLAG_TTYPE_TASK; */ /* tcb->flags |= TCB_FLAG_TTYPE_TASK; */
#ifdef CONFIG_PIC
/* Add the D-Space address as the PIC base address. By convention, this /* Add the D-Space address as the PIC base address. By convention, this
* must be the first allocated address space. * must be the first allocated address space.
*/ */
#ifdef CONFIG_PIC
tcb->cmn.dspace = binp->alloc[0]; tcb->cmn.dspace = binp->alloc[0];
/* Re-initialize the task's initial state to account for the new PIC base */ /* Re-initialize the task's initial state to account for the new PIC base */
@ -205,24 +205,24 @@ int exec_module(FAR const struct binary_s *binp)
up_initial_state(&tcb->cmn); up_initial_state(&tcb->cmn);
#endif #endif
#ifdef CONFIG_ARCH_ADDRENV
/* Assign the address environment to the new task group */ /* Assign the address environment to the new task group */
#ifdef CONFIG_ARCH_ADDRENV ret = up_addrenv_clone(&binp->addrenv, &tcb->cmn.group->addrenv);
ret = up_addrenv_assign(&binp->addrenv, tcb->cmn.group);
if (ret < 0) if (ret < 0)
{ {
err = -ret; err = -ret;
bdbg("ERROR: up_addrenv_assign() failed: %d\n", ret); bdbg("ERROR: up_addrenv_clone() failed: %d\n", ret);
goto errout_with_stack; goto errout_with_stack;
} }
#endif #endif
#ifdef CONFIG_BINFMT_CONSTRUCTORS
/* Setup a start hook that will execute all of the C++ static constructors /* Setup a start hook that will execute all of the C++ static constructors
* on the newly created thread. The struct binary_s must persist at least * on the newly created thread. The struct binary_s must persist at least
* until the new task has been started. * until the new task has been started.
*/ */
#ifdef CONFIG_BINFMT_CONSTRUCTORS
task_starthook(tcb, exec_ctors, (FAR void *)binp); task_starthook(tcb, exec_ctors, (FAR void *)binp);
#endif #endif
@ -261,4 +261,3 @@ errout:
} }
#endif /* CONFIG_BINFMT_DISABLE */ #endif /* CONFIG_BINFMT_DISABLE */

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* binfmt/elf.c * binfmt/elf.c
* *
* Copyright (C) 2012 Gregory Nutt. All rights reserved. * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -294,11 +294,11 @@ static int elf_loadbinary(FAR struct binary_s *binp)
#endif #endif
#ifdef CONFIG_ARCH_ADDRENV #ifdef CONFIG_ARCH_ADDRENV
/* Save the address environment. This will be needed when the module is /* Save the address environment in the binfmt structure. This will be
* executed for the up_addrenv_assign() call. * needed when the module is executed.
*/ */
binp->addrenv = loadinfo.addrenv; up_addrenv_clone(&loadinfo.addrenv, &binp->addrenv);
#endif #endif
elf_dumpentrypt(binp, &loadinfo); elf_dumpentrypt(binp, &loadinfo);

View File

@ -206,11 +206,11 @@ static int nxflat_loadbinary(struct binary_s *binp)
#endif #endif
#ifdef CONFIG_ARCH_ADDRENV #ifdef CONFIG_ARCH_ADDRENV
/* Save the address environment. This will be needed when the module is /* Save the address environment in the binfmt structure. This will be
* executed for the up_addrenv_assign() call. * needed when the module is executed.
*/ */
binp->addrenv = loadinfo.addrenv; up_addrenv_clone(&loadinfo.addrenv, &binp->addrenv);
#endif #endif
nxflat_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt, nxflat_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt,

View File

@ -162,11 +162,12 @@
* address environment * address environment
* up_addrenv_select - Instantiate an address environment * up_addrenv_select - Instantiate an address environment
* up_addrenv_restore - Restore an address environment * up_addrenv_restore - Restore an address environment
* up_addrenv_assign - Assign an address environment to a group * up_addrenv_clone - Copy an address environment from one location to
* another.
* *
* Higher-level interfaces used by the tasking logic. These interfaces are * Higher-level interfaces used by the tasking logic. These interfaces are
* used by the functions in sched/ and all operate on the thread which whose * used by the functions in sched/ and all operate on the thread which whose
* group been assigned an address environment by up_addrenv_assign(). * group been assigned an address environment by up_addrenv_clone().
* *
* up_addrenv_attach - Clone the address environment assigned to one TCB * up_addrenv_attach - Clone the address environment assigned to one TCB
* to another. This operation is done when a pthread * to another. This operation is done when a pthread

View File

@ -696,11 +696,12 @@ void up_allocate_pgheap(FAR void **heap_start, size_t *heap_size);
* address environment * address environment
* up_addrenv_select - Instantiate an address environment * up_addrenv_select - Instantiate an address environment
* up_addrenv_restore - Restore an address environment * up_addrenv_restore - Restore an address environment
* up_addrenv_assign - Assign an address environment to a group * up_addrenv_clone - Copy an address environment from one location to
* another.
* *
* Higher-level interfaces used by the tasking logic. These interfaces are * Higher-level interfaces used by the tasking logic. These interfaces are
* used by the functions in sched/ and all operate on the thread which whose * used by the functions in sched/ and all operate on the thread which whose
* group been assigned an address environment by up_addrenv_assign(). * group been assigned an address environment by up_addrenv_clone().
* *
* up_addrenv_attach - Clone the address environment assigned to one TCB * up_addrenv_attach - Clone the address environment assigned to one TCB
* to another. This operation is done when a pthread * to another. This operation is done when a pthread
@ -858,15 +859,16 @@ int up_addrenv_restore(FAR const save_addrenv_t *oldenv);
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: up_addrenv_assign * Name: up_addrenv_clone
* *
* Description: * Description:
* Assign an address environment to a new task group. * Duplicate an address environment. This does not copy the underlying
* memory, only the representation that can be used to instantiate that
* memory as an address environment.
* *
* Input Parameters: * Input Parameters:
* addrenv - The representation of the task address environment previously * src - The address environment to be copied.
* returned by up_addrenv_create(). * dest - The location to receive the copied address environment.
* group - The new task group to receive the address environment.
* *
* Returned Value: * Returned Value:
* Zero (OK) on success; a negated errno value on failure. * Zero (OK) on success; a negated errno value on failure.
@ -874,8 +876,8 @@ int up_addrenv_restore(FAR const save_addrenv_t *oldenv);
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_ARCH_ADDRENV #ifdef CONFIG_ARCH_ADDRENV
int up_addrenv_assign(FAR const group_addrenv_t *addrenv, int up_addrenv_clone(FAR const group_addrenv_t *src,
FAR struct task_group_s *group); FAR group_addrenv_t *dest);
#endif #endif
/**************************************************************************** /****************************************************************************