* mmap.cc: Call NtClose instead of CloseHandle throughout.

(CreateMapping): Drop unused last argument.  Accommodate throughout.
	(mmap64): Re-open file with execute permissions using NtOpenFile.
This commit is contained in:
Corinna Vinschen 2007-08-13 19:44:31 +00:00
parent deafd19cea
commit 7d2ade3341
2 changed files with 32 additions and 17 deletions

View File

@ -1,3 +1,9 @@
2007-08-13 Corinna Vinschen <corinna@vinschen.de>
* mmap.cc: Call NtClose instead of CloseHandle throughout.
(CreateMapping): Drop unused last argument. Accommodate throughout.
(mmap64): Re-open file with execute permissions using NtOpenFile.
2007-08-13 Corinna Vinschen <corinna@vinschen.de> 2007-08-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (fhandler_base::close_fs): Reintroduce (as inline function) * fhandler.h (fhandler_base::close_fs): Reintroduce (as inline function)

View File

@ -136,7 +136,7 @@ gen_protect (int prot, int flags)
static HANDLE static HANDLE
CreateMapping (HANDLE fhdl, size_t len, _off64_t off, DWORD openflags, CreateMapping (HANDLE fhdl, size_t len, _off64_t off, DWORD openflags,
int prot, int flags, const char *) int prot, int flags)
{ {
HANDLE h; HANDLE h;
NTSTATUS ret; NTSTATUS ret;
@ -166,7 +166,7 @@ CreateMapping (HANDLE fhdl, size_t len, _off64_t off, DWORD openflags,
&sectionsize, PAGE_READWRITE, attributes, fhdl); &sectionsize, PAGE_READWRITE, attributes, fhdl);
if (NT_SUCCESS (ret) && protect != PAGE_READWRITE) if (NT_SUCCESS (ret) && protect != PAGE_READWRITE)
{ {
CloseHandle (h); NtClose (h);
ret = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa, ret = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa,
&sectionsize, protect, attributes, fhdl); &sectionsize, protect, attributes, fhdl);
} }
@ -872,11 +872,21 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
/* You can't create mappings with PAGE_EXECUTE protection if /* You can't create mappings with PAGE_EXECUTE protection if
the file isn't explicitely opened with EXECUTE access. */ the file isn't explicitely opened with EXECUTE access. */
HANDLE h = CreateFile (fh->get_win32_name (), UNICODE_STRING fname;
fh->get_access () | GENERIC_EXECUTE, OBJECT_ATTRIBUTES attr;
FILE_SHARE_VALID_FLAGS, &sec_none_nih, NTSTATUS status;
OPEN_EXISTING, 0, NULL); HANDLE h;
if (h != INVALID_HANDLE_VALUE) IO_STATUS_BLOCK io;
RtlInitUnicodeString (&fname, L"");
InitializeObjectAttributes (&attr, &fname, OBJ_CASE_INSENSITIVE,
fh->get_handle (), NULL);
status = NtOpenFile (&h,
fh->get_access () | GENERIC_EXECUTE | SYNCHRONIZE,
&attr, &io, FILE_SHARE_VALID_FLAGS,
FILE_SYNCHRONOUS_IO_NONALERT
| FILE_OPEN_FOR_BACKUP_INTENT);
if (NT_SUCCESS (status))
{ {
fh_disk_file.set_io_handle (h); fh_disk_file.set_io_handle (h);
fh_disk_file.set_access (fh->get_access () | GENERIC_EXECUTE); fh_disk_file.set_access (fh->get_access () | GENERIC_EXECUTE);
@ -1065,7 +1075,7 @@ out:
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap"); ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
if (fh_disk_file.get_handle ()) if (fh_disk_file.get_handle ())
CloseHandle (fh_disk_file.get_handle ()); NtClose (fh_disk_file.get_handle ());
syscall_printf ("%p = mmap() ", ret); syscall_printf ("%p = mmap() ", ret);
return ret; return ret;
@ -1495,8 +1505,7 @@ fhandler_dev_zero::mmap (caddr_t *addr, size_t len, int prot,
} }
else else
{ {
h = CreateMapping (get_handle (), len, off, get_access (), h = CreateMapping (get_handle (), len, off, get_access (), prot, flags);
prot, flags, get_win32_name ());
if (!h) if (!h)
{ {
__seterrno (); __seterrno ();
@ -1515,7 +1524,7 @@ fhandler_dev_zero::mmap (caddr_t *addr, size_t len, int prot,
set_errno (EINVAL); set_errno (EINVAL);
debug_printf ("MapView: address shift with MAP_FIXED given"); debug_printf ("MapView: address shift with MAP_FIXED given");
} }
CloseHandle (h); NtClose (h);
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
} }
@ -1531,7 +1540,7 @@ fhandler_dev_zero::munmap (HANDLE h, caddr_t addr, size_t len)
else else
{ {
UnmapViewOfFile (addr); UnmapViewOfFile (addr);
CloseHandle (h); NtClose (h);
} }
return 0; return 0;
} }
@ -1576,7 +1585,7 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, int prot,
int flags, _off64_t off) int flags, _off64_t off)
{ {
HANDLE h = CreateMapping (get_handle (), len, off, get_access (), HANDLE h = CreateMapping (get_handle (), len, off, get_access (),
prot, flags, get_win32_name ()); prot, flags);
if (!h) if (!h)
{ {
__seterrno (); __seterrno ();
@ -1595,7 +1604,7 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, int prot,
set_errno (EINVAL); set_errno (EINVAL);
debug_printf ("MapView: address shift with MAP_FIXED given"); debug_printf ("MapView: address shift with MAP_FIXED given");
} }
CloseHandle (h); NtClose (h);
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
@ -1607,7 +1616,7 @@ int
fhandler_disk_file::munmap (HANDLE h, caddr_t addr, size_t len) fhandler_disk_file::munmap (HANDLE h, caddr_t addr, size_t len)
{ {
UnmapViewOfFile (addr); UnmapViewOfFile (addr);
CloseHandle (h); NtClose (h);
return 0; return 0;
} }
@ -1692,7 +1701,7 @@ fhandler_dev_mem::mmap (caddr_t *addr, size_t len, int prot,
set_errno (EINVAL); set_errno (EINVAL);
debug_printf ("MapView: address shift with MAP_FIXED given"); debug_printf ("MapView: address shift with MAP_FIXED given");
} }
CloseHandle (h); NtClose (h);
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
@ -1709,7 +1718,7 @@ fhandler_dev_mem::munmap (HANDLE h, caddr_t addr, size_t len)
__seterrno_from_nt_status (ret); __seterrno_from_nt_status (ret);
return -1; return -1;
} }
CloseHandle (h); NtClose (h);
return 0; return 0;
} }