From 584b7d2b1523e72fe016d484d385d545f6ed418e Mon Sep 17 00:00:00 2001 From: GPUCode Date: Fri, 23 Feb 2024 23:32:32 +0200 Subject: [PATCH] chore: Make shadps4 REUSE compliant --- .ci/clang-format.sh | 3 + .clang-format | 7 - .github/broken_workflows/linux.yml | 11 +- .github/workflows/ci.yml | 18 + .github/workflows/format.yml | 3 + .github/workflows/windows.yml | 10 +- .gitignore | 3 + .gitmodules | 3 + .reuse/dep5 | 10 + CMakeLists.txt | 3 + LICENSES/GPL-2.0-or-later.txt | 117 +++ LICENSES/MIT.txt | 9 + README.md | 5 + documents/building-windows.md | 5 + documents/linux_building.md | 4 + scripts/ps4_names2stubs.py | 3 + src/.clang-format | 3 + src/Emulator/Host/controller.cpp | 11 +- src/Emulator/Host/controller.h | 6 +- src/GUI/ElfViewer.cpp | 3 + src/GUI/ElfViewer.h | 3 + src/Util/config.cpp | 4 +- src/Util/config.h | 4 + src/common/debug.h | 3 + src/common/disassembler.cpp | 3 + src/common/disassembler.h | 3 + src/common/discord.cpp | 14 +- src/common/discord.h | 10 +- src/common/fs_file.cpp | 5 +- src/common/fs_file.h | 5 +- src/common/io_file.cpp | 7 +- src/common/io_file.h | 5 +- src/common/log.cpp | 3 + src/common/log.h | 3 + src/common/singleton.h | 3 + src/common/string_util.cpp | 4 + src/common/string_util.h | 4 + src/common/types.h | 5 +- src/common/version.h | 3 + src/core/PS4/GPU/gpu_memory.cpp | 10 +- src/core/PS4/GPU/gpu_memory.h | 9 +- src/core/PS4/GPU/tile_manager.cpp | 13 +- src/core/PS4/GPU/tile_manager.h | 6 +- src/core/PS4/GPU/video_out_buffer.cpp | 13 +- src/core/PS4/GPU/video_out_buffer.h | 6 +- .../HLE/Graphics/Objects/video_out_ctx.cpp | 3 + .../PS4/HLE/Graphics/Objects/video_out_ctx.h | 9 +- src/core/PS4/HLE/Graphics/graphics_ctx.h | 3 + src/core/PS4/HLE/Graphics/graphics_render.cpp | 5 +- src/core/PS4/HLE/Graphics/graphics_render.h | 5 +- src/core/PS4/HLE/Graphics/video_out.cpp | 5 +- src/core/PS4/HLE/Graphics/video_out.h | 7 +- src/core/aerolib/aerolib.cpp | 3 + src/core/aerolib/aerolib.h | 3 + src/core/aerolib/aerolib.inl | 3 + src/core/aerolib/stubs.cpp | 3 + src/core/aerolib/stubs.h | 3 + src/core/file_sys/fs.cpp | 6 +- src/core/file_sys/fs.h | 6 +- src/core/hle/error_codes.h | 3 + src/core/hle/kernel/Objects/event_queue.cpp | 3 + src/core/hle/kernel/Objects/event_queue.h | 3 + .../hle/kernel/Objects/physical_memory.cpp | 3 + src/core/hle/kernel/Objects/physical_memory.h | 4 +- src/core/hle/kernel/cpu_management.cpp | 3 + src/core/hle/kernel/cpu_management.h | 3 + src/core/hle/kernel/event_queues.cpp | 3 + src/core/hle/kernel/event_queues.h | 3 + src/core/hle/kernel/memory_management.cpp | 7 +- src/core/hle/kernel/memory_management.h | 3 + src/core/hle/libraries/libc/libc.cpp | 3 + src/core/hle/libraries/libc/libc.h | 3 + src/core/hle/libraries/libc/libc_cxa.cpp | 14 +- src/core/hle/libraries/libc/libc_cxa.h | 3 + src/core/hle/libraries/libc/libc_math.cpp | 3 + src/core/hle/libraries/libc/libc_math.h | 3 + src/core/hle/libraries/libc/libc_stdio.cpp | 3 + src/core/hle/libraries/libc/libc_stdio.h | 3 + src/core/hle/libraries/libc/libc_stdlib.cpp | 3 + src/core/hle/libraries/libc/libc_stdlib.h | 3 + src/core/hle/libraries/libc/libc_string.cpp | 3 + src/core/hle/libraries/libc/libc_string.h | 3 + src/core/hle/libraries/libc/printf.h | 5 +- src/core/hle/libraries/libc/va_ctx.h | 7 +- .../hle/libraries/libkernel/file_system.cpp | 9 +- .../hle/libraries/libkernel/file_system.h | 3 + .../hle/libraries/libkernel/libkernel.cpp | 6 +- src/core/hle/libraries/libkernel/libkernel.h | 4 +- .../libraries/libkernel/thread_management.cpp | 7 +- .../libraries/libkernel/thread_management.h | 20 +- .../libraries/libkernel/time_management.cpp | 3 + .../hle/libraries/libkernel/time_management.h | 3 + src/core/hle/libraries/libpad/pad.cpp | 3 + src/core/hle/libraries/libpad/pad.h | 29 +- src/core/hle/libraries/libs.cpp | 3 + src/core/hle/libraries/libs.h | 3 + .../libscegnmdriver/libscegnmdriver.cpp | 3 + .../libscegnmdriver/libscegnmdriver.h | 3 + .../libsystemservice/system_service.cpp | 4 +- .../libsystemservice/system_service.h | 5 +- .../libuserservice/libuserservice.cpp | 3 + .../libraries/libuserservice/libuserservice.h | 3 + .../libraries/libuserservice/usr_mng_codes.h | 13 +- src/core/linker.cpp | 14 +- src/core/linker.h | 11 +- src/core/loader/elf.cpp | 3 + src/core/loader/elf.h | 107 +- src/core/loader/symbols_resolver.cpp | 3 + src/core/loader/symbols_resolver.h | 7 +- src/core/virtual_memory.cpp | 3 + src/core/virtual_memory.h | 6 +- src/emulator.cpp | 3 + src/emulator.h | 3 + src/main.cpp | 3 + src/video_core/gpu_memory.cpp | 201 ---- src/video_core/gpu_memory.h | 90 -- src/video_core/tile_manager.cpp | 155 --- src/video_core/tile_manager.h | 9 - src/vulkan_util.cpp | 3 + src/vulkan_util.h | 10 +- third-party/CMakeLists.txt | 3 + third-party/result/LICENSE | 201 ---- third-party/result/README.md | 132 --- third-party/result/include/result.hpp | 910 ------------------ 124 files changed, 659 insertions(+), 1891 deletions(-) delete mode 100644 .clang-format create mode 100644 .github/workflows/ci.yml create mode 100644 .reuse/dep5 create mode 100644 LICENSES/GPL-2.0-or-later.txt create mode 100644 LICENSES/MIT.txt delete mode 100644 src/video_core/gpu_memory.cpp delete mode 100644 src/video_core/gpu_memory.h delete mode 100644 src/video_core/tile_manager.cpp delete mode 100644 src/video_core/tile_manager.h delete mode 100644 third-party/result/LICENSE delete mode 100644 third-party/result/README.md delete mode 100644 third-party/result/include/result.hpp diff --git a/.ci/clang-format.sh b/.ci/clang-format.sh index 8aa078f0..a357de5a 100755 --- a/.ci/clang-format.sh +++ b/.ci/clang-format.sh @@ -1,5 +1,8 @@ #!/bin/bash -ex +# SPDX-FileCopyrightText: 2023 Citra Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + if grep -nrI '\s$' src *.yml *.txt *.md Doxyfile .gitignore .gitmodules .ci* dist/*.desktop \ dist/*.svg dist/*.xml; then echo Trailing whitespace found, aborting diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 9f2c6426..00000000 --- a/.clang-format +++ /dev/null @@ -1,7 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 4 -ColumnLimit: 150 -AccessModifierOffset: -2 -TabWidth: 4 -AllowShortEnumsOnASingleLine: true -AllowShortCaseLabelsOnASingleLine: true diff --git a/.github/broken_workflows/linux.yml b/.github/broken_workflows/linux.yml index 258c5740..e6b79dcf 100644 --- a/.github/broken_workflows/linux.yml +++ b/.github/broken_workflows/linux.yml @@ -1,7 +1,5 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. +# SPDX-FileCopyrightText: 2024 shadPS4 Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later name: Linux @@ -21,25 +19,20 @@ permissions: jobs: build: runs-on: ubuntu-latest - steps: - name: Install dev packages run: | sudo apt install libxext-dev doxygen libgl-dev - - uses: actions/checkout@v3 with: submodules: recursive - - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - name: Build # Build your program with the given configuration run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel `nproc` - - name: Upload a Build Artifact uses: actions/upload-artifact@v3.1.2 with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..645a2ea9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ + +# SPDX-FileCopyrightText: 2021 yuzu Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + +name: Reuse + +on: + push: + branches: [ main ] + tags: [ "*" ] + pull_request: + branches: [ main ] +jobs: + reuse: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: fsfe/reuse-action@v1 \ No newline at end of file diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index a823da8b..4664b81a 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2024 shadPS4 Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + name: Clang Format on: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 821f3b02..48e2d246 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,7 +1,5 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. +# SPDX-FileCopyrightText: 2024 shadPS4 Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later name: Windows @@ -21,21 +19,17 @@ permissions: jobs: build: runs-on: windows-latest - steps: - uses: actions/checkout@v3 with: submodules: recursive - - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -T ClangCL - - name: Build # Build your program with the given configuration run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - - name: Upload a Build Artifact uses: actions/upload-artifact@v3.1.2 with: diff --git a/.gitignore b/.gitignore index 80a62d22..fcf7634f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2024 shadPS4 Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## diff --git a/.gitmodules b/.gitmodules index 8a240d58..b79e3cd0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2024 shadPS4 Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + [submodule "third-party/imgui"] path = third-party/imgui url = https://github.com/ocornut/imgui diff --git a/.reuse/dep5 b/.reuse/dep5 new file mode 100644 index 00000000..11f4aae4 --- /dev/null +++ b/.reuse/dep5 @@ -0,0 +1,10 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Comment: It is best to use this file to record copyright information about + generated, binary and third party files + +Files: CMakeSettings.json + scripts/ps4_names.txt + documents/changelog.txt + documents/readme.txt +Copyright: shadPS4 Emulator Project +License: GPL-2.0-or-later \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c440341c..b50d8b3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + cmake_minimum_required(VERSION 3.16.3) set(CMAKE_CXX_STANDARD 20) diff --git a/LICENSES/GPL-2.0-or-later.txt b/LICENSES/GPL-2.0-or-later.txt new file mode 100644 index 00000000..17cb2864 --- /dev/null +++ b/LICENSES/GPL-2.0-or-later.txt @@ -0,0 +1,117 @@ +GNU GENERAL PUBLIC LICENSE +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +Preamble + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. + + c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + + one line to give the program's name and an idea of what it does. Copyright (C) yyyy name of author + + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. + +signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 00000000..2071b23b --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +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. diff --git a/README.md b/README.md index 11729ba6..3e173688 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ + + # shadPS4 An early PS4 emulator for Windows and Linux written in C++ diff --git a/documents/building-windows.md b/documents/building-windows.md index 0a5e8e86..a95c7599 100644 --- a/documents/building-windows.md +++ b/documents/building-windows.md @@ -1,3 +1,8 @@ + + # How to build shadps4 in windows ## Download VStudio Community 2022 17.7.4 diff --git a/documents/linux_building.md b/documents/linux_building.md index f73a7844..5ed82b7d 100644 --- a/documents/linux_building.md +++ b/documents/linux_building.md @@ -1,3 +1,7 @@ + ## Linux diff --git a/scripts/ps4_names2stubs.py b/scripts/ps4_names2stubs.py index bd3e8a4b..e9dd2fca 100644 --- a/scripts/ps4_names2stubs.py +++ b/scripts/ps4_names2stubs.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + # Helper script that generates stub implementation of all known nids + lookup tables # for shadps4 diff --git a/src/.clang-format b/src/.clang-format index b7d6b4ab..d69044b0 100644 --- a/src/.clang-format +++ b/src/.clang-format @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2016 Emmanuel Gil Peyrot +# SPDX-License-Identifier: GPL-2.0-or-later + --- Language: Cpp # BasedOnStyle: LLVM diff --git a/src/Emulator/Host/controller.cpp b/src/Emulator/Host/controller.cpp index b2bf4541..fddac073 100644 --- a/src/Emulator/Host/controller.cpp +++ b/src/Emulator/Host/controller.cpp @@ -1,11 +1,16 @@ -#include -#include "controller.h" +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "Emulator/Host/controller.h" +#include "core/hle/libraries/libkernel/time_management.h" namespace Emulator::Host::Controller { + GameController::GameController() { m_states_num = 0; m_last_state = State(); } + void GameController::readState(State* state, bool* isConnected, int* connectedCount) { std::scoped_lock lock{m_mutex}; @@ -51,4 +56,4 @@ void GameController::checKButton(int id, u32 button, bool isPressed) { addState(state); } -} // namespace Emulator::Host::Controller \ No newline at end of file +} // namespace Emulator::Host::Controller diff --git a/src/Emulator/Host/controller.h b/src/Emulator/Host/controller.h index 22061a06..de8490d1 100644 --- a/src/Emulator/Host/controller.h +++ b/src/Emulator/Host/controller.h @@ -1,4 +1,8 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once + #include #include "common/types.h" @@ -30,4 +34,4 @@ private: State m_states[MAX_STATES]; }; -} // namespace Emulator::Host::Controller \ No newline at end of file +} // namespace Emulator::Host::Controller diff --git a/src/GUI/ElfViewer.cpp b/src/GUI/ElfViewer.cpp index 7ac8ce52..344e417f 100644 --- a/src/GUI/ElfViewer.cpp +++ b/src/GUI/ElfViewer.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "GUI/ElfViewer.h" #include "core/loader/elf.h" #include "imgui.h" diff --git a/src/GUI/ElfViewer.h b/src/GUI/ElfViewer.h index dcdf1cb3..6e7aa6dd 100644 --- a/src/GUI/ElfViewer.h +++ b/src/GUI/ElfViewer.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once namespace Core::Loader { diff --git a/src/Util/config.cpp b/src/Util/config.cpp index 24631a0e..5c0d2803 100644 --- a/src/Util/config.cpp +++ b/src/Util/config.cpp @@ -1,9 +1,11 @@ -#include "config.h" +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include #include #include #include +#include "config.h" namespace Config { diff --git a/src/Util/config.h b/src/Util/config.h index 5b5c3a78..9cd2e0c0 100644 --- a/src/Util/config.h +++ b/src/Util/config.h @@ -1,4 +1,8 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once + #include #include "common/types.h" diff --git a/src/common/debug.h b/src/common/debug.h index dedd19d9..e1c898a3 100644 --- a/src/common/debug.h +++ b/src/common/debug.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #ifdef _MSC_VER diff --git a/src/common/disassembler.cpp b/src/common/disassembler.cpp index 37d58103..2d1264a4 100644 --- a/src/common/disassembler.cpp +++ b/src/common/disassembler.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include "common/disassembler.h" diff --git a/src/common/disassembler.h b/src/common/disassembler.h index 6f7bbd4a..b81f9e31 100644 --- a/src/common/disassembler.h +++ b/src/common/disassembler.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include diff --git a/src/common/discord.cpp b/src/common/discord.cpp index 95ae0f3e..cce799a3 100644 --- a/src/common/discord.cpp +++ b/src/common/discord.cpp @@ -1,9 +1,13 @@ -#include "discord.h" +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include #include +#include "common/discord.h" -void Discord::RPC::init() { +namespace Discord { + +void RPC::init() { DiscordEventHandlers handlers{}; Discord_Initialize("1139939140494971051", &handlers, 1, nullptr); @@ -11,7 +15,7 @@ void Discord::RPC::init() { enabled = true; } -void Discord::RPC::update(Discord::RPCStatus status, const std::string& game) { +void RPC::update(Discord::RPCStatus status, const std::string& game) { DiscordRichPresence rpc{}; if (status == Discord::RPCStatus::Playing) { @@ -28,10 +32,12 @@ void Discord::RPC::update(Discord::RPCStatus status, const std::string& game) { Discord_UpdatePresence(&rpc); } -void Discord::RPC::stop() { +void RPC::stop() { if (enabled) { enabled = false; Discord_ClearPresence(); Discord_Shutdown(); } } + +} // namespace Discord diff --git a/src/common/discord.h b/src/common/discord.h index 14a6b17c..54aa6c17 100644 --- a/src/common/discord.h +++ b/src/common/discord.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include @@ -5,7 +8,11 @@ #include namespace Discord { -enum class RPCStatus { Idling, Playing }; + +enum class RPCStatus { + Idling, + Playing, +}; class RPC { std::uint64_t startTimestamp; @@ -16,4 +23,5 @@ public: void update(RPCStatus status, const std::string& title); void stop(); }; + } // namespace Discord diff --git a/src/common/fs_file.cpp b/src/common/fs_file.cpp index 97bb456a..3875b9ac 100644 --- a/src/common/fs_file.cpp +++ b/src/common/fs_file.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "common/fs_file.h" namespace Common::FS { @@ -32,7 +35,7 @@ bool File::close() { return true; } -bool File::write(std::span data) { +bool File::write(std::span data) { return isOpen() && std::fwrite(data.data(), 1, data.size(), m_file) == data.size(); } diff --git a/src/common/fs_file.h b/src/common/fs_file.h index 969379cd..d6a63db9 100644 --- a/src/common/fs_file.h +++ b/src/common/fs_file.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include @@ -27,7 +30,7 @@ public: bool open(const std::string& path, OpenMode mode = OpenMode::Read); bool close(); bool read(void* data, u64 size) const; - bool write(std::span data); + bool write(std::span data); bool seek(s64 offset, SeekMode mode); u64 getFileSize(); u64 tell() const; diff --git a/src/common/io_file.cpp b/src/common/io_file.cpp index 0f342fe7..3df32178 100644 --- a/src/common/io_file.cpp +++ b/src/common/io_file.cpp @@ -1,4 +1,7 @@ -#include "io_file.h" +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "common/io_file.h" // #include "helpers.hpp" @@ -135,4 +138,4 @@ bool IOFile::setSize(std::uint64_t size) { #endif fflush(handle); return success; -} \ No newline at end of file +} diff --git a/src/common/io_file.h b/src/common/io_file.h index e057d874..04e75600 100644 --- a/src/common/io_file.h +++ b/src/common/io_file.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include #include @@ -39,4 +42,4 @@ public: // Sets the size of the file to "size" and returns whether it succeeded or not bool setSize(std::uint64_t size); -}; \ No newline at end of file +}; diff --git a/src/common/log.cpp b/src/common/log.cpp index 130dcc9a..3ad797ba 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include #include diff --git a/src/common/log.h b/src/common/log.h index a9b4aa2e..089cdcbd 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE diff --git a/src/common/singleton.h b/src/common/singleton.h index c1099547..0838980b 100644 --- a/src/common/singleton.h +++ b/src/common/singleton.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index fc7e4bdf..a3973ef6 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project +// SPDX-FileCopyrightText: 2014 Citra Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include #include diff --git a/src/common/string_util.h b/src/common/string_util.h index 6d7b4208..923579c9 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project +// SPDX-FileCopyrightText: 2014 Citra Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include diff --git a/src/common/types.h b/src/common/types.h index a15febf3..f3c0862c 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include @@ -8,7 +11,7 @@ using s16 = std::int16_t; using s32 = std::int32_t; using s64 = std::int64_t; -using u08 = std::uint8_t; +using u8 = std::uint8_t; using u16 = std::uint16_t; using u32 = std::uint32_t; using u64 = std::uint64_t; diff --git a/src/common/version.h b/src/common/version.h index e9135885..8f1eed79 100644 --- a/src/common/version.h +++ b/src/common/version.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include diff --git a/src/core/PS4/GPU/gpu_memory.cpp b/src/core/PS4/GPU/gpu_memory.cpp index 4dc09d8d..21b9ea79 100644 --- a/src/core/PS4/GPU/gpu_memory.cpp +++ b/src/core/PS4/GPU/gpu_memory.cpp @@ -1,8 +1,10 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include -#include "gpu_memory.h" - #include "common/singleton.h" +#include "core/PS4/GPU/gpu_memory.h" void* GPU::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo /*CommandBuffer?*/, u64 virtual_addr, u64 size, @@ -24,7 +26,7 @@ void GPU::memorySetAllocArea(u64 virtual_addr, u64 size) { gpumemory->m_heaps.push_back(h); } -u64 GPU::calculate_hash(const u08* buf, u64 size) { +u64 GPU::calculate_hash(const u8* buf, u64 size) { return (size > 0 && buf != nullptr ? XXH3_64bits(buf, size) : 0); } @@ -108,7 +110,7 @@ void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::Graphi for (int h = 0; h < virtual_addr_num; h++) { if (info.check_hash) { objInfo.hash[h] = - GPU::calculate_hash(reinterpret_cast(virtual_addr[h]), size[h]); + GPU::calculate_hash(reinterpret_cast(virtual_addr[h]), size[h]); } else { objInfo.hash[h] = 0; } diff --git a/src/core/PS4/GPU/gpu_memory.h b/src/core/PS4/GPU/gpu_memory.h index 3de4db83..9897ae96 100644 --- a/src/core/PS4/GPU/gpu_memory.h +++ b/src/core/PS4/GPU/gpu_memory.h @@ -1,9 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include #include -#include #include "common/types.h" +#include "core/PS4/HLE/Graphics/graphics_ctx.h" namespace GPU { @@ -84,8 +87,8 @@ void memorySetAllocArea(u64 virtual_addr, u64 size); void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, /*CommandBuffer* buffer*/ void* todo, u64 virtual_addr, u64 size, const GPUObject& info); -u64 calculate_hash(const u08* buf, u64 size); +u64 calculate_hash(const u8* buf, u64 size); bool vulkanAllocateMemory(HLE::Libs::Graphics::GraphicCtx* ctx, HLE::Libs::Graphics::VulkanMemory* mem); void flushGarlic(HLE::Libs::Graphics::GraphicCtx* ctx); -} // namespace GPU \ No newline at end of file +} // namespace GPU diff --git a/src/core/PS4/GPU/tile_manager.cpp b/src/core/PS4/GPU/tile_manager.cpp index 9d74b3a6..4d8c2cfc 100644 --- a/src/core/PS4/GPU/tile_manager.cpp +++ b/src/core/PS4/GPU/tile_manager.cpp @@ -1,6 +1,9 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include "common/singleton.h" -#include "tile_manager.h" +#include "core/PS4/GPU/tile_manager.h" namespace GPU { @@ -160,15 +163,15 @@ void convertTileToLinear(void* dst, const void* src, u32 width, u32 height, bool for (; x + 1 < width; x += 2) { auto tiled_offset = t.getTiledOffs(x, y, is_neo); - *reinterpret_cast(static_cast(dst) + linear_offset) = - *reinterpret_cast(static_cast(src) + tiled_offset); + *reinterpret_cast(static_cast(dst) + linear_offset) = + *reinterpret_cast(static_cast(src) + tiled_offset); linear_offset += 8; } if (x < width) { auto tiled_offset = t.getTiledOffs(x, y, is_neo); - *reinterpret_cast(static_cast(dst) + linear_offset) = - *reinterpret_cast(static_cast(src) + tiled_offset); + *reinterpret_cast(static_cast(dst) + linear_offset) = + *reinterpret_cast(static_cast(src) + tiled_offset); } } } diff --git a/src/core/PS4/GPU/tile_manager.h b/src/core/PS4/GPU/tile_manager.h index 7dba4b3f..2e848232 100644 --- a/src/core/PS4/GPU/tile_manager.h +++ b/src/core/PS4/GPU/tile_manager.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" @@ -5,4 +8,5 @@ namespace GPU { void convertTileToLinear(void* dst, const void* src, u32 width, u32 height, bool neo); -} \ No newline at end of file + +} // namespace GPU diff --git a/src/core/PS4/GPU/video_out_buffer.cpp b/src/core/PS4/GPU/video_out_buffer.cpp index 5300f66e..b0a5493f 100644 --- a/src/core/PS4/GPU/video_out_buffer.cpp +++ b/src/core/PS4/GPU/video_out_buffer.cpp @@ -1,10 +1,11 @@ -#include "video_out_buffer.h" +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later -#include "common/log.h" - -#include #include "common/debug.h" -#include "tile_manager.h" +#include "common/log.h" +#include "core/PS4/GPU/tile_manager.h" +#include "core/PS4/GPU/video_out_buffer.h" +#include "vulkan_util.h" constexpr bool log_file_videoOutBuffer = true; // disable it to disable logging @@ -22,7 +23,7 @@ static void update_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params, vk_obj->layout = VK_IMAGE_LAYOUT_UNDEFINED; if (tiled) { - std::vector tempbuff(*size); + std::vector tempbuff(*size); GPU::convertTileToLinear(tempbuff.data(), reinterpret_cast(*virtual_addr), width, height, neo); Graphics::Vulkan::vulkanFillImage( diff --git a/src/core/PS4/GPU/video_out_buffer.h b/src/core/PS4/GPU/video_out_buffer.h index cc59a948..6b0e3225 100644 --- a/src/core/PS4/GPU/video_out_buffer.h +++ b/src/core/PS4/GPU/video_out_buffer.h @@ -1,8 +1,10 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" - -#include "gpu_memory.h" +#include "core/PS4/GPU/gpu_memory.h" namespace GPU { diff --git a/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp b/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp index 714a6b9a..f150df40 100644 --- a/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp +++ b/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "common/debug.h" #include "core/PS4/HLE/Graphics/Objects/video_out_ctx.h" #include "core/hle/libraries/libkernel/time_management.h" diff --git a/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h b/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h index baaa15c3..83e30ec3 100644 --- a/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h +++ b/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h @@ -1,10 +1,13 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include #include -#include -#include -#include +#include "core/PS4/HLE/Graphics/graphics_ctx.h" +#include "core/PS4/HLE/Graphics/video_out.h" +#include "emulator.h" using namespace HLE::Libs::Graphics::VideoOut; diff --git a/src/core/PS4/HLE/Graphics/graphics_ctx.h b/src/core/PS4/HLE/Graphics/graphics_ctx.h index bc2c37c8..52821065 100644 --- a/src/core/PS4/HLE/Graphics/graphics_ctx.h +++ b/src/core/PS4/HLE/Graphics/graphics_ctx.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include diff --git a/src/core/PS4/HLE/Graphics/graphics_render.cpp b/src/core/PS4/HLE/Graphics/graphics_render.cpp index 605295c5..d3d19333 100644 --- a/src/core/PS4/HLE/Graphics/graphics_render.cpp +++ b/src/core/PS4/HLE/Graphics/graphics_render.cpp @@ -1,7 +1,10 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include "common/singleton.h" +#include "core/PS4/HLE/Graphics/graphics_render.h" #include "emulator.h" -#include "graphics_render.h" static thread_local GPU::CommandPool g_command_pool; diff --git a/src/core/PS4/HLE/Graphics/graphics_render.h b/src/core/PS4/HLE/Graphics/graphics_render.h index 5daa27de..15c375f5 100644 --- a/src/core/PS4/HLE/Graphics/graphics_render.h +++ b/src/core/PS4/HLE/Graphics/graphics_render.h @@ -1,7 +1,10 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include -#include "graphics_ctx.h" +#include "core/PS4/HLE/Graphics/graphics_ctx.h" namespace GPU { diff --git a/src/core/PS4/HLE/Graphics/video_out.cpp b/src/core/PS4/HLE/Graphics/video_out.cpp index e083a38f..05a18db3 100644 --- a/src/core/PS4/HLE/Graphics/video_out.cpp +++ b/src/core/PS4/HLE/Graphics/video_out.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include #include @@ -8,6 +11,7 @@ #include "common/singleton.h" #include "core/PS4/GPU/gpu_memory.h" #include "core/PS4/GPU/video_out_buffer.h" +#include "core/PS4/HLE/Graphics/graphics_render.h" #include "core/PS4/HLE/Graphics/video_out.h" #include "core/hle/error_codes.h" #include "core/hle/libraries/libs.h" @@ -15,7 +19,6 @@ #include "core/hle/libraries/libuserservice/usr_mng_codes.h" #include "core/loader/symbols_resolver.h" #include "emulator.h" -#include "graphics_render.h" namespace HLE::Libs::Graphics::VideoOut { diff --git a/src/core/PS4/HLE/Graphics/video_out.h b/src/core/PS4/HLE/Graphics/video_out.h index b4d382a2..3a0e41ac 100644 --- a/src/core/PS4/HLE/Graphics/video_out.h +++ b/src/core/PS4/HLE/Graphics/video_out.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include @@ -92,8 +95,8 @@ struct SceVideoOutVblankStatus { u64 processTime = 0; u64 tsc = 0; u64 reserved[1] = {0}; - u08 flags = 0; - u08 pad1[7] = {}; + u8 flags = 0; + u8 pad1[7] = {}; }; struct VideoOutBufferSetInternal { diff --git a/src/core/aerolib/aerolib.cpp b/src/core/aerolib/aerolib.cpp index c7cb3a2f..b9e01431 100644 --- a/src/core/aerolib/aerolib.cpp +++ b/src/core/aerolib/aerolib.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include "common/types.h" #include "core/aerolib/aerolib.h" diff --git a/src/core/aerolib/aerolib.h b/src/core/aerolib/aerolib.h index a07eb4cb..c3dcf648 100644 --- a/src/core/aerolib/aerolib.h +++ b/src/core/aerolib/aerolib.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include diff --git a/src/core/aerolib/aerolib.inl b/src/core/aerolib/aerolib.inl index c822642c..cd7a6b01 100644 --- a/src/core/aerolib/aerolib.inl +++ b/src/core/aerolib/aerolib.inl @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + // generated using ps4_names2stubs.py STUB("++DO8Y1JaYU", sceAvSettingDebugSetProcessAttribute) diff --git a/src/core/aerolib/stubs.cpp b/src/core/aerolib/stubs.cpp index 73d8ab6a..34db7a94 100644 --- a/src/core/aerolib/stubs.cpp +++ b/src/core/aerolib/stubs.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "common/log.h" #include "core/aerolib/aerolib.h" #include "core/aerolib/stubs.h" diff --git a/src/core/aerolib/stubs.h b/src/core/aerolib/stubs.h index d36154e7..70cc9b64 100644 --- a/src/core/aerolib/stubs.h +++ b/src/core/aerolib/stubs.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" diff --git a/src/core/file_sys/fs.cpp b/src/core/file_sys/fs.cpp index fa60c04a..5e8f8312 100644 --- a/src/core/file_sys/fs.cpp +++ b/src/core/file_sys/fs.cpp @@ -1,6 +1,8 @@ -#include "fs.h" +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include +#include "core/file_sys/fs.h" namespace Core::FileSys { @@ -88,4 +90,4 @@ File* HandleTable::getFile(const std::string& host_name) { } return nullptr; } -} // namespace Core::FileSys \ No newline at end of file +} // namespace Core::FileSys diff --git a/src/core/file_sys/fs.h b/src/core/file_sys/fs.h index 23a23976..79910525 100644 --- a/src/core/file_sys/fs.h +++ b/src/core/file_sys/fs.h @@ -1,12 +1,14 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include #include #include #include - -#include #include "common/fs_file.h" +#include "common/io_file.h" namespace Core::FileSys { diff --git a/src/core/hle/error_codes.h b/src/core/hle/error_codes.h index 06438176..b9dd4f64 100644 --- a/src/core/hle/error_codes.h +++ b/src/core/hle/error_codes.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once // posix error codes diff --git a/src/core/hle/kernel/Objects/event_queue.cpp b/src/core/hle/kernel/Objects/event_queue.cpp index eb999b3f..1aef99e8 100644 --- a/src/core/hle/kernel/Objects/event_queue.cpp +++ b/src/core/hle/kernel/Objects/event_queue.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "common/debug.h" #include "core/hle/kernel/Objects/event_queue.h" diff --git a/src/core/hle/kernel/Objects/event_queue.h b/src/core/hle/kernel/Objects/event_queue.h index d03508c3..37f0fe21 100644 --- a/src/core/hle/kernel/Objects/event_queue.h +++ b/src/core/hle/kernel/Objects/event_queue.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include diff --git a/src/core/hle/kernel/Objects/physical_memory.cpp b/src/core/hle/kernel/Objects/physical_memory.cpp index 7f4475de..0c9976bd 100644 --- a/src/core/hle/kernel/Objects/physical_memory.cpp +++ b/src/core/hle/kernel/Objects/physical_memory.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "core/hle/kernel/Objects/physical_memory.h" namespace Core::Kernel { diff --git a/src/core/hle/kernel/Objects/physical_memory.h b/src/core/hle/kernel/Objects/physical_memory.h index 329b30b0..af8feda9 100644 --- a/src/core/hle/kernel/Objects/physical_memory.h +++ b/src/core/hle/kernel/Objects/physical_memory.h @@ -1,8 +1,10 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include #include - #include "common/types.h" #include "core/PS4/GPU/gpu_memory.h" #include "core/virtual_memory.h" diff --git a/src/core/hle/kernel/cpu_management.cpp b/src/core/hle/kernel/cpu_management.cpp index 71bf2f6b..bd483e84 100644 --- a/src/core/hle/kernel/cpu_management.cpp +++ b/src/core/hle/kernel/cpu_management.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "Util/config.h" #include "common/log.h" #include "core/hle/kernel/cpu_management.h" diff --git a/src/core/hle/kernel/cpu_management.h b/src/core/hle/kernel/cpu_management.h index a8f1d33a..73f298ba 100644 --- a/src/core/hle/kernel/cpu_management.h +++ b/src/core/hle/kernel/cpu_management.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" diff --git a/src/core/hle/kernel/event_queues.cpp b/src/core/hle/kernel/event_queues.cpp index 5f5de544..ca3264d4 100644 --- a/src/core/hle/kernel/event_queues.cpp +++ b/src/core/hle/kernel/event_queues.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "common/debug.h" #include "common/log.h" #include "core/hle/error_codes.h" diff --git a/src/core/hle/kernel/event_queues.h b/src/core/hle/kernel/event_queues.h index caaeee7a..68e8cddc 100644 --- a/src/core/hle/kernel/event_queues.h +++ b/src/core/hle/kernel/event_queues.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "core/hle/kernel/Objects/event_queue.h" diff --git a/src/core/hle/kernel/memory_management.cpp b/src/core/hle/kernel/memory_management.cpp index 5d406f55..7cb23e8f 100644 --- a/src/core/hle/kernel/memory_management.cpp +++ b/src/core/hle/kernel/memory_management.cpp @@ -1,14 +1,17 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include -#include -#include #include #include "common/debug.h" #include "common/log.h" #include "common/singleton.h" +#include "core/PS4/GPU/gpu_memory.h" #include "core/hle/error_codes.h" #include "core/hle/kernel/Objects/physical_memory.h" #include "core/hle/kernel/memory_management.h" #include "core/hle/libraries/libs.h" +#include "core/virtual_memory.h" namespace Core::Kernel { diff --git a/src/core/hle/kernel/memory_management.h b/src/core/hle/kernel/memory_management.h index 81a26e25..dc37cd2f 100644 --- a/src/core/hle/kernel/memory_management.h +++ b/src/core/hle/kernel/memory_management.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" diff --git a/src/core/hle/libraries/libc/libc.cpp b/src/core/hle/libraries/libc/libc.cpp index 49ea9a44..d3a90b22 100644 --- a/src/core/hle/libraries/libc/libc.cpp +++ b/src/core/hle/libraries/libc/libc.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include "common/debug.h" #include "common/log.h" diff --git a/src/core/hle/libraries/libc/libc.h b/src/core/hle/libraries/libc/libc.h index 70d4d80a..c740feaf 100644 --- a/src/core/hle/libraries/libc/libc.h +++ b/src/core/hle/libraries/libc/libc.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once namespace Core::Loader { diff --git a/src/core/hle/libraries/libc/libc_cxa.cpp b/src/core/hle/libraries/libc/libc_cxa.cpp index eab0d970..6d5dc7f8 100644 --- a/src/core/hle/libraries/libc/libc_cxa.cpp +++ b/src/core/hle/libraries/libc/libc_cxa.cpp @@ -1,7 +1,9 @@ -#include "libc_cxa.h" +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include "common/debug.h" #include "common/log.h" +#include "core/hle/libraries/libc/libc_cxa.h" // adapted from // https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html @@ -57,23 +59,23 @@ __attribute__((noinline)) static pthread_mutex_t* guard_mutex() { // helper functions for getting/setting flags in guard_object static bool initializerHasRun(u64* guard_object) { - return (*((u08*)guard_object) != 0); + return (*((u8*)guard_object) != 0); } static void setInitializerHasRun(u64* guard_object) { - *((u08*)guard_object) = 1; + *((u8*)guard_object) = 1; } static bool inUse(u64* guard_object) { - return (((u08*)guard_object)[1] != 0); + return (((u8*)guard_object)[1] != 0); } static void setInUse(u64* guard_object) { - ((u08*)guard_object)[1] = 1; + ((u8*)guard_object)[1] = 1; } static void setNotInUse(u64* guard_object) { - ((u08*)guard_object)[1] = 0; + ((u8*)guard_object)[1] = 0; } // diff --git a/src/core/hle/libraries/libc/libc_cxa.h b/src/core/hle/libraries/libc/libc_cxa.h index ad761562..30d61a50 100644 --- a/src/core/hle/libraries/libc/libc_cxa.h +++ b/src/core/hle/libraries/libc/libc_cxa.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #define _TIMESPEC_DEFINED diff --git a/src/core/hle/libraries/libc/libc_math.cpp b/src/core/hle/libraries/libc/libc_math.cpp index 4052b7c4..e3965445 100644 --- a/src/core/hle/libraries/libc/libc_math.cpp +++ b/src/core/hle/libraries/libc/libc_math.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include "core/hle/libraries/libc/libc_math.h" diff --git a/src/core/hle/libraries/libc/libc_math.h b/src/core/hle/libraries/libc/libc_math.h index fcc6448c..85633bcb 100644 --- a/src/core/hle/libraries/libc/libc_math.h +++ b/src/core/hle/libraries/libc/libc_math.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" diff --git a/src/core/hle/libraries/libc/libc_stdio.cpp b/src/core/hle/libraries/libc/libc_stdio.cpp index 3f817cd6..72c14e3d 100644 --- a/src/core/hle/libraries/libc/libc_stdio.cpp +++ b/src/core/hle/libraries/libc/libc_stdio.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "common/debug.h" #include "common/log.h" #include "core/hle/libraries/libc/libc_stdio.h" diff --git a/src/core/hle/libraries/libc/libc_stdio.h b/src/core/hle/libraries/libc/libc_stdio.h index 2992d07f..f4308213 100644 --- a/src/core/hle/libraries/libc/libc_stdio.h +++ b/src/core/hle/libraries/libc/libc_stdio.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" diff --git a/src/core/hle/libraries/libc/libc_stdlib.cpp b/src/core/hle/libraries/libc/libc_stdlib.cpp index d1990c16..f055ae58 100644 --- a/src/core/hle/libraries/libc/libc_stdlib.cpp +++ b/src/core/hle/libraries/libc/libc_stdlib.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include "common/debug.h" #include "common/log.h" diff --git a/src/core/hle/libraries/libc/libc_stdlib.h b/src/core/hle/libraries/libc/libc_stdlib.h index 4aa6a1d8..872e7a59 100644 --- a/src/core/hle/libraries/libc/libc_stdlib.h +++ b/src/core/hle/libraries/libc/libc_stdlib.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include diff --git a/src/core/hle/libraries/libc/libc_string.cpp b/src/core/hle/libraries/libc/libc_string.cpp index 609a8670..80ce6325 100644 --- a/src/core/hle/libraries/libc/libc_string.cpp +++ b/src/core/hle/libraries/libc/libc_string.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include "core/hle/libraries/libc/libc_string.h" diff --git a/src/core/hle/libraries/libc/libc_string.h b/src/core/hle/libraries/libc/libc_string.h index 30209aec..f8a197ee 100644 --- a/src/core/hle/libraries/libc/libc_string.h +++ b/src/core/hle/libraries/libc/libc_string.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include diff --git a/src/core/hle/libraries/libc/printf.h b/src/core/hle/libraries/libc/printf.h index f93df492..e2560879 100644 --- a/src/core/hle/libraries/libc/printf.h +++ b/src/core/hle/libraries/libc/printf.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2014-2018 Marco Paland (info@paland.com) +// SPDX-License-Identifier: MIT + /////////////////////////////////////////////////////////////////////////////// // \author (c) Marco Paland (info@paland.com) // 2014-2018, PALANDesign Hannover, Germany @@ -609,7 +612,7 @@ static inline int _vsnprintf(out_fct_type out, char* buffer, const char* format, // (unsigned short int)va.next(cpu, mem) : va.next(cpu, mem); const unsigned int value = - (flags & FLAGS_CHAR) ? static_cast(vaArgInteger(va_list)) + (flags & FLAGS_CHAR) ? static_cast(vaArgInteger(va_list)) : (flags & FLAGS_SHORT) ? static_cast(vaArgInteger(va_list)) : static_cast(vaArgInteger(va_list)); idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, diff --git a/src/core/hle/libraries/libc/va_ctx.h b/src/core/hle/libraries/libc/va_ctx.h index f83dd3de..8f7d7164 100644 --- a/src/core/hle/libraries/libc/va_ctx.h +++ b/src/core/hle/libraries/libc/va_ctx.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include "common/types.h" @@ -50,7 +53,7 @@ struct VaCtx { template T vaArgRegSaveAreaGp(VaList* l) { - auto* addr = reinterpret_cast(static_cast(l->reg_save_area) + l->gp_offset); + auto* addr = reinterpret_cast(static_cast(l->reg_save_area) + l->gp_offset); l->gp_offset += Size; return *addr; } @@ -64,7 +67,7 @@ T vaArgOverflowArgArea(VaList* l) { template T vaArgRegSaveAreaFp(VaList* l) { - auto* addr = reinterpret_cast(static_cast(l->reg_save_area) + l->fp_offset); + auto* addr = reinterpret_cast(static_cast(l->reg_save_area) + l->fp_offset); l->fp_offset += Size; return *addr; } diff --git a/src/core/hle/libraries/libkernel/file_system.cpp b/src/core/hle/libraries/libkernel/file_system.cpp index 47b33d34..d164274f 100644 --- a/src/core/hle/libraries/libkernel/file_system.cpp +++ b/src/core/hle/libraries/libkernel/file_system.cpp @@ -1,8 +1,11 @@ -#include -#include -#include +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "common/debug.h" #include "common/log.h" +#include "common/singleton.h" +#include "core/file_sys/fs.h" +#include "core/hle/error_codes.h" #include "core/hle/libraries/libkernel/file_system.h" #include "core/hle/libraries/libs.h" diff --git a/src/core/hle/libraries/libkernel/file_system.h b/src/core/hle/libraries/libkernel/file_system.h index 887f5f81..1648904e 100644 --- a/src/core/hle/libraries/libkernel/file_system.h +++ b/src/core/hle/libraries/libkernel/file_system.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" diff --git a/src/core/hle/libraries/libkernel/libkernel.cpp b/src/core/hle/libraries/libkernel/libkernel.cpp index 41df7d50..1e244d2b 100644 --- a/src/core/hle/libraries/libkernel/libkernel.cpp +++ b/src/core/hle/libraries/libkernel/libkernel.cpp @@ -1,4 +1,5 @@ -#include "core/hle/libraries/libkernel/libkernel.h" +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include "common/debug.h" #include "common/log.h" @@ -8,6 +9,8 @@ #include "core/hle/kernel/event_queues.h" #include "core/hle/kernel/memory_management.h" #include "core/hle/libraries/libkernel/file_system.h" +#include "core/hle/libraries/libkernel/libkernel.h" +#include "core/hle/libraries/libkernel/thread_management.h" #include "core/hle/libraries/libkernel/time_management.h" #include "core/hle/libraries/libs.h" #include "core/loader/elf.h" @@ -18,7 +21,6 @@ #else #include #endif -#include "thread_management.h" namespace Core::Libraries::LibKernel { diff --git a/src/core/hle/libraries/libkernel/libkernel.h b/src/core/hle/libraries/libkernel/libkernel.h index ffd8b505..436e7df1 100644 --- a/src/core/hle/libraries/libkernel/libkernel.h +++ b/src/core/hle/libraries/libkernel/libkernel.h @@ -1,7 +1,9 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include - #include "common/types.h" namespace Core::Loader { diff --git a/src/core/hle/libraries/libkernel/thread_management.cpp b/src/core/hle/libraries/libkernel/thread_management.cpp index 642e57ac..782351cb 100644 --- a/src/core/hle/libraries/libkernel/thread_management.cpp +++ b/src/core/hle/libraries/libkernel/thread_management.cpp @@ -1,10 +1,11 @@ -#include "core/hle/libraries/libkernel/thread_management.h" - -#include +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include "common/debug.h" #include "common/log.h" #include "core/hle/error_codes.h" +#include "core/hle/libraries/libkernel/thread_management.h" +#include "core/hle/libraries/libs.h" namespace Core::Libraries::LibKernel { diff --git a/src/core/hle/libraries/libkernel/thread_management.h b/src/core/hle/libraries/libkernel/thread_management.h index 5b4a53dc..ba3c513e 100644 --- a/src/core/hle/libraries/libkernel/thread_management.h +++ b/src/core/hle/libraries/libkernel/thread_management.h @@ -1,11 +1,13 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #define _TIMESPEC_DEFINED +#include #include #include -#include - #include "common/types.h" namespace Core::Loader { @@ -32,14 +34,14 @@ using ScePthreadCondattr = PthreadCondAttrInternal*; using pthreadEntryFunc = PS4_SYSV_ABI void* (*)(void*); struct PthreadInternal { - u08 reserved[4096]; + u8 reserved[4096]; std::string name; pthread_t pth; ScePthreadAttr attr; }; struct PthreadAttrInternal { - u08 reserved[64]; + u8 reserved[64]; u64 affinity; size_t guard_size; int policy; @@ -48,25 +50,25 @@ struct PthreadAttrInternal { }; struct PthreadMutexInternal { - u08 reserved[256]; + u8 reserved[256]; std::string name; pthread_mutex_t pth_mutex; }; struct PthreadMutexattrInternal { - u08 reserved[64]; + u8 reserved[64]; pthread_mutexattr_t pth_mutex_attr; int pprotocol; }; struct PthreadCondInternal { - u08 reserved[256]; + u8 reserved[256]; std::string name; pthread_cond_t cond; }; struct PthreadCondAttrInternal { - u08 reserved[64]; + u8 reserved[64]; pthread_condattr_t cond_attr; }; @@ -132,4 +134,4 @@ int PS4_SYSV_ABI posix_pthread_mutex_unlock(ScePthreadMutex* mutex); int PS4_SYSV_ABI posix_pthread_cond_broadcast(ScePthreadCond* cond); void pthreadSymbolsRegister(Loader::SymbolsResolver* sym); -} // namespace Core::Libraries::LibKernel \ No newline at end of file +} // namespace Core::Libraries::LibKernel diff --git a/src/core/hle/libraries/libkernel/time_management.cpp b/src/core/hle/libraries/libkernel/time_management.cpp index 646e6782..6d003868 100644 --- a/src/core/hle/libraries/libkernel/time_management.cpp +++ b/src/core/hle/libraries/libkernel/time_management.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "common/native_clock.h" #include "core/hle/libraries/libkernel/time_management.h" #include "core/hle/libraries/libs.h" diff --git a/src/core/hle/libraries/libkernel/time_management.h b/src/core/hle/libraries/libkernel/time_management.h index a3e6ee9f..d8b7bf80 100644 --- a/src/core/hle/libraries/libkernel/time_management.h +++ b/src/core/hle/libraries/libkernel/time_management.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" diff --git a/src/core/hle/libraries/libpad/pad.cpp b/src/core/hle/libraries/libpad/pad.cpp index fe9aec14..d9588b9e 100644 --- a/src/core/hle/libraries/libpad/pad.cpp +++ b/src/core/hle/libraries/libpad/pad.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "Emulator/Host/controller.h" #include "common/log.h" #include "common/singleton.h" diff --git a/src/core/hle/libraries/libpad/pad.h b/src/core/hle/libraries/libpad/pad.h index 84e9fced..67e14395 100644 --- a/src/core/hle/libraries/libpad/pad.h +++ b/src/core/hle/libraries/libpad/pad.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" @@ -26,17 +29,17 @@ enum ScePadButton : u32 { }; struct ScePadOpenParam { - u08 reserve[8]; + u8 reserve[8]; }; struct ScePadAnalogStick { - u08 x; - u08 y; + u8 x; + u8 y; }; struct ScePadAnalogButtons { - u08 l2; - u08 r2; - u08 padding[2]; + u8 l2; + u8 r2; + u8 padding[2]; }; struct SceFQuaternion { @@ -50,24 +53,24 @@ struct SceFVector3 { struct ScePadTouch { u16 x; u16 y; - u08 id; - u08 reserve[3]; + u8 id; + u8 reserve[3]; }; constexpr int SCE_PAD_MAX_TOUCH_NUM = 2; typedef struct ScePadTouchData { - u08 touchNum; - u08 reserve[3]; + u8 touchNum; + u8 reserve[3]; u32 reserve1; ScePadTouch touch[SCE_PAD_MAX_TOUCH_NUM]; } ScePadTouchData; struct ScePadExtensionUnitData { u32 extensionUnitId; - u08 reserve[1]; - u08 dataLength; - u08 data[10]; + u8 reserve[1]; + u8 dataLength; + u8 data[10]; }; struct ScePadData { diff --git a/src/core/hle/libraries/libs.cpp b/src/core/hle/libraries/libs.cpp index 14458183..683cbf81 100644 --- a/src/core/hle/libraries/libs.cpp +++ b/src/core/hle/libraries/libs.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "core/PS4/HLE/Graphics/video_out.h" #include "core/hle/libraries/libc/libc.h" #include "core/hle/libraries/libkernel/libkernel.h" diff --git a/src/core/hle/libraries/libs.h b/src/core/hle/libraries/libs.h index 3d42736c..59311fc4 100644 --- a/src/core/hle/libraries/libs.h +++ b/src/core/hle/libraries/libs.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "core/loader/elf.h" diff --git a/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp index 4fb25552..98aad084 100644 --- a/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp +++ b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "common/log.h" #include "core/PS4/GPU/gpu_memory.h" #include "core/hle/libraries/libs.h" diff --git a/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h index 810d49af..3a9dc178 100644 --- a/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h +++ b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" diff --git a/src/core/hle/libraries/libsystemservice/system_service.cpp b/src/core/hle/libraries/libsystemservice/system_service.cpp index 113415fd..dfffa3e3 100644 --- a/src/core/hle/libraries/libsystemservice/system_service.cpp +++ b/src/core/hle/libraries/libsystemservice/system_service.cpp @@ -1,8 +1,10 @@ -#include "core/hle/libraries/libsystemservice/system_service.h" +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include "common/log.h" #include "core/hle/error_codes.h" #include "core/hle/libraries/libs.h" +#include "core/hle/libraries/libsystemservice/system_service.h" namespace Core::Libraries::LibSystemService { diff --git a/src/core/hle/libraries/libsystemservice/system_service.h b/src/core/hle/libraries/libsystemservice/system_service.h index 9138e5ff..ed911adb 100644 --- a/src/core/hle/libraries/libsystemservice/system_service.h +++ b/src/core/hle/libraries/libsystemservice/system_service.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" @@ -15,7 +18,7 @@ struct SceSystemServiceStatus { bool isCpuMode7CpuNormal; bool isGameLiveStreamingOnAir; bool isOutOfVrPlayArea; - u08 reserved[]; + u8 reserved[]; }; s32 PS4_SYSV_ABI sceSystemServiceHideSplashScreen(); diff --git a/src/core/hle/libraries/libuserservice/libuserservice.cpp b/src/core/hle/libraries/libuserservice/libuserservice.cpp index 79ef3d28..55bf2355 100644 --- a/src/core/hle/libraries/libuserservice/libuserservice.cpp +++ b/src/core/hle/libraries/libuserservice/libuserservice.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "common/log.h" #include "core/hle/error_codes.h" #include "core/hle/libraries/libs.h" diff --git a/src/core/hle/libraries/libuserservice/libuserservice.h b/src/core/hle/libraries/libuserservice/libuserservice.h index a61c2be2..a446b281 100644 --- a/src/core/hle/libraries/libuserservice/libuserservice.h +++ b/src/core/hle/libraries/libuserservice/libuserservice.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "common/types.h" diff --git a/src/core/hle/libraries/libuserservice/usr_mng_codes.h b/src/core/hle/libraries/libuserservice/usr_mng_codes.h index bf367ee5..8b35ca64 100644 --- a/src/core/hle/libraries/libuserservice/usr_mng_codes.h +++ b/src/core/hle/libraries/libuserservice/usr_mng_codes.h @@ -1,11 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once -// constants - -constexpr int SCE_USER_SERVICE_MAX_LOGIN_USERS = 4; // max users logged in at once +constexpr int SCE_USER_SERVICE_MAX_LOGIN_USERS = 4; // Max users logged in at once constexpr int SCE_USER_SERVICE_MAX_USER_NAME_LENGTH = 16; // Max length for user name -constexpr int SCE_USER_SERVICE_USER_ID_INVALID = -1; // invalid user ID -constexpr int SCE_USER_SERVICE_USER_ID_SYSTEM = 255; // generic id for device +constexpr int SCE_USER_SERVICE_USER_ID_INVALID = -1; // Invalid user ID +constexpr int SCE_USER_SERVICE_USER_ID_SYSTEM = 255; // Generic id for device constexpr int SCE_USER_SERVICE_USER_ID_EVERYONE = - 254; // generic id for user (mostly used in common dialogs) + 254; // Generic id for user (mostly used in common dialogs) diff --git a/src/core/linker.cpp b/src/core/linker.cpp index 40094a57..7bf7691e 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include #include "common/log.h" @@ -531,7 +534,7 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) { u64 rel_base_virtual_addr = m->base_virtual_addr; u64 rel_virtual_addr = m->base_virtual_addr + rel->rel_offset; bool rel_isResolved = false; - u08 rel_sym_type = 0; + u8 rel_sym_type = 0; std::string rel_name; switch (type) { @@ -605,16 +608,15 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) { void Linker::Relocate(Module* m) { u32 idx = 0; for (auto* rel = m->dynamic_info.relocation_table; - reinterpret_cast(rel) < reinterpret_cast(m->dynamic_info.relocation_table) + - m->dynamic_info.relocation_table_size; + reinterpret_cast(rel) < reinterpret_cast(m->dynamic_info.relocation_table) + + m->dynamic_info.relocation_table_size; rel++, idx++) { relocate(idx, rel, m, false); } idx = 0; for (auto* rel = m->dynamic_info.jmp_relocation_table; - reinterpret_cast(rel) < - reinterpret_cast(m->dynamic_info.jmp_relocation_table) + - m->dynamic_info.jmp_relocation_table_size; + reinterpret_cast(rel) < reinterpret_cast(m->dynamic_info.jmp_relocation_table) + + m->dynamic_info.jmp_relocation_table_size; rel++, idx++) { relocate(idx, rel, m, true); } diff --git a/src/core/linker.h b/src/core/linker.h index 6ecd987a..5ee28f59 100644 --- a/src/core/linker.h +++ b/src/core/linker.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include @@ -22,8 +25,8 @@ struct ModuleInfo { u64 value; struct { u32 name_offset; - u08 version_minor; - u08 version_major; + u8 version_minor; + u8 version_major; u16 id; }; }; @@ -98,8 +101,8 @@ struct Module { Linker* linker = nullptr; - std::vector m_dynamic; - std::vector m_dynamic_data; + std::vector m_dynamic; + std::vector m_dynamic_data; DynamicModuleInfo dynamic_info{}; Loader::SymbolsResolver export_sym; diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 8dc6c8ee..a10cf999 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include "common/debug.h" #include "common/log.h" diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index 4b8e1713..9a570f28 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include @@ -12,12 +15,12 @@ struct self_header { static const u32 signature = 0x1D3D154Fu; u32 magic; - u08 version; - u08 mode; - u08 endian; // 1 is little endian - u08 attributes; - u08 category; - u08 program_type; + u8 version; + u8 mode; + u8 endian; // 1 is little endian + u8 attributes; + u8 category; + u8 program_type; u16 padding1; u16 header_size; u16 meta_size; @@ -59,21 +62,21 @@ struct self_segment_header { u64 memory_size; }; -constexpr u08 EI_MAG0 = 0; /* e_ident[] indexes */ -constexpr u08 EI_MAG1 = 1; -constexpr u08 EI_MAG2 = 2; -constexpr u08 EI_MAG3 = 3; -constexpr u08 EI_CLASS = 4; -constexpr u08 EI_DATA = 5; -constexpr u08 EI_VERSION = 6; -constexpr u08 EI_OSABI = 7; -constexpr u08 EI_ABIVERSION = 8; +constexpr u8 EI_MAG0 = 0; /* e_ident[] indexes */ +constexpr u8 EI_MAG1 = 1; +constexpr u8 EI_MAG2 = 2; +constexpr u8 EI_MAG3 = 3; +constexpr u8 EI_CLASS = 4; +constexpr u8 EI_DATA = 5; +constexpr u8 EI_VERSION = 6; +constexpr u8 EI_OSABI = 7; +constexpr u8 EI_ABIVERSION = 8; // Magic number -constexpr u08 ELFMAG0 = 0x7F; -constexpr u08 ELFMAG1 = 'E'; -constexpr u08 ELFMAG2 = 'L'; -constexpr u08 ELFMAG3 = 'F'; +constexpr u8 ELFMAG0 = 0x7F; +constexpr u8 ELFMAG1 = 'E'; +constexpr u8 ELFMAG2 = 'L'; +constexpr u8 ELFMAG3 = 'F'; typedef enum : u16 { ET_NONE = 0x0, @@ -183,27 +186,27 @@ typedef enum : u16 { typedef enum : u32 { EV_NONE = 0x0, EV_CURRENT = 0x1 } e_version_es; -typedef enum : u08 { +typedef enum : u8 { ELF_CLASS_NONE = 0x0, ELF_CLASS_32 = 0x1, ELF_CLASS_64 = 0x2, ELF_CLASS_NUM = 0x3 } ident_class_es; -typedef enum : u08 { +typedef enum : u8 { ELF_DATA_NONE = 0x0, ELF_DATA_2LSB = 0x1, ELF_DATA_2MSB = 0x2, ELF_DATA_NUM = 0x3 } ident_endian_es; -typedef enum : u08 { +typedef enum : u8 { ELF_VERSION_NONE = 0x0, ELF_VERSION_CURRENT = 0x1, ELF_VERSION_NUM = 0x2 } ident_version_es; -typedef enum : u08 { +typedef enum : u8 { ELF_OSABI_NONE = 0x0, /* No extensions or unspecified */ ELF_OSABI_HPUX = 0x1, /* Hewlett-Packard HP-UX */ ELF_OSABI_NETBSD = 0x2, /* NetBSD */ @@ -223,7 +226,7 @@ typedef enum : u08 { ELF_OSABI_STANDALONE = 0xFF /* Standalone (embedded applications) */ } ident_osabi_es; -typedef enum : u08 { +typedef enum : u8 { ELF_ABI_VERSION_AMDGPU_HSA_V2 = 0x0, ELF_ABI_VERSION_AMDGPU_HSA_V3 = 0x1, ELF_ABI_VERSION_AMDGPU_HSA_V4 = 0x2, @@ -231,13 +234,13 @@ typedef enum : u08 { } ident_abiversion_es; struct elf_ident { - u08 magic[4]; + u8 magic[4]; ident_class_es ei_class; ident_endian_es ei_data; ident_version_es ei_version; ident_osabi_es ei_osabi; ident_abiversion_es ei_abiversion; - u08 pad[6]; + u8 pad[6]; }; struct elf_header { @@ -339,7 +342,7 @@ struct elf_program_id_header { program_type_es program_type; u64 appver; u64 firmver; - u08 digest[32]; + u8 digest[32]; }; constexpr s64 DT_NULL = 0; @@ -387,43 +390,43 @@ struct elf_dynamic { } d_un; }; -constexpr u08 STB_LOCAL = 0; -constexpr u08 STB_GLOBAL = 1; -constexpr u08 STB_WEAK = 2; +constexpr u8 STB_LOCAL = 0; +constexpr u8 STB_GLOBAL = 1; +constexpr u8 STB_WEAK = 2; -constexpr u08 STT_NOTYPE = 0; -constexpr u08 STT_OBJECT = 1; -constexpr u08 STT_FUN = 2; -constexpr u08 STT_SECTION = 3; -constexpr u08 STT_FILE = 4; -constexpr u08 STT_COMMON = 5; -constexpr u08 STT_TLS = 6; -constexpr u08 STT_LOOS = 10; -constexpr u08 STT_SCE = 11; // module_start/module_stop -constexpr u08 STT_HIOS = 12; -constexpr u08 STT_LOPRO = 13; -constexpr u08 STT_SPARC_REGISTER = 13; -constexpr u08 STT_HIPROC = 15; +constexpr u8 STT_NOTYPE = 0; +constexpr u8 STT_OBJECT = 1; +constexpr u8 STT_FUN = 2; +constexpr u8 STT_SECTION = 3; +constexpr u8 STT_FILE = 4; +constexpr u8 STT_COMMON = 5; +constexpr u8 STT_TLS = 6; +constexpr u8 STT_LOOS = 10; +constexpr u8 STT_SCE = 11; // module_start/module_stop +constexpr u8 STT_HIOS = 12; +constexpr u8 STT_LOPRO = 13; +constexpr u8 STT_SPARC_REGISTER = 13; +constexpr u8 STT_HIPROC = 15; -constexpr u08 STV_DEFAULT = 0; -constexpr u08 STV_INTERNAL = 1; -constexpr u08 STV_HIDDEN = 2; -constexpr u08 STV_PROTECTED = 3; +constexpr u8 STV_DEFAULT = 0; +constexpr u8 STV_INTERNAL = 1; +constexpr u8 STV_HIDDEN = 2; +constexpr u8 STV_PROTECTED = 3; struct elf_symbol { - u08 GetBind() const { + u8 GetBind() const { return st_info >> 4u; } - u08 GetType() const { + u8 GetType() const { return st_info & 0xfu; } - u08 GetVisibility() const { + u8 GetVisibility() const { return st_other & 3u; } u32 st_name; - u08 st_info; - u08 st_other; + u8 st_info; + u8 st_other; u16 st_shndx; u64 st_value; u64 st_size; diff --git a/src/core/loader/symbols_resolver.cpp b/src/core/loader/symbols_resolver.cpp index 9455059b..221e764e 100644 --- a/src/core/loader/symbols_resolver.cpp +++ b/src/core/loader/symbols_resolver.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "common/log.h" #include "common/types.h" #include "core/loader/symbols_resolver.h" diff --git a/src/core/loader/symbols_resolver.h b/src/core/loader/symbols_resolver.h index 92fc5387..8bc17eb7 100644 --- a/src/core/loader/symbols_resolver.h +++ b/src/core/loader/symbols_resolver.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include @@ -18,8 +21,8 @@ struct SymbolRes { std::string library; u16 library_version; std::string module; - u08 module_version_major; - u08 module_version_minor; + u8 module_version_major; + u8 module_version_minor; u32 type; }; diff --git a/src/core/virtual_memory.cpp b/src/core/virtual_memory.cpp index 0f6ada46..9f3aacc1 100644 --- a/src/core/virtual_memory.cpp +++ b/src/core/virtual_memory.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include "core/virtual_memory.h" #include "common/log.h" diff --git a/src/core/virtual_memory.h b/src/core/virtual_memory.h index 5567703e..953f35f7 100644 --- a/src/core/virtual_memory.h +++ b/src/core/virtual_memory.h @@ -1,4 +1,8 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once + #include "common/types.h" constexpr u64 SYSTEM_RESERVED = 0x800000000u; @@ -40,4 +44,4 @@ inline bool containsExecuteMode(MemoryMode mode) { } } -} // namespace VirtualMemory \ No newline at end of file +} // namespace VirtualMemory diff --git a/src/emulator.cpp b/src/emulator.cpp index 954a6f8e..77e07f7c 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include #include "Emulator/Host/controller.h" diff --git a/src/emulator.h b/src/emulator.h index 72631750..bbe88a46 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include diff --git a/src/main.cpp b/src/main.cpp index 2d3771e9..95b7845c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include #include diff --git a/src/video_core/gpu_memory.cpp b/src/video_core/gpu_memory.cpp deleted file mode 100644 index ba86b075..00000000 --- a/src/video_core/gpu_memory.cpp +++ /dev/null @@ -1,201 +0,0 @@ -#include -#include -#include "gpu_memory.h" - -#include "common/singleton.h" - -void* GPU::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, - void* todo /*CommandBuffer?*/, u64 virtual_addr, u64 size, - const GPUObject& info) { - auto* gpumemory = Common::Singleton::Instance(); - - return gpumemory->memoryCreateObj(submit_id, ctx, nullptr, &virtual_addr, &size, 1, info); -} - -void GPU::memorySetAllocArea(u64 virtual_addr, u64 size) { - auto* gpumemory = Common::Singleton::Instance(); - - std::scoped_lock lock{gpumemory->m_mutex}; - - MemoryHeap h; - h.allocated_virtual_addr = virtual_addr; - h.allocated_size = size; - - gpumemory->m_heaps.push_back(h); -} - -u64 GPU::calculate_hash(const u08* buf, u64 size) { - return (size > 0 && buf != nullptr ? XXH3_64bits(buf, size) : 0); -} - -bool GPU::vulkanAllocateMemory(HLE::Libs::Graphics::GraphicCtx* ctx, - HLE::Libs::Graphics::VulkanMemory* mem) { - static std::atomic_uint64_t unique_id = 0; - - VkPhysicalDeviceMemoryProperties memory_properties{}; - vkGetPhysicalDeviceMemoryProperties(ctx->m_physical_device, &memory_properties); - - u32 index = 0; - for (; index < memory_properties.memoryTypeCount; index++) { - if ((mem->requirements.memoryTypeBits & (static_cast(1) << index)) != 0 && - (memory_properties.memoryTypes[index].propertyFlags & mem->property) == mem->property) { - break; - } - } - - mem->type = index; - mem->offset = 0; - - VkMemoryAllocateInfo alloc_info{}; - alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; - alloc_info.pNext = nullptr; - alloc_info.allocationSize = mem->requirements.size; - alloc_info.memoryTypeIndex = index; - - mem->unique_id = ++unique_id; - - auto result = vkAllocateMemory(ctx->m_device, &alloc_info, nullptr, &mem->memory); - - if (result == VK_SUCCESS) { - return true; - } - return false; -} - -void GPU::flushGarlic(HLE::Libs::Graphics::GraphicCtx* ctx) { - auto* gpumemory = Common::Singleton::Instance(); - gpumemory->flushAllHeaps(ctx); -} - -int GPU::GPUMemory::getHeapId(u64 virtual_addr, u64 size) { - int index = 0; - for (const auto& heap : m_heaps) { - if ((virtual_addr >= heap.allocated_virtual_addr && - virtual_addr < heap.allocated_virtual_addr + heap.allocated_size) || - ((virtual_addr + size - 1) >= heap.allocated_virtual_addr && - (virtual_addr + size - 1) < heap.allocated_virtual_addr + heap.allocated_size)) { - return index; - } - index++; - } - return -1; -} - -void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, - void* todo, const u64* virtual_addr, const u64* size, - int virtual_addr_num, const GPUObject& info) { - auto* gpumemory = Common::Singleton::Instance(); - - std::scoped_lock lock{gpumemory->m_mutex}; - - int heap_id = gpumemory->getHeapId(virtual_addr[0], size[0]); - - if (heap_id < 0) { - return nullptr; - } - auto& heap = m_heaps[heap_id]; - - ObjInfo objInfo = {}; - - // Copy parameters from info to obj - for (int i = 0; i < 8; i++) { - objInfo.obj_params[i] = info.obj_params[i]; - } - - objInfo.gpu_object.objectType = info.objectType; - objInfo.gpu_object.obj = nullptr; - - for (int h = 0; h < virtual_addr_num; h++) { - if (info.check_hash) { - objInfo.hash[h] = - GPU::calculate_hash(reinterpret_cast(virtual_addr[h]), size[h]); - } else { - objInfo.hash[h] = 0; - } - } - objInfo.submit_id = submit_id; - objInfo.check_hash = info.check_hash; - - objInfo.gpu_object.obj = info.getCreateFunc()(ctx, objInfo.obj_params, virtual_addr, size, - virtual_addr_num, &objInfo.mem); - - objInfo.update_func = info.getUpdateFunc(); - int index = static_cast(heap.objects.size()); - - HeapObject hobj{}; - hobj.block = createHeapBlock(virtual_addr, size, virtual_addr_num, heap_id, index); - hobj.info = objInfo; - hobj.free = false; - heap.objects.push_back(hobj); - - return objInfo.gpu_object.obj; -} - -GPU::HeapBlock GPU::GPUMemory::createHeapBlock(const u64* virtual_addr, const u64* size, - int virtual_addr_num, int heap_id, int obj_id) { - auto& heap = m_heaps[heap_id]; - - GPU::HeapBlock heapBlock{}; - heapBlock.virtual_addr_num = virtual_addr_num; - for (int vi = 0; vi < virtual_addr_num; vi++) { - heapBlock.virtual_addr[vi] = virtual_addr[vi]; - heapBlock.size[vi] = size[vi]; - } - return heapBlock; -} - -void GPU::GPUMemory::update(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, int heap_id, - int obj_id) { - auto& heap = m_heaps[heap_id]; - - auto& heapObj = heap.objects[obj_id]; - auto& objInfo = heapObj.info; - bool need_update = false; - - if (submit_id > objInfo.submit_id) { - uint64_t hash[3] = {}; - - for (int i = 0; i < heapObj.block.virtual_addr_num; i++) { - if (objInfo.check_hash) { - hash[i] = GPU::calculate_hash( - reinterpret_cast(heapObj.block.virtual_addr[i]), - heapObj.block.size[i]); - } else { - hash[i] = 0; - } - } - - for (int i = 0; i < heapObj.block.virtual_addr_num; i++) { - if (objInfo.hash[i] != hash[i]) { - need_update = true; - objInfo.hash[i] = hash[i]; - } - } - - if (submit_id != UINT64_MAX) { - objInfo.submit_id = submit_id; - } - } - - if (need_update) { - objInfo.update_func(ctx, objInfo.obj_params, objInfo.gpu_object.obj, - heapObj.block.virtual_addr, heapObj.block.size, - heapObj.block.virtual_addr_num); - } -} - -void GPU::GPUMemory::flushAllHeaps(HLE::Libs::Graphics::GraphicCtx* ctx) { - std::scoped_lock lock{m_mutex}; - - int heap_id = 0; - for (auto& heap : m_heaps) { - int index = 0; - for (auto& heapObj : heap.objects) { - if (!heapObj.free) { - update(UINT64_MAX, ctx, heap_id, index); - } - index++; - } - heap_id++; - } -} diff --git a/src/video_core/gpu_memory.h b/src/video_core/gpu_memory.h deleted file mode 100644 index 82705125..00000000 --- a/src/video_core/gpu_memory.h +++ /dev/null @@ -1,90 +0,0 @@ -#pragma once - -#include -#include -#include "common/types.h" - -namespace VideoCore { - -class GPUObject; - -enum class MemoryMode : u32 { - NoAccess = 0, - Read = 1, - Write = 2, - ReadWrite = 3, -}; - -enum class MemoryObjectType : u64 { - Invalid, - VideoOutBuffer, -}; - -struct GpuMemoryObject { - MemoryObjectType object_type = MemoryObjectType::Invalid; - void* obj = nullptr; -}; - -struct HeapBlock { - std::array virtual_address{}; - std::array size{}; - u32 virtual_addr_num = 0; -}; - -class GPUObject { -public: - GPUObject() = default; - virtual ~GPUObject() = default; - u64 obj_params[8] = {}; - bool check_hash = false; - bool isReadOnly = false; - MemoryObjectType objectType = MemoryObjectType::Invalid; -}; - -struct ObjInfo { - std::array obj_params{}; - GpuMemoryObject gpu_object; - std::array hash{}; - u64 submit_id = 0; - bool check_hash = false; -}; - -struct HeapObject { - HeapBlock block; - ObjInfo info; - bool free = true; -}; -struct MemoryHeap { - u64 allocated_virtual_addr = 0; - u64 allocated_size = 0; - std::vector objects; -}; - -class GPUMemory { -public: - GPUMemory() {} - virtual ~GPUMemory() {} - int getHeapId(u64 vaddr, u64 size); - void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, - /*CommandBuffer* buffer*/ void* todo, const u64* virtual_addr, - const u64* size, int virtual_addr_num, const GPUObject& info); - HeapBlock createHeapBlock(const u64* virtual_addr, const u64* size, int virtual_addr_num, - int heap_id, int obj_id); - void update(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, int heap_id, int obj_id); - void flushAllHeaps(HLE::Libs::Graphics::GraphicCtx* ctx); - -private: - std::mutex m_mutex; - std::vector m_heaps; -}; - -void memorySetAllocArea(u64 virtual_addr, u64 size); -void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, - /*CommandBuffer* buffer*/ void* todo, u64 virtual_addr, u64 size, - const GPUObject& info); -u64 calculate_hash(const u08* buf, u64 size); -bool vulkanAllocateMemory(HLE::Libs::Graphics::GraphicCtx* ctx, - HLE::Libs::Graphics::VulkanMemory* mem); -void flushGarlic(HLE::Libs::Graphics::GraphicCtx* ctx); - -} // namespace VideoCore diff --git a/src/video_core/tile_manager.cpp b/src/video_core/tile_manager.cpp deleted file mode 100644 index a1a8d0f0..00000000 --- a/src/video_core/tile_manager.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#include -#include -#include "video_core/tile_manager.h" - -namespace VideoCore { - -class TileManager32 { -public: - u32 m_macro_tile_height = 0; - u32 m_bank_height = 0; - u32 m_num_banks = 0; - u32 m_num_pipes = 0; - u32 m_padded_width = 0; - u32 m_padded_height = 0; - u32 m_pipe_bits = 0; - u32 m_bank_bits = 0; - - TileManager32(u32 width, u32 height, bool is_neo) { - m_macro_tile_height = (is_neo ? 128 : 64); - m_bank_height = is_neo ? 2 : 1; - m_num_banks = is_neo ? 8 : 16; - m_num_pipes = is_neo ? 16 : 8; - m_padded_width = width; - if (height == 1080) { - m_padded_height = is_neo ? 1152 : 1088; - } - if (height == 720) { - m_padded_height = 768; - } - m_pipe_bits = is_neo ? 4 : 3; - m_bank_bits = is_neo ? 3 : 4; - } - - static u32 GetElementIndex(u32 x, u32 y) { - u32 elem = 0; - elem |= ((x >> 0u) & 0x1u) << 0u; - elem |= ((x >> 1u) & 0x1u) << 1u; - elem |= ((y >> 0u) & 0x1u) << 2u; - elem |= ((x >> 2u) & 0x1u) << 3u; - elem |= ((y >> 1u) & 0x1u) << 4u; - elem |= ((y >> 2u) & 0x1u) << 5u; - - return elem; - } - - static u32 GetPipeIndex(u32 x, u32 y, bool is_neo) { - u32 pipe = 0; - - if (!is_neo) { - pipe |= (((x >> 3u) ^ (y >> 3u) ^ (x >> 4u)) & 0x1u) << 0u; - pipe |= (((x >> 4u) ^ (y >> 4u)) & 0x1u) << 1u; - pipe |= (((x >> 5u) ^ (y >> 5u)) & 0x1u) << 2u; - } else { - pipe |= (((x >> 3u) ^ (y >> 3u) ^ (x >> 4u)) & 0x1u) << 0u; - pipe |= (((x >> 4u) ^ (y >> 4u)) & 0x1u) << 1u; - pipe |= (((x >> 5u) ^ (y >> 5u)) & 0x1u) << 2u; - pipe |= (((x >> 6u) ^ (y >> 5u)) & 0x1u) << 3u; - } - - return pipe; - } - - static u32 GetBankIndex(u32 x, u32 y, u32 bank_width, u32 bank_height, u32 num_banks, - u32 num_pipes) { - const u32 x_shift_offset = std::bit_width(bank_width * num_pipes); - const u32 y_shift_offset = std::bit_width(bank_height); - const u32 xs = x >> x_shift_offset; - const u32 ys = y >> y_shift_offset; - u32 bank = 0; - switch (num_banks) { - case 8: - bank |= (((xs >> 3u) ^ (ys >> 5u)) & 0x1u) << 0u; - bank |= (((xs >> 4u) ^ (ys >> 4u) ^ (ys >> 5u)) & 0x1u) << 1u; - bank |= (((xs >> 5u) ^ (ys >> 3u)) & 0x1u) << 2u; - break; - case 16: - bank |= (((xs >> 3u) ^ (ys >> 6u)) & 0x1u) << 0u; - bank |= (((xs >> 4u) ^ (ys >> 5u) ^ (ys >> 6u)) & 0x1u) << 1u; - bank |= (((xs >> 5u) ^ (ys >> 4u)) & 0x1u) << 2u; - bank |= (((xs >> 6u) ^ (ys >> 3u)) & 0x1u) << 3u; - break; - default:; - } - - return bank; - } - - u64 GetTiledOffset(u32 x, u32 y, bool is_neo) const { - u64 element_index = GetElementIndex(x, y); - - u32 xh = x; - u32 yh = y; - u64 pipe = GetPipeIndex(xh, yh, is_neo); - u64 bank = GetBankIndex(xh, yh, 1, m_bank_height, m_num_banks, m_num_pipes); - u32 tile_bytes = (8 * 8 * 32 + 7) / 8; - u64 element_offset = (element_index * 32); - u64 tile_split_slice = 0; - - if (tile_bytes > 512) { - tile_split_slice = element_offset / (static_cast(512) * 8); - element_offset %= (static_cast(512) * 8); - tile_bytes = 512; - } - - u64 macro_tile_bytes = - (128 / 8) * (m_macro_tile_height / 8) * tile_bytes / (m_num_pipes * m_num_banks); - u64 macro_tiles_per_row = m_padded_width / 128; - u64 macro_tile_row_index = y / m_macro_tile_height; - u64 macro_tile_column_index = x / 128; - u64 macro_tile_index = - (macro_tile_row_index * macro_tiles_per_row) + macro_tile_column_index; - u64 macro_tile_offset = macro_tile_index * macro_tile_bytes; - u64 macro_tiles_per_slice = macro_tiles_per_row * (m_padded_height / m_macro_tile_height); - u64 slice_bytes = macro_tiles_per_slice * macro_tile_bytes; - u64 slice_offset = tile_split_slice * slice_bytes; - u64 tile_row_index = (y / 8) % m_bank_height; - u64 tile_index = tile_row_index; - u64 tile_offset = tile_index * tile_bytes; - - u64 tile_split_slice_rotation = ((m_num_banks / 2) + 1) * tile_split_slice; - bank ^= tile_split_slice_rotation; - bank &= (m_num_banks - 1); - - u64 total_offset = (slice_offset + macro_tile_offset + tile_offset) * 8 + element_offset; - u64 bit_offset = total_offset & 0x7u; - total_offset /= 8; - - u64 pipe_interleave_offset = total_offset & 0xffu; - u64 offset = total_offset >> 8u; - u64 byte_offset = pipe_interleave_offset | (pipe << (8u)) | (bank << (8u + m_pipe_bits)) | - (offset << (8u + m_pipe_bits + m_bank_bits)); - - return ((byte_offset << 3u) | bit_offset) / 8; - } -}; - -void ConvertTileToLinear(u08* dst, const u08* src, u32 width, u32 height, bool is_neo) { - const TileManager32 t{width, height, is_neo}; - for (u32 y = 0; y < height; y++) { - u32 x = 0; - u64 linear_offset = y * width * 4; - - for (; x + 1 < width; x += 2) { - auto tiled_offset = t.GetTiledOffset(x, y, is_neo); - std::memcpy(dst + linear_offset, src + tiled_offset, sizeof(u64)); - linear_offset += sizeof(u64); - } - if (x < width) { - auto tiled_offset = t.GetTiledOffset(x, y, is_neo); - std::memcpy(dst + linear_offset, src + tiled_offset, sizeof(u32)); - } - } -} - -} // namespace VideoCore diff --git a/src/video_core/tile_manager.h b/src/video_core/tile_manager.h deleted file mode 100644 index b58b99c9..00000000 --- a/src/video_core/tile_manager.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "common/types.h" - -namespace VideoCore { - -void ConvertTileToLinear(void* dst, const void* src, u32 width, u32 height, bool neo); - -} // namespace VideoCore diff --git a/src/vulkan_util.cpp b/src/vulkan_util.cpp index a2c10233..326ec81e 100644 --- a/src/vulkan_util.cpp +++ b/src/vulkan_util.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #include #include #include diff --git a/src/vulkan_util.h b/src/vulkan_util.h index 2cd32c88..18291a9d 100644 --- a/src/vulkan_util.h +++ b/src/vulkan_util.h @@ -1,10 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once -#include -#include -#include #include - +#include +#include +#include "core/PS4/HLE/Graphics/graphics_render.h" #include "emulator.h" namespace Graphics::Vulkan { diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index d9bbe697..49359516 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + if (MSVC) # Silence "deprecation" warnings add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS) diff --git a/third-party/result/LICENSE b/third-party/result/LICENSE deleted file mode 100644 index 6f4e91e3..00000000 --- a/third-party/result/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {2016} {Mathieu Stefani} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/third-party/result/README.md b/third-party/result/README.md deleted file mode 100644 index 7f588045..00000000 --- a/third-party/result/README.md +++ /dev/null @@ -1,132 +0,0 @@ -# Result -This is an adaption of [https://github.com/oktal/result](https://github.com/oktal/result). Make sure to support the original library! - -## Overview - -`Result` is a template type that can be used to return and propage errors. It can be used to replace -exceptions in context where they are not allowed or too slow to be used. `Result` is an algebraic data -type of `Ok(T)` that represents success and `Err(E)` representing an error. - -Design of this class has been mainly inspired by Rust's [std::result](https://doc.rust-lang.org/std/result/) - -``` - -struct Request { -}; - -struct Error { - - enum class Kind { - Timeout, - Invalid, - TooLong - } - - Error(Kind kind, std::string text); - - Kind kind; - std::string text; -}; - -Result parseRequest(const std::string& payload) { - if (payload.size() > 512) return Err(Error(Kind::TooLong, "Request exceeded maximum allowed size (512 bytes)")); - - Request request; - return Ok(request); -} - -std::string payload = receivePayload(); -auto request = parseRequest(payload).expect("Failed to parse request"); -``` - -To return a successfull `Result`, use the `Ok()` function. To return an error one, use the `Err()` function. - -## Extract and unwrap - -To extract the value from a `Result` type, you can use the `expect()` function that will yield the value -of an `Ok(T)` or terminate the program with an error message passed as a parameter. - -``` -Result r1 = Ok(3u); - -auto val = r1.expect("Failed to retrieve the value"); -assert(val == 3); -``` - -`unwrap()` can also be used to extract the value of a `Result`, yielding the value of an `Ok(T)` value or terminating -the program otherwise: - -``` -Result r1 = Ok(3u); - -auto val = r1.unwrap(); -assert(val == 3); -``` - -Instead a terminating the program, `unwrapOr` can be used to return a default value for an `Err(E)` Result: - -``` -Result r1 = Err(9u); - -auto val = r1.unwrapOr(0); -assert(val == 0); -``` - -## Map and bind - -To transform (or map) a `Result` to a `Result`, `Result` provides a `map` member function. -`map` will apply a function to a contained `Ok(T)` value and will return the result of the transformation, -and will leave an `Err(E)` untouched: - -``` -std::string stringify(int val) { return std::to_string(val); } - -Result r1 = Ok(2u); -auto r2 = r1.map(stringify); // Maps a Result to Result - -assert(r2.unwrap(), "2"); -``` - -Note that `map` should return a simple value and not a `Result`. A function returning nothing (`void`) -applied to a `Result` will yield a `Result`. - -To map a function to a contained `Err(E)` value, use the `mapError` function. - -To *bind* a `Result` to a `Result`, you can use the `andThen` member function: - -``` -Result square(uint32_t val) { return Ok(val * val); } - -Result r1 = Ok(3u); -auto r2 = r1.andThen(square); - -assert(r2.unwrap(), 9); -``` - -Use `orElse` to apply a function to a contained `Err(E)` value: - -``` -Result identity(uint32_t val) { return Ok(val); } - -Result r1 = Err(3u); -assert(r1.andThen(identity).orElse(square).unwrap(), 9); -``` - -## The TRY macro - -Like Rust, a `TRY` macro is also provided that comes in handy when writing code that calls a lot of functions returning a `Result`. - -the `TRY` macro will simply call its argument and short-cirtcuit the function returning an `Err(E)` if the operation returned an error `Result`: - -``` -Result copy(int srcFd, const char* dstFile) { - - auto fd = TRY(open(dstFile)); - auto data = TRY(read(srcFd)); - TRY(write(fd, data)); - - return Ok(); -} -``` - -Note that this macro uses a special extension called *compound statement* only supported by gcc and clang diff --git a/third-party/result/include/result.hpp b/third-party/result/include/result.hpp deleted file mode 100644 index b75dee90..00000000 --- a/third-party/result/include/result.hpp +++ /dev/null @@ -1,910 +0,0 @@ -/* - Mathieu Stefani, 03 mai 2016 - - This header provides a Result type that can be used to replace exceptions in code - that has to handle error. - - Result can be used to return and propagate an error to the caller. Result is an algebraic - data type that can either Ok(T) to represent success or Err(E) to represent an error. -*/ - -#pragma once - -#include -#include -#include - -namespace types { - template - struct Ok { - Ok(const T& val) : val(val) { } - Ok(T&& val) : val(std::move(val)) { } - - T val; - }; - - template<> - struct Ok { }; - - template - struct Err { - Err(const E& val) : val(val) { } - Err(E&& val) : val(std::move(val)) { } - - E val; - }; -} - -template::type> -types::Ok Ok(T&& val) { - return types::Ok(std::forward(val)); -} - -inline types::Ok Ok() { - return types::Ok(); -} - -template::type> -types::Err Err(E&& val) { - return types::Err(std::forward(val)); -} - -namespace Rust { -template struct Result; -} - -namespace details { - -template struct void_t { typedef void type; }; - -namespace impl { - template struct result_of; - - template - struct result_of : public result_of { }; - - template - struct result_of { - typedef Ret type; - }; -} - -template -struct result_of : public impl::result_of { }; - -template -struct result_of { - typedef Ret type; -}; - -template -struct result_of { - typedef Ret type; -}; - -template -struct ResultOkType { typedef typename std::decay::type type; }; - -template -struct ResultOkType> { - typedef T type; -}; - -template -struct ResultErrType { typedef R type; }; - -template -struct ResultErrType> { - typedef typename std::remove_reference::type type; -}; - -template struct IsResult : public std::false_type { }; -template -struct IsResult> : public std::true_type { }; - -namespace ok { - -namespace impl { - -template struct Map; - -template -struct Map : public Map { }; - -template -struct Map : public Map { }; - -// General implementation -template -struct Map { - - static_assert(!IsResult::value, - "Can not map a callback returning a Result, use andThen instead"); - - template - static Rust::Result map(const Rust::Result& result, Func func) { - - static_assert( - std::is_same::value || - std::is_convertible::value, - "Incompatible types detected"); - - if (result.isOk()) { - auto res = func(result.storage().template get()); - return types::Ok(std::move(res)); - } - - return types::Err(result.storage().template get()); - } -}; - -// Specialization for callback returning void -template -struct Map { - - template - static Rust::Result map(const Rust::Result& result, Func func) { - - if (result.isOk()) { - func(result.storage().template get()); - return types::Ok(); - } - - return types::Err(result.storage().template get()); - } -}; - -// Specialization for a void Result -template -struct Map { - - template - static Rust::Result map(const Rust::Result& result, Func func) { - static_assert(std::is_same::value, - "Can not map a void callback on a non-void Result"); - - if (result.isOk()) { - auto ret = func(); - return types::Ok(std::move(ret)); - } - - return types::Err(result.storage().template get()); - } -}; - -// Specialization for callback returning void on a void Result -template<> -struct Map { - - template - static Rust::Result map(const Rust::Result& result, Func func) { - static_assert(std::is_same::value, - "Can not map a void callback on a non-void Result"); - - if (result.isOk()) { - func(); - return types::Ok(); - } - - return types::Err(result.storage().template get()); - } -}; - -// General specialization for a callback returning a Result -template -struct Map (Arg)> { - - template - static Rust::Result map(const Rust::Result& result, Func func) { - static_assert( - std::is_same::value || - std::is_convertible::value, - "Incompatible types detected"); - - if (result.isOk()) { - auto res = func(result.storage().template get()); - return res; - } - - return types::Err(result.storage().template get()); - } -}; - -// Specialization for a void callback returning a Result -template -struct Map (void)> { - - template - static Rust::Result map(const Rust::Result& result, Func func) { - static_assert(std::is_same::value, "Can not call a void-callback on a non-void Result"); - - if (result.isOk()) { - auto res = func(); - return res; - } - - return types::Err(result.storage().template get()); - } - -}; - -} // namespace impl - -template struct Map : public impl::Map { }; - -template -struct Map : public impl::Map { }; - -template -struct Map : public impl::Map { }; - -template -struct Map : public impl::Map { }; - -template -struct Map> : public impl::Map { }; - -} // namespace ok - - -namespace err { - -namespace impl { - -template struct Map; - -template -struct Map { - - static_assert(!IsResult::value, - "Can not map a callback returning a Result, use orElse instead"); - - template - static Rust::Result map(const Rust::Result& result, Func func) { - if (result.isErr()) { - auto res = func(result.storage().template get()); - return types::Err(res); - } - - return types::Ok(result.storage().template get()); - } - - template - static Rust::Result map(const Rust::Result& result, Func func) { - if (result.isErr()) { - auto res = func(result.storage().template get()); - return types::Err(res); - } - - return types::Ok(); - } - - -}; - -} // namespace impl - -template struct Map : public impl::Map { }; - -} // namespace err; - -namespace And { - -namespace impl { - - template struct Then; - - template - struct Then : public Then { }; - - template - struct Then : public Then { }; - - template - struct Then : public Then { }; - - template - struct Then { - static_assert(std::is_same::value, - "then() should not return anything, use map() instead"); - - template - static Rust::Result then(const Rust::Result& result, Func func) { - if (result.isOk()) { - func(result.storage().template get()); - } - return result; - } - }; - - template - struct Then { - static_assert(std::is_same::value, - "then() should not return anything, use map() instead"); - - template - static Rust::Result then(const Rust::Result& result, Func func) { - static_assert(std::is_same::value, "Can not call a void-callback on a non-void Result"); - - if (result.isOk()) { - func(); - } - - return result; - } - }; - - -} // namespace impl - -template -struct Then : public impl::Then { }; - -template -struct Then : public impl::Then { }; - -template -struct Then : public impl::Then { }; - -template -struct Then : public impl::Then { }; - -} // namespace And - -namespace Or { - -namespace impl { - - template struct Else; - - template - struct Else : public Else { }; - - template - struct Else : public Else { }; - - template - struct Else : public Else { }; - - template - struct Else (Arg)> { - - template - static Rust::Result orElse(const Rust::Result& result, Func func) { - static_assert( - std::is_same::value || - std::is_convertible::value, - "Incompatible types detected"); - - if (result.isErr()) { - auto res = func(result.storage().template get()); - return res; - } - - return types::Ok(result.storage().template get()); - } - - template - static Rust::Result orElse(const Rust::Result& result, Func func) { - if (result.isErr()) { - auto res = func(result.storage().template get()); - return res; - } - - return types::Ok(); - } - - }; - - template - struct Else (void)> { - - template - static Rust::Result orElse(const Rust::Result& result, Func func) { - static_assert(std::is_same::value, - "Can not call a void-callback on a non-void Result"); - - if (result.isErr()) { - auto res = func(); - return res; - } - - return types::Ok(result.storage().template get()); - } - - template - static Rust::Result orElse(const Rust::Result& result, Func func) { - if (result.isErr()) { - auto res = func(); - return res; - } - - return types::Ok(); - } - - }; - -} // namespace impl - -template -struct Else : public impl::Else { }; - -template -struct Else : public impl::Else { }; - -template -struct Else : public impl::Else { }; - -template -struct Else : public impl::Else { }; - -} // namespace Or - -namespace Other { - -namespace impl { - - template struct Wise; - - template - struct Wise : public Wise { }; - - template - struct Wise : public Wise { }; - - template - struct Wise : public Wise { }; - - template - struct Wise { - - template - static Rust::Result otherwise(const Rust::Result& result, Func func) { - static_assert( - std::is_same::value || - std::is_convertible::value, - "Incompatible types detected"); - - static_assert(std::is_same::value, - "callback should not return anything, use mapError() for that"); - - if (result.isErr()) { - func(result.storage().template get()); - } - return result; - } - - }; - -} // namespace impl - -template -struct Wise : public impl::Wise { }; - -template -struct Wise : public impl::Wise { }; - -template -struct Wise : public impl::Wise { }; - -template -struct Wise : public impl::Wise { }; - -} // namespace Other - -template::type - >::type, - E> - > -Ret map(const Rust::Result& result, Func func) { - return ok::Map::map(result, func); -} - -template::type - >::type - > - > -Ret mapError(const Rust::Result& result, Func func) { - return err::Map::map(result, func); -} - -template -Rust::Result then(const Rust::Result& result, Func func) { - return And::Then::then(result, func); -} - -template -Rust::Result otherwise(const Rust::Result& result, Func func) { - return Other::Wise::otherwise(result, func); -} - -template::type - >::type - > -> -Ret orElse(const Rust::Result& result, Func func) { - return Or::Else::orElse(result, func); -} - -struct ok_tag { }; -struct err_tag { }; - -template -struct Storage { - static constexpr size_t Size = sizeof(T) > sizeof(E) ? sizeof(T) : sizeof(E); - static constexpr size_t Align = sizeof(T) > sizeof(E) ? alignof(T) : alignof(E); - - typedef typename std::aligned_storage::type type; - - Storage() - : initialized_(false) - { } - - void construct(types::Ok ok) - { - new (&storage_) T(ok.val); - initialized_ = true; - } - void construct(types::Err err) - { - new (&storage_) E(err.val); - initialized_ = true; - } - - template - void rawConstruct(U&& val) { - typedef typename std::decay::type CleanU; - - new (&storage_) CleanU(std::forward(val)); - initialized_ = true; - } - - template - const U& get() const { - return *reinterpret_cast(&storage_); - } - - template - U& get() { - return *reinterpret_cast(&storage_); - } - - void destroy(ok_tag) { - if (initialized_) { - get().~T(); - initialized_ = false; - } - } - - void destroy(err_tag) { - if (initialized_) { - get().~E(); - initialized_ = false; - } - } - - type storage_; - bool initialized_; -}; - -template -struct Storage { - typedef typename std::aligned_storage::type type; - - void construct(types::Ok) - { - initialized_ = true; - } - - void construct(types::Err err) - { - new (&storage_) E(err.val); - initialized_ = true; - } - - template - void rawConstruct(U&& val) { - typedef typename std::decay::type CleanU; - - new (&storage_) CleanU(std::forward(val)); - initialized_ = true; - } - - void destroy(ok_tag) { initialized_ = false; } - void destroy(err_tag) { - if (initialized_) { - get().~E(); initialized_ = false; - } - } - - template - const U& get() const { - return *reinterpret_cast(&storage_); - } - - template - U& get() { - return *reinterpret_cast(&storage_); - } - - type storage_; - bool initialized_; -}; - -template -struct Constructor { - - static void move(Storage&& src, Storage& dst, ok_tag) { - dst.rawConstruct(std::move(src.template get())); - src.destroy(ok_tag()); - } - - static void copy(const Storage& src, Storage& dst, ok_tag) { - dst.rawConstruct(src.template get()); - } - - static void move(Storage&& src, Storage& dst, err_tag) { - dst.rawConstruct(std::move(src.template get())); - src.destroy(err_tag()); - } - - static void copy(const Storage& src, Storage& dst, err_tag) { - dst.rawConstruct(src.template get()); - } -}; - -template -struct Constructor { - static void move(Storage&& src, Storage& dst, ok_tag) { - } - - static void copy(const Storage& src, Storage& dst, ok_tag) { - } - - static void move(Storage&& src, Storage& dst, err_tag) { - dst.rawConstruct(std::move(src.template get())); - src.destroy(err_tag()); - } - - static void copy(const Storage& src, Storage& dst, err_tag) { - dst.rawConstruct(src.template get()); - } -}; - -} // namespace details - -namespace rpog { - -template struct EqualityComparable : std::false_type { }; - -template -struct EqualityComparable() == std::declval())>::type - >::type -> : std::true_type -{ -}; - - -} // namespace rpog - -namespace Rust { -template -struct Result { - - static_assert(!std::is_same::value, "void error type is not allowed"); - - typedef details::Storage storage_type; - - Result(types::Ok ok) - : ok_(true) - { - storage_.construct(std::move(ok)); - } - - Result(types::Err err) - : ok_(false) - { - storage_.construct(std::move(err)); - } - - Result(Result&& other) { - if (other.isOk()) { - details::Constructor::move(std::move(other.storage_), storage_, details::ok_tag()); - ok_ = true; - } else { - details::Constructor::move(std::move(other.storage_), storage_, details::err_tag()); - ok_ = false; - } - } - - Result(const Result& other) { - if (other.isOk()) { - details::Constructor::copy(other.storage_, storage_, details::ok_tag()); - ok_ = true; - } else { - details::Constructor::copy(other.storage_, storage_, details::err_tag()); - ok_ = false; - } - } - - ~Result() { - if (ok_) - storage_.destroy(details::ok_tag()); - else - storage_.destroy(details::err_tag()); - } - - bool isOk() const { - return ok_; - } - - bool isErr() const { - return !ok_; - } - - T expect(const char* str) const { - if (!isOk()) { - std::fprintf(stderr, "%s\n", str); - std::terminate(); - } - return expect_impl(std::is_same()); - } - - template::type - >::type, - E> - > - Ret map(Func func) const { - return details::map(*this, func); - } - - template::type - >::type - > - > - Ret mapError(Func func) const { - return details::mapError(*this, func); - } - - template - Result then(Func func) const { - return details::then(*this, func); - } - - template - Result otherwise(Func func) const { - return details::otherwise(*this, func); - } - - template::type - >::type - > - > - Ret orElse(Func func) const { - return details::orElse(*this, func); - } - - storage_type& storage() { - return storage_; - } - - const storage_type& storage() const { - return storage_; - } - - template - typename std::enable_if< - !std::is_same::value, - U - >::type - unwrapOr(const U& defaultValue) const { - if (isOk()) { - return storage().template get(); - } - return defaultValue; - } - - template - typename std::enable_if< - !std::is_same::value, - U - >::type - unwrap() const { - if (isOk()) { - return storage().template get(); - } - - std::fprintf(stderr, "Attempting to unwrap an error Result\n"); - std::terminate(); - } - - E unwrapErr() const { - if (isErr()) { - return storage().template get(); - } - - std::fprintf(stderr, "Attempting to unwrapErr an ok Result\n"); - std::terminate(); - } - -private: - T expect_impl(std::true_type) const { } - T expect_impl(std::false_type) const { return storage_.template get(); } - - bool ok_; - storage_type storage_; -}; - -template -bool operator==(const Rust::Result& lhs, const Rust::Result& rhs) { - static_assert(rpog::EqualityComparable::value, "T must be EqualityComparable for Result to be comparable"); - static_assert(rpog::EqualityComparable::value, "E must be EqualityComparable for Result to be comparable"); - - if (lhs.isOk() && rhs.isOk()) { - return lhs.storage().template get() == rhs.storage().template get(); - } - if (lhs.isErr() && rhs.isErr()) { - return lhs.storage().template get() == rhs.storage().template get(); - } -} - -template -bool operator==(const Rust::Result& lhs, types::Ok ok) { - static_assert(rpog::EqualityComparable::value, "T must be EqualityComparable for Result to be comparable"); - - if (!lhs.isOk()) return false; - - return lhs.storage().template get() == ok.val; -} - -template -bool operator==(const Rust::Result& lhs, types::Ok) { - return lhs.isOk(); -} - -template -bool operator==(const Rust::Result& lhs, types::Err err) { - static_assert(rpog::EqualityComparable::value, "E must be EqualityComparable for Result to be comparable"); - if (!lhs.isErr()) return false; - - return lhs.storage().template get() == err.val; -} -} // end namespace Rust - -#define TRY(...) \ - ({ \ - auto res = __VA_ARGS__; \ - if (!res.isOk()) { \ - typedef details::ResultErrType::type E; \ - return types::Err(res.storage().get()); \ - } \ - typedef details::ResultOkType::type T; \ - res.storage().get(); \ - })