blob: 73bd7deeec8b57b162b0899ae8cd9791f6f8cd2b [file] [log] [blame]
<!--
Documentation/_templates/layout.html
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. The
ASF licenses this file to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
-->
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Address Environments &mdash; NuttX latest documentation</title>
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/copybutton.css" type="text/css" />
<link rel="stylesheet" href="../../_static/tabs.css" type="text/css" />
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<!--[if lt IE 9]>
<script src="../../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="../../_static/jquery.js"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/sphinx_highlight.js"></script>
<script src="../../_static/clipboard.min.js"></script>
<script src="../../_static/copybutton.js"></script>
<script src="../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Application OS vs. Internal OS Interfaces" href="app_vs_os.html" />
<link rel="prev" title="Architecture APIs" href="index.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> NuttX
</a>
<!-- this version selector is quite ugly, should be probably replaced by something
more modern -->
<div class="version-selector">
<select onchange="javascript:location.href = this.value;">
<option value="../../../latest" selected="selected">latest</option>
<option value="../../../10.0.0" >10.0.0</option>
<option value="../../../10.0.1" >10.0.1</option>
<option value="../../../10.1.0" >10.1.0</option>
<option value="../../../10.2.0" >10.2.0</option>
<option value="../../../10.3.0" >10.3.0</option>
<option value="../../../11.0.0" >11.0.0</option>
<option value="../../../12.0.0" >12.0.0</option>
<option value="../../../12.1.0" >12.1.0</option>
<option value="../../../12.2.0" >12.2.0</option>
<option value="../../../12.2.1" >12.2.1</option>
<option value="../../../12.3.0" >12.3.0</option>
<option value="../../../12.4.0" >12.4.0</option>
<option value="../../../12.5.0" >12.5.0</option>
<option value="../../../12.5.1" >12.5.1</option>
</select>
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Table of Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../introduction/index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../quickstart/index.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../contributing/index.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../introduction/inviolables.html">The Inviolable Principles of NuttX</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../platforms/index.html">Supported Platforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../components/index.html">OS Components</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../applications/index.html">Applications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../implementation/index.html">Implementation Details</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">API Reference</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../user/index.html">Userspace API</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">Architecture APIs</a><ul class="current">
<li class="toctree-l3 current"><a class="current reference internal" href="#">Address Environments</a></li>
<li class="toctree-l3"><a class="reference internal" href="app_vs_os.html">Application OS vs. Internal OS Interfaces</a></li>
<li class="toctree-l3"><a class="reference internal" href="arch.html">APIs Exported by Architecture-Specific Logic to NuttX</a></li>
<li class="toctree-l3"><a class="reference internal" href="board.html">APIs Exported by Board-Specific Logic to NuttX</a></li>
<li class="toctree-l3"><a class="reference internal" href="conventions.html">Naming and Header File Conventions</a></li>
<li class="toctree-l3"><a class="reference internal" href="iob.html">I/O Buffer Management</a></li>
<li class="toctree-l3"><a class="reference internal" href="led.html">LED Support</a></li>
<li class="toctree-l3"><a class="reference internal" href="mutex.html">Mutual Exclusion lock</a></li>
<li class="toctree-l3"><a class="reference internal" href="nat.html">Network Address Translation (NAT)</a></li>
<li class="toctree-l3"><a class="reference internal" href="newreno.html">Congestion Control NewReno</a></li>
<li class="toctree-l3"><a class="reference internal" href="notifier.html">Notifier Chain</a></li>
<li class="toctree-l3"><a class="reference internal" href="nuttx.html">APIs Exported by NuttX to Architecture-Specific Logic</a></li>
<li class="toctree-l3"><a class="reference internal" href="paging.html">On-Demand Paging</a></li>
<li class="toctree-l3"><a class="reference internal" href="shm.html">Shared Memory</a></li>
<li class="toctree-l3"><a class="reference internal" href="smp.html">Symmetric Multiprocessing (SMP) Application</a></li>
<li class="toctree-l3"><a class="reference internal" href="time_clock.html">System Time and Clock</a></li>
<li class="toctree-l3"><a class="reference internal" href="wqueue.html">Work Queues</a></li>
<li class="toctree-l3"><a class="reference internal" href="netdev.html">Network Devices</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../faq/index.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../guides/index.html">Guides</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">NuttX</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="../index.html">API Reference</a></li>
<li class="breadcrumb-item"><a href="index.html">Architecture APIs</a></li>
<li class="breadcrumb-item active">Address Environments</li>
<li class="wy-breadcrumbs-aside">
<a href="../../_sources/reference/os/addrenv.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="address-environments">
<h1>Address Environments<a class="headerlink" href="#address-environments" title="Permalink to this heading"></a></h1>
<p>CPUs that support memory management units (MMUs) may provide
<em>address environments</em> within which tasks and their child threads
execute. The configuration indicates the CPUs ability to support
address environments by setting the configuration variable
<code class="docutils literal notranslate"><span class="pre">CONFIG_ARCH_HAVE_ADDRENV=y</span></code>. That will enable the selection of
the actual address environment support which is indicated by the
selection of the configuration variable <code class="docutils literal notranslate"><span class="pre">CONFIG_ARCH_ADDRENV=y</span></code>.
These address environments are created only when tasks are created
via <code class="docutils literal notranslate"><span class="pre">exec()</span></code> or <code class="docutils literal notranslate"><span class="pre">exec_module()</span></code> (see
<code class="docutils literal notranslate"><span class="pre">include/nuttx/binfmt/binfmt.h</span></code>).</p>
<p>When <code class="docutils literal notranslate"><span class="pre">CONFIG_ARCH_ADDRENV=y</span></code> is set in the board configuration,
the CPU-specific logic must provide a set of interfaces as defined
in the header file <code class="docutils literal notranslate"><span class="pre">include/nuttx/arch.h</span></code>. These interfaces are
listed below and described in detail in the following paragraphs.</p>
<p>The CPU-specific logic must provide two categories in interfaces:</p>
<ol class="arabic">
<li><p><strong>Binary Loader Support</strong>. These are low-level interfaces used
in <code class="docutils literal notranslate"><span class="pre">binfmt/</span></code> to instantiate tasks with address environments.
These interfaces all operate on type <code class="docutils literal notranslate"><span class="pre">arch_addrenv_t</span></code> which
is an abstract representation of a task group’s address
environment and the type must be defined in<code class="docutils literal notranslate"><span class="pre">arch/arch.h</span></code> if
<code class="docutils literal notranslate"><span class="pre">CONFIG_ARCH_ADDRENV</span></code> is defined. These low-level interfaces
include:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#c.up_addrenv_create" title="up_addrenv_create"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_create()</span></code></a>: Create an address environment.</p></li>
<li><p><a class="reference internal" href="#c.up_addrenv_destroy" title="up_addrenv_destroy"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_destroy()</span></code></a>: Destroy an address environment.</p></li>
<li><p><a class="reference internal" href="#c.up_addrenv_vtext" title="up_addrenv_vtext"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_vtext()</span></code></a>: Returns the virtual base address of the <code class="docutils literal notranslate"><span class="pre">.text</span></code> address environment.</p></li>
<li><p><a class="reference internal" href="#c.up_addrenv_vdata" title="up_addrenv_vdata"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_vdata()</span></code></a>: Returns the virtual base address of the <code class="docutils literal notranslate"><span class="pre">.bss</span></code>/<code class="docutils literal notranslate"><span class="pre">.data</span></code> address environment.</p></li>
<li><p><a class="reference internal" href="#c.up_addrenv_heapsize" title="up_addrenv_heapsize"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_heapsize()</span></code></a>: Return the initial heap size.</p></li>
<li><p><a class="reference internal" href="#c.up_addrenv_select" title="up_addrenv_select"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_select()</span></code></a>: Instantiate an address environment.</p></li>
<li><p><a class="reference internal" href="#c.up_addrenv_clone" title="up_addrenv_clone"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_clone()</span></code></a>: Copy an address environment from one location to another.</p></li>
</ul>
</li>
<li><p><strong>Tasking Support</strong>. 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 class="docutils literal notranslate"><span class="pre">sched/</span></code>
and all operate on the task group which as been assigned an
address environment by <code class="docutils literal notranslate"><span class="pre">up_addrenv_clone()</span></code>.</p>
<ul class="simple">
<li><p><a class="reference internal" href="#c.up_addrenv_attach" title="up_addrenv_attach"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_attach()</span></code></a>: Clone the group address environment assigned to a new
thread. This operation is done when a pthread is created
that share’s the same address environment.</p></li>
<li><p><a class="reference internal" href="#c.up_addrenv_detach" title="up_addrenv_detach"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_detach()</span></code></a>: Release the thread’s reference to a group address
environment when a task/thread exits.</p></li>
</ul>
</li>
<li><p><strong>Dynamic Stack Support</strong>. <code class="docutils literal notranslate"><span class="pre">CONFIG_ARCH_STACK_DYNAMIC=y</span></code>
indicates that the user process stack resides in its own
address space. This option is also <em>required</em> if
<code class="docutils literal notranslate"><span class="pre">CONFIG_BUILD_KERNEL</span></code> and <code class="docutils literal notranslate"><span class="pre">CONFIG_LIBC_EXECFUNCS</span></code> are
selected. Why? Because the caller’s stack must be preserved in
its own address space when we instantiate the environment of
the new process in order to initialize it.</p>
<p><strong>NOTE:</strong> The naming of the <code class="docutils literal notranslate"><span class="pre">CONFIG_ARCH_STACK_DYNAMIC</span></code>
selection implies that dynamic stack allocation is supported.
Certainly this option must be set if dynamic stack allocation
is supported by a platform. But the more general meaning of
this configuration environment is simply that the stack has its
own address space.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">CONFIG_ARCH_STACK_DYNAMIC=y</span></code> is selected then the
platform specific code must export these additional interfaces:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#c.up_addrenv_ustackalloc" title="up_addrenv_ustackalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_ustackalloc()</span></code></a>: Create a stack address environment</p></li>
<li><p><a class="reference internal" href="#c.up_addrenv_ustackfree" title="up_addrenv_ustackfree"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_ustackfree()</span></code></a>: Destroy a stack address environment.</p></li>
<li><p><a class="reference internal" href="#c.up_addrenv_vustack" title="up_addrenv_vustack"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_vustack()</span></code></a>: Returns the virtual base address of the stack</p></li>
<li><p><a class="reference internal" href="#c.up_addrenv_ustackselect" title="up_addrenv_ustackselect"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_ustackselect()</span></code></a>: Instantiate a stack address environment</p></li>
</ul>
</li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">CONFIG_ARCH_KERNEL_STACK</span></code> is selected, then each user
process will have two stacks: (1) a large (and possibly
dynamic) user stack and (2) a smaller kernel stack. However,
this option is <em>required</em> if both <code class="docutils literal notranslate"><span class="pre">CONFIG_BUILD_KERNEL</span></code> and
<code class="docutils literal notranslate"><span class="pre">CONFIG_LIBC_EXECFUNCS</span></code> are selected. Why? Because when we
instantiate and initialize the address environment of the new
user process, we will temporarily lose the address environment
of the old user process, including its stack contents. The
kernel C logic will crash immediately with no valid stack in
place.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">CONFIG_ARCH_KERNEL_STACK=y</span></code> is selected then the platform
specific code must export these additional interfaces:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#c.up_addrenv_kstackalloc" title="up_addrenv_kstackalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">up_addrenv_kstackalloc()</span></code></a>: Allocate the process kernel stack.</p></li>
</ul>
</li>
</ol>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_create">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_create</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="../user/structures.html#c.size_t" title="size_t"><span class="n"><span class="pre">size_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">textsize</span></span>, <a class="reference internal" href="../user/structures.html#c.size_t" title="size_t"><span class="n"><span class="pre">size_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">datasize</span></span>, <a class="reference internal" href="../user/structures.html#c.size_t" title="size_t"><span class="n"><span class="pre">size_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">heapsize</span></span>, <span class="pre">FAR</span><span class="w"> </span><span class="n"><span class="pre">arch_addrenv_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">addrenv</span></span><span class="sig-paren">)</span><span class="p"><span class="pre">;</span></span><a class="headerlink" href="#c.up_addrenv_create" title="Permalink to this definition"></a><br /></dt>
<dd><p>This function is called when a new task is created in order to
instantiate an address environment for the new task group.
up_addrenv_create() is essentially the allocator of the physical memory for the new task.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>textsize</strong> – The size (in bytes) of the <code class="docutils literal notranslate"><span class="pre">.text</span></code> address
environment needed by the task. This region may be read/execute
only.</p></li>
<li><p><strong>datasize</strong> – The size (in bytes) of the <code class="docutils literal notranslate"><span class="pre">.bss/.data</span></code> address
environment needed by the task. This region may be read/write
only.</p></li>
<li><p><strong>heapsize</strong> – The initial size (in bytes) of the heap address
environment needed by the task. This region may be read/write
only.</p></li>
<li><p><strong>addrenv</strong> – The location to return the representation of the
task address environment.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_destroy">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_destroy</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">arch_addrenv_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">addrenv</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_destroy" title="Permalink to this definition"></a><br /></dt>
<dd><p>This function is called when a final thread leaves the task
group and the task group is destroyed. This function then destroys
the defunct address environment, releasing the underlying physical
memory allocated by up_addrenv_create().</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>addrenv</strong> – The representation of the task address environment
previously returned by <code class="docutils literal notranslate"><span class="pre">up_addrenv_create()</span></code>.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_vtext">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_vtext</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="n"><span class="pre">arch_addrenv_t</span></span><span class="w"> </span><span class="n"><span class="pre">addrenv</span></span>, <span class="pre">FAR</span><span class="w"> </span><span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">vtext</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_vtext" title="Permalink to this definition"></a><br /></dt>
<dd><p>Return the virtual .text address associated with the newly create
address environment. This function is used by the binary loaders
in order get an address that can be used to initialize the new task.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>addrenv</strong> – The representation of the task address environment
previously returned by <code class="docutils literal notranslate"><span class="pre">up_addrenv_create()</span></code>.</p></li>
<li><p><strong>vtext</strong> – The location to return the virtual address.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_vdata">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_vdata</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="n"><span class="pre">arch_addrenv_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">addrenv</span></span>, <a class="reference internal" href="../user/structures.html#c.size_t" title="size_t"><span class="n"><span class="pre">size_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">textsize</span></span>, <span class="pre">FAR</span><span class="w"> </span><span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">vdata</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_vdata" title="Permalink to this definition"></a><br /></dt>
<dd><p>Return the virtual .text address associated with the newly create
address environment. This function is used by the binary loaders
in order get an address that can be used to initialize the new task.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>addrenv</strong> – The representation of the task address environment
previously returned by <code class="docutils literal notranslate"><span class="pre">up_addrenv_create()</span></code>.</p></li>
<li><p><strong>textsize</strong> – For some implementations, the text and data will
be saved in the same memory region (read/write/execute) and, in
this case, the virtual address of the data just lies at this
offset into the common region.</p></li>
<li><p><strong>vdata</strong> – The location to return the virtual address.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_heapsize">
<span class="n"><span class="pre">ssize_t</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_heapsize</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="n"><span class="pre">arch_addrenv_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">addrenv</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_heapsize" title="Permalink to this definition"></a><br /></dt>
<dd><p>Return the initial heap allocation size. That is the amount of
memory allocated by up_addrenv_create() when the heap memory
region was first created. This may or may not differ from the
heapsize parameter that was passed to up_addrenv_create().</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>addrenv</strong> – The representation of the task address environment
previously returned by <code class="docutils literal notranslate"><span class="pre">up_addrenv_create()</span></code>.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>The initial heap size allocated is returned on success;
a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_select">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_select</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">arch_addrenv_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">addrenv</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_select" title="Permalink to this definition"></a><br /></dt>
<dd><p>After an address environment has been established for a task
(via up_addrenv_create()), this function may be called to instantiate
that address environment in the virtual address space. This might be
necessary, for example, to load the code for the task from a file or
to access address environment private data.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>addrenv</strong> – The representation of the task address environment
previously returned by <code class="docutils literal notranslate"><span class="pre">up_addrenv_create()</span></code>.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_clone">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_clone</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="n"><span class="pre">task_group_s</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">src</span></span>, <span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">task_group_s</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dest</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_clone" title="Permalink to this definition"></a><br /></dt>
<dd><p>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.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>src</strong> – The address environment to be copied.</p></li>
<li><p><strong>dest</strong> – The location to receive the copied address
environment.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_attach">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_attach</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">task_group_s</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">group</span></span>, <span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><a class="reference internal" href="../user/structures.html#c.tcb_s" title="tcb_s"><span class="n"><span class="pre">tcb_s</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">tcb</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_attach" title="Permalink to this definition"></a><br /></dt>
<dd><p>This function is called from the core scheduler logic when a
thread is created that needs to share the address environment
of its task group. In this case, the group’s address environment
may need to be “cloned” for the child thread.</p>
<p>NOTE: In most platforms, nothing will need to be done in this case.
Simply being a member of the group that has the address environment
may be sufficient.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>group</strong> – The task group to which the new thread belongs.</p></li>
<li><p><strong>ctcb</strong> – The TCB of the thread needing the address
environment.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_detach">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_detach</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">task_group_s</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">group</span></span>, <span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">task_group_s</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">tcb</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_detach" title="Permalink to this definition"></a><br /></dt>
<dd><p>This function is called when a task or thread exits in order
to release its reference to an address environment. The address
environment, however, should persist until up_addrenv_destroy()
is called when the task group is itself destroyed. Any resources
unique to this thread may be destroyed now.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>group</strong> – The group to which the thread belonged.</p></li>
<li><p><strong>tcb</strong> – The TCB of the task or thread whose the address
environment will be released.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_ustackalloc">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_ustackalloc</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><a class="reference internal" href="../user/structures.html#c.tcb_s" title="tcb_s"><span class="n"><span class="pre">tcb_s</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">tcb</span></span>, <a class="reference internal" href="../user/structures.html#c.size_t" title="size_t"><span class="n"><span class="pre">size_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">stacksize</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_ustackalloc" title="Permalink to this definition"></a><br /></dt>
<dd><p>This function is called when a new thread is created in order
to instantiate an address environment for the new thread’s stack.
up_addrenv_ustackalloc() is essentially the allocator of the
physical memory for the new task’s stack.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>tcb</strong> – The TCB of the thread that requires the stack address
environment.</p></li>
<li><p><strong>stacksize</strong> – The size (in bytes) of the initial stack address
environment needed by the task. This region may be read/write
only.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_ustackfree">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_ustackfree</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><a class="reference internal" href="../user/structures.html#c.tcb_s" title="tcb_s"><span class="n"><span class="pre">tcb_s</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">tcb</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_ustackfree" title="Permalink to this definition"></a><br /></dt>
<dd><p>This function is called when any thread exits. This function then
destroys the defunct address environment for the thread’s stack,
releasing the underlying physical memory.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>tcb</strong> – The TCB of the thread that no longer requires the
stack address environment.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_vustack">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_vustack</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><a class="reference internal" href="../user/structures.html#c.tcb_s" title="tcb_s"><span class="n"><span class="pre">tcb_s</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">tcb</span></span>, <span class="pre">FAR</span><span class="w"> </span><span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">vstack</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_vustack" title="Permalink to this definition"></a><br /></dt>
<dd><p>Return the virtual address associated with the newly create stack address environment.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>tcb</strong> – The TCB of the thread with the stack address environment of interest.</p></li>
<li><p><strong>vstack</strong> – The location to return the stack virtual base address.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_ustackselect">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_ustackselect</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><a class="reference internal" href="../user/structures.html#c.tcb_s" title="tcb_s"><span class="n"><span class="pre">tcb_s</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">tcb</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_ustackselect" title="Permalink to this definition"></a><br /></dt>
<dd><p>After an address environment has been established for a task’s
stack (via up_addrenv_ustackalloc(). This function may be called to
instantiate that address environment in the virtual address space.
This is a necessary step before each context switch to the newly
created thread (including the initial thread startup).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>tcb</strong> – The TCB of the thread with the stack address
environment to be instantiated.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_kstackalloc">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_kstackalloc</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><a class="reference internal" href="../user/structures.html#c.tcb_s" title="tcb_s"><span class="n"><span class="pre">tcb_s</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">tcb</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.up_addrenv_kstackalloc" title="Permalink to this definition"></a><br /></dt>
<dd><p>This function is called when a new thread is created to allocate the
new thread’s kernel stack. This function may be called for certain
terminating threads which have no kernel stack. It must be
tolerant of that case.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>tcb</strong> – The TCB of the thread that requires the kernel stack.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.up_addrenv_kstackfree">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">up_addrenv_kstackfree</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><a class="reference internal" href="../user/structures.html#c.tcb_s" title="tcb_s"><span class="n"><span class="pre">tcb_s</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">tcb</span></span><span class="sig-paren">)</span><span class="p"><span class="pre">;</span></span><a class="headerlink" href="#c.up_addrenv_kstackfree" title="Permalink to this definition"></a><br /></dt>
<dd><p>This function is called when any thread exits. This function frees the kernel stack.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>tcb</strong> – The TCB of the thread that no longer requires the
kernel stack.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Zero (OK) on success; a negated errno value on failure.</p>
</dd>
</dl>
</dd></dl>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="index.html" class="btn btn-neutral float-left" title="Architecture APIs" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="app_vs_os.html" class="btn btn-neutral float-right" title="Application OS vs. Internal OS Interfaces" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>&#169; Copyright 2023, The Apache Software Foundation.</p>
</div>
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>