2000-10-01 09:02:40 +08:00
|
|
|
/* fhandler_mem.cc. See fhandler.h for a description of the fhandler classes.
|
|
|
|
|
* child_info.h, cygheap.h, fhandler_clipboard.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, thread.h, uinfo.cc, include/cygwin/acl.h: Fix copyright.
2002-02-10 21:50:13 +08:00
|
|
|
Copyright 2000, 2001, 2002 Red Hat, Inc.
|
2000-10-01 09:02:40 +08:00
|
|
|
|
|
|
|
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. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
2000-10-08 01:35:36 +08:00
|
|
|
#include <sys/mman.h>
|
2000-10-01 09:02:40 +08:00
|
|
|
#include <ntdef.h>
|
|
|
|
|
|
|
|
#include "cygerrno.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2000-10-01 09:02:40 +08:00
|
|
|
#include "fhandler.h"
|
2000-10-25 02:44:56 +08:00
|
|
|
#include "ntdll.h"
|
2000-10-01 09:02:40 +08:00
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
/* fhandler_dev_mem */
|
|
|
|
|
2001-10-14 01:23:35 +08:00
|
|
|
fhandler_dev_mem::fhandler_dev_mem (int nunit)
|
|
|
|
: fhandler_base (FH_MEM), unit (nunit)
|
2000-10-05 01:08:46 +08:00
|
|
|
{
|
2000-10-09 22:02:25 +08:00
|
|
|
/* Reading physical memory only supported on NT/W2K. */
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
if (!wincap.has_physical_mem_access ())
|
2000-10-09 22:02:25 +08:00
|
|
|
{
|
|
|
|
mem_size = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-10-08 01:35:36 +08:00
|
|
|
if (unit == 1) /* /dev/mem */
|
2000-10-05 01:08:46 +08:00
|
|
|
{
|
2000-10-09 21:19:41 +08:00
|
|
|
NTSTATUS ret;
|
|
|
|
SYSTEM_BASIC_INFORMATION sbi;
|
|
|
|
if ((ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
|
2001-09-08 05:32:07 +08:00
|
|
|
sizeof sbi, NULL)) != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
|
|
|
debug_printf("NtQuerySystemInformation: ret = %d, Dos(ret) = %d",
|
|
|
|
ret, RtlNtStatusToDosError (ret));
|
|
|
|
mem_size = 0;
|
|
|
|
}
|
2000-10-09 21:19:41 +08:00
|
|
|
else
|
2001-09-08 05:32:07 +08:00
|
|
|
mem_size = sbi.PhysicalPageSize * sbi.NumberOfPhysicalPages;
|
2000-10-09 22:49:25 +08:00
|
|
|
debug_printf ("MemSize: %d MB", mem_size >> 20);
|
2000-10-08 01:35:36 +08:00
|
|
|
}
|
|
|
|
else if (unit == 2) /* /dev/kmem - Not yet supported */
|
|
|
|
{
|
|
|
|
mem_size = 0;
|
2000-10-09 22:49:25 +08:00
|
|
|
debug_printf ("KMemSize: %d MB", mem_size >> 20);
|
2000-10-08 01:35:36 +08:00
|
|
|
}
|
|
|
|
else if (unit == 4) /* /dev/port == First 64K of /dev/mem */
|
|
|
|
{
|
|
|
|
mem_size = 65536;
|
|
|
|
debug_printf ("PortSize: 64 KB");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-09 21:19:41 +08:00
|
|
|
mem_size = 0;
|
|
|
|
debug_printf ("Illegal minor number!!!");
|
2000-10-05 01:08:46 +08:00
|
|
|
}
|
2000-10-09 21:19:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fhandler_dev_mem::~fhandler_dev_mem (void)
|
|
|
|
{
|
2000-10-05 01:08:46 +08:00
|
|
|
}
|
|
|
|
|
2000-10-01 09:02:40 +08:00
|
|
|
int
|
2001-10-04 10:34:20 +08:00
|
|
|
fhandler_dev_mem::open (path_conv *, int flags, mode_t)
|
2000-10-01 09:02:40 +08:00
|
|
|
{
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
if (!wincap.has_physical_mem_access ())
|
2000-10-02 17:07:50 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOENT);
|
2000-10-08 01:35:36 +08:00
|
|
|
debug_printf ("%s is accessible under NT/W2K only",
|
2001-09-08 05:32:07 +08:00
|
|
|
unit == 1 ? "/dev/mem" :
|
|
|
|
unit == 2 ? "/dev/kmem" :
|
|
|
|
"/dev/port");
|
2000-10-02 17:07:50 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2000-10-01 09:02:40 +08:00
|
|
|
|
2000-10-05 01:08:46 +08:00
|
|
|
/* Check for illegal flags. */
|
|
|
|
if (flags & (O_APPEND | O_TRUNC | O_EXCL))
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-01 09:02:40 +08:00
|
|
|
UNICODE_STRING memstr;
|
|
|
|
RtlInitUnicodeString (&memstr, L"\\device\\physicalmemory");
|
|
|
|
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
2001-01-11 20:33:12 +08:00
|
|
|
InitializeObjectAttributes(&attr, &memstr,
|
2001-09-08 05:32:07 +08:00
|
|
|
OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
|
2001-01-11 20:33:12 +08:00
|
|
|
NULL, NULL);
|
2000-10-01 09:02:40 +08:00
|
|
|
|
2000-10-05 01:08:46 +08:00
|
|
|
ACCESS_MASK section_access;
|
2000-10-01 09:02:40 +08:00
|
|
|
if ((flags & (O_RDONLY | O_WRONLY | O_RDWR)) == O_RDONLY)
|
2000-10-05 01:08:46 +08:00
|
|
|
{
|
|
|
|
set_access (GENERIC_READ);
|
|
|
|
section_access = SECTION_MAP_READ;
|
|
|
|
}
|
2000-10-01 09:02:40 +08:00
|
|
|
else if ((flags & (O_RDONLY | O_WRONLY | O_RDWR)) == O_WRONLY)
|
2000-10-05 01:08:46 +08:00
|
|
|
{
|
|
|
|
set_access (GENERIC_WRITE);
|
|
|
|
section_access = SECTION_MAP_READ | SECTION_MAP_WRITE;
|
|
|
|
}
|
2000-10-01 09:02:40 +08:00
|
|
|
else
|
2000-10-05 01:08:46 +08:00
|
|
|
{
|
|
|
|
set_access (GENERIC_READ | GENERIC_WRITE);
|
|
|
|
section_access = SECTION_MAP_READ | SECTION_MAP_WRITE;
|
|
|
|
}
|
2000-10-01 09:02:40 +08:00
|
|
|
|
|
|
|
HANDLE mem;
|
2000-10-05 01:08:46 +08:00
|
|
|
NTSTATUS ret = NtOpenSection (&mem, section_access, &attr);
|
2000-10-01 09:02:40 +08:00
|
|
|
if (!NT_SUCCESS(ret))
|
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
|
|
|
set_io_handle (NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_io_handle (mem);
|
2001-04-24 10:07:58 +08:00
|
|
|
set_open_status ();
|
2000-10-01 09:02:40 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-10-05 01:08:46 +08:00
|
|
|
fhandler_dev_mem::write (const void *ptr, size_t ulen)
|
2000-10-01 09:02:40 +08:00
|
|
|
{
|
2000-10-05 01:08:46 +08:00
|
|
|
if (!ulen || pos >= mem_size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!(get_access () & GENERIC_WRITE))
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos + ulen > mem_size)
|
|
|
|
ulen = mem_size - pos;
|
|
|
|
|
|
|
|
PHYSICAL_ADDRESS phys;
|
|
|
|
NTSTATUS ret;
|
|
|
|
void *viewmem = NULL;
|
|
|
|
DWORD len = ulen + getpagesize () - 1;
|
|
|
|
|
|
|
|
phys.QuadPart = (ULONGLONG) pos;
|
|
|
|
if ((ret = NtMapViewOfSection (get_handle (),
|
2001-09-08 05:32:07 +08:00
|
|
|
INVALID_HANDLE_VALUE,
|
|
|
|
&viewmem,
|
|
|
|
0L,
|
|
|
|
len,
|
|
|
|
&phys,
|
|
|
|
&len,
|
|
|
|
ViewShare,
|
|
|
|
0,
|
|
|
|
PAGE_READONLY)) != STATUS_SUCCESS)
|
2000-10-05 01:08:46 +08:00
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy ((char *) viewmem + (pos - phys.QuadPart), ptr, ulen);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem)))
|
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos += ulen;
|
|
|
|
return ulen;
|
2000-10-01 09:02:40 +08:00
|
|
|
}
|
|
|
|
|
2001-10-24 12:16:45 +08:00
|
|
|
int __stdcall
|
2000-10-01 09:02:40 +08:00
|
|
|
fhandler_dev_mem::read (void *ptr, size_t ulen)
|
|
|
|
{
|
2000-10-05 01:08:46 +08:00
|
|
|
if (!ulen || pos >= mem_size)
|
2000-10-01 09:02:40 +08:00
|
|
|
return 0;
|
|
|
|
|
2000-10-05 01:08:46 +08:00
|
|
|
if (!(get_access () & GENERIC_READ))
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos + ulen > mem_size)
|
|
|
|
ulen = mem_size - pos;
|
|
|
|
|
2000-10-01 09:02:40 +08:00
|
|
|
PHYSICAL_ADDRESS phys;
|
|
|
|
NTSTATUS ret;
|
|
|
|
void *viewmem = NULL;
|
2000-10-05 01:08:46 +08:00
|
|
|
DWORD len = ulen + getpagesize () - 1;
|
2000-10-01 09:02:40 +08:00
|
|
|
|
|
|
|
phys.QuadPart = (ULONGLONG) pos;
|
|
|
|
if ((ret = NtMapViewOfSection (get_handle (),
|
2001-09-08 05:32:07 +08:00
|
|
|
INVALID_HANDLE_VALUE,
|
|
|
|
&viewmem,
|
|
|
|
0L,
|
|
|
|
len,
|
|
|
|
&phys,
|
|
|
|
&len,
|
|
|
|
ViewShare,
|
|
|
|
0,
|
|
|
|
PAGE_READONLY)) != STATUS_SUCCESS)
|
2000-10-01 09:02:40 +08:00
|
|
|
{
|
2000-10-09 21:19:41 +08:00
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
2000-10-01 09:02:40 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (ptr, (char *) viewmem + (pos - phys.QuadPart), ulen);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem)))
|
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos += ulen;
|
|
|
|
return ulen;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_mem::close (void)
|
|
|
|
{
|
|
|
|
return fhandler_base::close ();
|
|
|
|
}
|
|
|
|
|
2002-02-26 01:47:51 +08:00
|
|
|
__off64_t
|
|
|
|
fhandler_dev_mem::lseek (__off64_t offset, int whence)
|
2000-10-01 09:02:40 +08:00
|
|
|
{
|
|
|
|
switch (whence)
|
|
|
|
{
|
|
|
|
case SEEK_SET:
|
|
|
|
pos = offset;
|
|
|
|
break;
|
2000-10-28 13:41:44 +08:00
|
|
|
|
2000-10-01 09:02:40 +08:00
|
|
|
case SEEK_CUR:
|
|
|
|
pos += offset;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEEK_END:
|
2000-10-05 01:08:46 +08:00
|
|
|
pos = mem_size;
|
|
|
|
pos += offset;
|
2000-10-01 09:02:40 +08:00
|
|
|
break;
|
2000-10-28 13:41:44 +08:00
|
|
|
|
2000-10-01 09:02:40 +08:00
|
|
|
default:
|
|
|
|
set_errno (EINVAL);
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 21:38:51 +08:00
|
|
|
return ILLEGAL_SEEK;
|
2000-10-01 09:02:40 +08:00
|
|
|
}
|
|
|
|
|
2000-10-05 01:08:46 +08:00
|
|
|
if (pos > mem_size)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 21:38:51 +08:00
|
|
|
return ILLEGAL_SEEK;
|
2000-10-05 01:08:46 +08:00
|
|
|
}
|
|
|
|
|
2000-10-01 09:02:40 +08:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2000-10-08 01:35:36 +08:00
|
|
|
HANDLE
|
|
|
|
fhandler_dev_mem::mmap (caddr_t *addr, size_t len, DWORD access,
|
2002-02-26 01:47:51 +08:00
|
|
|
int flags, __off64_t off)
|
2000-10-08 01:35:36 +08:00
|
|
|
{
|
2002-02-26 01:47:51 +08:00
|
|
|
if (off >= mem_size
|
2000-10-08 01:35:36 +08:00
|
|
|
|| (DWORD) len >= mem_size
|
2002-02-26 01:47:51 +08:00
|
|
|
|| off + len >= mem_size)
|
2000-10-08 01:35:36 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
syscall_printf ("-1 = mmap(): illegal parameter, set EINVAL");
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UNICODE_STRING memstr;
|
|
|
|
RtlInitUnicodeString (&memstr, L"\\device\\physicalmemory");
|
|
|
|
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
2001-01-11 20:33:12 +08:00
|
|
|
InitializeObjectAttributes(&attr, &memstr,
|
|
|
|
OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
|
2001-09-08 05:32:07 +08:00
|
|
|
NULL, NULL);
|
2000-10-08 01:35:36 +08:00
|
|
|
|
|
|
|
ACCESS_MASK section_access;
|
|
|
|
ULONG protect;
|
|
|
|
|
|
|
|
if (access & FILE_MAP_COPY)
|
|
|
|
{
|
|
|
|
section_access = SECTION_MAP_READ | SECTION_MAP_WRITE;
|
|
|
|
protect = PAGE_WRITECOPY;
|
|
|
|
}
|
|
|
|
else if (access & FILE_MAP_WRITE)
|
|
|
|
{
|
|
|
|
section_access = SECTION_MAP_READ | SECTION_MAP_WRITE;
|
|
|
|
protect = PAGE_READWRITE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
section_access = SECTION_MAP_READ;
|
|
|
|
protect = PAGE_READONLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE h;
|
|
|
|
NTSTATUS ret = NtOpenSection (&h, section_access, &attr);
|
|
|
|
if (!NT_SUCCESS(ret))
|
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
|
|
|
syscall_printf ("-1 = mmap(): NtOpenSection failed with %E");
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PHYSICAL_ADDRESS phys;
|
|
|
|
void *base = *addr;
|
|
|
|
DWORD dlen = len;
|
|
|
|
|
|
|
|
phys.QuadPart = (ULONGLONG) off;
|
|
|
|
|
|
|
|
if ((ret = NtMapViewOfSection (h,
|
2000-10-28 13:41:44 +08:00
|
|
|
INVALID_HANDLE_VALUE,
|
2000-10-08 01:35:36 +08:00
|
|
|
&base,
|
|
|
|
0L,
|
|
|
|
dlen,
|
|
|
|
&phys,
|
|
|
|
&dlen,
|
|
|
|
ViewShare /*??*/,
|
|
|
|
0,
|
|
|
|
protect)) != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
|
|
|
syscall_printf ("-1 = mmap(): NtMapViewOfSection failed with %E");
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2001-02-23 17:49:19 +08:00
|
|
|
if ((flags & MAP_FIXED) && base != *addr)
|
2000-10-08 01:35:36 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
syscall_printf ("-1 = mmap(): address shift with MAP_FIXED given");
|
|
|
|
NtUnmapViewOfSection (INVALID_HANDLE_VALUE, base);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*addr = (caddr_t) base;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_mem::munmap (HANDLE h, caddr_t addr, size_t len)
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
if (!NT_SUCCESS(ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, addr)))
|
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
CloseHandle (h);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_mem::msync (HANDLE h, caddr_t addr, size_t len, int flags)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-11 20:33:12 +08:00
|
|
|
BOOL
|
|
|
|
fhandler_dev_mem::fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset,
|
|
|
|
DWORD size, void *address)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
PHYSICAL_ADDRESS phys;
|
|
|
|
void *base = address;
|
|
|
|
DWORD dlen = size;
|
|
|
|
ULONG protect;
|
|
|
|
|
|
|
|
if (access & FILE_MAP_COPY)
|
|
|
|
protect = PAGE_WRITECOPY;
|
|
|
|
else if (access & FILE_MAP_WRITE)
|
|
|
|
protect = PAGE_READWRITE;
|
|
|
|
else
|
|
|
|
protect = PAGE_READONLY;
|
|
|
|
|
|
|
|
phys.QuadPart = (ULONGLONG) offset;
|
|
|
|
|
|
|
|
if ((ret = NtMapViewOfSection (h,
|
|
|
|
INVALID_HANDLE_VALUE,
|
|
|
|
&base,
|
|
|
|
0L,
|
|
|
|
dlen,
|
|
|
|
&phys,
|
|
|
|
&dlen,
|
|
|
|
ViewShare /*??*/,
|
|
|
|
0,
|
|
|
|
protect)) != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
|
|
|
syscall_printf ("-1 = fixup_mmap_after_fork(): NtMapViewOfSection failed with %E");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return base == address;
|
|
|
|
}
|
|
|
|
|
2000-10-01 09:02:40 +08:00
|
|
|
int
|
2002-02-26 01:47:51 +08:00
|
|
|
fhandler_dev_mem::fstat (struct __stat64 *buf, path_conv *pc)
|
2000-10-01 09:02:40 +08:00
|
|
|
{
|
2001-10-05 12:21:41 +08:00
|
|
|
this->fhandler_base::fstat (buf, pc);
|
2000-10-01 09:02:40 +08:00
|
|
|
buf->st_mode = S_IFCHR;
|
2001-10-05 12:21:41 +08:00
|
|
|
if (wincap.has_physical_mem_access ())
|
2000-10-01 09:02:40 +08:00
|
|
|
buf->st_mode |= S_IRUSR | S_IWUSR |
|
|
|
|
S_IRGRP | S_IWGRP |
|
|
|
|
S_IROTH | S_IWOTH;
|
2000-10-05 01:08:46 +08:00
|
|
|
buf->st_blksize = getpagesize ();
|
2000-10-01 09:02:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_mem::dup (fhandler_base *child)
|
|
|
|
{
|
2000-10-05 01:08:46 +08:00
|
|
|
int ret = fhandler_base::dup (child);
|
|
|
|
|
|
|
|
if (! ret)
|
|
|
|
{
|
|
|
|
fhandler_dev_mem *fhc = (fhandler_dev_mem *) child;
|
|
|
|
|
|
|
|
fhc->mem_size = mem_size;
|
|
|
|
fhc->pos = pos;
|
|
|
|
}
|
|
|
|
return ret;
|
2000-10-01 09:02:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_dev_mem::dump ()
|
|
|
|
{
|
|
|
|
paranoid_printf("here, fhandler_dev_mem");
|
|
|
|
}
|