[PATCH v2 2/2] Cygwin: uname: add host machine tag to sysname.
Corinna Vinschen
corinna-cygwin@cygwin.com
Tue Nov 26 13:30:41 GMT 2024
On Nov 25 11:24, Jeremy Drake via Cygwin-patches wrote:
> From: Jeremy Drake <cygwin@jdrake.com>
>
> If the Cygwin dll's architecture is different from the host system's
> architecture, append an additional tag that indicates the host system
> architecture (the Cygwin dll's architecture is already indicated in
> machine).
>
> Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
> ---
> v2: get rid of hardcoded string lengths, use wincap accessors
> directly instead of caching their returns, actually add "n" variable as
> intended
>
> winsup/cygwin/uname.cc | 38 ++++++++++++++++++++++++++++++++++++--
> 1 file changed, 36 insertions(+), 2 deletions(-)
>
> diff --git a/winsup/cygwin/uname.cc b/winsup/cygwin/uname.cc
> index dd4160189c..2410dc502e 100644
> --- a/winsup/cygwin/uname.cc
> +++ b/winsup/cygwin/uname.cc
> @@ -24,6 +24,38 @@ extern "C" int getdomainname (char *__name, size_t __len);
> #define ATTRIBUTE_NONSTRING
> #endif
>
> +static int
> +append_host_suffix (char * buf)
> +{
> + int n = 0;
> + if (wincap.host_machine () != wincap.cygwin_machine ())
> + {
> + switch (wincap.host_machine ())
> + {
> + case IMAGE_FILE_MACHINE_AMD64:
> + /* special case for backwards compatibility */
> + if (wincap.cygwin_machine () == IMAGE_FILE_MACHINE_I386)
> + n = stpcpy (buf, "-WOW64") - buf;
> + else
> + n = stpcpy (buf, "-x64") - buf;
> + break;
> + case IMAGE_FILE_MACHINE_I386:
> + n = stpcpy (buf, "-x86") - buf;
> + break;
> + case IMAGE_FILE_MACHINE_ARMNT:
> + n = stpcpy (buf, "-ARM") - buf;
> + break;
> + case IMAGE_FILE_MACHINE_ARM64:
> + n = strcpy (buf, "-ARM64") - buf;
> + break;
> + default:
> + n = __small_sprintf (buf, "-%04y", (int) wincap.host_machine ());
> + break;
> + }
You can greatly simplify this switch. We don't support 32 bit systems
and we will never again support 32 bit systems. Any combination
including a 32 bit system can just go away. Theoretically, only
the IMAGE_FILE_MACHINE_ARM64 case should be left.
> __try
> {
> char buf[NI_MAXHOST + 1] ATTRIBUTE_NONSTRING;
> + int n;
>
> memset (name, 0, sizeof (*name));
> /* sysname */
> - __small_sprintf (name->sysname, "CYGWIN_%s-%u",
> - wincap.osname (), wincap.build_number ());
> + n = __small_sprintf (name->sysname, "CYGWIN_%s-%u",
> + wincap.osname (), wincap.build_number ());
> + n += append_host_suffix (name->sysname + n);
I guess a length check is not required here. The __small_sprintf
creates a 21 byte string, or 22 byte as soon as the build number gets
6 digits. The field length is 65 bytes, so there's some spare. But
at least we talked about it :)
Thanks,
Corinna
More information about the Cygwin-patches
mailing list