-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OSArchitecture is wrong on non-Windows #58463
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
If we switch this API to return the correct value, then do we have another to return the architecture of the process? If not, then it seems like we might be favoring one class of bugs over another. |
Closing with the same rationale as #26612 that the current behavior is reasonable. |
We have two APIs. One is OSArchitecture, the other is ProcessArchitecture
Reactivating this since there is as an active PR on this. |
Just discovered this issue when actually trying to report the OS architecture. The current implementation does not appear to meet the expectations of the documentation for this. |
@sgmunn What was the environment where you encountered this issue? |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsRelated: #26612 DescriptionWe hardcode the value as that which we're building for:
This will be incorrect when running x86 on x64, or x64 on ARM64. @richlander I noticed this when looking into how to differentiate x64 on ARM64. My current approach is to use sysctl("hw.machine") which seems like it could work here. Not sure if that's "best practice" for identifying the machine architecture or not. Configuration.NET 6.0. Tested on x64 build on ARM64 but would be true on any case where running an emulated architecture. Regression?No
|
@jeffhandley I updated the area path per the https://github.com/dotnet/runtime/blob/main/docs/area-owners.md. Feel free to re-assign if needed. |
@jkotas we were trying to report the OS architecture of VSMac when running on x64 or arm64. This hides the real OS architecture when x64 builds are run on arm64. I was expecting it to return the architecture of the OS, not what had been built against. I guess in some ways I can see why, but both ProcessArchitecture and OSArchitecture return the exact same thing, it seems redundant and non-useful, whereas reporting the actual architecture would be useful to know if you have x64 builds running on an arm64 (via rosetta). |
Why not rename this to ProcessArchetecture or put this into System.Diagnostics.Process as a static property, then have OSArchitecture use (on windows) GetSystemInfo() winapi function to get the real os architecture (at least on windows), and fall back to the renamed version of this when not on windows? |
@ericstj, I think part of the confusion here is that for all intents and purposes the OSArchitecture for If you are running in a The fact that you are functionally in a pseudo-VM running on top of a different OS is only available via alternative environment variables and APIs. For example, you must query Changing |
I would support having the information about the "native machine" to be placed in an Perhaps it could be shorted to |
There are number of different emulation technologies. Which ones would the new API be able to see through? I think it is the key challenge with the existing API or any new API like that.
Yes, it might like any other breaking change. On the other hand, it would keep the API surface somewhat understandable. If we want to do something here, my vote would be to modify the behavior of the existing API. If we were to introduce similar partial redundant APIs, I think it would be very hard to tell which one is the right one to use in a given context. |
No changes are suggested to In my opinion if we don't do our best effort to make |
I ran into this issue a while ago (~December last year) and was confused why it was wrong, so I now P/Invoke IsWow64Process2 with a fallback to OSArchitecture/GetNativeSystemInfo when unrecognised arch (in case of future additions, it will just be "wrong" like it currently is ie. report x86 or something) or unsupported Windows version. I ran into this issue when writing code that would make sure the correct files got extracted, it seemed to always think it was x64 on the arm64 machine I was testing it on. I hope this gets fixed, but if not it should state in the documentation that it may be wrong for windows arm64 and whatever other OSes it's wrong for so programmers can account for this. ITO whether in a VM it should return the VM's architecture or the host's architecture (#60910), I don't even know how it would be able to access the host's architecture, but if (for example) the host happened to be arm64 and the VM happened to be x64, then getting back arm64 wouldn't be very useful IMO since you can't run arm64 apps in the VM, if someone wanted this behaviour, perhaps there could be another API to detect this (I'd have no use for this, I just want OSArchitecture to tell me the truth about the OS), but I'd imagine most would think OSArchitecture would simply return the OS's architecture, even if the OS is a VM. @jkotas #60910 (comment) my situation is that the app would detect if it is using the wrong architecture executables and then get them replaced with what it deemed correct, this could happen in multiple ways with this app eg. being copied, new architecture in future .NET & Windows versions, restoring a backup of Windows onto a new machine with a different architecture, or supporting arm64 in the first place (which was an update, so as you can probably guess, this helped me discover this issue). It would be nice if this was fixed for .NET 7/8 since that's what I plan to use next. I can test my app with it if you want, I'll just need the exe installer for the PR (or I could try to built it myself...) |
I report process and is architecture as part of telemetry to understanding whether we should be adding support for more Architectures. I don’t want to be lied about the OS architecture. There’s naturally a distinct difference between OS and process architecture. |
Fixed by #60910 |
Related: #26612
Description
We hardcode the value as that which we're building for:
runtime/src/libraries/Native/Unix/System.Native/pal_runtimeinformation.c
Lines 62 to 79 in 5ca197c
This will be incorrect when running x86 on x64, or x64 on ARM64. @richlander
I noticed this when looking into how to differentiate x64 on ARM64. My current approach is to use sysctl("hw.machine") which seems like it could work here. Not sure if that's "best practice" for identifying the machine architecture or not.
Configuration
.NET 6.0. Tested on x64 build on ARM64 but would be true on any case where running an emulated architecture.
Regression?
No
The text was updated successfully, but these errors were encountered: