diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/3rdparty/BLAKE2/neon/blake2.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/3rdparty/BLAKE2/neon/blake2.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/3rdparty/BLAKE2/neon/blake2.h 2021-05-25 01:25:26.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/3rdparty/BLAKE2/neon/blake2.h 2021-10-25 20:43:27.000000000 +0000 @@ -137,8 +137,8 @@ /* Padded structs result in a compile-time error */ enum { - BLAKE2_DUMMY_1 = 1/(sizeof(blake2s_param) == BLAKE2S_OUTBYTES), - BLAKE2_DUMMY_2 = 1/(sizeof(blake2b_param) == BLAKE2B_OUTBYTES) + BLAKE2_DUMMY_1 = 1/(int)(sizeof(blake2s_param) == BLAKE2S_OUTBYTES), + BLAKE2_DUMMY_2 = 1/(int)(sizeof(blake2b_param) == BLAKE2B_OUTBYTES) }; /* Streaming API */ diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/3rdparty/BLAKE2/power8/blake2.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/3rdparty/BLAKE2/power8/blake2.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/3rdparty/BLAKE2/power8/blake2.h 2021-05-25 01:25:26.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/3rdparty/BLAKE2/power8/blake2.h 2021-10-25 20:43:27.000000000 +0000 @@ -133,8 +133,8 @@ /* Padded structs result in a compile-time error */ enum { - BLAKE2_DUMMY_1 = 1/(sizeof(blake2s_param) == BLAKE2S_OUTBYTES), - BLAKE2_DUMMY_2 = 1/(sizeof(blake2b_param) == BLAKE2B_OUTBYTES) + BLAKE2_DUMMY_1 = 1/(int)(sizeof(blake2s_param) == BLAKE2S_OUTBYTES), + BLAKE2_DUMMY_2 = 1/(int)(sizeof(blake2b_param) == BLAKE2B_OUTBYTES) }; /* Streaming API */ diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/3rdparty/BLAKE2/ref/blake2.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/3rdparty/BLAKE2/ref/blake2.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/3rdparty/BLAKE2/ref/blake2.h 2021-05-25 01:25:26.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/3rdparty/BLAKE2/ref/blake2.h 2021-10-25 20:43:27.000000000 +0000 @@ -137,8 +137,8 @@ /* Padded structs result in a compile-time error */ enum { - BLAKE2_DUMMY_1 = 1/(sizeof(blake2s_param) == BLAKE2S_OUTBYTES), - BLAKE2_DUMMY_2 = 1/(sizeof(blake2b_param) == BLAKE2B_OUTBYTES) + BLAKE2_DUMMY_1 = 1/(int)(sizeof(blake2s_param) == BLAKE2S_OUTBYTES), + BLAKE2_DUMMY_2 = 1/(int)(sizeof(blake2b_param) == BLAKE2B_OUTBYTES) }; /* Streaming API */ diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/3rdparty/BLAKE2/sse/blake2.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/3rdparty/BLAKE2/sse/blake2.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/3rdparty/BLAKE2/sse/blake2.h 2021-05-25 01:25:26.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/3rdparty/BLAKE2/sse/blake2.h 2021-10-25 20:43:27.000000000 +0000 @@ -137,8 +137,8 @@ /* Padded structs result in a compile-time error */ enum { - BLAKE2_DUMMY_1 = 1/(sizeof(blake2s_param) == BLAKE2S_OUTBYTES), - BLAKE2_DUMMY_2 = 1/(sizeof(blake2b_param) == BLAKE2B_OUTBYTES) + BLAKE2_DUMMY_1 = 1/(int)(sizeof(blake2s_param) == BLAKE2S_OUTBYTES), + BLAKE2_DUMMY_2 = 1/(int)(sizeof(blake2b_param) == BLAKE2B_OUTBYTES) }; /* Streaming API */ diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/3rdparty/tinydir/README.md softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/3rdparty/tinydir/README.md --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/3rdparty/tinydir/README.md 2021-05-25 01:25:20.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/3rdparty/tinydir/README.md 2021-10-25 20:43:19.000000000 +0000 @@ -1,6 +1,6 @@ TinyDir ======= -[![Build Status](https://travis-ci.org/cxong/tinydir.svg?branch=master)](https://travis-ci.org/cxong/tinydir) +[![Build Status](https://travis-ci.com/cxong/tinydir.svg?branch=master)](https://travis-ci.com/github/cxong/tinydir) [![Release](http://img.shields.io/github/release/cxong/tinydir.svg)](https://github.com/cxong/tinydir/releases/latest) Lightweight, portable and easy to integrate C directory and file reader. TinyDir wraps dirent for POSIX and FindFirstFile for Windows. diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/CMakeLists.txt softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/CMakeLists.txt --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/CMakeLists.txt 2021-05-25 01:25:09.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/CMakeLists.txt 2021-10-25 20:43:04.000000000 +0000 @@ -3,7 +3,14 @@ set(BUILD_NUMBER CACHE STRING "The number of the current build.") if ("${BUILD_NUMBER}" STREQUAL "") - set(BUILD_NUMBER "0") + set(BUILD_NUMBER "5180") +endif() + +if (BUILD_NUMBER LESS 5180) + message(WARNING + "Setting BUILD_NUMBER to a value less than 5180 will break compatibility with client binaries distributed by SoftEther Corporation. " + "Set to a value greater than or equal to 5180 if you want such clients to work properly.\n" + "For detailed info: https://github.com/SoftEtherVPN/SoftEtherVPN/issues/1392#issuecomment-867348281") endif() project("SoftEther VPN" diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/debian/changelog softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/debian/changelog --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/debian/changelog 2021-05-25 01:25:35.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/debian/changelog 2021-10-25 20:43:38.000000000 +0000 @@ -1,8 +1,8 @@ -softether-vpn (5.02.0~202105242329~ubuntu20.04.1) focal; urgency=low +softether-vpn (5.02.5180~202106240828~ubuntu20.04.1) focal; urgency=low * Auto build. - -- Dmitry Verkhoturov Tue, 25 May 2021 01:25:35 +0000 + -- Dmitry Verkhoturov Mon, 25 Oct 2021 20:43:38 +0000 softether-vpn (0:5.01.9674-0) unstable; urgency=low diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/debian/git-build-recipe.manifest softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/debian/git-build-recipe.manifest --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/debian/git-build-recipe.manifest 2021-05-25 01:25:35.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/debian/git-build-recipe.manifest 2021-10-25 20:43:38.000000000 +0000 @@ -1,7 +1,7 @@ -# git-build-recipe format 0.4 deb-version 5.02.0~202105242329 -lp:~paskal-07/softether-vpn git-commit:97d9761a9b49bc539945045a54733b6ff29b4106 -nest cpu_features lp:~paskal-07/softether-vpn/+git/cpu_features src/Mayaqua/3rdparty/cpu_features git-commit:bc2846e78faeb26b8a46c17df369d4e5f1f9e2bb -nest tinydir lp:~paskal-07/softether-vpn/+git/tinydir 3rdparty/tinydir git-commit:ec6bff2043eaac3ad25423705e63a781762a0dfd -nest BLAKE2 lp:~paskal-07/softether-vpn/+git/BLAKE2 3rdparty/BLAKE2 git-commit:b52178a376ca85a8ffe50492263c2a5bc0fa4f46 -nest libhamcore lp:~paskal-07/softether-vpn/+git/libhamcore src/libhamcore git-commit:79fd4aa6a140222fb186e4966771b19f8e733075 +# git-build-recipe format 0.4 deb-version 5.02.5180~202106240828 +lp:~paskal-07/softether-vpn git-commit:56bb573b17abf8256aae363ff3e07b48c2c89549 +nest cpu_features lp:~paskal-07/softether-vpn/+git/cpu_features src/Mayaqua/3rdparty/cpu_features git-commit:545b2e84ec68f4364be1e89309a1404575689226 +nest tinydir lp:~paskal-07/softether-vpn/+git/tinydir 3rdparty/tinydir git-commit:64fb1d4376d7580aa1013fdbacddbbeba67bb085 +nest BLAKE2 lp:~paskal-07/softether-vpn/+git/BLAKE2 3rdparty/BLAKE2 git-commit:54f4faa4c16ea34bcd59d16e8da46a64b259fc07 +nest libhamcore lp:~paskal-07/softether-vpn/+git/libhamcore src/libhamcore git-commit:2951ae5b61b16c1f4e03ceee88d6db7e1e45362b nest-part packaging lp:~paskal-07/softether-vpn/+git/SoftEtherVPN-debianisation debian debian git-commit:f730673a58a6478def432da7df3513a2ee6f3306 diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/.github/workflows/build_source_release.yml softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/.github/workflows/build_source_release.yml --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/.github/workflows/build_source_release.yml 1970-01-01 00:00:00.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/.github/workflows/build_source_release.yml 2021-10-25 20:43:04.000000000 +0000 @@ -0,0 +1,39 @@ +name: Build Source Release + +# Trigger whenever a release is created +on: + release: + types: + - created + +jobs: + build: + name: build + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v1 + with: + submodules: true + + - name: archive + id: archive + run: | + VERSION=${{ github.event.release.tag_name }} + PKGNAME="SoftEtherVPN-$VERSION" + mkdir -p /tmp/$PKGNAME + mv * /tmp/$PKGNAME + mv /tmp/$PKGNAME . + TARBALL=$PKGNAME.tar.xz + tar cJf $TARBALL $PKGNAME + echo "::set-output name=tarball::$TARBALL" + + - name: upload tarball + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./${{ steps.archive.outputs.tarball }} + asset_name: ${{ steps.archive.outputs.tarball }} + asset_content_type: application/gzip diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/.github/workflows/coverity.yml softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/.github/workflows/coverity.yml --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/.github/workflows/coverity.yml 2021-05-25 01:25:09.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/.github/workflows/coverity.yml 2021-10-25 20:43:04.000000000 +0000 @@ -22,7 +22,7 @@ - name: Install apt dependencies run: | sudo apt-get update - sudo apt-get install -y cmake gcc g++ libncurses5-dev libreadline-dev libssl-dev make zlib1g-dev + sudo apt-get install -y cmake gcc g++ libncurses5-dev libreadline-dev libssl-dev make zlib1g-dev libsodium-dev - name: Run Coverity Scan env: COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/bin/hamcore/strtable_ja.stb softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/bin/hamcore/strtable_ja.stb --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/bin/hamcore/strtable_ja.stb 2021-05-25 01:25:09.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/bin/hamcore/strtable_ja.stb 2021-10-25 20:43:04.000000000 +0000 @@ -1807,12 +1807,12 @@ # (WireGuard ログ) LW_PREFIX_SESSION [WireGuard] %r:%u -> %r:%u: -LW_KEYPAIR_EXPIRED Current keypair (%x -> %x) is expired! -LW_KEYPAIR_UNKNOWN The packet was encrypted with an unknown keypair! -LW_DECRYPT_FAIL Decryption failure! -LW_REPLAY_ATTACK Replay attack detected! -LW_FLOOD_ATTACK Flood attack detected! -LW_HUB_DISCONNECT The administrator of the Virtual Hub has disconnected this session. +LW_KEYPAIR_EXPIRED 現在の鍵ペア (%x -> %x) の有効期限が切れています。 +LW_KEYPAIR_UNKNOWN パケットが未知の鍵ペアによって暗号化されていました。 +LW_DECRYPT_FAIL 復号に失敗しました。 +LW_REPLAY_ATTACK リプレイ攻撃を検出しました。 +LW_FLOOD_ATTACK フラッド攻撃を検出しました。 +LW_HUB_DISCONNECT 仮想 HUB の管理者によって VPN セッションが切断されました。 # (OpenVPN ログ) @@ -1917,7 +1917,7 @@ LH_AUTH_PLAIN_PASSWORD 外部サーバー認証 LH_AUTH_CERT 証明書認証 LH_AUTH_TICKET チケット認証 -LH_AUTH_WIREGUARD_KEY WireGuard public key authentication +LH_AUTH_WIREGUARD_KEY WireGuard 公開鍵認証 LH_AUTH_OPENVPN_CERT OpenVPN 証明書認証 LH_AUTH_RADIUS_NOT_SUPPORT コネクション "%S": ユーザー "%S" の認証方法として RADIUS 認証または Active Directory 認証 (NT ドメイン認証) が指定されましたが、現在の VPN Server のエディションは "%S" であるため、RADIUS 認証または Active Directory 認証 (NT ドメイン認証) を使用することができません。接続は拒否されます。 LH_AUTH_RADIUS_NOT_SUPPORT_ON_OPEN_SOURCE コネクション "%S": ユーザー "%S" の認証方法として RADIUS 認証または Active Directory 認証 (NT ドメイン認証) が指定されましたが、RADIUS 認証または Active Directory 認証 (NT ドメイン認証) を使用することができません。この機能はオープンソース版 SoftEther VPN にはまだ実装されていません。接続は拒否されます。 @@ -4612,9 +4612,9 @@ CMD_ProtoOptions_Description_OpenVPN_DefaultClientOption OpenVPN の OCC codeRT 版以外の場合は、OpenVPN はサーバーに対してオプション文字列を送信しません。OpenVPN サーバーのオリジナル版は、オプションを固定で指定する仕組みになっているため、その場合でも動作します。一方、SoftEther VPN は、様々なオプションを動的に設定することができる機能を有しております。そこで、このオプションを使用することにより、OCC code なしでビルドされた OpenVPN に対してデフォルトの静的オプション文字列を送付することができるようになります。これにより、OCC code なしでビルドされた OpenVPN からの接続が成功するようになります。 CMD_ProtoOptions_Description_OpenVPN_Obfuscation OpenVPN クライアントが検閲用ファイアウォールを回避するための難読化コードを設定します。クライアント側とサーバー側では、同一の XOR マスクを設定する必要があります。コードが異なると、接続ができません。 CMD_ProtoOptions_Description_OpenVPN_ObfuscationMask パケットで使用される XOR マスクを指定します。OpenVPN クライアントが検閲用ファイアウォールを回避するための難読化コードとして使用されます。 -CMD_ProtoOptions_Description_OpenVPN_PingSendInterval Interval in milliseconds between each ping packet transmission. +CMD_ProtoOptions_Description_OpenVPN_PingSendInterval ping パケットを送信する間隔をミリ秒単位で指定します。 CMD_ProtoOptions_Description_OpenVPN_PushDummyIPv4AddressOnL2Mode Linux における特定の状況下では manifests に不具合があります。この不具合により、OpenVPN クライアントは TAP デバイスが UP 状態であるにもかかわらず、切断状態となります。このオプションを使用することにより、VPN サーバーは、ダミーの IPv4 アドレス (RFC7600 で規定) をクライアントに対してプッシュ送信することができるようになります。これにより、TAP アダプタが常に UP 状態になります。 -CMD_ProtoOptions_Description_OpenVPN_Timeout Time in milliseconds after which the session is forcifully interrupted if no packets are received from the client in the meantime. +CMD_ProtoOptions_Description_OpenVPN_Timeout クライアントからパケットを受信しなかった場合に強制的にセッションを切断するまでの時間をミリ秒単位で指定します。 # ServerPasswordSet コマンド @@ -5026,32 +5026,32 @@ # WgkAdd コマンド -CMD_WgkAdd Add a WireGuard key -CMD_WgkAdd_Help This command can be used to add a WireGuard key to the allowed key list. \nTo execute this command, you must have VPN Server administrator privileges. +CMD_WgkAdd WireGuard 公開鍵の追加 +CMD_WgkAdd_Help 新しい WireGuard 公開鍵をサーバーに追加します。\n公開鍵を追加すると、関連付けたユーザーとして仮想 HUB に WireGuard クライアントが接続できるようになります。\nこのコマンドを実行するには、VPN Server の管理者権限が必要です。 CMD_WgkAdd_Args WgkAdd [key] [/HUB:hub] [/USER:user] -CMD_WgkAdd_[key] WireGuard key. Make sure it is the public one! -CMD_WgkAdd_HUB Hub the key will be associated to. -CMD_WgkAdd_USER User the key will be associated to, in the specified hub. -CMD_WgkAdd_Prompt_[key] Key: -CMD_WgkAdd_Prompt_HUB Hub: -CMD_WgkAdd_Prompt_USER User: +CMD_WgkAdd_[key] 新しく追加する WireGuard 公開鍵を指定します。追加しようとしている鍵が公開鍵であることを確認してください。 +CMD_WgkAdd_HUB 公開鍵に関連付ける仮想ハブを指定します。 +CMD_WgkAdd_USER 指定された仮想 HUB 内で公開鍵に関連付けるユーザー名を指定します。 +CMD_WgkAdd_Prompt_[key] 公開鍵: +CMD_WgkAdd_Prompt_HUB 関連付ける仮想 HUB の名前: +CMD_WgkAdd_Prompt_USER ユーザー名: # WgkDelete コマンド -CMD_WgkDelete Delete a WireGuard key -CMD_WgkDelete_Help This command can be used to delete a WireGuard key from the allowed key list. \nTo execute this command, you must have VPN Server administrator privileges. +CMD_WgkDelete WireGuard 公開鍵の削除 +CMD_WgkDelete_Help サーバーに登録された WireGuard 公開鍵を削除します。\n公開鍵を削除すると WireGuard クライアントは仮想 HUB に接続できなくなります。 \nこのコマンドを実行するには、VPN Server の管理者権限が必要です。 CMD_WgkDelete_Args WgkDelete [key] -CMD_WgkDelete_[key] WireGuard key. -CMD_WgkDelete_Prompt_[key] Key: +CMD_WgkDelete_[key] 削除する WireGuard 公開鍵を指定します。 +CMD_WgkDelete_Prompt_[key] 公開鍵: # WgkEnum コマンド -CMD_WgkEnum List the WireGuard keys -CMD_WgkEnum_Help This command retrieves the WireGuard keys that are allowed to connect to the server, along with the associated Virtual Hub and user. \nYou can add a key with the WgkAdd command. \nYou can delete a key with the WgkDelete command. \nTo execute this command, you must have VPN Server administrator privileges. +CMD_WgkEnum Wireguard 公開鍵一覧の取得 +CMD_WgkEnum_Help 現在サーバーに登録されている WireGuard 公開鍵の一覧を取得します。\nWgkAdd コマンドで公開鍵の追加を、WgkDelete コマンドで公開鍵の削除を行うことができます。\nこのコマンドを実行するには、VPN Server の管理者権限が必要です。 CMD_WgkEnum_Args WgkEnum -CMD_WgkEnum_Column_Key Key -CMD_WgkEnum_Column_Hub Hub -CMD_WgkEnum_Column_User User +CMD_WgkEnum_Column_Key 公開鍵 +CMD_WgkEnum_Column_Hub 仮想 HUB 名 +CMD_WgkEnum_Column_User ユーザー名 # HubCreate コマンド @@ -5131,14 +5131,15 @@ CMD_Offline_Args Offline -# SetStaticNetwork command -CMD_SetStaticNetwork Set Virtual Hub static IPv4 network parameters -CMD_SetStaticNetwork_Help Set the static IPv4 network parameters for the Virtual Hub. They are used when DHCP is not available (e.g. WireGuard sessions). \nYou can get the current settings by using the OptionsGet command. +# SetStaticNetwork コマンド +CMD_SetStaticNetwork 仮想 HUB のスタティック IPv4 ネットワークパラメータを設定する + +CMD_SetStaticNetwork_Help 現在管理している仮想 HUB の、スタティック IPv4 パラメータを設定します。これらの設定は DHCP が利用できない場合に使用されます(例: WireGuard セッション)。\n 現在の設定は OptionsGet コマンドで取得することができます。 CMD_SetStaticNetwork_Args SetStaticNetwork [/GATEWAY:gateway] [/SUBNET:subnet] -CMD_SetStaticNetwork_GATEWAY Specify the IP address of the gateway that will be used for internet communication. -CMD_SetStaticNetwork_SUBNET Specify the subnet mask, required to determine the size of the local VPN network. -CMD_SetStaticNetwork_Prompt_GATEWAY Gateway: -CMD_SetStaticNetwork_Prompt_SUBNET Subnet mask: +CMD_SetStaticNetwork_GATEWAY ゲートウェイの IP アドレスを設定します +CMD_SetStaticNetwork_SUBNET ローカル VPN ネットワークの大きさを決定するために必要なサブネットマスクを指定します。 +CMD_SetStaticNetwork_Prompt_GATEWAY ゲートウェイ: +CMD_SetStaticNetwork_Prompt_SUBNET サブネットマスク: # SetMaxSession コマンド @@ -5177,8 +5178,8 @@ CMD_OptionsGet_MAXSESSIONS 最大同時接続セッション数 CMD_OptionsGet_STATUS 状態 CMD_OptionsGet_TYPE 仮想 HUB の種類 -CMD_OptionsGet_GATEWAY Default gateway -CMD_OptionsGet_SUBNET Default subnet +CMD_OptionsGet_GATEWAY デフォルトゲートウェイ +CMD_OptionsGet_SUBNET サブネットマスク # RadiusServerSet コマンド diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Cedar/Protocol.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Cedar/Protocol.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Cedar/Protocol.c 2021-05-25 01:25:09.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Cedar/Protocol.c 2021-10-25 20:43:04.000000000 +0000 @@ -6011,7 +6011,7 @@ if (server->DisableJsonRpcWebApi == false) { - b = ReadDump("|wwwroot\\index.html"); + b = ReadDump("|wwwroot/index.html"); } if (b != NULL) diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Cedar/Proto_PPP.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Cedar/Proto_PPP.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Cedar/Proto_PPP.c 2021-05-25 01:25:09.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Cedar/Proto_PPP.c 2021-10-25 20:43:04.000000000 +0000 @@ -257,7 +257,8 @@ case PPP_EAP_TYPE_TLS: // Sending TLS Start... flags |= PPP_EAP_TLS_FLAG_SSLSTARTED; - lcpEap = BuildEAPTlsRequest(p->Eap_PacketId++, 0, flags); + p->Eap_PacketId = p->NextId++; + lcpEap = BuildEAPTlsRequest(p->Eap_PacketId, 0, flags); PPPSetStatus(p, PPP_STATUS_AUTHENTICATING); if (!PPPSendAndRetransmitRequest(p, PPP_PROTOCOL_EAP, lcpEap)) { @@ -269,7 +270,8 @@ case PPP_EAP_TYPE_IDENTITY: default: // We treat the unspecified protocol as the IDENTITY protocol p->Eap_Protocol = PPP_EAP_TYPE_IDENTITY; - lcpEap = BuildEAPPacketEx(PPP_EAP_CODE_REQUEST, p->Eap_PacketId++, PPP_EAP_TYPE_IDENTITY, StrLen(welcomeMessage) + 1); + p->Eap_PacketId = p->NextId++; + lcpEap = BuildEAPPacketEx(PPP_EAP_CODE_REQUEST, p->Eap_PacketId, PPP_EAP_TYPE_IDENTITY, StrLen(welcomeMessage) + 1); eapPacket = lcpEap->Data; Copy(eapPacket->Data, welcomeMessage, StrLen(welcomeMessage)); PPPSetStatus(p, PPP_STATUS_AUTHENTICATING); @@ -1251,7 +1253,8 @@ eap = req->Lcp->Data; if (eap->Type == PPP_EAP_TYPE_TLS) { - PPP_LCP *lcp = BuildEAPTlsRequest(p->Eap_PacketId++, 0, PPP_EAP_TLS_FLAG_NONE); + p->Eap_PacketId = p->NextId++; + PPP_LCP *lcp = BuildEAPTlsRequest(p->Eap_PacketId, 0, PPP_EAP_TLS_FLAG_NONE); if (!PPPSendAndRetransmitRequest(p, PPP_PROTOCOL_EAP, lcp)) { PPPSetStatus(p, PPP_STATUS_FAIL); @@ -3218,7 +3221,8 @@ dataSize = sizeLeft; flags = PPP_EAP_TLS_FLAG_NONE; // Clearing the M flag because it is the last packet } - lcp = BuildEAPTlsRequest(p->Eap_PacketId++, dataSize, flags); + p->Eap_PacketId = p->NextId++; + lcp = BuildEAPTlsRequest(p->Eap_PacketId, dataSize, flags); eap = lcp->Data; Copy(eap->Tls.TlsDataWithoutLength, p->Eap_TlsCtx.CachedBufferSendPntr, dataSize); p->Eap_TlsCtx.CachedBufferSendPntr += (UINT64)dataSize; @@ -3252,7 +3256,8 @@ /*if (!p->Eap_TlsCtx.SslPipe->IsDisconnected) { dataSize = FifoSize(p->Eap_TlsCtx.SslPipe->RawOut->RecvFifo); - lcp = BuildEAPTlsRequest(p->Eap_PacketId++, dataSize, 0); + p->Eap_PacketId = p->NextId++; + lcp = BuildEAPTlsRequest(p->Eap_PacketId, dataSize, 0); eap = lcp->Data; ReadFifo(p->Eap_TlsCtx.SslPipe->RawOut->RecvFifo, &(eap->Tls.TlsDataWithoutLength), dataSize); if (!PPPSendAndRetransmitRequest(p, PPP_PROTOCOL_EAP, lcp)) @@ -3275,7 +3280,7 @@ if (ipc != NULL) { PPP_PACKET *pack; - UINT identificator = p->Eap_PacketId - 1; // THIS IS A HACK TO SUPPORT VPN Client Pro on Android!!! + UINT identificator = p->Eap_PacketId; p->Ipc = ipc; PPPSetStatus(p, PPP_STATUS_AUTH_SUCCESS); @@ -3298,7 +3303,7 @@ else { PPP_PACKET *pack; - UINT identificator = p->Eap_PacketId - 1; // THIS IS A HACK TO SUPPORT VPN Client Pro on Android!!! + UINT identificator = p->Eap_PacketId; PPPSetStatus(p, PPP_STATUS_AUTH_FAIL); @@ -3321,7 +3326,8 @@ { // Some clients needs a little help it seems - namely VPN Client Pro on Android flags |= PPP_EAP_TLS_FLAG_SSLSTARTED; - lcp = BuildEAPTlsRequest(p->Eap_PacketId++, 0, flags); + p->Eap_PacketId = p->NextId++; + lcp = BuildEAPTlsRequest(p->Eap_PacketId, 0, flags); PPPSetStatus(p, PPP_STATUS_AUTHENTICATING); if (!PPPSendAndRetransmitRequest(p, PPP_PROTOCOL_EAP, lcp)) { @@ -3399,7 +3405,8 @@ // Just acknoweldge that we buffered the fragmented data if (isFragmented) { - PPP_LCP *lcp = BuildEAPPacketEx(PPP_EAP_CODE_REQUEST, p->Eap_PacketId++, PPP_EAP_TYPE_TLS, 0); + p->Eap_PacketId = p->NextId++; + PPP_LCP *lcp = BuildEAPTlsRequest(p->Eap_PacketId, 0, PPP_EAP_TLS_FLAG_NONE); if (!PPPSendAndRetransmitRequest(p, PPP_PROTOCOL_EAP, lcp)) { PPPSetStatus(p, PPP_STATUS_FAIL); @@ -3445,7 +3452,8 @@ dataSize = p->Mru1 - 8 - 1 - 1 - 4; // Calculating the maximum payload size (adjusting for including TlsLength) flags = PPP_EAP_TLS_FLAG_TLS_LENGTH; // L flag flags |= PPP_EAP_TLS_FLAG_FRAGMENTED; // M flag - lcp = BuildEAPTlsRequest(p->Eap_PacketId++, dataSize, flags); + p->Eap_PacketId = p->NextId++; + lcp = BuildEAPTlsRequest(p->Eap_PacketId, dataSize, flags); eap = lcp->Data; eap->Tls.TlsDataWithLength.TlsLength = Endian32(tlsLength); Copy(eap->Tls.TlsDataWithLength.Data, p->Eap_TlsCtx.CachedBufferSend, dataSize); @@ -3460,7 +3468,8 @@ } else { - lcp = BuildEAPTlsRequest(p->Eap_PacketId++, dataSize, 0); + p->Eap_PacketId = p->NextId++; + lcp = BuildEAPTlsRequest(p->Eap_PacketId, dataSize, 0); eap = lcp->Data; ReadFifo(p->Eap_TlsCtx.SslPipe->RawOut->RecvFifo, &(eap->Tls.TlsDataWithoutLength), dataSize); if (!PPPSendAndRetransmitRequest(p, PPP_PROTOCOL_EAP, lcp)) diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/GlobalConst.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/GlobalConst.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/GlobalConst.h 2021-05-25 01:25:09.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/GlobalConst.h 2021-10-25 20:43:04.000000000 +0000 @@ -64,9 +64,4 @@ #define GC_UI_APPID_CM L"SoftEther.SoftEther VPN Client Developer Edition" -//// Hamcore - -#define HAMCORE_HEADER_DATA "HamCore" -#define HAMCORE_HEADER_SIZE 7 - #endif // GLOBAL_CONST_H diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/CMakeLists.txt softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/CMakeLists.txt --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/CMakeLists.txt 2021-05-25 01:25:28.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/CMakeLists.txt 2021-10-25 20:43:29.000000000 +0000 @@ -8,6 +8,8 @@ add_library(libhamcore STATIC) +set_property(TARGET libhamcore PROPERTY POSITION_INDEPENDENT_CODE ON) + test_big_endian(BIG_ENDIAN) if(BIG_ENDIAN) target_compile_definitions(libhamcore PRIVATE "BYTE_ORDER_BIG_ENDIAN") @@ -19,7 +21,7 @@ target_compile_definitions(libhamcore PRIVATE "_CRT_SECURE_NO_WARNINGS") endif() -target_include_directories(libhamcore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(libhamcore PUBLIC "include") target_sources(libhamcore PRIVATE @@ -29,7 +31,7 @@ Memory.c Memory.h PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/Hamcore.h + "${CMAKE_CURRENT_SOURCE_DIR}/include/Hamcore.h" ) find_package(ZLIB REQUIRED) diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/FileSystem.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/FileSystem.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/FileSystem.c 2021-05-25 01:25:28.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/FileSystem.c 2021-10-25 20:43:29.000000000 +0000 @@ -4,7 +4,7 @@ #include -FILE *FileOpen(const char *path, const bool write) +FILE *Ham_FileOpen(const char *path, const bool write) { if (!path) { @@ -14,7 +14,7 @@ return fopen(path, write ? "wb" : "rb"); } -bool FileClose(FILE *file) +bool Ham_FileClose(FILE *file) { if (!file) { @@ -24,7 +24,7 @@ return fclose(file) == 0; } -bool FileRead(FILE *file, void *dst, const size_t size) +bool Ham_FileRead(FILE *file, void *dst, const size_t size) { if (!file || !dst || size == 0) { @@ -34,7 +34,7 @@ return fread(dst, 1, size, file) == size; } -bool FileWrite(FILE *file, const void *src, const size_t size) +bool Ham_FileWrite(FILE *file, const void *src, const size_t size) { if (!file || !src || size == 0) { @@ -44,7 +44,7 @@ return fwrite(src, 1, size, file) == size; } -bool FileSeek(FILE *file, const size_t offset) +bool Ham_FileSeek(FILE *file, const size_t offset) { if (!file) { @@ -54,7 +54,7 @@ return fseek(file, (long)offset, SEEK_SET) == 0; } -size_t FileSize(const char *path) +size_t Ham_FileSize(const char *path) { if (!path) { @@ -70,7 +70,7 @@ return st.st_size; } -const char *PathRelativeToBase(const char *full, const char *base) +const char *Ham_PathRelativeToBase(const char *full, const char *base) { if (!full || !base) { diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/FileSystem.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/FileSystem.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/FileSystem.h 2021-05-25 01:25:28.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/FileSystem.h 2021-10-25 20:43:29.000000000 +0000 @@ -4,16 +4,16 @@ #include #include -FILE *FileOpen(const char *path, const bool write); -bool FileClose(FILE *file); +FILE *Ham_FileOpen(const char *path, const bool write); +bool Ham_FileClose(FILE *file); -bool FileRead(FILE *file, void *dst, const size_t size); -bool FileWrite(FILE *file, const void *src, const size_t size); +bool Ham_FileRead(FILE *file, void *dst, const size_t size); +bool Ham_FileWrite(FILE *file, const void *src, const size_t size); -bool FileSeek(FILE *file, const size_t offset); +bool Ham_FileSeek(FILE *file, const size_t offset); -size_t FileSize(const char *path); +size_t Ham_FileSize(const char *path); -const char *PathRelativeToBase(const char *full, const char *base); +const char *Ham_PathRelativeToBase(const char *full, const char *base); #endif diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/Hamcore.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/Hamcore.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/Hamcore.c 2021-05-25 01:25:28.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/Hamcore.c 2021-10-25 20:43:29.000000000 +0000 @@ -28,7 +28,7 @@ } memset(hamcore, 0, sizeof(HAMCORE)); - hamcore->File = FileOpen(path, false); + hamcore->File = Ham_FileOpen(path, false); if (!hamcore->File) { free(hamcore); @@ -38,7 +38,7 @@ bool ok = false; uint8_t header[HAMCORE_HEADER_SIZE]; - if (!FileRead(hamcore->File, header, sizeof(header))) + if (!Ham_FileRead(hamcore->File, header, sizeof(header))) { goto FINAL; } @@ -49,7 +49,7 @@ } uint32_t tmp; - if (!FileRead(hamcore->File, &tmp, sizeof(tmp))) + if (!Ham_FileRead(hamcore->File, &tmp, sizeof(tmp))) { goto FINAL; } @@ -66,7 +66,7 @@ for (size_t i = 0; i < files->Num; ++i) { - if (!FileRead(hamcore->File, &tmp, sizeof(tmp))) + if (!Ham_FileRead(hamcore->File, &tmp, sizeof(tmp))) { goto FINAL; } @@ -81,26 +81,26 @@ --tmp; } - if (!FileRead(hamcore->File, file->Path, tmp)) + if (!Ham_FileRead(hamcore->File, file->Path, tmp)) { goto FINAL; } - if (!FileRead(hamcore->File, &tmp, sizeof(tmp))) + if (!Ham_FileRead(hamcore->File, &tmp, sizeof(tmp))) { goto FINAL; } file->OriginalSize = BigEndian32(tmp); - if (!FileRead(hamcore->File, &tmp, sizeof(tmp))) + if (!Ham_FileRead(hamcore->File, &tmp, sizeof(tmp))) { goto FINAL; } file->Size = BigEndian32(tmp); - if (!FileRead(hamcore->File, &tmp, sizeof(tmp))) + if (!Ham_FileRead(hamcore->File, &tmp, sizeof(tmp))) { goto FINAL; } @@ -126,7 +126,7 @@ return; } - FileClose(hamcore->File); + Ham_FileClose(hamcore->File); HAMCORE_FILES *files = &hamcore->Files; if (!files->List) @@ -175,7 +175,7 @@ return false; } - if (!FileSeek(hamcore->File, hamcore_file->Offset)) + if (!Ham_FileSeek(hamcore->File, hamcore_file->Offset)) { return false; } @@ -183,7 +183,7 @@ bool ok = false; void *buf = malloc(hamcore_file->Size); - if (!FileRead(hamcore->File, buf, hamcore_file->Size)) + if (!Ham_FileRead(hamcore->File, buf, hamcore_file->Size)) { goto FINAL; } @@ -229,7 +229,7 @@ continue; } - FILE *handle = FileOpen(path, false); + FILE *handle = Ham_FileOpen(path, false); if (!handle) { fprintf(stderr, "HamcoreBuild(): Failed to open \"%s\", skipping...\n", path); @@ -239,10 +239,10 @@ COMPRESSED_FILE *compressed_file = &compressed_files[i]; HAMCORE_FILE *file = &compressed_file->File; - file->OriginalSize = FileSize(path); + file->OriginalSize = Ham_FileSize(path); void *content = malloc(file->OriginalSize); - int ret = FileRead(handle, content, file->OriginalSize); - FileClose(handle); + int ret = Ham_FileRead(handle, content, file->OriginalSize); + Ham_FileClose(handle); if (!ret) { @@ -271,7 +271,7 @@ continue; } - const char *relative_path = base_path ? PathRelativeToBase(path, base_path) : path; + const char *relative_path = base_path ? Ham_PathRelativeToBase(path, base_path) : path; if (!relative_path) { fprintf(stderr, "HamcoreBuild(): Failed to get relative path for \"%s\", skipping...\n", path); @@ -343,9 +343,9 @@ } void *ptr = buffer; - WriteAndSeek(&ptr, HAMCORE_HEADER_DATA, HAMCORE_HEADER_SIZE); + Ham_WriteAndSeek(&ptr, HAMCORE_HEADER_DATA, HAMCORE_HEADER_SIZE); uint32_t tmp = BigEndian32((uint32_t)num); - WriteAndSeek(&ptr, &tmp, sizeof(tmp)); + Ham_WriteAndSeek(&ptr, &tmp, sizeof(tmp)); for (size_t i = 0; i < num; ++i) { @@ -357,24 +357,24 @@ const size_t path_length = strlen(file->Path); tmp = BigEndian32((uint32_t)path_length + 1); - WriteAndSeek(&ptr, &tmp, sizeof(tmp)); - WriteAndSeek(&ptr, file->Path, path_length); + Ham_WriteAndSeek(&ptr, &tmp, sizeof(tmp)); + Ham_WriteAndSeek(&ptr, file->Path, path_length); free(file->Path); tmp = BigEndian32((uint32_t)file->OriginalSize); - WriteAndSeek(&ptr, &tmp, sizeof(tmp)); + Ham_WriteAndSeek(&ptr, &tmp, sizeof(tmp)); tmp = BigEndian32((uint32_t)file->Size); - WriteAndSeek(&ptr, &tmp, sizeof(tmp)); + Ham_WriteAndSeek(&ptr, &tmp, sizeof(tmp)); tmp = BigEndian32((uint32_t)file->Offset); - WriteAndSeek(&ptr, &tmp, sizeof(tmp)); + Ham_WriteAndSeek(&ptr, &tmp, sizeof(tmp)); } for (size_t i = 0; i < num; ++i) { COMPRESSED_FILE *compressed_file = &compressed_files[i]; - WriteAndSeek(&ptr, compressed_file->Data, compressed_file->File.Size); + Ham_WriteAndSeek(&ptr, compressed_file->Data, compressed_file->File.Size); free(compressed_file->Data); } @@ -382,14 +382,14 @@ bool ok = false; - FILE *handle = FileOpen(dst_path, true); + FILE *handle = Ham_FileOpen(dst_path, true); if (!handle) { fprintf(stderr, "HamcoreBuild(): Failed to open \"%s\"!\n", dst_path); goto FINAL; } - if (!FileWrite(handle, buffer, buffer_size)) + if (!Ham_FileWrite(handle, buffer, buffer_size)) { fprintf(stderr, "HamcoreBuild(): Failed to write \"%s\"!\n", dst_path); goto FINAL; @@ -397,7 +397,7 @@ ok = true; FINAL: - FileClose(handle); + Ham_FileClose(handle); free(buffer); return ok; } diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/Hamcore.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/Hamcore.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/Hamcore.h 2021-05-25 01:25:28.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/Hamcore.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,39 +0,0 @@ -#ifndef HAMCORE_H -#define HAMCORE_H - -#include -#include -#include - -#define HAMCORE_HEADER_DATA "HamCore" -#define HAMCORE_HEADER_SIZE 7 - -typedef struct HAMCORE_FILE -{ - char *Path; - size_t Offset; - size_t Size; - size_t OriginalSize; -} HAMCORE_FILE; - -typedef struct HAMCORE_FILES -{ - size_t Num; - HAMCORE_FILE *List; -} HAMCORE_FILES; - -typedef struct HAMCORE -{ - FILE *File; - HAMCORE_FILES Files; -} HAMCORE; - -HAMCORE *HamcoreOpen(const char *path); -void HamcoreClose(HAMCORE *hamcore); - -const HAMCORE_FILE *HamcoreFind(const HAMCORE *hamcore, const char *path); -bool HamcoreRead(HAMCORE *hamcore, void *dst, const HAMCORE_FILE *file); - -bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_paths, const size_t num); - -#endif diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/include/Hamcore.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/include/Hamcore.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/include/Hamcore.h 1970-01-01 00:00:00.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/include/Hamcore.h 2021-10-25 20:43:29.000000000 +0000 @@ -0,0 +1,39 @@ +#ifndef HAMCORE_H +#define HAMCORE_H + +#include +#include +#include + +#define HAMCORE_HEADER_DATA "HamCore" +#define HAMCORE_HEADER_SIZE 7 + +typedef struct HAMCORE_FILE +{ + char *Path; + size_t Offset; + size_t Size; + size_t OriginalSize; +} HAMCORE_FILE; + +typedef struct HAMCORE_FILES +{ + size_t Num; + HAMCORE_FILE *List; +} HAMCORE_FILES; + +typedef struct HAMCORE +{ + FILE *File; + HAMCORE_FILES Files; +} HAMCORE; + +HAMCORE *HamcoreOpen(const char *path); +void HamcoreClose(HAMCORE *hamcore); + +const HAMCORE_FILE *HamcoreFind(const HAMCORE *hamcore, const char *path); +bool HamcoreRead(HAMCORE *hamcore, void *dst, const HAMCORE_FILE *file); + +bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_paths, const size_t num); + +#endif diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/Memory.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/Memory.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/Memory.c 2021-05-25 01:25:28.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/Memory.c 2021-10-25 20:43:29.000000000 +0000 @@ -2,9 +2,7 @@ #include -size_t CompressionBufferSize(const size_t original_size) { return original_size * 2 + 256; } - -uint32_t Swap32(const uint32_t value) +uint32_t Ham_Swap32(const uint32_t value) { uint32_t swapped; ((uint8_t *)&swapped)[0] = ((uint8_t *)&value)[3]; @@ -14,7 +12,7 @@ return swapped; } -void WriteAndSeek(void **dst, const void *src, const size_t size) +void Ham_WriteAndSeek(void **dst, const void *src, const size_t size) { if (!dst || !*dst) { diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/Memory.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/Memory.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/libhamcore/Memory.h 2021-05-25 01:25:28.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/libhamcore/Memory.h 2021-10-25 20:43:29.000000000 +0000 @@ -7,13 +7,13 @@ #ifdef BYTE_ORDER_BIG_ENDIAN #define BigEndian32 #else -#define BigEndian32 Swap32 +#define BigEndian32 Ham_Swap32 #endif -size_t CompressionBufferSize(const size_t original_size); +#define CompressionBufferSize(original_size) (original_size * 2 + 256) -uint32_t Swap32(const uint32_t value); +uint32_t Ham_Swap32(const uint32_t value); -void WriteAndSeek(void **dst, const void *src, const size_t size); +void Ham_WriteAndSeek(void **dst, const void *src, const size_t size); #endif diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/ci/vagrant/freebsd/Vagrantfile softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/ci/vagrant/freebsd/Vagrantfile --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/ci/vagrant/freebsd/Vagrantfile 1970-01-01 00:00:00.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/ci/vagrant/freebsd/Vagrantfile 2021-10-25 20:43:15.000000000 +0000 @@ -0,0 +1,102 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://vagrantcloud.com/search. + config.vm.guest = :freebsd + config.vm.box = "generic/freebsd12" + + config.ssh.shell = "sh" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # NOTE: This will enable public access to the opened port + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine and only allow access + # via 127.0.0.1 to disable public access + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + #config.vm.synced_folder "../../..", "/home/vagrant/project" + config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true + + config.vm.provision "file", source: "../../../CMakeLists.txt", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../cmake", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../include", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../src", destination: "$HOME/project/" + config.vm.provision "file", source: "../../../test", destination: "$HOME/project/" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + # vb.memory = "1024" + # end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Enable provisioning with a shell script. Additional provisioners such as + # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the + # documentation for more information about their specific syntax and use. + # note: clang installed by default + config.vm.provision "env", type: "shell", inline:<<-SHELL + set -x + pkg update -f + pkg install -y git cmake + SHELL + config.vm.provision "devel", type: "shell", inline:<<-SHELL + set -x + cd project + ls + SHELL + config.vm.provision "configure", type: "shell", inline:<<-SHELL + set -x + cd project + cmake -S. -Bbuild -DBUILD_TESTING=ON + SHELL + config.vm.provision "build", type: "shell", inline:<<-SHELL + set -x + cd project + cmake --build build -v + SHELL + config.vm.provision "test", type: "shell", inline:<<-SHELL + set -x + cd project + cmake --build build --target test -v + SHELL +end diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/cmake/README.md softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/cmake/README.md --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/cmake/README.md 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/cmake/README.md 2021-10-25 20:43:15.000000000 +0000 @@ -20,9 +20,9 @@ 3- Add the `cpu_features` target to the `target_link_libraries()` section of your executable or of your library. -## Enabling tests +## Disabling tests CMake default options for cpu_features is Release built type with tests - disabled. To enable testing set cmake `BUILD_TESTING` variable to `ON`, + enabled. To disable testing set cmake `BUILD_TESTING` variable to `OFF`, [.travis.yml](../.travis.yml) and [appveyor.yml](../appveyor.yml) have up to date examples. diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/CMakeLists.txt softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/CMakeLists.txt --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/CMakeLists.txt 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/CMakeLists.txt 2021-10-25 20:43:15.000000000 +0000 @@ -17,22 +17,17 @@ FORCE) endif(NOT CMAKE_BUILD_TYPE) -# BUILD_TESTING is a standard CMake variable, but we declare it here to make it -# prominent in the GUI. -option(BUILD_TESTING "Enable test (depends on googletest)." OFF) # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make # it prominent in the GUI. # cpu_features uses bit-fields which are - to some extends - implementation-defined (see https://en.cppreference.com/w/c/language/bit_field). # As a consequence it is discouraged to use cpu_features as a shared library because different compilers may interpret the code in different ways. # Prefer static linking from source whenever possible. option(BUILD_SHARED_LIBS "Build library as shared." OFF) -# PIC -option(BUILD_PIC "Build with Position Independant Code." OFF) # Default is off at least for GCC # Force PIC on unix when building shared libs # see: https://en.wikipedia.org/wiki/Position-independent_code if(BUILD_SHARED_LIBS AND UNIX) - set(BUILD_PIC ON) + option(CMAKE_POSITION_INDEPENDENT_CODE "Build with Position Independant Code." ON) endif() include(CheckIncludeFile) @@ -104,7 +99,6 @@ ${PROJECT_SOURCE_DIR}/src/stack_line_reader.c ${PROJECT_SOURCE_DIR}/src/string_view.c ) -set_property(TARGET utils PROPERTY POSITION_INDEPENDENT_CODE ${BUILD_PIC}) setup_include_and_definitions(utils) # @@ -125,7 +119,6 @@ if(HAVE_STRONG_GETAUXVAL) target_compile_definitions(unix_based_hardware_detection PRIVATE HAVE_STRONG_GETAUXVAL) endif() - set_property(TARGET unix_based_hardware_detection PROPERTY POSITION_INDEPENDENT_CODE ${BUILD_PIC}) endif() # @@ -142,7 +135,6 @@ set_target_properties(cpu_features PROPERTIES PUBLIC_HEADER "${CPU_FEATURES_HDRS}") setup_include_and_definitions(cpu_features) target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS}) -set_property(TARGET cpu_features PROPERTY POSITION_INDEPENDENT_CODE ${BUILD_PIC}) target_include_directories(cpu_features PUBLIC $ ) @@ -233,6 +225,7 @@ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR} ) install(EXPORT CpuFeaturesTargets NAMESPACE CpuFeatures:: diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/.github/workflows/freebsd.yml softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/.github/workflows/freebsd.yml --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/.github/workflows/freebsd.yml 1970-01-01 00:00:00.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/.github/workflows/freebsd.yml 2021-10-25 20:43:15.000000000 +0000 @@ -0,0 +1,22 @@ +name: FreeBSD + +on: + push: + pull_request: + schedule: + # min hours day(month) month day(week) + - cron: '0 0 7,22 * *' + +jobs: + # Only MacOS hosted runner provides virtualisation with vagrant/virtualbox installed. + # see: https://github.com/actions/virtual-environments/tree/main/images/macos + freebsd: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - name: vagrant version + run: Vagrant --version + - name: VirtualBox version + run: virtualbox -h + - name: Build + run: cd ci/vagrant/freebsd && vagrant up diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpu_features_macros.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpu_features_macros.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpu_features_macros.h 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpu_features_macros.h 2021-10-25 20:43:15.000000000 +0000 @@ -83,6 +83,10 @@ #define CPU_FEATURES_OS_DARWIN #endif +#if (defined(__freebsd__) || defined(__FreeBSD__)) +#define CPU_FEATURES_OS_FREEBSD +#endif + //////////////////////////////////////////////////////////////////////////////// // Compilers //////////////////////////////////////////////////////////////////////////////// @@ -213,4 +217,17 @@ #endif // defined(__mips_msa) #endif // defined(CPU_FEATURES_ARCH_MIPS) +//////////////////////////////////////////////////////////////////////////////// +// Utils +//////////////////////////////////////////////////////////////////////////////// + +// Communicates to the compiler that the block is unreachable +#if defined(CPU_FEATURES_COMPILER_CLANG) || defined(CPU_FEATURES_COMPILER_GCC) +#define UNREACHABLE() __builtin_unreachable() +#elif defined(CPU_FEATURES_COMPILER_MSC) +#define UNREACHABLE() __assume(0) +#else +#define UNREACHABLE() +#endif + #endif // CPU_FEATURES_INCLUDE_CPU_FEATURES_MACROS_H_ diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpuinfo_ppc.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpuinfo_ppc.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpuinfo_ppc.h 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpuinfo_ppc.h 2021-10-25 20:43:15.000000000 +0000 @@ -17,7 +17,6 @@ #include "cpu_features_cache_info.h" #include "cpu_features_macros.h" -#include "internal/hwcaps.h" CPU_FEATURES_START_CPP_NAMESPACE @@ -75,11 +74,16 @@ PPCInfo GetPPCInfo(void); typedef struct { + char platform[64]; // 0 terminated string + char base_platform[64]; // 0 terminated string +} PPCPlatformTypeStrings; + +typedef struct { char platform[64]; // 0 terminated string char model[64]; // 0 terminated string char machine[64]; // 0 terminated string char cpu[64]; // 0 terminated string - PlatformType type; + PPCPlatformTypeStrings type; } PPCPlatformStrings; PPCPlatformStrings GetPPCPlatformStrings(void); diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpuinfo_x86.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpuinfo_x86.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpuinfo_x86.h 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/cpuinfo_x86.h 2021-10-25 20:43:15.000000000 +0000 @@ -21,6 +21,11 @@ CPU_FEATURES_START_CPP_NAMESPACE +// CPUID Vendors +#define CPU_FEATURES_VENDOR_GENUINE_INTEL "GenuineIntel" +#define CPU_FEATURES_VENDOR_AUTHENTIC_AMD "AuthenticAMD" +#define CPU_FEATURES_VENDOR_HYGON_GENUINE "HygonGenuine" + // See https://en.wikipedia.org/wiki/CPUID for a list of x86 cpu features. // The field names are based on the short name provided in the wikipedia tables. typedef struct { @@ -113,32 +118,40 @@ typedef enum { X86_UNKNOWN, - INTEL_CORE, // CORE - INTEL_PNR, // PENRYN - INTEL_NHM, // NEHALEM - INTEL_ATOM_BNL, // BONNELL - INTEL_WSM, // WESTMERE - INTEL_SNB, // SANDYBRIDGE - INTEL_IVB, // IVYBRIDGE - INTEL_ATOM_SMT, // SILVERMONT - INTEL_HSW, // HASWELL - INTEL_BDW, // BROADWELL - INTEL_SKL, // SKYLAKE - INTEL_ATOM_GMT, // GOLDMONT - INTEL_KBL, // KABY LAKE - INTEL_CFL, // COFFEE LAKE - INTEL_WHL, // WHISKEY LAKE - INTEL_CNL, // CANNON LAKE - INTEL_ICL, // ICE LAKE - INTEL_TGL, // TIGER LAKE - INTEL_SPR, // SAPPHIRE RAPIDS - AMD_HAMMER, // K8 - AMD_K10, // K10 - AMD_BOBCAT, // K14 - AMD_BULLDOZER, // K15 - AMD_JAGUAR, // K16 - AMD_ZEN, // K17 - AMD_ZEN3, // K19 + INTEL_CORE, // CORE + INTEL_PNR, // PENRYN + INTEL_NHM, // NEHALEM + INTEL_ATOM_BNL, // BONNELL + INTEL_WSM, // WESTMERE + INTEL_SNB, // SANDYBRIDGE + INTEL_IVB, // IVYBRIDGE + INTEL_ATOM_SMT, // SILVERMONT + INTEL_HSW, // HASWELL + INTEL_BDW, // BROADWELL + INTEL_SKL, // SKYLAKE + INTEL_ATOM_GMT, // GOLDMONT + INTEL_KBL, // KABY LAKE + INTEL_CFL, // COFFEE LAKE + INTEL_WHL, // WHISKEY LAKE + INTEL_CNL, // CANNON LAKE + INTEL_ICL, // ICE LAKE + INTEL_TGL, // TIGER LAKE + INTEL_SPR, // SAPPHIRE RAPIDS + AMD_HAMMER, // K8 HAMMER + AMD_K10, // K10 + AMD_K11, // K11 + AMD_K12, // K12 + AMD_BOBCAT, // K14 BOBCAT + AMD_PILEDRIVER, // K15 PILEDRIVER + AMD_STREAMROLLER, // K15 STREAMROLLER + AMD_EXCAVATOR, // K15 EXCAVATOR + AMD_BULLDOZER, // K15 BULLDOZER + AMD_JAGUAR, // K16 JAGUAR + AMD_PUMA, // K16 PUMA + AMD_ZEN, // K17 ZEN + AMD_ZEN_PLUS, // K17 ZEN+ + AMD_ZEN2, // K17 ZEN 2 + AMD_ZEN3, // K19 ZEN 3 } X86Microarchitecture; // Returns the underlying microarchitecture by looking at X86Info's vendor, diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/internal/hwcaps.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/internal/hwcaps.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/internal/hwcaps.h 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/internal/hwcaps.h 2021-10-25 20:43:15.000000000 +0000 @@ -171,16 +171,19 @@ unsigned long hwcaps2; } HardwareCapabilities; +// Retrieves values from auxiliary vector for types AT_HWCAP and AT_HWCAP2. +// First tries to call getauxval(), if not available falls back to reading +// "/proc/self/auxv". HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void); + +// Checks whether value for AT_HWCAP (or AT_HWCAP2) match hwcaps_mask. bool CpuFeatures_IsHwCapsSet(const HardwareCapabilities hwcaps_mask, const HardwareCapabilities hwcaps); -typedef struct { - char platform[64]; // 0 terminated string - char base_platform[64]; // 0 terminated string -} PlatformType; - -PlatformType CpuFeatures_GetPlatformType(void); +// Get pointer for the AT_PLATFORM type. +const char* CpuFeatures_GetPlatformPointer(void); +// Get pointer for the AT_BASE_PLATFORM type. +const char* CpuFeatures_GetBasePlatformPointer(void); CPU_FEATURES_END_CPP_NAMESPACE diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/internal/string_view.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/internal/string_view.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/internal/string_view.h 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/include/internal/string_view.h 2021-10-25 20:43:15.000000000 +0000 @@ -96,7 +96,8 @@ // Checks if line contains the specified whitespace separated word. bool CpuFeatures_StringView_HasWord(const StringView line, - const char* const word); + const char* const word, + const char separator); // Get key/value from line. key and value are separated by ": ". // key and value are cleaned up from leading and trailing whitespaces. diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/README.md softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/README.md --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/README.md 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/README.md 2021-10-25 20:43:15.000000000 +0000 @@ -12,6 +12,7 @@ - [Android NDK's drop in replacement](#ndk) - [License](#license) - [Build with cmake](#cmake) +- [Community Bindings](#bindings) ## Design Rationale @@ -141,13 +142,14 @@ ## What's supported -| | x86³ | ARM | AArch64 | MIPS⁴ | POWER | -|---------|:----:|:-------:|:-------:|:------:|:-------:| -| Android | yes² | yes¹ | yes¹ | yes¹ | N/A | -| iOS | N/A | not yet | not yet | N/A | N/A | -| Linux | yes² | yes¹ | yes¹ | yes¹ | yes¹ | -| MacOs | yes² | N/A | not yet | N/A | no | -| Windows | yes² | not yet | not yet | N/A | N/A | +| | x86³ | ARM | AArch64 | MIPS⁴ | POWER | +|---------|:----:|:-------:|:-------:|:-------:|:-------:| +| Android | yes² | yes¹ | yes¹ | yes¹ | N/A | +| iOS | N/A | not yet | not yet | N/A | N/A | +| Linux | yes² | yes¹ | yes¹ | yes¹ | yes¹ | +| MacOs | yes² | N/A | not yet | N/A | no | +| Windows | yes² | not yet | not yet | N/A | N/A | +| FreeBSD | yes² | not yet | not yet | not yet | not yet | 1. **Features revealed from Linux.** We gather data from several sources depending on availability: @@ -197,3 +199,16 @@ ninja -C/tmp/cpu_features ninja -C/tmp/cpu_features test ``` + + +## Community bindings + +Links provided here are not affiliated with Google but are kindly provided by the OSS Community. + + - .Net + - https://github.com/toor1245/cpu_features.NET + - Python + - https://github.com/Narasimha1997/py_cpu + + +_Send PR to showcase your wrapper here_ diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_aarch64.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_aarch64.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_aarch64.c 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_aarch64.c 2021-10-25 20:43:15.000000000 +0000 @@ -87,8 +87,8 @@ if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) { if (CpuFeatures_StringView_IsEquals(key, str("Features"))) { for (size_t i = 0; i < AARCH64_LAST_; ++i) { - kSetters[i](&info->features, - CpuFeatures_StringView_HasWord(value, kCpuInfoFlags[i])); + kSetters[i](&info->features, CpuFeatures_StringView_HasWord( + value, kCpuInfoFlags[i], ' ')); } } else if (CpuFeatures_StringView_IsEquals(key, str("CPU implementer"))) { info->implementer = CpuFeatures_StringView_ParsePositiveNumber(value); diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_arm.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_arm.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_arm.c 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_arm.c 2021-10-25 20:43:15.000000000 +0000 @@ -77,8 +77,8 @@ if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) { if (CpuFeatures_StringView_IsEquals(key, str("Features"))) { for (size_t i = 0; i < ARM_LAST_; ++i) { - kSetters[i](&info->features, - CpuFeatures_StringView_HasWord(value, kCpuInfoFlags[i])); + kSetters[i](&info->features, CpuFeatures_StringView_HasWord( + value, kCpuInfoFlags[i], ' ')); } } else if (CpuFeatures_StringView_IsEquals(key, str("CPU implementer"))) { info->implementer = CpuFeatures_StringView_ParsePositiveNumber(value); diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_mips.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_mips.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_mips.c 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_mips.c 2021-10-25 20:43:15.000000000 +0000 @@ -37,8 +37,8 @@ if (CpuFeatures_StringView_GetAttributeKeyValue(result.line, &key, &value)) { if (CpuFeatures_StringView_IsEquals(key, str("ASEs implemented"))) { for (size_t i = 0; i < MIPS_LAST_; ++i) { - kSetters[i](features, - CpuFeatures_StringView_HasWord(value, kCpuInfoFlags[i])); + kSetters[i](features, CpuFeatures_StringView_HasWord( + value, kCpuInfoFlags[i], ' ')); } } } diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_ppc.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_ppc.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_ppc.c 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_ppc.c 2021-10-25 20:43:15.000000000 +0000 @@ -20,6 +20,7 @@ #include "internal/bit_utils.h" #include "internal/filesystem.h" +#include "internal/hwcaps.h" #include "internal/stack_line_reader.h" #include "internal/string_view.h" @@ -81,7 +82,7 @@ StringView line = result.line; StringView key, value; if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) { - if (CpuFeatures_StringView_HasWord(key, "platform")) { + if (CpuFeatures_StringView_HasWord(key, "platform", ' ')) { CpuFeatures_StringView_CopyString(value, strings->platform, sizeof(strings->platform)); } else if (CpuFeatures_StringView_IsEquals(key, str("model"))) { @@ -133,9 +134,19 @@ PPCPlatformStrings GetPPCPlatformStrings(void) { PPCPlatformStrings strings = kEmptyPPCPlatformStrings; + const char* platform = CpuFeatures_GetPlatformPointer(); + const char* base_platform = CpuFeatures_GetBasePlatformPointer(); FillProcCpuInfoData(&strings); - strings.type = CpuFeatures_GetPlatformType(); + + if (platform != NULL) + CpuFeatures_StringView_CopyString(str(platform), strings.type.platform, + sizeof(strings.type.platform)); + if (base_platform != NULL) + CpuFeatures_StringView_CopyString(str(base_platform), + strings.type.base_platform, + sizeof(strings.type.base_platform)); + return strings; } diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_x86.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_x86.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_x86.c 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/cpuinfo_x86.c 2021-10-25 20:43:15.000000000 +0000 @@ -98,10 +98,10 @@ // microarchitectures. #if defined(CPU_FEATURES_OS_WINDOWS) #include // IsProcessorFeaturePresent -#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) +#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) || \ + defined(CPU_FEATURES_OS_FREEBSD) #include "internal/filesystem.h" // Needed to parse /proc/cpuinfo #include "internal/stack_line_reader.h" // Needed to parse /proc/cpuinfo -#include "internal/string_view.h" // Needed to parse /proc/cpuinfo #elif defined(CPU_FEATURES_OS_DARWIN) #if !defined(HAVE_SYSCTLBYNAME) #error "Darwin needs support for sysctlbyname" @@ -111,6 +111,8 @@ #error "Unsupported OS" #endif // CPU_FEATURES_OS +#include "internal/string_view.h" + //////////////////////////////////////////////////////////////////////////////// // Definitions for CpuId and GetXCR0Eax. //////////////////////////////////////////////////////////////////////////////// @@ -255,6 +257,10 @@ return leaf.ebx == ebx && leaf.ecx == ecx && leaf.edx == edx; } +static int IsVendorByX86Info(const X86Info* info, const char* const name) { + return memcmp(info->vendor, name, sizeof(info->vendor)) == 0; +} + static const CacheLevelInfo kEmptyCacheLevelInfo; static CacheLevelInfo GetCacheLevelInfo(const uint32_t reg) { @@ -1115,52 +1121,54 @@ } } -static void GetByteArrayFromRegister(uint32_t result[4], const uint32_t reg) { - for (int i = 0; i < 4; ++i) { - result[i] = ExtractBitRange(reg, (i + 1) * 8, i * 8); - } -} - +// From https://www.felixcloutier.com/x86/cpuid#tbl-3-12 static void ParseLeaf2(const int max_cpuid_leaf, CacheInfo* info) { Leaf leaf = SafeCpuId(max_cpuid_leaf, 2); - uint32_t registers[] = {leaf.eax, leaf.ebx, leaf.ecx, leaf.edx}; - for (int i = 0; i < 4; ++i) { - if (registers[i] & (1U << 31)) { - continue; // register does not contains valid information - } - uint32_t bytes[4]; - GetByteArrayFromRegister(bytes, registers[i]); - for (int j = 0; j < 4; ++j) { - if (bytes[j] == 0xFF) - break; // leaf 4 should be used to fetch cache information - info->levels[info->size] = GetCacheLevelInfo(bytes[j]); - } + // The least-significant byte in register EAX (register AL) will always return + // 01H. Software should ignore this value and not interpret it as an + // informational descriptor. + leaf.eax &= 0xFFFFFF00; // Zeroing out AL. 0 is the empty descriptor. + // The most significant bit (bit 31) of each register indicates whether the + // register contains valid information (set to 0) or is reserved (set to 1). + if (IsBitSet(leaf.eax, 31)) leaf.eax = 0; + if (IsBitSet(leaf.ebx, 31)) leaf.ebx = 0; + if (IsBitSet(leaf.ecx, 31)) leaf.ecx = 0; + if (IsBitSet(leaf.edx, 31)) leaf.edx = 0; + + uint8_t data[16]; +#if __STDC_VERSION__ >= 201112L + _Static_assert(sizeof(Leaf) == sizeof(data), "Leaf must be 16 bytes"); +#endif + memcpy(&data, &leaf, sizeof(data)); + for (size_t i = 0; i < sizeof(data); ++i) { + const uint8_t descriptor = data[i]; + if (descriptor == 0) continue; + info->levels[info->size] = GetCacheLevelInfo(descriptor); info->size++; } } -static void ParseLeaf4(const int max_cpuid_leaf, CacheInfo* info) { - info->size = 0; +// For newer Intel CPUs uses "CPUID, eax=0x00000004". +// For newer AMD CPUs uses "CPUID, eax=0x8000001D" +static void ParseCacheInfo(const int max_cpuid_leaf, uint32_t leaf_id, + CacheInfo* info) { for (int cache_id = 0; cache_id < CPU_FEATURES_MAX_CACHE_LEVEL; cache_id++) { - const Leaf leaf = SafeCpuIdEx(max_cpuid_leaf, 4, cache_id); + const Leaf leaf = SafeCpuIdEx(max_cpuid_leaf, leaf_id, cache_id); CacheType cache_type = ExtractBitRange(leaf.eax, 4, 0); - if (cache_type == CPU_FEATURE_CACHE_NULL) { - info->levels[cache_id] = kEmptyCacheLevelInfo; - continue; - } + if (cache_type == CPU_FEATURE_CACHE_NULL) continue; int level = ExtractBitRange(leaf.eax, 7, 5); int line_size = ExtractBitRange(leaf.ebx, 11, 0) + 1; int partitioning = ExtractBitRange(leaf.ebx, 21, 12) + 1; int ways = ExtractBitRange(leaf.ebx, 31, 22) + 1; int tlb_entries = leaf.ecx + 1; int cache_size = (ways * partitioning * line_size * (tlb_entries)); - info->levels[cache_id] = (CacheLevelInfo){.level = level, - .cache_type = cache_type, - .cache_size = cache_size, - .ways = ways, - .line_size = line_size, - .tlb_entries = tlb_entries, - .partitioning = partitioning}; + info->levels[info->size] = (CacheLevelInfo){.level = level, + .cache_type = cache_type, + .cache_size = cache_size, + .ways = ways, + .line_size = line_size, + .tlb_entries = tlb_entries, + .partitioning = partitioning}; info->size++; } } @@ -1181,41 +1189,11 @@ // Internal structure to hold the OS support for vector operations. // Avoid to recompute them since each call to cpuid is ~100 cycles. typedef struct { - bool have_sse_via_os; - bool have_sse_via_cpuid; - bool have_avx; - bool have_avx512; - bool have_amx; -} OsSupport; - -static const OsSupport kEmptyOsSupport; - -static OsSupport CheckOsSupport(const uint32_t max_cpuid_leaf) { - const Leaf leaf_1 = SafeCpuId(max_cpuid_leaf, 1); - const bool have_xsave = IsBitSet(leaf_1.ecx, 26); - const bool have_osxsave = IsBitSet(leaf_1.ecx, 27); - const bool have_xcr0 = have_xsave && have_osxsave; - - OsSupport os_support = kEmptyOsSupport; - - if (have_xcr0) { - // AVX capable cpu will expose XCR0. - const uint32_t xcr0_eax = GetXCR0Eax(); - os_support.have_sse_via_cpuid = HasXmmOsXSave(xcr0_eax); - os_support.have_avx = HasYmmOsXSave(xcr0_eax); -#if defined(CPU_FEATURES_OS_DARWIN) - os_support.have_avx512 = GetDarwinSysCtlByName("hw.optional.avx512f"); -#else - os_support.have_avx512 = HasZmmOsXSave(xcr0_eax); -#endif // CPU_FEATURES_OS_DARWIN - os_support.have_amx = HasTmmOsXSave(xcr0_eax); - } else { - // Atom based or older cpus need to ask the OS for sse support. - os_support.have_sse_via_os = true; - } - - return os_support; -} + bool sse_registers; + bool avx_registers; + bool avx512_registers; + bool amx_registers; +} OsPreserves; #if defined(CPU_FEATURES_OS_WINDOWS) #if defined(CPU_FEATURES_MOCK_CPUID_X86) @@ -1227,60 +1205,17 @@ #endif #endif // CPU_FEATURES_OS_WINDOWS -static void DetectSseViaOs(X86Features* features) { -#if defined(CPU_FEATURES_OS_WINDOWS) - // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent - features->sse = - GetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE); - features->sse2 = - GetWindowsIsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE); - features->sse3 = - GetWindowsIsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE); -#elif defined(CPU_FEATURES_OS_DARWIN) - // Handling Darwin platform through sysctlbyname. - features->sse = GetDarwinSysCtlByName("hw.optional.sse"); - features->sse2 = GetDarwinSysCtlByName("hw.optional.sse2"); - features->sse3 = GetDarwinSysCtlByName("hw.optional.sse3"); - features->ssse3 = GetDarwinSysCtlByName("hw.optional.supplementalsse3"); - features->sse4_1 = GetDarwinSysCtlByName("hw.optional.sse4_1"); - features->sse4_2 = GetDarwinSysCtlByName("hw.optional.sse4_2"); -#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) - // Handling Linux platform through /proc/cpuinfo. - const int fd = CpuFeatures_OpenFile("/proc/cpuinfo"); - if (fd >= 0) { - StackLineReader reader; - StackLineReader_Initialize(&reader, fd); - for (;;) { - const LineResult result = StackLineReader_NextLine(&reader); - const StringView line = result.line; - StringView key, value; - if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) { - if (CpuFeatures_StringView_IsEquals(key, str("flags"))) { - features->sse = CpuFeatures_StringView_HasWord(value, "sse"); - features->sse2 = CpuFeatures_StringView_HasWord(value, "sse2"); - features->sse3 = CpuFeatures_StringView_HasWord(value, "sse3"); - features->ssse3 = CpuFeatures_StringView_HasWord(value, "ssse3"); - features->sse4_1 = CpuFeatures_StringView_HasWord(value, "sse4_1"); - features->sse4_2 = CpuFeatures_StringView_HasWord(value, "sse4_2"); - break; - } - } - if (result.eof) break; - } - CpuFeatures_CloseFile(fd); - } -#else -#error "Unsupported fallback detection of SSE OS support." -#endif -} - // Reference https://en.wikipedia.org/wiki/CPUID. -static void ParseCpuId(const uint32_t max_cpuid_leaf, - const OsSupport os_support, X86Info* info) { +static void ParseCpuId(const uint32_t max_cpuid_leaf, X86Info* info, + OsPreserves* os_preserves) { const Leaf leaf_1 = SafeCpuId(max_cpuid_leaf, 1); const Leaf leaf_7 = SafeCpuId(max_cpuid_leaf, 7); const Leaf leaf_7_1 = SafeCpuIdEx(max_cpuid_leaf, 7, 1); + const bool have_xsave = IsBitSet(leaf_1.ecx, 26); + const bool have_osxsave = IsBitSet(leaf_1.ecx, 27); + const bool have_xcr0 = have_xsave && have_osxsave; + const uint32_t family = ExtractBitRange(leaf_1.eax, 11, 8); const uint32_t extended_family = ExtractBitRange(leaf_1.eax, 27, 20); const uint32_t model = ExtractBitRange(leaf_1.eax, 7, 4); @@ -1321,85 +1256,195 @@ features->vpclmulqdq = IsBitSet(leaf_7.ecx, 10); features->adx = IsBitSet(leaf_7.ebx, 19); - if (os_support.have_sse_via_os) { - DetectSseViaOs(features); - } else if (os_support.have_sse_via_cpuid) { - features->sse = IsBitSet(leaf_1.edx, 25); - features->sse2 = IsBitSet(leaf_1.edx, 26); - features->sse3 = IsBitSet(leaf_1.ecx, 0); - features->ssse3 = IsBitSet(leaf_1.ecx, 9); - features->sse4_1 = IsBitSet(leaf_1.ecx, 19); - features->sse4_2 = IsBitSet(leaf_1.ecx, 20); - } - - if (os_support.have_avx) { - features->fma3 = IsBitSet(leaf_1.ecx, 12); - features->avx = IsBitSet(leaf_1.ecx, 28); - features->avx2 = IsBitSet(leaf_7.ebx, 5); - } + ///////////////////////////////////////////////////////////////////////////// + // The following section is devoted to Vector Extensions. + ///////////////////////////////////////////////////////////////////////////// - if (os_support.have_avx512) { - features->avx512f = IsBitSet(leaf_7.ebx, 16); - features->avx512cd = IsBitSet(leaf_7.ebx, 28); - features->avx512er = IsBitSet(leaf_7.ebx, 27); - features->avx512pf = IsBitSet(leaf_7.ebx, 26); - features->avx512bw = IsBitSet(leaf_7.ebx, 30); - features->avx512dq = IsBitSet(leaf_7.ebx, 17); - features->avx512vl = IsBitSet(leaf_7.ebx, 31); - features->avx512ifma = IsBitSet(leaf_7.ebx, 21); - features->avx512vbmi = IsBitSet(leaf_7.ecx, 1); - features->avx512vbmi2 = IsBitSet(leaf_7.ecx, 6); - features->avx512vnni = IsBitSet(leaf_7.ecx, 11); - features->avx512bitalg = IsBitSet(leaf_7.ecx, 12); - features->avx512vpopcntdq = IsBitSet(leaf_7.ecx, 14); - features->avx512_4vnniw = IsBitSet(leaf_7.edx, 2); - features->avx512_4vbmi2 = IsBitSet(leaf_7.edx, 3); - features->avx512_second_fma = HasSecondFMA(info->model); - features->avx512_4fmaps = IsBitSet(leaf_7.edx, 3); - features->avx512_bf16 = IsBitSet(leaf_7_1.eax, 5); - features->avx512_vp2intersect = IsBitSet(leaf_7.edx, 8); - } + // CPU with AVX expose XCR0 which enables checking vector extensions OS + // support through cpuid. + if (have_xcr0) { + // Here we rely exclusively on cpuid for both CPU and OS support of vector + // extensions. + const uint32_t xcr0_eax = GetXCR0Eax(); + os_preserves->sse_registers = HasXmmOsXSave(xcr0_eax); + os_preserves->avx_registers = HasYmmOsXSave(xcr0_eax); +#if defined(CPU_FEATURES_OS_DARWIN) + // On Darwin AVX512 support is On-demand. + // We have to query the OS instead of querying the Zmm save/restore state. + // https://github.com/apple/darwin-xnu/blob/8f02f2a044b9bb1ad951987ef5bab20ec9486310/osfmk/i386/fpu.c#L173-L199 + os_preserves->avx512_registers = + GetDarwinSysCtlByName("hw.optional.avx512f"); +#else + os_preserves->avx512_registers = HasZmmOsXSave(xcr0_eax); +#endif // CPU_FEATURES_OS_DARWIN + os_preserves->amx_registers = HasTmmOsXSave(xcr0_eax); - if (os_support.have_amx) { - features->amx_bf16 = IsBitSet(leaf_7.edx, 22); - features->amx_tile = IsBitSet(leaf_7.edx, 24); - features->amx_int8 = IsBitSet(leaf_7.edx, 25); + if (os_preserves->sse_registers) { + features->sse = IsBitSet(leaf_1.edx, 25); + features->sse2 = IsBitSet(leaf_1.edx, 26); + features->sse3 = IsBitSet(leaf_1.ecx, 0); + features->ssse3 = IsBitSet(leaf_1.ecx, 9); + features->sse4_1 = IsBitSet(leaf_1.ecx, 19); + features->sse4_2 = IsBitSet(leaf_1.ecx, 20); + } + if (os_preserves->avx_registers) { + features->fma3 = IsBitSet(leaf_1.ecx, 12); + features->avx = IsBitSet(leaf_1.ecx, 28); + features->avx2 = IsBitSet(leaf_7.ebx, 5); + } + if (os_preserves->avx512_registers) { + features->avx512f = IsBitSet(leaf_7.ebx, 16); + features->avx512cd = IsBitSet(leaf_7.ebx, 28); + features->avx512er = IsBitSet(leaf_7.ebx, 27); + features->avx512pf = IsBitSet(leaf_7.ebx, 26); + features->avx512bw = IsBitSet(leaf_7.ebx, 30); + features->avx512dq = IsBitSet(leaf_7.ebx, 17); + features->avx512vl = IsBitSet(leaf_7.ebx, 31); + features->avx512ifma = IsBitSet(leaf_7.ebx, 21); + features->avx512vbmi = IsBitSet(leaf_7.ecx, 1); + features->avx512vbmi2 = IsBitSet(leaf_7.ecx, 6); + features->avx512vnni = IsBitSet(leaf_7.ecx, 11); + features->avx512bitalg = IsBitSet(leaf_7.ecx, 12); + features->avx512vpopcntdq = IsBitSet(leaf_7.ecx, 14); + features->avx512_4vnniw = IsBitSet(leaf_7.edx, 2); + features->avx512_4vbmi2 = IsBitSet(leaf_7.edx, 3); + features->avx512_second_fma = HasSecondFMA(info->model); + features->avx512_4fmaps = IsBitSet(leaf_7.edx, 3); + features->avx512_bf16 = IsBitSet(leaf_7_1.eax, 5); + features->avx512_vp2intersect = IsBitSet(leaf_7.edx, 8); + } + if (os_preserves->amx_registers) { + features->amx_bf16 = IsBitSet(leaf_7.edx, 22); + features->amx_tile = IsBitSet(leaf_7.edx, 24); + features->amx_int8 = IsBitSet(leaf_7.edx, 25); + } + } else { + // When XCR0 is not available (Atom based or older cpus) we need to defer to + // the OS via custom code. +#if defined(CPU_FEATURES_OS_WINDOWS) + // Handling Windows platform through IsProcessorFeaturePresent. + // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent + features->sse = + GetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE); + features->sse2 = + GetWindowsIsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE); + features->sse3 = + GetWindowsIsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE); +#elif defined(CPU_FEATURES_OS_DARWIN) + // Handling Darwin platform through sysctlbyname. + features->sse = GetDarwinSysCtlByName("hw.optional.sse"); + features->sse2 = GetDarwinSysCtlByName("hw.optional.sse2"); + features->sse3 = GetDarwinSysCtlByName("hw.optional.sse3"); + features->ssse3 = GetDarwinSysCtlByName("hw.optional.supplementalsse3"); + features->sse4_1 = GetDarwinSysCtlByName("hw.optional.sse4_1"); + features->sse4_2 = GetDarwinSysCtlByName("hw.optional.sse4_2"); +#elif defined(CPU_FEATURES_OS_FREEBSD) + // Handling FreeBSD platform through parsing /var/run/dmesg.boot. + const int fd = CpuFeatures_OpenFile("/var/run/dmesg.boot"); + if (fd >= 0) { + StackLineReader reader; + StackLineReader_Initialize(&reader, fd); + for (bool stop = false; !stop;) { + const LineResult result = StackLineReader_NextLine(&reader); + if (result.eof) stop = true; + const StringView line = result.line; + if (!CpuFeatures_StringView_StartsWith(line, str(" Features"))) + continue; + // Lines of interests are of the following form: + // " Features=0x1783fbff" + // We first extract the comma separated values between angle brackets. + StringView csv = result.line; + int index = CpuFeatures_StringView_IndexOfChar(csv, '<'); + if (index >= 0) csv = CpuFeatures_StringView_PopFront(csv, index + 1); + if (csv.size > 0 && CpuFeatures_StringView_Back(csv) == '>') + csv = CpuFeatures_StringView_PopBack(csv, 1); + if (CpuFeatures_StringView_HasWord(csv, "SSE", ',')) + features->sse = true; + if (CpuFeatures_StringView_HasWord(csv, "SSE2", ',')) + features->sse2 = true; + if (CpuFeatures_StringView_HasWord(csv, "SSE3", ',')) + features->sse3 = true; + if (CpuFeatures_StringView_HasWord(csv, "SSSE3", ',')) + features->ssse3 = true; + if (CpuFeatures_StringView_HasWord(csv, "SSE4.1", ',')) + features->sse4_1 = true; + if (CpuFeatures_StringView_HasWord(csv, "SSE4.2", ',')) + features->sse4_2 = true; + } + CpuFeatures_CloseFile(fd); + } +#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) + // Handling Linux platform through /proc/cpuinfo. + const int fd = CpuFeatures_OpenFile("/proc/cpuinfo"); + if (fd >= 0) { + StackLineReader reader; + StackLineReader_Initialize(&reader, fd); + for (bool stop = false; !stop;) { + const LineResult result = StackLineReader_NextLine(&reader); + if (result.eof) stop = true; + const StringView line = result.line; + StringView key, value; + if (!CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) + continue; + if (!CpuFeatures_StringView_IsEquals(key, str("flags"))) continue; + features->sse = CpuFeatures_StringView_HasWord(value, "sse", ' '); + features->sse2 = CpuFeatures_StringView_HasWord(value, "sse2", ' '); + features->sse3 = CpuFeatures_StringView_HasWord(value, "sse3", ' '); + features->ssse3 = CpuFeatures_StringView_HasWord(value, "ssse3", ' '); + features->sse4_1 = CpuFeatures_StringView_HasWord(value, "sse4_1", ' '); + features->sse4_2 = CpuFeatures_StringView_HasWord(value, "sse4_2", ' '); + break; + } + CpuFeatures_CloseFile(fd); + } +#else +#error "Unsupported fallback detection of SSE OS support." +#endif + // Now that we have queried the OS for SSE support, we report this back to + // os_preserves. This is needed in case of AMD CPU's to enable testing of + // sse4a (See ParseExtraAMDCpuId below). + if (features->sse) os_preserves->sse_registers = true; } } // Reference // https://en.wikipedia.org/wiki/CPUID#EAX=80000000h:_Get_Highest_Extended_Function_Implemented. -static void ParseExtraAMDCpuId(X86Info* info, OsSupport os_support) { - const Leaf leaf_80000000 = CpuId(0x80000000); - const uint32_t max_extended_cpuid_leaf = leaf_80000000.eax; - const Leaf leaf_80000001 = SafeCpuId(max_extended_cpuid_leaf, 0x80000001); +static Leaf GetLeafByIdAMD(uint32_t leaf_id) { + uint32_t max_extended = CpuId(0x80000000).eax; + return SafeCpuId(max_extended, leaf_id); +} + +static void ParseExtraAMDCpuId(X86Info* info, OsPreserves os_preserves) { + const Leaf leaf_80000001 = GetLeafByIdAMD(0x80000001); X86Features* const features = &info->features; - if (os_support.have_sse_via_cpuid) { + if (os_preserves.sse_registers) { features->sse4a = IsBitSet(leaf_80000001.ecx, 6); } - if (os_support.have_avx) { + if (os_preserves.avx_registers) { features->fma4 = IsBitSet(leaf_80000001.ecx, 16); } } static const X86Info kEmptyX86Info; static const CacheInfo kEmptyCacheInfo; +static const OsPreserves kEmptyOsPreserves; X86Info GetX86Info(void) { X86Info info = kEmptyX86Info; const Leaf leaf_0 = CpuId(0); - const bool is_intel = IsVendor(leaf_0, "GenuineIntel"); - const bool is_amd = IsVendor(leaf_0, "AuthenticAMD"); + const bool is_intel = IsVendor(leaf_0, CPU_FEATURES_VENDOR_GENUINE_INTEL); + const bool is_amd = IsVendor(leaf_0, CPU_FEATURES_VENDOR_AUTHENTIC_AMD); + const bool is_hygon = IsVendor(leaf_0, CPU_FEATURES_VENDOR_HYGON_GENUINE); SetVendor(leaf_0, info.vendor); - if (is_intel || is_amd) { + if (is_intel || is_amd || is_hygon) { + OsPreserves os_preserves = kEmptyOsPreserves; const uint32_t max_cpuid_leaf = leaf_0.eax; - const OsSupport os_support = CheckOsSupport(max_cpuid_leaf); - ParseCpuId(max_cpuid_leaf, os_support, &info); - if (is_amd) { - ParseExtraAMDCpuId(&info, os_support); + ParseCpuId(max_cpuid_leaf, &info, &os_preserves); + if (is_amd || is_hygon) { + ParseExtraAMDCpuId(&info, os_preserves); } } return info; @@ -1408,10 +1453,21 @@ CacheInfo GetX86CacheInfo(void) { CacheInfo info = kEmptyCacheInfo; const Leaf leaf_0 = CpuId(0); - const uint32_t max_cpuid_leaf = leaf_0.eax; - if (IsVendor(leaf_0, "GenuineIntel")) { - ParseLeaf2(max_cpuid_leaf, &info); - ParseLeaf4(max_cpuid_leaf, &info); + if (IsVendor(leaf_0, CPU_FEATURES_VENDOR_GENUINE_INTEL)) { + info.size = 0; + ParseLeaf2(leaf_0.eax, &info); + ParseCacheInfo(leaf_0.eax, 4, &info); + } else if (IsVendor(leaf_0, CPU_FEATURES_VENDOR_AUTHENTIC_AMD) || + IsVendor(leaf_0, CPU_FEATURES_VENDOR_HYGON_GENUINE)) { + const uint32_t max_ext = CpuId(0x80000000).eax; + const uint32_t cpuid_ext = SafeCpuId(max_ext, 0x80000001).ecx; + + // If CPUID Fn8000_0001_ECX[TopologyExtensions]==0 + // then CPUID Fn8000_0001_E[D,C,B,A]X is reserved. + // https://www.amd.com/system/files/TechDocs/25481.pdf + if (IsBitSet(cpuid_ext, 22)) { + ParseCacheInfo(max_ext, 0x8000001D, &info); + } } return info; } @@ -1419,10 +1475,12 @@ #define CPUID(FAMILY, MODEL) ((((FAMILY)&0xFF) << 8) | ((MODEL)&0xFF)) X86Microarchitecture GetX86Microarchitecture(const X86Info* info) { - if (memcmp(info->vendor, "GenuineIntel", sizeof(info->vendor)) == 0) { + if (IsVendorByX86Info(info, CPU_FEATURES_VENDOR_GENUINE_INTEL)) { switch (CPUID(info->family, info->model)) { + case CPUID(0x06, 0x1C): // Intel(R) Atom(TM) CPU 230 @ 1.60GHz case CPUID(0x06, 0x35): case CPUID(0x06, 0x36): + case CPUID(0x06, 0x70): // https://en.wikichip.org/wiki/intel/atom/230 // https://en.wikipedia.org/wiki/Bonnell_(microarchitecture) return INTEL_ATOM_BNL; case CPUID(0x06, 0x37): @@ -1516,45 +1574,136 @@ return X86_UNKNOWN; } } - if (memcmp(info->vendor, "AuthenticAMD", sizeof(info->vendor)) == 0) { - switch (info->family) { - // https://en.wikipedia.org/wiki/List_of_AMD_CPU_microarchitectures - case 0x0F: + if (IsVendorByX86Info(info, CPU_FEATURES_VENDOR_AUTHENTIC_AMD)) { + switch (CPUID(info->family, info->model)) { + // https://en.wikichip.org/wiki/amd/cpuid + case CPUID(0xF, 0x04): + case CPUID(0xF, 0x05): + case CPUID(0xF, 0x07): + case CPUID(0xF, 0x08): + case CPUID(0xF, 0x0C): + case CPUID(0xF, 0x0E): + case CPUID(0xF, 0x0F): + case CPUID(0xF, 0x14): + case CPUID(0xF, 0x15): + case CPUID(0xF, 0x17): + case CPUID(0xF, 0x18): + case CPUID(0xF, 0x1B): + case CPUID(0xF, 0x1C): + case CPUID(0xF, 0x1F): + case CPUID(0xF, 0x21): + case CPUID(0xF, 0x23): + case CPUID(0xF, 0x24): + case CPUID(0xF, 0x25): + case CPUID(0xF, 0x27): + case CPUID(0xF, 0x2B): + case CPUID(0xF, 0x2C): + case CPUID(0xF, 0x2F): + case CPUID(0xF, 0x41): + case CPUID(0xF, 0x43): + case CPUID(0xF, 0x48): + case CPUID(0xF, 0x4B): + case CPUID(0xF, 0x4C): + case CPUID(0xF, 0x4F): + case CPUID(0xF, 0x5D): + case CPUID(0xF, 0x5F): + case CPUID(0xF, 0x68): + case CPUID(0xF, 0x6B): + case CPUID(0xF, 0x6F): + case CPUID(0xF, 0x7F): + case CPUID(0xF, 0xC1): return AMD_HAMMER; - case 0x10: + case CPUID(0x10, 0x02): + case CPUID(0x10, 0x04): + case CPUID(0x10, 0x05): + case CPUID(0x10, 0x06): + case CPUID(0x10, 0x08): + case CPUID(0x10, 0x09): + case CPUID(0x10, 0x0A): return AMD_K10; - case 0x14: + case CPUID(0x11, 0x03): + // http://developer.amd.com/wordpress/media/2012/10/41788.pdf + return AMD_K11; + case CPUID(0x12, 0x01): + // https://www.amd.com/system/files/TechDocs/44739_12h_Rev_Gd.pdf + return AMD_K12; + case CPUID(0x14, 0x00): + case CPUID(0x14, 0x01): + case CPUID(0x14, 0x02): + // https://www.amd.com/system/files/TechDocs/47534_14h_Mod_00h-0Fh_Rev_Guide.pdf return AMD_BOBCAT; - case 0x15: + case CPUID(0x15, 0x01): + // https://en.wikichip.org/wiki/amd/microarchitectures/bulldozer return AMD_BULLDOZER; - case 0x16: + case CPUID(0x15, 0x02): + case CPUID(0x15, 0x11): + case CPUID(0x15, 0x13): + // https://en.wikichip.org/wiki/amd/microarchitectures/piledriver + return AMD_PILEDRIVER; + case CPUID(0x15, 0x30): + case CPUID(0x15, 0x38): + // https://en.wikichip.org/wiki/amd/microarchitectures/steamroller + return AMD_STREAMROLLER; + case CPUID(0x15, 0x60): + case CPUID(0x15, 0x65): + case CPUID(0x15, 0x70): + // https://en.wikichip.org/wiki/amd/microarchitectures/excavator + return AMD_EXCAVATOR; + case CPUID(0x16, 0x00): return AMD_JAGUAR; - case 0x17: + case CPUID(0x16, 0x30): + return AMD_PUMA; + case CPUID(0x17, 0x01): + case CPUID(0x17, 0x11): + case CPUID(0x17, 0x18): + case CPUID(0x17, 0x20): + // https://en.wikichip.org/wiki/amd/microarchitectures/zen return AMD_ZEN; - case 0x19: + case CPUID(0x17, 0x08): + // https://en.wikichip.org/wiki/amd/microarchitectures/zen%2B + return AMD_ZEN_PLUS; + case CPUID(0x17, 0x31): + case CPUID(0x17, 0x47): + case CPUID(0x17, 0x60): + case CPUID(0x17, 0x68): + case CPUID(0x17, 0x71): + case CPUID(0x17, 0x90): + case CPUID(0x17, 0x98): + // https://en.wikichip.org/wiki/amd/microarchitectures/zen_2 + return AMD_ZEN2; + case CPUID(0x19, 0x01): + case CPUID(0x19, 0x21): + case CPUID(0x19, 0x30): + case CPUID(0x19, 0x40): + case CPUID(0x19, 0x50): + // https://en.wikichip.org/wiki/amd/microarchitectures/zen_3 return AMD_ZEN3; default: return X86_UNKNOWN; } } + if (IsVendorByX86Info(info, CPU_FEATURES_VENDOR_HYGON_GENUINE)) { + switch (CPUID(info->family, info->model)) { + case CPUID(0x18, 0x00): + return AMD_ZEN; + } + } return X86_UNKNOWN; } -static void SetString(const uint32_t max_cpuid_ext_leaf, const uint32_t leaf_id, - char* buffer) { - const Leaf leaf = SafeCpuId(max_cpuid_ext_leaf, leaf_id); - // We allow calling memcpy from SetString which is only called when requesting - // X86BrandString. - memcpy(buffer, &leaf, sizeof(Leaf)); -} - void FillX86BrandString(char brand_string[49]) { const Leaf leaf_ext_0 = CpuId(0x80000000); const uint32_t max_cpuid_leaf_ext = leaf_ext_0.eax; - SetString(max_cpuid_leaf_ext, 0x80000002, brand_string); - SetString(max_cpuid_leaf_ext, 0x80000003, brand_string + 16); - SetString(max_cpuid_leaf_ext, 0x80000004, brand_string + 32); - brand_string[48] = '\0'; + const Leaf leaves[3] = { + SafeCpuId(max_cpuid_leaf_ext, 0x80000002), + SafeCpuId(max_cpuid_leaf_ext, 0x80000003), + SafeCpuId(max_cpuid_leaf_ext, 0x80000004), + }; +#if __STDC_VERSION__ >= 201112L + _Static_assert(sizeof(leaves) == 48, "Leaves must be packed"); +#endif + CpuFeatures_StringView_CopyString(view((const char*)leaves, sizeof(leaves)), + brand_string, 49); } //////////////////////////////////////////////////////////////////////////////// @@ -1617,14 +1766,30 @@ return "AMD_HAMMER"; case AMD_K10: return "AMD_K10"; + case AMD_K11: + return "AMD_K11"; + case AMD_K12: + return "AMD_K12"; case AMD_BOBCAT: return "AMD_BOBCAT"; + case AMD_PILEDRIVER: + return "AMD_PILEDRIVER"; + case AMD_STREAMROLLER: + return "AMD_STREAMROLLER"; + case AMD_EXCAVATOR: + return "AMD_EXCAVATOR"; case AMD_BULLDOZER: return "AMD_BULLDOZER"; + case AMD_PUMA: + return "AMD_PUMA"; case AMD_JAGUAR: return "AMD_JAGUAR"; case AMD_ZEN: return "AMD_ZEN"; + case AMD_ZEN_PLUS: + return "AMD_ZEN_PLUS"; + case AMD_ZEN2: + return "AMD_ZEN2"; case AMD_ZEN3: return "AMD_ZEN3"; } diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/hwcaps.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/hwcaps.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/hwcaps.c 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/hwcaps.c 2021-10-25 20:43:15.000000000 +0000 @@ -35,7 +35,8 @@ #ifdef CPU_FEATURES_TEST // In test mode, hwcaps_for_testing will define the following functions. HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void); -PlatformType CpuFeatures_GetPlatformType(void); +const char* CpuFeatures_GetPlatformPointer(void); +const char* CpuFeatures_GetBasePlatformPointer(void); #else // Debug facilities @@ -163,20 +164,12 @@ return capabilities; } -PlatformType kEmptyPlatformType; +const char *CpuFeatures_GetPlatformPointer(void) { + return (const char *)GetHardwareCapabilitiesFor(AT_PLATFORM); +} -PlatformType CpuFeatures_GetPlatformType(void) { - PlatformType type = kEmptyPlatformType; - char *platform = (char *)GetHardwareCapabilitiesFor(AT_PLATFORM); - char *base_platform = (char *)GetHardwareCapabilitiesFor(AT_BASE_PLATFORM); - - if (platform != NULL) - CpuFeatures_StringView_CopyString(str(platform), type.platform, - sizeof(type.platform)); - if (base_platform != NULL) - CpuFeatures_StringView_CopyString(str(base_platform), type.base_platform, - sizeof(type.base_platform)); - return type; +const char *CpuFeatures_GetBasePlatformPointer(void) { + return (const char *)GetHardwareCapabilitiesFor(AT_BASE_PLATFORM); } #endif // CPU_FEATURES_TEST diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/string_view.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/string_view.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/string_view.c 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/string_view.c 2021-10-25 20:43:15.000000000 +0000 @@ -144,7 +144,8 @@ } bool CpuFeatures_StringView_HasWord(const StringView line, - const char* const word_str) { + const char* const word_str, + const char separator) { const StringView word = str(word_str); StringView remainder = line; for (;;) { @@ -157,9 +158,9 @@ const StringView after = CpuFeatures_StringView_PopFront(line, index_of_word + word.size); const bool valid_before = - before.size == 0 || CpuFeatures_StringView_Back(before) == ' '; + before.size == 0 || CpuFeatures_StringView_Back(before) == separator; const bool valid_after = - after.size == 0 || CpuFeatures_StringView_Front(after) == ' '; + after.size == 0 || CpuFeatures_StringView_Front(after) == separator; if (valid_before && valid_after) return true; remainder = CpuFeatures_StringView_PopFront(remainder, index_of_word + word.size); diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/utils/list_cpu_features.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/utils/list_cpu_features.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/utils/list_cpu_features.c 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/src/utils/list_cpu_features.c 2021-10-25 20:43:15.000000000 +0000 @@ -340,6 +340,7 @@ case CPU_FEATURE_CACHE_PREFETCH: return CreateConstantString("prefetch"); } + UNREACHABLE(); } static void AddCacheInfo(Node* root, const CacheInfo* cache_info) { diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_aarch64_test.cc softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_aarch64_test.cc --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_aarch64_test.cc 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_aarch64_test.cc 2021-10-25 20:43:15.000000000 +0000 @@ -24,6 +24,7 @@ void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); } TEST(CpuinfoAarch64Test, FromHardwareCap) { + ResetHwcaps(); SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_AES, 0); GetEmptyFilesystem(); // disabling /proc/cpuinfo const auto info = GetAarch64Info(); @@ -62,6 +63,7 @@ } TEST(CpuinfoAarch64Test, FromHardwareCap2) { + ResetHwcaps(); SetHardwareCapabilities(AARCH64_HWCAP_FP, AARCH64_HWCAP2_SVE2 | AARCH64_HWCAP2_BTI); GetEmptyFilesystem(); // disabling /proc/cpuinfo @@ -90,7 +92,7 @@ } TEST(CpuinfoAarch64Test, ARMCortexA53) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(Processor : AArch64 Processor rev 3 (aarch64) diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_arm_test.cc softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_arm_test.cc --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_arm_test.cc 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_arm_test.cc 2021-10-25 20:43:15.000000000 +0000 @@ -21,9 +21,8 @@ namespace cpu_features { namespace { -void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); } - TEST(CpuinfoArmTest, FromHardwareCap) { + ResetHwcaps(); SetHardwareCapabilities(ARM_HWCAP_NEON, ARM_HWCAP2_AES | ARM_HWCAP2_CRC32); GetEmptyFilesystem(); // disabling /proc/cpuinfo const auto info = GetArmInfo(); @@ -52,7 +51,7 @@ } TEST(CpuinfoArmTest, ODroidFromCpuInfo) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(processor : 0 model name : ARMv7 Processor rev 3 (v71) @@ -101,7 +100,7 @@ // Linux test-case TEST(CpuinfoArmTest, RaspberryPiZeroFromCpuInfo) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(processor : 0 model name : ARMv6-compatible processor rev 7 (v6l) @@ -153,7 +152,7 @@ } TEST(CpuinfoArmTest, MarvellArmadaFromCpuInfo) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(processor : 0 model name : ARMv7 Processor rev 1 (v7l) @@ -217,7 +216,7 @@ // Android test-case // http://code.google.com/p/android/issues/detail?id=10812 TEST(CpuinfoArmTest, InvalidArmv7) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(Processor : ARMv6-compatible processor rev 6 (v6l) @@ -267,6 +266,7 @@ // Android test-case // https://crbug.com/341598. TEST(CpuinfoArmTest, InvalidNeon) { + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(Processor: ARMv7 Processory rev 0 (v71) @@ -294,7 +294,7 @@ // The Nexus 4 (Qualcomm Krait) kernel configuration forgets to report IDIV // support. TEST(CpuinfoArmTest, Nexus4_0x510006f2) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(CPU implementer : 0x51 @@ -312,7 +312,7 @@ // The Nexus 4 (Qualcomm Krait) kernel configuration forgets to report IDIV // support. TEST(CpuinfoArmTest, Nexus4_0x510006f3) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(CPU implementer : 0x51 @@ -331,7 +331,7 @@ // 32-bit ARM IDIV instruction. Technically, this is a feature of the virtual // CPU implemented by the emulator. TEST(CpuinfoArmTest, EmulatorSpecificIdiv) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(Processor : ARMv7 Processor rev 0 (v7l) diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_mips_test.cc softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_mips_test.cc --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_mips_test.cc 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_mips_test.cc 2021-10-25 20:43:15.000000000 +0000 @@ -24,9 +24,8 @@ namespace { -void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); } - TEST(CpuinfoMipsTest, FromHardwareCapBoth) { + ResetHwcaps(); SetHardwareCapabilities(MIPS_HWCAP_MSA | MIPS_HWCAP_R6, 0); GetEmptyFilesystem(); // disabling /proc/cpuinfo const auto info = GetMipsInfo(); @@ -36,6 +35,7 @@ } TEST(CpuinfoMipsTest, FromHardwareCapOnlyOne) { + ResetHwcaps(); SetHardwareCapabilities(MIPS_HWCAP_MSA, 0); GetEmptyFilesystem(); // disabling /proc/cpuinfo const auto info = GetMipsInfo(); @@ -44,7 +44,7 @@ } TEST(CpuinfoMipsTest, Ci40) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(system type : IMG Pistachio SoC (B0) machine : IMG Marduk – Ci40 with cc2520 @@ -72,7 +72,7 @@ } TEST(CpuinfoMipsTest, AR7161) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(system type : Atheros AR7161 rev 2 @@ -98,7 +98,7 @@ } TEST(CpuinfoMipsTest, Goldfish) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(system type : MIPS-Goldfish Hardware : goldfish diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_ppc_test.cc softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_ppc_test.cc --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_ppc_test.cc 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_ppc_test.cc 2021-10-25 20:43:15.000000000 +0000 @@ -22,9 +22,8 @@ namespace cpu_features { namespace { -void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); } - TEST(CpustringsPPCTest, FromHardwareCap) { + ResetHwcaps(); SetHardwareCapabilities(PPC_FEATURE_HAS_FPU | PPC_FEATURE_HAS_VSX, PPC_FEATURE2_ARCH_3_00); GetEmptyFilesystem(); // disabling /proc/cpuinfo @@ -40,7 +39,7 @@ } TEST(CpustringsPPCTest, Blade) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(processor : 14 @@ -57,7 +56,8 @@ platform : pSeries model : IBM,8406-70Y machine : CHRP IBM,8406-70Y)"); - SetPlatformTypes("power7", "power8"); + SetPlatformPointer("power7"); + SetBasePlatformPointer("power8"); const auto strings = GetPPCPlatformStrings(); ASSERT_STREQ(strings.platform, "pSeries"); ASSERT_STREQ(strings.model, "IBM,8406-70Y"); @@ -68,7 +68,7 @@ } TEST(CpustringsPPCTest, Firestone) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(processor : 126 @@ -94,7 +94,7 @@ } TEST(CpustringsPPCTest, w8) { - DisableHardwareCapabilities(); + ResetHwcaps(); auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(processor : 143 diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_x86_test.cc softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_x86_test.cc --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_x86_test.cc 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/cpuinfo_x86_test.cc 2021-10-25 20:43:15.000000000 +0000 @@ -79,23 +79,28 @@ uint32_t xcr0_eax_; }; -FakeCpu* g_fake_cpu = nullptr; +static FakeCpu* g_fake_cpu_instance = nullptr; + +static FakeCpu& cpu() { + assert(g_fake_cpu_instance != nullptr); + return *g_fake_cpu_instance; +} extern "C" Leaf GetCpuidLeaf(uint32_t leaf_id, int ecx) { - return g_fake_cpu->GetCpuidLeaf(leaf_id, ecx); + return cpu().GetCpuidLeaf(leaf_id, ecx); } -extern "C" uint32_t GetXCR0Eax(void) { return g_fake_cpu->GetXCR0Eax(); } +extern "C" uint32_t GetXCR0Eax(void) { return cpu().GetXCR0Eax(); } #if defined(CPU_FEATURES_OS_DARWIN) extern "C" bool GetDarwinSysCtlByName(const char* name) { - return g_fake_cpu->GetDarwinSysCtlByName(name); + return cpu().GetDarwinSysCtlByName(name); } #endif // CPU_FEATURES_OS_DARWIN #if defined(CPU_FEATURES_OS_WINDOWS) extern "C" bool GetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature) { - return g_fake_cpu->GetWindowsIsProcessorFeaturePresent(ProcessorFeature); + return cpu().GetWindowsIsProcessorFeaturePresent(ProcessorFeature); } #endif // CPU_FEATURES_OS_WINDOWS @@ -103,13 +108,19 @@ class CpuidX86Test : public ::testing::Test { protected: - void SetUp() override { g_fake_cpu = new FakeCpu(); } - void TearDown() override { delete g_fake_cpu; } + void SetUp() override { + assert(g_fake_cpu_instance == nullptr); + g_fake_cpu_instance = new FakeCpu(); + } + void TearDown() override { + delete g_fake_cpu_instance; + g_fake_cpu_instance = nullptr; + } }; TEST_F(CpuidX86Test, SandyBridge) { - g_fake_cpu->SetOsBackupsExtendedRegisters(true); - g_fake_cpu->SetLeaves({ + cpu().SetOsBackupsExtendedRegisters(true); + cpu().SetLeaves({ {{0x00000000, 0}, Leaf{0x0000000D, 0x756E6547, 0x6C65746E, 0x49656E69}}, {{0x00000001, 0}, Leaf{0x000206A6, 0x00100800, 0x1F9AE3BF, 0xBFEBFBFF}}, {{0x00000007, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}}, @@ -151,26 +162,27 @@ EXPECT_FALSE(features.adx); } +const int UNDEF = -1; const int KiB = 1024; const int MiB = 1024 * KiB; TEST_F(CpuidX86Test, SandyBridgeTestOsSupport) { - g_fake_cpu->SetLeaves({ + cpu().SetLeaves({ {{0x00000000, 0}, Leaf{0x0000000D, 0x756E6547, 0x6C65746E, 0x49656E69}}, {{0x00000001, 0}, Leaf{0x000206A6, 0x00100800, 0x1F9AE3BF, 0xBFEBFBFF}}, {{0x00000007, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}}, }); // avx is disabled if os does not support backing up ymm registers. - g_fake_cpu->SetOsBackupsExtendedRegisters(false); + cpu().SetOsBackupsExtendedRegisters(false); EXPECT_FALSE(GetX86Info().features.avx); // avx is disabled if os does not support backing up ymm registers. - g_fake_cpu->SetOsBackupsExtendedRegisters(true); + cpu().SetOsBackupsExtendedRegisters(true); EXPECT_TRUE(GetX86Info().features.avx); } TEST_F(CpuidX86Test, SkyLake) { - g_fake_cpu->SetOsBackupsExtendedRegisters(true); - g_fake_cpu->SetLeaves({ + cpu().SetOsBackupsExtendedRegisters(true); + cpu().SetLeaves({ {{0x00000000, 0}, Leaf{0x00000016, 0x756E6547, 0x6C65746E, 0x49656E69}}, {{0x00000001, 0}, Leaf{0x000406E3, 0x00100800, 0x7FFAFBBF, 0xBFEBFBFF}}, {{0x00000007, 0}, Leaf{0x00000000, 0x029C67AF, 0x00000000, 0x00000000}}, @@ -184,7 +196,7 @@ } TEST_F(CpuidX86Test, Branding) { - g_fake_cpu->SetLeaves({ + cpu().SetLeaves({ {{0x00000000, 0}, Leaf{0x00000016, 0x756E6547, 0x6C65746E, 0x49656E69}}, {{0x00000001, 0}, Leaf{0x000406E3, 0x00100800, 0x7FFAFBBF, 0xBFEBFBFF}}, {{0x00000007, 0}, Leaf{0x00000000, 0x029C67AF, 0x00000000, 0x00000000}}, @@ -200,7 +212,7 @@ } TEST_F(CpuidX86Test, KabyLakeCache) { - g_fake_cpu->SetLeaves({ + cpu().SetLeaves({ {{0x00000000, 0}, Leaf{0x00000016, 0x756E6547, 0x6C65746E, 0x49656E69}}, {{0x00000001, 0}, Leaf{0x000406E3, 0x00100800, 0x7FFAFBBF, 0xBFEBFBFF}}, {{0x00000004, 0}, Leaf{0x1C004121, 0x01C0003F, 0x0000003F, 0x00000000}}, @@ -249,7 +261,7 @@ } TEST_F(CpuidX86Test, HSWCache) { - g_fake_cpu->SetLeaves({ + cpu().SetLeaves({ {{0x00000000, 0}, Leaf{0x00000016, 0x756E6547, 0x6C65746E, 0x49656E69}}, {{0x00000001, 0}, Leaf{0x000406E3, 0x00100800, 0x7FFAFBBF, 0xBFEBFBFF}}, {{0x00000004, 0}, Leaf{0x1C004121, 0x01C0003F, 0x0000003F, 0x00000000}}, @@ -297,9 +309,220 @@ EXPECT_EQ(info.levels[3].partitioning, 1); } +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0200F30_K11_Griffin_CPUID.txt +TEST_F(CpuidX86Test, AMD_K11_GRIFFIN) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x00000001, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00200F30, 0x00020800, 0x00002001, 0x178BFBFF}}, + {{0x80000000, 0}, Leaf{0x8000001A, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00200F30, 0x20000000, 0x0000131F, 0xEBD3FBFF}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x11); + EXPECT_EQ(info.model, 0x03); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_K11); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0300F10_K12_Llano_CPUID.txt +TEST_F(CpuidX86Test, AMD_K12_LLANO) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x00000006, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00300F10, 0x00040800, 0x00802009, 0x178BFBFF}}, + {{0x80000000, 0}, Leaf{0x8000001B, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00300F10, 0x20002B31, 0x000037FF, 0xEFD3FBFF}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x12); + EXPECT_EQ(info.model, 0x01); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_K12); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0500F01_K14_Bobcat_CPUID.txt +TEST_F(CpuidX86Test, AMD_K14_BOBCAT_AMD0500F01) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x00000006, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00500F01, 0x00020800, 0x00802209, 0x178BFBFF}}, + {{0x80000000, 0}, Leaf{0x8000001B, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00500F01, 0x00000000, 0x000035FF, 0x2FD3FBFF}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x14); + EXPECT_EQ(info.model, 0x00); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_BOBCAT); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0500F10_K14_Bobcat_CPUID.txt +TEST_F(CpuidX86Test, AMD_K14_BOBCAT_AMD0500F10) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x00000006, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00500F10, 0x00020800, 0x00802209, 0x178BFBFF}}, + {{0x00000002, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}}, + {{0x00000003, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}}, + {{0x00000005, 0}, Leaf{0x00000040, 0x00000040, 0x00000003, 0x00000000}}, + {{0x00000006, 0}, Leaf{0x00000000, 0x00000000, 0x00000001, 0x00000000}}, + {{0x80000000, 0}, Leaf{0x8000001B, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00500F10, 0x00001242, 0x000035FF, 0x2FD3FBFF}}, + {{0x80000002, 0}, Leaf{0x20444D41, 0x35332D45, 0x72502030, 0x7365636F}}, + {{0x80000003, 0}, Leaf{0x00726F73, 0x00000000, 0x00000000, 0x00000000}}, + {{0x80000004, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}}, + {{0x80000005, 0}, Leaf{0xFF08FF08, 0xFF280000, 0x20080140, 0x20020140}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x14); + EXPECT_EQ(info.model, 0x01); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_BOBCAT); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0500F20_K14_Bobcat_CPUID.txt +TEST_F(CpuidX86Test, AMD_K14_BOBCAT_AMD0500F20) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x00000006, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00500F20, 0x00020800, 0x00802209, 0x178BFBFF}}, + {{0x80000000, 0}, Leaf{0x8000001B, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00500F20, 0x000012E9, 0x000035FF, 0x2FD3FBFF}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x14); + EXPECT_EQ(info.model, 0x02); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_BOBCAT); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0670F00_K15_StoneyRidge_CPUID.txt +TEST_F(CpuidX86Test, AMD_K15_EXCAVATOR_STONEY_RIDGE) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00670F00, 0x00020800, 0x7ED8320B, 0x178BFBFF}}, + {{0x00000007, 0}, Leaf{0x00000000, 0x000001A9, 0x00000000, 0x00000000}}, + {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00670F00, 0x00000000, 0x2FABBFFF, 0x2FD3FBFF}}, + {{0x80000002, 0}, Leaf{0x20444D41, 0x392D3941, 0x20303134, 0x45444152}}, + {{0x80000003, 0}, Leaf{0x52204E4F, 0x35202C35, 0x4D4F4320, 0x45545550}}, + {{0x80000004, 0}, Leaf{0x524F4320, 0x32205345, 0x47332B43, 0x00202020}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x15); + EXPECT_EQ(info.model, 0x70); + EXPECT_EQ(GetX86Microarchitecture(&info), + X86Microarchitecture::AMD_EXCAVATOR); + + char brand_string[49]; + FillX86BrandString(brand_string); + EXPECT_STREQ(brand_string, "AMD A9-9410 RADEON R5, 5 COMPUTE CORES 2C+3G "); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0600F20_K15_AbuDhabi_CPUID0.txt +TEST_F(CpuidX86Test, AMD_K15_PILEDRIVER_ABU_DHABI) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00600F20, 0x00100800, 0x3E98320B, 0x178BFBFF}}, + {{0x00000007, 0}, Leaf{0x00000000, 0x00000008, 0x00000000, 0x00000000}}, + {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00600F20, 0x30000000, 0x01EBBFFF, 0x2FD3FBFF}}, + {{0x80000002, 0}, Leaf{0x20444D41, 0x6574704F, 0x286E6F72, 0x20296D74}}, + {{0x80000003, 0}, Leaf{0x636F7250, 0x6F737365, 0x33362072, 0x20203637}}, + {{0x80000004, 0}, Leaf{0x20202020, 0x20202020, 0x20202020, 0x00202020}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x15); + EXPECT_EQ(info.model, 0x02); + EXPECT_EQ(GetX86Microarchitecture(&info), + X86Microarchitecture::AMD_PILEDRIVER); + + char brand_string[49]; + FillX86BrandString(brand_string); + EXPECT_STREQ(brand_string, "AMD Opteron(tm) Processor 6376 "); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0600F20_K15_AbuDhabi_CPUID0.txt +TEST_F(CpuidX86Test, AMD_K15_PILEDRIVER_ABU_DHABI_CACHE_INFO) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00600F20, 0x00100800, 0x3E98320B, 0x178BFBFF}}, + {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00600F20, 0x30000000, 0x01EBBFFF, 0x2FD3FBFF}}, + {{0x8000001D, 0}, Leaf{0x00000121, 0x00C0003F, 0x0000003F, 0x00000000}}, + {{0x8000001D, 1}, Leaf{0x00004122, 0x0040003F, 0x000001FF, 0x00000000}}, + {{0x8000001D, 2}, Leaf{0x00004143, 0x03C0003F, 0x000007FF, 0x00000001}}, + {{0x8000001D, 3}, Leaf{0x0001C163, 0x0BC0003F, 0x000007FF, 0x00000001}}, + }); + const auto info = GetX86CacheInfo(); + + EXPECT_EQ(info.size, 4); + EXPECT_EQ(info.levels[0].level, 1); + EXPECT_EQ(info.levels[0].cache_type, 1); + EXPECT_EQ(info.levels[0].cache_size, 16 * KiB); + EXPECT_EQ(info.levels[0].ways, 4); + EXPECT_EQ(info.levels[0].line_size, 64); + EXPECT_EQ(info.levels[0].tlb_entries, 64); + EXPECT_EQ(info.levels[0].partitioning, 1); + + EXPECT_EQ(info.levels[1].level, 1); + EXPECT_EQ(info.levels[1].cache_type, 2); + EXPECT_EQ(info.levels[1].cache_size, 64 * KiB); + EXPECT_EQ(info.levels[1].ways, 2); + EXPECT_EQ(info.levels[1].line_size, 64); + EXPECT_EQ(info.levels[1].tlb_entries, 512); + EXPECT_EQ(info.levels[1].partitioning, 1); + + EXPECT_EQ(info.levels[2].level, 2); + EXPECT_EQ(info.levels[2].cache_type, 3); + EXPECT_EQ(info.levels[2].cache_size, 2 * MiB); + EXPECT_EQ(info.levels[2].ways, 16); + EXPECT_EQ(info.levels[2].line_size, 64); + EXPECT_EQ(info.levels[2].tlb_entries, 2048); + EXPECT_EQ(info.levels[2].partitioning, 1); + + EXPECT_EQ(info.levels[3].level, 3); + EXPECT_EQ(info.levels[3].cache_type, 3); + EXPECT_EQ(info.levels[3].cache_size, 6 * MiB); + EXPECT_EQ(info.levels[3].ways, 48); + EXPECT_EQ(info.levels[3].line_size, 64); + EXPECT_EQ(info.levels[3].tlb_entries, 2048); + EXPECT_EQ(info.levels[3].partitioning, 1); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0600F12_K15_Interlagos_CPUID3.txt +TEST_F(CpuidX86Test, AMD_K15_BULLDOZER_INTERLAGOS) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00600F12, 0x000C0800, 0x1E98220B, 0x178BFBFF}}, + {{0x00000007, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}}, + {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00600F12, 0x30000000, 0x01C9BFFF, 0x2FD3FBFF}}, + {{0x80000002, 0}, Leaf{0x20444D41, 0x6574704F, 0x286E6F72, 0x20294D54}}, + {{0x80000003, 0}, Leaf{0x636F7250, 0x6F737365, 0x32362072, 0x20203833}}, + {{0x80000004, 0}, Leaf{0x20202020, 0x20202020, 0x20202020, 0x00202020}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x15); + EXPECT_EQ(info.model, 0x01); + EXPECT_EQ(GetX86Microarchitecture(&info), + X86Microarchitecture::AMD_BULLDOZER); + + char brand_string[49]; + FillX86BrandString(brand_string); + EXPECT_STREQ(brand_string, "AMD Opteron(TM) Processor 6238 "); +} + // http://users.atw.hu/instlatx64/AuthenticAMD0630F81_K15_Godavari_CPUID.txt -TEST_F(CpuidX86Test, AMD_K15) { - g_fake_cpu->SetLeaves({ +TEST_F(CpuidX86Test, AMD_K15_STREAMROLLER_GODAVARI) { + cpu().SetLeaves({ {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}}, {{0x00000001, 0}, Leaf{0x00630F81, 0x00040800, 0x3E98320B, 0x178BFBFF}}, {{0x00000007, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}}, @@ -317,40 +540,261 @@ EXPECT_EQ(info.model, 0x38); EXPECT_EQ(info.stepping, 0x01); EXPECT_EQ(GetX86Microarchitecture(&info), - X86Microarchitecture::AMD_BULLDOZER); + X86Microarchitecture::AMD_STREAMROLLER); char brand_string[49]; FillX86BrandString(brand_string); EXPECT_STREQ(brand_string, "AMD A8-7670K Radeon R7, 10 Compute Cores 4C+6G "); } +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0700F01_K16_Kabini_CPUID.txt +TEST_F(CpuidX86Test, AMD_K16_JAGUAR_KABINI) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00700F01, 0x00040800, 0x3ED8220B, 0x178BFBFF}}, + {{0x00000007, 0}, Leaf{0x00000000, 0x00000008, 0x00000000, 0x00000000}}, + {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00700F01, 0x00000000, 0x154037FF, 0x2FD3FBFF}}, + {{0x80000002, 0}, Leaf{0x20444D41, 0x352D3441, 0x20303030, 0x20555041}}, + {{0x80000003, 0}, Leaf{0x68746977, 0x64615220, 0x286E6F65, 0x20294D54}}, + {{0x80000004, 0}, Leaf{0x47204448, 0x68706172, 0x20736369, 0x00202020}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x16); + EXPECT_EQ(info.model, 0x00); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_JAGUAR); + + char brand_string[49]; + FillX86BrandString(brand_string); + EXPECT_STREQ(brand_string, "AMD A4-5000 APU with Radeon(TM) HD Graphics "); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0730F01_K16_Beema_CPUID2.txt +TEST_F(CpuidX86Test, AMD_K16_PUMA_BEEMA) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00730F01, 0x00040800, 0x7ED8220B, 0x178BFBFF}}, + {{0x00000007, 0}, Leaf{0x00000000, 0x00000008, 0x00000000, 0x00000000}}, + {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00730F01, 0x00000000, 0x1D4037FF, 0x2FD3FBFF}}, + {{0x80000002, 0}, Leaf{0x20444D41, 0x362D3641, 0x20303133, 0x20555041}}, + {{0x80000003, 0}, Leaf{0x68746977, 0x444D4120, 0x64615220, 0x206E6F65}}, + {{0x80000004, 0}, Leaf{0x47203452, 0x68706172, 0x20736369, 0x00202020}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x16); + EXPECT_EQ(info.model, 0x30); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_PUMA); + + char brand_string[49]; + FillX86BrandString(brand_string); + EXPECT_STREQ(brand_string, "AMD A6-6310 APU with AMD Radeon R4 Graphics "); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0820F01_K17_Dali_CPUID.txt +TEST_F(CpuidX86Test, AMD_K17_ZEN_DALI) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00820F01, 0x00020800, 0x7ED8320B, 0x178BFBFF}}, + {{0x00000007, 0}, Leaf{0x00000000, 0x209C01A9, 0x00000000, 0x00000000}}, + {{0x80000000, 0}, Leaf{0x8000001F, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00820F01, 0x00000000, 0x35C233FF, 0x2FD3FBFF}}, + {{0x80000002, 0}, Leaf{0x20444D41, 0x30323033, 0x69772065, 0x52206874}}, + {{0x80000003, 0}, Leaf{0x6F656461, 0x7247206E, 0x69687061, 0x20207363}}, + {{0x80000004, 0}, Leaf{0x20202020, 0x20202020, 0x20202020, 0x00202020}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x17); + EXPECT_EQ(info.model, 0x20); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_ZEN); + + char brand_string[49]; + FillX86BrandString(brand_string); + EXPECT_STREQ(brand_string, "AMD 3020e with Radeon Graphics "); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0800F82_K17_ZenP_CPUID.txt +TEST_F(CpuidX86Test, AMD_K17_ZEN_PLUS_PINNACLE_RIDGE) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00800F82, 0x00100800, 0x7ED8320B, 0x178BFBFF}}, + {{0x00000007, 0}, Leaf{0x00000000, 0x209C01A9, 0x00000000, 0x00000000}}, + {{0x80000000, 0}, Leaf{0x8000001F, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00800F82, 0x20000000, 0x35C233FF, 0x2FD3FBFF}}, + {{0x80000002, 0}, Leaf{0x20444D41, 0x657A7952, 0x2037206E, 0x30303732}}, + {{0x80000003, 0}, Leaf{0x69452058, 0x2D746867, 0x65726F43, 0x6F725020}}, + {{0x80000004, 0}, Leaf{0x73736563, 0x2020726F, 0x20202020, 0x00202020}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x17); + EXPECT_EQ(info.model, 0x08); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_ZEN_PLUS); + + char brand_string[49]; + FillX86BrandString(brand_string); + EXPECT_STREQ(brand_string, "AMD Ryzen 7 2700X Eight-Core Processor "); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0840F70_K17_CPUID.txt +TEST_F(CpuidX86Test, AMD_K17_ZEN2_XBOX_SERIES_X) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x00000010, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00840F70, 0x00100800, 0x7ED8320B, 0x178BFBFF}}, + {{0x00000007, 0}, Leaf{0x00000000, 0x219C91A9, 0x00400004, 0x00000000}}, + {{0x80000000, 0}, Leaf{0x80000020, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00840F70, 0x00000000, 0xF5C2B7FF, 0x2FD3FBFF}}, + {{0x80000002, 0}, Leaf{0x20444D41, 0x30303734, 0x2D382053, 0x65726F43}}, + {{0x80000003, 0}, Leaf{0x6F725020, 0x73736563, 0x4420726F, 0x746B7365}}, + {{0x80000004, 0}, Leaf{0x4B20706F, 0x00007469, 0x00000000, 0x00000000}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x17); + EXPECT_EQ(info.model, 0x47); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_ZEN2); + + char brand_string[49]; + FillX86BrandString(brand_string); + EXPECT_STREQ(brand_string, "AMD 4700S 8-Core Processor Desktop Kit"); +} + +// http://users.atw.hu/instlatx64/HygonGenuine/HygonGenuine0900F02_Hygon_CPUID3.txt +TEST_F(CpuidX86Test, AMD_K18_ZEN_DHYANA) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x0000000D, 0x6F677948, 0x656E6975, 0x6E65476E}}, + {{0x00000001, 0}, Leaf{0x00900F02, 0x00100800, 0x74D83209, 0x178BFBFF}}, + {{0x00000007, 0}, Leaf{0x00000000, 0x009C01A9, 0x0040068C, 0x00000000}}, + {{0x80000000, 0}, Leaf{0x8000001F, 0x6F677948, 0x656E6975, 0x6E65476E}}, + {{0x80000001, 0}, Leaf{0x00900F02, 0x60000000, 0x35C233FF, 0x2FD3FBFF}}, + {{0x80000002, 0}, Leaf{0x6F677948, 0x3843206E, 0x31332036, 0x20203538}}, + {{0x80000003, 0}, Leaf{0x6F632D38, 0x50206572, 0x65636F72, 0x726F7373}}, + {{0x80000004, 0}, Leaf{0x20202020, 0x20202020, 0x20202020, 0x00202020}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "HygonGenuine"); + EXPECT_EQ(info.family, 0x18); + EXPECT_EQ(info.model, 0x00); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_ZEN); + + char brand_string[49]; + FillX86BrandString(brand_string); + EXPECT_STREQ(brand_string, "Hygon C86 3185 8-core Processor "); +} + +// http://users.atw.hu/instlatx64/HygonGenuine/HygonGenuine0900F02_Hygon_CPUID.txt +TEST_F(CpuidX86Test, AMD_K18_ZEN_DHYANA_CACHE_INFO) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x0000000D, 0x6F677948, 0x656E6975, 0x6E65476E}}, + {{0x00000001, 0}, Leaf{0x00900F02, 0x00100800, 0x74D83209, 0x178BFBFF}}, + {{0x80000000, 0}, Leaf{0x8000001F, 0x6F677948, 0x656E6975, 0x6E65476E}}, + {{0x80000001, 0}, Leaf{0x00900F02, 0x60000000, 0x35C233FF, 0x2FD3FBFF}}, + {{0x8000001D, 0}, Leaf{0x00004121, 0x01C0003F, 0x0000003F, 0x00000000}}, + {{0x8000001D, 1}, Leaf{0x00004122, 0x00C0003F, 0x000000FF, 0x00000000}}, + {{0x8000001D, 2}, Leaf{0x00004143, 0x01C0003F, 0x000003FF, 0x00000002}}, + {{0x8000001D, 3}, Leaf{0x0001C163, 0x03C0003F, 0x00001FFF, 0x00000001}}, + }); + const auto info = GetX86CacheInfo(); + + EXPECT_EQ(info.size, 4); + EXPECT_EQ(info.levels[0].level, 1); + EXPECT_EQ(info.levels[0].cache_type, 1); + EXPECT_EQ(info.levels[0].cache_size, 32 * KiB); + EXPECT_EQ(info.levels[0].ways, 8); + EXPECT_EQ(info.levels[0].line_size, 64); + EXPECT_EQ(info.levels[0].tlb_entries, 64); + EXPECT_EQ(info.levels[0].partitioning, 1); + + EXPECT_EQ(info.levels[1].level, 1); + EXPECT_EQ(info.levels[1].cache_type, 2); + EXPECT_EQ(info.levels[1].cache_size, 64 * KiB); + EXPECT_EQ(info.levels[1].ways, 4); + EXPECT_EQ(info.levels[1].line_size, 64); + EXPECT_EQ(info.levels[1].tlb_entries, 256); + EXPECT_EQ(info.levels[1].partitioning, 1); + + EXPECT_EQ(info.levels[2].level, 2); + EXPECT_EQ(info.levels[2].cache_type, 3); + EXPECT_EQ(info.levels[2].cache_size, 512 * KiB); + EXPECT_EQ(info.levels[2].ways, 8); + EXPECT_EQ(info.levels[2].line_size, 64); + EXPECT_EQ(info.levels[2].tlb_entries, 1024); + EXPECT_EQ(info.levels[2].partitioning, 1); + + EXPECT_EQ(info.levels[3].level, 3); + EXPECT_EQ(info.levels[3].cache_type, 3); + EXPECT_EQ(info.levels[3].cache_size, 8 * MiB); + EXPECT_EQ(info.levels[3].ways, 16); + EXPECT_EQ(info.levels[3].line_size, 64); + EXPECT_EQ(info.levels[3].tlb_entries, 8192); + EXPECT_EQ(info.levels[3].partitioning, 1); +} + +// http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0A20F10_K19_Vermeer2_CPUID.txt +TEST_F(CpuidX86Test, AMD_K19_ZEN3_VERMEER) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x00000010, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x00000001, 0}, Leaf{0x00A20F10, 0x01180800, 0x7ED8320B, 0x178BFBFF}}, + {{0x00000007, 0}, Leaf{0x00000000, 0x219C97A9, 0x0040068C, 0x00000000}}, + {{0x80000000, 0}, Leaf{0x80000023, 0x68747541, 0x444D4163, 0x69746E65}}, + {{0x80000001, 0}, Leaf{0x00A20F10, 0x20000000, 0x75C237FF, 0x2FD3FBFF}}, + {{0x80000002, 0}, Leaf{0x20444D41, 0x657A7952, 0x2039206E, 0x30303935}}, + {{0x80000003, 0}, Leaf{0x32312058, 0x726F432D, 0x72502065, 0x7365636F}}, + {{0x80000004, 0}, Leaf{0x20726F73, 0x20202020, 0x20202020, 0x00202020}}, + }); + const auto info = GetX86Info(); + + EXPECT_STREQ(info.vendor, "AuthenticAMD"); + EXPECT_EQ(info.family, 0x19); + EXPECT_EQ(info.model, 0x21); + EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_ZEN3); + + char brand_string[49]; + FillX86BrandString(brand_string); + EXPECT_STREQ(brand_string, "AMD Ryzen 9 5900X 12-Core Processor "); +} + // https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel00106A1_Nehalem_CPUID.txt TEST_F(CpuidX86Test, Nehalem) { // Pre AVX cpus don't have xsave - g_fake_cpu->SetOsBackupsExtendedRegisters(false); + cpu().SetOsBackupsExtendedRegisters(false); #if defined(CPU_FEATURES_OS_WINDOWS) - g_fake_cpu->SetWindowsIsProcessorFeaturePresent( - PF_XMMI_INSTRUCTIONS_AVAILABLE); - g_fake_cpu->SetWindowsIsProcessorFeaturePresent( - PF_XMMI64_INSTRUCTIONS_AVAILABLE); - g_fake_cpu->SetWindowsIsProcessorFeaturePresent( - PF_SSE3_INSTRUCTIONS_AVAILABLE); -#endif // CPU_FEATURES_OS_WINDOWS -#if defined(CPU_FEATURES_OS_DARWIN) - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.sse"); - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.sse2"); - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.sse3"); - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.supplementalsse3"); - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.sse4_1"); - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.sse4_2"); -#endif // CPU_FEATURES_OS_DARWIN -#if defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) + cpu().SetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE); + cpu().SetWindowsIsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE); + cpu().SetWindowsIsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE); +#elif defined(CPU_FEATURES_OS_DARWIN) + cpu().SetDarwinSysCtlByName("hw.optional.sse"); + cpu().SetDarwinSysCtlByName("hw.optional.sse2"); + cpu().SetDarwinSysCtlByName("hw.optional.sse3"); + cpu().SetDarwinSysCtlByName("hw.optional.supplementalsse3"); + cpu().SetDarwinSysCtlByName("hw.optional.sse4_1"); + cpu().SetDarwinSysCtlByName("hw.optional.sse4_2"); +#elif defined(CPU_FEATURES_OS_FREEBSD) + auto& fs = GetEmptyFilesystem(); + fs.CreateFile("/var/run/dmesg.boot", R"( + ---<>--- +Copyright (c) 1992-2020 The FreeBSD Project. +FreeBSD is a registered trademark of The FreeBSD Foundation. + Features=0x1783fbff + Features2=0x5eda2203 +real memory = 2147418112 (2047 MB) +)"); +#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"(processor : flags : fpu mmx sse sse2 sse3 ssse3 sse4_1 sse4_2 )"); -#endif // CPU_FEATURES_OS_LINUX_OR_ANDROID - g_fake_cpu->SetLeaves({ +#endif + cpu().SetLeaves({ {{0x00000000, 0}, Leaf{0x0000000B, 0x756E6547, 0x6C65746E, 0x49656E69}}, {{0x00000001, 0}, Leaf{0x000106A2, 0x00100800, 0x00BCE3BD, 0xBFEBFBFF}}, {{0x00000002, 0}, Leaf{0x55035A01, 0x00F0B0E3, 0x00000000, 0x09CA212C}}, @@ -392,42 +836,47 @@ EXPECT_TRUE(info.features.sse); EXPECT_TRUE(info.features.sse2); EXPECT_TRUE(info.features.sse3); -#ifndef CPU_FEATURES_OS_WINDOWS +#if !defined(CPU_FEATURES_OS_WINDOWS) // Currently disabled on Windows as IsProcessorFeaturePresent do not support // feature detection > sse3. EXPECT_TRUE(info.features.ssse3); EXPECT_TRUE(info.features.sse4_1); EXPECT_TRUE(info.features.sse4_2); -#endif // CPU_FEATURES_OS_WINDOWS +#endif // !defined(CPU_FEATURES_OS_WINDOWS) } // https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0030673_Silvermont3_CPUID.txt TEST_F(CpuidX86Test, Atom) { // Pre AVX cpus don't have xsave - g_fake_cpu->SetOsBackupsExtendedRegisters(false); + cpu().SetOsBackupsExtendedRegisters(false); #if defined(CPU_FEATURES_OS_WINDOWS) - g_fake_cpu->SetWindowsIsProcessorFeaturePresent( - PF_XMMI_INSTRUCTIONS_AVAILABLE); - g_fake_cpu->SetWindowsIsProcessorFeaturePresent( - PF_XMMI64_INSTRUCTIONS_AVAILABLE); - g_fake_cpu->SetWindowsIsProcessorFeaturePresent( - PF_SSE3_INSTRUCTIONS_AVAILABLE); -#endif // CPU_FEATURES_OS_WINDOWS -#if defined(CPU_FEATURES_OS_DARWIN) - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.sse"); - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.sse2"); - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.sse3"); - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.supplementalsse3"); - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.sse4_1"); - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.sse4_2"); -#endif // CPU_FEATURES_OS_DARWIN -#if defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) + cpu().SetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE); + cpu().SetWindowsIsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE); + cpu().SetWindowsIsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE); +#elif defined(CPU_FEATURES_OS_DARWIN) + cpu().SetDarwinSysCtlByName("hw.optional.sse"); + cpu().SetDarwinSysCtlByName("hw.optional.sse2"); + cpu().SetDarwinSysCtlByName("hw.optional.sse3"); + cpu().SetDarwinSysCtlByName("hw.optional.supplementalsse3"); + cpu().SetDarwinSysCtlByName("hw.optional.sse4_1"); + cpu().SetDarwinSysCtlByName("hw.optional.sse4_2"); +#elif defined(CPU_FEATURES_OS_FREEBSD) + auto& fs = GetEmptyFilesystem(); + fs.CreateFile("/var/run/dmesg.boot", R"( + ---<>--- +Copyright (c) 1992-2020 The FreeBSD Project. +FreeBSD is a registered trademark of The FreeBSD Foundation. + Features=0x1783fbff + Features2=0x5eda2203 +real memory = 2147418112 (2047 MB) +)"); +#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"( flags : fpu mmx sse sse2 sse3 ssse3 sse4_1 sse4_2 )"); -#endif // CPU_FEATURES_OS_LINUX_OR_ANDROID - g_fake_cpu->SetLeaves({ +#endif + cpu().SetLeaves({ {{0x00000000, 0}, Leaf{0x0000000B, 0x756E6547, 0x6C65746E, 0x49656E69}}, {{0x00000001, 0}, Leaf{0x00030673, 0x00100800, 0x41D8E3BF, 0xBFEBFBFF}}, {{0x00000002, 0}, Leaf{0x61B3A001, 0x0000FFC2, 0x00000000, 0x00000000}}, @@ -469,33 +918,91 @@ EXPECT_TRUE(info.features.sse); EXPECT_TRUE(info.features.sse2); EXPECT_TRUE(info.features.sse3); -#ifndef CPU_FEATURES_OS_WINDOWS +#if !defined(CPU_FEATURES_OS_WINDOWS) // Currently disabled on Windows as IsProcessorFeaturePresent do not support // feature detection > sse3. EXPECT_TRUE(info.features.ssse3); EXPECT_TRUE(info.features.sse4_1); EXPECT_TRUE(info.features.sse4_2); -#endif // CPU_FEATURES_OS_WINDOWS +#endif // !defined(CPU_FEATURES_OS_WINDOWS) +} + +// https://www.felixcloutier.com/x86/cpuid#example-3-1--example-of-cache-and-tlb-interpretation +TEST_F(CpuidX86Test, P4_CacheInfo) { + cpu().SetLeaves({ + {{0x00000000, 0}, Leaf{0x00000002, 0x756E6547, 0x6C65746E, 0x49656E69}}, + {{0x00000001, 0}, Leaf{0x00000F0A, 0x00010808, 0x00000000, 0x3FEBFBFF}}, + {{0x00000002, 0}, Leaf{0x665B5001, 0x00000000, 0x00000000, 0x007A7000}}, + }); + + const auto info = GetX86CacheInfo(); + EXPECT_EQ(info.size, 5); + + EXPECT_EQ(info.levels[0].level, UNDEF); + EXPECT_EQ(info.levels[0].cache_type, CPU_FEATURE_CACHE_TLB); + EXPECT_EQ(info.levels[0].cache_size, 4 * KiB); + EXPECT_EQ(info.levels[0].ways, UNDEF); + EXPECT_EQ(info.levels[0].line_size, UNDEF); + EXPECT_EQ(info.levels[0].tlb_entries, 64); + EXPECT_EQ(info.levels[0].partitioning, 0); + + EXPECT_EQ(info.levels[1].level, UNDEF); + EXPECT_EQ(info.levels[1].cache_type, CPU_FEATURE_CACHE_TLB); + EXPECT_EQ(info.levels[1].cache_size, 4 * KiB); + EXPECT_EQ(info.levels[1].ways, UNDEF); + EXPECT_EQ(info.levels[1].line_size, UNDEF); + EXPECT_EQ(info.levels[1].tlb_entries, 64); + EXPECT_EQ(info.levels[1].partitioning, 0); + + EXPECT_EQ(info.levels[2].level, 1); + EXPECT_EQ(info.levels[2].cache_type, CPU_FEATURE_CACHE_DATA); + EXPECT_EQ(info.levels[2].cache_size, 8 * KiB); + EXPECT_EQ(info.levels[2].ways, 4); + EXPECT_EQ(info.levels[2].line_size, 64); + EXPECT_EQ(info.levels[2].tlb_entries, UNDEF); + EXPECT_EQ(info.levels[2].partitioning, 0); + + EXPECT_EQ(info.levels[3].level, 1); + EXPECT_EQ(info.levels[3].cache_type, CPU_FEATURE_CACHE_INSTRUCTION); + EXPECT_EQ(info.levels[3].cache_size, 12 * KiB); + EXPECT_EQ(info.levels[3].ways, 8); + EXPECT_EQ(info.levels[3].line_size, UNDEF); + EXPECT_EQ(info.levels[3].tlb_entries, UNDEF); + EXPECT_EQ(info.levels[3].partitioning, 0); + + EXPECT_EQ(info.levels[4].level, 2); + EXPECT_EQ(info.levels[4].cache_type, CPU_FEATURE_CACHE_DATA); + EXPECT_EQ(info.levels[4].cache_size, 256 * KiB); + EXPECT_EQ(info.levels[4].ways, 8); + EXPECT_EQ(info.levels[4].line_size, 64); + EXPECT_EQ(info.levels[4].tlb_entries, UNDEF); + EXPECT_EQ(info.levels[4].partitioning, 2); } // https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0000673_P3_KatmaiDP_CPUID.txt TEST_F(CpuidX86Test, P3) { // Pre AVX cpus don't have xsave - g_fake_cpu->SetOsBackupsExtendedRegisters(false); + cpu().SetOsBackupsExtendedRegisters(false); #if defined(CPU_FEATURES_OS_WINDOWS) - g_fake_cpu->SetWindowsIsProcessorFeaturePresent( - PF_XMMI_INSTRUCTIONS_AVAILABLE); -#endif // CPU_FEATURES_OS_WINDOWS -#if defined(CPU_FEATURES_OS_DARWIN) - g_fake_cpu->SetDarwinSysCtlByName("hw.optional.sse"); -#endif // CPU_FEATURES_OS_DARWIN -#if defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) + cpu().SetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE); +#elif defined(CPU_FEATURES_OS_DARWIN) + cpu().SetDarwinSysCtlByName("hw.optional.sse"); +#elif defined(CPU_FEATURES_OS_FREEBSD) + auto& fs = GetEmptyFilesystem(); + fs.CreateFile("/var/run/dmesg.boot", R"( + ---<>--- +Copyright (c) 1992-2020 The FreeBSD Project. +FreeBSD is a registered trademark of The FreeBSD Foundation. + Features=0x1783fbff +real memory = 2147418112 (2047 MB) +)"); +#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) auto& fs = GetEmptyFilesystem(); fs.CreateFile("/proc/cpuinfo", R"( flags : fpu mmx sse )"); -#endif // CPU_FEATURES_OS_LINUX_OR_ANDROID - g_fake_cpu->SetLeaves({ +#endif + cpu().SetLeaves({ {{0x00000000, 0}, Leaf{0x00000003, 0x756E6547, 0x6C65746E, 0x49656E69}}, {{0x00000001, 0}, Leaf{0x00000673, 0x00000000, 0x00000000, 0x0387FBFF}}, {{0x00000002, 0}, Leaf{0x03020101, 0x00000000, 0x00000000, 0x0C040843}}, @@ -517,13 +1024,13 @@ EXPECT_TRUE(info.features.sse); EXPECT_FALSE(info.features.sse2); EXPECT_FALSE(info.features.sse3); -#ifndef CPU_FEATURES_OS_WINDOWS +#if !defined(CPU_FEATURES_OS_WINDOWS) // Currently disabled on Windows as IsProcessorFeaturePresent do not support // feature detection > sse3. EXPECT_FALSE(info.features.ssse3); EXPECT_FALSE(info.features.sse4_1); EXPECT_FALSE(info.features.sse4_2); -#endif // CPU_FEATURES_OS_WINDOWS +#endif // !defined(CPU_FEATURES_OS_WINDOWS) } // TODO(user): test what happens when xsave/osxsave are not present. diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/hwcaps_for_testing.cc softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/hwcaps_for_testing.cc --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/hwcaps_for_testing.cc 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/hwcaps_for_testing.cc 2021-10-25 20:43:15.000000000 +0000 @@ -22,25 +22,31 @@ namespace { static auto* const g_hardware_capabilities = new HardwareCapabilities(); -static auto* const g_platform_types = new PlatformType(); +static const char* g_platform_pointer = nullptr; +static const char* g_base_platform_pointer = nullptr; } // namespace void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2) { g_hardware_capabilities->hwcaps = hwcaps; g_hardware_capabilities->hwcaps2 = hwcaps2; } +void SetPlatformPointer(const char* string) { g_platform_pointer = string; } +void SetBasePlatformPointer(const char* string) { + g_base_platform_pointer = string; +} + +void ResetHwcaps() { + SetHardwareCapabilities(0, 0); + SetPlatformPointer(nullptr); + SetBasePlatformPointer(nullptr); +} HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) { return *g_hardware_capabilities; } - -void SetPlatformTypes(const char* platform, const char* base_platform) { - CpuFeatures_StringView_CopyString(str(platform), g_platform_types->platform, - sizeof(g_platform_types->platform)); - CpuFeatures_StringView_CopyString(str(base_platform), - g_platform_types->base_platform, - sizeof(g_platform_types->base_platform)); +const char* CpuFeatures_GetPlatformPointer(void) { return g_platform_pointer; } +const char* CpuFeatures_GetBasePlatformPointer(void) { + return g_base_platform_pointer; } -PlatformType CpuFeatures_GetPlatformType(void) { return *g_platform_types; } } // namespace cpu_features diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/hwcaps_for_testing.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/hwcaps_for_testing.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/hwcaps_for_testing.h 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/hwcaps_for_testing.h 2021-10-25 20:43:15.000000000 +0000 @@ -20,7 +20,11 @@ namespace cpu_features { void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2); -void SetPlatformTypes(const char *platform, const char *base_platform); +void SetPlatformPointer(const char* string); +void SetBasePlatformPointer(const char* string); + +// To be called before each test. +void ResetHwcaps(); } // namespace cpu_features diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/string_view_test.cc softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/string_view_test.cc --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/string_view_test.cc 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/test/string_view_test.cc 2021-10-25 20:43:15.000000000 +0000 @@ -163,15 +163,25 @@ TEST(StringViewTest, CpuFeatures_StringView_HasWord) { // Find flags at beginning, middle and end. EXPECT_TRUE( - CpuFeatures_StringView_HasWord(str("first middle last"), "first")); + CpuFeatures_StringView_HasWord(str("first middle last"), "first", ' ')); EXPECT_TRUE( - CpuFeatures_StringView_HasWord(str("first middle last"), "middle")); - EXPECT_TRUE(CpuFeatures_StringView_HasWord(str("first middle last"), "last")); + CpuFeatures_StringView_HasWord(str("first middle last"), "middle", ' ')); + EXPECT_TRUE( + CpuFeatures_StringView_HasWord(str("first middle last"), "last", ' ')); + // Find flags at beginning, middle and end with a different separator + EXPECT_TRUE( + CpuFeatures_StringView_HasWord(str("first-middle-last"), "first", '-')); + EXPECT_TRUE( + CpuFeatures_StringView_HasWord(str("first-middle-last"), "middle", '-')); + EXPECT_TRUE( + CpuFeatures_StringView_HasWord(str("first-middle-last"), "last", '-')); // Do not match partial flags EXPECT_FALSE( - CpuFeatures_StringView_HasWord(str("first middle last"), "irst")); - EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "mid")); - EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "las")); + CpuFeatures_StringView_HasWord(str("first middle last"), "irst", ' ')); + EXPECT_FALSE( + CpuFeatures_StringView_HasWord(str("first middle last"), "mid", ' ')); + EXPECT_FALSE( + CpuFeatures_StringView_HasWord(str("first middle last"), "las", ' ')); } TEST(StringViewTest, CpuFeatures_StringView_GetAttributeKeyValue) { diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/WORKSPACE softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/WORKSPACE --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/WORKSPACE 2021-05-25 01:25:17.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/3rdparty/cpu_features/WORKSPACE 1970-01-01 00:00:00.000000000 +0000 @@ -1,7 +0,0 @@ -# ===== googletest ===== - -git_repository( - name = "com_google_googletest", - remote = "https://github.com/google/googletest.git", - commit = "c3f65335b79f47b05629e79a54685d899bc53b93", -) diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/CMakeLists.txt softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/CMakeLists.txt --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/CMakeLists.txt 2021-05-25 01:25:09.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/CMakeLists.txt 2021-10-25 20:43:04.000000000 +0000 @@ -22,7 +22,13 @@ # Required because we include in Encrypt.h. target_include_directories(mayaqua PUBLIC ${OPENSSL_INCLUDE_DIR}) -target_link_libraries(mayaqua PRIVATE OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB) +target_link_libraries(mayaqua + PRIVATE + libhamcore + OpenSSL::SSL + OpenSSL::Crypto + ZLIB::ZLIB +) if(WIN32) set_target_properties(mayaqua diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/FileIO.c softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/FileIO.c --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/FileIO.c 2021-05-25 01:25:09.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/FileIO.c 2021-10-25 20:43:04.000000000 +0000 @@ -18,10 +18,12 @@ #include "Unix.h" #include "Win32.h" +#include + static char exe_file_name[MAX_SIZE] = "/tmp/a.out"; static wchar_t exe_file_name_w[MAX_SIZE] = L"/tmp/a.out"; static LIST *hamcore = NULL; -static IO *hamcore_io = NULL; +static HAMCORE *hamcore_io = NULL; #define NUM_CRC32_TABLE 256 static UINT crc32_table[NUM_CRC32_TABLE]; @@ -554,25 +556,6 @@ return true; } -// Rename to replace the file -bool FileReplaceRenameW(wchar_t *old_name, wchar_t *new_name) -{ - // Validate arguments - if (old_name == NULL || new_name == NULL) - { - return false; - } - - if (FileCopyW(old_name, new_name) == false) - { - return false; - } - - FileDeleteW(old_name); - - return true; -} - // Make the file name safe void ConvertSafeFileName(char *dst, UINT size, char *src) { @@ -735,244 +718,135 @@ } BUF *ReadHamcore(char *name) { - wchar_t tmp[MAX_SIZE]; - wchar_t exe_dir[MAX_SIZE]; - BUF *b; - char filename[MAX_PATH]; - // Validate arguments - if (name == NULL) + if (name == NULL || MayaquaIsMinimalMode()) { return NULL; } - if (name[0] == '|') + if (name[0] == '/') { - name++; + ++name; } - if (name[0] == '/' || name[0] == '\\') - { - name++; - } - - StrCpy(filename, sizeof(filename), name); - - ReplaceStrEx(filename, sizeof(filename), filename, "/", "\\", true); + char path[MAX_PATH]; + GetExeDir(path, sizeof(path)); + Format(path, sizeof(path), "%s/%s/%s", path, HAMCORE_DIR_NAME, name); - if (MayaquaIsMinimalMode()) + BUF *buf = ReadDump(path); + if (buf != NULL) { - return NULL; + return buf; } - // If the file exist in hamcore/ directory on the local disk, read it - GetExeDirW(exe_dir, sizeof(exe_dir)); - - UniFormat(tmp, sizeof(tmp), L"%s/%S/%S", exe_dir, HAMCORE_DIR_NAME, filename); - - b = ReadDumpW(tmp); - if (b != NULL) - { - return b; - } - - // Search from HamCore file system if it isn't found LockList(hamcore); { - HC t, *c; - UINT i; - - Zero(&t, sizeof(t)); - t.FileName = filename; - c = Search(hamcore, &t); - + HC t = {0}; + t.Path = name; + HC *c = Search(hamcore, &t); if (c == NULL) { - // File does not exist - b = NULL; - } - else - { - // File exists - if (c->Buffer != NULL) + const HAMCORE_FILE *file = HamcoreFind(hamcore_io, name); + if (file) { - // It is already loaded - b = NewBuf(); - WriteBuf(b, c->Buffer, c->Size); - SeekBuf(b, 0, 0); - c->LastAccess = Tick64(); - } - else - { - // Read from a file is if it is not read - if (FileSeek(hamcore_io, 0, c->Offset) == false) + c = Malloc(sizeof(HC)); + c->Size = file->OriginalSize; + c->Path = CopyStr(name); + c->Buffer = Malloc(c->Size); + + if (HamcoreRead(hamcore_io, c->Buffer, file)) { - // Failed to seek - b = NULL; + Add(hamcore, c); } else { - // Read the compressed data - void *data = Malloc(c->SizeCompressed); - if (FileRead(hamcore_io, data, c->SizeCompressed) == false) - { - // Failed to read - Free(data); - b = NULL; - } - else - { - // Expand - c->Buffer = ZeroMalloc(c->Size); - if (Uncompress(c->Buffer, c->Size, data, c->SizeCompressed) != c->Size) - { - // Failed to expand - Free(data); - Free(c->Buffer); - b = NULL; - } - else - { - // Successful - Free(data); - b = NewBuf(); - WriteBuf(b, c->Buffer, c->Size); - SeekBuf(b, 0, 0); - c->LastAccess = Tick64(); - } - } + Free(c->Buffer); + Free(c->Path); + Free(c); + + c = NULL; } } } - // Delete the expired cache - for (i = 0;i < LIST_NUM(hamcore);i++) + if (c != NULL) { - HC *c = LIST_DATA(hamcore, i); + buf = NewBuf(); + WriteBuf(buf, c->Buffer, c->Size); + SeekBuf(buf, 0, 0); + c->LastAccess = Tick64(); + } - if (c->Buffer != NULL) + LIST *to_delete = NewListFast(NULL); + + for (UINT i = 0; i < LIST_NUM(hamcore); ++i) + { + HC *c = LIST_DATA(hamcore, i); + if (c->LastAccess + HAMCORE_CACHE_EXPIRES <= Tick64()) { - if (((c->LastAccess + HAMCORE_CACHE_EXPIRES) <= Tick64()) || - (StartWith(c->FileName, "Li"))) - { - Free(c->Buffer); - c->Buffer = NULL; - } + Add(to_delete, c); } } + + for (UINT i = 0; i < LIST_NUM(to_delete); ++i) + { + HC *c = LIST_DATA(to_delete, i); + + Delete(hamcore, c); + + Free(c->Buffer); + Free(c->Path); + Free(c); + } + + ReleaseList(to_delete); } UnlockList(hamcore); - return b; + return buf; } // Initialization of HamCore file system void InitHamcore() { - wchar_t tmp[MAX_PATH]; - wchar_t tmp2[MAX_PATH]; - wchar_t exe_dir[MAX_PATH]; - UINT i, num; - char header[HAMCORE_HEADER_SIZE]; - - hamcore = NewList(CompareHamcore); - if (MayaquaIsMinimalMode()) { return; } - GetExeDirW(exe_dir, sizeof(exe_dir)); - UniFormat(tmp, sizeof(tmp), L"%s/%S", exe_dir, HAMCORE_FILE_NAME); - - UniFormat(tmp2, sizeof(tmp2), L"%s/%S", exe_dir, HAMCORE_FILE_NAME_2); - - // If there is _hamcore.se2, overwrite it yo the hamcore.se2 - FileReplaceRenameW(tmp2, tmp); - - // Read if there is a file hamcore.se2 - hamcore_io = FileOpenW(tmp, false); - if (hamcore_io == NULL) - { - // Look in other locations if it isn't found -#ifdef OS_WIN32 - UniFormat(tmp, sizeof(tmp), L"%S/%S", MsGetSystem32Dir(), HAMCORE_FILE_NAME); -#else // OS_WIN32 - UniFormat(tmp, sizeof(tmp), L"/bin/%S", HAMCORE_FILE_NAME); -#endif // OS_WIN32 - - hamcore_io = FileOpenW(tmp, false); - if (hamcore_io == NULL) - { - return; - } - } - - // Read the file header - Zero(header, sizeof(header)); - FileRead(hamcore_io, header, HAMCORE_HEADER_SIZE); - - if (Cmp(header, HAMCORE_HEADER_DATA, HAMCORE_HEADER_SIZE) != 0) + hamcore = NewList(CompareHamcore); +#ifdef HAMCORE_FILE_PATH + hamcore_io = HamcoreOpen(HAMCORE_FILE_PATH); + if (hamcore_io != NULL) { - // Invalid header - FileClose(hamcore_io); - hamcore_io = NULL; + Debug("InitHamcore(): Loaded from \"%s\".\n", HAMCORE_FILE_PATH); return; } +#endif + char path[MAX_PATH]; + GetExeDir(path, sizeof(path)); + Format(path, sizeof(path), "%s/%s", path, HAMCORE_FILE_NAME); - // The number of the File - num = 0; - FileRead(hamcore_io, &num, sizeof(num)); - num = Endian32(num); - for (i = 0;i < num;i++) + hamcore_io = HamcoreOpen(path); + if (hamcore_io != NULL) { - // File name - char tmp[MAX_SIZE]; - UINT str_size = 0; - HC *c; - - FileRead(hamcore_io, &str_size, sizeof(str_size)); - str_size = Endian32(str_size); - if (str_size >= 1) - { - str_size--; - } - - Zero(tmp, sizeof(tmp)); - FileRead(hamcore_io, tmp, str_size); - - c = ZeroMalloc(sizeof(HC)); - c->FileName = CopyStr(tmp); - - FileRead(hamcore_io, &c->Size, sizeof(UINT)); - c->Size = Endian32(c->Size); - - FileRead(hamcore_io, &c->SizeCompressed, sizeof(UINT)); - c->SizeCompressed = Endian32(c->SizeCompressed); - - FileRead(hamcore_io, &c->Offset, sizeof(UINT)); - c->Offset = Endian32(c->Offset); - - Insert(hamcore, c); + Debug("InitHamcore(): Loaded from \"%s\".\n", path); } } // Release of HamCore file system void FreeHamcore() { - UINT i; - for (i = 0;i < LIST_NUM(hamcore);i++) + for (UINT i = 0; i < LIST_NUM(hamcore); ++i) { HC *c = LIST_DATA(hamcore, i); - Free(c->FileName); - if (c->Buffer != NULL) - { - Free(c->Buffer); - } + + Free(c->Buffer); + Free(c->Path); Free(c); } ReleaseList(hamcore); - FileClose(hamcore_io); + HamcoreClose(hamcore_io); hamcore_io = NULL; hamcore = NULL; } @@ -991,7 +865,7 @@ { return 0; } - return StrCmpi(c1->FileName, c2->FileName); + return StrCmpi(c1->Path, c2->Path); } // Getting the name of the directory where the EXE file is in diff -Nru softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/FileIO.h softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/FileIO.h --- softether-vpn-5.02.0~202105242329~ubuntu20.04.1/src/Mayaqua/FileIO.h 2021-05-25 01:25:09.000000000 +0000 +++ softether-vpn-5.02.5180~202106240828~ubuntu20.04.1/src/Mayaqua/FileIO.h 2021-10-25 20:43:04.000000000 +0000 @@ -10,11 +10,8 @@ #include "Mayaqua.h" -// Constant #define HAMCORE_DIR_NAME "hamcore" #define HAMCORE_FILE_NAME "hamcore.se2" -#define HAMCORE_FILE_NAME_2 "_hamcore.se2" -#define HAMCORE_TEXT_NAME "hamcore.txt" #define HAMCORE_CACHE_EXPIRES (5 * 60 * 1000) // IO structure @@ -33,12 +30,10 @@ // HC structure typedef struct HC { - char *FileName; // File name - UINT Size; // File size - UINT SizeCompressed; // Compressed file size - UINT Offset; // Offset - void *Buffer; // Buffer - UINT64 LastAccess; // Access Date + char *Path; + void *Buffer; + size_t Size; + UINT64 LastAccess; } HC; // DIRENT structure @@ -242,7 +237,6 @@ int CompareDirListByName(void *p1, void *p2); bool GetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size); void ConvertSafeFileName(char *dst, UINT size, char *src); -bool FileReplaceRenameW(wchar_t *old_name, wchar_t *new_name); bool IsFile(char *name); bool IsFileW(wchar_t *name); bool SaveFileW(wchar_t *name, void *data, UINT size);