2000-02-18 03:38:33 +08:00
|
|
|
/* mmap.cc
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2008-04-08 00:15:45 +08:00
|
|
|
#include "miscfuncs.h"
|
2001-01-16 03:42:33 +08:00
|
|
|
#include <unistd.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/mman.h>
|
2005-12-07 19:16:47 +08:00
|
|
|
#include <sys/param.h>
|
2005-01-13 06:40:46 +08:00
|
|
|
#include "cygerrno.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "dtable.h"
|
2001-04-17 01:26:04 +08:00
|
|
|
#include "cygheap.h"
|
2005-02-26 05:23:15 +08:00
|
|
|
#include "ntdll.h"
|
2007-11-27 18:09:05 +08:00
|
|
|
#include <sys/queue.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
/* __PROT_ATTACH indicates an anonymous mapping which is supposed to be
|
|
|
|
attached to a file mapping for pages beyond the file's EOF. The idea
|
|
|
|
is to support mappings longer than the file, without the file growing
|
|
|
|
to mapping length (POSIX semantics). */
|
|
|
|
#define __PROT_ATTACH 0x8000000
|
|
|
|
/* Filler pages are the pages from the last file backed page to the next
|
|
|
|
64K boundary. These pages are created as anonymous pages, but with
|
|
|
|
the same page protection as the file's pages, since POSIX applications
|
|
|
|
expect to be able to access this part the same way as the file pages. */
|
|
|
|
#define __PROT_FILLER 0x4000000
|
|
|
|
|
2007-01-09 19:18:57 +08:00
|
|
|
/* Stick with 4K pages for bookkeeping, otherwise we just get confused
|
|
|
|
when trying to do file mappings with trailing filler pages correctly. */
|
2011-12-22 19:02:36 +08:00
|
|
|
#define PAGE_CNT(bytes) howmany((bytes), wincap.page_size())
|
2001-01-16 03:42:33 +08:00
|
|
|
|
2002-09-23 08:31:31 +08:00
|
|
|
#define PGBITS (sizeof (DWORD)*8)
|
|
|
|
#define MAPSIZE(pages) howmany ((pages), PGBITS)
|
2001-01-16 03:42:33 +08:00
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
#define MAP_SET(n) (page_map[(n)/PGBITS] |= (1L << ((n) % PGBITS)))
|
|
|
|
#define MAP_CLR(n) (page_map[(n)/PGBITS] &= ~(1L << ((n) % PGBITS)))
|
|
|
|
#define MAP_ISSET(n) (page_map[(n)/PGBITS] & (1L << ((n) % PGBITS)))
|
2001-01-16 03:42:33 +08:00
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
/* Used for anonymous mappings. */
|
|
|
|
static fhandler_dev_zero fh_anonymous;
|
2005-11-30 00:28:05 +08:00
|
|
|
|
2007-11-27 22:45:14 +08:00
|
|
|
/* Used for thread synchronization while accessing mmap bookkeeping lists. */
|
|
|
|
static NO_COPY muto mmap_guard;
|
|
|
|
#define LIST_LOCK() (mmap_guard.init ("mmap_guard")->acquire ())
|
|
|
|
#define LIST_UNLOCK() (mmap_guard.release ())
|
|
|
|
|
2005-11-30 00:28:05 +08:00
|
|
|
/* Small helpers to avoid having lots of flag bit tests in the code. */
|
|
|
|
static inline bool
|
|
|
|
priv (int flags)
|
|
|
|
{
|
|
|
|
return (flags & MAP_PRIVATE) == MAP_PRIVATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
fixed (int flags)
|
|
|
|
{
|
|
|
|
return (flags & MAP_FIXED) == MAP_FIXED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
anonymous (int flags)
|
|
|
|
{
|
|
|
|
return (flags & MAP_ANONYMOUS) == MAP_ANONYMOUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
noreserve (int flags)
|
|
|
|
{
|
|
|
|
return (flags & MAP_NORESERVE) == MAP_NORESERVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
autogrow (int flags)
|
|
|
|
{
|
|
|
|
return (flags & MAP_AUTOGROW) == MAP_AUTOGROW;
|
|
|
|
}
|
2003-09-04 18:27:51 +08:00
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
static inline bool
|
|
|
|
attached (int prot)
|
|
|
|
{
|
|
|
|
return (prot & __PROT_ATTACH) == __PROT_ATTACH;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
filler (int prot)
|
|
|
|
{
|
|
|
|
return (prot & __PROT_FILLER) == __PROT_FILLER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DWORD
|
|
|
|
gen_create_protect (DWORD openflags, int flags)
|
|
|
|
{
|
|
|
|
DWORD ret = PAGE_READONLY;
|
|
|
|
|
2005-12-12 18:00:32 +08:00
|
|
|
if (priv (flags))
|
|
|
|
ret = PAGE_WRITECOPY;
|
|
|
|
else if (openflags & GENERIC_WRITE)
|
|
|
|
ret = PAGE_READWRITE;
|
2005-12-07 19:16:47 +08:00
|
|
|
|
2007-02-23 01:35:14 +08:00
|
|
|
if (openflags & GENERIC_EXECUTE)
|
2005-12-07 19:16:47 +08:00
|
|
|
ret <<= 4;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
/* Generate Windows protection flags from mmap prot and flag values. */
|
2005-12-02 04:35:13 +08:00
|
|
|
static inline DWORD
|
2005-12-07 19:16:47 +08:00
|
|
|
gen_protect (int prot, int flags)
|
2005-11-29 06:32:29 +08:00
|
|
|
{
|
|
|
|
DWORD ret = PAGE_NOACCESS;
|
2005-12-07 19:16:47 +08:00
|
|
|
|
|
|
|
/* Attached pages are only reserved, but the protection must be a
|
|
|
|
valid value, so we just return PAGE_READWRITE. */
|
|
|
|
if (attached (prot))
|
|
|
|
return PAGE_EXECUTE_READWRITE;
|
|
|
|
|
|
|
|
if (prot & PROT_WRITE)
|
|
|
|
ret = (priv (flags) && (!anonymous (flags) || filler (prot)))
|
|
|
|
? PAGE_WRITECOPY : PAGE_READWRITE;
|
2005-11-29 06:32:29 +08:00
|
|
|
else if (prot & PROT_READ)
|
2005-12-07 19:16:47 +08:00
|
|
|
ret = PAGE_READONLY;
|
|
|
|
|
2007-02-23 01:35:14 +08:00
|
|
|
if (prot & PROT_EXEC)
|
2005-11-29 06:32:29 +08:00
|
|
|
ret <<= 4;
|
2005-12-07 19:16:47 +08:00
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HANDLE
|
2013-04-23 17:44:36 +08:00
|
|
|
CreateMapping (HANDLE fhdl, size_t len, off_t off, DWORD openflags,
|
2007-08-14 03:44:31 +08:00
|
|
|
int prot, int flags)
|
2005-11-29 06:32:29 +08:00
|
|
|
{
|
|
|
|
HANDLE h;
|
2011-12-22 19:02:36 +08:00
|
|
|
NTSTATUS status;
|
2005-11-29 06:32:29 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
LARGE_INTEGER sectionsize = { QuadPart: (LONGLONG) len };
|
2005-12-07 19:16:47 +08:00
|
|
|
ULONG protect = gen_create_protect (openflags, flags);
|
|
|
|
ULONG attributes = attached (prot) ? SEC_RESERVE : SEC_COMMIT;
|
2005-11-29 06:32:29 +08:00
|
|
|
|
|
|
|
OBJECT_ATTRIBUTES oa;
|
2019-02-26 04:06:15 +08:00
|
|
|
InitializeObjectAttributes (&oa, NULL, OBJ_INHERIT, NULL, NULL);
|
2005-11-29 06:32:29 +08:00
|
|
|
|
|
|
|
if (fhdl == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
/* Standard anonymous mapping needs non-zero len. */
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa, §ionsize,
|
|
|
|
protect, attributes, NULL);
|
2005-11-29 06:32:29 +08:00
|
|
|
}
|
2005-11-30 00:28:05 +08:00
|
|
|
else if (autogrow (flags))
|
2005-11-29 06:32:29 +08:00
|
|
|
{
|
|
|
|
/* Auto-grow only works if the protection is PAGE_READWRITE. So,
|
2005-12-22 13:57:54 +08:00
|
|
|
first we call NtCreateSection with PAGE_READWRITE, then, if the
|
2005-11-29 06:32:29 +08:00
|
|
|
requested protection is different, we close the mapping and
|
|
|
|
reopen it again with the correct protection, if auto-grow worked. */
|
|
|
|
sectionsize.QuadPart += off;
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa, §ionsize,
|
|
|
|
PAGE_READWRITE, attributes, fhdl);
|
|
|
|
if (NT_SUCCESS (status) && protect != PAGE_READWRITE)
|
2005-12-22 13:57:54 +08:00
|
|
|
{
|
2007-08-14 03:44:31 +08:00
|
|
|
NtClose (h);
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa, §ionsize,
|
|
|
|
protect, attributes, fhdl);
|
2005-11-29 06:32:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Zero len creates mapping for whole file and allows
|
2005-12-22 13:57:54 +08:00
|
|
|
AT_EXTENDABLE_FILE mapping, if we ever use it... */
|
2005-11-29 06:32:29 +08:00
|
|
|
sectionsize.QuadPart = 0;
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa, §ionsize,
|
|
|
|
protect, attributes, fhdl);
|
2005-11-29 06:32:29 +08:00
|
|
|
}
|
2011-12-22 19:02:36 +08:00
|
|
|
if (!NT_SUCCESS (status))
|
2005-11-29 06:32:29 +08:00
|
|
|
{
|
|
|
|
h = NULL;
|
2011-12-22 19:02:36 +08:00
|
|
|
SetLastError (RtlNtStatusToDosError (status));
|
2005-11-29 06:32:29 +08:00
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2008-04-21 20:46:58 +08:00
|
|
|
static void *
|
2007-02-22 18:54:47 +08:00
|
|
|
MapView (HANDLE h, void *addr, size_t len, DWORD openflags,
|
2013-04-23 17:44:36 +08:00
|
|
|
int prot, int flags, off_t off)
|
2005-11-29 06:32:29 +08:00
|
|
|
{
|
2011-12-22 19:02:36 +08:00
|
|
|
NTSTATUS status;
|
2005-11-29 06:32:29 +08:00
|
|
|
LARGE_INTEGER offset = { QuadPart:off };
|
2005-12-07 19:16:47 +08:00
|
|
|
DWORD protect = gen_create_protect (openflags, flags);
|
2005-11-29 06:32:29 +08:00
|
|
|
void *base = addr;
|
2013-04-23 17:44:36 +08:00
|
|
|
SIZE_T commitsize = attached (prot) ? 0 : len;
|
|
|
|
SIZE_T viewsize = len;
|
|
|
|
#ifdef __x86_64__ /* AT_ROUND_TO_PAGE isn't supported on 64 bit systems. */
|
|
|
|
ULONG alloc_type = MEM_TOP_DOWN;
|
|
|
|
#else
|
2006-11-01 02:41:16 +08:00
|
|
|
ULONG alloc_type = (base && !wincap.is_wow64 () ? AT_ROUND_TO_PAGE : 0)
|
|
|
|
| MEM_TOP_DOWN;
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
2005-11-29 06:32:29 +08:00
|
|
|
|
|
|
|
/* Try mapping using the given address first, even if it's NULL.
|
|
|
|
If it failed, and addr was not NULL and flags is not MAP_FIXED,
|
2007-01-17 18:49:24 +08:00
|
|
|
try again with NULL address.
|
2007-02-20 08:16:18 +08:00
|
|
|
|
2007-01-17 18:49:24 +08:00
|
|
|
Note: Retrying the mapping might be unnecessary, now that mmap64 checks
|
|
|
|
for a valid memory area first. */
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtMapViewOfSection (h, NtCurrentProcess (), &base, 0, commitsize,
|
|
|
|
&offset, &viewsize, ViewShare, alloc_type,
|
|
|
|
protect);
|
|
|
|
if (!NT_SUCCESS (status) && addr && !fixed (flags))
|
2005-11-29 06:32:29 +08:00
|
|
|
{
|
|
|
|
base = NULL;
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtMapViewOfSection (h, NtCurrentProcess (), &base, 0, commitsize,
|
|
|
|
&offset, &viewsize, ViewShare, 0, protect);
|
2005-11-29 06:32:29 +08:00
|
|
|
}
|
2011-12-22 19:02:36 +08:00
|
|
|
if (!NT_SUCCESS (status))
|
2005-11-29 06:32:29 +08:00
|
|
|
{
|
|
|
|
base = NULL;
|
2011-12-22 19:02:36 +08:00
|
|
|
SetLastError (RtlNtStatusToDosError (status));
|
2005-11-29 06:32:29 +08:00
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("%p (status %p) = NtMapViewOfSection (h:%p, addr:%p, len:%lu,"
|
|
|
|
" off:%Y, protect:%y, type:%y)",
|
2011-12-22 19:02:36 +08:00
|
|
|
base, status, h, addr, len, off, protect, 0);
|
2005-11-29 06:32:29 +08:00
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
2003-09-04 18:27:51 +08:00
|
|
|
/* Class structure used to keep a record of all current mmap areas
|
|
|
|
in a process. Needed for bookkeeping all mmaps in a process and
|
|
|
|
for duplicating all mmaps after fork() since mmaps are not propagated
|
|
|
|
to child processes by Windows. All information must be duplicated
|
|
|
|
by hand, see fixup_mmaps_after_fork().
|
2003-11-29 04:55:59 +08:00
|
|
|
|
2003-09-04 18:27:51 +08:00
|
|
|
The class structure:
|
2003-11-29 04:55:59 +08:00
|
|
|
|
2003-09-04 18:27:51 +08:00
|
|
|
One member of class map per process, global variable mmapped_areas.
|
2007-11-27 18:09:05 +08:00
|
|
|
Contains a singly-linked list of type class mmap_list. Each mmap_list
|
|
|
|
entry represents all mapping to a file, keyed by file descriptor and
|
|
|
|
file name hash.
|
|
|
|
Each list entry contains a singly-linked list of type class mmap_record.
|
|
|
|
Each mmap_record represents exactly one mapping. For each mapping, there's
|
2003-09-04 18:27:51 +08:00
|
|
|
an additional so called `page_map'. It's an array of bits, one bit
|
|
|
|
per mapped memory page. The bit is set if the page is accessible,
|
|
|
|
unset otherwise. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-03-18 21:42:03 +08:00
|
|
|
#pragma pack(push, 4)
|
2000-02-18 03:38:33 +08:00
|
|
|
class mmap_record
|
|
|
|
{
|
2007-11-27 18:09:05 +08:00
|
|
|
public:
|
|
|
|
LIST_ENTRY (mmap_record) mr_next;
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
private:
|
2013-04-23 17:44:36 +08:00
|
|
|
/* 4 byte on 32 bit, 8 byte on 64 bit */
|
2005-11-29 06:32:29 +08:00
|
|
|
HANDLE mapping_hdl;
|
2013-04-23 17:44:36 +08:00
|
|
|
SIZE_T len;
|
|
|
|
caddr_t base_address;
|
|
|
|
/* Always 8 bytes */
|
|
|
|
off_t offset;
|
|
|
|
/* Always 4 bytes */
|
|
|
|
int fd;
|
2005-12-07 19:16:47 +08:00
|
|
|
DWORD openflags;
|
2005-11-29 06:32:29 +08:00
|
|
|
int prot;
|
|
|
|
int flags;
|
2013-04-23 17:44:36 +08:00
|
|
|
dev_t dev;
|
2011-03-18 21:38:34 +08:00
|
|
|
DWORD page_map[0];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
public:
|
2016-05-21 03:48:10 +08:00
|
|
|
mmap_record (int nfd, HANDLE h, DWORD of, int p, int f, off_t o, SIZE_T l,
|
2005-12-22 13:57:54 +08:00
|
|
|
caddr_t b) :
|
2005-11-29 06:32:29 +08:00
|
|
|
mapping_hdl (h),
|
2013-04-23 17:44:36 +08:00
|
|
|
len (l),
|
|
|
|
base_address (b),
|
|
|
|
offset (o),
|
|
|
|
fd (nfd),
|
2005-12-07 19:16:47 +08:00
|
|
|
openflags (of),
|
2005-11-29 06:32:29 +08:00
|
|
|
prot (p),
|
2013-04-23 17:44:36 +08:00
|
|
|
flags (f)
|
2001-04-17 01:26:04 +08:00
|
|
|
{
|
2011-03-18 21:42:03 +08:00
|
|
|
dev = 0;
|
2001-09-03 10:13:05 +08:00
|
|
|
if (fd >= 0 && !cygheap->fdtab.not_open (fd))
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
dev = cygheap->fdtab[fd]->dev ();
|
2005-11-30 00:28:05 +08:00
|
|
|
else if (fd == -1)
|
2011-03-18 21:42:03 +08:00
|
|
|
dev = FH_ZERO;
|
2001-04-17 01:26:04 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
int get_fd () const { return fd; }
|
|
|
|
HANDLE get_handle () const { return mapping_hdl; }
|
2011-03-18 21:42:03 +08:00
|
|
|
int get_device () { return dev; }
|
2005-11-29 06:32:29 +08:00
|
|
|
int get_prot () const { return prot; }
|
2005-12-07 19:16:47 +08:00
|
|
|
int get_openflags () const { return openflags; }
|
2005-11-29 06:32:29 +08:00
|
|
|
int get_flags () const { return flags; }
|
2005-11-30 00:28:05 +08:00
|
|
|
bool priv () const { return ::priv (flags); }
|
|
|
|
bool fixed () const { return ::fixed (flags); }
|
|
|
|
bool anonymous () const { return ::anonymous (flags); }
|
|
|
|
bool noreserve () const { return ::noreserve (flags); }
|
|
|
|
bool autogrow () const { return ::autogrow (flags); }
|
2005-12-07 19:16:47 +08:00
|
|
|
bool attached () const { return ::attached (prot); }
|
|
|
|
bool filler () const { return ::filler (prot); }
|
2013-04-23 17:44:36 +08:00
|
|
|
off_t get_offset () const { return offset; }
|
|
|
|
SIZE_T get_len () const { return len; }
|
2005-11-29 06:32:29 +08:00
|
|
|
caddr_t get_address () const { return base_address; }
|
2003-09-04 18:27:51 +08:00
|
|
|
|
2011-03-18 21:38:34 +08:00
|
|
|
void init_page_map (mmap_record &r);
|
2003-09-04 18:27:51 +08:00
|
|
|
|
2016-05-21 03:48:10 +08:00
|
|
|
SIZE_T find_unused_pages (SIZE_T pages) const;
|
|
|
|
bool match (caddr_t addr, SIZE_T len, caddr_t &m_addr, SIZE_T &m_len);
|
|
|
|
off_t map_pages (SIZE_T len);
|
2013-04-23 17:44:36 +08:00
|
|
|
bool map_pages (caddr_t addr, SIZE_T len);
|
|
|
|
bool unmap_pages (caddr_t addr, SIZE_T len);
|
2003-01-15 04:40:09 +08:00
|
|
|
int access (caddr_t address);
|
2001-04-17 01:26:04 +08:00
|
|
|
|
|
|
|
fhandler_base *alloc_fh ();
|
|
|
|
void free_fh (fhandler_base *fh);
|
2005-12-22 13:57:54 +08:00
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
DWORD gen_create_protect () const
|
|
|
|
{ return ::gen_create_protect (get_openflags (), get_flags ()); }
|
|
|
|
DWORD gen_protect () const
|
|
|
|
{ return ::gen_protect (get_prot (), get_flags ()); }
|
2005-11-29 06:32:29 +08:00
|
|
|
bool compatible_flags (int fl) const;
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
2011-03-18 21:42:03 +08:00
|
|
|
#pragma pack(pop)
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2007-11-27 18:09:05 +08:00
|
|
|
class mmap_list
|
2003-09-04 18:27:51 +08:00
|
|
|
{
|
2007-11-27 18:09:05 +08:00
|
|
|
public:
|
|
|
|
LIST_ENTRY (mmap_list) ml_next;
|
|
|
|
LIST_HEAD (, mmap_record) recs;
|
|
|
|
|
2003-09-04 18:27:51 +08:00
|
|
|
private:
|
|
|
|
int fd;
|
2013-04-23 17:44:36 +08:00
|
|
|
ino_t hash;
|
2003-09-04 18:27:51 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
int get_fd () const { return fd; }
|
2013-04-23 17:44:36 +08:00
|
|
|
ino_t get_hash () const { return hash; }
|
2003-09-04 18:27:51 +08:00
|
|
|
|
2005-11-30 00:28:05 +08:00
|
|
|
bool anonymous () const { return fd == -1; }
|
2013-04-23 17:44:36 +08:00
|
|
|
void set (int nfd, struct stat *st);
|
2011-03-18 21:38:34 +08:00
|
|
|
mmap_record *add_record (mmap_record &r);
|
2007-11-27 18:09:05 +08:00
|
|
|
bool del_record (mmap_record *rec);
|
2013-04-23 17:44:36 +08:00
|
|
|
caddr_t try_map (void *addr, size_t len, int flags, off_t off);
|
2003-09-04 18:27:51 +08:00
|
|
|
};
|
|
|
|
|
2007-11-27 18:09:05 +08:00
|
|
|
class mmap_areas
|
2003-09-04 18:27:51 +08:00
|
|
|
{
|
|
|
|
public:
|
2007-11-27 18:09:05 +08:00
|
|
|
LIST_HEAD (, mmap_list) lists;
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
mmap_list *get_list_by_fd (int fd, struct stat *st);
|
|
|
|
mmap_list *add_list (int fd, struct stat *st);
|
2007-11-27 18:09:05 +08:00
|
|
|
void del_list (mmap_list *ml);
|
2003-09-04 18:27:51 +08:00
|
|
|
};
|
|
|
|
|
2005-12-02 04:35:13 +08:00
|
|
|
/* This is the global map structure pointer. */
|
2007-11-27 18:09:05 +08:00
|
|
|
static mmap_areas mmapped_areas;
|
2005-11-29 06:32:29 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
mmap_record::compatible_flags (int fl) const
|
|
|
|
{
|
|
|
|
#define MAP_COMPATMASK (MAP_TYPE | MAP_NORESERVE)
|
|
|
|
return (get_flags () & MAP_COMPATMASK) == (fl & MAP_COMPATMASK);
|
|
|
|
}
|
2003-09-04 18:27:51 +08:00
|
|
|
|
2016-05-21 03:48:10 +08:00
|
|
|
SIZE_T
|
|
|
|
mmap_record::find_unused_pages (SIZE_T pages) const
|
2001-01-16 03:42:33 +08:00
|
|
|
{
|
2016-05-21 03:48:10 +08:00
|
|
|
SIZE_T mapped_pages = PAGE_CNT (get_len ());
|
|
|
|
SIZE_T start;
|
2001-01-16 03:42:33 +08:00
|
|
|
|
2001-11-06 04:58:22 +08:00
|
|
|
if (pages > mapped_pages)
|
2016-05-21 03:48:10 +08:00
|
|
|
return (SIZE_T) -1;
|
2001-01-29 17:25:10 +08:00
|
|
|
for (start = 0; start <= mapped_pages - pages; ++start)
|
2001-01-16 03:42:33 +08:00
|
|
|
if (!MAP_ISSET (start))
|
|
|
|
{
|
2016-05-21 03:48:10 +08:00
|
|
|
SIZE_T cnt;
|
2001-09-03 10:13:05 +08:00
|
|
|
for (cnt = 0; cnt < pages; ++cnt)
|
2001-01-16 03:42:33 +08:00
|
|
|
if (MAP_ISSET (start + cnt))
|
|
|
|
break;
|
2001-09-03 10:13:05 +08:00
|
|
|
if (cnt >= pages)
|
2001-01-16 03:42:33 +08:00
|
|
|
return start;
|
|
|
|
}
|
2016-05-21 03:48:10 +08:00
|
|
|
return (SIZE_T) -1;
|
2001-01-16 03:42:33 +08:00
|
|
|
}
|
|
|
|
|
2007-11-27 18:09:05 +08:00
|
|
|
bool
|
2016-05-21 03:48:10 +08:00
|
|
|
mmap_record::match (caddr_t addr, SIZE_T len, caddr_t &m_addr, SIZE_T &m_len)
|
2007-11-27 18:09:05 +08:00
|
|
|
{
|
|
|
|
caddr_t low = (addr >= get_address ()) ? addr : get_address ();
|
|
|
|
caddr_t high = get_address ();
|
|
|
|
if (filler ())
|
|
|
|
high += get_len ();
|
|
|
|
else
|
2011-12-22 19:02:36 +08:00
|
|
|
high += (PAGE_CNT (get_len ()) * wincap.page_size ());
|
2007-11-27 18:09:05 +08:00
|
|
|
high = (addr + len < high) ? addr + len : high;
|
|
|
|
if (low < high)
|
|
|
|
{
|
|
|
|
m_addr = low;
|
|
|
|
m_len = high - low;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-18 21:38:34 +08:00
|
|
|
void
|
|
|
|
mmap_record::init_page_map (mmap_record &r)
|
2003-02-08 04:57:30 +08:00
|
|
|
{
|
2011-03-18 21:38:34 +08:00
|
|
|
*this = r;
|
2005-12-07 19:16:47 +08:00
|
|
|
DWORD start_protect = gen_create_protect ();
|
2005-12-02 04:35:13 +08:00
|
|
|
DWORD real_protect = gen_protect ();
|
2006-07-13 04:15:00 +08:00
|
|
|
if (real_protect != start_protect && !noreserve ()
|
2005-12-02 04:35:13 +08:00
|
|
|
&& !VirtualProtect (get_address (), get_len (),
|
|
|
|
real_protect, &start_protect))
|
2013-04-23 17:44:36 +08:00
|
|
|
system_printf ("Warning: VirtualProtect (addr: %p, len: %ly, "
|
|
|
|
"new_prot: %y, old_prot: %y), %E",
|
2005-12-02 04:35:13 +08:00
|
|
|
get_address (), get_len (),
|
|
|
|
real_protect, start_protect);
|
2013-04-23 17:44:36 +08:00
|
|
|
SIZE_T len = PAGE_CNT (get_len ());
|
2004-07-16 22:32:03 +08:00
|
|
|
while (len-- > 0)
|
2005-11-29 06:32:29 +08:00
|
|
|
MAP_SET (len);
|
2003-02-08 04:57:30 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
off_t
|
2016-05-21 03:48:10 +08:00
|
|
|
mmap_record::map_pages (SIZE_T len)
|
2001-01-16 03:42:33 +08:00
|
|
|
{
|
2003-02-08 04:57:30 +08:00
|
|
|
/* Used ONLY if this mapping matches into the chunk of another already
|
|
|
|
performed mapping in a special case of MAP_ANON|MAP_PRIVATE.
|
2003-03-10 04:31:07 +08:00
|
|
|
|
2011-03-18 21:38:34 +08:00
|
|
|
Otherwise it's job is now done by init_page_map(). */
|
2005-11-29 06:32:29 +08:00
|
|
|
DWORD old_prot;
|
2016-05-21 03:48:10 +08:00
|
|
|
debug_printf ("map_pages (fd=%d, len=%lu)", get_fd (), len);
|
2001-01-16 03:42:33 +08:00
|
|
|
len = PAGE_CNT (len);
|
|
|
|
|
2016-05-21 03:48:10 +08:00
|
|
|
off_t off = find_unused_pages (len);
|
|
|
|
if (off == (off_t) -1)
|
|
|
|
return (off_t) 0;
|
2005-11-30 00:28:05 +08:00
|
|
|
if (!noreserve ()
|
2011-12-22 19:02:36 +08:00
|
|
|
&& !VirtualProtect (get_address () + off * wincap.page_size (),
|
|
|
|
len * wincap.page_size (), gen_protect (),
|
2007-01-09 19:18:57 +08:00
|
|
|
&old_prot))
|
2002-03-14 04:54:57 +08:00
|
|
|
{
|
2002-09-24 22:17:50 +08:00
|
|
|
__seterrno ();
|
2016-05-21 03:48:10 +08:00
|
|
|
return (off_t) -1;
|
2002-03-14 04:54:57 +08:00
|
|
|
}
|
2001-01-16 03:42:33 +08:00
|
|
|
|
2003-02-08 04:57:30 +08:00
|
|
|
while (len-- > 0)
|
|
|
|
MAP_SET (off + len);
|
2011-12-22 19:02:36 +08:00
|
|
|
return off * wincap.page_size ();
|
2001-01-16 03:42:33 +08:00
|
|
|
}
|
|
|
|
|
2005-02-25 19:15:22 +08:00
|
|
|
bool
|
2013-04-23 17:44:36 +08:00
|
|
|
mmap_record::map_pages (caddr_t addr, SIZE_T len)
|
2005-02-25 19:15:22 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("map_pages (addr=%p, len=%lu)", addr, len);
|
2005-11-29 06:32:29 +08:00
|
|
|
DWORD old_prot;
|
2016-05-21 03:48:10 +08:00
|
|
|
off_t off = addr - get_address ();
|
2011-12-22 19:02:36 +08:00
|
|
|
off /= wincap.page_size ();
|
2005-02-25 19:15:22 +08:00
|
|
|
len = PAGE_CNT (len);
|
|
|
|
/* First check if the area is unused right now. */
|
2016-05-21 03:48:10 +08:00
|
|
|
for (SIZE_T l = 0; l < len; ++l)
|
2005-02-25 19:15:22 +08:00
|
|
|
if (MAP_ISSET (off + l))
|
|
|
|
{
|
2005-05-02 11:50:11 +08:00
|
|
|
set_errno (EINVAL);
|
2005-02-25 19:15:22 +08:00
|
|
|
return false;
|
|
|
|
}
|
2005-11-30 00:28:05 +08:00
|
|
|
if (!noreserve ()
|
2011-12-22 19:02:36 +08:00
|
|
|
&& !VirtualProtect (get_address () + off * wincap.page_size (),
|
|
|
|
len * wincap.page_size (), gen_protect (),
|
2007-01-09 19:18:57 +08:00
|
|
|
&old_prot))
|
2005-02-25 19:15:22 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (; len-- > 0; ++off)
|
|
|
|
MAP_SET (off);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-12-08 06:37:12 +08:00
|
|
|
bool
|
2013-04-23 17:44:36 +08:00
|
|
|
mmap_record::unmap_pages (caddr_t addr, SIZE_T len)
|
2001-01-16 03:42:33 +08:00
|
|
|
{
|
|
|
|
DWORD old_prot;
|
2016-05-21 03:48:10 +08:00
|
|
|
SIZE_T off = addr - get_address ();
|
2006-07-13 18:29:21 +08:00
|
|
|
if (noreserve ()
|
2007-01-09 19:18:57 +08:00
|
|
|
&& !VirtualFree (get_address () + off, len, MEM_DECOMMIT))
|
2005-12-02 04:35:13 +08:00
|
|
|
debug_printf ("VirtualFree in unmap_pages () failed, %E");
|
2007-01-09 19:18:57 +08:00
|
|
|
else if (!VirtualProtect (get_address () + off, len, PAGE_NOACCESS,
|
|
|
|
&old_prot))
|
2005-12-02 04:35:13 +08:00
|
|
|
debug_printf ("VirtualProtect in unmap_pages () failed, %E");
|
2001-01-16 03:42:33 +08:00
|
|
|
|
2011-12-22 19:02:36 +08:00
|
|
|
off /= wincap.page_size ();
|
2007-01-09 19:18:57 +08:00
|
|
|
len = PAGE_CNT (len);
|
2001-01-16 03:42:33 +08:00
|
|
|
for (; len-- > 0; ++off)
|
|
|
|
MAP_CLR (off);
|
|
|
|
/* Return TRUE if all pages are free'd which may result in unmapping
|
|
|
|
the whole chunk. */
|
2005-11-29 06:32:29 +08:00
|
|
|
for (len = MAPSIZE (PAGE_CNT (get_len ())); len > 0; )
|
|
|
|
if (page_map[--len])
|
2003-12-08 06:37:12 +08:00
|
|
|
return false;
|
|
|
|
return true;
|
2001-01-16 03:42:33 +08:00
|
|
|
}
|
|
|
|
|
2002-03-12 01:57:22 +08:00
|
|
|
int
|
2003-01-15 04:40:09 +08:00
|
|
|
mmap_record::access (caddr_t address)
|
2002-03-12 01:57:22 +08:00
|
|
|
{
|
2005-11-29 06:32:29 +08:00
|
|
|
if (address < get_address () || address >= get_address () + get_len ())
|
2002-03-12 01:57:22 +08:00
|
|
|
return 0;
|
2016-05-21 03:48:10 +08:00
|
|
|
SIZE_T off = (address - get_address ()) / wincap.page_size ();
|
2002-03-12 01:57:22 +08:00
|
|
|
return MAP_ISSET (off);
|
|
|
|
}
|
|
|
|
|
2001-04-17 01:26:04 +08:00
|
|
|
fhandler_base *
|
|
|
|
mmap_record::alloc_fh ()
|
|
|
|
{
|
2005-11-30 00:28:05 +08:00
|
|
|
if (anonymous ())
|
2001-04-17 01:26:04 +08:00
|
|
|
{
|
2005-12-07 19:16:47 +08:00
|
|
|
fh_anonymous.set_io_handle (INVALID_HANDLE_VALUE);
|
|
|
|
fh_anonymous.set_access (GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE);
|
|
|
|
return &fh_anonymous;
|
2001-04-17 01:26:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The file descriptor could have been closed or, even
|
|
|
|
worse, could have been reused for another file before
|
|
|
|
the call to fork(). This requires creating a fhandler
|
|
|
|
of the correct type to be sure to call the method of the
|
|
|
|
correct class. */
|
2011-03-18 21:42:03 +08:00
|
|
|
device fdev;
|
2016-06-23 22:56:41 +08:00
|
|
|
fdev.name ("");
|
|
|
|
fdev.native ("");
|
2011-03-18 21:42:03 +08:00
|
|
|
fdev.parse (get_device ());
|
2011-03-18 21:56:56 +08:00
|
|
|
fhandler_base *fh = build_fh_dev (fdev);
|
2012-04-08 01:32:44 +08:00
|
|
|
if (fh)
|
|
|
|
fh->set_access (get_openflags ());
|
2005-12-07 19:16:47 +08:00
|
|
|
return fh;
|
2001-04-17 01:26:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mmap_record::free_fh (fhandler_base *fh)
|
|
|
|
{
|
2005-11-30 00:28:05 +08:00
|
|
|
if (!anonymous ())
|
2009-08-20 16:34:21 +08:00
|
|
|
delete fh;
|
2001-04-17 01:26:04 +08:00
|
|
|
}
|
|
|
|
|
2001-01-16 03:42:33 +08:00
|
|
|
mmap_record *
|
2011-03-18 21:38:34 +08:00
|
|
|
mmap_list::add_record (mmap_record &r)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-03-18 21:38:34 +08:00
|
|
|
mmap_record *rec = (mmap_record *) ccalloc (HEAP_MMAP,
|
|
|
|
sizeof (mmap_record)
|
|
|
|
+ MAPSIZE (PAGE_CNT (r.get_len ())) * sizeof (DWORD), 1);
|
2007-11-27 18:09:05 +08:00
|
|
|
if (!rec)
|
|
|
|
return NULL;
|
2011-03-18 21:38:34 +08:00
|
|
|
rec->init_page_map (r);
|
|
|
|
|
2007-11-27 18:09:05 +08:00
|
|
|
LIST_INSERT_HEAD (&recs, rec, mr_next);
|
|
|
|
return rec;
|
2001-01-16 03:42:33 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
void
|
2013-04-23 17:44:36 +08:00
|
|
|
mmap_list::set (int nfd, struct stat *st)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-11-30 00:28:05 +08:00
|
|
|
fd = nfd;
|
|
|
|
if (!anonymous ())
|
2005-12-07 19:16:47 +08:00
|
|
|
{
|
|
|
|
/* The fd isn't sufficient since it could already be the fd of another
|
|
|
|
file. So we use the inode number as evaluated by fstat to identify
|
|
|
|
the file. */
|
2013-04-23 17:44:36 +08:00
|
|
|
hash = st ? st->st_ino : (ino_t) 0;
|
2005-12-07 19:16:47 +08:00
|
|
|
}
|
2007-11-27 18:09:05 +08:00
|
|
|
LIST_INIT (&recs);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-09-04 18:27:51 +08:00
|
|
|
bool
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_list::del_record (mmap_record *rec)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2007-11-27 18:09:05 +08:00
|
|
|
LIST_REMOVE (rec, mr_next);
|
|
|
|
cfree (rec);
|
2003-09-04 18:27:51 +08:00
|
|
|
/* Return true if the list is empty which allows the caller to remove
|
2007-11-27 18:09:05 +08:00
|
|
|
this list from the list of lists. */
|
|
|
|
return !LIST_FIRST(&recs);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2005-11-30 23:05:48 +08:00
|
|
|
caddr_t
|
2013-04-23 17:44:36 +08:00
|
|
|
mmap_list::try_map (void *addr, size_t len, int flags, off_t off)
|
2005-11-30 23:05:48 +08:00
|
|
|
{
|
|
|
|
mmap_record *rec;
|
|
|
|
|
|
|
|
if (off == 0 && !fixed (flags))
|
|
|
|
{
|
|
|
|
/* If MAP_FIXED isn't given, check if this mapping matches into the
|
|
|
|
chunk of another already performed mapping. */
|
2013-04-23 17:44:36 +08:00
|
|
|
SIZE_T plen = PAGE_CNT (len);
|
2007-11-27 22:45:14 +08:00
|
|
|
LIST_FOREACH (rec, &recs, mr_next)
|
2016-05-21 03:48:10 +08:00
|
|
|
if (rec->find_unused_pages (plen) != (SIZE_T) -1)
|
2007-11-27 22:45:14 +08:00
|
|
|
break;
|
|
|
|
if (rec && rec->compatible_flags (flags))
|
2005-11-30 23:05:48 +08:00
|
|
|
{
|
2016-05-21 03:48:10 +08:00
|
|
|
if ((off = rec->map_pages (len)) == (off_t) -1)
|
2005-11-30 23:05:48 +08:00
|
|
|
return (caddr_t) MAP_FAILED;
|
|
|
|
return (caddr_t) rec->get_address () + off;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fixed (flags))
|
|
|
|
{
|
|
|
|
/* If MAP_FIXED is given, test if the requested area is in an
|
|
|
|
unmapped part of an still active mapping. This can happen
|
|
|
|
if a memory region is unmapped and remapped with MAP_FIXED. */
|
|
|
|
caddr_t u_addr;
|
2016-05-21 03:48:10 +08:00
|
|
|
SIZE_T u_len;
|
2007-11-27 18:09:05 +08:00
|
|
|
|
|
|
|
LIST_FOREACH (rec, &recs, mr_next)
|
|
|
|
if (rec->match ((caddr_t) addr, len, u_addr, u_len))
|
|
|
|
break;
|
|
|
|
if (rec)
|
2005-11-30 23:05:48 +08:00
|
|
|
{
|
|
|
|
if (u_addr > (caddr_t) addr || u_addr + len < (caddr_t) addr + len
|
|
|
|
|| !rec->compatible_flags (flags))
|
|
|
|
{
|
|
|
|
/* Partial match only, or access mode doesn't match. */
|
|
|
|
/* FIXME: Handle partial mappings gracefully if adjacent
|
|
|
|
memory is available. */
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return (caddr_t) MAP_FAILED;
|
|
|
|
}
|
|
|
|
if (!rec->map_pages ((caddr_t) addr, len))
|
|
|
|
return (caddr_t) MAP_FAILED;
|
|
|
|
return (caddr_t) addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_list *
|
2013-04-23 17:44:36 +08:00
|
|
|
mmap_areas::get_list_by_fd (int fd, struct stat *st)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_list *ml;
|
|
|
|
LIST_FOREACH (ml, &lists, ml_next)
|
2005-12-07 19:16:47 +08:00
|
|
|
{
|
2007-11-27 18:09:05 +08:00
|
|
|
if (fd == -1 && ml->anonymous ())
|
|
|
|
return ml;
|
2005-12-07 19:16:47 +08:00
|
|
|
/* The fd isn't sufficient since it could already be the fd of another
|
|
|
|
file. So we use the inode number as evaluated by fstat to identify
|
|
|
|
the file. */
|
2007-11-27 18:09:05 +08:00
|
|
|
if (fd != -1 && st && ml->get_hash () == st->st_ino)
|
|
|
|
return ml;
|
2005-12-07 19:16:47 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_list *
|
2013-04-23 17:44:36 +08:00
|
|
|
mmap_areas::add_list (int fd, struct stat *st)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_list *ml = (mmap_list *) cmalloc (HEAP_MMAP, sizeof (mmap_list));
|
|
|
|
if (!ml)
|
|
|
|
return NULL;
|
|
|
|
ml->set (fd, st);
|
|
|
|
LIST_INSERT_HEAD (&lists, ml, ml_next);
|
|
|
|
return ml;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_areas::del_list (mmap_list *ml)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2007-11-27 18:09:05 +08:00
|
|
|
LIST_REMOVE (ml, ml_next);
|
|
|
|
cfree (ml);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2011-05-16 17:55:18 +08:00
|
|
|
/* This function allows an external function to test if a given memory
|
|
|
|
region is part of an mmapped memory region. */
|
|
|
|
bool
|
|
|
|
is_mmapped_region (caddr_t start_addr, caddr_t end_address)
|
|
|
|
{
|
|
|
|
size_t len = end_address - start_addr;
|
|
|
|
|
|
|
|
LIST_LOCK ();
|
|
|
|
mmap_list *map_list = mmapped_areas.get_list_by_fd (-1, NULL);
|
|
|
|
|
2011-05-17 23:37:01 +08:00
|
|
|
if (!map_list)
|
2013-04-06 04:25:39 +08:00
|
|
|
{
|
|
|
|
LIST_UNLOCK ();
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-17 23:37:01 +08:00
|
|
|
|
2011-05-16 17:55:18 +08:00
|
|
|
mmap_record *rec;
|
|
|
|
caddr_t u_addr;
|
2016-05-21 03:48:10 +08:00
|
|
|
SIZE_T u_len;
|
2011-05-17 23:37:01 +08:00
|
|
|
bool ret = false;
|
2011-05-16 17:55:18 +08:00
|
|
|
|
|
|
|
LIST_FOREACH (rec, &map_list->recs, mr_next)
|
|
|
|
{
|
|
|
|
if (rec->match (start_addr, len, u_addr, u_len))
|
|
|
|
{
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LIST_UNLOCK ();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
/* This function is called from exception_handler when a segmentation
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
violation has occurred. It should also be called from all Cygwin
|
|
|
|
functions that want to support passing noreserve mmap page addresses
|
|
|
|
to Windows system calls. In that case, it should be called only after
|
|
|
|
a system call indicates that the application buffer passed had an
|
|
|
|
invalid virtual address to avoid any performance impact in non-noreserve
|
|
|
|
cases.
|
2007-02-20 08:16:18 +08:00
|
|
|
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
Check if the address range is all within noreserve mmap regions. If so,
|
|
|
|
call VirtualAlloc to commit the pages and return MMAP_NORESERVE_COMMITED
|
|
|
|
on success. If the page has __PROT_ATTACH (SUSv3 memory protection
|
2015-08-26 04:02:35 +08:00
|
|
|
extension), or if VirtualAlloc fails, return MMAP_RAISE_SIGBUS.
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
Otherwise, return MMAP_NONE if the address range is not covered by an
|
|
|
|
attached or noreserve map.
|
|
|
|
|
|
|
|
On MAP_NORESERVE_COMMITED, the exeception handler should return 0 to
|
|
|
|
allow the application to retry the memory access, or the calling Cygwin
|
|
|
|
function should retry the Windows system call. */
|
2011-05-16 17:55:18 +08:00
|
|
|
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
mmap_region_status
|
|
|
|
mmap_is_attached_or_noreserve (void *addr, size_t len)
|
|
|
|
{
|
2007-11-27 22:45:14 +08:00
|
|
|
mmap_region_status ret = MMAP_NONE;
|
|
|
|
|
|
|
|
LIST_LOCK ();
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_list *map_list = mmapped_areas.get_list_by_fd (-1, NULL);
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
|
2011-12-22 19:02:36 +08:00
|
|
|
size_t pagesize = wincap.allocation_granularity ();
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
caddr_t start_addr = (caddr_t) rounddown ((uintptr_t) addr, pagesize);
|
|
|
|
len += ((caddr_t) addr - start_addr);
|
|
|
|
len = roundup2 (len, pagesize);
|
|
|
|
|
|
|
|
if (map_list == NULL)
|
2007-11-27 22:45:14 +08:00
|
|
|
goto out;
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_record *rec;
|
|
|
|
caddr_t u_addr;
|
2016-05-21 03:48:10 +08:00
|
|
|
SIZE_T u_len;
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
|
2007-11-27 18:09:05 +08:00
|
|
|
LIST_FOREACH (rec, &map_list->recs, mr_next)
|
|
|
|
{
|
|
|
|
if (!rec->match (start_addr, len, u_addr, u_len))
|
|
|
|
continue;
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
if (rec->attached ())
|
2007-11-27 22:45:14 +08:00
|
|
|
{
|
|
|
|
ret = MMAP_RAISE_SIGBUS;
|
|
|
|
break;
|
|
|
|
}
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
if (!rec->noreserve ())
|
2007-11-27 22:45:14 +08:00
|
|
|
break;
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
|
|
|
|
size_t commit_len = u_len - (start_addr - u_addr);
|
|
|
|
if (commit_len > len)
|
|
|
|
commit_len = len;
|
|
|
|
|
|
|
|
if (!VirtualAlloc (start_addr, commit_len, MEM_COMMIT,
|
|
|
|
rec->gen_protect ()))
|
2007-11-27 22:45:14 +08:00
|
|
|
{
|
|
|
|
ret = MMAP_RAISE_SIGBUS;
|
|
|
|
break;
|
|
|
|
}
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
|
|
|
|
start_addr += commit_len;
|
|
|
|
len -= commit_len;
|
2007-11-27 18:09:05 +08:00
|
|
|
if (!len)
|
2007-11-27 22:45:14 +08:00
|
|
|
{
|
|
|
|
ret = MMAP_NORESERVE_COMMITED;
|
|
|
|
break;
|
|
|
|
}
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
}
|
2007-11-27 22:45:14 +08:00
|
|
|
out:
|
|
|
|
LIST_UNLOCK ();
|
|
|
|
return ret;
|
2005-12-07 19:16:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static caddr_t
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_worker (mmap_list *map_list, fhandler_base *fh, caddr_t base, size_t len,
|
2013-04-23 17:44:36 +08:00
|
|
|
int prot, int flags, int fd, off_t off, struct stat *st)
|
2005-12-07 19:16:47 +08:00
|
|
|
{
|
|
|
|
HANDLE h = fh->mmap (&base, len, prot, flags, off);
|
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
|
|
|
return NULL;
|
2007-01-19 01:15:59 +08:00
|
|
|
if (!map_list
|
|
|
|
&& !(map_list = mmapped_areas.get_list_by_fd (fd, st))
|
|
|
|
&& !(map_list = mmapped_areas.add_list (fd, st)))
|
2005-12-07 19:16:47 +08:00
|
|
|
{
|
|
|
|
fh->munmap (h, base, len);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
mmap_record mmap_rec (fd, h, fh->get_access (), prot, flags, off, len, base);
|
|
|
|
mmap_record *rec = map_list->add_record (mmap_rec);
|
|
|
|
if (!rec)
|
|
|
|
{
|
|
|
|
fh->munmap (h, base, len);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
|
|
|
|
/* The memory region used for memory maps */
|
|
|
|
#define MMAP_STORAGE_LOW 0x00800000000L /* Leave 8 Gigs for heap. */
|
|
|
|
#define MMAP_STORAGE_HIGH 0x70000000000L /* Leave enough room for OS. */
|
|
|
|
|
|
|
|
/* FIXME? Unfortunately the OS doesn't support a top down allocation with
|
|
|
|
a ceiling value. The ZeroBits mechanism only works for
|
|
|
|
NtMapViewOfSection and it only evaluates the high bit of ZeroBits
|
|
|
|
on 64 bit, so it's pretty much useless for our purposes.
|
|
|
|
|
|
|
|
If the below simple mechanism to perform top-down allocations
|
|
|
|
turns out to be too dumb, we need something else. One idea is to
|
|
|
|
dived the space in (3835) 4 Gig chunks and simply store the
|
|
|
|
available free space per slot. Then we can go top down from slot
|
|
|
|
to slot and only try slots which are supposed to have enough space.
|
|
|
|
Bookkeeping would be very simple and fast. */
|
|
|
|
class mmap_allocator
|
|
|
|
{
|
|
|
|
caddr_t mmap_current_low;
|
|
|
|
|
|
|
|
public:
|
|
|
|
mmap_allocator () : mmap_current_low ((caddr_t) MMAP_STORAGE_HIGH) {}
|
|
|
|
|
|
|
|
PVOID alloc (PVOID in_addr, SIZE_T in_size, bool fixed)
|
|
|
|
{
|
|
|
|
MEMORY_BASIC_INFORMATION mbi;
|
|
|
|
|
|
|
|
SIZE_T size = roundup2 (in_size, wincap.allocation_granularity ());
|
|
|
|
/* First check for the given address. */
|
|
|
|
if (in_addr)
|
|
|
|
{
|
|
|
|
/* If it points to a free area, big enough to fulfill the request,
|
|
|
|
return the address. */
|
|
|
|
if (VirtualQuery (in_addr, &mbi, sizeof mbi)
|
|
|
|
&& mbi.State == MEM_FREE
|
|
|
|
&& mbi.RegionSize >= size)
|
|
|
|
return in_addr;
|
|
|
|
/* Otherwise, if MAP_FIXED was given, give up. */
|
|
|
|
if (fixed)
|
|
|
|
return NULL;
|
|
|
|
/* Otherwise, fall through to the usual free space search mechanism. */
|
|
|
|
}
|
|
|
|
/* Start with the last allocation start address - requested size. */
|
|
|
|
caddr_t addr = mmap_current_low - size;
|
|
|
|
bool merry_go_round = false;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Did we hit the lower ceiling? If so, restart from the upper
|
|
|
|
ceiling, but note that we did it. */
|
|
|
|
if (addr < (caddr_t) MMAP_STORAGE_LOW)
|
|
|
|
{
|
|
|
|
addr = (caddr_t) MMAP_STORAGE_HIGH - size;
|
|
|
|
merry_go_round = true;
|
|
|
|
}
|
|
|
|
/* Shouldn't fail, but better test. */
|
|
|
|
if (!VirtualQuery ((PVOID) addr, &mbi, sizeof mbi))
|
|
|
|
return NULL;
|
|
|
|
/* If the region is free... */
|
|
|
|
if (mbi.State == MEM_FREE)
|
|
|
|
{
|
|
|
|
/* ...and the region is big enough to fulfill the request... */
|
|
|
|
if (mbi.RegionSize >= size)
|
|
|
|
{
|
|
|
|
/* ...note the address as next start address for our simple
|
|
|
|
merry-go-round and return the address. */
|
|
|
|
mmap_current_low = addr;
|
|
|
|
return (PVOID) addr;
|
|
|
|
}
|
|
|
|
/* Otherwise, subtract what's missing in size and try again. */
|
|
|
|
addr -= size - mbi.RegionSize;
|
|
|
|
}
|
|
|
|
/* If the region isn't free, skip to address below AllocationBase
|
|
|
|
and try again. */
|
|
|
|
else
|
|
|
|
addr = (caddr_t) mbi.AllocationBase - size;
|
|
|
|
}
|
|
|
|
/* Repeat until we had a full ride on the merry_go_round. */
|
|
|
|
while (!merry_go_round || addr >= mmap_current_low);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static mmap_allocator mmap_alloc; /* Inherited by forked child. */
|
|
|
|
#endif
|
|
|
|
|
2003-09-09 17:41:18 +08:00
|
|
|
extern "C" void *
|
2013-04-23 17:44:36 +08:00
|
|
|
mmap64 (void *addr, size_t len, int prot, int flags, int fd, off_t off)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("addr %p, len %lu, prot %y, flags %y, fd %d, off %Y",
|
2000-02-18 03:38:33 +08:00
|
|
|
addr, len, prot, flags, fd, off);
|
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
caddr_t ret = (caddr_t) MAP_FAILED;
|
|
|
|
fhandler_base *fh = NULL;
|
2007-09-18 23:59:50 +08:00
|
|
|
fhandler_disk_file *fh_disk_file = NULL; /* Used for reopening a disk file
|
|
|
|
when necessary. */
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_list *map_list = NULL;
|
2005-12-07 19:16:47 +08:00
|
|
|
size_t orig_len = 0;
|
|
|
|
caddr_t base = NULL;
|
2013-04-23 17:44:36 +08:00
|
|
|
struct stat st;
|
2005-11-29 06:32:29 +08:00
|
|
|
|
2013-10-15 16:13:42 +08:00
|
|
|
size_t pagesize = wincap.allocation_granularity ();
|
2001-01-16 03:42:33 +08:00
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
fh_anonymous.set_io_handle (INVALID_HANDLE_VALUE);
|
|
|
|
fh_anonymous.set_access (GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE);
|
|
|
|
|
2007-02-23 01:35:14 +08:00
|
|
|
/* EINVAL error conditions. */
|
2005-11-29 06:32:29 +08:00
|
|
|
if (off % pagesize
|
|
|
|
|| ((prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)))
|
2005-11-30 00:28:05 +08:00
|
|
|
|| ((flags & MAP_TYPE) != MAP_SHARED
|
|
|
|
&& (flags & MAP_TYPE) != MAP_PRIVATE)
|
2005-12-07 19:16:47 +08:00
|
|
|
|| (fixed (flags) && ((uintptr_t) addr % pagesize))
|
2001-01-16 03:42:33 +08:00
|
|
|
|| !len)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
2005-11-29 06:32:29 +08:00
|
|
|
goto out;
|
2001-01-16 03:42:33 +08:00
|
|
|
}
|
|
|
|
|
2017-12-10 21:11:03 +08:00
|
|
|
/* POSIX: When MAP_FIXED is not set, the implementation uses addr in an
|
|
|
|
implementation-defined manner to arrive at pa [the return address].
|
|
|
|
Given that we refuse addr if it's not exactly at a page boundary, we
|
|
|
|
can just make sure addr does so indiscriminately. Just round down
|
|
|
|
to the next lower page boundary. */
|
|
|
|
addr = (void *) rounddown ((uintptr_t) addr, pagesize);
|
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
if (!anonymous (flags) && fd != -1)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* Ensure that fd is open */
|
2001-10-16 07:39:33 +08:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
2005-11-29 06:32:29 +08:00
|
|
|
goto out;
|
2019-01-08 02:33:11 +08:00
|
|
|
if (cfd->get_flags () & O_PATH)
|
|
|
|
{
|
|
|
|
set_errno (EBADF);
|
|
|
|
goto out;
|
|
|
|
}
|
2005-11-29 06:32:29 +08:00
|
|
|
|
2001-10-16 22:04:26 +08:00
|
|
|
fh = cfd;
|
2005-12-07 19:16:47 +08:00
|
|
|
|
|
|
|
/* mmap /dev/zero is like MAP_ANONYMOUS. */
|
2005-03-01 19:51:29 +08:00
|
|
|
if (fh->get_device () == FH_ZERO)
|
2005-12-07 19:16:47 +08:00
|
|
|
flags |= MAP_ANONYMOUS;
|
2011-03-26 04:39:26 +08:00
|
|
|
|
|
|
|
/* The autoconf mmap test maps a file of size 1 byte. It then tests
|
|
|
|
every byte of the entire mapped page of 64K for 0-bytes since that's
|
|
|
|
what POSIX requires. The problem is, we can't create that mapping on
|
|
|
|
64 bit systems. The file mapping will be only a single page, 4K, and
|
|
|
|
since 64 bit systems don't support the AT_ROUND_TO_PAGE flag, the
|
|
|
|
remainder of the 64K slot will result in a SEGV when accessed.
|
|
|
|
|
|
|
|
So, what we do here is cheating for the sake of the autoconf test
|
|
|
|
on 64 bit systems. The justification is that there's very likely
|
|
|
|
no application actually utilizing the map beyond EOF, and we know that
|
|
|
|
all bytes beyond EOF are set to 0 anyway. If this test doesn't work
|
|
|
|
on 64 bit systems, it will result in not using mmap at all in a
|
|
|
|
package. But we want that mmap is treated as usable by autoconf,
|
|
|
|
regardless whether the autoconf test runs on a 32 bit or a 64 bit
|
|
|
|
system.
|
|
|
|
|
|
|
|
Ok, so we know exactly what autoconf is doing. The file is called
|
|
|
|
"conftest.txt", it has a size of 1 byte, the mapping size is the
|
|
|
|
pagesize, the requested protection is PROT_READ | PROT_WRITE, the
|
|
|
|
mapping is MAP_SHARED, the offset is 0.
|
|
|
|
|
|
|
|
If all these requirements are given, we just return an anonymous map.
|
|
|
|
This will help to get over the autoconf test even on 64 bit systems.
|
|
|
|
The tests are ordered for speed. */
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
if (1)
|
|
|
|
#else
|
2011-03-26 04:39:26 +08:00
|
|
|
if (wincap.is_wow64 ())
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
2011-03-26 04:39:26 +08:00
|
|
|
{
|
|
|
|
UNICODE_STRING fname;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
FILE_STANDARD_INFORMATION fsi;
|
|
|
|
|
|
|
|
if (len == pagesize
|
|
|
|
&& prot == (PROT_READ | PROT_WRITE)
|
|
|
|
&& flags == MAP_SHARED
|
|
|
|
&& off == 0
|
|
|
|
&& (RtlSplitUnicodePath (fh->pc.get_nt_native_path (), NULL,
|
|
|
|
&fname),
|
|
|
|
wcscmp (fname.Buffer, L"conftest.txt") == 0)
|
|
|
|
&& NT_SUCCESS (NtQueryInformationFile (fh->get_handle (), &io,
|
|
|
|
&fsi, sizeof fsi,
|
|
|
|
FileStandardInformation))
|
|
|
|
&& fsi.EndOfFile.QuadPart == 1LL)
|
|
|
|
flags |= MAP_ANONYMOUS;
|
|
|
|
}
|
2001-01-16 06:18:14 +08:00
|
|
|
}
|
2006-07-13 18:29:21 +08:00
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
if (anonymous (flags) || fd == -1)
|
2001-01-16 06:18:14 +08:00
|
|
|
{
|
2005-12-07 19:16:47 +08:00
|
|
|
fh = &fh_anonymous;
|
|
|
|
fd = -1;
|
2005-11-29 06:32:29 +08:00
|
|
|
flags |= MAP_ANONYMOUS;
|
2005-12-07 19:16:47 +08:00
|
|
|
/* Anonymous mappings are always forced to pagesize length with
|
2005-12-22 13:57:54 +08:00
|
|
|
no offset. */
|
2005-12-07 19:16:47 +08:00
|
|
|
len = roundup2 (len, pagesize);
|
2005-12-02 04:35:13 +08:00
|
|
|
off = 0;
|
2005-03-01 19:51:29 +08:00
|
|
|
}
|
2005-11-30 00:28:05 +08:00
|
|
|
else if (fh->get_device () == FH_FS)
|
2005-03-01 19:51:29 +08:00
|
|
|
{
|
2005-12-07 19:16:47 +08:00
|
|
|
/* EACCES error conditions according to SUSv3. File must be opened
|
2005-12-22 13:57:54 +08:00
|
|
|
for reading, regardless of the requested protection, and file must
|
2005-12-07 19:16:47 +08:00
|
|
|
be opened for writing when PROT_WRITE together with MAP_SHARED
|
|
|
|
is requested. */
|
|
|
|
if (!(fh->get_access () & GENERIC_READ)
|
|
|
|
|| (!(fh->get_access () & GENERIC_WRITE)
|
|
|
|
&& (prot & PROT_WRITE) && !priv (flags)))
|
|
|
|
{
|
|
|
|
set_errno (EACCES);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-02-22 18:54:47 +08:00
|
|
|
/* You can't create mappings with PAGE_EXECUTE protection if
|
|
|
|
the file isn't explicitely opened with EXECUTE access. */
|
2007-08-14 03:44:31 +08:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE h;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
2009-07-15 01:37:42 +08:00
|
|
|
InitializeObjectAttributes (&attr, &ro_u_empty, fh->pc.objcaseinsensitive (),
|
2007-08-14 03:44:31 +08:00
|
|
|
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))
|
2005-12-07 19:16:47 +08:00
|
|
|
{
|
2009-08-21 16:47:59 +08:00
|
|
|
fh_disk_file = new (ccalloc (HEAP_FHANDLER, 1, sizeof *fh_disk_file))
|
|
|
|
fhandler_disk_file;
|
2007-09-18 23:59:50 +08:00
|
|
|
fh_disk_file->set_name (fh->pc);
|
|
|
|
fh_disk_file->set_io_handle (h);
|
|
|
|
fh_disk_file->set_access (fh->get_access () | GENERIC_EXECUTE);
|
|
|
|
fh = fh_disk_file;
|
2005-12-07 19:16:47 +08:00
|
|
|
}
|
2007-02-22 18:54:47 +08:00
|
|
|
else if (prot & PROT_EXEC)
|
2005-12-22 13:57:54 +08:00
|
|
|
{
|
2007-02-22 18:54:47 +08:00
|
|
|
/* TODO: To be or not to be... I'm opting for refusing this
|
|
|
|
mmap request rather than faking it, but that might break
|
|
|
|
some non-portable code. */
|
|
|
|
set_errno (EACCES);
|
|
|
|
goto out;
|
2005-12-07 19:16:47 +08:00
|
|
|
}
|
|
|
|
|
2010-09-13 19:17:36 +08:00
|
|
|
if (fh->fstat_fs (&st))
|
2007-02-20 08:16:18 +08:00
|
|
|
{
|
2007-01-19 01:15:59 +08:00
|
|
|
__seterrno ();
|
|
|
|
goto out;
|
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
off_t fsiz = st.st_size;
|
2005-03-08 17:18:47 +08:00
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
/* Don't allow file mappings beginning beyond EOF since Windows can't
|
2005-03-08 17:18:47 +08:00
|
|
|
handle that POSIX like, unless MAP_AUTOGROW flag is set, which
|
2005-12-07 19:16:47 +08:00
|
|
|
mimics Windows behaviour. */
|
2005-11-30 00:28:05 +08:00
|
|
|
if (off >= fsiz && !autogrow (flags))
|
2005-03-01 19:51:29 +08:00
|
|
|
{
|
2005-12-07 19:16:47 +08:00
|
|
|
/* Instead, it seems suitable to return an anonymous mapping of
|
|
|
|
the given size instead. Mapped addresses beyond EOF aren't
|
|
|
|
written back to the file anyway, so the handling is identical
|
|
|
|
to other pages beyond EOF. */
|
|
|
|
fh = &fh_anonymous;
|
|
|
|
len = roundup2 (len, pagesize);
|
|
|
|
prot = PROT_READ | PROT_WRITE | __PROT_ATTACH;
|
|
|
|
flags &= MAP_FIXED;
|
|
|
|
flags |= MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;
|
|
|
|
fd = -1;
|
|
|
|
off = 0;
|
|
|
|
goto go_ahead;
|
2005-03-01 19:51:29 +08:00
|
|
|
}
|
2005-11-29 06:32:29 +08:00
|
|
|
fsiz -= off;
|
2007-02-23 01:35:14 +08:00
|
|
|
/* We're creating the pages beyond EOF as reserved, anonymous pages.
|
2013-04-23 17:44:36 +08:00
|
|
|
Note that this isn't done in 64 bit environments since apparently
|
|
|
|
64 bit systems don't support the AT_ROUND_TO_PAGE flag, which is
|
|
|
|
required to get this right. Too bad. */
|
2017-11-27 21:36:06 +08:00
|
|
|
#ifdef __i386__
|
2007-02-23 01:35:14 +08:00
|
|
|
if (!wincap.is_wow64 ()
|
2013-04-23 17:44:36 +08:00
|
|
|
&& (((off_t) len > fsiz && !autogrow (flags))
|
2011-12-22 19:02:36 +08:00
|
|
|
|| roundup2 (len, wincap.page_size ())
|
2009-01-18 01:20:37 +08:00
|
|
|
< roundup2 (len, pagesize)))
|
2005-12-07 19:16:47 +08:00
|
|
|
orig_len = len;
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
|
|
|
if ((off_t) len > fsiz)
|
2005-05-02 11:50:11 +08:00
|
|
|
{
|
2005-11-30 00:28:05 +08:00
|
|
|
if (autogrow (flags))
|
2005-03-08 17:18:47 +08:00
|
|
|
{
|
2005-12-07 19:16:47 +08:00
|
|
|
/* Allow mapping beyond EOF if MAP_AUTOGROW flag is set.
|
2005-12-22 13:57:54 +08:00
|
|
|
Check if file has been opened for writing, otherwise
|
2005-12-07 19:16:47 +08:00
|
|
|
MAP_AUTOGROW is invalid. */
|
2005-03-08 17:18:47 +08:00
|
|
|
if (!(fh->get_access () & GENERIC_WRITE))
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
2005-11-29 06:32:29 +08:00
|
|
|
goto out;
|
2005-03-08 17:18:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2005-12-07 19:16:47 +08:00
|
|
|
/* Otherwise, don't map beyond EOF, since Windows would change
|
|
|
|
the file to the new length, in contrast to POSIX. */
|
2005-11-29 06:32:29 +08:00
|
|
|
len = fsiz;
|
2005-03-08 17:18:47 +08:00
|
|
|
}
|
2005-11-29 06:32:29 +08:00
|
|
|
|
|
|
|
/* If the requested offset + len is <= file size, drop MAP_AUTOGROW.
|
2005-05-02 11:50:11 +08:00
|
|
|
This simplifes fhandler::mmap's job. */
|
2013-04-23 17:44:36 +08:00
|
|
|
if (autogrow (flags) && (off + (off_t) len) <= fsiz)
|
2005-05-02 11:50:11 +08:00
|
|
|
flags &= ~MAP_AUTOGROW;
|
2005-03-01 19:51:29 +08:00
|
|
|
}
|
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
go_ahead:
|
|
|
|
|
2006-07-13 18:29:21 +08:00
|
|
|
/* MAP_NORESERVE is only supported on private anonymous mappings.
|
|
|
|
Remove that bit from flags so that later code doesn't have to
|
|
|
|
test all bits. */
|
|
|
|
if (noreserve (flags) && (!anonymous (flags) || !priv (flags)))
|
|
|
|
flags &= ~MAP_NORESERVE;
|
|
|
|
|
2007-11-27 22:45:14 +08:00
|
|
|
LIST_LOCK ();
|
2007-01-19 01:15:59 +08:00
|
|
|
map_list = mmapped_areas.get_list_by_fd (fd, &st);
|
2001-02-09 05:02:36 +08:00
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
/* Test if an existing anonymous mapping can be recycled. */
|
2005-11-30 00:28:05 +08:00
|
|
|
if (map_list && anonymous (flags))
|
2005-02-25 19:15:22 +08:00
|
|
|
{
|
2005-11-30 23:05:48 +08:00
|
|
|
caddr_t tried = map_list->try_map (addr, len, flags, off);
|
|
|
|
/* try_map returns NULL if no map matched, otherwise it returns
|
2007-11-27 22:45:14 +08:00
|
|
|
a valid address, or MAP_FAILED in case of a fatal error. */
|
2005-11-30 23:05:48 +08:00
|
|
|
if (tried)
|
2005-12-22 13:57:54 +08:00
|
|
|
{
|
2005-11-30 23:05:48 +08:00
|
|
|
ret = tried;
|
2007-11-27 22:45:14 +08:00
|
|
|
goto out_with_unlock;
|
2005-02-25 19:15:22 +08:00
|
|
|
}
|
|
|
|
}
|
2001-09-28 06:39:50 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
addr = mmap_alloc.alloc (addr, orig_len ?: len, fixed (flags));
|
|
|
|
#else
|
2007-01-10 17:30:38 +08:00
|
|
|
if (orig_len)
|
|
|
|
{
|
|
|
|
/* If the requested length is bigger than the file size, we try to
|
|
|
|
allocate an area of the full size first. This area is immediately
|
|
|
|
deallocated and the address we got is used as base address for the
|
|
|
|
subsequent real mappings. This ensures that we have enough space
|
|
|
|
for the whole thing. */
|
|
|
|
orig_len = roundup2 (orig_len, pagesize);
|
2007-01-17 18:49:24 +08:00
|
|
|
PVOID newaddr = VirtualAlloc (addr, orig_len, MEM_TOP_DOWN | MEM_RESERVE,
|
|
|
|
PAGE_READWRITE);
|
|
|
|
if (!newaddr)
|
2007-02-20 08:16:18 +08:00
|
|
|
{
|
2007-01-17 18:49:24 +08:00
|
|
|
/* If addr is not NULL, but MAP_FIXED isn't given, allow the OS
|
|
|
|
to choose. */
|
|
|
|
if (addr && !fixed (flags))
|
|
|
|
newaddr = VirtualAlloc (NULL, orig_len, MEM_TOP_DOWN | MEM_RESERVE,
|
|
|
|
PAGE_READWRITE);
|
|
|
|
if (!newaddr)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
2007-11-27 22:45:14 +08:00
|
|
|
goto out_with_unlock;
|
2007-01-17 18:49:24 +08:00
|
|
|
}
|
2007-01-10 17:30:38 +08:00
|
|
|
}
|
2007-01-17 18:49:24 +08:00
|
|
|
if (!VirtualFree (newaddr, 0, MEM_RELEASE))
|
2007-02-20 08:16:18 +08:00
|
|
|
{
|
2007-01-10 17:30:38 +08:00
|
|
|
__seterrno ();
|
2007-11-27 22:45:14 +08:00
|
|
|
goto out_with_unlock;
|
2007-01-10 17:30:38 +08:00
|
|
|
}
|
2007-01-17 18:49:24 +08:00
|
|
|
addr = newaddr;
|
2007-01-10 17:30:38 +08:00
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
2007-01-10 17:30:38 +08:00
|
|
|
|
2007-01-19 01:15:59 +08:00
|
|
|
base = mmap_worker (map_list, fh, (caddr_t) addr, len, prot, flags, fd, off,
|
|
|
|
&st);
|
2005-12-07 19:16:47 +08:00
|
|
|
if (!base)
|
2007-11-27 22:45:14 +08:00
|
|
|
goto out_with_unlock;
|
2005-11-29 06:32:29 +08:00
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
if (orig_len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-12-07 19:16:47 +08:00
|
|
|
/* If the requested length is bigger than the file size, the
|
|
|
|
remainder is created as anonymous mapping. Actually two
|
2007-01-10 17:30:38 +08:00
|
|
|
mappings are created, first the remainder from the file end to
|
2005-12-07 19:16:47 +08:00
|
|
|
the next 64K boundary as accessible pages with the same
|
|
|
|
protection as the file's pages, then as much pages as necessary
|
|
|
|
to accomodate the requested length, but as reserved pages which
|
|
|
|
raise a SIGBUS when trying to access them. AT_ROUND_TO_PAGE
|
2017-12-10 21:11:41 +08:00
|
|
|
and page protection on shared pages is only supported by the
|
|
|
|
32 bit environment, so don't even try on 64 bit or even WOW64.
|
|
|
|
This is accomplished by not setting orig_len on 64 bit above. */
|
2011-12-22 19:02:36 +08:00
|
|
|
len = roundup2 (len, wincap.page_size ());
|
2005-12-07 19:16:47 +08:00
|
|
|
if (orig_len - len)
|
|
|
|
{
|
|
|
|
orig_len -= len;
|
|
|
|
size_t valid_page_len = orig_len % pagesize;
|
|
|
|
size_t sigbus_page_len = orig_len - valid_page_len;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
caddr_t at_base = base + len;
|
|
|
|
if (valid_page_len)
|
|
|
|
{
|
|
|
|
prot |= __PROT_FILLER;
|
|
|
|
flags &= MAP_SHARED | MAP_PRIVATE;
|
|
|
|
flags |= MAP_ANONYMOUS | MAP_FIXED;
|
2007-01-19 01:15:59 +08:00
|
|
|
at_base = mmap_worker (NULL, &fh_anonymous, at_base,
|
|
|
|
valid_page_len, prot, flags, -1, 0, NULL);
|
2005-12-07 19:16:47 +08:00
|
|
|
if (!at_base)
|
|
|
|
{
|
|
|
|
fh->munmap (fh->get_handle (), base, len);
|
|
|
|
set_errno (ENOMEM);
|
2007-11-27 22:45:14 +08:00
|
|
|
goto out_with_unlock;
|
2005-12-07 19:16:47 +08:00
|
|
|
}
|
|
|
|
at_base += valid_page_len;
|
|
|
|
}
|
|
|
|
if (sigbus_page_len)
|
|
|
|
{
|
|
|
|
prot = PROT_READ | PROT_WRITE | __PROT_ATTACH;
|
|
|
|
flags = MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED;
|
2007-01-19 01:15:59 +08:00
|
|
|
at_base = mmap_worker (NULL, &fh_anonymous, at_base,
|
|
|
|
sigbus_page_len, prot, flags, -1, 0, NULL);
|
2005-12-07 19:16:47 +08:00
|
|
|
if (!at_base)
|
|
|
|
debug_printf ("Warning: Mapping beyond EOF failed, %E");
|
|
|
|
}
|
|
|
|
}
|
2003-09-04 18:27:51 +08:00
|
|
|
}
|
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
ret = base;
|
|
|
|
|
2007-11-27 22:45:14 +08:00
|
|
|
out_with_unlock:
|
|
|
|
LIST_UNLOCK ();
|
2005-11-29 06:32:29 +08:00
|
|
|
|
2007-11-27 22:45:14 +08:00
|
|
|
out:
|
2005-12-07 19:16:47 +08:00
|
|
|
|
2007-09-18 23:59:50 +08:00
|
|
|
if (fh_disk_file)
|
2009-08-21 16:47:59 +08:00
|
|
|
{
|
|
|
|
NtClose (fh_disk_file->get_handle ());
|
|
|
|
delete fh;
|
|
|
|
}
|
2005-12-07 19:16:47 +08:00
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
syscall_printf ("%p = mmap() ", ret);
|
2001-01-16 03:42:33 +08:00
|
|
|
return ret;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2017-11-27 21:36:06 +08:00
|
|
|
#ifdef __i386__
|
2003-09-09 17:41:18 +08:00
|
|
|
extern "C" void *
|
|
|
|
mmap (void *addr, size_t len, int prot, int flags, int fd, _off_t off)
|
2002-02-26 01:47:51 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
return mmap64 (addr, len, prot, flags, fd, (off_t)off);
|
2002-02-26 01:47:51 +08:00
|
|
|
}
|
2017-11-27 21:36:06 +08:00
|
|
|
#else
|
|
|
|
EXPORT_ALIAS (mmap64, mmap)
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
2002-02-26 01:47:51 +08:00
|
|
|
|
2003-07-06 02:59:35 +08:00
|
|
|
/* munmap () removes all mmapped pages between addr and addr+len. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-10 04:10:25 +08:00
|
|
|
extern "C" int
|
2003-09-09 17:41:18 +08:00
|
|
|
munmap (void *addr, size_t len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("munmap (addr %p, len %lu)", addr, len);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-07-06 02:59:35 +08:00
|
|
|
/* Error conditions according to SUSv3 */
|
2005-11-29 06:32:29 +08:00
|
|
|
if (!addr || !len || check_invalid_virtual_addr (addr, len))
|
2001-01-16 03:42:33 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-12-22 19:02:36 +08:00
|
|
|
size_t pagesize = wincap.allocation_granularity ();
|
2005-12-07 19:16:47 +08:00
|
|
|
if (((uintptr_t) addr % pagesize) || !len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-11-29 06:32:29 +08:00
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2005-12-07 19:16:47 +08:00
|
|
|
len = roundup2 (len, pagesize);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2007-11-27 22:45:14 +08:00
|
|
|
LIST_LOCK ();
|
2005-11-29 06:32:29 +08:00
|
|
|
|
2015-08-26 04:02:35 +08:00
|
|
|
/* Iterate over maps, unmap pages between addr and addr+len in all maps. */
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_list *map_list, *next_map_list;
|
|
|
|
LIST_FOREACH_SAFE (map_list, &mmapped_areas.lists, ml_next, next_map_list)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_record *rec, *next_rec;
|
2003-09-04 18:27:51 +08:00
|
|
|
caddr_t u_addr;
|
2016-05-21 03:48:10 +08:00
|
|
|
SIZE_T u_len;
|
2003-07-06 02:59:35 +08:00
|
|
|
|
2007-11-27 18:09:05 +08:00
|
|
|
LIST_FOREACH_SAFE (rec, &map_list->recs, mr_next, next_rec)
|
2008-02-16 01:53:11 +08:00
|
|
|
{
|
2007-11-27 18:09:05 +08:00
|
|
|
if (!rec->match ((caddr_t) addr, len, u_addr, u_len))
|
|
|
|
continue;
|
2003-09-04 18:27:51 +08:00
|
|
|
if (rec->unmap_pages (u_addr, u_len))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-09-26 16:50:12 +08:00
|
|
|
/* The whole record has been unmapped, so we now actually
|
2003-11-29 04:55:59 +08:00
|
|
|
unmap it from the system in full length... */
|
2003-09-04 18:27:51 +08:00
|
|
|
fhandler_base *fh = rec->alloc_fh ();
|
2003-09-26 16:50:12 +08:00
|
|
|
fh->munmap (rec->get_handle (),
|
2003-11-29 04:55:59 +08:00
|
|
|
rec->get_address (),
|
2005-11-29 06:32:29 +08:00
|
|
|
rec->get_len ());
|
2003-09-04 18:27:51 +08:00
|
|
|
rec->free_fh (fh);
|
2000-10-05 21:07:02 +08:00
|
|
|
|
2003-09-26 16:50:12 +08:00
|
|
|
/* ...and delete the record. */
|
2007-11-27 18:09:05 +08:00
|
|
|
if (map_list->del_record (rec))
|
2003-09-04 18:27:51 +08:00
|
|
|
{
|
|
|
|
/* Yay, the last record has been removed from the list,
|
|
|
|
we can remove the list now, too. */
|
2007-11-27 18:09:05 +08:00
|
|
|
mmapped_areas.del_list (map_list);
|
2003-09-04 18:27:51 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2001-01-16 03:42:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2007-11-27 22:45:14 +08:00
|
|
|
LIST_UNLOCK ();
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("0 = munmap(): %p", addr);
|
2003-07-06 02:59:35 +08:00
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sync file with memory. Ignore flags for now. */
|
|
|
|
|
2003-03-10 04:10:25 +08:00
|
|
|
extern "C" int
|
2003-09-09 17:41:18 +08:00
|
|
|
msync (void *addr, size_t len, int flags)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-11-29 06:32:29 +08:00
|
|
|
int ret = -1;
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_list *map_list;
|
2005-11-29 06:32:29 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("msync (addr: %p, len %lu, flags %y)", addr, len, flags);
|
2005-12-07 19:16:47 +08:00
|
|
|
|
2011-05-01 00:34:48 +08:00
|
|
|
pthread_testcancel ();
|
|
|
|
|
2007-11-27 22:45:14 +08:00
|
|
|
LIST_LOCK ();
|
2005-11-29 06:32:29 +08:00
|
|
|
|
2011-12-22 19:02:36 +08:00
|
|
|
if (((uintptr_t) addr % wincap.allocation_granularity ())
|
2005-12-07 19:16:47 +08:00
|
|
|
|| (flags & ~(MS_ASYNC | MS_SYNC | MS_INVALIDATE))
|
2008-09-11 12:34:24 +08:00
|
|
|
|| ((flags & (MS_ASYNC | MS_SYNC)) == (MS_ASYNC | MS_SYNC)))
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
2005-11-29 06:32:29 +08:00
|
|
|
goto out;
|
2000-10-05 21:07:02 +08:00
|
|
|
}
|
2006-07-19 16:58:09 +08:00
|
|
|
#if 0 /* If I only knew why I did that... */
|
2011-12-22 19:02:36 +08:00
|
|
|
len = roundup2 (len, wincap.allocation_granularity ());
|
2006-07-19 16:58:09 +08:00
|
|
|
#endif
|
2000-10-05 21:07:02 +08:00
|
|
|
|
2015-08-26 04:02:35 +08:00
|
|
|
/* Iterate over maps, looking for the mmapped area. Error if not found. */
|
2007-11-27 18:09:05 +08:00
|
|
|
LIST_FOREACH (map_list, &mmapped_areas.lists, ml_next)
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
2003-09-04 18:27:51 +08:00
|
|
|
mmap_record *rec;
|
2007-11-27 18:09:05 +08:00
|
|
|
LIST_FOREACH (rec, &map_list->recs, mr_next)
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
2007-11-27 18:09:05 +08:00
|
|
|
if (rec->access ((caddr_t) addr))
|
2001-02-05 20:36:41 +08:00
|
|
|
{
|
2003-09-04 18:27:51 +08:00
|
|
|
/* Check whole area given by len. */
|
2016-05-21 03:48:10 +08:00
|
|
|
for (SIZE_T i = wincap.allocation_granularity ();
|
2011-12-22 19:02:36 +08:00
|
|
|
i < len;
|
|
|
|
i += wincap.allocation_granularity ())
|
2007-11-27 18:09:05 +08:00
|
|
|
if (!rec->access ((caddr_t) addr + i))
|
2005-11-29 06:32:29 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
goto out;
|
|
|
|
}
|
2003-09-04 18:27:51 +08:00
|
|
|
fhandler_base *fh = rec->alloc_fh ();
|
2007-11-27 18:09:05 +08:00
|
|
|
ret = fh->msync (rec->get_handle (), (caddr_t) addr, len, flags);
|
2003-09-04 18:27:51 +08:00
|
|
|
rec->free_fh (fh);
|
2005-11-29 06:32:29 +08:00
|
|
|
goto out;
|
2002-03-12 04:23:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-10-05 21:07:02 +08:00
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
/* No matching mapping exists. */
|
2000-10-05 21:07:02 +08:00
|
|
|
set_errno (ENOMEM);
|
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
out:
|
2007-11-27 22:45:14 +08:00
|
|
|
LIST_UNLOCK ();
|
2011-12-04 05:43:27 +08:00
|
|
|
syscall_printf ("%R = msync()", ret);
|
2005-11-29 06:32:29 +08:00
|
|
|
return ret;
|
2000-10-05 21:07:02 +08:00
|
|
|
}
|
|
|
|
|
2003-09-09 17:41:18 +08:00
|
|
|
/* Set memory protection */
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
mprotect (void *addr, size_t len, int prot)
|
|
|
|
{
|
2005-12-07 19:16:47 +08:00
|
|
|
bool in_mapped = false;
|
|
|
|
bool ret = false;
|
2003-09-09 17:41:18 +08:00
|
|
|
DWORD old_prot;
|
|
|
|
DWORD new_prot = 0;
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("mprotect (addr: %p, len %lu, prot %y)", addr, len, prot);
|
2003-09-09 17:41:18 +08:00
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
/* See comment in mmap64 for a description. */
|
2011-12-22 19:02:36 +08:00
|
|
|
size_t pagesize = wincap.allocation_granularity ();
|
2005-12-07 19:16:47 +08:00
|
|
|
if ((uintptr_t) addr % pagesize)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
len = roundup2 (len, pagesize);
|
2003-09-09 17:41:18 +08:00
|
|
|
|
2007-11-27 22:45:14 +08:00
|
|
|
LIST_LOCK ();
|
2005-12-06 04:20:18 +08:00
|
|
|
|
2015-08-26 04:02:35 +08:00
|
|
|
/* Iterate over maps, protect pages between addr and addr+len in all maps. */
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_list *map_list;
|
|
|
|
LIST_FOREACH (map_list, &mmapped_areas.lists, ml_next)
|
|
|
|
{
|
|
|
|
mmap_record *rec;
|
|
|
|
caddr_t u_addr;
|
2016-05-21 03:48:10 +08:00
|
|
|
SIZE_T u_len;
|
2007-11-27 18:09:05 +08:00
|
|
|
|
|
|
|
LIST_FOREACH (rec, &map_list->recs, mr_next)
|
2008-02-16 01:53:11 +08:00
|
|
|
{
|
2007-11-27 18:09:05 +08:00
|
|
|
if (!rec->match ((caddr_t) addr, len, u_addr, u_len))
|
|
|
|
continue;
|
|
|
|
in_mapped = true;
|
|
|
|
if (rec->attached ())
|
|
|
|
continue;
|
|
|
|
new_prot = gen_protect (prot, rec->get_flags ());
|
|
|
|
if (rec->noreserve ())
|
|
|
|
{
|
|
|
|
if (new_prot == PAGE_NOACCESS)
|
|
|
|
ret = VirtualFree (u_addr, u_len, MEM_DECOMMIT);
|
|
|
|
else
|
|
|
|
ret = !!VirtualAlloc (u_addr, u_len, MEM_COMMIT, new_prot);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = VirtualProtect (u_addr, u_len, new_prot, &old_prot);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-11-29 06:32:29 +08:00
|
|
|
|
2007-11-27 22:45:14 +08:00
|
|
|
LIST_UNLOCK ();
|
2005-11-29 06:32:29 +08:00
|
|
|
|
|
|
|
if (!in_mapped)
|
2004-07-16 01:00:44 +08:00
|
|
|
{
|
2005-11-29 06:32:29 +08:00
|
|
|
int flags = 0;
|
2005-11-30 00:28:05 +08:00
|
|
|
MEMORY_BASIC_INFORMATION mbi;
|
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
ret = VirtualQuery (addr, &mbi, sizeof mbi);
|
|
|
|
if (ret)
|
2005-12-22 13:57:54 +08:00
|
|
|
{
|
2005-12-07 19:16:47 +08:00
|
|
|
/* If write protection is requested, check if the page was
|
|
|
|
originally protected writecopy. In this case call VirtualProtect
|
|
|
|
requesting PAGE_WRITECOPY, otherwise the VirtualProtect will fail
|
|
|
|
on NT version >= 5.0 */
|
|
|
|
if (prot & PROT_WRITE)
|
|
|
|
{
|
|
|
|
if (mbi.AllocationProtect == PAGE_WRITECOPY
|
|
|
|
|| mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY)
|
|
|
|
flags = MAP_PRIVATE;
|
|
|
|
}
|
|
|
|
new_prot = gen_protect (prot, flags);
|
|
|
|
if (new_prot != PAGE_NOACCESS && mbi.State == MEM_RESERVE)
|
|
|
|
ret = VirtualAlloc (addr, len, MEM_COMMIT, new_prot);
|
|
|
|
else
|
|
|
|
ret = VirtualProtect (addr, len, new_prot, &old_prot);
|
2005-11-29 06:32:29 +08:00
|
|
|
}
|
2005-11-30 00:28:05 +08:00
|
|
|
if (!ret)
|
2005-12-07 19:16:47 +08:00
|
|
|
__seterrno ();
|
2003-09-09 17:41:18 +08:00
|
|
|
}
|
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
out:
|
|
|
|
|
2011-12-04 05:43:27 +08:00
|
|
|
syscall_printf ("%R = mprotect ()", ret ? 0 : -1);
|
2005-12-07 19:16:47 +08:00
|
|
|
return ret ? 0 : -1;
|
2003-09-09 17:41:18 +08:00
|
|
|
}
|
|
|
|
|
2005-10-19 02:51:33 +08:00
|
|
|
extern "C" int
|
|
|
|
mlock (const void *addr, size_t len)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
/* Align address and length values to page size. */
|
2011-12-22 19:02:36 +08:00
|
|
|
size_t pagesize = wincap.allocation_granularity ();
|
2017-12-10 21:11:41 +08:00
|
|
|
PVOID base = (PVOID) rounddown ((uintptr_t) addr, pagesize);
|
2013-04-23 17:44:36 +08:00
|
|
|
SIZE_T size = roundup2 (((uintptr_t) addr - (uintptr_t) base) + len,
|
|
|
|
pagesize);
|
2005-10-19 02:51:33 +08:00
|
|
|
NTSTATUS status = 0;
|
|
|
|
do
|
|
|
|
{
|
2009-12-19 04:32:04 +08:00
|
|
|
status = NtLockVirtualMemory (NtCurrentProcess (), &base, &size,
|
2011-12-05 23:46:26 +08:00
|
|
|
MAP_PROCESS);
|
2005-10-19 02:51:33 +08:00
|
|
|
if (status == STATUS_WORKING_SET_QUOTA)
|
|
|
|
{
|
|
|
|
/* The working set is too small, try to increase it so that the
|
|
|
|
requested locking region fits in. Unfortunately I don't know
|
|
|
|
any function which would return the currently locked pages of
|
|
|
|
a process (no go with NtQueryVirtualMemory).
|
2005-12-22 13:57:54 +08:00
|
|
|
|
2005-10-19 02:51:33 +08:00
|
|
|
So, except for the border cases, what we do here is something
|
|
|
|
really embarrassing. We raise the working set by 64K at a time
|
|
|
|
and retry, until either we fail to raise the working set size
|
|
|
|
further, or until NtLockVirtualMemory returns successfully (or
|
|
|
|
with another error). */
|
2013-04-23 17:44:36 +08:00
|
|
|
SIZE_T min, max;
|
2009-12-19 04:32:04 +08:00
|
|
|
if (!GetProcessWorkingSetSize (GetCurrentProcess (), &min, &max))
|
2005-10-19 02:51:33 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (min < size)
|
2005-11-29 06:32:29 +08:00
|
|
|
min = size + pagesize;
|
|
|
|
else if (size < pagesize)
|
2005-10-19 02:51:33 +08:00
|
|
|
min += size;
|
|
|
|
else
|
2005-11-29 06:32:29 +08:00
|
|
|
min += pagesize;
|
2005-10-19 02:51:33 +08:00
|
|
|
if (max < min)
|
|
|
|
max = min;
|
2009-12-19 04:32:04 +08:00
|
|
|
if (!SetProcessWorkingSetSize (GetCurrentProcess (), min, max))
|
2005-10-19 02:51:33 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!NT_SUCCESS (status))
|
|
|
|
__seterrno_from_nt_status (status);
|
|
|
|
else
|
2005-12-22 13:57:54 +08:00
|
|
|
ret = 0;
|
2005-10-19 02:51:33 +08:00
|
|
|
}
|
|
|
|
while (status == STATUS_WORKING_SET_QUOTA);
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("%R = mlock(%p, %lu)", ret, addr, len);
|
2005-10-19 02:51:33 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
munlock (const void *addr, size_t len)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
/* Align address and length values to page size. */
|
2011-12-22 19:02:36 +08:00
|
|
|
size_t pagesize = wincap.allocation_granularity ();
|
2017-12-10 21:11:41 +08:00
|
|
|
PVOID base = (PVOID) rounddown ((uintptr_t) addr, pagesize);
|
2013-04-23 17:44:36 +08:00
|
|
|
SIZE_T size = roundup2 (((uintptr_t) addr - (uintptr_t) base) + len,
|
|
|
|
pagesize);
|
2009-12-19 04:32:04 +08:00
|
|
|
NTSTATUS status = NtUnlockVirtualMemory (NtCurrentProcess (), &base, &size,
|
2011-12-05 23:46:26 +08:00
|
|
|
MAP_PROCESS);
|
2005-10-19 02:51:33 +08:00
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
__seterrno_from_nt_status (status);
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("%R = munlock(%p, %lu)", ret, addr, len);
|
2005-10-19 02:51:33 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-27 19:34:10 +08:00
|
|
|
/* This is required until Mingw-w64 catches up with newer functions. */
|
|
|
|
extern "C" WINAPI DWORD DiscardVirtualMemory (PVOID, SIZE_T);
|
|
|
|
|
2007-02-08 01:22:40 +08:00
|
|
|
extern "C" int
|
|
|
|
posix_madvise (void *addr, size_t len, int advice)
|
|
|
|
{
|
2015-08-27 19:34:10 +08:00
|
|
|
int ret = 0;
|
2007-02-08 01:22:40 +08:00
|
|
|
/* Check parameters. */
|
|
|
|
if (advice < POSIX_MADV_NORMAL || advice > POSIX_MADV_DONTNEED
|
|
|
|
|| !len)
|
|
|
|
{
|
2015-08-27 19:34:10 +08:00
|
|
|
ret = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check requested memory area. */
|
|
|
|
MEMORY_BASIC_INFORMATION m;
|
|
|
|
char *p, *endp;
|
|
|
|
|
|
|
|
for (p = (char *) addr, endp = p + len;
|
|
|
|
p < endp;
|
|
|
|
p = (char *) m.BaseAddress + m.RegionSize)
|
|
|
|
{
|
|
|
|
if (!VirtualQuery (p, &m, sizeof m) || m.State == MEM_FREE)
|
2011-12-04 07:55:21 +08:00
|
|
|
{
|
2015-08-27 19:34:10 +08:00
|
|
|
ret = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
switch (advice)
|
|
|
|
{
|
|
|
|
case POSIX_MADV_WILLNEED:
|
|
|
|
{
|
|
|
|
/* Align address and length values to page size. */
|
|
|
|
size_t pagesize = wincap.allocation_granularity ();
|
|
|
|
PVOID base = (PVOID) rounddown ((uintptr_t) addr, pagesize);
|
|
|
|
SIZE_T size = roundup2 (((uintptr_t) addr - (uintptr_t) base)
|
|
|
|
+ len, pagesize);
|
|
|
|
WIN32_MEMORY_RANGE_ENTRY me = { base, size };
|
|
|
|
if (!PrefetchVirtualMemory (GetCurrentProcess (), 1, &me, 0)
|
|
|
|
&& GetLastError () != ERROR_PROC_NOT_FOUND)
|
|
|
|
{
|
|
|
|
/* FIXME 2015-08-27: On W10 build 10240 under WOW64,
|
|
|
|
PrefetchVirtualMemory always returns ERROR_INVALID_PARAMETER
|
|
|
|
for some reason. If we're running on W10 WOW64, ignore this
|
2015-12-03 20:33:43 +08:00
|
|
|
error. This has been fixed in W10 1511. */
|
2015-08-27 19:34:10 +08:00
|
|
|
if (!wincap.has_broken_prefetchvm ()
|
|
|
|
|| GetLastError () != ERROR_INVALID_PARAMETER)
|
|
|
|
ret = EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case POSIX_MADV_DONTNEED:
|
|
|
|
{
|
|
|
|
/* Align address and length values to page size. */
|
|
|
|
size_t pagesize = wincap.allocation_granularity ();
|
|
|
|
PVOID base = (PVOID) rounddown ((uintptr_t) addr, pagesize);
|
|
|
|
SIZE_T size = roundup2 (((uintptr_t) addr - (uintptr_t) base)
|
|
|
|
+ len, pagesize);
|
|
|
|
DWORD err = DiscardVirtualMemory (base, size);
|
|
|
|
/* DiscardVirtualMemory is unfortunately pretty crippled:
|
|
|
|
On copy-on-write pages it returns ERROR_INVALID_PARAMETER, on
|
|
|
|
any file-backed memory map it returns ERROR_USER_MAPPED_FILE.
|
|
|
|
Since POSIX_MADV_DONTNEED is advisory only anyway, let them
|
|
|
|
slip through. */
|
|
|
|
switch (err)
|
|
|
|
{
|
|
|
|
case ERROR_PROC_NOT_FOUND:
|
|
|
|
case ERROR_USER_MAPPED_FILE:
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case ERROR_INVALID_PARAMETER:
|
2011-12-04 07:55:21 +08:00
|
|
|
{
|
2015-08-27 19:34:10 +08:00
|
|
|
ret = EINVAL;
|
|
|
|
/* Check if the region contains copy-on-write pages.*/
|
|
|
|
for (p = (char *) addr, endp = p + len;
|
|
|
|
p < endp;
|
|
|
|
p = (char *) m.BaseAddress + m.RegionSize)
|
|
|
|
{
|
|
|
|
if (VirtualQuery (p, &m, sizeof m)
|
|
|
|
&& m.State == MEM_COMMIT
|
|
|
|
&& m.Protect
|
|
|
|
& (PAGE_EXECUTE_WRITECOPY | PAGE_WRITECOPY))
|
|
|
|
{
|
|
|
|
/* Yes, let this slip. */
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-12-04 07:55:21 +08:00
|
|
|
}
|
2015-08-27 19:34:10 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = geterrno_from_win_error (err);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2007-02-08 01:22:40 +08:00
|
|
|
}
|
2015-08-27 19:34:10 +08:00
|
|
|
out:
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("%d = posix_madvise(%p, %lu, %d)", ret, addr, len, advice);
|
2015-08-27 19:34:10 +08:00
|
|
|
return ret;
|
2007-02-08 01:22:40 +08:00
|
|
|
}
|
|
|
|
|
2000-10-05 21:07:02 +08:00
|
|
|
/*
|
|
|
|
* Base implementation:
|
|
|
|
*
|
|
|
|
* `mmap' returns ENODEV as documented in SUSv2.
|
|
|
|
* In contrast to the global function implementation, the member function
|
|
|
|
* `mmap' has to return the mapped base address in `addr' and the handle to
|
|
|
|
* the mapping object as return value. In case of failure, the fhandler
|
|
|
|
* mmap has to close that handle by itself and return INVALID_HANDLE_VALUE.
|
|
|
|
*
|
|
|
|
* `munmap' and `msync' get the handle to the mapping object as first parameter
|
|
|
|
* additionally.
|
|
|
|
*/
|
|
|
|
HANDLE
|
2005-11-29 06:32:29 +08:00
|
|
|
fhandler_base::mmap (caddr_t *addr, size_t len, int prot,
|
2013-04-23 17:44:36 +08:00
|
|
|
int flags, off_t off)
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
|
|
|
set_errno (ENODEV);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::munmap (HANDLE h, caddr_t addr, size_t len)
|
|
|
|
{
|
|
|
|
set_errno (ENODEV);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_base::msync (HANDLE h, caddr_t addr, size_t len, int flags)
|
|
|
|
{
|
|
|
|
set_errno (ENODEV);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-12-08 06:37:12 +08:00
|
|
|
bool
|
2005-11-29 06:32:29 +08:00
|
|
|
fhandler_base::fixup_mmap_after_fork (HANDLE h, int prot, int flags,
|
2016-05-21 03:48:10 +08:00
|
|
|
off_t offset, SIZE_T size,
|
2005-02-26 05:23:15 +08:00
|
|
|
void *address)
|
2001-01-11 20:33:12 +08:00
|
|
|
{
|
|
|
|
set_errno (ENODEV);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-11-30 00:28:05 +08:00
|
|
|
/* Implementation for anonymous maps. Using fhandler_dev_zero looks
|
|
|
|
quite the natural way. */
|
|
|
|
HANDLE
|
|
|
|
fhandler_dev_zero::mmap (caddr_t *addr, size_t len, int prot,
|
2013-04-23 17:44:36 +08:00
|
|
|
int flags, off_t off)
|
2005-11-30 00:28:05 +08:00
|
|
|
{
|
|
|
|
HANDLE h;
|
|
|
|
void *base;
|
|
|
|
|
2005-12-07 19:16:47 +08:00
|
|
|
if (priv (flags) && !filler (prot))
|
2005-11-30 00:28:05 +08:00
|
|
|
{
|
|
|
|
/* Private anonymous maps are now implemented using VirtualAlloc.
|
2005-12-22 13:57:54 +08:00
|
|
|
This has two advantages:
|
2005-11-30 00:28:05 +08:00
|
|
|
|
|
|
|
- VirtualAlloc has a smaller footprint than a copy-on-write
|
|
|
|
anonymous map.
|
|
|
|
|
|
|
|
- It supports decommitting using VirtualFree, in contrast to
|
|
|
|
section maps. This allows minimum footprint private maps,
|
|
|
|
when using the (non-POSIX, yay-Linux) MAP_NORESERVE flag.
|
|
|
|
*/
|
|
|
|
DWORD protect = gen_protect (prot, flags);
|
2006-11-01 02:41:16 +08:00
|
|
|
DWORD alloc_type = MEM_TOP_DOWN | MEM_RESERVE
|
2007-02-20 08:16:18 +08:00
|
|
|
| (noreserve (flags) ? 0 : MEM_COMMIT);
|
2005-11-30 00:28:05 +08:00
|
|
|
base = VirtualAlloc (*addr, len, alloc_type, protect);
|
|
|
|
if (!base && addr && !fixed (flags))
|
|
|
|
base = VirtualAlloc (NULL, len, alloc_type, protect);
|
|
|
|
if (!base || (fixed (flags) && base != *addr))
|
|
|
|
{
|
|
|
|
if (!base)
|
|
|
|
__seterrno ();
|
|
|
|
else
|
|
|
|
{
|
2005-12-19 23:25:23 +08:00
|
|
|
VirtualFree (base, 0, MEM_RELEASE);
|
2005-11-30 00:28:05 +08:00
|
|
|
set_errno (EINVAL);
|
2005-12-02 04:35:13 +08:00
|
|
|
debug_printf ("VirtualAlloc: address shift with MAP_FIXED given");
|
2005-11-30 00:28:05 +08:00
|
|
|
}
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
h = (HANDLE) 1; /* Fake handle to indicate success. */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-14 03:44:31 +08:00
|
|
|
h = CreateMapping (get_handle (), len, off, get_access (), prot, flags);
|
2005-11-30 00:28:05 +08:00
|
|
|
if (!h)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
2005-12-02 04:35:13 +08:00
|
|
|
debug_printf ("CreateMapping failed with %E");
|
2005-11-30 00:28:05 +08:00
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
2007-02-22 18:54:47 +08:00
|
|
|
base = MapView (h, *addr, len, get_access(), prot, flags, off);
|
2005-11-30 00:28:05 +08:00
|
|
|
if (!base || (fixed (flags) && base != *addr))
|
|
|
|
{
|
|
|
|
if (!base)
|
|
|
|
__seterrno ();
|
|
|
|
else
|
|
|
|
{
|
2009-12-19 04:32:04 +08:00
|
|
|
NtUnmapViewOfSection (NtCurrentProcess (), base);
|
2005-11-30 00:28:05 +08:00
|
|
|
set_errno (EINVAL);
|
2005-12-02 04:35:13 +08:00
|
|
|
debug_printf ("MapView: address shift with MAP_FIXED given");
|
2005-11-30 00:28:05 +08:00
|
|
|
}
|
2007-08-14 03:44:31 +08:00
|
|
|
NtClose (h);
|
2005-11-30 00:28:05 +08:00
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*addr = (caddr_t) base;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_zero::munmap (HANDLE h, caddr_t addr, size_t len)
|
|
|
|
{
|
2005-12-07 19:16:47 +08:00
|
|
|
if (h == (HANDLE) 1) /* See fhandler_dev_zero::mmap. */
|
2005-12-19 23:25:23 +08:00
|
|
|
VirtualFree (addr, 0, MEM_RELEASE);
|
2005-12-07 19:16:47 +08:00
|
|
|
else
|
|
|
|
{
|
2009-12-19 04:32:04 +08:00
|
|
|
NtUnmapViewOfSection (NtCurrentProcess (), addr);
|
2007-08-14 03:44:31 +08:00
|
|
|
NtClose (h);
|
2005-12-07 19:16:47 +08:00
|
|
|
}
|
2005-11-30 00:28:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_zero::msync (HANDLE h, caddr_t addr, size_t len, int flags)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
fhandler_dev_zero::fixup_mmap_after_fork (HANDLE h, int prot, int flags,
|
2016-05-21 03:48:10 +08:00
|
|
|
off_t offset, SIZE_T size,
|
2005-11-30 00:28:05 +08:00
|
|
|
void *address)
|
|
|
|
{
|
|
|
|
/* Re-create the map */
|
|
|
|
void *base;
|
2005-12-07 19:16:47 +08:00
|
|
|
if (priv (flags) && !filler (prot))
|
2005-11-30 00:28:05 +08:00
|
|
|
{
|
|
|
|
DWORD alloc_type = MEM_RESERVE | (noreserve (flags) ? 0 : MEM_COMMIT);
|
2005-11-30 23:05:48 +08:00
|
|
|
/* Always allocate R/W so that ReadProcessMemory doesn't fail
|
2005-12-22 13:57:54 +08:00
|
|
|
due to a non-writable target address. The protection is
|
2005-11-30 23:05:48 +08:00
|
|
|
set to the correct one anyway in the fixup loop. */
|
|
|
|
base = VirtualAlloc (address, size, alloc_type, PAGE_READWRITE);
|
2005-11-30 00:28:05 +08:00
|
|
|
}
|
|
|
|
else
|
2007-02-22 18:54:47 +08:00
|
|
|
base = MapView (h, address, size, get_access (), prot, flags, offset);
|
2005-11-30 00:28:05 +08:00
|
|
|
if (base != address)
|
|
|
|
{
|
|
|
|
MEMORY_BASIC_INFORMATION m;
|
|
|
|
VirtualQuery (address, &m, sizeof (m));
|
2013-04-23 17:44:36 +08:00
|
|
|
system_printf ("requested %p != %p mem alloc base %p, state %y, "
|
|
|
|
"size %lu, %E", address, base, m.AllocationBase, m.State,
|
2005-12-15 17:04:28 +08:00
|
|
|
m.RegionSize);
|
2005-11-30 00:28:05 +08:00
|
|
|
}
|
|
|
|
return base == address;
|
|
|
|
}
|
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
/* Implementation for disk files and anonymous mappings. */
|
2000-10-05 21:07:02 +08:00
|
|
|
HANDLE
|
2005-11-29 06:32:29 +08:00
|
|
|
fhandler_disk_file::mmap (caddr_t *addr, size_t len, int prot,
|
2013-04-23 17:44:36 +08:00
|
|
|
int flags, off_t off)
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
2007-02-22 18:54:47 +08:00
|
|
|
HANDLE h = CreateMapping (get_handle (), len, off, get_access (),
|
2007-08-14 03:44:31 +08:00
|
|
|
prot, flags);
|
2001-07-11 05:04:14 +08:00
|
|
|
if (!h)
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
2005-12-02 04:35:13 +08:00
|
|
|
debug_printf ("CreateMapping failed with %E");
|
2000-10-05 21:07:02 +08:00
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
2007-02-22 18:54:47 +08:00
|
|
|
void *base = MapView (h, *addr, len, get_access (), prot, flags, off);
|
2005-11-30 00:28:05 +08:00
|
|
|
if (!base || (fixed (flags) && base != *addr))
|
2000-10-05 21:07:02 +08:00
|
|
|
{
|
2000-10-08 01:35:36 +08:00
|
|
|
if (!base)
|
2005-11-29 06:32:29 +08:00
|
|
|
__seterrno ();
|
2000-10-08 01:35:36 +08:00
|
|
|
else
|
2001-09-03 10:13:05 +08:00
|
|
|
{
|
2009-12-19 04:32:04 +08:00
|
|
|
NtUnmapViewOfSection (NtCurrentProcess (), base);
|
2000-10-08 01:35:36 +08:00
|
|
|
set_errno (EINVAL);
|
2005-12-02 04:35:13 +08:00
|
|
|
debug_printf ("MapView: address shift with MAP_FIXED given");
|
2001-09-03 10:13:05 +08:00
|
|
|
}
|
2007-08-14 03:44:31 +08:00
|
|
|
NtClose (h);
|
2000-10-05 21:07:02 +08:00
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*addr = (caddr_t) base;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_disk_file::munmap (HANDLE h, caddr_t addr, size_t len)
|
|
|
|
{
|
2009-12-19 04:32:04 +08:00
|
|
|
NtUnmapViewOfSection (NtCurrentProcess (), addr);
|
2007-08-14 03:44:31 +08:00
|
|
|
NtClose (h);
|
2000-10-05 21:07:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_disk_file::msync (HANDLE h, caddr_t addr, size_t len, int flags)
|
|
|
|
{
|
2013-01-18 08:28:21 +08:00
|
|
|
const int retry = 100;
|
|
|
|
/* The wisdom of google tells us that FlushViewOfFile may fail with
|
|
|
|
ERROR_LOCK_VIOLATION if "if the memory system is writing dirty
|
|
|
|
pages to disk". And, we've seen reports of this happening in the
|
|
|
|
cygwin list. So retry 99 times and hope we get lucky. */
|
|
|
|
for (int i = 0; i < retry; i++)
|
|
|
|
if (FlushViewOfFile (addr, len))
|
2013-01-18 17:35:05 +08:00
|
|
|
{
|
|
|
|
/* FlushViewOfFile just triggers the action and returns immediately,
|
|
|
|
so it's equivalent to MS_ASYNC. MS_SYNC requires another call to
|
|
|
|
FlushFileBuffers. */
|
|
|
|
if (flags & MS_SYNC)
|
|
|
|
FlushFileBuffers (h);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-01-18 08:28:21 +08:00
|
|
|
else if (GetLastError () != ERROR_LOCK_VIOLATION)
|
|
|
|
break;
|
|
|
|
else if (i < (retry - 1))
|
|
|
|
yield ();
|
|
|
|
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-12-08 06:37:12 +08:00
|
|
|
bool
|
2005-11-29 06:32:29 +08:00
|
|
|
fhandler_disk_file::fixup_mmap_after_fork (HANDLE h, int prot, int flags,
|
2016-05-21 03:48:10 +08:00
|
|
|
off_t offset, SIZE_T size,
|
2005-02-26 05:23:15 +08:00
|
|
|
void *address)
|
2001-01-11 20:33:12 +08:00
|
|
|
{
|
2005-11-29 06:32:29 +08:00
|
|
|
/* Re-create the map */
|
2007-02-22 18:54:47 +08:00
|
|
|
void *base = MapView (h, address, size, get_access (), prot, flags, offset);
|
2002-10-21 09:00:58 +08:00
|
|
|
if (base != address)
|
|
|
|
{
|
|
|
|
MEMORY_BASIC_INFORMATION m;
|
2005-07-07 04:05:03 +08:00
|
|
|
VirtualQuery (address, &m, sizeof (m));
|
2013-04-23 17:44:36 +08:00
|
|
|
system_printf ("requested %p != %p mem alloc base %p, state %y, "
|
|
|
|
"size %lu, %E", address, base, m.AllocationBase, m.State,
|
2005-11-29 06:32:29 +08:00
|
|
|
m.RegionSize);
|
2002-10-21 09:00:58 +08:00
|
|
|
}
|
2001-01-11 20:33:12 +08:00
|
|
|
return base == address;
|
|
|
|
}
|
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
/* 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
|
|
|
|
none of the mapped areas are in our address space. We need to iterate
|
|
|
|
through the map, doing the MapViewOfFile calls. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int __stdcall
|
2002-03-12 01:57:22 +08:00
|
|
|
fixup_mmaps_after_fork (HANDLE parent)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2015-08-26 04:02:35 +08:00
|
|
|
/* Iterate over maps */
|
2007-11-27 18:09:05 +08:00
|
|
|
mmap_list *map_list;
|
|
|
|
LIST_FOREACH (map_list, &mmapped_areas.lists, ml_next)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-09-04 18:27:51 +08:00
|
|
|
mmap_record *rec;
|
2007-11-27 18:09:05 +08:00
|
|
|
LIST_FOREACH (rec, &map_list->recs, mr_next)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("fd %d, h %p, address %p, len %ly, prot: %y, "
|
|
|
|
"flags: %y, offset %Y",
|
2005-12-02 04:35:13 +08:00
|
|
|
rec->get_fd (), rec->get_handle (), rec->get_address (),
|
|
|
|
rec->get_len (), rec->get_prot (), rec->get_flags (),
|
|
|
|
rec->get_offset ());
|
2003-09-04 18:27:51 +08:00
|
|
|
|
|
|
|
fhandler_base *fh = rec->alloc_fh ();
|
2003-12-08 06:37:12 +08:00
|
|
|
bool ret = fh->fixup_mmap_after_fork (rec->get_handle (),
|
2005-11-29 06:32:29 +08:00
|
|
|
rec->get_prot (),
|
2005-12-02 04:35:13 +08:00
|
|
|
rec->get_flags () | MAP_FIXED,
|
2003-09-04 18:27:51 +08:00
|
|
|
rec->get_offset (),
|
2005-11-29 06:32:29 +08:00
|
|
|
rec->get_len (),
|
2003-09-04 18:27:51 +08:00
|
|
|
rec->get_address ());
|
|
|
|
rec->free_fh (fh);
|
|
|
|
|
|
|
|
if (!ret)
|
2005-12-07 19:16:47 +08:00
|
|
|
{
|
|
|
|
if (rec->attached ())
|
2005-12-22 13:57:54 +08:00
|
|
|
{
|
2005-12-07 19:16:47 +08:00
|
|
|
system_printf ("Warning: Fixup mapping beyond EOF failed");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2005-11-29 06:32:29 +08:00
|
|
|
|
|
|
|
MEMORY_BASIC_INFORMATION mbi;
|
|
|
|
DWORD old_prot;
|
|
|
|
|
|
|
|
for (char *address = rec->get_address ();
|
|
|
|
address < rec->get_address () + rec->get_len ();
|
|
|
|
address += mbi.RegionSize)
|
2003-09-04 18:27:51 +08:00
|
|
|
{
|
2005-11-29 06:32:29 +08:00
|
|
|
if (!VirtualQueryEx (parent, address, &mbi, sizeof mbi))
|
2005-12-22 13:57:54 +08:00
|
|
|
{
|
2005-11-29 06:32:29 +08:00
|
|
|
system_printf ("VirtualQueryEx failed for MAP_PRIVATE "
|
2005-12-22 13:57:54 +08:00
|
|
|
"address %p, %E", address);
|
2005-11-29 06:32:29 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2005-12-07 19:16:47 +08:00
|
|
|
/* Just skip reserved pages. */
|
2005-11-29 06:32:29 +08:00
|
|
|
if (mbi.State == MEM_RESERVE)
|
2005-12-07 19:16:47 +08:00
|
|
|
continue;
|
2005-11-29 06:32:29 +08:00
|
|
|
/* Copy-on-write pages must be copied to the child to circumvent
|
2005-12-22 13:57:54 +08:00
|
|
|
a strange notion how copy-on-write is supposed to work. */
|
2005-11-29 06:32:29 +08:00
|
|
|
if (rec->priv ())
|
|
|
|
{
|
2006-07-13 18:29:21 +08:00
|
|
|
if (rec->noreserve ()
|
2005-11-30 00:28:05 +08:00
|
|
|
&& !VirtualAlloc (address, mbi.RegionSize,
|
2005-12-22 13:57:54 +08:00
|
|
|
MEM_COMMIT, PAGE_READWRITE))
|
2005-11-30 00:28:05 +08:00
|
|
|
{
|
|
|
|
system_printf ("VirtualAlloc failed for MAP_PRIVATE "
|
|
|
|
"address %p, %E", address);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-11-29 06:32:29 +08:00
|
|
|
if (mbi.Protect == PAGE_NOACCESS
|
|
|
|
&& !VirtualProtectEx (parent, address, mbi.RegionSize,
|
|
|
|
PAGE_READONLY, &old_prot))
|
|
|
|
{
|
|
|
|
system_printf ("VirtualProtectEx failed for MAP_PRIVATE "
|
|
|
|
"address %p, %E", address);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-12-12 18:00:32 +08:00
|
|
|
else if ((mbi.AllocationProtect == PAGE_WRITECOPY
|
|
|
|
|| mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY)
|
2005-11-30 00:28:05 +08:00
|
|
|
&& (mbi.Protect == PAGE_READWRITE
|
|
|
|
|| mbi.Protect == PAGE_EXECUTE_READWRITE))
|
2005-12-12 18:00:32 +08:00
|
|
|
/* A WRITECOPY page which has been written to is set to
|
|
|
|
READWRITE, but that's an incompatible protection to
|
|
|
|
set the page to. Convert the protection to WRITECOPY
|
|
|
|
so that the below VirtualProtect doesn't fail. */
|
|
|
|
mbi.Protect <<= 1;
|
|
|
|
|
2005-11-29 06:32:29 +08:00
|
|
|
if (!ReadProcessMemory (parent, address, address,
|
|
|
|
mbi.RegionSize, NULL))
|
|
|
|
{
|
|
|
|
system_printf ("ReadProcessMemory failed for MAP_PRIVATE "
|
|
|
|
"address %p, %E", address);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (mbi.Protect == PAGE_NOACCESS
|
|
|
|
&& !VirtualProtectEx (parent, address, mbi.RegionSize,
|
|
|
|
PAGE_NOACCESS, &old_prot))
|
|
|
|
{
|
|
|
|
system_printf ("WARNING: VirtualProtectEx to return to "
|
|
|
|
"PAGE_NOACCESS state in parent failed for "
|
|
|
|
"MAP_PRIVATE address %p, %E", address);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2005-11-30 23:05:48 +08:00
|
|
|
/* Set child page protection to parent protection */
|
2005-11-29 06:32:29 +08:00
|
|
|
if (!VirtualProtect (address, mbi.RegionSize,
|
|
|
|
mbi.Protect, &old_prot))
|
|
|
|
{
|
2005-11-30 00:28:05 +08:00
|
|
|
MEMORY_BASIC_INFORMATION m;
|
|
|
|
VirtualQuery (address, &m, sizeof m);
|
2005-11-29 06:32:29 +08:00
|
|
|
system_printf ("VirtualProtect failed for "
|
2005-12-22 13:57:54 +08:00
|
|
|
"address %p, "
|
2013-04-23 17:44:36 +08:00
|
|
|
"parentstate: %y, "
|
|
|
|
"state: %y, "
|
|
|
|
"parentprot: %y, "
|
|
|
|
"prot: %y, %E",
|
2005-11-30 00:28:05 +08:00
|
|
|
address, mbi.State, m.State,
|
|
|
|
mbi.Protect, m.Protect);
|
2005-11-29 06:32:29 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2000-11-15 14:27:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
debug_printf ("succeeded");
|
|
|
|
return 0;
|
|
|
|
}
|