Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2000-10-02 13:07:50 +0400
committerCorinna Vinschen <corinna@vinschen.de>2000-10-02 13:07:50 +0400
commita26fb3150d1a39743d7e95f7f46036bdd882061f (patch)
tree4217b716e9d3b9e110209799ef892b960c391682 /winsup/cygwin/fhandler_mem.cc
parent2f696b4bdb81874f43fb9dcc759a0af7490117b8 (diff)
* fhandler_mem.cc: Load ntdll functions via autoload method.
(load_ntdll_funcs): Eliminated.
Diffstat (limited to 'winsup/cygwin/fhandler_mem.cc')
-rw-r--r--winsup/cygwin/fhandler_mem.cc135
1 files changed, 53 insertions, 82 deletions
diff --git a/winsup/cygwin/fhandler_mem.cc b/winsup/cygwin/fhandler_mem.cc
index 1d7439b31..50370d876 100644
--- a/winsup/cygwin/fhandler_mem.cc
+++ b/winsup/cygwin/fhandler_mem.cc
@@ -15,91 +15,20 @@
#include <unistd.h>
#include <ntdef.h>
+#include "autoload.h"
#include "cygheap.h"
#include "cygerrno.h"
#include "fhandler.h"
#include "path.h"
-static int inited = FALSE;
-NTSTATUS (__stdcall *NtMapViewOfSection)(HANDLE,HANDLE,PVOID*,ULONG,ULONG,
- PLARGE_INTEGER,PULONG,SECTION_INHERIT,
- ULONG,ULONG);
-NTSTATUS (__stdcall *NtOpenSection)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES);
-NTSTATUS (__stdcall *NtUnmapViewOfSection)(HANDLE,PVOID);
-VOID (__stdcall *RtlInitUnicodeString)(PUNICODE_STRING,PCWSTR);
-ULONG (__stdcall *RtlNtStatusToDosError) (NTSTATUS);
-
-int
-load_ntdll_funcs ()
-{
- int ret = 0;
-
- if (os_being_run != winNT)
- {
- set_errno (ENOENT);
- debug_printf ("/dev/mem is accessible under NT/W2K only");
- return 0;
- }
-
- HMODULE ntdll = GetModuleHandle ("ntdll.dll");
-
- if (inited)
- {
- debug_printf ("function pointers already inited");
- return 1;
- }
-
- if (!ntdll)
- {
- __seterrno ();
- goto out;
- }
-
- if (!(NtMapViewOfSection = (NTSTATUS (__stdcall *)(HANDLE,HANDLE,PVOID*,ULONG,
- ULONG,PLARGE_INTEGER,
- PULONG,SECTION_INHERIT,
- ULONG,ULONG))
- GetProcAddress (ntdll, "NtMapViewOfSection")))
- {
- __seterrno ();
- goto out;
- }
-
- if (!(NtOpenSection = (NTSTATUS (__stdcall *)(PHANDLE,ACCESS_MASK,
- POBJECT_ATTRIBUTES))
- GetProcAddress (ntdll, "NtOpenSection")))
- {
- __seterrno ();
- goto out;
- }
-
- if (!(NtUnmapViewOfSection = (NTSTATUS (__stdcall *)(HANDLE,PVOID))
- GetProcAddress (ntdll, "NtUnmapViewOfSection")))
- {
- __seterrno ();
- goto out;
- }
-
- if (!(RtlInitUnicodeString = (VOID (__stdcall *)(PUNICODE_STRING,PCWSTR))
- GetProcAddress (ntdll, "RtlInitUnicodeString")))
- {
- __seterrno ();
- goto out;
- }
-
- if (!(RtlNtStatusToDosError = (ULONG (__stdcall *)(NTSTATUS))
- GetProcAddress (ntdll, "RtlNtStatusToDosError")))
- {
- __seterrno ();
- goto out;
- }
-
- inited = TRUE;
- ret = 1;
-
-out:
- debug_printf ("%d = load_ntdll_funcs()", ret);
- return ret;
+extern "C" {
+NTSTATUS NTAPI NtMapViewOfSection(HANDLE,HANDLE,PVOID*,ULONG,ULONG,
+ PLARGE_INTEGER,PULONG,SECTION_INHERIT,
+ ULONG,ULONG);
+NTSTATUS NTAPI NtOpenSection(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES);
+NTSTATUS NTAPI NtUnmapViewOfSection(HANDLE,PVOID);
+VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING,PCWSTR);
+ULONG NTAPI RtlNtStatusToDosError(NTSTATUS);
}
/**********************************************************************/
@@ -118,8 +47,12 @@ fhandler_dev_mem::~fhandler_dev_mem (void)
int
fhandler_dev_mem::open (const char *, int flags, mode_t)
{
- if (!load_ntdll_funcs ())
- return 0;
+ if (os_being_run != winNT)
+ {
+ set_errno (ENOENT);
+ debug_printf ("/dev/mem is accessible under NT/W2K only");
+ return 0;
+ }
UNICODE_STRING memstr;
RtlInitUnicodeString (&memstr, L"\\device\\physicalmemory");
@@ -260,3 +193,41 @@ fhandler_dev_mem::dump ()
{
paranoid_printf("here, fhandler_dev_mem");
}
+
+extern "C" {
+
+LoadDLLinitfunc (ntdll)
+{
+ HANDLE h;
+ static NO_COPY LONG here = -1L;
+
+ while (InterlockedIncrement (&here))
+ {
+ InterlockedDecrement (&here);
+small_printf ("Multiple tries to read ntdll.dll\n");
+ Sleep (0);
+ }
+
+ if (ntdll_handle)
+ /* nothing to do */;
+ else if ((h = LoadLibrary ("ntdll.dll")) != NULL)
+ ntdll_handle = h;
+ else if (!ntdll_handle)
+ api_fatal ("could not load ntdll.dll, %E");
+
+ InterlockedDecrement (&here);
+ return 0;
+}
+
+static void dummy_autoload (void) __attribute__ ((unused));
+static void
+dummy_autoload (void)
+{
+LoadDLLinit (ntdll)
+LoadDLLfuncEx (NtMapViewOfSection, 40, ntdll, 1)
+LoadDLLfuncEx (NtOpenSection, 12, ntdll, 1)
+LoadDLLfuncEx (NtUnmapViewOfSection, 8, ntdll, 1)
+LoadDLLfuncEx (RtlInitUnicodeString, 8, ntdll, 1)
+LoadDLLfuncEx (RtlNtStatusToDosError, 4, ntdll, 1)
+}
+}