Skip to content

Commit

Permalink
task_switch: drop the next TaskRef right before context switch (t…
Browse files Browse the repository at this point in the history
…heseus-os#630)

* `task_switch()` now takes an owned `TaskRef` object for the `next`
  task instead of a `&Task`, which prevents that `next` `TaskRef` object
  from being on the stack frame of the `schedule()` function
  (or whatever other function may call `task_switch() in the future).

* This avoids a rare issue where a task may not be immediately dropped
  upon exiting and being reaped, because a reference to that task might
  still persist as a local variable on a different task's stack,
  due to the way that `schedule()` previously invoked `task_switch()`.

* This also more clearly states our intent in `task_switch()`  by ensuring
  that `next` cannot be invalidly accessed after the context switch
  operation has returned. 0c6afd2
  • Loading branch information
kevinaboos committed Aug 29, 2022
1 parent 421a877 commit 0174917
Show file tree
Hide file tree
Showing 206 changed files with 2,763 additions and 1,001 deletions.
2 changes: 1 addition & 1 deletion doc/context_switch_regular/fn.context_switch_regular.html
Expand Up @@ -5,7 +5,7 @@
</a><div class="sidebar-elems"><h2 class="location"><a href="index.html">In context_switch_regular</a></h2></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../context_switch_regular/index.html"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1">
<a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div>
</div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
<h1 class="fqn"><span class="in-band">Function <a href="index.html">context_switch_regular</a>::<wbr><a class="fn" href="#">context_switch_regular</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/lib.rs.html#112-122">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><pre class="rust fn"><code>pub unsafe extern &quot;C&quot; fn context_switch_regular(<br>&nbsp;&nbsp;&nbsp;&nbsp;_prev_stack_pointer: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.pointer.html">*mut </a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;_next_stack_pointer_value: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a><br>)</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Switches context from a regular Task to another regular Task.</p>
<h1 class="fqn"><span class="in-band">Function <a href="index.html">context_switch_regular</a>::<wbr><a class="fn" href="#">context_switch_regular</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/lib.rs.html#119-129">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><pre class="rust fn"><code>pub unsafe extern &quot;C&quot; fn context_switch_regular(<br>&nbsp;&nbsp;&nbsp;&nbsp;_prev_stack_pointer: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.pointer.html">*mut </a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;_next_stack_pointer_value: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a><br>)</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Switches context from a regular Task to another regular Task.</p>
<h2 id="arguments"><a href="#arguments">Arguments</a></h2>
<ul>
<li>First argument (in <code>RDI</code>): mutable pointer to the previous task’s stack pointer</li>
Expand Down
2 changes: 1 addition & 1 deletion doc/context_switch_regular/index.html
Expand Up @@ -5,7 +5,7 @@
</a><h2 class="location"><a href="#">Crate context_switch_regular</a></h2><div class="sidebar-elems"><div class="block"><ul><li class="version">Version 0.1.0</li><li><a id="all-types" href="all.html">All Items</a></li></ul></div><section><div class="block"><ul><li><a href="#macros">Macros</a></li><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></div></section></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../context_switch_regular/index.html"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1">
<a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div>
</div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
<h1 class="fqn"><span class="in-band">Crate <a class="mod" href="#">context_switch_regular</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/lib.rs.html#1-122">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This crate contains structures and routines for context switching
<h1 class="fqn"><span class="in-band">Crate <a class="mod" href="#">context_switch_regular</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/lib.rs.html#1-129">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This crate contains structures and routines for context switching
when SSE/SIMD extensions are not active. </p>
</div></details><h2 id="macros" class="small-section-header"><a href="#macros">Macros</a></h2>
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.restore_registers_regular.html" title="context_switch_regular::restore_registers_regular macro">restore_registers_regular</a></div><div class="item-right docblock-short"><p>An assembly block for restoring regular x86_64 registers
Expand Down
Expand Up @@ -5,7 +5,7 @@
</a><div class="sidebar-elems"><h2 class="location"><a href="index.html">In context_switch_regular</a></h2></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../context_switch_regular/index.html"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1">
<a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div>
</div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
<h1 class="fqn"><span class="in-band">Macro <a href="index.html">context_switch_regular</a>::<wbr><a class="macro" href="#">restore_registers_regular</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/lib.rs.html#87-100">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><div class="example-wrap"><pre class="rust macro"><code><span class="macro">macro_rules!</span> <span class="ident">restore_registers_regular</span> {
<h1 class="fqn"><span class="in-band">Macro <a href="index.html">context_switch_regular</a>::<wbr><a class="macro" href="#">restore_registers_regular</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/lib.rs.html#94-107">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><div class="example-wrap"><pre class="rust macro"><code><span class="macro">macro_rules!</span> <span class="ident">restore_registers_regular</span> {
() =&gt; { ... };
}</code></pre></div>
</div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An assembly block for restoring regular x86_64 registers
Expand Down
Expand Up @@ -5,7 +5,7 @@
</a><div class="sidebar-elems"><h2 class="location"><a href="index.html">In context_switch_regular</a></h2></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../context_switch_regular/index.html"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1">
<a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div>
</div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
<h1 class="fqn"><span class="in-band">Macro <a href="index.html">context_switch_regular</a>::<wbr><a class="macro" href="#">save_registers_regular</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/lib.rs.html#47-59">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><div class="example-wrap"><pre class="rust macro"><code><span class="macro">macro_rules!</span> <span class="ident">save_registers_regular</span> {
<h1 class="fqn"><span class="in-band">Macro <a href="index.html">context_switch_regular</a>::<wbr><a class="macro" href="#">save_registers_regular</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/lib.rs.html#54-66">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><div class="example-wrap"><pre class="rust macro"><code><span class="macro">macro_rules!</span> <span class="ident">save_registers_regular</span> {
() =&gt; { ... };
}</code></pre></div>
</div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An assembly block for saving regular x86_64 registers
Expand Down
2 changes: 1 addition & 1 deletion doc/context_switch_regular/macro.switch_stacks.html
Expand Up @@ -5,7 +5,7 @@
</a><div class="sidebar-elems"><h2 class="location"><a href="index.html">In context_switch_regular</a></h2></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../context_switch_regular/index.html"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1">
<a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div>
</div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
<h1 class="fqn"><span class="in-band">Macro <a href="index.html">context_switch_regular</a>::<wbr><a class="macro" href="#">switch_stacks</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/lib.rs.html#68-76">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><div class="example-wrap"><pre class="rust macro"><code><span class="macro">macro_rules!</span> <span class="ident">switch_stacks</span> {
<h1 class="fqn"><span class="in-band">Macro <a href="index.html">context_switch_regular</a>::<wbr><a class="macro" href="#">switch_stacks</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/context_switch_regular/lib.rs.html#75-83">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><div class="example-wrap"><pre class="rust macro"><code><span class="macro">macro_rules!</span> <span class="ident">switch_stacks</span> {
() =&gt; { ... };
}</code></pre></div>
</div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An assembly block for switching stacks,
Expand Down

0 comments on commit 0174917

Please sign in to comment.