OSDN Git Service

* ntdll.h: New file.
authorcorinna <corinna>
Tue, 24 Oct 2000 18:44:56 +0000 (18:44 +0000)
committercorinna <corinna>
Tue, 24 Oct 2000 18:44:56 +0000 (18:44 +0000)
        * fhandler_mem.cc: Move ntdll.dll specific definitions and
        declarations to ntdll.h.
        * sysconf.cc (sysconf): Add support for _SC_NPROCESSORS_CONF,
        _SC_NPROCESSORS_ONLN, _SC_PHYS_PAGES and _SC_AVPHYS_PAGES.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler_mem.cc
winsup/cygwin/ntdll.h [new file with mode: 0644]
winsup/cygwin/sysconf.cc

index b95b5d7..c82f601 100644 (file)
@@ -1,3 +1,11 @@
+Tue Oct 24 20:38:00 2000  Corinna Vinschen <corinna@vinschen.de>
+
+       * ntdll.h: New file.
+       * fhandler_mem.cc: Move ntdll.dll specific definitions and
+       declarations to ntdll.h.
+       * sysconf.cc (sysconf): Add support for _SC_NPROCESSORS_CONF,
+       _SC_NPROCESSORS_ONLN, _SC_PHYS_PAGES and _SC_AVPHYS_PAGES.
+
 Tue Oct 24 20:00:00 2000  Corinna Vinschen <corinna@vinschen.de>
 
        * fhandler.cc (fhandler_base::fcntl): Behave properly when passed
index 5aa3bee..5c9ed1e 100644 (file)
 #include "autoload.h"
 #include "cygerrno.h"
 #include "fhandler.h"
-
-/*
- * The following both data structures aren't defined anywhere in the Microsoft
- * header files. Taken from the book "Windows NT/2000 Native API Reference"
- * by Gary Nebbett.
- */
-typedef enum _SYSTEM_INFORMATION_CLASS {
-  SystemBasicInformation = 0
-  /* Dropped each other since not used here. */
-} SYSTEM_INFORMATION_CLASS;
-
-typedef struct _SYSTEM_BASIC_INFORMATION {
-  ULONG Unknown;
-  ULONG MaximumIncrement;
-  ULONG PhysicalPageSize;
-  ULONG NumberOfPhysicalPages;
-  ULONG LowestPhysicalPage;
-  ULONG HighestPhysicalPage;
-  ULONG AllocationGranularity;
-  ULONG LowestUserAddress;
-  ULONG HighestUserAddress;
-  ULONG ActiveProcessors;
-  ULONG NumberProcessors;
-} SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION;
-
-extern "C" {
-NTSTATUS NTAPI NtMapViewOfSection(HANDLE,HANDLE,PVOID*,ULONG,ULONG,
-                                  PLARGE_INTEGER,PULONG,SECTION_INHERIT,
-                                  ULONG,ULONG);
-NTSTATUS NTAPI NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS,
-                                        PVOID,ULONG,PULONG);
-NTSTATUS NTAPI NtOpenSection(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES);
-NTSTATUS NTAPI NtUnmapViewOfSection(HANDLE,PVOID);
-VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING,PCWSTR);
-ULONG NTAPI RtlNtStatusToDosError(NTSTATUS);
-}
+#include "ntdll.h"
 
 /**********************************************************************/
 /* fhandler_dev_mem */
diff --git a/winsup/cygwin/ntdll.h b/winsup/cygwin/ntdll.h
new file mode 100644 (file)
index 0000000..bdb4fe8
--- /dev/null
@@ -0,0 +1,50 @@
+/* ntdll.h.  Contains ntdll specific stuff which is nowhere defined.
+
+   Copyright 2000 Cygnus Solutions.
+
+   This file is part of Cygwin.
+
+   This software is a copyrighted work licensed under the terms of the
+   Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
+   details. */
+
+/*
+ * The following both data structures aren't defined anywhere in the Microsoft
+ * header files. Taken from the book "Windows NT/2000 Native API Reference"
+ * by Gary Nebbett.
+ */
+typedef enum _SYSTEM_INFORMATION_CLASS {
+  SystemBasicInformation = 0
+  /* Dropped each other since not used here. */
+} SYSTEM_INFORMATION_CLASS;
+
+typedef struct _SYSTEM_BASIC_INFORMATION {
+  ULONG Unknown;
+  ULONG MaximumIncrement;
+  ULONG PhysicalPageSize;
+  ULONG NumberOfPhysicalPages;
+  ULONG LowestPhysicalPage;
+  ULONG HighestPhysicalPage;
+  ULONG AllocationGranularity;
+  ULONG LowestUserAddress;
+  ULONG HighestUserAddress;
+  ULONG ActiveProcessors;
+  ULONG NumberProcessors;
+} SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION;
+
+/*
+ * Function declarations for ntdll.dll. They doesn't appear in any
+ * Win32 header either.
+ */
+extern "C" {
+NTSTATUS NTAPI NtMapViewOfSection(HANDLE,HANDLE,PVOID*,ULONG,ULONG,
+                                  PLARGE_INTEGER,PULONG,SECTION_INHERIT,
+                                  ULONG,ULONG);
+NTSTATUS NTAPI NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS,
+                                        PVOID,ULONG,PULONG);
+NTSTATUS NTAPI NtOpenSection(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES);
+NTSTATUS NTAPI NtUnmapViewOfSection(HANDLE,PVOID);
+VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING,PCWSTR);
+ULONG NTAPI RtlNtStatusToDosError(NTSTATUS);
+}
+
index a6383dc..964fdb1 100644 (file)
@@ -13,9 +13,11 @@ details. */
 #include <errno.h>
 #include <time.h>
 #include <limits.h>
+#include <ntdef.h>
 #include "fhandler.h"
 #include "dtable.h"
 #include "cygerrno.h"
+#include "ntdll.h"
 
 /* sysconf: POSIX 4.8.1.1 */
 /* Allows a portable app to determine quantities of resources or
@@ -57,6 +59,39 @@ sysconf (int in)
       case _SC_STREAM_MAX:
        return _POSIX_STREAM_MAX;
 #endif
+      case _SC_NPROCESSORS_CONF:
+      case _SC_NPROCESSORS_ONLN:
+       if (os_being_run != winNT)
+         return 1;
+       /*FALLTHRU*/
+      case _SC_PHYS_PAGES:
+      case _SC_AVPHYS_PAGES:
+        {
+         NTSTATUS ret;
+         SYSTEM_BASIC_INFORMATION sbi;
+          if ((ret = NtQuerySystemInformation (SystemBasicInformation,
+                                                (PVOID) &sbi,
+                                                sizeof sbi, NULL))
+               != STATUS_SUCCESS)
+            {
+              __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+              debug_printf("NtQuerySystemInformation: ret = %d, "
+                          "Dos(ret) = %d",
+                           ret, RtlNtStatusToDosError (ret));
+             return -1;
+            }
+         switch (in)
+           {
+           case _SC_NPROCESSORS_CONF:
+            return sbi.NumberProcessors;
+           case _SC_NPROCESSORS_ONLN:
+            return sbi.ActiveProcessors;
+           case _SC_PHYS_PAGES:
+             return sbi.NumberOfPhysicalPages;
+           case _SC_AVPHYS_PAGES:
+             return sbi.HighestPhysicalPage - sbi.LowestPhysicalPage + 1;
+           }
+       }
     }
 
   /* Invalid input or unimplemented sysconf name */