Skip to content
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

Cygwin: uname: add host machine tag to sysname #244

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions winsup/cygwin/local_includes/wincap.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class wincapc
RTL_OSVERSIONINFOEXW version;
char osnam[40];
const void *caps;
USHORT host_mach;
USHORT cygwin_mach;
bool _is_server;

public:
Expand All @@ -61,6 +63,8 @@ class wincapc
{ return (size_t) system_info.dwAllocationGranularity; }
const char *osname () const { return osnam; }
const DWORD build_number () const { return version.dwBuildNumber; }
const USHORT host_machine () const { return host_mach; }
const USHORT cygwin_machine () const { return cygwin_mach; }

#define IMPLEMENT(cap) cap() const { return ((wincaps *) this->caps)->cap; }

Expand Down
6 changes: 2 additions & 4 deletions winsup/cygwin/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4826,14 +4826,12 @@ find_fast_cwd_pointer ()
static fcwd_access_t **
find_fast_cwd ()
{
USHORT emulated, hosted;
fcwd_access_t **f_cwd_ptr;

/* First check if we're running in WOW64 on ARM64 emulating AMD64. Skip
/* First check if we're running on an ARM64 system. Skip
fetching FAST_CWD pointer as long as there's no solution for finding
it on that system. */
if (IsWow64Process2 (GetCurrentProcess (), &emulated, &hosted)
&& hosted == IMAGE_FILE_MACHINE_ARM64)
if (wincap.host_machine () == IMAGE_FILE_MACHINE_ARM64)
return NULL;

/* Fetch the pointer but don't set the global fast_cwd_ptr yet. First
Expand Down
20 changes: 17 additions & 3 deletions winsup/cygwin/uname.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,27 @@ uname_x (struct utsname *name)
__try
{
char buf[NI_MAXHOST + 1] ATTRIBUTE_NONSTRING;
int n;

memset (name, 0, sizeof (*name));
/* sysname */
const char* sysname = get_sysname();
__small_sprintf (name->sysname, "%s_%s-%u",
sysname,
wincap.osname (), wincap.build_number ());
n = __small_sprintf (name->sysname, "%s_%s-%u",
sysname,
wincap.osname (), wincap.build_number ());
if (wincap.host_machine () != wincap.cygwin_machine ())
{
switch (wincap.host_machine ())
{
case IMAGE_FILE_MACHINE_ARM64:
n = stpcpy (name->sysname + n, "-ARM64") - name->sysname;
break;
default:
n += __small_sprintf (name->sysname + n, "-%04y",
(int) wincap.host_machine ());
break;
}
}
/* nodename */
memset (buf, 0, sizeof buf);
cygwin_gethostname (buf, sizeof buf - 1);
Expand Down
19 changes: 19 additions & 0 deletions winsup/cygwin/wincap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,15 @@ static const wincaps wincap_11 = {

wincapc wincap __attribute__((section (".cygwin_dll_common"), shared));

extern IMAGE_DOS_HEADER
__image_base__;

void
wincapc::init ()
{
PIMAGE_NT_HEADERS ntheader;
USHORT emul_mach;

if (caps)
return; // already initialized

Expand Down Expand Up @@ -282,4 +288,17 @@ wincapc::init ()

__small_sprintf (osnam, "NT-%d.%d", version.dwMajorVersion,
version.dwMinorVersion);

if (!IsWow64Process2 (GetCurrentProcess (), &emul_mach, &host_mach))
{
/* If IsWow64Process2 succeeded, it filled in host_mach. Assume the only
way it fails for the current process is that we're running on an OS
version where it's not implemented yet. As such, the only realistic
option for host_mach is AMD64 */
host_mach = IMAGE_FILE_MACHINE_AMD64;
}

ntheader = (PIMAGE_NT_HEADERS)((LPBYTE) &__image_base__
+ __image_base__.e_lfanew);
cygwin_mach = ntheader->FileHeader.Machine;
}
Loading