Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup for firmware installer #8016

Merged
merged 2 commits into from Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions rpcs3/Loader/TAR.cpp
Expand Up @@ -114,9 +114,29 @@ bool tar_object::extract(std::string path, std::string ignore)
{
case '0':
{
auto data = get_file(header.name).release();

if (fs::file prev{result})
{
if (prev.to_vector<u8>() == static_cast<fs::container_stream<std::vector<u8>>*>(data.get())->obj)
{
// Workaround: avoid overwriting existing data if it's the same.
tar_log.notice("TAR Loader: skipped existing file %s", header.name);
break;
}
}

fs::file file(result, fs::rewrite);
file.write(get_file(header.name).to_vector<u8>());
break;

if (file)
{
file.write(static_cast<fs::container_stream<std::vector<u8>>*>(data.get())->obj);
tar_log.notice("TAR Loader: written file %s", header.name);
break;
}

tar_log.error("TAR Loader: failed to write file %s (%s)", header.name, fs::g_tls_error);
return false;
}

case '5':
Expand Down
55 changes: 53 additions & 2 deletions rpcs3/util/atomic.hpp
Expand Up @@ -1176,7 +1176,6 @@ class atomic_with_lock_bit
static_assert(std::is_pointer_v<T> == (BitWidth == 0), "BitWidth should be 0 for pointers");
static_assert(!std::is_pointer_v<T> || (alignof(std::remove_pointer_t<T>) >= 4), "Pointer type should have align 4 or more");

// Use the most significant bit as a mutex
atomic_t<type> m_data;

public:
Expand Down Expand Up @@ -1255,7 +1254,6 @@ class atomic_with_lock_bit
// Try to set dirty bit if not set already
if (!m_data.compare_and_swap_test(old_val, old_val | c_dirty))
{
// Situation changed
continue;
}
}
Expand Down Expand Up @@ -1301,6 +1299,7 @@ class atomic_with_lock_bit
{
if (!m_data.compare_and_swap_test(old_val, old_val | c_dirty))
{
old_val = m_data.load();
continue;
}
}
Expand All @@ -1313,6 +1312,11 @@ class atomic_with_lock_bit
}

void store(T value)
{
static_cast<void>(exchange(value));
}

T exchange(T value)
{
type old_val = m_data.load();

Expand All @@ -1322,13 +1326,59 @@ class atomic_with_lock_bit
{
if (!m_data.compare_and_swap_test(old_val, old_val | c_dirty))
{
old_val = m_data.load();
continue;
}
}

m_data.wait(old_val);
old_val = m_data.load();
}

return reinterpret_cast<T>(clamp_value(old_val));
}

T compare_and_swap(T cmp, T exch)
{
static_cast<void>(compare_exchange(cmp, exch));
return cmp;
}

bool compare_and_swap_test(T cmp, T exch)
{
return compare_exchange(cmp, exch);
}

bool compare_exchange(T& cmp_and_old, T exch)
{
type old_val = m_data.load();
type expected = clamp_value(reinterpret_cast<type>(cmp_and_old));
type new_val = clamp_value(reinterpret_cast<type>(exch));

while (is_locked(old_val) || (old_val == expected && !m_data.compare_and_swap_test(expected, new_val))) [[unlikely]]
{
if (old_val == expected)
{
old_val = m_data.load();
continue;
}

if ((old_val & c_dirty) == 0)
{
if (!m_data.compare_and_swap_test(old_val, old_val | c_dirty))
{
old_val = m_data.load();
continue;
}
}

m_data.wait(old_val);
old_val = m_data.load();
}

cmp_and_old = reinterpret_cast<T>(clamp_value(old_val));

return clamp_value(old_val) == expected;
}

template <typename F, typename RT = std::invoke_result_t<F, T&>>
Expand All @@ -1345,6 +1395,7 @@ class atomic_with_lock_bit
{
if (!m_data.compare_and_swap_test(old, old | c_dirty))
{
old = m_data.load();
continue;
}
}
Expand Down