<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re:Risk of infinite loop when using weak_ptr on Windows in Intel® Software Guard Extensions (Intel® SGX)</title>
    <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Risk-of-infinite-loop-when-using-weak-ptr-on-Windows/m-p/1436591#M5578</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This is a bug and the engineering team is working on fixing it. &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;Sahira &lt;/P&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 07 Dec 2022 20:08:22 GMT</pubDate>
    <dc:creator>Sahira_Intel</dc:creator>
    <dc:date>2022-12-07T20:08:22Z</dc:date>
    <item>
      <title>Risk of infinite loop when using weak_ptr on Windows</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Risk-of-infinite-loop-when-using-weak-ptr-on-Windows/m-p/1435699#M5568</link>
      <description>&lt;P&gt;From the disassembler view, it seems the implementation of &lt;FONT face="courier new,courier"&gt;weak_ptr::lock&lt;/FONT&gt; in Windows SGX SDK is similar to the&amp;nbsp;&lt;A href="https://github.com/intel/linux-sgx/blob/master/sdk/tlibcxx/src/memory.cpp#L119" target="_self"&gt;Linux one&lt;/A&gt;&amp;nbsp;:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;__shared_weak_count*
__shared_weak_count::lock() _NOEXCEPT
{
    long object_owners = __libcpp_atomic_load(&amp;amp;__shared_owners_);
    while (object_owners != -1)
    {
        if (__libcpp_atomic_compare_exchange(&amp;amp;__shared_owners_,
                                             &amp;amp;object_owners,
                                             object_owners+1))
            return this;
    }
    return nullptr;
}
&lt;/LI-CODE&gt;
&lt;P&gt;However the compare_exchange function ends up being this piece of code from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;include\libc++\support\win32\atomic.h&lt;/FONT&gt; :&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;template&amp;lt;class _Tp&amp;gt;
static inline bool __atomic_compare_exchange_strong_explicit(volatile _Tp *__val, volatile _Tp *__expected, _Tp __after, int, int)
{
    return _atomic_msvc_wrapper::FetchClass&amp;lt;sizeof(_Tp)&amp;gt;::compare_exchange&amp;lt;_Tp&amp;gt;(__val, *__expected, __after);
}
&lt;/LI-CODE&gt;
&lt;P&gt;This implementation is incorrect, as it loses the feature that if the exchange doesn't happen, the current value of &lt;FONT face="courier new,courier"&gt;__val&lt;/FONT&gt; is written to &lt;FONT face="courier new,courier"&gt;__expected&lt;/FONT&gt;. As a result, if indeed there has been a change between the load on line 4 and the exchange on line 7, &lt;FONT face="courier new,courier"&gt;object_owners&lt;/FONT&gt; is not modified, and the loop continues, possibly forever (if the value doesn't come back to what it was).&lt;/P&gt;
&lt;P&gt;This happens sometimes in our code, during shutdown, when many shared or weak pointers are released concurrently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 08:11:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Risk-of-infinite-loop-when-using-weak-ptr-on-Windows/m-p/1435699#M5568</guid>
      <dc:creator>Jean-Jacques</dc:creator>
      <dc:date>2022-12-05T08:11:07Z</dc:date>
    </item>
    <item>
      <title>Re:Risk of infinite loop when using weak_ptr on Windows</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Risk-of-infinite-loop-when-using-weak-ptr-on-Windows/m-p/1435985#M5571</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have escalated this issue for further feedback and will let you know when I have more information.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;Sahira &lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Dec 2022 01:03:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Risk-of-infinite-loop-when-using-weak-ptr-on-Windows/m-p/1435985#M5571</guid>
      <dc:creator>Sahira_Intel</dc:creator>
      <dc:date>2022-12-06T01:03:23Z</dc:date>
    </item>
    <item>
      <title>Re:Risk of infinite loop when using weak_ptr on Windows</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Risk-of-infinite-loop-when-using-weak-ptr-on-Windows/m-p/1436591#M5578</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This is a bug and the engineering team is working on fixing it. &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;Sahira &lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Dec 2022 20:08:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Risk-of-infinite-loop-when-using-weak-ptr-on-Windows/m-p/1436591#M5578</guid>
      <dc:creator>Sahira_Intel</dc:creator>
      <dc:date>2022-12-07T20:08:22Z</dc:date>
    </item>
  </channel>
</rss>

