/proc/uptime etc. - NtQuerySystemInformation() needs bigger structure

c@pobox.co.uk c@pobox.co.uk
Fri Jul 5 07:18:00 GMT 2002


/proc/uptime, /proc/stat, and /proc/*/stat seem not to be working for
me with cygwin 1.3.12.  I think I've found a fix, though.

Looking at the code for uptime, it seems to be using
NtQuerySystemInformation() -- a function which I investigated fairly
thoroughly a while back while when disassembling win2k's taskmgr.exe
(in order to write a wrapper to tweak its output to ignore specified
processes in its usage graph).

One thing I noticed was that function 8 (named SystemProcessorTimes in
the cygwin source) needs an extra DWORD member at the end of its
structure.  This isn't overwritten, yet needs to be included in the
structure size.  (Who am I to suggest that MS simply got it wrong, and
require the wrong size as a parameter; it's clearly just an usused
value. :-) ) This is consistent with strace's report of
NtQuerySystemInformation returning 0xc0000004
(STATUS_INFO_LENGTH_MISMATCH).

The following patch seems to fix the problem.  I've not done thorough
tests to see if it's broken anything else.  I just altered ntdll.h,
and attempted to build from source.  This didn't get further than
having problems with memset in winsup/utils/cygcheck.cc (and I've not
yet had chance to investigate why, other than to recognise it as the
same problem I had much earlier with #include_next <string.h> until I
built into a separate dir from the source), but it did get as far as
building new-cygwin1.dll before giving up.  Putting this dll (named as
cygwin1.dll) in a dir together with cat.exe, and, from a non-cygwin
shell, running "cat /proc/uptime" seems to work.  I've not tried
putting it in /usr/bin/cygwin1.dll, so there's a small chance it would
break something else.

The diff is against the released source, not the latest cvs version,
but I assume the patch will still apply.  (I've not got enough
bandwidth at home to justify getting the CVS version (though hopefully
I soon will), and the firewall at work prevents it (though I wouldn't
have enough time there, anyway).)

Please CC me any reply (if one happens to be needed), rather than
sending just to the list (as I'm not yet subscribed).


--- winsup/cygwin/ntdll.h.old 2002-05-30 21:21:04.000000000 +0100
+++ winsup/cygwin/ntdll.h     2002-07-05 11:15:52.000000000 +0100
@@ -58,6 +58,7 @@ typedef struct _SYSTEM_PROCESSOR_TIMES
   LARGE_INTEGER DpcTime;
   LARGE_INTEGER InterruptTime;
   ULONG InterruptCount;
+  ULONG Unused;
 } SYSTEM_PROCESSOR_TIMES, *PSYSTEM_PROCESSOR_TIMES;

 typedef LONG KPRIORITY;



-- 
Chris Hall


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list