From e49ac15049340156ea6dca54b8243e2049e416b3 Mon Sep 17 00:00:00 2001 From: spectranator Date: Sun, 28 Apr 2024 23:23:39 +0200 Subject: [PATCH 01/27] Updated logo and name in preparation for flatpak --- CMakeLists.txt | 8 +-- ....desktop => onion.torzu_emu.torzu.desktop} | 6 +- dist/onion.torzu_emu.torzu.metainfo.xml | 46 ++++++++++++++ ...emu.yuzu.xml => onion.torzu_emu.torzu.xml} | 8 +-- dist/org.yuzu_emu.yuzu.metainfo.xml | 62 ------------------- src/yuzu/about_dialog.cpp | 2 +- src/yuzu/main.cpp | 2 +- 7 files changed, 59 insertions(+), 75 deletions(-) rename dist/{org.yuzu_emu.yuzu.desktop => onion.torzu_emu.torzu.desktop} (87%) create mode 100644 dist/onion.torzu_emu.torzu.metainfo.xml rename dist/{org.yuzu_emu.yuzu.xml => onion.torzu_emu.torzu.xml} (86%) delete mode 100644 dist/org.yuzu_emu.yuzu.metainfo.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d03990224..b5f26af545 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -712,13 +712,13 @@ endif() # https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html # https://www.freedesktop.org/software/appstream/docs/ if(ENABLE_QT AND UNIX AND NOT APPLE) - install(FILES "dist/org.yuzu_emu.yuzu.desktop" + install(FILES "dist/onion.torzu_emu.torzu.desktop" DESTINATION "share/applications") install(FILES "dist/yuzu.svg" DESTINATION "share/icons/hicolor/scalable/apps" - RENAME "org.yuzu_emu.yuzu.svg") - install(FILES "dist/org.yuzu_emu.yuzu.xml" + RENAME "onion.torzu_emu.torzu.svg") + install(FILES "dist/onion.torzu_emu.torzu.xml" DESTINATION "share/mime/packages") - install(FILES "dist/org.yuzu_emu.yuzu.metainfo.xml" + install(FILES "dist/onion.torzu_emu.torzu.metainfo.xml" DESTINATION "share/metainfo") endif() diff --git a/dist/org.yuzu_emu.yuzu.desktop b/dist/onion.torzu_emu.torzu.desktop similarity index 87% rename from dist/org.yuzu_emu.yuzu.desktop rename to dist/onion.torzu_emu.torzu.desktop index 51e191a8e5..55b389d80c 100644 --- a/dist/org.yuzu_emu.yuzu.desktop +++ b/dist/onion.torzu_emu.torzu.desktop @@ -4,13 +4,13 @@ [Desktop Entry] Version=1.0 Type=Application -Name=yuzu +Name=torzu GenericName=Switch Emulator Comment=Nintendo Switch video game console emulator -Icon=org.yuzu_emu.yuzu +Icon=onion.torzu_emu.torzu TryExec=yuzu Exec=yuzu %f Categories=Game;Emulator;Qt; MimeType=application/x-nx-nro;application/x-nx-nso;application/x-nx-nsp;application/x-nx-xci; Keywords=Nintendo;Switch; -StartupWMClass=yuzu +StartupWMClass=torzu diff --git a/dist/onion.torzu_emu.torzu.metainfo.xml b/dist/onion.torzu_emu.torzu.metainfo.xml new file mode 100644 index 0000000000..baecbff0b8 --- /dev/null +++ b/dist/onion.torzu_emu.torzu.metainfo.xml @@ -0,0 +1,46 @@ + + + + + + onion.torzu_emu.torzu + CC0-1.0 + Torzu + Nintendo Switch emulator + +

yuzu is the world's most popular, open-source, Nintendo Switch emulator — started by the creators of Citra.

+

The emulator is capable of running most commercial games at full speed, provided you meet the necessary hardware requirements.

+
+ + Game + Emulator + + + switch + emulator + + http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu/issues + http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu + onion.torzu_emu.torzu.desktop + + yuzu + yuzu-cmd + + + pointing + keyboard + gamepad + + + 8192 + + + 16384 + + GPL-3.0-or-later + yuzu Emulator Team + +
diff --git a/dist/org.yuzu_emu.yuzu.xml b/dist/onion.torzu_emu.torzu.xml similarity index 86% rename from dist/org.yuzu_emu.yuzu.xml rename to dist/onion.torzu_emu.torzu.xml index b774eb0c4e..6e38c7e084 100644 --- a/dist/org.yuzu_emu.yuzu.xml +++ b/dist/onion.torzu_emu.torzu.xml @@ -9,7 +9,7 @@ SPDX-License-Identifier: GPL-2.0-or-later Nintendo Switch homebrew executable NRO - + @@ -17,7 +17,7 @@ SPDX-License-Identifier: GPL-2.0-or-later Nintendo Switch homebrew executable NSO - + @@ -25,7 +25,7 @@ SPDX-License-Identifier: GPL-2.0-or-later Nintendo Switch Package NSP - + @@ -33,7 +33,7 @@ SPDX-License-Identifier: GPL-2.0-or-later Nintendo Switch Card Image XCI - + diff --git a/dist/org.yuzu_emu.yuzu.metainfo.xml b/dist/org.yuzu_emu.yuzu.metainfo.xml deleted file mode 100644 index cfd1741748..0000000000 --- a/dist/org.yuzu_emu.yuzu.metainfo.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - org.yuzu_emu.yuzu - CC0-1.0 - yuzu - Nintendo Switch emulator - -

yuzu is the world's most popular, open-source, Nintendo Switch emulator — started by the creators of Citra.

-

The emulator is capable of running most commercial games at full speed, provided you meet the necessary hardware requirements.

-

For a full list of games yuzu support, please visit our Compatibility page.

-

Check out our website for the latest news on exciting features, monthly progress reports, and more!

-
- - Game - Emulator - - - switch - emulator - - https://yuzu-emu.org/ - https://github.com/yuzu-emu/yuzu/issues - https://yuzu-emu.org/wiki/faq/ - https://yuzu-emu.org/wiki/home/ - https://yuzu-emu.org/donate/ - https://www.transifex.com/projects/p/yuzu - https://community.citra-emu.org/ - https://github.com/yuzu-emu/yuzu - https://yuzu-emu.org/wiki/contributing/ - org.yuzu_emu.yuzu.desktop - - yuzu - yuzu-cmd - - - pointing - keyboard - gamepad - - - 8192 - - - 16384 - - GPL-3.0-or-later - yuzu Emulator Team - - - https://raw.githubusercontent.com/yuzu-emu/yuzu-emu.github.io/master/images/screenshots/001-Super%20Mario%20Odyssey%20.png - https://raw.githubusercontent.com/yuzu-emu/yuzu-emu.github.io/master/images/screenshots/004-The%20Legend%20of%20Zelda%20Skyward%20Sword%20HD.png - https://raw.githubusercontent.com/yuzu-emu/yuzu-emu.github.io/master/images/screenshots/007-Pokemon%20Sword.png - https://raw.githubusercontent.com/yuzu-emu/yuzu-emu.github.io/master/images/screenshots/010-Hyrule%20Warriors%20Age%20of%20Calamity.png - https://raw.githubusercontent.com/yuzu-emu/yuzu-emu.github.io/master/images/screenshots/039-Pok%C3%A9mon%20Mystery%20Dungeon%20Rescue%20Team%20DX.png.png.png - -
diff --git a/src/yuzu/about_dialog.cpp b/src/yuzu/about_dialog.cpp index eeff543599..61a6efc7c8 100644 --- a/src/yuzu/about_dialog.cpp +++ b/src/yuzu/about_dialog.cpp @@ -20,7 +20,7 @@ AboutDialog::AboutDialog(QWidget* parent) ui->setupUi(this); // Try and request the icon from Qt theme (Linux?) - const QIcon yuzu_logo = QIcon::fromTheme(QStringLiteral("org.yuzu_emu.yuzu")); + const QIcon yuzu_logo = QIcon::fromTheme(QStringLiteral("onion.torzu_emu.torzu")); if (!yuzu_logo.isNull()) { ui->labelLogo->setPixmap(yuzu_logo.pixmap(200)); } diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 3d38fb258c..62114aa57a 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -5292,7 +5292,7 @@ int main(int argc, char* argv[]) { // Fix the Wayland appId. This needs to match the name of the .desktop file without the .desktop // suffix. - QGuiApplication::setDesktopFileName(QStringLiteral("org.yuzu_emu.yuzu")); + QGuiApplication::setDesktopFileName(QStringLiteral("onion.torzu_emu.torzu")); #endif SetHighDPIAttributes(); From 934d816fd63ef279cef5b8f7e363739505603e23 Mon Sep 17 00:00:00 2001 From: spectranator Date: Mon, 29 Apr 2024 00:17:17 +0200 Subject: [PATCH 02/27] Changed about dialog and main window titles --- src/yuzu/aboutdialog.ui | 37 +++++++++++++++++++++++++++++-------- src/yuzu/main.cpp | 2 +- src/yuzu/main.ui | 2 +- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/yuzu/aboutdialog.ui b/src/yuzu/aboutdialog.ui index aea82809d0..9ea07f7884 100644 --- a/src/yuzu/aboutdialog.ui +++ b/src/yuzu/aboutdialog.ui @@ -69,7 +69,7 @@ - <html><head/><body><p><span style=" font-size:28pt;">yuzu</span></p></body></html> + <html><head/><body><p><span style=" font-size:28pt;">torzu</span></p></body></html> @@ -96,11 +96,13 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:12pt;">yuzu is an experimental open-source emulator for the Nintendo Switch licensed under GPLv3.0+.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8pt;"><br /></p> +hr { height: 1px; border-width: 0; } +li.unchecked::marker { content: "\2610"; } +li.checked::marker { content: "\2612"; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:12pt;">torzu is an experimental open-source emulator for the Nintendo Switch forked from yuzu and licensed under GPLv3.0+.</span></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:12pt;">This software should not be used to play games you have not legally obtained.</span></p></body></html> @@ -127,7 +129,7 @@ p, li { white-space: pre-wrap; } - <html><head/><body><p><a href="https://yuzu-emu.org/"><span style=" text-decoration: underline; color:#039be5;">Website</span></a> | <a href="https://github.com/yuzu-emu"><span style=" text-decoration: underline; color:#039be5;">Source Code</span></a> | <a href="https://github.com/yuzu-emu/yuzu/graphs/contributors"><span style=" text-decoration: underline; color:#039be5;">Contributors</span></a> | <a href="https://github.com/yuzu-emu/yuzu/blob/master/LICENSE.txt"><span style=" text-decoration: underline; color:#039be5;">License</span></a></p></body></html> + <html><head/><body><p><a href="http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu"><span style=" text-decoration: underline; color:#039be5;">Source Code</span></a> | <a href="https://github.com/litucks/torzu/graphs/contributors"><span style=" text-decoration: underline; color:#039be5;">Contributors</span></a> | <a href="http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu/src/branch/master/LICENSE.txt"><span style=" text-decoration: underline; color:#039be5;">License</span></a></p></body></html> true @@ -143,7 +145,7 @@ p, li { white-space: pre-wrap; } - <html><head/><body><p><span style=" font-size:7pt;">&quot;Nintendo Switch&quot; is a trademark of Nintendo. yuzu is not affiliated with Nintendo in any way.</span></p></body></html> + <html><head/><body><p><span style=" font-size:6pt;">&quot;Nintendo Switch&quot; is a trademark of Nintendo. torzu is not affiliated with Nintendo in any way.</span></p></body></html> @@ -164,7 +166,6 @@ p, li { white-space: pre-wrap; } - @@ -173,12 +174,32 @@ p, li { white-space: pre-wrap; } accepted() AboutDialog accept() + + + 20 + 20 + + + 20 + 20 + + buttonBox rejected() AboutDialog reject() + + + 20 + 20 + + + 20 + 20 + + diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 62114aa57a..6ff14063e7 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -4544,7 +4544,7 @@ void GMainWindow::UpdateWindowTitle(std::string_view title_name, std::string_vie const auto description = std::string(Common::g_scm_desc); const auto build_id = std::string(Common::g_build_id); - const auto yuzu_title = fmt::format("yuzu | {}-{}", branch_name, description); + const auto yuzu_title = fmt::format("torzu | {}-{}", branch_name, description); const auto override_title = fmt::format(fmt::runtime(std::string(Common::g_title_bar_format_idle)), build_id); const auto window_title = override_title.empty() ? yuzu_title : override_title; diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index 5b8bb44056..dfe025ca61 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui @@ -242,7 +242,7 @@ - &About yuzu + &About torzu From f05ffb6b05198cfec4789b06562c576a30cd2827 Mon Sep 17 00:00:00 2001 From: spectranator Date: Mon, 6 May 2024 00:32:53 +0200 Subject: [PATCH 03/27] Added changelog to README --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d1c8890e20..eb6f5d9ccf 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,16 @@ The emulator is capable of running most commercial games at full speed, provided It runs most Nintendo Switch games released until the date of the Yuzu takedown. +## Changes + +Following are the changes made since forking from Yuzu: + + - Added option to optimize generated SPIR-V shaders via spirv-opt + - Added option to synchronize CPU clock to render speed limit + - Added option to launch home menu from Switch firmware + - Fixed crash when switching away from null graphics per-game + - Minor improvements and additions + ## Development Most of the development happens on [Dark Git](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/). It's also where [our central repository](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu) is hosted. @@ -63,7 +73,7 @@ This project incorporates several commits from the [Suyu](https://suyu.dev) and ## Download -There are no precompiled releases available (yet). +Precompiled build are available **in the releases section**. ## License From f890dbb06419674be3c037d9b48de6c37626e48d Mon Sep 17 00:00:00 2001 From: spectranator Date: Mon, 6 May 2024 00:33:52 +0200 Subject: [PATCH 04/27] Mention next mirror location in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb6f5d9ccf..0c8738b166 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Alternatively, you can clone from the [GitHub mirror repository](https://github. git clone https://github.com/litucks/torzu.git --depth 1 --recursive -Note that above repository may be taken down any time. Do not rely on its existence in production. +Note that above repository may be taken down any time. Do not rely on its existence in production. In case the GitHub mirror goes down, a mirror will be set up on Gitlab. This project incorporates several commits from the [Suyu](https://suyu.dev) and [Sudachi](https://github.com/sudachi-emu/sudachi) forks (but cleaned up due to the typically mediocre code/commit quality from both projects) as well as some custom changes, including lowered minimum boost library version requirements and faster fibers. From b6e8e0453386c35e42e457aa53cee314201fb015 Mon Sep 17 00:00:00 2001 From: spectranator Date: Mon, 6 May 2024 00:38:49 +0200 Subject: [PATCH 05/27] Fixed SVG logo rendering black on certain renderers --- dist/yuzu.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/yuzu.svg b/dist/yuzu.svg index 3ba9254ab5..de64431282 100644 --- a/dist/yuzu.svg +++ b/dist/yuzu.svg @@ -1,2 +1,2 @@ - + From 37e53d50bb64c233eca6ac18bd8b71b86b52cbc9 Mon Sep 17 00:00:00 2001 From: spectranator Date: Mon, 6 May 2024 00:47:02 +0200 Subject: [PATCH 06/27] Clarified recompiler work in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c8738b166..28e9c7214f 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Following are the changes made since forking from Yuzu: Most of the development happens on [Dark Git](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/). It's also where [our central repository](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu) is hosted. -Currently, development is limited to external commits as I'm working on implementing a faster recompiler! This will increase emulation speed in CPU-bound scenarios. +Currently, development is somewhat limited to external commits as I'm working on improvements in dynarmic! This will increase emulation speed in CPU-bound scenarios. If you want to contribute, please take a look at the [Contributor's Guide](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu/wiki/Contributing) and [Developer Information](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu/wiki/Developer-Information). From b242ac022c6648b0669af1363a38f3c23ea283e8 Mon Sep 17 00:00:00 2001 From: spectranator Date: Mon, 6 May 2024 01:12:46 +0200 Subject: [PATCH 07/27] Fixed controller UI being cut off at the bottom --- README.md | 1 + .../configuration/configure_input_player.ui | 6081 +++++++++-------- 2 files changed, 3059 insertions(+), 3023 deletions(-) diff --git a/README.md b/README.md index 28e9c7214f..3ae1b949f2 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ Following are the changes made since forking from Yuzu: - Added option to synchronize CPU clock to render speed limit - Added option to launch home menu from Switch firmware - Fixed crash when switching away from null graphics per-game + - Fixed controller UI being cut off at the bottom - Minor improvements and additions ## Development diff --git a/src/yuzu/configuration/configure_input_player.ui b/src/yuzu/configuration/configure_input_player.ui index 5518cccd1d..697ef51aff 100644 --- a/src/yuzu/configuration/configure_input_player.ui +++ b/src/yuzu/configuration/configure_input_player.ui @@ -6,8 +6,8 @@ 0 0 - 780 - 487 + 1098 + 696 @@ -216,3011 +216,1954 @@ - - - - 0 - 0 - + + + true - - - QLayout::SetMinimumSize + + + + 0 + 0 + 1080 + 673 + - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 + + + + + + 0 + 0 + - - QLayout::SetDefaultConstraint - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - Left Stick - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - 0 - - - QLayout::SetDefaultConstraint - - - 3 - - - 6 - - - 3 - - - 0 - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - Up - - - Qt::AlignCenter - - - false - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Up - - - - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - - - - 3 - - - - - Left - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Left - - - - - - - - - - Right - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Right - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - Down - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Down - - - - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - - - - 3 - - - - - Pressed - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Pressed - - - - - - - - - - Modifier - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Modifier - - - - - - - - - - Range - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 21 - - - - - 68 - 16777215 - - - - % - - - 25 - - - 150 - - - 95 - - - - - - - - - - - - 3 - - - QLayout::SetDefaultConstraint - - - 0 - - - 2 - - - 0 - - - 3 - - - - - - - Deadzone: 0% - - - Qt::AlignHCenter - - - - - - - - - 100 - - - Qt::Horizontal - - - - - - - - - Modifier Range: 0% - - - Qt::AlignHCenter - - - - - - - - - 100 - - - Qt::Horizontal - - - - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - 0 - 0 - - - - D-Pad - - - false - - - false - - - - 0 - - - 3 - - - 6 - - - 3 - - - 3 - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - Up - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Up - - - - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - - - - 3 - - - - - Left - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Left - - - - - - - - - - Right - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Right - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - Down - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Down - - - - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 3 - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - SL - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - SL - - - - - - - - - - SR - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - SR - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 0 - 20 - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - L - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - L - - - - - - - - - - - 0 - 0 - - - - ZL - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - ZL - - - - - - - - 70 - 15 - - - - 100 - - - Qt::Horizontal - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 0 - 20 - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Minus - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Minus - - - - - - - - - - Capture - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Capture - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Plus - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Plus - - - - - - - - - - Home - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Home - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 0 - 20 - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - R - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - R - - - - - - - - - - - 0 - 0 - - - - ZR - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - ZR - - - - - - - - 70 - 15 - - - - 100 - - - Qt::Horizontal - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 0 - 20 - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - SL - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - SL - - - - - - - - - - SR - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - SR - - - - - - - - - - - + + + QLayout::SetMinimumSize + + + 0 + + + 0 + + + 0 + + + 0 + - - - - 0 - 0 + + + + 0 + + + QLayout::SetDefaultConstraint + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 - - - - 75 - true - - - - image: url(:/controller/pro); - - + + + Left Stick + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + 0 + + + QLayout::SetDefaultConstraint + - 0 + 3 - 0 + 6 - 0 + 3 - 0 + 0 - - + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + Up + + + Qt::AlignCenter + + + false + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Up + + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + + 3 + + + + + Left + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Left + + + + + + + + + + Right + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Right + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + Down + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Down + + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + + 3 + + + + + Pressed + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Pressed + + + + + + + + + + Modifier + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Modifier + + + + + + + + + + Range + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 68 + 21 + + + + + 68 + 16777215 + + + + % + + + 25 + + + 150 + + + 95 + + + + + + + + + + + + 3 + + + QLayout::SetDefaultConstraint + + + 0 + + + 2 + + + 0 + + + 3 + + + + + + + Deadzone: 0% + + + Qt::AlignHCenter + + + + + + + + + 100 + + + Qt::Horizontal + + + + + + + + + Modifier Range: 0% + + + Qt::AlignHCenter + + + + + + + + + 100 + + + Qt::Horizontal + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::MinimumExpanding + + + + 20 + 0 + + + + + + + + + 0 + 0 + + + + D-Pad + + + false + + + false + + + + 0 + + + 3 + + + 6 + + + 3 + + + 3 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + Up + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Up + + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + + 3 + + + + + Left + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Left + + + + + + + + + + Right + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Right + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + Down + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Down + + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + - - - - 3 - - - 0 - - - - - Qt::Horizontal + + + + + 6 - - - 20 - 20 - + + 0 - - - - - - Motion 1 + + 0 - - Qt::AlignCenter + + 0 - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Left - - - - - - - - - - Motion 2 + + 0 - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Right - - - - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - Face Buttons - - - false - - - false - - - - 0 - - - 3 - - - 6 - - - 3 - - - 3 - - - - + + - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - X - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - X - - - - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - - - - 3 - - - - - Y - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Y - - - - - - - - - - A - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - A - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - B - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - B - - - - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - 0 - 0 - - - - Right Stick - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - false - - - false - - - - 0 - - - 3 - - - 6 - - - 3 - - - 0 - - - - - - 0 - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - Up - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Up - - - - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - - - - 3 - - - - - Left - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Left - - - - - - - - - - Right - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Right - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - Down - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Down - - - - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - - - - 3 - - - - - Pressed - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Pressed - - - - - - - - - - Modifier - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Modifier - - - - - - - - - - Range - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 21 - - - - - 68 - 16777215 - - - - % - - - 25 - - - 150 - - - 95 - - - - - - - - - - - - 3 - - - 0 - - - 2 - - - 0 - - - 3 - - - - - - - Deadzone: 0% - - - Qt::AlignHCenter - - - - - - - - - 100 - - - Qt::Horizontal - - - - - - - - - Modifier Range: 0% - - - Qt::AlignHCenter - - - - - - - - - 100 - - - Qt::Horizontal - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - 3 - + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + SL + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + SL + + + + + + + + + + SR + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + SR + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + L + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + L + + + + + + + + + + + 0 + 0 + + + + ZL + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + ZL + + + + + + + + 70 + 15 + + + + 100 + + + Qt::Horizontal + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Minus + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Minus + + + + + + + + + + Capture + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Capture + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Plus + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Plus + + + + + + + + + + Home + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Home + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + R + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + R + + + + + + + + + + + 0 + 0 + + + + ZR + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + ZR + + + + + + + + 70 + 15 + + + + 100 + + + Qt::Horizontal + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + SL + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + SL + + + + + + + + + + SR + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + SR + + + + + + + + + + + + + + + + 0 + 0 + + + + + true + + + + image: url(:/controller/pro); + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 3 + + + 0 + + + Qt::Horizontal @@ -3233,14 +2176,14 @@ - + - Mouse panning + Motion 1 Qt::AlignCenter - + 3 @@ -3257,9 +2200,24 @@ 3 - + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + - Configure + Left @@ -3267,7 +2225,56 @@ - + + + Motion 2 + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Right + + + + + + + + Qt::Horizontal @@ -3280,44 +2287,1072 @@ - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Face Buttons + + + false + + + false + + + + 0 + + + 3 + + + 6 + + + 3 + + + 3 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + X + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + X + + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + + 3 + + + + + Y + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Y + + + + + + + + + + A + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + A + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + B + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + B + + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::MinimumExpanding + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + 0 + 0 + + + + Right Stick + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + false + + + + 0 + + + 3 + + + 6 + + + 3 + + + 0 + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + Up + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Up + + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + + 3 + + + + + Left + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Left + + + + + + + + + + Right + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Right + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + Down + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Down + + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + + 3 + + + + + Pressed + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Pressed + + + + + + + + + + Modifier + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Modifier + + + + + + + + + + Range + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 68 + 21 + + + + + 68 + 16777215 + + + + % + + + 25 + + + 150 + + + 95 + + + + + + + + + + + + 3 + + + 0 + + + 2 + + + 0 + + + 3 + + + + + + + Deadzone: 0% + + + Qt::AlignHCenter + + + + + + + + + 100 + + + Qt::Horizontal + + + + + + + + + Modifier Range: 0% + + + Qt::AlignHCenter + + + + + + + + + 100 + + + Qt::Horizontal + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 3 + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + Mouse panning + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + Configure + + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + + + + - - - PlayerControlPreview - QFrame -
yuzu/configuration/configure_input_player_widget.h
- 1 -
-
- - - + + + PlayerControlPreview + QFrame +
yuzu/configuration/configure_input_player_widget.h
+ 1 +
+
+ From c1449cca64f23ec3eec4104caf830c5c101cd6a2 Mon Sep 17 00:00:00 2001 From: darktux Date: Mon, 6 May 2024 07:01:28 +0200 Subject: [PATCH 08/27] Changed misleading header statememt regarding Citra developers --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ae1b949f2..73ed65a7cd 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
-

torzu is a fork of yuzu, the world's most popular, open-source, Nintendo Switch emulator — started by the creators of Citra. +

torzu is a fork of yuzu, the world's most popular, open-source, Nintendo Switch emulator.
It is written in C++ with portability in mind, and I plan to actively maintain builds for Linux, Android and Windows.

From f7f1114ec1768c0c3335650602a41b0c50b76871 Mon Sep 17 00:00:00 2001 From: darktux Date: Mon, 6 May 2024 07:03:03 +0200 Subject: [PATCH 09/27] Don't use SVG in README because of rendering issue --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 73ed65a7cd..75bf722ad1 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ SPDX-License-Identifier: GPL-2.0-or-later


- torzu + torzu
torzu
From bddfb77343faadb59c90aedbd892b807c9141a85 Mon Sep 17 00:00:00 2001 From: darktux Date: Mon, 6 May 2024 07:28:15 +0200 Subject: [PATCH 10/27] Added words about project goals to README --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 75bf722ad1..5b9418ac66 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,16 @@ Following are the changes made since forking from Yuzu: - Fixed controller UI being cut off at the bottom - Minor improvements and additions +## Goals + +The first and foremost goal is long-term maintenance. Even if I stop commiting new features I will always do my best to keep the emulator functional and third party dependencies updated. This also means most of the changes made will eventually be bug fixes. +Essentially, the main goal is that you can still use this emulator on modern systems in 20 years. +It is very important to me that this project is going to be a good base to fork once grass has grown over the whole legal dilemma and people are willing to do real work on this emulator non-anonymously. + +While the main platform is Linux as it is the main operating system I run on my personal and development desktops, Windows support is planned and will not be forgotten about. Android support is low priority but would be a nice bonus. + +A secondary goal is the improvement of usability on low-end systems. This includes both improving the performance of the emulator as well as making games more playable below 100% speed whenever possible (the sync CPU to render speed limit option already helps with that in few cases). + ## Development Most of the development happens on [Dark Git](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/). It's also where [our central repository](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu) is hosted. From 82fce02827f794d40c0672ef4173b405f4914d81 Mon Sep 17 00:00:00 2001 From: spectranator Date: Mon, 6 May 2024 21:04:31 +0200 Subject: [PATCH 11/27] Do not build SPIRV-Tools executables --- externals/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index ab637b3f09..8b8eea908f 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -168,6 +168,7 @@ endif() # SPIRV-Tools if (YUZU_USE_EXTERNAL_VULKAN_SPIRV_TOOLS) + set(SPIRV_SKIP_EXECUTABLES ON) add_subdirectory(SPIRV-Tools) endif() From 12ccc468f462eb176e134f69eb2611b99d189e0a Mon Sep 17 00:00:00 2001 From: spectranator Date: Mon, 6 May 2024 21:54:38 +0200 Subject: [PATCH 12/27] Download precompiled Windows blobs from yuzu-mirror --- CMakeModules/DownloadExternals.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeModules/DownloadExternals.cmake b/CMakeModules/DownloadExternals.cmake index a52148bd8f..d22e021e8e 100644 --- a/CMakeModules/DownloadExternals.cmake +++ b/CMakeModules/DownloadExternals.cmake @@ -7,7 +7,7 @@ # prefix_var: name of a variable which will be set with the path to the extracted contents function(download_bundled_external remote_path lib_name prefix_var) -set(package_base_url "https://github.com/yuzu-emu/") +set(package_base_url "https://github.com/yuzu-mirror/") set(package_repo "no_platform") set(package_extension "no_platform") if (WIN32) From 4ebd9dc2b5a3a95958a3474f615e8788b14ad468 Mon Sep 17 00:00:00 2001 From: spectranator Date: Mon, 6 May 2024 23:30:50 +0200 Subject: [PATCH 13/27] Readd MSWSOCK_LIBRARY for MINGW --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5f26af545..512306e97b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -344,6 +344,11 @@ if (YUZU_TESTS) find_package(Catch2 3.0.1 REQUIRED) endif() +# boost:asio has functions that require AcceptEx et al +if (MINGW) + find_library(MSWSOCK_LIBRARY mswsock REQUIRED) +endif() + if(ENABLE_OPENSSL) find_package(OpenSSL 1.1.1 REQUIRED) endif() From 4821698cd8060cc6ed6f366b0f3dddc28ebda1f6 Mon Sep 17 00:00:00 2001 From: darktux Date: Tue, 7 May 2024 16:18:03 +0200 Subject: [PATCH 14/27] Mention analytics and authentication code removal in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5b9418ac66..0f3bbeb0df 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Following are the changes made since forking from Yuzu: - Added option to launch home menu from Switch firmware - Fixed crash when switching away from null graphics per-game - Fixed controller UI being cut off at the bottom + - Removed analytics and authentication as they'd be useless (perhaps even outright dangerous) now - Minor improvements and additions ## Goals From 5097c6a0b9dadf3e6376e1e97290f1fbf62fabd3 Mon Sep 17 00:00:00 2001 From: darktux Date: Tue, 7 May 2024 16:26:38 +0200 Subject: [PATCH 15/27] Updated README: Building for Windows is now possible --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0f3bbeb0df..ce8e87bd28 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ The first and foremost goal is long-term maintenance. Even if I stop commiting n Essentially, the main goal is that you can still use this emulator on modern systems in 20 years. It is very important to me that this project is going to be a good base to fork once grass has grown over the whole legal dilemma and people are willing to do real work on this emulator non-anonymously. -While the main platform is Linux as it is the main operating system I run on my personal and development desktops, Windows support is planned and will not be forgotten about. Android support is low priority but would be a nice bonus. +While the main platform is Linux as it is the main operating system I run on my personal and development desktops, Windows support is very near and will not be forgotten about. Android support is low priority but would be a nice bonus. A secondary goal is the improvement of usability on low-end systems. This includes both improving the performance of the emulator as well as making games more playable below 100% speed whenever possible (the sync CPU to render speed limit option already helps with that in few cases). @@ -77,15 +77,16 @@ This project incorporates several commits from the [Suyu](https://suyu.dev) and ## Building * __Linux__: [Linux Build](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu/wiki/Building-for-Linux) -* ~~__Windows__: [Windows Build](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu/wiki/Building-for-Windows)~~ +* __Windows__: [Windows Build](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu/wiki/Building-for-Windows) * ~~__Android__: [Android Build](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu/wiki/Building-For-Android)~~ * ~~__macOS__: [macOS Build](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu/wiki/Building-for-macOS)~~ -(Only Linux builds are available for now. Next planned are Windows, then Android.) +(Only Linux and Windows builds are available for now. Android is planned eventually.) ## Download Precompiled build are available **in the releases section**. +Windows builds have not been released yet but will very soon. ## License From 1df1841ad1233dcc6d037a5ddf45fafbe4f1552f Mon Sep 17 00:00:00 2001 From: spectranator Date: Tue, 7 May 2024 18:57:50 +0200 Subject: [PATCH 16/27] Disabled problematic MSVC warning-to-errors --- src/CMakeLists.txt | 2 -- src/audio_core/CMakeLists.txt | 2 -- src/common/CMakeLists.txt | 2 -- src/core/CMakeLists.txt | 2 -- src/hid_core/CMakeLists.txt | 2 -- src/input_common/CMakeLists.txt | 1 - src/shader_recompiler/CMakeLists.txt | 1 - src/video_core/CMakeLists.txt | 7 +------ 8 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 697a9ab970..71f5773c50 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -62,12 +62,10 @@ if (MSVC) # Warnings /W4 - /WX /we4062 # Enumerator 'identifier' in a switch of enum 'enumeration' is not handled /we4189 # 'identifier': local variable is initialized but not referenced /we4265 # 'class': class has virtual functions, but destructor is not virtual - /we4388 # 'expression': signed/unsigned mismatch /we4389 # 'operator': signed/unsigned mismatch /we4456 # Declaration of 'identifier' hides previous local declaration /we4457 # Declaration of 'identifier' hides function parameter diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 4e4ed1789f..381df19ff2 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -212,8 +212,6 @@ add_library(audio_core STATIC if (MSVC) target_compile_options(audio_core PRIVATE - /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data - /we4244 # 'conversion': conversion from 'type1' to 'type2', possible loss of data /we4245 # 'conversion': conversion from 'type1' to 'type2', signed/unsigned mismatch /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data /we4800 # Implicit conversion from 'type' to bool. Possible information loss diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 796ffc26b1..3ecbd5a0d0 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -233,8 +233,6 @@ if (MSVC) _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING ) target_compile_options(common PRIVATE - /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data - /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data /we4800 # Implicit conversion from 'type' to bool. Possible information loss ) else() diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 81b79abc58..d67ca881b9 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1144,8 +1144,6 @@ add_library(core STATIC if (MSVC) target_compile_options(core PRIVATE - /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data - /we4244 # 'conversion': conversion from 'type1' to 'type2', possible loss of data /we4245 # 'conversion': conversion from 'type1' to 'type2', signed/unsigned mismatch /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data /we4800 # Implicit conversion from 'type' to bool. Possible information loss diff --git a/src/hid_core/CMakeLists.txt b/src/hid_core/CMakeLists.txt index 2699e1599e..98464fbccb 100644 --- a/src/hid_core/CMakeLists.txt +++ b/src/hid_core/CMakeLists.txt @@ -141,8 +141,6 @@ add_library(hid_core STATIC if (MSVC) target_compile_options(hid_core PRIVATE - /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data - /we4244 # 'conversion': conversion from 'type1' to 'type2', possible loss of data /we4245 # 'conversion': conversion from 'type1' to 'type2', signed/unsigned mismatch /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data /we4800 # Implicit conversion from 'type' to bool. Possible information loss diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index d455323e05..d6fd9360d7 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -37,7 +37,6 @@ add_library(input_common STATIC if (MSVC) target_compile_options(input_common PRIVATE - /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data /we4800 # Implicit conversion from 'type' to bool. Possible information loss ) diff --git a/src/shader_recompiler/CMakeLists.txt b/src/shader_recompiler/CMakeLists.txt index eb412d08e3..393478ba20 100644 --- a/src/shader_recompiler/CMakeLists.txt +++ b/src/shader_recompiler/CMakeLists.txt @@ -252,7 +252,6 @@ target_link_libraries(shader_recompiler PUBLIC common fmt::fmt sirit ${SPIRV_TOO if (MSVC) target_compile_options(shader_recompiler PRIVATE - /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data /we4800 # Implicit conversion from 'type' to bool. Possible information loss ) diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 6c0dda296e..94a88eede5 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -341,12 +341,7 @@ if (ENABLE_NSIGHT_AFTERMATH) target_include_directories(video_core PRIVATE "$ENV{NSIGHT_AFTERMATH_SDK}/include") endif() -if (MSVC) - target_compile_options(video_core PRIVATE - /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data - /we4244 # 'conversion': conversion from 'type1' to 'type2', possible loss of data - ) -else() +if (NOT MSVC) if (APPLE) # error: declaration shadows a typedef in 'interval_base_set' # error: implicit conversion loses integer precision: 'int' to 'boost::icl::bound_type' (aka 'unsigned char') From 036a7edb2c0dd239542f3fee83193855a48fba73 Mon Sep 17 00:00:00 2001 From: spectranator Date: Wed, 8 May 2024 07:58:20 +0200 Subject: [PATCH 17/27] Removed custom fibers implementation due to issues caused on Windows Looks like the Windows ATL doesn't play along well at all. What a bummer. --- .gitmodules | 3 - CMakeLists.txt | 16 +- README.md | 2 +- externals/CMakeLists.txt | 3 - src/common/CMakeLists.txt | 2 +- src/common/fiber.cpp | 153 +-- src/common/fiber.h | 17 +- src/common/minicoro.h | 2077 ----------------------------------- src/tests/common/fibers.cpp | 39 + 9 files changed, 153 insertions(+), 2159 deletions(-) delete mode 100644 src/common/minicoro.h diff --git a/.gitmodules b/.gitmodules index 1184a1702f..e74fc38919 100644 --- a/.gitmodules +++ b/.gitmodules @@ -55,9 +55,6 @@ [submodule "externals/SPIRV-Headers"] path = externals/SPIRV-Headers url = https://github.com/KhronosGroup/SPIRV-Headers.git -[submodule "externals/boost-headers"] - path = externals/boost-headers - url = https://github.com/boostorg/headers.git [submodule "externals/SPIRV-Tools"] path = externals/SPIRV-Tools url = https://github.com/KhronosGroup/SPIRV-Tools.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 512306e97b..34478ff293 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -275,8 +275,17 @@ endif() # Configure C++ standard # =========================== -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +# boost asio's concept usage doesn't play nicely with some compilers yet. +add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS) +if (MSVC) + add_compile_options($<$:/std:c++20>) + + # boost still makes use of deprecated result_of. + add_definitions(-D_HAS_DEPRECATED_RESULT_OF) +else() + set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD_REQUIRED ON) +endif() # Output binaries to bin/ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) @@ -285,6 +294,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) # ======================================================================= # Enforce the search mode of non-required packages for better and shorter failure messages +find_package(Boost 1.79.0 REQUIRED context) find_package(enet 1.3 MODULE) find_package(fmt 9 REQUIRED) find_package(LLVM 17.0.2 MODULE COMPONENTS Demangle) @@ -674,6 +684,8 @@ function(create_target_directory_groups target_name) endforeach() endfunction() +# Prevent boost from linking against libs when building +target_link_libraries(Boost::headers INTERFACE Boost::disable_autolinking) # Adjustments for MSVC + Ninja if (MSVC AND CMAKE_GENERATOR STREQUAL "Ninja") add_compile_options( diff --git a/README.md b/README.md index ce8e87bd28..bf358f9dbb 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Alternatively, you can clone from the [GitHub mirror repository](https://github. Note that above repository may be taken down any time. Do not rely on its existence in production. In case the GitHub mirror goes down, a mirror will be set up on Gitlab. -This project incorporates several commits from the [Suyu](https://suyu.dev) and [Sudachi](https://github.com/sudachi-emu/sudachi) forks (but cleaned up due to the typically mediocre code/commit quality from both projects) as well as some custom changes, including lowered minimum boost library version requirements and faster fibers. +This project incorporates several commits from the [Suyu](https://suyu.dev) and [Sudachi](https://github.com/sudachi-emu/sudachi) forks (but cleaned up due to the typically mediocre code/commit quality from both projects) as well as changes listed in **Changes**. ## Building diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 8b8eea908f..8ed3ff6e99 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -172,9 +172,6 @@ if (YUZU_USE_EXTERNAL_VULKAN_SPIRV_TOOLS) add_subdirectory(SPIRV-Tools) endif() -# Boost headers -add_subdirectory(boost-headers) - # TZDB (Time Zone Database) add_subdirectory(nx_tzdb) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 3ecbd5a0d0..e7e5766a3c 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -259,7 +259,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") ) endif() -target_link_libraries(common PUBLIC Boost::headers fmt::fmt microprofile stb::headers Threads::Threads) +target_link_libraries(common PUBLIC Boost::context Boost::headers fmt::fmt microprofile stb::headers Threads::Threads) target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd LLVM::Demangle) if (ANDROID) diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp index aa0d5e4d92..2eb5ff3f6b 100644 --- a/src/common/fiber.cpp +++ b/src/common/fiber.cpp @@ -5,46 +5,87 @@ #include "common/assert.h" #include "common/fiber.h" -#define MINICORO_IMPL -#include "common/minicoro.h" +#include "common/virtual_buffer.h" + +#include namespace Common { +constexpr std::size_t default_stack_size = 512 * 1024; + struct Fiber::FiberImpl { - FiberImpl() {} + FiberImpl() : stack{default_stack_size}, rewind_stack{default_stack_size} {} + + VirtualBuffer stack; + VirtualBuffer rewind_stack; std::mutex guard; - bool released{}; - bool is_thread_fiber{}; - Fiber* next_fiber{}; - Fiber** next_fiber_ptr; std::function entry_point; + std::function rewind_point; + std::shared_ptr previous_fiber; + bool is_thread_fiber{}; + bool released{}; - mco_coro* context; + u8* stack_limit{}; + u8* rewind_stack_limit{}; + boost::context::detail::fcontext_t context{}; + boost::context::detail::fcontext_t rewind_context{}; }; -Fiber::Fiber() : impl{std::make_unique()} { - impl->is_thread_fiber = true; +void Fiber::SetRewindPoint(std::function&& rewind_func) { + impl->rewind_point = std::move(rewind_func); +} + +void Fiber::Start(boost::context::detail::transfer_t& transfer) { + ASSERT(impl->previous_fiber != nullptr); + impl->previous_fiber->impl->context = transfer.fctx; + impl->previous_fiber->impl->guard.unlock(); + impl->previous_fiber.reset(); + impl->entry_point(); + UNREACHABLE(); +} + +void Fiber::OnRewind([[maybe_unused]] boost::context::detail::transfer_t& transfer) { + ASSERT(impl->context != nullptr); + impl->context = impl->rewind_context; + impl->rewind_context = nullptr; + u8* tmp = impl->stack_limit; + impl->stack_limit = impl->rewind_stack_limit; + impl->rewind_stack_limit = tmp; + impl->rewind_point(); + UNREACHABLE(); +} + +void Fiber::FiberStartFunc(boost::context::detail::transfer_t transfer) { + auto* fiber = static_cast(transfer.data); + fiber->Start(transfer); +} + +void Fiber::RewindStartFunc(boost::context::detail::transfer_t transfer) { + auto* fiber = static_cast(transfer.data); + fiber->OnRewind(transfer); } Fiber::Fiber(std::function&& entry_point_func) : impl{std::make_unique()} { impl->entry_point = std::move(entry_point_func); - auto desc = mco_desc_init( - [](mco_coro* coro) { reinterpret_cast(coro->user_data)->impl->entry_point(); }, 0); - desc.user_data = this; - mco_result res = mco_create(&impl->context, &desc); - ASSERT(res == MCO_SUCCESS); + impl->stack_limit = impl->stack.data(); + impl->rewind_stack_limit = impl->rewind_stack.data(); + u8* stack_base = impl->stack_limit + default_stack_size; + impl->context = + boost::context::detail::make_fcontext(stack_base, impl->stack.size(), FiberStartFunc); } +Fiber::Fiber() : impl{std::make_unique()} {} + Fiber::~Fiber() { if (impl->released) { return; } - DestroyPre(); - if (impl->is_thread_fiber) { - DestroyThreadFiber(); - } else { - DestroyWorkFiber(); + // Make sure the Fiber is not being used + const bool locked = impl->guard.try_lock(); + ASSERT_MSG(locked, "Destroying a fiber that's still running"); + if (locked) { + impl->guard.unlock(); } } @@ -53,66 +94,42 @@ void Fiber::Exit() { if (!impl->is_thread_fiber) { return; } - DestroyPre(); - DestroyThreadFiber(); -} - -void Fiber::DestroyPre() { - // Make sure the Fiber is not being used - const bool locked = impl->guard.try_lock(); - ASSERT_MSG(locked, "Destroying a fiber that's still running"); - if (locked) { - impl->guard.unlock(); - } + impl->guard.unlock(); impl->released = true; } -void Fiber::DestroyWorkFiber() { - mco_result res = mco_destroy(impl->context); - ASSERT(res == MCO_SUCCESS); -} - -void Fiber::DestroyThreadFiber() { - if (impl->next_fiber_ptr && *impl->next_fiber_ptr) { - *impl->next_fiber_ptr = nullptr; - } +void Fiber::Rewind() { + ASSERT(impl->rewind_point); + ASSERT(impl->rewind_context == nullptr); + u8* stack_base = impl->rewind_stack_limit + default_stack_size; + impl->rewind_context = + boost::context::detail::make_fcontext(stack_base, impl->stack.size(), RewindStartFunc); + boost::context::detail::jump_fcontext(impl->rewind_context, this); } void Fiber::YieldTo(std::weak_ptr weak_from, Fiber& to) { + to.impl->guard.lock(); + to.impl->previous_fiber = weak_from.lock(); + + auto transfer = boost::context::detail::jump_fcontext(to.impl->context, &to); + + // "from" might no longer be valid if the thread was killed if (auto from = weak_from.lock()) { - if (!from->impl->is_thread_fiber) { - // Set next fiber - from->impl->next_fiber = &to; - // Yield from thread - if (!from->impl->released) { - from->impl->guard.unlock(); - mco_yield(from->impl->context); - } - } else { - from->impl->guard.lock(); - // Keep running next fiber until they've ran out - auto& next_fiber_ptr = from->impl->next_fiber_ptr; - next_fiber_ptr = &from->impl->next_fiber; - *next_fiber_ptr = &to; - while (*next_fiber_ptr) { - auto next = *next_fiber_ptr; - *next_fiber_ptr = nullptr; - next_fiber_ptr = &next->impl->next_fiber; - // Stop if new thread is thread fiber - if (next->impl->is_thread_fiber) - break; - // Resume new thread - next->impl->guard.lock(); - mco_result res = mco_resume(next->impl->context); - ASSERT(res == MCO_SUCCESS); - } - from->impl->guard.unlock(); + if (from->impl->previous_fiber == nullptr) { + ASSERT_MSG(false, "previous_fiber is nullptr!"); + return; } + from->impl->previous_fiber->impl->context = transfer.fctx; + from->impl->previous_fiber->impl->guard.unlock(); + from->impl->previous_fiber.reset(); } } std::shared_ptr Fiber::ThreadToFiber() { - return std::shared_ptr{new Fiber()}; + std::shared_ptr fiber = std::shared_ptr{new Fiber()}; + fiber->impl->guard.lock(); + fiber->impl->is_thread_fiber = true; + return fiber; } } // namespace Common diff --git a/src/common/fiber.h b/src/common/fiber.h index 6cb33352f2..92ec817724 100644 --- a/src/common/fiber.h +++ b/src/common/fiber.h @@ -6,7 +6,9 @@ #include #include -#include "common/minicoro.h" +namespace boost::context::detail { +struct transfer_t; +} namespace Common { @@ -36,18 +38,25 @@ public: Fiber(Fiber&&) = default; Fiber& operator=(Fiber&&) = default; + /// Yields control from Fiber 'from' to Fiber 'to' + /// Fiber 'from' must be the currently running fiber. static void YieldTo(std::weak_ptr weak_from, Fiber& to); [[nodiscard]] static std::shared_ptr ThreadToFiber(); + void SetRewindPoint(std::function&& rewind_func); + + void Rewind(); + /// Only call from main thread's fiber void Exit(); private: Fiber(); - void DestroyPre(); - void DestroyWorkFiber(); - void DestroyThreadFiber(); + void OnRewind(boost::context::detail::transfer_t& transfer); + void Start(boost::context::detail::transfer_t& transfer); + static void FiberStartFunc(boost::context::detail::transfer_t transfer); + static void RewindStartFunc(boost::context::detail::transfer_t transfer); struct FiberImpl; std::unique_ptr impl; diff --git a/src/common/minicoro.h b/src/common/minicoro.h deleted file mode 100644 index 9f1dbcafb3..0000000000 --- a/src/common/minicoro.h +++ /dev/null @@ -1,2077 +0,0 @@ -/* -Minimal asymmetric stackful cross-platform coroutine library in pure C. -minicoro - v0.2.0 - 15/Nov/2023 -Eduardo Bart - edub4rt@gmail.com -https://github.com/edubart/minicoro - -Minicoro is single file library for using asymmetric coroutines in C. -The API is inspired by Lua coroutines but with C use in mind. - -# Features - -- Stackful asymmetric coroutines. -- Supports nesting coroutines (resuming a coroutine from another coroutine). -- Supports custom allocators. -- Storage system to allow passing values between yield and resume. -- Customizable stack size. -- Supports growable stacks and low memory footprint when enabling the virtual memory allocator. -- Coroutine API design inspired by Lua with C use in mind. -- Yield across any C function. -- Made to work in multithread applications. -- Cross platform. -- Minimal, self contained and no external dependencies. -- Readable sources and documented. -- Implemented via assembly, ucontext or fibers. -- Lightweight and very efficient. -- Works in most C89 compilers. -- Error prone API, returning proper error codes on misuse. -- Support running with Valgrind, ASan (AddressSanitizer) and TSan (ThreadSanitizer). - -# Supported Platforms - -Most platforms are supported through different methods: - -| Platform | Assembly Method | Fallback Method | -|--------------|------------------|-------------------| -| Android | ARM/ARM64 | N/A | -| iOS | ARM/ARM64 | N/A | -| Windows | x86_64 | Windows fibers | -| Linux | x86_64/i686 | ucontext | -| Mac OS X | x86_64/ARM/ARM64 | ucontext | -| WebAssembly | N/A | Emscripten fibers / Binaryen asyncify | -| Raspberry Pi | ARM | ucontext | -| RISC-V | rv64/rv32 | ucontext | - -The assembly method is used by default if supported by the compiler and CPU, -otherwise ucontext or fiber method is used as a fallback. - -The assembly method is very efficient, it just take a few cycles -to create, resume, yield or destroy a coroutine. - -# Caveats - -- Avoid using coroutines with C++ exceptions, this is not recommended, it may not behave as you -expect. -- When using C++ RAII (i.e. destructors) you must resume the coroutine until it dies to properly -execute all destructors. -- Some unsupported sanitizers for C may trigger false warnings when using coroutines. -- The `mco_coro` object is not thread safe, you should use a mutex for manipulating it in -multithread applications. -- To use in multithread applications, you must compile with C compiler that supports `thread_local` -qualifier. -- Avoid using `thread_local` inside coroutine code, the compiler may cache thread local variables -pointers which can be invalid when a coroutine switch threads. -- Stack space is limited. By default it has 56KB of space, this can be changed on coroutine -creation, or by enabling the virtual memory backed allocator to make it 2040KB. -- Take care to not cause stack overflows (run out of stack space), otherwise your program may crash -or not, the behavior is undefined. -- On WebAssembly you must compile with Emscripten flag `-s ASYNCIFY=1`. -- The WebAssembly Binaryen asyncify method can be used when explicitly enabled, -you may want to do this only to use minicoro with WebAssembly native interpreters -(no Web browser). This method is confirmed to work well with Emscripten toolchain, -however it fails on other WebAssembly toolchains like WASI SDK. - -# Introduction - -A coroutine represents an independent "green" thread of execution. -Unlike threads in multithread systems, however, -a coroutine only suspends its execution by explicitly calling a yield function. - -You create a coroutine by calling `mco_create`. -Its sole argument is a `mco_desc` structure with a description for the coroutine. -The `mco_create` function only creates a new coroutine and returns a handle to it, it does not start -the coroutine. - -You execute a coroutine by calling `mco_resume`. -When calling a resume function the coroutine starts its execution by calling its body function. -After the coroutine starts running, it runs until it terminates or yields. - -A coroutine yields by calling `mco_yield`. -When a coroutine yields, the corresponding resume returns immediately, -even if the yield happens inside nested function calls (that is, not in the main function). -The next time you resume the same coroutine, it continues its execution from the point where it -yielded. - -To associate a persistent value with the coroutine, -you can optionally set `user_data` on its creation and later retrieve with `mco_get_user_data`. - -To pass values between resume and yield, -you can optionally use `mco_push` and `mco_pop` APIs, -they are intended to pass temporary values using a LIFO style buffer. -The storage system can also be used to send and receive initial values on coroutine creation or -before it finishes. - -# Usage - -To use minicoro, do the following in one .c file: - -```c -#define MINICORO_IMPL -#include "minicoro.h" -``` - -You can do `#include "minicoro.h"` in other parts of the program just like any other header. - -## Minimal Example - -The following simple example demonstrates on how to use the library: - -```c -#define MINICORO_IMPL -#include -#include -#include "minicoro.h" - -// Coroutine entry function. -void coro_entry(mco_coro* co) { - printf("coroutine 1\n"); - mco_yield(co); - printf("coroutine 2\n"); -} - -int main() { - // First initialize a `desc` object through `mco_desc_init`. - mco_desc desc = mco_desc_init(coro_entry, 0); - // Configure `desc` fields when needed (e.g. customize user_data or allocation functions). - desc.user_data = NULL; - // Call `mco_create` with the output coroutine pointer and `desc` pointer. - mco_coro* co; - mco_result res = mco_create(&co, &desc); - assert(res == MCO_SUCCESS); - // The coroutine should be now in suspended state. - assert(mco_status(co) == MCO_SUSPENDED); - // Call `mco_resume` to start for the first time, switching to its context. - res = mco_resume(co); // Should print "coroutine 1". - assert(res == MCO_SUCCESS); - // We get back from coroutine context in suspended state (because it's unfinished). - assert(mco_status(co) == MCO_SUSPENDED); - // Call `mco_resume` to resume for a second time. - res = mco_resume(co); // Should print "coroutine 2". - assert(res == MCO_SUCCESS); - // The coroutine finished and should be now dead. - assert(mco_status(co) == MCO_DEAD); - // Call `mco_destroy` to destroy the coroutine. - res = mco_destroy(co); - assert(res == MCO_SUCCESS); - return 0; -} -``` - -_NOTE_: In case you don't want to use the minicoro allocator system you should -allocate a coroutine object yourself using `mco_desc.coro_size` and call `mco_init`, -then later to destroy call `mco_uninit` and deallocate it. - -## Yielding from anywhere - -You can yield the current running coroutine from anywhere -without having to pass `mco_coro` pointers around, -to this just use `mco_yield(mco_running())`. - -## Passing data between yield and resume - -The library has the storage interface to assist passing data between yield and resume. -It's usage is straightforward, -use `mco_push` to send data before a `mco_resume` or `mco_yield`, -then later use `mco_pop` after a `mco_resume` or `mco_yield` to receive data. -Take care to not mismatch a push and pop, otherwise these functions will return -an error. - -## Error handling - -The library return error codes in most of its API in case of misuse or system error, -the user is encouraged to handle them properly. - -## Virtual memory backed allocator - -The new compile time option `MCO_USE_VMEM_ALLOCATOR` enables a virtual memory backed allocator. - -Every stackful coroutine usually have to reserve memory for its full stack, -this typically makes the total memory usage very high when allocating thousands of coroutines, -for example, an application with 100 thousands coroutine with stacks of 56KB would consume as high -as 5GB of memory, however your application may not really full stack usage for every coroutine. - -Some developers often prefer stackless coroutines over stackful coroutines -because of this problem, stackless memory footprint is low, therefore often considered more -lightweight. However stackless have many other limitations, like you cannot run unconstrained code -inside them. - -One remedy to the solution is to make stackful coroutines growable, -to only use physical memory on demand when its really needed, -and there is a nice way to do this relying on virtual memory allocation -when supported by the operating system. - -The virtual memory backed allocator will reserve virtual memory in the OS for each coroutine stack, -but not trigger real physical memory usage yet. -While the application virtual memory usage will be high, -the physical memory usage will be low and actually grow on demand (usually every 4KB chunk in -Linux). - -The virtual memory backed allocator also raises the default stack size to about 2MB, -typically the size of extra threads in Linux, -so you have more space in your coroutines and the risk of stack overflow is low. - -As an example, allocating 100 thousands coroutines with nearly 2MB stack reserved space -with the virtual memory allocator uses 783MB of physical memory usage, that is about 8KB per -coroutine, however the virtual memory usage will be at 98GB. - -It is recommended to enable this option only if you plan to spawn thousands of coroutines -while wanting to have a low memory footprint. -Not all environments have an OS with virtual memory support, therefore this option is disabled by -default. - -This option may add an order of magnitude overhead to `mco_create()`/`mco_destroy()`, -because they will request the OS to manage virtual memory page tables, -if this is a problem for you, please customize a custom allocator for your own needs. - -## Library customization - -The following can be defined to change the library behavior: - -- `MCO_API` - Public API qualifier. Default is `extern`. -- `MCO_MIN_STACK_SIZE` - Minimum stack size when creating a coroutine. Default is 32768 -(32KB). -- `MCO_DEFAULT_STORAGE_SIZE` - Size of coroutine storage buffer. Default is 1024. -- `MCO_DEFAULT_STACK_SIZE` - Default stack size when creating a coroutine. Default is 57344 -(56KB). When `MCO_USE_VMEM_ALLOCATOR` is true the default is 2040KB (nearly 2MB). -- `MCO_ALLOC` - Default allocation function. Default is `calloc`. -- `MCO_DEALLOC` - Default deallocation function. Default is `free`. -- `MCO_USE_VMEM_ALLOCATOR` - Use virtual memory backed allocator, improving memory footprint per -coroutine. -- `MCO_NO_DEFAULT_ALLOCATOR` - Disable the default allocator using `MCO_ALLOC` and `MCO_DEALLOC`. -- `MCO_ZERO_MEMORY` - Zero memory of stack when poping storage, intended for garbage -collected environments. -- `MCO_DEBUG` - Enable debug mode, logging any runtime error to stdout. Defined -automatically unless `NDEBUG` or `MCO_NO_DEBUG` is defined. -- `MCO_NO_DEBUG` - Disable debug mode. -- `MCO_NO_MULTITHREAD` - Disable multithread usage. Multithread is supported when -`thread_local` is supported. -- `MCO_USE_ASM` - Force use of assembly context switch implementation. -- `MCO_USE_UCONTEXT` - Force use of ucontext context switch implementation. -- `MCO_USE_FIBERS` - Force use of fibers context switch implementation. -- `MCO_USE_ASYNCIFY` - Force use of Binaryen asyncify context switch implementation. -- `MCO_USE_VALGRIND` - Define if you want run with valgrind to fix accessing memory errors. - -# License - -Your choice of either Public Domain or MIT No Attribution, see end of file. -*/ - -#ifndef MINICORO_H -#define MINICORO_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Public API qualifier. */ -#ifndef MCO_API -#define MCO_API extern -#endif - -/* Size of coroutine storage buffer. */ -#ifndef MCO_DEFAULT_STORAGE_SIZE -#define MCO_DEFAULT_STORAGE_SIZE 1024 -#endif - -#include /* for size_t */ - -/* ---------------------------------------------------------------------------------------------- */ - -/* Coroutine states. */ -typedef enum mco_state { - MCO_DEAD = 0, /* The coroutine has finished normally or was uninitialized before finishing. */ - MCO_NORMAL, /* The coroutine is active but not running (that is, it has resumed another - coroutine). */ - MCO_RUNNING, /* The coroutine is active and running. */ - MCO_SUSPENDED /* The coroutine is suspended (in a call to yield, or it has not started running - yet). */ -} mco_state; - -/* Coroutine result codes. */ -typedef enum mco_result { - MCO_SUCCESS = 0, - MCO_GENERIC_ERROR, - MCO_INVALID_POINTER, - MCO_INVALID_COROUTINE, - MCO_NOT_SUSPENDED, - MCO_NOT_RUNNING, - MCO_MAKE_CONTEXT_ERROR, - MCO_SWITCH_CONTEXT_ERROR, - MCO_NOT_ENOUGH_SPACE, - MCO_OUT_OF_MEMORY, - MCO_INVALID_ARGUMENTS, - MCO_INVALID_OPERATION, - MCO_STACK_OVERFLOW -} mco_result; - -/* Coroutine structure. */ -typedef struct mco_coro mco_coro; -struct mco_coro { - void* context; - mco_state state; - void (*func)(mco_coro* co); - mco_coro* prev_co; - void* user_data; - size_t coro_size; - void* allocator_data; - void (*dealloc_cb)(void* ptr, size_t size, void* allocator_data); - void* stack_base; /* Stack base address, can be used to scan memory in a garbage collector. */ - size_t stack_size; - unsigned char* storage; - size_t bytes_stored; - size_t storage_size; - void* asan_prev_stack; /* Used by address sanitizer. */ - void* tsan_prev_fiber; /* Used by thread sanitizer. */ - void* tsan_fiber; /* Used by thread sanitizer. */ - size_t magic_number; /* Used to check stack overflow. */ -}; - -/* Structure used to initialize a coroutine. */ -typedef struct mco_desc { - void (*func)(mco_coro* co); /* Entry point function for the coroutine. */ - void* user_data; /* Coroutine user data, can be get with `mco_get_user_data`. */ - /* Custom allocation interface. */ - void* (*alloc_cb)(size_t size, void* allocator_data); /* Custom allocation function. */ - void (*dealloc_cb)(void* ptr, size_t size, - void* allocator_data); /* Custom deallocation function. */ - void* allocator_data; /* User data pointer passed to `alloc`/`dealloc` allocation functions. */ - size_t storage_size; /* Coroutine storage size, to be used with the storage APIs. */ - /* These must be initialized only through `mco_init_desc`. */ - size_t coro_size; /* Coroutine structure size. */ - size_t stack_size; /* Coroutine stack size. */ -} mco_desc; - -/* Coroutine functions. */ -MCO_API mco_desc -mco_desc_init(void (*func)(mco_coro* co), - size_t stack_size); /* Initialize description of a coroutine. When stack size is 0 - then MCO_DEFAULT_STACK_SIZE is used. */ -MCO_API mco_result mco_init(mco_coro* co, mco_desc* desc); /* Initialize the coroutine. */ -MCO_API mco_result -mco_uninit(mco_coro* co); /* Uninitialize the coroutine, may fail if it's not dead or suspended. */ -MCO_API mco_result mco_create(mco_coro** out_co, - mco_desc* desc); /* Allocates and initializes a new coroutine. */ -MCO_API mco_result mco_destroy(mco_coro* co); /* Uninitialize and deallocate the coroutine, may fail - if it's not dead or suspended. */ -MCO_API mco_result -mco_resume(mco_coro* co); /* Starts or continues the execution of the coroutine. */ -MCO_API mco_result mco_yield(mco_coro* co); /* Suspends the execution of a coroutine. */ -MCO_API mco_state mco_status(mco_coro* co); /* Returns the status of the coroutine. */ -MCO_API void* mco_get_user_data( - mco_coro* co); /* Get coroutine user data supplied on coroutine creation. */ - -/* Storage interface functions, used to pass values between yield and resume. */ -MCO_API mco_result mco_push(mco_coro* co, const void* src, - size_t len); /* Push bytes to the coroutine storage. Use to send values - between yield and resume. */ -MCO_API mco_result mco_pop(mco_coro* co, void* dest, - size_t len); /* Pop bytes from the coroutine storage. Use to get values - between yield and resume. */ -MCO_API mco_result mco_peek(mco_coro* co, void* dest, - size_t len); /* Like `mco_pop` but it does not consumes the storage. */ -MCO_API size_t mco_get_bytes_stored( - mco_coro* co); /* Get the available bytes that can be retrieved with a `mco_pop`. */ -MCO_API size_t mco_get_storage_size(mco_coro* co); /* Get the total storage size. */ - -/* Misc functions. */ -MCO_API mco_coro* mco_running(void); /* Returns the running coroutine for the current thread. */ -MCO_API const char* mco_result_description(mco_result res); /* Get the description of a result. */ - -#ifdef __cplusplus -} -#endif - -#endif /* MINICORO_H */ - -#ifdef MINICORO_IMPL - -#ifdef __cplusplus -extern "C" { -#endif - -/* ---------------------------------------------------------------------------------------------- */ - -/* Minimum stack size when creating a coroutine. */ -#ifndef MCO_MIN_STACK_SIZE -#define MCO_MIN_STACK_SIZE 32768 -#endif - -/* Default stack size when creating a coroutine. */ -#ifndef MCO_DEFAULT_STACK_SIZE -/* Use multiples of 64KB minus 8KB, because 8KB is reserved for coroutine internal structures. */ -#ifdef MCO_USE_VMEM_ALLOCATOR -#define MCO_DEFAULT_STACK_SIZE \ - 2040 * 1024 /* 2040KB, nearly the same stack size of a thread in x86_64 Linux. */ -#else -#define MCO_DEFAULT_STACK_SIZE 56 * 1024 /* 56KB */ -#endif -#endif - -/* Number used only to assist checking for stack overflows. */ -#define MCO_MAGIC_NUMBER 0x7E3CB1A9 - -/* Detect implementation based on OS, arch and compiler. */ -#if !defined(MCO_USE_UCONTEXT) && !defined(MCO_USE_FIBERS) && !defined(MCO_USE_ASM) && \ - !defined(MCO_USE_ASYNCIFY) -#if defined(_WIN32) -#if (defined(__GNUC__) && defined(__x86_64__)) || (defined(_MSC_VER) && defined(_M_X64)) -#define MCO_USE_ASM -#else -#define MCO_USE_FIBERS -#endif -#elif defined(__CYGWIN__) /* MSYS */ -#define MCO_USE_UCONTEXT -#elif defined(__EMSCRIPTEN__) -#define MCO_USE_FIBERS -#elif defined(__wasm__) -#define MCO_USE_ASYNCIFY -#else -#if __GNUC__ >= 3 /* Assembly extension supported. */ -#if defined(__x86_64__) || defined(__i386) || defined(__i386__) || defined(__ARM_EABI__) || \ - defined(__aarch64__) || defined(__riscv) -#define MCO_USE_ASM -#else -#define MCO_USE_UCONTEXT -#endif -#else -#define MCO_USE_UCONTEXT -#endif -#endif -#endif - -#define _MCO_UNUSED(x) (void)(x) - -#if !defined(MCO_NO_DEBUG) && !defined(NDEBUG) && !defined(MCO_DEBUG) -#define MCO_DEBUG -#endif - -#ifndef MCO_LOG -#ifdef MCO_DEBUG -#include -#define MCO_LOG(s) puts(s) -#else -#define MCO_LOG(s) -#endif -#endif - -#ifndef MCO_ASSERT -#ifdef MCO_DEBUG -#include -#define MCO_ASSERT(c) assert(c) -#else -#define MCO_ASSERT(c) -#endif -#endif - -#ifndef MCO_THREAD_LOCAL -#ifdef MCO_NO_MULTITHREAD -#define MCO_THREAD_LOCAL -#else -#ifdef thread_local -#define MCO_THREAD_LOCAL thread_local -#elif __STDC_VERSION__ >= 201112 && !defined(__STDC_NO_THREADS__) -#define MCO_THREAD_LOCAL _Thread_local -#elif defined(_WIN32) && \ - (defined(_MSC_VER) || defined(__ICL) || defined(__DMC__) || defined(__BORLANDC__)) -#define MCO_THREAD_LOCAL __declspec(thread) -#elif defined(__GNUC__) || defined(__SUNPRO_C) || defined(__xlC__) -#define MCO_THREAD_LOCAL __thread -#else /* No thread local support, `mco_running` will be thread unsafe. */ -#define MCO_THREAD_LOCAL -#define MCO_NO_MULTITHREAD -#endif -#endif -#endif - -#ifndef MCO_FORCE_INLINE -#ifdef _MSC_VER -#define MCO_FORCE_INLINE __forceinline -#elif defined(__GNUC__) -#if defined(__STRICT_ANSI__) -#define MCO_FORCE_INLINE __inline__ __attribute__((always_inline)) -#else -#define MCO_FORCE_INLINE inline __attribute__((always_inline)) -#endif -#elif defined(__BORLANDC__) || defined(__DMC__) || defined(__SC__) || defined(__WATCOMC__) || \ - defined(__LCC__) || defined(__DECC) -#define MCO_FORCE_INLINE __inline -#else /* No inline support. */ -#define MCO_FORCE_INLINE -#endif -#endif - -#ifndef MCO_NO_INLINE -#ifdef __GNUC__ -#define MCO_NO_INLINE __attribute__((noinline)) -#elif defined(_MSC_VER) -#define MCO_NO_INLINE __declspec(noinline) -#else -#define MCO_NO_INLINE -#endif -#endif - -#if defined(_WIN32) && (defined(MCO_USE_FIBERS) || defined(MCO_USE_VMEM_ALLOCATOR)) -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0400 -#endif -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#endif - -#ifndef MCO_NO_DEFAULT_ALLOCATOR -#if defined(MCO_USE_VMEM_ALLOCATOR) && defined(_WIN32) -static void* mco_alloc(size_t size, void* allocator_data) { - _MCO_UNUSED(allocator_data); - return VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); -} -static void mco_dealloc(void* ptr, size_t size, void* allocator_data) { - _MCO_UNUSED(allocator_data); - _MCO_UNUSED(size); - int res = VirtualFree(ptr, 0, MEM_RELEASE); - _MCO_UNUSED(res); - MCO_ASSERT(res != 0); -} -#elif defined(MCO_USE_VMEM_ALLOCATOR) /* POSIX virtual memory allocator */ -#include -static void* mco_alloc(size_t size, void* allocator_data) { - _MCO_UNUSED(allocator_data); - void* ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - return ptr != MAP_FAILED ? ptr : NULL; -} -static void mco_dealloc(void* ptr, size_t size, void* allocator_data) { - _MCO_UNUSED(allocator_data); - int res = munmap(ptr, size); - _MCO_UNUSED(res); - MCO_ASSERT(res == 0); -} -#else /* C allocator */ -#ifndef MCO_ALLOC -#include -/* We use calloc() so we give a chance for the OS to reserve virtual memory without really using - physical memory, calloc() also has the nice property of initializing the stack to zeros. */ -#define MCO_ALLOC(size) calloc(1, size) -#define MCO_DEALLOC(ptr, size) free(ptr) -#endif -static void* mco_alloc(size_t size, void* allocator_data) { - _MCO_UNUSED(allocator_data); - return MCO_ALLOC(size); -} -static void mco_dealloc(void* ptr, size_t size, void* allocator_data) { - _MCO_UNUSED(size); - _MCO_UNUSED(allocator_data); - MCO_DEALLOC(ptr, size); -} -#endif /* MCO_USE_VMEM_ALLOCATOR */ -#endif /* MCO_NO_DEFAULT_ALLOCATOR */ - -#if defined(__has_feature) -#if __has_feature(address_sanitizer) -#define _MCO_USE_ASAN -#endif -#if __has_feature(thread_sanitizer) -#define _MCO_USE_TSAN -#endif -#endif -#if defined(__SANITIZE_ADDRESS__) -#define _MCO_USE_ASAN -#endif -#if defined(__SANITIZE_THREAD__) -#define _MCO_USE_TSAN -#endif -#ifdef _MCO_USE_ASAN -void __sanitizer_start_switch_fiber(void** fake_stack_save, const void* bottom, size_t size); -void __sanitizer_finish_switch_fiber(void* fake_stack_save, const void** bottom_old, - size_t* size_old); -#endif -#ifdef _MCO_USE_TSAN -void* __tsan_get_current_fiber(void); -void* __tsan_create_fiber(unsigned flags); -void __tsan_destroy_fiber(void* fiber); -void __tsan_switch_to_fiber(void* fiber, unsigned flags); -#endif - -#include /* For memcpy and memset. */ - -/* Utility for aligning addresses. */ -static MCO_FORCE_INLINE size_t _mco_align_forward(size_t addr, size_t align) { - return (addr + (align - 1)) & ~(align - 1); -} - -/* Variable holding the current running coroutine per thread. */ -static MCO_THREAD_LOCAL mco_coro* mco_current_co = NULL; - -static MCO_FORCE_INLINE void _mco_prepare_jumpin(mco_coro* co) { - /* Set the old coroutine to normal state and update it. */ - mco_coro* prev_co = mco_running(); /* Must access through `mco_running`. */ - MCO_ASSERT(co->prev_co == NULL); - co->prev_co = prev_co; - if (prev_co) { - MCO_ASSERT(prev_co->state == MCO_RUNNING); - prev_co->state = MCO_NORMAL; - } - mco_current_co = co; -#ifdef _MCO_USE_ASAN - if (prev_co) { - void* bottom_old = NULL; - size_t size_old = 0; - __sanitizer_finish_switch_fiber(prev_co->asan_prev_stack, (const void**)&bottom_old, - &size_old); - prev_co->asan_prev_stack = NULL; - } - __sanitizer_start_switch_fiber(&co->asan_prev_stack, co->stack_base, co->stack_size); -#endif -#ifdef _MCO_USE_TSAN - co->tsan_prev_fiber = __tsan_get_current_fiber(); - __tsan_switch_to_fiber(co->tsan_fiber, 0); -#endif -} - -static MCO_FORCE_INLINE void _mco_prepare_jumpout(mco_coro* co) { - /* Switch back to the previous running coroutine. */ - /* MCO_ASSERT(mco_running() == co); */ - mco_coro* prev_co = co->prev_co; - co->prev_co = NULL; - if (prev_co) { - /* MCO_ASSERT(prev_co->state == MCO_NORMAL); */ - prev_co->state = MCO_RUNNING; - } - mco_current_co = prev_co; -#ifdef _MCO_USE_ASAN - void* bottom_old = NULL; - size_t size_old = 0; - __sanitizer_finish_switch_fiber(co->asan_prev_stack, (const void**)&bottom_old, &size_old); - co->asan_prev_stack = NULL; - if (prev_co) { - __sanitizer_start_switch_fiber(&prev_co->asan_prev_stack, bottom_old, size_old); - } -#endif -#ifdef _MCO_USE_TSAN - void* tsan_prev_fiber = co->tsan_prev_fiber; - co->tsan_prev_fiber = NULL; - __tsan_switch_to_fiber(tsan_prev_fiber, 0); -#endif -} - -static void _mco_jumpin(mco_coro* co); -static void _mco_jumpout(mco_coro* co); - -static MCO_NO_INLINE void _mco_main(mco_coro* co) { - co->func(co); /* Run the coroutine function. */ - co->state = MCO_DEAD; /* Coroutine finished successfully, set state to dead. */ - _mco_jumpout(co); /* Jump back to the old context .*/ -} - -/* ---------------------------------------------------------------------------------------------- */ - -#if defined(MCO_USE_UCONTEXT) || defined(MCO_USE_ASM) - -/* -Some of the following assembly code is taken from LuaCoco by Mike Pall. -See https://coco.luajit.org/index.html - -MIT license - -Copyright (C) 2004-2016 Mike Pall. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifdef MCO_USE_ASM - -#if defined(__x86_64__) || defined(_M_X64) - -#ifdef _WIN32 - -typedef struct _mco_ctxbuf { - void *rip, *rsp, *rbp, *rbx, *r12, *r13, *r14, *r15, *rdi, *rsi; - void* xmm[20]; /* xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 */ - void* fiber_storage; - void* dealloc_stack; - void* stack_limit; - void* stack_base; -} _mco_ctxbuf; - -#if defined(__GNUC__) -#define _MCO_ASM_BLOB __attribute__((section(".text"))) -#elif defined(_MSC_VER) -#define _MCO_ASM_BLOB __declspec(allocate(".text")) -#pragma section(".text") -#endif - -_MCO_ASM_BLOB static unsigned char _mco_wrap_main_code[] = { - 0x4c, 0x89, 0xe9, /* mov %r13,%rcx */ - 0x41, 0xff, 0xe4, /* jmpq *%r12 */ - 0xc3, /* retq */ - 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 /* nop */ -}; - -_MCO_ASM_BLOB static unsigned char _mco_switch_code[] = { - 0x48, 0x8d, 0x05, 0x3e, 0x01, 0x00, 0x00, /* lea 0x13e(%rip),%rax */ - 0x48, 0x89, 0x01, /* mov %rax,(%rcx) */ - 0x48, 0x89, 0x61, 0x08, /* mov %rsp,0x8(%rcx) */ - 0x48, 0x89, 0x69, 0x10, /* mov %rbp,0x10(%rcx) */ - 0x48, 0x89, 0x59, 0x18, /* mov %rbx,0x18(%rcx) */ - 0x4c, 0x89, 0x61, 0x20, /* mov %r12,0x20(%rcx) */ - 0x4c, 0x89, 0x69, 0x28, /* mov %r13,0x28(%rcx) */ - 0x4c, 0x89, 0x71, 0x30, /* mov %r14,0x30(%rcx) */ - 0x4c, 0x89, 0x79, 0x38, /* mov %r15,0x38(%rcx) */ - 0x48, 0x89, 0x79, 0x40, /* mov %rdi,0x40(%rcx) */ - 0x48, 0x89, 0x71, 0x48, /* mov %rsi,0x48(%rcx) */ - 0x0f, 0x11, 0x71, 0x50, /* movups %xmm6,0x50(%rcx) */ - 0x0f, 0x11, 0x79, 0x60, /* movups %xmm7,0x60(%rcx) */ - 0x44, 0x0f, 0x11, 0x41, 0x70, /* movups %xmm8,0x70(%rcx) */ - 0x44, 0x0f, 0x11, 0x89, 0x80, 0x00, 0x00, 0x00, /* movups %xmm9,0x80(%rcx) */ - 0x44, 0x0f, 0x11, 0x91, 0x90, 0x00, 0x00, 0x00, /* movups %xmm10,0x90(%rcx) */ - 0x44, 0x0f, 0x11, 0x99, 0xa0, 0x00, 0x00, 0x00, /* movups %xmm11,0xa0(%rcx) */ - 0x44, 0x0f, 0x11, 0xa1, 0xb0, 0x00, 0x00, 0x00, /* movups %xmm12,0xb0(%rcx) */ - 0x44, 0x0f, 0x11, 0xa9, 0xc0, 0x00, 0x00, 0x00, /* movups %xmm13,0xc0(%rcx) */ - 0x44, 0x0f, 0x11, 0xb1, 0xd0, 0x00, 0x00, 0x00, /* movups %xmm14,0xd0(%rcx) */ - 0x44, 0x0f, 0x11, 0xb9, 0xe0, 0x00, 0x00, 0x00, /* movups %xmm15,0xe0(%rcx) */ - 0x65, 0x4c, 0x8b, 0x14, 0x25, 0x30, 0x00, 0x00, 0x00, /* mov %gs:0x30,%r10 */ - 0x49, 0x8b, 0x42, 0x20, /* mov 0x20(%r10),%rax */ - 0x48, 0x89, 0x81, 0xf0, 0x00, 0x00, 0x00, /* mov %rax,0xf0(%rcx) */ - 0x49, 0x8b, 0x82, 0x78, 0x14, 0x00, 0x00, /* mov 0x1478(%r10),%rax */ - 0x48, 0x89, 0x81, 0xf8, 0x00, 0x00, 0x00, /* mov %rax,0xf8(%rcx) */ - 0x49, 0x8b, 0x42, 0x10, /* mov 0x10(%r10),%rax */ - 0x48, 0x89, 0x81, 0x00, 0x01, 0x00, 0x00, /* mov %rax,0x100(%rcx) */ - 0x49, 0x8b, 0x42, 0x08, /* mov 0x8(%r10),%rax */ - 0x48, 0x89, 0x81, 0x08, 0x01, 0x00, 0x00, /* mov %rax,0x108(%rcx) */ - 0x48, 0x8b, 0x82, 0x08, 0x01, 0x00, 0x00, /* mov 0x108(%rdx),%rax */ - 0x49, 0x89, 0x42, 0x08, /* mov %rax,0x8(%r10) */ - 0x48, 0x8b, 0x82, 0x00, 0x01, 0x00, 0x00, /* mov 0x100(%rdx),%rax */ - 0x49, 0x89, 0x42, 0x10, /* mov %rax,0x10(%r10) */ - 0x48, 0x8b, 0x82, 0xf8, 0x00, 0x00, 0x00, /* mov 0xf8(%rdx),%rax */ - 0x49, 0x89, 0x82, 0x78, 0x14, 0x00, 0x00, /* mov %rax,0x1478(%r10) */ - 0x48, 0x8b, 0x82, 0xf0, 0x00, 0x00, 0x00, /* mov 0xf0(%rdx),%rax */ - 0x49, 0x89, 0x42, 0x20, /* mov %rax,0x20(%r10) */ - 0x44, 0x0f, 0x10, 0xba, 0xe0, 0x00, 0x00, 0x00, /* movups 0xe0(%rdx),%xmm15 */ - 0x44, 0x0f, 0x10, 0xb2, 0xd0, 0x00, 0x00, 0x00, /* movups 0xd0(%rdx),%xmm14 */ - 0x44, 0x0f, 0x10, 0xaa, 0xc0, 0x00, 0x00, 0x00, /* movups 0xc0(%rdx),%xmm13 */ - 0x44, 0x0f, 0x10, 0xa2, 0xb0, 0x00, 0x00, 0x00, /* movups 0xb0(%rdx),%xmm12 */ - 0x44, 0x0f, 0x10, 0x9a, 0xa0, 0x00, 0x00, 0x00, /* movups 0xa0(%rdx),%xmm11 */ - 0x44, 0x0f, 0x10, 0x92, 0x90, 0x00, 0x00, 0x00, /* movups 0x90(%rdx),%xmm10 */ - 0x44, 0x0f, 0x10, 0x8a, 0x80, 0x00, 0x00, 0x00, /* movups 0x80(%rdx),%xmm9 */ - 0x44, 0x0f, 0x10, 0x42, 0x70, /* movups 0x70(%rdx),%xmm8 */ - 0x0f, 0x10, 0x7a, 0x60, /* movups 0x60(%rdx),%xmm7 */ - 0x0f, 0x10, 0x72, 0x50, /* movups 0x50(%rdx),%xmm6 */ - 0x48, 0x8b, 0x72, 0x48, /* mov 0x48(%rdx),%rsi */ - 0x48, 0x8b, 0x7a, 0x40, /* mov 0x40(%rdx),%rdi */ - 0x4c, 0x8b, 0x7a, 0x38, /* mov 0x38(%rdx),%r15 */ - 0x4c, 0x8b, 0x72, 0x30, /* mov 0x30(%rdx),%r14 */ - 0x4c, 0x8b, 0x6a, 0x28, /* mov 0x28(%rdx),%r13 */ - 0x4c, 0x8b, 0x62, 0x20, /* mov 0x20(%rdx),%r12 */ - 0x48, 0x8b, 0x5a, 0x18, /* mov 0x18(%rdx),%rbx */ - 0x48, 0x8b, 0x6a, 0x10, /* mov 0x10(%rdx),%rbp */ - 0x48, 0x8b, 0x62, 0x08, /* mov 0x8(%rdx),%rsp */ - 0xff, 0x22, /* jmpq *(%rdx) */ - 0xc3, /* retq */ - 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, /* nop */ - 0x90, 0x90, /* nop */ -}; - -void (*_mco_wrap_main)(void) = (void (*)(void))(void*)_mco_wrap_main_code; -void (*_mco_switch)(_mco_ctxbuf* from, - _mco_ctxbuf* to) = (void (*)(_mco_ctxbuf* from, - _mco_ctxbuf* to))(void*)_mco_switch_code; - -static mco_result _mco_makectx(mco_coro* co, _mco_ctxbuf* ctx, void* stack_base, - size_t stack_size) { - stack_size = stack_size - 32; /* Reserve 32 bytes for the shadow space. */ - void** stack_high_ptr = (void**)((size_t)stack_base + stack_size - sizeof(size_t)); - stack_high_ptr[0] = (void*)(0xdeaddeaddeaddead); /* Dummy return address. */ - ctx->rip = (void*)(_mco_wrap_main); - ctx->rsp = (void*)(stack_high_ptr); - ctx->r12 = (void*)(_mco_main); - ctx->r13 = (void*)(co); - void* stack_top = (void*)((size_t)stack_base + stack_size); - ctx->stack_base = stack_top; - ctx->stack_limit = stack_base; - ctx->dealloc_stack = stack_base; - return MCO_SUCCESS; -} - -#else /* not _WIN32 */ - -typedef struct _mco_ctxbuf { - void *rip, *rsp, *rbp, *rbx, *r12, *r13, *r14, *r15; -} _mco_ctxbuf; - -void _mco_wrap_main(void); -int _mco_switch(_mco_ctxbuf* from, _mco_ctxbuf* to); - -__asm__(".text\n" -#ifdef __MACH__ /* Mac OS X assembler */ - ".globl __mco_wrap_main\n" - "__mco_wrap_main:\n" -#else /* Linux assembler */ - ".globl _mco_wrap_main\n" - ".type _mco_wrap_main @function\n" - ".hidden _mco_wrap_main\n" - "_mco_wrap_main:\n" -#endif - " movq %r13, %rdi\n" - " jmpq *%r12\n" -#ifndef __MACH__ - ".size _mco_wrap_main, .-_mco_wrap_main\n" -#endif -); - -__asm__(".text\n" -#ifdef __MACH__ /* Mac OS assembler */ - ".globl __mco_switch\n" - "__mco_switch:\n" -#else /* Linux assembler */ - ".globl _mco_switch\n" - ".type _mco_switch @function\n" - ".hidden _mco_switch\n" - "_mco_switch:\n" -#endif - " leaq 0x3d(%rip), %rax\n" - " movq %rax, (%rdi)\n" - " movq %rsp, 8(%rdi)\n" - " movq %rbp, 16(%rdi)\n" - " movq %rbx, 24(%rdi)\n" - " movq %r12, 32(%rdi)\n" - " movq %r13, 40(%rdi)\n" - " movq %r14, 48(%rdi)\n" - " movq %r15, 56(%rdi)\n" - " movq 56(%rsi), %r15\n" - " movq 48(%rsi), %r14\n" - " movq 40(%rsi), %r13\n" - " movq 32(%rsi), %r12\n" - " movq 24(%rsi), %rbx\n" - " movq 16(%rsi), %rbp\n" - " movq 8(%rsi), %rsp\n" - " jmpq *(%rsi)\n" - " ret\n" -#ifndef __MACH__ - ".size _mco_switch, .-_mco_switch\n" -#endif -); - -static mco_result _mco_makectx(mco_coro* co, _mco_ctxbuf* ctx, void* stack_base, - size_t stack_size) { - stack_size = - stack_size - 128; /* Reserve 128 bytes for the Red Zone space (System V AMD64 ABI). */ - void** stack_high_ptr = (void**)((size_t)stack_base + stack_size - sizeof(size_t)); - stack_high_ptr[0] = (void*)(0xdeaddeaddeaddead); /* Dummy return address. */ - ctx->rip = (void*)(_mco_wrap_main); - ctx->rsp = (void*)(stack_high_ptr); - ctx->r12 = (void*)(_mco_main); - ctx->r13 = (void*)(co); - return MCO_SUCCESS; -} - -#endif /* not _WIN32 */ - -#elif defined(__riscv) - -typedef struct _mco_ctxbuf { - void* s[12]; /* s0-s11 */ - void* ra; - void* pc; - void* sp; -#ifdef __riscv_flen -#if __riscv_flen == 64 - double fs[12]; /* fs0-fs11 */ -#elif __riscv_flen == 32 - float fs[12]; /* fs0-fs11 */ -#endif -#endif /* __riscv_flen */ -} _mco_ctxbuf; - -void _mco_wrap_main(void); -int _mco_switch(_mco_ctxbuf* from, _mco_ctxbuf* to); - -__asm__(".text\n" - ".globl _mco_wrap_main\n" - ".type _mco_wrap_main @function\n" - ".hidden _mco_wrap_main\n" - "_mco_wrap_main:\n" - " mv a0, s0\n" - " jr s1\n" - ".size _mco_wrap_main, .-_mco_wrap_main\n"); - -__asm__(".text\n" - ".globl _mco_switch\n" - ".type _mco_switch @function\n" - ".hidden _mco_switch\n" - "_mco_switch:\n" -#if __riscv_xlen == 64 - " sd s0, 0x00(a0)\n" - " sd s1, 0x08(a0)\n" - " sd s2, 0x10(a0)\n" - " sd s3, 0x18(a0)\n" - " sd s4, 0x20(a0)\n" - " sd s5, 0x28(a0)\n" - " sd s6, 0x30(a0)\n" - " sd s7, 0x38(a0)\n" - " sd s8, 0x40(a0)\n" - " sd s9, 0x48(a0)\n" - " sd s10, 0x50(a0)\n" - " sd s11, 0x58(a0)\n" - " sd ra, 0x60(a0)\n" - " sd ra, 0x68(a0)\n" /* pc */ - " sd sp, 0x70(a0)\n" -#ifdef __riscv_flen -#if __riscv_flen == 64 - " fsd fs0, 0x78(a0)\n" - " fsd fs1, 0x80(a0)\n" - " fsd fs2, 0x88(a0)\n" - " fsd fs3, 0x90(a0)\n" - " fsd fs4, 0x98(a0)\n" - " fsd fs5, 0xa0(a0)\n" - " fsd fs6, 0xa8(a0)\n" - " fsd fs7, 0xb0(a0)\n" - " fsd fs8, 0xb8(a0)\n" - " fsd fs9, 0xc0(a0)\n" - " fsd fs10, 0xc8(a0)\n" - " fsd fs11, 0xd0(a0)\n" - " fld fs0, 0x78(a1)\n" - " fld fs1, 0x80(a1)\n" - " fld fs2, 0x88(a1)\n" - " fld fs3, 0x90(a1)\n" - " fld fs4, 0x98(a1)\n" - " fld fs5, 0xa0(a1)\n" - " fld fs6, 0xa8(a1)\n" - " fld fs7, 0xb0(a1)\n" - " fld fs8, 0xb8(a1)\n" - " fld fs9, 0xc0(a1)\n" - " fld fs10, 0xc8(a1)\n" - " fld fs11, 0xd0(a1)\n" -#else -#error "Unsupported RISC-V FLEN" -#endif -#endif /* __riscv_flen */ - " ld s0, 0x00(a1)\n" - " ld s1, 0x08(a1)\n" - " ld s2, 0x10(a1)\n" - " ld s3, 0x18(a1)\n" - " ld s4, 0x20(a1)\n" - " ld s5, 0x28(a1)\n" - " ld s6, 0x30(a1)\n" - " ld s7, 0x38(a1)\n" - " ld s8, 0x40(a1)\n" - " ld s9, 0x48(a1)\n" - " ld s10, 0x50(a1)\n" - " ld s11, 0x58(a1)\n" - " ld ra, 0x60(a1)\n" - " ld a2, 0x68(a1)\n" /* pc */ - " ld sp, 0x70(a1)\n" - " jr a2\n" -#elif __riscv_xlen == 32 - " sw s0, 0x00(a0)\n" - " sw s1, 0x04(a0)\n" - " sw s2, 0x08(a0)\n" - " sw s3, 0x0c(a0)\n" - " sw s4, 0x10(a0)\n" - " sw s5, 0x14(a0)\n" - " sw s6, 0x18(a0)\n" - " sw s7, 0x1c(a0)\n" - " sw s8, 0x20(a0)\n" - " sw s9, 0x24(a0)\n" - " sw s10, 0x28(a0)\n" - " sw s11, 0x2c(a0)\n" - " sw ra, 0x30(a0)\n" - " sw ra, 0x34(a0)\n" /* pc */ - " sw sp, 0x38(a0)\n" -#ifdef __riscv_flen -#if __riscv_flen == 64 - " fsd fs0, 0x3c(a0)\n" - " fsd fs1, 0x44(a0)\n" - " fsd fs2, 0x4c(a0)\n" - " fsd fs3, 0x54(a0)\n" - " fsd fs4, 0x5c(a0)\n" - " fsd fs5, 0x64(a0)\n" - " fsd fs6, 0x6c(a0)\n" - " fsd fs7, 0x74(a0)\n" - " fsd fs8, 0x7c(a0)\n" - " fsd fs9, 0x84(a0)\n" - " fsd fs10, 0x8c(a0)\n" - " fsd fs11, 0x94(a0)\n" - " fld fs0, 0x3c(a1)\n" - " fld fs1, 0x44(a1)\n" - " fld fs2, 0x4c(a1)\n" - " fld fs3, 0x54(a1)\n" - " fld fs4, 0x5c(a1)\n" - " fld fs5, 0x64(a1)\n" - " fld fs6, 0x6c(a1)\n" - " fld fs7, 0x74(a1)\n" - " fld fs8, 0x7c(a1)\n" - " fld fs9, 0x84(a1)\n" - " fld fs10, 0x8c(a1)\n" - " fld fs11, 0x94(a1)\n" -#elif __riscv_flen == 32 - " fsw fs0, 0x3c(a0)\n" - " fsw fs1, 0x40(a0)\n" - " fsw fs2, 0x44(a0)\n" - " fsw fs3, 0x48(a0)\n" - " fsw fs4, 0x4c(a0)\n" - " fsw fs5, 0x50(a0)\n" - " fsw fs6, 0x54(a0)\n" - " fsw fs7, 0x58(a0)\n" - " fsw fs8, 0x5c(a0)\n" - " fsw fs9, 0x60(a0)\n" - " fsw fs10, 0x64(a0)\n" - " fsw fs11, 0x68(a0)\n" - " flw fs0, 0x3c(a1)\n" - " flw fs1, 0x40(a1)\n" - " flw fs2, 0x44(a1)\n" - " flw fs3, 0x48(a1)\n" - " flw fs4, 0x4c(a1)\n" - " flw fs5, 0x50(a1)\n" - " flw fs6, 0x54(a1)\n" - " flw fs7, 0x58(a1)\n" - " flw fs8, 0x5c(a1)\n" - " flw fs9, 0x60(a1)\n" - " flw fs10, 0x64(a1)\n" - " flw fs11, 0x68(a1)\n" -#else -#error "Unsupported RISC-V FLEN" -#endif -#endif /* __riscv_flen */ - " lw s0, 0x00(a1)\n" - " lw s1, 0x04(a1)\n" - " lw s2, 0x08(a1)\n" - " lw s3, 0x0c(a1)\n" - " lw s4, 0x10(a1)\n" - " lw s5, 0x14(a1)\n" - " lw s6, 0x18(a1)\n" - " lw s7, 0x1c(a1)\n" - " lw s8, 0x20(a1)\n" - " lw s9, 0x24(a1)\n" - " lw s10, 0x28(a1)\n" - " lw s11, 0x2c(a1)\n" - " lw ra, 0x30(a1)\n" - " lw a2, 0x34(a1)\n" /* pc */ - " lw sp, 0x38(a1)\n" - " jr a2\n" -#else -#error "Unsupported RISC-V XLEN" -#endif /* __riscv_xlen */ - ".size _mco_switch, .-_mco_switch\n"); - -static mco_result _mco_makectx(mco_coro* co, _mco_ctxbuf* ctx, void* stack_base, - size_t stack_size) { - ctx->s[0] = (void*)(co); - ctx->s[1] = (void*)(_mco_main); - ctx->pc = (void*)(_mco_wrap_main); -#if __riscv_xlen == 64 - ctx->ra = (void*)(0xdeaddeaddeaddead); -#elif __riscv_xlen == 32 - ctx->ra = (void*)(0xdeaddead); -#endif - ctx->sp = (void*)((size_t)stack_base + stack_size); - return MCO_SUCCESS; -} - -#elif defined(__i386) || defined(__i386__) - -typedef struct _mco_ctxbuf { - void *eip, *esp, *ebp, *ebx, *esi, *edi; -} _mco_ctxbuf; - -void _mco_switch(_mco_ctxbuf* from, _mco_ctxbuf* to); - -__asm__( -#ifdef __DJGPP__ /* DOS compiler */ - "__mco_switch:\n" -#else - ".text\n" - ".globl _mco_switch\n" - ".type _mco_switch @function\n" - ".hidden _mco_switch\n" - "_mco_switch:\n" -#endif - " call 1f\n" - " 1:\n" - " popl %ecx\n" - " addl $(2f-1b), %ecx\n" - " movl 4(%esp), %eax\n" - " movl 8(%esp), %edx\n" - " movl %ecx, (%eax)\n" - " movl %esp, 4(%eax)\n" - " movl %ebp, 8(%eax)\n" - " movl %ebx, 12(%eax)\n" - " movl %esi, 16(%eax)\n" - " movl %edi, 20(%eax)\n" - " movl 20(%edx), %edi\n" - " movl 16(%edx), %esi\n" - " movl 12(%edx), %ebx\n" - " movl 8(%edx), %ebp\n" - " movl 4(%edx), %esp\n" - " jmp *(%edx)\n" - " 2:\n" - " ret\n" -#ifndef __DJGPP__ - ".size _mco_switch, .-_mco_switch\n" -#endif -); - -static mco_result _mco_makectx(mco_coro* co, _mco_ctxbuf* ctx, void* stack_base, - size_t stack_size) { - void** stack_high_ptr = (void**)((size_t)stack_base + stack_size - 16 - 1 * sizeof(size_t)); - stack_high_ptr[0] = (void*)(0xdeaddead); /* Dummy return address. */ - stack_high_ptr[1] = (void*)(co); - ctx->eip = (void*)(_mco_main); - ctx->esp = (void*)(stack_high_ptr); - return MCO_SUCCESS; -} - -#elif defined(__ARM_EABI__) - -typedef struct _mco_ctxbuf { -#ifndef __SOFTFP__ - void* f[16]; -#endif - void* d[4]; /* d8-d15 */ - void* r[4]; /* r4-r11 */ - void* lr; - void* sp; -} _mco_ctxbuf; - -void _mco_wrap_main(void); -int _mco_switch(_mco_ctxbuf* from, _mco_ctxbuf* to); - -__asm__(".text\n" -#ifdef __APPLE__ - ".globl __mco_switch\n" - "__mco_switch:\n" -#else - ".globl _mco_switch\n" - ".type _mco_switch #function\n" - ".hidden _mco_switch\n" - "_mco_switch:\n" -#endif -#ifndef __SOFTFP__ - " vstmia r0!, {d8-d15}\n" -#endif - " stmia r0, {r4-r11, lr}\n" - " str sp, [r0, #9*4]\n" -#ifndef __SOFTFP__ - " vldmia r1!, {d8-d15}\n" -#endif - " ldr sp, [r1, #9*4]\n" - " ldmia r1, {r4-r11, pc}\n" -#ifndef __APPLE__ - ".size _mco_switch, .-_mco_switch\n" -#endif -); - -__asm__(".text\n" -#ifdef __APPLE__ - ".globl __mco_wrap_main\n" - "__mco_wrap_main:\n" -#else - ".globl _mco_wrap_main\n" - ".type _mco_wrap_main #function\n" - ".hidden _mco_wrap_main\n" - "_mco_wrap_main:\n" -#endif - " mov r0, r4\n" - " mov ip, r5\n" - " mov lr, r6\n" - " bx ip\n" -#ifndef __APPLE__ - ".size _mco_wrap_main, .-_mco_wrap_main\n" -#endif -); - -static mco_result _mco_makectx(mco_coro* co, _mco_ctxbuf* ctx, void* stack_base, - size_t stack_size) { - ctx->d[0] = (void*)(co); - ctx->d[1] = (void*)(_mco_main); - ctx->d[2] = (void*)(0xdeaddead); /* Dummy return address. */ - ctx->lr = (void*)(_mco_wrap_main); - ctx->sp = (void*)((size_t)stack_base + stack_size); - return MCO_SUCCESS; -} - -#elif defined(__aarch64__) - -typedef struct _mco_ctxbuf { - void* x[12]; /* x19-x30 */ - void* sp; - void* lr; - void* d[8]; /* d8-d15 */ -} _mco_ctxbuf; - -void _mco_wrap_main(void); -int _mco_switch(_mco_ctxbuf* from, _mco_ctxbuf* to); - -__asm__(".text\n" -#ifdef __APPLE__ - ".globl __mco_switch\n" - "__mco_switch:\n" -#else - ".globl _mco_switch\n" - ".type _mco_switch #function\n" - ".hidden _mco_switch\n" - "_mco_switch:\n" -#endif - - " mov x10, sp\n" - " mov x11, x30\n" - " stp x19, x20, [x0, #(0*16)]\n" - " stp x21, x22, [x0, #(1*16)]\n" - " stp d8, d9, [x0, #(7*16)]\n" - " stp x23, x24, [x0, #(2*16)]\n" - " stp d10, d11, [x0, #(8*16)]\n" - " stp x25, x26, [x0, #(3*16)]\n" - " stp d12, d13, [x0, #(9*16)]\n" - " stp x27, x28, [x0, #(4*16)]\n" - " stp d14, d15, [x0, #(10*16)]\n" - " stp x29, x30, [x0, #(5*16)]\n" - " stp x10, x11, [x0, #(6*16)]\n" - " ldp x19, x20, [x1, #(0*16)]\n" - " ldp x21, x22, [x1, #(1*16)]\n" - " ldp d8, d9, [x1, #(7*16)]\n" - " ldp x23, x24, [x1, #(2*16)]\n" - " ldp d10, d11, [x1, #(8*16)]\n" - " ldp x25, x26, [x1, #(3*16)]\n" - " ldp d12, d13, [x1, #(9*16)]\n" - " ldp x27, x28, [x1, #(4*16)]\n" - " ldp d14, d15, [x1, #(10*16)]\n" - " ldp x29, x30, [x1, #(5*16)]\n" - " ldp x10, x11, [x1, #(6*16)]\n" - " mov sp, x10\n" - " br x11\n" -#ifndef __APPLE__ - ".size _mco_switch, .-_mco_switch\n" -#endif -); - -__asm__(".text\n" -#ifdef __APPLE__ - ".globl __mco_wrap_main\n" - "__mco_wrap_main:\n" -#else - ".globl _mco_wrap_main\n" - ".type _mco_wrap_main #function\n" - ".hidden _mco_wrap_main\n" - "_mco_wrap_main:\n" -#endif - " mov x0, x19\n" - " mov x30, x21\n" - " br x20\n" -#ifndef __APPLE__ - ".size _mco_wrap_main, .-_mco_wrap_main\n" -#endif -); - -static mco_result _mco_makectx(mco_coro* co, _mco_ctxbuf* ctx, void* stack_base, - size_t stack_size) { - ctx->x[0] = (void*)(co); - ctx->x[1] = (void*)(_mco_main); - ctx->x[2] = (void*)(0xdeaddeaddeaddead); /* Dummy return address. */ - ctx->sp = (void*)((size_t)stack_base + stack_size); - ctx->lr = (void*)(_mco_wrap_main); - return MCO_SUCCESS; -} - -#else - -#error "Unsupported architecture for assembly method." - -#endif /* ARCH */ - -#elif defined(MCO_USE_UCONTEXT) - -#include - -typedef ucontext_t _mco_ctxbuf; - -#if defined(_LP64) || defined(__LP64__) -static void _mco_wrap_main(unsigned int lo, unsigned int hi) { - mco_coro* co = - (mco_coro*)(((size_t)lo) | (((size_t)hi) << 32)); /* Extract coroutine pointer. */ - _mco_main(co); -} -#else -static void _mco_wrap_main(unsigned int lo) { - mco_coro* co = (mco_coro*)((size_t)lo); /* Extract coroutine pointer. */ - _mco_main(co); -} -#endif - -static MCO_FORCE_INLINE void _mco_switch(_mco_ctxbuf* from, _mco_ctxbuf* to) { - int res = swapcontext(from, to); - _MCO_UNUSED(res); - MCO_ASSERT(res == 0); -} - -static mco_result _mco_makectx(mco_coro* co, _mco_ctxbuf* ctx, void* stack_base, - size_t stack_size) { - /* Initialize ucontext. */ - if (getcontext(ctx) != 0) { - MCO_LOG("failed to get ucontext"); - return MCO_MAKE_CONTEXT_ERROR; - } - ctx->uc_link = NULL; /* We never exit from _mco_wrap_main. */ - ctx->uc_stack.ss_sp = stack_base; - ctx->uc_stack.ss_size = stack_size; - unsigned int lo = (unsigned int)((size_t)co); -#if defined(_LP64) || defined(__LP64__) - unsigned int hi = (unsigned int)(((size_t)co) >> 32); - makecontext(ctx, (void (*)(void))_mco_wrap_main, 2, lo, hi); -#else - makecontext(ctx, (void (*)(void))_mco_wrap_main, 1, lo); -#endif - return MCO_SUCCESS; -} - -#endif /* defined(MCO_USE_UCONTEXT) */ - -#ifdef MCO_USE_VALGRIND -#include -#endif - -typedef struct _mco_context { -#ifdef MCO_USE_VALGRIND - unsigned int valgrind_stack_id; -#endif - _mco_ctxbuf ctx; - _mco_ctxbuf back_ctx; -} _mco_context; - -static void _mco_jumpin(mco_coro* co) { - _mco_context* context = (_mco_context*)co->context; - _mco_prepare_jumpin(co); - _mco_switch(&context->back_ctx, &context->ctx); /* Do the context switch. */ -} - -static void _mco_jumpout(mco_coro* co) { - _mco_context* context = (_mco_context*)co->context; - _mco_prepare_jumpout(co); - _mco_switch(&context->ctx, &context->back_ctx); /* Do the context switch. */ -} - -static mco_result _mco_create_context(mco_coro* co, mco_desc* desc) { - /* Determine the context and stack address. */ - size_t co_addr = (size_t)co; - size_t context_addr = _mco_align_forward(co_addr + sizeof(mco_coro), 16); - size_t storage_addr = _mco_align_forward(context_addr + sizeof(_mco_context), 16); - size_t stack_addr = _mco_align_forward(storage_addr + desc->storage_size, 16); - /* Initialize context. */ - _mco_context* context = (_mco_context*)context_addr; - memset(context, 0, sizeof(_mco_context)); - /* Initialize storage. */ - unsigned char* storage = (unsigned char*)storage_addr; - /* Initialize stack. */ - void* stack_base = (void*)stack_addr; - size_t stack_size = desc->stack_size; - /* Make the context. */ - mco_result res = _mco_makectx(co, &context->ctx, stack_base, stack_size); - if (res != MCO_SUCCESS) { - return res; - } -#ifdef MCO_USE_VALGRIND - context->valgrind_stack_id = VALGRIND_STACK_REGISTER(stack_addr, stack_addr + stack_size); -#endif - co->context = context; - co->stack_base = stack_base; - co->stack_size = stack_size; - co->storage = storage; - co->storage_size = desc->storage_size; - return MCO_SUCCESS; -} - -static void _mco_destroy_context(mco_coro* co) { -#ifdef MCO_USE_VALGRIND - _mco_context* context = (_mco_context*)co->context; - if (context && context->valgrind_stack_id != 0) { - VALGRIND_STACK_DEREGISTER(context->valgrind_stack_id); - context->valgrind_stack_id = 0; - } -#else - _MCO_UNUSED(co); -#endif -} - -static MCO_FORCE_INLINE void _mco_init_desc_sizes(mco_desc* desc, size_t stack_size) { - desc->coro_size = _mco_align_forward(sizeof(mco_coro), 16) + - _mco_align_forward(sizeof(_mco_context), 16) + - _mco_align_forward(desc->storage_size, 16) + stack_size + 16; - desc->stack_size = stack_size; /* This is just a hint, it won't be the real one. */ -} - -#endif /* defined(MCO_USE_UCONTEXT) || defined(MCO_USE_ASM) */ - -/* ---------------------------------------------------------------------------------------------- */ - -#ifdef MCO_USE_FIBERS - -#ifdef _WIN32 - -typedef struct _mco_context { - void* fib; - void* back_fib; -} _mco_context; - -static void _mco_jumpin(mco_coro* co) { - void* cur_fib = GetCurrentFiber(); - if (!cur_fib || - cur_fib == - (void*)0x1e00) { /* See http://blogs.msdn.com/oldnewthing/archive/2004/12/31/344799.aspx - */ - cur_fib = ConvertThreadToFiber(NULL); - } - MCO_ASSERT(cur_fib != NULL); - _mco_context* context = (_mco_context*)co->context; - context->back_fib = cur_fib; - _mco_prepare_jumpin(co); - SwitchToFiber(context->fib); -} - -static void CALLBACK _mco_wrap_main(void* co) { - _mco_main((mco_coro*)co); -} - -static void _mco_jumpout(mco_coro* co) { - _mco_context* context = (_mco_context*)co->context; - void* back_fib = context->back_fib; - MCO_ASSERT(back_fib != NULL); - context->back_fib = NULL; - _mco_prepare_jumpout(co); - SwitchToFiber(back_fib); -} - -/* Reverse engineered Fiber struct, used to get stack base. */ -typedef struct _mco_fiber { - LPVOID param; /* fiber param */ - void* except; /* saved exception handlers list */ - void* stack_base; /* top of fiber stack */ - void* stack_limit; /* fiber stack low-water mark */ - void* stack_allocation; /* base of the fiber stack allocation */ - CONTEXT context; /* fiber context */ - DWORD flags; /* fiber flags */ - LPFIBER_START_ROUTINE start; /* start routine */ - void** fls_slots; /* fiber storage slots */ -} _mco_fiber; - -static mco_result _mco_create_context(mco_coro* co, mco_desc* desc) { - /* Determine the context address. */ - size_t co_addr = (size_t)co; - size_t context_addr = _mco_align_forward(co_addr + sizeof(mco_coro), 16); - size_t storage_addr = _mco_align_forward(context_addr + sizeof(_mco_context), 16); - /* Initialize context. */ - _mco_context* context = (_mco_context*)context_addr; - memset(context, 0, sizeof(_mco_context)); - /* Initialize storage. */ - unsigned char* storage = (unsigned char*)storage_addr; - /* Create the fiber. */ - _mco_fiber* fib = (_mco_fiber*)CreateFiberEx(desc->stack_size, desc->stack_size, - FIBER_FLAG_FLOAT_SWITCH, _mco_wrap_main, co); - if (!fib) { - MCO_LOG("failed to create fiber"); - return MCO_MAKE_CONTEXT_ERROR; - } - context->fib = fib; - co->context = context; - co->stack_base = (void*)((size_t)fib->stack_base - desc->stack_size); - co->stack_size = desc->stack_size; - co->storage = storage; - co->storage_size = desc->storage_size; - return MCO_SUCCESS; -} - -static void _mco_destroy_context(mco_coro* co) { - _mco_context* context = (_mco_context*)co->context; - if (context && context->fib) { - DeleteFiber(context->fib); - context->fib = NULL; - } -} - -static MCO_FORCE_INLINE void _mco_init_desc_sizes(mco_desc* desc, size_t stack_size) { - desc->coro_size = _mco_align_forward(sizeof(mco_coro), 16) + - _mco_align_forward(sizeof(_mco_context), 16) + - _mco_align_forward(desc->storage_size, 16) + 16; - desc->stack_size = stack_size; -} - -#elif defined(__EMSCRIPTEN__) - -#include - -#ifndef MCO_ASYNCFY_STACK_SIZE -#define MCO_ASYNCFY_STACK_SIZE 16384 -#endif - -typedef struct _mco_context { - emscripten_fiber_t fib; - emscripten_fiber_t* back_fib; -} _mco_context; - -static emscripten_fiber_t* running_fib = NULL; -static unsigned char main_asyncify_stack[MCO_ASYNCFY_STACK_SIZE]; -static emscripten_fiber_t main_fib; - -static void _mco_wrap_main(void* co) { - _mco_main((mco_coro*)co); -} - -static void _mco_jumpin(mco_coro* co) { - _mco_context* context = (_mco_context*)co->context; - emscripten_fiber_t* back_fib = running_fib; - if (!back_fib) { - back_fib = &main_fib; - emscripten_fiber_init_from_current_context(back_fib, main_asyncify_stack, - MCO_ASYNCFY_STACK_SIZE); - } - running_fib = &context->fib; - context->back_fib = back_fib; - _mco_prepare_jumpin(co); - emscripten_fiber_swap(back_fib, &context->fib); /* Do the context switch. */ -} - -static void _mco_jumpout(mco_coro* co) { - _mco_context* context = (_mco_context*)co->context; - running_fib = context->back_fib; - _mco_prepare_jumpout(co); - emscripten_fiber_swap(&context->fib, context->back_fib); /* Do the context switch. */ -} - -static mco_result _mco_create_context(mco_coro* co, mco_desc* desc) { - if (emscripten_has_asyncify() != 1) { - MCO_LOG("failed to create fiber because ASYNCIFY is not enabled"); - return MCO_MAKE_CONTEXT_ERROR; - } - /* Determine the context address. */ - size_t co_addr = (size_t)co; - size_t context_addr = _mco_align_forward(co_addr + sizeof(mco_coro), 16); - size_t storage_addr = _mco_align_forward(context_addr + sizeof(_mco_context), 16); - size_t stack_addr = _mco_align_forward(storage_addr + desc->storage_size, 16); - size_t asyncify_stack_addr = _mco_align_forward(stack_addr + desc->stack_size, 16); - /* Initialize context. */ - _mco_context* context = (_mco_context*)context_addr; - memset(context, 0, sizeof(_mco_context)); - /* Initialize storage. */ - unsigned char* storage = (unsigned char*)storage_addr; - /* Initialize stack. */ - void* stack_base = (void*)stack_addr; - size_t stack_size = asyncify_stack_addr - stack_addr; - void* asyncify_stack_base = (void*)asyncify_stack_addr; - size_t asyncify_stack_size = co_addr + desc->coro_size - asyncify_stack_addr; - /* Create the fiber. */ - emscripten_fiber_init(&context->fib, _mco_wrap_main, co, stack_base, stack_size, - asyncify_stack_base, asyncify_stack_size); - co->context = context; - co->stack_base = stack_base; - co->stack_size = stack_size; - co->storage = storage; - co->storage_size = desc->storage_size; - return MCO_SUCCESS; -} - -static void _mco_destroy_context(mco_coro* co) { - /* Nothing to do. */ - _MCO_UNUSED(co); -} - -static MCO_FORCE_INLINE void _mco_init_desc_sizes(mco_desc* desc, size_t stack_size) { - desc->coro_size = - _mco_align_forward(sizeof(mco_coro), 16) + _mco_align_forward(sizeof(_mco_context), 16) + - _mco_align_forward(desc->storage_size, 16) + _mco_align_forward(stack_size, 16) + - _mco_align_forward(MCO_ASYNCFY_STACK_SIZE, 16) + 16; - desc->stack_size = stack_size; /* This is just a hint, it won't be the real one. */ -} - -#else - -#error "Unsupported architecture for fibers method." - -#endif - -#endif /* MCO_USE_FIBERS */ - -/* ---------------------------------------------------------------------------------------------- */ - -#ifdef MCO_USE_ASYNCIFY - -typedef struct _asyncify_stack_region { - void* start; - void* limit; -} _asyncify_stack_region; - -typedef struct _mco_context { - int rewind_id; - _asyncify_stack_region stack_region; -} _mco_context; - -__attribute__((import_module("asyncify"), import_name("start_unwind"))) void _asyncify_start_unwind( - void*); -__attribute__((import_module("asyncify"), import_name("stop_unwind"))) void _asyncify_stop_unwind(); -__attribute__((import_module("asyncify"), import_name("start_rewind"))) void _asyncify_start_rewind( - void*); -__attribute__((import_module("asyncify"), import_name("stop_rewind"))) void _asyncify_stop_rewind(); - -MCO_NO_INLINE void _mco_jumpin(mco_coro* co) { - _mco_context* context = (_mco_context*)co->context; - _mco_prepare_jumpin(co); - if (context->rewind_id > 0) { /* Begin rewinding until last yield point. */ - _asyncify_start_rewind(&context->stack_region); - } - _mco_main(co); /* Run the coroutine function. */ - _asyncify_stop_unwind(); /* Stop saving coroutine stack. */ -} - -static MCO_NO_INLINE void _mco_finish_jumpout(mco_coro* co, volatile int rewind_id) { - _mco_context* context = (_mco_context*)co->context; - int next_rewind_id = context->rewind_id + 1; - if (rewind_id == next_rewind_id) { /* Begins unwinding the stack (save locals and call stack to - rewind later) */ - _mco_prepare_jumpout(co); - context->rewind_id = next_rewind_id; - _asyncify_start_unwind(&context->stack_region); - } else if (rewind_id == context->rewind_id) { /* Continue from yield point. */ - _asyncify_stop_rewind(); - } - /* Otherwise, we should be rewinding, let it continue... */ -} - -MCO_NO_INLINE void _mco_jumpout(mco_coro* co) { - _mco_context* context = (_mco_context*)co->context; - /* - Save rewind point into a local, that should be restored when rewinding. - That is "rewind_id != co->rewind_id + 1" may be true when rewinding. - Use volatile here just to be safe from compiler optimizing this out. - */ - volatile int rewind_id = context->rewind_id + 1; - _mco_finish_jumpout(co, rewind_id); -} - -static mco_result _mco_create_context(mco_coro* co, mco_desc* desc) { - /* Determine the context address. */ - size_t co_addr = (size_t)co; - size_t context_addr = _mco_align_forward(co_addr + sizeof(mco_coro), 16); - size_t storage_addr = _mco_align_forward(context_addr + sizeof(_mco_context), 16); - size_t stack_addr = _mco_align_forward(storage_addr + desc->storage_size, 16); - /* Initialize context. */ - _mco_context* context = (_mco_context*)context_addr; - memset(context, 0, sizeof(_mco_context)); - /* Initialize storage. */ - unsigned char* storage = (unsigned char*)storage_addr; - /* Initialize stack. */ - void* stack_base = (void*)stack_addr; - size_t stack_size = desc->stack_size; - context->stack_region.start = stack_base; - context->stack_region.limit = (void*)((size_t)stack_base + stack_size); - co->context = context; - co->stack_base = stack_base; - co->stack_size = stack_size; - co->storage = storage; - co->storage_size = desc->storage_size; - return MCO_SUCCESS; -} - -static void _mco_destroy_context(mco_coro* co) { - /* Nothing to do. */ - _MCO_UNUSED(co); -} - -static MCO_FORCE_INLINE void _mco_init_desc_sizes(mco_desc* desc, size_t stack_size) { - desc->coro_size = - _mco_align_forward(sizeof(mco_coro), 16) + _mco_align_forward(sizeof(_mco_context), 16) + - _mco_align_forward(desc->storage_size, 16) + _mco_align_forward(stack_size, 16) + 16; - desc->stack_size = stack_size; /* This is just a hint, it won't be the real one. */ -} - -#endif /* MCO_USE_ASYNCIFY */ - -/* ---------------------------------------------------------------------------------------------- */ - -mco_desc mco_desc_init(void (*func)(mco_coro* co), size_t stack_size) { - if (stack_size != 0) { - /* Stack size should be at least `MCO_MIN_STACK_SIZE`. */ - if (stack_size < MCO_MIN_STACK_SIZE) { - stack_size = MCO_MIN_STACK_SIZE; - } - } else { - stack_size = MCO_DEFAULT_STACK_SIZE; - } - stack_size = _mco_align_forward(stack_size, 16); /* Stack size should be aligned to 16 bytes. */ - mco_desc desc; - memset(&desc, 0, sizeof(mco_desc)); -#ifndef MCO_NO_DEFAULT_ALLOCATOR - /* Set default allocators. */ - desc.alloc_cb = mco_alloc; - desc.dealloc_cb = mco_dealloc; -#endif - desc.func = func; - desc.storage_size = MCO_DEFAULT_STORAGE_SIZE; - _mco_init_desc_sizes(&desc, stack_size); - return desc; -} - -static mco_result _mco_validate_desc(mco_desc* desc) { - if (!desc) { - MCO_LOG("coroutine description is NULL"); - return MCO_INVALID_ARGUMENTS; - } - if (!desc->func) { - MCO_LOG("coroutine function in invalid"); - return MCO_INVALID_ARGUMENTS; - } - if (desc->stack_size < MCO_MIN_STACK_SIZE) { - MCO_LOG("coroutine stack size is too small"); - return MCO_INVALID_ARGUMENTS; - } - if (desc->coro_size < sizeof(mco_coro)) { - MCO_LOG("coroutine size is invalid"); - return MCO_INVALID_ARGUMENTS; - } - return MCO_SUCCESS; -} - -mco_result mco_init(mco_coro* co, mco_desc* desc) { - if (!co) { - MCO_LOG("attempt to initialize an invalid coroutine"); - return MCO_INVALID_COROUTINE; - } - memset(co, 0, sizeof(mco_coro)); - /* Validate coroutine description. */ - mco_result res = _mco_validate_desc(desc); - if (res != MCO_SUCCESS) - return res; - /* Create the coroutine. */ - res = _mco_create_context(co, desc); - if (res != MCO_SUCCESS) - return res; - co->state = MCO_SUSPENDED; /* We initialize in suspended state. */ - co->dealloc_cb = desc->dealloc_cb; - co->coro_size = desc->coro_size; - co->allocator_data = desc->allocator_data; - co->func = desc->func; - co->user_data = desc->user_data; -#ifdef _MCO_USE_TSAN - co->tsan_fiber = __tsan_create_fiber(0); -#endif - co->magic_number = MCO_MAGIC_NUMBER; - return MCO_SUCCESS; -} - -mco_result mco_uninit(mco_coro* co) { - if (!co) { - MCO_LOG("attempt to uninitialize an invalid coroutine"); - return MCO_INVALID_COROUTINE; - } - /* Cannot uninitialize while running. */ - if (!(co->state == MCO_SUSPENDED || co->state == MCO_DEAD)) { - MCO_LOG("attempt to uninitialize a coroutine that is not dead or suspended"); - return MCO_INVALID_OPERATION; - } - /* The coroutine is now dead and cannot be used anymore. */ - co->state = MCO_DEAD; -#ifdef _MCO_USE_TSAN - if (co->tsan_fiber != NULL) { - __tsan_destroy_fiber(co->tsan_fiber); - co->tsan_fiber = NULL; - } -#endif - _mco_destroy_context(co); - return MCO_SUCCESS; -} - -mco_result mco_create(mco_coro** out_co, mco_desc* desc) { - /* Validate input. */ - if (!out_co) { - MCO_LOG("coroutine output pointer is NULL"); - return MCO_INVALID_POINTER; - } - if (!desc || !desc->alloc_cb || !desc->dealloc_cb) { - *out_co = NULL; - MCO_LOG("coroutine allocator description is not set"); - return MCO_INVALID_ARGUMENTS; - } - /* Allocate the coroutine. */ - mco_coro* co = (mco_coro*)desc->alloc_cb(desc->coro_size, desc->allocator_data); - if (!co) { - MCO_LOG("coroutine allocation failed"); - *out_co = NULL; - return MCO_OUT_OF_MEMORY; - } - /* Initialize the coroutine. */ - mco_result res = mco_init(co, desc); - if (res != MCO_SUCCESS) { - desc->dealloc_cb(co, desc->coro_size, desc->allocator_data); - *out_co = NULL; - return res; - } - *out_co = co; - return MCO_SUCCESS; -} - -mco_result mco_destroy(mco_coro* co) { - if (!co) { - MCO_LOG("attempt to destroy an invalid coroutine"); - return MCO_INVALID_COROUTINE; - } - /* Uninitialize the coroutine first. */ - mco_result res = mco_uninit(co); - if (res != MCO_SUCCESS) - return res; - /* Free the coroutine. */ - if (!co->dealloc_cb) { - MCO_LOG("attempt destroy a coroutine that has no free callback"); - return MCO_INVALID_POINTER; - } - co->dealloc_cb(co, co->coro_size, co->allocator_data); - return MCO_SUCCESS; -} - -mco_result mco_resume(mco_coro* co) { - if (!co) { - MCO_LOG("attempt to resume an invalid coroutine"); - return MCO_INVALID_COROUTINE; - } - if (co->state != MCO_SUSPENDED) { /* Can only resume coroutines that are suspended. */ - MCO_LOG("attempt to resume a coroutine that is not suspended"); - return MCO_NOT_SUSPENDED; - } - co->state = MCO_RUNNING; /* The coroutine is now running. */ - _mco_jumpin(co); - return MCO_SUCCESS; -} - -mco_result mco_yield(mco_coro* co) { - if (!co) { - MCO_LOG("attempt to yield an invalid coroutine"); - return MCO_INVALID_COROUTINE; - } -#ifdef MCO_USE_ASYNCIFY - /* Asyncify already checks for stack overflow. */ -#else - /* This check happens when the stack overflow already happened, but better later than never. */ - volatile size_t dummy; - size_t stack_addr = (size_t)&dummy; - size_t stack_min = (size_t)co->stack_base; - size_t stack_max = stack_min + co->stack_size; - if (co->magic_number != MCO_MAGIC_NUMBER || stack_addr < stack_min || - stack_addr > stack_max) { /* Stack overflow. */ - MCO_LOG("coroutine stack overflow, try increasing the stack size"); - return MCO_STACK_OVERFLOW; - } -#endif - if (co->state != MCO_RUNNING) { /* Can only yield coroutines that are running. */ - MCO_LOG("attempt to yield a coroutine that is not running"); - return MCO_NOT_RUNNING; - } - co->state = MCO_SUSPENDED; /* The coroutine is now suspended. */ - _mco_jumpout(co); - return MCO_SUCCESS; -} - -mco_state mco_status(mco_coro* co) { - if (co != NULL) { - return co->state; - } - return MCO_DEAD; -} - -void* mco_get_user_data(mco_coro* co) { - if (co != NULL) { - return co->user_data; - } - return NULL; -} - -mco_result mco_push(mco_coro* co, const void* src, size_t len) { - if (!co) { - MCO_LOG("attempt to use an invalid coroutine"); - return MCO_INVALID_COROUTINE; - } else if (len > 0) { - size_t bytes_stored = co->bytes_stored + len; - if (bytes_stored > co->storage_size) { - MCO_LOG("attempt to push too many bytes into coroutine storage"); - return MCO_NOT_ENOUGH_SPACE; - } - if (!src) { - MCO_LOG("attempt push a null pointer into coroutine storage"); - return MCO_INVALID_POINTER; - } - memcpy(&co->storage[co->bytes_stored], src, len); - co->bytes_stored = bytes_stored; - } - return MCO_SUCCESS; -} - -mco_result mco_pop(mco_coro* co, void* dest, size_t len) { - if (!co) { - MCO_LOG("attempt to use an invalid coroutine"); - return MCO_INVALID_COROUTINE; - } else if (len > 0) { - if (len > co->bytes_stored) { - MCO_LOG("attempt to pop too many bytes from coroutine storage"); - return MCO_NOT_ENOUGH_SPACE; - } - size_t bytes_stored = co->bytes_stored - len; - if (dest) { - memcpy(dest, &co->storage[bytes_stored], len); - } - co->bytes_stored = bytes_stored; -#ifdef MCO_ZERO_MEMORY - /* Clear garbage in the discarded storage. */ - memset(&co->storage[bytes_stored], 0, len); -#endif - } - return MCO_SUCCESS; -} - -mco_result mco_peek(mco_coro* co, void* dest, size_t len) { - if (!co) { - MCO_LOG("attempt to use an invalid coroutine"); - return MCO_INVALID_COROUTINE; - } else if (len > 0) { - if (len > co->bytes_stored) { - MCO_LOG("attempt to peek too many bytes from coroutine storage"); - return MCO_NOT_ENOUGH_SPACE; - } - if (!dest) { - MCO_LOG("attempt peek into a null pointer"); - return MCO_INVALID_POINTER; - } - memcpy(dest, &co->storage[co->bytes_stored - len], len); - } - return MCO_SUCCESS; -} - -size_t mco_get_bytes_stored(mco_coro* co) { - if (co == NULL) { - return 0; - } - return co->bytes_stored; -} - -size_t mco_get_storage_size(mco_coro* co) { - if (co == NULL) { - return 0; - } - return co->storage_size; -} - -#ifdef MCO_NO_MULTITHREAD -mco_coro* mco_running(void) { - return mco_current_co; -} -#else -static MCO_NO_INLINE mco_coro* _mco_running(void) { - return mco_current_co; -} -mco_coro* mco_running(void) { - /* - Compilers aggressively optimize the use of TLS by caching loads. - Since fiber code can migrate between threads it’s possible for the load to be stale. - To prevent this from happening we avoid inline functions. - */ - mco_coro* (*volatile func)(void) = _mco_running; - return func(); -} -#endif - -const char* mco_result_description(mco_result res) { - switch (res) { - case MCO_SUCCESS: - return "No error"; - case MCO_GENERIC_ERROR: - return "Generic error"; - case MCO_INVALID_POINTER: - return "Invalid pointer"; - case MCO_INVALID_COROUTINE: - return "Invalid coroutine"; - case MCO_NOT_SUSPENDED: - return "Coroutine not suspended"; - case MCO_NOT_RUNNING: - return "Coroutine not running"; - case MCO_MAKE_CONTEXT_ERROR: - return "Make context error"; - case MCO_SWITCH_CONTEXT_ERROR: - return "Switch context error"; - case MCO_NOT_ENOUGH_SPACE: - return "Not enough space"; - case MCO_OUT_OF_MEMORY: - return "Out of memory"; - case MCO_INVALID_ARGUMENTS: - return "Invalid arguments"; - case MCO_INVALID_OPERATION: - return "Invalid operation"; - case MCO_STACK_OVERFLOW: - return "Stack overflow"; - } - return "Unknown error"; -} - -#ifdef __cplusplus -} -#endif - -#endif /* MINICORO_IMPL */ - -/* -This software is available as a choice of the following licenses. Choose -whichever you prefer. - -=============================================================================== -ALTERNATIVE 1 - Public Domain (www.unlicense.org) -=============================================================================== -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or distribute this -software, either in source code form or as a compiled binary, for any purpose, -commercial or non-commercial, and by any means. - -In jurisdictions that recognize copyright laws, the author or authors of this -software dedicate any and all copyright interest in the software to the public -domain. We make this dedication for the benefit of the public at large and to -the detriment of our heirs and successors. We intend this dedication to be an -overt act of relinquishment in perpetuity of all present and future rights to -this software under copyright law. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to - -=============================================================================== -ALTERNATIVE 2 - MIT No Attribution -=============================================================================== -Copyright (c) 2021-2023 Eduardo Bart (https://github.com/edubart/minicoro) - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ diff --git a/src/tests/common/fibers.cpp b/src/tests/common/fibers.cpp index 7bc13d1131..f560d9b2f6 100644 --- a/src/tests/common/fibers.cpp +++ b/src/tests/common/fibers.cpp @@ -271,4 +271,43 @@ TEST_CASE("Fibers::StartRace", "[common]") { REQUIRE(test_control.value3 == 1); } +class TestControl4; + +class TestControl4 { +public: + TestControl4() { + fiber1 = std::make_shared([this] { DoWork(); }); + goal_reached = false; + rewinded = false; + } + + void Execute() { + thread_fiber = Fiber::ThreadToFiber(); + Fiber::YieldTo(thread_fiber, *fiber1); + thread_fiber->Exit(); + } + + void DoWork() { + fiber1->SetRewindPoint([this] { DoWork(); }); + if (rewinded) { + goal_reached = true; + Fiber::YieldTo(fiber1, *thread_fiber); + } + rewinded = true; + fiber1->Rewind(); + } + + std::shared_ptr fiber1; + std::shared_ptr thread_fiber; + bool goal_reached; + bool rewinded; +}; + +TEST_CASE("Fibers::Rewind", "[common]") { + TestControl4 test_control{}; + test_control.Execute(); + REQUIRE(test_control.goal_reached); + REQUIRE(test_control.rewinded); +} + } // namespace Common From cdcbfdc83749e6451e34dfbc73dd40bb32e48fc6 Mon Sep 17 00:00:00 2001 From: spectranator Date: Wed, 8 May 2024 13:23:45 +0200 Subject: [PATCH 18/27] Removed leftover submodule path externals/boost-headers --- externals/boost-headers | 1 - 1 file changed, 1 deletion(-) delete mode 160000 externals/boost-headers diff --git a/externals/boost-headers b/externals/boost-headers deleted file mode 160000 index 0456900fad..0000000000 --- a/externals/boost-headers +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0456900fadde4b07c84760eadea4ccc9f948fe28 From 08f47542e84e0f4d73ea85a309d4b8fdb0e43c6a Mon Sep 17 00:00:00 2001 From: spectranator Date: Wed, 8 May 2024 14:16:40 +0200 Subject: [PATCH 19/27] Added menu option to locate current mirror repository --- src/yuzu/CMakeLists.txt | 2 +- src/yuzu/main.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/yuzu/main.h | 1 + src/yuzu/main.ui | 8 +++++++- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 0259a8c293..b67df498f2 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -382,7 +382,7 @@ elseif(WIN32) endif() target_link_libraries(yuzu PRIVATE common core input_common frontend_common network video_core) -target_link_libraries(yuzu PRIVATE Boost::headers glad Qt${QT_MAJOR_VERSION}::Widgets) +target_link_libraries(yuzu PRIVATE Boost::headers glad Qt${QT_MAJOR_VERSION}::Widgets httplib::httplib) target_link_libraries(yuzu PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads) target_link_libraries(yuzu PRIVATE Vulkan::Headers) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 6ff14063e7..e21c05bb80 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -21,6 +21,7 @@ #include "common/linux/gamemode.h" #endif +#include #include // VFS includes must be before glad as they will conflict with Windows file api, which uses defines. @@ -1524,6 +1525,7 @@ void GMainWindow::ConnectMenuEvents() { connect_menu(ui->action_Open_Mods_Page, &GMainWindow::OnOpenModsPage); connect_menu(ui->action_Open_Quickstart_Guide, &GMainWindow::OnOpenQuickstartGuide); connect_menu(ui->action_Open_FAQ, &GMainWindow::OnOpenFAQ); + connect_menu(ui->action_Open_Mirror_Repo, &GMainWindow::OnOpenMirrorRepo); connect_menu(ui->action_Restart, &GMainWindow::OnRestartGame); connect_menu(ui->action_Configure, &GMainWindow::OnConfigure); connect_menu(ui->action_Configure_Current_Game, &GMainWindow::OnConfigurePerGame); @@ -3566,6 +3568,41 @@ void GMainWindow::OnOpenFAQ() { OpenURL(QUrl(QStringLiteral("https://yuzu-emu.org/wiki/faq/"))); } +void GMainWindow::OnOpenMirrorRepo() { + struct Mirror { + const char *host, *path; + }; + const std::initializer_list mirrors = { + {"https://github.com", "/litucks/torzu"}, + {"https://gitlab.com", "/litucks/torzu"}, + {"https://bitbucket.org", "/litucks/torzu"}, + {"https://codeberg.org", "/litucks/torzu"}, + {"https://notabug.org", "/litucks/torzu"}, + {"https://gitea.com", "/litucks/torzu"}, + {"https://try.gitea.io", "/litucks/torzu"}, + {"https://git.math.hamburg", "/litucks/torzu"}, + {"https://gitea.sprint-pay.com", "/litucks/torzu"}, + {"https://gitea.djoe.ovh", "/litucks/torzu"}, + {"https://git.sheetjs.com", "/litucks/torzu"}, + {"https://gitea.cisetech.com", "/litucks/torzu"} + }; + + for (const auto& mirror : mirrors) { + httplib::Client cli(mirror.host); + if (cli.Get(mirror.path)) { + OpenURL(QUrl(QString::fromStdString(fmt::format("{}{}", mirror.host, mirror.path)))); + return; + } + } + + QMessageBox::warning(this, tr("Error locating mirror"), tr("There has been an error finding the current mirror repository.\n" + "Your version may be so old the list has already been depleted\n" + "or your network connectivity may be limited.\n" + "Please either try again later, through a VPN or access the main\n" + "repository via the Tor Browser:\n" + "http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu")); +} + void GMainWindow::ToggleFullscreen() { if (!emulation_running) { return; diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 03a2a5dd81..2a528b1d09 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -337,6 +337,7 @@ private slots: void OnOpenModsPage(); void OnOpenQuickstartGuide(); void OnOpenFAQ(); + void OnOpenMirrorRepo(); /// Called whenever a user selects a game in the game list widget. void OnGameListLoadFile(QString game_path, u64 program_id); void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target, diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index dfe025ca61..f958413b84 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui @@ -45,7 +45,7 @@ 0 0 1280 - 21 + 22 @@ -185,6 +185,7 @@ + @@ -481,6 +482,11 @@ Open Home Menu + + + Open current Mirror &Repo + + From bef55d43a530f90411fda0d77265c4916a5cb7f6 Mon Sep 17 00:00:00 2001 From: spectranator Date: Wed, 8 May 2024 14:30:57 +0200 Subject: [PATCH 20/27] Removed old menu entries for pages that don't exist anymore --- src/yuzu/main.cpp | 49 ----------------------------------------------- src/yuzu/main.h | 4 ---- src/yuzu/main.ui | 3 --- 3 files changed, 56 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index e21c05bb80..e2266bc9e7 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1521,10 +1521,6 @@ void GMainWindow::ConnectMenuEvents() { // Emulation connect_menu(ui->action_Pause, &GMainWindow::OnPauseContinueGame); connect_menu(ui->action_Stop, &GMainWindow::OnStopGame); - connect_menu(ui->action_Report_Compatibility, &GMainWindow::OnMenuReportCompatibility); - connect_menu(ui->action_Open_Mods_Page, &GMainWindow::OnOpenModsPage); - connect_menu(ui->action_Open_Quickstart_Guide, &GMainWindow::OnOpenQuickstartGuide); - connect_menu(ui->action_Open_FAQ, &GMainWindow::OnOpenFAQ); connect_menu(ui->action_Open_Mirror_Repo, &GMainWindow::OnOpenMirrorRepo); connect_menu(ui->action_Restart, &GMainWindow::OnRestartGame); connect_menu(ui->action_Configure, &GMainWindow::OnConfigure); @@ -3515,39 +3511,6 @@ void GMainWindow::ErrorDisplayRequestExit() { } } -void GMainWindow::OnMenuReportCompatibility() { -#if defined(ARCHITECTURE_x86_64) && !defined(__APPLE__) - const auto& caps = Common::GetCPUCaps(); - const bool has_fma = caps.fma || caps.fma4; - const auto processor_count = std::thread::hardware_concurrency(); - const bool has_4threads = processor_count == 0 || processor_count >= 4; - const bool has_8gb_ram = Common::GetMemInfo().TotalPhysicalMemory >= 8_GiB; - const bool has_broken_vulkan = UISettings::values.has_broken_vulkan; - - if (!has_fma || !has_4threads || !has_8gb_ram || has_broken_vulkan) { - QMessageBox::critical(this, tr("Hardware requirements not met"), - tr("Your system does not meet the recommended hardware requirements. " - "Compatibility reporting has been disabled.")); - return; - } - - if (!Settings::values.yuzu_token.GetValue().empty() && - !Settings::values.yuzu_username.GetValue().empty()) { - } else { - QMessageBox::critical( - this, tr("Missing yuzu Account"), - tr("In order to submit a game compatibility test case, you must link your yuzu " - "account.

To link your yuzu account, go to Emulation > Configuration " - "> " - "Web.")); - } -#else - QMessageBox::critical(this, tr("Hardware requirements not met"), - tr("Your system does not meet the recommended hardware requirements. " - "Compatibility reporting has been disabled.")); -#endif -} - void GMainWindow::OpenURL(const QUrl& url) { const bool open = QDesktopServices::openUrl(url); if (!open) { @@ -3556,18 +3519,6 @@ void GMainWindow::OpenURL(const QUrl& url) { } } -void GMainWindow::OnOpenModsPage() { - OpenURL(QUrl(QStringLiteral("https://github.com/yuzu-emu/yuzu/wiki/Switch-Mods"))); -} - -void GMainWindow::OnOpenQuickstartGuide() { - OpenURL(QUrl(QStringLiteral("https://yuzu-emu.org/help/quickstart/"))); -} - -void GMainWindow::OnOpenFAQ() { - OpenURL(QUrl(QStringLiteral("https://yuzu-emu.org/wiki/faq/"))); -} - void GMainWindow::OnOpenMirrorRepo() { struct Mirror { const char *host, *path; diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 2a528b1d09..fe96ebd19b 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -333,10 +333,6 @@ private slots: void OnPauseContinueGame(); void OnStopGame(); void OnPrepareForSleep(bool prepare_sleep); - void OnMenuReportCompatibility(); - void OnOpenModsPage(); - void OnOpenQuickstartGuide(); - void OnOpenFAQ(); void OnOpenMirrorRepo(); /// Called whenever a user selects a game in the game list widget. void OnGameListLoadFile(QString game_path, u64 program_id); diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index f958413b84..14985e782c 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui @@ -183,10 +183,7 @@ &Help - - - From ef6fc3e26a5943f12076e33348e6e9dfdc7bbd91 Mon Sep 17 00:00:00 2001 From: spectranator Date: Wed, 8 May 2024 15:29:51 +0200 Subject: [PATCH 21/27] Updated README.md: Removed Windows build off goals list as it is done --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bf358f9dbb..167de64783 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,10 @@ The first and foremost goal is long-term maintenance. Even if I stop commiting n Essentially, the main goal is that you can still use this emulator on modern systems in 20 years. It is very important to me that this project is going to be a good base to fork once grass has grown over the whole legal dilemma and people are willing to do real work on this emulator non-anonymously. -While the main platform is Linux as it is the main operating system I run on my personal and development desktops, Windows support is very near and will not be forgotten about. Android support is low priority but would be a nice bonus. - A secondary goal is the improvement of usability on low-end systems. This includes both improving the performance of the emulator as well as making games more playable below 100% speed whenever possible (the sync CPU to render speed limit option already helps with that in few cases). +Android support is low priority but would be a nice bonus. + ## Development Most of the development happens on [Dark Git](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/). It's also where [our central repository](http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu) is hosted. From 377c9bc831acea8087b3c2f1b557fce3e6c87874 Mon Sep 17 00:00:00 2001 From: spectranator Date: Wed, 8 May 2024 17:47:00 +0200 Subject: [PATCH 22/27] Implemented safer and faster way to get current mirror URL --- src/yuzu/main.cpp | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index e2266bc9e7..6c58c5558e 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -3520,38 +3520,18 @@ void GMainWindow::OpenURL(const QUrl& url) { } void GMainWindow::OnOpenMirrorRepo() { - struct Mirror { - const char *host, *path; - }; - const std::initializer_list mirrors = { - {"https://github.com", "/litucks/torzu"}, - {"https://gitlab.com", "/litucks/torzu"}, - {"https://bitbucket.org", "/litucks/torzu"}, - {"https://codeberg.org", "/litucks/torzu"}, - {"https://notabug.org", "/litucks/torzu"}, - {"https://gitea.com", "/litucks/torzu"}, - {"https://try.gitea.io", "/litucks/torzu"}, - {"https://git.math.hamburg", "/litucks/torzu"}, - {"https://gitea.sprint-pay.com", "/litucks/torzu"}, - {"https://gitea.djoe.ovh", "/litucks/torzu"}, - {"https://git.sheetjs.com", "/litucks/torzu"}, - {"https://gitea.cisetech.com", "/litucks/torzu"} - }; - - for (const auto& mirror : mirrors) { - httplib::Client cli(mirror.host); - if (cli.Get(mirror.path)) { - OpenURL(QUrl(QString::fromStdString(fmt::format("{}{}", mirror.host, mirror.path)))); - return; - } + httplib::Client cli("https://codeberg.org"); + auto res = cli.Get("/litucks/tz-mu/raw/branch/main/mu.txt"); + if (!res) { + QMessageBox::warning(this, tr("Error locating mirror"), tr("There has been an error finding the current mirror repository.
" + "Your version may be too old or your network connectivity may be" + "limited.
" + "Please either try again later, through a VPN or access the main
" + "repository via the Tor Browser:
" + "http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu")); } - QMessageBox::warning(this, tr("Error locating mirror"), tr("There has been an error finding the current mirror repository.\n" - "Your version may be so old the list has already been depleted\n" - "or your network connectivity may be limited.\n" - "Please either try again later, through a VPN or access the main\n" - "repository via the Tor Browser:\n" - "http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu")); + OpenURL(QUrl(QString::fromStdString(res->body))); } void GMainWindow::ToggleFullscreen() { From e96b877ee275b0bbda539853d9fe1f6107b57b47 Mon Sep 17 00:00:00 2001 From: lol Date: Tue, 9 Apr 2024 18:05:24 +0200 Subject: [PATCH 23/27] fix qlaunch on firmware 18 (from Suyu 70c52a1914) --- src/core/hle/kernel/k_page_table_base.cpp | 7 +++++++ src/core/hle/kernel/k_page_table_base.h | 4 ++++ src/core/hle/kernel/k_process_page_table.h | 3 +++ src/core/hle/kernel/svc/svc_info.cpp | 7 ++++++- src/core/hle/kernel/svc_types.h | 6 +++++- src/core/hle/service/acc/acc.cpp | 19 +++++++++++++++++-- 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/core/hle/kernel/k_page_table_base.cpp b/src/core/hle/kernel/k_page_table_base.cpp index 19cdf4f3ac..af5be17135 100644 --- a/src/core/hle/kernel/k_page_table_base.cpp +++ b/src/core/hle/kernel/k_page_table_base.cpp @@ -172,6 +172,7 @@ Result KPageTableBase::InitializeForKernel(bool is_64_bit, KVirtualAddress start m_mapped_unsafe_physical_memory = 0; m_mapped_insecure_memory = 0; m_mapped_ipc_server_memory = 0; + m_alias_region_extra_size = 0; m_memory_block_slab_manager = m_kernel.GetSystemSystemResource().GetMemoryBlockSlabManagerPointer(); @@ -269,6 +270,12 @@ Result KPageTableBase::InitializeForProcess(Svc::CreateProcessFlag as_type, bool process_code_end = m_code_region_end; } + m_alias_region_extra_size = 0; + if (as_type == Svc::CreateProcessFlag::EnableReservedRegionExtraSize) { + m_alias_region_extra_size = GetAddressSpaceSize() / 8; + alias_region_size += m_alias_region_extra_size; + } + // Set other basic fields. m_enable_aslr = enable_aslr; m_enable_device_address_space_merge = enable_das_merge; diff --git a/src/core/hle/kernel/k_page_table_base.h b/src/core/hle/kernel/k_page_table_base.h index 748419f862..fd6b7216b8 100644 --- a/src/core/hle/kernel/k_page_table_base.h +++ b/src/core/hle/kernel/k_page_table_base.h @@ -208,6 +208,7 @@ private: size_t m_mapped_unsafe_physical_memory{}; size_t m_mapped_insecure_memory{}; size_t m_mapped_ipc_server_memory{}; + size_t m_alias_region_extra_size{}; mutable KLightLock m_general_lock; mutable KLightLock m_map_physical_memory_lock; KLightLock m_device_map_lock; @@ -682,6 +683,9 @@ public: size_t GetAliasRegionSize() const { return m_alias_region_end - m_alias_region_start; } + size_t GetReservedRegionExtraSize() const { + return m_alias_region_extra_size; + } size_t GetStackRegionSize() const { return m_stack_region_end - m_stack_region_start; } diff --git a/src/core/hle/kernel/k_process_page_table.h b/src/core/hle/kernel/k_process_page_table.h index 346d7ca083..38c5fb8162 100644 --- a/src/core/hle/kernel/k_process_page_table.h +++ b/src/core/hle/kernel/k_process_page_table.h @@ -410,6 +410,9 @@ public: size_t GetAliasRegionSize() const { return m_page_table.GetAliasRegionSize(); } + size_t GetReservedRegionExtraSize() const { + return m_page_table.GetReservedRegionExtraSize(); + } size_t GetStackRegionSize() const { return m_page_table.GetStackRegionSize(); } diff --git a/src/core/hle/kernel/svc/svc_info.cpp b/src/core/hle/kernel/svc/svc_info.cpp index 231e4d0e1b..007bb9f705 100644 --- a/src/core/hle/kernel/svc/svc_info.cpp +++ b/src/core/hle/kernel/svc/svc_info.cpp @@ -37,7 +37,8 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle case InfoType::TotalNonSystemMemorySize: case InfoType::UsedNonSystemMemorySize: case InfoType::IsApplication: - case InfoType::FreeThreadCount: { + case InfoType::FreeThreadCount: + case InfoType::ReservedRegionExtraSize: { R_UNLESS(info_sub_id == 0, ResultInvalidEnumValue); const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); @@ -134,6 +135,10 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle } R_SUCCEED(); + case InfoType::ReservedRegionExtraSize: + *result = process->GetPageTable().GetReservedRegionExtraSize(); + R_SUCCEED(); + default: break; } diff --git a/src/core/hle/kernel/svc_types.h b/src/core/hle/kernel/svc_types.h index ab432ea78b..df92fa0089 100644 --- a/src/core/hle/kernel/svc_types.h +++ b/src/core/hle/kernel/svc_types.h @@ -153,6 +153,7 @@ enum class InfoType : u32 { ThreadTickCount = 25, IsSvcPermitted = 26, IoRegionHint = 27, + ReservedRegionExtraSize = 28, MesosphereMeta = 65000, MesosphereCurrentProcess = 65001, @@ -642,9 +643,12 @@ enum class CreateProcessFlag : u32 { // 11.x+ DisableDeviceAddressSpaceMerge. DisableDeviceAddressSpaceMerge = (1 << 12), + EnableReservedRegionExtraSize = (1 << 13), + // Mask of all flags. All = Is64Bit | AddressSpaceMask | EnableDebug | EnableAslr | IsApplication | - PoolPartitionMask | OptimizeMemoryAllocation | DisableDeviceAddressSpaceMerge, + PoolPartitionMask | OptimizeMemoryAllocation | DisableDeviceAddressSpaceMerge | + EnableReservedRegionExtraSize, }; DECLARE_ENUM_FLAG_OPERATORS(CreateProcessFlag); diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 14ecca9453..4464e4af94 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp @@ -325,7 +325,7 @@ public: {11, &IProfileCommon::LoadImage, "LoadImage"}, {20, &IProfileCommon::GetImageSize, "GetLargeImageSize"}, // 18.0.0+ {21, &IProfileCommon::LoadImage, "LoadLargeImage"}, // 18.0.0+ - {30, nullptr, "GetImageId"} // 18.0.0+ + {30, &IProfileCommon::Unknown, "GetImageId"} // 18.0.0+ }; RegisterHandlers(functions); @@ -496,6 +496,13 @@ protected: rb.Push(ResultSuccess); } + void Unknown(HLERequestContext& ctx) { + LOG_WARNING(Service_ACC, "(STUBBED) called"); + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(0); + } + ProfileManager& profile_manager; Common::UUID user_id{}; ///< The user id this profile refers to. }; @@ -511,7 +518,15 @@ class IProfileEditor final : public IProfileCommon { public: explicit IProfileEditor(Core::System& system_, Common::UUID user_id_, ProfileManager& profile_manager_) - : IProfileCommon{system_, "IProfileEditor", true, user_id_, profile_manager_} {} + : IProfileCommon{system_, "IProfileEditor", true, user_id_, profile_manager_} { + // clang-format off + static const FunctionInfo functions[] = { + {30, &IProfileEditor::Unknown, "Unknown"}, + }; + // clang-format on + + RegisterHandlers(functions); + } }; class ISessionObject final : public ServiceFramework { From fad59842104e99d92c5559c3852ccf0053e8dedf Mon Sep 17 00:00:00 2001 From: spectranator Date: Wed, 8 May 2024 23:35:57 +0200 Subject: [PATCH 24/27] Added FAQ document --- FAQ.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 FAQ.md diff --git a/FAQ.md b/FAQ.md new file mode 100644 index 0000000000..06d5f963a0 --- /dev/null +++ b/FAQ.md @@ -0,0 +1,32 @@ +# FAQ + +**Q:** Will you fix game X?
+**A:** I would love to! Unfortunately my resources are severely limited as I'm a one-man team. I will give it a try, but if you can link me to a commit in any other fork fixing the game I'd be glad to cherry-pick it. + +**Q:** Will you add feature X?
+**A:** Most likely, no. I hesitate from adding complex features that may jeopardize stability and introduce bugs. Such features would only be added behind a settings toggle. + +**Q:** You're only doing this for fame/money/...
+**A:** At the moment I am not considering to take any donations. I won't need them anyways in the foreseeable future. +About the fame thing, I kind of dislike the attention. It distracts me from doing actual work, and it makes me feel pressured. Read this if you'd like to know more: [https://www.reddit.com/r/EmulationOnAndroid/comments/1ckmdh7/comment/l36hru9/?utm\_source=share&utm\_medium=web3x&utm\_name=web3xcss&utm\_term=1&utm\_content=share\_button](https://www.reddit.com/r/EmulationOnAndroid/comments/1ckmdh7/comment/l36hru9/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button) + +**Q:** What happens if Nintendo DMCAs the repo?
+**A:** The main repository is on the Tor network. That means Nintendo can do no harm to it unless they manage to deanonymize me and send me a personal letter. I'm doing my best to avoid that. +Whenever a mirror repository gets taken down, I'll just move on to another git service. Yes, they are finite but I've got enough to hopefully make them give up before I've depleted my list. + +**Q:** But you're just stealing changes from other forks!
+**A:** This is a pretty normal thing to do in the open source world. Yes, a lot of the changes are cherry-picked from other forks. There is no point in duplicating work unnecessarily and keeping good additions out of the project just because they are not mine. Original contributors are always credited as commit author of course. +Note however that all changes listed in the README file are my own work and other forks should feel free to cherry-pick them! + +**Q:** Will there ever be an Android version?
+**A:** Unfortunately I am pretty inexperienced in the Android world. This whole gradle stuff makes no sense to me and I've given up for now. +Let's say, it'd be a nice bonus but it's very low priority. If you'd like to run Yuzu on Android you'd probably be better off with Sudachi. + +**Q:** This fork is going to be abandoned very soon!
+**A:** I have committed myself to at the very least keep it updated enough to compile and run on modern systems for the next decade or so. If you don't see commits for a while it doesn't mean I've abandoned it. +I have ADHD and need to shift my focus between different projects sometimes to stay motivated. Also, personal life is a thing. ~~Who knows maybe I'll be run over by a car tomorrow? Joking, that's not going to happen. Hopefully.~~ + +Enjoy playing your favorite (and legally obtained) Nintendo games on whatever device and emulator you prefer!
+Don't let Nintendo pressure you into using their kind of terrible and overpriced hardware... I'm truly sorry if no emulator can currently play the game you want to play. + +Finally, enjoy life, make the most of it, don't be a ~~couch~~ office chair potato like me. Tip, even if you are, a walk around the green city areas can be incredibly refreshing! From e966068fea67bdf71131c16541041bdb7b525177 Mon Sep 17 00:00:00 2001 From: spectranator Date: Fri, 10 May 2024 03:44:35 +0200 Subject: [PATCH 25/27] Update README: Windows bullds now available in releases section --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 167de64783..14fabbd5c9 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,6 @@ This project incorporates several commits from the [Suyu](https://suyu.dev) and ## Download Precompiled build are available **in the releases section**. -Windows builds have not been released yet but will very soon. ## License From ffc907460f422e4ee69b54767ce35c755cc468b9 Mon Sep 17 00:00:00 2001 From: spectranator Date: Mon, 13 May 2024 23:03:36 +0200 Subject: [PATCH 26/27] Removed web service reminiscents This will be undone (except for the analytics part) once a good reimplementation is available. I will include a configuration value for the server to use. --- .gitmodules | 3 -- CMakeLists.txt | 10 +--- externals/CMakeLists.txt | 10 +--- externals/cpp-jwt | 1 - src/CMakeLists.txt | 4 -- src/core/CMakeLists.txt | 5 -- src/dedicated_room/CMakeLists.txt | 4 -- src/dedicated_room/yuzu_room.cpp | 9 ---- src/network/CMakeLists.txt | 4 -- src/network/announce_multiplayer_session.cpp | 16 ------ src/yuzu/CMakeLists.txt | 4 -- src/yuzu/applets/qt_amiibo_settings.cpp | 52 -------------------- src/yuzu/applets/qt_amiibo_settings.h | 1 - src/yuzu/multiplayer/chat_room.cpp | 35 ------------- src/yuzu/multiplayer/host_room.cpp | 23 --------- src/yuzu/multiplayer/lobby.cpp | 17 ------- 16 files changed, 2 insertions(+), 196 deletions(-) delete mode 160000 externals/cpp-jwt diff --git a/.gitmodules b/.gitmodules index e74fc38919..6576a823be 100644 --- a/.gitmodules +++ b/.gitmodules @@ -31,9 +31,6 @@ [submodule "vcpkg"] path = externals/vcpkg url = https://github.com/microsoft/vcpkg.git -[submodule "cpp-jwt"] - path = externals/cpp-jwt - url = https://github.com/arun11299/cpp-jwt.git [submodule "libadrenotools"] path = externals/libadrenotools url = https://github.com/bylaws/libadrenotools.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 34478ff293..7b23d135a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,6 @@ set(QT6_LOCATION "" CACHE PATH "Additional Location to search for Qt6 libraries option(ENABLE_QT_TRANSLATION "Enable translations for the Qt frontend" OFF) CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_QT "Download bundled Qt binaries" "${MSVC}" "ENABLE_QT" OFF) -option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON) - option(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled FFmpeg" "${WIN32}") option(YUZU_USE_EXTERNAL_VULKAN_HEADERS "Use Vulkan-Headers from externals" ON) @@ -143,9 +141,6 @@ if (YUZU_USE_BUNDLED_VCPKG) if (YUZU_TESTS) list(APPEND VCPKG_MANIFEST_FEATURES "yuzu-tests") endif() - if (ENABLE_WEB_SERVICE) - list(APPEND VCPKG_MANIFEST_FEATURES "web-service") - endif() if (ANDROID) list(APPEND VCPKG_MANIFEST_FEATURES "android") endif() @@ -345,10 +340,7 @@ if (USE_DISCORD_PRESENCE) find_package(DiscordRPC MODULE) endif() -if (ENABLE_WEB_SERVICE) - find_package(cpp-jwt 1.4 CONFIG) - find_package(httplib 0.12 MODULE COMPONENTS OpenSSL) -endif() +find_package(httplib 0.12 MODULE COMPONENTS OpenSSL) if (YUZU_TESTS) find_package(Catch2 3.0.1 REQUIRED) diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 8ed3ff6e99..6b508107ca 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -125,19 +125,11 @@ endif() add_subdirectory(sirit) # httplib -if (ENABLE_WEB_SERVICE AND NOT TARGET httplib::httplib) +if (NOT TARGET httplib::httplib) set(HTTPLIB_REQUIRE_OPENSSL ON) add_subdirectory(cpp-httplib) endif() -# cpp-jwt -if (ENABLE_WEB_SERVICE AND NOT TARGET cpp-jwt::cpp-jwt) - set(CPP_JWT_BUILD_EXAMPLES OFF) - set(CPP_JWT_BUILD_TESTS OFF) - set(CPP_JWT_USE_VENDORED_NLOHMANN_JSON OFF) - add_subdirectory(cpp-jwt) -endif() - # Opus if (NOT TARGET Opus::opus) set(OPUS_BUILD_TESTING OFF) diff --git a/externals/cpp-jwt b/externals/cpp-jwt deleted file mode 160000 index 10ef5735d8..0000000000 --- a/externals/cpp-jwt +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 10ef5735d842b31025f1257ae78899f50a40fb14 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 71f5773c50..fea04aa1d7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -207,10 +207,6 @@ if (ENABLE_QT) add_subdirectory(yuzu) endif() -if (ENABLE_WEB_SERVICE) - add_subdirectory(web_service) -endif() - if (ANDROID) add_subdirectory(android/app/src/main/jni) target_include_directories(yuzu-android PRIVATE android/app/src/main) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d67ca881b9..cf427ed2a0 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1165,11 +1165,6 @@ if (MINGW) target_link_libraries(core PRIVATE ${MSWSOCK_LIBRARY}) endif() -if (ENABLE_WEB_SERVICE) - target_compile_definitions(core PRIVATE -DENABLE_WEB_SERVICE) - target_link_libraries(core PRIVATE web_service) -endif() - if (HAS_NCE) enable_language(C ASM) set(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp") diff --git a/src/dedicated_room/CMakeLists.txt b/src/dedicated_room/CMakeLists.txt index c0dcc0241f..1d26e00bfd 100644 --- a/src/dedicated_room/CMakeLists.txt +++ b/src/dedicated_room/CMakeLists.txt @@ -8,10 +8,6 @@ add_executable(yuzu-room ) target_link_libraries(yuzu-room PRIVATE common network) -if (ENABLE_WEB_SERVICE) - target_compile_definitions(yuzu-room PRIVATE -DENABLE_WEB_SERVICE) - target_link_libraries(yuzu-room PRIVATE web_service) -endif() target_link_libraries(yuzu-room PRIVATE mbedtls mbedcrypto) if (MSVC) diff --git a/src/dedicated_room/yuzu_room.cpp b/src/dedicated_room/yuzu_room.cpp index 93038f161b..ae483830db 100644 --- a/src/dedicated_room/yuzu_room.cpp +++ b/src/dedicated_room/yuzu_room.cpp @@ -33,10 +33,6 @@ #include "network/room.h" #include "network/verify_user.h" -#ifdef ENABLE_WEB_SERVICE -#include "web_service/verify_user_jwt.h" -#endif - #undef _UNICODE #include #ifndef _MSC_VER @@ -351,14 +347,9 @@ int main(int argc, char** argv) { std::unique_ptr verify_backend; if (announce) { -#ifdef ENABLE_WEB_SERVICE - verify_backend = - std::make_unique(Settings::values.web_api_url.GetValue()); -#else LOG_INFO(Network, "yuzu Web Services is not available with this build: validation is disabled."); verify_backend = std::make_unique(); -#endif } else { verify_backend = std::make_unique(); } diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index 8e306219fb..47bafee801 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -20,10 +20,6 @@ add_library(network STATIC create_target_directory_groups(network) target_link_libraries(network PRIVATE common enet::enet Boost::headers) -if (ENABLE_WEB_SERVICE) - target_compile_definitions(network PRIVATE -DENABLE_WEB_SERVICE) - target_link_libraries(network PRIVATE web_service) -endif() if (YUZU_USE_PRECOMPILED_HEADERS) target_precompile_headers(network PRIVATE precompiled_headers.h) diff --git a/src/network/announce_multiplayer_session.cpp b/src/network/announce_multiplayer_session.cpp index 6737ce85ad..98339cc58f 100644 --- a/src/network/announce_multiplayer_session.cpp +++ b/src/network/announce_multiplayer_session.cpp @@ -10,10 +10,6 @@ #include "common/settings.h" #include "network/network.h" -#ifdef ENABLE_WEB_SERVICE -#include "web_service/announce_room_json.h" -#endif - namespace Core { // Time between room is announced to web_service @@ -21,13 +17,7 @@ static constexpr std::chrono::seconds announce_time_interval(15); AnnounceMultiplayerSession::AnnounceMultiplayerSession(Network::RoomNetwork& room_network_) : room_network{room_network_} { -#ifdef ENABLE_WEB_SERVICE - backend = std::make_unique(Settings::values.web_api_url.GetValue(), - Settings::values.yuzu_username.GetValue(), - Settings::values.yuzu_token.GetValue()); -#else backend = std::make_unique(); -#endif } WebService::WebResult AnnounceMultiplayerSession::Register() { @@ -153,12 +143,6 @@ bool AnnounceMultiplayerSession::IsRunning() const { void AnnounceMultiplayerSession::UpdateCredentials() { ASSERT_MSG(!IsRunning(), "Credentials can only be updated when session is not running"); - -#ifdef ENABLE_WEB_SERVICE - backend = std::make_unique(Settings::values.web_api_url.GetValue(), - Settings::values.yuzu_username.GetValue(), - Settings::values.yuzu_token.GetValue()); -#endif } } // namespace Core diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index b67df498f2..acdf710f7d 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -425,10 +425,6 @@ if (USE_DISCORD_PRESENCE) target_compile_definitions(yuzu PRIVATE -DUSE_DISCORD_PRESENCE) endif() -if (ENABLE_WEB_SERVICE) - target_compile_definitions(yuzu PRIVATE -DENABLE_WEB_SERVICE) -endif() - if (YUZU_USE_QT_MULTIMEDIA) target_link_libraries(yuzu PRIVATE Qt${QT_MAJOR_VERSION}::Multimedia) target_compile_definitions(yuzu PRIVATE -DYUZU_USE_QT_MULTIMEDIA) diff --git a/src/yuzu/applets/qt_amiibo_settings.cpp b/src/yuzu/applets/qt_amiibo_settings.cpp index b91796ddef..f5b423fca6 100644 --- a/src/yuzu/applets/qt_amiibo_settings.cpp +++ b/src/yuzu/applets/qt_amiibo_settings.cpp @@ -13,9 +13,6 @@ #include "input_common/drivers/virtual_amiibo.h" #include "input_common/main.h" #include "ui_qt_amiibo_settings.h" -#ifdef ENABLE_WEB_SERVICE -#include "web_service/web_backend.h" -#endif #include "yuzu/applets/qt_amiibo_settings.h" #include "yuzu/main.h" @@ -91,55 +88,6 @@ void QtAmiiboSettingsDialog::LoadAmiiboInfo() { ui->amiiboInfoGroup->setVisible(false); } -void QtAmiiboSettingsDialog::LoadAmiiboApiInfo(std::string_view amiibo_id) { -#ifdef ENABLE_WEB_SERVICE - // TODO: Host this data on our website - WebService::Client client{"https://amiiboapi.com", {}, {}}; - WebService::Client image_client{"https://raw.githubusercontent.com", {}, {}}; - const auto url_path = fmt::format("/api/amiibo/?id={}", amiibo_id); - - const auto amiibo_json = client.GetJson(url_path, true).returned_data; - if (amiibo_json.empty()) { - ui->amiiboImageLabel->setVisible(false); - ui->amiiboInfoGroup->setVisible(false); - return; - } - - std::string amiibo_series{}; - std::string amiibo_name{}; - std::string amiibo_image_url{}; - std::string amiibo_type{}; - - const auto parsed_amiibo_json_json = nlohmann::json::parse(amiibo_json).at("amiibo"); - parsed_amiibo_json_json.at("amiiboSeries").get_to(amiibo_series); - parsed_amiibo_json_json.at("name").get_to(amiibo_name); - parsed_amiibo_json_json.at("image").get_to(amiibo_image_url); - parsed_amiibo_json_json.at("type").get_to(amiibo_type); - - ui->amiiboSeriesValue->setText(QString::fromStdString(amiibo_series)); - ui->amiiboNameValue->setText(QString::fromStdString(amiibo_name)); - ui->amiiboTypeValue->setText(QString::fromStdString(amiibo_type)); - - if (amiibo_image_url.size() < 34) { - ui->amiiboImageLabel->setVisible(false); - } - - const auto image_url_path = amiibo_image_url.substr(34, amiibo_image_url.size() - 34); - const auto image_data = image_client.GetImage(image_url_path, true).returned_data; - - if (image_data.empty()) { - ui->amiiboImageLabel->setVisible(false); - } - - QPixmap pixmap; - pixmap.loadFromData(reinterpret_cast(image_data.data()), - static_cast(image_data.size())); - pixmap = pixmap.scaled(250, 350, Qt::AspectRatioMode::KeepAspectRatio, - Qt::TransformationMode::SmoothTransformation); - ui->amiiboImageLabel->setPixmap(pixmap); -#endif -} - void QtAmiiboSettingsDialog::LoadAmiiboData() { Service::NFP::RegisterInfo register_info{}; Service::NFP::CommonInfo common_info{}; diff --git a/src/yuzu/applets/qt_amiibo_settings.h b/src/yuzu/applets/qt_amiibo_settings.h index 3833cf6f2a..0cdb86ef35 100644 --- a/src/yuzu/applets/qt_amiibo_settings.h +++ b/src/yuzu/applets/qt_amiibo_settings.h @@ -43,7 +43,6 @@ public: private: void LoadInfo(); void LoadAmiiboInfo(); - void LoadAmiiboApiInfo(std::string_view amiibo_id); void LoadAmiiboData(); void LoadAmiiboGameInfo(); void SetGameDataName(u32 application_area_id); diff --git a/src/yuzu/multiplayer/chat_room.cpp b/src/yuzu/multiplayer/chat_room.cpp index 4463616b45..e0b84853cd 100644 --- a/src/yuzu/multiplayer/chat_room.cpp +++ b/src/yuzu/multiplayer/chat_room.cpp @@ -21,9 +21,6 @@ #include "yuzu/game_list_p.h" #include "yuzu/multiplayer/chat_room.h" #include "yuzu/multiplayer/message.h" -#ifdef ENABLE_WEB_SERVICE -#include "web_service/web_backend.h" -#endif class ChatMessage { public: @@ -387,38 +384,6 @@ void ChatRoom::SetPlayerList(const Network::RoomMember::MemberList& member_list) QStandardItem* name_item = new PlayerListItem(member.nickname, member.username, member.avatar_url, member.game_info); -#ifdef ENABLE_WEB_SERVICE - if (!icon_cache.count(member.avatar_url) && !member.avatar_url.empty()) { - // Start a request to get the member's avatar - const QUrl url(QString::fromStdString(member.avatar_url)); - QFuture future = QtConcurrent::run([url] { - WebService::Client client( - QStringLiteral("%1://%2").arg(url.scheme(), url.host()).toStdString(), "", ""); - auto result = client.GetImage(url.path().toStdString(), true); - if (result.returned_data.empty()) { - LOG_ERROR(WebService, "Failed to get avatar"); - } - return result.returned_data; - }); - auto* future_watcher = new QFutureWatcher(this); - connect(future_watcher, &QFutureWatcher::finished, this, - [this, future_watcher, avatar_url = member.avatar_url] { - const std::string result = future_watcher->result(); - if (result.empty()) - return; - QPixmap pixmap; - if (!pixmap.loadFromData(reinterpret_cast(result.data()), - static_cast(result.size()))) - return; - icon_cache[avatar_url] = - pixmap.scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - // Update all the displayed icons with the new icon_cache - UpdateIconDisplay(); - }); - future_watcher->setFuture(future); - } -#endif - player_list->invisibleRootItem()->appendRow(name_item); } UpdateIconDisplay(); diff --git a/src/yuzu/multiplayer/host_room.cpp b/src/yuzu/multiplayer/host_room.cpp index ef364ee43a..6ac4693fc8 100644 --- a/src/yuzu/multiplayer/host_room.cpp +++ b/src/yuzu/multiplayer/host_room.cpp @@ -23,9 +23,6 @@ #include "yuzu/multiplayer/state.h" #include "yuzu/multiplayer/validation.h" #include "yuzu/uisettings.h" -#ifdef ENABLE_WEB_SERVICE -#include "web_service/verify_user_jwt.h" -#endif HostRoomWindow::HostRoomWindow(QWidget* parent, QStandardItemModel* list, std::shared_ptr session, @@ -98,12 +95,7 @@ std::unique_ptr HostRoomWindow::CreateVerifyBacken bool use_validation) const { std::unique_ptr verify_backend; if (use_validation) { -#ifdef ENABLE_WEB_SERVICE - verify_backend = - std::make_unique(Settings::values.web_api_url.GetValue()); -#else verify_backend = std::make_unique(); -#endif } else { verify_backend = std::make_unique(); } @@ -201,21 +193,6 @@ void HostRoomWindow::Host() { } } std::string token; -#ifdef ENABLE_WEB_SERVICE - if (is_public) { - WebService::Client client(Settings::values.web_api_url.GetValue(), - Settings::values.yuzu_username.GetValue(), - Settings::values.yuzu_token.GetValue()); - if (auto room = room_network.GetRoom().lock()) { - token = client.GetExternalJWT(room->GetVerifyUID()).returned_data; - } - if (token.empty()) { - LOG_ERROR(WebService, "Could not get external JWT, verification may fail"); - } else { - LOG_INFO(WebService, "Successfully requested external JWT: size={}", token.size()); - } - } -#endif // TODO: Check what to do with this member->Join(ui->username->text().toStdString(), "127.0.0.1", port, 0, Network::NoPreferredIP, password, token); diff --git a/src/yuzu/multiplayer/lobby.cpp b/src/yuzu/multiplayer/lobby.cpp index 77ac842952..68ea16d0e2 100644 --- a/src/yuzu/multiplayer/lobby.cpp +++ b/src/yuzu/multiplayer/lobby.cpp @@ -20,9 +20,6 @@ #include "yuzu/multiplayer/state.h" #include "yuzu/multiplayer/validation.h" #include "yuzu/uisettings.h" -#ifdef ENABLE_WEB_SERVICE -#include "web_service/web_backend.h" -#endif Lobby::Lobby(QWidget* parent, QStandardItemModel* list, std::shared_ptr session, Core::System& system_) @@ -186,20 +183,6 @@ void Lobby::OnJoinRoom(const QModelIndex& source) { // attempt to connect in a different thread QFuture f = QtConcurrent::run([nickname, ip, port, password, verify_uid, this] { std::string token; -#ifdef ENABLE_WEB_SERVICE - if (!Settings::values.yuzu_username.GetValue().empty() && - !Settings::values.yuzu_token.GetValue().empty()) { - WebService::Client client(Settings::values.web_api_url.GetValue(), - Settings::values.yuzu_username.GetValue(), - Settings::values.yuzu_token.GetValue()); - token = client.GetExternalJWT(verify_uid).returned_data; - if (token.empty()) { - LOG_ERROR(WebService, "Could not get external JWT, verification may fail"); - } else { - LOG_INFO(WebService, "Successfully requested external JWT: size={}", token.size()); - } - } -#endif if (auto room_member = room_network.GetRoomMember().lock()) { room_member->Join(nickname, ip.c_str(), port, 0, Network::NoPreferredIP, password, token); From 2184968eb4685b04fd300fd1f14021f561416303 Mon Sep 17 00:00:00 2001 From: spectranator Date: Mon, 13 May 2024 23:11:32 +0200 Subject: [PATCH 27/27] Applied clang-format --- src/common/settings.h | 3 ++- src/core/core_timing.cpp | 7 ++++--- src/core/hle/service/acc/acc.cpp | 4 ++-- src/network/announce_multiplayer_session.cpp | 1 - src/yuzu/configuration/shared_translation.cpp | 13 +++++++----- src/yuzu/main.cpp | 20 ++++++++++++------- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/common/settings.h b/src/common/settings.h index ffcdb811dd..2ea310e13d 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -210,7 +210,8 @@ struct Values { true, true, &use_speed_limit}; - SwitchableSetting sync_core_speed{linkage, false, "sync_core_speed", Category::Core, Specialization::Default}; + SwitchableSetting sync_core_speed{linkage, false, "sync_core_speed", Category::Core, + Specialization::Default}; // Cpu SwitchableSetting cpu_backend{linkage, diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 0576882691..cb31a3b450 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -14,8 +14,8 @@ #include "common/x64/cpu_wait.h" #endif -#include "common/settings.h" #include "common/microprofile.h" +#include "common/settings.h" #include "core/core_timing.h" #include "core/hardware_properties.h" @@ -194,8 +194,9 @@ u64 CoreTiming::GetClockTicks() const { if (Settings::values.sync_core_speed.GetValue()) { const double ticks = static_cast(fres); - const double speed_limit = static_cast(Settings::values.speed_limit.GetValue())*0.01; - return static_cast(ticks/speed_limit); + const double speed_limit = + static_cast(Settings::values.speed_limit.GetValue()) * 0.01; + return static_cast(ticks / speed_limit); } else { return fres; } diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 4464e4af94..671b33b4b9 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp @@ -324,8 +324,8 @@ public: {10, &IProfileCommon::GetImageSize, "GetImageSize"}, {11, &IProfileCommon::LoadImage, "LoadImage"}, {20, &IProfileCommon::GetImageSize, "GetLargeImageSize"}, // 18.0.0+ - {21, &IProfileCommon::LoadImage, "LoadLargeImage"}, // 18.0.0+ - {30, &IProfileCommon::Unknown, "GetImageId"} // 18.0.0+ + {21, &IProfileCommon::LoadImage, "LoadLargeImage"}, // 18.0.0+ + {30, &IProfileCommon::Unknown, "GetImageId"} // 18.0.0+ }; RegisterHandlers(functions); diff --git a/src/network/announce_multiplayer_session.cpp b/src/network/announce_multiplayer_session.cpp index 98339cc58f..c61141efdc 100644 --- a/src/network/announce_multiplayer_session.cpp +++ b/src/network/announce_multiplayer_session.cpp @@ -7,7 +7,6 @@ #include "announce_multiplayer_session.h" #include "common/announce_multiplayer_room.h" #include "common/assert.h" -#include "common/settings.h" #include "network/network.h" namespace Core { diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index 6b5d990f02..56ee9f0002 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -71,11 +71,14 @@ std::unique_ptr InitializeTranslations(QWidget* parent) { "faster or not.\n200% for a 30 FPS game is 60 FPS, and for a " "60 FPS game it will be 120 FPS.\nDisabling it means unlocking the framerate to the " "maximum your PC can reach.")); - INSERT(Settings, sync_core_speed, tr("Synchronize core speed"), - tr("Synchronizes CPU core speed to game's maximum rendering speed, which can be useful to " - "increase FPS without increasing the actual speed of the game (animations, physics, etc.)\n" - "It's up to each game if it plays well with this or not. Most games (specially original ones) " - "simply ignore this.\nThis can help play the game stutter-free at a lower framerate.")); + INSERT( + Settings, sync_core_speed, tr("Synchronize core speed"), + tr("Synchronizes CPU core speed to game's maximum rendering speed, which can be useful to " + "increase FPS without increasing the actual speed of the game (animations, physics, " + "etc.)\n" + "It's up to each game if it plays well with this or not. Most games (specially original " + "ones) " + "simply ignore this.\nThis can help play the game stutter-free at a lower framerate.")); // Cpu INSERT(Settings, cpu_accuracy, tr("Accuracy:"), diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 6c58c5558e..a08172416e 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -21,8 +21,8 @@ #include "common/linux/gamemode.h" #endif -#include #include +#include // VFS includes must be before glad as they will conflict with Windows file api, which uses defines. #include "applets/qt_amiibo_settings.h" @@ -3523,12 +3523,18 @@ void GMainWindow::OnOpenMirrorRepo() { httplib::Client cli("https://codeberg.org"); auto res = cli.Get("/litucks/tz-mu/raw/branch/main/mu.txt"); if (!res) { - QMessageBox::warning(this, tr("Error locating mirror"), tr("There has been an error finding the current mirror repository.
" - "Your version may be too old or your network connectivity may be" - "limited.
" - "Please either try again later, through a VPN or access the main
" - "repository via the Tor Browser:
" - "http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu")); + QMessageBox::warning( + this, tr("Error locating mirror"), + tr("There has been an error finding the current mirror repository.
" + "Your version may be too old or your network connectivity may be" + "limited.
" + "Please either try again later, through a VPN or access the main
" + "repository via the Tor Browser:
" + "http://" + "y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu")); } OpenURL(QUrl(QString::fromStdString(res->body)));