Remove /dev/mem, /dev/kmem, /dev/port support.

* Makefile.in (DLL_OFILES): Drop fhandler_mem.o.
	(fhandler_mem_CFLAGS): Remove rule.
	* devices.in (enum fh_devices): Remove FH_MEM, FH_KMEM and FH_PORT.
	* devices.cc: Regenerate.
	* dtable.cc (fh_alloc): Drop handling for FH_MEM, FH_KMEM and FH_PORT.
	* fhandler.h (class fhandler_dev_mem): Remove.
	* fhandler_mem.cc: Remove file.
	* globals.cc (ro_u_pmem): Remove.
	* mmap.cc (fhandler_dev_mem::mmap): Remove.
	(fhandler_dev_mem::munmap): Remove.
	(fhandler_dev_mem::fixup_mmap_after_fork): Remove.
This commit is contained in:
Corinna Vinschen 2013-07-15 13:54:27 +00:00
parent 7ea982e75a
commit 4c4693008a
11 changed files with 2575 additions and 3009 deletions

View File

@ -1,3 +1,18 @@
2013-07-15 Corinna Vinschen <corinna@vinschen.de>
Remove /dev/mem, /dev/kmem, /dev/port support.
* Makefile.in (DLL_OFILES): Drop fhandler_mem.o.
(fhandler_mem_CFLAGS): Remove rule.
* devices.in (enum fh_devices): Remove FH_MEM, FH_KMEM and FH_PORT.
* devices.cc: Regenerate.
* dtable.cc (fh_alloc): Drop handling for FH_MEM, FH_KMEM and FH_PORT.
* fhandler.h (class fhandler_dev_mem): Remove.
* fhandler_mem.cc: Remove file.
* globals.cc (ro_u_pmem): Remove.
* mmap.cc (fhandler_dev_mem::mmap): Remove.
(fhandler_dev_mem::munmap): Remove.
(fhandler_dev_mem::fixup_mmap_after_fork): Remove.
2013-07-15 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h (CYGWIN_VERSION_DLL_MINOR): Bump to 22.

View File

@ -158,7 +158,7 @@ DLL_OFILES:=advapi32.o arc4random.o assert.o autoload.o base64.o bsdlib.o ctype.
devices.o dir.o dlfcn.o dll_init.o dtable.o environ.o errno.o exceptions.o \
exec.o external.o fcntl.o fenv.o fhandler.o fhandler_clipboard.o \
fhandler_console.o fhandler_dev.o fhandler_disk_file.o fhandler_dsp.o \
fhandler_fifo.o fhandler_floppy.o fhandler_mailslot.o fhandler_mem.o \
fhandler_fifo.o fhandler_floppy.o fhandler_mailslot.o \
fhandler_netdrive.o fhandler_nodevice.o fhandler_proc.o \
fhandler_process.o fhandler_procnet.o fhandler_procsys.o \
fhandler_procsysvipc.o fhandler_random.o fhandler_raw.o \
@ -286,7 +286,6 @@ fhandler_console_CFLAGS:=-fomit-frame-pointer
fhandler_disk_file_CFLAGS:=-fomit-frame-pointer
fhandler_dsp_CFLAGS:=-fomit-frame-pointer
fhandler_floppy_CFLAGS:=-fomit-frame-pointer
fhandler_mem_CFLAGS:=-fomit-frame-pointer
fhandler_netdrive_CFLAGS:=-fomit-frame-pointer
fhandler_proc_CFLAGS:=-fomit-frame-pointer
fhandler_process_CFLAGS:=-fomit-frame-pointer

File diff suppressed because it is too large Load Diff

View File

@ -232,10 +232,7 @@ enum fh_devices
FH_SDDX = FHDEV (DEV_SD7_MAJOR, 240),
DEV_MEM_MAJOR = 1,
FH_MEM = FHDEV (DEV_MEM_MAJOR, 1),
FH_KMEM = FHDEV (DEV_MEM_MAJOR, 2), /* not implemented yet */
FH_NULL = FHDEV (DEV_MEM_MAJOR, 3),
FH_PORT = FHDEV (DEV_MEM_MAJOR, 4),
FH_ZERO = FHDEV (DEV_MEM_MAJOR, 5),
FH_FULL = FHDEV (DEV_MEM_MAJOR, 7),
FH_RANDOM = FHDEV (DEV_MEM_MAJOR, 8),

View File

@ -156,10 +156,7 @@ const device dev_error_storage =
"/dev/full", BRACK(FH_FULL), "/dev/full", exists, S_IFCHR
"/dev/random", BRACK(FH_RANDOM), "/dev/random", exists, S_IFCHR
"/dev/urandom", BRACK(FH_URANDOM), "/dev/urandom", exists, S_IFCHR, =urandom_dev
"/dev/mem", BRACK(FH_MEM), "/dev/mem", exists, S_IFCHR
"/dev/kmem", BRACK(FH_KMEM), "/dev/kmem", exists, S_IFCHR
"/dev/clipboard", BRACK(FH_CLIPBOARD), "/dev/clipboard", exists, S_IFCHR
"/dev/port", BRACK(FH_PORT), "/dev/port", exists, S_IFCHR
"/dev/com%(1-16)d", BRACK(FHDEV(DEV_SERIAL_MAJOR, {$1 - 1})), "\\??\\COM{$1}", exists_ntdev_silent, S_IFCHR
"/dev/ttyS%(0-63)d", BRACK(FHDEV(DEV_SERIAL_MAJOR, {$1})), "\\??\\COM{$1 + 1}", exists_ntdev, S_IFCHR
":pipe", BRACK(FH_PIPE), "/dev/pipe", exists_internal, S_IFCHR

View File

@ -528,11 +528,6 @@ fh_alloc (path_conv& pc)
case FH_URANDOM:
fh = cnew (fhandler_dev_random);
break;
case FH_MEM:
case FH_KMEM:
case FH_PORT:
fh = cnew (fhandler_dev_mem);
break;
case FH_CLIPBOARD:
fh = cnew (fhandler_dev_clipboard);
break;

View File

@ -1687,46 +1687,6 @@ class fhandler_dev_random: public fhandler_base
}
};
class fhandler_dev_mem: public fhandler_base
{
protected:
SIZE_T mem_size;
off_t pos;
public:
fhandler_dev_mem ();
~fhandler_dev_mem ();
int open (int flags, mode_t mode = 0);
ssize_t __stdcall write (const void *ptr, size_t ulen);
void __reg3 read (void *ptr, size_t& len);
off_t lseek (off_t offset, int whence);
int __reg2 fstat (struct stat *buf);
HANDLE mmap (caddr_t *addr, size_t len, int prot, int flags, off_t off);
int munmap (HANDLE h, caddr_t addr, size_t len);
int msync (HANDLE h, caddr_t addr, size_t len, int flags);
bool fixup_mmap_after_fork (HANDLE h, int prot, int flags,
off_t offset, DWORD size, void *address);
fhandler_dev_mem (void *) {}
void copyto (fhandler_base *x)
{
x->pc.free_strings ();
*reinterpret_cast<fhandler_dev_mem *> (x) = *this;
x->reset (this);
}
fhandler_dev_mem *clone (cygheap_types malloc_type = HEAP_FHANDLER)
{
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_dev_mem));
fhandler_dev_mem *fh = new (ptr) fhandler_dev_mem (ptr);
copyto (fh);
return fh;
}
};
class fhandler_dev_clipboard: public fhandler_base
{
off_t pos;
@ -2148,7 +2108,6 @@ typedef union
char __dev_clipboard[sizeof (fhandler_dev_clipboard)];
char __dev_dsp[sizeof (fhandler_dev_dsp)];
char __dev_floppy[sizeof (fhandler_dev_floppy)];
char __dev_mem[sizeof (fhandler_dev_mem)];
char __dev_null[sizeof (fhandler_dev_null)];
char __dev_random[sizeof (fhandler_dev_random)];
char __dev_raw[sizeof (fhandler_dev_raw)];

View File

@ -1,258 +0,0 @@
/* fhandler_mem.cc. See fhandler.h for a description of the fhandler classes.
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010, 2011,
2012, 2013 Red Hat, Inc.
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 <unistd.h>
#include "cygerrno.h"
#include "path.h"
#include "fhandler.h"
#include "ntdll.h"
/**********************************************************************/
/* fhandler_dev_mem */
fhandler_dev_mem::fhandler_dev_mem ()
: fhandler_base ()
{
}
fhandler_dev_mem::~fhandler_dev_mem ()
{
}
int
fhandler_dev_mem::open (int flags, mode_t)
{
NTSTATUS status;
if (!wincap.has_physical_mem_access ())
{
set_errno (EACCES);
debug_printf ("%s is accessible under XP only", dev ().name);
return 0;
}
if (dev () == FH_MEM) /* /dev/mem */
{
SYSTEM_BASIC_INFORMATION sbi;
status = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
sizeof sbi, NULL);
if (NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
debug_printf("NtQuerySystemInformation: status %p", status);
mem_size = 0;
}
else
mem_size = (SIZE_T) sbi.PhysicalPageSize
* (SIZE_T) sbi.NumberOfPhysicalPages;
debug_printf ("MemSize: %ld MB", mem_size >> 20);
}
else if (dev () == FH_KMEM) /* /dev/kmem - Not yet supported */
{
mem_size = 0;
debug_printf ("KMemSize: %ld MB", mem_size >> 20);
}
else if (dev () == FH_PORT) /* /dev/port == First 64K of /dev/mem */
{
mem_size = 65536;
debug_printf ("PortSize: 64 KB");
}
else
{
mem_size = 0;
debug_printf ("Illegal minor number");
}
/* Check for illegal flags. */
if (flags & (O_APPEND | O_TRUNC | O_EXCL))
{
set_errno (EINVAL);
return 0;
}
OBJECT_ATTRIBUTES attr;
InitializeObjectAttributes (&attr, &ro_u_pmem,
OBJ_CASE_INSENSITIVE
| (flags & O_CLOEXEC ? 0 : OBJ_INHERIT),
NULL, NULL);
ACCESS_MASK section_access;
if ((flags & O_ACCMODE) == O_RDONLY)
{
set_access (GENERIC_READ);
section_access = SECTION_MAP_READ;
}
else if ((flags & O_ACCMODE) == O_WRONLY)
{
set_access (GENERIC_WRITE);
section_access = SECTION_MAP_READ | SECTION_MAP_WRITE;
}
else
{
set_access (GENERIC_READ | GENERIC_WRITE);
section_access = SECTION_MAP_READ | SECTION_MAP_WRITE;
}
HANDLE mem;
status = NtOpenSection (&mem, section_access, &attr);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
set_io_handle (NULL);
return 0;
}
set_io_handle (mem);
set_open_status ();
return 1;
}
ssize_t __stdcall
fhandler_dev_mem::write (const void *ptr, size_t ulen)
{
if (!ulen || pos >= (off_t) mem_size)
return 0;
if (!(get_access () & GENERIC_WRITE))
{
set_errno (EINVAL);
return -1;
}
if (pos + ulen > mem_size)
ulen = (off_t) mem_size - pos;
PHYSICAL_ADDRESS phys;
NTSTATUS status;
void *viewmem = NULL;
SIZE_T len = ulen + wincap.page_size () - 1;
phys.QuadPart = (ULONGLONG) pos;
status = NtMapViewOfSection (get_handle (), INVALID_HANDLE_VALUE, &viewmem,
0L, len, &phys, &len, ViewShare, 0,
PAGE_READONLY);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
return -1;
}
memcpy ((char *) viewmem + (pos - phys.QuadPart), ptr, ulen);
status = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
return -1;
}
pos += ulen;
return ulen;
}
void __reg3
fhandler_dev_mem::read (void *ptr, size_t& ulen)
{
if (!ulen || pos >= (off_t) mem_size)
{
ulen = 0;
return;
}
if (!(get_access () & GENERIC_READ))
{
set_errno (EINVAL);
ulen = (size_t) -1;
return;
}
if (pos + ulen > mem_size)
ulen = (off_t) mem_size - pos;
PHYSICAL_ADDRESS phys;
NTSTATUS status;
void *viewmem = NULL;
SIZE_T len = ulen + wincap.page_size () - 1;
phys.QuadPart = (ULONGLONG) pos;
status = NtMapViewOfSection (get_handle (), INVALID_HANDLE_VALUE, &viewmem,
0L, len, &phys, &len, ViewShare, 0,
PAGE_READONLY);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
ulen = (size_t) -1;
return;
}
memcpy (ptr, (char *) viewmem + (pos - phys.QuadPart), ulen);
status = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
ulen = (size_t) -1;
return;
}
pos += ulen;
}
off_t
fhandler_dev_mem::lseek (off_t offset, int whence)
{
switch (whence)
{
case SEEK_SET:
pos = offset;
break;
case SEEK_CUR:
pos += offset;
break;
case SEEK_END:
pos = (off_t) mem_size;
pos += offset;
break;
default:
set_errno (EINVAL);
return ILLEGAL_SEEK;
}
if (pos > (off_t) mem_size)
{
set_errno (EINVAL);
return ILLEGAL_SEEK;
}
return pos;
}
int __reg2
fhandler_dev_mem::fstat (struct stat *buf)
{
fhandler_base::fstat (buf);
buf->st_blksize = wincap.page_size ();
if (is_auto_device ())
{
buf->st_mode = S_IFCHR;
if (wincap.has_physical_mem_access ())
buf->st_mode |= S_IRUSR | S_IWUSR |
S_IRGRP | S_IWGRP |
S_IROTH | S_IWOTH;
}
return 0;
}

View File

@ -127,7 +127,6 @@ extern "C" {
extern UNICODE_STRING _RDATA ro_u_sys = _ROU (L".sys");
extern UNICODE_STRING _RDATA ro_u_proc = _ROU (L"proc");
extern UNICODE_STRING _RDATA ro_u_dev = _ROU (L"dev");
extern UNICODE_STRING _RDATA ro_u_pmem = _ROU (L"\\Device\\PhysicalMemory");
extern UNICODE_STRING _RDATA ro_u_natp = _ROU (L"\\??\\");
extern UNICODE_STRING _RDATA ro_u_uncp = _ROU (L"\\??\\UNC\\");
extern UNICODE_STRING _RDATA ro_u_mtx = _ROU (L"mtx");

View File

@ -1811,100 +1811,6 @@ fhandler_disk_file::fixup_mmap_after_fork (HANDLE h, int prot, int flags,
return base == address;
}
HANDLE
fhandler_dev_mem::mmap (caddr_t *addr, size_t len, int prot,
int flags, off_t off)
{
if (off >= (off_t) mem_size
|| len >= mem_size
|| off + len >= mem_size)
{
set_errno (EINVAL);
debug_printf ("-1 = mmap(): illegal parameter, set EINVAL");
return INVALID_HANDLE_VALUE;
}
OBJECT_ATTRIBUTES attr;
InitializeObjectAttributes (&attr, &ro_u_pmem,
OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
NULL, NULL);
/* Section access is bit-wise ored, while on the Win32 level access
is only one of the values. It's not quite clear if the section
access has to be defined this way, or if SECTION_ALL_ACCESS would
be sufficient but this worked fine so far, so why change? */
ACCESS_MASK section_access;
if (prot & PROT_WRITE)
section_access = SECTION_MAP_READ | SECTION_MAP_WRITE;
else
section_access = SECTION_MAP_READ;
HANDLE h;
NTSTATUS status = NtOpenSection (&h, section_access, &attr);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
debug_printf ("-1 = mmap(): NtOpenSection failed with %E");
return INVALID_HANDLE_VALUE;
}
void *base = MapView (h, *addr, len, get_access (), prot,
flags | MAP_ANONYMOUS, off);
if (!base || (fixed (flags) && base != *addr))
{
if (!base)
__seterrno ();
else
{
NtUnmapViewOfSection (NtCurrentProcess (), base);
set_errno (EINVAL);
debug_printf ("MapView: address shift with MAP_FIXED given");
}
NtClose (h);
return INVALID_HANDLE_VALUE;
}
*addr = (caddr_t) base;
return h;
}
int
fhandler_dev_mem::munmap (HANDLE h, caddr_t addr, size_t len)
{
NTSTATUS status;
if (!NT_SUCCESS (status = NtUnmapViewOfSection (NtCurrentProcess (), addr)))
{
__seterrno_from_nt_status (status);
return -1;
}
NtClose (h);
return 0;
}
int
fhandler_dev_mem::msync (HANDLE h, caddr_t addr, size_t len, int flags)
{
return 0;
}
bool
fhandler_dev_mem::fixup_mmap_after_fork (HANDLE h, int prot, int flags,
off_t offset, DWORD size,
void *address)
{
void *base = MapView (h, address, size, get_access (), prot,
flags | MAP_ANONYMOUS, offset);
if (base != address)
{
MEMORY_BASIC_INFORMATION m;
VirtualQuery (address, &m, sizeof (m));
system_printf ("requested %p != %p mem alloc base %p, state %y, "
"size %lu, %E", address, base, m.AllocationBase, m.State,
m.RegionSize);
}
return base == address;
}
/* Call to re-create all the file mappings in a forked child. Called from
the child in initialization. At this point we are passed a valid
mmapped_areas map, and all the HANDLE's are valid for the child, but

View File

@ -0,0 +1,14 @@
What's new:
-----------
What changed:
-----------
- Support for /dev/mem, /dev/kmem and /dev/port removed, since OS support
was limited to 32 bit Windows XP only.
Bug fixes:
----------